content
stringlengths
23
1.05M
------------------------------------------------------------------------------ -- Copyright (C) 2020 by Heisenbug Ltd. (gh+spat@heisenbug.eu) -- -- This work is free. You can redistribute it and/or modify it under the -- terms of the Do What The Fuck You Want To Public License, Version 2, -- as published by Sam Hocevar. See the LICENSE file for more details. ------------------------------------------------------------------------------ pragma License (Unrestricted); ------------------------------------------------------------------------------ -- -- SPARK Proof Analysis Tool -- -- S.P.A.T. - Read .spark files -- -- Collect file contents. -- -- Please note that Read is parallelized and uses background threads, hence -- you need to call Shutdown once you're done, otherwise the application will -- hang. -- ------------------------------------------------------------------------------ limited with Ada.Containers.Hashed_Maps; limited with SPAT.Strings; package SPAT.Spark_Files is -- .spark files are stored in a Hash map with the file name as key and the -- JSON reading result as value. package File_Maps is new Ada.Containers.Hashed_Maps (Key_Type => File_Name, Element_Type => GNATCOLL.JSON.Read_Result, Hash => Hash, Equivalent_Keys => "=", "=" => GNATCOLL.JSON."="); -- -- Some renames for commonly used File_Maps.Cursor operations. -- No_Element : File_Maps.Cursor renames File_Maps.No_Element; subtype Cursor is File_Maps.Cursor; --------------------------------------------------------------------------- -- Key --------------------------------------------------------------------------- function Key (C : in Cursor) return File_Name renames File_Maps.Key; -- -- Data collection and operations defined on it. -- type T is new File_Maps.Map with private; -- Stores all data collected from SPARK files for analysis. --------------------------------------------------------------------------- -- Read --------------------------------------------------------------------------- not overriding procedure Read (This : in out T; Names : in Strings.File_Names); -- Reads the list of files, and parses and stores their content in This. --------------------------------------------------------------------------- -- Num_Workers -- -- Report the number of tasks used for parallel file reads. --------------------------------------------------------------------------- function Num_Workers return Positive; --------------------------------------------------------------------------- -- Shutdown -- -- Terminates all worker tasks. --------------------------------------------------------------------------- procedure Shutdown; private type T is new File_Maps.Map with null record; end SPAT.Spark_Files;
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- S Y S T E M . D I M . G E N E R I C _ M K S -- -- -- -- S p e c -- -- -- -- Copyright (C) 2011-2019, 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. -- -- -- ------------------------------------------------------------------------------ -- Defines the MKS dimension system which is the SI system of units -- Some other prefixes of this system are defined in a child package (see -- System.Dim.Generic_Mks.Generic_Other_Prefixes) in order to avoid too many -- constant declarations in this package. -- The dimension terminology is defined in System.Dim package with Ada.Numerics; generic type Float_Type is digits <>; package System.Dim.Generic_Mks is e : constant := Ada.Numerics.e; Pi : constant := Ada.Numerics.Pi; -- Dimensioned type Mks_Type type Mks_Type is new Float_Type with Dimension_System => ( (Unit_Name => Meter, Unit_Symbol => 'm', Dim_Symbol => 'L'), (Unit_Name => Kilogram, Unit_Symbol => "kg", Dim_Symbol => 'M'), (Unit_Name => Second, Unit_Symbol => 's', Dim_Symbol => 'T'), (Unit_Name => Ampere, Unit_Symbol => 'A', Dim_Symbol => 'I'), (Unit_Name => Kelvin, Unit_Symbol => 'K', Dim_Symbol => '@'), (Unit_Name => Mole, Unit_Symbol => "mol", Dim_Symbol => 'N'), (Unit_Name => Candela, Unit_Symbol => "cd", Dim_Symbol => 'J')); -- SI Base dimensioned subtypes subtype Length is Mks_Type with Dimension => (Symbol => 'm', Meter => 1, others => 0); subtype Mass is Mks_Type with Dimension => (Symbol => "kg", Kilogram => 1, others => 0); subtype Time is Mks_Type with Dimension => (Symbol => 's', Second => 1, others => 0); subtype Electric_Current is Mks_Type with Dimension => (Symbol => 'A', Ampere => 1, others => 0); subtype Thermodynamic_Temperature is Mks_Type with Dimension => (Symbol => 'K', Kelvin => 1, others => 0); subtype Amount_Of_Substance is Mks_Type with Dimension => (Symbol => "mol", Mole => 1, others => 0); subtype Luminous_Intensity is Mks_Type with Dimension => (Symbol => "cd", Candela => 1, others => 0); -- Initialize SI Base unit values -- Turn off the all the dimension warnings for these basic assignments -- since otherwise we would get complaints about assigning dimensionless -- values to dimensioned subtypes (we can't assign 1.0*m to m). pragma Warnings (Off, "*assumed to be*"); m : constant Length := 1.0; kg : constant Mass := 1.0; s : constant Time := 1.0; A : constant Electric_Current := 1.0; K : constant Thermodynamic_Temperature := 1.0; mol : constant Amount_Of_Substance := 1.0; cd : constant Luminous_Intensity := 1.0; pragma Warnings (On, "*assumed to be*"); -- SI Derived dimensioned subtypes subtype Absorbed_Dose is Mks_Type with Dimension => (Symbol => "Gy", Meter => 2, Second => -2, others => 0); subtype Angle is Mks_Type with Dimension => (Symbol => "rad", others => 0); subtype Area is Mks_Type with Dimension => ( Meter => 2, others => 0); subtype Catalytic_Activity is Mks_Type with Dimension => (Symbol => "kat", Second => -1, Mole => 1, others => 0); subtype Celsius_Temperature is Mks_Type with Dimension => (Symbol => "°C", Kelvin => 1, others => 0); subtype Electric_Capacitance is Mks_Type with Dimension => (Symbol => 'F', Meter => -2, Kilogram => -1, Second => 4, Ampere => 2, others => 0); subtype Electric_Charge is Mks_Type with Dimension => (Symbol => 'C', Second => 1, Ampere => 1, others => 0); subtype Electric_Conductance is Mks_Type with Dimension => (Symbol => 'S', Meter => -2, Kilogram => -1, Second => 3, Ampere => 2, others => 0); subtype Electric_Potential_Difference is Mks_Type with Dimension => (Symbol => 'V', Meter => 2, Kilogram => 1, Second => -3, Ampere => -1, others => 0); -- Note the type punning below. The Symbol is a single "ohm" character -- encoded in UTF-8 (ce a9 in hexadecimal), but this file is not compiled -- with -gnatW8, so we're treating the string literal as a two-character -- String. subtype Electric_Resistance is Mks_Type with Dimension => (Symbol => "Ω", Meter => 2, Kilogram => 1, Second => -3, Ampere => -2, others => 0); subtype Energy is Mks_Type with Dimension => (Symbol => 'J', Meter => 2, Kilogram => 1, Second => -2, others => 0); subtype Equivalent_Dose is Mks_Type with Dimension => (Symbol => "Sv", Meter => 2, Second => -2, others => 0); subtype Force is Mks_Type with Dimension => (Symbol => 'N', Meter => 1, Kilogram => 1, Second => -2, others => 0); subtype Frequency is Mks_Type with Dimension => (Symbol => "Hz", Second => -1, others => 0); subtype Illuminance is Mks_Type with Dimension => (Symbol => "lx", Meter => -2, Candela => 1, others => 0); subtype Inductance is Mks_Type with Dimension => (Symbol => 'H', Meter => 2, Kilogram => 1, Second => -2, Ampere => -2, others => 0); subtype Luminous_Flux is Mks_Type with Dimension => (Symbol => "lm", Candela => 1, others => 0); subtype Magnetic_Flux is Mks_Type with Dimension => (Symbol => "Wb", Meter => 2, Kilogram => 1, Second => -2, Ampere => -1, others => 0); subtype Magnetic_Flux_Density is Mks_Type with Dimension => (Symbol => 'T', Kilogram => 1, Second => -2, Ampere => -1, others => 0); subtype Power is Mks_Type with Dimension => (Symbol => 'W', Meter => 2, Kilogram => 1, Second => -3, others => 0); subtype Pressure is Mks_Type with Dimension => (Symbol => "Pa", Meter => -1, Kilogram => 1, Second => -2, others => 0); subtype Radioactivity is Mks_Type with Dimension => (Symbol => "Bq", Second => -1, others => 0); subtype Solid_Angle is Mks_Type with Dimension => (Symbol => "sr", others => 0); subtype Speed is Mks_Type with Dimension => ( Meter => 1, Second => -1, others => 0); subtype Volume is Mks_Type with Dimension => ( Meter => 3, others => 0); -- Initialize derived dimension values -- Turn off the all the dimension warnings for these basic assignments -- since otherwise we would get complaints about assigning dimensionless -- values to dimensioned subtypes. pragma Warnings (Off, "*assumed to be*"); rad : constant Angle := 1.0; sr : constant Solid_Angle := 1.0; Hz : constant Frequency := 1.0; N : constant Force := 1.0; Pa : constant Pressure := 1.0; J : constant Energy := 1.0; W : constant Power := 1.0; C : constant Electric_Charge := 1.0; V : constant Electric_Potential_Difference := 1.0; F : constant Electric_Capacitance := 1.0; Ohm : constant Electric_Resistance := 1.0; Si : constant Electric_Conductance := 1.0; Wb : constant Magnetic_Flux := 1.0; T : constant Magnetic_Flux_Density := 1.0; H : constant Inductance := 1.0; dC : constant Celsius_Temperature := 273.15; lm : constant Luminous_Flux := 1.0; lx : constant Illuminance := 1.0; Bq : constant Radioactivity := 1.0; Gy : constant Absorbed_Dose := 1.0; Sv : constant Equivalent_Dose := 1.0; kat : constant Catalytic_Activity := 1.0; -- SI prefixes for Meter um : constant Length := 1.0E-06; -- micro (u) mm : constant Length := 1.0E-03; -- milli cm : constant Length := 1.0E-02; -- centi dm : constant Length := 1.0E-01; -- deci dam : constant Length := 1.0E+01; -- deka hm : constant Length := 1.0E+02; -- hecto km : constant Length := 1.0E+03; -- kilo Mem : constant Length := 1.0E+06; -- mega -- SI prefixes for Kilogram ug : constant Mass := 1.0E-09; -- micro (u) mg : constant Mass := 1.0E-06; -- milli cg : constant Mass := 1.0E-05; -- centi dg : constant Mass := 1.0E-04; -- deci g : constant Mass := 1.0E-03; -- gram dag : constant Mass := 1.0E-02; -- deka hg : constant Mass := 1.0E-01; -- hecto Meg : constant Mass := 1.0E+03; -- mega -- SI prefixes for Second us : constant Time := 1.0E-06; -- micro (u) ms : constant Time := 1.0E-03; -- milli cs : constant Time := 1.0E-02; -- centi ds : constant Time := 1.0E-01; -- deci das : constant Time := 1.0E+01; -- deka hs : constant Time := 1.0E+02; -- hecto ks : constant Time := 1.0E+03; -- kilo Mes : constant Time := 1.0E+06; -- mega -- Other constants for Second min : constant Time := 60.0 * s; hour : constant Time := 60.0 * min; day : constant Time := 24.0 * hour; year : constant Time := 365.25 * day; -- SI prefixes for Ampere mA : constant Electric_Current := 1.0E-03; -- milli cA : constant Electric_Current := 1.0E-02; -- centi dA : constant Electric_Current := 1.0E-01; -- deci daA : constant Electric_Current := 1.0E+01; -- deka hA : constant Electric_Current := 1.0E+02; -- hecto kA : constant Electric_Current := 1.0E+03; -- kilo MeA : constant Electric_Current := 1.0E+06; -- mega pragma Warnings (On, "*assumed to be*"); end System.Dim.Generic_Mks;
-- { dg-do run } with System; use System; with Deferred_Const2_Pkg; use Deferred_Const2_Pkg; procedure Deferred_Const2 is begin if I'Address /= S'Address then raise Program_Error; end if; end;
with Ada.Numerics.Discrete_Random; with Ada.Text_IO; use Ada.Text_IO; procedure Saskas is subtype Rand1_10 is Integer range 1..10; package RandomPos is new Ada.Numerics.Discrete_Random(Rand1_10); seed: RandomPos.Generator; protected Kiiro is entry Kiir(mit: String); end Kiiro; protected body Kiiro is entry Kiir(mit: String) when true is begin Put_Line(mit); end Kiir; end Kiiro; type KertParcella is array(Integer range <>) of Boolean; protected Kert is procedure Ugrik(pos: Integer; elet: in out integer); procedure Permetez(pos: Integer); procedure Felszivodik; private K: KertParcella(1..10) := (1..10 => false); end Kert; protected body Kert is procedure Ugrik(pos: Integer; elet: in out integer) is begin if(K(pos) = true) then elet := elet -1; Kiiro.Kiir("Saska: Meghaltam"); end if; end Ugrik; procedure Permetez(pos: Integer) is begin Felszivodik; K(pos) := true; end Permetez; procedure Felszivodik is begin K := (1..10 => false); end Felszivodik; end Kert; task Saska is end Saska; task body Saska is Pozicio: Integer; Elet: Natural := 1; begin while Elet > 0 loop Pozicio := RandomPos.Random(seed); Kiiro.Kiir("Saska: Ugrok egyet ide: " & Integer'Image(Pozicio)); Kert.Ugrik(Pozicio,Elet); delay 1.0; end loop; end Saska; task Kertesz is end Kertesz; task body Kertesz is PermetPos: Integer; begin while Saska'Callable loop PermetPos := RandomPos.Random(seed); Kiiro.Kiir("Kertesz: Permetezek egyet itt: " & Integer'Image(PermetPos)); Kert.Permetez(PermetPos); delay 1.0; end loop; end Kertesz; begin RandomPos.Reset(seed); end Saskas;
-- Generated at 2016-03-04 22:16:27 +0000 by Natools.Static_Hash_Maps -- from src/simple_webapps-append_servers-maps.sx package Simple_Webapps.Commands.Append_Servers is pragma Pure; type Endpoint_Command is (Endpoint_Error, Data_Path, Force_Separator, Invalid_Log, Key, No_Separator, Redirect, Separator_If_Needed); type Server_Command is (Server_Error, Default_Printer, Endpoints, Static_Path, Template); function To_Endpoint_Command (Key : String) return Endpoint_Command; function To_Server_Command (Key : String) return Server_Command; private Map_1_Key_0 : aliased constant String := "data-path"; Map_1_Key_1 : aliased constant String := "path"; Map_1_Key_2 : aliased constant String := "file"; Map_1_Key_3 : aliased constant String := "file-path"; Map_1_Key_4 : aliased constant String := "force-separator"; Map_1_Key_5 : aliased constant String := "invalid-log"; Map_1_Key_6 : aliased constant String := "key"; Map_1_Key_7 : aliased constant String := "no-separator"; Map_1_Key_8 : aliased constant String := "redirect"; Map_1_Key_9 : aliased constant String := "location"; Map_1_Key_10 : aliased constant String := "separator-if-needed"; Map_1_Keys : constant array (0 .. 10) of access constant String := (Map_1_Key_0'Access, Map_1_Key_1'Access, Map_1_Key_2'Access, Map_1_Key_3'Access, Map_1_Key_4'Access, Map_1_Key_5'Access, Map_1_Key_6'Access, Map_1_Key_7'Access, Map_1_Key_8'Access, Map_1_Key_9'Access, Map_1_Key_10'Access); Map_1_Elements : constant array (0 .. 10) of Endpoint_Command := (Data_Path, Data_Path, Data_Path, Data_Path, Force_Separator, Invalid_Log, Key, No_Separator, Redirect, Redirect, Separator_If_Needed); Map_2_Key_0 : aliased constant String := "default-printer"; Map_2_Key_1 : aliased constant String := "default-pretty-printer"; Map_2_Key_2 : aliased constant String := "pretty-printer"; Map_2_Key_3 : aliased constant String := "endpoints"; Map_2_Key_4 : aliased constant String := "static"; Map_2_Key_5 : aliased constant String := "static-path"; Map_2_Key_6 : aliased constant String := "template"; Map_2_Keys : constant array (0 .. 6) of access constant String := (Map_2_Key_0'Access, Map_2_Key_1'Access, Map_2_Key_2'Access, Map_2_Key_3'Access, Map_2_Key_4'Access, Map_2_Key_5'Access, Map_2_Key_6'Access); Map_2_Elements : constant array (0 .. 6) of Server_Command := (Default_Printer, Default_Printer, Default_Printer, Endpoints, Static_Path, Static_Path, Template); end Simple_Webapps.Commands.Append_Servers;
-------------------------------------------------------------------------------------------------------------------- -- Copyright (c) 2013-2020, Luke A. Guest -- -- This software is provided 'as-is', without any express or implied -- warranty. In no event will the authors be held liable for any damages -- arising from the use of this software. -- -- Permission is granted to anyone to use this software for any purpose, -- including commercial applications, and to alter it and redistribute it -- freely, subject to the following restrictions: -- -- 1. The origin of this software must not be misrepresented; you must not -- claim that you wrote the original software. If you use this software -- in a product, an acknowledgment in the product documentation would be -- appreciated but is not required. -- -- 2. Altered source versions must be plainly marked as such, and must not be -- misrepresented as being the original software. -- -- 3. This notice may not be removed or altered from any source -- distribution. -------------------------------------------------------------------------------------------------------------------- -- Gen_Keyboard -------------------------------------------------------------------------------------------------------------------- -- Generates the SDL.Events.Keyboards.ads file. -- Makefile should call this and redirect the output to the correct file in $TOP/gen_src/sdl-events-keyboards.ads. -------------------------------------------------------------------------------------------------------------------- with Ada.Unchecked_Conversion; with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Characters.Latin_1; with Utils; use Utils; with Scancodes; use Scancodes; procedure Gen_Keyboard is package Latin_1 renames Ada.Characters.Latin_1; function To_US (Str : in String) return Unbounded_String renames To_Unbounded_String; License : constant array (Positive range <>) of Unbounded_String := (To_US ("Copyright (c) 2013-2020, Luke A. Guest"), To_US (""), To_US ("This software is provided 'as-is', without any express or implied"), To_US ("warranty. In no event will the authors be held liable for any damages"), To_US ("arising from the use of this software."), To_US (""), To_US ("Permission is granted to anyone to use this software for any purpose,"), To_US ("including commercial applications, and to alter it and redistribute it"), To_US ("freely, subject to the following restrictions:"), To_US (""), To_US (" 1. The origin of this software must not be misrepresented; you must not"), To_US (" claim that you wrote the original software. If you use this software"), To_US (" in a product, an acknowledgment in the product documentation would be"), To_US (" appreciated but is not required."), To_US (""), To_US (" 2. Altered source versions must be plainly marked as such, and must not be"), To_US (" misrepresented as being the original software."), To_US (""), To_US (" 3. This notice may not be removed or altered from any source"), To_US (" distribution.")); Package_Description : constant array (Positive range <>) of Unbounded_String := (To_US ("SDL.Events.Keyboards"), To_US (""), To_US ("Keyboard specific events.")); type Mapping_States is (Output, New_Line, Comment); package Scan_Codes_IO is new Integer_IO (Scan_Codes); use Scan_Codes_IO; type Scan_Code_Mapping is record State : Mapping_States := Output; Name : Unbounded_String := Null_Unbounded_String; Code : Scan_Codes := Scan_Codes'Last; Comment : Unbounded_String := Null_Unbounded_String; end record; New_Line_Scan_Code : constant Scan_Code_Mapping := (New_Line, Null_Unbounded_String, Scan_Codes'Last, Null_Unbounded_String); type Scan_Code_Tables is array (Positive range <>) of Scan_Code_Mapping; Scan_Code_Table : constant Scan_Code_Tables := ((Output, To_US ("Scan_Code_Unknown"), 0, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_A"), 4, Null_Unbounded_String), (Output, To_US ("Scan_Code_B"), 5, Null_Unbounded_String), (Output, To_US ("Scan_Code_C"), 6, Null_Unbounded_String), (Output, To_US ("Scan_Code_D"), 7, Null_Unbounded_String), (Output, To_US ("Scan_Code_E"), 8, Null_Unbounded_String), (Output, To_US ("Scan_Code_F"), 9, Null_Unbounded_String), (Output, To_US ("Scan_Code_G"), 10, Null_Unbounded_String), (Output, To_US ("Scan_Code_H"), 11, Null_Unbounded_String), (Output, To_US ("Scan_Code_I"), 12, Null_Unbounded_String), (Output, To_US ("Scan_Code_J"), 13, Null_Unbounded_String), (Output, To_US ("Scan_Code_K"), 14, Null_Unbounded_String), (Output, To_US ("Scan_Code_L"), 15, Null_Unbounded_String), (Output, To_US ("Scan_Code_M"), 16, Null_Unbounded_String), (Output, To_US ("Scan_Code_N"), 17, Null_Unbounded_String), (Output, To_US ("Scan_Code_O"), 18, Null_Unbounded_String), (Output, To_US ("Scan_Code_P"), 19, Null_Unbounded_String), (Output, To_US ("Scan_Code_Q"), 20, Null_Unbounded_String), (Output, To_US ("Scan_Code_R"), 21, Null_Unbounded_String), (Output, To_US ("Scan_Code_S"), 22, Null_Unbounded_String), (Output, To_US ("Scan_Code_T"), 23, Null_Unbounded_String), (Output, To_US ("Scan_Code_U"), 24, Null_Unbounded_String), (Output, To_US ("Scan_Code_V"), 25, Null_Unbounded_String), (Output, To_US ("Scan_Code_W"), 26, Null_Unbounded_String), (Output, To_US ("Scan_Code_X"), 27, Null_Unbounded_String), (Output, To_US ("Scan_Code_Y"), 28, Null_Unbounded_String), (Output, To_US ("Scan_Code_Z"), 29, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_1"), 30, Null_Unbounded_String), (Output, To_US ("Scan_Code_2"), 31, Null_Unbounded_String), (Output, To_US ("Scan_Code_3"), 32, Null_Unbounded_String), (Output, To_US ("Scan_Code_4"), 33, Null_Unbounded_String), (Output, To_US ("Scan_Code_5"), 34, Null_Unbounded_String), (Output, To_US ("Scan_Code_6"), 35, Null_Unbounded_String), (Output, To_US ("Scan_Code_7"), 36, Null_Unbounded_String), (Output, To_US ("Scan_Code_8"), 37, Null_Unbounded_String), (Output, To_US ("Scan_Code_9"), 38, Null_Unbounded_String), (Output, To_US ("Scan_Code_0"), 39, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Return"), 40, Null_Unbounded_String), (Output, To_US ("Scan_Code_Escape"), 41, Null_Unbounded_String), (Output, To_US ("Scan_Code_Backspace"), 42, Null_Unbounded_String), (Output, To_US ("Scan_Code_Tab"), 43, Null_Unbounded_String), (Output, To_US ("Scan_Code_Space"), 44, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Minus"), 45, Null_Unbounded_String), (Output, To_US ("Scan_Code_Equals"), 46, Null_Unbounded_String), (Output, To_US ("Scan_Code_Left_Bracket"), 47, Null_Unbounded_String), (Output, To_US ("Scan_Code_Right_Bracket"), 48, Null_Unbounded_String), (Output, To_US ("Scan_Code_Back_Slash"), 49, Null_Unbounded_String), (Output, To_US ("Scan_Code_Non_US_Hash"), 50, Null_Unbounded_String), (Output, To_US ("Scan_Code_Semi_Colon"), 51, Null_Unbounded_String), (Output, To_US ("Scan_Code_Apostrophe"), 52, Null_Unbounded_String), (Output, To_US ("Scan_Code_Grave"), 53, Null_Unbounded_String), (Output, To_US ("Scan_Code_Comma"), 54, Null_Unbounded_String), (Output, To_US ("Scan_Code_Period"), 55, Null_Unbounded_String), (Output, To_US ("Scan_Code_Slash"), 56, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Caps_Lock"), 57, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_F1"), 58, Null_Unbounded_String), (Output, To_US ("Scan_Code_F2"), 59, Null_Unbounded_String), (Output, To_US ("Scan_Code_F3"), 60, Null_Unbounded_String), (Output, To_US ("Scan_Code_F4"), 61, Null_Unbounded_String), (Output, To_US ("Scan_Code_F5"), 62, Null_Unbounded_String), (Output, To_US ("Scan_Code_F6"), 63, Null_Unbounded_String), (Output, To_US ("Scan_Code_F7"), 64, Null_Unbounded_String), (Output, To_US ("Scan_Code_F8"), 65, Null_Unbounded_String), (Output, To_US ("Scan_Code_F9"), 66, Null_Unbounded_String), (Output, To_US ("Scan_Code_F10"), 67, Null_Unbounded_String), (Output, To_US ("Scan_Code_F11"), 68, Null_Unbounded_String), (Output, To_US ("Scan_Code_F12"), 69, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Print_Screen"), 70, Null_Unbounded_String), (Output, To_US ("Scan_Code_Scroll_Lock"), 71, Null_Unbounded_String), (Output, To_US ("Scan_Code_Pause"), 72, Null_Unbounded_String), (Output, To_US ("Scan_Code_Insert"), 73, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Home"), 74, Null_Unbounded_String), (Output, To_US ("Scan_Code_Page_Up"), 75, Null_Unbounded_String), (Output, To_US ("Scan_Code_Delete"), 76, Null_Unbounded_String), (Output, To_US ("Scan_Code_End"), 77, Null_Unbounded_String), (Output, To_US ("Scan_Code_Page_Down"), 78, Null_Unbounded_String), (Output, To_US ("Scan_Code_Right"), 79, Null_Unbounded_String), (Output, To_US ("Scan_Code_Left"), 80, Null_Unbounded_String), (Output, To_US ("Scan_Code_Down"), 81, Null_Unbounded_String), (Output, To_US ("Scan_Code_Up"), 82, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Num_Lock_Clear"), 83, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_KP_Divide"), 84, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Multiply"), 85, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Minus"), 86, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Plus"), 87, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Enter"), 88, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_1"), 89, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_2"), 90, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_3"), 91, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_4"), 92, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_5"), 93, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_6"), 94, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_7"), 95, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_8"), 96, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_9"), 97, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_0"), 98, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Period"), 99, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Non_US_Back_Slash"), 100, Null_Unbounded_String), (Output, To_US ("Scan_Code_Application"), 101, Null_Unbounded_String), (Output, To_US ("Scan_Code_Power"), 102, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Equals"), 103, Null_Unbounded_String), (Output, To_US ("Scan_Code_F13"), 104, Null_Unbounded_String), (Output, To_US ("Scan_Code_F14"), 105, Null_Unbounded_String), (Output, To_US ("Scan_Code_F15"), 106, Null_Unbounded_String), (Output, To_US ("Scan_Code_F16"), 107, Null_Unbounded_String), (Output, To_US ("Scan_Code_F17"), 108, Null_Unbounded_String), (Output, To_US ("Scan_Code_F18"), 109, Null_Unbounded_String), (Output, To_US ("Scan_Code_F19"), 110, Null_Unbounded_String), (Output, To_US ("Scan_Code_F20"), 111, Null_Unbounded_String), (Output, To_US ("Scan_Code_F21"), 112, Null_Unbounded_String), (Output, To_US ("Scan_Code_F22"), 113, Null_Unbounded_String), (Output, To_US ("Scan_Code_F23"), 114, Null_Unbounded_String), (Output, To_US ("Scan_Code_F24"), 115, Null_Unbounded_String), (Output, To_US ("Scan_Code_Execute"), 116, Null_Unbounded_String), (Output, To_US ("Scan_Code_Help"), 117, Null_Unbounded_String), (Output, To_US ("Scan_Code_Menu"), 118, Null_Unbounded_String), (Output, To_US ("Scan_Code_Select"), 119, Null_Unbounded_String), (Output, To_US ("Scan_Code_Stop"), 120, Null_Unbounded_String), (Output, To_US ("Scan_Code_Again"), 121, Null_Unbounded_String), (Output, To_US ("Scan_Code_Undo"), 122, Null_Unbounded_String), (Output, To_US ("Scan_Code_Cut"), 123, Null_Unbounded_String), (Output, To_US ("Scan_Code_Copy"), 124, Null_Unbounded_String), (Output, To_US ("Scan_Code_Paste"), 125, Null_Unbounded_String), (Output, To_US ("Scan_Code_Find"), 126, Null_Unbounded_String), (Output, To_US ("Scan_Code_Mute"), 127, Null_Unbounded_String), (Output, To_US ("Scan_Code_Volume_Up"), 128, Null_Unbounded_String), (Output, To_US ("Scan_Code_Volume_Down"), 129, Null_Unbounded_String), (Comment, Null_Unbounded_String, Scan_Codes'Last, To_US ("Scan_Code_Locking_Caps_Lock : constant Scan_Codes := 130;")), (Comment, Null_Unbounded_String, Scan_Codes'Last, To_US ("Scan_Code_Locking_Num_Lock : constant Scan_Codes := 131;")), (Comment, Null_Unbounded_String, Scan_Codes'Last, To_US ("Scan_Code_Locking_Scroll_Lock : constant Scan_Codes := 132;")), (Output, To_US ("Scan_Code_KP_Comma"), 133, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Equals_AS400"), 134, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_International_1"), 135, To_US ("Used on Asian keyboards.")), (Output, To_US ("Scan_Code_International_2"), 136, Null_Unbounded_String), (Output, To_US ("Scan_Code_International_3"), 137, To_US ("Yen")), (Output, To_US ("Scan_Code_International_4"), 138, Null_Unbounded_String), (Output, To_US ("Scan_Code_International_5"), 139, Null_Unbounded_String), (Output, To_US ("Scan_Code_International_6"), 140, Null_Unbounded_String), (Output, To_US ("Scan_Code_International_7"), 141, Null_Unbounded_String), (Output, To_US ("Scan_Code_International_8"), 142, Null_Unbounded_String), (Output, To_US ("Scan_Code_International_9"), 143, Null_Unbounded_String), (Output, To_US ("Scan_Code_Language_1"), 144, To_US ("Hangul/En")), (Output, To_US ("Scan_Code_Language_2"), 145, To_US ("Hanja con")), (Output, To_US ("Scan_Code_Language_3"), 146, To_US ("Katakana.")), (Output, To_US ("Scan_Code_Language_4"), 147, To_US ("Hiragana.")), (Output, To_US ("Scan_Code_Language_5"), 148, To_US ("Zenkaku/H")), (Output, To_US ("Scan_Code_Language_6"), 149, To_US ("Reserved.")), (Output, To_US ("Scan_Code_Language_7"), 150, To_US ("Reserved.")), (Output, To_US ("Scan_Code_Language_8"), 151, To_US ("Reserved.")), (Output, To_US ("Scan_Code_Language_9"), 152, To_US ("Reserved.")), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Alt_Erase"), 153, To_US ("Erase-ease.")), (Output, To_US ("Scan_Code_Sys_Req"), 154, Null_Unbounded_String), (Output, To_US ("Scan_Code_Cancel"), 155, Null_Unbounded_String), (Output, To_US ("Scan_Code_Clear"), 156, Null_Unbounded_String), (Output, To_US ("Scan_Code_Prior"), 157, Null_Unbounded_String), (Output, To_US ("Scan_Code_Return_2"), 158, Null_Unbounded_String), (Output, To_US ("Scan_Code_Separator"), 159, Null_Unbounded_String), (Output, To_US ("Scan_Code_Out"), 160, Null_Unbounded_String), (Output, To_US ("Scan_Code_Oper"), 161, Null_Unbounded_String), (Output, To_US ("Scan_Code_Clear_Again"), 162, Null_Unbounded_String), (Output, To_US ("Scan_Code_CR_Sel"), 163, Null_Unbounded_String), (Output, To_US ("Scan_Code_EX_Sel"), 164, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_KP_00"), 176, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_000"), 177, Null_Unbounded_String), (Output, To_US ("Scan_Code_Thousands_Separator"), 178, Null_Unbounded_String), (Output, To_US ("Scan_Code_Decimal_Separator"), 179, Null_Unbounded_String), (Output, To_US ("Scan_Code_Currency_Unit"), 180, Null_Unbounded_String), (Output, To_US ("Scan_Code_Currency_Subunit"), 181, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Left_Parenthesis"), 182, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Right_Parentheesis"), 183, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Left_Brace"), 184, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Right_Brace"), 185, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Tab"), 186, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Backspace"), 187, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_A"), 188, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_B"), 189, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_C"), 190, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_D"), 191, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_E"), 192, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_F"), 193, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_XOR"), 194, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Power"), 195, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Percent"), 196, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Less"), 197, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Greater"), 198, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Ampersand"), 199, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Double_Ampersand"), 200, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Vertical_Bar"), 201, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Double_Vertical_Bar"), 202, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Colon"), 203, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Hash"), 204, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Space"), 205, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_At"), 206, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Exclamation"), 207, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Memory_Store"), 208, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Memory_Recall"), 209, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Memory_Clear"), 210, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Memory_Add"), 211, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Memory_Subtract"), 212, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Memory_Multiply"), 213, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Memory_Divide"), 214, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Plus_Minus"), 215, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Clear"), 216, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Clear_Entry"), 217, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Binary"), 218, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Octal"), 219, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Decimal"), 220, Null_Unbounded_String), (Output, To_US ("Scan_Code_KP_Hexadecimal"), 221, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Left_Control"), 224, Null_Unbounded_String), (Output, To_US ("Scan_Code_Left_Shift"), 225, Null_Unbounded_String), (Output, To_US ("Scan_Code_Left_Alt"), 226, To_US ("Alt, option, etc.")), (Output, To_US ("Scan_Code_Left_GUI"), 227, To_US ("Windows, Command (Apple), Meta, etc.")), (Output, To_US ("Scan_Code_Right_Control"), 228, Null_Unbounded_String), (Output, To_US ("Scan_Code_Right_Shift"), 229, Null_Unbounded_String), (Output, To_US ("Scan_Code_Right_Alt"), 230, To_US ("Alt gr, option, etc.")), (Output, To_US ("Scan_Code_Right_GUI"), 231, To_US ("Windows, Command (Apple), Meta, etc.")), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Mode"), 257, Null_Unbounded_String), (New_Line_Scan_Code), (Comment, Null_Unbounded_String, Scan_Codes'Last, To_US ("Usage page in USB document.")), (Output, To_US ("Scan_Code_Audio_Next"), 258, Null_Unbounded_String), (Output, To_US ("Scan_Code_Audio_Previous"), 259, Null_Unbounded_String), (Output, To_US ("Scan_Code_Audio_Stop"), 260, Null_Unbounded_String), (Output, To_US ("Scan_Code_Audio_Play"), 261, Null_Unbounded_String), (Output, To_US ("Scan_Code_Audio_Mute"), 262, Null_Unbounded_String), (Output, To_US ("Scan_Code_Media_Select"), 263, Null_Unbounded_String), (Output, To_US ("Scan_Code_WWW"), 264, Null_Unbounded_String), (Output, To_US ("Scan_Code_Mail"), 265, Null_Unbounded_String), (Output, To_US ("Scan_Code_Calculator"), 266, Null_Unbounded_String), (Output, To_US ("Scan_Code_Computer"), 267, Null_Unbounded_String), (Output, To_US ("Scan_Code_AC_Search"), 268, Null_Unbounded_String), (Output, To_US ("Scan_Code_AC_Home"), 269, Null_Unbounded_String), (Output, To_US ("Scan_Code_AC_Back"), 270, Null_Unbounded_String), (Output, To_US ("Scan_Code_AC_Forward"), 271, Null_Unbounded_String), (Output, To_US ("Scan_Code_AC_Stop"), 272, Null_Unbounded_String), (Output, To_US ("Scan_Code_AC_Refresh"), 273, Null_Unbounded_String), (Output, To_US ("Scan_Code_AC_Bookmarks"), 274, Null_Unbounded_String), (New_Line_Scan_Code), (Comment, Null_Unbounded_String, Scan_Codes'Last, To_US ("Walther keys (for Mac?).")), (Output, To_US ("Scan_Code_Brightness_Up"), 275, Null_Unbounded_String), (Output, To_US ("Scan_Code_Brightness_Down"), 276, Null_Unbounded_String), (Output, To_US ("Scan_Code_Display_Switch"), 277, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Illumination_Toggle"), 278, Null_Unbounded_String), (Output, To_US ("Scan_Code_Illumination_Down"), 279, Null_Unbounded_String), (Output, To_US ("Scan_Code_Illumination_Up"), 280, Null_Unbounded_String), (Output, To_US ("Scan_Code_Eject"), 281, Null_Unbounded_String), (Output, To_US ("Scan_Code_Sleep"), 282, Null_Unbounded_String), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Application_1"), 283, Null_Unbounded_String), (Output, To_US ("Scan_Code_Application_2"), 284, Null_Unbounded_String), (New_Line_Scan_Code), (Comment, Null_Unbounded_String, Scan_Codes'Last, To_US ("All other scan codes go here.")), (New_Line_Scan_Code), (Output, To_US ("Scan_Code_Total"), 512, Null_Unbounded_String)); type Key_Codes is mod 2 ** 32 with Convention => C, Size => 32; Internal_To_Key_Code_Mask : constant Key_Codes := 16#2000_0000#; package Key_Codes_IO is new Modular_IO (Key_Codes); use Key_Codes_IO; function Convert is new Ada.Unchecked_Conversion (Source => Scan_Codes, Target => Key_Codes); function To_Key_Code (Code : in Scan_Codes) return Key_Codes is (Internal_To_Key_Code_Mask or Convert (Code)); type Key_Code_Mapping is record State : Mapping_States := Output; Name : Unbounded_String := Null_Unbounded_String; Code : Key_Codes := Key_Codes'Last; end record; New_Line_Code : constant Key_Code_Mapping := (New_Line, Null_Unbounded_String, Key_Codes'Last); type Key_Code_Tables is array (Positive range <>) of Key_Code_Mapping; Key_Code_Table : constant Key_Code_Tables := ((Output, To_US ("Code_Return"), Character'Pos (Latin_1.CR)), (Output, To_US ("Code_Escape"), Character'Pos (Latin_1.ESC)), (Output, To_US ("Code_Backspace"), Character'Pos (Latin_1.BS)), (Output, To_US ("Code_Tab"), Character'Pos (Latin_1.HT)), (Output, To_US ("Code_Space"), Character'Pos (Latin_1.Space)), (Output, To_US ("Code_Exclamation"), Character'Pos (Latin_1.Exclamation)), (Output, To_US ("Code_Double_Quote"), Character'Pos (Latin_1.Quotation)), (Output, To_US ("Code_Hash"), Character'Pos (Latin_1.Number_Sign)), (Output, To_US ("Code_Percent"), Character'Pos (Latin_1.Percent_Sign)), (Output, To_US ("Code_Dollar"), Character'Pos (Latin_1.Dollar_Sign)), (Output, To_US ("Code_Ampersand"), Character'Pos (Latin_1.Ampersand)), (Output, To_US ("Code_Quote"), Character'Pos (Latin_1.Apostrophe)), (Output, To_US ("Code_Left_Parenthesis"), Character'Pos (Latin_1.Left_Parenthesis)), (Output, To_US ("Code_Right_Parenthesis"), Character'Pos (Latin_1.Right_Parenthesis)), (Output, To_US ("Code_Asterisk"), Character'Pos (Latin_1.Asterisk)), (Output, To_US ("Code_Plus"), Character'Pos (Latin_1.Plus_Sign)), (Output, To_US ("Code_Comma"), Character'Pos (Latin_1.Comma)), (Output, To_US ("Code_Minus"), Character'Pos (Latin_1.Minus_Sign)), (Output, To_US ("Code_Period"), Character'Pos (Latin_1.Full_Stop)), (Output, To_US ("Code_Slash"), Character'Pos (Latin_1.Solidus)), (Output, To_US ("Code_0"), Character'Pos ('0')), (Output, To_US ("Code_1"), Character'Pos ('1')), (Output, To_US ("Code_2"), Character'Pos ('2')), (Output, To_US ("Code_3"), Character'Pos ('3')), (Output, To_US ("Code_4"), Character'Pos ('4')), (Output, To_US ("Code_5"), Character'Pos ('5')), (Output, To_US ("Code_6"), Character'Pos ('6')), (Output, To_US ("Code_7"), Character'Pos ('7')), (Output, To_US ("Code_8"), Character'Pos ('8')), (Output, To_US ("Code_9"), Character'Pos ('9')), (Output, To_US ("Code_Colon"), Character'Pos (Latin_1.Colon)), (Output, To_US ("Code_Semi_Colon"), Character'Pos (Latin_1.Semicolon)), (Output, To_US ("Code_Less"), Character'Pos (Latin_1.Less_Than_Sign)), (Output, To_US ("Code_Equals"), Character'Pos (Latin_1.Equals_Sign)), (Output, To_US ("Code_Greater"), Character'Pos (Latin_1.Greater_Than_Sign)), (Output, To_US ("Code_Question"), Character'Pos (Latin_1.Question)), (Output, To_US ("Code_At"), Character'Pos (Latin_1.Commercial_At)), (New_Line_Code), (Comment, To_US ("Skip the uppercase letters."), Key_Codes'Last), (New_Line_Code), (Output, To_US ("Code_Left_Bracket"), Character'Pos (Latin_1.Left_Square_Bracket)), (Output, To_US ("Code_Back_Slash"), Character'Pos (Latin_1.Reverse_Solidus)), (Output, To_US ("Code_Right_Bracket"), Character'Pos (Latin_1.Right_Square_Bracket)), (Output, To_US ("Code_Caret"), Character'Pos (Latin_1.Circumflex)), (Output, To_US ("Code_Underscore"), Character'Pos (Latin_1.Low_Line)), (Output, To_US ("Code_Back_Quote"), Character'Pos (Latin_1.Grave)), (Output, To_US ("Code_A"), Character'Pos ('a')), (Output, To_US ("Code_B"), Character'Pos ('b')), (Output, To_US ("Code_C"), Character'Pos ('c')), (Output, To_US ("Code_D"), Character'Pos ('d')), (Output, To_US ("Code_E"), Character'Pos ('e')), (Output, To_US ("Code_F"), Character'Pos ('f')), (Output, To_US ("Code_G"), Character'Pos ('g')), (Output, To_US ("Code_H"), Character'Pos ('h')), (Output, To_US ("Code_I"), Character'Pos ('i')), (Output, To_US ("Code_J"), Character'Pos ('j')), (Output, To_US ("Code_K"), Character'Pos ('k')), (Output, To_US ("Code_L"), Character'Pos ('l')), (Output, To_US ("Code_M"), Character'Pos ('m')), (Output, To_US ("Code_N"), Character'Pos ('n')), (Output, To_US ("Code_O"), Character'Pos ('o')), (Output, To_US ("Code_P"), Character'Pos ('p')), (Output, To_US ("Code_Q"), Character'Pos ('q')), (Output, To_US ("Code_R"), Character'Pos ('r')), (Output, To_US ("Code_S"), Character'Pos ('s')), (Output, To_US ("Code_T"), Character'Pos ('t')), (Output, To_US ("Code_U"), Character'Pos ('u')), (Output, To_US ("Code_V"), Character'Pos ('v')), (Output, To_US ("Code_W"), Character'Pos ('w')), (Output, To_US ("Code_X"), Character'Pos ('x')), (Output, To_US ("Code_Y"), Character'Pos ('y')), (Output, To_US ("Code_Z"), Character'Pos ('z')), (New_Line_Code), (Output, To_US ("Code_Caps_Lock"), To_Key_Code (Scan_Code_Caps_Lock)), (Output, To_US ("Code_F1"), To_Key_Code (Scan_Code_F1)), (Output, To_US ("Code_F2"), To_Key_Code (Scan_Code_F2)), (Output, To_US ("Code_F3"), To_Key_Code (Scan_Code_F3)), (Output, To_US ("Code_F4"), To_Key_Code (Scan_Code_F4)), (Output, To_US ("Code_F5"), To_Key_Code (Scan_Code_F5)), (Output, To_US ("Code_F6"), To_Key_Code (Scan_Code_F6)), (Output, To_US ("Code_F7"), To_Key_Code (Scan_Code_F7)), (Output, To_US ("Code_F8"), To_Key_Code (Scan_Code_F8)), (Output, To_US ("Code_F9"), To_Key_Code (Scan_Code_F9)), (Output, To_US ("Code_F10"), To_Key_Code (Scan_Code_F10)), (Output, To_US ("Code_F11"), To_Key_Code (Scan_Code_F11)), (Output, To_US ("Code_F12"), To_Key_Code (Scan_Code_F12)), (New_Line_Code), (Output, To_US ("Code_Print_Screen"), To_Key_Code (Scan_Code_Print_Screen)), (Output, To_US ("Code_Scroll_Lock"), To_Key_Code (Scan_Code_Scroll_Lock)), (Output, To_US ("Code_Pause"), To_Key_Code (Scan_Code_Pause)), (Output, To_US ("Code_Insert"), To_Key_Code (Scan_Code_Insert)), (Output, To_US ("Code_Home"), To_Key_Code (Scan_Code_Home)), (Output, To_US ("Code_Page_Up"), To_Key_Code (Scan_Code_Page_Up)), (Output, To_US ("Code_Delete"), Character'Pos (Latin_1.DEL)), (Output, To_US ("Code_End"), To_Key_Code (Scan_Code_End)), (Output, To_US ("Code_Page_Down"), To_Key_Code (Scan_Code_Page_Down)), (Output, To_US ("Code_Right"), To_Key_Code (Scan_Code_Right)), (Output, To_US ("Code_Left"), To_Key_Code (Scan_Code_Left)), (Output, To_US ("Code_Down"), To_Key_Code (Scan_Code_Down)), (Output, To_US ("Code_Up"), To_Key_Code (Scan_Code_Up)), (New_Line_Code), (Output, To_US ("Code_Num_Lock_Clear"), To_Key_Code (Scan_Code_Num_Lock_Clear)), (Output, To_US ("Code_KP_Divide"), To_Key_Code (Scan_Code_KP_Divide)), (Output, To_US ("Code_KP_Multiply"), To_Key_Code (Scan_Code_KP_Multiply)), (Output, To_US ("Code_KP_Minus"), To_Key_Code (Scan_Code_KP_Minus)), (Output, To_US ("Code_KP_Plus"), To_Key_Code (Scan_Code_KP_Plus)), (Output, To_US ("Code_KP_Enter"), To_Key_Code (Scan_Code_KP_Enter)), (Output, To_US ("Code_KP_1"), To_Key_Code (Scan_Code_KP_1)), (Output, To_US ("Code_KP_2"), To_Key_Code (Scan_Code_KP_2)), (Output, To_US ("Code_KP_3"), To_Key_Code (Scan_Code_KP_3)), (Output, To_US ("Code_KP_4"), To_Key_Code (Scan_Code_KP_4)), (Output, To_US ("Code_KP_5"), To_Key_Code (Scan_Code_KP_5)), (Output, To_US ("Code_KP_6"), To_Key_Code (Scan_Code_KP_6)), (Output, To_US ("Code_KP_7"), To_Key_Code (Scan_Code_KP_7)), (Output, To_US ("Code_KP_8"), To_Key_Code (Scan_Code_KP_8)), (Output, To_US ("Code_KP_9"), To_Key_Code (Scan_Code_KP_9)), (Output, To_US ("Code_KP_0"), To_Key_Code (Scan_Code_KP_0)), (Output, To_US ("Code_KP_Period"), To_Key_Code (Scan_Code_KP_Period)), (New_Line_Code), (Output, To_US ("Code_Application"), To_Key_Code (Scan_Code_Application)), (Output, To_US ("Code_Power"), To_Key_Code (Scan_Code_Power)), (Output, To_US ("Code_KP_Equals"), To_Key_Code (Scan_Code_KP_Equals)), (Output, To_US ("Code_F13"), To_Key_Code (Scan_Code_F13)), (Output, To_US ("Code_F14"), To_Key_Code (Scan_Code_F14)), (Output, To_US ("Code_F15"), To_Key_Code (Scan_Code_F15)), (Output, To_US ("Code_F16"), To_Key_Code (Scan_Code_F16)), (Output, To_US ("Code_F17"), To_Key_Code (Scan_Code_F17)), (Output, To_US ("Code_F18"), To_Key_Code (Scan_Code_F18)), (Output, To_US ("Code_F19"), To_Key_Code (Scan_Code_F19)), (Output, To_US ("Code_F20"), To_Key_Code (Scan_Code_F20)), (Output, To_US ("Code_F21"), To_Key_Code (Scan_Code_F21)), (Output, To_US ("Code_F22"), To_Key_Code (Scan_Code_F22)), (Output, To_US ("Code_F23"), To_Key_Code (Scan_Code_F23)), (Output, To_US ("Code_F24"), To_Key_Code (Scan_Code_F24)), (Output, To_US ("Code_Execute"), To_Key_Code (Scan_Code_Execute)), (Output, To_US ("Code_Help"), To_Key_Code (Scan_Code_Help)), (Output, To_US ("Code_Menu"), To_Key_Code (Scan_Code_Menu)), (Output, To_US ("Code_Select"), To_Key_Code (Scan_Code_Select)), (Output, To_US ("Code_Stop"), To_Key_Code (Scan_Code_Stop)), (Output, To_US ("Code_Again"), To_Key_Code (Scan_Code_Again)), (Output, To_US ("Code_Undo"), To_Key_Code (Scan_Code_Undo)), (Output, To_US ("Code_Cut"), To_Key_Code (Scan_Code_Cut)), (Output, To_US ("Code_Copy"), To_Key_Code (Scan_Code_Copy)), (Output, To_US ("Code_Paste"), To_Key_Code (Scan_Code_Paste)), (Output, To_US ("Code_Find"), To_Key_Code (Scan_Code_Find)), (Output, To_US ("Code_Mute"), To_Key_Code (Scan_Code_Mute)), (Output, To_US ("Code_Volume_Up"), To_Key_Code (Scan_Code_Volume_Up)), (Output, To_US ("Code_Volume_Down"), To_Key_Code (Scan_Code_Volume_Down)), (Output, To_US ("Code_KP_Comma"), To_Key_Code (Scan_Code_KP_Comma)), (Output, To_US ("Code_KP_Equals_AS400"), To_Key_Code (Scan_Code_KP_Equals_AS400)), (New_Line_Code), (Output, To_US ("Code_Alt_Erase"), To_Key_Code (Scan_Code_Alt_Erase)), (Output, To_US ("Code_Sys_Req"), To_Key_Code (Scan_Code_Sys_Req)), (Output, To_US ("Code_Cancel"), To_Key_Code (Scan_Code_Cancel)), (Output, To_US ("Code_Clear"), To_Key_Code (Scan_Code_Clear)), (Output, To_US ("Code_Prior"), To_Key_Code (Scan_Code_Prior)), (Output, To_US ("Code_Return_2"), To_Key_Code (Scan_Code_Return_2)), (Output, To_US ("Code_Separator"), To_Key_Code (Scan_Code_Separator)), (Output, To_US ("Code_Out"), To_Key_Code (Scan_Code_Out)), (Output, To_US ("Code_Oper"), To_Key_Code (Scan_Code_Oper)), (Output, To_US ("Code_Clear_Again"), To_Key_Code (Scan_Code_Clear_Again)), (Output, To_US ("Code_CR_Sel"), To_Key_Code (Scan_Code_CR_Sel)), (Output, To_US ("Code_Ex_Sel"), To_Key_Code (Scan_Code_EX_Sel)), (New_Line_Code), (Output, To_US ("Code_KP_00"), To_Key_Code (Scan_Code_KP_00)), (Output, To_US ("Code_KP_000"), To_Key_Code (Scan_Code_KP_000)), (Output, To_US ("Code_Thousands_Separator"), To_Key_Code (Scan_Code_Thousands_Separator)), (Output, To_US ("Code_Decimal_Separator"), To_Key_Code (Scan_Code_Decimal_Separator)), (Output, To_US ("Code_Currency_Unit"), To_Key_Code (Scan_Code_Currency_Unit)), (Output, To_US ("Code_Currency_Subunit"), To_Key_Code (Scan_Code_Currency_Subunit)), (Output, To_US ("Code_KP_Left_Parenthesis"), To_Key_Code (Scan_Code_KP_Left_Parenthesis)), (Output, To_US ("Code_KP_Right_Parentheesis"), To_Key_Code (Scan_Code_KP_Right_Parentheesis)), (Output, To_US ("Code_KP_Left_Brace"), To_Key_Code (Scan_Code_KP_Left_Brace)), (Output, To_US ("Code_KP_Right_Brace"), To_Key_Code (Scan_Code_KP_Right_Brace)), (Output, To_US ("Code_KP_Tab"), To_Key_Code (Scan_Code_KP_Tab)), (Output, To_US ("Code_KP_Backspace"), To_Key_Code (Scan_Code_KP_Backspace)), (Output, To_US ("Code_KP_A"), To_Key_Code (Scan_Code_KP_A)), (Output, To_US ("Code_KP_B"), To_Key_Code (Scan_Code_KP_B)), (Output, To_US ("Code_KP_C"), To_Key_Code (Scan_Code_KP_C)), (Output, To_US ("Code_KP_D"), To_Key_Code (Scan_Code_KP_D)), (Output, To_US ("Code_KP_E"), To_Key_Code (Scan_Code_KP_E)), (Output, To_US ("Code_KP_F"), To_Key_Code (Scan_Code_KP_F)), (Output, To_US ("Code_KP_XOR"), To_Key_Code (Scan_Code_KP_XOR)), (Output, To_US ("Code_KP_Power"), To_Key_Code (Scan_Code_KP_Power)), (Output, To_US ("Code_KP_Percent"), To_Key_Code (Scan_Code_KP_Percent)), (Output, To_US ("Code_KP_Less"), To_Key_Code (Scan_Code_KP_Less)), (Output, To_US ("Code_KP_Greater"), To_Key_Code (Scan_Code_KP_Greater)), (Output, To_US ("Code_KP_Ampersand"), To_Key_Code (Scan_Code_KP_Ampersand)), (Output, To_US ("Code_KP_Double_Ampersand"), To_Key_Code (Scan_Code_KP_Double_Ampersand)), (Output, To_US ("Code_KP_Vertical_Bar"), To_Key_Code (Scan_Code_KP_Vertical_Bar)), (Output, To_US ("Code_KP_Double_Vertical_Bar"), To_Key_Code (Scan_Code_KP_Double_Vertical_Bar)), (Output, To_US ("Code_KP_Colon"), To_Key_Code (Scan_Code_KP_Colon)), (Output, To_US ("Code_KP_Hash"), To_Key_Code (Scan_Code_KP_Hash)), (Output, To_US ("Code_KP_Space"), To_Key_Code (Scan_Code_KP_Space)), (Output, To_US ("Code_KP_At"), To_Key_Code (Scan_Code_KP_At)), (Output, To_US ("Code_KP_Exclamation"), To_Key_Code (Scan_Code_KP_Exclamation)), (Output, To_US ("Code_KP_Memory_Store"), To_Key_Code (Scan_Code_KP_Memory_Store)), (Output, To_US ("Code_KP_Memory_Recall"), To_Key_Code (Scan_Code_KP_Memory_Recall)), (Output, To_US ("Code_KP_Memory_Clear"), To_Key_Code (Scan_Code_KP_Memory_Clear)), (Output, To_US ("Code_KP_Memory_Add"), To_Key_Code (Scan_Code_KP_Memory_Add)), (Output, To_US ("Code_KP_Memory_Subtract"), To_Key_Code (Scan_Code_KP_Memory_Subtract)), (Output, To_US ("Code_KP_Memory_Multiply"), To_Key_Code (Scan_Code_KP_Memory_Multiply)), (Output, To_US ("Code_KP_Memory_Divide"), To_Key_Code (Scan_Code_KP_Memory_Divide)), (Output, To_US ("Code_KP_Plus_Minus"), To_Key_Code (Scan_Code_KP_Plus_Minus)), (Output, To_US ("Code_KP_Clear"), To_Key_Code (Scan_Code_KP_Clear)), (Output, To_US ("Code_KP_Clear_Entry"), To_Key_Code (Scan_Code_KP_Clear_Entry)), (Output, To_US ("Code_KP_Binary"), To_Key_Code (Scan_Code_KP_Binary)), (Output, To_US ("Code_KP_Octal"), To_Key_Code (Scan_Code_KP_Octal)), (Output, To_US ("Code_KP_Decimal"), To_Key_Code (Scan_Code_KP_Decimal)), (Output, To_US ("Code_KP_Hexadecimal"), To_Key_Code (Scan_Code_KP_Hexadecimal)), (New_Line_Code), (Output, To_US ("Code_Left_Control"), To_Key_Code (Scan_Code_Left_Control)), (Output, To_US ("Code_Left_Shift"), To_Key_Code (Scan_Code_Left_Shift)), (Output, To_US ("Code_Left_Alt"), To_Key_Code (Scan_Code_Left_Alt)), (Output, To_US ("Code_Left_GUI"), To_Key_Code (Scan_Code_Left_GUI)), (Output, To_US ("Code_Right_Control"), To_Key_Code (Scan_Code_Right_Control)), (Output, To_US ("Code_Right_Shift"), To_Key_Code (Scan_Code_Right_Shift)), (Output, To_US ("Code_Right_Alt"), To_Key_Code (Scan_Code_Right_Alt)), (Output, To_US ("Code_Right_GUI"), To_Key_Code (Scan_Code_Right_GUI)), (New_Line_Code), (Output, To_US ("Code_Mode"), To_Key_Code (Scan_Code_Mode)), (New_Line_Code), (Output, To_US ("Code_Audio_Next"), To_Key_Code (Scan_Code_Audio_Next)), (Output, To_US ("Code_Audio_Previous"), To_Key_Code (Scan_Code_Audio_Previous)), (Output, To_US ("Code_Audio_Stop"), To_Key_Code (Scan_Code_Audio_Stop)), (Output, To_US ("Code_Audio_Play"), To_Key_Code (Scan_Code_Audio_Play)), (Output, To_US ("Code_Audio_Mute"), To_Key_Code (Scan_Code_Audio_Mute)), (Output, To_US ("Code_Media_Select"), To_Key_Code (Scan_Code_Media_Select)), (Output, To_US ("Code_WWW"), To_Key_Code (Scan_Code_WWW)), (Output, To_US ("Code_Mail"), To_Key_Code (Scan_Code_Mail)), (Output, To_US ("Code_Calculator"), To_Key_Code (Scan_Code_Calculator)), (Output, To_US ("Code_Computer"), To_Key_Code (Scan_Code_Computer)), (Output, To_US ("Code_AC_Search"), To_Key_Code (Scan_Code_AC_Search)), (Output, To_US ("Code_AC_Home"), To_Key_Code (Scan_Code_AC_Home)), (Output, To_US ("Code_AC_Back"), To_Key_Code (Scan_Code_AC_Back)), (Output, To_US ("Code_AC_Forward"), To_Key_Code (Scan_Code_AC_Forward)), (Output, To_US ("Code_AC_Stop"), To_Key_Code (Scan_Code_AC_Stop)), (Output, To_US ("Code_AC_Refresh"), To_Key_Code (Scan_Code_AC_Refresh)), (Output, To_US ("Code_AC_Bookmarks"), To_Key_Code (Scan_Code_AC_Bookmarks)), (New_Line_Code), (Output, To_US ("Code_Brightness_Down"), To_Key_Code (Scan_Code_Brightness_Down)), (Output, To_US ("Code_Brightness_Up"), To_Key_Code (Scan_Code_Brightness_Up)), (Output, To_US ("Code_Display_Switch"), To_Key_Code (Scan_Code_Display_Switch)), (Output, To_US ("Code_Illumination_Toggle"), To_Key_Code (Scan_Code_Illumination_Toggle)), (Output, To_US ("Code_Illumination_Down"), To_Key_Code (Scan_Code_Illumination_Down)), (Output, To_US ("Code_Illumination_Up"), To_Key_Code (Scan_Code_Illumination_Up)), (Output, To_US ("Code_Eject"), To_Key_Code (Scan_Code_Eject)), (Output, To_US ("Code_Sleep"), To_Key_Code (Scan_Code_Sleep))); begin Comment (Indent => 0, Text => "Automatically generated, do not edit."); Comment_Dash (117); for Line of License loop Comment (Indent => 0, Text => To_String (Line)); end loop; Comment_Dash (117); for Line of Package_Description loop Comment (Indent => 0, Text => To_String (Line)); end loop; Comment_Dash (117); Put_Line ("package SDL.Events.Keyboards is"); Put_Line (" -- Keyboard events."); Put_Line (" Key_Down : constant Event_Types := 16#0000_0300#;"); Put_Line (" Key_Up : constant Event_Types := Key_Down + 1;"); Put_Line (" Text_Editing : constant Event_Types := Key_Down + 2;"); Put_Line (" Text_Input : constant Event_Types := Key_Down + 3;"); New_Line; -- Output the scan codes. Comment_Dash (Total => 114, Indent => 3); Put_Line (" -- Scan codes."); Comment_Dash (Total => 114, Indent => 3); Put_Line (" type Scan_Codes is range 0 .. 512 with"); Put_Line (" Convention => C,"); Put_Line (" Size => 32;"); New_Line; for Code of Scan_Code_Table loop case Code.State is when Output => Output_Field (Text => To_String (Code.Name), Width => 33, Indent => 3); Put (": constant Scan_Codes := "); Put (Code.Code, Width => 0); Put (Latin_1.Semicolon); if Code.Comment /= Null_Unbounded_String then Put (" -- " & To_String (Code.Comment)); end if; New_Line; when New_Line => New_Line; when Comment => Comment (Indent => 3, Text => To_String (Code.Comment)); end case; end loop; New_Line; Put_Line (" function Value (Name : in String) return SDL.Events.Keyboards.Scan_Codes with"); Put_Line (" Inline => True;"); New_Line; Put_Line (" function Image (Scan_Code : in SDL.Events.Keyboards.Scan_Codes) return String with"); Put_Line (" Inline => True;"); New_Line; Comment_Dash (Total => 114, Indent => 3); Comment (Indent => 3, Text => "Key codes."); Comment_Dash (Total => 114, Indent => 3); Put_Line (" type Key_Codes is mod 2 ** 32 with"); Put_Line (" Convention => C,"); Put_Line (" Size => 32;"); New_Line; for Code of Key_Code_Table loop case Code.State is when Output => Output_Field (Text => To_String (Code.Name), Width => 33, Indent => 3); Put (": constant Key_Codes := "); Put (Code.Code, Width => 12, Base => 16); Put (Latin_1.Semicolon); New_Line; when New_Line => New_Line; when Comment => Comment (Indent => 3, Text => To_String (Code.Name)); end case; end loop; New_Line; Put_Line (" function Value (Name : in String) return SDL.Events.Keyboards.Key_Codes with"); Put_Line (" Inline => True;"); New_Line; Put_Line (" function Image (Key_Code : in SDL.Events.Keyboards.Key_Codes) return String with"); Put_Line (" Inline => True;"); New_Line; Put_Line (" function To_Key_Code (Scan_Code : in SDL.Events.Keyboards.Scan_Codes) return " & "SDL.Events.Keyboards.Key_Codes with"); Put_Line (" Inline => True;"); New_Line; Put_Line (" function To_Scan_Code (Key_Code : in SDL.Events.Keyboards.Key_Codes) return " & "SDL.Events.Keyboards.Scan_Codes with"); Put_Line (" Inline => True;"); New_Line; Comment_Dash (Total => 114, Indent => 3); Comment (Indent => 3, Text => "Key modifiers."); Comment_Dash (Total => 114, Indent => 3); Put_Line (" type Key_Modifiers is mod 2 ** 16 with"); Put_Line (" Convention => C,"); Put_Line (" Size => 16;"); New_Line; Put_Line (" Modifier_None : constant Key_Modifiers := 16#00_00#;"); Put_Line (" Modifier_Left_Shift : constant Key_Modifiers := 16#00_01#;"); Put_Line (" Modifier_Right_Shift : constant Key_Modifiers := 16#00_02#;"); Put_Line (" Modifier_Left_Control : constant Key_Modifiers := 16#00_40#;"); Put_Line (" Modifier_Right_Control : constant Key_Modifiers := 16#00_80#;"); Put_Line (" Modifier_Left_Alt : constant Key_Modifiers := 16#01_00#;"); Put_Line (" Modifier_Right_Alt : constant Key_Modifiers := 16#02_00#;"); Put_Line (" Modifier_Left_GUI : constant Key_Modifiers := 16#04_00#;"); Put_Line (" Modifier_Right_GUI : constant Key_Modifiers := 16#08_00#;"); Put_Line (" Modifier_Num : constant Key_Modifiers := 16#10_00#;"); Put_Line (" Modifier_Caps : constant Key_Modifiers := 16#20_00#;"); Put_Line (" Modifier_Mode : constant Key_Modifiers := 16#40_00#;"); Put_Line (" Modifier_Control : constant Key_Modifiers := Modifier_Left_Control or Modifier_Right_Control;"); Put_Line (" Modifier_Shift : constant Key_Modifiers := Modifier_Left_Shift or Modifier_Right_Shift;"); Put_Line (" Modifier_Alt : constant Key_Modifiers := Modifier_Left_Alt or Modifier_Right_Alt;"); Put_Line (" Modifier_GUI : constant Key_Modifiers := Modifier_Left_GUI or Modifier_Right_GUI;"); Put_Line (" Modifier_Reserved : constant Key_Modifiers := 16#80_00#;"); New_Line; Put_Line (" type Key_Syms is"); Put_Line (" record"); Put_Line (" Scan_Code : Scan_Codes;"); Put_Line (" Key_Code : Key_Codes;"); Put_Line (" Modifiers : Key_Modifiers;"); Put_Line (" Unused : Interfaces.Unsigned_32;"); Put_Line (" end record with"); Put_Line (" Convention => C;"); New_Line; Put_Line (" type Keyboard_Events is"); Put_Line (" record"); Put_Line (" Event_Type : Event_Types; -- Will be set to Key_Up/Down."); Put_Line (" Time_Stamp : Time_Stamps;"); New_Line; Put_Line (" ID : SDL.Video.Windows.ID;"); Put_Line (" State : Button_State;"); Put_Line (" Repeat : Interfaces.Unsigned_8;"); Put_Line (" Padding_2 : Padding_8;"); Put_Line (" Padding_3 : Padding_8;"); Put_Line (" Key_Sym : Key_Syms;"); Put_Line (" end record with"); Put_Line (" Convention => C;"); New_Line; Comment_Dash (Total => 114, Indent => 3); Comment (Indent => 3, Text => "Text editing events."); Comment_Dash (Total => 114, Indent => 3); Put_Line (" Max_UTF8_Elements : constant := 31;"); Put_Line (" Max_UTF8_Element_Storage_Bits : constant := ((Max_UTF8_Elements + 1) * 8) - 1;"); New_Line; Put_Line (" subtype UTF8_Text_Buffers is Interfaces.C.char_array (0 .. Max_UTF8_Elements);"); New_Line; Put_Line (" type Cursor_Positions is range -2 ** 31 .. 2 ** 31 - 1 with"); Put_Line (" Convention => C,"); Put_Line (" Size => 32;"); New_Line; Put_Line (" type Text_Lengths is range -2 ** 31 .. 2 ** 31 - 1 with"); Put_Line (" Convention => C,"); Put_Line (" Size => 32;"); New_Line; Put_Line (" type Text_Editing_Events is"); Put_Line (" record"); Put_Line (" Event_Type : Event_Types; -- Will be set to Text_Editing."); Put_Line (" Time_Stamp : Time_Stamps;"); New_Line; Put_Line (" ID : SDL.Video.Windows.ID;"); Put_Line (" Text : UTF8_Text_Buffers;"); Put_Line (" Start : Cursor_Positions; -- TODO: Find out why this needs to be a signed value!"); Put_Line (" Length : Text_Lengths; -- TODO: Again, signed, why?"); Put_Line (" end record with"); Put_Line (" Convention => C;"); New_Line; Comment_Dash (Total => 114, Indent => 3); Comment (Indent => 3, Text => "Text input events."); Comment_Dash (Total => 114, Indent => 3); Put_Line (" type Text_Input_Events is"); Put_Line (" record"); Put_Line (" Event_Type : Event_Types; -- Will be set to Text_Editing."); Put_Line (" Time_Stamp : Time_Stamps;"); New_Line; Put_Line (" ID : SDL.Video.Windows.ID;"); Put_Line (" Text : UTF8_Text_Buffers;"); Put_Line (" end record with"); Put_Line (" Convention => C;"); New_Line; Put_Line ("private"); Put_Line (" for Key_Syms use"); Put_Line (" record"); Put_Line (" Scan_Code at 0 * SDL.Word range 0 .. 31;"); Put_Line (" Key_Code at 1 * SDL.Word range 0 .. 31;"); Put_Line (" Modifiers at 2 * SDL.Word range 0 .. 15;"); Put_Line (" Unused at 3 * SDL.Word range 0 .. 31;"); Put_Line (" end record;"); New_Line; Put_Line (" for Keyboard_Events use"); Put_Line (" record"); Put_Line (" Event_Type at 0 * SDL.Word range 0 .. 31;"); Put_Line (" Time_Stamp at 1 * SDL.Word range 0 .. 31;"); New_Line; Put_Line (" ID at 2 * SDL.Word range 0 .. 31;"); Put_Line (" State at 3 * SDL.Word range 0 .. 7;"); Put_Line (" Repeat at 3 * SDL.Word range 8 .. 15;"); Put_Line (" Padding_2 at 3 * SDL.Word range 16 .. 23;"); Put_Line (" Padding_3 at 3 * SDL.Word range 24 .. 31;"); Put_Line (" end record;"); New_Line; Put_Line (" for Text_Editing_Events use"); Put_Line (" record"); Put_Line (" Event_Type at 0 * SDL.Word range 0 .. 31;"); Put_Line (" Time_Stamp at 1 * SDL.Word range 0 .. 31;"); New_Line; Put_Line (" ID at 2 * SDL.Word range 0 .. 31;"); Put_Line (" Text at 3 * SDL.Word range 0 .. Max_UTF8_Element_Storage_Bits; -- 31 characters."); Put_Line (" Start at 11 * SDL.Word range 0 .. 31;"); Put_Line (" Length at 12 * SDL.Word range 0 .. 31;"); Put_Line (" end record;"); New_Line; Put_Line (" for Text_Input_Events use"); Put_Line (" record"); Put_Line (" Event_Type at 0 * SDL.Word range 0 .. 31;"); Put_Line (" Time_Stamp at 1 * SDL.Word range 0 .. 31;"); New_Line; Put_Line (" ID at 2 * SDL.Word range 0 .. 31;"); Put_Line (" Text at 3 * SDL.Word range 0 .. Max_UTF8_Element_Storage_Bits; -- 31 characters."); Put_Line (" end record;"); Put_Line ("end SDL.Events.Keyboards;"); end Gen_Keyboard;
with openGL.Texture; private with ada.unchecked_Conversion; package openGL.Primitive -- -- Provides a base class for openGL primitives. -- is type Item is abstract tagged limited private; subtype Class is Item'Class; type View is access all Item'class; type Views is array (Index_t range <>) of View; ---------- -- Facets -- type facet_Kind is (Points, Lines, line_Loop, line_Strip, Triangles, triangle_Strip, triangle_Fan); --------- -- Forge -- procedure define (Self : in out Item; Kind : in facet_Kind); procedure destroy (Self : in out Item) is abstract; procedure free (Self : in out View); -------------- -- Attributes -- function Texture (Self : in Item) return openGL.Texture.Object; procedure Texture_is (Self : in out Item; Now : in openGL.Texture.Object); procedure Bounds_are (Self : in out Item; Now : in openGL.Bounds); function Bounds (self : in Item) return openGL.Bounds; -- -- Returns the bounds in object space. procedure is_Transparent (Self : in out Item; Now : in Boolean := True); function is_Transparent (Self : in Item) return Boolean; --------------- --- Operations -- procedure render (Self : in out Item); unused_line_Width : constant := -1.0; private type Item is abstract tagged limited record facet_Kind : primitive.facet_Kind; Texture : openGL.Texture.Object := openGL.Texture.null_Object; is_Transparent : Boolean; Bounds : openGL.Bounds; line_Width : Real := unused_line_Width; end record; ---------- -- Facets -- function Thin (Self : in facet_Kind) return gl.GLenum; for facet_Kind use (Points => gl.GL_POINTS, Lines => gl.GL_LINES, line_Loop => gl.GL_LINE_LOOP, line_Strip => gl.GL_LINE_STRIP, Triangles => gl.GL_TRIANGLES, triangle_Strip => gl.GL_TRIANGLE_STRIP, triangle_Fan => gl.GL_TRIANGLE_FAN); for facet_Kind'Size use gl.GLenum'Size; function Convert is new ada.Unchecked_Conversion (facet_Kind, gl.GLenum); function Thin (Self : in facet_Kind) return gl.GLenum renames Convert; end openGL.Primitive;
with ada.Containers.Vectors; package body AdaM.Any is package view_resolver_Vectors is new ada.Containers.Vectors (Positive, view_Resolver); all_Resolvers : view_resolver_Vectors.Vector; procedure register_view_Resolver (the_Resolver : in view_Resolver) is begin all_Resolvers.append (the_resolver); end register_view_Resolver; procedure resolve_all_Views is use view_resolver_Vectors; Cursor : view_resolver_Vectors.Cursor := all_Resolvers.First; begin while has_Element (Cursor) loop Element (Cursor).all; next (Cursor); end loop; end resolve_all_Views; end AdaM.Any;
with ILI9341_Regs; package body ILI9341.Hack is --------------------- -- Prepare_For_DMA -- --------------------- procedure Prepare_For_DMA (This : in out ILI9341_Device; X1 : Width; Y1 : Height; X2 : Width; Y2 : Height) is begin This.Set_Cursor_Position (X1, Y1, X2, Y2); This.Send_Command (ILI9341_Regs.ILI9341_GRAM); This.WRX.Set; This.Chip_Select_Low; end Prepare_For_DMA; ------------- -- End_DMA -- ------------- procedure End_DMA (This : in out ILI9341_Device) is begin This.Chip_Select_High; end End_DMA; end ILI9341.Hack;
----------------------------------------------------------------------- -- mat-types -- Global types -- Copyright (C) 2014, 2015, 2019 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Util.Strings; package body MAT.Types is -- ------------------------------ -- Return an hexadecimal string representation of the value. -- ------------------------------ function Hex_Image (Value : in Uint32; Length : in Positive := 8) return String is use type Interfaces.Unsigned_32; Conversion : constant String (1 .. 16) := "0123456789ABCDEF"; S : String (1 .. Length) := (others => '0'); P : Uint32 := Value; N : Uint32; I : Positive := Length; begin while P /= 0 loop N := P mod 16; P := P / 16; S (I) := Conversion (Natural (N + 1)); exit when I = 1; I := I - 1; end loop; return S; end Hex_Image; -- ------------------------------ -- Return an hexadecimal string representation of the value. -- ------------------------------ function Hex_Image (Value : in Uint64; Length : in Positive := 16) return String is use type Interfaces.Unsigned_64; Conversion : constant String (1 .. 16) := "0123456789ABCDEF"; S : String (1 .. Length) := (others => '0'); P : Uint64 := Value; N : Uint64; I : Positive := Length; begin while P /= 0 loop N := P mod 16; P := P / 16; S (I) := Conversion (Natural (N + 1)); exit when I = 1; I := I - 1; end loop; return S; end Hex_Image; -- ------------------------------ -- Format the target time to a printable representation. -- ------------------------------ function Tick_Image (Value : in Target_Tick_Ref) return String is use Interfaces; Sec : constant Unsigned_32 := Unsigned_32 (Interfaces.Shift_Right (Uint64 (Value), 32)); Usec : constant Unsigned_32 := Interfaces.Unsigned_32 (Value and 16#0ffffffff#); Frac : constant String := Interfaces.Unsigned_32'Image (Usec); Img : String (1 .. 6) := (others => '0'); begin Img (Img'Last - Frac'Length + 2 .. Img'Last) := Frac (Frac'First + 1 .. Frac'Last); return Interfaces.Unsigned_32'Image (Sec) & "." & Img; end Tick_Image; -- ------------------------------ -- Convert the string in the form NN.MM into a tick value. -- ------------------------------ function Tick_Value (Value : in String) return Target_Tick_Ref is use Interfaces; Pos : constant Natural := Util.Strings.Index (Value, '.'); Frac : Uint64; Val : Uint64; begin if Pos > 0 then Frac := Uint64'Value (Value (Pos + 1 .. Value'Last)); for I in 1 .. 6 - (Value'Last - Pos) loop Frac := Frac * 10; end loop; if Pos > Value'First then Val := Uint64'Value (Value (Value'First .. Pos - 1)); else Val := 0; end if; else Frac := 0; Val := Uint64'Value (Value); end if; return Target_Tick_Ref (Val * 1_000_000 + Frac); end Tick_Value; -- ------------------------------ -- Convert the hexadecimal string into an unsigned integer. -- ------------------------------ function Hex_Value (Value : in String) return Uint64 is use type Interfaces.Unsigned_64; Result : Uint64 := 0; begin if Value'Length = 0 then raise Constraint_Error with "Empty string"; end if; for I in Value'Range loop declare C : constant Character := Value (I); begin if C >= '0' and C <= '9' then Result := (Result * 16) + (Character'Pos (C) - Character'Pos ('0')); elsif C >= 'A' and C <= 'F' then Result := (Result * 16) + (Character'Pos (C) - Character'Pos ('A') + 10); elsif C >= 'a' and C <= 'f' then Result := (Result * 16) + (Character'Pos (C) - Character'Pos ('a') + 10); else raise Constraint_Error with "Invalid character: " & C; end if; end; end loop; return Result; end Hex_Value; end MAT.Types;
with Ada.Text_IO; with Ada.Strings.Unbounded; with ada.Text_IO.Unbounded_IO; with Ada.IO_Exceptions; with Ada.Command_Line, Ada.Text_IO; use Ada.Command_Line, Ada.Text_IO; procedure Friends is -- Initializing Read_From : Ada.Strings.Unbounded.Unbounded_String; Write_To : Ada.Strings.Unbounded.Unbounded_String; name : Ada.Strings.Unbounded.Unbounded_String; Input, Output : File_Type; begin -- taking inputs Put_Line ("Please enter the name of your friend:"); ada.Text_IO.Unbounded_IO.Get_Line(name); begin ada.Text_IO.Open (File => Input, Mode => In_File, Name => "out.txt"); exception when Ada.IO_Exceptions.Name_Error => Ada.Text_IO.create (File => Input, Mode => In_File, Name => "out.txt"); end; -- Creating new file file begin Ada.Text_IO.Open (File => Output, Name => "friends.txt", Mode => Ada.Text_IO.Append_File); exception when Ada.IO_Exceptions.Name_Error => Ada.Text_IO.Create (File => Output, Name => "friends.txt", Mode => Ada.Text_IO.Append_File); return; end; -- Here is the loop............................................. ------------------ loop declare Line : String := Get_Line (Input); begin Put_Line (Output, Line); Put_Line (Ada.Strings.Unbounded.To_String(name) & " Has been added to your friends list"); end; end loop; exception when End_Error => if Is_Open (Input) then Close (Input); end if; if Is_Open (Output) then Close (Output); end if; end Friends;
-------------------------------------------------------------------------------- -- 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. -------------------------------------------------------------------------------- -- -- This package provides GLSL geometry operations. -------------------------------------------------------------------------------- with Vulkan.Math.Exponential; use Vulkan.Math.Exponential; package body Vulkan.Math.Geometry is function Mag (x : in Vkm_GenFType) return Vkm_Float is magnitude : Vkm_Float := 0.0; begin for Index in x.data'Range loop magnitude := magnitude + x.data(index) * x.data(index); end loop; return Sqrt(magnitude); end Mag; ---------------------------------------------------------------------------- function Mag (x : in Vkm_GenDType) return Vkm_Double is magnitude : Vkm_Double := 0.0; begin for index in x.data'Range loop magnitude := magnitude + x.data(index) * x.data(index); end loop; return Sqrt(magnitude); end Mag; ---------------------------------------------------------------------------- function Dot (x, y : in Vkm_GenFType) return Vkm_Float is dot_product : Vkm_Float := 0.0; begin for index in x.data'Range loop dot_product := dot_product + x.data(index) * y.data(index); end loop; return dot_product; end Dot; ---------------------------------------------------------------------------- function Dot (x, y : in Vkm_GenDType) return Vkm_Double is dot_product : Vkm_Double := 0.0; begin for index in x.data'Range loop dot_product := dot_product + x.data(index) * y.data(index); end loop; return dot_product; end Dot; ---------------------------------------------------------------------------- function Cross (x, y : in Vkm_Vec3 ) return Vkm_Vec3 is cross_product : Vkm_Vec3 := Make_Vec3(0.0); begin cross_product.x(x.y*y.z - x.z * y.y) .y(x.z*y.x - x.x * y.z) .z(x.x*y.y - x.y * y.x); return cross_product; end Cross; ---------------------------------------------------------------------------- function Cross (x, y : in Vkm_Dvec3) return Vkm_Dvec3 is cross_product : Vkm_Dvec3 := Make_Dvec3(0.0); begin cross_product.x(x.y*y.z - x.z * y.y) .y(x.z*y.x - x.x * y.z) .z(x.x*y.y - x.y * y.x); return cross_product; end Cross; ---------------------------------------------------------------------------- function Refract(i, n : in Vkm_GenFType; eta : in Vkm_Float ) return Vkm_GenFType is dot_n_i : constant Vkm_Float := Dot(n, i); k : constant Vkm_Float := 1.0 - eta * eta * (1.0 - dot_n_i * dot_n_i); begin return (if k < 0.0 then GFT.Make_GenType(Last_Index => i.Last_Index, value => 0.0) else eta*i - (eta * dot_n_i + Sqrt(k)) * N); end Refract; ---------------------------------------------------------------------------- function Refract(i, n : in Vkm_GenDType; eta : in Vkm_Double ) return Vkm_GenDType is dot_n_i : constant Vkm_Double := Dot(n, i); k : constant Vkm_Double := 1.0 - eta * eta * (1.0 - dot_n_i * dot_n_i); begin return (if k < 0.0 then GDT.Make_GenType(Last_Index => i.Last_Index, value => 0.0) else eta*i - (eta * dot_n_i + Sqrt(k)) * N); end Refract; end Vulkan.Math.Geometry;
package FLTK.Widgets.Clocks is type Clock is new Widget with private; type Clock_Reference (Data : not null access Clock'Class) is limited null record with Implicit_Dereference => Data; subtype Hour is Integer range 0 .. 23; subtype Minute is Integer range 0 .. 59; subtype Second is Integer range 0 .. 60; type Time_Value is mod 2 ** 32; package Forge is function Create (X, Y, W, H : in Integer; Text : in String) return Clock; end Forge; function Get_Hour (This : in Clock) return Hour; function Get_Minute (This : in Clock) return Minute; function Get_Second (This : in Clock) return Second; function Get_Time (This : in Clock) return Time_Value; procedure Set_Time (This : in out Clock; To : in Time_Value); procedure Set_Time (This : in out Clock; Hours : in Hour; Minutes : in Minute; Seconds : in Second); procedure Draw (This : in out Clock); procedure Draw (This : in out Clock; X, Y, W, H : in Integer); function Handle (This : in out Clock; Event : in Event_Kind) return Event_Outcome; private type Clock is new Widget with null record; overriding procedure Finalize (This : in out Clock); pragma Inline (Get_Hour); pragma Inline (Get_Minute); pragma Inline (Get_Second); pragma Inline (Get_Time); pragma Inline (Set_Time); pragma Inline (Draw); pragma Inline (Handle); end FLTK.Widgets.Clocks;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- R E P I N F O - I N P U T -- -- -- -- B o d y -- -- -- -- Copyright (C) 2018-2020, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Alloc; with Csets; use Csets; with Hostparm; use Hostparm; with Namet; use Namet; with Output; use Output; with Snames; use Snames; with Table; with Ttypes; package body Repinfo.Input is SSU : Pos renames Ttypes.System_Storage_Unit; -- Value for Storage_Unit type JSON_Entity_Kind is (JE_Record_Type, JE_Array_Type, JE_Other); -- Kind of an entiy type JSON_Entity_Node (Kind : JSON_Entity_Kind := JE_Other) is record Esize : Node_Ref_Or_Val; RM_Size : Node_Ref_Or_Val; case Kind is when JE_Record_Type => Variant : Nat; when JE_Array_Type => Component_Size : Node_Ref_Or_Val; when JE_Other => Dummy : Boolean; end case; end record; pragma Unchecked_Union (JSON_Entity_Node); -- Record to represent an entity package JSON_Entity_Table is new Table.Table ( Table_Component_Type => JSON_Entity_Node, Table_Index_Type => Nat, Table_Low_Bound => 1, Table_Initial => Alloc.Rep_JSON_Table_Initial, Table_Increment => Alloc.Rep_JSON_Table_Increment, Table_Name => "JSON_Entity_Table"); -- Table of entities type JSON_Component_Node is record Bit_Offset : Node_Ref_Or_Val; Esize : Node_Ref_Or_Val; end record; -- Record to represent a component package JSON_Component_Table is new Table.Table ( Table_Component_Type => JSON_Component_Node, Table_Index_Type => Nat, Table_Low_Bound => 1, Table_Initial => Alloc.Rep_JSON_Table_Initial, Table_Increment => Alloc.Rep_JSON_Table_Increment, Table_Name => "JSON_Component_Table"); -- Table of components type JSON_Variant_Node is record Present : Node_Ref_Or_Val; Variant : Nat; Next : Nat; end record; -- Record to represent a variant package JSON_Variant_Table is new Table.Table ( Table_Component_Type => JSON_Variant_Node, Table_Index_Type => Nat, Table_Low_Bound => 1, Table_Initial => Alloc.Rep_JSON_Table_Initial, Table_Increment => Alloc.Rep_JSON_Table_Increment, Table_Name => "JSON_Variant_Table"); -- Table of variants ------------------------------------- -- Get_JSON_Component_Bit_Offset -- ------------------------------------- function Get_JSON_Component_Bit_Offset (Name : String; Record_Name : String) return Node_Ref_Or_Val is Namid : constant Valid_Name_Id := Name_Find (Record_Name & '.' & Name); Index : constant Int := Get_Name_Table_Int (Namid); begin -- Return No_Uint if no information is available for the component if Index = 0 then return No_Uint; end if; return JSON_Component_Table.Table (Index).Bit_Offset; end Get_JSON_Component_Bit_Offset; ------------------------------- -- Get_JSON_Component_Size -- ------------------------------- function Get_JSON_Component_Size (Name : String) return Node_Ref_Or_Val is Namid : constant Valid_Name_Id := Name_Find (Name); Index : constant Int := Get_Name_Table_Int (Namid); begin -- Return No_Uint if no information is available for the component if Index = 0 then return No_Uint; end if; return JSON_Entity_Table.Table (Index).Component_Size; end Get_JSON_Component_Size; ---------------------- -- Get_JSON_Esize -- ---------------------- function Get_JSON_Esize (Name : String) return Node_Ref_Or_Val is Namid : constant Valid_Name_Id := Name_Find (Name); Index : constant Int := Get_Name_Table_Int (Namid); begin -- Return No_Uint if no information is available for the entity if Index = 0 then return No_Uint; end if; return JSON_Entity_Table.Table (Index).Esize; end Get_JSON_Esize; ---------------------- -- Get_JSON_Esize -- ---------------------- function Get_JSON_Esize (Name : String; Record_Name : String) return Node_Ref_Or_Val is Namid : constant Valid_Name_Id := Name_Find (Record_Name & '.' & Name); Index : constant Int := Get_Name_Table_Int (Namid); begin -- Return No_Uint if no information is available for the entity if Index = 0 then return No_Uint; end if; return JSON_Component_Table.Table (Index).Esize; end Get_JSON_Esize; ------------------------ -- Get_JSON_RM_Size -- ------------------------ function Get_JSON_RM_Size (Name : String) return Node_Ref_Or_Val is Namid : constant Valid_Name_Id := Name_Find (Name); Index : constant Int := Get_Name_Table_Int (Namid); begin -- Return No_Uint if no information is available for the entity if Index = 0 then return No_Uint; end if; return JSON_Entity_Table.Table (Index).RM_Size; end Get_JSON_RM_Size; ----------------------- -- Read_JSON_Stream -- ----------------------- procedure Read_JSON_Stream (Text : Text_Buffer; File_Name : String) is type Text_Position is record Index : Text_Ptr := 0; Line : Natural := 0; Column : Natural := 0; end record; -- Record to represent position in the text type Token_Kind is (J_NULL, J_TRUE, J_FALSE, J_NUMBER, J_INTEGER, J_STRING, J_ARRAY, J_OBJECT, J_ARRAY_END, J_OBJECT_END, J_COMMA, J_COLON, J_EOF); -- JSON Token kind. Note that in ECMA 404 there is no notion of integer. -- Only numbers are supported. In our implementation we return J_INTEGER -- if there is no decimal part in the number. The semantic is that this -- is a J_NUMBER token that might be represented as an integer. Special -- token J_EOF means that end of stream has been reached. function Decode_Integer (Lo, Hi : Text_Ptr) return Uint; -- Decode and return the integer in Text (Lo .. Hi) function Decode_Name (Lo, Hi : Text_Ptr) return Valid_Name_Id; -- Decode and return the name in Text (Lo .. Hi) function Decode_Symbol (Lo, Hi : Text_Ptr) return TCode; -- Decode and return the expression symbol in Text (Lo .. Hi) procedure Error (Msg : String); pragma No_Return (Error); -- Print an error message and raise an exception procedure Read_Entity; -- Read an entity function Read_Name return Valid_Name_Id; -- Read a name function Read_Name_With_Prefix return Valid_Name_Id; -- Read a name and prepend a prefix function Read_Number return Uint; -- Read a number function Read_Numerical_Expr return Node_Ref_Or_Val; -- Read a numerical expression procedure Read_Record; -- Read a record function Read_String return Valid_Name_Id; -- Read a string procedure Read_Token (Kind : out Token_Kind; Token_Start : out Text_Position; Token_End : out Text_Position); -- Read a token and return it (this is a standard JSON lexer) procedure Read_Token_And_Error (TK : Token_Kind; Token_Start : out Text_Position; Token_End : out Text_Position); pragma Inline (Read_Token_And_Error); -- Read a specified token and error out on failure function Read_Variant_Part return Nat; -- Read a variant part procedure Skip_Value; -- Skip a value Pos : Text_Position := (Text'First, 1, 1); -- The current position in the text buffer Name_Buffer : Bounded_String (4 * Max_Name_Length); -- The buffer used to build full qualifed names Prefix_Len : Natural := 0; -- The length of the prefix present in Name_Buffer ---------------------- -- Decode_Integer -- ---------------------- function Decode_Integer (Lo, Hi : Text_Ptr) return Uint is Len : constant Nat := Int (Hi) - Int (Lo) + 1; begin -- Decode up to 9 characters manually, otherwise call into Uint if Len < 10 then declare Val : Int := 0; begin for J in Lo .. Hi loop Val := Val * 10 + Character'Pos (Text (J)) - Character'Pos ('0'); end loop; return UI_From_Int (Val); end; else declare Val : Uint := Uint_0; begin for J in Lo .. Hi loop Val := Val * 10 + Character'Pos (Text (J)) - Character'Pos ('0'); end loop; return Val; end; end if; end Decode_Integer; ------------------- -- Decode_Name -- ------------------- function Decode_Name (Lo, Hi : Text_Ptr) return Valid_Name_Id is begin -- Names are stored in lower case so fold them if need be if Is_Upper_Case_Letter (Text (Lo)) then declare S : String (Integer (Lo) .. Integer (Hi)); begin for J in Lo .. Hi loop S (Integer (J)) := Fold_Lower (Text (J)); end loop; return Name_Find (S); end; else declare S : String (Integer (Lo) .. Integer (Hi)); for S'Address use Text (Lo)'Address; begin return Name_Find (S); end; end if; end Decode_Name; --------------------- -- Decode_Symbol -- --------------------- function Decode_Symbol (Lo, Hi : Text_Ptr) return TCode is function Cmp12 (A, B : Character) return Boolean; pragma Inline (Cmp12); -- Compare Text (Lo + 1 .. Lo + 2) with A & B. ------------- -- Cmp12 -- ------------- function Cmp12 (A, B : Character) return Boolean is begin return Text (Lo + 1) = A and then Text (Lo + 2) = B; end Cmp12; Len : constant Nat := Int (Hi) - Int (Lo) + 1; -- Start of processing for Decode_Symbol begin case Len is when 1 => case Text (Lo) is when '+' => return Plus_Expr; when '-' => return Minus_Expr; -- or Negate_Expr when '*' => return Mult_Expr; when '<' => return Lt_Expr; when '>' => return Gt_Expr; when '&' => return Bit_And_Expr; when '#' => return Discrim_Val; when others => null; end case; when 2 => if Text (Lo) = '/' then case Text (Lo + 1) is when 't' => return Trunc_Div_Expr; when 'c' => return Ceil_Div_Expr; when 'f' => return Floor_Div_Expr; when 'e' => return Exact_Div_Expr; when others => null; end case; elsif Text (Lo + 1) = '=' then case Text (Lo) is when '<' => return Le_Expr; when '>' => return Ge_Expr; when '=' => return Eq_Expr; when '!' => return Ne_Expr; when others => null; end case; elsif Text (Lo) = 'o' and then Text (Lo + 1) = 'r' then return Truth_Or_Expr; end if; when 3 => case Text (Lo) is when '?' => if Cmp12 ('<', '>') then return Cond_Expr; end if; when 'a' => if Cmp12 ('b', 's') then return Abs_Expr; elsif Cmp12 ('n', 'd') then return Truth_And_Expr; end if; when 'm' => if Cmp12 ('a', 'x') then return Max_Expr; elsif Cmp12 ('i', 'n') then return Min_Expr; end if; when 'n' => if Cmp12 ('o', 't') then return Truth_Not_Expr; end if; when 'x' => if Cmp12 ('o', 'r') then return Truth_Xor_Expr; end if; when 'v' => if Cmp12 ('a', 'r') then return Dynamic_Val; end if; when others => null; end case; when 4 => if Text (Lo) = 'm' and then Text (Lo + 1) = 'o' and then Text (Lo + 2) = 'd' then case Text (Lo + 3) is when 't' => return Trunc_Mod_Expr; when 'c' => return Ceil_Mod_Expr; when 'f' => return Floor_Mod_Expr; when others => null; end case; end if; pragma Annotate (CodePeer, Intentional, "condition predetermined", "Error called as defensive code"); when others => null; end case; Error ("unknown symbol"); end Decode_Symbol; ----------- -- Error -- ----------- procedure Error (Msg : String) is L : constant String := Pos.Line'Img; C : constant String := Pos.Column'Img; begin Set_Standard_Error; Write_Eol; Write_Str (File_Name); Write_Char (':'); Write_Str (L (L'First + 1 .. L'Last)); Write_Char (':'); Write_Str (C (C'First + 1 .. C'Last)); Write_Char (':'); Write_Line (Msg); raise Invalid_JSON_Stream; end Error; ------------------ -- Read_Entity -- ------------------ procedure Read_Entity is Ent : JSON_Entity_Node; Nam : Name_Id := No_Name; Siz : Node_Ref_Or_Val; Token_Start : Text_Position; Token_End : Text_Position; TK : Token_Kind; begin Ent.Esize := No_Uint; Ent.RM_Size := No_Uint; Ent.Component_Size := No_Uint; -- Read the members as string : value pairs loop case Read_String is when Name_Name => Nam := Read_Name; when Name_Record => if Nam = No_Name then Error ("name expected"); end if; Ent.Variant := 0; Prefix_Len := Natural (Length_Of_Name (Nam)); Name_Buffer.Chars (1 .. Prefix_Len) := Get_Name_String (Nam); Read_Record; when Name_Variant => Ent.Variant := Read_Variant_Part; when Name_Size => Siz := Read_Numerical_Expr; Ent.Esize := Siz; Ent.RM_Size := Siz; when Name_Object_Size => Ent.Esize := Read_Numerical_Expr; when Name_Value_Size => Ent.RM_Size := Read_Numerical_Expr; when Name_Component_Size => Ent.Component_Size := Read_Numerical_Expr; when others => Skip_Value; end case; Read_Token (TK, Token_Start, Token_End); if TK = J_OBJECT_END then exit; elsif TK /= J_COMMA then Error ("comma expected"); end if; end loop; -- Store the entity into the table JSON_Entity_Table.Append (Ent); -- Associate the name with the entity if Nam = No_Name then Error ("name expected"); end if; Set_Name_Table_Int (Nam, JSON_Entity_Table.Last); end Read_Entity; ----------------- -- Read_Name -- ----------------- function Read_Name return Valid_Name_Id is Token_Start : Text_Position; Token_End : Text_Position; begin -- Read a single string Read_Token_And_Error (J_STRING, Token_Start, Token_End); return Decode_Name (Token_Start.Index + 1, Token_End.Index - 1); end Read_Name; ----------------------------- -- Read_Name_With_Prefix -- ----------------------------- function Read_Name_With_Prefix return Valid_Name_Id is Len : Natural; Lo, Hi : Text_Ptr; Token_Start : Text_Position; Token_End : Text_Position; begin -- Read a single string Read_Token_And_Error (J_STRING, Token_Start, Token_End); Lo := Token_Start.Index + 1; Hi := Token_End.Index - 1; -- Prepare for the concatenation with the prefix Len := Integer (Hi) - Integer (Lo) + 1; if Prefix_Len + 1 + Len > Name_Buffer.Max_Length then Error ("Name buffer too small"); end if; Name_Buffer.Length := Prefix_Len + 1 + Len; Name_Buffer.Chars (Prefix_Len + 1) := '.'; -- Names are stored in lower case so fold them if need be if Is_Upper_Case_Letter (Text (Lo)) then for J in Lo .. Hi loop Name_Buffer.Chars (Prefix_Len + 2 + Integer (J - Lo)) := Fold_Lower (Text (J)); end loop; else declare S : String (Integer (Lo) .. Integer (Hi)); for S'Address use Text (Lo)'Address; begin Name_Buffer.Chars (Prefix_Len + 2 .. Prefix_Len + 1 + Len) := S; end; end if; return Name_Find (Name_Buffer); end Read_Name_With_Prefix; ------------------ -- Read_Number -- ------------------ function Read_Number return Uint is Token_Start : Text_Position; Token_End : Text_Position; begin -- Only integers are to be expected here Read_Token_And_Error (J_INTEGER, Token_Start, Token_End); return Decode_Integer (Token_Start.Index, Token_End.Index); end Read_Number; -------------------------- -- Read_Numerical_Expr -- -------------------------- function Read_Numerical_Expr return Node_Ref_Or_Val is Code : TCode; Nop : Integer; Ops : array (1 .. 3) of Node_Ref_Or_Val; TK : Token_Kind; Token_Start : Text_Position; Token_End : Text_Position; begin -- Read either an integer or an expression Read_Token (TK, Token_Start, Token_End); if TK = J_INTEGER then return Decode_Integer (Token_Start.Index, Token_End.Index); elsif TK = J_OBJECT then -- Read the code of the expression and decode it if Read_String /= Name_Code then Error ("name expected"); end if; Read_Token_And_Error (J_STRING, Token_Start, Token_End); Code := Decode_Symbol (Token_Start.Index + 1, Token_End.Index - 1); Read_Token_And_Error (J_COMMA, Token_Start, Token_End); -- Read the array of operands if Read_String /= Name_Operands then Error ("operands expected"); end if; Read_Token_And_Error (J_ARRAY, Token_Start, Token_End); Nop := 0; Ops := (others => No_Uint); loop Nop := Nop + 1; Ops (Nop) := Read_Numerical_Expr; Read_Token (TK, Token_Start, Token_End); if TK = J_ARRAY_END then exit; elsif TK /= J_COMMA then Error ("comma expected"); end if; end loop; Read_Token_And_Error (J_OBJECT_END, Token_Start, Token_End); -- Resolve the ambiguity for '-' now if Code = Minus_Expr and then Nop = 1 then Code := Negate_Expr; end if; return Create_Node (Code, Ops (1), Ops (2), Ops (3)); else Error ("numerical expression expected"); end if; end Read_Numerical_Expr; ------------------- -- Read_Record -- ------------------- procedure Read_Record is Comp : JSON_Component_Node; First_Bit : Node_Ref_Or_Val := No_Uint; Is_First : Boolean := True; Nam : Name_Id := No_Name; Position : Node_Ref_Or_Val := No_Uint; TK : Token_Kind; Token_Start : Text_Position; Token_End : Text_Position; begin -- Read a possibly empty array of components Read_Token_And_Error (J_ARRAY, Token_Start, Token_End); loop Read_Token (TK, Token_Start, Token_End); if Is_First and then TK = J_ARRAY_END then exit; elsif TK /= J_OBJECT then Error ("object expected"); end if; -- Read the members as string : value pairs loop case Read_String is when Name_Name => Nam := Read_Name_With_Prefix; when Name_Discriminant => Skip_Value; when Name_Position => Position := Read_Numerical_Expr; when Name_First_Bit => First_Bit := Read_Number; when Name_Size => Comp.Esize := Read_Numerical_Expr; when others => Error ("invalid component"); end case; Read_Token (TK, Token_Start, Token_End); if TK = J_OBJECT_END then exit; elsif TK /= J_COMMA then Error ("comma expected"); end if; end loop; -- Compute Component_Bit_Offset from Position and First_Bit, -- either symbolically or literally depending on Position. if Position = No_Uint or else First_Bit = No_Uint then Error ("bit offset expected"); end if; if Position < Uint_0 then declare Bit_Position : constant Node_Ref_Or_Val := Create_Node (Mult_Expr, Position, UI_From_Int (SSU)); begin if First_Bit = Uint_0 then Comp.Bit_Offset := Bit_Position; else Comp.Bit_Offset := Create_Node (Plus_Expr, Bit_Position, First_Bit); end if; end; else Comp.Bit_Offset := Position * SSU + First_Bit; end if; -- Store the component into the table JSON_Component_Table.Append (Comp); -- Associate the name with the component if Nam = No_Name then Error ("name expected"); end if; Set_Name_Table_Int (Nam, JSON_Component_Table.Last); Read_Token (TK, Token_Start, Token_End); if TK = J_ARRAY_END then exit; elsif TK /= J_COMMA then Error ("comma expected"); end if; Is_First := False; end loop; end Read_Record; ------------------ -- Read_String -- ------------------ function Read_String return Valid_Name_Id is Token_Start : Text_Position; Token_End : Text_Position; Nam : Valid_Name_Id; begin -- Read the string and the following colon Read_Token_And_Error (J_STRING, Token_Start, Token_End); Nam := Decode_Name (Token_Start.Index + 1, Token_End.Index - 1); Read_Token_And_Error (J_COLON, Token_Start, Token_End); return Nam; end Read_String; ------------------ -- Read_Token -- ------------------ procedure Read_Token (Kind : out Token_Kind; Token_Start : out Text_Position; Token_End : out Text_Position) is procedure Next_Char; -- Update Pos to point to next char function Is_Whitespace return Boolean; pragma Inline (Is_Whitespace); -- Return True of current character is a whitespace function Is_Structural_Token return Boolean; pragma Inline (Is_Structural_Token); -- Return True if current character is one of the structural tokens function Is_Token_Sep return Boolean; pragma Inline (Is_Token_Sep); -- Return True if current character is a token separator procedure Delimit_Keyword (Kw : String); -- Helper function to parse tokens such as null, false and true --------------- -- Next_Char -- --------------- procedure Next_Char is begin if Pos.Index > Text'Last then Pos.Column := Pos.Column + 1; elsif Text (Pos.Index) = ASCII.LF then Pos.Column := 1; Pos.Line := Pos.Line + 1; else Pos.Column := Pos.Column + 1; end if; Pos.Index := Pos.Index + 1; end Next_Char; ------------------- -- Is_Whitespace -- ------------------- function Is_Whitespace return Boolean is begin return Pos.Index <= Text'Last and then (Text (Pos.Index) = ASCII.LF or else Text (Pos.Index) = ASCII.CR or else Text (Pos.Index) = ASCII.HT or else Text (Pos.Index) = ' '); end Is_Whitespace; ------------------------- -- Is_Structural_Token -- ------------------------- function Is_Structural_Token return Boolean is begin return Pos.Index <= Text'Last and then (Text (Pos.Index) = '[' or else Text (Pos.Index) = ']' or else Text (Pos.Index) = '{' or else Text (Pos.Index) = '}' or else Text (Pos.Index) = ',' or else Text (Pos.Index) = ':'); end Is_Structural_Token; ------------------ -- Is_Token_Sep -- ------------------ function Is_Token_Sep return Boolean is begin return Pos.Index > Text'Last or else Is_Whitespace or else Is_Structural_Token; end Is_Token_Sep; --------------------- -- Delimit_Keyword -- --------------------- procedure Delimit_Keyword (Kw : String) is pragma Unreferenced (Kw); begin while not Is_Token_Sep loop Token_End := Pos; Next_Char; end loop; end Delimit_Keyword; CC : Character; Can_Be_Integer : Boolean := True; -- Start of processing for Read_Token begin -- Skip leading whitespaces while Is_Whitespace loop Next_Char; end loop; -- Initialize token delimiters Token_Start := Pos; Token_End := Pos; -- End of stream reached if Pos.Index > Text'Last then Kind := J_EOF; return; end if; CC := Text (Pos.Index); if CC = '[' then Next_Char; Kind := J_ARRAY; return; elsif CC = ']' then Next_Char; Kind := J_ARRAY_END; return; elsif CC = '{' then Next_Char; Kind := J_OBJECT; return; elsif CC = '}' then Next_Char; Kind := J_OBJECT_END; return; elsif CC = ',' then Next_Char; Kind := J_COMMA; return; elsif CC = ':' then Next_Char; Kind := J_COLON; return; elsif CC = 'n' then Delimit_Keyword ("null"); Kind := J_NULL; return; elsif CC = 'f' then Delimit_Keyword ("false"); Kind := J_FALSE; return; elsif CC = 't' then Delimit_Keyword ("true"); Kind := J_TRUE; return; elsif CC = '"' then -- We expect a string -- Just scan till the end the of the string but do not attempt -- to decode it. This means that even if we get a string token -- it might not be a valid string from the ECMA 404 point of -- view. Next_Char; while Pos.Index <= Text'Last and then Text (Pos.Index) /= '"' loop if Text (Pos.Index) in ASCII.NUL .. ASCII.US then Error ("control character not allowed in string"); end if; if Text (Pos.Index) = '\' then Next_Char; if Pos.Index > Text'Last then Error ("non terminated string token"); end if; case Text (Pos.Index) is when 'u' => for Idx in 1 .. 4 loop Next_Char; if Pos.Index > Text'Last or else (Text (Pos.Index) not in 'a' .. 'f' and then Text (Pos.Index) not in 'A' .. 'F' and then Text (Pos.Index) not in '0' .. '9') then Error ("invalid unicode escape sequence"); end if; end loop; when '\' | '/' | '"' | 'b' | 'f' | 'n' | 'r' | 't' => null; when others => Error ("invalid escape sequence"); end case; end if; Next_Char; end loop; -- No quote found report and error if Pos.Index > Text'Last then Error ("non terminated string token"); end if; Token_End := Pos; -- Go to next char and ensure that this is separator. Indeed -- construction such as "string1""string2" are not allowed Next_Char; if not Is_Token_Sep then Error ("invalid syntax"); end if; Kind := J_STRING; return; elsif CC = '-' or else CC in '0' .. '9' then -- We expect a number if CC = '-' then Next_Char; end if; if Pos.Index > Text'Last then Error ("invalid number"); end if; -- Parse integer part of a number. Superfluous leading zeros are -- not allowed. if Text (Pos.Index) = '0' then Token_End := Pos; Next_Char; elsif Text (Pos.Index) in '1' .. '9' then Token_End := Pos; Next_Char; while Pos.Index <= Text'Last and then Text (Pos.Index) in '0' .. '9' loop Token_End := Pos; Next_Char; end loop; else Error ("invalid number"); end if; if Is_Token_Sep then -- Valid integer number Kind := J_INTEGER; return; elsif Text (Pos.Index) /= '.' and then Text (Pos.Index) /= 'e' and then Text (Pos.Index) /= 'E' then Error ("invalid number"); end if; -- Check for a fractional part if Text (Pos.Index) = '.' then Can_Be_Integer := False; Token_End := Pos; Next_Char; if Pos.Index > Text'Last or else Text (Pos.Index) not in '0' .. '9' then Error ("invalid number"); end if; while Pos.Index <= Text'Last and then Text (Pos.Index) in '0' .. '9' loop Token_End := Pos; Next_Char; end loop; end if; -- Check for exponent part if Pos.Index <= Text'Last and then (Text (Pos.Index) = 'e' or else Text (Pos.Index) = 'E') then Token_End := Pos; Next_Char; if Pos.Index > Text'Last then Error ("invalid number"); end if; if Text (Pos.Index) = '-' then -- Also a few corner cases can lead to an integer, assume -- that the number is not an integer. Can_Be_Integer := False; end if; if Text (Pos.Index) = '-' or else Text (Pos.Index) = '+' then Next_Char; end if; if Pos.Index > Text'Last or else Text (Pos.Index) not in '0' .. '9' then Error ("invalid number"); end if; while Pos.Index <= Text'Last and then Text (Pos.Index) in '0' .. '9' loop Token_End := Pos; Next_Char; end loop; end if; if Is_Token_Sep then -- Valid decimal number if Can_Be_Integer then Kind := J_INTEGER; else Kind := J_NUMBER; end if; return; else Error ("invalid number"); end if; elsif CC = EOF then Kind := J_EOF; else Error ("Unexpected character"); end if; end Read_Token; ---------------------------- -- Read_Token_And_Error -- ---------------------------- procedure Read_Token_And_Error (TK : Token_Kind; Token_Start : out Text_Position; Token_End : out Text_Position) is Kind : Token_Kind; begin -- Read a token and errout out if not of the expected kind Read_Token (Kind, Token_Start, Token_End); if Kind /= TK then Error ("specific token expected"); end if; end Read_Token_And_Error; ------------------------- -- Read_Variant_Part -- ------------------------- function Read_Variant_Part return Nat is Next : Nat := 0; TK : Token_Kind; Token_Start : Text_Position; Token_End : Text_Position; Var : JSON_Variant_Node; begin -- Read a non-empty array of components Read_Token_And_Error (J_ARRAY, Token_Start, Token_End); loop Read_Token_And_Error (J_OBJECT, Token_Start, Token_End); Var.Variant := 0; -- Read the members as string : value pairs loop case Read_String is when Name_Present => Var.Present := Read_Numerical_Expr; when Name_Record => Read_Record; when Name_Variant => Var.Variant := Read_Variant_Part; when others => Error ("invalid variant"); end case; Read_Token (TK, Token_Start, Token_End); if TK = J_OBJECT_END then exit; elsif TK /= J_COMMA then Error ("comma expected"); end if; end loop; -- Chain the variant and store it into the table Var.Next := Next; JSON_Variant_Table.Append (Var); Next := JSON_Variant_Table.Last; Read_Token (TK, Token_Start, Token_End); if TK = J_ARRAY_END then exit; elsif TK /= J_COMMA then Error ("comma expected"); end if; end loop; return Next; end Read_Variant_Part; ------------------ -- Skip_Value -- ------------------ procedure Skip_Value is Array_Depth : Natural := 0; Object_Depth : Natural := 0; TK : Token_Kind; Token_Start : Text_Position; Token_End : Text_Position; begin -- Read a value without recursing loop Read_Token (TK, Token_Start, Token_End); case TK is when J_STRING | J_INTEGER | J_NUMBER => null; when J_ARRAY => Array_Depth := Array_Depth + 1; when J_ARRAY_END => Array_Depth := Array_Depth - 1; when J_OBJECT => Object_Depth := Object_Depth + 1; when J_OBJECT_END => Object_Depth := Object_Depth - 1; when J_COLON | J_COMMA => if Array_Depth = 0 and then Object_Depth = 0 then Error ("value expected"); end if; when others => Error ("value expected"); end case; exit when Array_Depth = 0 and then Object_Depth = 0; end loop; end Skip_Value; Token_Start : Text_Position; Token_End : Text_Position; TK : Token_Kind; Is_First : Boolean := True; -- Start of processing for Read_JSON_Stream begin -- Read a possibly empty array of entities Read_Token_And_Error (J_ARRAY, Token_Start, Token_End); loop Read_Token (TK, Token_Start, Token_End); if Is_First and then TK = J_ARRAY_END then exit; elsif TK /= J_OBJECT then Error ("object expected"); end if; Read_Entity; Read_Token (TK, Token_Start, Token_End); if TK = J_ARRAY_END then exit; elsif TK /= J_COMMA then Error ("comma expected"); end if; Is_First := False; end loop; end Read_JSON_Stream; end Repinfo.Input;
function Duplication ( T: Tomb ) return Boolean is J: Index := T'First; Re: Boolean := False; begin for I in T'Range loop if T(Mh) < T(I) then Mh := I; end if; end loop; return Mh; end Duplication;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- P A R . E N D H -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Namet.Sp; use Namet.Sp; with Stringt; use Stringt; with Uintp; use Uintp; with GNAT.Spelling_Checker; use GNAT.Spelling_Checker; separate (Par) package body Endh is ---------------- -- Local Data -- ---------------- type End_Action_Type is ( -- Type used to describe the result of the Pop_End_Context call Accept_As_Scanned, -- Current end sequence is entirely c correct. In this case Token and -- the scan pointer are left pointing past the end sequence (i.e. they -- are unchanged from the values set on entry to Pop_End_Context). Insert_And_Accept, -- Current end sequence is to be left in place to satisfy some outer -- scope. Token and the scan pointer are set to point to the end -- token, and should be left there. A message has been generated -- indicating a missing end sequence. This status is also used for -- the case when no end token is present. Skip_And_Accept, -- The end sequence is incorrect (and an error message has been -- posted), but it will still be accepted. In this case Token and -- the scan pointer point back to the end token, and the caller -- should skip past the end sequence before proceeding. Skip_And_Reject); -- The end sequence is judged to belong to an unrecognized inner -- scope. An appropriate message has been issued and the caller -- should skip past the end sequence and then proceed as though -- no end sequence had been encountered. End_Action : End_Action_Type; -- The variable set by Pop_End_Context call showing which of the four -- decisions described above is judged the best. End_Sloc : Source_Ptr; -- Source location of END token End_OK : Boolean; -- Set False if error is found in END line End_Column : Column_Number; -- Column of END line End_Type : SS_End_Type; -- Type of END expected. The special value E_Dummy is set to indicate that -- no END token was present (so a missing END inserted message is needed) End_Labl : Node_Id; -- Node_Id value for explicit name on END line, or for compiler supplied -- name in the case where an optional name is not given. Empty if no name -- appears. If non-empty, then it is either an N_Designator node for a -- child unit or a node with a Chars field identifying the actual label. End_Labl_Present : Boolean; -- Indicates that the value in End_Labl was for an explicit label Syntax_OK : Boolean; -- Set True if the entry is syntactically correct Token_OK : Boolean; -- Set True if the keyword in the END sequence matches, or if neither -- the END sequence nor the END stack entry has a keyword. Label_OK : Boolean; -- Set True if both the END sequence and the END stack entry contained -- labels (other than No_Name or Error_Name) and the labels matched. -- This is a stronger condition than SYNTAX_OK, since it means that a -- label was present, even in a case where it was optional. Note that -- the case of no label required, and no label present does NOT set -- Label_OK to True, it is True only if a positive label match is found. Column_OK : Boolean; -- Column_OK is set True if the END sequence appears in the expected column Scan_State : Saved_Scan_State; -- Save state at start of END sequence, in case we decide not to eat it up ----------------------- -- Local Subprograms -- ----------------------- procedure Evaluate_End_Entry (SS_Index : Nat); -- Compare scanned END entry (as recorded by a prior call to P_End_Scan) -- with a specified entry in the scope stack (the single parameter is the -- entry index in the scope stack). Note that Scan is not called. The above -- variables xxx_OK are set to indicate the result of the evaluation. function Explicit_Start_Label (SS_Index : Nat) return Boolean; -- Determines whether the specified entry in the scope stack has an -- explicit start label (i.e. one other than one that was created by -- the parser when no explicit label was present). procedure Output_End_Deleted; -- Output a message complaining that the current END structure does not -- match anything and is being deleted. procedure Output_End_Expected (Ins : Boolean); -- Output a message at the start of the current token which is always an -- END, complaining that the END is not of the right form. The message -- indicates the expected form. The information for the message is taken -- from the top entry in the scope stack. The Ins parameter is True if -- an end is being inserted, and false if an existing end is being -- replaced. Note that in the case of a suspicious IS for the Ins case, -- we do not output the message, but instead simply mark the scope stack -- entry as being a case of a bad IS. procedure Output_End_Missing; -- Output a message just before the current token, complaining that the -- END is not of the right form. The message indicates the expected form. -- The information for the message is taken from the top entry in the -- scope stack. Note that in the case of a suspicious IS, we do not output -- the message, but instead simply mark the scope stack entry as a bad IS. procedure Pop_End_Context; -- Pop_End_Context is called after processing a construct, to pop the -- top entry off the end stack. It decides on the appropriate action to -- to take, signalling the result by setting End_Action as described in -- the global variable section. function Same_Label (Label1, Label2 : Node_Id) return Boolean; -- This function compares the two names associated with the given nodes. -- If they are both simple (i.e. have Chars fields), then they have to -- be the same name. Otherwise they must both be N_Selected_Component -- nodes, referring to the same set of names, or Label1 is an N_Designator -- referring to the same set of names as the N_Defining_Program_Unit_Name -- in Label2. Any other combination returns False. This routine is used -- to compare the End_Labl scanned from the End line with the saved label -- value in the scope stack. --------------- -- Check_End -- --------------- function Check_End (Decl : Node_Id := Empty; Is_Loc : Source_Ptr := No_Location) return Boolean is Name_On_Separate_Line : Boolean; -- Set True if the name on an END line is on a separate source line -- from the END. This is highly suspicious, but is allowed. The point -- is that we want to make sure that we don't just have a missing -- semicolon misleading us into swallowing an identifier from the -- following line. Name_Scan_State : Saved_Scan_State; -- Save state at start of name if Name_On_Separate_Line is TRUE Span_Node : constant Node_Id := Scope.Table (Scope.Last).Node; begin End_Labl_Present := False; End_Labl := Empty; -- Our first task is to scan out the END sequence if one is present. -- If none is present, signal by setting End_Type to E_Dummy. if Token /= Tok_End then End_Type := E_Dummy; else Save_Scan_State (Scan_State); -- at END End_Sloc := Token_Ptr; End_Column := Start_Column; End_OK := True; Scan; -- past END -- Set End_Span if expected. Note that this will be useless -- if we do not have the right ending keyword, but in this -- case we have a malformed program anyway, and the setting -- of End_Span will simply be unreliable in this case anyway. if Present (Span_Node) then Set_End_Location (Span_Node, Token_Ptr); end if; -- Cases of keywords where no label is allowed if Token = Tok_Case then End_Type := E_Case; Scan; -- past CASE elsif Token = Tok_If then End_Type := E_If; Scan; -- past IF elsif Token = Tok_Record then End_Type := E_Record; Scan; -- past RECORD elsif Token = Tok_Return then End_Type := E_Return; Scan; -- past RETURN elsif Token = Tok_Select then End_Type := E_Select; Scan; -- past SELECT -- Cases which do allow labels else -- LOOP if Token = Tok_Loop then Scan; -- past LOOP End_Type := E_Loop; -- FOR or WHILE allowed (signalling error) to substitute for LOOP -- if on the same line as the END. elsif (Token = Tok_For or else Token = Tok_While) and then not Token_Is_At_Start_Of_Line then Scan; -- past FOR or WHILE End_Type := E_Loop; End_OK := False; -- Cases with no keyword else End_Type := E_Name; end if; -- Now see if a name is present if Token = Tok_Identifier or else Token = Tok_String_Literal or else Token = Tok_Operator_Symbol then if Token_Is_At_Start_Of_Line then Name_On_Separate_Line := True; Save_Scan_State (Name_Scan_State); else Name_On_Separate_Line := False; end if; End_Labl := P_Designator; End_Labl_Present := True; -- We have now scanned out a name. Here is where we do a check -- to catch the cases like: -- -- end loop -- X := 3; -- -- where the missing semicolon might make us swallow up the X -- as a bogus end label. In a situation like this, where the -- apparent name is on a separate line, we accept it only if -- it matches the label and is followed by a semicolon. if Name_On_Separate_Line then if Token /= Tok_Semicolon or else not Same_Label (End_Labl, Scope.Table (Scope.Last).Labl) then Restore_Scan_State (Name_Scan_State); End_Labl := Empty; End_Labl_Present := False; end if; end if; -- Here for case of name allowed, but no name present. We will -- supply an implicit matching name, with source location set -- to the scan location past the END token. else End_Labl := Scope.Table (Scope.Last).Labl; if End_Labl > Empty_Or_Error then -- The task here is to construct a designator from the -- opening label, with the components all marked as not -- from source, and Is_End_Label set in the identifier -- or operator symbol. The location for all components -- is the current token location. -- Case of child unit name if Nkind (End_Labl) = N_Defining_Program_Unit_Name then Child_End : declare Eref : constant Node_Id := Make_Identifier (Token_Ptr, Chars => Chars (Defining_Identifier (End_Labl))); function Copy_Name (N : Node_Id) return Node_Id; -- Copies a selected component or identifier --------------- -- Copy_Name -- --------------- function Copy_Name (N : Node_Id) return Node_Id is R : Node_Id; begin if Nkind (N) = N_Selected_Component then return Make_Selected_Component (Token_Ptr, Prefix => Copy_Name (Prefix (N)), Selector_Name => Copy_Name (Selector_Name (N))); else R := Make_Identifier (Token_Ptr, Chars (N)); Set_Comes_From_Source (N, False); return R; end if; end Copy_Name; -- Start of processing for Child_End begin Set_Comes_From_Source (Eref, False); End_Labl := Make_Designator (Token_Ptr, Name => Copy_Name (Name (End_Labl)), Identifier => Eref); end Child_End; -- Simple identifier case elsif Nkind (End_Labl) = N_Defining_Identifier or else Nkind (End_Labl) = N_Identifier then End_Labl := Make_Identifier (Token_Ptr, Chars (End_Labl)); elsif Nkind (End_Labl) = N_Defining_Operator_Symbol or else Nkind (End_Labl) = N_Operator_Symbol then Get_Decoded_Name_String (Chars (End_Labl)); End_Labl := Make_Operator_Symbol (Token_Ptr, Chars => Chars (End_Labl), Strval => String_From_Name_Buffer); end if; Set_Comes_From_Source (End_Labl, False); End_Labl_Present := False; -- Do style check for label permitted but not present. Note: -- for the case of a block statement, the label is required -- to be repeated, and this legality rule is enforced -- independently. if Style_Check and then End_Type = E_Name and then Explicit_Start_Label (Scope.Last) and then Nkind (Parent (Scope.Table (Scope.Last).Labl)) /= N_Block_Statement then Style.No_End_Name (Scope.Table (Scope.Last).Labl); end if; end if; end if; end if; -- Deal with terminating aspect specifications and following semi- -- colon. We skip this in the case of END RECORD, since in this -- case the aspect specifications and semicolon are handled at -- a higher level. if End_Type /= E_Record then -- Scan aspect specifications if Aspect_Specifications_Present then -- Aspect specifications not allowed if No (Decl) then -- Package declaration case if Is_Loc /= No_Location then Error_Msg_SC ("misplaced aspects for package declaration"); Error_Msg ("info: aspect specifications belong here??", Is_Loc); P_Aspect_Specifications (Empty); -- Other cases where aspect specifications are not allowed else P_Aspect_Specifications (Error); end if; -- Aspect specifications allowed else P_Aspect_Specifications (Decl); end if; -- If no aspect specifications, must have a semicolon elsif End_Type /= E_Record then if Token = Tok_Semicolon then T_Semicolon; -- Semicolon is missing. If the missing semicolon is at the end -- of the line, i.e. we are at the start of the line now, then -- a missing semicolon gets flagged, but is not serious enough -- to consider the END statement to be bad in the sense that we -- are dealing with (i.e. to be suspicious that this END is not -- the END statement we are looking for). -- Similarly, if we are at a colon, we flag it but a colon for -- a semicolon is not serious enough to consider the END to be -- incorrect. Same thing for a period in place of a semicolon. elsif Token_Is_At_Start_Of_Line or else Token = Tok_Colon or else Token = Tok_Dot then T_Semicolon; -- If the missing semicolon is not at the start of the line, -- then we consider the END line to be dubious in this sense. else End_OK := False; end if; end if; end if; end if; -- Now we call the Pop_End_Context routine to get a recommendation -- as to what should be done with the END sequence we have scanned. Pop_End_Context; -- Remaining action depends on End_Action set by Pop_End_Context case End_Action is -- Accept_As_Scanned. In this case, Pop_End_Context left Token -- pointing past the last token of a syntactically correct END when Accept_As_Scanned => -- Syntactically correct included the possibility of a missing -- semicolon. If we do have a missing semicolon, then we have -- already given a message, but now we scan out possible rubbish -- on the same line as the END while not Token_Is_At_Start_Of_Line and then Prev_Token /= Tok_Record and then Prev_Token /= Tok_Semicolon and then Token /= Tok_End and then Token /= Tok_EOF loop Scan; -- past junk end loop; return True; -- Insert_And_Accept. In this case, Pop_End_Context has reset Token -- to point to the start of the END sequence, and recommends that it -- be left in place to satisfy an outer scope level END. This means -- that we proceed as though an END were present, and leave the scan -- pointer unchanged. when Insert_And_Accept => return True; -- Skip_And_Accept. In this case, Pop_End_Context has reset Token -- to point to the start of the END sequence. This END sequence is -- syntactically incorrect, and an appropriate error message has -- already been posted. Pop_End_Context recommends accepting the -- END sequence as the one we want, so we skip past it and then -- proceed as though an END were present. when Skip_And_Accept => End_Skip; return True; -- Skip_And_Reject. In this case, Pop_End_Context has reset Token -- to point to the start of the END sequence. This END sequence is -- syntactically incorrect, and an appropriate error message has -- already been posted. Pop_End_Context recommends entirely ignoring -- this END sequence, so we skip past it and then return False, since -- as far as the caller is concerned, no END sequence is present. when Skip_And_Reject => End_Skip; return False; end case; end Check_End; -------------- -- End Skip -- -------------- -- This procedure skips past an END sequence. On entry Token contains -- Tok_End, and we know that the END sequence is syntactically incorrect, -- and that an appropriate error message has already been posted. The -- mission is simply to position the scan pointer to be the best guess of -- the position after the END sequence. We do not issue any additional -- error messages while carrying this out. -- Error recovery: does not raise Error_Resync procedure End_Skip is begin Scan; -- past END -- If the scan past the END leaves us on the next line, that's probably -- where we should quit the scan, since it is likely that what we have -- is a missing semicolon. Consider the following: -- END -- Process_Input; -- This will have looked like a syntactically valid END sequence to the -- initial scan of the END, but subsequent checking will have determined -- that the label Process_Input is not an appropriate label. The real -- error is a missing semicolon after the END, and by leaving the scan -- pointer just past the END, we will improve the error recovery. if Token_Is_At_Start_Of_Line then return; end if; -- If there is a semicolon after the END, scan it out and we are done if Token = Tok_Semicolon then T_Semicolon; return; end if; -- Otherwise skip past a token after the END on the same line. Note -- that we do not eat a token on the following line since it seems -- very unlikely in any case that the END gets separated from its -- token, and we do not want to swallow up a keyword that starts a -- legitimate construct following the bad END. if not Token_Is_At_Start_Of_Line and then -- Cases of normal tokens following an END (Token = Tok_Case or else Token = Tok_If or else Token = Tok_Loop or else Token = Tok_Record or else Token = Tok_Select or else -- Cases of bogus keywords ending loops Token = Tok_For or else Token = Tok_While or else -- Cases of operator symbol names without quotes Token = Tok_Abs or else Token = Tok_And or else Token = Tok_Mod or else Token = Tok_Not or else Token = Tok_Or or else Token = Tok_Xor) then Scan; -- past token after END -- If that leaves us on the next line, then we are done. This is the -- same principle described above for the case of END at line end if Token_Is_At_Start_Of_Line then return; -- If we just scanned out record, then we are done, since the -- semicolon after END RECORD is not part of the END sequence elsif Prev_Token = Tok_Record then return; -- If we have a semicolon, scan it out and we are done elsif Token = Tok_Semicolon then T_Semicolon; return; end if; end if; -- Check for a label present on the same line loop if Token_Is_At_Start_Of_Line then return; end if; if Token /= Tok_Identifier and then Token /= Tok_Operator_Symbol and then Token /= Tok_String_Literal then exit; end if; Scan; -- past identifier, operator symbol or string literal if Token_Is_At_Start_Of_Line then return; elsif Token = Tok_Dot then Scan; -- past dot end if; end loop; -- Skip final semicolon if Token = Tok_Semicolon then T_Semicolon; -- If we don't have a final semicolon, skip until we either encounter -- an END token, or a semicolon or the start of the next line. This -- allows general junk to follow the end line (normally it is hard to -- think that anyone will put anything deliberate here, and remember -- that we know there is a missing semicolon in any case). We also -- quite on an EOF (or else we would get stuck in an infinite loop -- if there is no line end at the end of the last line of the file) else while Token /= Tok_End and then Token /= Tok_EOF and then Token /= Tok_Semicolon and then not Token_Is_At_Start_Of_Line loop Scan; -- past junk token on same line end loop; end if; return; end End_Skip; -------------------- -- End Statements -- -------------------- -- This procedure is called when END is required or expected to terminate -- a sequence of statements. The caller has already made an appropriate -- entry on the scope stack to describe the expected form of the END. -- End_Statements should only be used in cases where the only appropriate -- terminator is END. -- Error recovery: cannot raise Error_Resync; procedure End_Statements (Parent : Node_Id := Empty; Decl : Node_Id := Empty; Is_Sloc : Source_Ptr := No_Location) is begin -- This loop runs more than once in the case where Check_End rejects -- the END sequence, as indicated by Check_End returning False. loop if Check_End (Decl, Is_Sloc) then if Present (Parent) then Set_End_Label (Parent, End_Labl); end if; return; end if; -- Extra statements past the bogus END are discarded. This is not -- ideal for maximum error recovery, but it's too much trouble to -- find an appropriate place to put them. Discard_Junk_List (P_Sequence_Of_Statements (SS_None)); end loop; end End_Statements; ------------------------ -- Evaluate End Entry -- ------------------------ procedure Evaluate_End_Entry (SS_Index : Nat) is STE : Scope_Table_Entry renames Scope.Table (SS_Index); begin Column_OK := (End_Column = STE.Ecol); Token_OK := (End_Type = STE.Etyp or else (End_Type = E_Name and then STE.Etyp >= E_Name)); Label_OK := End_Labl_Present and then (Same_Label (End_Labl, STE.Labl) or else STE.Labl = Error); -- Special case to consider. Suppose we have the suspicious label case, -- e.g. a situation like: -- My_Label; -- declare -- ... -- begin -- ... -- end My_Label; -- This is the case where we want to use the entry in the suspicous -- label table to flag the semicolon saying it should be a colon. -- Label_OK will be false because the label does not match (we have -- My_Label on the end line, and the generated name for the scope). Also -- End_Labl_Present will be True. if not Label_OK and then End_Labl_Present and then not Comes_From_Source (Scope.Table (SS_Index).Labl) then -- Here is where we will search the suspicious labels table for J in 1 .. Suspicious_Labels.Last loop declare SLE : Suspicious_Label_Entry renames Suspicious_Labels.Table (J); begin -- See if character name of label matches if Chars (Name (SLE.Proc_Call)) = Chars (End_Labl) -- And first token of loop/block identifies this entry and then SLE.Start_Token = STE.Sloc then -- We have the special case, issue the error message Error_Msg -- CODEFIX (""";"" should be "":""", SLE.Semicolon_Loc); -- And indicate we consider the Label OK after all Label_OK := True; exit; end if; end; end loop; end if; -- Compute setting of Syntax_OK. We definitely have a syntax error -- if the Token does not match properly or if P_End_Scan detected -- a syntax error such as a missing semicolon. if not Token_OK or not End_OK then Syntax_OK := False; -- Final check is that label is OK. Certainly it is OK if there -- was an exact match on the label (the END label = the stack label) elsif Label_OK then Syntax_OK := True; -- Case of label present elsif End_Labl_Present then -- If probably misspelling, then complain, and pretend it is OK declare Nam : constant Node_Or_Entity_Id := Scope.Table (SS_Index).Labl; begin if Nkind (End_Labl) in N_Has_Chars and then Comes_From_Source (Nam) and then Nkind (Nam) in N_Has_Chars and then Chars (End_Labl) > Error_Name and then Chars (Nam) > Error_Name then Error_Msg_Name_1 := Chars (Nam); if Error_Msg_Name_1 > Error_Name then if Is_Bad_Spelling_Of (Chars (Nam), Chars (End_Labl)) then Error_Msg_Name_1 := Chars (Nam); Error_Msg_N -- CODEFIX ("misspelling of %", End_Labl); Syntax_OK := True; return; end if; end if; end if; end; Syntax_OK := False; -- Otherwise we have cases of no label on the END line. For the loop -- case, this is acceptable only if the loop is unlabeled. elsif End_Type = E_Loop then Syntax_OK := not Explicit_Start_Label (SS_Index); -- Cases where a label is definitely allowed on the END line elsif End_Type = E_Name then Syntax_OK := (not Explicit_Start_Label (SS_Index)) or else (not Scope.Table (SS_Index).Lreq); -- Otherwise we have cases which don't allow labels anyway, so we -- certainly accept an END which does not have a label. else Syntax_OK := True; end if; end Evaluate_End_Entry; -------------------------- -- Explicit_Start_Label -- -------------------------- function Explicit_Start_Label (SS_Index : Nat) return Boolean is L : constant Node_Id := Scope.Table (SS_Index).Labl; Etyp : constant SS_End_Type := Scope.Table (SS_Index).Etyp; begin if No (L) then return False; -- In the following test we protect the call to Comes_From_Source -- against lines containing previously reported syntax errors. elsif (Etyp = E_Loop or else Etyp = E_Name or else Etyp = E_Suspicious_Is or else Etyp = E_Bad_Is) and then Comes_From_Source (L) then return True; else return False; end if; end Explicit_Start_Label; ------------------------ -- Output_End_Deleted -- ------------------------ procedure Output_End_Deleted is begin if End_Type = E_Loop then Error_Msg_SC ("no LOOP for this `END LOOP`!"); elsif End_Type = E_Case then Error_Msg_SC ("no CASE for this `END CASE`"); elsif End_Type = E_If then Error_Msg_SC ("no IF for this `END IF`!"); elsif End_Type = E_Record then Error_Msg_SC ("no RECORD for this `END RECORD`!"); elsif End_Type = E_Return then Error_Msg_SC ("no RETURN for this `END RETURN`!"); elsif End_Type = E_Select then Error_Msg_SC ("no SELECT for this `END SELECT`!"); else Error_Msg_SC ("no BEGIN for this END!"); end if; end Output_End_Deleted; ------------------------- -- Output_End_Expected -- ------------------------- procedure Output_End_Expected (Ins : Boolean) is End_Type : SS_End_Type; begin -- Suppress message if this was a potentially junk entry (e.g. a record -- entry where no record keyword was present). if Scope.Table (Scope.Last).Junk then return; end if; End_Type := Scope.Table (Scope.Last).Etyp; Error_Msg_Col := Scope.Table (Scope.Last).Ecol; Error_Msg_Sloc := Scope.Table (Scope.Last).Sloc; if Explicit_Start_Label (Scope.Last) then Error_Msg_Node_1 := Scope.Table (Scope.Last).Labl; else Error_Msg_Node_1 := Empty; end if; -- Suppress message if error was posted on opening label if Error_Msg_Node_1 > Empty_Or_Error and then Error_Posted (Error_Msg_Node_1) then return; end if; if End_Type = E_Case then Error_Msg_SC -- CODEFIX ("`END CASE;` expected@ for CASE#!"); elsif End_Type = E_If then Error_Msg_SC -- CODEFIX ("`END IF;` expected@ for IF#!"); elsif End_Type = E_Loop then if Error_Msg_Node_1 = Empty then Error_Msg_SC -- CODEFIX ("`END LOOP;` expected@ for LOOP#!"); else Error_Msg_SC -- CODEFIX ("`END LOOP &;` expected@!"); end if; elsif End_Type = E_Record then Error_Msg_SC -- CODEFIX ("`END RECORD;` expected@ for RECORD#!"); elsif End_Type = E_Return then Error_Msg_SC -- CODEFIX ("`END RETURN;` expected@ for RETURN#!"); elsif End_Type = E_Select then Error_Msg_SC -- CODEFIX ("`END SELECT;` expected@ for SELECT#!"); -- All remaining cases are cases with a name (we do not treat the -- suspicious is cases specially for a replaced end, only for an -- inserted end). elsif End_Type = E_Name or else not Ins then if Error_Msg_Node_1 = Empty then Error_Msg_SC -- CODEFIX ("`END;` expected@ for BEGIN#!"); else Error_Msg_SC -- CODEFIX ("`END &;` expected@!"); end if; -- The other possibility is a missing END for a subprogram with a -- suspicious IS (that probably should have been a semicolon). The -- missing IS confirms the suspicion. else -- End_Type = E_Suspicious_Is or E_Bad_Is Scope.Table (Scope.Last).Etyp := E_Bad_Is; end if; end Output_End_Expected; ------------------------ -- Output_End_Missing -- ------------------------ procedure Output_End_Missing is End_Type : SS_End_Type; begin -- Suppress message if this was a potentially junk entry (e.g. a record -- entry where no record keyword was present). if Scope.Table (Scope.Last).Junk then return; end if; End_Type := Scope.Table (Scope.Last).Etyp; Error_Msg_Sloc := Scope.Table (Scope.Last).Sloc; if Explicit_Start_Label (Scope.Last) then Error_Msg_Node_1 := Scope.Table (Scope.Last).Labl; else Error_Msg_Node_1 := Empty; end if; if End_Type = E_Case then Error_Msg_BC ("missing `END CASE;` for CASE#!"); elsif End_Type = E_If then Error_Msg_BC ("missing `END IF;` for IF#!"); elsif End_Type = E_Loop then if Error_Msg_Node_1 = Empty then Error_Msg_BC ("missing `END LOOP;` for LOOP#!"); else Error_Msg_BC ("missing `END LOOP &;`!"); end if; elsif End_Type = E_Record then Error_Msg_SC ("missing `END RECORD;` for RECORD#!"); elsif End_Type = E_Return then Error_Msg_SC ("missing `END RETURN;` for RETURN#!"); elsif End_Type = E_Select then Error_Msg_BC ("missing `END SELECT;` for SELECT#!"); elsif End_Type = E_Name then if Error_Msg_Node_1 = Empty then Error_Msg_BC ("missing `END;` for BEGIN#!"); else Error_Msg_BC ("missing `END &;`!"); end if; else -- End_Type = E_Suspicious_Is or E_Bad_Is Scope.Table (Scope.Last).Etyp := E_Bad_Is; end if; end Output_End_Missing; --------------------- -- Pop_End_Context -- --------------------- procedure Pop_End_Context is Pretty_Good : Boolean; -- This flag is set True if the END sequence is syntactically incorrect, -- but is (from a heuristic point of view), pretty likely to be simply -- a misspelling of the intended END. Outer_Match : Boolean; -- This flag is set True if we decide that the current END sequence -- belongs to some outer level entry in the scope stack, and thus -- we will NOT eat it up in matching the current expected END. begin -- If not at END, then output END expected message if End_Type = E_Dummy then Output_End_Missing; Pop_Scope_Stack; End_Action := Insert_And_Accept; return; -- Otherwise we do have an END present else -- A special check. If we have END; followed by an end of file, -- WITH or SEPARATE, then if we are not at the outer level, then -- we have a syntax error. Consider the example: -- ... -- declare -- X : Integer; -- begin -- X := Father (A); -- Process (X, X); -- end; -- with Package1; -- ... -- Now the END; here is a syntactically correct closer for the -- declare block, but if we eat it up, then we obviously have -- a missing END for the outer context (since WITH can only appear -- at the outer level. -- In this situation, we always reserve the END; for the outer level, -- even if it is in the wrong column. This is because it's much more -- useful to have the error message point to the DECLARE than to the -- package header in this case. -- We also reserve an end with a name before the end of file if the -- name is the one we expect at the outer level. if (Token = Tok_EOF or else Token = Tok_With or else Token = Tok_Separate) and then End_Type >= E_Name and then (not End_Labl_Present or else Same_Label (End_Labl, Scope.Table (1).Labl)) and then Scope.Last > 1 then Restore_Scan_State (Scan_State); -- to END Output_End_Expected (Ins => True); Pop_Scope_Stack; End_Action := Insert_And_Accept; return; end if; -- Otherwise we go through the normal END evaluation procedure Evaluate_End_Entry (Scope.Last); -- If top entry in stack is syntactically correct, then we have -- scanned it out and everything is fine. This is the required -- action to properly process correct Ada programs. if Syntax_OK then -- Complain if checking columns and END is not in right column. -- Right in this context means exactly right, or on the same -- line as the opener. if RM_Column_Check then if End_Column /= Scope.Table (Scope.Last).Ecol and then Current_Line_Start > Scope.Table (Scope.Last).Sloc -- A special case, for END RECORD, we are also allowed to -- line up with the TYPE keyword opening the declaration. and then (Scope.Table (Scope.Last).Etyp /= E_Record or else Get_Column_Number (End_Sloc) /= Get_Column_Number (Type_Token_Location)) then Error_Msg_Col := Scope.Table (Scope.Last).Ecol; Error_Msg ("(style) END in wrong column, should be@", End_Sloc); end if; end if; -- One final check. If the end had a label, check for an exact -- duplicate of this end sequence, and if so, skip it with an -- appropriate message. if End_Labl_Present and then Token = Tok_End then declare Scan_State : Saved_Scan_State; End_Loc : constant Source_Ptr := Token_Ptr; Nxt_Labl : Node_Id; Dup_Found : Boolean := False; begin Save_Scan_State (Scan_State); Scan; -- past END if Token = Tok_Identifier or else Token = Tok_Operator_Symbol then Nxt_Labl := P_Designator; -- We only consider it an error if the label is a match -- and would be wrong for the level one above us, and -- the indentation is the same. if Token = Tok_Semicolon and then Same_Label (End_Labl, Nxt_Labl) and then End_Column = Start_Column and then (Scope.Last = 1 or else (not Explicit_Start_Label (Scope.Last - 1)) or else (not Same_Label (End_Labl, Scope.Table (Scope.Last - 1).Labl))) then T_Semicolon; Error_Msg ("duplicate end line ignored", End_Loc); Dup_Found := True; end if; end if; if not Dup_Found then Restore_Scan_State (Scan_State); end if; end; end if; -- All OK, so return to caller indicating END is OK Pop_Scope_Stack; End_Action := Accept_As_Scanned; return; end if; -- If that check failed, then we definitely have an error. The issue -- is how to choose among three possible courses of action: -- 1. Ignore the current END text completely, scanning past it, -- deciding that it belongs neither to the current context, -- nor to any outer context. -- 2. Accept the current END text, scanning past it, and issuing -- an error message that it does not have the right form. -- 3. Leave the current END text in place, NOT scanning past it, -- issuing an error message indicating the END expected for the -- current context. In this case, the END is available to match -- some outer END context. -- From a correct functioning point of view, it does not make any -- difference which of these three approaches we take, the program -- will work correctly in any case. However, making an accurate -- choice among these alternatives, i.e. choosing the one that -- corresponds to what the programmer had in mind, does make a -- significant difference in the quality of error recovery. Restore_Scan_State (Scan_State); -- to END -- First we see how good the current END entry is with respect to -- what we expect. It is considered pretty good if the token is OK, -- and either the label or the column matches. An END for RECORD is -- always considered to be pretty good in the record case. This is -- because not only does a record disallow a nested structure, but -- also it is unlikely that such nesting could occur by accident. Pretty_Good := (Token_OK and (Column_OK or Label_OK)) or else Scope.Table (Scope.Last).Etyp = E_Record; -- Next check, if there is a deeper entry in the stack which -- has a very high probability of being acceptable, then insert -- the END entry we want, leaving the higher level entry for later for J in reverse 1 .. Scope.Last - 1 loop Evaluate_End_Entry (J); -- To even consider the deeper entry to be immediately acceptable, -- it must be syntactically correct. Furthermore it must either -- have a correct label, or the correct column. If the current -- entry was a close match (Pretty_Good set), then we are even -- more strict in accepting the outer level one: even if it has -- the right label, it must have the right column as well. if Syntax_OK then if Pretty_Good then Outer_Match := Label_OK and Column_OK; else Outer_Match := Label_OK or Column_OK; end if; else Outer_Match := False; end if; -- If the outer entry does convincingly match the END text, then -- back up the scan to the start of the END sequence, issue an -- error message indicating the END we expected, and return with -- Token pointing to the END (case 3 from above discussion). if Outer_Match then Output_End_Missing; Pop_Scope_Stack; End_Action := Insert_And_Accept; return; end if; end loop; -- Here we have a situation in which the current END entry is -- syntactically incorrect, but there is no deeper entry in the -- END stack which convincingly matches it. -- If the END text was judged to be a Pretty_Good match for the -- expected token or if it appears left of the expected column, -- then we will accept it as the one we want, scanning past it, even -- though it is not completely right (we issue a message showing what -- we expected it to be). This is action 2 from the discussion above. -- There is one other special case to consider: the LOOP case. -- Consider the example: -- Lbl: loop -- null; -- end loop; -- Here the column lines up with Lbl, so END LOOP is to the right, -- but it is still acceptable. LOOP is the one case where alignment -- practices vary substantially in practice. if Pretty_Good or else End_Column <= Scope.Table (Scope.Last).Ecol or else (End_Type = Scope.Table (Scope.Last).Etyp and then End_Type = E_Loop) then Output_End_Expected (Ins => False); Pop_Scope_Stack; End_Action := Skip_And_Accept; return; -- Here we have the case where the END is to the right of the -- expected column and does not have a correct label to convince -- us that it nevertheless belongs to the current scope. For this -- we consider that it probably belongs not to the current context, -- but to some inner context that was not properly recognized (due to -- other syntax errors), and for which no proper scope stack entry -- was made. The proper action in this case is to delete the END text -- and return False to the caller as a signal to keep on looking for -- an acceptable END. This is action 1 from the discussion above. else Output_End_Deleted; End_Action := Skip_And_Reject; return; end if; end if; end Pop_End_Context; ---------------- -- Same_Label -- ---------------- function Same_Label (Label1, Label2 : Node_Id) return Boolean is begin if Nkind (Label1) in N_Has_Chars and then Nkind (Label2) in N_Has_Chars then return Chars (Label1) = Chars (Label2); elsif Nkind (Label1) = N_Selected_Component and then Nkind (Label2) = N_Selected_Component then return Same_Label (Prefix (Label1), Prefix (Label2)) and then Same_Label (Selector_Name (Label1), Selector_Name (Label2)); elsif Nkind (Label1) = N_Designator and then Nkind (Label2) = N_Defining_Program_Unit_Name then return Same_Label (Name (Label1), Name (Label2)) and then Same_Label (Identifier (Label1), Defining_Identifier (Label2)); else return False; end if; end Same_Label; end Endh;
------------------------------------------------------------------------------ -- -- -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS -- -- -- -- S Y S T E M - S T A C K _ U S A G E -- -- -- -- B o d y -- -- -- -- Copyright (C) 2004-2020, Free Software Foundation, Inc. -- -- -- -- GNARL is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNARL was developed by the GNARL team at Florida State University. -- -- Extensive contributions were provided by Ada Core Technologies, Inc. -- -- -- ------------------------------------------------------------------------------ with System.Parameters; with System.CRTL; with System.IO; package body System.Stack_Usage is use System.Storage_Elements; use System.IO; use Interfaces; ----------------- -- Stack_Slots -- ----------------- -- Stack_Slots is an internal data type to represent a sequence of real -- stack slots initialized with a provided pattern, with operations to -- abstract away the target call stack growth direction. type Stack_Slots is array (Integer range <>) of Pattern_Type; for Stack_Slots'Component_Size use Pattern_Type'Object_Size; -- We will carefully handle the initializations ourselves and might want -- to remap an initialized overlay later on with an address clause. pragma Suppress_Initialization (Stack_Slots); -- The abstract Stack_Slots operations all operate over the simple array -- memory model: -- memory addresses increasing ----> -- Slots('First) Slots('Last) -- | | -- V V -- +------------------------------------------------------------------+ -- |####| |####| -- +------------------------------------------------------------------+ -- What we call Top or Bottom always denotes call chain leaves or entry -- points respectively, and their relative positions in the stack array -- depends on the target stack growth direction: -- Stack_Grows_Down -- <----- calls push frames towards decreasing addresses -- Top(most) Slot Bottom(most) Slot -- | | -- V V -- +------------------------------------------------------------------+ -- |####| | leaf frame | ... | entry frame | -- +------------------------------------------------------------------+ -- Stack_Grows_Up -- calls push frames towards increasing addresses -----> -- Bottom(most) Slot Top(most) Slot -- | | -- V V -- +------------------------------------------------------------------+ -- | entry frame | ... | leaf frame | |####| -- +------------------------------------------------------------------+ ------------------- -- Unit Services -- ------------------- -- Now the implementation of the services offered by this unit, on top of -- the Stack_Slots abstraction above. Index_Str : constant String := "Index"; Task_Name_Str : constant String := "Task Name"; Stack_Size_Str : constant String := "Stack Size"; Actual_Size_Str : constant String := "Stack usage"; procedure Output_Result (Result_Id : Natural; Result : Task_Result; Max_Stack_Size_Len : Natural; Max_Actual_Use_Len : Natural); -- Prints the result on the standard output. Result Id is the number of -- the result in the array, and Result the contents of the actual result. -- Max_Stack_Size_Len and Max_Actual_Use_Len are used for displaying the -- proper layout. They hold the maximum length of the string representing -- the Stack_Size and Actual_Use values. ---------------- -- Initialize -- ---------------- procedure Initialize (Buffer_Size : Natural) is Stack_Size_Chars : System.Address; begin -- Initialize the buffered result array Result_Array := new Result_Array_Type (1 .. Buffer_Size); Result_Array.all := (others => (Task_Name => (others => ASCII.NUL), Value => 0, Stack_Size => 0)); -- Set the Is_Enabled flag to true, so that the task wrapper knows that -- it has to handle dynamic stack analysis Is_Enabled := True; Stack_Size_Chars := System.CRTL.getenv ("GNAT_STACK_LIMIT" & ASCII.NUL); -- If variable GNAT_STACK_LIMIT is set, then we will take care of the -- environment task, using GNAT_STASK_LIMIT as the size of the stack. -- It doesn't make sens to process the stack when no bound is set (e.g. -- limit is typically up to 4 GB). if Stack_Size_Chars /= Null_Address then declare My_Stack_Size : Integer; begin My_Stack_Size := System.CRTL.atoi (Stack_Size_Chars) * 1024; Initialize_Analyzer (Environment_Task_Analyzer, "ENVIRONMENT TASK", My_Stack_Size, 0, My_Stack_Size); Fill_Stack (Environment_Task_Analyzer); Compute_Environment_Task := True; end; -- GNAT_STACK_LIMIT not set else Compute_Environment_Task := False; end if; end Initialize; ---------------- -- Fill_Stack -- ---------------- procedure Fill_Stack (Analyzer : in out Stack_Analyzer) is -- Change the local variables and parameters of this function with -- super-extra care. The more the stack frame size of this function is -- big, the more an "instrumentation threshold at writing" error is -- likely to happen. Current_Stack_Level : aliased Integer; Guard : constant := 256; -- Guard space between the Current_Stack_Level'Address and the last -- allocated byte on the stack. begin if Parameters.Stack_Grows_Down then if Analyzer.Stack_Base - Stack_Address (Analyzer.Pattern_Size) > To_Stack_Address (Current_Stack_Level'Address) - Guard then -- No room for a pattern Analyzer.Pattern_Size := 0; return; end if; Analyzer.Pattern_Limit := Analyzer.Stack_Base - Stack_Address (Analyzer.Pattern_Size); if Analyzer.Stack_Base > To_Stack_Address (Current_Stack_Level'Address) - Guard then -- Reduce pattern size to prevent local frame overwrite Analyzer.Pattern_Size := Integer (To_Stack_Address (Current_Stack_Level'Address) - Guard - Analyzer.Pattern_Limit); end if; Analyzer.Pattern_Overlay_Address := To_Address (Analyzer.Pattern_Limit); else if Analyzer.Stack_Base + Stack_Address (Analyzer.Pattern_Size) < To_Stack_Address (Current_Stack_Level'Address) + Guard then -- No room for a pattern Analyzer.Pattern_Size := 0; return; end if; Analyzer.Pattern_Limit := Analyzer.Stack_Base + Stack_Address (Analyzer.Pattern_Size); if Analyzer.Stack_Base < To_Stack_Address (Current_Stack_Level'Address) + Guard then -- Reduce pattern size to prevent local frame overwrite Analyzer.Pattern_Size := Integer (Analyzer.Pattern_Limit - (To_Stack_Address (Current_Stack_Level'Address) + Guard)); end if; Analyzer.Pattern_Overlay_Address := To_Address (Analyzer.Pattern_Limit - Stack_Address (Analyzer.Pattern_Size)); end if; -- Declare and fill the pattern buffer declare Pattern : aliased Stack_Slots (1 .. Analyzer.Pattern_Size / Bytes_Per_Pattern); for Pattern'Address use Analyzer.Pattern_Overlay_Address; begin if System.Parameters.Stack_Grows_Down then for J in reverse Pattern'Range loop Pattern (J) := Analyzer.Pattern; end loop; else for J in Pattern'Range loop Pattern (J) := Analyzer.Pattern; end loop; end if; end; end Fill_Stack; ------------------------- -- Initialize_Analyzer -- ------------------------- procedure Initialize_Analyzer (Analyzer : in out Stack_Analyzer; Task_Name : String; Stack_Size : Natural; Stack_Base : Stack_Address; Pattern_Size : Natural; Pattern : Interfaces.Unsigned_32 := 16#DEAD_BEEF#) is begin -- Initialize the analyzer fields Analyzer.Stack_Base := Stack_Base; Analyzer.Stack_Size := Stack_Size; Analyzer.Pattern_Size := Pattern_Size; Analyzer.Pattern := Pattern; Analyzer.Result_Id := Next_Id; Analyzer.Task_Name := (others => ' '); -- Compute the task name, and truncate if bigger than Task_Name_Length if Task_Name'Length <= Task_Name_Length then Analyzer.Task_Name (1 .. Task_Name'Length) := Task_Name; else Analyzer.Task_Name := Task_Name (Task_Name'First .. Task_Name'First + Task_Name_Length - 1); end if; Next_Id := Next_Id + 1; end Initialize_Analyzer; ---------------- -- Stack_Size -- ---------------- function Stack_Size (SP_Low : Stack_Address; SP_High : Stack_Address) return Natural is begin if SP_Low > SP_High then return Natural (SP_Low - SP_High); else return Natural (SP_High - SP_Low); end if; end Stack_Size; -------------------- -- Compute_Result -- -------------------- procedure Compute_Result (Analyzer : in out Stack_Analyzer) is -- Change the local variables and parameters of this function with -- super-extra care. The larger the stack frame size of this function -- is, the more an "instrumentation threshold at reading" error is -- likely to happen. Stack : Stack_Slots (1 .. Analyzer.Pattern_Size / Bytes_Per_Pattern); for Stack'Address use Analyzer.Pattern_Overlay_Address; begin -- Value if the pattern was not modified if Parameters.Stack_Grows_Down then Analyzer.Topmost_Touched_Mark := Analyzer.Pattern_Limit + Stack_Address (Analyzer.Pattern_Size); else Analyzer.Topmost_Touched_Mark := Analyzer.Pattern_Limit - Stack_Address (Analyzer.Pattern_Size); end if; if Analyzer.Pattern_Size = 0 then return; end if; -- Look backward from the topmost possible end of the marked stack to -- the bottom of it. The first index not equals to the patterns marks -- the beginning of the used stack. if System.Parameters.Stack_Grows_Down then for J in Stack'Range loop if Stack (J) /= Analyzer.Pattern then Analyzer.Topmost_Touched_Mark := To_Stack_Address (Stack (J)'Address); exit; end if; end loop; else for J in reverse Stack'Range loop if Stack (J) /= Analyzer.Pattern then Analyzer.Topmost_Touched_Mark := To_Stack_Address (Stack (J)'Address); exit; end if; end loop; end if; end Compute_Result; --------------------- -- Output_Result -- --------------------- procedure Output_Result (Result_Id : Natural; Result : Task_Result; Max_Stack_Size_Len : Natural; Max_Actual_Use_Len : Natural) is Result_Id_Str : constant String := Natural'Image (Result_Id); Stack_Size_Str : constant String := Natural'Image (Result.Stack_Size); Actual_Use_Str : constant String := Natural'Image (Result.Value); Result_Id_Blanks : constant String (1 .. Index_Str'Length - Result_Id_Str'Length) := (others => ' '); Stack_Size_Blanks : constant String (1 .. Max_Stack_Size_Len - Stack_Size_Str'Length) := (others => ' '); Actual_Use_Blanks : constant String (1 .. Max_Actual_Use_Len - Actual_Use_Str'Length) := (others => ' '); begin Set_Output (Standard_Error); Put (Result_Id_Blanks & Natural'Image (Result_Id)); Put (" | "); Put (Result.Task_Name); Put (" | "); Put (Stack_Size_Blanks & Stack_Size_Str); Put (" | "); Put (Actual_Use_Blanks & Actual_Use_Str); New_Line; end Output_Result; --------------------- -- Output_Results -- --------------------- procedure Output_Results is Max_Stack_Size : Natural := 0; Max_Stack_Usage : Natural := 0; Max_Stack_Size_Len, Max_Actual_Use_Len : Natural := 0; Task_Name_Blanks : constant String (1 .. Task_Name_Length - Task_Name_Str'Length) := (others => ' '); begin Set_Output (Standard_Error); if Compute_Environment_Task then Compute_Result (Environment_Task_Analyzer); Report_Result (Environment_Task_Analyzer); end if; if Result_Array'Length > 0 then -- Computes the size of the largest strings that will get displayed, -- in order to do correct column alignment. for J in Result_Array'Range loop exit when J >= Next_Id; if Result_Array (J).Value > Max_Stack_Usage then Max_Stack_Usage := Result_Array (J).Value; end if; if Result_Array (J).Stack_Size > Max_Stack_Size then Max_Stack_Size := Result_Array (J).Stack_Size; end if; end loop; Max_Stack_Size_Len := Natural'Image (Max_Stack_Size)'Length; Max_Actual_Use_Len := Natural'Image (Max_Stack_Usage)'Length; -- Display the output header. Blanks will be added in front of the -- labels if needed. declare Stack_Size_Blanks : constant String (1 .. Max_Stack_Size_Len - Stack_Size_Str'Length) := (others => ' '); Stack_Usage_Blanks : constant String (1 .. Max_Actual_Use_Len - Actual_Size_Str'Length) := (others => ' '); begin if Stack_Size_Str'Length > Max_Stack_Size_Len then Max_Stack_Size_Len := Stack_Size_Str'Length; end if; if Actual_Size_Str'Length > Max_Actual_Use_Len then Max_Actual_Use_Len := Actual_Size_Str'Length; end if; Put (Index_Str & " | " & Task_Name_Str & Task_Name_Blanks & " | " & Stack_Size_Str & Stack_Size_Blanks & " | " & Stack_Usage_Blanks & Actual_Size_Str); end; New_Line; -- Now display the individual results for J in Result_Array'Range loop exit when J >= Next_Id; Output_Result (J, Result_Array (J), Max_Stack_Size_Len, Max_Actual_Use_Len); end loop; -- Case of no result stored, still display the labels else Put (Index_Str & " | " & Task_Name_Str & Task_Name_Blanks & " | " & Stack_Size_Str & " | " & Actual_Size_Str); New_Line; end if; end Output_Results; ------------------- -- Report_Result -- ------------------- procedure Report_Result (Analyzer : Stack_Analyzer) is Result : Task_Result := (Task_Name => Analyzer.Task_Name, Stack_Size => Analyzer.Stack_Size, Value => 0); begin if Analyzer.Pattern_Size = 0 then -- If we have that result, it means that we didn't do any computation -- at all (i.e. we used at least everything (and possibly more). Result.Value := Analyzer.Stack_Size; else Result.Value := Stack_Size (Analyzer.Topmost_Touched_Mark, Analyzer.Stack_Base); end if; if Analyzer.Result_Id in Result_Array'Range then -- If the result can be stored, then store it in Result_Array Result_Array (Analyzer.Result_Id) := Result; else -- If the result cannot be stored, then we display it right away declare Result_Str_Len : constant Natural := Natural'Image (Result.Value)'Length; Size_Str_Len : constant Natural := Natural'Image (Analyzer.Stack_Size)'Length; Max_Stack_Size_Len : Natural; Max_Actual_Use_Len : Natural; begin -- Take either the label size or the number image size for the -- size of the column "Stack Size". Max_Stack_Size_Len := (if Size_Str_Len > Stack_Size_Str'Length then Size_Str_Len else Stack_Size_Str'Length); -- Take either the label size or the number image size for the -- size of the column "Stack Usage". Max_Actual_Use_Len := (if Result_Str_Len > Actual_Size_Str'Length then Result_Str_Len else Actual_Size_Str'Length); Output_Result (Analyzer.Result_Id, Result, Max_Stack_Size_Len, Max_Actual_Use_Len); end; end if; end Report_Result; end System.Stack_Usage;
with Ada.Task_Identification; use Ada.Task_Identification; procedure Main is -- Create as many task objects as your program needs begin -- whatever logic is required in your Main procedure if some_condition then Abort_Task (Current_Task); end if; end Main;
pragma License (Unrestricted); generic type Real is digits <>; package Ada.Numerics.Generic_Real_Arrays is pragma Pure; -- Types type Real_Vector is array (Integer range <>) of Real'Base; for Real_Vector'Alignment use Standard'Maximum_Alignment; type Real_Matrix is array (Integer range <>, Integer range <>) of Real'Base; for Real_Matrix'Alignment use Standard'Maximum_Alignment; -- Subprograms for Real_Vector types -- Real_Vector arithmetic operations function "+" (Right : Real_Vector) return Real_Vector; function "-" (Right : Real_Vector) return Real_Vector; function "abs" (Right : Real_Vector) return Real_Vector; function "+" (Left, Right : Real_Vector) return Real_Vector; function "-" (Left, Right : Real_Vector) return Real_Vector; function "*" (Left, Right : Real_Vector) return Real'Base; function "abs" (Right : Real_Vector) return Real'Base; -- Real_Vector scaling operations function "*" (Left : Real'Base; Right : Real_Vector) return Real_Vector; function "*" (Left : Real_Vector; Right : Real'Base) return Real_Vector; function "/" (Left : Real_Vector; Right : Real'Base) return Real_Vector; -- Other Real_Vector operations function Unit_Vector ( Index : Integer; Order : Positive; First : Integer := 1) return Real_Vector; -- Subprograms for Real_Matrix types -- Real_Matrix arithmetic operations function "+" (Right : Real_Matrix) return Real_Matrix; function "-" (Right : Real_Matrix) return Real_Matrix; function "abs" (Right : Real_Matrix) return Real_Matrix; function Transpose (X : Real_Matrix) return Real_Matrix; function "+" (Left, Right : Real_Matrix) return Real_Matrix; function "-" (Left, Right : Real_Matrix) return Real_Matrix; function "*" (Left, Right : Real_Matrix) return Real_Matrix; function "*" (Left, Right : Real_Vector) return Real_Matrix; function "*" (Left : Real_Vector; Right : Real_Matrix) return Real_Vector; function "*" (Left : Real_Matrix; Right : Real_Vector) return Real_Vector; -- Real_Matrix scaling operations function "*" (Left : Real'Base; Right : Real_Matrix) return Real_Matrix; function "*" (Left : Real_Matrix; Right : Real'Base) return Real_Matrix; function "/" (Left : Real_Matrix; Right : Real'Base) return Real_Matrix; -- Real_Matrix inversion and related operations function Solve (A : Real_Matrix; X : Real_Vector) return Real_Vector; function Solve (A, X : Real_Matrix) return Real_Matrix; function Inverse (A : Real_Matrix) return Real_Matrix; function Determinant (A : Real_Matrix) return Real'Base; -- Eigenvalues and vectors of a real symmetric matrix function Eigenvalues (A : Real_Matrix) return Real_Vector; procedure Eigensystem ( A : Real_Matrix; Values : out Real_Vector; Vectors : out Real_Matrix); -- Other Real_Matrix operations function Unit_Matrix (Order : Positive; First_1, First_2 : Integer := 1) return Real_Matrix; end Ada.Numerics.Generic_Real_Arrays;
-- { dg-do compile } with Pack3_Pkg; package Pack3 is subtype N_TYPE is INTEGER range 0..5; type LIST_ARRAY is array (N_TYPE range <>) of INTEGER; type LIST (N : N_TYPE := 0) is record LIST : LIST_ARRAY(1..N); end record; pragma PACK(LIST); subtype CS is STRING(1..Pack3_Pkg.F); type CSA is array (NATURAL range <>) of CS; type REC is record I1, I2 : INTEGER; end record ; type CMD is (CO, AS); type CMD_BLOCK_TYPE (D : CMD := CO) is record N : CSA (1..4); case D is when CO => L : LIST; when AS => R : REC; end case ; end record; pragma PACK(CMD_BLOCK_TYPE); type CMD_TYPE is (RIGHT, WRONG); type CMD_RESULT (D : CMD_TYPE) is record case D is when RIGHT => C : CMD_BLOCK_TYPE; when WRONG => null; end case; end record ; pragma PACK(CMD_RESULT); end Pack3;
-- smart_ptrs.adb -- A reference-counted "smart pointer" type similar to that in C++ -- Copyright (c) 2016, James Humphry -- -- Permission to use, copy, modify, and/or distribute this software for any -- purpose with or without fee is hereby granted, provided that the above -- copyright notice and this permission notice appear in all copies. -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -- PERFORMANCE OF THIS SOFTWARE. pragma Profile (No_Implementation_Extensions); with Ada.Unchecked_Deallocation; with Ada.Unchecked_Conversion; package body Smart_Ptrs is -- * -- * Internal implementation definitions -- * procedure Deallocate_T is new Ada.Unchecked_Deallocation (Object => T, Name => T_Ptr); type Access_T is not null access all T; function Access_T_to_T_Ptr is new Ada.Unchecked_Conversion (Source => Access_T, Target => T_Ptr); -- * -- * Public routines -- * --------------- -- Smart_Ptr -- --------------- function P (S : in Smart_Ptr) return T_Ref is (T_Ref'(Element => S.Element)); function Get (S : in Smart_Ptr) return T_Ptr is (S.Element); function Make_Smart_Ptr (X : T_Ptr) return Smart_Ptr is (Smart_Ptr'(Ada.Finalization.Controlled with Element => X, Counter => (if X = null then null else Make_New_Counter ) ) ); function Make_Smart_Ptr (S : Smart_Ref) return Smart_Ptr is begin pragma Assert (Check => S.Counter /= null, Message => "Attempting to make a Smart_Ptr from an invalid Smart_Ref"); Check_Increment_Use_Count(S.Counter.all); -- As we ensure Smart_Ref is always made from a T_Ptr, the unchecked -- reverse conversion is always safe. return Smart_Ptr'(Ada.Finalization.Controlled with Element => Access_T_to_T_Ptr(S.Element), Counter => S.Counter); end Make_Smart_Ptr; function Use_Count (S : in Smart_Ptr) return Natural is (if S.Is_Null then 1 else Use_Count(S.Counter.all)); function Weak_Ptr_Count (S : in Smart_Ptr) return Natural is (if S.Is_Null then 0 else Weak_Ptr_Count(S.Counter.all)); function Is_Null (S : in Smart_Ptr) return Boolean is (S.Element = null and S.Counter = null); function Get (S : in Smart_Ref) return T_Ptr is (Access_T_to_T_Ptr(S.Element)); --------------- -- Smart_Ref -- --------------- function Make_Smart_Ref (X : T_Ptr) return Smart_Ref is begin return Smart_Ref'(Ada.Finalization.Controlled with Element => X, Counter => Make_New_Counter ); end Make_Smart_Ref; function Make_Smart_Ref (S : Smart_Ptr'Class) return Smart_Ref is begin Check_Increment_Use_Count(S.Counter.all); return Smart_Ref'(Ada.Finalization.Controlled with Element => S.Element, Counter => S.Counter); end Make_Smart_Ref; function Use_Count (S : in Smart_Ref) return Natural is (Use_Count(S.Counter.all)); function Weak_Ptr_Count (S : in Smart_Ref) return Natural is (Weak_Ptr_Count(S.Counter.all)); -------------- -- Weak_Ptr -- -------------- function Make_Weak_Ptr (S : in Smart_Ptr'Class) return Weak_Ptr is begin Increment_Weak_Ptr_Count(S.Counter.all); return Weak_Ptr' (Ada.Finalization.Controlled with Element => S.Element, Counter => S.Counter); end Make_Weak_Ptr; function Make_Weak_Ptr (S : in Smart_Ref'Class) return Weak_Ptr is begin Increment_Weak_Ptr_Count(S.Counter.all); return Weak_Ptr' (Ada.Finalization.Controlled with Element => Access_T_to_T_Ptr(S.Element), Counter => S.Counter); end Make_Weak_Ptr; function Use_Count (W : in Weak_Ptr) return Natural is (Use_Count(W.Counter.all)); function Weak_Ptr_Count (W : in Weak_Ptr) return Natural is (Weak_Ptr_Count(W.Counter.all)); function Expired (W : in Weak_Ptr) return Boolean is (Use_Count(W.Counter.all) = 0); function Lock (W : in Weak_Ptr'Class) return Smart_Ptr is begin Check_Increment_Use_Count(W.Counter.all); if Use_Count(W.Counter.all) = 0 then raise Smart_Ptr_Error with "Attempt to lock an expired Weak_Ptr."; end if; -- The increment will only work if the Use_Count was > 0, and it ensures -- that if the target Element existed at that point, it cannot be -- destroyed after the check but before the new Smart_Ptr is created, -- as the Use_Count will not drop below zero. return Smart_Ptr' (Ada.Finalization.Controlled with Element => W.Element, Counter => W.Counter); end Lock; function Lock (W : in Weak_Ptr'Class) return Smart_Ref is begin Check_Increment_Use_Count(W.Counter.all); if Use_Count(W.Counter.all) = 0 then raise Smart_Ptr_Error with "Attempt to lock an expired Weak_Ptr."; end if; -- The increment will only work if the Use_Count was > 0, and it ensures -- that if the target Element existed at that point, it cannot be -- destroyed after the check but before the new Smart_Ptr is created, -- as the Use_Count will not drop below zero. return Smart_Ref' (Ada.Finalization.Controlled with Element => W.Element, Counter => W.Counter); end Lock; function Lock_Or_Null (W : in Weak_Ptr'Class) return Smart_Ptr is begin Check_Increment_Use_Count(W.Counter.all); if Use_Count(W.Counter.all) = 0 then return Null_Smart_Ptr; end if; -- The increment will only work if the Use_Count was > 0, and it ensures -- that if the target Element existed at that point, it cannot be -- destroyed after the check but before the new Smart_Ptr is created, -- as the Use_Count will not drop below zero. return Smart_Ptr' (Ada.Finalization.Controlled with Element => W.Element, Counter => W.Counter); end Lock_Or_Null; -- * -- * Private routines -- * --------------- -- Smart_Ptr -- --------------- procedure Adjust (Object : in out Smart_Ptr) is begin if not Object.Is_Null then pragma Assert (Check => Object.Counter /= null, Message => "Corruption during Smart_Ptr assignment."); Check_Increment_Use_Count(Object.Counter.all); end if; end Adjust; procedure Finalize (Object : in out Smart_Ptr) is begin if Object.Counter /= null then -- Finalize is required to be idempotent to cope with rare -- situations when it may be called multiple times. By setting -- Object.Counter to null, I ensure that there can be no -- double-decrementing of counters or double-deallocations. Decrement_Use_Count(Object.Counter.all); if Use_Count(Object.Counter.all) = 0 then Delete (Object.Element.all); Deallocate_T (Object.Element); Deallocate_If_Unused(Object.Counter); end if; Object.Counter := null; end if; end Finalize; --------------- -- Smart_Ref -- --------------- procedure Initialize (Object : in out Smart_Ref) is begin raise Smart_Ptr_Error with "Smart_Ref should be created via Make_Smart_Ref only"; end Initialize; procedure Adjust (Object : in out Smart_Ref) is begin pragma Assert (Check => Object.Counter /= null, Message => "Corruption during Smart_Ref assignment."); Check_Increment_Use_Count(Object.Counter.all); end Adjust; procedure Finalize (Object : in out Smart_Ref) is Converted_Ptr : T_Ptr; begin if not (Object.Counter = null) then -- Finalize is required to be idempotent to cope with rare -- situations when it may be called multiple times. Decrement_Use_Count(Object.Counter.all); if Use_Count(Object.Counter.all) = 0 then Converted_Ptr := Access_T_to_T_Ptr(Object.Element); -- We know U.Element was set from a T_Ptr so the unchecked -- conversion will in fact always be valid. Delete (Converted_Ptr.all); Deallocate_T (Converted_Ptr); Deallocate_If_Unused(Object.Counter); end if; Object.Counter := null; end if; end Finalize; -------------- -- Weak_Ptr -- -------------- procedure Adjust (Object : in out Weak_Ptr) is begin pragma Assert (Check => Object.Counter /= null, Message => "Corruption during Weak_Ptr assignment."); Increment_Weak_Ptr_Count(Object.Counter.all); end Adjust; procedure Finalize (Object : in out Weak_Ptr) is begin -- Make sure this procedure is idempotent. if Object.Counter /= null then Decrement_Weak_Ptr_Count(Object.Counter.all); Deallocate_If_Unused(Object.Counter); Object.Counter := null; end if; end Finalize; end Smart_Ptrs;
-- C41104A.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- CHECK THAT CONSTRAINT_ERROR IS RAISED IF AN EXPRESSION GIVES AN INDEX -- VALUE OUTSIDE THE RANGE SPECIFIED FOR THE INDEX FOR ARRAYS AND ACCESS -- TYPES. -- TBN 9/12/86 -- EDS 8/03/98 AVOID OPTIMIZATION WITH REPORT; USE REPORT; PROCEDURE C41104A IS SUBTYPE INT IS INTEGER RANGE 1 .. 5; SUBTYPE BOOL IS BOOLEAN RANGE TRUE .. TRUE; SUBTYPE CHAR IS CHARACTER RANGE 'W' .. 'Z'; TYPE ARRAY1 IS ARRAY (INT RANGE <>) OF INTEGER; TYPE ARRAY2 IS ARRAY (3 .. 1) OF INTEGER; TYPE ARRAY3 IS ARRAY (BOOL RANGE <>) OF INTEGER; TYPE ARRAY4 IS ARRAY (CHAR RANGE <>) OF INTEGER; TYPE REC (D : INT) IS RECORD A : ARRAY1 (1 .. D); END RECORD; TYPE B_REC (D : BOOL) IS RECORD A : ARRAY3 (TRUE .. D); END RECORD; TYPE NULL_REC (D : INT) IS RECORD A : ARRAY1 (D .. 1); END RECORD; TYPE NULL_CREC (D : CHAR) IS RECORD A : ARRAY4 (D .. 'W'); END RECORD; BEGIN TEST ("C41104A", "CHECK THAT CONSTRAINT_ERROR IS RAISED IF AN " & "EXPRESSION GIVES AN INDEX VALUE OUTSIDE THE " & "RANGE SPECIFIED FOR THE INDEX FOR ARRAYS AND " & "ACCESS TYPES"); DECLARE ARA1 : ARRAY1 (1 .. 5) := (1, 2, 3, 4, 5); BEGIN ARA1 (IDENT_INT(0)) := 1; BEGIN FAILED ("CONSTRAINT_ERROR WAS NOT RAISED - " & INTEGER'IMAGE(ARA1 (1))); EXCEPTION WHEN OTHERS => FAILED ("EXCEPTION ON ATTEMPT TO USE OBJECT"); END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ("WRONG EXCEPTION RAISED - 1"); END; ------------------------------------------------------------------------ DECLARE TYPE ACC_ARRAY IS ACCESS ARRAY3 (TRUE .. TRUE); ACC_ARA : ACC_ARRAY := NEW ARRAY3'(TRUE => 2); BEGIN ACC_ARA (IDENT_BOOL(FALSE)) := 2; BEGIN FAILED ("CONSTRAINT_ERROR WAS NOT RAISED - " & INTEGER'IMAGE(ACC_ARA (TRUE))); EXCEPTION WHEN OTHERS => FAILED ("EXCEPTION ON ATTEMPT TO USE OBJECT"); END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ("WRONG EXCEPTION RAISED - 2"); END; ------------------------------------------------------------------------ DECLARE ARA2 : ARRAY4 ('Z' .. 'Y'); BEGIN ARA2 (IDENT_CHAR('Y')) := 3; FAILED ("CONSTRAINT_ERROR WAS NOT RAISED - 3"); BEGIN COMMENT ("ARA2 (Y) IS " & INTEGER'IMAGE(ARA2 ('Y'))); EXCEPTION WHEN OTHERS => FAILED ("EXCEPTION ON ATTEMPT TO USE OBJECT"); END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ("WRONG EXCEPTION RAISED - 3"); END; ------------------------------------------------------------------------ DECLARE TYPE ACC_ARRAY IS ACCESS ARRAY2; ACC_ARA : ACC_ARRAY := NEW ARRAY2; BEGIN ACC_ARA (IDENT_INT(4)) := 4; FAILED ("CONSTRAINT_ERROR WAS NOT RAISED - 4"); BEGIN COMMENT ("ACC_ARA (4) IS " & INTEGER'IMAGE(ACC_ARA (4))); EXCEPTION WHEN OTHERS => FAILED ("EXCEPTION ON ATTEMPT TO USE OBJECT"); END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ("WRONG EXCEPTION RAISED - 4"); END; ------------------------------------------------------------------------ DECLARE REC1 : B_REC (TRUE) := (TRUE, A => (TRUE => 5)); BEGIN REC1.A (IDENT_BOOL (FALSE)) := 1; BEGIN FAILED ("CONSTRAINT_ERROR WAS NOT RAISED - " & INTEGER'IMAGE(REC1.A (TRUE))); EXCEPTION WHEN OTHERS => FAILED ("EXCEPTION ON ATTEMPT TO USE OBJECT"); END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ("WRONG EXCEPTION RAISED - 5"); END; ------------------------------------------------------------------------ DECLARE TYPE ACC_REC IS ACCESS REC (3); ACC_REC1 : ACC_REC := NEW REC'(3, (4, 5, 6)); BEGIN ACC_REC1.A (IDENT_INT(4)) := 4; BEGIN FAILED ("CONSTRAINT_ERROR WAS NOT RAISED - " & INTEGER'IMAGE(ACC_REC1.A (3))); EXCEPTION WHEN OTHERS => FAILED ("EXCEPTION ON ATTEMPT TO USE OBJECT"); END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ("WRONG EXCEPTION RAISED - 6"); END; ------------------------------------------------------------------------ DECLARE REC1 : NULL_REC (2); BEGIN REC1.A (IDENT_INT(2)) := 1; FAILED ("CONSTRAINT_ERROR WAS NOT RAISED - 7"); BEGIN COMMENT ("REC1.A (2) IS " & INTEGER'IMAGE(REC1.A (2))); EXCEPTION WHEN OTHERS => FAILED ("EXCEPTION ON ATTEMPT TO USE OBJECT"); END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ("WRONG EXCEPTION RAISED - 7"); END; ------------------------------------------------------------------------ DECLARE TYPE ACC_REC IS ACCESS NULL_CREC ('Z'); ACC_REC1 : ACC_REC := NEW NULL_CREC ('Z'); BEGIN ACC_REC1.A (IDENT_CHAR('A')) := 4; FAILED ("CONSTRAINT_ERROR WAS NOT RAISED - 8"); BEGIN COMMENT ("ACC_REC1.A (A) IS " & INTEGER'IMAGE(ACC_REC1.A ('A'))); EXCEPTION WHEN OTHERS => FAILED ("EXCEPTION ON ATTEMPT TO USE OBJECT"); END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ("WRONG EXCEPTION RAISED - 8"); END; ------------------------------------------------------------------------ RESULT; END C41104A;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ -- Property represents a declared state of one or more instances in terms of -- a named relationship to a value or values. When a property is an attribute -- of a classifier, the value or values are related to the instance of the -- classifier by being held in slots of the instance. When a property is an -- association end, the value or values are related to the instance or -- instances at the other end(s) of the association. The range of valid -- values represented by the property can be controlled by setting the -- property's type. -- -- A property has the capability of being a deployment target in a deployment -- relationship. This enables modeling the deployment to hierarchical nodes -- that have properties functioning as internal parts. -- -- Property specializes ParameterableElement to specify that a property can -- be exposed as a formal template parameter, and provided as an actual -- parameter in a binding of a template. -- -- A property represents a set of instances that are owned by a containing -- classifier instance. -- -- A property is a structural feature of a classifier that characterizes -- instances of the classifier. A property related by ownedAttribute to a -- classifier (other than an association) represents an attribute and might -- also represent an association end. It relates an instance of the class to -- a value or set of values of the type of the attribute. A property related -- by memberEnd or its specializations to an association represents an end of -- the association. The type of the property is the type of the end of the -- association. ------------------------------------------------------------------------------ limited with AMF.UML.Associations; limited with AMF.UML.Classes; with AMF.UML.Connectable_Elements; limited with AMF.UML.Data_Types; with AMF.UML.Deployment_Targets; limited with AMF.UML.Interfaces; limited with AMF.UML.Parameterable_Elements; limited with AMF.UML.Properties.Collections; limited with AMF.UML.Redefinable_Elements; with AMF.UML.Structural_Features; limited with AMF.UML.Types.Collections; limited with AMF.UML.Value_Specifications; package AMF.UML.Properties is pragma Preelaborate; type UML_Property is limited interface and AMF.UML.Connectable_Elements.UML_Connectable_Element and AMF.UML.Deployment_Targets.UML_Deployment_Target and AMF.UML.Structural_Features.UML_Structural_Feature; type UML_Property_Access is access all UML_Property'Class; for UML_Property_Access'Storage_Size use 0; not overriding function Get_Aggregation (Self : not null access constant UML_Property) return AMF.UML.UML_Aggregation_Kind is abstract; -- Getter of Property::aggregation. -- -- Specifies the kind of aggregation that applies to the Property. not overriding procedure Set_Aggregation (Self : not null access UML_Property; To : AMF.UML.UML_Aggregation_Kind) is abstract; -- Setter of Property::aggregation. -- -- Specifies the kind of aggregation that applies to the Property. not overriding function Get_Association (Self : not null access constant UML_Property) return AMF.UML.Associations.UML_Association_Access is abstract; -- Getter of Property::association. -- -- References the association of which this property is a member, if any. not overriding procedure Set_Association (Self : not null access UML_Property; To : AMF.UML.Associations.UML_Association_Access) is abstract; -- Setter of Property::association. -- -- References the association of which this property is a member, if any. not overriding function Get_Association_End (Self : not null access constant UML_Property) return AMF.UML.Properties.UML_Property_Access is abstract; -- Getter of Property::associationEnd. -- -- Designates the optional association end that owns a qualifier attribute. not overriding procedure Set_Association_End (Self : not null access UML_Property; To : AMF.UML.Properties.UML_Property_Access) is abstract; -- Setter of Property::associationEnd. -- -- Designates the optional association end that owns a qualifier attribute. not overriding function Get_Class (Self : not null access constant UML_Property) return AMF.UML.Classes.UML_Class_Access is abstract; -- Getter of Property::class. -- -- References the Class that owns the Property. -- References the Class that owns the Property. not overriding procedure Set_Class (Self : not null access UML_Property; To : AMF.UML.Classes.UML_Class_Access) is abstract; -- Setter of Property::class. -- -- References the Class that owns the Property. -- References the Class that owns the Property. not overriding function Get_Datatype (Self : not null access constant UML_Property) return AMF.UML.Data_Types.UML_Data_Type_Access is abstract; -- Getter of Property::datatype. -- -- The DataType that owns this Property. not overriding procedure Set_Datatype (Self : not null access UML_Property; To : AMF.UML.Data_Types.UML_Data_Type_Access) is abstract; -- Setter of Property::datatype. -- -- The DataType that owns this Property. not overriding function Get_Default (Self : not null access constant UML_Property) return AMF.Optional_String is abstract; -- Getter of Property::default. -- -- A String that is evaluated to give a default value for the Property -- when an object of the owning Classifier is instantiated. -- Specifies a String that represents a value to be used when no argument -- is supplied for the Property. not overriding procedure Set_Default (Self : not null access UML_Property; To : AMF.Optional_String) is abstract; -- Setter of Property::default. -- -- A String that is evaluated to give a default value for the Property -- when an object of the owning Classifier is instantiated. -- Specifies a String that represents a value to be used when no argument -- is supplied for the Property. not overriding function Get_Default_Value (Self : not null access constant UML_Property) return AMF.UML.Value_Specifications.UML_Value_Specification_Access is abstract; -- Getter of Property::defaultValue. -- -- A ValueSpecification that is evaluated to give a default value for the -- Property when an object of the owning Classifier is instantiated. not overriding procedure Set_Default_Value (Self : not null access UML_Property; To : AMF.UML.Value_Specifications.UML_Value_Specification_Access) is abstract; -- Setter of Property::defaultValue. -- -- A ValueSpecification that is evaluated to give a default value for the -- Property when an object of the owning Classifier is instantiated. not overriding function Get_Interface (Self : not null access constant UML_Property) return AMF.UML.Interfaces.UML_Interface_Access is abstract; -- Getter of Property::interface. -- -- References the Interface that owns the Property not overriding procedure Set_Interface (Self : not null access UML_Property; To : AMF.UML.Interfaces.UML_Interface_Access) is abstract; -- Setter of Property::interface. -- -- References the Interface that owns the Property not overriding function Get_Is_Composite (Self : not null access constant UML_Property) return Boolean is abstract; -- Getter of Property::isComposite. -- -- If isComposite is true, the object containing the attribute is a -- container for the object or value contained in the attribute. -- This is a derived value, indicating whether the aggregation of the -- Property is composite or not. not overriding procedure Set_Is_Composite (Self : not null access UML_Property; To : Boolean) is abstract; -- Setter of Property::isComposite. -- -- If isComposite is true, the object containing the attribute is a -- container for the object or value contained in the attribute. -- This is a derived value, indicating whether the aggregation of the -- Property is composite or not. not overriding function Get_Is_Derived (Self : not null access constant UML_Property) return Boolean is abstract; -- Getter of Property::isDerived. -- -- Specifies whether the Property is derived, i.e., whether its value or -- values can be computed from other information. -- If isDerived is true, the value of the attribute is derived from -- information elsewhere. not overriding procedure Set_Is_Derived (Self : not null access UML_Property; To : Boolean) is abstract; -- Setter of Property::isDerived. -- -- Specifies whether the Property is derived, i.e., whether its value or -- values can be computed from other information. -- If isDerived is true, the value of the attribute is derived from -- information elsewhere. not overriding function Get_Is_Derived_Union (Self : not null access constant UML_Property) return Boolean is abstract; -- Getter of Property::isDerivedUnion. -- -- Specifies whether the property is derived as the union of all of the -- properties that are constrained to subset it. not overriding procedure Set_Is_Derived_Union (Self : not null access UML_Property; To : Boolean) is abstract; -- Setter of Property::isDerivedUnion. -- -- Specifies whether the property is derived as the union of all of the -- properties that are constrained to subset it. not overriding function Get_Is_ID (Self : not null access constant UML_Property) return Boolean is abstract; -- Getter of Property::isID. -- -- True indicates this property can be used to uniquely identify an -- instance of the containing Class. not overriding procedure Set_Is_ID (Self : not null access UML_Property; To : Boolean) is abstract; -- Setter of Property::isID. -- -- True indicates this property can be used to uniquely identify an -- instance of the containing Class. overriding function Get_Is_Read_Only (Self : not null access constant UML_Property) return Boolean is abstract; -- Getter of Property::isReadOnly. -- -- If isReadOnly is true, the attribute may not be written to after -- initialization. -- If true, the attribute may only be read, and not written. overriding procedure Set_Is_Read_Only (Self : not null access UML_Property; To : Boolean) is abstract; -- Setter of Property::isReadOnly. -- -- If isReadOnly is true, the attribute may not be written to after -- initialization. -- If true, the attribute may only be read, and not written. not overriding function Get_Opposite (Self : not null access constant UML_Property) return AMF.UML.Properties.UML_Property_Access is abstract; -- Getter of Property::opposite. -- -- In the case where the property is one navigable end of a binary -- association with both ends navigable, this gives the other end. not overriding procedure Set_Opposite (Self : not null access UML_Property; To : AMF.UML.Properties.UML_Property_Access) is abstract; -- Setter of Property::opposite. -- -- In the case where the property is one navigable end of a binary -- association with both ends navigable, this gives the other end. not overriding function Get_Owning_Association (Self : not null access constant UML_Property) return AMF.UML.Associations.UML_Association_Access is abstract; -- Getter of Property::owningAssociation. -- -- References the owning association of this property, if any. not overriding procedure Set_Owning_Association (Self : not null access UML_Property; To : AMF.UML.Associations.UML_Association_Access) is abstract; -- Setter of Property::owningAssociation. -- -- References the owning association of this property, if any. not overriding function Get_Qualifier (Self : not null access constant UML_Property) return AMF.UML.Properties.Collections.Ordered_Set_Of_UML_Property is abstract; -- Getter of Property::qualifier. -- -- An optional list of ordered qualifier attributes for the end. If the -- list is empty, then the Association is not qualified. not overriding function Get_Redefined_Property (Self : not null access constant UML_Property) return AMF.UML.Properties.Collections.Set_Of_UML_Property is abstract; -- Getter of Property::redefinedProperty. -- -- References the properties that are redefined by this property. not overriding function Get_Subsetted_Property (Self : not null access constant UML_Property) return AMF.UML.Properties.Collections.Set_Of_UML_Property is abstract; -- Getter of Property::subsettedProperty. -- -- References the properties of which this property is constrained to be a -- subset. not overriding function Default (Self : not null access constant UML_Property) return AMF.Optional_String is abstract; -- Operation Property::default. -- -- Missing derivation for Property::/default : String not overriding function Is_Attribute (Self : not null access constant UML_Property; P : AMF.UML.Properties.UML_Property_Access) return Boolean is abstract; -- Operation Property::isAttribute. -- -- The query isAttribute() is true if the Property is defined as an -- attribute of some classifier. overriding function Is_Compatible_With (Self : not null access constant UML_Property; P : AMF.UML.Parameterable_Elements.UML_Parameterable_Element_Access) return Boolean is abstract; -- Operation Property::isCompatibleWith. -- -- The query isCompatibleWith() determines if this parameterable element -- is compatible with the specified parameterable element. By default -- parameterable element P is compatible with parameterable element Q if -- the kind of P is the same or a subtype as the kind of Q. In addition, -- for properties, the type must be conformant with the type of the -- specified parameterable element. not overriding function Is_Composite (Self : not null access constant UML_Property) return Boolean is abstract; -- Operation Property::isComposite. -- -- The value of isComposite is true only if aggregation is composite. overriding function Is_Consistent_With (Self : not null access constant UML_Property; Redefinee : AMF.UML.Redefinable_Elements.UML_Redefinable_Element_Access) return Boolean is abstract; -- Operation Property::isConsistentWith. -- -- The query isConsistentWith() specifies, for any two Properties in a -- context in which redefinition is possible, whether redefinition would -- be logically consistent. A redefining property is consistent with a -- redefined property if the type of the redefining property conforms to -- the type of the redefined property, the multiplicity of the redefining -- property (if specified) is contained in the multiplicity of the -- redefined property. -- The query isConsistentWith() specifies, for any two Properties in a -- context in which redefinition is possible, whether redefinition would -- be logically consistent. A redefining property is consistent with a -- redefined property if the type of the redefining property conforms to -- the type of the redefined property, and the multiplicity of the -- redefining property (if specified) is contained in the multiplicity of -- the redefined property. not overriding function Is_Navigable (Self : not null access constant UML_Property) return Boolean is abstract; -- Operation Property::isNavigable. -- -- The query isNavigable() indicates whether it is possible to navigate -- across the property. not overriding function Opposite (Self : not null access constant UML_Property) return AMF.UML.Properties.UML_Property_Access is abstract; -- Operation Property::opposite. -- -- If this property is owned by a class, associated with a binary -- association, and the other end of the association is also owned by a -- class, then opposite gives the other end. not overriding function Subsetting_Context (Self : not null access constant UML_Property) return AMF.UML.Types.Collections.Set_Of_UML_Type is abstract; -- Operation Property::subsettingContext. -- -- The query subsettingContext() gives the context for subsetting a -- property. It consists, in the case of an attribute, of the -- corresponding classifier, and in the case of an association end, all of -- the classifiers at the other ends. end AMF.UML.Properties;
with Types; use Types; with Vecteur; with TH; generic type T_Precision is digits<>; Taille: Integer; MaxIterations: Integer; Alpha: T_Precision; package Google_Creuse is type T_Google is limited private; -- Initialiser la matrice Google. procedure Initialiser(Google: out T_Google); procedure Creer(Google: in out T_Google; Liens: in LC_Integer_Integer.T_LC); procedure Calculer_Rangs(Google: in out T_Google; Rangs: out Vecteur_Poids.T_Vecteur); private type T_Matrice_Valeur is record Indice: T_Indice; Valeur: T_Precision; end record; package Vecteur_Matrice is new Vecteur (T_Matrice_Valeur); package Vecteur_Precision is new Vecteur (T_Precision); package TH_Matrice is new TH(T_Indice, T_Precision, Hachage); type T_Google is record Matrice_Creuse: Vecteur_Matrice.T_Vecteur; Addition : T_Precision; PreVide: T_Precision; Sortants: Vecteur_Integer.T_Vecteur; end record; end Google_Creuse;
------------------------------------------------------------------------------ -- Copyright (c) 2014-2019, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ with Ada.Containers.Generic_Array_Sort; with Natools.S_Expressions.Atom_Ref_Constructors; with Natools.S_Expressions.Interpreter_Loop; with Natools.S_Expressions.Printers; with Natools.Time_IO.RFC_3339; package body Natools.Web.Containers is procedure Add_Atom (List : in out Unsafe_Atom_Lists.List; Context : in Meaningless_Type; Atom : in S_Expressions.Atom); -- Append a new atom to List procedure Add_Date (Map : in out Date_Maps.Unsafe_Maps.Map; Context : in Meaningless_Type; Name : in S_Expressions.Atom; Value : in out S_Expressions.Lockable.Descriptor'Class); -- Append a new named date to Map procedure Add_Expression (Map : in out Expression_Maps.Unsafe_Maps.Map; Context : in Meaningless_Type; Name : in S_Expressions.Atom; Value : in out S_Expressions.Lockable.Descriptor'Class); -- Insert a new node (Name -> Cache (Value)) in Map procedure Add_Expression_Map (Map : in out Expression_Map_Maps.Unsafe_Maps.Map; Context : in Meaningless_Type; Name : in S_Expressions.Atom; Value : in out S_Expressions.Lockable.Descriptor'Class); -- Insert a new node (Name -> Expression_Map (Value)) in Map function Less_Than (Left, Right : S_Expressions.Atom_Refs.Immutable_Reference) return Boolean is (S_Expressions.Less_Than (Left.Query, Right.Query)); -- Compare the contents of two non-empty immutable references procedure Atom_Array_Sort is new Ada.Containers.Generic_Array_Sort (S_Expressions.Count, S_Expressions.Atom_Refs.Immutable_Reference, Atom_Array, Less_Than); procedure Date_Reader is new S_Expressions.Interpreter_Loop (Date_Maps.Unsafe_Maps.Map, Meaningless_Type, Add_Date); procedure List_Reader is new S_Expressions.Interpreter_Loop (Unsafe_Atom_Lists.List, Meaningless_Type, Dispatch_Without_Argument => Add_Atom); procedure Map_Map_Reader is new S_Expressions.Interpreter_Loop (Expression_Map_Maps.Unsafe_Maps.Map, Meaningless_Type, Add_Expression_Map); procedure Map_Reader is new S_Expressions.Interpreter_Loop (Expression_Maps.Unsafe_Maps.Map, Meaningless_Type, Add_Expression); ------------------------------ -- Local Helper Subprograms -- ------------------------------ procedure Add_Atom (List : in out Unsafe_Atom_Lists.List; Context : in Meaningless_Type; Atom : in S_Expressions.Atom) is pragma Unreferenced (Context); begin List.Append (Atom); end Add_Atom; procedure Add_Date (Map : in out Date_Maps.Unsafe_Maps.Map; Context : in Meaningless_Type; Name : in S_Expressions.Atom; Value : in out S_Expressions.Lockable.Descriptor'Class) is pragma Unreferenced (Context); use type S_Expressions.Events.Event; Item : Date; begin if Value.Current_Event = S_Expressions.Events.Add_Atom then declare Image : constant String := S_Expressions.To_String (Value.Current_Atom); begin if Time_IO.RFC_3339.Is_Valid (Image) then Time_IO.RFC_3339.Value (Image, Item.Time, Item.Offset); Map.Include (Name, Item); elsif Image'Length > 0 then Log (Severities.Warning, "Ignoring invalid date named """ & S_Expressions.To_String (Name) & '"'); end if; end; else Map.Exclude (Name); end if; end Add_Date; procedure Add_Expression (Map : in out Expression_Maps.Unsafe_Maps.Map; Context : in Meaningless_Type; Name : in S_Expressions.Atom; Value : in out S_Expressions.Lockable.Descriptor'Class) is pragma Unreferenced (Context); Expression : S_Expressions.Caches.Reference; begin S_Expressions.Printers.Transfer (Value, Expression); Map.Include (Name, Expression.First); end Add_Expression; procedure Add_Expression_Map (Map : in out Expression_Map_Maps.Unsafe_Maps.Map; Context : in Meaningless_Type; Name : in S_Expressions.Atom; Value : in out S_Expressions.Lockable.Descriptor'Class) is pragma Unreferenced (Context); Expression_Map : Expression_Maps.Constant_Map; begin if Map.Contains (Name) then Log (Severities.Error, "Duplicate name """ & S_Expressions.To_String (Name) & """ in expression map map"); return; end if; Set_Expressions (Expression_Map, Value); Map.Insert (Name, Expression_Map); end Add_Expression_Map; -------------------- -- Map Interfaces -- -------------------- procedure Add_Expressions (Map : in out Expression_Maps.Constant_Map; Expression_List : in out S_Expressions.Lockable.Descriptor'Class) is New_Map : Expression_Maps.Unsafe_Maps.Map := Map.To_Unsafe_Map; begin Map_Reader (Expression_List, New_Map, Meaningless_Value); Map.Replace (New_Map); end Add_Expressions; procedure Set_Dates (Map : in out Date_Maps.Constant_Map; Date_List : in out S_Expressions.Lockable.Descriptor'Class) is New_Map : Date_Maps.Unsafe_Maps.Map; begin Date_Reader (Date_List, New_Map, Meaningless_Value); Map.Replace (New_Map); end Set_Dates; procedure Set_Expressions (Map : in out Expression_Maps.Constant_Map; Expression_List : in out S_Expressions.Lockable.Descriptor'Class) is New_Map : Expression_Maps.Unsafe_Maps.Map; begin Map_Reader (Expression_List, New_Map, Meaningless_Value); Map.Replace (New_Map); end Set_Expressions; procedure Set_Expression_Maps (Map : in out Expression_Map_Maps.Constant_Map; Expression_Map_List : in out S_Expressions.Lockable.Descriptor'Class) is New_Map : Expression_Map_Maps.Unsafe_Maps.Map; begin Map_Map_Reader (Expression_Map_List, New_Map, Meaningless_Value); Map.Replace (New_Map); end Set_Expression_Maps; --------------------------- -- Atom Arrays Interface -- --------------------------- procedure Append_Atoms (Target : in out Unsafe_Atom_Lists.List; Expression : in out S_Expressions.Lockable.Descriptor'Class) is begin List_Reader (Expression, Target, Meaningless_Value); end Append_Atoms; function Create (Source : Unsafe_Atom_Lists.List) return Atom_Array_Refs.Immutable_Reference is function Create_Array return Atom_Array; function Create_Array return Atom_Array is Cursor : Unsafe_Atom_Lists.Cursor := Source.First; Result : Atom_Array (1 .. S_Expressions.Count (Source.Length)); begin for I in Result'Range loop Result (I) := S_Expressions.Atom_Ref_Constructors.Create (Unsafe_Atom_Lists.Element (Cursor)); Unsafe_Atom_Lists.Next (Cursor); end loop; return Result; end Create_Array; begin return Atom_Array_Refs.Create (Create_Array'Access); end Create; function Create (Expression : in out S_Expressions.Lockable.Descriptor'Class) return Atom_Array_Refs.Immutable_Reference is List : Unsafe_Atom_Lists.List; begin Append_Atoms (List, Expression); return Create (List); end Create; -------------------------- -- Atom Table Interface -- -------------------------- function Create (Expression : in out S_Expressions.Lockable.Descriptor'Class) return Atom_Table_Refs.Immutable_Reference is List : Atom_Row_Lists.List; Event : S_Expressions.Events.Event := Expression.Current_Event; Lock : S_Expressions.Lockable.Lock_State; begin Read_Expression : loop case Event is when S_Expressions.Events.Close_List | S_Expressions.Events.End_Of_Input | S_Expressions.Events.Error => exit Read_Expression; when S_Expressions.Events.Add_Atom => null; when S_Expressions.Events.Open_List => Expression.Lock (Lock); begin Expression.Next (Event); if Event in S_Expressions.Events.Add_Atom | S_Expressions.Events.Open_List then List.Append (Create (Expression)); end if; Expression.Unlock (Lock); exception when others => Expression.Unlock (Lock, False); raise; end; end case; Expression.Next (Event); end loop Read_Expression; return Create (List); end Create; function Create (Row_List : in Atom_Row_Lists.List) return Atom_Table_Refs.Immutable_Reference is begin Build_Table : declare Data : constant Atom_Table_Refs.Data_Access := new Atom_Table (1 .. S_Expressions.Count (Atom_Row_Lists.Length (Row_List))); Ref : constant Atom_Table_Refs.Immutable_Reference := Atom_Table_Refs.Create (Data); Cursor : Atom_Row_Lists.Cursor := Atom_Row_Lists.First (Row_List); begin for I in Data.all'Range loop Data (I) := Atom_Row_Lists.Element (Cursor); Atom_Row_Lists.Next (Cursor); end loop; pragma Assert (not Atom_Row_Lists.Has_Element (Cursor)); return Ref; end Build_Table; end Create; ------------------------ -- Atom Set Interface -- ------------------------ function Create (Source : in Atom_Array) return Atom_Set is Data : constant Atom_Array_Refs.Data_Access := new Atom_Array'(Source); Ref : constant Atom_Array_Refs.Immutable_Reference := Atom_Array_Refs.Create (Data); begin Atom_Array_Sort (Data.all); return (Elements => Ref); end Create; function Create (Source : in Unsafe_Atom_Lists.List) return Atom_Set is begin return Create (Create (Source).Query); end Create; function Contains (Set : in Atom_Set; Value : in S_Expressions.Atom) return Boolean is use type S_Expressions.Offset; Upper, Middle, Lower : S_Expressions.Offset; begin if Set.Elements.Is_Empty then return False; end if; declare Elements : constant Atom_Array_Refs.Accessor := Set.Elements.Query; begin if Elements.Data'Length = 0 then return False; end if; Lower := Elements.Data'First - 1; Upper := Elements.Data'Last + 1; loop pragma Assert (Upper - Lower >= 2); Middle := Lower + (Upper - Lower) / 2; declare Middle_Value : constant S_Expressions.Atom_Refs.Accessor := Elements (Middle).Query; begin if S_Expressions.Less_Than (Middle_Value, Value) then Lower := Middle; elsif S_Expressions.Less_Than (Value, Middle_Value) then Upper := Middle; else return True; end if; end; if Lower + 1 >= Upper then return False; end if; end loop; end; end Contains; function Contains (Set : in Atom_Set; Value : in String) return Boolean is begin return Contains (Set, S_Expressions.To_Atom (Value)); end Contains; end Natools.Web.Containers;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- XML Processor -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Ada.Containers.Vectors; with League.Strings; package Matreshka.XML_Catalogs.Entry_Files is type Prefer_Mode is (System, Public); type Catalog_Entry_File is tagged; type Catalog_Entry_File_Access is access all Catalog_Entry_File; type Public_Entry; type Public_Entry_Access is access all Public_Entry; type System_Entry; type System_Entry_Access is access all System_Entry; type Rewrite_System_Entry; type Rewrite_System_Entry_Access is access all Rewrite_System_Entry; type System_Suffix_Entry; type System_Suffix_Entry_Access is access all System_Suffix_Entry; type Delegate_Public_Entry; type Delegate_Public_Entry_Access is access all Delegate_Public_Entry; type Delegate_System_Entry; type Delegate_System_Entry_Access is access all Delegate_System_Entry; type URI_Entry; type URI_Entry_Access is access all URI_Entry; type Rewrite_URI_Entry; type Rewrite_URI_Entry_Access is access all Rewrite_URI_Entry; type URI_Suffix_Entry; type URI_Suffix_Entry_Access is access all URI_Suffix_Entry; type Delegate_URI_Entry; type Delegate_URI_Entry_Access is access all Delegate_URI_Entry; type Next_Catalog_Entry; type Next_Catalog_Entry_Access is access all Next_Catalog_Entry; package Catalog_Entry_File_Vectors is new Ada.Containers.Vectors (Positive, Catalog_Entry_File_Access); package Public_Entry_Vectors is new Ada.Containers.Vectors (Positive, Public_Entry_Access); package System_Entry_Vectors is new Ada.Containers.Vectors (Positive, System_Entry_Access); package Rewrite_System_Entry_Vectors is new Ada.Containers.Vectors (Positive, Rewrite_System_Entry_Access); package System_Suffix_Entry_Vectors is new Ada.Containers.Vectors (Positive, System_Suffix_Entry_Access); package Delegate_Public_Entry_Vectors is new Ada.Containers.Vectors (Positive, Delegate_Public_Entry_Access); package Delegate_System_Entry_Vectors is new Ada.Containers.Vectors (Positive, Delegate_System_Entry_Access); package URI_Entry_Vectors is new Ada.Containers.Vectors (Positive, URI_Entry_Access); package Rewrite_URI_Entry_Vectors is new Ada.Containers.Vectors (Positive, Rewrite_URI_Entry_Access); package URI_Suffix_Entry_Vectors is new Ada.Containers.Vectors (Positive, URI_Suffix_Entry_Access); package Delegate_URI_Entry_Vectors is new Ada.Containers.Vectors (Positive, Delegate_URI_Entry_Access); package Next_Catalog_Entry_Vectors is new Ada.Containers.Vectors (Positive, Next_Catalog_Entry_Access); type Public_Entry is limited record Public_Id : League.Strings.Universal_String; URI : League.Strings.Universal_String; Prefer : Prefer_Mode; end record; type System_Entry is limited record System_Id : League.Strings.Universal_String; URI : League.Strings.Universal_String; end record; type Rewrite_System_Entry is limited record System_Id : League.Strings.Universal_String; Prefix : League.Strings.Universal_String; end record; type System_Suffix_Entry is limited record System_Id : League.Strings.Universal_String; URI : League.Strings.Universal_String; end record; type Delegate_Public_Entry is limited record Public_Id : League.Strings.Universal_String; Catalog : League.Strings.Universal_String; Prefer : Prefer_Mode; end record; type Delegate_System_Entry is limited record System_Id : League.Strings.Universal_String; Catalog : League.Strings.Universal_String; end record; type URI_Entry is limited record Name : League.Strings.Universal_String; URI : League.Strings.Universal_String; end record; type Rewrite_URI_Entry is limited record Prefix : League.Strings.Universal_String; Rewrite : League.Strings.Universal_String; end record; type URI_Suffix_Entry is limited record Suffix : League.Strings.Universal_String; URI : League.Strings.Universal_String; end record; type Delegate_URI_Entry is limited record Prefix : League.Strings.Universal_String; Catalog : League.Strings.Universal_String; end record; type Next_Catalog_Entry is limited record Catalog : League.Strings.Universal_String; Default_Prefer_Mode : Prefer_Mode; File : Catalog_Entry_File_Access; end record; type Catalog_Entry_File is tagged limited record Default_Prefer_Mode : Prefer_Mode; -- Default prefer mode. Public_Entries : Public_Entry_Vectors.Vector; -- List of 'public' entries of entry file. System_Entries : System_Entry_Vectors.Vector; -- List of 'system' entries of entry file. Rewrite_System_Entries : Rewrite_System_Entry_Vectors.Vector; -- List of 'rewriteSystem' entries of entry file. System_Suffix_Entries : System_Suffix_Entry_Vectors.Vector; -- List of 'systemSuffix' entries of entry file. Delegate_Public_Entries : Delegate_Public_Entry_Vectors.Vector; -- List of 'delegatePublic' entries on the entry file. Delegate_System_Entries : Delegate_System_Entry_Vectors.Vector; -- List of 'delegateSystem' entries on the entry file. URI_Entries : URI_Entry_Vectors.Vector; -- List of 'uri' entries of entry file. Rewrite_URI_Entries : Rewrite_URI_Entry_Vectors.Vector; -- List of 'rewriteURI' entries of entry file. URI_Suffix_Entries : URI_Suffix_Entry_Vectors.Vector; -- List of 'uriSuffix' entries of entry file. Delegate_URI_Entries : Delegate_URI_Entry_Vectors.Vector; -- List of 'delegateURI' entries of entry file. Next_Catalog_Entries : Next_Catalog_Entry_Vectors.Vector; -- List of 'nextCatalog' entries of entry file. end record; type Catalog_Entry_File_List is tagged limited record Catalog_Entry_Files : Catalog_Entry_File_Vectors.Vector; end record; type Catalog_Entry_File_List_Access is access all Catalog_Entry_File_List; procedure Append (Self : in out Catalog_Entry_File; Public_Entry : not null Public_Entry_Access); -- Adds 'public' entry into the end of list of 'public' entries of the -- entry file. procedure Append (Self : in out Catalog_Entry_File; System_Entry : not null System_Entry_Access); -- Adds 'system' entry into the end of list of 'system' entries of the -- entry file. procedure Append (Self : in out Catalog_Entry_File; Rewrite_System_Entry : not null Rewrite_System_Entry_Access); -- Adds 'rewriteSystem' entry into the end of list of 'rewriteSystem' -- entries of the entry file. procedure Append (Self : in out Catalog_Entry_File; System_Suffix_Entry : not null System_Suffix_Entry_Access); -- Adds 'systemSuffix' entry into the end of list of 'systemSuffix' entries -- of the entry file. procedure Append (Self : in out Catalog_Entry_File; Delegate_Public_Entry : not null Delegate_Public_Entry_Access); -- Adds 'delegatePublic' entry into the end of list of 'delegatePublic' -- entries of the entry file. procedure Append (Self : in out Catalog_Entry_File; Delegate_System_Entry : not null Delegate_System_Entry_Access); -- Adds 'delegateSystem' entry into the end of list of 'delegateSystem' -- entries of the entry file. procedure Append (Self : in out Catalog_Entry_File; URI_Entry : not null URI_Entry_Access); -- Adds 'uri' entry into the end of list of 'uri' entries of the entry -- file. procedure Append (Self : in out Catalog_Entry_File; Rewrite_URI_Entry : not null Rewrite_URI_Entry_Access); -- Adds 'rewriteURI' entry into the end of list of 'rewriteURI' entries of -- the entry file. procedure Append (Self : in out Catalog_Entry_File; URI_Suffix_Entry : not null URI_Suffix_Entry_Access); -- Adds 'uriSuffix' entry into the end of list of 'uriSuffix' entries of -- the entry file. procedure Append (Self : in out Catalog_Entry_File; Delegate_URI_Entry : not null Delegate_URI_Entry_Access); -- Adds 'delegateURI' entry into the end of list of 'delegateURI' entries -- of the entry file. procedure Append (Self : in out Catalog_Entry_File; Next_Catalog_Entry : not null Next_Catalog_Entry_Access); -- Adds 'nextCatalog' entry into the end of list of 'nextCatalog' entries -- of the entry file. end Matreshka.XML_Catalogs.Entry_Files;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S Y S T E M . S E C O N D A R Y _ S T A C K -- -- -- -- S p e c -- -- -- -- $Revision: 2 $ -- -- -- -- Copyright (c) 1992,1993,1994 NYU, All Rights Reserved -- -- -- -- The GNAT library is free software; you can redistribute it and/or modify -- -- it under terms of the GNU Library General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) any -- -- later version. The GNAT library is distributed in the hope that it will -- -- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -- -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- Library General Public License for more details. You should have -- -- received a copy of the GNU Library General Public License along with -- -- the GNAT library; see the file COPYING.LIB. If not, write to the Free -- -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. -- -- -- ------------------------------------------------------------------------------ with System.Storage_Elements; use System.Storage_Elements; with System.Storage_Pools; use System.Storage_Pools; package System.Secondary_Stack is type Secondary_Stack_Pool is new Root_Storage_Pool with null record; function Storage_Size (Pool : Secondary_Stack_Pool) return Storage_Count; procedure Allocate (Pool : in out Secondary_Stack_Pool; Address : out System.Address; Storage_Size : in Storage_Count; Alignment : in Storage_Count); procedure Deallocate (Pool : in out Secondary_Stack_Pool; Address : in System.Address; Storage_Size : in Storage_Count; Alignment : in Storage_Count); type Mark_Id is private; -- Type used to mark the stack. procedure SS_Init (Stk : out Address; Size : Natural); -- Initialize the secondary stack with a main stack of the given Size. -- All further allocations which do not overflow the main stack will not -- generate dynamic (de)allocation calls. If the main Stack overflows -- a new chuck of at least the same size will be allocated and linked -- to the previous chunk. -- -- Note: the reason that Stk is passed is that SS_Init is called before -- the proper interface is established to obtain the address of the -- stack using System.Task_Specific_Data.Get_Sec_Stack_Addr. procedure SS_Free (Stk : Address); -- Release the memory allocated for the Secondary Stack. That is to say, -- all the allocated chuncks. function SS_Mark return Mark_Id; -- Return the Mark corresponding to the current state of the stack procedure SS_Release (M : Mark_Id); -- Restore the state of the stack corresponding to the mark M. If an -- additional chunk have been allocated, it will never be freed during a generic with procedure Put_Line (S : String); procedure SS_Info; -- Debugging procedure used to print out secondary Stack allocation -- information. This procedure is generic in order to avoid a direct -- dependance on a particular IO package. SS_Pool : Secondary_Stack_Pool; -- the pool for the secondary stack private type Mark_Id is new Integer; end System.Secondary_Stack;
-- -- 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. -- with Ada.Text_IO; with Ada.Strings.Unbounded; with Database.Jobs; with Database.Events; with Types; package body CSV_IO is procedure Export (File_Name : String) is use Ada.Text_IO; Export_File : File_Type; procedure Put_Row (Col_1, Col_2, Col_3, Col_4 : String); procedure Put_Row (Col_1, Col_2, Col_3, Col_4 : String) is begin Put_Line (Export_File, Col_1 & ";" & Col_2 & ";" & Col_3 & ";" & Col_4 & ";"); end Put_Row; -- Lists : Database.List_Set; begin Create (Export_File, Out_File, File_Name); -- Database.Get_Lists (Lists); -- for List of Lists.Vector loop -- Put_Row (List.Ref, -- Ada.Strings.Unbounded.To_String (List.Name), -- List.Id'Img, -- Ada.Strings.Unbounded.To_String (List.Desc)); declare Jobs : constant Types.Job_Sets.Vector := Database.Jobs.Get_Jobs (Top => Database.Jobs.All_Jobs); begin for Job of Jobs loop Put_Row (Col_1 => "RRR", -- Job.Ref, Col_2 => Ada.Strings.Unbounded.To_String (Job.Title), Col_3 => Job.Id'Img, Col_4 => ""); declare use Database.Events; Events : constant Event_Lists.Vector := Get_Job_Events (Job.Id); begin for Event of Events loop Put_Row ("", Ada.Strings.Unbounded.To_String (Event.Stamp), Ada.Strings.Unbounded.To_String (Event.Kind), ""); end loop; end; end loop; end; Put_Row ("", "", "", ""); -- end loop; Close (Export_File); end Export; end CSV_IO;
package body Fractal_Impl is procedure Init (Viewport : Viewport_Info) is begin Float_Julia_Fractal.Init (Viewport => Viewport); Fixed_Julia_Fractal.Init (Viewport => Viewport); end Init; procedure Compute_Image (Buffer : in out Buffer_Access) is begin case Current_Computation is when Fixed_Type => -- Fixed_Julia_Fractal.Increment_Frame; Fixed_Julia_Fractal.Calculate_Image (Buffer => Buffer); when Float_Type => -- Float_Julia_Fractal.Increment_Frame; Float_Julia_Fractal.Calculate_Image (Buffer => Buffer); end case; end Compute_Image; procedure Increment_Frame is begin if Cnt_Up then if Frame_Counter = UInt5'Last then Cnt_Up := not Cnt_Up; return; else Frame_Counter := Frame_Counter + 1; return; end if; end if; if Frame_Counter = UInt5'First then Cnt_Up := not Cnt_Up; return; end if; Frame_Counter := Frame_Counter - 1; end Increment_Frame; procedure RGB565_Color_Pixel (Z_Escape : Boolean; Iter_Escape : Natural; Px : out RGB565_Pixel) is Value : constant Integer := 765 * (Iter_Escape - 1) / Max_Iterations; begin if Z_Escape then if Value > 510 then Px := RGB565_Pixel'(Red => UInt5'Last - Frame_Counter, Green => UInt6'Last, Blue => UInt5 (Value rem Integer (UInt5'Last))); elsif Value > 255 then Px := RGB565_Pixel'(Red => UInt5'Last - Frame_Counter, Green => UInt6 (Value rem Integer (UInt6'Last)), Blue => UInt5'First + Frame_Counter); else Px := RGB565_Pixel'(Red => UInt5 (Value rem Integer (UInt5'Last)), Green => UInt6'First + UInt6 (Frame_Counter), Blue => UInt5'First); end if; else Px := RGB565_Pixel'(Red => UInt5'First + Frame_Counter, Green => UInt6'First + UInt6 (Frame_Counter), Blue => UInt5'First + Frame_Counter); end if; end RGB565_Color_Pixel; procedure Set_Computation_Type (Comp_Type : Computation_Enum) is begin Current_Computation := Comp_Type; end Set_Computation_Type; procedure Compute_Row (Row : Natural; Buffer : in out Buffer_Access) is begin case Current_Computation is when Fixed_Type => -- Fixed_Julia_Fractal.Increment_Frame; Fixed_Julia_Fractal.Calculate_Row (Y => Row, Idx => Buffer'First, Buffer => Buffer); when Float_Type => -- Float_Julia_Fractal.Increment_Frame; Float_Julia_Fractal.Calculate_Row (Y => Row, Idx => Buffer'First, Buffer => Buffer); end case; end Compute_Row; end Fractal_Impl;
-- This file is covered by the Internet Software Consortium (ISC) License -- Reference: ../License.txt package body Replicant.Platform is ------------------ -- df_command -- ------------------ function df_command return String is begin case platform_type is when dragonfly | freebsd | netbsd => return "/bin/df -h"; when solaris => return "/usr/sbin/df -h"; when linux => return "/usr/bin/df -h"; when unknown => return "skip"; end case; end df_command; ------------------------- -- file_type_command -- ------------------------- function file_type_command return String is bsd_command : constant String := "/usr/bin/file -b " & JT.USS (PM.configuration.dir_system) & "/bin/sh"; lin_command : constant String := "/usr/bin/file -b " & JT.USS (PM.configuration.dir_system) & "/usr/bin/bash"; sol_command : constant String := "/usr/bin/file " & JT.USS (PM.configuration.dir_system) & "/usr/sbin/sh"; begin case platform_type is when freebsd | dragonfly | netbsd => return bsd_command; when linux => return lin_command; when solaris => return sol_command; when unknown => return "bad file_type_command invocation"; end case; end file_type_command; -------------------------- -- file_is_executable -- -------------------------- function file_is_executable (filename : String) return Boolean is command : constant String := "/usr/bin/file -b -L " & "-e ascii -e encoding -e tar -e compress " & LAT.Quotation & filename & LAT.Quotation; sol_cmd : constant String := "/usr/bin/file " & LAT.Quotation & filename & LAT.Quotation; comres : JT.Text; begin case platform_type is when dragonfly | freebsd | netbsd | linux => comres := internal_system_command (command); when solaris => comres := internal_system_command (sol_cmd); when unknown => return False; end case; return JT.contains (comres, "executable"); exception when others => return False; end file_is_executable; -------------------------- -- ARM_version_7 -- -------------------------- function ARM_version_7 return Boolean is -- Don't worry about other platforms, consider synth *BSD now command : constant String := "/usr/bin/readelf -A " & JT.USS (PM.configuration.dir_system) & "/bin/sh"; comres : JT.Text; begin comres := internal_system_command (command); declare contents : constant String := JT.USS (comres); markers : JT.Line_Markers; begin JT.initialize_markers (contents, markers); if JT.next_line_with_content_present (contents, " Tag_CPU_arch:", markers) then declare line : constant String := JT.extract_line (contents, markers); begin return JT.trim (JT.part_2 (line, ":")) = "ARM v7"; end; else TIO.Put_Line ("ARM_version_7 error: expected Tag_CPU_arch not found"); return False; end if; end; exception when others => TIO.Put_Line ("Handled exception (ARM_version_7 failed: defaulted to FALSE)"); return False; end ARM_version_7; -------------------------- -- dynamically_linked -- -------------------------- function dynamically_linked (base, filename : String) return Boolean is command : String := chroot & base & " /usr/bin/file -b -L " & "-e ascii -e encoding -e tar -e compress " & LAT.Quotation & filename & LAT.Quotation; sol_cmd : constant String := "/usr/bin/file " & LAT.Quotation & filename & LAT.Quotation; comres : JT.Text; begin case platform_type is when dragonfly | freebsd | netbsd | linux => comres := internal_system_command (command); when solaris => comres := internal_system_command (sol_cmd); when unknown => return False; end case; return JT.contains (comres, "dynamically linked"); exception when others => return False; end dynamically_linked; ----------------------------------- -- isolate_arch_from_file_type -- ----------------------------------- function isolate_arch_from_file_type (fileinfo : String) return filearch is -- DF: ELF 64-bit LSB executable, x86-64 -- FB: ELF 64-bit LSB executable, x86-64 -- FB: ELF 32-bit LSB executable, Intel 80386 -- NB: ELF 64-bit LSB executable, x86-64 -- L: ELF 64-bit LSB executable, x86-64 -- OPN: ELF 64-bit LSB shared object, x86-64, version 1 (FreeBSD), ... fragment : constant String := JT.trim (JT.specific_field (fileinfo, 2, ",")); answer : filearch := (others => ' '); begin if fragment'Length > filearch'Length then answer := fragment (fragment'First .. fragment'First + filearch'Length - 1); else answer (answer'First .. answer'First + fragment'Length - 1) := fragment; end if; return answer; end isolate_arch_from_file_type; ---------------------------------- -- get_arch_from_bourne_shell -- ---------------------------------- function get_arch_from_bourne_shell return String is function translate_arch (arch : filearch) return String; badarch : constant String := "BADARCH"; comres : JT.Text; arch : filearch; function translate_arch (arch : filearch) return String is begin if arch (arch'First .. arch'First + 5) = "x86-64" or else arch (arch'First .. arch'First + 4) = "AMD64" then case platform_type is when freebsd => return "amd64"; when netbsd => return "amd64"; when dragonfly => return "x86_64"; when linux => return "x86_64"; when solaris => return "x86_64"; when unknown => return badarch; end case; elsif arch = "ARM aarch64" then return "aarch64"; elsif arch = "ARM " then if ARM_version_7 then return "armv7"; else return "armv6"; end if; elsif arch = "Intel 80386" then return "i386"; else return badarch; end if; end translate_arch; begin comres := internal_system_command (file_type_command); arch := isolate_arch_from_file_type (JT.USS (comres)); return translate_arch (arch); exception when others => return badarch; end get_arch_from_bourne_shell; -------------------------------------- -- determine_package_architecture -- -------------------------------------- function determine_package_architecture return package_abi is function newsuffix (arch : filearch) return String; function suffix (arch : filearch) return String; function get_major (fileinfo : String; OS : String) return String; function even (fileinfo : String) return String; command : constant String := file_type_command; res : package_abi; arch : filearch; UN : JT.Text; function suffix (arch : filearch) return String is begin if arch (arch'First .. arch'First + 5) = "x86-64" or else arch (arch'First .. arch'First + 4) = "AMD64" then return "x86:64"; elsif arch = "Intel 80386" then return "x86:32"; elsif arch = "ARM aarch64" then return "aarch64:64"; elsif arch = "ARM " then if ARM_version_7 then return "armv7:32:el:eabi:softfp"; else return "armv6:32:el:eabi:softfp"; end if; else return "unknown:" & arch; end if; end suffix; function newsuffix (arch : filearch) return String is begin if arch (arch'First .. arch'First + 5) = "x86-64" or else arch (arch'First .. arch'First + 4) = "AMD64" then return "amd64"; elsif arch = "Intel 80386" then return "i386"; elsif arch = "ARM aarch64" then return "aarch64"; elsif arch = "ARM " then if ARM_version_7 then return "armv7"; else return "armv6"; end if; else return "unknown:" & arch; end if; end newsuffix; function even (fileinfo : String) return String is -- DF 4.5-DEVELOPMENT: ... DragonFly 4.0.501 -- DF 4.10-RELEASE : ... DragonFly 4.0.1000 -- DF 4.11-DEVELOPMENT: ... DragonFly 4.0.1102 -- -- Alternative future format (file version 2.0) -- DFV 400702: ... DragonFly 4.7.2 -- DFV 401117: .. DragonFly 4.11.17 rest : constant String := JT.part_2 (fileinfo, "DragonFly "); major : constant String := JT.part_1 (rest, "."); rest2 : constant String := JT.part_2 (rest, "."); part2 : constant String := JT.part_1 (rest2, "."); rest3 : constant String := JT.part_2 (rest2, "."); part3 : constant String := JT.part_1 (rest3, ","); minor : String (1 .. 2) := "00"; point : Character; begin if part2 = "0" then -- version format in October 2016 declare mvers : String (1 .. 4) := "0000"; lenp3 : constant Natural := part3'Length; begin mvers (mvers'Last - lenp3 + 1 .. mvers'Last) := part3; minor := mvers (1 .. 2); end; else -- Alternative future format (file version 2.0) declare lenp2 : constant Natural := part2'Length; begin minor (minor'Last - lenp2 + 1 .. minor'Last) := part2; end; end if; point := minor (2); case point is when '1' => minor (2) := '2'; when '3' => minor (2) := '4'; when '5' => minor (2) := '6'; when '7' => minor (2) := '8'; when '9' => minor (2) := '0'; minor (1) := Character'Val (Character'Pos (minor (1)) + 1); when others => null; end case; if minor (1) = '0' then return major & "." & minor (2); else return major & "." & minor (1 .. 2); end if; end even; function get_major (fileinfo : String; OS : String) return String is -- FreeBSD 10.2, stripped -- FreeBSD 11.0 (1100093), stripped -- NetBSD 7.0.1, not stripped rest : constant String := JT.part_2 (fileinfo, OS); major : constant String := JT.part_1 (rest, "."); begin return major; end get_major; begin UN := internal_system_command (file_type_command); arch := isolate_arch_from_file_type (JT.USS (UN)); case platform_type is when dragonfly => declare dfly : constant String := "dragonfly:"; release : constant String := even (JT.USS (UN)); begin res.calculated_abi := JT.SUS (dfly); JT.SU.Append (res.calculated_abi, release & ":"); res.calc_abi_noarch := res.calculated_abi; JT.SU.Append (res.calculated_abi, suffix (arch)); JT.SU.Append (res.calc_abi_noarch, "*"); res.calculated_alt_abi := res.calculated_abi; res.calc_alt_abi_noarch := res.calc_abi_noarch; end; when freebsd => declare fbsd1 : constant String := "FreeBSD:"; fbsd2 : constant String := "freebsd:"; release : constant String := get_major (JT.USS (UN), "FreeBSD "); begin res.calculated_abi := JT.SUS (fbsd1); res.calculated_alt_abi := JT.SUS (fbsd2); JT.SU.Append (res.calculated_abi, release & ":"); JT.SU.Append (res.calculated_alt_abi, release & ":"); res.calc_abi_noarch := res.calculated_abi; res.calc_alt_abi_noarch := res.calculated_alt_abi; JT.SU.Append (res.calculated_abi, newsuffix (arch)); JT.SU.Append (res.calculated_alt_abi, suffix (arch)); JT.SU.Append (res.calc_abi_noarch, "*"); JT.SU.Append (res.calc_alt_abi_noarch, "*"); end; when netbsd => declare net1 : constant String := "NetBSD:"; net2 : constant String := "netbsd:"; release : constant String := get_major (JT.USS (UN), "NetBSD "); begin res.calculated_abi := JT.SUS (net1); res.calculated_alt_abi := JT.SUS (net2); JT.SU.Append (res.calculated_abi, release & ":"); JT.SU.Append (res.calculated_alt_abi, release & ":"); res.calc_abi_noarch := res.calculated_abi; res.calc_alt_abi_noarch := res.calculated_alt_abi; JT.SU.Append (res.calculated_abi, newsuffix (arch)); JT.SU.Append (res.calculated_alt_abi, suffix (arch)); JT.SU.Append (res.calc_abi_noarch, "*"); JT.SU.Append (res.calc_alt_abi_noarch, "*"); end; when linux => null; -- TBD (check ABI first) when solaris => null; -- TBD (check ABI first) when unknown => null; end case; return res; end determine_package_architecture; ------------------------ -- swapinfo_command -- ------------------------ function swapinfo_command return String is begin case platform_type is when dragonfly | freebsd => return "/usr/sbin/swapinfo -k"; when netbsd => return "/sbin/swapctl -lk"; when linux => return "/usr/sbin/swapon --bytes --show=NAME,SIZE,USED,PRIO"; when solaris => return "/usr/sbin/swap -l"; when unknown => return ""; end case; end swapinfo_command; ------------------------- -- interactive_shell -- ------------------------- function interactive_shell return String is begin case platform_type is when dragonfly | freebsd => return "/bin/tcsh"; when netbsd => return "/bin/sh"; when linux => return "/bin/bash"; when solaris => return "TBD"; when unknown => return "DONTCARE"; end case; end interactive_shell; ----------------- -- load_core -- ----------------- function load_core (instant_load : Boolean) return Float is function probe_load return String; ----------------- 123456789-123456789-123456789- -- DFLY/FreeBSD: vm.loadavg: { 0.00 0.00 0.00 } -- NetBSD: vm.loadavg: 0.00 0.00 0.00 -- Linux: 0.00 0.01 0.05 3/382 15409 -- Solaris: [~42 chars]load average: 0.01, 0.01, 0.01 zero : constant Float := 0.0; lo : Integer; function probe_load return String is bsd : constant String := "/usr/bin/env LANG=C /sbin/sysctl vm.loadavg"; lin : constant String := "/bin/cat /proc/loadavg"; sol : constant String := "/usr/bin/uptime"; begin case platform_type is when dragonfly | freebsd => lo := 14; return JT.USS (internal_system_command (bsd)); when netbsd => lo := 12; return JT.USS (internal_system_command (bsd)); when linux => lo := 0; return JT.USS (internal_system_command (lin)); when solaris => return JT.USS (internal_system_command (sol)); when unknown => return ""; end case; end probe_load; comres : constant String := probe_load; begin case platform_type is when dragonfly | freebsd | netbsd | linux => declare stripped : constant String := comres (comres'First + lo .. comres'Last); begin if instant_load then return Float'Value (JT.specific_field (stripped, 1, " ")); else return Float'Value (JT.specific_field (stripped, 2, " ")); end if; end; when solaris => declare stripped : constant String := JT.part_2 (comres, "load average: "); begin if instant_load then return Float'Value (JT.specific_field (stripped, 1, ", ")); else return Float'Value (JT.specific_field (stripped, 2, ", ")); end if; end; when unknown => return zero; end case; exception when others => return zero; end load_core; ------------------------ -- get_instant_load -- ------------------------ function get_instant_load return Float is begin return load_core (instant_load => True); end get_instant_load; ------------------------- -- get_5_minute_load -- ------------------------- function get_5_minute_load return Float is begin return load_core (instant_load => False); end get_5_minute_load; ----------------------- -- get_number_cpus -- ----------------------- function get_number_cpus return Positive is -- Chicken/Egg issue. -- Platform type is not available. This function is called before -- The profile loading which requires the number of cpus as an argument. -- Therefore, we need two commands, the first being getting the OPSYS -- through the uname -s command. type opsys is (FreeFly, NetBSD, Linux, Solaris, Unsupported); uname : constant String := "/usr/bin/uname -s"; bsd_cmd : constant String := "/sbin/sysctl hw.ncpu"; lin_cmd : constant String := "/usr/bin/nproc"; sol_cmd : constant String := "/usr/sbin/psrinfo -pv"; thissys : opsys; comres : JT.Text; status : Integer; start : Positive; begin comres := Unix.piped_command (uname, status); if status /= 0 then return 1; end if; declare resstr : String := JT.USS (comres); opsys_str : String := resstr (resstr'First .. resstr'Last - 1); begin if opsys_str = "FreeBSD" then thissys := FreeFly; elsif opsys_str = "DragonFly" then thissys := FreeFly; elsif opsys_str = "NetBSD" then thissys := NetBSD; elsif opsys_str = "Linux" then thissys := Linux; elsif opsys_str = "SunOS" then thissys := Solaris; else thissys := Unsupported; end if; end; -- DF/Free: expected output: "hw.ncpu: C" where C is integer -- NetBSD: expected output: "hw.ncpu = C" -- Linux: expected output: "C" -- Solaris: expected output: -- The physical processor has 64 virtual processors (0-63) -- UltraSPARC-T2+ (cpuid 0 clock 1165 MHz) -- The physical processor has 64 virtual processors (64-127) -- UltraSPARC-T2+ (cpuid 64 clock 1165 MHz) case thissys is when FreeFly => start := 10; comres := Unix.piped_command (bsd_cmd, status); when NetBSD => start := 11; comres := Unix.piped_command (bsd_cmd, status); when Linux => start := 1; comres := Unix.piped_command (lin_cmd, status); when Solaris => start := 1; comres := Unix.piped_command (sol_cmd, status); -- garbage (incomplete). See src/parameters.adb#L686 off ravenadm for rest when Unsupported => return 1; end case; if status /= 0 then return 1; end if; declare resstr : String := JT.USS (comres); ncpu : String := resstr (start .. resstr'Last - 1); number : Positive := Integer'Value (ncpu); begin return number; exception when others => return 1; end; end get_number_cpus; ------------------------------ -- set_file_as_executable -- ------------------------------ procedure set_file_as_executable (fullpath : String) is -- supported by all platforms command : constant String := "/bin/chmod 755 " & fullpath; begin silent_exec (command); exception when others => null; end set_file_as_executable; ------------------------------- -- standalone_pkg8_install -- ------------------------------- function standalone_pkg8_install (id : builders) return Boolean is smount : constant String := get_slave_mount (id); taropt1 : constant String := "*/pkg-static"; taropt2 : constant String := "*/pkg-static */pkgng_admin"; command : constant String := chroot & smount & " /usr/bin/tar -x -f /packages/Latest/pkg.pkg -C / "; install_make : constant String := chroot & smount & " /usr/pkg/sbin/pkg-static add -A /packages/Latest/bmake.pkg"; begin case software_framework is when ports_collection => silent_exec (command & taropt1); when pkgsrc => silent_exec (command & taropt2); silent_exec (install_make); end case; return True; exception when others => return False; end standalone_pkg8_install; ------------------------------ -- host_pkgsrc_mk_install -- ------------------------------ function host_pkgsrc_mk_install (id : builders) return Boolean is smount : constant String := get_slave_mount (id); src_dir : constant String := host_localbase & "/share/mk"; tgt_dir : constant String := smount & root_localbase & "/share/mk"; begin return copy_directory_contents (src_dir, tgt_dir, "*.mk"); end host_pkgsrc_mk_install; --------------------------------- -- host_pkgsrc_bmake_install -- --------------------------------- function host_pkgsrc_bmake_install (id : builders) return Boolean is smount : constant String := get_slave_mount (id); host_bmake : constant String := host_localbase & "/bin/bmake"; slave_path : constant String := smount & root_localbase & "/bin"; slave_bmake : constant String := slave_path & "/bmake"; begin if not AD.Exists (host_bmake) then return False; end if; AD.Create_Path (slave_path); AD.Copy_File (Source_Name => host_bmake, Target_Name => slave_bmake); set_file_as_executable (slave_bmake); return True; exception when others => return False; end host_pkgsrc_bmake_install; ---------------------------------- -- host_pkgsrc_digest_install -- ---------------------------------- function host_pkgsrc_digest_install (id : builders) return Boolean is smount : String := get_slave_mount (id); host_digest : String := host_localbase & "/bin/digest"; slave_digest : String := smount & root_localbase & "/bin/digest"; begin if not AD.Exists (host_digest) then return False; end if; AD.Copy_File (Source_Name => host_digest, Target_Name => slave_digest); set_file_as_executable (slave_digest); return True; exception when others => return False; end host_pkgsrc_digest_install; -------------------------------- -- host_pkgsrc_pkg8_install -- -------------------------------- function host_pkgsrc_pkg8_install (id : builders) return Boolean is smount : constant String := get_slave_mount (id); host_pkgst : constant String := host_localbase & "/sbin/pkg-static"; host_admin : constant String := host_localbase & "/sbin/pkgng_admin"; slave_path : constant String := smount & root_localbase & "/sbin"; slave_pkg : constant String := slave_path & "/pkg-static"; slave_admin : constant String := slave_path & "/pkgng_admin"; begin if not AD.Exists (host_pkgst) or else not AD.Exists (host_admin) then return False; end if; AD.Create_Path (slave_path); AD.Copy_File (Source_Name => host_pkgst, Target_Name => slave_pkg); AD.Copy_File (Source_Name => host_admin, Target_Name => slave_admin); set_file_as_executable (slave_pkg); set_file_as_executable (slave_admin); return True; exception when others => return False; end host_pkgsrc_pkg8_install; ---------------------------- -- cache_port_variables -- ---------------------------- procedure cache_port_variables (path_to_mm : String) is function create_OSRELEASE (OSRELEASE : String) return String; procedure write_if_defined (varname, value : String); OSVER : constant String := get_osversion_from_param_header; ARCH : constant String := get_arch_from_bourne_shell; portsdir : constant String := JT.USS (PM.configuration.dir_portsdir); fullport : constant String := portsdir & "/ports-mgmt/pkg"; command : constant String := host_make & " __MAKE_CONF=/dev/null -C " & fullport & " USES=" & LAT.Quotation & "python compiler:features objc" & LAT.Quotation & " GNU_CONFIGURE=1 USE_JAVA=1 USE_LINUX=1" & " -VHAVE_COMPAT_IA32_KERN" & " -VCONFIGURE_MAX_CMD_LEN" & " -V_PERL5_FROM_BIN" & " -V_CCVERSION_921dbbb2" & " -V_CXXINTERNAL_acaad9ca" & " -V_OBJC_CCVERSION_921dbbb2" & " -VCC_OUTPUT_921dbbb2_58173849" & -- c89 " -VCC_OUTPUT_921dbbb2_9bdba57c" & -- c99 " -VCC_OUTPUT_921dbbb2_6a4fe7f5" & -- c11 " -VCC_OUTPUT_921dbbb2_6bcac02b" & -- gnu89 " -VCC_OUTPUT_921dbbb2_67d20829" & -- gnu99 " -VCC_OUTPUT_921dbbb2_bfa62e83" & -- gnu11 " -VCC_OUTPUT_921dbbb2_f0b4d593" & -- c++98 " -VCC_OUTPUT_921dbbb2_308abb44" & -- c++0x " -VCC_OUTPUT_921dbbb2_f00456e5" & -- c++11 " -VCC_OUTPUT_921dbbb2_65ad290d" & -- c++14 " -VCC_OUTPUT_921dbbb2_b2657cc3" & -- gnu++98 " -VCC_OUTPUT_921dbbb2_380987f7"; -- gnu++11 content : JT.Text; topline : JT.Text; status : Integer; vconf : TIO.File_Type; type result_range is range 1 .. 18; function create_OSRELEASE (OSRELEASE : String) return String is -- FreeBSD OSVERSION is 6 or 7 digits -- OSVERSION [M]MNNPPP -- DragonFly OSVERSION is 6 digits -- OSVERSION MNNNPP -- NetBSD OSVERSION is 9 or 10 digits -- OSVERSION [M]MNNrrPP00 len : constant Natural := OSRELEASE'Length; OSR : constant String (1 .. len) := OSRELEASE; MM : String (1 .. 2) := " "; NN : String (1 .. 2) := " "; PP : String (1 .. 2) := " "; FL : Natural; one_digit : Boolean := True; begin if len < 6 then return "1.0-SYNTH"; end if; case platform_type is when dragonfly => MM (2) := OSR (1); FL := 3; when freebsd => if len > 6 then one_digit := False; end if; FL := len - 4; when netbsd => if len > 9 then one_digit := False; end if; FL := len - 7; if OSR (FL + 4) = '0' then PP (2) := OSR (FL + 5); else PP := OSR (FL + 4 .. FL + 5); end if; when unknown => null; when linux | solaris => null; -- TBD end case; if one_digit then MM (2) := OSR (1); else MM := OSR (1 .. 2); end if; if OSR (FL) = '0' then NN (2) := OSR (FL + 1); else NN := OSR (FL .. FL + 1); end if; case software_framework is when ports_collection => return JT.trim (MM) & "." & JT.trim (NN) & "-SYNTH"; when pkgsrc => case platform_type is when netbsd => return JT.trim (MM) & "." & JT.trim (NN) & "." & JT.trim (PP); when others => return JT.trim (MM) & "." & JT.trim (NN); end case; end case; end create_OSRELEASE; procedure write_if_defined (varname, value : String) is begin if value /= "" then TIO.Put_Line (vconf, varname & "=" & value); end if; end write_if_defined; release : constant String := create_OSRELEASE (OSVER); begin builder_env := JT.blank; TIO.Create (File => vconf, Mode => TIO.Out_File, Name => path_to_mm & "/varcache.conf"); -- framework specific parts case software_framework is when ports_collection => content := Unix.piped_command (command, status); if status = 0 then for k in result_range loop JT.nextline (lineblock => content, firstline => topline); declare value : constant String := JT.USS (topline); begin case k is when 1 => TIO.Put_Line (vconf, "HAVE_COMPAT_IA32_KERN=" & value); when 2 => TIO.Put_Line (vconf, "CONFIGURE_MAX_CMD_LEN=" & value); when 3 => TIO.Put_Line (vconf, "_PERL5_FROM_BIN=" & value); when 4 => write_if_defined ("_CCVERSION_921dbbb2", value); when 5 => write_if_defined ("_CXXINTERNAL_acaad9ca", value); when 6 => write_if_defined ("_OBJC_CCVERSION_921dbbb2", value); when 7 => write_if_defined ("CC_OUTPUT_921dbbb2_58173849", value); when 8 => write_if_defined ("CC_OUTPUT_921dbbb2_9bdba57c", value); when 9 => write_if_defined ("CC_OUTPUT_921dbbb2_6a4fe7f5", value); when 10 => write_if_defined ("CC_OUTPUT_921dbbb2_6bcac02b", value); when 11 => write_if_defined ("CC_OUTPUT_921dbbb2_67d20829", value); when 12 => write_if_defined ("CC_OUTPUT_921dbbb2_bfa62e83", value); when 13 => write_if_defined ("CC_OUTPUT_921dbbb2_f0b4d593", value); when 14 => write_if_defined ("CC_OUTPUT_921dbbb2_308abb44", value); when 15 => write_if_defined ("CC_OUTPUT_921dbbb2_f00456e5", value); when 16 => write_if_defined ("CC_OUTPUT_921dbbb2_65ad290d", value); when 17 => write_if_defined ("CC_OUTPUT_921dbbb2_b2657cc3", value); when 18 => write_if_defined ("CC_OUTPUT_921dbbb2_380987f7", value); end case; end; end loop; end if; TIO.Put_Line (vconf, "_ALTCCVERSION_921dbbb2=none"); TIO.Put_Line (vconf, "_OBJC_ALTCCVERSION_921dbbb2=none"); TIO.Put_Line (vconf, "_SMP_CPUS=" & JT.int2str (Integer (smp_cores))); TIO.Put_Line (vconf, "UID=0"); TIO.Put_Line (vconf, "ARCH=" & ARCH); case platform_type is when freebsd => TIO.Put_Line (vconf, "OPSYS=FreeBSD"); TIO.Put_Line (vconf, "OSVERSION=" & OSVER); when dragonfly => TIO.Put_Line (vconf, "OPSYS=DragonFly"); TIO.Put_Line (vconf, "DFLYVERSION=" & OSVER); TIO.Put_Line (vconf, "OSVERSION=9999999"); when netbsd | linux | solaris => null; when unknown => null; end case; TIO.Put_Line (vconf, "OSREL=" & release (1 .. release'Last - 6)); TIO.Put_Line (vconf, "_OSRELEASE=" & release); TIO.Put_Line (vconf, "PYTHONBASE=/usr/local"); TIO.Put_Line (vconf, "_PKG_CHECKED=1"); when pkgsrc => TIO.Put_Line (vconf, "OS_VERSION= " & release); TIO.Put_Line (vconf, "HOST_MACHINE_ARCH= " & ARCH); case platform_type is when freebsd => TIO.Put_Line (vconf, "OPSYS= FreeBSD" & LAT.LF & "LOWER_OPSYS= freebsd" & LAT.LF & "MAKEFLAGS= OPSYS=FreeBSD"); when dragonfly => TIO.Put_Line (vconf, "OPSYS= DragonFly" & LAT.LF & "LOWER_OPSYS= dragonfly" & LAT.LF & "MAKEFLAGS= OPSYS=DragonFly"); when netbsd => TIO.Put_Line (vconf, "OPSYS= NetBSD" & LAT.LF & "LOWER_OPSYS= netbsd" & LAT.LF & "MAKEFLAGS= OPSYS=NetBSD"); when linux => TIO.Put_Line (vconf, "OPSYS= Linux" & LAT.LF & "LOWER_OPSYS= linux" & LAT.LF & "MAKEFLAGS= OPSYS=Linux"); when solaris => TIO.Put_Line (vconf, "OPSYS= SunOS" & LAT.LF & "LOWER_OPSYS= solaris" & LAT.LF & "MAKEFLAGS= OPSYS=SunOS"); when unknown => null; end case; TIO.Put_Line (vconf, "MAKEFLAGS+= OS_VERSION=" & release & LAT.LF & "MAKEFLAGS+= HOST_MACHINE_ARCH=" & ARCH & LAT.LF & "MAKEFLAGS+= _PKGSRCDIR=/xports"); end case; TIO.Close (vconf); case platform_type is when freebsd => JT.SU.Append (builder_env, "UNAME_s=FreeBSD " & "UNAME_v=FreeBSD\ " & release); when dragonfly => JT.SU.Append (builder_env, "UNAME_s=DragonFly " & "UNAME_v=DragonFly\ " & release); when netbsd => JT.SU.Append (builder_env, "UNAME_s=NetBSD " & "UNAME_v=NetBSD\ " & release); when linux => JT.SU.Append (builder_env, "UNAME_s=Linux " & "UNAME_v=Linux\ " & release); when solaris => JT.SU.Append (builder_env, "UNAME_s=SunOS " & "UNAME_v=SunOS\ " & release); when unknown => null; end case; -- The last entry of builder_env must be a blank space JT.SU.Append (builder_env, " UNAME_p=" & ARCH); JT.SU.Append (builder_env, " UNAME_m=" & ARCH); JT.SU.Append (builder_env, " UNAME_r=" & release & " "); end cache_port_variables; --------------------------------------- -- get_osversion_from_param_header -- --------------------------------------- function get_osversion_from_param_header return String is function get_pattern return String; function get_pattern return String is DFVER : constant String := "#define __DragonFly_version "; FBVER : constant String := "#define __FreeBSD_version "; NBVER : constant String := "#define" & LAT.HT & "__NetBSD_Version__" & LAT.HT; BADVER : constant String := "#define __Unknown_version "; begin case platform_type is when freebsd => return FBVER; when dragonfly => return DFVER; when netbsd => return NBVER; when linux => return BADVER; -- TBD when solaris => return BADVER; -- TBD when unknown => return BADVER; end case; end get_pattern; header : TIO.File_Type; badres : constant String := "100000"; pattern : constant String := get_pattern; paramh : constant String := JT.USS (PM.configuration.dir_system) & "/usr/include/sys/param.h"; begin TIO.Open (File => header, Mode => TIO.In_File, Name => paramh); while not TIO.End_Of_File (header) loop declare Line : constant String := TIO.Get_Line (header); begin if JT.contains (Line, pattern) then declare OSVER : constant String := JT.trim (JT.part_2 (Line, pattern)); len : constant Natural := OSVER'Length; final : Integer; begin exit when len < 7; TIO.Close (header); final := OSVER'First + 5; for x in final + 1 .. OSVER'Last loop case OSVER (x) is when '0' .. '9' => final := x; when others => return OSVER (OSVER'First .. final); end case; end loop; -- All characters from 5th position to end of OSVER are digits return OSVER; end; end if; end; end loop; TIO.Close (header); return badres; exception when others => if TIO.Is_Open (header) then TIO.Close (header); end if; return badres; end get_osversion_from_param_header; end Replicant.Platform;
-- This package has been generated automatically by GNATtest. -- You are allowed to add your code to the bodies of test routines. -- Such changes will be kept during further regeneration of this file. -- All code placed outside of test routine bodies will be lost. The -- code intended to set up and tear down the test environment should be -- placed into Ships.Test_Data. with AUnit.Assertions; use AUnit.Assertions; with System.Assertions; -- begin read only -- id:2.2/00/ -- -- This section can be used to add with clauses if necessary. -- -- end read only -- begin read only -- end read only package body Ships.Test_Data.Tests is -- begin read only -- id:2.2/01/ -- -- This section can be used to add global variables and other elements. -- -- end read only -- begin read only -- end read only -- begin read only function Wrap_Test_Create_Ship_14edf1_469250 (Proto_Index, Name: Unbounded_String; X: Map_X_Range; Y: Map_Y_Range; Speed: Ship_Speed; Random_Upgrades: Boolean := True) return Ship_Record is begin begin pragma Assert(Proto_Ships_List.Contains(Key => Proto_Index)); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "req_sloc(ships.ads:0):Test_CreateShip test requirement violated"); end; declare Test_Create_Ship_14edf1_469250_Result: constant Ship_Record := GNATtest_Generated.GNATtest_Standard.Ships.Create_Ship (Proto_Index, Name, X, Y, Speed, Random_Upgrades); begin begin pragma Assert(True); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "ens_sloc(ships.ads:0:):Test_CreateShip test commitment violated"); end; return Test_Create_Ship_14edf1_469250_Result; end; end Wrap_Test_Create_Ship_14edf1_469250; -- end read only -- begin read only procedure Test_Create_Ship_test_createship(Gnattest_T: in out Test); procedure Test_Create_Ship_14edf1_469250(Gnattest_T: in out Test) renames Test_Create_Ship_test_createship; -- id:2.2/14edf110e8654721/Create_Ship/1/0/test_createship/ procedure Test_Create_Ship_test_createship(Gnattest_T: in out Test) is function Create_Ship (Proto_Index, Name: Unbounded_String; X: Map_X_Range; Y: Map_Y_Range; Speed: Ship_Speed; Random_Upgrades: Boolean := True) return Ship_Record renames Wrap_Test_Create_Ship_14edf1_469250; -- end read only pragma Unreferenced(Gnattest_T); TestShip: constant Ship_Record := Create_Ship (To_Unbounded_String("2"), Null_Unbounded_String, 5, 5, FULL_SPEED); begin Assert (TestShip.Name = To_Unbounded_String("Tiny pirates ship"), "Failed to create a new NPC ship."); -- begin read only end Test_Create_Ship_test_createship; -- end read only -- begin read only function Wrap_Test_Count_Ship_Weight_dec0b9_0591fd (Ship: Ship_Record) return Positive is begin declare Test_Count_Ship_Weight_dec0b9_0591fd_Result: constant Positive := GNATtest_Generated.GNATtest_Standard.Ships.Count_Ship_Weight(Ship); begin return Test_Count_Ship_Weight_dec0b9_0591fd_Result; end; end Wrap_Test_Count_Ship_Weight_dec0b9_0591fd; -- end read only -- begin read only procedure Test_Count_Ship_Weight_test_countshipweight (Gnattest_T: in out Test); procedure Test_Count_Ship_Weight_dec0b9_0591fd (Gnattest_T: in out Test) renames Test_Count_Ship_Weight_test_countshipweight; -- id:2.2/dec0b99ac9e9a6b9/Count_Ship_Weight/1/0/test_countshipweight/ procedure Test_Count_Ship_Weight_test_countshipweight (Gnattest_T: in out Test) is function Count_Ship_Weight(Ship: Ship_Record) return Positive renames Wrap_Test_Count_Ship_Weight_dec0b9_0591fd; -- end read only pragma Unreferenced(Gnattest_T); begin if Count_Ship_Weight(Player_Ship) = 1 then Assert(True, "This test can only crash."); return; end if; Assert(True, "This test can only crash."); -- begin read only end Test_Count_Ship_Weight_test_countshipweight; -- end read only -- begin read only function Wrap_Test_Generate_Ship_Name_7b8806_7313c0 (Owner: Unbounded_String) return Unbounded_String is begin begin pragma Assert(Owner /= Null_Unbounded_String); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "req_sloc(ships.ads:0):Test_GenerateShipName test requirement violated"); end; declare Test_Generate_Ship_Name_7b8806_7313c0_Result: constant Unbounded_String := GNATtest_Generated.GNATtest_Standard.Ships.Generate_Ship_Name (Owner); begin begin pragma Assert(True); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "ens_sloc(ships.ads:0:):Test_GenerateShipName test commitment violated"); end; return Test_Generate_Ship_Name_7b8806_7313c0_Result; end; end Wrap_Test_Generate_Ship_Name_7b8806_7313c0; -- end read only -- begin read only procedure Test_Generate_Ship_Name_test_generateshipname (Gnattest_T: in out Test); procedure Test_Generate_Ship_Name_7b8806_7313c0 (Gnattest_T: in out Test) renames Test_Generate_Ship_Name_test_generateshipname; -- id:2.2/7b880651d3391b98/Generate_Ship_Name/1/0/test_generateshipname/ procedure Test_Generate_Ship_Name_test_generateshipname (Gnattest_T: in out Test) is function Generate_Ship_Name (Owner: Unbounded_String) return Unbounded_String renames Wrap_Test_Generate_Ship_Name_7b8806_7313c0; -- end read only pragma Unreferenced(Gnattest_T); begin Assert (Generate_Ship_Name(To_Unbounded_String("POLEIS")) /= Null_Unbounded_String, "Failed to generate ship name."); -- begin read only end Test_Generate_Ship_Name_test_generateshipname; -- end read only -- begin read only function Wrap_Test_Count_Combat_Value_145322_424a30 return Natural is begin declare Test_Count_Combat_Value_145322_424a30_Result: constant Natural := GNATtest_Generated.GNATtest_Standard.Ships.Count_Combat_Value; begin return Test_Count_Combat_Value_145322_424a30_Result; end; end Wrap_Test_Count_Combat_Value_145322_424a30; -- end read only -- begin read only procedure Test_Count_Combat_Value_test_countcombatvalue (Gnattest_T: in out Test); procedure Test_Count_Combat_Value_145322_424a30 (Gnattest_T: in out Test) renames Test_Count_Combat_Value_test_countcombatvalue; -- id:2.2/145322adc54fa48a/Count_Combat_Value/1/0/test_countcombatvalue/ procedure Test_Count_Combat_Value_test_countcombatvalue (Gnattest_T: in out Test) is function Count_Combat_Value return Natural renames Wrap_Test_Count_Combat_Value_145322_424a30; -- end read only pragma Unreferenced(Gnattest_T); begin if Count_Combat_Value = 0 then Assert(True, "This test can only crash"); return; end if; Assert(True, "This test can only crash"); -- begin read only end Test_Count_Combat_Value_test_countcombatvalue; -- end read only -- begin read only function Wrap_Test_Get_Cabin_Quality_3a9d5d_bc7a0e (Quality: Natural) return String is begin begin pragma Assert(True); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "req_sloc(ships.ads:0):Test_GetCabinQuality test requirement violated"); end; declare Test_Get_Cabin_Quality_3a9d5d_bc7a0e_Result: constant String := GNATtest_Generated.GNATtest_Standard.Ships.Get_Cabin_Quality (Quality); begin begin pragma Assert (Test_Get_Cabin_Quality_3a9d5d_bc7a0e_Result'Length > 0); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "ens_sloc(ships.ads:0:):Test_GetCabinQuality test commitment violated"); end; return Test_Get_Cabin_Quality_3a9d5d_bc7a0e_Result; end; end Wrap_Test_Get_Cabin_Quality_3a9d5d_bc7a0e; -- end read only -- begin read only procedure Test_Get_Cabin_Quality_test_getcabinquality (Gnattest_T: in out Test); procedure Test_Get_Cabin_Quality_3a9d5d_bc7a0e (Gnattest_T: in out Test) renames Test_Get_Cabin_Quality_test_getcabinquality; -- id:2.2/3a9d5d1acf73079a/Get_Cabin_Quality/1/0/test_getcabinquality/ procedure Test_Get_Cabin_Quality_test_getcabinquality (Gnattest_T: in out Test) is function Get_Cabin_Quality(Quality: Natural) return String renames Wrap_Test_Get_Cabin_Quality_3a9d5d_bc7a0e; -- end read only pragma Unreferenced(Gnattest_T); begin Assert (Get_Cabin_Quality(10) = "Empty room", "Failed to get quality of cabin."); -- begin read only end Test_Get_Cabin_Quality_test_getcabinquality; -- end read only -- begin read only procedure Wrap_Test_Damage_Module_222cf0_819b51 (Ship: in out Ship_Record; Module_Index: Modules_Container.Extended_Index; Damage: Positive; Death_Reason: String) is begin begin pragma Assert (Module_Index in Ship.Modules.First_Index .. Ship.Modules.Last_Index and Death_Reason'Length > 0); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "req_sloc(ships.ads:0):Test_DamageModule test requirement violated"); end; GNATtest_Generated.GNATtest_Standard.Ships.Damage_Module (Ship, Module_Index, Damage, Death_Reason); begin pragma Assert(True); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "ens_sloc(ships.ads:0:):Test_DamageModule test commitment violated"); end; end Wrap_Test_Damage_Module_222cf0_819b51; -- end read only -- begin read only procedure Test_Damage_Module_test_damagemodule(Gnattest_T: in out Test); procedure Test_Damage_Module_222cf0_819b51(Gnattest_T: in out Test) renames Test_Damage_Module_test_damagemodule; -- id:2.2/222cf0d00b136333/Damage_Module/1/0/test_damagemodule/ procedure Test_Damage_Module_test_damagemodule(Gnattest_T: in out Test) is procedure Damage_Module (Ship: in out Ship_Record; Module_Index: Modules_Container.Extended_Index; Damage: Positive; Death_Reason: String) renames Wrap_Test_Damage_Module_222cf0_819b51; -- end read only pragma Unreferenced(Gnattest_T); OldDurability: constant Positive := Player_Ship.Modules(1).Durability; begin Damage_Module(Player_Ship, 1, 10, "during tests"); AUnit.Assertions.Assert (Player_Ship.Modules(1).Durability + 10 = OldDurability, "Failed to damage player ship hull."); Player_Ship.Modules(1).Durability := OldDurability; -- begin read only end Test_Damage_Module_test_damagemodule; -- end read only -- begin read only -- id:2.2/02/ -- -- This section can be used to add elaboration code for the global state. -- begin -- end read only null; -- begin read only -- end read only end Ships.Test_Data.Tests;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- G N A T . A L T I V E C . L O W _ L E V E L _ I N T E R F A C E -- -- -- -- S p e c -- -- -- -- Copyright (C) 2004-2005, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This unit provides entities to be used internally by the units common to -- both bindings (Hard or Soft), and relevant to the interfacing with the -- underlying Low Level support. -- The set of "services" includes: -- -- o Imports to the low level routines for which a direct binding is -- mandatory (or just possible when analyzed as such). -- -- o Conversion routines (unchecked) between low level types, or between -- various pointer representations. with GNAT.Altivec.Vector_Types; with GNAT.Altivec.Low_Level_Vectors; with Ada.Unchecked_Conversion; package GNAT.Altivec.Low_Level_Interface is ---------------------------------------------------------------------------- -- Imports for "argument must be literal" constraints in the Hard binding -- ---------------------------------------------------------------------------- use GNAT.Altivec.Vector_Types; -- vec_ctf -- function vec_ctf_vui_cint_r_vf (A : vector_unsigned_int; B : c_int) return vector_float; pragma Import (LL_Altivec, vec_ctf_vui_cint_r_vf, "__builtin_altivec_vcfux"); function vec_ctf_vsi_cint_r_vf (A : vector_signed_int; B : c_int) return vector_float; pragma Import (LL_Altivec, vec_ctf_vsi_cint_r_vf, "__builtin_altivec_vcfsx"); -- vec_vcfsx -- function vec_vcfsx_vsi_cint_r_vf (A : vector_signed_int; B : c_int) return vector_float; pragma Import (LL_Altivec, vec_vcfsx_vsi_cint_r_vf, "__builtin_altivec_vcfsx"); -- vec_vcfux -- function vec_vcfux_vui_cint_r_vf (A : vector_unsigned_int; B : c_int) return vector_float; pragma Import (LL_Altivec, vec_vcfux_vui_cint_r_vf, "__builtin_altivec_vcfux"); -- vec_cts -- function vec_cts_vf_cint_r_vsi (A : vector_float; B : c_int) return vector_signed_int; pragma Import (LL_Altivec, vec_cts_vf_cint_r_vsi, "__builtin_altivec_vctsxs"); -- vec_ctu -- function vec_ctu_vf_cint_r_vui (A : vector_float; B : c_int) return vector_unsigned_int; pragma Import (LL_Altivec, vec_ctu_vf_cint_r_vui, "__builtin_altivec_vctuxs"); -- vec_dss -- procedure vec_dss_cint (A : c_int); pragma Import (LL_Altivec, vec_dss_cint, "__builtin_altivec_dss"); -- vec_dst -- procedure vec_dst_kvucp_cint_cint (A : const_vector_unsigned_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kvucp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kvscp_cint_cint (A : const_vector_signed_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kvscp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kvbcp_cint_cint (A : const_vector_bool_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kvbcp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kvusp_cint_cint (A : const_vector_unsigned_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kvusp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kvssp_cint_cint (A : const_vector_signed_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kvssp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kvbsp_cint_cint (A : const_vector_bool_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kvbsp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kvxp_cint_cint (A : const_vector_pixel_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kvxp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kvuip_cint_cint (A : const_vector_unsigned_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kvuip_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kvsip_cint_cint (A : const_vector_signed_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kvsip_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kvbip_cint_cint (A : const_vector_bool_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kvbip_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kvfp_cint_cint (A : const_vector_float_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kvfp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kucp_cint_cint (A : const_unsigned_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kucp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kscp_cint_cint (A : const_signed_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kscp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kusp_cint_cint (A : const_unsigned_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kusp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_ksp_cint_cint (A : const_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_ksp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kuip_cint_cint (A : const_unsigned_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kuip_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kip_cint_cint (A : const_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kip_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kulongp_cint_cint (A : const_unsigned_long_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kulongp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_klongp_cint_cint (A : const_long_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_klongp_cint_cint, "__builtin_altivec_dst"); procedure vec_dst_kfp_cint_cint (A : const_float_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dst_kfp_cint_cint, "__builtin_altivec_dst"); -- vec_dstst -- procedure vec_dstst_kvucp_cint_cint (A : const_vector_unsigned_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kvucp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kvscp_cint_cint (A : const_vector_signed_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kvscp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kvbcp_cint_cint (A : const_vector_bool_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kvbcp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kvusp_cint_cint (A : const_vector_unsigned_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kvusp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kvssp_cint_cint (A : const_vector_signed_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kvssp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kvbsp_cint_cint (A : const_vector_bool_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kvbsp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kvxp_cint_cint (A : const_vector_pixel_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kvxp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kvuip_cint_cint (A : const_vector_unsigned_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kvuip_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kvsip_cint_cint (A : const_vector_signed_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kvsip_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kvbip_cint_cint (A : const_vector_bool_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kvbip_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kvfp_cint_cint (A : const_vector_float_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kvfp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kucp_cint_cint (A : const_unsigned_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kucp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kscp_cint_cint (A : const_signed_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kscp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kusp_cint_cint (A : const_unsigned_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kusp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_ksp_cint_cint (A : const_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_ksp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kuip_cint_cint (A : const_unsigned_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kuip_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kip_cint_cint (A : const_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kip_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kulongp_cint_cint (A : const_unsigned_long_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kulongp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_klongp_cint_cint (A : const_long_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_klongp_cint_cint, "__builtin_altivec_dstst"); procedure vec_dstst_kfp_cint_cint (A : const_float_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstst_kfp_cint_cint, "__builtin_altivec_dstst"); -- vec_dststt -- procedure vec_dststt_kvucp_cint_cint (A : const_vector_unsigned_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kvucp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kvscp_cint_cint (A : const_vector_signed_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kvscp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kvbcp_cint_cint (A : const_vector_bool_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kvbcp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kvusp_cint_cint (A : const_vector_unsigned_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kvusp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kvssp_cint_cint (A : const_vector_signed_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kvssp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kvbsp_cint_cint (A : const_vector_bool_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kvbsp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kvxp_cint_cint (A : const_vector_pixel_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kvxp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kvuip_cint_cint (A : const_vector_unsigned_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kvuip_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kvsip_cint_cint (A : const_vector_signed_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kvsip_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kvbip_cint_cint (A : const_vector_bool_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kvbip_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kvfp_cint_cint (A : const_vector_float_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kvfp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kucp_cint_cint (A : const_unsigned_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kucp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kscp_cint_cint (A : const_signed_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kscp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kusp_cint_cint (A : const_unsigned_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kusp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_ksp_cint_cint (A : const_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_ksp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kuip_cint_cint (A : const_unsigned_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kuip_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kip_cint_cint (A : const_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kip_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kulongp_cint_cint (A : const_unsigned_long_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kulongp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_klongp_cint_cint (A : const_long_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_klongp_cint_cint, "__builtin_altivec_dststt"); procedure vec_dststt_kfp_cint_cint (A : const_float_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dststt_kfp_cint_cint, "__builtin_altivec_dststt"); -- vec_dstt -- procedure vec_dstt_kvucp_cint_cint (A : const_vector_unsigned_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kvucp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kvscp_cint_cint (A : const_vector_signed_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kvscp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kvbcp_cint_cint (A : const_vector_bool_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kvbcp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kvusp_cint_cint (A : const_vector_unsigned_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kvusp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kvssp_cint_cint (A : const_vector_signed_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kvssp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kvbsp_cint_cint (A : const_vector_bool_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kvbsp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kvxp_cint_cint (A : const_vector_pixel_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kvxp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kvuip_cint_cint (A : const_vector_unsigned_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kvuip_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kvsip_cint_cint (A : const_vector_signed_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kvsip_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kvbip_cint_cint (A : const_vector_bool_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kvbip_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kvfp_cint_cint (A : const_vector_float_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kvfp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kucp_cint_cint (A : const_unsigned_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kucp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kscp_cint_cint (A : const_signed_char_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kscp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kusp_cint_cint (A : const_unsigned_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kusp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_ksp_cint_cint (A : const_short_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_ksp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kuip_cint_cint (A : const_unsigned_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kuip_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kip_cint_cint (A : const_int_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kip_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kulongp_cint_cint (A : const_unsigned_long_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kulongp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_klongp_cint_cint (A : const_long_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_klongp_cint_cint, "__builtin_altivec_dstt"); procedure vec_dstt_kfp_cint_cint (A : const_float_ptr; B : c_int; C : c_int); pragma Import (LL_Altivec, vec_dstt_kfp_cint_cint, "__builtin_altivec_dstt"); -- vec_sld -- -- ??? The base GCC implementation maps everything to vsldoi_4si, while -- it defines builtin variants for all the modes. Adjust here, to avoid -- the infamous argument mode mismatch. function vec_sld_vf_vf_cint_r_vf (A : vector_float; B : vector_float; C : c_int) return vector_float; pragma Import (LL_Altivec, vec_sld_vf_vf_cint_r_vf, "__builtin_altivec_vsldoi_4sf"); function vec_sld_vsi_vsi_cint_r_vsi (A : vector_signed_int; B : vector_signed_int; C : c_int) return vector_signed_int; pragma Import (LL_Altivec, vec_sld_vsi_vsi_cint_r_vsi, "__builtin_altivec_vsldoi_4si"); function vec_sld_vui_vui_cint_r_vui (A : vector_unsigned_int; B : vector_unsigned_int; C : c_int) return vector_unsigned_int; pragma Import (LL_Altivec, vec_sld_vui_vui_cint_r_vui, "__builtin_altivec_vsldoi_4si"); function vec_sld_vbi_vbi_cint_r_vbi (A : vector_bool_int; B : vector_bool_int; C : c_int) return vector_bool_int; pragma Import (LL_Altivec, vec_sld_vbi_vbi_cint_r_vbi, "__builtin_altivec_vsldoi_4si"); function vec_sld_vss_vss_cint_r_vss (A : vector_signed_short; B : vector_signed_short; C : c_int) return vector_signed_short; pragma Import (LL_Altivec, vec_sld_vss_vss_cint_r_vss, "__builtin_altivec_vsldoi_8hi"); function vec_sld_vus_vus_cint_r_vus (A : vector_unsigned_short; B : vector_unsigned_short; C : c_int) return vector_unsigned_short; pragma Import (LL_Altivec, vec_sld_vus_vus_cint_r_vus, "__builtin_altivec_vsldoi_8hi"); function vec_sld_vbs_vbs_cint_r_vbs (A : vector_bool_short; B : vector_bool_short; C : c_int) return vector_bool_short; pragma Import (LL_Altivec, vec_sld_vbs_vbs_cint_r_vbs, "__builtin_altivec_vsldoi_8hi"); function vec_sld_vx_vx_cint_r_vx (A : vector_pixel; B : vector_pixel; C : c_int) return vector_pixel; pragma Import (LL_Altivec, vec_sld_vx_vx_cint_r_vx, "__builtin_altivec_vsldoi_4si"); function vec_sld_vsc_vsc_cint_r_vsc (A : vector_signed_char; B : vector_signed_char; C : c_int) return vector_signed_char; pragma Import (LL_Altivec, vec_sld_vsc_vsc_cint_r_vsc, "__builtin_altivec_vsldoi_16qi"); function vec_sld_vuc_vuc_cint_r_vuc (A : vector_unsigned_char; B : vector_unsigned_char; C : c_int) return vector_unsigned_char; pragma Import (LL_Altivec, vec_sld_vuc_vuc_cint_r_vuc, "__builtin_altivec_vsldoi_16qi"); function vec_sld_vbc_vbc_cint_r_vbc (A : vector_bool_char; B : vector_bool_char; C : c_int) return vector_bool_char; pragma Import (LL_Altivec, vec_sld_vbc_vbc_cint_r_vbc, "__builtin_altivec_vsldoi_16qi"); -- vec_splat -- function vec_splat_vsc_cint_r_vsc (A : vector_signed_char; B : c_int) return vector_signed_char; pragma Import (LL_Altivec, vec_splat_vsc_cint_r_vsc, "__builtin_altivec_vspltb"); function vec_splat_vuc_cint_r_vuc (A : vector_unsigned_char; B : c_int) return vector_unsigned_char; pragma Import (LL_Altivec, vec_splat_vuc_cint_r_vuc, "__builtin_altivec_vspltb"); function vec_splat_vbc_cint_r_vbc (A : vector_bool_char; B : c_int) return vector_bool_char; pragma Import (LL_Altivec, vec_splat_vbc_cint_r_vbc, "__builtin_altivec_vspltb"); function vec_splat_vss_cint_r_vss (A : vector_signed_short; B : c_int) return vector_signed_short; pragma Import (LL_Altivec, vec_splat_vss_cint_r_vss, "__builtin_altivec_vsplth"); function vec_splat_vus_cint_r_vus (A : vector_unsigned_short; B : c_int) return vector_unsigned_short; pragma Import (LL_Altivec, vec_splat_vus_cint_r_vus, "__builtin_altivec_vsplth"); function vec_splat_vbs_cint_r_vbs (A : vector_bool_short; B : c_int) return vector_bool_short; pragma Import (LL_Altivec, vec_splat_vbs_cint_r_vbs, "__builtin_altivec_vsplth"); function vec_splat_vx_cint_r_vx (A : vector_pixel; B : c_int) return vector_pixel; pragma Import (LL_Altivec, vec_splat_vx_cint_r_vx, "__builtin_altivec_vsplth"); function vec_splat_vf_cint_r_vf (A : vector_float; B : c_int) return vector_float; pragma Import (LL_Altivec, vec_splat_vf_cint_r_vf, "__builtin_altivec_vspltw"); function vec_splat_vsi_cint_r_vsi (A : vector_signed_int; B : c_int) return vector_signed_int; pragma Import (LL_Altivec, vec_splat_vsi_cint_r_vsi, "__builtin_altivec_vspltw"); function vec_splat_vui_cint_r_vui (A : vector_unsigned_int; B : c_int) return vector_unsigned_int; pragma Import (LL_Altivec, vec_splat_vui_cint_r_vui, "__builtin_altivec_vspltw"); function vec_splat_vbi_cint_r_vbi (A : vector_bool_int; B : c_int) return vector_bool_int; pragma Import (LL_Altivec, vec_splat_vbi_cint_r_vbi, "__builtin_altivec_vspltw"); -- vec_vspltw -- function vec_vspltw_vf_cint_r_vf (A : vector_float; B : c_int) return vector_float; pragma Import (LL_Altivec, vec_vspltw_vf_cint_r_vf, "__builtin_altivec_vspltw"); function vec_vspltw_vsi_cint_r_vsi (A : vector_signed_int; B : c_int) return vector_signed_int; pragma Import (LL_Altivec, vec_vspltw_vsi_cint_r_vsi, "__builtin_altivec_vspltw"); function vec_vspltw_vui_cint_r_vui (A : vector_unsigned_int; B : c_int) return vector_unsigned_int; pragma Import (LL_Altivec, vec_vspltw_vui_cint_r_vui, "__builtin_altivec_vspltw"); function vec_vspltw_vbi_cint_r_vbi (A : vector_bool_int; B : c_int) return vector_bool_int; pragma Import (LL_Altivec, vec_vspltw_vbi_cint_r_vbi, "__builtin_altivec_vspltw"); -- vec_vsplth -- function vec_vsplth_vbs_cint_r_vbs (A : vector_bool_short; B : c_int) return vector_bool_short; pragma Import (LL_Altivec, vec_vsplth_vbs_cint_r_vbs, "__builtin_altivec_vsplth"); function vec_vsplth_vss_cint_r_vss (A : vector_signed_short; B : c_int) return vector_signed_short; pragma Import (LL_Altivec, vec_vsplth_vss_cint_r_vss, "__builtin_altivec_vsplth"); function vec_vsplth_vus_cint_r_vus (A : vector_unsigned_short; B : c_int) return vector_unsigned_short; pragma Import (LL_Altivec, vec_vsplth_vus_cint_r_vus, "__builtin_altivec_vsplth"); function vec_vsplth_vx_cint_r_vx (A : vector_pixel; B : c_int) return vector_pixel; pragma Import (LL_Altivec, vec_vsplth_vx_cint_r_vx, "__builtin_altivec_vsplth"); -- vec_vspltb -- function vec_vspltb_vsc_cint_r_vsc (A : vector_signed_char; B : c_int) return vector_signed_char; pragma Import (LL_Altivec, vec_vspltb_vsc_cint_r_vsc, "__builtin_altivec_vspltb"); function vec_vspltb_vuc_cint_r_vuc (A : vector_unsigned_char; B : c_int) return vector_unsigned_char; pragma Import (LL_Altivec, vec_vspltb_vuc_cint_r_vuc, "__builtin_altivec_vspltb"); function vec_vspltb_vbc_cint_r_vbc (A : vector_bool_char; B : c_int) return vector_bool_char; pragma Import (LL_Altivec, vec_vspltb_vbc_cint_r_vbc, "__builtin_altivec_vspltb"); -- vec_splat_s8 -- function vec_splat_s8_cint_r_vsc (A : c_int) return vector_signed_char; pragma Import (LL_Altivec, vec_splat_s8_cint_r_vsc, "__builtin_altivec_vspltisb"); -- vec_splat_s16 -- function vec_splat_s16_cint_r_vss (A : c_int) return vector_signed_short; pragma Import (LL_Altivec, vec_splat_s16_cint_r_vss, "__builtin_altivec_vspltish"); -- vec_splat_s32 -- function vec_splat_s32_cint_r_vsi (A : c_int) return vector_signed_int; pragma Import (LL_Altivec, vec_splat_s32_cint_r_vsi, "__builtin_altivec_vspltisw"); -- vec_splat_u8 -- function vec_splat_u8_cint_r_vuc (A : c_int) return vector_unsigned_char; pragma Import (LL_Altivec, vec_splat_u8_cint_r_vuc, "__builtin_altivec_vspltisb"); -- vec_splat_u16 -- function vec_splat_u16_cint_r_vus (A : c_int) return vector_unsigned_short; pragma Import (LL_Altivec, vec_splat_u16_cint_r_vus, "__builtin_altivec_vspltish"); -- vec_splat_u32 -- function vec_splat_u32_cint_r_vui (A : c_int) return vector_unsigned_int; pragma Import (LL_Altivec, vec_splat_u32_cint_r_vui, "__builtin_altivec_vspltisw"); ------------------------------------------------------------ -- Imports for low-level signature consistent subprograms -- ------------------------------------------------------------ -- vec_dssall -- procedure vec_dssall; pragma Import (LL_Altivec, vec_dssall, "__builtin_altivec_dssall"); ----------------------------------------- -- Conversions between low level types -- ----------------------------------------- use GNAT.Altivec.Low_Level_Vectors; -- Something like... -- -- TYPES="LL_VBC LL_VUC LL_VSC LL_VBS LL_VUS LL_VSS \ -- LL_VBI LL_VUI LL_VSI LL_VF LL_VP" -- for TT in `echo $TYPES`; do -- for ST in `echo $TYPES`; do -- echo "function To_$TT is new Ada.Unchecked_Conversion ($ST, $TT);" -- done -- echo "" -- done function To_LL_VBC is new Ada.Unchecked_Conversion (LL_VBC, LL_VBC); function To_LL_VBC is new Ada.Unchecked_Conversion (LL_VUC, LL_VBC); function To_LL_VBC is new Ada.Unchecked_Conversion (LL_VSC, LL_VBC); function To_LL_VBC is new Ada.Unchecked_Conversion (LL_VBS, LL_VBC); function To_LL_VBC is new Ada.Unchecked_Conversion (LL_VUS, LL_VBC); function To_LL_VBC is new Ada.Unchecked_Conversion (LL_VSS, LL_VBC); function To_LL_VBC is new Ada.Unchecked_Conversion (LL_VBI, LL_VBC); function To_LL_VBC is new Ada.Unchecked_Conversion (LL_VUI, LL_VBC); function To_LL_VBC is new Ada.Unchecked_Conversion (LL_VSI, LL_VBC); function To_LL_VBC is new Ada.Unchecked_Conversion (LL_VF, LL_VBC); function To_LL_VBC is new Ada.Unchecked_Conversion (LL_VP, LL_VBC); function To_LL_VUC is new Ada.Unchecked_Conversion (LL_VBC, LL_VUC); function To_LL_VUC is new Ada.Unchecked_Conversion (LL_VUC, LL_VUC); function To_LL_VUC is new Ada.Unchecked_Conversion (LL_VSC, LL_VUC); function To_LL_VUC is new Ada.Unchecked_Conversion (LL_VBS, LL_VUC); function To_LL_VUC is new Ada.Unchecked_Conversion (LL_VUS, LL_VUC); function To_LL_VUC is new Ada.Unchecked_Conversion (LL_VSS, LL_VUC); function To_LL_VUC is new Ada.Unchecked_Conversion (LL_VBI, LL_VUC); function To_LL_VUC is new Ada.Unchecked_Conversion (LL_VUI, LL_VUC); function To_LL_VUC is new Ada.Unchecked_Conversion (LL_VSI, LL_VUC); function To_LL_VUC is new Ada.Unchecked_Conversion (LL_VF, LL_VUC); function To_LL_VUC is new Ada.Unchecked_Conversion (LL_VP, LL_VUC); function To_LL_VSC is new Ada.Unchecked_Conversion (LL_VBC, LL_VSC); function To_LL_VSC is new Ada.Unchecked_Conversion (LL_VUC, LL_VSC); function To_LL_VSC is new Ada.Unchecked_Conversion (LL_VSC, LL_VSC); function To_LL_VSC is new Ada.Unchecked_Conversion (LL_VBS, LL_VSC); function To_LL_VSC is new Ada.Unchecked_Conversion (LL_VUS, LL_VSC); function To_LL_VSC is new Ada.Unchecked_Conversion (LL_VSS, LL_VSC); function To_LL_VSC is new Ada.Unchecked_Conversion (LL_VBI, LL_VSC); function To_LL_VSC is new Ada.Unchecked_Conversion (LL_VUI, LL_VSC); function To_LL_VSC is new Ada.Unchecked_Conversion (LL_VSI, LL_VSC); function To_LL_VSC is new Ada.Unchecked_Conversion (LL_VF, LL_VSC); function To_LL_VSC is new Ada.Unchecked_Conversion (LL_VP, LL_VSC); function To_LL_VBS is new Ada.Unchecked_Conversion (LL_VBC, LL_VBS); function To_LL_VBS is new Ada.Unchecked_Conversion (LL_VUC, LL_VBS); function To_LL_VBS is new Ada.Unchecked_Conversion (LL_VSC, LL_VBS); function To_LL_VBS is new Ada.Unchecked_Conversion (LL_VBS, LL_VBS); function To_LL_VBS is new Ada.Unchecked_Conversion (LL_VUS, LL_VBS); function To_LL_VBS is new Ada.Unchecked_Conversion (LL_VSS, LL_VBS); function To_LL_VBS is new Ada.Unchecked_Conversion (LL_VBI, LL_VBS); function To_LL_VBS is new Ada.Unchecked_Conversion (LL_VUI, LL_VBS); function To_LL_VBS is new Ada.Unchecked_Conversion (LL_VSI, LL_VBS); function To_LL_VBS is new Ada.Unchecked_Conversion (LL_VF, LL_VBS); function To_LL_VBS is new Ada.Unchecked_Conversion (LL_VP, LL_VBS); function To_LL_VUS is new Ada.Unchecked_Conversion (LL_VBC, LL_VUS); function To_LL_VUS is new Ada.Unchecked_Conversion (LL_VUC, LL_VUS); function To_LL_VUS is new Ada.Unchecked_Conversion (LL_VSC, LL_VUS); function To_LL_VUS is new Ada.Unchecked_Conversion (LL_VBS, LL_VUS); function To_LL_VUS is new Ada.Unchecked_Conversion (LL_VUS, LL_VUS); function To_LL_VUS is new Ada.Unchecked_Conversion (LL_VSS, LL_VUS); function To_LL_VUS is new Ada.Unchecked_Conversion (LL_VBI, LL_VUS); function To_LL_VUS is new Ada.Unchecked_Conversion (LL_VUI, LL_VUS); function To_LL_VUS is new Ada.Unchecked_Conversion (LL_VSI, LL_VUS); function To_LL_VUS is new Ada.Unchecked_Conversion (LL_VF, LL_VUS); function To_LL_VUS is new Ada.Unchecked_Conversion (LL_VP, LL_VUS); function To_LL_VSS is new Ada.Unchecked_Conversion (LL_VBC, LL_VSS); function To_LL_VSS is new Ada.Unchecked_Conversion (LL_VUC, LL_VSS); function To_LL_VSS is new Ada.Unchecked_Conversion (LL_VSC, LL_VSS); function To_LL_VSS is new Ada.Unchecked_Conversion (LL_VBS, LL_VSS); function To_LL_VSS is new Ada.Unchecked_Conversion (LL_VUS, LL_VSS); function To_LL_VSS is new Ada.Unchecked_Conversion (LL_VSS, LL_VSS); function To_LL_VSS is new Ada.Unchecked_Conversion (LL_VBI, LL_VSS); function To_LL_VSS is new Ada.Unchecked_Conversion (LL_VUI, LL_VSS); function To_LL_VSS is new Ada.Unchecked_Conversion (LL_VSI, LL_VSS); function To_LL_VSS is new Ada.Unchecked_Conversion (LL_VF, LL_VSS); function To_LL_VSS is new Ada.Unchecked_Conversion (LL_VP, LL_VSS); function To_LL_VBI is new Ada.Unchecked_Conversion (LL_VBC, LL_VBI); function To_LL_VBI is new Ada.Unchecked_Conversion (LL_VUC, LL_VBI); function To_LL_VBI is new Ada.Unchecked_Conversion (LL_VSC, LL_VBI); function To_LL_VBI is new Ada.Unchecked_Conversion (LL_VBS, LL_VBI); function To_LL_VBI is new Ada.Unchecked_Conversion (LL_VUS, LL_VBI); function To_LL_VBI is new Ada.Unchecked_Conversion (LL_VSS, LL_VBI); function To_LL_VBI is new Ada.Unchecked_Conversion (LL_VBI, LL_VBI); function To_LL_VBI is new Ada.Unchecked_Conversion (LL_VUI, LL_VBI); function To_LL_VBI is new Ada.Unchecked_Conversion (LL_VSI, LL_VBI); function To_LL_VBI is new Ada.Unchecked_Conversion (LL_VF, LL_VBI); function To_LL_VBI is new Ada.Unchecked_Conversion (LL_VP, LL_VBI); function To_LL_VUI is new Ada.Unchecked_Conversion (LL_VBC, LL_VUI); function To_LL_VUI is new Ada.Unchecked_Conversion (LL_VUC, LL_VUI); function To_LL_VUI is new Ada.Unchecked_Conversion (LL_VSC, LL_VUI); function To_LL_VUI is new Ada.Unchecked_Conversion (LL_VBS, LL_VUI); function To_LL_VUI is new Ada.Unchecked_Conversion (LL_VUS, LL_VUI); function To_LL_VUI is new Ada.Unchecked_Conversion (LL_VSS, LL_VUI); function To_LL_VUI is new Ada.Unchecked_Conversion (LL_VBI, LL_VUI); function To_LL_VUI is new Ada.Unchecked_Conversion (LL_VUI, LL_VUI); function To_LL_VUI is new Ada.Unchecked_Conversion (LL_VSI, LL_VUI); function To_LL_VUI is new Ada.Unchecked_Conversion (LL_VF, LL_VUI); function To_LL_VUI is new Ada.Unchecked_Conversion (LL_VP, LL_VUI); function To_LL_VSI is new Ada.Unchecked_Conversion (LL_VBC, LL_VSI); function To_LL_VSI is new Ada.Unchecked_Conversion (LL_VUC, LL_VSI); function To_LL_VSI is new Ada.Unchecked_Conversion (LL_VSC, LL_VSI); function To_LL_VSI is new Ada.Unchecked_Conversion (LL_VBS, LL_VSI); function To_LL_VSI is new Ada.Unchecked_Conversion (LL_VUS, LL_VSI); function To_LL_VSI is new Ada.Unchecked_Conversion (LL_VSS, LL_VSI); function To_LL_VSI is new Ada.Unchecked_Conversion (LL_VBI, LL_VSI); function To_LL_VSI is new Ada.Unchecked_Conversion (LL_VUI, LL_VSI); function To_LL_VSI is new Ada.Unchecked_Conversion (LL_VSI, LL_VSI); function To_LL_VSI is new Ada.Unchecked_Conversion (LL_VF, LL_VSI); function To_LL_VSI is new Ada.Unchecked_Conversion (LL_VP, LL_VSI); function To_LL_VF is new Ada.Unchecked_Conversion (LL_VBC, LL_VF); function To_LL_VF is new Ada.Unchecked_Conversion (LL_VUC, LL_VF); function To_LL_VF is new Ada.Unchecked_Conversion (LL_VSC, LL_VF); function To_LL_VF is new Ada.Unchecked_Conversion (LL_VBS, LL_VF); function To_LL_VF is new Ada.Unchecked_Conversion (LL_VUS, LL_VF); function To_LL_VF is new Ada.Unchecked_Conversion (LL_VSS, LL_VF); function To_LL_VF is new Ada.Unchecked_Conversion (LL_VBI, LL_VF); function To_LL_VF is new Ada.Unchecked_Conversion (LL_VUI, LL_VF); function To_LL_VF is new Ada.Unchecked_Conversion (LL_VSI, LL_VF); function To_LL_VF is new Ada.Unchecked_Conversion (LL_VF, LL_VF); function To_LL_VF is new Ada.Unchecked_Conversion (LL_VP, LL_VF); function To_LL_VP is new Ada.Unchecked_Conversion (LL_VBC, LL_VP); function To_LL_VP is new Ada.Unchecked_Conversion (LL_VUC, LL_VP); function To_LL_VP is new Ada.Unchecked_Conversion (LL_VSC, LL_VP); function To_LL_VP is new Ada.Unchecked_Conversion (LL_VBS, LL_VP); function To_LL_VP is new Ada.Unchecked_Conversion (LL_VUS, LL_VP); function To_LL_VP is new Ada.Unchecked_Conversion (LL_VSS, LL_VP); function To_LL_VP is new Ada.Unchecked_Conversion (LL_VBI, LL_VP); function To_LL_VP is new Ada.Unchecked_Conversion (LL_VUI, LL_VP); function To_LL_VP is new Ada.Unchecked_Conversion (LL_VSI, LL_VP); function To_LL_VP is new Ada.Unchecked_Conversion (LL_VF, LL_VP); function To_LL_VP is new Ada.Unchecked_Conversion (LL_VP, LL_VP); ---------------------------------------------- -- Conversions between pointer/access types -- ---------------------------------------------- function To_PTR is new Ada.Unchecked_Conversion (vector_unsigned_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (vector_signed_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (vector_bool_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (vector_unsigned_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (vector_signed_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (vector_bool_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (vector_unsigned_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (vector_signed_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (vector_bool_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (vector_float_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (vector_pixel_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_vector_bool_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_vector_signed_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_vector_unsigned_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_vector_bool_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_vector_signed_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_vector_unsigned_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_vector_bool_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_vector_signed_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_vector_unsigned_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_vector_float_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_vector_pixel_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (c_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (signed_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (unsigned_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (signed_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (unsigned_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (signed_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (unsigned_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (long_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (signed_long_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (unsigned_long_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (float_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_signed_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_unsigned_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_signed_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_unsigned_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_signed_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_unsigned_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_long_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_signed_long_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_unsigned_long_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (const_float_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_signed_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_unsigned_char_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_signed_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_unsigned_short_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_signed_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_unsigned_int_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_long_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_signed_long_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_unsigned_long_ptr, c_ptr); function To_PTR is new Ada.Unchecked_Conversion (constv_float_ptr, c_ptr); end GNAT.Altivec.Low_Level_Interface;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M -- -- -- -- S p e c -- -- -- -- Copyright (C) 1992-2020, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. 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. -- -- -- ------------------------------------------------------------------------------ -------------------------------------- -- Semantic Analysis: General Model -- -------------------------------------- -- Semantic processing involves 3 phases which are highly intertwined -- (i.e. mutually recursive): -- Analysis implements the bulk of semantic analysis such as -- name analysis and type resolution for declarations, -- instructions and expressions. The main routine -- driving this process is procedure Analyze given below. -- This analysis phase is really a bottom up pass that is -- achieved during the recursive traversal performed by the -- Analyze_... procedures implemented in the sem_* packages. -- For expressions this phase determines unambiguous types -- and collects sets of possible types where the -- interpretation is potentially ambiguous. -- Resolution is carried out only for expressions to finish type -- resolution that was initiated but not necessarily -- completed during analysis (because of overloading -- ambiguities). Specifically, after completing the bottom -- up pass carried out during analysis for expressions, the -- Resolve routine (see the spec of sem_res for more info) -- is called to perform a top down resolution with -- recursive calls to itself to resolve operands. -- Expansion if we are not generating code this phase is a no-op. -- Otherwise this phase expands, i.e. transforms, original -- declaration, expressions or instructions into simpler -- structures that can be handled by the back-end. This -- phase is also in charge of generating code which is -- implicit in the original source (for instance for -- default initializations, controlled types, etc.) -- There are two separate instances where expansion is -- invoked. For declarations and instructions, expansion is -- invoked just after analysis since no resolution needs -- to be performed. For expressions, expansion is done just -- after resolution. In both cases expansion is done from the -- bottom up just before the end of Analyze for instructions -- and declarations or the call to Resolve for expressions. -- The main routine driving expansion is Expand. -- See the spec of Expander for more details. -- To summarize, in normal code generation mode we recursively traverse the -- abstract syntax tree top-down performing semantic analysis bottom -- up. For instructions and declarations, before the call to the Analyze -- routine completes we perform expansion since at that point we have all -- semantic information needed. For expression nodes, after the call to -- Analyze terminates we invoke the Resolve routine to transmit top-down -- the type that was gathered by Analyze which will resolve possible -- ambiguities in the expression. Just before the call to Resolve -- terminates, the expression can be expanded since all the semantic -- information is available at that point. -- If we are not generating code then the expansion phase is a no-op -- When generating code there are a number of exceptions to the basic -- Analysis-Resolution-Expansion model for expressions. The most prominent -- examples are the handling of default expressions and aggregates. ----------------------------------------------------------------------- -- Handling of Default and Per-Object Expressions (Spec-Expressions) -- ----------------------------------------------------------------------- -- The default expressions in component declarations and in procedure -- specifications (but not the ones in object declarations) are quite tricky -- to handle. The problem is that some processing is required at the point -- where the expression appears: -- visibility analysis (including user defined operators) -- freezing of static expressions -- but other processing must be deferred until the enclosing entity (record or -- procedure specification) is frozen: -- freezing of any other types in the expression expansion -- generation of code -- A similar situation occurs with the argument of priority and interrupt -- priority pragmas that appear in task and protected definition specs and -- other cases of per-object expressions (see RM 3.8(18)). -- Another similar case is the conditions in precondition and postcondition -- pragmas that appear with subprogram specifications rather than in the body. -- Collectively we call these Spec_Expressions. The routine that performs the -- special analysis is called Analyze_Spec_Expression. -- Expansion has to be deferred since you can't generate code for expressions -- that reference types that have not been frozen yet. As an example, consider -- the following: -- type x is delta 0.5 range -10.0 .. +10.0; -- ... -- type q is record -- xx : x := y * z; -- end record; -- for x'small use 0.25; -- The expander is in charge of dealing with fixed-point, and of course the -- small declaration, which is not too late, since the declaration of type q -- does *not* freeze type x, definitely affects the expanded code. -- Another reason that we cannot expand early is that expansion can generate -- range checks. These range checks need to be inserted not at the point of -- definition but at the point of use. The whole point here is that the value -- of the expression cannot be obtained at the point of declaration, only at -- the point of use. -- Generally our model is to combine analysis resolution and expansion, but -- this is the one case where this model falls down. Here is how we patch -- it up without causing too much distortion to our basic model. -- A flag (In_Spec_Expression) is set to show that we are in the initial -- occurrence of a default expression. The analyzer is then called on this -- expression with the switch set true. Analysis and resolution proceed almost -- as usual, except that Freeze_Expression will not freeze non-static -- expressions if this switch is set, and the call to Expand at the end of -- resolution is skipped. This also skips the code that normally sets the -- Analyzed flag to True. The result is that when we are done the tree is -- still marked as unanalyzed, but all types for static expressions are frozen -- as required, and all entities of variables have been recorded. We then turn -- off the switch, and later on reanalyze the expression with the switch off. -- The effect is that this second analysis freezes the rest of the types as -- required, and generates code but visibility analysis is not repeated since -- all the entities are marked. -- The second analysis (the one that generates code) is in the context -- where the code is required. For a record field default, this is in the -- initialization procedure for the record and for a subprogram default -- parameter, it is at the point the subprogram is frozen. For a priority or -- storage size pragma it is in the context of the Init_Proc for the task or -- protected object. For a pre/postcondition pragma it is in the body when -- code for the pragma is generated. ------------------ -- Preanalysis -- ------------------ -- For certain kind of expressions, such as aggregates, we need to defer -- expansion of the aggregate and its inner expressions until after the whole -- set of expressions appearing inside the aggregate have been analyzed. -- Consider, for instance the following example: -- -- (1 .. 100 => new Thing (Function_Call)) -- -- The normal Analysis-Resolution-Expansion mechanism where expansion of the -- children is performed before expansion of the parent does not work if the -- code generated for the children by the expander needs to be evaluated -- repeatedly (for instance in the above aggregate "new Thing (Function_Call)" -- needs to be called 100 times.) -- The reason this mechanism does not work is that the expanded code for the -- children is typically inserted above the parent and thus when the parent -- gets expanded no re-evaluation takes place. For instance in the case of -- aggregates if "new Thing (Function_Call)" is expanded before the aggregate -- the expanded code will be placed outside of the aggregate and when -- expanding the aggregate the loop from 1 to 100 will not surround the -- expanded code for "new Thing (Function_Call)". -- To remedy this situation we introduce a flag that signals whether we want a -- full analysis (i.e. expansion is enabled) or a preanalysis which performs -- Analysis and Resolution but no expansion. -- After the complete preanalysis of an expression has been carried out we -- can transform the expression and then carry out the full three stage -- (Analyze-Resolve-Expand) cycle on the transformed expression top-down so -- that the expansion of inner expressions happens inside the newly generated -- node for the parent expression. -- Note that the difference between processing of default expressions and -- preanalysis of other expressions is that we do carry out freezing in -- the latter but not in the former (except for static scalar expressions). -- The routine that performs preanalysis and corresponding resolution is -- called Preanalyze_And_Resolve and is in Sem_Res. with Alloc; with Einfo; use Einfo; with Opt; use Opt; with Table; with Types; use Types; package Sem is ----------------------------- -- Semantic Analysis Flags -- ----------------------------- Full_Analysis : Boolean := True; -- Switch to indicate if we are doing a full analysis or a preanalysis. -- In normal analysis mode (Analysis-Expansion for instructions or -- declarations) or (Analysis-Resolution-Expansion for expressions) this -- flag is set. Note that if we are not generating code the expansion phase -- merely sets the Analyzed flag to True in this case. If we are in -- Preanalysis mode (see above) this flag is set to False then the -- expansion phase is skipped. -- -- When this flag is False the flag Expander_Active is also False (the -- Expander_Active flag defined in the spec of package Expander tells you -- whether expansion is currently enabled). You should really regard this -- as a read only flag. In_Spec_Expression : Boolean := False; -- Switch to indicate that we are in a spec-expression, as described -- above. Note that this must be recursively saved on a Semantics call -- since it is possible for the analysis of an expression to result in a -- recursive call (e.g. to get the entity for System.Address as part of the -- processing of an Address attribute reference). When this switch is True -- then Full_Analysis above must be False. You should really regard this as -- a read only flag. In_Deleted_Code : Boolean := False; -- If the condition in an if-statement is statically known, the branch -- that is not taken is analyzed with expansion disabled, and the tree -- is deleted after analysis. Itypes generated in deleted code must be -- frozen from start, because the tree on which they depend will not -- be available at the freeze point. In_Assertion_Expr : Nat := 0; -- This is set non-zero if we are within the expression of an assertion -- pragma or aspect. It is incremented at the start of expanding such an -- expression, and decremented on completion of expanding that -- expression. This needs to be a counter, rather than a Boolean, because -- assertions can contain declare_expressions, which can contain -- assertions. As with In_Spec_Expression, it must be recursively saved and -- restored for a Semantics call. In_Declare_Expr : Nat := 0; -- This is set non-zero if we are within a declare_expression. It is -- incremented at the start of expanding such an expression, and -- decremented on completion of expanding that expression. This needs to be -- a counter, rather than a Boolean, because declare_expressions can -- nest. As with In_Spec_Expression, it must be recursively saved and -- restored for a Semantics call. In_Compile_Time_Warning_Or_Error : Boolean := False; -- Switch to indicate that we are validating a pragma Compile_Time_Warning -- or Compile_Time_Error after the back end has been called (to check these -- pragmas for size and alignment appropriateness). In_Default_Expr : Boolean := False; -- Switch to indicate that we are analyzing a default component expression. -- As with In_Spec_Expression, it must be recursively saved and restored -- for a Semantics call. In_Inlined_Body : Boolean := False; -- Switch to indicate that we are analyzing and resolving an inlined body. -- Type checking is disabled in this context, because types are known to be -- compatible. This avoids problems with private types whose full view is -- derived from private types. Inside_A_Generic : Boolean := False; -- This flag is set if we are processing a generic specification, generic -- definition, or generic body. When this flag is True the Expander_Active -- flag is False to disable any code expansion (see package Expander). Only -- the generic processing can modify the status of this flag, any other -- client should regard it as read-only. Inside_Freezing_Actions : Nat := 0; -- Flag indicating whether we are within a call to Expand_N_Freeze_Actions. -- Non-zero means we are inside (it is actually a level counter to deal -- with nested calls). Used to avoid traversing the tree each time a -- subprogram call is processed to know if we must not clear all constant -- indications from entities in the current scope. Only the expansion of -- freezing nodes can modify the status of this flag, any other client -- should regard it as read-only. Inside_Preanalysis_Without_Freezing : Nat := 0; -- Flag indicating whether we are preanalyzing an expression performing no -- freezing. Non-zero means we are inside (it is actually a level counter -- to deal with nested calls). Unloaded_Subunits : Boolean := False; -- This flag is set True if we have subunits that are not loaded. This -- occurs when the main unit is a subunit, and contains lower level -- subunits that are not loaded. We use this flag to suppress warnings -- about unused variables, since these warnings are unreliable in this -- case. We could perhaps do a more accurate job and retain some of the -- warnings, but it is quite a tricky job. ----------------------------------- -- Handling of Check Suppression -- ----------------------------------- -- There are two kinds of suppress checks: scope based suppress checks, -- and entity based suppress checks. -- Scope based suppress checks for the predefined checks (from initial -- command line arguments, or from Suppress pragmas not including an entity -- name) are recorded in the Sem.Scope_Suppress variable, and all that -- is necessary is to save the state of this variable on scope entry, and -- restore it on scope exit. This mechanism allows for fast checking of the -- scope suppress state without needing complex data structures. -- Entity based checks, from Suppress/Unsuppress pragmas giving an -- Entity_Id and scope based checks for non-predefined checks (introduced -- using pragma Check_Name), are handled as follows. If a suppress or -- unsuppress pragma is encountered for a given entity, then the flag -- Checks_May_Be_Suppressed is set in the entity and an entry is made in -- either the Local_Entity_Suppress stack (case of pragma that appears in -- other than a package spec), or in the Global_Entity_Suppress stack (case -- of pragma that appears in a package spec, which is by the rule of RM -- 11.5(7) applicable throughout the life of the entity). Similarly, a -- Suppress/Unsuppress pragma for a non-predefined check which does not -- specify an entity is also stored in one of these stacks. -- If the Checks_May_Be_Suppressed flag is set in an entity then the -- procedure is to search first the local and then the global suppress -- stacks (we search these in reverse order, top element first). The only -- other point is that we have to make sure that we have proper nested -- interaction between such specific pragmas and locally applied general -- pragmas applying to all entities. This is achieved by including in the -- Local_Entity_Suppress table dummy entries with an empty Entity field -- that are applicable to all entities. A similar search is needed for any -- non-predefined check even if no specific entity is involved. Scope_Suppress : Suppress_Record; -- This variable contains the current scope based settings of the suppress -- switches. It is initialized from Suppress_Options in Gnat1drv, and then -- modified by pragma Suppress. On entry to each scope, the current setting -- is saved on the scope stack, and then restored on exit from the scope. -- This record may be rapidly checked to determine the current status of -- a check if no specific entity is involved or if the specific entity -- involved is one for which no specific Suppress/Unsuppress pragma has -- been set (as indicated by the Checks_May_Be_Suppressed flag being set). -- This scheme is a little complex, but serves the purpose of enabling -- a very rapid check in the common case where no entity specific pragma -- applies, and gives the right result when such pragmas are used even -- in complex cases of nested Suppress and Unsuppress pragmas. -- The Local_Entity_Suppress and Global_Entity_Suppress stacks are handled -- using dynamic allocation and linked lists. We do not often use this -- approach in the compiler (preferring to use extensible tables instead). -- The reason we do it here is that scope stack entries save a pointer to -- the current local stack top, which is also saved and restored on scope -- exit. Furthermore for processing of generics we save pointers to the -- top of the stack, so that the local stack is actually a tree of stacks -- rather than a single stack, a structure that is easy to represent using -- linked lists, but impossible to represent using a single table. Note -- that because of the generic issue, we never release entries in these -- stacks, but that's no big deal, since we are unlikely to have a huge -- number of Suppress/Unsuppress entries in a single compilation. type Suppress_Stack_Entry; type Suppress_Stack_Entry_Ptr is access all Suppress_Stack_Entry; type Suppress_Stack_Entry is record Entity : Entity_Id; -- Entity to which the check applies, or Empty for a check that has -- no entity name (and thus applies to all entities). Check : Check_Id; -- Check which is set (can be All_Checks for the All_Checks case) Suppress : Boolean; -- Set True for Suppress, and False for Unsuppress Prev : Suppress_Stack_Entry_Ptr; -- Pointer to previous entry on stack Next : Suppress_Stack_Entry_Ptr; -- All allocated Suppress_Stack_Entry records are chained together in -- a linked list whose head is Suppress_Stack_Entries, and the Next -- field is used as a forward pointer (null ends the list). This is -- used to free all entries in Sem.Init (which will be important if -- we ever setup the compiler to be reused). end record; Suppress_Stack_Entries : Suppress_Stack_Entry_Ptr := null; -- Pointer to linked list of records (see comments for Next above) Local_Suppress_Stack_Top : Suppress_Stack_Entry_Ptr; -- Pointer to top element of local suppress stack. This is the entry that -- is saved and restored in the scope stack, and also saved for generic -- body expansion. Global_Suppress_Stack_Top : Suppress_Stack_Entry_Ptr; -- Pointer to top element of global suppress stack procedure Push_Local_Suppress_Stack_Entry (Entity : Entity_Id; Check : Check_Id; Suppress : Boolean); -- Push a new entry on to the top of the local suppress stack, updating -- the value in Local_Suppress_Stack_Top; procedure Push_Global_Suppress_Stack_Entry (Entity : Entity_Id; Check : Check_Id; Suppress : Boolean); -- Push a new entry on to the top of the global suppress stack, updating -- the value in Global_Suppress_Stack_Top; ----------------- -- Scope Stack -- ----------------- -- The scope stack indicates the declarative regions that are currently -- being processed (analyzed and/or expanded). The scope stack is one of -- the basic visibility structures in the compiler: entities that are -- declared in a scope that is currently on the scope stack are immediately -- visible (leaving aside issues of hiding and overloading). -- Initially, the scope stack only contains an entry for package Standard. -- When a compilation unit, subprogram unit, block or declarative region -- is being processed, the corresponding entity is pushed on the scope -- stack. It is removed after the processing step is completed. A given -- entity can be placed several times on the scope stack, for example -- when processing derived type declarations, freeze nodes, etc. The top -- of the scope stack is the innermost scope currently being processed. -- It is obtained through function Current_Scope. After a compilation unit -- has been processed, the scope stack must contain only Standard. -- The predicate In_Open_Scopes specifies whether a scope is currently -- on the scope stack. -- This model is complicated by the need to compile units on the fly, in -- the middle of the compilation of other units. This arises when compiling -- instantiations, and when compiling run-time packages obtained through -- rtsfind. Given that the scope stack is a single static and global -- structure (not originally designed for the recursive processing required -- by rtsfind for example) additional machinery is needed to indicate what -- is currently being compiled. As a result, the scope stack holds several -- contiguous sections that correspond to the compilation of a given -- compilation unit. These sections are separated by distinct occurrences -- of package Standard. The currently active section of the scope stack -- goes from the current scope to the first (innermost) occurrence of -- Standard, which is additionally marked with flag Is_Active_Stack_Base. -- The basic visibility routine (Find_Direct_Name, in Sem_Ch8) uses this -- contiguous section of the scope stack to determine whether a given -- entity is or is not visible at a point. In_Open_Scopes only examines -- the currently active section of the scope stack. -- Similar complications arise when processing child instances. These -- must be compiled in the context of parent instances, and therefore the -- parents must be pushed on the stack before compiling the child, and -- removed afterwards. Routines Save_Scope_Stack and Restore_Scope_Stack -- are used to set/reset the visibility of entities declared in scopes -- that are currently on the scope stack, and are used when compiling -- instance bodies on the fly. -- It is clear in retrospect that all semantic processing and visibility -- structures should have been fully recursive. The rtsfind mechanism, -- and the complexities brought about by subunits and by generic child -- units and their instantiations, have led to a hybrid model that carries -- more state than one would wish. type Scope_Action_Kind is (Before, After, Cleanup); type Scope_Actions is array (Scope_Action_Kind) of List_Id; -- Transient blocks have three associated actions list, to be inserted -- before and after the block's statements, and as cleanup actions. Configuration_Component_Alignment : Component_Alignment_Kind := Calign_Default; -- Used for handling the pragma Component_Alignment in the context of a -- configuration file. type Scope_Stack_Entry is record Entity : Entity_Id; -- Entity representing the scope Last_Subprogram_Name : String_Ptr; -- Pointer to name of last subprogram body in this scope. Used for -- testing proper alpha ordering of subprogram bodies in scope. Save_Scope_Suppress : Suppress_Record; -- Save contents of Scope_Suppress on entry Save_Local_Suppress_Stack_Top : Suppress_Stack_Entry_Ptr; -- Save contents of Local_Suppress_Stack on entry to restore on exit Save_Check_Policy_List : Node_Id; -- Save contents of Check_Policy_List on entry to restore on exit. The -- Check_Policy pragmas are chained with Check_Policy_List pointing to -- the most recent entry. This list is searched starting here, so that -- the search finds the most recent appicable entry. When we restore -- Check_Policy_List on exit from the scope, the effect is to remove -- all entries set in the scope being exited. Save_Default_Storage_Pool : Node_Id; -- Save contents of Default_Storage_Pool on entry to restore on exit Save_SPARK_Mode : SPARK_Mode_Type; -- Setting of SPARK_Mode on entry to restore on exit Save_SPARK_Mode_Pragma : Node_Id; -- Setting of SPARK_Mode_Pragma on entry to restore on exit Save_No_Tagged_Streams : Node_Id; -- Setting of No_Tagged_Streams to restore on exit Save_Default_SSO : Character; -- Setting of Default_SSO on entry to restore on exit Save_Uneval_Old : Character; -- Setting of Uneval_Old on entry to restore on exit Is_Transient : Boolean; -- Marks transient scopes (see Exp_Ch7 body for details) Previous_Visibility : Boolean; -- Used when installing the parent(s) of the current compilation unit. -- The parent may already be visible because of an ongoing compilation, -- and the proper visibility must be restored on exit. The flag is -- typically needed when the context of a child unit requires -- compilation of a sibling. In other cases the flag is set to False. -- See Sem_Ch10 (Install_Parents, Remove_Parents). Node_To_Be_Wrapped : Node_Id; -- Only used in transient scopes. Records the node which will be wrapped -- by the transient block. Actions_To_Be_Wrapped : Scope_Actions; -- Actions that have to be inserted at the start, at the end, or as -- cleanup actions of a transient block. Used to temporarily hold these -- actions until the block is created, at which time the actions are -- moved to the block. Pending_Freeze_Actions : List_Id; -- Used to collect freeze entity nodes and associated actions that are -- generated in an inner context but need to be analyzed outside, such -- as records and initialization procedures. On exit from the scope, -- this list of actions is inserted before the scope construct and -- analyzed to generate the corresponding freeze processing and -- elaboration of other associated actions. First_Use_Clause : Node_Id; -- Head of list of Use_Clauses in current scope. The list is built when -- the declarations in the scope are processed. The list is traversed -- on scope exit to undo the effect of the use clauses. Component_Alignment_Default : Component_Alignment_Kind; -- Component alignment to be applied to any record or array types that -- are declared for which a specific component alignment pragma does not -- set the alignment. Is_Active_Stack_Base : Boolean; -- Set to true only when entering the scope for Standard_Standard from -- from within procedure Semantics. Indicates the base of the current -- active set of scopes. Needed by In_Open_Scopes to handle cases where -- Standard_Standard can be pushed anew on the scope stack to start a -- new active section (see comment above). Locked_Shared_Objects : Elist_Id; -- List of shared passive protected objects that have been locked in -- this transient scope (always No_Elist for non-transient scopes). end record; package Scope_Stack is new Table.Table ( Table_Component_Type => Scope_Stack_Entry, Table_Index_Type => Int, Table_Low_Bound => 0, Table_Initial => Alloc.Scope_Stack_Initial, Table_Increment => Alloc.Scope_Stack_Increment, Table_Name => "Sem.Scope_Stack"); ----------------- -- Subprograms -- ----------------- procedure Initialize; -- Initialize internal tables procedure Lock; -- Lock internal tables before calling back end procedure Unlock; -- Unlock internal tables procedure Semantics (Comp_Unit : Node_Id); -- This procedure is called to perform semantic analysis on the specified -- node which is the N_Compilation_Unit node for the unit. procedure Analyze (N : Node_Id); procedure Analyze (N : Node_Id; Suppress : Check_Id); -- This is the recursive procedure that is applied to individual nodes of -- the tree, starting at the top level node (compilation unit node) and -- then moving down the tree in a top down traversal. It calls individual -- routines with names Analyze_xxx to analyze node xxx. Each of these -- routines is responsible for calling Analyze on the components of the -- subtree. -- -- Note: In the case of expression components (nodes whose Nkind is in -- N_Subexpr), the call to Analyze does not complete the semantic analysis -- of the node, since the type resolution cannot be completed until the -- complete context is analyzed. The completion of the type analysis occurs -- in the corresponding Resolve routine (see Sem_Res). -- -- Note: for integer and real literals, the analyzer sets the flag to -- indicate that the result is a static expression. If the expander -- generates a literal that does NOT correspond to a static expression, -- e.g. by folding an expression whose value is known at compile time, -- but is not technically static, then the caller should reset the -- Is_Static_Expression flag after analyzing but before resolving. -- -- If the Suppress argument is present, then the analysis is done -- with the specified check suppressed (can be All_Checks to suppress -- all checks). procedure Analyze_List (L : List_Id); procedure Analyze_List (L : List_Id; Suppress : Check_Id); -- Analyzes each element of a list. If the Suppress argument is present, -- then the analysis is done with the specified check suppressed (can -- be All_Checks to suppress all checks). procedure Copy_Suppress_Status (C : Check_Id; From : Entity_Id; To : Entity_Id); -- If From is an entity for which check C is explicitly suppressed -- then also explicitly suppress the corresponding check in To. procedure Insert_List_After_And_Analyze (N : Node_Id; L : List_Id); -- Inserts list L after node N using Nlists.Insert_List_After, and then, -- after this insertion is complete, analyzes all the nodes in the list, -- including any additional nodes generated by this analysis. If the list -- is empty or No_List, the call has no effect. procedure Insert_List_Before_And_Analyze (N : Node_Id; L : List_Id); -- Inserts list L before node N using Nlists.Insert_List_Before, and then, -- after this insertion is complete, analyzes all the nodes in the list, -- including any additional nodes generated by this analysis. If the list -- is empty or No_List, the call has no effect. procedure Insert_After_And_Analyze (N : Node_Id; M : Node_Id); procedure Insert_After_And_Analyze (N : Node_Id; M : Node_Id; Suppress : Check_Id); -- Inserts node M after node N and then after the insertion is complete, -- analyzes the inserted node and all nodes that are generated by -- this analysis. If the node is empty, the call has no effect. If the -- Suppress argument is present, then the analysis is done with the -- specified check suppressed (can be All_Checks to suppress all checks). procedure Insert_Before_And_Analyze (N : Node_Id; M : Node_Id); procedure Insert_Before_And_Analyze (N : Node_Id; M : Node_Id; Suppress : Check_Id); -- Inserts node M before node N and then after the insertion is complete, -- analyzes the inserted node and all nodes that could be generated by -- this analysis. If the node is empty, the call has no effect. If the -- Suppress argument is present, then the analysis is done with the -- specified check suppressed (can be All_Checks to suppress all checks). procedure Insert_Before_First_Source_Declaration (Stmt : Node_Id; Decls : List_Id); -- Insert node Stmt before the first source declaration of the related -- subprogram's body. If no such declaration exists, Stmt becomes the last -- declaration. function External_Ref_In_Generic (E : Entity_Id) return Boolean; -- Return True if we are in the context of a generic and E is -- external (more global) to it. procedure Enter_Generic_Scope (S : Entity_Id); -- Called each time a Generic subprogram or package scope is entered. S is -- the entity of the scope. -- -- ??? At the moment, only called for package specs because this mechanism -- is only used for avoiding freezing of external references in generics -- and this can only be an issue if the outer generic scope is a package -- spec (otherwise all external entities are already frozen) procedure Exit_Generic_Scope (S : Entity_Id); -- Called each time a Generic subprogram or package scope is exited. S is -- the entity of the scope. -- -- ??? At the moment, only called for package specs exit. function Explicit_Suppress (E : Entity_Id; C : Check_Id) return Boolean; -- This function returns True if an explicit pragma Suppress for check C -- is present in the package defining E. function Preanalysis_Active return Boolean; pragma Inline (Preanalysis_Active); -- Determine whether preanalysis is active at the point of invocation procedure Preanalyze (N : Node_Id); -- Performs a preanalysis of node N. During preanalysis no expansion is -- carried out for N or its children. See above for more info on -- preanalysis. generic with procedure Action (Item : Node_Id); procedure Walk_Library_Items; -- Primarily for use by CodePeer and GNATprove. Must be called after -- semantic analysis (and expansion in the case of CodePeer) are complete. -- Walks each relevant library item, calling Action for each, in an order -- such that one will not run across forward references. Each Item passed -- to Action is the declaration or body of a library unit, including -- generics and renamings. The first item is the N_Package_Declaration node -- for package Standard. Bodies are not included, except for the main unit -- itself, which always comes last. -- -- Item is never a subunit -- -- Item is never an instantiation. Instead, the instance declaration is -- passed, and (if the instantiation is the main unit), the instance body. ------------------------ -- Debugging Routines -- ------------------------ function ss (Index : Int) return Scope_Stack_Entry; pragma Export (Ada, ss); -- "ss" = "scope stack"; returns the Index'th entry in the Scope_Stack function sst return Scope_Stack_Entry; pragma Export (Ada, sst); -- "sst" = "scope stack top"; same as ss(Scope_Stack.Last) end Sem;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Containers.Ordered_Maps; use Ada.Containers; with Interfaces.C; use Interfaces.C; with GNAT.Regpat; use GNAT.Regpat; with Device; use Device; with Memory.Cache; use Memory.Cache; with Memory.SPM; use Memory.SPM; package body CACTI is subtype file is char; type file_ptr is access file; type Parameter_Type is record size : Positive; block_size : Positive; bus_bits : Positive; associativity : Natural := 1; is_cache : Boolean := False; end record; type Result_Type is record area : Cost_Type; time : Time_Type; end record; function "<"(a, b : Parameter_Type) return Boolean is begin if a.size /= b.size then return a.size < b.size; end if; if a.block_size /= b.block_size then return a.block_size < b.block_size; end if; if a.bus_bits /= b.bus_bits then return a.bus_bits < b.bus_bits; end if; if a.associativity /= b.associativity then return a.associativity < b.associativity; end if; if a.is_cache /= b.is_cache then return a.is_cache; end if; return False; end "<"; package Result_Maps is new Ordered_Maps(Parameter_Type, Result_Type); function popen(c, t : char_array) return file_ptr; pragma Import(C, popen, "popen"); procedure pclose(s : file_ptr); pragma Import(C, pclose, "pclose"); function fgetc(ptr : file_ptr) return int; pragma Import(C, fgetc, "fgetc"); -- Regular expressions for extracting area and time information. area_matcher : constant Pattern_Matcher := Compile("Data array: Area \(mm2\): ([0-9\.]+)"); time_matcher : constant Pattern_Matcher := Compile("Access time \(ns\): ([0-9\.]+)"); -- Cache of results. results : Result_Maps.Map; -- Generate CACTI input. procedure Generate(file : in File_Type; param : in Parameter_Type) is begin -- Size in bytes. Put_Line(file, "-size (bytes) " & To_String(param.size)); -- Line size in bytes. Put_Line(file, "-block size (bytes) " & To_String(param.block_size)); -- Associativity (0 for fully-associativity). Put_Line(file, "-associativity " & To_String(param.associativity)); -- Ports. Put_Line(file, "-read-write port 1"); Put_Line(file, "-exclusive read port 0"); Put_Line(file, "-exclusive write port 0"); Put_Line(file, "-single ended read ports 0"); -- Banks. Put_Line(file, "-UCA bank count 1"); -- Technology. -- TODO support other technologies. Put_Line(file, "-technology (u) 0.032"); -- Cell types. Put_Line(file, "-Data array cell type - ""itrs-hp"""); Put_Line(file, "-Data array peripheral type - ""itrs-hp"""); Put_Line(file, "-Tag array cell type - ""itrs-hp"""); Put_Line(file, "-Tag array peripheral type - ""itrs-hp"""); -- Bus width. Put_Line(file, "-output/input bus width " & To_String(param.bus_bits)); -- Operating temperature. Put_Line(file, "-operating temperature (K) 350"); -- Type of memory. if param.is_cache then Put_Line(file, "-cache type ""cache"""); else Put_Line(file, "-cache type ""ram"""); end if; -- Tag size. Put_Line(file, "-tag size (b) ""default"""); -- Access mode. Put_Line(file, "-access mode (normal, sequential, fast) - ""normal"""); -- Cache model. Put_Line(file, "-Cache model (NUCA, UCA) - ""UCA"""); -- Design objective. Put_Line(file, "-design objective (weight delay, dynamic power, " & "leakage power, cycle time, area) 0:0:0:0:100"); Put_Line(file, "-deviate (delay, dynamic power, leakage power, " & "cycle time, area) 60:100000:100000:100000:1000000"); -- Make sure we get all the information we need. Put_Line(file, "-Print level (DETAILED, CONCISE) - ""DETAILED"""); -- Prefetch width (needed to prevent cacti from crashing). Put_Line(file, "-internal prefetch width 8"); end Generate; -- Get CACTI parameters for a cache. function Get_Cache(cache : Cache_Type) return Parameter_Type is wsize : constant Positive := Get_Word_Size(cache); lsize : constant Positive := Get_Line_Size(cache); lcount : constant Positive := Get_Line_Count(cache); bsize : constant Positive := wsize * lsize; size : constant Positive := bsize * lcount; assoc : constant Natural := Get_Associativity(cache); abits : constant Positive := Get_Address_Bits; bus_bits : constant Positive := abits + wsize * 8; param : Parameter_Type; begin param.size := size; param.block_size := bsize; param.bus_bits := bus_bits; param.is_cache := True; if assoc = lcount then param.associativity := 0; else param.associativity := assoc; end if; return param; end Get_Cache; -- Get CACTI parameters for an SPM. function Get_SPM(spm : SPM_Type) return Parameter_Type is wsize : constant Positive := Get_Word_Size(spm); size : constant Positive := Get_Size(spm); bus_bits : constant Positive := 8 * wsize; param : Parameter_Type; begin param.size := size; param.block_size := wsize; param.bus_bits := bus_bits; return param; end Get_SPM; -- Get CACTI parameters. function Get_Parameter(mem : Memory_Type'Class) return Parameter_Type is begin if mem in Cache_Type'Class then return Get_Cache(Cache_Type(mem)); elsif mem in SPM_Type'Class then return Get_SPM(SPM_Type(mem)); else raise CACTI_Error; end if; end Get_Parameter; -- Run the CACTI program with parameters from the specified memory. function Run(mem : Memory_Type'Class) return Result_Type is param : constant Parameter_Type := Get_Parameter(mem); command : constant String := "./cacti -infile "; cacti_type : constant char_array := To_C("r"); cursor : Result_Maps.Cursor; buffer : Unbounded_String; ptr : file_ptr; temp : File_Type; result : Result_Type; matches : Match_Array(0 .. 1); begin -- Check if we've already run CACTI with these parameters. cursor := results.Find(param); if Result_Maps."/="(cursor, Result_Maps.No_Element) then return Result_Maps.Element(cursor); end if; -- Create a temporary file with the parameters. Create(File => temp); Generate(temp, param); Flush(temp); -- Run CACTI. declare cacti_name : constant char_array := To_C(command & Name(temp)); begin ptr := popen(cacti_name, cacti_type); end; if ptr /= null then loop declare ch : constant int := fgetc(ptr); begin exit when ch < 0; Append(buffer, Character'Val(ch)); end; end loop; pclose(ptr); else Put_Line("ERROR: popen failed"); Delete(temp); raise CACTI_Error; end if; -- Destroy the temporary file. Delete(temp); -- Extract the area and time from the CACTI results. declare str : constant String := To_String(buffer); value : Float; begin -- Here we use units of nm^2, so we need to convert from mm^2. Match(area_matcher, str, matches); value := Float'Value(str(matches(1).First .. matches(1).Last)); result.area := Cost_Type(Float'Ceiling(value * 1000.0 * 1000.0)); -- Here we assume 1 cycle is 1 ns. Match(time_matcher, str, matches); value := Float'Value(str(matches(1).First .. matches(1).Last)); result.time := Time_Type(Float'Ceiling(value)); exception when others => result.area := Cost_Type'Last; result.time := Time_Type'Last; end; -- Insert the result to our results map. results.Insert(param, result); return result; end Run; function Get_Area(mem : Memory_Type'Class) return Cost_Type is result : constant Result_Type := Run(mem); begin return result.area; end Get_Area; function Get_Time(mem : Memory_Type'Class) return Time_Type is result : constant Result_Type := Run(mem); begin return result.time; end Get_Time; end CACTI;
-- Integer_Storage_IO -- A re-implementation of Storage_IO for Integers with SPARK_Mode turned on in -- the specification and off in the body. -- Copyright (c) 2015, James Humphry - see LICENSE file for details with Ada.Unchecked_Conversion; package body Integer_Storage_IO with SPARK_Mode => Off is type Integer_Access is access all Integer; type Storage_Element_Access is access all System.Storage_Elements.Storage_Element; function SEA_to_ETA is new Ada.Unchecked_Conversion(Source => Storage_Element_Access, Target => Integer_Access); procedure Read (Buffer : in Buffer_Type; Item : out Integer) is B : aliased Buffer_Type := Buffer; B_Access : constant Storage_Element_Access := B(1)'Unchecked_Access; B_Access_As_ETA : constant Integer_Access := SEA_to_ETA(B_Access); begin Item := B_Access_As_ETA.all; end Read; procedure Write(Buffer : out Buffer_Type; Item : in Integer) is B : aliased Buffer_Type; B_Access : constant Storage_Element_Access := B(1)'Unchecked_Access; B_Access_As_ETA : constant Integer_Access := SEA_to_ETA(B_Access); begin B_Access_As_ETA.all := Item; Buffer := B; end Write; end Integer_Storage_IO;
------------------------------------------------------------------------------ -- -- -- GNAT LIBRARY COMPONENTS -- -- -- -- ADA.CONTAINERS.FUNCTIONAL_MAPS -- -- -- -- S p e c -- -- -- -- Copyright (C) 2016-2020, Free Software Foundation, Inc. -- -- -- -- This specification is derived from the Ada Reference Manual for use with -- -- GNAT. The copyright notice above, and the license provisions that follow -- -- apply solely to the contents of the part following the private keyword. -- -- -- -- 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/>. -- ------------------------------------------------------------------------------ pragma Ada_2012; private with Ada.Containers.Functional_Base; generic type Key_Type (<>) is private; type Element_Type (<>) is private; with function Equivalent_Keys (Left : Key_Type; Right : Key_Type) return Boolean is "="; with function "=" (Left, Right : Element_Type) return Boolean is <>; Enable_Handling_Of_Equivalence : Boolean := True; -- This constant should only be set to False when no particular handling -- of equivalence over keys is needed, that is, Equivalent_Keys defines a -- key uniquely. package Ada.Containers.Functional_Maps with SPARK_Mode is type Map is private with Default_Initial_Condition => Is_Empty (Map) and Length (Map) = 0, Iterable => (First => Iter_First, Next => Iter_Next, Has_Element => Iter_Has_Element, Element => Iter_Element); -- Maps are empty when default initialized. -- "For in" quantification over maps should not be used. -- "For of" quantification over maps iterates over keys. -- Note that, for proof, "for of" quantification is understood modulo -- equivalence (the range of quantification comprises all the keys that are -- equivalent to any key of the map). ----------------------- -- Basic operations -- ----------------------- -- Maps are axiomatized using Has_Key and Get, encoding respectively the -- presence of a key in a map and an accessor to elements associated with -- its keys. The length of a map is also added to protect Add against -- overflows but it is not actually modeled. function Has_Key (Container : Map; Key : Key_Type) return Boolean with -- Return True if Key is present in Container Global => null, Post => (if Enable_Handling_Of_Equivalence then -- Has_Key returns the same result on all equivalent keys (if (for some K of Container => Equivalent_Keys (K, Key)) then Has_Key'Result)); function Get (Container : Map; Key : Key_Type) return Element_Type with -- Return the element associated with Key in Container Global => null, Pre => Has_Key (Container, Key), Post => (if Enable_Handling_Of_Equivalence then -- Get returns the same result on all equivalent keys Get'Result = W_Get (Container, Witness (Container, Key)) and (for all K of Container => (Equivalent_Keys (K, Key) = (Witness (Container, Key) = Witness (Container, K))))); function Length (Container : Map) return Count_Type with Global => null; -- Return the number of mappings in Container ------------------------ -- Property Functions -- ------------------------ function "<=" (Left : Map; Right : Map) return Boolean with -- Map inclusion Global => null, Post => "<="'Result = (for all Key of Left => Has_Key (Right, Key) and then Get (Right, Key) = Get (Left, Key)); function "=" (Left : Map; Right : Map) return Boolean with -- Extensional equality over maps Global => null, Post => "="'Result = ((for all Key of Left => Has_Key (Right, Key) and then Get (Right, Key) = Get (Left, Key)) and (for all Key of Right => Has_Key (Left, Key))); pragma Warnings (Off, "unused variable ""Key"""); function Is_Empty (Container : Map) return Boolean with -- A map is empty if it contains no key Global => null, Post => Is_Empty'Result = (for all Key of Container => False); pragma Warnings (On, "unused variable ""Key"""); function Keys_Included (Left : Map; Right : Map) return Boolean -- Returns True if every Key of Left is in Right with Global => null, Post => Keys_Included'Result = (for all Key of Left => Has_Key (Right, Key)); function Same_Keys (Left : Map; Right : Map) return Boolean -- Returns True if Left and Right have the same keys with Global => null, Post => Same_Keys'Result = (Keys_Included (Left, Right) and Keys_Included (Left => Right, Right => Left)); pragma Annotate (GNATprove, Inline_For_Proof, Same_Keys); function Keys_Included_Except (Left : Map; Right : Map; New_Key : Key_Type) return Boolean -- Returns True if Left contains only keys of Right and possibly New_Key with Global => null, Post => Keys_Included_Except'Result = (for all Key of Left => (if not Equivalent_Keys (Key, New_Key) then Has_Key (Right, Key))); function Keys_Included_Except (Left : Map; Right : Map; X : Key_Type; Y : Key_Type) return Boolean -- Returns True if Left contains only keys of Right and possibly X and Y with Global => null, Post => Keys_Included_Except'Result = (for all Key of Left => (if not Equivalent_Keys (Key, X) and not Equivalent_Keys (Key, Y) then Has_Key (Right, Key))); function Elements_Equal_Except (Left : Map; Right : Map; New_Key : Key_Type) return Boolean -- Returns True if all the keys of Left are mapped to the same elements in -- Left and Right except New_Key. with Global => null, Post => Elements_Equal_Except'Result = (for all Key of Left => (if not Equivalent_Keys (Key, New_Key) then Has_Key (Right, Key) and then Get (Left, Key) = Get (Right, Key))); function Elements_Equal_Except (Left : Map; Right : Map; X : Key_Type; Y : Key_Type) return Boolean -- Returns True if all the keys of Left are mapped to the same elements in -- Left and Right except X and Y. with Global => null, Post => Elements_Equal_Except'Result = (for all Key of Left => (if not Equivalent_Keys (Key, X) and not Equivalent_Keys (Key, Y) then Has_Key (Right, Key) and then Get (Left, Key) = Get (Right, Key))); ---------------------------- -- Construction Functions -- ---------------------------- -- For better efficiency of both proofs and execution, avoid using -- construction functions in annotations and rather use property functions. function Add (Container : Map; New_Key : Key_Type; New_Item : Element_Type) return Map -- Returns Container augmented with the mapping Key -> New_Item with Global => null, Pre => not Has_Key (Container, New_Key) and Length (Container) < Count_Type'Last, Post => Length (Container) + 1 = Length (Add'Result) and Has_Key (Add'Result, New_Key) and Get (Add'Result, New_Key) = New_Item and Container <= Add'Result and Keys_Included_Except (Add'Result, Container, New_Key); function Remove (Container : Map; Key : Key_Type) return Map -- Returns Container without any mapping for Key with Global => null, Pre => Has_Key (Container, Key), Post => Length (Container) = Length (Remove'Result) + 1 and not Has_Key (Remove'Result, Key) and Remove'Result <= Container and Keys_Included_Except (Container, Remove'Result, Key); function Set (Container : Map; Key : Key_Type; New_Item : Element_Type) return Map -- Returns Container, where the element associated with Key has been -- replaced by New_Item. with Global => null, Pre => Has_Key (Container, Key), Post => Length (Container) = Length (Set'Result) and Get (Set'Result, Key) = New_Item and Same_Keys (Container, Set'Result) and Elements_Equal_Except (Container, Set'Result, Key); ------------------------------ -- Handling of Equivalence -- ------------------------------ -- These functions are used to specify that Get returns the same value on -- equivalent keys. They should not be used directly in user code. function Has_Witness (Container : Map; Witness : Count_Type) return Boolean with Ghost, Global => null; -- Returns True if there is a key with witness Witness in Container function Witness (Container : Map; Key : Key_Type) return Count_Type with -- Returns the witness of Key in Container Ghost, Global => null, Pre => Has_Key (Container, Key), Post => Has_Witness (Container, Witness'Result); function W_Get (Container : Map; Witness : Count_Type) return Element_Type with -- Returns the element associated with a witness in Container Ghost, Global => null, Pre => Has_Witness (Container, Witness); --------------------------- -- Iteration Primitives -- --------------------------- type Private_Key is private; function Iter_First (Container : Map) return Private_Key with Global => null; function Iter_Has_Element (Container : Map; Key : Private_Key) return Boolean with Global => null; function Iter_Next (Container : Map; Key : Private_Key) return Private_Key with Global => null, Pre => Iter_Has_Element (Container, Key); function Iter_Element (Container : Map; Key : Private_Key) return Key_Type with Global => null, Pre => Iter_Has_Element (Container, Key); pragma Annotate (GNATprove, Iterable_For_Proof, "Contains", Has_Key); private pragma SPARK_Mode (Off); function "=" (Left : Key_Type; Right : Key_Type) return Boolean renames Equivalent_Keys; subtype Positive_Count_Type is Count_Type range 1 .. Count_Type'Last; package Element_Containers is new Ada.Containers.Functional_Base (Element_Type => Element_Type, Index_Type => Positive_Count_Type); package Key_Containers is new Ada.Containers.Functional_Base (Element_Type => Key_Type, Index_Type => Positive_Count_Type); type Map is record Keys : Key_Containers.Container; Elements : Element_Containers.Container; end record; type Private_Key is new Count_Type; function Iter_First (Container : Map) return Private_Key is (1); function Iter_Has_Element (Container : Map; Key : Private_Key) return Boolean is (Count_Type (Key) in 1 .. Key_Containers.Length (Container.Keys)); function Iter_Next (Container : Map; Key : Private_Key) return Private_Key is (if Key = Private_Key'Last then 0 else Key + 1); function Iter_Element (Container : Map; Key : Private_Key) return Key_Type is (Key_Containers.Get (Container.Keys, Count_Type (Key))); end Ada.Containers.Functional_Maps;
with SPARKNaCl; use SPARKNaCl; with SPARKNaCl.Sign; use SPARKNaCl.Sign; with SPARKNaCl.Cryptobox; use SPARKNaCl.Cryptobox; with SPARKNaCl.Hashing; use SPARKNaCl.Hashing; with SPARKNaCl.Stream; use SPARKNaCl.Stream; with SPARKNaCl.Core; use SPARKNaCl.Core; with Interfaces; use Interfaces; package TweetNaCl_API is GF_Add : Unsigned_64 with Import, Convention => C, Link_Name => "tweet_gf_add"; GF_Sub : Unsigned_64 with Import, Convention => C, Link_Name => "tweet_gf_sub"; GF_Mul : Unsigned_64 with Import, Convention => C, Link_Name => "tweet_gf_mul"; GF_Car : Unsigned_64 with Import, Convention => C, Link_Name => "tweet_gf_car"; procedure Crypto_Sign (SM : out Byte_Seq; SMLen : out Unsigned_64; M : in Byte_Seq; N : in Unsigned_64; SK : in Signing_SK) with Import, Convention => C, Link_Name => "crypto_sign_ed25519_tweet"; procedure Crypto_Sign2 (SM : out Byte_Seq; SMLen : out Unsigned_64; M : in Byte_Seq; N : in Unsigned_64; SK : in Signing_SK; Hash_SK : out Unsigned_64; Hash_Reduce_SM1 : out Unsigned_64; Scalarbase_R : out Unsigned_64; Pack_P : out Unsigned_64; Hash_Reduce_SM2 : out Unsigned_64; Initialize_X : out Unsigned_64; Assign_X : out Unsigned_64; ModL_X : out Unsigned_64) with Import, Convention => C, Link_Name => "crypto_sign2_ed25519_tweet"; procedure Crypto_Hash (SM : out Digest; M : in Byte_Seq; N : in Unsigned_64) with Import, Convention => C, Link_Name => "crypto_hash_sha512_tweet"; procedure Crypto_Box (C : out Byte_Seq; M : in Byte_Seq; MLen : in Unsigned_64; N : in Stream.HSalsa20_Nonce; Recipient_PK : in Public_Key; Sender_SK : in Secret_Key) with Import, Convention => C, Link_Name => "crypto_box_curve25519xsalsa20poly1305_tweet"; procedure Reset with Import, Convention => C, Link_Name => "tweet_reset"; procedure Crypto_Scalarmult (Q : out Bytes_32; N : in Bytes_32; P : in Bytes_32) with Import, Convention => C, Link_Name => "crypto_scalarmult_curve25519_tweet"; procedure HSalsa20 (C : out Byte_Seq; -- Output stream CLen : in Unsigned_64; N : in HSalsa20_Nonce; -- Nonce K : in Salsa20_Key) -- Key with Import, Convention => C, Link_Name => "crypto_stream_xsalsa20_tweet"; end TweetNaCl_API;
package Array17_Pkg is type Varray is array (Integer range <>) of Long_Float; for Varray'Alignment use 16; function "+" (X, Y : Varray) return Varray; end Array17_Pkg;
-------------------------------------------------------------------------------- -- Copyright (C) 2020 by Heisenbug Ltd. (gh+owm@heisenbug.eu) -- -- This work is free. You can redistribute it and/or modify it under the -- terms of the Do What The Fuck You Want To Public License, Version 2, -- as published by Sam Hocevar. See the LICENSE file for more details. -------------------------------------------------------------------------------- pragma License (Unrestricted); with Ada.Directories; with Ada.Text_IO; package body Open_Weather_Map.Configuration is My_Debug : constant not null GNATCOLL.Traces.Trace_Handle := GNATCOLL.Traces.Create (Unit_Name => "OWM.CONFIGURATION"); Config_Name : constant String := "config"; Config_Ext : constant String := "json"; -- Full configuration file name: "$HOME/.openweathermap/config.json". ----------------------------------------------------------------------------- -- Initialize ----------------------------------------------------------------------------- procedure Initialize (Self : out T) is begin My_Debug.all.Trace (Message => "Initialize"); Self.Read_Config (From_File => Ada.Directories.Compose (Containing_Directory => Application_Directory, Name => Config_Name, Extension => Config_Ext)); end Initialize; ----------------------------------------------------------------------------- -- Read_Config ----------------------------------------------------------------------------- procedure Read_Config (Self : in out T; From_File : in String) is Content : Ada.Strings.Unbounded.Unbounded_String; begin My_Debug.all.Trace (Message => "Read_Config"); My_Debug.all.Trace (Message => "Read_Config: Reading configuration file """ & From_File & """."); declare JSON_File : Ada.Text_IO.File_Type; begin Ada.Text_IO.Open (File => JSON_File, Mode => Ada.Text_IO.In_File, Name => From_File); begin while not Ada.Text_IO.End_Of_File (File => JSON_File) loop Ada.Strings.Unbounded.Append (Source => Content, New_Item => Ada.Text_IO.Get_Line (JSON_File)); end loop; exception when others => Ada.Text_IO.Close (File => JSON_File); raise; end; Ada.Text_IO.Close (File => JSON_File); exception when E : others => My_Debug.all.Trace (E => E, Msg => "Read_Config: Error reading """ & From_File & """: "); Ada.Text_IO.Put_Line (File => Ada.Text_IO.Standard_Error, Item => "Error reading from file """ & From_File & """, " & "no configuration loaded!"); end; begin Self.Config := GNATCOLL.JSON.Read (Strm => Content, Filename => From_File); My_Debug.all.Trace (Message => "Read_Config: Configuration loaded."); exception when E : GNATCOLL.JSON.Invalid_JSON_Stream => My_Debug.all.Trace (E => E, Msg => "Read_Config: Invalid data in JSON stream: "); -- Error reporting already done by callee. end; end Read_Config; end Open_Weather_Map.Configuration;
with Ada.Command_Line; with Ada.Text_IO; with ZMQ; procedure HWClient is function Main return Ada.Command_Line.Exit_Status is begin Ada.Text_IO.Put_Line ("Connecting to hello world server..."); declare Context : ZMQ.Context_Type := ZMQ.New_Context; Requester : constant ZMQ.Socket_Type'Class := Context.New_Socket (ZMQ.ZMQ_REQ); begin Requester.Connect ("tcp://localhost:5555"); for Request_Nbr in 0 .. 10 loop Ada.Text_IO.Put_Line ("Sending Hello "&Request_Nbr'Img&"..."); Requester.Send ("Hello"); declare Dummy : String := Requester.Recv; begin Ada.Text_IO.Put_Line ("Received World " & Request_Nbr'Img); end; end loop; Requester.Close; Context.Term; end; return 0; end Main; begin Ada.Command_Line.Set_Exit_Status (Main); end HWClient;
-- This file is used to illustrate all -- the files in the library -- Root package with Sf; -- Used in all modules with Sf.Config; -- System module with Sf.System; with Sf.System.Types; with Sf.System.Clock; with Sf.System.Mutex; with Sf.System.Randomizer; with Sf.System.Sleep; with Sf.System.Thread; -- Window module with Sf.Window; with Sf.Window.Types; with Sf.Window.Context; with Sf.Window.Event; with Sf.Window.Input; with Sf.Window.VideoMode; with Sf.Window.Window; with Sf.Window.WindowHandle; with Sf.Window.GL; with Sf.Window.GLU; -- Graphics module with Sf.Graphics; with Sf.Graphics.Types; with Sf.Graphics.BlendMode; with Sf.Graphics.Color; with Sf.Graphics.Font; with Sf.Graphics.Glyph; with Sf.Graphics.Image; with Sf.Graphics.PostFX; with Sf.Graphics.Rect; with Sf.Graphics.RenderWindow; with Sf.Graphics.Shape; with Sf.Graphics.Sprite; with Sf.Graphics.String; with Sf.Graphics.View; -- Audio module with Sf.Audio; with Sf.Audio.Types; with Sf.Audio.Listener; with Sf.Audio.Music; with Sf.Audio.Sound; with Sf.Audio.SoundBuffer; with Sf.Audio.SoundBufferRecorder; with Sf.Audio.SoundRecorder; with Sf.Audio.SoundStatus; with Sf.Audio.SoundStream; -- Network module with Sf.Network; with Sf.Network.Types; with Sf.Network.Ftp; with Sf.Network.Http; with Sf.Network.IPAddress; with Sf.Network.Packet; with Sf.Network.Selector; with Sf.Network.SocketStatus; with Sf.Network.SocketTCP; with Sf.Network.SocketUDP; procedure Main is begin null; end Main;
-- generated parser support file. -- command line: wisitoken-bnf-generate.exe --generate LR1 Ada_Emacs re2c PROCESS gpr.wy -- -- Copyright (C) 2013 - 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, or (at -- your option) any later version. -- -- This software 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. with Gpr_Process_Actions; use Gpr_Process_Actions; with WisiToken.Lexer.re2c; with gpr_re2c_c; package body Gpr_Process_LR1_Main is package Lexer is new WisiToken.Lexer.re2c (gpr_re2c_c.New_Lexer, gpr_re2c_c.Free_Lexer, gpr_re2c_c.Reset_Lexer, gpr_re2c_c.Next_Token); procedure Create_Parser (Parser : out WisiToken.Parse.LR.Parser.Parser; Language_Fixes : in WisiToken.Parse.LR.Parser.Language_Fixes_Access; Language_Matching_Begin_Tokens : in WisiToken.Parse.LR.Parser.Language_Matching_Begin_Tokens_Access; Language_String_ID_Set : in WisiToken.Parse.LR.Parser.Language_String_ID_Set_Access; Trace : not null access WisiToken.Trace'Class; User_Data : in WisiToken.Syntax_Trees.User_Data_Access) is use WisiToken.Parse.LR; McKenzie_Param : constant McKenzie_Param_Type := (First_Terminal => 3, Last_Terminal => 39, First_Nonterminal => 40, Last_Nonterminal => 73, Insert => (4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), Delete => (4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), Push_Back => (2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Undo_Reduce => (2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Minimal_Complete_Cost_Delta => -1, Fast_Forward => 0, Matching_Begin => 0, Ignore_Check_Fail => 2, Task_Count => 0, Check_Limit => 3, Check_Delta_Limit => 200, Enqueue_Limit => 10000); Table : constant Parse_Table_Ptr := new Parse_Table (State_First => 0, State_Last => 322, First_Terminal => 3, Last_Terminal => 39, First_Nonterminal => 40, Last_Nonterminal => 73); begin Table.McKenzie_Param := McKenzie_Param; declare procedure Subr_1 is begin Add_Action (Table.States (0), 3, Reduce, (50, 0), 0, null, null); Add_Action (Table.States (0), 5, Reduce, (50, 0), 0, null, null); Add_Action (Table.States (0), 7, Reduce, (50, 0), 0, null, null); Add_Action (Table.States (0), 15, Reduce, (50, 0), 0, null, null); Add_Action (Table.States (0), 19, Reduce, (50, 0), 0, null, null); Add_Action (Table.States (0), 22, Reduce, (50, 0), 0, null, null); Add_Action (Table.States (0), 26, 1); Add_Action (Table.States (0), 39, Reduce, (50, 0), 0, null, null); Add_Error (Table.States (0)); Add_Goto (Table.States (0), 48, 2); Add_Goto (Table.States (0), 49, 3); Add_Goto (Table.States (0), 50, 4); Add_Goto (Table.States (0), 73, 5); Table.States (0).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 48, 0))); Add_Action (Table.States (1), 10, 6); Add_Action (Table.States (1), 11, 7); Add_Action (Table.States (1), 14, 8); Add_Action (Table.States (1), 19, 9); Add_Action (Table.States (1), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (1), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (1), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (1), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (1), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (1), 37, 10); Add_Action (Table.States (1), 38, 11); Add_Error (Table.States (1)); Add_Goto (Table.States (1), 41, 12); Add_Goto (Table.States (1), 43, 13); Add_Goto (Table.States (1), 44, 14); Add_Goto (Table.States (1), 56, 15); Add_Goto (Table.States (1), 57, 16); Add_Goto (Table.States (1), 58, 17); Add_Goto (Table.States (1), 59, 18); Add_Goto (Table.States (1), 69, 19); Add_Goto (Table.States (1), 70, 20); Add_Goto (Table.States (1), 71, 21); Table.States (1).Kernel := To_Vector ((0 => (73, 26, 1, False))); Table.States (1).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 70, 0))); Add_Action (Table.States (2), 39, Accept_It, (40, 0), 1, null, null); Add_Error (Table.States (2)); Table.States (2).Kernel := To_Vector ((0 => (40, 48, 1, False))); Add_Action (Table.States (3), 3, Reduce, (50, 1), 1, null, null); Add_Action (Table.States (3), 5, Reduce, (50, 1), 1, null, null); Add_Action (Table.States (3), 7, Reduce, (50, 1), 1, null, null); Add_Action (Table.States (3), 15, Reduce, (50, 1), 1, null, null); Add_Action (Table.States (3), 19, Reduce, (50, 1), 1, null, null); Add_Action (Table.States (3), 22, Reduce, (50, 1), 1, null, null); Add_Action (Table.States (3), 26, 1); Add_Action (Table.States (3), 39, Reduce, (50, 1), 1, null, null); Add_Error (Table.States (3)); Add_Goto (Table.States (3), 73, 22); Table.States (3).Kernel := To_Vector (((49, 49, 2, True), (50, 49, 0, False))); Table.States (3).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 50, 1))); Add_Action (Table.States (4), 3, 23); Add_Action (Table.States (4), 5, 24); Add_Action (Table.States (4), 7, 25); Add_Action (Table.States (4), 15, 26); Add_Action (Table.States (4), 19, Reduce, (66, 0), 0, null, null); Add_Action (Table.States (4), 22, 27); Add_Action (Table.States (4), 39, Reduce, (66, 0), 0, null, null); Add_Error (Table.States (4)); Add_Goto (Table.States (4), 66, 28); Table.States (4).Kernel := To_Vector ((0 => (48, 50, 0, False))); Table.States (4).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 66, 0))); Add_Action (Table.States (5), (3, 5, 7, 15, 19, 22, 26, 39), (49, 0), 1, null, null); Table.States (5).Kernel := To_Vector ((0 => (49, 73, 0, False))); Table.States (5).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 49, 1))); Add_Action (Table.States (6), 14, 29); Add_Error (Table.States (6)); Add_Goto (Table.States (6), 41, 30); Table.States (6).Kernel := To_Vector ((0 => (57, 10, 2, False))); Table.States (6).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 29))); Add_Action (Table.States (7), 14, 29); Add_Error (Table.States (7)); Add_Goto (Table.States (7), 41, 31); Table.States (7).Kernel := To_Vector ((0 => (57, 11, 2, False))); Table.States (7).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 29))); Add_Action (Table.States (8), 10, 32); Add_Action (Table.States (8), 11, 33); Add_Action (Table.States (8), 14, 34); Add_Action (Table.States (8), 19, 9); Add_Action (Table.States (8), 21, 35); Add_Conflict (Table.States (8), 21, (58, 0), 0, null, null); Add_Action (Table.States (8), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (8), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (8), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (8), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (8), 37, 36); Add_Action (Table.States (8), 38, 37); Add_Error (Table.States (8)); Add_Goto (Table.States (8), 41, 38); Add_Goto (Table.States (8), 43, 39); Add_Goto (Table.States (8), 44, 40); Add_Goto (Table.States (8), 56, 41); Add_Goto (Table.States (8), 57, 42); Add_Goto (Table.States (8), 58, 43); Add_Goto (Table.States (8), 59, 44); Add_Goto (Table.States (8), 69, 45); Add_Goto (Table.States (8), 70, 46); Add_Goto (Table.States (8), 71, 47); Table.States (8).Kernel := To_Vector (((41, 14, 1, False), (71, 14, 1, False))); Table.States (8).Minimal_Complete_Actions := To_Vector (((Reduce, 70, 0), (Shift, 21, 35))); Add_Action (Table.States (9), (1 => 33), (43, 0), 1, null, null); Table.States (9).Kernel := To_Vector ((0 => (43, 19, 0, False))); Table.States (9).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 43, 1))); Add_Action (Table.States (10), (27, 30, 31, 33, 34), (58, 1), 1, null, identifier_opt_1_check'Access); Table.States (10).Kernel := To_Vector ((0 => (58, 37, 0, False))); Table.States (10).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 1))); Add_Action (Table.States (11), (27, 30, 34), (69, 0), 1, null, null); Table.States (11).Kernel := To_Vector ((0 => (69, 38, 0, False))); Table.States (11).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (12), (27, 30, 34), (71, 2), 1, null, null); Table.States (12).Kernel := To_Vector ((0 => (71, 41, 0, False))); Table.States (12).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 1))); Add_Action (Table.States (13), 33, 48); Add_Error (Table.States (13)); Table.States (13).Kernel := To_Vector (((44, 43, 2, False), (44, 43, 5, False))); Table.States (13).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 33, 48))); Add_Action (Table.States (14), (27, 30, 34), (69, 3), 1, null, null); Table.States (14).Kernel := To_Vector ((0 => (69, 44, 0, False))); Table.States (14).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (15), 27, 49); Add_Action (Table.States (15), 30, Reduce, (70, 0), 1, null, null); Add_Action (Table.States (15), 34, Reduce, (70, 0), 1, null, null); Add_Error (Table.States (15)); Table.States (15).Kernel := To_Vector (((56, 56, 1, True), (70, 56, 0, False))); Table.States (15).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 70, 1))); Add_Action (Table.States (16), (27, 30, 34), (69, 2), 1, null, null); Table.States (16).Kernel := To_Vector ((0 => (69, 57, 0, False))); Table.States (16).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (17), (27, 30, 31, 33, 34), (59, 0), 1, null, null); Table.States (17).Kernel := To_Vector ((0 => (59, 58, 0, False))); Table.States (17).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 1))); Add_Action (Table.States (18), 27, Reduce, (69, 1), 1, null, null); Add_Action (Table.States (18), 30, Reduce, (69, 1), 1, null, null); Add_Action (Table.States (18), 31, 50); Add_Action (Table.States (18), 33, Reduce, (43, 1), 1, null, null); Add_Action (Table.States (18), 34, Reduce, (69, 1), 1, null, null); Add_Error (Table.States (18)); Table.States (18).Kernel := To_Vector (((43, 59, 0, False), (59, 59, 2, True), (69, 59, 0, False))); Table.States (18).Minimal_Complete_Actions := To_Vector (((Reduce, 43, 1), (Reduce, 69, 1))); Add_Action (Table.States (19), (27, 30, 34), (71, 0), 1, null, null); Table.States (19).Kernel := To_Vector ((0 => (71, 69, 0, False))); Table.States (19).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 1))); Add_Action (Table.States (20), 30, 51); Add_Action (Table.States (20), 34, 52); Add_Error (Table.States (20)); Table.States (20).Kernel := To_Vector (((70, 70, 1, True), (73, 70, 1, False))); Table.States (20).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 52))); Add_Action (Table.States (21), (27, 30, 34), (56, 0), 1, null, null); Table.States (21).Kernel := To_Vector ((0 => (56, 71, 0, False))); Table.States (21).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 1))); Add_Action (Table.States (22), (3, 5, 7, 15, 19, 22, 26, 39), (49, 1), 2, null, null); Table.States (22).Kernel := To_Vector ((0 => (49, 73, 0, True))); Table.States (22).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 49, 2))); Table.States (22).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (23), (19, 39), (66, 1), 1, null, null); Table.States (23).Kernel := To_Vector ((0 => (66, 3, 0, False))); Table.States (23).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 66, 1))); Add_Action (Table.States (24), 15, 53); Add_Action (Table.States (24), 19, Reduce, (66, 3), 1, null, null); Add_Action (Table.States (24), 39, Reduce, (66, 3), 1, null, null); Add_Error (Table.States (24)); Table.States (24).Kernel := To_Vector (((66, 5, 0, False), (66, 5, 1, False))); Table.States (24).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 66, 1))); Add_Action (Table.States (25), (19, 39), (66, 6), 1, null, null); Table.States (25).Kernel := To_Vector ((0 => (66, 7, 0, False))); Table.States (25).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 66, 1))); Add_Action (Table.States (26), (19, 39), (66, 5), 1, null, null); Table.States (26).Kernel := To_Vector ((0 => (66, 15, 0, False))); Table.States (26).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 66, 1))); Add_Action (Table.States (27), (19, 39), (66, 2), 1, null, null); Table.States (27).Kernel := To_Vector ((0 => (66, 22, 0, False))); Table.States (27).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 66, 1))); Add_Action (Table.States (28), 19, 54); Add_Action (Table.States (28), 39, Reduce, (64, 0), 0, null, null); Add_Error (Table.States (28)); Add_Goto (Table.States (28), 64, 55); Add_Goto (Table.States (28), 65, 56); Add_Goto (Table.States (28), 68, 57); Table.States (28).Kernel := To_Vector ((0 => (48, 66, 0, False))); Table.States (28).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 64, 0))); Add_Action (Table.States (29), 10, 32); Add_Action (Table.States (29), 11, 33); Add_Action (Table.States (29), 14, 34); Add_Action (Table.States (29), 19, 9); Add_Action (Table.States (29), 21, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (29), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (29), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (29), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (29), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (29), 37, 36); Add_Action (Table.States (29), 38, 37); Add_Error (Table.States (29)); Add_Goto (Table.States (29), 41, 38); Add_Goto (Table.States (29), 43, 39); Add_Goto (Table.States (29), 44, 40); Add_Goto (Table.States (29), 56, 41); Add_Goto (Table.States (29), 57, 42); Add_Goto (Table.States (29), 58, 43); Add_Goto (Table.States (29), 59, 44); Add_Goto (Table.States (29), 69, 45); Add_Goto (Table.States (29), 70, 46); Add_Goto (Table.States (29), 71, 47); Table.States (29).Kernel := To_Vector ((0 => (41, 14, 1, False))); Table.States (29).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 70, 0))); Add_Action (Table.States (30), (27, 30, 34), (57, 0), 2, null, null); Table.States (30).Kernel := To_Vector ((0 => (57, 41, 0, False))); Table.States (30).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 57, 2))); Add_Action (Table.States (31), (27, 30, 34), (57, 1), 2, null, null); Table.States (31).Kernel := To_Vector ((0 => (57, 41, 0, False))); Table.States (31).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 57, 2))); Add_Action (Table.States (32), 14, 58); Add_Error (Table.States (32)); Add_Goto (Table.States (32), 41, 59); Table.States (32).Kernel := To_Vector ((0 => (57, 10, 2, False))); Table.States (32).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 58))); Add_Action (Table.States (33), 14, 58); Add_Error (Table.States (33)); Add_Goto (Table.States (33), 41, 60); Table.States (33).Kernel := To_Vector ((0 => (57, 11, 2, False))); Table.States (33).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 58))); Add_Action (Table.States (34), 10, 32); Add_Action (Table.States (34), 11, 33); Add_Action (Table.States (34), 14, 34); Add_Action (Table.States (34), 19, 9); Add_Action (Table.States (34), 21, 61); Add_Conflict (Table.States (34), 21, (58, 0), 0, null, null); Add_Action (Table.States (34), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (34), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (34), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (34), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (34), 37, 36); Add_Action (Table.States (34), 38, 37); Add_Error (Table.States (34)); Add_Goto (Table.States (34), 41, 38); Add_Goto (Table.States (34), 43, 39); Add_Goto (Table.States (34), 44, 40); Add_Goto (Table.States (34), 56, 41); Add_Goto (Table.States (34), 57, 42); Add_Goto (Table.States (34), 58, 43); Add_Goto (Table.States (34), 59, 44); Add_Goto (Table.States (34), 69, 45); Add_Goto (Table.States (34), 70, 62); Add_Goto (Table.States (34), 71, 47); Table.States (34).Kernel := To_Vector (((41, 14, 1, False), (71, 14, 1, False))); Table.States (34).Minimal_Complete_Actions := To_Vector (((Reduce, 70, 0), (Shift, 21, 61))); Add_Action (Table.States (35), (27, 30, 34), (71, 1), 2, null, null); Table.States (35).Kernel := To_Vector ((0 => (71, 21, 0, False))); Table.States (35).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 2))); Add_Action (Table.States (36), (21, 27, 30, 31, 33), (58, 1), 1, null, identifier_opt_1_check'Access); Table.States (36).Kernel := To_Vector ((0 => (58, 37, 0, False))); Table.States (36).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 1))); Add_Action (Table.States (37), (21, 27, 30), (69, 0), 1, null, null); Table.States (37).Kernel := To_Vector ((0 => (69, 38, 0, False))); Table.States (37).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (38), (21, 27, 30), (71, 2), 1, null, null); Table.States (38).Kernel := To_Vector ((0 => (71, 41, 0, False))); Table.States (38).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 1))); Add_Action (Table.States (39), 33, 63); Add_Error (Table.States (39)); Table.States (39).Kernel := To_Vector (((44, 43, 2, False), (44, 43, 5, False))); Table.States (39).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 33, 63))); Add_Action (Table.States (40), (21, 27, 30), (69, 3), 1, null, null); Table.States (40).Kernel := To_Vector ((0 => (69, 44, 0, False))); Table.States (40).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (41), 21, Reduce, (70, 0), 1, null, null); Add_Action (Table.States (41), 27, 64); Add_Action (Table.States (41), 30, Reduce, (70, 0), 1, null, null); Add_Error (Table.States (41)); Table.States (41).Kernel := To_Vector (((56, 56, 1, True), (70, 56, 0, False))); Table.States (41).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 70, 1))); Add_Action (Table.States (42), (21, 27, 30), (69, 2), 1, null, null); Table.States (42).Kernel := To_Vector ((0 => (69, 57, 0, False))); Table.States (42).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (43), (21, 27, 30, 31, 33), (59, 0), 1, null, null); Table.States (43).Kernel := To_Vector ((0 => (59, 58, 0, False))); Table.States (43).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 1))); Add_Action (Table.States (44), 21, Reduce, (69, 1), 1, null, null); Add_Action (Table.States (44), 27, Reduce, (69, 1), 1, null, null); Add_Action (Table.States (44), 30, Reduce, (69, 1), 1, null, null); Add_Action (Table.States (44), 31, 65); Add_Action (Table.States (44), 33, Reduce, (43, 1), 1, null, null); Add_Error (Table.States (44)); Table.States (44).Kernel := To_Vector (((43, 59, 0, False), (59, 59, 2, True), (69, 59, 0, False))); Table.States (44).Minimal_Complete_Actions := To_Vector (((Reduce, 43, 1), (Reduce, 69, 1))); Add_Action (Table.States (45), (21, 27, 30), (71, 0), 1, null, null); Table.States (45).Kernel := To_Vector ((0 => (71, 69, 0, False))); Table.States (45).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 1))); Add_Action (Table.States (46), 21, 66); Add_Action (Table.States (46), 30, 67); Add_Error (Table.States (46)); Table.States (46).Kernel := To_Vector (((41, 70, 1, False), (70, 70, 1, True))); Table.States (46).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 66))); Add_Action (Table.States (47), (21, 27, 30), (56, 0), 1, null, null); Table.States (47).Kernel := To_Vector ((0 => (56, 71, 0, False))); Table.States (47).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 1))); Add_Action (Table.States (48), 37, 68); Add_Error (Table.States (48)); Table.States (48).Kernel := To_Vector (((44, 33, 1, False), (44, 33, 4, False))); Table.States (48).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 68))); Add_Action (Table.States (49), 10, 6); Add_Action (Table.States (49), 11, 7); Add_Action (Table.States (49), 14, 8); Add_Action (Table.States (49), 19, 9); Add_Action (Table.States (49), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (49), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (49), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (49), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (49), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (49), 37, 10); Add_Action (Table.States (49), 38, 11); Add_Error (Table.States (49)); Add_Goto (Table.States (49), 41, 12); Add_Goto (Table.States (49), 43, 13); Add_Goto (Table.States (49), 44, 14); Add_Goto (Table.States (49), 57, 16); Add_Goto (Table.States (49), 58, 17); Add_Goto (Table.States (49), 59, 18); Add_Goto (Table.States (49), 69, 19); Add_Goto (Table.States (49), 71, 69); Table.States (49).Kernel := To_Vector ((0 => (56, 27, 0, True))); Table.States (49).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 0))); Table.States (49).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (50), 37, 70); Add_Error (Table.States (50)); Table.States (50).Kernel := To_Vector ((0 => (59, 31, 1, True))); Table.States (50).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 70))); Table.States (50).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (51), 10, 6); Add_Action (Table.States (51), 11, 7); Add_Action (Table.States (51), 14, 8); Add_Action (Table.States (51), 19, 9); Add_Action (Table.States (51), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (51), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (51), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (51), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (51), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (51), 37, 10); Add_Action (Table.States (51), 38, 11); Add_Error (Table.States (51)); Add_Goto (Table.States (51), 41, 12); Add_Goto (Table.States (51), 43, 13); Add_Goto (Table.States (51), 44, 14); Add_Goto (Table.States (51), 56, 71); Add_Goto (Table.States (51), 57, 16); Add_Goto (Table.States (51), 58, 17); Add_Goto (Table.States (51), 59, 18); Add_Goto (Table.States (51), 69, 19); Add_Goto (Table.States (51), 71, 21); Table.States (51).Kernel := To_Vector ((0 => (70, 30, 0, True))); Table.States (51).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Table.States (51).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (52), (3, 5, 7, 15, 19, 22, 26, 39), (73, 0), 3, null, null); Table.States (52).Kernel := To_Vector ((0 => (73, 34, 0, False))); Table.States (52).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 73, 3))); Add_Action (Table.States (53), (19, 39), (66, 4), 2, null, null); Table.States (53).Kernel := To_Vector ((0 => (66, 15, 0, False))); Table.States (53).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 66, 2))); Add_Action (Table.States (54), 9, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (54), 13, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (54), 37, 72); Add_Error (Table.States (54)); Add_Goto (Table.States (54), 58, 73); Table.States (54).Kernel := To_Vector (((65, 19, 5, False), (68, 19, 3, False))); Table.States (54).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 0))); Add_Action (Table.States (55), (1 => 39), (48, 0), 3, compilation_unit_0'Access, null); Table.States (55).Kernel := To_Vector ((0 => (48, 64, 0, False))); Table.States (55).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 48, 3))); Add_Action (Table.States (56), (1 => 39), (64, 2), 1, null, null); Table.States (56).Kernel := To_Vector ((0 => (64, 65, 0, False))); Table.States (56).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 64, 1))); Add_Action (Table.States (57), (1 => 39), (64, 1), 1, null, null); Table.States (57).Kernel := To_Vector ((0 => (64, 68, 0, False))); Table.States (57).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 64, 1))); Add_Action (Table.States (58), 10, 32); Add_Action (Table.States (58), 11, 33); Add_Action (Table.States (58), 14, 34); Add_Action (Table.States (58), 19, 9); Add_Action (Table.States (58), 21, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (58), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (58), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (58), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (58), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (58), 37, 36); Add_Action (Table.States (58), 38, 37); Add_Error (Table.States (58)); Add_Goto (Table.States (58), 41, 38); Add_Goto (Table.States (58), 43, 39); Add_Goto (Table.States (58), 44, 40); Add_Goto (Table.States (58), 56, 41); Add_Goto (Table.States (58), 57, 42); Add_Goto (Table.States (58), 58, 43); Add_Goto (Table.States (58), 59, 44); Add_Goto (Table.States (58), 69, 45); Add_Goto (Table.States (58), 70, 62); Add_Goto (Table.States (58), 71, 47); Table.States (58).Kernel := To_Vector ((0 => (41, 14, 1, False))); Table.States (58).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 70, 0))); Add_Action (Table.States (59), (21, 27, 30), (57, 0), 2, null, null); Table.States (59).Kernel := To_Vector ((0 => (57, 41, 0, False))); Table.States (59).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 57, 2))); Add_Action (Table.States (60), (21, 27, 30), (57, 1), 2, null, null); Table.States (60).Kernel := To_Vector ((0 => (57, 41, 0, False))); Table.States (60).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 57, 2))); Add_Action (Table.States (61), (21, 27, 30), (71, 1), 2, null, null); Table.States (61).Kernel := To_Vector ((0 => (71, 21, 0, False))); Table.States (61).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 2))); Add_Action (Table.States (62), 21, 74); Add_Action (Table.States (62), 30, 67); Add_Error (Table.States (62)); Table.States (62).Kernel := To_Vector (((41, 70, 1, False), (70, 70, 1, True))); Table.States (62).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 74))); Add_Action (Table.States (63), 37, 75); Add_Error (Table.States (63)); Table.States (63).Kernel := To_Vector (((44, 33, 1, False), (44, 33, 4, False))); Table.States (63).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 75))); Add_Action (Table.States (64), 10, 32); Add_Action (Table.States (64), 11, 33); Add_Action (Table.States (64), 14, 34); Add_Action (Table.States (64), 19, 9); Add_Action (Table.States (64), 21, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (64), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (64), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (64), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (64), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (64), 37, 36); Add_Action (Table.States (64), 38, 37); Add_Error (Table.States (64)); Add_Goto (Table.States (64), 41, 38); Add_Goto (Table.States (64), 43, 39); Add_Goto (Table.States (64), 44, 40); Add_Goto (Table.States (64), 57, 42); Add_Goto (Table.States (64), 58, 43); Add_Goto (Table.States (64), 59, 44); Add_Goto (Table.States (64), 69, 45); Add_Goto (Table.States (64), 71, 76); Table.States (64).Kernel := To_Vector ((0 => (56, 27, 0, True))); Table.States (64).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 0))); Table.States (64).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (65), 37, 77); Add_Error (Table.States (65)); Table.States (65).Kernel := To_Vector ((0 => (59, 31, 1, True))); Table.States (65).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 77))); Table.States (65).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (66), (27, 30, 34), (41, 0), 3, aggregate_g_0'Access, null); Table.States (66).Kernel := To_Vector ((0 => (41, 21, 0, False))); Table.States (66).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 41, 3))); Add_Action (Table.States (67), 10, 32); Add_Action (Table.States (67), 11, 33); Add_Action (Table.States (67), 14, 34); Add_Action (Table.States (67), 19, 9); Add_Action (Table.States (67), 21, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (67), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (67), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (67), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (67), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (67), 37, 36); Add_Action (Table.States (67), 38, 37); Add_Error (Table.States (67)); Add_Goto (Table.States (67), 41, 38); Add_Goto (Table.States (67), 43, 39); Add_Goto (Table.States (67), 44, 40); Add_Goto (Table.States (67), 56, 78); Add_Goto (Table.States (67), 57, 42); Add_Goto (Table.States (67), 58, 43); Add_Goto (Table.States (67), 59, 44); Add_Goto (Table.States (67), 69, 45); Add_Goto (Table.States (67), 71, 47); Table.States (67).Kernel := To_Vector ((0 => (70, 30, 0, True))); Table.States (67).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Table.States (67).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (68), 14, 79); Add_Action (Table.States (68), 27, Reduce, (44, 0), 3, null, null); Add_Action (Table.States (68), 30, Reduce, (44, 0), 3, null, null); Add_Action (Table.States (68), 34, Reduce, (44, 0), 3, null, null); Add_Error (Table.States (68)); Table.States (68).Kernel := To_Vector (((44, 37, 0, False), (44, 37, 3, False))); Table.States (68).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 44, 3))); Add_Action (Table.States (69), (27, 30, 34), (56, 1), 3, null, null); Table.States (69).Kernel := To_Vector ((0 => (56, 71, 0, True))); Table.States (69).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 3))); Table.States (69).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (70), (27, 30, 31, 33, 34), (59, 1), 3, null, null); Table.States (70).Kernel := To_Vector ((0 => (59, 37, 0, True))); Table.States (70).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 3))); Table.States (70).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (71), 27, 49); Add_Action (Table.States (71), 30, Reduce, (70, 1), 3, null, null); Add_Action (Table.States (71), 34, Reduce, (70, 1), 3, null, null); Add_Error (Table.States (71)); Table.States (71).Kernel := To_Vector (((56, 56, 1, True), (70, 56, 0, True))); Table.States (71).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 70, 3))); Table.States (71).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (72), (9, 13), (58, 1), 1, null, identifier_opt_1_check'Access); Table.States (72).Kernel := To_Vector ((0 => (58, 37, 0, False))); Table.States (72).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 1))); Add_Action (Table.States (73), 9, 80); Add_Action (Table.States (73), 13, 81); Add_Error (Table.States (73)); Table.States (73).Kernel := To_Vector (((65, 58, 5, False), (68, 58, 3, False))); Table.States (73).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 13, 81))); Add_Action (Table.States (74), (21, 27, 30), (41, 0), 3, aggregate_g_0'Access, null); Table.States (74).Kernel := To_Vector ((0 => (41, 21, 0, False))); Table.States (74).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 41, 3))); Add_Action (Table.States (75), 14, 82); Add_Action (Table.States (75), 21, Reduce, (44, 0), 3, null, null); Add_Action (Table.States (75), 27, Reduce, (44, 0), 3, null, null); Add_Action (Table.States (75), 30, Reduce, (44, 0), 3, null, null); Add_Error (Table.States (75)); Table.States (75).Kernel := To_Vector (((44, 37, 0, False), (44, 37, 3, False))); Table.States (75).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 44, 3))); Add_Action (Table.States (76), (21, 27, 30), (56, 1), 3, null, null); Table.States (76).Kernel := To_Vector ((0 => (56, 71, 0, True))); Table.States (76).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 3))); Table.States (76).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (77), (21, 27, 30, 31, 33), (59, 1), 3, null, null); Table.States (77).Kernel := To_Vector ((0 => (59, 37, 0, True))); Table.States (77).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 3))); Table.States (77).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (78), 21, Reduce, (70, 1), 3, null, null); Add_Action (Table.States (78), 27, 64); Add_Action (Table.States (78), 30, Reduce, (70, 1), 3, null, null); Add_Error (Table.States (78)); Table.States (78).Kernel := To_Vector (((56, 56, 1, True), (70, 56, 0, True))); Table.States (78).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 70, 3))); Table.States (78).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (79), 38, 83); Add_Error (Table.States (79)); Table.States (79).Kernel := To_Vector ((0 => (44, 14, 2, False))); Table.States (79).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 38, 83))); Add_Action (Table.States (80), 38, 84); Add_Error (Table.States (80)); Table.States (80).Kernel := To_Vector ((0 => (65, 9, 4, False))); Table.States (80).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 38, 84))); Add_Action (Table.States (81), 6, 85); Add_Action (Table.States (81), 8, Reduce, (53, 0), 0, null, null); Add_Action (Table.States (81), 12, 86); Add_Action (Table.States (81), 16, 87); Add_Action (Table.States (81), 18, 88); Add_Action (Table.States (81), 23, 89); Add_Action (Table.States (81), 37, 90); Add_Error (Table.States (81)); Add_Goto (Table.States (81), 42, 91); Add_Goto (Table.States (81), 45, 92); Add_Goto (Table.States (81), 51, 93); Add_Goto (Table.States (81), 52, 94); Add_Goto (Table.States (81), 53, 95); Add_Goto (Table.States (81), 60, 96); Add_Goto (Table.States (81), 61, 97); Add_Goto (Table.States (81), 62, 98); Add_Goto (Table.States (81), 63, 99); Add_Goto (Table.States (81), 67, 100); Add_Goto (Table.States (81), 72, 101); Table.States (81).Kernel := To_Vector ((0 => (68, 13, 2, False))); Table.States (81).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 53, 0))); Add_Action (Table.States (82), 38, 102); Add_Error (Table.States (82)); Table.States (82).Kernel := To_Vector ((0 => (44, 14, 2, False))); Table.States (82).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 38, 102))); Add_Action (Table.States (83), 21, 103); Add_Error (Table.States (83)); Table.States (83).Kernel := To_Vector ((0 => (44, 38, 1, False))); Table.States (83).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 103))); Add_Action (Table.States (84), 13, 104); Add_Error (Table.States (84)); Table.States (84).Kernel := To_Vector ((0 => (65, 38, 3, False))); Table.States (84).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 13, 104))); Add_Action (Table.States (85), 13, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (85), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (85), 37, 105); Add_Error (Table.States (85)); Add_Goto (Table.States (85), 58, 106); Add_Goto (Table.States (85), 59, 107); Table.States (85).Kernel := To_Vector ((0 => (45, 6, 4, False))); Table.States (85).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 0))); Add_Action (Table.States (86), 10, 108); Add_Action (Table.States (86), 37, 109); Add_Error (Table.States (86)); Table.States (86).Kernel := To_Vector (((42, 12, 3, False), (42, 12, 5, False), (42, 12, 7, False), (42, 12, 6, False))); Table.States (86).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 109))); Add_Action (Table.States (87), 34, 110); Add_Error (Table.States (87)); Table.States (87).Kernel := To_Vector ((0 => (67, 16, 1, False))); Table.States (87).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 110))); Add_Action (Table.States (88), 9, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (88), 13, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (88), 20, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (88), 37, 111); Add_Error (Table.States (88)); Add_Goto (Table.States (88), 58, 112); Table.States (88).Kernel := To_Vector (((61, 18, 3, False), (62, 18, 4, False), (63, 18, 2, False))); Table.States (88).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 0))); Add_Action (Table.States (89), 37, 113); Add_Error (Table.States (89)); Table.States (89).Kernel := To_Vector ((0 => (72, 23, 5, False))); Table.States (89).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 113))); Add_Action (Table.States (90), 28, 114); Add_Action (Table.States (90), 29, 115); Add_Error (Table.States (90)); Table.States (90).Kernel := To_Vector (((67, 37, 2, False), (67, 37, 4, False))); Table.States (90).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 29, 115))); Add_Action (Table.States (91), (6, 8, 12, 16, 18, 23, 37), (67, 2), 1, null, null); Table.States (91).Kernel := To_Vector ((0 => (67, 42, 0, False))); Table.States (91).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 67, 1))); Add_Action (Table.States (92), (6, 8, 12, 16, 18, 23, 37), (67, 3), 1, null, null); Table.States (92).Kernel := To_Vector ((0 => (67, 45, 0, False))); Table.States (92).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 67, 1))); Add_Action (Table.States (93), (6, 8, 12, 16, 18, 23, 37), (52, 0), 1, null, null); Table.States (93).Kernel := To_Vector ((0 => (52, 51, 0, False))); Table.States (93).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 52, 1))); Add_Action (Table.States (94), 6, 85); Add_Action (Table.States (94), 8, Reduce, (53, 1), 1, null, null); Add_Action (Table.States (94), 12, 86); Add_Action (Table.States (94), 16, 87); Add_Action (Table.States (94), 18, 88); Add_Action (Table.States (94), 23, 89); Add_Action (Table.States (94), 37, 90); Add_Error (Table.States (94)); Add_Goto (Table.States (94), 42, 91); Add_Goto (Table.States (94), 45, 92); Add_Goto (Table.States (94), 51, 116); Add_Goto (Table.States (94), 60, 96); Add_Goto (Table.States (94), 61, 97); Add_Goto (Table.States (94), 62, 98); Add_Goto (Table.States (94), 63, 99); Add_Goto (Table.States (94), 67, 100); Add_Goto (Table.States (94), 72, 101); Table.States (94).Kernel := To_Vector (((52, 52, 2, True), (53, 52, 0, False))); Table.States (94).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 53, 1))); Add_Action (Table.States (95), 8, 117); Add_Error (Table.States (95)); Table.States (95).Kernel := To_Vector ((0 => (68, 53, 2, False))); Table.States (95).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 8, 117))); Add_Action (Table.States (96), (6, 8, 12, 16, 18, 23, 37), (51, 2), 1, null, null); Table.States (96).Kernel := To_Vector ((0 => (51, 60, 0, False))); Table.States (96).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 51, 1))); Add_Action (Table.States (97), (6, 8, 12, 16, 18, 23, 37), (60, 0), 1, null, null); Table.States (97).Kernel := To_Vector ((0 => (60, 61, 0, False))); Table.States (97).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 60, 1))); Add_Action (Table.States (98), (6, 8, 12, 16, 18, 23, 37), (60, 1), 1, null, null); Table.States (98).Kernel := To_Vector ((0 => (60, 62, 0, False))); Table.States (98).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 60, 1))); Add_Action (Table.States (99), (6, 8, 12, 16, 18, 23, 37), (60, 2), 1, null, null); Table.States (99).Kernel := To_Vector ((0 => (60, 63, 0, False))); Table.States (99).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 60, 1))); Add_Action (Table.States (100), (6, 8, 12, 16, 18, 23, 37), (51, 0), 1, null, null); Table.States (100).Kernel := To_Vector ((0 => (51, 67, 0, False))); Table.States (100).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 51, 1))); Add_Action (Table.States (101), (6, 8, 12, 16, 18, 23, 37), (51, 1), 1, null, null); Table.States (101).Kernel := To_Vector ((0 => (51, 72, 0, False))); Table.States (101).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 51, 1))); Add_Action (Table.States (102), 21, 118); Add_Error (Table.States (102)); Table.States (102).Kernel := To_Vector ((0 => (44, 38, 1, False))); Table.States (102).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 118))); Add_Action (Table.States (103), (27, 30, 34), (44, 1), 6, null, null); Table.States (103).Kernel := To_Vector ((0 => (44, 21, 0, False))); Table.States (103).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 44, 6))); Add_Action (Table.States (104), 6, 85); Add_Action (Table.States (104), 8, Reduce, (53, 0), 0, null, null); Add_Action (Table.States (104), 12, 86); Add_Action (Table.States (104), 16, 87); Add_Action (Table.States (104), 18, 88); Add_Action (Table.States (104), 23, 89); Add_Action (Table.States (104), 37, 90); Add_Error (Table.States (104)); Add_Goto (Table.States (104), 42, 91); Add_Goto (Table.States (104), 45, 92); Add_Goto (Table.States (104), 51, 93); Add_Goto (Table.States (104), 52, 94); Add_Goto (Table.States (104), 53, 119); Add_Goto (Table.States (104), 60, 96); Add_Goto (Table.States (104), 61, 97); Add_Goto (Table.States (104), 62, 98); Add_Goto (Table.States (104), 63, 99); Add_Goto (Table.States (104), 67, 100); Add_Goto (Table.States (104), 72, 101); Table.States (104).Kernel := To_Vector ((0 => (65, 13, 2, False))); Table.States (104).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 53, 0))); end Subr_1; procedure Subr_2 is begin Add_Action (Table.States (105), (13, 31), (58, 1), 1, null, identifier_opt_1_check'Access); Table.States (105).Kernel := To_Vector ((0 => (58, 37, 0, False))); Table.States (105).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 1))); Add_Action (Table.States (106), (13, 31), (59, 0), 1, null, null); Table.States (106).Kernel := To_Vector ((0 => (59, 58, 0, False))); Table.States (106).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 1))); Add_Action (Table.States (107), 13, 120); Add_Action (Table.States (107), 31, 121); Add_Error (Table.States (107)); Table.States (107).Kernel := To_Vector (((45, 59, 4, False), (59, 59, 2, True))); Table.States (107).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 13, 120))); Add_Action (Table.States (108), 14, 122); Add_Error (Table.States (108)); Table.States (108).Kernel := To_Vector ((0 => (42, 10, 5, False))); Table.States (108).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 122))); Add_Action (Table.States (109), 14, 123); Add_Action (Table.States (109), 24, 124); Add_Error (Table.States (109)); Table.States (109).Kernel := To_Vector (((42, 37, 2, False), (42, 37, 4, False), (42, 37, 6, False))); Table.States (109).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 24, 124))); Add_Action (Table.States (110), (6, 8, 12, 16, 18, 23, 37), (67, 4), 2, simple_declarative_item_4'Access, null); Table.States (110).Kernel := To_Vector ((0 => (67, 34, 0, False))); Table.States (110).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 67, 2))); Add_Action (Table.States (111), (9, 13, 20), (58, 1), 1, null, identifier_opt_1_check'Access); Table.States (111).Kernel := To_Vector ((0 => (58, 37, 0, False))); Table.States (111).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 1))); Add_Action (Table.States (112), 9, 125); Add_Action (Table.States (112), 13, 126); Add_Action (Table.States (112), 20, 127); Add_Error (Table.States (112)); Table.States (112).Kernel := To_Vector (((61, 58, 3, False), (62, 58, 4, False), (63, 58, 2, False))); Table.States (112).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 20, 127))); Add_Action (Table.States (113), 13, 128); Add_Error (Table.States (113)); Table.States (113).Kernel := To_Vector ((0 => (72, 37, 4, False))); Table.States (113).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 13, 128))); Add_Action (Table.States (114), 37, 129); Add_Error (Table.States (114)); Table.States (114).Kernel := To_Vector ((0 => (67, 28, 3, False))); Table.States (114).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 129))); Add_Action (Table.States (115), 10, 130); Add_Action (Table.States (115), 11, 131); Add_Action (Table.States (115), 14, 132); Add_Action (Table.States (115), 19, 9); Add_Action (Table.States (115), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (115), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (115), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (115), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (115), 37, 133); Add_Action (Table.States (115), 38, 134); Add_Error (Table.States (115)); Add_Goto (Table.States (115), 41, 135); Add_Goto (Table.States (115), 43, 136); Add_Goto (Table.States (115), 44, 137); Add_Goto (Table.States (115), 56, 138); Add_Goto (Table.States (115), 57, 139); Add_Goto (Table.States (115), 58, 140); Add_Goto (Table.States (115), 59, 141); Add_Goto (Table.States (115), 69, 142); Add_Goto (Table.States (115), 71, 143); Table.States (115).Kernel := To_Vector ((0 => (67, 29, 1, False))); Table.States (115).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Add_Action (Table.States (116), (6, 8, 12, 16, 18, 23, 37), (52, 1), 2, null, null); Table.States (116).Kernel := To_Vector ((0 => (52, 51, 0, True))); Table.States (116).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 52, 2))); Table.States (116).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (117), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (117), 37, 144); Add_Error (Table.States (117)); Add_Goto (Table.States (117), 58, 145); Table.States (117).Kernel := To_Vector ((0 => (68, 8, 1, False))); Table.States (117).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 0))); Add_Action (Table.States (118), (21, 27, 30), (44, 1), 6, null, null); Table.States (118).Kernel := To_Vector ((0 => (44, 21, 0, False))); Table.States (118).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 44, 6))); Add_Action (Table.States (119), 8, 146); Add_Error (Table.States (119)); Table.States (119).Kernel := To_Vector ((0 => (65, 53, 2, False))); Table.States (119).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 8, 146))); Add_Action (Table.States (120), 8, Reduce, (47, 0), 0, null, null); Add_Action (Table.States (120), 25, 147); Add_Conflict (Table.States (120), 25, (47, 0), 0, null, null); Add_Error (Table.States (120)); Add_Goto (Table.States (120), 46, 148); Add_Goto (Table.States (120), 47, 149); Table.States (120).Kernel := To_Vector ((0 => (45, 13, 3, False))); Table.States (120).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 47, 0))); Add_Action (Table.States (121), 37, 150); Add_Error (Table.States (121)); Table.States (121).Kernel := To_Vector ((0 => (59, 31, 1, True))); Table.States (121).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 150))); Table.States (121).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (122), 38, 151); Add_Error (Table.States (122)); Table.States (122).Kernel := To_Vector ((0 => (42, 14, 4, False))); Table.States (122).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 38, 151))); Add_Action (Table.States (123), 17, 152); Add_Action (Table.States (123), 21, Reduce, (54, 0), 0, null, null); Add_Action (Table.States (123), 38, 153); Add_Error (Table.States (123)); Add_Goto (Table.States (123), 54, 154); Table.States (123).Kernel := To_Vector (((42, 14, 3, False), (42, 14, 5, False))); Table.States (123).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 54, 0))); Add_Action (Table.States (124), 10, 130); Add_Action (Table.States (124), 11, 131); Add_Action (Table.States (124), 14, 132); Add_Action (Table.States (124), 19, 9); Add_Action (Table.States (124), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (124), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (124), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (124), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (124), 37, 133); Add_Action (Table.States (124), 38, 134); Add_Error (Table.States (124)); Add_Goto (Table.States (124), 41, 135); Add_Goto (Table.States (124), 43, 136); Add_Goto (Table.States (124), 44, 137); Add_Goto (Table.States (124), 56, 155); Add_Goto (Table.States (124), 57, 139); Add_Goto (Table.States (124), 58, 140); Add_Goto (Table.States (124), 59, 141); Add_Goto (Table.States (124), 69, 142); Add_Goto (Table.States (124), 71, 143); Table.States (124).Kernel := To_Vector ((0 => (42, 24, 1, False))); Table.States (124).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Add_Action (Table.States (125), 13, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (125), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (125), 37, 105); Add_Error (Table.States (125)); Add_Goto (Table.States (125), 58, 106); Add_Goto (Table.States (125), 59, 156); Table.States (125).Kernel := To_Vector ((0 => (62, 9, 3, False))); Table.States (125).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 0))); Add_Action (Table.States (126), 6, 85); Add_Action (Table.States (126), 8, Reduce, (53, 0), 0, null, null); Add_Action (Table.States (126), 12, 86); Add_Action (Table.States (126), 16, 87); Add_Action (Table.States (126), 18, 88); Add_Action (Table.States (126), 23, 89); Add_Action (Table.States (126), 37, 90); Add_Error (Table.States (126)); Add_Goto (Table.States (126), 42, 91); Add_Goto (Table.States (126), 45, 92); Add_Goto (Table.States (126), 51, 93); Add_Goto (Table.States (126), 52, 94); Add_Goto (Table.States (126), 53, 157); Add_Goto (Table.States (126), 60, 96); Add_Goto (Table.States (126), 61, 97); Add_Goto (Table.States (126), 62, 98); Add_Goto (Table.States (126), 63, 99); Add_Goto (Table.States (126), 67, 100); Add_Goto (Table.States (126), 72, 101); Table.States (126).Kernel := To_Vector ((0 => (61, 13, 2, False))); Table.States (126).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 53, 0))); Add_Action (Table.States (127), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (127), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (127), 37, 158); Add_Error (Table.States (127)); Add_Goto (Table.States (127), 58, 159); Add_Goto (Table.States (127), 59, 160); Table.States (127).Kernel := To_Vector ((0 => (63, 20, 1, False))); Table.States (127).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 0))); Add_Action (Table.States (128), 14, 161); Add_Error (Table.States (128)); Add_Goto (Table.States (128), 41, 162); Table.States (128).Kernel := To_Vector ((0 => (72, 13, 3, False))); Table.States (128).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 161))); Add_Action (Table.States (129), 29, 163); Add_Error (Table.States (129)); Table.States (129).Kernel := To_Vector ((0 => (67, 37, 2, False))); Table.States (129).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 29, 163))); Add_Action (Table.States (130), 14, 164); Add_Error (Table.States (130)); Add_Goto (Table.States (130), 41, 165); Table.States (130).Kernel := To_Vector ((0 => (57, 10, 2, False))); Table.States (130).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 164))); Add_Action (Table.States (131), 14, 164); Add_Error (Table.States (131)); Add_Goto (Table.States (131), 41, 166); Table.States (131).Kernel := To_Vector ((0 => (57, 11, 2, False))); Table.States (131).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 164))); Add_Action (Table.States (132), 10, 32); Add_Action (Table.States (132), 11, 33); Add_Action (Table.States (132), 14, 34); Add_Action (Table.States (132), 19, 9); Add_Action (Table.States (132), 21, 167); Add_Conflict (Table.States (132), 21, (58, 0), 0, null, null); Add_Action (Table.States (132), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (132), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (132), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (132), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (132), 37, 36); Add_Action (Table.States (132), 38, 37); Add_Error (Table.States (132)); Add_Goto (Table.States (132), 41, 38); Add_Goto (Table.States (132), 43, 39); Add_Goto (Table.States (132), 44, 40); Add_Goto (Table.States (132), 56, 41); Add_Goto (Table.States (132), 57, 42); Add_Goto (Table.States (132), 58, 43); Add_Goto (Table.States (132), 59, 44); Add_Goto (Table.States (132), 69, 45); Add_Goto (Table.States (132), 70, 168); Add_Goto (Table.States (132), 71, 47); Table.States (132).Kernel := To_Vector (((41, 14, 1, False), (71, 14, 1, False))); Table.States (132).Minimal_Complete_Actions := To_Vector (((Reduce, 70, 0), (Shift, 21, 167))); Add_Action (Table.States (133), (27, 31, 33, 34), (58, 1), 1, null, identifier_opt_1_check'Access); Table.States (133).Kernel := To_Vector ((0 => (58, 37, 0, False))); Table.States (133).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 1))); Add_Action (Table.States (134), (27, 34), (69, 0), 1, null, null); Table.States (134).Kernel := To_Vector ((0 => (69, 38, 0, False))); Table.States (134).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (135), (27, 34), (71, 2), 1, null, null); Table.States (135).Kernel := To_Vector ((0 => (71, 41, 0, False))); Table.States (135).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 1))); Add_Action (Table.States (136), 33, 169); Add_Error (Table.States (136)); Table.States (136).Kernel := To_Vector (((44, 43, 2, False), (44, 43, 5, False))); Table.States (136).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 33, 169))); Add_Action (Table.States (137), (27, 34), (69, 3), 1, null, null); Table.States (137).Kernel := To_Vector ((0 => (69, 44, 0, False))); Table.States (137).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (138), 27, 170); Add_Action (Table.States (138), 34, 171); Add_Error (Table.States (138)); Table.States (138).Kernel := To_Vector (((56, 56, 1, True), (67, 56, 1, False))); Table.States (138).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 171))); Add_Action (Table.States (139), (27, 34), (69, 2), 1, null, null); Table.States (139).Kernel := To_Vector ((0 => (69, 57, 0, False))); Table.States (139).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (140), (27, 31, 33, 34), (59, 0), 1, null, null); Table.States (140).Kernel := To_Vector ((0 => (59, 58, 0, False))); Table.States (140).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 1))); Add_Action (Table.States (141), 27, Reduce, (69, 1), 1, null, null); Add_Action (Table.States (141), 31, 172); Add_Action (Table.States (141), 33, Reduce, (43, 1), 1, null, null); Add_Action (Table.States (141), 34, Reduce, (69, 1), 1, null, null); Add_Error (Table.States (141)); Table.States (141).Kernel := To_Vector (((43, 59, 0, False), (59, 59, 2, True), (69, 59, 0, False))); Table.States (141).Minimal_Complete_Actions := To_Vector (((Reduce, 43, 1), (Reduce, 69, 1))); Add_Action (Table.States (142), (27, 34), (71, 0), 1, null, null); Table.States (142).Kernel := To_Vector ((0 => (71, 69, 0, False))); Table.States (142).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 1))); Add_Action (Table.States (143), (27, 34), (56, 0), 1, null, null); Table.States (143).Kernel := To_Vector ((0 => (56, 71, 0, False))); Table.States (143).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 1))); Add_Action (Table.States (144), (1 => 34), (58, 1), 1, null, identifier_opt_1_check'Access); Table.States (144).Kernel := To_Vector ((0 => (58, 37, 0, False))); Table.States (144).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 1))); Add_Action (Table.States (145), 34, 173); Add_Error (Table.States (145)); Table.States (145).Kernel := To_Vector ((0 => (68, 58, 1, False))); Table.States (145).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 173))); Add_Action (Table.States (146), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (146), 37, 144); Add_Error (Table.States (146)); Add_Goto (Table.States (146), 58, 174); Table.States (146).Kernel := To_Vector ((0 => (65, 8, 1, False))); Table.States (146).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 0))); Add_Action (Table.States (147), 17, 175); Add_Action (Table.States (147), 32, Reduce, (54, 0), 0, null, null); Add_Action (Table.States (147), 35, Reduce, (54, 0), 0, null, null); Add_Action (Table.States (147), 38, 176); Add_Error (Table.States (147)); Add_Goto (Table.States (147), 54, 177); Add_Goto (Table.States (147), 55, 178); Table.States (147).Kernel := To_Vector ((0 => (46, 25, 1, False))); Table.States (147).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 55, 0))); Add_Action (Table.States (148), (8, 25), (47, 1), 1, null, null); Table.States (148).Kernel := To_Vector ((0 => (47, 46, 0, False))); Table.States (148).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 47, 1))); Add_Action (Table.States (149), 8, 179); Add_Action (Table.States (149), 25, 147); Add_Error (Table.States (149)); Add_Goto (Table.States (149), 46, 180); Table.States (149).Kernel := To_Vector (((45, 47, 3, False), (47, 47, 2, True))); Table.States (149).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 8, 179))); Add_Action (Table.States (150), (13, 31), (59, 1), 3, null, null); Table.States (150).Kernel := To_Vector ((0 => (59, 37, 0, True))); Table.States (150).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 3))); Table.States (150).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (151), 21, 181); Add_Error (Table.States (151)); Table.States (151).Kernel := To_Vector ((0 => (42, 38, 3, False))); Table.States (151).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 181))); Add_Action (Table.States (152), (1 => 21), (54, 2), 1, null, null); Table.States (152).Kernel := To_Vector ((0 => (54, 17, 0, False))); Table.States (152).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 54, 1))); Add_Action (Table.States (153), (1 => 21), (54, 1), 1, null, null); Table.States (153).Kernel := To_Vector ((0 => (54, 38, 0, False))); Table.States (153).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 54, 1))); Add_Action (Table.States (154), 21, 182); Add_Error (Table.States (154)); Table.States (154).Kernel := To_Vector (((42, 54, 3, False), (42, 54, 5, False))); Table.States (154).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 182))); Add_Action (Table.States (155), 27, 170); Add_Action (Table.States (155), 34, 183); Add_Error (Table.States (155)); Table.States (155).Kernel := To_Vector (((42, 56, 1, False), (56, 56, 1, True))); Table.States (155).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 183))); Add_Action (Table.States (156), 13, 184); Add_Action (Table.States (156), 31, 121); Add_Error (Table.States (156)); Table.States (156).Kernel := To_Vector (((59, 59, 2, True), (62, 59, 3, False))); Table.States (156).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 13, 184))); Add_Action (Table.States (157), 8, 185); Add_Error (Table.States (157)); Table.States (157).Kernel := To_Vector ((0 => (61, 53, 2, False))); Table.States (157).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 8, 185))); Add_Action (Table.States (158), (31, 34), (58, 1), 1, null, identifier_opt_1_check'Access); Table.States (158).Kernel := To_Vector ((0 => (58, 37, 0, False))); Table.States (158).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 1))); Add_Action (Table.States (159), (31, 34), (59, 0), 1, null, null); Table.States (159).Kernel := To_Vector ((0 => (59, 58, 0, False))); Table.States (159).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 1))); Add_Action (Table.States (160), 31, 186); Add_Action (Table.States (160), 34, 187); Add_Error (Table.States (160)); Table.States (160).Kernel := To_Vector (((59, 59, 2, True), (63, 59, 1, False))); Table.States (160).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 187))); Add_Action (Table.States (161), 10, 32); Add_Action (Table.States (161), 11, 33); Add_Action (Table.States (161), 14, 34); Add_Action (Table.States (161), 19, 9); Add_Action (Table.States (161), 21, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (161), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (161), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (161), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (161), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (161), 37, 36); Add_Action (Table.States (161), 38, 37); Add_Error (Table.States (161)); Add_Goto (Table.States (161), 41, 38); Add_Goto (Table.States (161), 43, 39); Add_Goto (Table.States (161), 44, 40); Add_Goto (Table.States (161), 56, 41); Add_Goto (Table.States (161), 57, 42); Add_Goto (Table.States (161), 58, 43); Add_Goto (Table.States (161), 59, 44); Add_Goto (Table.States (161), 69, 45); Add_Goto (Table.States (161), 70, 188); Add_Goto (Table.States (161), 71, 47); Table.States (161).Kernel := To_Vector ((0 => (41, 14, 1, False))); Table.States (161).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 70, 0))); Add_Action (Table.States (162), 34, 189); Add_Error (Table.States (162)); Table.States (162).Kernel := To_Vector ((0 => (72, 41, 1, False))); Table.States (162).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 189))); Add_Action (Table.States (163), 10, 130); Add_Action (Table.States (163), 11, 131); Add_Action (Table.States (163), 14, 132); Add_Action (Table.States (163), 19, 9); Add_Action (Table.States (163), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (163), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (163), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (163), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (163), 37, 133); Add_Action (Table.States (163), 38, 134); Add_Error (Table.States (163)); Add_Goto (Table.States (163), 41, 135); Add_Goto (Table.States (163), 43, 136); Add_Goto (Table.States (163), 44, 137); Add_Goto (Table.States (163), 56, 190); Add_Goto (Table.States (163), 57, 139); Add_Goto (Table.States (163), 58, 140); Add_Goto (Table.States (163), 59, 141); Add_Goto (Table.States (163), 69, 142); Add_Goto (Table.States (163), 71, 143); Table.States (163).Kernel := To_Vector ((0 => (67, 29, 1, False))); Table.States (163).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Add_Action (Table.States (164), 10, 32); Add_Action (Table.States (164), 11, 33); Add_Action (Table.States (164), 14, 34); Add_Action (Table.States (164), 19, 9); Add_Action (Table.States (164), 21, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (164), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (164), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (164), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (164), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (164), 37, 36); Add_Action (Table.States (164), 38, 37); Add_Error (Table.States (164)); Add_Goto (Table.States (164), 41, 38); Add_Goto (Table.States (164), 43, 39); Add_Goto (Table.States (164), 44, 40); Add_Goto (Table.States (164), 56, 41); Add_Goto (Table.States (164), 57, 42); Add_Goto (Table.States (164), 58, 43); Add_Goto (Table.States (164), 59, 44); Add_Goto (Table.States (164), 69, 45); Add_Goto (Table.States (164), 70, 168); Add_Goto (Table.States (164), 71, 47); Table.States (164).Kernel := To_Vector ((0 => (41, 14, 1, False))); Table.States (164).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 70, 0))); Add_Action (Table.States (165), (27, 34), (57, 0), 2, null, null); Table.States (165).Kernel := To_Vector ((0 => (57, 41, 0, False))); Table.States (165).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 57, 2))); Add_Action (Table.States (166), (27, 34), (57, 1), 2, null, null); Table.States (166).Kernel := To_Vector ((0 => (57, 41, 0, False))); Table.States (166).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 57, 2))); Add_Action (Table.States (167), (27, 34), (71, 1), 2, null, null); Table.States (167).Kernel := To_Vector ((0 => (71, 21, 0, False))); Table.States (167).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 2))); Add_Action (Table.States (168), 21, 191); Add_Action (Table.States (168), 30, 67); Add_Error (Table.States (168)); Table.States (168).Kernel := To_Vector (((41, 70, 1, False), (70, 70, 1, True))); Table.States (168).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 191))); Add_Action (Table.States (169), 37, 192); Add_Error (Table.States (169)); Table.States (169).Kernel := To_Vector (((44, 33, 1, False), (44, 33, 4, False))); Table.States (169).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 192))); Add_Action (Table.States (170), 10, 130); Add_Action (Table.States (170), 11, 131); Add_Action (Table.States (170), 14, 132); Add_Action (Table.States (170), 19, 9); Add_Action (Table.States (170), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (170), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (170), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (170), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (170), 37, 133); Add_Action (Table.States (170), 38, 134); Add_Error (Table.States (170)); Add_Goto (Table.States (170), 41, 135); Add_Goto (Table.States (170), 43, 136); Add_Goto (Table.States (170), 44, 137); Add_Goto (Table.States (170), 57, 139); Add_Goto (Table.States (170), 58, 140); Add_Goto (Table.States (170), 59, 141); Add_Goto (Table.States (170), 69, 142); Add_Goto (Table.States (170), 71, 193); Table.States (170).Kernel := To_Vector ((0 => (56, 27, 0, True))); Table.States (170).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 0))); Table.States (170).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (171), (6, 8, 12, 16, 18, 23, 37), (67, 0), 4, simple_declarative_item_0'Access, null); Table.States (171).Kernel := To_Vector ((0 => (67, 34, 0, False))); Table.States (171).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 67, 4))); Add_Action (Table.States (172), 37, 194); Add_Error (Table.States (172)); Table.States (172).Kernel := To_Vector ((0 => (59, 31, 1, True))); Table.States (172).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 194))); Table.States (172).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (173), (1 => 39), (68, 0), 7, simple_project_declaration_0'Access, simple_project_declaration_0_check'Access); Table.States (173).Kernel := To_Vector ((0 => (68, 34, 0, False))); Table.States (173).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 68, 7))); Add_Action (Table.States (174), 34, 195); Add_Error (Table.States (174)); Table.States (174).Kernel := To_Vector ((0 => (65, 58, 1, False))); Table.States (174).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 195))); Add_Action (Table.States (175), (32, 35), (54, 2), 1, null, null); Table.States (175).Kernel := To_Vector ((0 => (54, 17, 0, False))); Table.States (175).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 54, 1))); Add_Action (Table.States (176), (32, 35), (54, 1), 1, null, null); Table.States (176).Kernel := To_Vector ((0 => (54, 38, 0, False))); Table.States (176).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 54, 1))); Add_Action (Table.States (177), (32, 35), (55, 0), 1, null, null); Table.States (177).Kernel := To_Vector ((0 => (55, 54, 0, False))); Table.States (177).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 55, 1))); Add_Action (Table.States (178), 32, 196); Add_Action (Table.States (178), 35, 197); Add_Error (Table.States (178)); Table.States (178).Kernel := To_Vector (((46, 55, 1, False), (55, 55, 1, True))); Table.States (178).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 32, 196))); Add_Action (Table.States (179), 6, 198); Add_Error (Table.States (179)); Table.States (179).Kernel := To_Vector ((0 => (45, 8, 2, False))); Table.States (179).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 6, 198))); Add_Action (Table.States (180), (8, 25), (47, 2), 2, null, null); Table.States (180).Kernel := To_Vector ((0 => (47, 46, 0, True))); Table.States (180).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 47, 2))); Table.States (180).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (181), 24, 199); Add_Error (Table.States (181)); Table.States (181).Kernel := To_Vector ((0 => (42, 21, 2, False))); Table.States (181).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 24, 199))); Add_Action (Table.States (182), 24, 200); Add_Error (Table.States (182)); Table.States (182).Kernel := To_Vector (((42, 21, 2, False), (42, 21, 4, False))); Table.States (182).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 24, 200))); Add_Action (Table.States (183), (6, 8, 12, 16, 18, 23, 37), (42, 0), 5, attribute_declaration_0'Access, null); Table.States (183).Kernel := To_Vector ((0 => (42, 34, 0, False))); Table.States (183).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 42, 5))); Add_Action (Table.States (184), 6, 85); Add_Action (Table.States (184), 8, Reduce, (53, 0), 0, null, null); Add_Action (Table.States (184), 12, 86); Add_Action (Table.States (184), 16, 87); Add_Action (Table.States (184), 18, 88); Add_Action (Table.States (184), 23, 89); Add_Action (Table.States (184), 37, 90); Add_Error (Table.States (184)); Add_Goto (Table.States (184), 42, 91); Add_Goto (Table.States (184), 45, 92); Add_Goto (Table.States (184), 51, 93); Add_Goto (Table.States (184), 52, 94); Add_Goto (Table.States (184), 53, 201); Add_Goto (Table.States (184), 60, 96); Add_Goto (Table.States (184), 61, 97); Add_Goto (Table.States (184), 62, 98); Add_Goto (Table.States (184), 63, 99); Add_Goto (Table.States (184), 67, 100); Add_Goto (Table.States (184), 72, 101); Table.States (184).Kernel := To_Vector ((0 => (62, 13, 2, False))); Table.States (184).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 53, 0))); Add_Action (Table.States (185), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (185), 37, 144); Add_Error (Table.States (185)); Add_Goto (Table.States (185), 58, 202); Table.States (185).Kernel := To_Vector ((0 => (61, 8, 1, False))); Table.States (185).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 0))); Add_Action (Table.States (186), 37, 203); Add_Error (Table.States (186)); Table.States (186).Kernel := To_Vector ((0 => (59, 31, 1, True))); Table.States (186).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 203))); Table.States (186).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (187), (6, 8, 12, 16, 18, 23, 37), (63, 0), 5, package_renaming_0'Access, null); Table.States (187).Kernel := To_Vector ((0 => (63, 34, 0, False))); Table.States (187).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 63, 5))); Add_Action (Table.States (188), 21, 204); Add_Action (Table.States (188), 30, 67); Add_Error (Table.States (188)); Table.States (188).Kernel := To_Vector (((41, 70, 1, False), (70, 70, 1, True))); Table.States (188).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 204))); Add_Action (Table.States (189), (6, 8, 12, 16, 18, 23, 37), (72, 0), 5, typed_string_declaration_0'Access, null); Table.States (189).Kernel := To_Vector ((0 => (72, 34, 0, False))); Table.States (189).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 72, 5))); Add_Action (Table.States (190), 27, 170); Add_Action (Table.States (190), 34, 205); Add_Error (Table.States (190)); Table.States (190).Kernel := To_Vector (((56, 56, 1, True), (67, 56, 1, False))); Table.States (190).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 205))); Add_Action (Table.States (191), (27, 34), (41, 0), 3, aggregate_g_0'Access, null); Table.States (191).Kernel := To_Vector ((0 => (41, 21, 0, False))); Table.States (191).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 41, 3))); Add_Action (Table.States (192), 14, 206); Add_Action (Table.States (192), 27, Reduce, (44, 0), 3, null, null); Add_Action (Table.States (192), 34, Reduce, (44, 0), 3, null, null); Add_Error (Table.States (192)); Table.States (192).Kernel := To_Vector (((44, 37, 0, False), (44, 37, 3, False))); Table.States (192).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 44, 3))); Add_Action (Table.States (193), (27, 34), (56, 1), 3, null, null); Table.States (193).Kernel := To_Vector ((0 => (56, 71, 0, True))); Table.States (193).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 3))); Table.States (193).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (194), (27, 31, 33, 34), (59, 1), 3, null, null); Table.States (194).Kernel := To_Vector ((0 => (59, 37, 0, True))); Table.States (194).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 3))); Table.States (194).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (195), (1 => 39), (65, 0), 9, project_extension_0'Access, project_extension_0_check'Access); Table.States (195).Kernel := To_Vector ((0 => (65, 34, 0, False))); Table.States (195).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 65, 9))); Add_Action (Table.States (196), 6, 207); Add_Action (Table.States (196), 8, Reduce, (53, 0), 0, null, null); Add_Action (Table.States (196), 12, 208); Add_Action (Table.States (196), 16, 209); Add_Action (Table.States (196), 18, 210); Add_Action (Table.States (196), 23, 211); Add_Action (Table.States (196), 25, Reduce, (53, 0), 0, null, null); Add_Action (Table.States (196), 37, 212); Add_Error (Table.States (196)); Add_Goto (Table.States (196), 42, 213); Add_Goto (Table.States (196), 45, 214); Add_Goto (Table.States (196), 51, 215); Add_Goto (Table.States (196), 52, 216); Add_Goto (Table.States (196), 53, 217); Add_Goto (Table.States (196), 60, 218); Add_Goto (Table.States (196), 61, 219); Add_Goto (Table.States (196), 62, 220); Add_Goto (Table.States (196), 63, 221); Add_Goto (Table.States (196), 67, 222); Add_Goto (Table.States (196), 72, 223); Table.States (196).Kernel := To_Vector ((0 => (46, 32, 0, False))); Table.States (196).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 53, 0))); Add_Action (Table.States (197), 17, 175); Add_Action (Table.States (197), 32, Reduce, (54, 0), 0, null, null); Add_Action (Table.States (197), 35, Reduce, (54, 0), 0, null, null); Add_Action (Table.States (197), 38, 176); Add_Error (Table.States (197)); Add_Goto (Table.States (197), 54, 224); Table.States (197).Kernel := To_Vector ((0 => (55, 35, 0, True))); Table.States (197).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 54, 0))); Table.States (197).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (198), 34, 225); Add_Error (Table.States (198)); Table.States (198).Kernel := To_Vector ((0 => (45, 6, 1, False))); Table.States (198).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 225))); Add_Action (Table.States (199), 10, 130); Add_Action (Table.States (199), 11, 131); Add_Action (Table.States (199), 14, 132); Add_Action (Table.States (199), 19, 9); Add_Action (Table.States (199), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (199), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (199), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (199), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (199), 37, 133); Add_Action (Table.States (199), 38, 134); Add_Error (Table.States (199)); Add_Goto (Table.States (199), 41, 135); Add_Goto (Table.States (199), 43, 136); Add_Goto (Table.States (199), 44, 137); Add_Goto (Table.States (199), 56, 226); Add_Goto (Table.States (199), 57, 139); Add_Goto (Table.States (199), 58, 140); Add_Goto (Table.States (199), 59, 141); Add_Goto (Table.States (199), 69, 142); Add_Goto (Table.States (199), 71, 143); Table.States (199).Kernel := To_Vector ((0 => (42, 24, 1, False))); Table.States (199).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Add_Action (Table.States (200), 4, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (200), 10, 227); Add_Action (Table.States (200), 11, 228); Add_Action (Table.States (200), 14, 229); Add_Action (Table.States (200), 19, 9); Add_Action (Table.States (200), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (200), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (200), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (200), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (200), 37, 230); Add_Action (Table.States (200), 38, 231); Add_Error (Table.States (200)); Add_Goto (Table.States (200), 41, 232); Add_Goto (Table.States (200), 43, 233); Add_Goto (Table.States (200), 44, 234); Add_Goto (Table.States (200), 56, 235); Add_Goto (Table.States (200), 57, 236); Add_Goto (Table.States (200), 58, 237); Add_Goto (Table.States (200), 59, 238); Add_Goto (Table.States (200), 69, 239); Add_Goto (Table.States (200), 71, 240); Table.States (200).Kernel := To_Vector (((42, 24, 1, False), (42, 24, 3, False))); Table.States (200).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Add_Action (Table.States (201), 8, 241); Add_Error (Table.States (201)); Table.States (201).Kernel := To_Vector ((0 => (62, 53, 2, False))); Table.States (201).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 8, 241))); Add_Action (Table.States (202), 34, 242); Add_Error (Table.States (202)); Table.States (202).Kernel := To_Vector ((0 => (61, 58, 1, False))); Table.States (202).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 242))); Add_Action (Table.States (203), (31, 34), (59, 1), 3, null, null); Table.States (203).Kernel := To_Vector ((0 => (59, 37, 0, True))); Table.States (203).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 3))); Table.States (203).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (204), (1 => 34), (41, 0), 3, aggregate_g_0'Access, null); Table.States (204).Kernel := To_Vector ((0 => (41, 21, 0, False))); Table.States (204).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 41, 3))); Add_Action (Table.States (205), (6, 8, 12, 16, 18, 23, 37), (67, 1), 6, simple_declarative_item_1'Access, null); Table.States (205).Kernel := To_Vector ((0 => (67, 34, 0, False))); Table.States (205).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 67, 6))); Add_Action (Table.States (206), 38, 243); Add_Error (Table.States (206)); Table.States (206).Kernel := To_Vector ((0 => (44, 14, 2, False))); Table.States (206).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 38, 243))); Add_Action (Table.States (207), 13, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (207), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (207), 37, 105); Add_Error (Table.States (207)); Add_Goto (Table.States (207), 58, 106); Add_Goto (Table.States (207), 59, 244); Table.States (207).Kernel := To_Vector ((0 => (45, 6, 4, False))); Table.States (207).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 0))); Add_Action (Table.States (208), 10, 245); Add_Action (Table.States (208), 37, 246); Add_Error (Table.States (208)); Table.States (208).Kernel := To_Vector (((42, 12, 3, False), (42, 12, 5, False), (42, 12, 7, False), (42, 12, 6, False))); Table.States (208).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 246))); Add_Action (Table.States (209), 34, 247); Add_Error (Table.States (209)); Table.States (209).Kernel := To_Vector ((0 => (67, 16, 1, False))); Table.States (209).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 247))); Add_Action (Table.States (210), 9, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (210), 13, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (210), 20, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (210), 37, 111); Add_Error (Table.States (210)); Add_Goto (Table.States (210), 58, 248); Table.States (210).Kernel := To_Vector (((61, 18, 3, False), (62, 18, 4, False), (63, 18, 2, False))); Table.States (210).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 0))); end Subr_2; procedure Subr_3 is begin Add_Action (Table.States (211), 37, 249); Add_Error (Table.States (211)); Table.States (211).Kernel := To_Vector ((0 => (72, 23, 5, False))); Table.States (211).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 249))); Add_Action (Table.States (212), 28, 250); Add_Action (Table.States (212), 29, 251); Add_Error (Table.States (212)); Table.States (212).Kernel := To_Vector (((67, 37, 2, False), (67, 37, 4, False))); Table.States (212).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 29, 251))); Add_Action (Table.States (213), (6, 8, 12, 16, 18, 23, 25, 37), (67, 2), 1, null, null); Table.States (213).Kernel := To_Vector ((0 => (67, 42, 0, False))); Table.States (213).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 67, 1))); Add_Action (Table.States (214), (6, 8, 12, 16, 18, 23, 25, 37), (67, 3), 1, null, null); Table.States (214).Kernel := To_Vector ((0 => (67, 45, 0, False))); Table.States (214).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 67, 1))); Add_Action (Table.States (215), (6, 8, 12, 16, 18, 23, 25, 37), (52, 0), 1, null, null); Table.States (215).Kernel := To_Vector ((0 => (52, 51, 0, False))); Table.States (215).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 52, 1))); Add_Action (Table.States (216), 6, 207); Add_Action (Table.States (216), 8, Reduce, (53, 1), 1, null, null); Add_Action (Table.States (216), 12, 208); Add_Action (Table.States (216), 16, 209); Add_Action (Table.States (216), 18, 210); Add_Action (Table.States (216), 23, 211); Add_Action (Table.States (216), 25, Reduce, (53, 1), 1, null, null); Add_Action (Table.States (216), 37, 212); Add_Error (Table.States (216)); Add_Goto (Table.States (216), 42, 213); Add_Goto (Table.States (216), 45, 214); Add_Goto (Table.States (216), 51, 252); Add_Goto (Table.States (216), 60, 218); Add_Goto (Table.States (216), 61, 219); Add_Goto (Table.States (216), 62, 220); Add_Goto (Table.States (216), 63, 221); Add_Goto (Table.States (216), 67, 222); Add_Goto (Table.States (216), 72, 223); Table.States (216).Kernel := To_Vector (((52, 52, 2, True), (53, 52, 0, False))); Table.States (216).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 53, 1))); Add_Action (Table.States (217), (8, 25), (46, 0), 4, case_item_0'Access, null); Table.States (217).Kernel := To_Vector ((0 => (46, 53, 0, False))); Table.States (217).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 46, 4))); Add_Action (Table.States (218), (6, 8, 12, 16, 18, 23, 25, 37), (51, 2), 1, null, null); Table.States (218).Kernel := To_Vector ((0 => (51, 60, 0, False))); Table.States (218).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 51, 1))); Add_Action (Table.States (219), (6, 8, 12, 16, 18, 23, 25, 37), (60, 0), 1, null, null); Table.States (219).Kernel := To_Vector ((0 => (60, 61, 0, False))); Table.States (219).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 60, 1))); Add_Action (Table.States (220), (6, 8, 12, 16, 18, 23, 25, 37), (60, 1), 1, null, null); Table.States (220).Kernel := To_Vector ((0 => (60, 62, 0, False))); Table.States (220).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 60, 1))); Add_Action (Table.States (221), (6, 8, 12, 16, 18, 23, 25, 37), (60, 2), 1, null, null); Table.States (221).Kernel := To_Vector ((0 => (60, 63, 0, False))); Table.States (221).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 60, 1))); Add_Action (Table.States (222), (6, 8, 12, 16, 18, 23, 25, 37), (51, 0), 1, null, null); Table.States (222).Kernel := To_Vector ((0 => (51, 67, 0, False))); Table.States (222).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 51, 1))); Add_Action (Table.States (223), (6, 8, 12, 16, 18, 23, 25, 37), (51, 1), 1, null, null); Table.States (223).Kernel := To_Vector ((0 => (51, 72, 0, False))); Table.States (223).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 51, 1))); Add_Action (Table.States (224), (32, 35), (55, 1), 3, null, null); Table.States (224).Kernel := To_Vector ((0 => (55, 54, 0, True))); Table.States (224).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 55, 3))); Table.States (224).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (225), (6, 8, 12, 16, 18, 23, 37), (45, 0), 7, case_statement_0'Access, null); Table.States (225).Kernel := To_Vector ((0 => (45, 34, 0, False))); Table.States (225).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 45, 7))); Add_Action (Table.States (226), 27, 170); Add_Action (Table.States (226), 34, 253); Add_Error (Table.States (226)); Table.States (226).Kernel := To_Vector (((42, 56, 1, False), (56, 56, 1, True))); Table.States (226).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 253))); Add_Action (Table.States (227), 14, 254); Add_Error (Table.States (227)); Add_Goto (Table.States (227), 41, 255); Table.States (227).Kernel := To_Vector ((0 => (57, 10, 2, False))); Table.States (227).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 254))); Add_Action (Table.States (228), 14, 254); Add_Error (Table.States (228)); Add_Goto (Table.States (228), 41, 256); Table.States (228).Kernel := To_Vector ((0 => (57, 11, 2, False))); Table.States (228).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 254))); Add_Action (Table.States (229), 10, 32); Add_Action (Table.States (229), 11, 33); Add_Action (Table.States (229), 14, 34); Add_Action (Table.States (229), 19, 9); Add_Action (Table.States (229), 21, 257); Add_Conflict (Table.States (229), 21, (58, 0), 0, null, null); Add_Action (Table.States (229), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (229), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (229), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (229), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (229), 37, 36); Add_Action (Table.States (229), 38, 37); Add_Error (Table.States (229)); Add_Goto (Table.States (229), 41, 38); Add_Goto (Table.States (229), 43, 39); Add_Goto (Table.States (229), 44, 40); Add_Goto (Table.States (229), 56, 41); Add_Goto (Table.States (229), 57, 42); Add_Goto (Table.States (229), 58, 43); Add_Goto (Table.States (229), 59, 44); Add_Goto (Table.States (229), 69, 45); Add_Goto (Table.States (229), 70, 258); Add_Goto (Table.States (229), 71, 47); Table.States (229).Kernel := To_Vector (((41, 14, 1, False), (71, 14, 1, False))); Table.States (229).Minimal_Complete_Actions := To_Vector (((Reduce, 70, 0), (Shift, 21, 257))); Add_Action (Table.States (230), (4, 27, 31, 33, 34), (58, 1), 1, null, identifier_opt_1_check'Access); Table.States (230).Kernel := To_Vector ((0 => (58, 37, 0, False))); Table.States (230).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 1))); Add_Action (Table.States (231), (4, 27, 34), (69, 0), 1, null, null); Table.States (231).Kernel := To_Vector ((0 => (69, 38, 0, False))); Table.States (231).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (232), (4, 27, 34), (71, 2), 1, null, null); Table.States (232).Kernel := To_Vector ((0 => (71, 41, 0, False))); Table.States (232).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 1))); Add_Action (Table.States (233), 33, 259); Add_Error (Table.States (233)); Table.States (233).Kernel := To_Vector (((44, 43, 2, False), (44, 43, 5, False))); Table.States (233).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 33, 259))); Add_Action (Table.States (234), (4, 27, 34), (69, 3), 1, null, null); Table.States (234).Kernel := To_Vector ((0 => (69, 44, 0, False))); Table.States (234).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (235), 4, 260); Add_Action (Table.States (235), 27, 261); Add_Action (Table.States (235), 34, 262); Add_Error (Table.States (235)); Table.States (235).Kernel := To_Vector (((42, 56, 1, False), (42, 56, 3, False), (56, 56, 1, True))); Table.States (235).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 262))); Add_Action (Table.States (236), (4, 27, 34), (69, 2), 1, null, null); Table.States (236).Kernel := To_Vector ((0 => (69, 57, 0, False))); Table.States (236).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 69, 1))); Add_Action (Table.States (237), (4, 27, 31, 33, 34), (59, 0), 1, null, null); Table.States (237).Kernel := To_Vector ((0 => (59, 58, 0, False))); Table.States (237).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 1))); Add_Action (Table.States (238), 4, Reduce, (69, 1), 1, null, null); Add_Action (Table.States (238), 27, Reduce, (69, 1), 1, null, null); Add_Action (Table.States (238), 31, 263); Add_Action (Table.States (238), 33, Reduce, (43, 1), 1, null, null); Add_Action (Table.States (238), 34, Reduce, (69, 1), 1, null, null); Add_Error (Table.States (238)); Table.States (238).Kernel := To_Vector (((43, 59, 0, False), (59, 59, 2, True), (69, 59, 0, False))); Table.States (238).Minimal_Complete_Actions := To_Vector (((Reduce, 43, 1), (Reduce, 69, 1))); Add_Action (Table.States (239), (4, 27, 34), (71, 0), 1, null, null); Table.States (239).Kernel := To_Vector ((0 => (71, 69, 0, False))); Table.States (239).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 1))); Add_Action (Table.States (240), (4, 27, 34), (56, 0), 1, null, null); Table.States (240).Kernel := To_Vector ((0 => (56, 71, 0, False))); Table.States (240).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 1))); Add_Action (Table.States (241), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (241), 37, 144); Add_Error (Table.States (241)); Add_Goto (Table.States (241), 58, 264); Table.States (241).Kernel := To_Vector ((0 => (62, 8, 1, False))); Table.States (241).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 0))); Add_Action (Table.States (242), (6, 8, 12, 16, 18, 23, 37), (61, 0), 7, package_spec_0'Access, package_spec_0_check'Access); Table.States (242).Kernel := To_Vector ((0 => (61, 34, 0, False))); Table.States (242).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 61, 7))); Add_Action (Table.States (243), 21, 265); Add_Error (Table.States (243)); Table.States (243).Kernel := To_Vector ((0 => (44, 38, 1, False))); Table.States (243).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 265))); Add_Action (Table.States (244), 13, 266); Add_Action (Table.States (244), 31, 121); Add_Error (Table.States (244)); Table.States (244).Kernel := To_Vector (((45, 59, 4, False), (59, 59, 2, True))); Table.States (244).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 13, 266))); Add_Action (Table.States (245), 14, 267); Add_Error (Table.States (245)); Table.States (245).Kernel := To_Vector ((0 => (42, 10, 5, False))); Table.States (245).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 267))); Add_Action (Table.States (246), 14, 268); Add_Action (Table.States (246), 24, 269); Add_Error (Table.States (246)); Table.States (246).Kernel := To_Vector (((42, 37, 2, False), (42, 37, 4, False), (42, 37, 6, False))); Table.States (246).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 24, 269))); Add_Action (Table.States (247), (6, 8, 12, 16, 18, 23, 25, 37), (67, 4), 2, simple_declarative_item_4'Access, null); Table.States (247).Kernel := To_Vector ((0 => (67, 34, 0, False))); Table.States (247).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 67, 2))); Add_Action (Table.States (248), 9, 270); Add_Action (Table.States (248), 13, 271); Add_Action (Table.States (248), 20, 272); Add_Error (Table.States (248)); Table.States (248).Kernel := To_Vector (((61, 58, 3, False), (62, 58, 4, False), (63, 58, 2, False))); Table.States (248).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 20, 272))); Add_Action (Table.States (249), 13, 273); Add_Error (Table.States (249)); Table.States (249).Kernel := To_Vector ((0 => (72, 37, 4, False))); Table.States (249).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 13, 273))); Add_Action (Table.States (250), 37, 274); Add_Error (Table.States (250)); Table.States (250).Kernel := To_Vector ((0 => (67, 28, 3, False))); Table.States (250).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 274))); Add_Action (Table.States (251), 10, 130); Add_Action (Table.States (251), 11, 131); Add_Action (Table.States (251), 14, 132); Add_Action (Table.States (251), 19, 9); Add_Action (Table.States (251), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (251), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (251), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (251), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (251), 37, 133); Add_Action (Table.States (251), 38, 134); Add_Error (Table.States (251)); Add_Goto (Table.States (251), 41, 135); Add_Goto (Table.States (251), 43, 136); Add_Goto (Table.States (251), 44, 137); Add_Goto (Table.States (251), 56, 275); Add_Goto (Table.States (251), 57, 139); Add_Goto (Table.States (251), 58, 140); Add_Goto (Table.States (251), 59, 141); Add_Goto (Table.States (251), 69, 142); Add_Goto (Table.States (251), 71, 143); Table.States (251).Kernel := To_Vector ((0 => (67, 29, 1, False))); Table.States (251).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Add_Action (Table.States (252), (6, 8, 12, 16, 18, 23, 25, 37), (52, 1), 2, null, null); Table.States (252).Kernel := To_Vector ((0 => (52, 51, 0, True))); Table.States (252).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 52, 2))); Table.States (252).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (253), (6, 8, 12, 16, 18, 23, 37), (42, 3), 8, attribute_declaration_3'Access, null); Table.States (253).Kernel := To_Vector ((0 => (42, 34, 0, False))); Table.States (253).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 42, 8))); Add_Action (Table.States (254), 10, 32); Add_Action (Table.States (254), 11, 33); Add_Action (Table.States (254), 14, 34); Add_Action (Table.States (254), 19, 9); Add_Action (Table.States (254), 21, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (254), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (254), 30, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (254), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (254), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (254), 37, 36); Add_Action (Table.States (254), 38, 37); Add_Error (Table.States (254)); Add_Goto (Table.States (254), 41, 38); Add_Goto (Table.States (254), 43, 39); Add_Goto (Table.States (254), 44, 40); Add_Goto (Table.States (254), 56, 41); Add_Goto (Table.States (254), 57, 42); Add_Goto (Table.States (254), 58, 43); Add_Goto (Table.States (254), 59, 44); Add_Goto (Table.States (254), 69, 45); Add_Goto (Table.States (254), 70, 258); Add_Goto (Table.States (254), 71, 47); Table.States (254).Kernel := To_Vector ((0 => (41, 14, 1, False))); Table.States (254).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 70, 0))); Add_Action (Table.States (255), (4, 27, 34), (57, 0), 2, null, null); Table.States (255).Kernel := To_Vector ((0 => (57, 41, 0, False))); Table.States (255).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 57, 2))); Add_Action (Table.States (256), (4, 27, 34), (57, 1), 2, null, null); Table.States (256).Kernel := To_Vector ((0 => (57, 41, 0, False))); Table.States (256).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 57, 2))); Add_Action (Table.States (257), (4, 27, 34), (71, 1), 2, null, null); Table.States (257).Kernel := To_Vector ((0 => (71, 21, 0, False))); Table.States (257).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 2))); Add_Action (Table.States (258), 21, 276); Add_Action (Table.States (258), 30, 67); Add_Error (Table.States (258)); Table.States (258).Kernel := To_Vector (((41, 70, 1, False), (70, 70, 1, True))); Table.States (258).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 276))); Add_Action (Table.States (259), 37, 277); Add_Error (Table.States (259)); Table.States (259).Kernel := To_Vector (((44, 33, 1, False), (44, 33, 4, False))); Table.States (259).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 277))); Add_Action (Table.States (260), 36, 278); Add_Error (Table.States (260)); Table.States (260).Kernel := To_Vector ((0 => (42, 4, 2, False))); Table.States (260).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 36, 278))); Add_Action (Table.States (261), 4, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (261), 10, 227); Add_Action (Table.States (261), 11, 228); Add_Action (Table.States (261), 14, 229); Add_Action (Table.States (261), 19, 9); Add_Action (Table.States (261), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (261), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (261), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (261), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (261), 37, 230); Add_Action (Table.States (261), 38, 231); Add_Error (Table.States (261)); Add_Goto (Table.States (261), 41, 232); Add_Goto (Table.States (261), 43, 233); Add_Goto (Table.States (261), 44, 234); Add_Goto (Table.States (261), 57, 236); Add_Goto (Table.States (261), 58, 237); Add_Goto (Table.States (261), 59, 238); Add_Goto (Table.States (261), 69, 239); Add_Goto (Table.States (261), 71, 279); Table.States (261).Kernel := To_Vector ((0 => (56, 27, 0, True))); Table.States (261).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 71, 0))); Table.States (261).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (262), (6, 8, 12, 16, 18, 23, 37), (42, 1), 8, attribute_declaration_1'Access, null); Table.States (262).Kernel := To_Vector ((0 => (42, 34, 0, False))); Table.States (262).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 42, 8))); Add_Action (Table.States (263), 37, 280); Add_Error (Table.States (263)); Table.States (263).Kernel := To_Vector ((0 => (59, 31, 1, True))); Table.States (263).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 37, 280))); Table.States (263).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (264), 34, 281); Add_Error (Table.States (264)); Table.States (264).Kernel := To_Vector ((0 => (62, 58, 1, False))); Table.States (264).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 281))); Add_Action (Table.States (265), (27, 34), (44, 1), 6, null, null); Table.States (265).Kernel := To_Vector ((0 => (44, 21, 0, False))); Table.States (265).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 44, 6))); Add_Action (Table.States (266), 8, Reduce, (47, 0), 0, null, null); Add_Action (Table.States (266), 25, 147); Add_Conflict (Table.States (266), 25, (47, 0), 0, null, null); Add_Error (Table.States (266)); Add_Goto (Table.States (266), 46, 148); Add_Goto (Table.States (266), 47, 282); Table.States (266).Kernel := To_Vector ((0 => (45, 13, 3, False))); Table.States (266).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 47, 0))); Add_Action (Table.States (267), 38, 283); Add_Error (Table.States (267)); Table.States (267).Kernel := To_Vector ((0 => (42, 14, 4, False))); Table.States (267).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 38, 283))); Add_Action (Table.States (268), 17, 152); Add_Action (Table.States (268), 21, Reduce, (54, 0), 0, null, null); Add_Action (Table.States (268), 38, 153); Add_Error (Table.States (268)); Add_Goto (Table.States (268), 54, 284); Table.States (268).Kernel := To_Vector (((42, 14, 3, False), (42, 14, 5, False))); Table.States (268).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 54, 0))); Add_Action (Table.States (269), 10, 130); Add_Action (Table.States (269), 11, 131); Add_Action (Table.States (269), 14, 132); Add_Action (Table.States (269), 19, 9); Add_Action (Table.States (269), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (269), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (269), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (269), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (269), 37, 133); Add_Action (Table.States (269), 38, 134); Add_Error (Table.States (269)); Add_Goto (Table.States (269), 41, 135); Add_Goto (Table.States (269), 43, 136); Add_Goto (Table.States (269), 44, 137); Add_Goto (Table.States (269), 56, 285); Add_Goto (Table.States (269), 57, 139); Add_Goto (Table.States (269), 58, 140); Add_Goto (Table.States (269), 59, 141); Add_Goto (Table.States (269), 69, 142); Add_Goto (Table.States (269), 71, 143); Table.States (269).Kernel := To_Vector ((0 => (42, 24, 1, False))); Table.States (269).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Add_Action (Table.States (270), 13, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (270), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (270), 37, 105); Add_Error (Table.States (270)); Add_Goto (Table.States (270), 58, 106); Add_Goto (Table.States (270), 59, 286); Table.States (270).Kernel := To_Vector ((0 => (62, 9, 3, False))); Table.States (270).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 0))); Add_Action (Table.States (271), 6, 85); Add_Action (Table.States (271), 8, Reduce, (53, 0), 0, null, null); Add_Action (Table.States (271), 12, 86); Add_Action (Table.States (271), 16, 87); Add_Action (Table.States (271), 18, 88); Add_Action (Table.States (271), 23, 89); Add_Action (Table.States (271), 37, 90); Add_Error (Table.States (271)); Add_Goto (Table.States (271), 42, 91); Add_Goto (Table.States (271), 45, 92); Add_Goto (Table.States (271), 51, 93); Add_Goto (Table.States (271), 52, 94); Add_Goto (Table.States (271), 53, 287); Add_Goto (Table.States (271), 60, 96); Add_Goto (Table.States (271), 61, 97); Add_Goto (Table.States (271), 62, 98); Add_Goto (Table.States (271), 63, 99); Add_Goto (Table.States (271), 67, 100); Add_Goto (Table.States (271), 72, 101); Table.States (271).Kernel := To_Vector ((0 => (61, 13, 2, False))); Table.States (271).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 53, 0))); Add_Action (Table.States (272), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (272), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (272), 37, 158); Add_Error (Table.States (272)); Add_Goto (Table.States (272), 58, 159); Add_Goto (Table.States (272), 59, 288); Table.States (272).Kernel := To_Vector ((0 => (63, 20, 1, False))); Table.States (272).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 0))); Add_Action (Table.States (273), 14, 161); Add_Error (Table.States (273)); Add_Goto (Table.States (273), 41, 289); Table.States (273).Kernel := To_Vector ((0 => (72, 13, 3, False))); Table.States (273).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 14, 161))); Add_Action (Table.States (274), 29, 290); Add_Error (Table.States (274)); Table.States (274).Kernel := To_Vector ((0 => (67, 37, 2, False))); Table.States (274).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 29, 290))); Add_Action (Table.States (275), 27, 170); Add_Action (Table.States (275), 34, 291); Add_Error (Table.States (275)); Table.States (275).Kernel := To_Vector (((56, 56, 1, True), (67, 56, 1, False))); Table.States (275).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 291))); Add_Action (Table.States (276), (4, 27, 34), (41, 0), 3, aggregate_g_0'Access, null); Table.States (276).Kernel := To_Vector ((0 => (41, 21, 0, False))); Table.States (276).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 41, 3))); Add_Action (Table.States (277), 4, Reduce, (44, 0), 3, null, null); Add_Action (Table.States (277), 14, 292); Add_Action (Table.States (277), 27, Reduce, (44, 0), 3, null, null); Add_Action (Table.States (277), 34, Reduce, (44, 0), 3, null, null); Add_Error (Table.States (277)); Table.States (277).Kernel := To_Vector (((44, 37, 0, False), (44, 37, 3, False))); Table.States (277).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 44, 3))); Add_Action (Table.States (278), 34, 293); Add_Error (Table.States (278)); Table.States (278).Kernel := To_Vector ((0 => (42, 36, 1, False))); Table.States (278).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 293))); Add_Action (Table.States (279), (4, 27, 34), (56, 1), 3, null, null); Table.States (279).Kernel := To_Vector ((0 => (56, 71, 0, True))); Table.States (279).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 3))); Table.States (279).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (280), (4, 27, 31, 33, 34), (59, 1), 3, null, null); Table.States (280).Kernel := To_Vector ((0 => (59, 37, 0, True))); Table.States (280).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 59, 3))); Table.States (280).Minimal_Complete_Actions_Recursive := True; Add_Action (Table.States (281), (6, 8, 12, 16, 18, 23, 37), (62, 0), 9, package_extension_0'Access, package_extension_0_check'Access); Table.States (281).Kernel := To_Vector ((0 => (62, 34, 0, False))); Table.States (281).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 62, 9))); Add_Action (Table.States (282), 8, 294); Add_Action (Table.States (282), 25, 147); Add_Error (Table.States (282)); Add_Goto (Table.States (282), 46, 180); Table.States (282).Kernel := To_Vector (((45, 47, 3, False), (47, 47, 2, True))); Table.States (282).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 8, 294))); Add_Action (Table.States (283), 21, 295); Add_Error (Table.States (283)); Table.States (283).Kernel := To_Vector ((0 => (42, 38, 3, False))); Table.States (283).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 295))); Add_Action (Table.States (284), 21, 296); Add_Error (Table.States (284)); Table.States (284).Kernel := To_Vector (((42, 54, 3, False), (42, 54, 5, False))); Table.States (284).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 296))); Add_Action (Table.States (285), 27, 170); Add_Action (Table.States (285), 34, 297); Add_Error (Table.States (285)); Table.States (285).Kernel := To_Vector (((42, 56, 1, False), (56, 56, 1, True))); Table.States (285).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 297))); Add_Action (Table.States (286), 13, 298); Add_Action (Table.States (286), 31, 121); Add_Error (Table.States (286)); Table.States (286).Kernel := To_Vector (((59, 59, 2, True), (62, 59, 3, False))); Table.States (286).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 13, 298))); Add_Action (Table.States (287), 8, 299); Add_Error (Table.States (287)); Table.States (287).Kernel := To_Vector ((0 => (61, 53, 2, False))); Table.States (287).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 8, 299))); Add_Action (Table.States (288), 31, 186); Add_Action (Table.States (288), 34, 300); Add_Error (Table.States (288)); Table.States (288).Kernel := To_Vector (((59, 59, 2, True), (63, 59, 1, False))); Table.States (288).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 300))); Add_Action (Table.States (289), 34, 301); Add_Error (Table.States (289)); Table.States (289).Kernel := To_Vector ((0 => (72, 41, 1, False))); Table.States (289).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 301))); Add_Action (Table.States (290), 10, 130); Add_Action (Table.States (290), 11, 131); Add_Action (Table.States (290), 14, 132); Add_Action (Table.States (290), 19, 9); Add_Action (Table.States (290), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (290), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (290), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (290), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (290), 37, 133); Add_Action (Table.States (290), 38, 134); Add_Error (Table.States (290)); Add_Goto (Table.States (290), 41, 135); Add_Goto (Table.States (290), 43, 136); Add_Goto (Table.States (290), 44, 137); Add_Goto (Table.States (290), 56, 302); Add_Goto (Table.States (290), 57, 139); Add_Goto (Table.States (290), 58, 140); Add_Goto (Table.States (290), 59, 141); Add_Goto (Table.States (290), 69, 142); Add_Goto (Table.States (290), 71, 143); Table.States (290).Kernel := To_Vector ((0 => (67, 29, 1, False))); Table.States (290).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Add_Action (Table.States (291), (6, 8, 12, 16, 18, 23, 25, 37), (67, 0), 4, simple_declarative_item_0'Access, null); Table.States (291).Kernel := To_Vector ((0 => (67, 34, 0, False))); Table.States (291).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 67, 4))); Add_Action (Table.States (292), 38, 303); Add_Error (Table.States (292)); Table.States (292).Kernel := To_Vector ((0 => (44, 14, 2, False))); Table.States (292).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 38, 303))); Add_Action (Table.States (293), (6, 8, 12, 16, 18, 23, 37), (42, 2), 10, attribute_declaration_2'Access, null); Table.States (293).Kernel := To_Vector ((0 => (42, 34, 0, False))); Table.States (293).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 42, 10))); Add_Action (Table.States (294), 6, 304); Add_Error (Table.States (294)); Table.States (294).Kernel := To_Vector ((0 => (45, 8, 2, False))); Table.States (294).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 6, 304))); Add_Action (Table.States (295), 24, 305); Add_Error (Table.States (295)); Table.States (295).Kernel := To_Vector ((0 => (42, 21, 2, False))); Table.States (295).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 24, 305))); Add_Action (Table.States (296), 24, 306); Add_Error (Table.States (296)); Table.States (296).Kernel := To_Vector (((42, 21, 2, False), (42, 21, 4, False))); Table.States (296).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 24, 306))); Add_Action (Table.States (297), (6, 8, 12, 16, 18, 23, 25, 37), (42, 0), 5, attribute_declaration_0'Access, null); Table.States (297).Kernel := To_Vector ((0 => (42, 34, 0, False))); Table.States (297).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 42, 5))); Add_Action (Table.States (298), 6, 85); Add_Action (Table.States (298), 8, Reduce, (53, 0), 0, null, null); Add_Action (Table.States (298), 12, 86); Add_Action (Table.States (298), 16, 87); Add_Action (Table.States (298), 18, 88); Add_Action (Table.States (298), 23, 89); Add_Action (Table.States (298), 37, 90); Add_Error (Table.States (298)); Add_Goto (Table.States (298), 42, 91); Add_Goto (Table.States (298), 45, 92); Add_Goto (Table.States (298), 51, 93); Add_Goto (Table.States (298), 52, 94); Add_Goto (Table.States (298), 53, 307); Add_Goto (Table.States (298), 60, 96); Add_Goto (Table.States (298), 61, 97); Add_Goto (Table.States (298), 62, 98); Add_Goto (Table.States (298), 63, 99); Add_Goto (Table.States (298), 67, 100); Add_Goto (Table.States (298), 72, 101); Table.States (298).Kernel := To_Vector ((0 => (62, 13, 2, False))); Table.States (298).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 53, 0))); Add_Action (Table.States (299), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (299), 37, 144); Add_Error (Table.States (299)); Add_Goto (Table.States (299), 58, 308); Table.States (299).Kernel := To_Vector ((0 => (61, 8, 1, False))); Table.States (299).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 0))); Add_Action (Table.States (300), (6, 8, 12, 16, 18, 23, 25, 37), (63, 0), 5, package_renaming_0'Access, null); Table.States (300).Kernel := To_Vector ((0 => (63, 34, 0, False))); Table.States (300).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 63, 5))); Add_Action (Table.States (301), (6, 8, 12, 16, 18, 23, 25, 37), (72, 0), 5, typed_string_declaration_0'Access, null); Table.States (301).Kernel := To_Vector ((0 => (72, 34, 0, False))); Table.States (301).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 72, 5))); Add_Action (Table.States (302), 27, 170); Add_Action (Table.States (302), 34, 309); Add_Error (Table.States (302)); Table.States (302).Kernel := To_Vector (((56, 56, 1, True), (67, 56, 1, False))); Table.States (302).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 309))); Add_Action (Table.States (303), 21, 310); Add_Error (Table.States (303)); Table.States (303).Kernel := To_Vector ((0 => (44, 38, 1, False))); Table.States (303).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 21, 310))); Add_Action (Table.States (304), 34, 311); Add_Error (Table.States (304)); Table.States (304).Kernel := To_Vector ((0 => (45, 6, 1, False))); Table.States (304).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 311))); Add_Action (Table.States (305), 10, 130); Add_Action (Table.States (305), 11, 131); Add_Action (Table.States (305), 14, 132); Add_Action (Table.States (305), 19, 9); Add_Action (Table.States (305), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (305), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (305), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (305), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (305), 37, 133); Add_Action (Table.States (305), 38, 134); Add_Error (Table.States (305)); Add_Goto (Table.States (305), 41, 135); Add_Goto (Table.States (305), 43, 136); Add_Goto (Table.States (305), 44, 137); Add_Goto (Table.States (305), 56, 312); Add_Goto (Table.States (305), 57, 139); Add_Goto (Table.States (305), 58, 140); Add_Goto (Table.States (305), 59, 141); Add_Goto (Table.States (305), 69, 142); Add_Goto (Table.States (305), 71, 143); Table.States (305).Kernel := To_Vector ((0 => (42, 24, 1, False))); Table.States (305).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Add_Action (Table.States (306), 4, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (306), 10, 227); Add_Action (Table.States (306), 11, 228); Add_Action (Table.States (306), 14, 229); Add_Action (Table.States (306), 19, 9); Add_Action (Table.States (306), 27, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (306), 31, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (306), 33, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (306), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (306), 37, 230); Add_Action (Table.States (306), 38, 231); Add_Error (Table.States (306)); Add_Goto (Table.States (306), 41, 232); Add_Goto (Table.States (306), 43, 233); Add_Goto (Table.States (306), 44, 234); Add_Goto (Table.States (306), 56, 313); Add_Goto (Table.States (306), 57, 236); Add_Goto (Table.States (306), 58, 237); Add_Goto (Table.States (306), 59, 238); Add_Goto (Table.States (306), 69, 239); Add_Goto (Table.States (306), 71, 240); Table.States (306).Kernel := To_Vector (((42, 24, 1, False), (42, 24, 3, False))); Table.States (306).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 56, 0))); Add_Action (Table.States (307), 8, 314); Add_Error (Table.States (307)); Table.States (307).Kernel := To_Vector ((0 => (62, 53, 2, False))); Table.States (307).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 8, 314))); Add_Action (Table.States (308), 34, 315); Add_Error (Table.States (308)); Table.States (308).Kernel := To_Vector ((0 => (61, 58, 1, False))); Table.States (308).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 315))); Add_Action (Table.States (309), (6, 8, 12, 16, 18, 23, 25, 37), (67, 1), 6, simple_declarative_item_1'Access, null); Table.States (309).Kernel := To_Vector ((0 => (67, 34, 0, False))); Table.States (309).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 67, 6))); Add_Action (Table.States (310), (4, 27, 34), (44, 1), 6, null, null); Table.States (310).Kernel := To_Vector ((0 => (44, 21, 0, False))); Table.States (310).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 44, 6))); Add_Action (Table.States (311), (6, 8, 12, 16, 18, 23, 25, 37), (45, 0), 7, case_statement_0'Access, null); Table.States (311).Kernel := To_Vector ((0 => (45, 34, 0, False))); Table.States (311).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 45, 7))); Add_Action (Table.States (312), 27, 170); Add_Action (Table.States (312), 34, 316); Add_Error (Table.States (312)); Table.States (312).Kernel := To_Vector (((42, 56, 1, False), (56, 56, 1, True))); Table.States (312).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 316))); Add_Action (Table.States (313), 4, 317); Add_Action (Table.States (313), 27, 261); Add_Action (Table.States (313), 34, 318); Add_Error (Table.States (313)); Table.States (313).Kernel := To_Vector (((42, 56, 1, False), (42, 56, 3, False), (56, 56, 1, True))); Table.States (313).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 318))); Add_Action (Table.States (314), 34, Reduce, (58, 0), 0, null, null); Add_Action (Table.States (314), 37, 144); Add_Error (Table.States (314)); Add_Goto (Table.States (314), 58, 319); Table.States (314).Kernel := To_Vector ((0 => (62, 8, 1, False))); Table.States (314).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 58, 0))); Add_Action (Table.States (315), (6, 8, 12, 16, 18, 23, 25, 37), (61, 0), 7, package_spec_0'Access, package_spec_0_check'Access); Table.States (315).Kernel := To_Vector ((0 => (61, 34, 0, False))); Table.States (315).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 61, 7))); Add_Action (Table.States (316), (6, 8, 12, 16, 18, 23, 25, 37), (42, 3), 8, attribute_declaration_3'Access, null); Table.States (316).Kernel := To_Vector ((0 => (42, 34, 0, False))); Table.States (316).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 42, 8))); Add_Action (Table.States (317), 36, 320); Add_Error (Table.States (317)); Table.States (317).Kernel := To_Vector ((0 => (42, 4, 2, False))); Table.States (317).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 36, 320))); Add_Action (Table.States (318), (6, 8, 12, 16, 18, 23, 25, 37), (42, 1), 8, attribute_declaration_1'Access, null); Table.States (318).Kernel := To_Vector ((0 => (42, 34, 0, False))); Table.States (318).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 42, 8))); Add_Action (Table.States (319), 34, 321); Add_Error (Table.States (319)); Table.States (319).Kernel := To_Vector ((0 => (62, 58, 1, False))); Table.States (319).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 321))); Add_Action (Table.States (320), 34, 322); Add_Error (Table.States (320)); Table.States (320).Kernel := To_Vector ((0 => (42, 36, 1, False))); Table.States (320).Minimal_Complete_Actions := To_Vector ((0 => (Shift, 34, 322))); Add_Action (Table.States (321), (6, 8, 12, 16, 18, 23, 25, 37), (62, 0), 9, package_extension_0'Access, package_extension_0_check'Access); Table.States (321).Kernel := To_Vector ((0 => (62, 34, 0, False))); Table.States (321).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 62, 9))); Add_Action (Table.States (322), (6, 8, 12, 16, 18, 23, 25, 37), (42, 2), 10, attribute_declaration_2'Access, null); Table.States (322).Kernel := To_Vector ((0 => (42, 34, 0, False))); Table.States (322).Minimal_Complete_Actions := To_Vector ((0 => (Reduce, 42, 10))); end Subr_3; begin Subr_1; Subr_2; Subr_3; end; WisiToken.Parse.LR.Parser.New_Parser (Parser, Trace, Lexer.New_Lexer (Trace.Descriptor), Table, Language_Fixes, Language_Matching_Begin_Tokens, Language_String_ID_Set, User_Data, Max_Parallel => 15, Terminate_Same_State => True); end Create_Parser; end Gpr_Process_LR1_Main;
-- This sample program receives MIDI events from a keyboard and from -- rotary encoders and outputs audio, like a synthesizer. -- Call it like this from Linux: -- -- amidi -p "hw:1,0,0" -r >(./obj/ada_synth | \ -- aplay -f S16_LE -c1 -r44100 --buffer-size=4096) -- -- The BASH syntax ">(program)" creates a temporary FIFO file, because amidi -- needs a file where it writes the received MIDI events. In case of problems, -- you can also create a named FIFO with "mkfifo", then start amidi in the -- background writing to this file, and then the ada_synth program like this: -- -- cat midi | ./ada_synth | aplay -f S16_LE -c1 -r44100 --buffer-size=4096) -- -- where "midi" is the named FIFO file. If it keeps playing a tone when you -- stop the program with ctrl-c, try this command: -- -- killall amidi aplay -- -- You can see the list of available MIDI devices with "amidi -l". -- For testing it is useful to use the AMIDI "--dump" option. -- For lower latency, you might need to change the Linux pipe size: -- -- sudo sysctl fs.pipe-max-size=4096 with GNAT.OS_Lib; with Interfaces; use Interfaces; with MIDI_Synthesizer; use MIDI_Synthesizer; procedure Ada_Synth is Data : Unsigned_8; Ignore : Integer; Main_Synthesizer : constant access Synthesizer'Class := Create_Synthesizer; task Main_Task is entry Data_Received (Data : Unsigned_8); end Main_Task; task body Main_Task is Sample : Float; Int_Smp : Short_Integer := 0; Ignore : Integer; begin loop select accept Data_Received (Data : Unsigned_8) do Main_Synthesizer.Parse_MIDI_Byte (Data); end Data_Received; else Sample := Main_Synthesizer.Next_Sample; Int_Smp := Short_Integer (Sample * 32767.0); Ignore := GNAT.OS_Lib.Write (GNAT.OS_Lib.Standout, Int_Smp'Address, Int_Smp'Size / 8); end select; end loop; end Main_Task; begin loop Ignore := GNAT.OS_Lib.Read (GNAT.OS_Lib.Standin, Data'Address, Data'Size / 8); Main_Task.Data_Received (Data); end loop; end Ada_Synth;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ A G G R -- -- -- -- B o d y -- -- -- -- $Revision$ -- -- -- Copyright (C) 1992-2001 Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Atree; use Atree; with Checks; use Checks; with Einfo; use Einfo; with Elists; use Elists; with Errout; use Errout; with Exp_Util; use Exp_Util; with Freeze; use Freeze; with Itypes; use Itypes; with Namet; use Namet; with Nmake; use Nmake; with Nlists; use Nlists; with Opt; use Opt; with Sem; use Sem; with Sem_Cat; use Sem_Cat; with Sem_Ch8; use Sem_Ch8; with Sem_Ch13; use Sem_Ch13; with Sem_Eval; use Sem_Eval; with Sem_Res; use Sem_Res; with Sem_Util; use Sem_Util; with Sem_Type; use Sem_Type; with Sinfo; use Sinfo; with Snames; use Snames; with Stringt; use Stringt; with Stand; use Stand; with Tbuild; use Tbuild; with Uintp; use Uintp; with GNAT.Spelling_Checker; use GNAT.Spelling_Checker; package body Sem_Aggr is type Case_Bounds is record Choice_Lo : Node_Id; Choice_Hi : Node_Id; Choice_Node : Node_Id; end record; type Case_Table_Type is array (Nat range <>) of Case_Bounds; -- Table type used by Check_Case_Choices procedure ----------------------- -- Local Subprograms -- ----------------------- procedure Sort_Case_Table (Case_Table : in out Case_Table_Type); -- Sort the Case Table using the Lower Bound of each Choice as the key. -- A simple insertion sort is used since the number of choices in a case -- statement of variant part will usually be small and probably in near -- sorted order. ------------------------------------------------------ -- Subprograms used for RECORD AGGREGATE Processing -- ------------------------------------------------------ procedure Resolve_Record_Aggregate (N : Node_Id; Typ : Entity_Id); -- This procedure performs all the semantic checks required for record -- aggregates. Note that for aggregates analysis and resolution go -- hand in hand. Aggregate analysis has been delayed up to here and -- it is done while resolving the aggregate. -- -- N is the N_Aggregate node. -- Typ is the record type for the aggregate resolution -- -- While performing the semantic checks, this procedure -- builds a new Component_Association_List where each record field -- appears alone in a Component_Choice_List along with its corresponding -- expression. The record fields in the Component_Association_List -- appear in the same order in which they appear in the record type Typ. -- -- Once this new Component_Association_List is built and all the -- semantic checks performed, the original aggregate subtree is replaced -- with the new named record aggregate just built. Note that the subtree -- substitution is performed with Rewrite so as to be -- able to retrieve the original aggregate. -- -- The aggregate subtree manipulation performed by Resolve_Record_Aggregate -- yields the aggregate format expected by Gigi. Typically, this kind of -- tree manipulations are done in the expander. However, because the -- semantic checks that need to be performed on record aggregates really -- go hand in hand with the record aggreagate normalization, the aggregate -- subtree transformation is performed during resolution rather than -- expansion. Had we decided otherwise we would have had to duplicate -- most of the code in the expansion procedure Expand_Record_Aggregate. -- Note, however, that all the expansion concerning aggegates for tagged -- records is done in Expand_Record_Aggregate. -- -- The algorithm of Resolve_Record_Aggregate proceeds as follows: -- -- 1. Make sure that the record type against which the record aggregate -- has to be resolved is not abstract. Furthermore if the type is -- a null aggregate make sure the input aggregate N is also null. -- -- 2. Verify that the structure of the aggregate is that of a record -- aggregate. Specifically, look for component associations and ensure -- that each choice list only has identifiers or the N_Others_Choice -- node. Also make sure that if present, the N_Others_Choice occurs -- last and by itself. -- -- 3. If Typ contains discriminants, the values for each discriminant -- is looked for. If the record type Typ has variants, we check -- that the expressions corresponding to each discriminant ruling -- the (possibly nested) variant parts of Typ, are static. This -- allows us to determine the variant parts to which the rest of -- the aggregate must conform. The names of discriminants with their -- values are saved in a new association list, New_Assoc_List which -- is later augmented with the names and values of the remaining -- components in the record type. -- -- During this phase we also make sure that every discriminant is -- assigned exactly one value. Note that when several values -- for a given discriminant are found, semantic processing continues -- looking for further errors. In this case it's the first -- discriminant value found which we will be recorded. -- -- IMPORTANT NOTE: For derived tagged types this procedure expects -- First_Discriminant and Next_Discriminant to give the correct list -- of discriminants, in the correct order. -- -- 4. After all the discriminant values have been gathered, we can -- set the Etype of the record aggregate. If Typ contains no -- discriminants this is straightforward: the Etype of N is just -- Typ, otherwise a new implicit constrained subtype of Typ is -- built to be the Etype of N. -- -- 5. Gather the remaining record components according to the discriminant -- values. This involves recursively traversing the record type -- structure to see what variants are selected by the given discriminant -- values. This processing is a little more convoluted if Typ is a -- derived tagged types since we need to retrieve the record structure -- of all the ancestors of Typ. -- -- 6. After gathering the record components we look for their values -- in the record aggregate and emit appropriate error messages -- should we not find such values or should they be duplicated. -- -- 7. We then make sure no illegal component names appear in the -- record aggegate and make sure that the type of the record -- components appearing in a same choice list is the same. -- Finally we ensure that the others choice, if present, is -- used to provide the value of at least a record component. -- -- 8. The original aggregate node is replaced with the new named -- aggregate built in steps 3 through 6, as explained earlier. -- -- Given the complexity of record aggregate resolution, the primary -- goal of this routine is clarity and simplicity rather than execution -- and storage efficiency. If there are only positional components in the -- aggregate the running time is linear. If there are associations -- the running time is still linear as long as the order of the -- associations is not too far off the order of the components in the -- record type. If this is not the case the running time is at worst -- quadratic in the size of the association list. procedure Check_Misspelled_Component (Elements : Elist_Id; Component : Node_Id); -- Give possible misspelling diagnostic if Component is likely to be -- a misspelling of one of the components of the Assoc_List. -- This is called by Resolv_Aggr_Expr after producing -- an invalid component error message. procedure Check_Static_Discriminated_Subtype (T : Entity_Id; V : Node_Id); -- An optimization: determine whether a discriminated subtype has a -- static constraint, and contains array components whose length is also -- static, either because they are constrained by the discriminant, or -- because the original component bounds are static. ----------------------------------------------------- -- Subprograms used for ARRAY AGGREGATE Processing -- ----------------------------------------------------- function Resolve_Array_Aggregate (N : Node_Id; Index : Node_Id; Index_Constr : Node_Id; Component_Typ : Entity_Id; Others_Allowed : Boolean) return Boolean; -- This procedure performs the semantic checks for an array aggregate. -- True is returned if the aggregate resolution succeeds. -- The procedure works by recursively checking each nested aggregate. -- Specifically, after checking a sub-aggreate nested at the i-th level -- we recursively check all the subaggregates at the i+1-st level (if any). -- Note that for aggregates analysis and resolution go hand in hand. -- Aggregate analysis has been delayed up to here and it is done while -- resolving the aggregate. -- -- N is the current N_Aggregate node to be checked. -- -- Index is the index node corresponding to the array sub-aggregate that -- we are currently checking (RM 4.3.3 (8)). Its Etype is the -- corresponding index type (or subtype). -- -- Index_Constr is the node giving the applicable index constraint if -- any (RM 4.3.3 (10)). It "is a constraint provided by certain -- contexts [...] that can be used to determine the bounds of the array -- value specified by the aggregate". If Others_Allowed below is False -- there is no applicable index constraint and this node is set to Index. -- -- Component_Typ is the array component type. -- -- Others_Allowed indicates whether an others choice is allowed -- in the context where the top-level aggregate appeared. -- -- The algorithm of Resolve_Array_Aggregate proceeds as follows: -- -- 1. Make sure that the others choice, if present, is by itself and -- appears last in the sub-aggregate. Check that we do not have -- positional and named components in the array sub-aggregate (unless -- the named association is an others choice). Finally if an others -- choice is present, make sure it is allowed in the aggregate contex. -- -- 2. If the array sub-aggregate contains discrete_choices: -- -- (A) Verify their validity. Specifically verify that: -- -- (a) If a null range is present it must be the only possible -- choice in the array aggregate. -- -- (b) Ditto for a non static range. -- -- (c) Ditto for a non static expression. -- -- In addition this step analyzes and resolves each discrete_choice, -- making sure that its type is the type of the corresponding Index. -- If we are not at the lowest array aggregate level (in the case of -- multi-dimensional aggregates) then invoke Resolve_Array_Aggregate -- recursively on each component expression. Otherwise, resolve the -- bottom level component expressions against the expected component -- type ONLY IF the component corresponds to a single discrete choice -- which is not an others choice (to see why read the DELAYED -- COMPONENT RESOLUTION below). -- -- (B) Determine the bounds of the sub-aggregate and lowest and -- highest choice values. -- -- 3. For positional aggregates: -- -- (A) Loop over the component expressions either recursively invoking -- Resolve_Array_Aggregate on each of these for multi-dimensional -- array aggregates or resolving the bottom level component -- expressions against the expected component type. -- -- (B) Determine the bounds of the positional sub-aggregates. -- -- 4. Try to determine statically whether the evaluation of the array -- sub-aggregate raises Constraint_Error. If yes emit proper -- warnings. The precise checks are the following: -- -- (A) Check that the index range defined by aggregate bounds is -- compatible with corresponding index subtype. -- We also check against the base type. In fact it could be that -- Low/High bounds of the base type are static whereas those of -- the index subtype are not. Thus if we can statically catch -- a problem with respect to the base type we are guaranteed -- that the same problem will arise with the index subtype -- -- (B) If we are dealing with a named aggregate containing an others -- choice and at least one discrete choice then make sure the range -- specified by the discrete choices does not overflow the -- aggregate bounds. We also check against the index type and base -- type bounds for the same reasons given in (A). -- -- (C) If we are dealing with a positional aggregate with an others -- choice make sure the number of positional elements specified -- does not overflow the aggregate bounds. We also check against -- the index type and base type bounds as mentioned in (A). -- -- Finally construct an N_Range node giving the sub-aggregate bounds. -- Set the Aggregate_Bounds field of the sub-aggregate to be this -- N_Range. The routine Array_Aggr_Subtype below uses such N_Ranges -- to build the appropriate aggregate subtype. Aggregate_Bounds -- information is needed during expansion. -- -- DELAYED COMPONENT RESOLUTION: The resolution of bottom level component -- expressions in an array aggregate may call Duplicate_Subexpr or some -- other routine that inserts code just outside the outermost aggregate. -- If the array aggregate contains discrete choices or an others choice, -- this may be wrong. Consider for instance the following example. -- -- type Rec is record -- V : Integer := 0; -- end record; -- -- type Acc_Rec is access Rec; -- Arr : array (1..3) of Acc_Rec := (1 .. 3 => new Rec); -- -- Then the transformation of "new Rec" that occurs during resolution -- entails the following code modifications -- -- P7b : constant Acc_Rec := new Rec; -- Rec_init_proc (P7b.all); -- Arr : array (1..3) of Acc_Rec := (1 .. 3 => P7b); -- -- This code transformation is clearly wrong, since we need to call -- "new Rec" for each of the 3 array elements. To avoid this problem we -- delay resolution of the components of non positional array aggregates -- to the expansion phase. As an optimization, if the discrete choice -- specifies a single value we do not delay resolution. function Array_Aggr_Subtype (N : Node_Id; Typ : Node_Id) return Entity_Id; -- This routine returns the type or subtype of an array aggregate. -- -- N is the array aggregate node whose type we return. -- -- Typ is the context type in which N occurs. -- -- This routine creates an implicit array subtype whose bouds are -- those defined by the aggregate. When this routine is invoked -- Resolve_Array_Aggregate has already processed aggregate N. Thus the -- Aggregate_Bounds of each sub-aggregate, is an N_Range node giving the -- sub-aggregate bounds. When building the aggegate itype, this function -- traverses the array aggregate N collecting such Aggregate_Bounds and -- constructs the proper array aggregate itype. -- -- Note that in the case of multidimensional aggregates each inner -- sub-aggregate corresponding to a given array dimension, may provide a -- different bounds. If it is possible to determine statically that -- some sub-aggregates corresponding to the same index do not have the -- same bounds, then a warning is emitted. If such check is not possible -- statically (because some sub-aggregate bounds are dynamic expressions) -- then this job is left to the expander. In all cases the particular -- bounds that this function will chose for a given dimension is the first -- N_Range node for a sub-aggregate corresponding to that dimension. -- -- Note that the Raises_Constraint_Error flag of an array aggregate -- whose evaluation is determined to raise CE by Resolve_Array_Aggregate, -- is set in Resolve_Array_Aggregate but the aggregate is not -- immediately replaced with a raise CE. In fact, Array_Aggr_Subtype must -- first construct the proper itype for the aggregate (Gigi needs -- this). After constructing the proper itype we will eventually replace -- the top-level aggregate with a raise CE (done in Resolve_Aggregate). -- Of course in cases such as: -- -- type Arr is array (integer range <>) of Integer; -- A : Arr := (positive range -1 .. 2 => 0); -- -- The bounds of the aggregate itype are cooked up to look reasonable -- (in this particular case the bounds will be 1 .. 2). procedure Aggregate_Constraint_Checks (Exp : Node_Id; Check_Typ : Entity_Id); -- Checks expression Exp against subtype Check_Typ. If Exp is an -- aggregate and Check_Typ a constrained record type with discriminants, -- we generate the appropriate discriminant checks. If Exp is an array -- aggregate then emit the appropriate length checks. If Exp is a scalar -- type, or a string literal, Exp is changed into Check_Typ'(Exp) to -- ensure that range checks are performed at run time. procedure Make_String_Into_Aggregate (N : Node_Id); -- A string literal can appear in a context in which a one dimensional -- array of characters is expected. This procedure simply rewrites the -- string as an aggregate, prior to resolution. --------------------------------- -- Aggregate_Constraint_Checks -- --------------------------------- procedure Aggregate_Constraint_Checks (Exp : Node_Id; Check_Typ : Entity_Id) is Exp_Typ : constant Entity_Id := Etype (Exp); begin if Raises_Constraint_Error (Exp) then return; end if; -- This is really expansion activity, so make sure that expansion -- is on and is allowed. if not Expander_Active or else In_Default_Expression then return; end if; -- First check if we have to insert discriminant checks if Has_Discriminants (Exp_Typ) then Apply_Discriminant_Check (Exp, Check_Typ); -- Next emit length checks for array aggregates elsif Is_Array_Type (Exp_Typ) then Apply_Length_Check (Exp, Check_Typ); -- Finally emit scalar and string checks. If we are dealing with a -- scalar literal we need to check by hand because the Etype of -- literals is not necessarily correct. elsif Is_Scalar_Type (Exp_Typ) and then Compile_Time_Known_Value (Exp) then if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then Apply_Compile_Time_Constraint_Error (Exp, "value not in range of}?", Ent => Base_Type (Check_Typ), Typ => Base_Type (Check_Typ)); elsif Is_Out_Of_Range (Exp, Check_Typ) then Apply_Compile_Time_Constraint_Error (Exp, "value not in range of}?", Ent => Check_Typ, Typ => Check_Typ); elsif not Range_Checks_Suppressed (Check_Typ) then Apply_Scalar_Range_Check (Exp, Check_Typ); end if; elsif (Is_Scalar_Type (Exp_Typ) or else Nkind (Exp) = N_String_Literal) and then Exp_Typ /= Check_Typ then if Is_Entity_Name (Exp) and then Ekind (Entity (Exp)) = E_Constant then -- If expression is a constant, it is worthwhile checking whether -- it is a bound of the type. if (Is_Entity_Name (Type_Low_Bound (Check_Typ)) and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ))) or else (Is_Entity_Name (Type_High_Bound (Check_Typ)) and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ))) then return; else Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp))); Analyze_And_Resolve (Exp, Check_Typ); end if; else Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp))); Analyze_And_Resolve (Exp, Check_Typ); end if; end if; end Aggregate_Constraint_Checks; ------------------------ -- Array_Aggr_Subtype -- ------------------------ function Array_Aggr_Subtype (N : Node_Id; Typ : Entity_Id) return Entity_Id is Aggr_Dimension : constant Pos := Number_Dimensions (Typ); -- Number of aggregate index dimensions. Aggr_Range : array (1 .. Aggr_Dimension) of Node_Id := (others => Empty); -- Constrained N_Range of each index dimension in our aggregate itype. Aggr_Low : array (1 .. Aggr_Dimension) of Node_Id := (others => Empty); Aggr_High : array (1 .. Aggr_Dimension) of Node_Id := (others => Empty); -- Low and High bounds for each index dimension in our aggregate itype. Is_Fully_Positional : Boolean := True; procedure Collect_Aggr_Bounds (N : Node_Id; Dim : Pos); -- N is an array (sub-)aggregate. Dim is the dimension corresponding to -- (sub-)aggregate N. This procedure collects the constrained N_Range -- nodes corresponding to each index dimension of our aggregate itype. -- These N_Range nodes are collected in Aggr_Range above. -- Likewise collect in Aggr_Low & Aggr_High above the low and high -- bounds of each index dimension. If, when collecting, two bounds -- corresponding to the same dimension are static and found to differ, -- then emit a warning, and mark N as raising Constraint_Error. ------------------------- -- Collect_Aggr_Bounds -- ------------------------- procedure Collect_Aggr_Bounds (N : Node_Id; Dim : Pos) is This_Range : constant Node_Id := Aggregate_Bounds (N); -- The aggregate range node of this specific sub-aggregate. This_Low : constant Node_Id := Low_Bound (Aggregate_Bounds (N)); This_High : constant Node_Id := High_Bound (Aggregate_Bounds (N)); -- The aggregate bounds of this specific sub-aggregate. Assoc : Node_Id; Expr : Node_Id; begin -- Collect the first N_Range for a given dimension that you find. -- For a given dimension they must be all equal anyway. if No (Aggr_Range (Dim)) then Aggr_Low (Dim) := This_Low; Aggr_High (Dim) := This_High; Aggr_Range (Dim) := This_Range; else if Compile_Time_Known_Value (This_Low) then if not Compile_Time_Known_Value (Aggr_Low (Dim)) then Aggr_Low (Dim) := This_Low; elsif Expr_Value (This_Low) /= Expr_Value (Aggr_Low (Dim)) then Set_Raises_Constraint_Error (N); Error_Msg_N ("Sub-aggregate low bound mismatch?", N); Error_Msg_N ("Constraint_Error will be raised at run-time?", N); end if; end if; if Compile_Time_Known_Value (This_High) then if not Compile_Time_Known_Value (Aggr_High (Dim)) then Aggr_High (Dim) := This_High; elsif Expr_Value (This_High) /= Expr_Value (Aggr_High (Dim)) then Set_Raises_Constraint_Error (N); Error_Msg_N ("Sub-aggregate high bound mismatch?", N); Error_Msg_N ("Constraint_Error will be raised at run-time?", N); end if; end if; end if; if Dim < Aggr_Dimension then -- Process positional components if Present (Expressions (N)) then Expr := First (Expressions (N)); while Present (Expr) loop Collect_Aggr_Bounds (Expr, Dim + 1); Next (Expr); end loop; end if; -- Process component associations if Present (Component_Associations (N)) then Is_Fully_Positional := False; Assoc := First (Component_Associations (N)); while Present (Assoc) loop Expr := Expression (Assoc); Collect_Aggr_Bounds (Expr, Dim + 1); Next (Assoc); end loop; end if; end if; end Collect_Aggr_Bounds; -- Array_Aggr_Subtype variables Itype : Entity_Id; -- the final itype of the overall aggregate Index_Constraints : List_Id := New_List; -- The list of index constraints of the aggregate itype. -- Start of processing for Array_Aggr_Subtype begin -- Make sure that the list of index constraints is properly attached -- to the tree, and then collect the aggregate bounds. Set_Parent (Index_Constraints, N); Collect_Aggr_Bounds (N, 1); -- Build the list of constrained indices of our aggregate itype. for J in 1 .. Aggr_Dimension loop Create_Index : declare Index_Base : Entity_Id := Base_Type (Etype (Aggr_Range (J))); Index_Typ : Entity_Id; begin -- Construct the Index subtype Index_Typ := Create_Itype (Subtype_Kind (Ekind (Index_Base)), N); Set_Etype (Index_Typ, Index_Base); if Is_Character_Type (Index_Base) then Set_Is_Character_Type (Index_Typ); end if; Set_Size_Info (Index_Typ, (Index_Base)); Set_RM_Size (Index_Typ, RM_Size (Index_Base)); Set_First_Rep_Item (Index_Typ, First_Rep_Item (Index_Base)); Set_Scalar_Range (Index_Typ, Aggr_Range (J)); if Is_Discrete_Or_Fixed_Point_Type (Index_Typ) then Set_RM_Size (Index_Typ, UI_From_Int (Minimum_Size (Index_Typ))); end if; Set_Etype (Aggr_Range (J), Index_Typ); Append (Aggr_Range (J), To => Index_Constraints); end Create_Index; end loop; -- Now build the Itype Itype := Create_Itype (E_Array_Subtype, N); Set_First_Rep_Item (Itype, First_Rep_Item (Typ)); Set_Component_Type (Itype, Component_Type (Typ)); Set_Convention (Itype, Convention (Typ)); Set_Depends_On_Private (Itype, Has_Private_Component (Typ)); Set_Etype (Itype, Base_Type (Typ)); Set_Has_Alignment_Clause (Itype, Has_Alignment_Clause (Typ)); Set_Is_Aliased (Itype, Is_Aliased (Typ)); Set_Suppress_Index_Checks (Itype, Suppress_Index_Checks (Typ)); Set_Suppress_Length_Checks (Itype, Suppress_Length_Checks (Typ)); Set_Depends_On_Private (Itype, Depends_On_Private (Typ)); Set_First_Index (Itype, First (Index_Constraints)); Set_Is_Constrained (Itype, True); Set_Is_Internal (Itype, True); Init_Size_Align (Itype); -- A simple optimization: purely positional aggregates of static -- components should be passed to gigi unexpanded whenever possible, -- and regardless of the staticness of the bounds themselves. Subse- -- quent checks in exp_aggr verify that type is not packed, etc. Set_Size_Known_At_Compile_Time (Itype, Is_Fully_Positional and then Comes_From_Source (N) and then Size_Known_At_Compile_Time (Component_Type (Typ))); -- We always need a freeze node for a packed array subtype, so that -- we can build the Packed_Array_Type corresponding to the subtype. -- If expansion is disabled, the packed array subtype is not built, -- and we must not generate a freeze node for the type, or else it -- will appear incomplete to gigi. if Is_Packed (Itype) and then not In_Default_Expression and then Expander_Active then Freeze_Itype (Itype, N); end if; return Itype; end Array_Aggr_Subtype; -------------------------------- -- Check_Misspelled_Component -- -------------------------------- procedure Check_Misspelled_Component (Elements : Elist_Id; Component : Node_Id) is Max_Suggestions : constant := 2; Nr_Of_Suggestions : Natural := 0; Suggestion_1 : Entity_Id := Empty; Suggestion_2 : Entity_Id := Empty; Component_Elmt : Elmt_Id; begin -- All the components of List are matched against Component and -- a count is maintained of possible misspellings. When at the -- end of the analysis there are one or two (not more!) possible -- misspellings, these misspellings will be suggested as -- possible correction. Get_Name_String (Chars (Component)); declare S : constant String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); begin Component_Elmt := First_Elmt (Elements); while Nr_Of_Suggestions <= Max_Suggestions and then Present (Component_Elmt) loop Get_Name_String (Chars (Node (Component_Elmt))); if Is_Bad_Spelling_Of (Name_Buffer (1 .. Name_Len), S) then Nr_Of_Suggestions := Nr_Of_Suggestions + 1; case Nr_Of_Suggestions is when 1 => Suggestion_1 := Node (Component_Elmt); when 2 => Suggestion_2 := Node (Component_Elmt); when others => exit; end case; end if; Next_Elmt (Component_Elmt); end loop; -- Report at most two suggestions if Nr_Of_Suggestions = 1 then Error_Msg_NE ("\possible misspelling of&", Component, Suggestion_1); elsif Nr_Of_Suggestions = 2 then Error_Msg_Node_2 := Suggestion_2; Error_Msg_NE ("\possible misspelling of& or&", Component, Suggestion_1); end if; end; end Check_Misspelled_Component; ---------------------------------------- -- Check_Static_Discriminated_Subtype -- ---------------------------------------- procedure Check_Static_Discriminated_Subtype (T : Entity_Id; V : Node_Id) is Disc : constant Entity_Id := First_Discriminant (T); Comp : Entity_Id; Ind : Entity_Id; begin if Has_Record_Rep_Clause (Base_Type (T)) then return; elsif Present (Next_Discriminant (Disc)) then return; elsif Nkind (V) /= N_Integer_Literal then return; end if; Comp := First_Component (T); while Present (Comp) loop if Is_Scalar_Type (Etype (Comp)) then null; elsif Is_Private_Type (Etype (Comp)) and then Present (Full_View (Etype (Comp))) and then Is_Scalar_Type (Full_View (Etype (Comp))) then null; elsif Is_Array_Type (Etype (Comp)) then if Is_Bit_Packed_Array (Etype (Comp)) then return; end if; Ind := First_Index (Etype (Comp)); while Present (Ind) loop if Nkind (Ind) /= N_Range or else Nkind (Low_Bound (Ind)) /= N_Integer_Literal or else Nkind (High_Bound (Ind)) /= N_Integer_Literal then return; end if; Next_Index (Ind); end loop; else return; end if; Next_Component (Comp); end loop; -- On exit, all components have statically known sizes. Set_Size_Known_At_Compile_Time (T); end Check_Static_Discriminated_Subtype; -------------------------------- -- Make_String_Into_Aggregate -- -------------------------------- procedure Make_String_Into_Aggregate (N : Node_Id) is C : Char_Code; C_Node : Node_Id; Exprs : List_Id := New_List; Loc : constant Source_Ptr := Sloc (N); New_N : Node_Id; P : Source_Ptr := Loc + 1; Str : constant String_Id := Strval (N); Strlen : constant Nat := String_Length (Str); begin for J in 1 .. Strlen loop C := Get_String_Char (Str, J); Set_Character_Literal_Name (C); C_Node := Make_Character_Literal (P, Name_Find, C); Set_Etype (C_Node, Any_Character); Set_Analyzed (C_Node); Append_To (Exprs, C_Node); P := P + 1; -- something special for wide strings ? end loop; New_N := Make_Aggregate (Loc, Expressions => Exprs); Set_Analyzed (New_N); Set_Etype (New_N, Any_Composite); Rewrite (N, New_N); end Make_String_Into_Aggregate; ----------------------- -- Resolve_Aggregate -- ----------------------- procedure Resolve_Aggregate (N : Node_Id; Typ : Entity_Id) is Pkind : constant Node_Kind := Nkind (Parent (N)); Aggr_Subtyp : Entity_Id; -- The actual aggregate subtype. This is not necessarily the same as Typ -- which is the subtype of the context in which the aggregate was found. begin if Is_Limited_Type (Typ) then Error_Msg_N ("aggregate type cannot be limited", N); elsif Is_Limited_Composite (Typ) then Error_Msg_N ("aggregate type cannot have limited component", N); elsif Is_Class_Wide_Type (Typ) then Error_Msg_N ("type of aggregate cannot be class-wide", N); elsif Typ = Any_String or else Typ = Any_Composite then Error_Msg_N ("no unique type for aggregate", N); Set_Etype (N, Any_Composite); elsif Is_Array_Type (Typ) and then Null_Record_Present (N) then Error_Msg_N ("null record forbidden in array aggregate", N); elsif Is_Record_Type (Typ) then Resolve_Record_Aggregate (N, Typ); elsif Is_Array_Type (Typ) then -- First a special test, for the case of a positional aggregate -- of characters which can be replaced by a string literal. -- Do not perform this transformation if this was a string literal -- to start with, whose components needed constraint checks, or if -- the component type is non-static, because it will require those -- checks and be transformed back into an aggregate. if Number_Dimensions (Typ) = 1 and then (Root_Type (Component_Type (Typ)) = Standard_Character or else Root_Type (Component_Type (Typ)) = Standard_Wide_Character) and then No (Component_Associations (N)) and then not Is_Limited_Composite (Typ) and then not Is_Private_Composite (Typ) and then not Is_Bit_Packed_Array (Typ) and then Nkind (Original_Node (Parent (N))) /= N_String_Literal and then Is_Static_Subtype (Component_Type (Typ)) then declare Expr : Node_Id; begin Expr := First (Expressions (N)); while Present (Expr) loop exit when Nkind (Expr) /= N_Character_Literal; Next (Expr); end loop; if No (Expr) then Start_String; Expr := First (Expressions (N)); while Present (Expr) loop Store_String_Char (Char_Literal_Value (Expr)); Next (Expr); end loop; Rewrite (N, Make_String_Literal (Sloc (N), End_String)); Analyze_And_Resolve (N, Typ); return; end if; end; end if; -- Here if we have a real aggregate to deal with Array_Aggregate : declare Aggr_Resolved : Boolean; Aggr_Typ : Entity_Id := Etype (Typ); -- This is the unconstrained array type, which is the type -- against which the aggregate is to be resoved. Typ itself -- is the array type of the context which may not be the same -- subtype as the subtype for the final aggregate. begin -- In the following we determine whether an others choice is -- allowed inside the array aggregate. The test checks the context -- in which the array aggregate occurs. If the context does not -- permit it, or the aggregate type is unconstrained, an others -- choice is not allowed. -- -- Note that there is no node for Explicit_Actual_Parameter. -- To test for this context we therefore have to test for node -- N_Parameter_Association which itself appears only if there is a -- formal parameter. Consequently we also need to test for -- N_Procedure_Call_Statement or N_Function_Call. if Is_Constrained (Typ) and then (Pkind = N_Assignment_Statement or else Pkind = N_Parameter_Association or else Pkind = N_Function_Call or else Pkind = N_Procedure_Call_Statement or else Pkind = N_Generic_Association or else Pkind = N_Formal_Object_Declaration or else Pkind = N_Return_Statement or else Pkind = N_Object_Declaration or else Pkind = N_Component_Declaration or else Pkind = N_Parameter_Specification or else Pkind = N_Qualified_Expression or else Pkind = N_Aggregate or else Pkind = N_Extension_Aggregate or else Pkind = N_Component_Association) then Aggr_Resolved := Resolve_Array_Aggregate (N, Index => First_Index (Aggr_Typ), Index_Constr => First_Index (Typ), Component_Typ => Component_Type (Typ), Others_Allowed => True); else Aggr_Resolved := Resolve_Array_Aggregate (N, Index => First_Index (Aggr_Typ), Index_Constr => First_Index (Aggr_Typ), Component_Typ => Component_Type (Typ), Others_Allowed => False); end if; if not Aggr_Resolved then Aggr_Subtyp := Any_Composite; else Aggr_Subtyp := Array_Aggr_Subtype (N, Typ); end if; Set_Etype (N, Aggr_Subtyp); end Array_Aggregate; else Error_Msg_N ("illegal context for aggregate", N); end if; -- If we can determine statically that the evaluation of the -- aggregate raises Constraint_Error, then replace the -- aggregate with an N_Raise_Constraint_Error node, but set the -- Etype to the right aggregate subtype. Gigi needs this. if Raises_Constraint_Error (N) then Aggr_Subtyp := Etype (N); Rewrite (N, Make_Raise_Constraint_Error (Sloc (N))); Set_Raises_Constraint_Error (N); Set_Etype (N, Aggr_Subtyp); Set_Analyzed (N); end if; end Resolve_Aggregate; ----------------------------- -- Resolve_Array_Aggregate -- ----------------------------- function Resolve_Array_Aggregate (N : Node_Id; Index : Node_Id; Index_Constr : Node_Id; Component_Typ : Entity_Id; Others_Allowed : Boolean) return Boolean is Loc : constant Source_Ptr := Sloc (N); Failure : constant Boolean := False; Success : constant Boolean := True; Index_Typ : constant Entity_Id := Etype (Index); Index_Typ_Low : constant Node_Id := Type_Low_Bound (Index_Typ); Index_Typ_High : constant Node_Id := Type_High_Bound (Index_Typ); -- The type of the index corresponding to the array sub-aggregate -- along with its low and upper bounds Index_Base : constant Entity_Id := Base_Type (Index_Typ); Index_Base_Low : constant Node_Id := Type_Low_Bound (Index_Base); Index_Base_High : constant Node_Id := Type_High_Bound (Index_Base); -- ditto for the base type function Add (Val : Uint; To : Node_Id) return Node_Id; -- Creates a new expression node where Val is added to expression To. -- Tries to constant fold whenever possible. To must be an already -- analyzed expression. procedure Check_Bound (BH : Node_Id; AH : in out Node_Id); -- Checks that AH (the upper bound of an array aggregate) is <= BH -- (the upper bound of the index base type). If the check fails a -- warning is emitted, the Raises_Constraint_Error Flag of N is set, -- and AH is replaced with a duplicate of BH. procedure Check_Bounds (L, H : Node_Id; AL, AH : Node_Id); -- Checks that range AL .. AH is compatible with range L .. H. Emits a -- warning if not and sets the Raises_Constraint_Error Flag in N. procedure Check_Length (L, H : Node_Id; Len : Uint); -- Checks that range L .. H contains at least Len elements. Emits a -- warning if not and sets the Raises_Constraint_Error Flag in N. function Dynamic_Or_Null_Range (L, H : Node_Id) return Boolean; -- Returns True if range L .. H is dynamic or null. procedure Get (Value : out Uint; From : Node_Id; OK : out Boolean); -- Given expression node From, this routine sets OK to False if it -- cannot statically evaluate From. Otherwise it stores this static -- value into Value. function Resolve_Aggr_Expr (Expr : Node_Id; Single_Elmt : Boolean) return Boolean; -- Resolves aggregate expression Expr. Returs False if resolution -- fails. If Single_Elmt is set to False, the expression Expr may be -- used to initialize several array aggregate elements (this can -- happen for discrete choices such as "L .. H => Expr" or the others -- choice). In this event we do not resolve Expr unless expansion is -- disabled. To know why, see the DELAYED COMPONENT RESOLUTION -- note above. --------- -- Add -- --------- function Add (Val : Uint; To : Node_Id) return Node_Id is Expr_Pos : Node_Id; Expr : Node_Id; To_Pos : Node_Id; begin if Raises_Constraint_Error (To) then return To; end if; -- First test if we can do constant folding if Compile_Time_Known_Value (To) or else Nkind (To) = N_Integer_Literal then Expr_Pos := Make_Integer_Literal (Loc, Expr_Value (To) + Val); Set_Is_Static_Expression (Expr_Pos); Set_Etype (Expr_Pos, Etype (To)); Set_Analyzed (Expr_Pos, Analyzed (To)); if not Is_Enumeration_Type (Index_Typ) then Expr := Expr_Pos; -- If we are dealing with enumeration return -- Index_Typ'Val (Expr_Pos) else Expr := Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Index_Typ, Loc), Attribute_Name => Name_Val, Expressions => New_List (Expr_Pos)); end if; return Expr; end if; -- If we are here no constant folding possible if not Is_Enumeration_Type (Index_Base) then Expr := Make_Op_Add (Loc, Left_Opnd => Duplicate_Subexpr (To), Right_Opnd => Make_Integer_Literal (Loc, Val)); -- If we are dealing with enumeration return -- Index_Typ'Val (Index_Typ'Pos (To) + Val) else To_Pos := Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Index_Typ, Loc), Attribute_Name => Name_Pos, Expressions => New_List (Duplicate_Subexpr (To))); Expr_Pos := Make_Op_Add (Loc, Left_Opnd => To_Pos, Right_Opnd => Make_Integer_Literal (Loc, Val)); Expr := Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Index_Typ, Loc), Attribute_Name => Name_Val, Expressions => New_List (Expr_Pos)); end if; return Expr; end Add; ----------------- -- Check_Bound -- ----------------- procedure Check_Bound (BH : Node_Id; AH : in out Node_Id) is Val_BH : Uint; Val_AH : Uint; OK_BH : Boolean; OK_AH : Boolean; begin Get (Value => Val_BH, From => BH, OK => OK_BH); Get (Value => Val_AH, From => AH, OK => OK_AH); if OK_BH and then OK_AH and then Val_BH < Val_AH then Set_Raises_Constraint_Error (N); Error_Msg_N ("upper bound out of range?", AH); Error_Msg_N ("Constraint_Error will be raised at run-time?", AH); -- You need to set AH to BH or else in the case of enumerations -- indices we will not be able to resolve the aggregate bounds. AH := Duplicate_Subexpr (BH); end if; end Check_Bound; ------------------ -- Check_Bounds -- ------------------ procedure Check_Bounds (L, H : Node_Id; AL, AH : Node_Id) is Val_L : Uint; Val_H : Uint; Val_AL : Uint; Val_AH : Uint; OK_L : Boolean; OK_H : Boolean; OK_AL : Boolean; OK_AH : Boolean; begin if Raises_Constraint_Error (N) or else Dynamic_Or_Null_Range (AL, AH) then return; end if; Get (Value => Val_L, From => L, OK => OK_L); Get (Value => Val_H, From => H, OK => OK_H); Get (Value => Val_AL, From => AL, OK => OK_AL); Get (Value => Val_AH, From => AH, OK => OK_AH); if OK_L and then Val_L > Val_AL then Set_Raises_Constraint_Error (N); Error_Msg_N ("lower bound of aggregate out of range?", N); Error_Msg_N ("Constraint_Error will be raised at run-time?", N); end if; if OK_H and then Val_H < Val_AH then Set_Raises_Constraint_Error (N); Error_Msg_N ("upper bound of aggregate out of range?", N); Error_Msg_N ("Constraint_Error will be raised at run-time?", N); end if; end Check_Bounds; ------------------ -- Check_Length -- ------------------ procedure Check_Length (L, H : Node_Id; Len : Uint) is Val_L : Uint; Val_H : Uint; OK_L : Boolean; OK_H : Boolean; Range_Len : Uint; begin if Raises_Constraint_Error (N) then return; end if; Get (Value => Val_L, From => L, OK => OK_L); Get (Value => Val_H, From => H, OK => OK_H); if not OK_L or else not OK_H then return; end if; -- If null range length is zero if Val_L > Val_H then Range_Len := Uint_0; else Range_Len := Val_H - Val_L + 1; end if; if Range_Len < Len then Set_Raises_Constraint_Error (N); Error_Msg_N ("Too many elements?", N); Error_Msg_N ("Constraint_Error will be raised at run-time?", N); end if; end Check_Length; --------------------------- -- Dynamic_Or_Null_Range -- --------------------------- function Dynamic_Or_Null_Range (L, H : Node_Id) return Boolean is Val_L : Uint; Val_H : Uint; OK_L : Boolean; OK_H : Boolean; begin Get (Value => Val_L, From => L, OK => OK_L); Get (Value => Val_H, From => H, OK => OK_H); return not OK_L or else not OK_H or else not Is_OK_Static_Expression (L) or else not Is_OK_Static_Expression (H) or else Val_L > Val_H; end Dynamic_Or_Null_Range; --------- -- Get -- --------- procedure Get (Value : out Uint; From : Node_Id; OK : out Boolean) is begin OK := True; if Compile_Time_Known_Value (From) then Value := Expr_Value (From); -- If expression From is something like Some_Type'Val (10) then -- Value = 10 elsif Nkind (From) = N_Attribute_Reference and then Attribute_Name (From) = Name_Val and then Compile_Time_Known_Value (First (Expressions (From))) then Value := Expr_Value (First (Expressions (From))); else Value := Uint_0; OK := False; end if; end Get; ----------------------- -- Resolve_Aggr_Expr -- ----------------------- function Resolve_Aggr_Expr (Expr : Node_Id; Single_Elmt : Boolean) return Boolean is Nxt_Ind : Node_Id := Next_Index (Index); Nxt_Ind_Constr : Node_Id := Next_Index (Index_Constr); -- Index is the current index corresponding to the expression. Resolution_OK : Boolean := True; -- Set to False if resolution of the expression failed. begin -- If the array type against which we are resolving the aggregate -- has several dimensions, the expressions nested inside the -- aggregate must be further aggregates (or strings). if Present (Nxt_Ind) then if Nkind (Expr) /= N_Aggregate then -- A string literal can appear where a one-dimensional array -- of characters is expected. If the literal looks like an -- operator, it is still an operator symbol, which will be -- transformed into a string when analyzed. if Is_Character_Type (Component_Typ) and then No (Next_Index (Nxt_Ind)) and then (Nkind (Expr) = N_String_Literal or else Nkind (Expr) = N_Operator_Symbol) then -- A string literal used in a multidimensional array -- aggregate in place of the final one-dimensional -- aggregate must not be enclosed in parentheses. if Paren_Count (Expr) /= 0 then Error_Msg_N ("No parenthesis allowed here", Expr); end if; Make_String_Into_Aggregate (Expr); else Error_Msg_N ("nested array aggregate expected", Expr); return Failure; end if; end if; Resolution_OK := Resolve_Array_Aggregate (Expr, Nxt_Ind, Nxt_Ind_Constr, Component_Typ, Others_Allowed); -- Do not resolve the expressions of discrete or others choices -- unless the expression covers a single component, or the expander -- is inactive. elsif Single_Elmt or else not Expander_Active or else In_Default_Expression then Analyze_And_Resolve (Expr, Component_Typ); Check_Non_Static_Context (Expr); Aggregate_Constraint_Checks (Expr, Component_Typ); end if; if Raises_Constraint_Error (Expr) and then Nkind (Parent (Expr)) /= N_Component_Association then Set_Raises_Constraint_Error (N); end if; return Resolution_OK; end Resolve_Aggr_Expr; -- Variables local to Resolve_Array_Aggregate Assoc : Node_Id; Choice : Node_Id; Expr : Node_Id; Who_Cares : Node_Id; Aggr_Low : Node_Id := Empty; Aggr_High : Node_Id := Empty; -- The actual low and high bounds of this sub-aggegate Choices_Low : Node_Id := Empty; Choices_High : Node_Id := Empty; -- The lowest and highest discrete choices values for a named aggregate Nb_Elements : Uint := Uint_0; -- The number of elements in a positional aggegate Others_Present : Boolean := False; Nb_Choices : Nat := 0; -- Contains the overall number of named choices in this sub-aggregate Nb_Discrete_Choices : Nat := 0; -- The overall number of discrete choices (not counting others choice) Case_Table_Size : Nat; -- Contains the size of the case table needed to sort aggregate choices -- Start of processing for Resolve_Array_Aggregate begin -- STEP 1: make sure the aggregate is correctly formatted if Present (Component_Associations (N)) then Assoc := First (Component_Associations (N)); while Present (Assoc) loop Choice := First (Choices (Assoc)); while Present (Choice) loop if Nkind (Choice) = N_Others_Choice then Others_Present := True; if Choice /= First (Choices (Assoc)) or else Present (Next (Choice)) then Error_Msg_N ("OTHERS must appear alone in a choice list", Choice); return Failure; end if; if Present (Next (Assoc)) then Error_Msg_N ("OTHERS must appear last in an aggregate", Choice); return Failure; end if; if Ada_83 and then Assoc /= First (Component_Associations (N)) and then (Nkind (Parent (N)) = N_Assignment_Statement or else Nkind (Parent (N)) = N_Object_Declaration) then Error_Msg_N ("(Ada 83) illegal context for OTHERS choice", N); end if; end if; Nb_Choices := Nb_Choices + 1; Next (Choice); end loop; Next (Assoc); end loop; end if; -- At this point we know that the others choice, if present, is by -- itself and appears last in the aggregate. Check if we have mixed -- positional and discrete associations (other than the others choice). if Present (Expressions (N)) and then (Nb_Choices > 1 or else (Nb_Choices = 1 and then not Others_Present)) then Error_Msg_N ("named association cannot follow positional association", First (Choices (First (Component_Associations (N))))); return Failure; end if; -- Test for the validity of an others choice if present if Others_Present and then not Others_Allowed then Error_Msg_N ("OTHERS choice not allowed here", First (Choices (First (Component_Associations (N))))); return Failure; end if; -- STEP 2: Process named components if No (Expressions (N)) then if Others_Present then Case_Table_Size := Nb_Choices - 1; else Case_Table_Size := Nb_Choices; end if; Step_2 : declare Low : Node_Id; High : Node_Id; -- Denote the lowest and highest values in an aggregate choice Hi_Val : Uint; Lo_Val : Uint; -- High end of one range and Low end of the next. Should be -- contiguous if there is no hole in the list of values. Missing_Values : Boolean; -- Set True if missing index values S_Low : Node_Id := Empty; S_High : Node_Id := Empty; -- if a choice in an aggregate is a subtype indication these -- denote the lowest and highest values of the subtype Table : Case_Table_Type (1 .. Case_Table_Size); -- Used to sort all the different choice values Single_Choice : Boolean; -- Set to true every time there is a single discrete choice in a -- discrete association Prev_Nb_Discrete_Choices : Nat; -- Used to keep track of the number of discrete choices -- in the current association. begin -- STEP 2 (A): Check discrete choices validity. Assoc := First (Component_Associations (N)); while Present (Assoc) loop Prev_Nb_Discrete_Choices := Nb_Discrete_Choices; Choice := First (Choices (Assoc)); loop Analyze (Choice); if Nkind (Choice) = N_Others_Choice then Single_Choice := False; exit; -- Test for subtype mark without constraint elsif Is_Entity_Name (Choice) and then Is_Type (Entity (Choice)) then if Base_Type (Entity (Choice)) /= Index_Base then Error_Msg_N ("invalid subtype mark in aggregate choice", Choice); return Failure; end if; elsif Nkind (Choice) = N_Subtype_Indication then Resolve_Discrete_Subtype_Indication (Choice, Index_Base); -- Does the subtype indication evaluation raise CE ? Get_Index_Bounds (Subtype_Mark (Choice), S_Low, S_High); Get_Index_Bounds (Choice, Low, High); Check_Bounds (S_Low, S_High, Low, High); else -- Choice is a range or an expression Resolve (Choice, Index_Base); Check_Non_Static_Context (Choice); -- Do not range check a choice. This check is redundant -- since this test is already performed when we check -- that the bounds of the array aggregate are within -- range. Set_Do_Range_Check (Choice, False); end if; -- If we could not resolve the discrete choice stop here if Etype (Choice) = Any_Type then return Failure; -- If the discrete choice raises CE get its original bounds. elsif Nkind (Choice) = N_Raise_Constraint_Error then Set_Raises_Constraint_Error (N); Get_Index_Bounds (Original_Node (Choice), Low, High); -- Otherwise get its bounds as usual else Get_Index_Bounds (Choice, Low, High); end if; if (Dynamic_Or_Null_Range (Low, High) or else (Nkind (Choice) = N_Subtype_Indication and then Dynamic_Or_Null_Range (S_Low, S_High))) and then Nb_Choices /= 1 then Error_Msg_N ("dynamic or empty choice in aggregate " & "must be the only choice", Choice); return Failure; end if; Nb_Discrete_Choices := Nb_Discrete_Choices + 1; Table (Nb_Discrete_Choices).Choice_Lo := Low; Table (Nb_Discrete_Choices).Choice_Hi := High; Next (Choice); if No (Choice) then -- Check if we have a single discrete choice and whether -- this discrete choice specifies a single value. Single_Choice := (Nb_Discrete_Choices = Prev_Nb_Discrete_Choices + 1) and then (Low = High); exit; end if; end loop; if not Resolve_Aggr_Expr (Expression (Assoc), Single_Elmt => Single_Choice) then return Failure; end if; Next (Assoc); end loop; -- If aggregate contains more than one choice then these must be -- static. Sort them and check that they are contiguous if Nb_Discrete_Choices > 1 then Sort_Case_Table (Table); Missing_Values := False; Outer : for J in 1 .. Nb_Discrete_Choices - 1 loop if Expr_Value (Table (J).Choice_Hi) >= Expr_Value (Table (J + 1).Choice_Lo) then Error_Msg_N ("duplicate choice values in array aggregate", Table (J).Choice_Hi); return Failure; elsif not Others_Present then Hi_Val := Expr_Value (Table (J).Choice_Hi); Lo_Val := Expr_Value (Table (J + 1).Choice_Lo); -- If missing values, output error messages if Lo_Val - Hi_Val > 1 then -- Header message if not first missing value if not Missing_Values then Error_Msg_N ("missing index value(s) in array aggregate", N); Missing_Values := True; end if; -- Output values of missing indexes Lo_Val := Lo_Val - 1; Hi_Val := Hi_Val + 1; -- Enumeration type case if Is_Enumeration_Type (Index_Typ) then Error_Msg_Name_1 := Chars (Get_Enum_Lit_From_Pos (Index_Typ, Hi_Val, Loc)); if Lo_Val = Hi_Val then Error_Msg_N ("\ %", N); else Error_Msg_Name_2 := Chars (Get_Enum_Lit_From_Pos (Index_Typ, Lo_Val, Loc)); Error_Msg_N ("\ % .. %", N); end if; -- Integer types case else Error_Msg_Uint_1 := Hi_Val; if Lo_Val = Hi_Val then Error_Msg_N ("\ ^", N); else Error_Msg_Uint_2 := Lo_Val; Error_Msg_N ("\ ^ .. ^", N); end if; end if; end if; end if; end loop Outer; if Missing_Values then Set_Etype (N, Any_Composite); return Failure; end if; end if; -- STEP 2 (B): Compute aggregate bounds and min/max choices values if Nb_Discrete_Choices > 0 then Choices_Low := Table (1).Choice_Lo; Choices_High := Table (Nb_Discrete_Choices).Choice_Hi; end if; if Others_Present then Get_Index_Bounds (Index_Constr, Aggr_Low, Aggr_High); else Aggr_Low := Choices_Low; Aggr_High := Choices_High; end if; end Step_2; -- STEP 3: Process positional components else -- STEP 3 (A): Process positional elements Expr := First (Expressions (N)); Nb_Elements := Uint_0; while Present (Expr) loop Nb_Elements := Nb_Elements + 1; if not Resolve_Aggr_Expr (Expr, Single_Elmt => True) then return Failure; end if; Next (Expr); end loop; if Others_Present then Assoc := Last (Component_Associations (N)); if not Resolve_Aggr_Expr (Expression (Assoc), Single_Elmt => False) then return Failure; end if; end if; -- STEP 3 (B): Compute the aggregate bounds if Others_Present then Get_Index_Bounds (Index_Constr, Aggr_Low, Aggr_High); else if Others_Allowed then Get_Index_Bounds (Index_Constr, Aggr_Low, Who_Cares); else Aggr_Low := Index_Typ_Low; end if; Aggr_High := Add (Nb_Elements - 1, To => Aggr_Low); Check_Bound (Index_Base_High, Aggr_High); end if; end if; -- STEP 4: Perform static aggregate checks and save the bounds -- Check (A) Check_Bounds (Index_Typ_Low, Index_Typ_High, Aggr_Low, Aggr_High); Check_Bounds (Index_Base_Low, Index_Base_High, Aggr_Low, Aggr_High); -- Check (B) if Others_Present and then Nb_Discrete_Choices > 0 then Check_Bounds (Aggr_Low, Aggr_High, Choices_Low, Choices_High); Check_Bounds (Index_Typ_Low, Index_Typ_High, Choices_Low, Choices_High); Check_Bounds (Index_Base_Low, Index_Base_High, Choices_Low, Choices_High); -- Check (C) elsif Others_Present and then Nb_Elements > 0 then Check_Length (Aggr_Low, Aggr_High, Nb_Elements); Check_Length (Index_Typ_Low, Index_Typ_High, Nb_Elements); Check_Length (Index_Base_Low, Index_Base_High, Nb_Elements); end if; if Raises_Constraint_Error (Aggr_Low) or else Raises_Constraint_Error (Aggr_High) then Set_Raises_Constraint_Error (N); end if; Aggr_Low := Duplicate_Subexpr (Aggr_Low); -- Do not duplicate Aggr_High if Aggr_High = Aggr_Low + Nb_Elements -- since the addition node returned by Add is not yet analyzed. Attach -- to tree and analyze first. Reset analyzed flag to insure it will get -- analyzed when it is a literal bound whose type must be properly -- set. if Others_Present or else Nb_Discrete_Choices > 0 then Aggr_High := Duplicate_Subexpr (Aggr_High); if Etype (Aggr_High) = Universal_Integer then Set_Analyzed (Aggr_High, False); end if; end if; Set_Aggregate_Bounds (N, Make_Range (Loc, Low_Bound => Aggr_Low, High_Bound => Aggr_High)); -- The bounds may contain expressions that must be inserted upwards. -- Attach them fully to the tree. After analysis, remove side effects -- from upper bound, if still needed. Set_Parent (Aggregate_Bounds (N), N); Analyze_And_Resolve (Aggregate_Bounds (N), Index_Typ); if not Others_Present and then Nb_Discrete_Choices = 0 then Set_High_Bound (Aggregate_Bounds (N), Duplicate_Subexpr (High_Bound (Aggregate_Bounds (N)))); end if; return Success; end Resolve_Array_Aggregate; --------------------------------- -- Resolve_Extension_Aggregate -- --------------------------------- -- There are two cases to consider: -- a) If the ancestor part is a type mark, the components needed are -- the difference between the components of the expected type and the -- components of the given type mark. -- b) If the ancestor part is an expression, it must be unambiguous, -- and once we have its type we can also compute the needed components -- as in the previous case. In both cases, if the ancestor type is not -- the immediate ancestor, we have to build this ancestor recursively. -- In both cases discriminants of the ancestor type do not play a -- role in the resolution of the needed components, because inherited -- discriminants cannot be used in a type extension. As a result we can -- compute independently the list of components of the ancestor type and -- of the expected type. procedure Resolve_Extension_Aggregate (N : Node_Id; Typ : Entity_Id) is A : constant Node_Id := Ancestor_Part (N); A_Type : Entity_Id; I : Interp_Index; It : Interp; Imm_Type : Entity_Id; function Valid_Ancestor_Type return Boolean; -- Verify that the type of the ancestor part is a non-private ancestor -- of the expected type. function Valid_Ancestor_Type return Boolean is Imm_Type : Entity_Id; begin Imm_Type := Base_Type (Typ); while Is_Derived_Type (Imm_Type) and then Etype (Imm_Type) /= Base_Type (A_Type) loop Imm_Type := Etype (Base_Type (Imm_Type)); end loop; if Etype (Imm_Type) /= Base_Type (A_Type) then Error_Msg_NE ("expect ancestor type of &", A, Typ); return False; else return True; end if; end Valid_Ancestor_Type; -- Start of processing for Resolve_Extension_Aggregate begin Analyze (A); if not Is_Tagged_Type (Typ) then Error_Msg_N ("type of extension aggregate must be tagged", N); return; elsif Is_Limited_Type (Typ) then Error_Msg_N ("aggregate type cannot be limited", N); return; elsif Is_Class_Wide_Type (Typ) then Error_Msg_N ("aggregate cannot be of a class-wide type", N); return; end if; if Is_Entity_Name (A) and then Is_Type (Entity (A)) then A_Type := Get_Full_View (Entity (A)); Imm_Type := Base_Type (Typ); if Valid_Ancestor_Type then Set_Entity (A, A_Type); Set_Etype (A, A_Type); Validate_Ancestor_Part (N); Resolve_Record_Aggregate (N, Typ); end if; elsif Nkind (A) /= N_Aggregate then if Is_Overloaded (A) then A_Type := Any_Type; Get_First_Interp (A, I, It); while Present (It.Typ) loop if Is_Tagged_Type (It.Typ) and then not Is_Limited_Type (It.Typ) then if A_Type /= Any_Type then Error_Msg_N ("cannot resolve expression", A); return; else A_Type := It.Typ; end if; end if; Get_Next_Interp (I, It); end loop; if A_Type = Any_Type then Error_Msg_N ("ancestor part must be non-limited tagged type", A); return; end if; else A_Type := Etype (A); end if; if Valid_Ancestor_Type then Resolve (A, A_Type); Check_Non_Static_Context (A); Resolve_Record_Aggregate (N, Typ); end if; else Error_Msg_N (" No unique type for this aggregate", A); end if; end Resolve_Extension_Aggregate; ------------------------------ -- Resolve_Record_Aggregate -- ------------------------------ procedure Resolve_Record_Aggregate (N : Node_Id; Typ : Entity_Id) is Regular_Aggr : constant Boolean := Nkind (N) /= N_Extension_Aggregate; New_Assoc_List : List_Id := New_List; New_Assoc : Node_Id; -- New_Assoc_List is the newly built list of N_Component_Association -- nodes. New_Assoc is one such N_Component_Association node in it. -- Please note that while Assoc and New_Assoc contain the same -- kind of nodes, they are used to iterate over two different -- N_Component_Association lists. Others_Etype : Entity_Id := Empty; -- This variable is used to save the Etype of the last record component -- that takes its value from the others choice. Its purpose is: -- -- (a) make sure the others choice is useful -- -- (b) make sure the type of all the components whose value is -- subsumed by the others choice are the same. -- -- This variable is updated as a side effect of function Get_Value procedure Add_Association (Component : Entity_Id; Expr : Node_Id); -- Builds a new N_Component_Association node which associates -- Component to expression Expr and adds it to the new association -- list New_Assoc_List being built. function Discr_Present (Discr : Entity_Id) return Boolean; -- If aggregate N is a regular aggregate this routine will return True. -- Otherwise, if N is an extension aggreagte, Discr is a discriminant -- whose value may already have been specified by N's ancestor part, -- this routine checks whether this is indeed the case and if so -- returns False, signaling that no value for Discr should appear in the -- N's aggregate part. Also, in this case, the routine appends to -- New_Assoc_List Discr the discriminant value specified in the ancestor -- part. function Get_Value (Compon : Node_Id; From : List_Id; Consider_Others_Choice : Boolean := False) return Node_Id; -- Given a record component stored in parameter Compon, the -- following function returns its value as it appears in the list -- From, which is a list of N_Component_Association nodes. If no -- component association has a choice for the searched component, -- the value provided by the others choice is returned, if there -- is one and Consider_Others_Choice is set to true. Otherwise -- Empty is returned. If there is more than one component association -- giving a value for the searched record component, an error message -- is emitted and the first found value is returned. -- -- If Consider_Others_Choice is set and the returned expression comes -- from the others choice, then Others_Etype is set as a side effect. -- An error message is emitted if the components taking their value -- from the others choice do not have same type. procedure Resolve_Aggr_Expr (Expr : Node_Id; Component : Node_Id); -- Analyzes and resolves expression Expr against the Etype of the -- Component. This routine also applies all appropriate checks to Expr. -- It finally saves a Expr in the newly created association list that -- will be attached to the final record aggregate. Note that if the -- Parent pointer of Expr is not set then Expr was produced with a -- New_copy_Tree or some such. --------------------- -- Add_Association -- --------------------- procedure Add_Association (Component : Entity_Id; Expr : Node_Id) is New_Assoc : Node_Id; Choice_List : List_Id := New_List; begin Append (New_Occurrence_Of (Component, Sloc (Expr)), Choice_List); New_Assoc := Make_Component_Association (Sloc (Expr), Choices => Choice_List, Expression => Expr); Append (New_Assoc, New_Assoc_List); end Add_Association; ------------------- -- Discr_Present -- ------------------- function Discr_Present (Discr : Entity_Id) return Boolean is Loc : Source_Ptr; Ancestor : Node_Id; Discr_Expr : Node_Id; Ancestor_Typ : Entity_Id; Orig_Discr : Entity_Id; D : Entity_Id; D_Val : Elmt_Id := No_Elmt; -- stop junk warning Ancestor_Is_Subtyp : Boolean; begin if Regular_Aggr then return True; end if; Ancestor := Ancestor_Part (N); Ancestor_Typ := Etype (Ancestor); Loc := Sloc (Ancestor); Ancestor_Is_Subtyp := Is_Entity_Name (Ancestor) and then Is_Type (Entity (Ancestor)); -- If the ancestor part has no discriminants clearly N's aggregate -- part must provide a value for Discr. if not Has_Discriminants (Ancestor_Typ) then return True; -- If the ancestor part is an unconstrained subtype mark then the -- Discr must be present in N's aggregate part. elsif Ancestor_Is_Subtyp and then not Is_Constrained (Entity (Ancestor)) then return True; end if; -- Now look to see if Discr was specified in the ancestor part. Orig_Discr := Original_Record_Component (Discr); D := First_Discriminant (Ancestor_Typ); if Ancestor_Is_Subtyp then D_Val := First_Elmt (Discriminant_Constraint (Entity (Ancestor))); end if; while Present (D) loop -- If Ancestor has already specified Disc value than -- insert its value in the final aggregate. if Original_Record_Component (D) = Orig_Discr then if Ancestor_Is_Subtyp then Discr_Expr := New_Copy_Tree (Node (D_Val)); else Discr_Expr := Make_Selected_Component (Loc, Prefix => Duplicate_Subexpr (Ancestor), Selector_Name => New_Occurrence_Of (Discr, Loc)); end if; Resolve_Aggr_Expr (Discr_Expr, Discr); return False; end if; Next_Discriminant (D); if Ancestor_Is_Subtyp then Next_Elmt (D_Val); end if; end loop; return True; end Discr_Present; --------------- -- Get_Value -- --------------- function Get_Value (Compon : Node_Id; From : List_Id; Consider_Others_Choice : Boolean := False) return Node_Id is Assoc : Node_Id; Expr : Node_Id := Empty; Selector_Name : Node_Id; begin if Present (From) then Assoc := First (From); else return Empty; end if; while Present (Assoc) loop Selector_Name := First (Choices (Assoc)); while Present (Selector_Name) loop if Nkind (Selector_Name) = N_Others_Choice then if Consider_Others_Choice and then No (Expr) then if Present (Others_Etype) and then Base_Type (Others_Etype) /= Base_Type (Etype (Compon)) then Error_Msg_N ("components in OTHERS choice must " & "have same type", Selector_Name); end if; Others_Etype := Etype (Compon); -- We need to duplicate the expression for each -- successive component covered by the others choice. -- If the expression is itself an array aggregate with -- "others", its subtype must be obtained from the -- current component, and therefore it must be (at least -- partly) reanalyzed. if Analyzed (Expression (Assoc)) then Expr := New_Copy_Tree (Expression (Assoc)); if Nkind (Expr) = N_Aggregate and then Is_Array_Type (Etype (Expr)) and then No (Expressions (Expr)) and then Nkind (First (Choices (First (Component_Associations (Expr))))) = N_Others_Choice then Set_Analyzed (Expr, False); end if; return Expr; else return Expression (Assoc); end if; end if; elsif Chars (Compon) = Chars (Selector_Name) then if No (Expr) then -- We need to duplicate the expression when several -- components are grouped together with a "|" choice. -- For instance "filed1 | filed2 => Expr" if Present (Next (Selector_Name)) then Expr := New_Copy_Tree (Expression (Assoc)); else Expr := Expression (Assoc); end if; else Error_Msg_NE ("more than one value supplied for &", Selector_Name, Compon); end if; end if; Next (Selector_Name); end loop; Next (Assoc); end loop; return Expr; end Get_Value; ----------------------- -- Resolve_Aggr_Expr -- ----------------------- procedure Resolve_Aggr_Expr (Expr : Node_Id; Component : Node_Id) is New_C : Entity_Id := Component; Expr_Type : Entity_Id := Empty; function Has_Expansion_Delayed (Expr : Node_Id) return Boolean; -- If the expression is an aggregate (possibly qualified) then its -- expansion is delayed until the enclosing aggregate is expanded -- into assignments. In that case, do not generate checks on the -- expression, because they will be generated later, and will other- -- wise force a copy (to remove side-effects) that would leave a -- dynamic-sized aggregate in the code, something that gigi cannot -- handle. Relocate : Boolean; -- Set to True if the resolved Expr node needs to be relocated -- when attached to the newly created association list. This node -- need not be relocated if its parent pointer is not set. -- In fact in this case Expr is the output of a New_Copy_Tree call. -- if Relocate is True then we have analyzed the expression node -- in the original aggregate and hence it needs to be relocated -- when moved over the new association list. function Has_Expansion_Delayed (Expr : Node_Id) return Boolean is Kind : constant Node_Kind := Nkind (Expr); begin return ((Kind = N_Aggregate or else Kind = N_Extension_Aggregate) and then Present (Etype (Expr)) and then Is_Record_Type (Etype (Expr)) and then Expansion_Delayed (Expr)) or else (Kind = N_Qualified_Expression and then Has_Expansion_Delayed (Expression (Expr))); end Has_Expansion_Delayed; -- Start of processing for Resolve_Aggr_Expr begin -- If the type of the component is elementary or the type of the -- aggregate does not contain discriminants, use the type of the -- component to resolve Expr. if Is_Elementary_Type (Etype (Component)) or else not Has_Discriminants (Etype (N)) then Expr_Type := Etype (Component); -- Otherwise we have to pick up the new type of the component from -- the new costrained subtype of the aggregate. In fact components -- which are of a composite type might be constrained by a -- discriminant, and we want to resolve Expr against the subtype were -- all discriminant occurrences are replaced with their actual value. else New_C := First_Component (Etype (N)); while Present (New_C) loop if Chars (New_C) = Chars (Component) then Expr_Type := Etype (New_C); exit; end if; Next_Component (New_C); end loop; pragma Assert (Present (Expr_Type)); -- For each range in an array type where a discriminant has been -- replaced with the constraint, check that this range is within -- the range of the base type. This checks is done in the -- _init_proc for regular objects, but has to be done here for -- aggregates since no _init_proc is called for them. if Is_Array_Type (Expr_Type) then declare Index : Node_Id := First_Index (Expr_Type); -- Range of the current constrained index in the array. Orig_Index : Node_Id := First_Index (Etype (Component)); -- Range corresponding to the range Index above in the -- original unconstrained record type. The bounds of this -- range may be governed by discriminants. Unconstr_Index : Node_Id := First_Index (Etype (Expr_Type)); -- Range corresponding to the range Index above for the -- unconstrained array type. This range is needed to apply -- range checks. begin while Present (Index) loop if Depends_On_Discriminant (Orig_Index) then Apply_Range_Check (Index, Etype (Unconstr_Index)); end if; Next_Index (Index); Next_Index (Orig_Index); Next_Index (Unconstr_Index); end loop; end; end if; end if; -- If the Parent pointer of Expr is not set, Expr is an expression -- duplicated by New_Tree_Copy (this happens for record aggregates -- that look like (Field1 | Filed2 => Expr) or (others => Expr)). -- Such a duplicated expression must be attached to the tree -- before analysis and resolution to enforce the rule that a tree -- fragment should never be analyzed or resolved unless it is -- attached to the current compilation unit. if No (Parent (Expr)) then Set_Parent (Expr, N); Relocate := False; else Relocate := True; end if; Analyze_And_Resolve (Expr, Expr_Type); Check_Non_Static_Context (Expr); if not Has_Expansion_Delayed (Expr) then Aggregate_Constraint_Checks (Expr, Expr_Type); end if; if Raises_Constraint_Error (Expr) then Set_Raises_Constraint_Error (N); end if; if Relocate then Add_Association (New_C, Relocate_Node (Expr)); else Add_Association (New_C, Expr); end if; end Resolve_Aggr_Expr; -- Resolve_Record_Aggregate local variables Assoc : Node_Id; -- N_Component_Association node belonging to the input aggregate N Expr : Node_Id; Positional_Expr : Node_Id; Component : Entity_Id; Component_Elmt : Elmt_Id; Components : Elist_Id := New_Elmt_List; -- Components is the list of the record components whose value must -- be provided in the aggregate. This list does include discriminants. -- Start of processing for Resolve_Record_Aggregate begin -- We may end up calling Duplicate_Subexpr on expressions that are -- attached to New_Assoc_List. For this reason we need to attach it -- to the tree by setting its parent pointer to N. This parent point -- will change in STEP 8 below. Set_Parent (New_Assoc_List, N); -- STEP 1: abstract type and null record verification if Is_Abstract (Typ) then Error_Msg_N ("type of aggregate cannot be abstract", N); end if; if No (First_Entity (Typ)) and then Null_Record_Present (N) then Set_Etype (N, Typ); return; elsif Present (First_Entity (Typ)) and then Null_Record_Present (N) and then not Is_Tagged_Type (Typ) then Error_Msg_N ("record aggregate cannot be null", N); return; elsif No (First_Entity (Typ)) then Error_Msg_N ("record aggregate must be null", N); return; end if; -- STEP 2: Verify aggregate structure Step_2 : declare Selector_Name : Node_Id; Bad_Aggregate : Boolean := False; begin if Present (Component_Associations (N)) then Assoc := First (Component_Associations (N)); else Assoc := Empty; end if; while Present (Assoc) loop Selector_Name := First (Choices (Assoc)); while Present (Selector_Name) loop if Nkind (Selector_Name) = N_Identifier then null; elsif Nkind (Selector_Name) = N_Others_Choice then if Selector_Name /= First (Choices (Assoc)) or else Present (Next (Selector_Name)) then Error_Msg_N ("OTHERS must appear alone in a choice list", Selector_Name); return; elsif Present (Next (Assoc)) then Error_Msg_N ("OTHERS must appear last in an aggregate", Selector_Name); return; end if; else Error_Msg_N ("selector name should be identifier or OTHERS", Selector_Name); Bad_Aggregate := True; end if; Next (Selector_Name); end loop; Next (Assoc); end loop; if Bad_Aggregate then return; end if; end Step_2; -- STEP 3: Find discriminant Values Step_3 : declare Discrim : Entity_Id; Missing_Discriminants : Boolean := False; begin if Present (Expressions (N)) then Positional_Expr := First (Expressions (N)); else Positional_Expr := Empty; end if; if Has_Discriminants (Typ) then Discrim := First_Discriminant (Typ); else Discrim := Empty; end if; -- First find the discriminant values in the positional components while Present (Discrim) and then Present (Positional_Expr) loop if Discr_Present (Discrim) then Resolve_Aggr_Expr (Positional_Expr, Discrim); Next (Positional_Expr); end if; if Present (Get_Value (Discrim, Component_Associations (N))) then Error_Msg_NE ("more than one value supplied for discriminant&", N, Discrim); end if; Next_Discriminant (Discrim); end loop; -- Find remaining discriminant values, if any, among named components while Present (Discrim) loop Expr := Get_Value (Discrim, Component_Associations (N), True); if not Discr_Present (Discrim) then if Present (Expr) then Error_Msg_NE ("more than one value supplied for discriminant&", N, Discrim); end if; elsif No (Expr) then Error_Msg_NE ("no value supplied for discriminant &", N, Discrim); Missing_Discriminants := True; else Resolve_Aggr_Expr (Expr, Discrim); end if; Next_Discriminant (Discrim); end loop; if Missing_Discriminants then return; end if; -- At this point and until the beginning of STEP 6, New_Assoc_List -- contains only the discriminants and their values. end Step_3; -- STEP 4: Set the Etype of the record aggregate -- ??? This code is pretty much a copy of Sem_Ch3.Build_Subtype. That -- routine should really be exported in sem_util or some such and used -- in sem_ch3 and here rather than have a copy of the code which is a -- maintenance nightmare. -- ??? Performace WARNING. The current implementation creates a new -- itype for all aggregates whose base type is discriminated. -- This means that for record aggregates nested inside an array -- aggregate we will create a new itype for each record aggregate -- if the array cmponent type has discriminants. For large aggregates -- this may be a problem. What should be done in this case is -- to reuse itypes as much as possible. if Has_Discriminants (Typ) then Build_Constrained_Itype : declare Loc : constant Source_Ptr := Sloc (N); Indic : Node_Id; Subtyp_Decl : Node_Id; Def_Id : Entity_Id; C : List_Id := New_List; begin New_Assoc := First (New_Assoc_List); while Present (New_Assoc) loop Append (Duplicate_Subexpr (Expression (New_Assoc)), To => C); Next (New_Assoc); end loop; Indic := Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (Base_Type (Typ), Loc), Constraint => Make_Index_Or_Discriminant_Constraint (Loc, C)); Def_Id := Create_Itype (Ekind (Typ), N); Subtyp_Decl := Make_Subtype_Declaration (Loc, Defining_Identifier => Def_Id, Subtype_Indication => Indic); Set_Parent (Subtyp_Decl, Parent (N)); -- Itypes must be analyzed with checks off (see itypes.ads). Analyze (Subtyp_Decl, Suppress => All_Checks); Set_Etype (N, Def_Id); Check_Static_Discriminated_Subtype (Def_Id, Expression (First (New_Assoc_List))); end Build_Constrained_Itype; else Set_Etype (N, Typ); end if; -- STEP 5: Get remaining components according to discriminant values Step_5 : declare Record_Def : Node_Id; Parent_Typ : Entity_Id; Root_Typ : Entity_Id; Parent_Typ_List : Elist_Id; Parent_Elmt : Elmt_Id; Errors_Found : Boolean := False; Dnode : Node_Id; begin if Is_Derived_Type (Typ) and then Is_Tagged_Type (Typ) then Parent_Typ_List := New_Elmt_List; -- If this is an extension aggregate, the component list must -- include all components that are not in the given ancestor -- type. Otherwise, the component list must include components -- of all ancestors. if Nkind (N) = N_Extension_Aggregate then Root_Typ := Base_Type (Etype (Ancestor_Part (N))); else Root_Typ := Root_Type (Typ); if Nkind (Parent (Base_Type (Root_Typ))) = N_Private_Type_Declaration then Error_Msg_NE ("type of aggregate has private ancestor&!", N, Root_Typ); Error_Msg_N ("must use extension aggregate!", N); return; end if; Dnode := Declaration_Node (Base_Type (Root_Typ)); -- If we don't get a full declaration, then we have some -- error which will get signalled later so skip this part. if Nkind (Dnode) = N_Full_Type_Declaration then Record_Def := Type_Definition (Dnode); Gather_Components (Typ, Component_List (Record_Def), Governed_By => New_Assoc_List, Into => Components, Report_Errors => Errors_Found); end if; end if; Parent_Typ := Base_Type (Typ); while Parent_Typ /= Root_Typ loop Prepend_Elmt (Parent_Typ, To => Parent_Typ_List); Parent_Typ := Etype (Parent_Typ); if (Nkind (Parent (Base_Type (Parent_Typ))) = N_Private_Type_Declaration or else Nkind (Parent (Base_Type (Parent_Typ))) = N_Private_Extension_Declaration) then if Nkind (N) /= N_Extension_Aggregate then Error_Msg_NE ("type of aggregate has private ancestor&!", N, Parent_Typ); Error_Msg_N ("must use extension aggregate!", N); return; elsif Parent_Typ /= Root_Typ then Error_Msg_NE ("ancestor part of aggregate must be private type&", Ancestor_Part (N), Parent_Typ); return; end if; end if; end loop; -- Now collect components from all other ancestors. Parent_Elmt := First_Elmt (Parent_Typ_List); while Present (Parent_Elmt) loop Parent_Typ := Node (Parent_Elmt); Record_Def := Type_Definition (Parent (Base_Type (Parent_Typ))); Gather_Components (Empty, Component_List (Record_Extension_Part (Record_Def)), Governed_By => New_Assoc_List, Into => Components, Report_Errors => Errors_Found); Next_Elmt (Parent_Elmt); end loop; else Record_Def := Type_Definition (Parent (Base_Type (Typ))); if Null_Present (Record_Def) then null; else Gather_Components (Typ, Component_List (Record_Def), Governed_By => New_Assoc_List, Into => Components, Report_Errors => Errors_Found); end if; end if; if Errors_Found then return; end if; end Step_5; -- STEP 6: Find component Values Component := Empty; Component_Elmt := First_Elmt (Components); -- First scan the remaining positional associations in the aggregate. -- Remember that at this point Positional_Expr contains the current -- positional association if any is left after looking for discriminant -- values in step 3. while Present (Positional_Expr) and then Present (Component_Elmt) loop Component := Node (Component_Elmt); Resolve_Aggr_Expr (Positional_Expr, Component); if Present (Get_Value (Component, Component_Associations (N))) then Error_Msg_NE ("more than one value supplied for Component &", N, Component); end if; Next (Positional_Expr); Next_Elmt (Component_Elmt); end loop; if Present (Positional_Expr) then Error_Msg_N ("too many components for record aggregate", Positional_Expr); end if; -- Now scan for the named arguments of the aggregate while Present (Component_Elmt) loop Component := Node (Component_Elmt); Expr := Get_Value (Component, Component_Associations (N), True); if No (Expr) then Error_Msg_NE ("no value supplied for component &!", N, Component); else Resolve_Aggr_Expr (Expr, Component); end if; Next_Elmt (Component_Elmt); end loop; -- STEP 7: check for invalid components + check type in choice list Step_7 : declare Selectr : Node_Id; -- Selector name Typech : Entity_Id; -- Type of first component in choice list begin if Present (Component_Associations (N)) then Assoc := First (Component_Associations (N)); else Assoc := Empty; end if; Verification : while Present (Assoc) loop Selectr := First (Choices (Assoc)); Typech := Empty; if Nkind (Selectr) = N_Others_Choice then if No (Others_Etype) then Error_Msg_N ("OTHERS must represent at least one component", Selectr); end if; exit Verification; end if; while Present (Selectr) loop New_Assoc := First (New_Assoc_List); while Present (New_Assoc) loop Component := First (Choices (New_Assoc)); exit when Chars (Selectr) = Chars (Component); Next (New_Assoc); end loop; -- If no association, this is not a legal component of -- of the type in question, except if this is an internal -- component supplied by a previous expansion. if No (New_Assoc) then if Chars (Selectr) /= Name_uTag and then Chars (Selectr) /= Name_uParent and then Chars (Selectr) /= Name_uController then if not Has_Discriminants (Typ) then Error_Msg_Node_2 := Typ; Error_Msg_N ("& is not a component of}", Selectr); else Error_Msg_N ("& is not a component of the aggregate subtype", Selectr); end if; Check_Misspelled_Component (Components, Selectr); end if; elsif No (Typech) then Typech := Base_Type (Etype (Component)); elsif Typech /= Base_Type (Etype (Component)) then Error_Msg_N ("components in choice list must have same type", Selectr); end if; Next (Selectr); end loop; Next (Assoc); end loop Verification; end Step_7; -- STEP 8: replace the original aggregate Step_8 : declare New_Aggregate : Node_Id := New_Copy (N); begin Set_Expressions (New_Aggregate, No_List); Set_Etype (New_Aggregate, Etype (N)); Set_Component_Associations (New_Aggregate, New_Assoc_List); Rewrite (N, New_Aggregate); end Step_8; end Resolve_Record_Aggregate; --------------------- -- Sort_Case_Table -- --------------------- procedure Sort_Case_Table (Case_Table : in out Case_Table_Type) is L : Int := Case_Table'First; U : Int := Case_Table'Last; K : Int; J : Int; T : Case_Bounds; begin K := L; while K /= U loop T := Case_Table (K + 1); J := K + 1; while J /= L and then Expr_Value (Case_Table (J - 1).Choice_Lo) > Expr_Value (T.Choice_Lo) loop Case_Table (J) := Case_Table (J - 1); J := J - 1; end loop; Case_Table (J) := T; K := K + 1; end loop; end Sort_Case_Table; end Sem_Aggr;
----------------------------------------------------------------------- -- akt-commands-extract -- Get content from keystore -- Copyright (C) 2019 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Text_IO; with Ada.Command_Line; with Ada.Directories; with Ada.Streams.Stream_IO; with GNAT.Regpat; with Util.Streams.Raw; with Util.Systems.Os; with Util.Files; with Util.Streams.Files; package body AKT.Commands.Extract is use GNAT.Strings; -- ------------------------------ -- Get a value from the keystore. -- ------------------------------ overriding procedure Execute (Command : in out Command_Type; Name : in String; Args : in Argument_List'Class; Context : in out Context_Type) is pragma Unreferenced (Name); Output : Util.Streams.Raw.Raw_Stream; procedure Extract_Directory (Path : in String; Output : in String); procedure Extract_Standard_Output (Name : in String); procedure Extract_File (Name : in String; Output : in String); procedure Extract_File (Name : in String; Output : in String) is Target : constant String := Util.Files.Compose ((if Output = "" then "." else Output), Name); Dir : constant String := Ada.Directories.Containing_Directory (Target); File : Util.Streams.Files.File_Stream; begin Ada.Directories.Create_Path (Dir); File.Create (Mode => Ada.Streams.Stream_IO.Out_File, Name => Target); Context.Wallet.Get (Name => Name, Output => File); exception when Keystore.Not_Found => AKT.Commands.Log.Error (-("Value '{0}' not found"), Name); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); end Extract_File; procedure Extract_Directory (Path : in String; Output : in String) is Pattern : constant GNAT.Regpat.Pattern_Matcher := GNAT.Regpat.Compile (Path & "/.*"); List : Keystore.Entry_Map; Iter : Keystore.Entry_Cursor; begin Context.Wallet.List (Pattern => Pattern, Filter => (Keystore.T_FILE => True, others => False), Content => List); if List.Is_Empty then AKT.Commands.Log.Error (-("Value '{0}' not found"), Path); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; Iter := List.First; while Keystore.Entry_Maps.Has_Element (Iter) loop declare Name : constant String := Keystore.Entry_Maps.Key (Iter); begin Ada.Text_IO.Put_Line (-("Extract ") & Name); Extract_File (Name, Output); end; Keystore.Entry_Maps.Next (Iter); end loop; end Extract_Directory; procedure Extract_Standard_Output (Name : in String) is begin Context.Wallet.Get (Name, Output); exception when Keystore.Not_Found => AKT.Commands.Log.Error (-("Value '{0}' not found"), Name); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); end Extract_Standard_Output; begin Context.Open_Keystore (Args, Use_Worker => True); if Context.First_Arg > Args.Get_Count then AKT.Commands.Log.Error (-("Missing file or directory to extract")); raise Error; end if; if Command.Use_Stdout then Output.Initialize (File => Util.Systems.Os.STDOUT_FILENO); for I in Context.First_Arg .. Args.Get_Count loop Extract_Standard_Output (Args.Get_Argument (I)); end loop; else for I in Context.First_Arg .. Args.Get_Count loop declare Name : constant String := Args.Get_Argument (I); begin if Context.Wallet.Contains (Name) then Extract_File (Name, Command.Output.all); else Extract_Directory (Name, Command.Output.all); end if; end; end loop; end if; end Execute; -- ------------------------------ -- Setup the command before parsing the arguments and executing it. -- ------------------------------ procedure Setup (Command : in out Command_Type; Config : in out GNAT.Command_Line.Command_Line_Configuration; Context : in out Context_Type) is package GC renames GNAT.Command_Line; begin Drivers.Command_Type (Command).Setup (Config, Context); GC.Define_Switch (Config, Command.Output'Access, "-o:", "--output=", -("Store the result in the output file or directory")); GC.Define_Switch (Config => Config, Output => Command.Use_Stdout'Access, Switch => "--", Help => -("Use the standard input to read the content")); end Setup; end AKT.Commands.Extract;
package body GL.Materials is function is_Transparent (Self : Material_type) return Boolean is (Self.diffuse (3) < 1.0); end GL.Materials;
-- A74106C.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- OBJECTIVE: -- CHECK THAT A FULL DECLARATION FOR A PRIVATE TYPE OR FOR A LIMITED -- PRIVATE TYPE CAN BE GIVEN IN TERMS OF ANY SCALAR TYPE, ARRAY -- TYPE, RECORD TYPE (WITH OR WITHOUT DISCRIMINANTS), ACCESS TYPE -- (WITH OR WITHOUT DISCRIMINANTS), OR ANY TYPE DERIVED FROM ANY -- OF THE ABOVE. -- PART C: TYPES INVOLVING FIXED-POINT DATA. -- HISTORY: -- RM 05/11/81 CREATED ORIGINAL TEST. -- DHH 10/15/87 CORRECTED RANGE ERRORS. WITH REPORT; PROCEDURE A74106C IS USE REPORT; BEGIN TEST( "A74106C" , "CHECK THAT PRIVATE TYPES AND LIMITED PRIVATE" & " TYPES CAN BE DEFINED IN TERMS OF" & " FIXED-POINT TYPES" ); DECLARE PACKAGE P0 IS TYPE F0 IS PRIVATE; PRIVATE TYPE F0 IS DELTA 1.0 RANGE 0.0 .. 10.0; END P0; PACKAGE P1 IS USE P0; TYPE FX IS DELTA 0.1 RANGE 0.0 .. 1.0; TYPE F1 IS PRIVATE; TYPE F2 IS PRIVATE; TYPE F3 IS PRIVATE; TYPE F4 IS PRIVATE; TYPE F5 IS PRIVATE; TYPE F6 IS PRIVATE; TYPE F7 IS PRIVATE; TYPE F8 IS PRIVATE; TYPE F9 IS PRIVATE; TYPE FA IS PRIVATE; TYPE FB IS PRIVATE; TYPE FC IS PRIVATE; TYPE NF IS DELTA 0.1 RANGE 1.0 .. 2.0; TYPE ARR_F IS ARRAY(1..2) OF FX; TYPE ACC_F IS ACCESS FX; TYPE REC_F IS RECORD F : FX; END RECORD; TYPE D_REC_F(I : INTEGER := 1) IS RECORD F : FX; END RECORD; PRIVATE TYPE FC IS NEW F0; TYPE F1 IS DELTA 100.0 RANGE -100.0 .. 900.0; TYPE F2 IS NEW FX RANGE 0.0 .. 0.5; TYPE F3 IS NEW NF; TYPE F4 IS ARRAY(1..2) OF FX; TYPE F5 IS NEW ARR_F; TYPE F6 IS ACCESS FX; TYPE F7 IS NEW ACC_F; TYPE F8 IS RECORD F : FX; END RECORD; TYPE F9 IS NEW REC_F; TYPE FA IS ACCESS D_REC_F; TYPE FB IS ACCESS D_REC_F; END P1; BEGIN NULL; END; DECLARE PACKAGE P0 IS TYPE F0 IS LIMITED PRIVATE; PRIVATE TYPE F0 IS DELTA 1.0 RANGE 0.0 .. 10.0; END P0; PACKAGE P1 IS USE P0; TYPE FX IS DELTA 0.1 RANGE 0.0 .. 1.0; TYPE F1 IS LIMITED PRIVATE; TYPE F2 IS LIMITED PRIVATE; TYPE F3 IS LIMITED PRIVATE; TYPE F4 IS LIMITED PRIVATE; TYPE F5 IS LIMITED PRIVATE; TYPE F6 IS LIMITED PRIVATE; TYPE F7 IS LIMITED PRIVATE; TYPE F8 IS LIMITED PRIVATE; TYPE F9 IS LIMITED PRIVATE; TYPE FA IS LIMITED PRIVATE; TYPE FB IS LIMITED PRIVATE; TYPE FC IS LIMITED PRIVATE; TYPE NF IS DELTA 0.1 RANGE 1.0 .. 2.0; TYPE ARR_F IS ARRAY(1..2) OF FX; TYPE ACC_F IS ACCESS FX; TYPE REC_F IS RECORD F : FX; END RECORD; TYPE D_REC_F(I : INTEGER := 1) IS RECORD F : FX; END RECORD; PRIVATE TYPE FC IS NEW F0; TYPE F1 IS DELTA 100.0 RANGE -100.0 .. 900.0; TYPE F2 IS NEW FX RANGE 0.0 .. 0.5; TYPE F3 IS NEW NF; TYPE F4 IS ARRAY(1..2) OF FX; TYPE F5 IS NEW ARR_F; TYPE F6 IS ACCESS FX; TYPE F7 IS NEW ACC_F; TYPE F8 IS RECORD F : FX; END RECORD; TYPE F9 IS NEW REC_F; TYPE FA IS ACCESS D_REC_F; TYPE FB IS ACCESS D_REC_F; END P1; BEGIN NULL; END; RESULT; END A74106C;
-- Ada_GUI implementation based on Gnoga. Adapted 2021 -- -- -- GNOGA - The GNU Omnificent GUI for Ada -- -- -- -- G N O G A . S E R V E R -- -- -- -- S p e c -- -- -- -- -- -- Copyright (C) 2014 David Botton -- -- -- -- This library is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 3, or (at your option) any -- -- later version. This library is distributed in the hope that it will be -- -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are -- -- granted additional permissions described in the GCC Runtime Library -- -- Exception, version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- For more information please go to http://www.gnoga.com -- ------------------------------------------------------------------------------ -- Serverside bindings and tools package Ada_GUI.Gnoga.Server is -- Gnoga applications generally use the following layout. However -- if the executable can be located in App Dir. Any missing standard -- subdirectory will instead use the html root which if missing is -- App Dir. -- -- App Dir -- | -- |___ bin - your Gnoga app binary -- | -- |___ html - boot.html (or other boot loader used) -- | -- |___ js - must contain jquery.min.js -- | -- |___ css - optional, a directory for serving css files -- | -- |___ img - optional, a directory of serving graphics. -- | -- |___ templates - optional, if using Gnoga.Server.Template_Parser -- | -- |___ upload - option, optional directory for incoming files function Directory_Separator return String; -- Return the Directory Separator using for the OS Gnoga is compiled on. function Application_Directory return String; -- This is the root directory for the application. function Executable_Directory return String; -- Locates this application's executable directory -- This is usually in Application_Directory/bin function HTML_Directory return String; -- Locates the applications HTML Root for this application function JS_Directory return String; -- Locates the /js directory for this application function CSS_Directory return String; -- Locates the /css director for this application function IMG_Directory return String; -- Locates the /img directory for this application function Upload_Directory return String; -- Locates the /upload directory for this application function Templates_Directory return String; -- Locates the templates directory for this application -- If not in Application_Directory/templates, tries -- Application_Directory/share/gnoga/templates, if not -- uses Application_Directory end Ada_GUI.Gnoga.Server;
----------------------------------------------------------------------- -- asf-events-faces-actions -- Actions Events -- Copyright (C) 2009, 2010, 2011, 2012, 2013 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- package body ASF.Events.Faces.Actions is -- ------------------------------ -- Get the method expression to invoke -- ------------------------------ function Get_Method (Event : in Action_Event) return EL.Expressions.Method_Expression is begin return Event.Method; end Get_Method; -- ------------------------------ -- Get the method binding with the Ada bean object to invoke. -- ------------------------------ function Get_Method_Info (Event : in Action_Event; Context : in Contexts.Faces.Faces_Context'Class) return EL.Expressions.Method_Info is begin return Event.Method.Get_Method_Info (Context => Context.Get_ELContext.all); end Get_Method_Info; -- ------------------------------ -- Post an <b>Action_Event</b> on the component. -- ------------------------------ procedure Post_Event (UI : in out Components.Base.UIComponent'Class; Method : in EL.Expressions.Method_Expression) is Ev : constant Action_Event_Access := new Action_Event; begin Ev.Phase := ASF.Events.Phases.INVOKE_APPLICATION; Ev.Component := UI'Unchecked_Access; Ev.Method := Method; UI.Queue_Event (Ev.all'Access); end Post_Event; end ASF.Events.Faces.Actions;
generic type Position is (<>); package Garden_Pkg is function GetRandPos return Position; function GetField(pos : Position) return Boolean; procedure Start; task type Gardener; task type Mantis; type Mantis_Access is access Mantis; type Mantis_Array is array (Integer range <>) of Mantis_Access; numberOfMantises : Natural; John : access Gardener; Fields : array(Position) of Boolean; end Garden_Pkg;
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding -- -- -- -- Terminal_Interface.Curses -- -- -- -- B O D Y -- -- -- ------------------------------------------------------------------------------ -- Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining a -- -- copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, distribute with modifications, sublicense, and/or sell -- -- copies of the Software, and to permit persons to whom the Software is -- -- furnished to do so, subject to the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be included -- -- in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Juergen Pfeifer, 1996 -- Version Control: -- $Revision: 1.34 $ -- $Date: 2006/06/25 14:30:22 $ -- Binding Version 01.00 ------------------------------------------------------------------------------ with System; with Terminal_Interface.Curses.Aux; with Interfaces.C; use Interfaces.C; with Interfaces.C.Strings; use Interfaces.C.Strings; with Interfaces.C.Pointers; with Ada.Characters.Handling; use Ada.Characters.Handling; with Ada.Strings.Fixed; with Ada.Unchecked_Conversion; package body Terminal_Interface.Curses is use Aux; use type System.Bit_Order; package ASF renames Ada.Strings.Fixed; type chtype_array is array (size_t range <>) of aliased Attributed_Character; pragma Convention (C, chtype_array); ------------------------------------------------------------------------------ generic type Element is (<>); function W_Get_Element (Win : in Window; Offset : in Natural) return Element; function W_Get_Element (Win : in Window; Offset : in Natural) return Element is type E_Array is array (Natural range <>) of aliased Element; package C_E_Array is new Interfaces.C.Pointers (Natural, Element, E_Array, Element'Val (0)); use C_E_Array; function To_Pointer is new Ada.Unchecked_Conversion (Window, Pointer); P : Pointer := To_Pointer (Win); begin if Win = Null_Window then raise Curses_Exception; else P := P + ptrdiff_t (Offset); return P.all; end if; end W_Get_Element; function W_Get_Int is new W_Get_Element (C_Int); function W_Get_Short is new W_Get_Element (C_Short); function W_Get_Byte is new W_Get_Element (Interfaces.C.unsigned_char); function Get_Flag (Win : Window; Offset : Natural) return Boolean; function Get_Flag (Win : Window; Offset : Natural) return Boolean is Res : C_Int; begin case Sizeof_bool is when 1 => Res := C_Int (W_Get_Byte (Win, Offset)); when 2 => Res := C_Int (W_Get_Short (Win, Offset)); when 4 => Res := C_Int (W_Get_Int (Win, Offset)); when others => raise Curses_Exception; end case; case Res is when 0 => return False; when others => return True; end case; end Get_Flag; ------------------------------------------------------------------------------ function Key_Name (Key : in Real_Key_Code) return String is function Keyname (K : C_Int) return chars_ptr; pragma Import (C, Keyname, "keyname"); Ch : Character; begin if Key <= Character'Pos (Character'Last) then Ch := Character'Val (Key); if Is_Control (Ch) then return Un_Control (Attributed_Character'(Ch => Ch, Color => Color_Pair'First, Attr => Normal_Video)); elsif Is_Graphic (Ch) then declare S : String (1 .. 1); begin S (1) := Ch; return S; end; else return ""; end if; else return Fill_String (Keyname (C_Int (Key))); end if; end Key_Name; procedure Key_Name (Key : in Real_Key_Code; Name : out String) is begin ASF.Move (Key_Name (Key), Name); end Key_Name; ------------------------------------------------------------------------------ procedure Init_Screen is function Initscr return Window; pragma Import (C, Initscr, "initscr"); W : Window; begin W := Initscr; if W = Null_Window then raise Curses_Exception; end if; end Init_Screen; procedure End_Windows is function Endwin return C_Int; pragma Import (C, Endwin, "endwin"); begin if Endwin = Curses_Err then raise Curses_Exception; end if; end End_Windows; function Is_End_Window return Boolean is function Isendwin return Curses_Bool; pragma Import (C, Isendwin, "isendwin"); begin if Isendwin = Curses_Bool_False then return False; else return True; end if; end Is_End_Window; ------------------------------------------------------------------------------ procedure Move_Cursor (Win : in Window := Standard_Window; Line : in Line_Position; Column : in Column_Position) is function Wmove (Win : Window; Line : C_Int; Column : C_Int ) return C_Int; pragma Import (C, Wmove, "wmove"); begin if Wmove (Win, C_Int (Line), C_Int (Column)) = Curses_Err then raise Curses_Exception; end if; end Move_Cursor; ------------------------------------------------------------------------------ procedure Add (Win : in Window := Standard_Window; Ch : in Attributed_Character) is function Waddch (W : Window; Ch : C_Chtype) return C_Int; pragma Import (C, Waddch, "waddch"); begin if Waddch (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then raise Curses_Exception; end if; end Add; procedure Add (Win : in Window := Standard_Window; Ch : in Character) is begin Add (Win, Attributed_Character'(Ch => Ch, Color => Color_Pair'First, Attr => Normal_Video)); end Add; procedure Add (Win : in Window := Standard_Window; Line : in Line_Position; Column : in Column_Position; Ch : in Attributed_Character) is function mvwaddch (W : Window; Y : C_Int; X : C_Int; Ch : C_Chtype) return C_Int; pragma Import (C, mvwaddch, "mvwaddch"); begin if mvwaddch (Win, C_Int (Line), C_Int (Column), AttrChar_To_Chtype (Ch)) = Curses_Err then raise Curses_Exception; end if; end Add; procedure Add (Win : in Window := Standard_Window; Line : in Line_Position; Column : in Column_Position; Ch : in Character) is begin Add (Win, Line, Column, Attributed_Character'(Ch => Ch, Color => Color_Pair'First, Attr => Normal_Video)); end Add; procedure Add_With_Immediate_Echo (Win : in Window := Standard_Window; Ch : in Attributed_Character) is function Wechochar (W : Window; Ch : C_Chtype) return C_Int; pragma Import (C, Wechochar, "wechochar"); begin if Wechochar (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then raise Curses_Exception; end if; end Add_With_Immediate_Echo; procedure Add_With_Immediate_Echo (Win : in Window := Standard_Window; Ch : in Character) is begin Add_With_Immediate_Echo (Win, Attributed_Character'(Ch => Ch, Color => Color_Pair'First, Attr => Normal_Video)); end Add_With_Immediate_Echo; ------------------------------------------------------------------------------ function Create (Number_Of_Lines : Line_Count; Number_Of_Columns : Column_Count; First_Line_Position : Line_Position; First_Column_Position : Column_Position) return Window is function Newwin (Number_Of_Lines : C_Int; Number_Of_Columns : C_Int; First_Line_Position : C_Int; First_Column_Position : C_Int) return Window; pragma Import (C, Newwin, "newwin"); W : Window; begin W := Newwin (C_Int (Number_Of_Lines), C_Int (Number_Of_Columns), C_Int (First_Line_Position), C_Int (First_Column_Position)); if W = Null_Window then raise Curses_Exception; end if; return W; end Create; procedure Delete (Win : in out Window) is function Wdelwin (W : Window) return C_Int; pragma Import (C, Wdelwin, "delwin"); begin if Wdelwin (Win) = Curses_Err then raise Curses_Exception; end if; Win := Null_Window; end Delete; function Sub_Window (Win : Window := Standard_Window; Number_Of_Lines : Line_Count; Number_Of_Columns : Column_Count; First_Line_Position : Line_Position; First_Column_Position : Column_Position) return Window is function Subwin (Win : Window; Number_Of_Lines : C_Int; Number_Of_Columns : C_Int; First_Line_Position : C_Int; First_Column_Position : C_Int) return Window; pragma Import (C, Subwin, "subwin"); W : Window; begin W := Subwin (Win, C_Int (Number_Of_Lines), C_Int (Number_Of_Columns), C_Int (First_Line_Position), C_Int (First_Column_Position)); if W = Null_Window then raise Curses_Exception; end if; return W; end Sub_Window; function Derived_Window (Win : Window := Standard_Window; Number_Of_Lines : Line_Count; Number_Of_Columns : Column_Count; First_Line_Position : Line_Position; First_Column_Position : Column_Position) return Window is function Derwin (Win : Window; Number_Of_Lines : C_Int; Number_Of_Columns : C_Int; First_Line_Position : C_Int; First_Column_Position : C_Int) return Window; pragma Import (C, Derwin, "derwin"); W : Window; begin W := Derwin (Win, C_Int (Number_Of_Lines), C_Int (Number_Of_Columns), C_Int (First_Line_Position), C_Int (First_Column_Position)); if W = Null_Window then raise Curses_Exception; end if; return W; end Derived_Window; function Duplicate (Win : Window) return Window is function Dupwin (Win : Window) return Window; pragma Import (C, Dupwin, "dupwin"); W : constant Window := Dupwin (Win); begin if W = Null_Window then raise Curses_Exception; end if; return W; end Duplicate; procedure Move_Window (Win : in Window; Line : in Line_Position; Column : in Column_Position) is function Mvwin (Win : Window; Line : C_Int; Column : C_Int) return C_Int; pragma Import (C, Mvwin, "mvwin"); begin if Mvwin (Win, C_Int (Line), C_Int (Column)) = Curses_Err then raise Curses_Exception; end if; end Move_Window; procedure Move_Derived_Window (Win : in Window; Line : in Line_Position; Column : in Column_Position) is function Mvderwin (Win : Window; Line : C_Int; Column : C_Int) return C_Int; pragma Import (C, Mvderwin, "mvderwin"); begin if Mvderwin (Win, C_Int (Line), C_Int (Column)) = Curses_Err then raise Curses_Exception; end if; end Move_Derived_Window; procedure Set_Synch_Mode (Win : in Window := Standard_Window; Mode : in Boolean := False) is function Syncok (Win : Window; Mode : Curses_Bool) return C_Int; pragma Import (C, Syncok, "syncok"); begin if Syncok (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then raise Curses_Exception; end if; end Set_Synch_Mode; ------------------------------------------------------------------------------ procedure Add (Win : in Window := Standard_Window; Str : in String; Len : in Integer := -1) is function Waddnstr (Win : Window; Str : char_array; Len : C_Int := -1) return C_Int; pragma Import (C, Waddnstr, "waddnstr"); Txt : char_array (0 .. Str'Length); Length : size_t; begin To_C (Str, Txt, Length); if Waddnstr (Win, Txt, C_Int (Len)) = Curses_Err then raise Curses_Exception; end if; end Add; procedure Add (Win : in Window := Standard_Window; Line : in Line_Position; Column : in Column_Position; Str : in String; Len : in Integer := -1) is begin Move_Cursor (Win, Line, Column); Add (Win, Str, Len); end Add; ------------------------------------------------------------------------------ procedure Add (Win : in Window := Standard_Window; Str : in Attributed_String; Len : in Integer := -1) is function Waddchnstr (Win : Window; Str : chtype_array; Len : C_Int := -1) return C_Int; pragma Import (C, Waddchnstr, "waddchnstr"); Txt : chtype_array (0 .. Str'Length); begin for Length in 1 .. size_t (Str'Length) loop Txt (Length - 1) := Str (Natural (Length)); end loop; Txt (Str'Length) := Default_Character; if Waddchnstr (Win, Txt, C_Int (Len)) = Curses_Err then raise Curses_Exception; end if; end Add; procedure Add (Win : in Window := Standard_Window; Line : in Line_Position; Column : in Column_Position; Str : in Attributed_String; Len : in Integer := -1) is begin Move_Cursor (Win, Line, Column); Add (Win, Str, Len); end Add; ------------------------------------------------------------------------------ procedure Border (Win : in Window := Standard_Window; Left_Side_Symbol : in Attributed_Character := Default_Character; Right_Side_Symbol : in Attributed_Character := Default_Character; Top_Side_Symbol : in Attributed_Character := Default_Character; Bottom_Side_Symbol : in Attributed_Character := Default_Character; Upper_Left_Corner_Symbol : in Attributed_Character := Default_Character; Upper_Right_Corner_Symbol : in Attributed_Character := Default_Character; Lower_Left_Corner_Symbol : in Attributed_Character := Default_Character; Lower_Right_Corner_Symbol : in Attributed_Character := Default_Character) is function Wborder (W : Window; LS : C_Chtype; RS : C_Chtype; TS : C_Chtype; BS : C_Chtype; ULC : C_Chtype; URC : C_Chtype; LLC : C_Chtype; LRC : C_Chtype) return C_Int; pragma Import (C, Wborder, "wborder"); begin if Wborder (Win, AttrChar_To_Chtype (Left_Side_Symbol), AttrChar_To_Chtype (Right_Side_Symbol), AttrChar_To_Chtype (Top_Side_Symbol), AttrChar_To_Chtype (Bottom_Side_Symbol), AttrChar_To_Chtype (Upper_Left_Corner_Symbol), AttrChar_To_Chtype (Upper_Right_Corner_Symbol), AttrChar_To_Chtype (Lower_Left_Corner_Symbol), AttrChar_To_Chtype (Lower_Right_Corner_Symbol) ) = Curses_Err then raise Curses_Exception; end if; end Border; procedure Box (Win : in Window := Standard_Window; Vertical_Symbol : in Attributed_Character := Default_Character; Horizontal_Symbol : in Attributed_Character := Default_Character) is begin Border (Win, Vertical_Symbol, Vertical_Symbol, Horizontal_Symbol, Horizontal_Symbol); end Box; procedure Horizontal_Line (Win : in Window := Standard_Window; Line_Size : in Natural; Line_Symbol : in Attributed_Character := Default_Character) is function Whline (W : Window; Ch : C_Chtype; Len : C_Int) return C_Int; pragma Import (C, Whline, "whline"); begin if Whline (Win, AttrChar_To_Chtype (Line_Symbol), C_Int (Line_Size)) = Curses_Err then raise Curses_Exception; end if; end Horizontal_Line; procedure Vertical_Line (Win : in Window := Standard_Window; Line_Size : in Natural; Line_Symbol : in Attributed_Character := Default_Character) is function Wvline (W : Window; Ch : C_Chtype; Len : C_Int) return C_Int; pragma Import (C, Wvline, "wvline"); begin if Wvline (Win, AttrChar_To_Chtype (Line_Symbol), C_Int (Line_Size)) = Curses_Err then raise Curses_Exception; end if; end Vertical_Line; ------------------------------------------------------------------------------ function Get_Keystroke (Win : Window := Standard_Window) return Real_Key_Code is function Wgetch (W : Window) return C_Int; pragma Import (C, Wgetch, "wgetch"); C : constant C_Int := Wgetch (Win); begin if C = Curses_Err then return Key_None; else return Real_Key_Code (C); end if; end Get_Keystroke; procedure Undo_Keystroke (Key : in Real_Key_Code) is function Ungetch (Ch : C_Int) return C_Int; pragma Import (C, Ungetch, "ungetch"); begin if Ungetch (C_Int (Key)) = Curses_Err then raise Curses_Exception; end if; end Undo_Keystroke; function Has_Key (Key : Special_Key_Code) return Boolean is function Haskey (Key : C_Int) return C_Int; pragma Import (C, Haskey, "has_key"); begin if Haskey (C_Int (Key)) = Curses_False then return False; else return True; end if; end Has_Key; function Is_Function_Key (Key : Special_Key_Code) return Boolean is L : constant Special_Key_Code := Special_Key_Code (Natural (Key_F0) + Natural (Function_Key_Number'Last)); begin if (Key >= Key_F0) and then (Key <= L) then return True; else return False; end if; end Is_Function_Key; function Function_Key (Key : Real_Key_Code) return Function_Key_Number is begin if Is_Function_Key (Key) then return Function_Key_Number (Key - Key_F0); else raise Constraint_Error; end if; end Function_Key; function Function_Key_Code (Key : Function_Key_Number) return Real_Key_Code is begin return Real_Key_Code (Natural (Key_F0) + Natural (Key)); end Function_Key_Code; ------------------------------------------------------------------------------ procedure Standout (Win : Window := Standard_Window; On : Boolean := True) is function wstandout (Win : Window) return C_Int; pragma Import (C, wstandout, "wstandout"); function wstandend (Win : Window) return C_Int; pragma Import (C, wstandend, "wstandend"); Err : C_Int; begin if On then Err := wstandout (Win); else Err := wstandend (Win); end if; if Err = Curses_Err then raise Curses_Exception; end if; end Standout; procedure Switch_Character_Attribute (Win : in Window := Standard_Window; Attr : in Character_Attribute_Set := Normal_Video; On : in Boolean := True) is function Wattron (Win : Window; C_Attr : C_AttrType) return C_Int; pragma Import (C, Wattron, "wattr_on"); function Wattroff (Win : Window; C_Attr : C_AttrType) return C_Int; pragma Import (C, Wattroff, "wattr_off"); -- In Ada we use the On Boolean to control whether or not we want to -- switch on or off the attributes in the set. Err : C_Int; AC : constant Attributed_Character := (Ch => Character'First, Color => Color_Pair'First, Attr => Attr); begin if On then Err := Wattron (Win, AttrChar_To_AttrType (AC)); else Err := Wattroff (Win, AttrChar_To_AttrType (AC)); end if; if Err = Curses_Err then raise Curses_Exception; end if; end Switch_Character_Attribute; procedure Set_Character_Attributes (Win : in Window := Standard_Window; Attr : in Character_Attribute_Set := Normal_Video; Color : in Color_Pair := Color_Pair'First) is function Wattrset (Win : Window; C_Attr : C_AttrType) return C_Int; pragma Import (C, Wattrset, "wattrset"); -- ??? wattr_set begin if Wattrset (Win, AttrChar_To_AttrType (Attributed_Character' (Ch => Character'First, Color => Color, Attr => Attr))) = Curses_Err then raise Curses_Exception; end if; end Set_Character_Attributes; function Get_Character_Attribute (Win : Window := Standard_Window) return Character_Attribute_Set is function Wattrget (Win : Window; Atr : access C_AttrType; Col : access C_Short; Opt : System.Address) return C_Int; pragma Import (C, Wattrget, "wattr_get"); Attr : aliased C_AttrType; Col : aliased C_Short; Res : constant C_Int := Wattrget (Win, Attr'Access, Col'Access, System.Null_Address); Ch : Attributed_Character; begin if Res = Curses_Ok then Ch := AttrType_To_AttrChar (Attr); return Ch.Attr; else raise Curses_Exception; end if; end Get_Character_Attribute; function Get_Character_Attribute (Win : Window := Standard_Window) return Color_Pair is function Wattrget (Win : Window; Atr : access C_AttrType; Col : access C_Short; Opt : System.Address) return C_Int; pragma Import (C, Wattrget, "wattr_get"); Attr : aliased C_AttrType; Col : aliased C_Short; Res : constant C_Int := Wattrget (Win, Attr'Access, Col'Access, System.Null_Address); Ch : Attributed_Character; begin if Res = Curses_Ok then Ch := AttrType_To_AttrChar (Attr); return Ch.Color; else raise Curses_Exception; end if; end Get_Character_Attribute; procedure Set_Color (Win : in Window := Standard_Window; Pair : in Color_Pair) is function Wset_Color (Win : Window; Color : C_Short; Opts : C_Void_Ptr) return C_Int; pragma Import (C, Wset_Color, "wcolor_set"); begin if Wset_Color (Win, C_Short (Pair), C_Void_Ptr (System.Null_Address)) = Curses_Err then raise Curses_Exception; end if; end Set_Color; procedure Change_Attributes (Win : in Window := Standard_Window; Count : in Integer := -1; Attr : in Character_Attribute_Set := Normal_Video; Color : in Color_Pair := Color_Pair'First) is function Wchgat (Win : Window; Cnt : C_Int; Attr : C_AttrType; Color : C_Short; Opts : System.Address := System.Null_Address) return C_Int; pragma Import (C, Wchgat, "wchgat"); Ch : constant Attributed_Character := (Ch => Character'First, Color => Color_Pair'First, Attr => Attr); begin if Wchgat (Win, C_Int (Count), AttrChar_To_AttrType (Ch), C_Short (Color)) = Curses_Err then raise Curses_Exception; end if; end Change_Attributes; procedure Change_Attributes (Win : in Window := Standard_Window; Line : in Line_Position := Line_Position'First; Column : in Column_Position := Column_Position'First; Count : in Integer := -1; Attr : in Character_Attribute_Set := Normal_Video; Color : in Color_Pair := Color_Pair'First) is begin Move_Cursor (Win, Line, Column); Change_Attributes (Win, Count, Attr, Color); end Change_Attributes; ------------------------------------------------------------------------------ procedure Beep is function Beeper return C_Int; pragma Import (C, Beeper, "beep"); begin if Beeper = Curses_Err then raise Curses_Exception; end if; end Beep; procedure Flash_Screen is function Flash return C_Int; pragma Import (C, Flash, "flash"); begin if Flash = Curses_Err then raise Curses_Exception; end if; end Flash_Screen; ------------------------------------------------------------------------------ procedure Set_Cbreak_Mode (SwitchOn : in Boolean := True) is function Cbreak return C_Int; pragma Import (C, Cbreak, "cbreak"); function NoCbreak return C_Int; pragma Import (C, NoCbreak, "nocbreak"); Err : C_Int; begin if SwitchOn then Err := Cbreak; else Err := NoCbreak; end if; if Err = Curses_Err then raise Curses_Exception; end if; end Set_Cbreak_Mode; procedure Set_Raw_Mode (SwitchOn : in Boolean := True) is function Raw return C_Int; pragma Import (C, Raw, "raw"); function NoRaw return C_Int; pragma Import (C, NoRaw, "noraw"); Err : C_Int; begin if SwitchOn then Err := Raw; else Err := NoRaw; end if; if Err = Curses_Err then raise Curses_Exception; end if; end Set_Raw_Mode; procedure Set_Echo_Mode (SwitchOn : in Boolean := True) is function Echo return C_Int; pragma Import (C, Echo, "echo"); function NoEcho return C_Int; pragma Import (C, NoEcho, "noecho"); Err : C_Int; begin if SwitchOn then Err := Echo; else Err := NoEcho; end if; if Err = Curses_Err then raise Curses_Exception; end if; end Set_Echo_Mode; procedure Set_Meta_Mode (Win : in Window := Standard_Window; SwitchOn : in Boolean := True) is function Meta (W : Window; Mode : Curses_Bool) return C_Int; pragma Import (C, Meta, "meta"); begin if Meta (Win, Curses_Bool (Boolean'Pos (SwitchOn))) = Curses_Err then raise Curses_Exception; end if; end Set_Meta_Mode; procedure Set_KeyPad_Mode (Win : in Window := Standard_Window; SwitchOn : in Boolean := True) is function Keypad (W : Window; Mode : Curses_Bool) return C_Int; pragma Import (C, Keypad, "keypad"); begin if Keypad (Win, Curses_Bool (Boolean'Pos (SwitchOn))) = Curses_Err then raise Curses_Exception; end if; end Set_KeyPad_Mode; function Get_KeyPad_Mode (Win : in Window := Standard_Window) return Boolean is begin return Get_Flag (Win, Offset_use_keypad); end Get_KeyPad_Mode; procedure Half_Delay (Amount : in Half_Delay_Amount) is function Halfdelay (Amount : C_Int) return C_Int; pragma Import (C, Halfdelay, "halfdelay"); begin if Halfdelay (C_Int (Amount)) = Curses_Err then raise Curses_Exception; end if; end Half_Delay; procedure Set_Flush_On_Interrupt_Mode (Win : in Window := Standard_Window; Mode : in Boolean := True) is function Intrflush (Win : Window; Mode : Curses_Bool) return C_Int; pragma Import (C, Intrflush, "intrflush"); begin if Intrflush (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then raise Curses_Exception; end if; end Set_Flush_On_Interrupt_Mode; procedure Set_Queue_Interrupt_Mode (Win : in Window := Standard_Window; Flush : in Boolean := True) is procedure Qiflush; pragma Import (C, Qiflush, "qiflush"); procedure No_Qiflush; pragma Import (C, No_Qiflush, "noqiflush"); begin if Win = Null_Window then raise Curses_Exception; end if; if Flush then Qiflush; else No_Qiflush; end if; end Set_Queue_Interrupt_Mode; procedure Set_NoDelay_Mode (Win : in Window := Standard_Window; Mode : in Boolean := False) is function Nodelay (Win : Window; Mode : Curses_Bool) return C_Int; pragma Import (C, Nodelay, "nodelay"); begin if Nodelay (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then raise Curses_Exception; end if; end Set_NoDelay_Mode; procedure Set_Timeout_Mode (Win : in Window := Standard_Window; Mode : in Timeout_Mode; Amount : in Natural) is function Wtimeout (Win : Window; Amount : C_Int) return C_Int; pragma Import (C, Wtimeout, "wtimeout"); Time : C_Int; begin case Mode is when Blocking => Time := -1; when Non_Blocking => Time := 0; when Delayed => if Amount = 0 then raise Constraint_Error; end if; Time := C_Int (Amount); end case; if Wtimeout (Win, Time) = Curses_Err then raise Curses_Exception; end if; end Set_Timeout_Mode; procedure Set_Escape_Timer_Mode (Win : in Window := Standard_Window; Timer_Off : in Boolean := False) is function Notimeout (Win : Window; Mode : Curses_Bool) return C_Int; pragma Import (C, Notimeout, "notimeout"); begin if Notimeout (Win, Curses_Bool (Boolean'Pos (Timer_Off))) = Curses_Err then raise Curses_Exception; end if; end Set_Escape_Timer_Mode; ------------------------------------------------------------------------------ procedure Set_NL_Mode (SwitchOn : in Boolean := True) is function NL return C_Int; pragma Import (C, NL, "nl"); function NoNL return C_Int; pragma Import (C, NoNL, "nonl"); Err : C_Int; begin if SwitchOn then Err := NL; else Err := NoNL; end if; if Err = Curses_Err then raise Curses_Exception; end if; end Set_NL_Mode; procedure Clear_On_Next_Update (Win : in Window := Standard_Window; Do_Clear : in Boolean := True) is function Clear_Ok (W : Window; Flag : Curses_Bool) return C_Int; pragma Import (C, Clear_Ok, "clearok"); begin if Clear_Ok (Win, Curses_Bool (Boolean'Pos (Do_Clear))) = Curses_Err then raise Curses_Exception; end if; end Clear_On_Next_Update; procedure Use_Insert_Delete_Line (Win : in Window := Standard_Window; Do_Idl : in Boolean := True) is function IDL_Ok (W : Window; Flag : Curses_Bool) return C_Int; pragma Import (C, IDL_Ok, "idlok"); begin if IDL_Ok (Win, Curses_Bool (Boolean'Pos (Do_Idl))) = Curses_Err then raise Curses_Exception; end if; end Use_Insert_Delete_Line; procedure Use_Insert_Delete_Character (Win : in Window := Standard_Window; Do_Idc : in Boolean := True) is function IDC_Ok (W : Window; Flag : Curses_Bool) return C_Int; pragma Import (C, IDC_Ok, "idcok"); begin if IDC_Ok (Win, Curses_Bool (Boolean'Pos (Do_Idc))) = Curses_Err then raise Curses_Exception; end if; end Use_Insert_Delete_Character; procedure Leave_Cursor_After_Update (Win : in Window := Standard_Window; Do_Leave : in Boolean := True) is function Leave_Ok (W : Window; Flag : Curses_Bool) return C_Int; pragma Import (C, Leave_Ok, "leaveok"); begin if Leave_Ok (Win, Curses_Bool (Boolean'Pos (Do_Leave))) = Curses_Err then raise Curses_Exception; end if; end Leave_Cursor_After_Update; procedure Immediate_Update_Mode (Win : in Window := Standard_Window; Mode : in Boolean := False) is function Immedok (Win : Window; Mode : Curses_Bool) return C_Int; pragma Import (C, Immedok, "immedok"); begin if Immedok (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then raise Curses_Exception; end if; end Immediate_Update_Mode; procedure Allow_Scrolling (Win : in Window := Standard_Window; Mode : in Boolean := False) is function Scrollok (Win : Window; Mode : Curses_Bool) return C_Int; pragma Import (C, Scrollok, "scrollok"); begin if Scrollok (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then raise Curses_Exception; end if; end Allow_Scrolling; function Scrolling_Allowed (Win : Window := Standard_Window) return Boolean is begin return Get_Flag (Win, Offset_scroll); end Scrolling_Allowed; procedure Set_Scroll_Region (Win : in Window := Standard_Window; Top_Line : in Line_Position; Bottom_Line : in Line_Position) is function Wsetscrreg (Win : Window; Lin : C_Int; Col : C_Int) return C_Int; pragma Import (C, Wsetscrreg, "wsetscrreg"); begin if Wsetscrreg (Win, C_Int (Top_Line), C_Int (Bottom_Line)) = Curses_Err then raise Curses_Exception; end if; end Set_Scroll_Region; ------------------------------------------------------------------------------ procedure Update_Screen is function Do_Update return C_Int; pragma Import (C, Do_Update, "doupdate"); begin if Do_Update = Curses_Err then raise Curses_Exception; end if; end Update_Screen; procedure Refresh (Win : in Window := Standard_Window) is function Wrefresh (W : Window) return C_Int; pragma Import (C, Wrefresh, "wrefresh"); begin if Wrefresh (Win) = Curses_Err then raise Curses_Exception; end if; end Refresh; procedure Refresh_Without_Update (Win : in Window := Standard_Window) is function Wnoutrefresh (W : Window) return C_Int; pragma Import (C, Wnoutrefresh, "wnoutrefresh"); begin if Wnoutrefresh (Win) = Curses_Err then raise Curses_Exception; end if; end Refresh_Without_Update; procedure Redraw (Win : in Window := Standard_Window) is function Redrawwin (Win : Window) return C_Int; pragma Import (C, Redrawwin, "redrawwin"); begin if Redrawwin (Win) = Curses_Err then raise Curses_Exception; end if; end Redraw; procedure Redraw (Win : in Window := Standard_Window; Begin_Line : in Line_Position; Line_Count : in Positive) is function Wredrawln (Win : Window; First : C_Int; Cnt : C_Int) return C_Int; pragma Import (C, Wredrawln, "wredrawln"); begin if Wredrawln (Win, C_Int (Begin_Line), C_Int (Line_Count)) = Curses_Err then raise Curses_Exception; end if; end Redraw; ------------------------------------------------------------------------------ procedure Erase (Win : in Window := Standard_Window) is function Werase (W : Window) return C_Int; pragma Import (C, Werase, "werase"); begin if Werase (Win) = Curses_Err then raise Curses_Exception; end if; end Erase; procedure Clear (Win : in Window := Standard_Window) is function Wclear (W : Window) return C_Int; pragma Import (C, Wclear, "wclear"); begin if Wclear (Win) = Curses_Err then raise Curses_Exception; end if; end Clear; procedure Clear_To_End_Of_Screen (Win : in Window := Standard_Window) is function Wclearbot (W : Window) return C_Int; pragma Import (C, Wclearbot, "wclrtobot"); begin if Wclearbot (Win) = Curses_Err then raise Curses_Exception; end if; end Clear_To_End_Of_Screen; procedure Clear_To_End_Of_Line (Win : in Window := Standard_Window) is function Wcleareol (W : Window) return C_Int; pragma Import (C, Wcleareol, "wclrtoeol"); begin if Wcleareol (Win) = Curses_Err then raise Curses_Exception; end if; end Clear_To_End_Of_Line; ------------------------------------------------------------------------------ procedure Set_Background (Win : in Window := Standard_Window; Ch : in Attributed_Character) is procedure WBackground (W : in Window; Ch : in C_Chtype); pragma Import (C, WBackground, "wbkgdset"); begin WBackground (Win, AttrChar_To_Chtype (Ch)); end Set_Background; procedure Change_Background (Win : in Window := Standard_Window; Ch : in Attributed_Character) is function WChangeBkgd (W : Window; Ch : C_Chtype) return C_Int; pragma Import (C, WChangeBkgd, "wbkgd"); begin if WChangeBkgd (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then raise Curses_Exception; end if; end Change_Background; function Get_Background (Win : Window := Standard_Window) return Attributed_Character is function Wgetbkgd (Win : Window) return C_Chtype; pragma Import (C, Wgetbkgd, "getbkgd"); begin return Chtype_To_AttrChar (Wgetbkgd (Win)); end Get_Background; ------------------------------------------------------------------------------ procedure Change_Lines_Status (Win : in Window := Standard_Window; Start : in Line_Position; Count : in Positive; State : in Boolean) is function Wtouchln (Win : Window; Sta : C_Int; Cnt : C_Int; Chg : C_Int) return C_Int; pragma Import (C, Wtouchln, "wtouchln"); begin if Wtouchln (Win, C_Int (Start), C_Int (Count), C_Int (Boolean'Pos (State))) = Curses_Err then raise Curses_Exception; end if; end Change_Lines_Status; procedure Touch (Win : in Window := Standard_Window) is Y : Line_Position; X : Column_Position; begin Get_Size (Win, Y, X); Change_Lines_Status (Win, 0, Positive (Y), True); end Touch; procedure Untouch (Win : in Window := Standard_Window) is Y : Line_Position; X : Column_Position; begin Get_Size (Win, Y, X); Change_Lines_Status (Win, 0, Positive (Y), False); end Untouch; procedure Touch (Win : in Window := Standard_Window; Start : in Line_Position; Count : in Positive) is begin Change_Lines_Status (Win, Start, Count, True); end Touch; function Is_Touched (Win : Window := Standard_Window; Line : Line_Position) return Boolean is function WLineTouched (W : Window; L : C_Int) return Curses_Bool; pragma Import (C, WLineTouched, "is_linetouched"); begin if WLineTouched (Win, C_Int (Line)) = Curses_Bool_False then return False; else return True; end if; end Is_Touched; function Is_Touched (Win : Window := Standard_Window) return Boolean is function WWinTouched (W : Window) return Curses_Bool; pragma Import (C, WWinTouched, "is_wintouched"); begin if WWinTouched (Win) = Curses_Bool_False then return False; else return True; end if; end Is_Touched; ------------------------------------------------------------------------------ procedure Copy (Source_Window : in Window; Destination_Window : in Window; Source_Top_Row : in Line_Position; Source_Left_Column : in Column_Position; Destination_Top_Row : in Line_Position; Destination_Left_Column : in Column_Position; Destination_Bottom_Row : in Line_Position; Destination_Right_Column : in Column_Position; Non_Destructive_Mode : in Boolean := True) is function Copywin (Src : Window; Dst : Window; Str : C_Int; Slc : C_Int; Dtr : C_Int; Dlc : C_Int; Dbr : C_Int; Drc : C_Int; Ndm : C_Int) return C_Int; pragma Import (C, Copywin, "copywin"); begin if Copywin (Source_Window, Destination_Window, C_Int (Source_Top_Row), C_Int (Source_Left_Column), C_Int (Destination_Top_Row), C_Int (Destination_Left_Column), C_Int (Destination_Bottom_Row), C_Int (Destination_Right_Column), Boolean'Pos (Non_Destructive_Mode) ) = Curses_Err then raise Curses_Exception; end if; end Copy; procedure Overwrite (Source_Window : in Window; Destination_Window : in Window) is function Overwrite (Src : Window; Dst : Window) return C_Int; pragma Import (C, Overwrite, "overwrite"); begin if Overwrite (Source_Window, Destination_Window) = Curses_Err then raise Curses_Exception; end if; end Overwrite; procedure Overlay (Source_Window : in Window; Destination_Window : in Window) is function Overlay (Src : Window; Dst : Window) return C_Int; pragma Import (C, Overlay, "overlay"); begin if Overlay (Source_Window, Destination_Window) = Curses_Err then raise Curses_Exception; end if; end Overlay; ------------------------------------------------------------------------------ procedure Insert_Delete_Lines (Win : in Window := Standard_Window; Lines : in Integer := 1) -- default is to insert one line above is function Winsdelln (W : Window; N : C_Int) return C_Int; pragma Import (C, Winsdelln, "winsdelln"); begin if Winsdelln (Win, C_Int (Lines)) = Curses_Err then raise Curses_Exception; end if; end Insert_Delete_Lines; procedure Delete_Line (Win : in Window := Standard_Window) is begin Insert_Delete_Lines (Win, -1); end Delete_Line; procedure Insert_Line (Win : in Window := Standard_Window) is begin Insert_Delete_Lines (Win, 1); end Insert_Line; ------------------------------------------------------------------------------ procedure Get_Size (Win : in Window := Standard_Window; Number_Of_Lines : out Line_Count; Number_Of_Columns : out Column_Count) is -- Please note: in ncurses they are one off. -- This might be different in other implementations of curses Y : constant C_Int := C_Int (W_Get_Short (Win, Offset_maxy)) + C_Int (Offset_XY); X : constant C_Int := C_Int (W_Get_Short (Win, Offset_maxx)) + C_Int (Offset_XY); begin Number_Of_Lines := Line_Count (Y); Number_Of_Columns := Column_Count (X); end Get_Size; procedure Get_Window_Position (Win : in Window := Standard_Window; Top_Left_Line : out Line_Position; Top_Left_Column : out Column_Position) is Y : constant C_Short := W_Get_Short (Win, Offset_begy); X : constant C_Short := W_Get_Short (Win, Offset_begx); begin Top_Left_Line := Line_Position (Y); Top_Left_Column := Column_Position (X); end Get_Window_Position; procedure Get_Cursor_Position (Win : in Window := Standard_Window; Line : out Line_Position; Column : out Column_Position) is Y : constant C_Short := W_Get_Short (Win, Offset_cury); X : constant C_Short := W_Get_Short (Win, Offset_curx); begin Line := Line_Position (Y); Column := Column_Position (X); end Get_Cursor_Position; procedure Get_Origin_Relative_To_Parent (Win : in Window; Top_Left_Line : out Line_Position; Top_Left_Column : out Column_Position; Is_Not_A_Subwindow : out Boolean) is Y : constant C_Int := W_Get_Int (Win, Offset_pary); X : constant C_Int := W_Get_Int (Win, Offset_parx); begin if Y = -1 then Top_Left_Line := Line_Position'Last; Top_Left_Column := Column_Position'Last; Is_Not_A_Subwindow := True; else Top_Left_Line := Line_Position (Y); Top_Left_Column := Column_Position (X); Is_Not_A_Subwindow := False; end if; end Get_Origin_Relative_To_Parent; ------------------------------------------------------------------------------ function New_Pad (Lines : Line_Count; Columns : Column_Count) return Window is function Newpad (Lines : C_Int; Columns : C_Int) return Window; pragma Import (C, Newpad, "newpad"); W : Window; begin W := Newpad (C_Int (Lines), C_Int (Columns)); if W = Null_Window then raise Curses_Exception; end if; return W; end New_Pad; function Sub_Pad (Pad : Window; Number_Of_Lines : Line_Count; Number_Of_Columns : Column_Count; First_Line_Position : Line_Position; First_Column_Position : Column_Position) return Window is function Subpad (Pad : Window; Number_Of_Lines : C_Int; Number_Of_Columns : C_Int; First_Line_Position : C_Int; First_Column_Position : C_Int) return Window; pragma Import (C, Subpad, "subpad"); W : Window; begin W := Subpad (Pad, C_Int (Number_Of_Lines), C_Int (Number_Of_Columns), C_Int (First_Line_Position), C_Int (First_Column_Position)); if W = Null_Window then raise Curses_Exception; end if; return W; end Sub_Pad; procedure Refresh (Pad : in Window; Source_Top_Row : in Line_Position; Source_Left_Column : in Column_Position; Destination_Top_Row : in Line_Position; Destination_Left_Column : in Column_Position; Destination_Bottom_Row : in Line_Position; Destination_Right_Column : in Column_Position) is function Prefresh (Pad : Window; Source_Top_Row : C_Int; Source_Left_Column : C_Int; Destination_Top_Row : C_Int; Destination_Left_Column : C_Int; Destination_Bottom_Row : C_Int; Destination_Right_Column : C_Int) return C_Int; pragma Import (C, Prefresh, "prefresh"); begin if Prefresh (Pad, C_Int (Source_Top_Row), C_Int (Source_Left_Column), C_Int (Destination_Top_Row), C_Int (Destination_Left_Column), C_Int (Destination_Bottom_Row), C_Int (Destination_Right_Column)) = Curses_Err then raise Curses_Exception; end if; end Refresh; procedure Refresh_Without_Update (Pad : in Window; Source_Top_Row : in Line_Position; Source_Left_Column : in Column_Position; Destination_Top_Row : in Line_Position; Destination_Left_Column : in Column_Position; Destination_Bottom_Row : in Line_Position; Destination_Right_Column : in Column_Position) is function Pnoutrefresh (Pad : Window; Source_Top_Row : C_Int; Source_Left_Column : C_Int; Destination_Top_Row : C_Int; Destination_Left_Column : C_Int; Destination_Bottom_Row : C_Int; Destination_Right_Column : C_Int) return C_Int; pragma Import (C, Pnoutrefresh, "pnoutrefresh"); begin if Pnoutrefresh (Pad, C_Int (Source_Top_Row), C_Int (Source_Left_Column), C_Int (Destination_Top_Row), C_Int (Destination_Left_Column), C_Int (Destination_Bottom_Row), C_Int (Destination_Right_Column)) = Curses_Err then raise Curses_Exception; end if; end Refresh_Without_Update; procedure Add_Character_To_Pad_And_Echo_It (Pad : in Window; Ch : in Attributed_Character) is function Pechochar (Pad : Window; Ch : C_Chtype) return C_Int; pragma Import (C, Pechochar, "pechochar"); begin if Pechochar (Pad, AttrChar_To_Chtype (Ch)) = Curses_Err then raise Curses_Exception; end if; end Add_Character_To_Pad_And_Echo_It; procedure Add_Character_To_Pad_And_Echo_It (Pad : in Window; Ch : in Character) is begin Add_Character_To_Pad_And_Echo_It (Pad, Attributed_Character'(Ch => Ch, Color => Color_Pair'First, Attr => Normal_Video)); end Add_Character_To_Pad_And_Echo_It; ------------------------------------------------------------------------------ procedure Scroll (Win : in Window := Standard_Window; Amount : in Integer := 1) is function Wscrl (Win : Window; N : C_Int) return C_Int; pragma Import (C, Wscrl, "wscrl"); begin if Wscrl (Win, C_Int (Amount)) = Curses_Err then raise Curses_Exception; end if; end Scroll; ------------------------------------------------------------------------------ procedure Delete_Character (Win : in Window := Standard_Window) is function Wdelch (Win : Window) return C_Int; pragma Import (C, Wdelch, "wdelch"); begin if Wdelch (Win) = Curses_Err then raise Curses_Exception; end if; end Delete_Character; procedure Delete_Character (Win : in Window := Standard_Window; Line : in Line_Position; Column : in Column_Position) is function Mvwdelch (Win : Window; Lin : C_Int; Col : C_Int) return C_Int; pragma Import (C, Mvwdelch, "mvwdelch"); begin if Mvwdelch (Win, C_Int (Line), C_Int (Column)) = Curses_Err then raise Curses_Exception; end if; end Delete_Character; ------------------------------------------------------------------------------ function Peek (Win : Window := Standard_Window) return Attributed_Character is function Winch (Win : Window) return C_Chtype; pragma Import (C, Winch, "winch"); begin return Chtype_To_AttrChar (Winch (Win)); end Peek; function Peek (Win : Window := Standard_Window; Line : Line_Position; Column : Column_Position) return Attributed_Character is function Mvwinch (Win : Window; Lin : C_Int; Col : C_Int) return C_Chtype; pragma Import (C, Mvwinch, "mvwinch"); begin return Chtype_To_AttrChar (Mvwinch (Win, C_Int (Line), C_Int (Column))); end Peek; ------------------------------------------------------------------------------ procedure Insert (Win : in Window := Standard_Window; Ch : in Attributed_Character) is function Winsch (Win : Window; Ch : C_Chtype) return C_Int; pragma Import (C, Winsch, "winsch"); begin if Winsch (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then raise Curses_Exception; end if; end Insert; procedure Insert (Win : in Window := Standard_Window; Line : in Line_Position; Column : in Column_Position; Ch : in Attributed_Character) is function Mvwinsch (Win : Window; Lin : C_Int; Col : C_Int; Ch : C_Chtype) return C_Int; pragma Import (C, Mvwinsch, "mvwinsch"); begin if Mvwinsch (Win, C_Int (Line), C_Int (Column), AttrChar_To_Chtype (Ch)) = Curses_Err then raise Curses_Exception; end if; end Insert; ------------------------------------------------------------------------------ procedure Insert (Win : in Window := Standard_Window; Str : in String; Len : in Integer := -1) is function Winsnstr (Win : Window; Str : char_array; Len : Integer := -1) return C_Int; pragma Import (C, Winsnstr, "winsnstr"); Txt : char_array (0 .. Str'Length); Length : size_t; begin To_C (Str, Txt, Length); if Winsnstr (Win, Txt, Len) = Curses_Err then raise Curses_Exception; end if; end Insert; procedure Insert (Win : in Window := Standard_Window; Line : in Line_Position; Column : in Column_Position; Str : in String; Len : in Integer := -1) is function Mvwinsnstr (Win : Window; Line : C_Int; Column : C_Int; Str : char_array; Len : C_Int) return C_Int; pragma Import (C, Mvwinsnstr, "mvwinsnstr"); Txt : char_array (0 .. Str'Length); Length : size_t; begin To_C (Str, Txt, Length); if Mvwinsnstr (Win, C_Int (Line), C_Int (Column), Txt, C_Int (Len)) = Curses_Err then raise Curses_Exception; end if; end Insert; ------------------------------------------------------------------------------ procedure Peek (Win : in Window := Standard_Window; Str : out String; Len : in Integer := -1) is function Winnstr (Win : Window; Str : char_array; Len : C_Int) return C_Int; pragma Import (C, Winnstr, "winnstr"); N : Integer := Len; Txt : char_array (0 .. Str'Length); Cnt : Natural; begin if N < 0 then N := Str'Length; end if; if N > Str'Length then raise Constraint_Error; end if; Txt (0) := Interfaces.C.char'First; if Winnstr (Win, Txt, C_Int (N)) = Curses_Err then raise Curses_Exception; end if; To_Ada (Txt, Str, Cnt, True); if Cnt < Str'Length then Str ((Str'First + Cnt) .. Str'Last) := (others => ' '); end if; end Peek; procedure Peek (Win : in Window := Standard_Window; Line : in Line_Position; Column : in Column_Position; Str : out String; Len : in Integer := -1) is begin Move_Cursor (Win, Line, Column); Peek (Win, Str, Len); end Peek; ------------------------------------------------------------------------------ procedure Peek (Win : in Window := Standard_Window; Str : out Attributed_String; Len : in Integer := -1) is function Winchnstr (Win : Window; Str : chtype_array; -- out Len : C_Int) return C_Int; pragma Import (C, Winchnstr, "winchnstr"); N : Integer := Len; Txt : constant chtype_array (0 .. Str'Length) := (0 => Default_Character); Cnt : Natural := 0; begin if N < 0 then N := Str'Length; end if; if N > Str'Length then raise Constraint_Error; end if; if Winchnstr (Win, Txt, C_Int (N)) = Curses_Err then raise Curses_Exception; end if; for To in Str'Range loop exit when Txt (size_t (Cnt)) = Default_Character; Str (To) := Txt (size_t (Cnt)); Cnt := Cnt + 1; end loop; if Cnt < Str'Length then Str ((Str'First + Cnt) .. Str'Last) := (others => (Ch => ' ', Color => Color_Pair'First, Attr => Normal_Video)); end if; end Peek; procedure Peek (Win : in Window := Standard_Window; Line : in Line_Position; Column : in Column_Position; Str : out Attributed_String; Len : in Integer := -1) is begin Move_Cursor (Win, Line, Column); Peek (Win, Str, Len); end Peek; ------------------------------------------------------------------------------ procedure Get (Win : in Window := Standard_Window; Str : out String; Len : in Integer := -1) is function Wgetnstr (Win : Window; Str : char_array; Len : C_Int) return C_Int; pragma Import (C, Wgetnstr, "wgetnstr"); N : Integer := Len; Txt : char_array (0 .. Str'Length); Cnt : Natural; begin if N < 0 then N := Str'Length; end if; if N > Str'Length then raise Constraint_Error; end if; Txt (0) := Interfaces.C.char'First; if Wgetnstr (Win, Txt, C_Int (N)) = Curses_Err then raise Curses_Exception; end if; To_Ada (Txt, Str, Cnt, True); if Cnt < Str'Length then Str ((Str'First + Cnt) .. Str'Last) := (others => ' '); end if; end Get; procedure Get (Win : in Window := Standard_Window; Line : in Line_Position; Column : in Column_Position; Str : out String; Len : in Integer := -1) is begin Move_Cursor (Win, Line, Column); Get (Win, Str, Len); end Get; ------------------------------------------------------------------------------ procedure Init_Soft_Label_Keys (Format : in Soft_Label_Key_Format := Three_Two_Three) is function Slk_Init (Fmt : C_Int) return C_Int; pragma Import (C, Slk_Init, "slk_init"); begin if Slk_Init (Soft_Label_Key_Format'Pos (Format)) = Curses_Err then raise Curses_Exception; end if; end Init_Soft_Label_Keys; procedure Set_Soft_Label_Key (Label : in Label_Number; Text : in String; Fmt : in Label_Justification := Left) is function Slk_Set (Label : C_Int; Txt : char_array; Fmt : C_Int) return C_Int; pragma Import (C, Slk_Set, "slk_set"); Txt : char_array (0 .. Text'Length); Len : size_t; begin To_C (Text, Txt, Len); if Slk_Set (C_Int (Label), Txt, C_Int (Label_Justification'Pos (Fmt))) = Curses_Err then raise Curses_Exception; end if; end Set_Soft_Label_Key; procedure Refresh_Soft_Label_Keys is function Slk_Refresh return C_Int; pragma Import (C, Slk_Refresh, "slk_refresh"); begin if Slk_Refresh = Curses_Err then raise Curses_Exception; end if; end Refresh_Soft_Label_Keys; procedure Refresh_Soft_Label_Keys_Without_Update is function Slk_Noutrefresh return C_Int; pragma Import (C, Slk_Noutrefresh, "slk_noutrefresh"); begin if Slk_Noutrefresh = Curses_Err then raise Curses_Exception; end if; end Refresh_Soft_Label_Keys_Without_Update; procedure Get_Soft_Label_Key (Label : in Label_Number; Text : out String) is function Slk_Label (Label : C_Int) return chars_ptr; pragma Import (C, Slk_Label, "slk_label"); begin Fill_String (Slk_Label (C_Int (Label)), Text); end Get_Soft_Label_Key; function Get_Soft_Label_Key (Label : in Label_Number) return String is function Slk_Label (Label : C_Int) return chars_ptr; pragma Import (C, Slk_Label, "slk_label"); begin return Fill_String (Slk_Label (C_Int (Label))); end Get_Soft_Label_Key; procedure Clear_Soft_Label_Keys is function Slk_Clear return C_Int; pragma Import (C, Slk_Clear, "slk_clear"); begin if Slk_Clear = Curses_Err then raise Curses_Exception; end if; end Clear_Soft_Label_Keys; procedure Restore_Soft_Label_Keys is function Slk_Restore return C_Int; pragma Import (C, Slk_Restore, "slk_restore"); begin if Slk_Restore = Curses_Err then raise Curses_Exception; end if; end Restore_Soft_Label_Keys; procedure Touch_Soft_Label_Keys is function Slk_Touch return C_Int; pragma Import (C, Slk_Touch, "slk_touch"); begin if Slk_Touch = Curses_Err then raise Curses_Exception; end if; end Touch_Soft_Label_Keys; procedure Switch_Soft_Label_Key_Attributes (Attr : in Character_Attribute_Set; On : in Boolean := True) is function Slk_Attron (Ch : C_Chtype) return C_Int; pragma Import (C, Slk_Attron, "slk_attron"); function Slk_Attroff (Ch : C_Chtype) return C_Int; pragma Import (C, Slk_Attroff, "slk_attroff"); Err : C_Int; Ch : constant Attributed_Character := (Ch => Character'First, Attr => Attr, Color => Color_Pair'First); begin if On then Err := Slk_Attron (AttrChar_To_Chtype (Ch)); else Err := Slk_Attroff (AttrChar_To_Chtype (Ch)); end if; if Err = Curses_Err then raise Curses_Exception; end if; end Switch_Soft_Label_Key_Attributes; procedure Set_Soft_Label_Key_Attributes (Attr : in Character_Attribute_Set := Normal_Video; Color : in Color_Pair := Color_Pair'First) is function Slk_Attrset (Ch : C_Chtype) return C_Int; pragma Import (C, Slk_Attrset, "slk_attrset"); Ch : constant Attributed_Character := (Ch => Character'First, Attr => Attr, Color => Color); begin if Slk_Attrset (AttrChar_To_Chtype (Ch)) = Curses_Err then raise Curses_Exception; end if; end Set_Soft_Label_Key_Attributes; function Get_Soft_Label_Key_Attributes return Character_Attribute_Set is function Slk_Attr return C_Chtype; pragma Import (C, Slk_Attr, "slk_attr"); Attr : constant C_Chtype := Slk_Attr; begin return Chtype_To_AttrChar (Attr).Attr; end Get_Soft_Label_Key_Attributes; function Get_Soft_Label_Key_Attributes return Color_Pair is function Slk_Attr return C_Chtype; pragma Import (C, Slk_Attr, "slk_attr"); Attr : constant C_Chtype := Slk_Attr; begin return Chtype_To_AttrChar (Attr).Color; end Get_Soft_Label_Key_Attributes; procedure Set_Soft_Label_Key_Color (Pair : in Color_Pair) is function Slk_Color (Color : in C_Short) return C_Int; pragma Import (C, Slk_Color, "slk_color"); begin if Slk_Color (C_Short (Pair)) = Curses_Err then raise Curses_Exception; end if; end Set_Soft_Label_Key_Color; ------------------------------------------------------------------------------ procedure Enable_Key (Key : in Special_Key_Code; Enable : in Boolean := True) is function Keyok (Keycode : C_Int; On_Off : Curses_Bool) return C_Int; pragma Import (C, Keyok, "keyok"); begin if Keyok (C_Int (Key), Curses_Bool (Boolean'Pos (Enable))) = Curses_Err then raise Curses_Exception; end if; end Enable_Key; ------------------------------------------------------------------------------ procedure Define_Key (Definition : in String; Key : in Special_Key_Code) is function Defkey (Def : char_array; Key : C_Int) return C_Int; pragma Import (C, Defkey, "define_key"); Txt : char_array (0 .. Definition'Length); Length : size_t; begin To_C (Definition, Txt, Length); if Defkey (Txt, C_Int (Key)) = Curses_Err then raise Curses_Exception; end if; end Define_Key; ------------------------------------------------------------------------------ procedure Un_Control (Ch : in Attributed_Character; Str : out String) is function Unctrl (Ch : C_Chtype) return chars_ptr; pragma Import (C, Unctrl, "unctrl"); begin Fill_String (Unctrl (AttrChar_To_Chtype (Ch)), Str); end Un_Control; function Un_Control (Ch : in Attributed_Character) return String is function Unctrl (Ch : C_Chtype) return chars_ptr; pragma Import (C, Unctrl, "unctrl"); begin return Fill_String (Unctrl (AttrChar_To_Chtype (Ch))); end Un_Control; procedure Delay_Output (Msecs : in Natural) is function Delayoutput (Msecs : C_Int) return C_Int; pragma Import (C, Delayoutput, "delay_output"); begin if Delayoutput (C_Int (Msecs)) = Curses_Err then raise Curses_Exception; end if; end Delay_Output; procedure Flush_Input is function Flushinp return C_Int; pragma Import (C, Flushinp, "flushinp"); begin if Flushinp = Curses_Err then -- docu says that never happens, but... raise Curses_Exception; end if; end Flush_Input; ------------------------------------------------------------------------------ function Baudrate return Natural is function Baud return C_Int; pragma Import (C, Baud, "baudrate"); begin return Natural (Baud); end Baudrate; function Erase_Character return Character is function Erasechar return C_Int; pragma Import (C, Erasechar, "erasechar"); begin return Character'Val (Erasechar); end Erase_Character; function Kill_Character return Character is function Killchar return C_Int; pragma Import (C, Killchar, "killchar"); begin return Character'Val (Killchar); end Kill_Character; function Has_Insert_Character return Boolean is function Has_Ic return Curses_Bool; pragma Import (C, Has_Ic, "has_ic"); begin if Has_Ic = Curses_Bool_False then return False; else return True; end if; end Has_Insert_Character; function Has_Insert_Line return Boolean is function Has_Il return Curses_Bool; pragma Import (C, Has_Il, "has_il"); begin if Has_Il = Curses_Bool_False then return False; else return True; end if; end Has_Insert_Line; function Supported_Attributes return Character_Attribute_Set is function Termattrs return C_Chtype; pragma Import (C, Termattrs, "termattrs"); Ch : constant Attributed_Character := Chtype_To_AttrChar (Termattrs); begin return Ch.Attr; end Supported_Attributes; procedure Long_Name (Name : out String) is function Longname return chars_ptr; pragma Import (C, Longname, "longname"); begin Fill_String (Longname, Name); end Long_Name; function Long_Name return String is function Longname return chars_ptr; pragma Import (C, Longname, "longname"); begin return Fill_String (Longname); end Long_Name; procedure Terminal_Name (Name : out String) is function Termname return chars_ptr; pragma Import (C, Termname, "termname"); begin Fill_String (Termname, Name); end Terminal_Name; function Terminal_Name return String is function Termname return chars_ptr; pragma Import (C, Termname, "termname"); begin return Fill_String (Termname); end Terminal_Name; ------------------------------------------------------------------------------ procedure Init_Pair (Pair : in Redefinable_Color_Pair; Fore : in Color_Number; Back : in Color_Number) is function Initpair (Pair : C_Short; Fore : C_Short; Back : C_Short) return C_Int; pragma Import (C, Initpair, "init_pair"); begin if Integer (Pair) >= Number_Of_Color_Pairs then raise Constraint_Error; end if; if Integer (Fore) >= Number_Of_Colors or else Integer (Back) >= Number_Of_Colors then raise Constraint_Error; end if; if Initpair (C_Short (Pair), C_Short (Fore), C_Short (Back)) = Curses_Err then raise Curses_Exception; end if; end Init_Pair; procedure Pair_Content (Pair : in Color_Pair; Fore : out Color_Number; Back : out Color_Number) is type C_Short_Access is access all C_Short; function Paircontent (Pair : C_Short; Fp : C_Short_Access; Bp : C_Short_Access) return C_Int; pragma Import (C, Paircontent, "pair_content"); F, B : aliased C_Short; begin if Paircontent (C_Short (Pair), F'Access, B'Access) = Curses_Err then raise Curses_Exception; else Fore := Color_Number (F); Back := Color_Number (B); end if; end Pair_Content; function Has_Colors return Boolean is function Hascolors return Curses_Bool; pragma Import (C, Hascolors, "has_colors"); begin if Hascolors = Curses_Bool_False then return False; else return True; end if; end Has_Colors; procedure Init_Color (Color : in Color_Number; Red : in RGB_Value; Green : in RGB_Value; Blue : in RGB_Value) is function Initcolor (Col : C_Short; Red : C_Short; Green : C_Short; Blue : C_Short) return C_Int; pragma Import (C, Initcolor, "init_color"); begin if Initcolor (C_Short (Color), C_Short (Red), C_Short (Green), C_Short (Blue)) = Curses_Err then raise Curses_Exception; end if; end Init_Color; function Can_Change_Color return Boolean is function Canchangecolor return Curses_Bool; pragma Import (C, Canchangecolor, "can_change_color"); begin if Canchangecolor = Curses_Bool_False then return False; else return True; end if; end Can_Change_Color; procedure Color_Content (Color : in Color_Number; Red : out RGB_Value; Green : out RGB_Value; Blue : out RGB_Value) is type C_Short_Access is access all C_Short; function Colorcontent (Color : C_Short; R, G, B : C_Short_Access) return C_Int; pragma Import (C, Colorcontent, "color_content"); R, G, B : aliased C_Short; begin if Colorcontent (C_Short (Color), R'Access, G'Access, B'Access) = Curses_Err then raise Curses_Exception; else Red := RGB_Value (R); Green := RGB_Value (G); Blue := RGB_Value (B); end if; end Color_Content; ------------------------------------------------------------------------------ procedure Save_Curses_Mode (Mode : in Curses_Mode) is function Def_Prog_Mode return C_Int; pragma Import (C, Def_Prog_Mode, "def_prog_mode"); function Def_Shell_Mode return C_Int; pragma Import (C, Def_Shell_Mode, "def_shell_mode"); Err : C_Int; begin case Mode is when Curses => Err := Def_Prog_Mode; when Shell => Err := Def_Shell_Mode; end case; if Err = Curses_Err then raise Curses_Exception; end if; end Save_Curses_Mode; procedure Reset_Curses_Mode (Mode : in Curses_Mode) is function Reset_Prog_Mode return C_Int; pragma Import (C, Reset_Prog_Mode, "reset_prog_mode"); function Reset_Shell_Mode return C_Int; pragma Import (C, Reset_Shell_Mode, "reset_shell_mode"); Err : C_Int; begin case Mode is when Curses => Err := Reset_Prog_Mode; when Shell => Err := Reset_Shell_Mode; end case; if Err = Curses_Err then raise Curses_Exception; end if; end Reset_Curses_Mode; procedure Save_Terminal_State is function Savetty return C_Int; pragma Import (C, Savetty, "savetty"); begin if Savetty = Curses_Err then raise Curses_Exception; end if; end Save_Terminal_State; procedure Reset_Terminal_State is function Resetty return C_Int; pragma Import (C, Resetty, "resetty"); begin if Resetty = Curses_Err then raise Curses_Exception; end if; end Reset_Terminal_State; procedure Rip_Off_Lines (Lines : in Integer; Proc : in Stdscr_Init_Proc) is function Ripoffline (Lines : C_Int; Proc : Stdscr_Init_Proc) return C_Int; pragma Import (C, Ripoffline, "_nc_ripoffline"); begin if Ripoffline (C_Int (Lines), Proc) = Curses_Err then raise Curses_Exception; end if; end Rip_Off_Lines; procedure Set_Cursor_Visibility (Visibility : in out Cursor_Visibility) is function Curs_Set (Curs : C_Int) return C_Int; pragma Import (C, Curs_Set, "curs_set"); Res : C_Int; begin Res := Curs_Set (Cursor_Visibility'Pos (Visibility)); if Res /= Curses_Err then Visibility := Cursor_Visibility'Val (Res); end if; end Set_Cursor_Visibility; procedure Nap_Milli_Seconds (Ms : in Natural) is function Napms (Ms : C_Int) return C_Int; pragma Import (C, Napms, "napms"); begin if Napms (C_Int (Ms)) = Curses_Err then raise Curses_Exception; end if; end Nap_Milli_Seconds; ------------------------------------------------------------------------------ function Standard_Window return Window is Stdscr : Window; pragma Import (C, Stdscr, "stdscr"); begin return Stdscr; end Standard_Window; function Lines return Line_Count is C_Lines : C_Int; pragma Import (C, C_Lines, "LINES"); begin return Line_Count (C_Lines); end Lines; function Columns return Column_Count is C_Columns : C_Int; pragma Import (C, C_Columns, "COLS"); begin return Column_Count (C_Columns); end Columns; function Tab_Size return Natural is C_Tab_Size : C_Int; pragma Import (C, C_Tab_Size, "TABSIZE"); begin return Natural (C_Tab_Size); end Tab_Size; function Number_Of_Colors return Natural is C_Number_Of_Colors : C_Int; pragma Import (C, C_Number_Of_Colors, "COLORS"); begin return Natural (C_Number_Of_Colors); end Number_Of_Colors; function Number_Of_Color_Pairs return Natural is C_Number_Of_Color_Pairs : C_Int; pragma Import (C, C_Number_Of_Color_Pairs, "COLOR_PAIRS"); begin return Natural (C_Number_Of_Color_Pairs); end Number_Of_Color_Pairs; ------------------------------------------------------------------------------ procedure Transform_Coordinates (W : in Window := Standard_Window; Line : in out Line_Position; Column : in out Column_Position; Dir : in Transform_Direction := From_Screen) is type Int_Access is access all C_Int; function Transform (W : Window; Y, X : Int_Access; Dir : Curses_Bool) return C_Int; pragma Import (C, Transform, "wmouse_trafo"); X : aliased C_Int := C_Int (Column); Y : aliased C_Int := C_Int (Line); D : Curses_Bool := Curses_Bool_False; R : C_Int; begin if Dir = To_Screen then D := 1; end if; R := Transform (W, Y'Access, X'Access, D); if R = Curses_False then raise Curses_Exception; else Line := Line_Position (Y); Column := Column_Position (X); end if; end Transform_Coordinates; ------------------------------------------------------------------------------ procedure Use_Default_Colors is function C_Use_Default_Colors return C_Int; pragma Import (C, C_Use_Default_Colors, "use_default_colors"); Err : constant C_Int := C_Use_Default_Colors; begin if Err = Curses_Err then raise Curses_Exception; end if; end Use_Default_Colors; procedure Assume_Default_Colors (Fore : Color_Number := Default_Color; Back : Color_Number := Default_Color) is function C_Assume_Default_Colors (Fore : C_Int; Back : C_Int) return C_Int; pragma Import (C, C_Assume_Default_Colors, "assume_default_colors"); Err : constant C_Int := C_Assume_Default_Colors (C_Int (Fore), C_Int (Back)); begin if Err = Curses_Err then raise Curses_Exception; end if; end Assume_Default_Colors; ------------------------------------------------------------------------------ function Curses_Version return String is function curses_versionC return chars_ptr; pragma Import (C, curses_versionC, "curses_version"); Result : constant chars_ptr := curses_versionC; begin return Fill_String (Result); end Curses_Version; ------------------------------------------------------------------------------ function Use_Extended_Names (Enable : Boolean) return Boolean is function use_extended_namesC (e : Curses_Bool) return C_Int; pragma Import (C, use_extended_namesC, "use_extended_names"); Res : constant C_Int := use_extended_namesC (Curses_Bool (Boolean'Pos (Enable))); begin if Res = C_Int (Curses_Bool_False) then return False; else return True; end if; end Use_Extended_Names; ------------------------------------------------------------------------------ procedure Screen_Dump_To_File (Filename : in String) is function scr_dump (f : char_array) return C_Int; pragma Import (C, scr_dump, "scr_dump"); Txt : char_array (0 .. Filename'Length); Length : size_t; begin To_C (Filename, Txt, Length); if Curses_Err = scr_dump (Txt) then raise Curses_Exception; end if; end Screen_Dump_To_File; procedure Screen_Restore_From_File (Filename : in String) is function scr_restore (f : char_array) return C_Int; pragma Import (C, scr_restore, "scr_restore"); Txt : char_array (0 .. Filename'Length); Length : size_t; begin To_C (Filename, Txt, Length); if Curses_Err = scr_restore (Txt) then raise Curses_Exception; end if; end Screen_Restore_From_File; procedure Screen_Init_From_File (Filename : in String) is function scr_init (f : char_array) return C_Int; pragma Import (C, scr_init, "scr_init"); Txt : char_array (0 .. Filename'Length); Length : size_t; begin To_C (Filename, Txt, Length); if Curses_Err = scr_init (Txt) then raise Curses_Exception; end if; end Screen_Init_From_File; procedure Screen_Set_File (Filename : in String) is function scr_set (f : char_array) return C_Int; pragma Import (C, scr_set, "scr_set"); Txt : char_array (0 .. Filename'Length); Length : size_t; begin To_C (Filename, Txt, Length); if Curses_Err = scr_set (Txt) then raise Curses_Exception; end if; end Screen_Set_File; ------------------------------------------------------------------------------ procedure Resize (Win : Window := Standard_Window; Number_Of_Lines : Line_Count; Number_Of_Columns : Column_Count) is function wresize (win : Window; lines : C_Int; columns : C_Int) return C_Int; pragma Import (C, wresize); begin if wresize (Win, C_Int (Number_Of_Lines), C_Int (Number_Of_Columns)) = Curses_Err then raise Curses_Exception; end if; end Resize; ------------------------------------------------------------------------------ end Terminal_Interface.Curses;
-- Shoot'n'loot -- Copyright (c) 2020 Fabien Chouteau with VirtAPU; use VirtAPU; package Music_2 is C_32nd : constant Command := (Wait_Ticks, 1); C_16th : constant Command := (Wait_Ticks, C_32nd.Ticks * 2); C_8th : constant Command := (Wait_Ticks, C_16th.Ticks * 2); C_Quarter : constant Command := (Wait_Ticks, C_8th.Ticks * 2); C_Half : constant Command := (Wait_Ticks, C_Quarter.Ticks * 2); C_Whole : constant Command := (Wait_Ticks, C_Half.Ticks * 2); C_Double : constant Command := (Wait_Ticks, C_Whole.Ticks * 2); C_Long : constant Command := (Wait_Ticks, C_Double.Ticks * 2); Kick : aliased constant Command_Array := ((Set_Decay, 6), (Set_Sweep, Up, 7, 0), (Set_Mode, Noise_2), (Note_On, 150.0), Off ); Snare : aliased constant Command_Array := ((Set_Decay, 6), (Set_Mode, Noise_1), (Note_On, 2000.0), Off ); Hi_Hat : aliased constant Command_Array := ((Set_Decay, 2), (Set_Mode, Noise_1), (Note_On, 10000.0), Off ); Beat_1 : constant Command_Array := Kick & C_Whole & Snare & C_Whole & Kick & C_Whole & Snare & C_Whole; Drums : aliased constant Command_Array := Beat_1; Bass_1 : constant Command_Array := C3 & C_Half & Off & C_Quarter & As2 & C_Half & Off & C_Quarter & C3 & C_Half & Off & C_Double; Bass_2 : constant Command_Array := Gs2 & C_Quarter & Off & C_Half & Ds3 & C_Quarter & Off & C_Half & Gs2 & C_Quarter & Off & C_Quarter & G2 & C_Quarter & Off & C_Half & As2 & C_Quarter & Off & C_Half & B2 & C_Quarter & Off & C_Quarter; Bass_3 : constant Command_Array := C3 & C_Half & Off & C_Quarter & C3 & C_Quarter & Off & C_Quarter & As2 & C_Quarter & C3 & C_Quarter & Off & C_Quarter & C_Quarter & C_Quarter & C_Quarter & C_Quarter & C_Quarter & C_Quarter & C_Quarter & C_Quarter; Bass_4 : constant Command_Array := Gs2 & C_Quarter & Off & C_Half & Ds3 & C_Quarter & Off & C_Half & Gs2 & C_Quarter & Off & C_Quarter & G2 & C_Quarter & Off & C_Half & D3 & C_Quarter & Off & C_Half & G2 & C_Quarter & Off & C_Quarter; Bass : aliased constant Command_Array := Bass_1 & Bass_2 & Bass_3 & Bass_4; end Music_2;
with Ada.Command_Line; with GNAT.Command_Line; use GNAT.Command_Line; with GNAT.OS_Lib; with GNAT.Strings; with Ada.Containers.Hashed_Maps; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Strings.Unbounded.Hash; with AAA.Table_IO; with AAA.Text_IO; package body CLIC.Subcommand.Instance is package Command_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Ada.Strings.Unbounded.Unbounded_String, Element_Type => Command_Access, Hash => Ada.Strings.Unbounded.Hash, Equivalent_Keys => Ada.Strings.Unbounded."="); package Topic_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Ada.Strings.Unbounded.Unbounded_String, Element_Type => Help_Topic_Access, Hash => Ada.Strings.Unbounded.Hash, Equivalent_Keys => Ada.Strings.Unbounded."="); package Group_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Ada.Strings.Unbounded.Unbounded_String, Element_Type => AAA.Strings.Vectors.Vector, "=" => AAA.Strings.Vectors."=", Hash => Ada.Strings.Unbounded.Hash, Equivalent_Keys => Ada.Strings.Unbounded."="); Registered_Commands : Command_Maps.Map; -- A map of commands based on their names Registered_Topics : Topic_Maps.Map; -- A map of topics based on their names Registered_Groups : Group_Maps.Map; -- A map of list of commands based on their group names Not_In_A_Group : AAA.Strings.Vector; -- List of commands that are not in a group Global_Arguments : AAA.Strings.Vector; -- Vector of arguments for the global command, the first one should be the -- command name, otherwise there is an invalid global switch on the command -- line. Help_Requested : Boolean; First_Nonswitch : Integer; Global_Config : Switches_Configuration; Global_Parsing_Done : Boolean := False; procedure Display_Options (Config : Switches_Configuration; Title : String); procedure Display_Global_Options; function Highlight_Switches (Line : String) return String; function What_Command (Str : String := "") return not null Command_Access; procedure Put_Line_For_Access (Str : String); function To_Argument_List (V : AAA.Strings.Vector) return GNAT.OS_Lib.Argument_List_Access; ------------------------- -- Put_Line_For_Access -- ------------------------- procedure Put_Line_For_Access (Str : String) is begin Put_Line (Str); end Put_Line_For_Access; ---------------------- -- To_Argument_List -- ---------------------- function To_Argument_List (V : AAA.Strings.Vector) return GNAT.OS_Lib.Argument_List_Access is List : constant GNAT.OS_Lib.Argument_List_Access := new GNAT.Strings.String_List (1 .. V.Count); begin for Index in List.all'Range loop List (Index) := new String'(V (Index)); end loop; return List; end To_Argument_List; -------------- -- Register -- -------------- procedure Register (Cmd : not null Command_Access) is Name : constant Unbounded_String := To_Unbounded_String (Cmd.Name); begin if Registered_Commands.Contains (Name) then raise Command_Already_Defined with Cmd.Name; else -- Register the command Registered_Commands.Insert (Name, Cmd); -- This command is not in a group Not_In_A_Group.Append (Cmd.Name); end if; end Register; -------------- -- Register -- -------------- procedure Register (Group : String; Cmd : not null Command_Access) is Name : constant Unbounded_String := To_Unbounded_String (Cmd.Name); Ugroup : constant Unbounded_String := To_Unbounded_String (Group); begin if Registered_Commands.Contains (Name) then raise Command_Already_Defined with Cmd.Name; else -- Register the command Registered_Commands.Insert (Name, Cmd); -- Create the group if it doesn't exist yet if not Registered_Groups.Contains (Ugroup) then Registered_Groups.Insert (Ugroup, AAA.Strings.Vectors.Empty_Vector); end if; -- Add this command to the list of commands for the group Registered_Groups.Reference (Ugroup).Append (Cmd.Name); end if; end Register; -------------- -- Register -- -------------- procedure Register (Topic : not null Help_Topic_Access) is Name : constant Unbounded_String := To_Unbounded_String (Topic.Name); begin if Registered_Topics.Contains (Name) then raise Program_Error; else Registered_Topics.Insert (Name, Topic); end if; end Register; ------------------ -- What_Command -- ------------------ function What_Command (Str : String := "") return not null Command_Access is Name : constant Unbounded_String := To_Unbounded_String (if Str = "" then What_Command else Str); begin if Registered_Commands.Contains (Name) then return Registered_Commands.Element (Name); else raise Error_No_Command; end if; end What_Command; ------------------ -- What_Command -- ------------------ function What_Command return String is begin if Global_Arguments.Is_Empty or else AAA.Strings.Has_Prefix (Global_Arguments.First_Element, "-") then raise Error_No_Command; else return Global_Arguments.First_Element; end if; end What_Command; -------------------- -- Fill_Arguments -- -------------------- procedure Fill_Arguments (Switch : String; Parameter : String; Section : String) is pragma Unreferenced (Parameter); pragma Unreferenced (Section); begin Global_Arguments.Append (Switch); end Fill_Arguments; ---------------------------- -- Display_Valid_Commands -- ---------------------------- procedure Display_Valid_Commands is use Command_Maps; use Group_Maps; Tab : constant String (1 .. 1) := (others => ' '); Table : AAA.Table_IO.Table; ----------------- -- Add_Command -- ----------------- procedure Add_Command (Cmd : not null Command_Access) is begin Table.New_Row; Table.Append (Tab); Table.Append (TTY_Description (Cmd.Name)); Table.Append (Tab); Table.Append (Cmd.Short_Description); end Add_Command; First_Group : Boolean := Not_In_A_Group.Is_Empty; begin if Registered_Commands.Is_Empty then return; end if; Put_Line (TTY_Chapter ("COMMANDS")); for Name of Not_In_A_Group loop Add_Command (Registered_Commands (To_Unbounded_String (Name))); end loop; for Iter in Registered_Groups.Iterate loop if not First_Group then Table.New_Row; Table.Append (Tab); else First_Group := False; end if; declare Group : constant String := To_String (Key (Iter)); begin Table.New_Row; Table.Append (Tab); Table.Append (TTY_Underline (Group)); for Name of Element (Iter) loop Add_Command (Registered_Commands (To_Unbounded_String (Name))); end loop; end; end loop; Table.Print (Separator => " ", Put_Line => Put_Line_For_Access'Access); end Display_Valid_Commands; -------------------------- -- Display_Valid_Topics -- -------------------------- procedure Display_Valid_Topics is Tab : constant String (1 .. 1) := (others => ' '); Table : AAA.Table_IO.Table; use Topic_Maps; begin if Registered_Topics.Is_Empty then return; end if; Put_Line (TTY_Chapter ("TOPICS")); for Elt in Registered_Topics.Iterate loop Table.New_Row; Table.Append (Tab); Table.Append (TTY_Description (To_String (Key (Elt)))); Table.Append (Tab); Table.Append (Element (Elt).Title); end loop; Table.Print (Separator => " ", Put_Line => Put_Line_For_Access'Access); end Display_Valid_Topics; ------------------- -- Display_Usage -- ------------------- procedure Display_Usage (Cmd : not null Command_Access) is Config : Switches_Configuration; Canary1 : Switches_Configuration; Canary2 : Switches_Configuration; begin Put_Line (TTY_Chapter ("SUMMARY")); Put_Line (" " & Cmd.Short_Description); Put_Line (""); Put_Line (TTY_Chapter ("USAGE")); Put (" "); Put_Line (TTY_Underline (Main_Command_Name) & " " & TTY_Underline (Cmd.Name) & " [options] " & Cmd.Usage_Custom_Parameters); -- We use the following two canaries to detect if a command is adding -- its own switches, in which case we need to show their specific help. Set_Global_Switches (Canary1); -- For comparison Set_Global_Switches (Canary2); -- For comparison Cmd.Setup_Switches (Canary1); if Get_Switches (Canary1.GNAT_Cfg) /= Get_Switches (Canary2.GNAT_Cfg) then Cmd.Setup_Switches (Config); end if; -- Without the following line, GNAT.Display_Help causes a segfault for -- reasons I'm unable to pinpoint. This way it prints a harmless blank -- line that we want anyway. Define_Switch (Config, " ", " ", " ", " ", " "); Display_Options (Config, "OPTIONS"); Display_Global_Options; -- Format and print the long command description Put_Line (""); Put_Line (TTY_Chapter ("DESCRIPTION")); for Line of Cmd.Long_Description loop AAA.Text_IO.Put_Paragraph (Highlight_Switches (Line), Line_Prefix => " "); -- GNATCOLL.Paragraph_Filling seems buggy at the moment, otherwise -- it would be the logical choice. end loop; end Display_Usage; ------------------- -- Display_Usage -- ------------------- procedure Display_Usage (Displayed_Error : Boolean := False) is begin if not Displayed_Error then Put_Line (Main_Command_Name & " " & TTY_Version (Version)); Put_Line (""); end if; Put_Line (TTY_Chapter ("USAGE")); Put_Line (" " & TTY_Underline (Main_Command_Name) & " [global options] " & "<command> [command options] [<arguments>]"); Put_Line (""); Put_Line (" " & TTY_Underline (Main_Command_Name) & " " & TTY_Underline ("help") & " [<command>|<topic>]"); Put_Line (""); Put_Line (TTY_Chapter ("ARGUMENTS")); declare Tab : constant String (1 .. 1) := (others => ' '); Table : AAA.Table_IO.Table; begin Table.New_Row; Table.Append (Tab); Table.Append (TTY_Description ("<command>")); Table.Append ("Command to execute"); Table.New_Row; Table.Append (Tab); Table.Append (TTY_Description ("<arguments>")); Table.Append ("List of arguments for the command"); Table.Print (Separator => " ", Put_Line => Put_Line_For_Access'Access); end; Display_Global_Options; Display_Valid_Commands; Display_Valid_Topics; end Display_Usage; --------------------------- -- Parse_Global_Switches -- --------------------------- procedure Parse_Global_Switches is --------------------------- -- Check_First_Nonswitch -- --------------------------- function Check_First_Nonswitch return Integer is use Ada.Command_Line; First_Nonswitch : Integer := 0; -- Used to store the first argument that doesn't start with '-'; -- that would be the command for which help is being asked. begin for I in 1 .. Argument_Count loop declare Arg : constant String := Ada.Command_Line.Argument (I); begin if First_Nonswitch = 0 and then Arg (Arg'First) /= '-' then First_Nonswitch := I; end if; end; end loop; return First_Nonswitch; end Check_First_Nonswitch; -------------------- -- Check_For_Help -- -------------------- function Check_For_Help return Boolean is use Ada.Command_Line; begin return (for some I in 1 .. Argument_Count => Ada.Command_Line.Argument (I) in "-h" | "--help"); end Check_For_Help; ---------------------- -- Filter_Arguments -- ---------------------- function Filter_Arguments return GNAT.OS_Lib.Argument_List_Access is use Ada.Command_Line; Arguments : AAA.Strings.Vector; begin for I in 1 .. Argument_Count loop declare Arg : constant String := Ada.Command_Line.Argument (I); begin if Arg not in "-h" | "--help" then Arguments.Append (Arg); end if; end; end loop; return To_Argument_List (Arguments); end Filter_Arguments; Arguments : GNAT.OS_Lib.Argument_List_Access; Arguments_Parser : Opt_Parser; begin -- Only do the global parsing once if Global_Parsing_Done then return; else Global_Parsing_Done := True; end if; -- GNAT switch handling intercepts -h/--help. To have the same output -- for '<main> -h command' and '<main> help command', we do manual -- handling first in search of a -h/--help: Help_Requested := Check_For_Help; First_Nonswitch := Check_First_Nonswitch; -- We filter the command line arguments to remove -h/--help that would -- trigger the Getopt automatic help system. Arguments := Filter_Arguments; Set_Global_Switches (Global_Config); -- To avoid erroring on command-specific switches we add the wildcard. -- However, if help was requested, we don't want the "[any string]" text -- to be displayed by Getopt below, so in that case we bypass it. if not Help_Requested then Define_Switch (Global_Config, "*"); end if; -- Run the parser first with only the global switches. With the wildcard -- above (Define_Switch (Global_Config, "*")) all the unknown switches -- and arguments go through the Fill_Arguments callback, and therefore -- are added to Global_Arguments. This includes the command name and all -- potential command specific switches and arguments. Initialize_Option_Scan (Arguments_Parser, Arguments); Getopt (Global_Config.GNAT_Cfg, Callback => Fill_Arguments'Unrestricted_Access, Parser => Arguments_Parser); GNAT.OS_Lib.Free (Arguments); -- At this point the command and all unknown switches are in -- Global_Arguments. exception when Exit_From_Command_Line | Invalid_Switch | Invalid_Parameter => Put_Line (""); Put_Line ("Use """ & Main_Command_Name & " help <command>"" for specific command help"); Error_Exit (1); end Parse_Global_Switches; ------------- -- Execute -- ------------- procedure Execute is begin Parse_Global_Switches; -- Show either general or specific help if Help_Requested then if First_Nonswitch > 0 then Display_Help (Ada.Command_Line.Argument (First_Nonswitch)); Error_Exit (0); else null; -- Nothing to do; later on GNAT switch processing will catch -- the -h/--help and display the general help. end if; end if; if Global_Arguments.Is_Empty then -- We should at least have the sub-command name in the arguments Display_Usage; Error_Exit (1); elsif AAA.Strings.Has_Prefix (Global_Arguments.First_Element, "-") then -- If the first Global_Arguments is a switch (starts with '-'), -- that means it is an invalid global switch. It is in the arguments -- because of the wildcard: Define_Switch (Global_Config, "*"); Put_Error ("Unrecognized global option: " & Global_Arguments.First_Element); Display_Global_Options; Error_Exit (1); end if; -- Dispatch to the appropriate command declare Cmd : constant not null Command_Access := What_Command; -- Might raise if invalid, if so we are done Command_Config : Switches_Configuration; Sub_Cmd_Line : GNAT.OS_Lib.String_List_Access := To_Argument_List (Global_Arguments); -- Make a new command line argument list from the remaining arguments -- and switches after global parsing. Parser : Opt_Parser; Sub_Arguments : AAA.Strings.Vector; begin -- Add command specific switches to the config. We don't need the -- global switches because they have been parsed before. Cmd.Setup_Switches (Command_Config); -- Ensure Command has not set a switch that is already global: if not Verify_No_Duplicates (Command_Config, Global_Config) then Put_Error ("Duplicate switch definition detected"); Error_Exit (1); end if; -- Initialize a new switch parser that will only see the new -- sub-command line (i.e. the remaining args and switches after -- global parsing). Initialize_Option_Scan (Parser, Sub_Cmd_Line); -- Parse sub-command line, invalid switches will raise an exception Getopt (Command_Config.GNAT_Cfg, Parser => Parser); -- Make a vector of arguments for the sub-command (every element that -- was not a switch in the sub-command line). loop declare Arg : constant String := GNAT.Command_Line.Get_Argument (Parser => Parser); begin exit when Arg = ""; Sub_Arguments.Append (Arg); end; end loop; -- We don't need this anymore GNAT.OS_Lib.Free (Sub_Cmd_Line); pragma Assert (not Sub_Arguments.Is_Empty, "Should have at least the command name"); -- Remove the sub-command name from the list Sub_Arguments.Delete_First; Cmd.Execute (Sub_Arguments); end; exception when Exit_From_Command_Line | Invalid_Switch | Invalid_Parameter => -- Getopt has already displayed some help Put_Line (""); Put_Line ("Use """ & Main_Command_Name & " help <command>"" for specific command help"); Error_Exit (1); when Error_No_Command => Put_Error ("Unrecognized command: " & Global_Arguments.First_Element); Put_Line (""); Display_Usage (Displayed_Error => True); Error_Exit (1); end Execute; ------------------------ -- Highlight_Switches -- ------------------------ function Highlight_Switches (Line : String) return String is use AAA.Strings.Vectors; use AAA.Strings; --------------- -- Highlight -- --------------- -- Avoid highlighting non-alphanumeric characters function Highlight (Word : String) return String is subtype Valid_Chars is Character with Dynamic_Predicate => Valid_Chars in '0' .. '9' | 'a' .. 'z'; I : Natural := Word'Last; -- last char to highlight begin while I >= Word'First and then Word (I) not in Valid_Chars loop I := I - 1; end loop; return TTY_Emph (Word (Word'First .. I)) & Word (I + 1 .. Word'Last); end Highlight; Words : AAA.Strings.Vector := AAA.Strings.Split (Line, Separator => ' '); I, J : Vectors.Cursor; begin I := Words.First; while Has_Element (I) loop declare Word : constant String := Element (I); begin J := Next (I); if Has_Prefix (Word, "--") and then Word'Length > 2 then Words.Insert (Before => J, New_Item => Highlight (Word)); Words.Delete (I); end if; I := J; end; end loop; return Flatten (Words); end Highlight_Switches; --------------------- -- Display_Options -- --------------------- procedure Display_Options (Config : Switches_Configuration; Title : String) is Tab : constant String (1 .. 1) := (others => ' '); Table : AAA.Table_IO.Table; Has_Printable_Rows : Boolean := False; ----------------- -- Without_Arg -- ----------------- function Without_Arg (Value : String) return String is Required_Character : constant Character := Value (Value'Last); begin return (if Required_Character in '=' | ':' | '!' | '?' then Value (Value'First .. Value'Last - 1) else Value); end Without_Arg; -------------- -- With_Arg -- -------------- function With_Arg (Value, Arg : String) return String is Required_Character : constant Character := Value (Value'Last); begin return (if Required_Character in '=' | ':' | '!' | '?' then AAA.Strings.Replace (Value, "" & Required_Character, (case Required_Character is when '=' => "=" & Arg, when ':' => "[ ] " & Arg, when '!' => Arg, when '?' => "[" & Arg & "]", when others => raise Program_Error)) else Value); end With_Arg; --------------- -- Print_Row -- --------------- procedure Print_Row (Short_Switch, Long_Switch, Arg, Help : String) is Has_Short : constant Boolean := Short_Switch not in " " | ""; Has_Long : constant Boolean := Long_Switch not in " " | ""; begin if (not Has_Short and not Has_Long) or Help = "" then return; end if; Table.New_Row; Table.Append (Tab); if Has_Short and Has_Long then Table.Append (TTY_Description (Without_Arg (Short_Switch)) & " (" & With_Arg (Long_Switch, Arg) & ")"); elsif not Has_Short and Has_Long then Table.Append (TTY_Description (With_Arg (Long_Switch, Arg))); elsif Has_Short and not Has_Long then Table.Append (TTY_Description (With_Arg (Short_Switch, Arg))); end if; Table.Append (Help); Has_Printable_Rows := True; end Print_Row; begin for Elt of Config.Info loop Print_Row (To_String (Elt.Switch), To_String (Elt.Long_Switch), To_String (Elt.Argument), To_String (Elt.Help)); end loop; if Has_Printable_Rows then Put_Line (""); Put_Line (TTY_Chapter (Title)); Table.Print (Separator => " ", Put_Line => Put_Line_For_Access'Access); end if; end Display_Options; ---------------------------- -- Display_Global_Options -- ---------------------------- procedure Display_Global_Options is Global_Config : Switches_Configuration; begin Set_Global_Switches (Global_Config); Display_Options (Global_Config, "GLOBAL OPTIONS"); end Display_Global_Options; ------------------ -- Display_Help -- ------------------ procedure Display_Help (Keyword : String) is ------------ -- Format -- ------------ procedure Format (Text : AAA.Strings.Vector) is begin for Line of Text loop AAA.Text_IO.Put_Paragraph (Highlight_Switches (Line), Line_Prefix => " "); end loop; end Format; Ukey : constant Unbounded_String := To_Unbounded_String (Keyword); begin if Registered_Commands.Contains (Ukey) then Display_Usage (What_Command (Keyword)); elsif Registered_Topics.Contains (Ukey) then Put_Line (TTY_Chapter (Registered_Topics.Element (Ukey).Title)); Format (Registered_Topics.Element (Ukey).Content); else Put_Error ("No help found for: " & Keyword); Display_Global_Options; Display_Valid_Commands; Display_Valid_Topics; Error_Exit (1); end if; end Display_Help; ------------- -- Execute -- ------------- overriding procedure Execute (This : in out Builtin_Help; Args : AAA.Strings.Vector) is pragma Unreferenced (This); begin if Args.Count /= 1 then if Args.Count > 1 then Put_Error ("Please specify a single help keyword"); Put_Line (""); end if; Put_Line (TTY_Chapter ("USAGE")); Put_Line (" " & TTY_Underline (Main_Command_Name) & " " & TTY_Underline ("help") & " [<command>|<topic>]"); Put_Line (""); Put_Line (TTY_Chapter ("ARGUMENTS")); declare Tab : constant String (1 .. 1) := (others => ' '); Table : AAA.Table_IO.Table; begin Table.New_Row; Table.Append (Tab); Table.Append (TTY_Description ("<command>")); Table.Append ("Command for which to show a description"); Table.New_Row; Table.Append (Tab); Table.Append (TTY_Description ("<topic>")); Table.Append ("Topic for which to show a description"); Table.Print (Separator => " ", Put_Line => Put_Line_For_Access'Access); end; Display_Global_Options; Display_Valid_Commands; Display_Valid_Topics; Error_Exit (1); end if; Display_Help (Args (1)); end Execute; end CLIC.Subcommand.Instance;
generic type Element_Type is private; -- The type of picture elements within the input. type Element_Matrix is array (Natural range <>, Natural range <>) of Element_Type; -- The array type we'll take as input and provide as output. -- We treat these as a toroidal surface which infinitely tiles. with function "<" (E1, E2 : Element_Type) return Boolean is <>; with function "=" (E1, E2 : Element_Type) return Boolean is <>; -- Because the element type might be a record, we don't -- constrain it to be discrete, but for various purposes -- we at least require it to be orderable. package WFC is subtype Tile_ID is Positive; -- A tile represents a part of the input array as a submatrix of elements. -- Because passing around arrays by value is -- more expensive, instead we represent tiles as -- indices into arrays of their properties, for simplicity. type Tile_Element_Array is array (Tile_ID range <>) of Element_Type; -- Mapping the id to the tile itself is somewhat -- more than required, as each tile contributes only one -- pixel to the output. Here, we map each tile to -- the pixel it will contribute. The adjacency information -- will guarantee their combined behavior is as desired. type Frequency_Array is array (Tile_ID range <>) of Natural; -- Mapping each tile to its frequency in the input type Adjacency_Direction is (Upwards, Downwards, Leftwards, Rightwards); -- The directions in which we record tile adjacency information. type Adjacency is array (Adjacency_Direction) of Boolean with Pack; -- A bitvector recording for each direction -- whether there is an adjacency. type Adjacency_Matrix is array (Tile_ID range <>, Tile_ID range <>) of Adjacency with Pack; -- For every pair of tiles, we store whether they are -- allowed to be adjacent to each other, in each direction. -- For efficiency we also pack together the bitvectors; -- when the number of tiles is large this still becomes the majority -- of the data we need to store, even when each adjacency -- is stored in one bit. type Small_Integer is mod 2 ** 16; -- This only needs to be large enough to hold a number -- as high as a particular instance's Num_Tiles value. -- -- The necessary size of adjacency matrices in the general case -- becomes far larger than is reasonable long before -- the number of tiles reaches 65536, but more than 255 tiles -- is possible, so we just use two bytes to count enablers. type Enablers_By_Direction is array (Adjacency_Direction) of Small_Integer with Pack; type Enabler_Counts is array (Tile_ID range <>) of Enablers_By_Direction; -- The number of "enablers" of a particular tile -- in a direction is the number of other tiles which -- can be adjacent in that direction. type Instance (Num_Tiles : Natural) is tagged record Tile_Elements : Tile_Element_Array (1 .. Num_Tiles); Frequency_Total : Natural; Frequencies : Frequency_Array (1 .. Num_Tiles); Adjacencies : Adjacency_Matrix (1 .. Num_Tiles, 1 .. Num_Tiles); Enablers : Enabler_Counts (1 .. Num_Tiles); end record; -- All information we need to record about a particular input -- in order to generate similar outputs via wave function collapse. function Initialize_From_Sample ( Sample : in Element_Matrix; Include_Rotations : in Boolean := False; Include_Reflections : in Boolean := False; N, M : in Positive := 2 ) return Instance; -- Create an instantiation representing the empirical tile and frequency -- information from a sample matrix provided. If desired, -- this information will be combined with rotated and reflected -- versions of the tiles for more variety. The size of each tile -- is specified with the N and M parameters. function Collapse_Within (Parameters : in Instance; World : out Element_Matrix) return Boolean; -- Given an instance and a matrix to populate, attempt a wave function -- collapse within the space with the tiles from the parameters. -- This is an operation which is (although likely) not guaranteed to -- succeed, and so the return value indicates whether it was successful. -- -- If this fails many times it may indicate that the tileset is unable -- to seamlessly tile a matrix of the size given; this may happen if -- the size of a single tile is larger than the matrix especially, or -- if every tile in the sample used to create the instance was unique, -- leading to a tileset which can only tile spaces with size equal -- to the sample modulo its dimensions. -- -- In such cases the recommendation is simply to use larger samples, -- or decrease the N/M tile parameter until there is wider representation -- of different tiles and adjacencies. generic type X_Dim is range <>; type Y_Dim is range <>; package Extended_Interfaces is -- If more control over generation, data structures, etc. -- is required, then the extended interfaces package -- provides an way of allowing more internals of the collapse -- algorithm to be inspected or configured as need be. type Collapse_Info is interface; -- For the more generic collapsing procedure, we allow returning -- information to the user by querying an instance of this type. function Is_Possible ( Info : in Collapse_Info; X : in X_Dim; Y : in Y_Dim; E : in Element_Type) return Boolean is abstract; function Is_Possible ( Info : in Collapse_Info; X : in X_Dim; Y : in Y_Dim; T : in Tile_ID) return Boolean is abstract; -- Determine whether it's possible for a particular element or -- tile_id to occur at the position specified. type Collapse_Settings is interface and Collapse_Info; -- This type not only allows querying information -- about what is possible, but also configuring -- certain requirements within the procedure Require (Info : in Collapse_Settings; X : in X_Dim; Y : in Y_Dim; E : in Element_Type) is abstract; procedure Require (Info : in Collapse_Settings; X : in X_Dim; Y : in Y_Dim; T : in Tile_ID) is abstract; -- inject requirements for certain positions to have -- certain tile or element values. generic with procedure Set_Resulting_Element (X : X_Dim; Y : Y_Dim; Element : Element_Type) is <>; with procedure Set_Initial_Requirements (Info : in Collapse_Settings'Class) is null; with procedure Upon_Collapse (X : X_Dim; Y : Y_Dim; Info : in Collapse_Info'Class) is null; with procedure Upon_Removal (X : X_Dim; Y : Y_Dim; Info : in Collapse_Info'Class) is null; function Generic_Collapse_Within (Parameters : in Instance) return Boolean; end; end;
-- Generated at 2016-07-04 19:19:16 +0000 by Natools.Static_Hash_Maps -- from src/natools-web-comments-maps.sx with Natools.Static_Maps.Web.Comments.Item_Commands; with Natools.Static_Maps.Web.Comments.Item_Conditions; with Natools.Static_Maps.Web.Comments.Item_Elements; with Natools.Static_Maps.Web.Comments.Item_Forms; with Natools.Static_Maps.Web.Comments.Item_Actions; with Natools.Static_Maps.Web.Comments.List_Commands; with Natools.Static_Maps.Web.Comments.List_Elements; function Natools.Static_Maps.Web.Comments.T return Boolean is begin for I in Map_1_Keys'Range loop if Natools.Static_Maps.Web.Comments.Item_Commands.Hash (Map_1_Keys (I).all) /= I then return False; end if; end loop; for I in Map_2_Keys'Range loop if Natools.Static_Maps.Web.Comments.Item_Conditions.Hash (Map_2_Keys (I).all) /= I then return False; end if; end loop; for I in Map_3_Keys'Range loop if Natools.Static_Maps.Web.Comments.Item_Elements.Hash (Map_3_Keys (I).all) /= I then return False; end if; end loop; for I in Map_4_Keys'Range loop if Natools.Static_Maps.Web.Comments.Item_Forms.Hash (Map_4_Keys (I).all) /= I then return False; end if; end loop; for I in Map_5_Keys'Range loop if Natools.Static_Maps.Web.Comments.Item_Actions.Hash (Map_5_Keys (I).all) /= I then return False; end if; end loop; for I in Map_6_Keys'Range loop if Natools.Static_Maps.Web.Comments.List_Commands.Hash (Map_6_Keys (I).all) /= I then return False; end if; end loop; for I in Map_7_Keys'Range loop if Natools.Static_Maps.Web.Comments.List_Elements.Hash (Map_7_Keys (I).all) /= I then return False; end if; end loop; return True; end Natools.Static_Maps.Web.Comments.T;
package body openGL.Glyph.texture is --------- -- Forge -- function to_Glyph (glyth_Slot : in freetype_c.FT_GlyphSlot.item; texture_Id : in openGL.Texture.texture_Name; xOffset, yOffset : in Integer; Width, Height : in Integer) return Glyph.texture.item is Self : Glyph .texture.item; Impl : constant GlyphImpl.texture.view := GlyphImpl.texture.new_GlyphImpl (glyth_Slot, texture_Id, xOffset, yOffset, Width, Height); begin Self.define (Impl.all'Access); return Self; end to_Glyph; function new_Glyph (glyth_Slot : in freetype_c.FT_GlyphSlot.item; texture_Id : in openGL.Texture.texture_Name; xOffset, yOffset : in Integer; Width, Height : in Integer) return access Glyph.texture.item'Class is begin return new Glyph.texture.item' (to_Glyph (glyth_Slot, texture_Id, xOffset, yOffset, Width, Height)); end new_Glyph; -------------- -- Attributes -- function Quad (Self : in Item; Pen : in Vector_3) return GlyphImpl.texture.Quad_t is begin return GlyphImpl.texture.view (Self.Impl).Quad (Pen); end Quad; -------------- -- Operations -- overriding function render (Self : in Item; Pen : in Vector_3; renderMode : in Integer) return Vector_3 is begin return GlyphImpl.texture.view (Self.Impl).renderImpl (Pen, renderMode); end render; end openGL.Glyph.texture;
generic type Element is (<>); function Get_Discreet return Element;
with Ada.Text_IO; with Gnat.Regpat; use Ada.Text_IO; procedure Regex is package Pat renames Gnat.Regpat; procedure Search_For_Pattern(Compiled_Expression: Pat.Pattern_Matcher; Search_In: String; First, Last: out Positive; Found: out Boolean) is Result: Pat.Match_Array (0 .. 1); begin Pat.Match(Compiled_Expression, Search_In, Result); Found := not Pat."="(Result(1), Pat.No_Match); if Found then First := Result(1).First; Last := Result(1).Last; end if; end Search_For_Pattern; Word_Pattern: constant String := "([a-zA-Z]+)"; Str: String:= "I love PATTERN matching!"; Current_First: Positive := Str'First; First, Last: Positive; Found: Boolean; begin -- first, find all the words in Str loop Search_For_Pattern(Pat.Compile(Word_Pattern), Str(Current_First .. Str'Last), First, Last, Found); exit when not Found; Put_Line("<" & Str(First .. Last) & ">"); Current_First := Last+1; end loop; -- second, replace "PATTERN" in Str by "pattern" Search_For_Pattern(Pat.Compile("(PATTERN)"), Str, First, Last, Found); Str := Str(Str'First .. First-1) & "pattern" & Str(Last+1 .. Str'Last); Put_Line(Str); end Regex;
with Text_IO; procedure Main is task type Sieve is entry Pass_On(Int: Integer); end Sieve; type Sieve_Ptr is access Sieve; function Get_New_Sieve return Sieve_Ptr is begin return new Sieve; end Get_New_Sieve; task Odd; task body Odd is Limit : constant Positive := 1000; Num: Positive; S: Sieve_Ptr := Get_New_Sieve; begin Num := 3; while Num < Limit loop S.Pass_On(Num); Num := Num + 2; end loop; end Odd; task body Sieve is New_Sieve : Sieve_Ptr; Prime, Num: Natural; begin accept Pass_On(Int : Integer) do Prime := Int; end Pass_On; Text_IO.Put(Prime'Img & ", "); -- Prime is a prime number, which coud be output loop accept Pass_On(Int : Integer) do Num := Int; end Pass_On; exit when Num rem Prime /= 0; end loop; New_Sieve := Get_New_Sieve; New_Sieve.Pass_On(Num); loop accept Pass_On (Int : Integer) do Num := Int; end Pass_On; if Num rem Prime /= 0 then New_Sieve.Pass_On(Num); end if; end loop; end Sieve; begin null; end;
with Ada.Finalization; generic type Item_Type is private; with function "=" (L : Item_Type; R : Item_Type) return Boolean is <>; package ACO.Utils.DS.Generic_Collection is pragma Preelaborate; type Collection (Max_Size : Positive) is new Ada.Finalization.Controlled with private; No_Index : constant Natural := 0; function Is_Full (C : Collection) return Boolean with Inline; function Is_Empty (C : Collection) return Boolean with Inline; function Is_Valid_Index (C : Collection; Index : Positive) return Boolean with Inline; function Available (C : Collection) return Natural with Inline; function Length (C : Collection) return Natural with Inline; function First (C : Collection) return Item_Type with Inline, Pre => not Is_Empty (C); function Last (C : Collection) return Item_Type with Inline, Pre => not Is_Empty (C); procedure Clear (C : in out Collection) with Post => Is_Empty (C); procedure Insert (C : in out Collection; Item : in Item_Type) with Pre => not Is_Full (C); procedure Insert (C : in out Collection; Item : in Item_Type; Before : in Positive) with Pre => not Is_Full (C); procedure Append (C : in out Collection; Item : in Item_Type) with Pre => not Is_Full (C); procedure Append (C : in out Collection; Item : in Item_Type; After : in Positive) with Pre => not Is_Full (C); procedure Remove (C : in out Collection; From : in Positive) with Pre => Is_Valid_Index (C, From); procedure Replace (C : in out Collection; Index : in Positive; Item : in Item_Type) with Inline, Pre => Is_Valid_Index (C, Index); function Item_At (C : Collection; Index : Positive) return Item_Type with Inline, Pre => Is_Valid_Index (C, Index); function Location (C : Collection; Item : Item_Type; Start : Positive := 1) return Natural; private subtype Item_Index is Positive; type Item_Array is array (Item_Index range <>) of Item_Type; type Collection (Max_Size : Positive) is new Ada.Finalization.Controlled with record Items : Item_Array (1 .. Max_Size); Start : Item_Index := 1; Size : Natural := 0; end record; procedure Initialize (C : in out Collection); end ACO.Utils.DS.Generic_Collection;
-- -- Copyright (C) 2015-2016 secunet Security Networks AG -- -- 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 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- with HW.GFX.I2C; with HW.GFX.EDID; with HW.GFX.GMA.Config; with HW.GFX.GMA.Config_Helpers; with HW.GFX.GMA.I2C; with HW.GFX.GMA.DP_Aux_Ch; with HW.GFX.GMA.Panel; with HW.GFX.GMA.Power_And_Clocks; with HW.Debug; with GNAT.Source_Info; package body HW.GFX.GMA.Display_Probing is function Port_Configured (Configs : Pipe_Configs; Port : Port_Type) return Boolean with Global => null is begin return Configs (Primary).Port = Port or Configs (Secondary).Port = Port or Configs (Tertiary).Port = Port; end Port_Configured; -- DP and HDMI share physical pins. function Sibling_Port (Port : Port_Type) return Port_Type is begin return (case Port is when HDMI1 => DP1, when HDMI2 => DP2, when HDMI3 => DP3, when DP1 => HDMI1, when DP2 => HDMI2, when DP3 => HDMI3, when others => Disabled); end Sibling_Port; function Has_Sibling_Port (Port : Port_Type) return Boolean is begin return Sibling_Port (Port) /= Disabled; end Has_Sibling_Port; function Is_DVI_I (Port : Active_Port_Type) return Boolean with Global => null is begin return Config.Have_DVI_I and (Port = Analog or Config_Helpers.To_PCH_Port (Port) = Config.Analog_I2C_Port); end Is_DVI_I; procedure Read_EDID (Raw_EDID : out EDID.Raw_EDID_Data; Port : in Active_Port_Type; Success : out Boolean) with Post => (if Success then EDID.Valid (Raw_EDID)) is Raw_EDID_Length : GFX.I2C.Transfer_Length := Raw_EDID'Length; begin pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); for I in 1 .. 2 loop if Config_Helpers.To_Display_Type (Port) = DP then -- May need power to read edid declare Temp_Configs : Pipe_Configs := Cur_Configs; begin Temp_Configs (Primary).Port := Port; Power_And_Clocks.Power_Up (Cur_Configs, Temp_Configs); end; declare DP_Port : constant GMA.DP_Port := (case Port is when Internal => DP_A, when DP1 => DP_B, when DP2 => DP_C, when DP3 => DP_D, when others => GMA.DP_Port'First); begin DP_Aux_Ch.I2C_Read (Port => DP_Port, Address => 16#50#, Length => Raw_EDID_Length, Data => Raw_EDID, Success => Success); end; else I2C.I2C_Read (Port => (if Port = Analog then Config.Analog_I2C_Port else Config_Helpers.To_PCH_Port (Port)), Address => 16#50#, Length => Raw_EDID_Length, Data => Raw_EDID, Success => Success); end if; exit when not Success; -- don't retry if reading itself failed pragma Debug (Debug.Put_Buffer ("EDID", Raw_EDID, Raw_EDID_Length)); EDID.Sanitize (Raw_EDID, Success); exit when Success; end loop; end Read_EDID; procedure Probe_Port (Pipe_Cfg : in out Pipe_Config; Port : in Active_Port_Type; Success : out Boolean) with Pre => True is Raw_EDID : EDID.Raw_EDID_Data := (others => 16#00#); begin Success := Config.Valid_Port (Port); if Success then if Port = Internal then Panel.Wait_On; end if; Read_EDID (Raw_EDID, Port, Success); end if; if Success and then ((not Is_DVI_I (Port) or EDID.Compatible_Display (Raw_EDID, Config_Helpers.To_Display_Type (Port))) and EDID.Has_Preferred_Mode (Raw_EDID)) then Pipe_Cfg.Port := Port; Pipe_Cfg.Mode := EDID.Preferred_Mode (Raw_EDID); pragma Warnings (GNATprove, Off, "unused assignment to ""Raw_EDID""", Reason => "We just want to check if it's readable."); if Has_Sibling_Port (Port) then -- Probe sibling port too and bail out if something is detected. -- This is a precaution for adapters that expose the pins of a -- port for both HDMI/DVI and DP (like some ThinkPad docks). A -- user might have attached both by accident and there are ru- -- mors of displays that got fried by applying the wrong signal. declare Have_Sibling_EDID : Boolean; begin Read_EDID (Raw_EDID, Sibling_Port (Port), Have_Sibling_EDID); if Have_Sibling_EDID then Pipe_Cfg.Port := Disabled; Success := False; end if; end; end if; pragma Warnings (GNATprove, On, "unused assignment to ""Raw_EDID"""); else Success := False; end if; end Probe_Port; procedure Scan_Ports (Configs : out Pipe_Configs; Ports : in Port_List := All_Ports; Max_Pipe : in Pipe_Index := Pipe_Index'Last; Keep_Power : in Boolean := False) is Probe_Internal : Boolean := False; Port_Idx : Port_List_Range := Port_List_Range'First; Success : Boolean; begin Configs := (Pipe_Index => (Port => Disabled, Mode => Invalid_Mode, Cursor => Default_Cursor, Framebuffer => Default_FB)); -- Turn panel on early to probe other ports during the power on delay. for Idx in Port_List_Range loop exit when Ports (Idx) = Disabled; if Ports (Idx) = Internal then Panel.On (Wait => False); Probe_Internal := True; exit; end if; end loop; for Pipe in Pipe_Index range Pipe_Index'First .. Pipe_Index'Min (Max_Pipe, Config.Max_Pipe) loop while Ports (Port_Idx) /= Disabled loop if not Port_Configured (Configs, Ports (Port_Idx)) and (not Has_Sibling_Port (Ports (Port_Idx)) or not Port_Configured (Configs, Sibling_Port (Ports (Port_Idx)))) then Probe_Port (Configs (Pipe), Ports (Port_Idx), Success); else Success := False; end if; exit when Port_Idx = Port_List_Range'Last; Port_Idx := Port_List_Range'Succ (Port_Idx); exit when Success; end loop; end loop; -- Restore power settings if not Keep_Power then Power_And_Clocks.Power_Set_To (Cur_Configs); end if; -- Turn panel power off if probing failed. if Probe_Internal and not Port_Configured (Configs, Internal) then Panel.Off; end if; end Scan_Ports; end HW.GFX.GMA.Display_Probing;
-- Copyright 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. name = "IPv4Info" type = "scrape" function start() setratelimit(1) end function vertical(ctx, domain) local path = getpath(ctx, domain) if path == "" then return end local token = gettoken(ctx, domain, path) if token == "" then return end local u = "http://ipv4info.com/subdomains/" .. token .. "/" .. domain .. ".html" local resp, err = request(ctx, {['url']=u}) if (err ~= nil and err ~= "") then return end sendnames(ctx, resp) -- Attempt to scrape additional pages of subdomain names local pagenum = 1 while(true) do local last = resp resp = "" local page = "page" .. tostring(pagenum) local key = domain .. page resp = nextpage(ctx, domain, last, page) if (resp == nil or resp == "") then break end sendnames(ctx, resp) pagenum = pagenum + 1 end end function getpath(ctx, domain) local u = "http://ipv4info.com/search/" .. domain local page, err = request(ctx, {['url']=u}) if (err ~= nil and err ~= "") then return "" end local match = find(page, "/ip-address/(.*)/" .. domain) if (match == nil or #match == 0) then return "" end return match[1] end function gettoken(ctx, domain, path) local u = "http://ipv4info.com" .. path local page, err = request(ctx, {['url']=u}) if (err ~= nil and err ~= "") then return "" end local match = submatch(page, "/dns/(.*?)/" .. domain) if (match == nil or #match < 2) then return "" end return match[2] end function nextpage(ctx, domain, resp, page) local match = find(resp, "/subdomains/(.*)/" .. page .. "/" .. domain .. ".html") if (match == nil or #match == 0) then return "" end local u = "http://ipv4info.com" .. match[1] local page, err = request(ctx, {['url']=u}) if (err ~= nil and err ~= "") then return "" end return page 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
--------------------------------------------------------------- -- SPECIFICATIONS FILE --------------------------------------------------------------- -- Author: Matthew Bennett --- -- Class: CSC410 Burgess --- -- Date: 09-01-04 Modified: 9-02-04 --- -- Desc: Assignment 1:DEKKER's ALGORITHM --- -- a simple implementation of --- -- Dekker's algorithm which describes mutual exclusion for --- -- two processes (TASKS) assuming fair hardware. --- -- Dekker's algorithm as described in --- -- "Algorithms for Mutual Exclusion", M. Raynal --- -- MIT PRESS Cambridge, 1974 ISBN: 0-262-18119-3 --- ---------------------------------------------------------------- PACKAGE as1 IS --package for assignment #1, dekkers algorithm PROCEDURE dekker; END as1;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- U R E A L P -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2010, 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 Alloc; with Output; use Output; with Table; with Tree_IO; use Tree_IO; package body Urealp is Ureal_First_Entry : constant Ureal := Ureal'Succ (No_Ureal); -- First subscript allocated in Ureal table (note that we can't just -- add 1 to No_Ureal, since "+" means something different for Ureals! type Ureal_Entry is record Num : Uint; -- Numerator (always non-negative) Den : Uint; -- Denominator (always non-zero, always positive if base is zero) Rbase : Nat; -- Base value. If Rbase is zero, then the value is simply Num / Den. -- If Rbase is non-zero, then the value is Num / (Rbase ** Den) Negative : Boolean; -- Flag set if value is negative end record; -- The following representation clause ensures that the above record -- has no holes. We do this so that when instances of this record are -- written by Tree_Gen, we do not write uninitialized values to the file. for Ureal_Entry use record Num at 0 range 0 .. 31; Den at 4 range 0 .. 31; Rbase at 8 range 0 .. 31; Negative at 12 range 0 .. 31; end record; for Ureal_Entry'Size use 16 * 8; -- This ensures that we did not leave out any fields package Ureals is new Table.Table ( Table_Component_Type => Ureal_Entry, Table_Index_Type => Ureal'Base, Table_Low_Bound => Ureal_First_Entry, Table_Initial => Alloc.Ureals_Initial, Table_Increment => Alloc.Ureals_Increment, Table_Name => "Ureals"); -- The following universal reals are the values returned by the constant -- functions. They are initialized by the initialization procedure. UR_0 : Ureal; UR_M_0 : Ureal; UR_Tenth : Ureal; UR_Half : Ureal; UR_1 : Ureal; UR_2 : Ureal; UR_10 : Ureal; UR_10_36 : Ureal; UR_M_10_36 : Ureal; UR_100 : Ureal; UR_2_128 : Ureal; UR_2_80 : Ureal; UR_2_M_128 : Ureal; UR_2_M_80 : Ureal; Num_Ureal_Constants : constant := 10; -- This is used for an assertion check in Tree_Read and Tree_Write to -- help remember to add values to these routines when we add to the list. Normalized_Real : Ureal := No_Ureal; -- Used to memoize Norm_Num and Norm_Den, if either of these functions -- is called, this value is set and Normalized_Entry contains the result -- of the normalization. On subsequent calls, this is used to avoid the -- call to Normalize if it has already been made. Normalized_Entry : Ureal_Entry; -- Entry built by most recent call to Normalize ----------------------- -- Local Subprograms -- ----------------------- function Decimal_Exponent_Hi (V : Ureal) return Int; -- Returns an estimate of the exponent of Val represented as a normalized -- decimal number (non-zero digit before decimal point), The estimate is -- either correct, or high, but never low. The accuracy of the estimate -- affects only the efficiency of the comparison routines. function Decimal_Exponent_Lo (V : Ureal) return Int; -- Returns an estimate of the exponent of Val represented as a normalized -- decimal number (non-zero digit before decimal point), The estimate is -- either correct, or low, but never high. The accuracy of the estimate -- affects only the efficiency of the comparison routines. function Equivalent_Decimal_Exponent (U : Ureal_Entry) return Int; -- U is a Ureal entry for which the base value is non-zero, the value -- returned is the equivalent decimal exponent value, i.e. the value of -- Den, adjusted as though the base were base 10. The value is rounded -- to the nearest integer, and so can be one off. function Is_Integer (Num, Den : Uint) return Boolean; -- Return true if the real quotient of Num / Den is an integer value function Normalize (Val : Ureal_Entry) return Ureal_Entry; -- Normalizes the Ureal_Entry by reducing it to lowest terms (with a base -- value of 0). function Same (U1, U2 : Ureal) return Boolean; pragma Inline (Same); -- Determines if U1 and U2 are the same Ureal. Note that we cannot use -- the equals operator for this test, since that tests for equality, not -- identity. function Store_Ureal (Val : Ureal_Entry) return Ureal; -- This store a new entry in the universal reals table and return its index -- in the table. function Store_Ureal_Normalized (Val : Ureal_Entry) return Ureal; pragma Inline (Store_Ureal_Normalized); -- Like Store_Ureal, but normalizes its operand first. ------------------------- -- Decimal_Exponent_Hi -- ------------------------- function Decimal_Exponent_Hi (V : Ureal) return Int is Val : constant Ureal_Entry := Ureals.Table (V); begin -- Zero always returns zero if UR_Is_Zero (V) then return 0; -- For numbers in rational form, get the maximum number of digits in the -- numerator and the minimum number of digits in the denominator, and -- subtract. For example: -- 1000 / 99 = 1.010E+1 -- 9999 / 10 = 9.999E+2 -- This estimate may of course be high, but that is acceptable elsif Val.Rbase = 0 then return UI_Decimal_Digits_Hi (Val.Num) - UI_Decimal_Digits_Lo (Val.Den); -- For based numbers, just subtract the decimal exponent from the -- high estimate of the number of digits in the numerator and add -- one to accommodate possible round off errors for non-decimal -- bases. For example: -- 1_500_000 / 10**4 = 1.50E-2 else -- Val.Rbase /= 0 return UI_Decimal_Digits_Hi (Val.Num) - Equivalent_Decimal_Exponent (Val) + 1; end if; end Decimal_Exponent_Hi; ------------------------- -- Decimal_Exponent_Lo -- ------------------------- function Decimal_Exponent_Lo (V : Ureal) return Int is Val : constant Ureal_Entry := Ureals.Table (V); begin -- Zero always returns zero if UR_Is_Zero (V) then return 0; -- For numbers in rational form, get min digits in numerator, max digits -- in denominator, and subtract and subtract one more for possible loss -- during the division. For example: -- 1000 / 99 = 1.010E+1 -- 9999 / 10 = 9.999E+2 -- This estimate may of course be low, but that is acceptable elsif Val.Rbase = 0 then return UI_Decimal_Digits_Lo (Val.Num) - UI_Decimal_Digits_Hi (Val.Den) - 1; -- For based numbers, just subtract the decimal exponent from the -- low estimate of the number of digits in the numerator and subtract -- one to accommodate possible round off errors for non-decimal -- bases. For example: -- 1_500_000 / 10**4 = 1.50E-2 else -- Val.Rbase /= 0 return UI_Decimal_Digits_Lo (Val.Num) - Equivalent_Decimal_Exponent (Val) - 1; end if; end Decimal_Exponent_Lo; ----------------- -- Denominator -- ----------------- function Denominator (Real : Ureal) return Uint is begin return Ureals.Table (Real).Den; end Denominator; --------------------------------- -- Equivalent_Decimal_Exponent -- --------------------------------- function Equivalent_Decimal_Exponent (U : Ureal_Entry) return Int is -- The following table is a table of logs to the base 10 Logs : constant array (Nat range 1 .. 16) of Long_Float := ( 1 => 0.000000000000000, 2 => 0.301029995663981, 3 => 0.477121254719662, 4 => 0.602059991327962, 5 => 0.698970004336019, 6 => 0.778151250383644, 7 => 0.845098040014257, 8 => 0.903089986991944, 9 => 0.954242509439325, 10 => 1.000000000000000, 11 => 1.041392685158230, 12 => 1.079181246047620, 13 => 1.113943352306840, 14 => 1.146128035678240, 15 => 1.176091259055680, 16 => 1.204119982655920); begin pragma Assert (U.Rbase /= 0); return Int (Long_Float (UI_To_Int (U.Den)) * Logs (U.Rbase)); end Equivalent_Decimal_Exponent; ---------------- -- Initialize -- ---------------- procedure Initialize is begin Ureals.Init; UR_0 := UR_From_Components (Uint_0, Uint_1, 0, False); UR_M_0 := UR_From_Components (Uint_0, Uint_1, 0, True); UR_Half := UR_From_Components (Uint_1, Uint_1, 2, False); UR_Tenth := UR_From_Components (Uint_1, Uint_1, 10, False); UR_1 := UR_From_Components (Uint_1, Uint_1, 0, False); UR_2 := UR_From_Components (Uint_1, Uint_Minus_1, 2, False); UR_10 := UR_From_Components (Uint_1, Uint_Minus_1, 10, False); UR_10_36 := UR_From_Components (Uint_1, Uint_Minus_36, 10, False); UR_M_10_36 := UR_From_Components (Uint_1, Uint_Minus_36, 10, True); UR_100 := UR_From_Components (Uint_1, Uint_Minus_2, 10, False); UR_2_128 := UR_From_Components (Uint_1, Uint_Minus_128, 2, False); UR_2_M_128 := UR_From_Components (Uint_1, Uint_128, 2, False); UR_2_80 := UR_From_Components (Uint_1, Uint_Minus_80, 2, False); UR_2_M_80 := UR_From_Components (Uint_1, Uint_80, 2, False); end Initialize; ---------------- -- Is_Integer -- ---------------- function Is_Integer (Num, Den : Uint) return Boolean is begin return (Num / Den) * Den = Num; end Is_Integer; ---------- -- Mark -- ---------- function Mark return Save_Mark is begin return Save_Mark (Ureals.Last); end Mark; -------------- -- Norm_Den -- -------------- function Norm_Den (Real : Ureal) return Uint is begin if not Same (Real, Normalized_Real) then Normalized_Real := Real; Normalized_Entry := Normalize (Ureals.Table (Real)); end if; return Normalized_Entry.Den; end Norm_Den; -------------- -- Norm_Num -- -------------- function Norm_Num (Real : Ureal) return Uint is begin if not Same (Real, Normalized_Real) then Normalized_Real := Real; Normalized_Entry := Normalize (Ureals.Table (Real)); end if; return Normalized_Entry.Num; end Norm_Num; --------------- -- Normalize -- --------------- function Normalize (Val : Ureal_Entry) return Ureal_Entry is J : Uint; K : Uint; Tmp : Uint; Num : Uint; Den : Uint; M : constant Uintp.Save_Mark := Uintp.Mark; begin -- Start by setting J to the greatest of the absolute values of the -- numerator and the denominator (taking into account the base value), -- and K to the lesser of the two absolute values. The gcd of Num and -- Den is the gcd of J and K. if Val.Rbase = 0 then J := Val.Num; K := Val.Den; elsif Val.Den < 0 then J := Val.Num * Val.Rbase ** (-Val.Den); K := Uint_1; else J := Val.Num; K := Val.Rbase ** Val.Den; end if; Num := J; Den := K; if K > J then Tmp := J; J := K; K := Tmp; end if; J := UI_GCD (J, K); Num := Num / J; Den := Den / J; Uintp.Release_And_Save (M, Num, Den); -- Divide numerator and denominator by gcd and return result return (Num => Num, Den => Den, Rbase => 0, Negative => Val.Negative); end Normalize; --------------- -- Numerator -- --------------- function Numerator (Real : Ureal) return Uint is begin return Ureals.Table (Real).Num; end Numerator; -------- -- pr -- -------- procedure pr (Real : Ureal) is begin UR_Write (Real); Write_Eol; end pr; ----------- -- Rbase -- ----------- function Rbase (Real : Ureal) return Nat is begin return Ureals.Table (Real).Rbase; end Rbase; ------------- -- Release -- ------------- procedure Release (M : Save_Mark) is begin Ureals.Set_Last (Ureal (M)); end Release; ---------- -- Same -- ---------- function Same (U1, U2 : Ureal) return Boolean is begin return Int (U1) = Int (U2); end Same; ----------------- -- Store_Ureal -- ----------------- function Store_Ureal (Val : Ureal_Entry) return Ureal is begin Ureals.Append (Val); -- Normalize representation of signed values if Val.Num < 0 then Ureals.Table (Ureals.Last).Negative := True; Ureals.Table (Ureals.Last).Num := -Val.Num; end if; return Ureals.Last; end Store_Ureal; ---------------------------- -- Store_Ureal_Normalized -- ---------------------------- function Store_Ureal_Normalized (Val : Ureal_Entry) return Ureal is begin return Store_Ureal (Normalize (Val)); end Store_Ureal_Normalized; --------------- -- Tree_Read -- --------------- procedure Tree_Read is begin pragma Assert (Num_Ureal_Constants = 10); Ureals.Tree_Read; Tree_Read_Int (Int (UR_0)); Tree_Read_Int (Int (UR_M_0)); Tree_Read_Int (Int (UR_Tenth)); Tree_Read_Int (Int (UR_Half)); Tree_Read_Int (Int (UR_1)); Tree_Read_Int (Int (UR_2)); Tree_Read_Int (Int (UR_10)); Tree_Read_Int (Int (UR_100)); Tree_Read_Int (Int (UR_2_128)); Tree_Read_Int (Int (UR_2_M_128)); -- Clear the normalization cache Normalized_Real := No_Ureal; end Tree_Read; ---------------- -- Tree_Write -- ---------------- procedure Tree_Write is begin pragma Assert (Num_Ureal_Constants = 10); Ureals.Tree_Write; Tree_Write_Int (Int (UR_0)); Tree_Write_Int (Int (UR_M_0)); Tree_Write_Int (Int (UR_Tenth)); Tree_Write_Int (Int (UR_Half)); Tree_Write_Int (Int (UR_1)); Tree_Write_Int (Int (UR_2)); Tree_Write_Int (Int (UR_10)); Tree_Write_Int (Int (UR_100)); Tree_Write_Int (Int (UR_2_128)); Tree_Write_Int (Int (UR_2_M_128)); end Tree_Write; ------------ -- UR_Abs -- ------------ function UR_Abs (Real : Ureal) return Ureal is Val : constant Ureal_Entry := Ureals.Table (Real); begin return Store_Ureal ((Num => Val.Num, Den => Val.Den, Rbase => Val.Rbase, Negative => False)); end UR_Abs; ------------ -- UR_Add -- ------------ function UR_Add (Left : Uint; Right : Ureal) return Ureal is begin return UR_From_Uint (Left) + Right; end UR_Add; function UR_Add (Left : Ureal; Right : Uint) return Ureal is begin return Left + UR_From_Uint (Right); end UR_Add; function UR_Add (Left : Ureal; Right : Ureal) return Ureal is Lval : Ureal_Entry := Ureals.Table (Left); Rval : Ureal_Entry := Ureals.Table (Right); Num : Uint; begin -- Note, in the temporary Ureal_Entry values used in this procedure, -- we store the sign as the sign of the numerator (i.e. xxx.Num may -- be negative, even though in stored entries this can never be so) if Lval.Rbase /= 0 and then Lval.Rbase = Rval.Rbase then declare Opd_Min, Opd_Max : Ureal_Entry; Exp_Min, Exp_Max : Uint; begin if Lval.Negative then Lval.Num := (-Lval.Num); end if; if Rval.Negative then Rval.Num := (-Rval.Num); end if; if Lval.Den < Rval.Den then Exp_Min := Lval.Den; Exp_Max := Rval.Den; Opd_Min := Lval; Opd_Max := Rval; else Exp_Min := Rval.Den; Exp_Max := Lval.Den; Opd_Min := Rval; Opd_Max := Lval; end if; Num := Opd_Min.Num * Lval.Rbase ** (Exp_Max - Exp_Min) + Opd_Max.Num; if Num = 0 then return Store_Ureal ((Num => Uint_0, Den => Uint_1, Rbase => 0, Negative => Lval.Negative)); else return Store_Ureal ((Num => abs Num, Den => Exp_Max, Rbase => Lval.Rbase, Negative => (Num < 0))); end if; end; else declare Ln : Ureal_Entry := Normalize (Lval); Rn : Ureal_Entry := Normalize (Rval); begin if Ln.Negative then Ln.Num := (-Ln.Num); end if; if Rn.Negative then Rn.Num := (-Rn.Num); end if; Num := (Ln.Num * Rn.Den) + (Rn.Num * Ln.Den); if Num = 0 then return Store_Ureal ((Num => Uint_0, Den => Uint_1, Rbase => 0, Negative => Lval.Negative)); else return Store_Ureal_Normalized ((Num => abs Num, Den => Ln.Den * Rn.Den, Rbase => 0, Negative => (Num < 0))); end if; end; end if; end UR_Add; ---------------- -- UR_Ceiling -- ---------------- function UR_Ceiling (Real : Ureal) return Uint is Val : constant Ureal_Entry := Normalize (Ureals.Table (Real)); begin if Val.Negative then return UI_Negate (Val.Num / Val.Den); else return (Val.Num + Val.Den - 1) / Val.Den; end if; end UR_Ceiling; ------------ -- UR_Div -- ------------ function UR_Div (Left : Uint; Right : Ureal) return Ureal is begin return UR_From_Uint (Left) / Right; end UR_Div; function UR_Div (Left : Ureal; Right : Uint) return Ureal is begin return Left / UR_From_Uint (Right); end UR_Div; function UR_Div (Left, Right : Ureal) return Ureal is Lval : constant Ureal_Entry := Ureals.Table (Left); Rval : constant Ureal_Entry := Ureals.Table (Right); Rneg : constant Boolean := Rval.Negative xor Lval.Negative; begin pragma Assert (Rval.Num /= Uint_0); if Lval.Rbase = 0 then if Rval.Rbase = 0 then return Store_Ureal_Normalized ((Num => Lval.Num * Rval.Den, Den => Lval.Den * Rval.Num, Rbase => 0, Negative => Rneg)); elsif Is_Integer (Lval.Num, Rval.Num * Lval.Den) then return Store_Ureal ((Num => Lval.Num / (Rval.Num * Lval.Den), Den => (-Rval.Den), Rbase => Rval.Rbase, Negative => Rneg)); elsif Rval.Den < 0 then return Store_Ureal_Normalized ((Num => Lval.Num, Den => Rval.Rbase ** (-Rval.Den) * Rval.Num * Lval.Den, Rbase => 0, Negative => Rneg)); else return Store_Ureal_Normalized ((Num => Lval.Num * Rval.Rbase ** Rval.Den, Den => Rval.Num * Lval.Den, Rbase => 0, Negative => Rneg)); end if; elsif Is_Integer (Lval.Num, Rval.Num) then if Rval.Rbase = Lval.Rbase then return Store_Ureal ((Num => Lval.Num / Rval.Num, Den => Lval.Den - Rval.Den, Rbase => Lval.Rbase, Negative => Rneg)); elsif Rval.Rbase = 0 then return Store_Ureal ((Num => (Lval.Num / Rval.Num) * Rval.Den, Den => Lval.Den, Rbase => Lval.Rbase, Negative => Rneg)); elsif Rval.Den < 0 then declare Num, Den : Uint; begin if Lval.Den < 0 then Num := (Lval.Num / Rval.Num) * (Lval.Rbase ** (-Lval.Den)); Den := Rval.Rbase ** (-Rval.Den); else Num := Lval.Num / Rval.Num; Den := (Lval.Rbase ** Lval.Den) * (Rval.Rbase ** (-Rval.Den)); end if; return Store_Ureal ((Num => Num, Den => Den, Rbase => 0, Negative => Rneg)); end; else return Store_Ureal ((Num => (Lval.Num / Rval.Num) * (Rval.Rbase ** Rval.Den), Den => Lval.Den, Rbase => Lval.Rbase, Negative => Rneg)); end if; else declare Num, Den : Uint; begin if Lval.Den < 0 then Num := Lval.Num * (Lval.Rbase ** (-Lval.Den)); Den := Rval.Num; else Num := Lval.Num; Den := Rval.Num * (Lval.Rbase ** Lval.Den); end if; if Rval.Rbase /= 0 then if Rval.Den < 0 then Den := Den * (Rval.Rbase ** (-Rval.Den)); else Num := Num * (Rval.Rbase ** Rval.Den); end if; else Num := Num * Rval.Den; end if; return Store_Ureal_Normalized ((Num => Num, Den => Den, Rbase => 0, Negative => Rneg)); end; end if; end UR_Div; ----------- -- UR_Eq -- ----------- function UR_Eq (Left, Right : Ureal) return Boolean is begin return not UR_Ne (Left, Right); end UR_Eq; --------------------- -- UR_Exponentiate -- --------------------- function UR_Exponentiate (Real : Ureal; N : Uint) return Ureal is X : constant Uint := abs N; Bas : Ureal; Val : Ureal_Entry; Neg : Boolean; IBas : Uint; begin -- If base is negative, then the resulting sign depends on whether -- the exponent is even or odd (even => positive, odd = negative) if UR_Is_Negative (Real) then Neg := (N mod 2) /= 0; Bas := UR_Negate (Real); else Neg := False; Bas := Real; end if; Val := Ureals.Table (Bas); -- If the base is a small integer, then we can return the result in -- exponential form, which can save a lot of time for junk exponents. IBas := UR_Trunc (Bas); if IBas <= 16 and then UR_From_Uint (IBas) = Bas then return Store_Ureal ((Num => Uint_1, Den => -N, Rbase => UI_To_Int (UR_Trunc (Bas)), Negative => Neg)); -- If the exponent is negative then we raise the numerator and the -- denominator (after normalization) to the absolute value of the -- exponent and we return the reciprocal. An assert error will happen -- if the numerator is zero. elsif N < 0 then pragma Assert (Val.Num /= 0); Val := Normalize (Val); return Store_Ureal ((Num => Val.Den ** X, Den => Val.Num ** X, Rbase => 0, Negative => Neg)); -- If positive, we distinguish the case when the base is not zero, in -- which case the new denominator is just the product of the old one -- with the exponent, else if Val.Rbase /= 0 then return Store_Ureal ((Num => Val.Num ** X, Den => Val.Den * X, Rbase => Val.Rbase, Negative => Neg)); -- And when the base is zero, in which case we exponentiate -- the old denominator. else return Store_Ureal ((Num => Val.Num ** X, Den => Val.Den ** X, Rbase => 0, Negative => Neg)); end if; end if; end UR_Exponentiate; -------------- -- UR_Floor -- -------------- function UR_Floor (Real : Ureal) return Uint is Val : constant Ureal_Entry := Normalize (Ureals.Table (Real)); begin if Val.Negative then return UI_Negate ((Val.Num + Val.Den - 1) / Val.Den); else return Val.Num / Val.Den; end if; end UR_Floor; ------------------------ -- UR_From_Components -- ------------------------ function UR_From_Components (Num : Uint; Den : Uint; Rbase : Nat := 0; Negative : Boolean := False) return Ureal is begin return Store_Ureal ((Num => Num, Den => Den, Rbase => Rbase, Negative => Negative)); end UR_From_Components; ------------------ -- UR_From_Uint -- ------------------ function UR_From_Uint (UI : Uint) return Ureal is begin return UR_From_Components (abs UI, Uint_1, Negative => (UI < 0)); end UR_From_Uint; ----------- -- UR_Ge -- ----------- function UR_Ge (Left, Right : Ureal) return Boolean is begin return not (Left < Right); end UR_Ge; ----------- -- UR_Gt -- ----------- function UR_Gt (Left, Right : Ureal) return Boolean is begin return (Right < Left); end UR_Gt; -------------------- -- UR_Is_Negative -- -------------------- function UR_Is_Negative (Real : Ureal) return Boolean is begin return Ureals.Table (Real).Negative; end UR_Is_Negative; -------------------- -- UR_Is_Positive -- -------------------- function UR_Is_Positive (Real : Ureal) return Boolean is begin return not Ureals.Table (Real).Negative and then Ureals.Table (Real).Num /= 0; end UR_Is_Positive; ---------------- -- UR_Is_Zero -- ---------------- function UR_Is_Zero (Real : Ureal) return Boolean is begin return Ureals.Table (Real).Num = 0; end UR_Is_Zero; ----------- -- UR_Le -- ----------- function UR_Le (Left, Right : Ureal) return Boolean is begin return not (Right < Left); end UR_Le; ----------- -- UR_Lt -- ----------- function UR_Lt (Left, Right : Ureal) return Boolean is begin -- An operand is not less than itself if Same (Left, Right) then return False; -- Deal with zero cases elsif UR_Is_Zero (Left) then return UR_Is_Positive (Right); elsif UR_Is_Zero (Right) then return Ureals.Table (Left).Negative; -- Different signs are decisive (note we dealt with zero cases) elsif Ureals.Table (Left).Negative and then not Ureals.Table (Right).Negative then return True; elsif not Ureals.Table (Left).Negative and then Ureals.Table (Right).Negative then return False; -- Signs are same, do rapid check based on worst case estimates of -- decimal exponent, which will often be decisive. Precise test -- depends on whether operands are positive or negative. elsif Decimal_Exponent_Hi (Left) < Decimal_Exponent_Lo (Right) then return UR_Is_Positive (Left); elsif Decimal_Exponent_Lo (Left) > Decimal_Exponent_Hi (Right) then return UR_Is_Negative (Left); -- If we fall through, full gruesome test is required. This happens -- if the numbers are close together, or in some weird (/=10) base. else declare Imrk : constant Uintp.Save_Mark := Mark; Rmrk : constant Urealp.Save_Mark := Mark; Lval : Ureal_Entry; Rval : Ureal_Entry; Result : Boolean; begin Lval := Ureals.Table (Left); Rval := Ureals.Table (Right); -- An optimization. If both numbers are based, then subtract -- common value of base to avoid unnecessarily giant numbers if Lval.Rbase = Rval.Rbase and then Lval.Rbase /= 0 then if Lval.Den < Rval.Den then Rval.Den := Rval.Den - Lval.Den; Lval.Den := Uint_0; else Lval.Den := Lval.Den - Rval.Den; Rval.Den := Uint_0; end if; end if; Lval := Normalize (Lval); Rval := Normalize (Rval); if Lval.Negative then Result := (Lval.Num * Rval.Den) > (Rval.Num * Lval.Den); else Result := (Lval.Num * Rval.Den) < (Rval.Num * Lval.Den); end if; Release (Imrk); Release (Rmrk); return Result; end; end if; end UR_Lt; ------------ -- UR_Max -- ------------ function UR_Max (Left, Right : Ureal) return Ureal is begin if Left >= Right then return Left; else return Right; end if; end UR_Max; ------------ -- UR_Min -- ------------ function UR_Min (Left, Right : Ureal) return Ureal is begin if Left <= Right then return Left; else return Right; end if; end UR_Min; ------------ -- UR_Mul -- ------------ function UR_Mul (Left : Uint; Right : Ureal) return Ureal is begin return UR_From_Uint (Left) * Right; end UR_Mul; function UR_Mul (Left : Ureal; Right : Uint) return Ureal is begin return Left * UR_From_Uint (Right); end UR_Mul; function UR_Mul (Left, Right : Ureal) return Ureal is Lval : constant Ureal_Entry := Ureals.Table (Left); Rval : constant Ureal_Entry := Ureals.Table (Right); Num : Uint := Lval.Num * Rval.Num; Den : Uint; Rneg : constant Boolean := Lval.Negative xor Rval.Negative; begin if Lval.Rbase = 0 then if Rval.Rbase = 0 then return Store_Ureal_Normalized ((Num => Num, Den => Lval.Den * Rval.Den, Rbase => 0, Negative => Rneg)); elsif Is_Integer (Num, Lval.Den) then return Store_Ureal ((Num => Num / Lval.Den, Den => Rval.Den, Rbase => Rval.Rbase, Negative => Rneg)); elsif Rval.Den < 0 then return Store_Ureal_Normalized ((Num => Num * (Rval.Rbase ** (-Rval.Den)), Den => Lval.Den, Rbase => 0, Negative => Rneg)); else return Store_Ureal_Normalized ((Num => Num, Den => Lval.Den * (Rval.Rbase ** Rval.Den), Rbase => 0, Negative => Rneg)); end if; elsif Lval.Rbase = Rval.Rbase then return Store_Ureal ((Num => Num, Den => Lval.Den + Rval.Den, Rbase => Lval.Rbase, Negative => Rneg)); elsif Rval.Rbase = 0 then if Is_Integer (Num, Rval.Den) then return Store_Ureal ((Num => Num / Rval.Den, Den => Lval.Den, Rbase => Lval.Rbase, Negative => Rneg)); elsif Lval.Den < 0 then return Store_Ureal_Normalized ((Num => Num * (Lval.Rbase ** (-Lval.Den)), Den => Rval.Den, Rbase => 0, Negative => Rneg)); else return Store_Ureal_Normalized ((Num => Num, Den => Rval.Den * (Lval.Rbase ** Lval.Den), Rbase => 0, Negative => Rneg)); end if; else Den := Uint_1; if Lval.Den < 0 then Num := Num * (Lval.Rbase ** (-Lval.Den)); else Den := Den * (Lval.Rbase ** Lval.Den); end if; if Rval.Den < 0 then Num := Num * (Rval.Rbase ** (-Rval.Den)); else Den := Den * (Rval.Rbase ** Rval.Den); end if; return Store_Ureal_Normalized ((Num => Num, Den => Den, Rbase => 0, Negative => Rneg)); end if; end UR_Mul; ----------- -- UR_Ne -- ----------- function UR_Ne (Left, Right : Ureal) return Boolean is begin -- Quick processing for case of identical Ureal values (note that -- this also deals with comparing two No_Ureal values). if Same (Left, Right) then return False; -- Deal with case of one or other operand is No_Ureal, but not both elsif Same (Left, No_Ureal) or else Same (Right, No_Ureal) then return True; -- Do quick check based on number of decimal digits elsif Decimal_Exponent_Hi (Left) < Decimal_Exponent_Lo (Right) or else Decimal_Exponent_Lo (Left) > Decimal_Exponent_Hi (Right) then return True; -- Otherwise full comparison is required else declare Imrk : constant Uintp.Save_Mark := Mark; Rmrk : constant Urealp.Save_Mark := Mark; Lval : constant Ureal_Entry := Normalize (Ureals.Table (Left)); Rval : constant Ureal_Entry := Normalize (Ureals.Table (Right)); Result : Boolean; begin if UR_Is_Zero (Left) then return not UR_Is_Zero (Right); elsif UR_Is_Zero (Right) then return not UR_Is_Zero (Left); -- Both operands are non-zero else Result := Rval.Negative /= Lval.Negative or else Rval.Num /= Lval.Num or else Rval.Den /= Lval.Den; Release (Imrk); Release (Rmrk); return Result; end if; end; end if; end UR_Ne; --------------- -- UR_Negate -- --------------- function UR_Negate (Real : Ureal) return Ureal is begin return Store_Ureal ((Num => Ureals.Table (Real).Num, Den => Ureals.Table (Real).Den, Rbase => Ureals.Table (Real).Rbase, Negative => not Ureals.Table (Real).Negative)); end UR_Negate; ------------ -- UR_Sub -- ------------ function UR_Sub (Left : Uint; Right : Ureal) return Ureal is begin return UR_From_Uint (Left) + UR_Negate (Right); end UR_Sub; function UR_Sub (Left : Ureal; Right : Uint) return Ureal is begin return Left + UR_From_Uint (-Right); end UR_Sub; function UR_Sub (Left, Right : Ureal) return Ureal is begin return Left + UR_Negate (Right); end UR_Sub; ---------------- -- UR_To_Uint -- ---------------- function UR_To_Uint (Real : Ureal) return Uint is Val : constant Ureal_Entry := Normalize (Ureals.Table (Real)); Res : Uint; begin Res := (Val.Num + (Val.Den / 2)) / Val.Den; if Val.Negative then return UI_Negate (Res); else return Res; end if; end UR_To_Uint; -------------- -- UR_Trunc -- -------------- function UR_Trunc (Real : Ureal) return Uint is Val : constant Ureal_Entry := Normalize (Ureals.Table (Real)); begin if Val.Negative then return -(Val.Num / Val.Den); else return Val.Num / Val.Den; end if; end UR_Trunc; -------------- -- UR_Write -- -------------- procedure UR_Write (Real : Ureal; Brackets : Boolean := False) is Val : constant Ureal_Entry := Ureals.Table (Real); T : Uint; begin -- If value is negative, we precede the constant by a minus sign if Val.Negative then Write_Char ('-'); end if; -- Zero is zero if Val.Num = 0 then Write_Str ("0.0"); -- For constants with a denominator of zero, the value is simply the -- numerator value, since we are dividing by base**0, which is 1. elsif Val.Den = 0 then UI_Write (Val.Num, Decimal); Write_Str (".0"); -- Small powers of 2 get written in decimal fixed-point format elsif Val.Rbase = 2 and then Val.Den <= 3 and then Val.Den >= -16 then if Val.Den = 1 then T := Val.Num * (10/2); UI_Write (T / 10, Decimal); Write_Char ('.'); UI_Write (T mod 10, Decimal); elsif Val.Den = 2 then T := Val.Num * (100/4); UI_Write (T / 100, Decimal); Write_Char ('.'); UI_Write (T mod 100 / 10, Decimal); if T mod 10 /= 0 then UI_Write (T mod 10, Decimal); end if; elsif Val.Den = 3 then T := Val.Num * (1000 / 8); UI_Write (T / 1000, Decimal); Write_Char ('.'); UI_Write (T mod 1000 / 100, Decimal); if T mod 100 /= 0 then UI_Write (T mod 100 / 10, Decimal); if T mod 10 /= 0 then UI_Write (T mod 10, Decimal); end if; end if; else UI_Write (Val.Num * (Uint_2 ** (-Val.Den)), Decimal); Write_Str (".0"); end if; -- Constants in base 10 or 16 can be written in normal Ada literal -- style, as long as they fit in the UI_Image_Buffer. Using hexadecimal -- notation, 4 bytes are required for the 16# # part, and every fifth -- character is an underscore. So, a buffer of size N has room for -- ((N - 4) - (N - 4) / 5) * 4 bits, -- or at least -- N * 16 / 5 - 12 bits. elsif (Val.Rbase = 10 or else Val.Rbase = 16) and then Num_Bits (Val.Num) < UI_Image_Buffer'Length * 16 / 5 - 12 then pragma Assert (Val.Den /= 0); -- Use fixed-point format for small scaling values if (Val.Rbase = 10 and then Val.Den < 0 and then Val.Den > -3) or else (Val.Rbase = 16 and then Val.Den = -1) then UI_Write (Val.Num * Val.Rbase**(-Val.Den), Decimal); Write_Str (".0"); -- Write hexadecimal constants in exponential notation with a zero -- unit digit. This matches the Ada canonical form for floating point -- numbers, and also ensures that the underscores end up in the -- correct place. elsif Val.Rbase = 16 then UI_Image (Val.Num, Hex); pragma Assert (Val.Rbase = 16); Write_Str ("16#0."); Write_Str (UI_Image_Buffer (4 .. UI_Image_Length)); -- For exponent, exclude 16# # and underscores from length UI_Image_Length := UI_Image_Length - 4; UI_Image_Length := UI_Image_Length - UI_Image_Length / 5; Write_Char ('E'); UI_Write (Int (UI_Image_Length) - Val.Den, Decimal); elsif Val.Den = 1 then UI_Write (Val.Num / 10, Decimal); Write_Char ('.'); UI_Write (Val.Num mod 10, Decimal); elsif Val.Den = 2 then UI_Write (Val.Num / 100, Decimal); Write_Char ('.'); UI_Write (Val.Num / 10 mod 10, Decimal); UI_Write (Val.Num mod 10, Decimal); -- Else use decimal exponential format else -- Write decimal constants with a non-zero unit digit. This -- matches usual scientific notation. UI_Image (Val.Num, Decimal); Write_Char (UI_Image_Buffer (1)); Write_Char ('.'); if UI_Image_Length = 1 then Write_Char ('0'); else Write_Str (UI_Image_Buffer (2 .. UI_Image_Length)); end if; Write_Char ('E'); UI_Write (Int (UI_Image_Length - 1) - Val.Den, Decimal); end if; -- Constants in a base other than 10 can still be easily written in -- normal Ada literal style if the numerator is one. elsif Val.Rbase /= 0 and then Val.Num = 1 then Write_Int (Val.Rbase); Write_Str ("#1.0#E"); UI_Write (-Val.Den); -- Other constants with a base other than 10 are written using one -- of the following forms, depending on the sign of the number -- and the sign of the exponent (= minus denominator value) -- numerator.0*base**exponent -- numerator.0*base**-exponent -- And of course an exponent of 0 can be omitted elsif Val.Rbase /= 0 then if Brackets then Write_Char ('['); end if; UI_Write (Val.Num, Decimal); Write_Str (".0"); if Val.Den /= 0 then Write_Char ('*'); Write_Int (Val.Rbase); Write_Str ("**"); if Val.Den <= 0 then UI_Write (-Val.Den, Decimal); else Write_Str ("(-"); UI_Write (Val.Den, Decimal); Write_Char (')'); end if; end if; if Brackets then Write_Char (']'); end if; -- Rationals where numerator is divisible by denominator can be output -- as literals after we do the division. This includes the common case -- where the denominator is 1. elsif Val.Num mod Val.Den = 0 then UI_Write (Val.Num / Val.Den, Decimal); Write_Str (".0"); -- Other non-based (rational) constants are written in num/den style else if Brackets then Write_Char ('['); end if; UI_Write (Val.Num, Decimal); Write_Str (".0/"); UI_Write (Val.Den, Decimal); Write_Str (".0"); if Brackets then Write_Char (']'); end if; end if; end UR_Write; ------------- -- Ureal_0 -- ------------- function Ureal_0 return Ureal is begin return UR_0; end Ureal_0; ------------- -- Ureal_1 -- ------------- function Ureal_1 return Ureal is begin return UR_1; end Ureal_1; ------------- -- Ureal_2 -- ------------- function Ureal_2 return Ureal is begin return UR_2; end Ureal_2; -------------- -- Ureal_10 -- -------------- function Ureal_10 return Ureal is begin return UR_10; end Ureal_10; --------------- -- Ureal_100 -- --------------- function Ureal_100 return Ureal is begin return UR_100; end Ureal_100; ----------------- -- Ureal_10_36 -- ----------------- function Ureal_10_36 return Ureal is begin return UR_10_36; end Ureal_10_36; ---------------- -- Ureal_2_80 -- ---------------- function Ureal_2_80 return Ureal is begin return UR_2_80; end Ureal_2_80; ----------------- -- Ureal_2_128 -- ----------------- function Ureal_2_128 return Ureal is begin return UR_2_128; end Ureal_2_128; ------------------- -- Ureal_2_M_80 -- ------------------- function Ureal_2_M_80 return Ureal is begin return UR_2_M_80; end Ureal_2_M_80; ------------------- -- Ureal_2_M_128 -- ------------------- function Ureal_2_M_128 return Ureal is begin return UR_2_M_128; end Ureal_2_M_128; ---------------- -- Ureal_Half -- ---------------- function Ureal_Half return Ureal is begin return UR_Half; end Ureal_Half; --------------- -- Ureal_M_0 -- --------------- function Ureal_M_0 return Ureal is begin return UR_M_0; end Ureal_M_0; ------------------- -- Ureal_M_10_36 -- ------------------- function Ureal_M_10_36 return Ureal is begin return UR_M_10_36; end Ureal_M_10_36; ----------------- -- Ureal_Tenth -- ----------------- function Ureal_Tenth return Ureal is begin return UR_Tenth; end Ureal_Tenth; end Urealp;
----------------------------------------------------------------------- -- Ada Labs -- -- -- -- Copyright (C) 2008-2009, AdaCore -- -- -- -- Labs is free software; you can redistribute it and/or modify it -- -- under the terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2 of the License, or -- -- (at your option) any later version. -- -- -- -- This program is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- General Public License for more details. You should have received -- -- a copy of the GNU General Public License along with this program; -- -- if not, write to the Free Software Foundation, Inc., 59 Temple -- -- Place - Suite 330, Boston, MA 02111-1307, USA. -- ----------------------------------------------------------------------- with Display; use Display; with Display.Basic; use Display.Basic; package Solar_System is -- define type Bodies_Enum as an enumeration of Sun, Earth, Moon, Satellite type Bodies_Enum_T is (Sun, Earth, Moon, Satellite, Comet, Black_Hole, Asteroid_1, Asteroid_2); procedure Init_Body (B : Bodies_Enum_T; Radius : Float; Color : RGBA_T; Distance : Float; Speed : Float; Turns_Around : Bodies_Enum_T; Angle : Float := 0.0; Tail : Boolean := False; Visible : Boolean := True); type Body_T is private; function Get_Body(B : Bodies_Enum_T) return Body_T; private type Position_T is record X : Float := 0.0; Y : Float := 0.0; end record; type Tail_Length_T is new Integer range 1 .. 10; type Tail_T is array (Tail_Length_T) of Position_T; type Body_T is record Pos : Position_T; Distance : Float; Speed : Float; Angle : Float; Radius : Float; Color : RGBA_T; Visible : Boolean := True; Turns_Around : Bodies_Enum_T; With_Tail : Boolean := False; Tail : Tail_T := (others => (0.0, 0.0)); end record; protected Dispatch_Tasks is procedure Get_Next_Body (B : out Bodies_Enum_T); private Current : Bodies_Enum_T := Bodies_Enum_T'First; end Dispatch_Tasks; task type T_Move_Body; type Task_Array_T is array (Bodies_Enum_T) of T_Move_Body; Tasks : Task_Array_T; protected type Body_P is function Get_Data return Body_T; procedure Set_Data (B : Body_T); private Data : Body_T; end Body_P; type Bodies_Array_T is array (Bodies_Enum_T) of Body_P; Bodies : Bodies_Array_T; procedure Move (Body_To_Move : in out Body_T; Turns_Around : Body_T); end Solar_System;
with AWS.Response; with AWS.Status; package HTTPd.Callbacks is function Default (Request : in AWS.Status.Data) return AWS.Response.Data; end HTTPd.Callbacks;
with AdaM.Factory; package body AdaM.a_Type.access_type is -- Storage Pool -- record_Version : constant := 1; pool_Size : constant := 5_000; package Pool is new AdaM.Factory.Pools (storage_Folder => ".adam-store", pool_Name => "access_Types", max_Items => pool_Size, record_Version => record_Version, Item => a_Type.access_type.item, View => a_Type.access_type.view); -- Forge -- procedure define (Self : in out Item; is_access_to_Object : in Boolean) is the_Definition : Definition (is_access_to_Object); begin if is_access_to_Object then the_Definition.Indication := AdaM.subtype_Indication.new_Indication; else the_Definition.Subprogram := AdaM.Subprogram.new_Subprogram (Name => ""); end if; Self.Def := the_Definition; end define; procedure destruct (Self : in out Item) is begin null; end destruct; function new_Type (is_access_to_Object : in Boolean) return access_Type.view is new_View : constant access_Type.view := Pool.new_Item; begin define (a_Type.access_type.item (new_View.all), is_access_to_Object); return new_View; end new_Type; procedure free (Self : in out access_Type.view) is begin destruct (access_Type.item (Self.all)); Pool.free (Self); end free; -- Attributes -- overriding function Id (Self : access Item) return AdaM.Id is begin return Pool.to_Id (Self); end Id; -- overriding -- function Name (Self : in Item) return Identifier -- is -- pragma Unreferenced (Self); -- begin -- return ""; -- end Name; overriding function to_Source (Self : in Item) return text_Vectors.Vector is pragma Unreferenced (Self); the_Source : text_Vectors.Vector; begin raise Program_Error with "TODO"; return the_Source; end to_Source; function has_not_Null (Self : in Item) return Boolean is begin return Self.has_not_Null; end has_not_Null; procedure has_not_Null (Self : in out Item; Now : in Boolean := True) is begin Self.has_not_Null := Now; end has_not_Null; function is_access_to_Object (Self : in Item) return Boolean is begin return Self.Def.is_access_to_Object; end is_access_to_Object; --- Access to Object -- function Modifier (Self : in Item) return general_access_Modifier is begin return Self.Def.Modifier; end Modifier; procedure Modifier_is (Self : in out Item; Now : in general_access_Modifier) is begin Self.Def.Modifier := Now; end Modifier_is; function Indication (Self : in Item) return subtype_Indication.view is begin return Self.Def.Indication; end Indication; --- Access to Subprogram. -- function is_Protected (Self : in Item) return Boolean is begin return Self.Def.is_Protected; end is_Protected; procedure is_Protected (Self : in out Item; Now : in Boolean := True) is begin Self.Def.is_Protected := Now; end is_Protected; function Subprogram (Self : in Item) return AdaM.Subprogram.view is begin return Self.Def.Subprogram; end Subprogram; ---------- -- Streams -- procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class; Self : in View) renames Pool.View_write; procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class; Self : out View) renames Pool.View_read; end AdaM.a_Type.access_type;
------------------------------------------------------------------------------ -- -- -- ASIS-for-GNAT IMPLEMENTATION COMPONENTS -- -- -- -- A 4 G . M A P P I N G -- -- -- -- B o d y -- -- -- -- Copyright (C) 1995-2012, Free Software Foundation, Inc. -- -- -- -- ASIS-for-GNAT is free software; you can redistribute it and/or modify it -- -- under terms of the GNU General Public License as published by the Free -- -- Software Foundation; either version 2, or (at your option) any later -- -- version. ASIS-for-GNAT is distributed in the hope that it will be use- -- -- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- -- -- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -- -- Public License for more details. You should have received a copy of the -- -- GNU General Public License distributed with ASIS-for-GNAT; see file -- -- COPYING. If not, write to the Free Software Foundation, 51 Franklin -- -- Street, Fifth Floor, Boston, MA 02110-1301, USA. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the -- -- Software Engineering Laboratory of the Swiss Federal Institute of -- -- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the -- -- Scientific Research Computer Center of Moscow State University (SRCC -- -- MSU), Russia, with funding partially provided by grants from the Swiss -- -- National Science Foundation and the Swiss Academy of Engineering -- -- Sciences. ASIS-for-GNAT is now maintained by AdaCore -- -- (http://www.adacore.com). -- -- -- ------------------------------------------------------------------------------ with Ada.Characters.Handling; use Ada.Characters.Handling; with Asis; use Asis; with Asis.Compilation_Units; use Asis.Compilation_Units; with Asis.Elements; use Asis.Elements; with Asis.Set_Get; use Asis.Set_Get; with A4G.A_Debug; use A4G.A_Debug; with A4G.A_Output; use A4G.A_Output; with A4G.A_Sem; use A4G.A_Sem; with A4G.A_Sinput; use A4G.A_Sinput; with A4G.Asis_Tables; use A4G.Asis_Tables; with A4G.Contt; use A4G.Contt; with A4G.Norm; use A4G.Norm; with A4G.Vcheck; use A4G.Vcheck; with Atree; use Atree; with Einfo; use Einfo; with Elists; use Elists; with Namet; use Namet; with Nlists; use Nlists; with Output; use Output; with Snames; use Snames; with Stand; use Stand; with Uintp; use Uintp; with Urealp; use Urealp; package body A4G.Mapping is ------------------------------------------- -- Tree nodes onto ASIS Elements Mapping -- ------------------------------------------- -- The kernel of the mapping from tree nodes onto ASIS Elements is -- determining the ASIS kind of the Element which should be built on top -- of a given node. We are computing the Element position in the internal -- flat classification, that is, the corresponding value of -- Internal_Element_Kinds (which is further referred simply as Element -- kind in this unit). -- -- Mapping of tree nodes onto Element kinds is implemented as two-level -- switching based on look-up tables. Both look-up tables are one-dimension -- arrays indexed by Node_Kind type). -- -- The first table has Internal_Element_Kinds as its component type. It -- defines the mapping of Node_Kind values onto Internal_Element_Kinds -- values as pairs index_value -> component_value, the semantics of this -- mapping depends on the component value in the following way: -- -- Component value First switch mapping semantics -- -- A_Xxx, where A_Xxx corresponds - Element which should be based on -- to some position in the original any node having the corresponding -- ASIS element classification Node_Kind will always be of A_Xxx -- hierarchy (such as An_Identifier) ASIS kind, no more computation -- of Element kind is needed -- -- Non_Trivial_Mapping - Elements which can be built on -- nodes having the corresponding -- Node_Kind may have different ASIS -- kinds, therefore a special function -- computing the ASIS kind should be -- used, this function is defined by -- the second look-up table -- -- No_Mapping - no ASIS Element kind corresponds to -- nodes of the corresponding -- Node_Kind in the framework of the -- given node-to-Element mapping -- -- Not_Implemented_Mapping - this value was used during the -- development phase and now it is -- kept as the value for 'others' -- choice in the initialization -- aggregate just in case if a new -- value appear in Node_Kind type -- -- No_Mapping does not mean, that for a given Node_Kind value no Element -- can be created at all, it means, that automatic Element kind -- determination is impossible for these nodes because of any reason. -- -- Both No_Mapping and Not_Implemented_Mapping mapping items, when chosen. -- resulted in raising the ASIS_Failed exception. The reason because of -- which we keep Not_Implemented_Mapping value after finishing the -- development stage is to catch possible changes in Node_Kind definition. -- No_Mapping means that for sure there is no mapping for a given Node_Kind -- value, and Not_Implemented_Mapping means that processing of the given -- Node_Kind value is missed in the existing code. -- -- The second look-up table defines functions to be used to compute -- Element kind for those Node_Kind values for which the first table -- defines Non_Trivial_Mapping. All these functions are supposed to be -- called for nodes of the Node_Kind from the corresponding mapping item -- defined by the second table, it is erroneous to call them for other -- nodes. -- -- The structure, documentation and naming policy for look-up tables -- implementing note-to-Element mapping are based on the GNAT Sinfo -- package, and, in particular, on the Sinfo.Node_Kind type definition. -- Rather old version of the spec of Sinfo is used, so some deviations -- with the latest version may be possible ------------------------------------------------------ -- Tree nodes lists onto ASIS Element lists Mapping -- ------------------------------------------------------ -- ASIS Element lists are built from tree node lists: when constructing an -- ASIS Element_List value, the corresponding routine goes trough the -- corresponding tree node list, checks which nodes should be used as a -- basis for ASIS Elements to be placed in the result Element_List, and -- which should not, and then calls node-to-Element conversion function -- for the selected nodes. Therefore, two main components of node list to -- Element list mapping are filters for the nodes in the argument node -- list and node-to-Element mapping ----------------------- -- Local subprograms -- ----------------------- procedure Normalize_Name (Capitalized : Boolean := False); -- This procedure "normalizes" a name stored in Namet.Name_Buffer by -- capitalizing its firs letter and all the letters following underscores -- (if any). If Capitalized is set ON, all the letters are converted to -- upper case, this is used for some defining names from Standard (such as -- ASCII) function Is_Protected_Procedure_Call (N : Node_Id) return Boolean; -- In case if N is of N_Entry_Call_Statement, it checks if this is a call -- to a protected subprogram (if it is, the corresponding ASIS Element -- should be classified as A_Procedure_Call_Statement, but not as -- An_Entry_Call_Statement function Is_Stub_To_Body_Instanse_Replacement (N : Node_Id) return Boolean; -- Checks if the node corresponds to the body which replaces the body stub -- within the instance. The reason why we need this is that Sloc -- field is not set to point into the instance copy if the source for -- such node, so the ordinary Is_From_Instance check does not work -- for this node (see 8930-001) function Is_Config_Pragma (N : Node_Id) return Boolean; -- Checks if N represents a configuration pragma function Requires_Parentheses (N : Node_Id) return Boolean; -- Checks if N represents a conditional or quantified expression in the -- context that requires the expression to be in parentheses. The problem -- is that in this case Parent_Count is 0. This function is supposed to be -- called if Parent_Count (N) = 0 -------------------------------------------------------------- -- Subprograms for the second Note-to-Element Look-Up Table -- -------------------------------------------------------------- procedure No_Mapping (Node : Node_Id); function Not_Implemented_Mapping (Node : Node_Id) return Internal_Element_Kinds; procedure Not_Implemented_Mapping (Source_Node_Kind : Node_Kind); -- These three subprograms raise ASIS_Failed with the appropriate -- Diagnosis string pragma No_Return (Not_Implemented_Mapping); pragma No_Return (No_Mapping); -- Individual mapping components: function N_Pragma_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Defining_Identifier_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Defining_Operator_Symbol_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Expanded_Name_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Identifier_Mapping (Node : Node_Id) return Internal_Element_Kinds renames N_Expanded_Name_Mapping; function N_Attribute_Reference_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Function_Call_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Range_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Allocator_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Aggregate_Mapping (Node : Node_Id) return Internal_Element_Kinds; -- |A2005 start function N_Incomplete_Type_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds; -- |A2005 end function N_Subtype_Indication_Mapping (Node : Node_Id) return Internal_Element_Kinds; -- |A2012 start function N_Formal_Type_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Iterator_Specification_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Quantified_Expression_Mapping (Node : Node_Id) return Internal_Element_Kinds; -- |A2012 end function N_Object_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Access_Function_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Access_Procedure_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Subprogram_Body_Stub_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Subprogram_Body_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Subprogram_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Generic_Subprogram_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Constrained_Array_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Unconstrained_Array_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Subprogram_Renaming_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Loop_Statement_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Requeue_Statement_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Abstract_Subprogram_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Accept_Alternative_Mapping (Node : Node_Id) return Internal_Element_Kinds; -- --|A2005 start function N_Access_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds; -- --|A2005 end function N_Access_To_Object_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Component_Association_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Derived_Type_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Delay_Alternative_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Formal_Package_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Formal_Private_Type_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Formal_Subprogram_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Index_Or_Discriminant_Constraint_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Number_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Procedure_Call_Statement_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Range_Constraint_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Record_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Use_Type_Clause_Mapping (Node : Node_Id) return Internal_Element_Kinds; function N_Terminate_Alternative_Mapping (Node : Node_Id) return Internal_Element_Kinds renames N_Accept_Alternative_Mapping; ----------------------------------------- -- Node lists to Element lists filters -- ----------------------------------------- function May_Be_Included (Node : Node_Id) return Boolean; -- Top-level filter for selecting nodes from a node list to be used to -- create ASIS Elements which are members of some ASIS Element List. function Ordinary_Inclusion_Condition (Node : Node_Id) return Boolean; -- Defines the general condition for a separate node list member to be -- used to construct an Element to be returned by some ASIS query. This -- function does not make the final decision, because the node may be -- duplicated, and this is checked in the May_Be_Included function procedure Skip_Normalized_Declarations (Node : in out Node_Id); -- This procedure is applied in case when the compiler normalizes a -- multi-identifier declaration (or multi-name with clause) in a set of -- equivalent one-identifier (one-name) declarations (clauses). It is -- intended to be called for Node representing the first declaration -- (clause) in this normalized sequence, and it resets its parameter -- to point to the last declaration (clause) in this sequence ----------------------------------------- -- Node-to-Element First Look-Up Table -- ----------------------------------------- Node_To_Element_Kind_Mapping_First_Switch : constant array (Node_Kind) of Internal_Element_Kinds := ( N_Unused_At_Start => No_Mapping, N_At_Clause => An_At_Clause, N_Component_Clause => A_Component_Clause, N_Enumeration_Representation_Clause => An_Enumeration_Representation_Clause, N_Mod_Clause => No_Mapping, N_Record_Representation_Clause => A_Record_Representation_Clause, N_Attribute_Definition_Clause => An_Attribute_Definition_Clause, N_Empty => No_Mapping, N_Error => No_Mapping, N_Pragma => Non_Trivial_Mapping, N_Pragma_Argument_Association => A_Pragma_Argument_Association, N_Defining_Character_Literal => A_Defining_Character_Literal, N_Defining_Identifier => Non_Trivial_Mapping, N_Defining_Operator_Symbol => Non_Trivial_Mapping, N_Expanded_Name => Non_Trivial_Mapping, N_Identifier => Non_Trivial_Mapping, N_Character_Literal => A_Character_Literal, N_Operator_Symbol => Non_Trivial_Mapping, N_Op_Add => A_Function_Call, N_Op_And => A_Function_Call, N_And_Then => An_And_Then_Short_Circuit, N_Op_Concat => A_Function_Call, N_Op_Divide => A_Function_Call, N_Op_Eq => A_Function_Call, N_Op_Expon => A_Function_Call, N_Op_Ge => A_Function_Call, N_Op_Gt => A_Function_Call, -- N_In => Non_Trivial_Mapping, N_In => An_In_Membership_Test, N_Op_Le => A_Function_Call, N_Op_Lt => A_Function_Call, N_Op_Mod => A_Function_Call, N_Op_Multiply => A_Function_Call, N_Op_Ne => A_Function_Call, -- N_Not_In => Non_Trivial_Mapping, N_Not_In => A_Not_In_Membership_Test, N_Op_Or => A_Function_Call, N_Or_Else => An_Or_Else_Short_Circuit, N_Op_Rem => A_Function_Call, N_Op_Subtract => A_Function_Call, N_Op_Xor => A_Function_Call, N_Op_Abs => A_Function_Call, N_Op_Minus => A_Function_Call, N_Op_Not => A_Function_Call, N_Op_Plus => A_Function_Call, N_Attribute_Reference => Non_Trivial_Mapping, N_Conditional_Expression => An_If_Expression, N_Explicit_Dereference => An_Explicit_Dereference, N_Function_Call => Non_Trivial_Mapping, N_Indexed_Component => An_Indexed_Component, N_Integer_Literal => An_Integer_Literal, N_Null => A_Null_Literal, N_Procedure_Call_Statement => Non_Trivial_Mapping, N_Qualified_Expression => A_Qualified_Expression, N_Quantified_Expression => Non_Trivial_Mapping, N_Raise_Constraint_Error => No_Mapping, N_Range => Non_Trivial_Mapping, N_Real_Literal => A_Real_Literal, N_Selected_Component => A_Selected_Component, N_Type_Conversion => A_Type_Conversion, N_Allocator => Non_Trivial_Mapping, N_Case_Expression => A_Case_Expression, -- ASIS 2012 N_Aggregate => Non_Trivial_Mapping, N_Extension_Aggregate => An_Extension_Aggregate, N_Slice => A_Slice, N_String_Literal => A_String_Literal, N_Subtype_Indication => Non_Trivial_Mapping, N_Component_Declaration => A_Component_Declaration, N_Entry_Body => An_Entry_Body_Declaration, N_Entry_Declaration => An_Entry_Declaration, -- N_Expression_Function => An_Expression_Function_Declaration, (SCz) N_Entry_Index_Specification => An_Entry_Index_Specification, N_Formal_Object_Declaration => A_Formal_Object_Declaration, N_Formal_Type_Declaration => Non_Trivial_Mapping, N_Freeze_Entity => No_Mapping, N_Full_Type_Declaration => An_Ordinary_Type_Declaration, -- --|A2005 start -- N_Incomplete_Type_Declaration => An_Incomplete_Type_Declaration, N_Incomplete_Type_Declaration => Non_Trivial_Mapping, -- --|A2005 end -- --|A2012 start N_Iterator_Specification => Non_Trivial_Mapping, -- --|A2012 end N_Loop_Parameter_Specification => A_Loop_Parameter_Specification, N_Object_Declaration => Non_Trivial_Mapping, N_Private_Extension_Declaration => A_Private_Extension_Declaration, N_Private_Type_Declaration => A_Private_Type_Declaration, N_Subtype_Declaration => A_Subtype_Declaration, N_Protected_Type_Declaration => A_Protected_Type_Declaration, N_Accept_Statement => An_Accept_Statement, N_Function_Specification => No_Mapping, N_Procedure_Specification => No_Mapping, N_Access_Function_Definition => Non_Trivial_Mapping, N_Access_Procedure_Definition => Non_Trivial_Mapping, N_Task_Type_Declaration => A_Task_Type_Declaration, N_Package_Body_Stub => A_Package_Body_Stub, N_Protected_Body_Stub => A_Protected_Body_Stub, N_Subprogram_Body_Stub => Non_Trivial_Mapping, N_Task_Body_Stub => A_Task_Body_Stub, N_Function_Instantiation => A_Function_Instantiation, N_Package_Instantiation => A_Package_Instantiation, N_Procedure_Instantiation => A_Procedure_Instantiation, N_Package_Body => A_Package_Body_Declaration, N_Subprogram_Body => Non_Trivial_Mapping, N_Implicit_Label_Declaration => No_Mapping, N_Package_Declaration => A_Package_Declaration, N_Single_Task_Declaration => A_Single_Task_Declaration, N_Subprogram_Declaration => Non_Trivial_Mapping, N_Task_Body => A_Task_Body_Declaration, N_Use_Package_Clause => A_Use_Package_Clause, N_Generic_Package_Declaration => A_Generic_Package_Declaration, N_Generic_Subprogram_Declaration => Non_Trivial_Mapping, N_Constrained_Array_Definition => Non_Trivial_Mapping, N_Unconstrained_Array_Definition => Non_Trivial_Mapping, N_Exception_Renaming_Declaration => An_Exception_Renaming_Declaration, N_Object_Renaming_Declaration => An_Object_Renaming_Declaration, N_Package_Renaming_Declaration => A_Package_Renaming_Declaration, N_Subprogram_Renaming_Declaration => Non_Trivial_Mapping, N_Generic_Function_Renaming_Declaration => A_Generic_Function_Renaming_Declaration, N_Generic_Package_Renaming_Declaration => A_Generic_Package_Renaming_Declaration, N_Generic_Procedure_Renaming_Declaration => A_Generic_Procedure_Renaming_Declaration, N_Abort_Statement => An_Abort_Statement, N_Assignment_Statement => An_Assignment_Statement, N_Block_Statement => A_Block_Statement, N_Case_Statement => A_Case_Statement, N_Code_Statement => A_Code_Statement, N_Delay_Relative_Statement => A_Delay_Relative_Statement, N_Delay_Until_Statement => A_Delay_Until_Statement, N_Entry_Call_Statement => An_Entry_Call_Statement, N_Exit_Statement => An_Exit_Statement, N_Free_Statement => No_Mapping, N_Goto_Statement => A_Goto_Statement, N_If_Statement => An_If_Statement, N_Loop_Statement => Non_Trivial_Mapping, N_Null_Statement => A_Null_Statement, N_Raise_Statement => A_Raise_Statement, N_Requeue_Statement => Non_Trivial_Mapping, N_Return_Statement => A_Return_Statement, N_Extended_Return_Statement => An_Extended_Return_Statement, N_Abortable_Part => A_Then_Abort_Path, N_Abstract_Subprogram_Declaration => Non_Trivial_Mapping, N_Accept_Alternative => Non_Trivial_Mapping, -- --|A2005 start N_Access_Definition => Non_Trivial_Mapping, -- --|A2005 end N_Access_To_Object_Definition => Non_Trivial_Mapping, -- --|A2012 start N_Aspect_Specification => An_Aspect_Specification, N_Case_Expression_Alternative => A_Case_Expression_Path, -- --|A2012 end N_Asynchronous_Select => An_Asynchronous_Select_Statement, N_Case_Statement_Alternative => A_Case_Path, N_Compilation_Unit => No_Mapping, N_Component_Association => Non_Trivial_Mapping, N_Component_Definition => A_Component_Definition, N_Conditional_Entry_Call => A_Conditional_Entry_Call_Statement, N_Derived_Type_Definition => Non_Trivial_Mapping, N_Decimal_Fixed_Point_Definition => A_Decimal_Fixed_Point_Definition, N_Defining_Program_Unit_Name => A_Defining_Expanded_Name, N_Delay_Alternative => Non_Trivial_Mapping, N_Delta_Constraint => A_Delta_Constraint, N_Digits_Constraint => A_Digits_Constraint, N_Discriminant_Association => A_Discriminant_Association, N_Discriminant_Specification => A_Discriminant_Specification, N_Elsif_Part => An_Elsif_Path, N_Enumeration_Type_Definition => An_Enumeration_Type_Definition, N_Entry_Call_Alternative => A_Select_Path, N_Exception_Declaration => An_Exception_Declaration, N_Exception_Handler => An_Exception_Handler, N_Floating_Point_Definition => A_Floating_Point_Definition, N_Formal_Decimal_Fixed_Point_Definition => A_Formal_Decimal_Fixed_Point_Definition, N_Formal_Derived_Type_Definition => A_Formal_Derived_Type_Definition, N_Formal_Discrete_Type_Definition => A_Formal_Discrete_Type_Definition, N_Formal_Floating_Point_Definition => A_Formal_Floating_Point_Definition, N_Formal_Modular_Type_Definition => A_Formal_Modular_Type_Definition, N_Formal_Ordinary_Fixed_Point_Definition => A_Formal_Ordinary_Fixed_Point_Definition, N_Formal_Package_Declaration => Non_Trivial_Mapping, N_Formal_Private_Type_Definition => Non_Trivial_Mapping, N_Formal_Signed_Integer_Type_Definition => A_Formal_Signed_Integer_Type_Definition, N_Formal_Subprogram_Declaration => Non_Trivial_Mapping, N_Generic_Association => A_Generic_Association, N_Index_Or_Discriminant_Constraint => Non_Trivial_Mapping, N_Label => No_Mapping, N_Modular_Type_Definition => A_Modular_Type_Definition, N_Number_Declaration => Non_Trivial_Mapping, N_Ordinary_Fixed_Point_Definition => An_Ordinary_Fixed_Point_Definition, N_Others_Choice => An_Others_Choice, N_Package_Specification => No_Mapping, N_Parameter_Association => A_Parameter_Association, N_Parameter_Specification => A_Parameter_Specification, N_Protected_Body => A_Protected_Body_Declaration, N_Protected_Definition => A_Protected_Definition, N_Range_Constraint => Non_Trivial_Mapping, N_Real_Range_Specification => A_Simple_Expression_Range, N_Record_Definition => Non_Trivial_Mapping, N_Selective_Accept => A_Selective_Accept_Statement, N_Signed_Integer_Type_Definition => A_Signed_Integer_Type_Definition, N_Single_Protected_Declaration => A_Single_Protected_Declaration, N_Subunit => No_Mapping, N_Task_Definition => A_Task_Definition, N_Terminate_Alternative => Non_Trivial_Mapping, N_Timed_Entry_Call => A_Timed_Entry_Call_Statement, N_Triggering_Alternative => A_Select_Path, N_Use_Type_Clause => Non_Trivial_Mapping, N_Variant => A_Variant, N_Variant_Part => A_Variant_Part, N_With_Clause => A_With_Clause, N_Unused_At_End => No_Mapping, others => Not_Implemented_Mapping); ------------------------------------------ -- Node-to-Element Second Look-Up Table -- ------------------------------------------ type Mapping_Item is access function (Node : Node_Id) return Internal_Element_Kinds; Node_To_Element_Kind_Mapping_Second_Switch : constant array (Node_Kind) of Mapping_Item := ( N_Pragma => N_Pragma_Mapping'Access, N_Defining_Identifier => N_Defining_Identifier_Mapping'Access, N_Defining_Operator_Symbol => N_Defining_Operator_Symbol_Mapping'Access, N_Expanded_Name => N_Expanded_Name_Mapping'Access, N_Identifier => N_Identifier_Mapping'Access, N_Operator_Symbol => N_Operator_Symbol_Mapping'Access, N_Attribute_Reference => N_Attribute_Reference_Mapping'Access, N_Function_Call => N_Function_Call_Mapping'Access, N_Quantified_Expression => N_Quantified_Expression_Mapping'Access, N_Range => N_Range_Mapping'Access, N_Allocator => N_Allocator_Mapping'Access, N_Aggregate => N_Aggregate_Mapping'Access, N_Subtype_Indication => N_Subtype_Indication_Mapping'Access, -- --|A2012 start N_Formal_Type_Declaration => N_Formal_Type_Declaration_Mapping'Access, -- --|A2012 end -- --|A2005 start -- N_Incomplete_Type_Declaration => An_Incomplete_Type_Declaration, N_Incomplete_Type_Declaration => N_Incomplete_Type_Declaration_Mapping'Access, -- --|A2005 end -- --|A2012 start N_Iterator_Specification => N_Iterator_Specification_Mapping'Access, -- --|A2012 end N_Object_Declaration => N_Object_Declaration_Mapping'Access, N_Access_Function_Definition => N_Access_Function_Definition_Mapping'Access, N_Access_Procedure_Definition => N_Access_Procedure_Definition_Mapping'Access, N_Subprogram_Body_Stub => N_Subprogram_Body_Stub_Mapping'Access, N_Subprogram_Body => N_Subprogram_Body_Mapping'Access, N_Subprogram_Declaration => N_Subprogram_Declaration_Mapping'Access, N_Generic_Subprogram_Declaration => N_Generic_Subprogram_Declaration_Mapping'Access, N_Constrained_Array_Definition => N_Constrained_Array_Definition_Mapping'Access, N_Unconstrained_Array_Definition => N_Unconstrained_Array_Definition_Mapping'Access, N_Subprogram_Renaming_Declaration => N_Subprogram_Renaming_Declaration_Mapping'Access, N_Loop_Statement => N_Loop_Statement_Mapping'Access, N_Requeue_Statement => N_Requeue_Statement_Mapping'Access, N_Abstract_Subprogram_Declaration => N_Abstract_Subprogram_Declaration_Mapping'Access, N_Accept_Alternative => N_Accept_Alternative_Mapping'Access, -- --|A2005 start N_Access_Definition => N_Access_Definition_Mapping'Access, -- --|A2005 end N_Access_To_Object_Definition => N_Access_To_Object_Definition_Mapping'Access, N_Component_Association => N_Component_Association_Mapping'Access, N_Derived_Type_Definition => N_Derived_Type_Definition_Mapping'Access, N_Delay_Alternative => N_Delay_Alternative_Mapping'Access, N_Formal_Package_Declaration => N_Formal_Package_Declaration_Mapping'Access, N_Formal_Private_Type_Definition => N_Formal_Private_Type_Definition_Mapping'Access, N_Formal_Subprogram_Declaration => N_Formal_Subprogram_Declaration_Mapping'Access, N_Index_Or_Discriminant_Constraint => N_Index_Or_Discriminant_Constraint_Mapping'Access, N_Number_Declaration => N_Number_Declaration_Mapping'Access, N_Range_Constraint => N_Range_Constraint_Mapping'Access, N_Record_Definition => N_Record_Definition_Mapping'Access, N_Terminate_Alternative => N_Terminate_Alternative_Mapping'Access, N_Use_Type_Clause => N_Use_Type_Clause_Mapping'Access, N_Procedure_Call_Statement => N_Procedure_Call_Statement_Mapping'Access, others => Not_Implemented_Mapping'Access); ---------------------------------------------------- -- Node List to Element List Filter Look-Up Table -- ---------------------------------------------------- -- The following look-up table defines the first, very rough filter for -- selecting node list elements to be used as a basis for ASIS Element -- list components: it defines which Node_Kind values could never be used -- for creating Elements in Element List (for them False is set in the -- table) May_Be_Included_Switch : constant array (Node_Kind) of Boolean := ( N_Unused_At_Start => False, N_Freeze_Entity => False, N_Implicit_Label_Declaration => False, N_Label => False, others => True); -------------------------------- -- Asis_Internal_Element_Kind -- -------------------------------- function Asis_Internal_Element_Kind (Node : Node_Id) return Internal_Element_Kinds is Mapping_Case : Internal_Element_Kinds; Source_Node_Kind : Node_Kind; begin -- two-level switching only! Source_Node_Kind := Nkind (Node); Mapping_Case := Node_To_Element_Kind_Mapping_First_Switch (Source_Node_Kind); case Mapping_Case is when Non_Trivial_Mapping => return Node_To_Element_Kind_Mapping_Second_Switch (Source_Node_Kind) (Node); when Not_Implemented_Mapping => Not_Implemented_Mapping (Source_Node_Kind); when No_Mapping => No_Mapping (Node); when others => -- all trivial cases! return Mapping_Case; end case; end Asis_Internal_Element_Kind; -------------------------------------- -- Defining_Id_List_From_Normalized -- -------------------------------------- function Defining_Id_List_From_Normalized (N : Node_Id; From_Declaration : Asis.Element) return Asis.Defining_Name_List is Res_Max_Len : constant Natural := Natural (List_Length (List_Containing (N))); -- to avoid two loops through the list of declarations/specifications, -- we use the rough estimation of the length of the result -- Defining_Name_List - it cannot contain more elements that the -- number of nodes in the tree node list containing (normalized) -- declarations Res_Act_Len : Natural := 1; -- the actual number of defining identifiers in the normalized -- declaration Result_List : Defining_Name_List (1 .. Res_Max_Len); Decl_Node : Node_Id := N; Decl_Nkind : constant Node_Kind := Nkind (Decl_Node); Def_Id_Node : Node_Id; begin Def_Id_Node := Defining_Identifier (Decl_Node); Result_List (Res_Act_Len) := Node_To_Element_New (Node => Def_Id_Node, Starting_Element => From_Declaration, Internal_Kind => A_Defining_Identifier); while More_Ids (Decl_Node) loop Decl_Node := Next (Decl_Node); while Nkind (Decl_Node) /= Decl_Nkind loop -- some implicit subtype declarations may be inserted by -- the compiler in between the normalized declarations, so: Decl_Node := Next (Decl_Node); end loop; Def_Id_Node := Defining_Identifier (Decl_Node); Res_Act_Len := Res_Act_Len + 1; Result_List (Res_Act_Len) := Node_To_Element_New (Node => Def_Id_Node, Starting_Element => From_Declaration, Internal_Kind => A_Defining_Identifier); end loop; return Result_List (1 .. Res_Act_Len); end Defining_Id_List_From_Normalized; ------------------------------------------ -- Discrete_Choice_Node_To_Element_List -- ------------------------------------------ function Discrete_Choice_Node_To_Element_List (Choice_List : List_Id; Starting_Element : Asis.Element) return Asis.Element_List is Result_List : Asis.Element_List (1 .. ASIS_Integer (List_Length (Choice_List))); -- List_Length (Choice_List) cannot be 0 for the DISCRETE_CHOICE_LIST! Current_Node : Node_Id; Current_Original_Node : Node_Id; Element_Already_Composed : Boolean; Result_Kind : Internal_Element_Kinds; begin Current_Node := First (Choice_List); -- first list element to process cannot be Empty! Current_Original_Node := Original_Node (Current_Node); for I in 1 .. ASIS_Integer (List_Length (Choice_List)) loop Element_Already_Composed := False; if Paren_Count (Current_Original_Node) > 0 then -- Corner but legal case of discrete choice like -- -- when (1) => -- -- or -- -- When (A.B.C) => Result_Kind := Not_An_Element; else case Nkind (Current_Original_Node) is -- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE} -- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others when N_Others_Choice => -- DISCRETE_CHOICE ::= ... | others Result_Kind := An_Others_Choice; -- DISCRETE_CHOICE ::= ... | DISCRETE_RANGE | ... -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE when N_Subtype_Indication => -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | ... -- -- The problem is that GNAT reduces the subtype_indication -- having NO constraint directly to subtype_mark -- (-> N_Identifier, N_Expanded_Name). May be, it is a -- pathological case, but it can also be represented by -- ...'Base construction (-> N_Attribute_Reference) Result_Kind := A_Discrete_Subtype_Indication; when N_Identifier => if Ekind (Entity (Current_Original_Node)) in Discrete_Kind then -- discrete subtype mark!! Result_Kind := A_Discrete_Subtype_Indication; elsif Ekind (Entity (Current_Original_Node)) = E_Enumeration_Literal then Result_Kind := An_Enumeration_Literal; else Result_Kind := An_Identifier; end if; when N_Expanded_Name => if Ekind (Entity (Current_Original_Node)) in Discrete_Kind then -- discrete subtype mark!! Result_Kind := A_Discrete_Subtype_Indication; else -- expression Result_Kind := A_Selected_Component; end if; -- DISCRETE_RANGE ::= ... | RANGE -- RANGE ::= -- RANGE_ATTRIBUTE_REFERENCE -- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION when N_Range => -- RANGE ::= ... -- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION Result_Kind := A_Discrete_Simple_Expression_Range; when N_Attribute_Reference => -- RANGE ::= RANGE_ATTRIBUTE_REFERENCE | ... -- Sinfo.ads: -- A range attribute designator is represented -- in the tree using the normal N_Attribute_Reference -- node. -- But if the tree corresponds to the compilable Compilation -- Unit, the RANGE_ATTRIBUTE_REFERENCE is the only construct -- which could be in this position --W_R_O_N_G !!! T'Base!!! if Attribute_Name (Current_Original_Node) = Name_Range then Result_Kind := A_Discrete_Range_Attribute_Reference; else -- attribute denoting a type/subtype or yielding a value: Result_List (I) := Node_To_Element_New ( Node => Current_Node, Starting_Element => Starting_Element); Element_Already_Composed := True; end if; -- DISCRETE_CHOICE ::= EXPRESSION | ... when others => -- In the tree corresponding to the compilable Compilation -- Unit the only possibility in the others choice is the -- EXPRESSION as the DISCRETE_CHOICE. Result_List (I) := Node_To_Element_New ( Node => Current_Node, Starting_Element => Starting_Element); Element_Already_Composed := True; end case; end if; if not Element_Already_Composed then Result_List (I) := Node_To_Element_New ( Node => Current_Node, Internal_Kind => Result_Kind, Starting_Element => Starting_Element); end if; Current_Node := Next (Current_Node); Current_Original_Node := Original_Node (Current_Node); end loop; return Result_List; end Discrete_Choice_Node_To_Element_List; ---------------------- -- Is_Config_Pragma -- ---------------------- function Is_Config_Pragma (N : Node_Id) return Boolean is begin return True and then Nkind (N) = N_Pragma and then Pragma_Name (N) in First_Pragma_Name .. Last_Configuration_Pragma_Name; end Is_Config_Pragma; ------------------------------- -- Is_GNAT_Attribute_Routine -- ------------------------------- function Is_GNAT_Attribute_Routine (N : Node_Id) return Boolean is Attribute_Chars : Name_Id; Result : Boolean := False; begin Attribute_Chars := Attribute_Name (N); if Attribute_Chars = Name_Asm_Input or else Attribute_Chars = Name_Asm_Output or else Attribute_Chars = Name_Enum_Rep or else Attribute_Chars = Name_Enum_Val or else Attribute_Chars = Name_Fixed_Value or else Attribute_Chars = Name_Integer_Value or else Attribute_Chars = Name_Ref then Result := True; end if; return Result; end Is_GNAT_Attribute_Routine; ------------------------------------------- -- Is_Rewritten_Function_Prefix_Notation -- ------------------------------------------- function Is_Rewritten_Function_Prefix_Notation (N : Node_Id) return Boolean is Result : Boolean := False; begin if Nkind (N) = N_Function_Call and then Is_Rewrite_Substitution (N) and then Nkind (Original_Node (N)) not in N_Op and then Present (Parameter_Associations (N)) and then not Is_Empty_List (Parameter_Associations (N)) and then Sloc (First (Parameter_Associations (N))) < Sloc (Sinfo.Name (N)) then Result := True; end if; return Result; end Is_Rewritten_Function_Prefix_Notation; ------------------------------------------------------ -- Is_Rewritten_Impl_Deref_Function_Prefix_Notation -- ------------------------------------------------------ function Is_Rewritten_Impl_Deref_Function_Prefix_Notation (N : Node_Id) return Boolean is Result : Boolean := False; begin if Nkind (N) = N_Function_Call and then Present (Parameter_Associations (N)) and then not Is_Empty_List (Parameter_Associations (N)) and then Sloc (First (Parameter_Associations (N))) < Sloc (Sinfo.Name (N)) then Result := True; end if; return Result; end Is_Rewritten_Impl_Deref_Function_Prefix_Notation; ----------------------------------- -- Get_Next_Configuration_Pragma -- ----------------------------------- function Get_Next_Configuration_Pragma (N : Node_Id) return Node_Id is Result : Node_Id := N; begin while not (Is_Config_Pragma (Result) or else No (Result)) loop Result := Next (Result); end loop; return Result; end Get_Next_Configuration_Pragma; ---------------------------- -- Is_Not_Duplicated_Decl -- ---------------------------- function Is_Not_Duplicated_Decl (Node : Node_Id) return Boolean is Prev_List_Elem : Node_Id; begin -- the idea is to check if the previous list member (and we are -- sure that Node itself is a list member) to be included -- in the list is the rewritten tree structure representing -- just the same Ada construct -- -- If we change Prev_Non_Pragma to Next_Non_Pragma, then this -- function will return False for the first, but not for the second -- of the two duplicated declarations if not (Nkind (Node) = N_Full_Type_Declaration or else Nkind (Node) = N_Private_Type_Declaration or else Nkind (Node) = N_Subtype_Declaration) then return True; -- as far as we know for now, the problem of duplicated -- declaration exists only for type declarations end if; Prev_List_Elem := Prev_Non_Pragma (Node); while Present (Prev_List_Elem) loop if Ordinary_Inclusion_Condition (Prev_List_Elem) and then (Nkind (Prev_List_Elem) = N_Full_Type_Declaration or else Nkind (Prev_List_Elem) = N_Subtype_Declaration) and then Chars (Defining_Identifier (Prev_List_Elem)) = Chars (Defining_Identifier (Node)) then return False; end if; Prev_List_Elem := Prev_Non_Pragma (Prev_List_Elem); end loop; return True; end Is_Not_Duplicated_Decl; --------------------------------- -- Is_Protected_Procedure_Call -- --------------------------------- function Is_Protected_Procedure_Call (N : Node_Id) return Boolean is Result : Boolean := False; Tmp_Node : Node_Id; begin Tmp_Node := Sinfo.Name (N); if Nkind (Tmp_Node) = N_Indexed_Component then -- Call to an entry from an entry family, Tmp_Node := Prefix (Tmp_Node); end if; if Nkind (Tmp_Node) = N_Selected_Component then Tmp_Node := Selector_Name (Tmp_Node); end if; Tmp_Node := Entity (Tmp_Node); Result := Ekind (Tmp_Node) = E_Procedure; return Result; end Is_Protected_Procedure_Call; ------------------ -- Is_Statement -- ------------------ function Is_Statement (N : Node_Id) return Boolean is Arg_Kind : constant Node_Kind := Nkind (N); begin return Arg_Kind in N_Statement_Other_Than_Procedure_Call or else Arg_Kind = N_Procedure_Call_Statement; end Is_Statement; ------------------------------------------ -- Is_Stub_To_Body_Instanse_Replacement -- ------------------------------------------ function Is_Stub_To_Body_Instanse_Replacement (N : Node_Id) return Boolean is Arg_Kind : constant Node_Kind := Nkind (N); Result : Boolean := False; begin if Arg_Kind in N_Proper_Body and then Was_Originally_Stub (N) then case Arg_Kind is when N_Subprogram_Body => Result := Is_From_Instance (Sinfo.Specification (N)); when N_Package_Body => Result := Is_From_Instance (Sinfo.Defining_Unit_Name (N)); when others => Result := Is_From_Instance (Sinfo.Defining_Identifier (N)); end case; end if; return Result; end Is_Stub_To_Body_Instanse_Replacement; --------------------- -- May_Be_Included -- --------------------- function May_Be_Included (Node : Node_Id) return Boolean is begin return Ordinary_Inclusion_Condition (Node) and then Is_Not_Duplicated_Decl (Node); end May_Be_Included; ----------------------------------------------- -- N_Abstract_Subprogram_Declaration_Mapping -- ----------------------------------------------- function N_Abstract_Subprogram_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Procedure_Declaration -- A_Function_Declaration if Nkind (Specification (Node)) = N_Function_Specification then return A_Function_Declaration; else return A_Procedure_Declaration; end if; end N_Abstract_Subprogram_Declaration_Mapping; ---------------------------------- -- N_Accept_Alternative_Mapping -- ---------------------------------- function N_Accept_Alternative_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Select_Path -- An_Or_Path if No (Prev (Node)) then return A_Select_Path; else return An_Or_Path; end if; end N_Accept_Alternative_Mapping; ------------------------------------------ -- N_Access_Function_Definition_Mapping -- ------------------------------------------ function N_Access_Function_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Four Internal_Element_Kinds values may be possible: -- -- An_Access_To_Function -- An_Access_To_Protected_Function -- -- A_Formal_Access_To_Function -- A_Formal_Access_To_Protected_Function if Nkind (Parent (Node)) = N_Formal_Type_Declaration then if Protected_Present (Node) then return A_Formal_Access_To_Protected_Function; else return A_Formal_Access_To_Function; end if; else if Protected_Present (Node) then return An_Access_To_Protected_Function; else return An_Access_To_Function; end if; end if; end N_Access_Function_Definition_Mapping; ------------------------------------------- -- N_Access_Procedure_Definition_Mapping -- ------------------------------------------- function N_Access_Procedure_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Four Internal_Element_Kinds values may be possible: -- -- An_Access_To_Procedure -- An_Access_To_Protected_Procedure -- -- A_Formal_Access_To_Procedure -- A_Formal_Access_To_Protected_Procedure if Nkind (Parent (Node)) = N_Formal_Type_Declaration then if Protected_Present (Node) then return A_Formal_Access_To_Protected_Procedure; else return A_Formal_Access_To_Procedure; end if; else if Protected_Present (Node) then return An_Access_To_Protected_Procedure; else return An_Access_To_Procedure; end if; end if; end N_Access_Procedure_Definition_Mapping; -- --|A2005 start --------------------------------- -- N_Access_Definition_Mapping -- --------------------------------- function N_Access_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds is Result : Internal_Element_Kinds := Not_An_Element; Tmp : constant Node_Id := Sinfo.Access_To_Subprogram_Definition (Node); begin case Nkind (Tmp) is when N_Empty => if Constant_Present (Node) then Result := An_Anonymous_Access_To_Constant; else Result := An_Anonymous_Access_To_Variable; end if; when N_Access_Function_Definition => if Protected_Present (Tmp) then Result := An_Anonymous_Access_To_Protected_Function; else Result := An_Anonymous_Access_To_Function; end if; when N_Access_Procedure_Definition => if Protected_Present (Tmp) then Result := An_Anonymous_Access_To_Protected_Procedure; else Result := An_Anonymous_Access_To_Procedure; end if; when others => pragma Assert (False); null; end case; return Result; end N_Access_Definition_Mapping; -- --|A2005 end ------------------------------------------- -- N_Access_To_Object_Definition_Mapping -- ------------------------------------------- function N_Access_To_Object_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Six Internal_Element_Kinds values may be possible: -- -- A_Pool_Specific_Access_To_Variable -- An_Access_To_Variable -- An_Access_To_Constant -- -- A_Formal_Pool_Specific_Access_To_Variable -- A_Formal_Access_To_Variable -- A_Formal_Access_To_Constant if Nkind (Parent (Node)) = N_Formal_Type_Declaration then if All_Present (Node) then return A_Formal_Access_To_Variable; elsif Constant_Present (Node) then return A_Formal_Access_To_Constant; else return A_Formal_Pool_Specific_Access_To_Variable; end if; else if All_Present (Node) then return An_Access_To_Variable; elsif Constant_Present (Node) then return An_Access_To_Constant; else return A_Pool_Specific_Access_To_Variable; end if; end if; end N_Access_To_Object_Definition_Mapping; ------------------------- -- N_Aggregate_Mapping -- ------------------------- function N_Aggregate_Mapping (Node : Node_Id) return Internal_Element_Kinds is Aggregate_Type : Node_Id := Etype (Node); begin -- Three Internal_Element_Kinds values may be possible: -- A_Record_Aggregate -- A_Positional_Array_Aggregate -- A_Named_Array_Aggregate -- the following fragment is a result of the current setting -- of Etype field in the tree, see open problems #77 -- for multi-dimensional array aggregates, Etype field for -- inner aggregates is set to Empty!! if Present (Aggregate_Type) and then Ekind (Aggregate_Type) in Private_Kind and then not (Ekind (Aggregate_Type) in Array_Kind or else Ekind (Aggregate_Type) in Record_Kind) then -- we need a full view of the type! Aggregate_Type := Full_View (Aggregate_Type); end if; -- Special case: if No (Aggregate_Type) and then (Nkind (Parent (Node)) = N_Pragma_Argument_Association or else Nkind (Parent (Node)) = N_Aspect_Specification) then return A_Record_Aggregate; end if; if Present (Aggregate_Type) and then Ekind (Aggregate_Type) in Record_Kind then return A_Record_Aggregate; else if Present (Expressions (Node)) then return A_Positional_Array_Aggregate; else return A_Named_Array_Aggregate; end if; end if; end N_Aggregate_Mapping; ------------------------- -- N_Allocator_Mapping -- ------------------------- function N_Allocator_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- An_Allocation_From_Subtype -- An_Allocation_From_Qualified_Expression if Nkind (Sinfo.Expression (Node)) = N_Qualified_Expression then return An_Allocation_From_Qualified_Expression; else return An_Allocation_From_Subtype; end if; end N_Allocator_Mapping; ----------------------------------- -- N_Attribute_Reference_Mapping -- ----------------------------------- function N_Attribute_Reference_Mapping (Node : Node_Id) return Internal_Element_Kinds is Attribute_Chars : constant Name_Id := Attribute_Name (Node); Context_Kind : constant Node_Kind := Nkind (Original_Node (Parent_Node)); begin -- The following Internal_Element_Kinds values may be possible: -- -- For range attribute reference: -- -- A_Discrete_Range_Attribute_Reference_As_Subtype_Definition -- A_Discrete_Range_Attribute_Reference -- A_Range_Attribute_Reference -- -- For attribute reference corresponding to the attributes which are -- functions -- -- Adjacent -- Ceiling -- Compose -- Copy_Sign -- Exponent -- Floor -- Fraction -- Image -- Input -- Leading_Part -- Machine -- Max -- Min -- Model -- Pos -- Pred -- Remainder -- Round -- Rounding -- Scaling -- Succ -- Truncation -- Unbiased_Rounding -- Val -- Value -- Wide_Image -- Wide_Value -- |A2005 start -- -- Ada 2005 attributes that are functions: -- -- Machine_Rounding -- Mod -- Wide_Wide_Image -- |A2005 end -- -- plus GNAT-specific attributes: -- Enum_Rep -- Fixed_Value -- Integer_Value -- Result -- -- the Element of A_Function_Call Internal_Element_Kinds value should be -- created, and the determination of the prefix kind should further be -- done by hand (function Asis_Expressions.Prefix) -- -- For attribute reference corresponding to the attributes which are -- procedures -- -- Output -- Read -- Write -- -- the Element of A_Procedure_Call_Statement kind should be created -- -- For attributes returning types: -- Base -- Class -- the Element of A_Type_Conversion should be created if the node is -- rewritten into N_Type_Conversion node. But this is done by the -- Node_To_Element function (together with setting the Special_Case -- Element field, which is then taken into account by functions -- decomposing A_Type_Conversion Element. if Attribute_Chars = Name_Range then -- processing the range attribute reference -- range attribute reference is the part of the RANGE -- Syntax Cross Reference extraction for RANGE: -- -- range -- discrete_range 3.6.1 -- discrete_choice 3.8.1 -- discrete_choice_list 3.8.1 -- array_component_association 4.3.3 -- named_array_aggregate 4.3.3 -- case_statement_alternative 5.4 -- variant 3.8.1 -- index_constraint 3.6.1 -- slice 4.1.2 -- discrete_subtype_definition 3.6 -- constrained_array_definition 3.6 -- entry_declaration 9.5.2 -- entry_index_specification 9.5.2 -- loop_parameter_specification 5.5 -- range_constraint 3.5 -- delta_constraint J.3 -- digits_constraint 3.5.9 -- scalar_constraint 3.2.2 -- relation 4.4 case Context_Kind is -- should be reorganized when complete when -- discrete_range N_Component_Association | N_Case_Statement_Alternative | N_Variant | N_Index_Or_Discriminant_Constraint | N_Slice => return A_Discrete_Range_Attribute_Reference; when -- discrete_subtype_definition N_Constrained_Array_Definition | N_Entry_Index_Specification | N_Loop_Parameter_Specification | N_Entry_Declaration => return A_Discrete_Range_Attribute_Reference_As_Subtype_Definition; when N_Range_Constraint => -- range_constraint ??? return A_Range_Attribute_Reference; when N_In -- relation | N_Not_In => return A_Range_Attribute_Reference; when others => -- impossible cases: raise Internal_Implementation_Error; end case; elsif -- language-defined attributes which are functions: Attribute_Chars = Name_Adjacent or else Attribute_Chars = Name_Ceiling or else Attribute_Chars = Name_Compose or else Attribute_Chars = Name_Copy_Sign or else Attribute_Chars = Name_Exponent or else Attribute_Chars = Name_Floor or else Attribute_Chars = Name_Fraction or else Attribute_Chars = Name_Image or else Attribute_Chars = Name_Input or else Attribute_Chars = Name_Leading_Part or else Attribute_Chars = Name_Machine or else Attribute_Chars = Name_Max or else Attribute_Chars = Name_Min or else Attribute_Chars = Name_Model or else Attribute_Chars = Name_Pos or else Attribute_Chars = Name_Pred or else Attribute_Chars = Name_Remainder or else Attribute_Chars = Name_Round or else Attribute_Chars = Name_Rounding or else Attribute_Chars = Name_Scaling or else Attribute_Chars = Name_Succ or else Attribute_Chars = Name_Truncation or else Attribute_Chars = Name_Unbiased_Rounding or else Attribute_Chars = Name_Val or else Attribute_Chars = Name_Value or else Attribute_Chars = Name_Wide_Image or else Attribute_Chars = Name_Wide_Value or else -- |A2005 start -- Ada 2005 attributes that are functions: Attribute_Chars = Name_Machine_Rounding or else Attribute_Chars = Name_Mod or else Attribute_Chars = Name_Wide_Wide_Image or else Attribute_Chars = Name_Wide_Wide_Value or else -- |A2012 start -- Ada 2012 attributes that are functions: -- Attribute_Chars = Name_Overlaps_Storage or else (SCz) -- |A2012 end -- |A2005 end -- Implementation Dependent Attributes-Functions: Attribute_Chars = Name_Asm_Input or else Attribute_Chars = Name_Asm_Output or else Attribute_Chars = Name_Enum_Rep or else Attribute_Chars = Name_Enum_Val or else Attribute_Chars = Name_Fixed_Value or else Attribute_Chars = Name_Integer_Value or else Attribute_Chars = Name_Ref then return A_Function_Call; elsif -- language-defined attributes which are procedures: Attribute_Chars = Name_Output or else Attribute_Chars = Name_Read or else Attribute_Chars = Name_Write then return A_Procedure_Call_Statement; -- language-defined attributes: elsif Attribute_Chars = Name_Access then return An_Access_Attribute; elsif Attribute_Chars = Name_Address then return An_Address_Attribute; elsif Attribute_Chars = Name_Aft then return An_Aft_Attribute; elsif Attribute_Chars = Name_Alignment then return An_Alignment_Attribute; elsif Attribute_Chars = Name_Base then return A_Base_Attribute; elsif Attribute_Chars = Name_Bit_Order then return A_Bit_Order_Attribute; elsif Attribute_Chars = Name_Body_Version then return A_Body_Version_Attribute; elsif Attribute_Chars = Name_Callable then return A_Callable_Attribute; elsif Attribute_Chars = Name_Caller then return A_Caller_Attribute; elsif Attribute_Chars = Name_Class then return A_Class_Attribute; elsif Attribute_Chars = Name_Component_Size then return A_Component_Size_Attribute; elsif Attribute_Chars = Name_Constrained then return A_Constrained_Attribute; elsif Attribute_Chars = Name_Count then return A_Count_Attribute; elsif Attribute_Chars = Name_Definite then return A_Definite_Attribute; elsif Attribute_Chars = Name_Delta then return A_Delta_Attribute; elsif Attribute_Chars = Name_Denorm then return A_Denorm_Attribute; elsif Attribute_Chars = Name_Digits then return A_Digits_Attribute; elsif Attribute_Chars = Name_External_Tag then return An_External_Tag_Attribute; elsif Attribute_Chars = Name_First then return A_First_Attribute; elsif Attribute_Chars = Name_First_Bit then return A_First_Bit_Attribute; elsif Attribute_Chars = Name_Fore then return A_Fore_Attribute; elsif Attribute_Chars = Name_Identity then return An_Identity_Attribute; elsif Attribute_Chars = Name_Last then return A_Last_Attribute; elsif Attribute_Chars = Name_Last_Bit then return A_Last_Bit_Attribute; elsif Attribute_Chars = Name_Length then return A_Length_Attribute; elsif Attribute_Chars = Name_Machine_Emax then return A_Machine_Emax_Attribute; elsif Attribute_Chars = Name_Machine_Emin then return A_Machine_Emin_Attribute; elsif Attribute_Chars = Name_Machine_Mantissa then return A_Machine_Mantissa_Attribute; elsif Attribute_Chars = Name_Machine_Overflows then return A_Machine_Overflows_Attribute; elsif Attribute_Chars = Name_Machine_Radix then return A_Machine_Radix_Attribute; elsif Attribute_Chars = Name_Machine_Rounds then return A_Machine_Rounds_Attribute; elsif Attribute_Chars = Name_Max_Size_In_Storage_Elements then return A_Max_Size_In_Storage_Elements_Attribute; elsif Attribute_Chars = Name_Model_Emin then return A_Model_Emin_Attribute; elsif Attribute_Chars = Name_Model_Epsilon then return A_Model_Epsilon_Attribute; elsif Attribute_Chars = Name_Model_Mantissa then return A_Model_Mantissa_Attribute; elsif Attribute_Chars = Name_Model_Small then return A_Model_Small_Attribute; elsif Attribute_Chars = Name_Modulus then return A_Modulus_Attribute; elsif Attribute_Chars = Name_Partition_ID then return A_Partition_ID_Attribute; elsif Attribute_Chars = Name_Position then return A_Position_Attribute; elsif Attribute_Chars = Name_Range then -- this alternative return A_Range_Attribute; -- never works! elsif Attribute_Chars = Name_Safe_First then return A_Safe_First_Attribute; elsif Attribute_Chars = Name_Safe_Last then return A_Safe_Last_Attribute; elsif Attribute_Chars = Name_Scale then return A_Scale_Attribute; elsif Attribute_Chars = Name_Signed_Zeros then return A_Signed_Zeros_Attribute; elsif Attribute_Chars = Name_Size then return A_Size_Attribute; elsif Attribute_Chars = Name_Small then return A_Small_Attribute; elsif Attribute_Chars = Name_Storage_Pool then return A_Storage_Pool_Attribute; elsif Attribute_Chars = Name_Storage_Size then return A_Storage_Size_Attribute; elsif Attribute_Chars = Name_Tag then return A_Tag_Attribute; elsif Attribute_Chars = Name_Terminated then return A_Terminated_Attribute; elsif Attribute_Chars = Name_Unchecked_Access then return An_Unchecked_Access_Attribute; elsif Attribute_Chars = Name_Valid then return A_Valid_Attribute; elsif Attribute_Chars = Name_Version then return A_Version_Attribute; elsif Attribute_Chars = Name_Wide_Width then return A_Wide_Width_Attribute; elsif Attribute_Chars = Name_Width then return A_Width_Attribute; -- New Ada 2005/2012 attributes: elsif Attribute_Chars = Name_Priority then return A_Priority_Attribute; elsif Attribute_Chars = Name_Stream_Size then return A_Stream_Size_Attribute; elsif Attribute_Chars = Name_Wide_Wide_Width then return A_Wide_Wide_Width_Attribute; elsif Attribute_Chars = Name_Max_Alignment_For_Allocation then return A_Max_Alignment_For_Allocation_Attribute; -- New Ada 2005/2012 attributes: -- Implementation Dependent Attributes: elsif Attribute_Chars = Name_Abort_Signal or else Attribute_Chars = Name_Address_Size or else Attribute_Chars = Name_Asm_Input or else Attribute_Chars = Name_Asm_Output or else Attribute_Chars = Name_AST_Entry or else -- VMS Attribute_Chars = Name_Bit or else Attribute_Chars = Name_Bit_Position or else Attribute_Chars = Name_Code_Address or else Attribute_Chars = Name_Compiler_Version or else Attribute_Chars = Name_Default_Bit_Order or else -- Attribute_Chars = Name_Elab_Subp_Body or else (SCz) Attribute_Chars = Name_Elaborated or else Attribute_Chars = Name_Emax or else -- Ada 83 Attribute_Chars = Name_Enabled or else Attribute_Chars = Name_Enum_Rep or else Attribute_Chars = Name_Enum_Val or else Attribute_Chars = Name_Epsilon or else -- Ada 83 Attribute_Chars = Name_Fixed_Value or else Attribute_Chars = Name_Has_Access_Values or else Attribute_Chars = Name_Has_Discriminants or else Attribute_Chars = Name_Img or else Attribute_Chars = Name_Integer_Value or else Attribute_Chars = Name_Invalid_Value or else Attribute_Chars = Name_Large or else -- Ada 83 Attribute_Chars = Name_Machine_Size or else Attribute_Chars = Name_Mantissa or else -- Ada 83 Attribute_Chars = Name_Maximum_Alignment or else Attribute_Chars = Name_Mechanism_Code or else Attribute_Chars = Name_Null_Parameter or else Attribute_Chars = Name_Object_Size or else Attribute_Chars = Name_Old or else Attribute_Chars = Name_Passed_By_Reference or else Attribute_Chars = Name_Range_Length or else Attribute_Chars = Name_Ref or else Attribute_Chars = Name_Result or else Attribute_Chars = Name_Safe_Emax or else -- Ada 83 Attribute_Chars = Name_Safe_Large or else -- Ada 83 Attribute_Chars = Name_Safe_Small or else -- Ada 83 Attribute_Chars = Name_Storage_Unit or else -- Attribute_Chars = Name_System_Allocator_Alignment or else (SCz) Attribute_Chars = Name_Target_Name or else Attribute_Chars = Name_To_Address or else Attribute_Chars = Name_Type_Class or else Attribute_Chars = Name_UET_Address or else Attribute_Chars = Name_Universal_Literal_String or else Attribute_Chars = Name_Unrestricted_Access or else Attribute_Chars = Name_VADS_Size or else Attribute_Chars = Name_Value_Size or else Attribute_Chars = Name_Wchar_T_Size or else Attribute_Chars = Name_Word_Size or else Attribute_Chars = Name_Elab_Body or else Attribute_Chars = Name_Elab_Spec then return An_Implementation_Defined_Attribute; else return An_Unknown_Attribute; end if; end N_Attribute_Reference_Mapping; ------------------------------------- -- N_Component_Association_Mapping -- ------------------------------------- function N_Component_Association_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Special cases first: case Nkind (Parent (Parent (Node))) is when N_Enumeration_Representation_Clause => return An_Array_Component_Association; when N_Pragma_Argument_Association | N_Aspect_Specification => return A_Record_Component_Association; when others => null; end case; -- Regular case: if Nkind (Parent (Parent (Node))) = N_Enumeration_Representation_Clause or else Ekind (Etype (Parent (Node))) in Array_Kind then return An_Array_Component_Association; else return A_Record_Component_Association; end if; end N_Component_Association_Mapping; -------------------------------------------- -- N_Constrained_Array_Definition_Mapping -- -------------------------------------------- function N_Constrained_Array_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Constrained_Array_Definition -- A_Formal_Constrained_Array_Definition if Nkind (Parent (Node)) = N_Formal_Type_Declaration then return A_Formal_Constrained_Array_Definition; else return A_Constrained_Array_Definition; end if; end N_Constrained_Array_Definition_Mapping; ----------------------------------- -- N_Defining_Identifier_Mapping -- ----------------------------------- function N_Defining_Identifier_Mapping (Node : Node_Id) return Internal_Element_Kinds is Template_Node : Node_Id := Empty; begin -- Several Internal_Element_Kinds values may be possible for automatic -- Internal Kind Determination: -- -- A_Defining_Identifier -- A_Defining_Enumeration_Literal -- Internal Defining Name kinds, this happens for the extended -- code of the function instantiation in case if the instance -- defines an operator symbol - in this case the defining name of -- the extended function spec and body is represented by -- N_Defining_Identifier node. -- -- Some other Internal_Element_Kinds values could be set "by-hand", -- for example: -- -- An_Enumeration_Literal_Specification if Sloc (Node) > Standard_Location and then Get_Character (Sloc (Node)) = '"' then Template_Node := Parent (Parent (Node)); if Pass_Generic_Actual (Template_Node) then -- This is the case of subprogram renaming that passes an actual -- for a formal operator function Template_Node := Corresponding_Formal_Spec (Template_Node); else -- This is the case of expanded generic subprogram having a -- defining operator symbol, it comes as the defining name from -- the corresponding instance, but is represented by -- N_Defining_Identifier node in the expanded code. We just -- go to the defining name from the instance and call -- N_Defining_Operator_Symbol_Mapping for it Template_Node := Parent (Template_Node); if Nkind (Template_Node) = N_Package_Specification then Template_Node := Parent (Template_Node); end if; Template_Node := Next (Template_Node); if Nkind (Template_Node) = N_Package_Body then -- skipping the body of wrapper package for extended subprogram -- body Template_Node := Next (Template_Node); end if; Template_Node := Defining_Unit_Name (Template_Node); end if; pragma Assert (Nkind (Template_Node) = N_Defining_Operator_Symbol); return N_Defining_Operator_Symbol_Mapping (Template_Node); else if Nkind (Parent (Node)) = N_Enumeration_Type_Definition then return A_Defining_Enumeration_Literal; else return A_Defining_Identifier; end if; end if; end N_Defining_Identifier_Mapping; ---------------------------------------- -- N_Defining_Operator_Symbol_Mapping -- ---------------------------------------- function N_Defining_Operator_Symbol_Mapping (Node : Node_Id) return Internal_Element_Kinds is Operator_Chars : constant Name_Id := Chars (Node); Parameter_Number : Nat range 1 .. 2; -- see the GNAT components Namet.ads and Snames.ads -- N_Operator_Symbol_Mapping uses just the same approach, -- (except computing the Parameter_Number value) -- so if there is any error in it, then both functions contain it begin -- The following Internal_Element_Kinds values may be possible: -- -- A_Defining_And_Operator, -- and -- A_Defining_Or_Operator, -- or -- A_Defining_Xor_Operator, -- xor -- A_Defining_Equal_Operator, -- = -- A_Defining_Not_Equal_Operator, -- /= -- A_Defining_Less_Than_Operator, -- < -- A_Defining_Less_Than_Or_Equal_Operator, -- <= -- A_Defining_Greater_Than_Operator, -- > -- A_Defining_Greater_Than_Or_Equal_Operator, -- >= -- A_Defining_Plus_Operator, -- + -- A_Defining_Minus_Operator, -- - -- A_Defining_Concatenate_Operator, -- & -- A_Defining_Unary_Plus_Operator, -- + -- A_Defining_Unary_Minus_Operator, -- - -- A_Defining_Multiply_Operator, -- * -- A_Defining_Divide_Operator, -- / -- A_Defining_Mod_Operator, -- mod -- A_Defining_Rem_Operator, -- rem -- A_Defining_Exponentiate_Operator, -- ** -- A_Defining_Abs_Operator, -- abs -- A_Defining_Not_Operator, -- not if Operator_Chars = Name_Op_And then return A_Defining_And_Operator; elsif Operator_Chars = Name_Op_Or then return A_Defining_Or_Operator; elsif Operator_Chars = Name_Op_Xor then return A_Defining_Xor_Operator; elsif Operator_Chars = Name_Op_Eq then return A_Defining_Equal_Operator; elsif Operator_Chars = Name_Op_Ne then return A_Defining_Not_Equal_Operator; elsif Operator_Chars = Name_Op_Lt then return A_Defining_Less_Than_Operator; elsif Operator_Chars = Name_Op_Le then return A_Defining_Less_Than_Or_Equal_Operator; elsif Operator_Chars = Name_Op_Gt then return A_Defining_Greater_Than_Operator; elsif Operator_Chars = Name_Op_Ge then return A_Defining_Greater_Than_Or_Equal_Operator; elsif Operator_Chars = Name_Op_Concat then return A_Defining_Concatenate_Operator; elsif Operator_Chars = Name_Op_Multiply then return A_Defining_Multiply_Operator; elsif Operator_Chars = Name_Op_Divide then return A_Defining_Divide_Operator; elsif Operator_Chars = Name_Op_Mod then return A_Defining_Mod_Operator; elsif Operator_Chars = Name_Op_Rem then return A_Defining_Rem_Operator; elsif Operator_Chars = Name_Op_Expon then return A_Defining_Exponentiate_Operator; elsif Operator_Chars = Name_Op_Abs then return A_Defining_Abs_Operator; elsif Operator_Chars = Name_Op_Not then return A_Defining_Not_Operator; else -- for + and - operator signs binary and unary cases -- should be distinguished if Nkind (Parent_Node) = N_Function_Instantiation then -- we have to compute the number of parameters -- from the declaration of the corresponding generic -- function Parent_Node := Parent (Entity (Sinfo.Name (Parent_Node))); if Nkind (Parent_Node) = N_Defining_Program_Unit_Name then Parent_Node := Parent (Parent_Node); end if; end if; Parameter_Number := List_Length (Parameter_Specifications (Parent_Node)); if Operator_Chars = Name_Op_Add then if Parameter_Number = 1 then return A_Defining_Unary_Plus_Operator; else return A_Defining_Plus_Operator; end if; else -- Operator_Chars = "-" if Parameter_Number = 1 then return A_Defining_Unary_Minus_Operator; else return A_Defining_Minus_Operator; end if; end if; end if; end N_Defining_Operator_Symbol_Mapping; --------------------------------- -- N_Delay_Alternative_Mapping -- --------------------------------- function N_Delay_Alternative_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Select_Path -- An_Or_Path if Is_List_Member (Node) then -- a delay alternative in a selective accept statement, -- processing is the same as for N_Accept_Alternative return N_Accept_Alternative_Mapping (Node); else -- a relay alternative in a timed entry call return An_Or_Path; end if; end N_Delay_Alternative_Mapping; --------------------------------------- -- N_Derived_Type_Definition_Mapping -- --------------------------------------- function N_Derived_Type_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds is Result : Internal_Element_Kinds := A_Derived_Type_Definition; begin -- Two Internal_Element_Kinds values may be possible: -- A_Derived_Type_Definition -- A_Derived_Record_Extension_Definition -- --|A2005 start -- Plus the following values for Ada 2005: -- An_Ordinary_Interface -- A_Limited_Interface -- A_Task_Interface -- A_Protected_Interface -- A_Synchronized_Interface -- --|A2005 end -- Implementation revised for Ada 2005 if Interface_Present (Node) then if Limited_Present (Node) then Result := A_Limited_Interface; elsif Task_Present (Node) then Result := A_Task_Interface; elsif Protected_Present (Node) then Result := A_Protected_Interface; elsif Synchronized_Present (Node) then Result := A_Synchronized_Interface; else Result := An_Ordinary_Interface; end if; elsif Present (Record_Extension_Part (Node)) then Result := A_Derived_Record_Extension_Definition; end if; return Result; -- --|A2005 end end N_Derived_Type_Definition_Mapping; ----------------------------- -- N_Expanded_Name_Mapping -- ----------------------------- function N_Expanded_Name_Mapping (Node : Node_Id) return Internal_Element_Kinds is Context : constant Node_Id := Parent_Node; Context_Kind : constant Node_Kind := Nkind (Context); Temp_Node : Node_Id; begin -- The following Internal_Element_Kinds values may be possible: -- -- A_Subtype_Indication -- A_Discrete_Subtype_Indication_As_Subtype_Definition -- A_Discrete_Subtype_Indication -- A_Selected_Component -- An_Identifier (we use this routine for An_Identifier node as well) -- A_Function_Call (F in F.X) -- An_Attribute_Reference case Context_Kind is -- special cases should be reorganized when complete ??? when N_Object_Declaration => if Node = Object_Definition (Context) then return A_Subtype_Indication; else -- an initializing expression in an object declaration goto Expr; end if; when N_Derived_Type_Definition | N_Access_To_Object_Definition => -- --|A2005 start if Is_List_Member (Node) then -- The node represents an interface name from some interface -- list if Nkind (Node) = N_Expanded_Name then return A_Selected_Component; else return An_Identifier; end if; else return A_Subtype_Indication; end if; -- --|A2005 end when N_Constrained_Array_Definition | N_Entry_Declaration => return A_Discrete_Subtype_Indication_As_Subtype_Definition; when N_Unconstrained_Array_Definition => if Is_List_Member (Node) then -- this for sure means, that node represents one of index -- subtype definitions -- CODE SHARING WITH N_IDENTIFIER MAPPING ITEM :-[#] if Nkind (Node) = N_Expanded_Name then return A_Selected_Component; else return An_Identifier; end if; else -- this is a component definition! return A_Component_Definition; end if; when N_Index_Or_Discriminant_Constraint => if Asis_Internal_Element_Kind (Context) = An_Index_Constraint then return A_Discrete_Subtype_Indication; end if; when N_Slice => -- A.B(C.D) <- Context -- / \ -- Prefix Discrete_Range if Node = Sinfo.Discrete_Range (Context) then return A_Discrete_Subtype_Indication; end if; -- when N_??? => should be implemented when N_Selected_Component => -- This corresponds to a special case: F.A, where F is -- a function call Temp_Node := Prefix (Context); if Is_Rewrite_Substitution (Temp_Node) and then Nkind (Temp_Node) = N_Function_Call and then Original_Node (Temp_Node) = Node then return A_Function_Call; end if; when N_Parameter_Specification => -- See FA13-008. In case if we have an implicit "/=" -- declaration, and in the corresponding explicit "=" -- declaration parameter type is defined by a 'Class attribute, -- in the parameter specification of "/=" the front-end uses -- the reference to the internal type entity node if Nkind (Node) = N_Identifier and then not Comes_From_Source (Node) and then Ekind (Entity (Node)) = E_Class_Wide_Type then return A_Class_Attribute; end if; when others => null; end case; -- general case, the following if statement is necessary because -- of sharing of this code between N_Expanded_Name and N_Identifier -- mapping items. -- IS THIS CODE SHARING A REALLY GOOD THING??? <<Expr>> -- here we are analyzing the "ordinary" expression if Nkind (Node) = N_Expanded_Name then return A_Selected_Component; elsif Context_Kind /= N_Defining_Program_Unit_Name then if (Nkind (Node) in N_Has_Entity or else Nkind (Node) = N_Attribute_Definition_Clause) and then Entity_Present (Node) and then Ekind (Entity (Node)) = E_Enumeration_Literal then return An_Enumeration_Literal; else return An_Identifier; end if; else return An_Identifier; end if; end N_Expanded_Name_Mapping; --------------------------------------- -- N_Formal_Type_Declaration_Mapping -- --------------------------------------- function N_Formal_Type_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- if Nkind (Sinfo.Formal_Type_Definition (Node)) = (SCz) -- N_Formal_Incomplete_Type_Definition -- then -- return A_Formal_Incomplete_Type_Declaration; -- else return A_Formal_Type_Declaration; -- end if; end N_Formal_Type_Declaration_Mapping; ------------------------------------------ -- N_Formal_Package_Declaration_Mapping -- ------------------------------------------ function N_Formal_Package_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Formal_Package_Declaration, -- A_Formal_Package_Declaration_With_Box if Box_Present (Node) then return A_Formal_Package_Declaration_With_Box; else return A_Formal_Package_Declaration; end if; end N_Formal_Package_Declaration_Mapping; ---------------------------------------------- -- N_Formal_Private_Type_Definition_Mapping -- ---------------------------------------------- function N_Formal_Private_Type_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Formal_Private_Type_Definition -- A_Formal_Tagged_Private_Type_Definition if Tagged_Present (Node) then return A_Formal_Tagged_Private_Type_Definition; else return A_Formal_Private_Type_Definition; end if; end N_Formal_Private_Type_Definition_Mapping; --------------------------------------------- -- N_Formal_Subprogram_Declaration_Mapping -- --------------------------------------------- function N_Formal_Subprogram_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Formal_Procedure_Declaration -- A_Formal_Function_Declaration. if Nkind (Specification (Node)) = N_Function_Specification then return A_Formal_Function_Declaration; else return A_Formal_Procedure_Declaration; end if; end N_Formal_Subprogram_Declaration_Mapping; ----------------------------- -- N_Function_Call_Mapping -- ----------------------------- function N_Function_Call_Mapping (Node : Node_Id) return Internal_Element_Kinds is Called_Name : Node_Id; Called_Function : Node_Id := Empty; Result : Internal_Element_Kinds := A_Function_Call; begin -- Three Internal_Element_Kinds values may be possible: -- A_Function_Call (usual situation) -- A_Selected_Component -- An_Enumeration_Literal -- The last two cases correspond to a reference to an overloaded -- enumeration literal (either qualified or direct) if No (Parameter_Associations (Node)) then Called_Name := Sinfo.Name (Node); if Nkind (Called_Name) in N_Has_Entity then Called_Function := Entity (Called_Name); end if; if Nkind (Parent (Called_Function)) = N_Enumeration_Type_Definition then if Nkind (Called_Name) = N_Selected_Component or else -- ??? Nkind (Called_Name) = N_Expanded_Name then Result := A_Selected_Component; elsif Nkind (Called_Name) = N_Identifier then Result := An_Enumeration_Literal; end if; end if; end if; return Result; end N_Function_Call_Mapping; ---------------------------------------------- -- N_Generic_Subprogram_Declaration_Mapping -- ---------------------------------------------- function N_Generic_Subprogram_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Generic_Procedure_Declaration and A_Generic_Function_Declaration if Nkind (Specification (Node)) = N_Function_Specification then return A_Generic_Function_Declaration; else return A_Generic_Procedure_Declaration; end if; end N_Generic_Subprogram_Declaration_Mapping; -- |A2005 start ------------------------------------------- -- N_Incomplete_Type_Declaration_Mapping -- ------------------------------------------- function N_Incomplete_Type_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds is Result : Internal_Element_Kinds := An_Incomplete_Type_Declaration; begin if Tagged_Present (Node) then Result := A_Tagged_Incomplete_Type_Declaration; end if; return Result; end N_Incomplete_Type_Declaration_Mapping; -- |A2005 end ------------------------------------------------ -- N_Index_Or_Discriminant_Constraint_Mapping -- ------------------------------------------------ function N_Index_Or_Discriminant_Constraint_Mapping (Node : Node_Id) return Internal_Element_Kinds is First_Item : Node_Id; -- the first element in the list of discrete ranges or discriminant -- associations, this element is the only one used to determine the kind -- of the constraint being analyzed First_Item_Kind : Node_Kind; Type_Entity : Node_Id; -- Needed in case when we can not make the decision using the syntax -- information only. Represents the type or subtype entity to which the -- constraint is applied begin -- Two Internal_Element_Kinds values may be possible: -- An_Index_Constraint -- A_Discriminant_Constraint First_Item := First (Constraints (Node)); First_Item_Kind := Nkind (First_Item); -- analyzing the syntax structure of First_Item: if First_Item_Kind = N_Discriminant_Association then return A_Discriminant_Constraint; elsif First_Item_Kind = N_Subtype_Indication or else First_Item_Kind = N_Range then return An_Index_Constraint; elsif First_Item_Kind = N_Attribute_Reference then -- analyzing the attribute designator: if Attribute_Name (First_Item) = Name_Range then return An_Index_Constraint; else return A_Discriminant_Constraint; end if; elsif not (First_Item_Kind = N_Identifier or else First_Item_Kind = N_Expanded_Name) then -- First_Item is an expression and it could not be interpreted as a -- subtype_mark from a discrete_subtype_indication, so what we have -- in this case is: return A_Discriminant_Constraint; end if; -- First_Item is of N_Identifier or N_Expanded_Name kind, and it may be -- either an expression in index constraint or a subtype mark in a -- discriminant constraint. In this case it is easier to analyze the -- type to which the constraint is applied, but not the constraint -- itself. Type_Entity := Entity (Sinfo.Subtype_Mark (Parent (Node))); while Ekind (Type_Entity) in Access_Kind loop Type_Entity := Directly_Designated_Type (Type_Entity); end loop; if Has_Discriminants (Type_Entity) then return A_Discriminant_Constraint; else return An_Index_Constraint; end if; end N_Index_Or_Discriminant_Constraint_Mapping; -------------------------------------- -- N_Iterator_Specification_Mapping -- -------------------------------------- function N_Iterator_Specification_Mapping (Node : Node_Id) return Internal_Element_Kinds is Result : Internal_Element_Kinds := A_Generalized_Iterator_Specification; begin if Of_Present (Node) then Result := An_Element_Iterator_Specification; end if; return Result; end N_Iterator_Specification_Mapping; ------------------------------ -- N_Loop_Statement_Mapping -- ------------------------------ function N_Loop_Statement_Mapping (Node : Node_Id) return Internal_Element_Kinds is Iteration : Node_Id; begin -- Three Internal_Element_Kinds values may be possible: -- A_Loop_Statement, -- A_While_Loop_Statement, -- A_For_Loop_Statement, Iteration := Iteration_Scheme (Node); if Present (Iteration) then if Present (Condition (Iteration)) then return A_While_Loop_Statement; else return A_For_Loop_Statement; end if; else return A_Loop_Statement; end if; end N_Loop_Statement_Mapping; ---------------------------------- -- N_Number_Declaration_Mapping -- ---------------------------------- function N_Number_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- An_Integer_Number_Declaration -- A_Real_Number_Declaration if Ekind (Defining_Identifier (Node)) = E_Named_Integer then return An_Integer_Number_Declaration; else return A_Real_Number_Declaration; end if; end N_Number_Declaration_Mapping; ---------------------------------- -- N_Object_Declaration_Mapping -- ---------------------------------- function N_Object_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds is Result : Internal_Element_Kinds; begin -- Three Internal_Element_Kinds values may be possible: -- A_Variable_Declaration, -- A_Constant_Declaration, -- A_Deferred_Constant_Declaration. -- |A2005 start -- A_Return_Variable_Specification -- A_Return_Constant_Specification -- |A2005 end if Nkind (Parent (Node)) = N_Extended_Return_Statement then if not Constant_Present (Node) then Result := A_Return_Variable_Specification; else Result := A_Return_Constant_Specification; end if; elsif not Constant_Present (Node) then Result := A_Variable_Declaration; elsif Present (Sinfo.Expression (Node)) then Result := A_Constant_Declaration; else Result := A_Deferred_Constant_Declaration; end if; return Result; end N_Object_Declaration_Mapping; ------------------------------- -- N_Operator_Symbol_Mapping -- ------------------------------- function N_Operator_Symbol_Mapping (Node : Node_Id) return Internal_Element_Kinds is Tmp : Node_Id; Operator_Chars : constant Name_Id := Chars (Node); Parameter_Number : Nat range 1 .. 2; -- see the GNAT components Namet.ads and Snames.ads -- N_Defining_Operator_Symbol_Mapping uses just the same approach, -- so if there is any error in it, then both functions contain it begin -- The following Internal_Element_Kinds values may be possible: -- -- A_And_Operator, -- and -- A_Or_Operator, -- or -- A_Xor_Operator, -- xor -- A_Equal_Operator, -- = -- A_Not_Equal_Operator, -- /= -- A_Less_Than_Operator, -- < -- A_Less_Than_Or_Equal_Operator, -- <= -- A_Greater_Than_Operator, -- > -- A_Greater_Than_Or_Equal_Operator, -- >= -- A_Plus_Operator, -- + -- A_Minus_Operator, -- - -- A_Concatenate_Operator, -- & -- A_Unary_Plus_Operator, -- + -- A_Unary_Minus_Operator, -- - -- A_Multiply_Operator, -- * -- A_Divide_Operator, -- / -- A_Mod_Operator, -- mod -- A_Rem_Operator, -- rem -- A_Exponentiate_Operator, -- ** -- A_Abs_Operator, -- abs -- A_Not_Operator, -- not if Operator_Chars = Name_Op_And then return An_And_Operator; elsif Operator_Chars = Name_Op_Or then return An_Or_Operator; elsif Operator_Chars = Name_Op_Xor then return An_Xor_Operator; elsif Operator_Chars = Name_Op_Eq then return An_Equal_Operator; elsif Operator_Chars = Name_Op_Ne then return A_Not_Equal_Operator; elsif Operator_Chars = Name_Op_Lt then return A_Less_Than_Operator; elsif Operator_Chars = Name_Op_Le then return A_Less_Than_Or_Equal_Operator; elsif Operator_Chars = Name_Op_Gt then return A_Greater_Than_Operator; elsif Operator_Chars = Name_Op_Ge then return A_Greater_Than_Or_Equal_Operator; elsif Operator_Chars = Name_Op_Concat then return A_Concatenate_Operator; elsif Operator_Chars = Name_Op_Multiply then return A_Multiply_Operator; elsif Operator_Chars = Name_Op_Divide then return A_Divide_Operator; elsif Operator_Chars = Name_Op_Mod then return A_Mod_Operator; elsif Operator_Chars = Name_Op_Rem then return A_Rem_Operator; elsif Operator_Chars = Name_Op_Expon then return An_Exponentiate_Operator; elsif Operator_Chars = Name_Op_Abs then return An_Abs_Operator; elsif Operator_Chars = Name_Op_Not then return A_Not_Operator; else -- for + and - operator signs binary and unary cases -- should be distinguished -- A simple case - we have an entity: if Entity_Present (Node) then Tmp := Entity (Node); if First_Entity (Tmp) = Last_Entity (Tmp) then Parameter_Number := 1; else Parameter_Number := 2; end if; else Parent_Node := Parent (Node); if Nkind (Parent_Node) = N_Integer_Literal or else Nkind (Parent_Node) = N_Real_Literal then -- Static expression of the form "+"(1, 2) rewritten into -- a literal value Parent_Node := Original_Node (Parent_Node); end if; -- we have to do this assignment also here, because this -- function may be called outside Node_To_Element -- convertors -- because of the possible tree rewriting, the parent node -- may be either of N_Function_Call or of N_Op_Xxx type) -- it can be also of N_Formal_Subprogram_Declaration kind, -- or even of N_Expanded_Name kind, while Nkind (Parent_Node) = N_Expanded_Name loop Parent_Node := Parent (Parent_Node); if Nkind (Parent_Node) = N_Integer_Literal or else Nkind (Parent_Node) = N_Real_Literal then -- Static expression of the form -- Prefix_Name."+"(1, 2) -- rewritten into a literal value Parent_Node := Original_Node (Parent_Node); end if; end loop; if Nkind (Parent_Node) = N_Op_Plus or else Nkind (Parent_Node) = N_Op_Minus then Parameter_Number := 1; elsif Nkind (Parent_Node) = N_Op_Add or else Nkind (Parent_Node) = N_Op_Subtract then Parameter_Number := 2; elsif Nkind (Parent_Node) = N_Function_Call then Parameter_Number := List_Length (Parameter_Associations (Parent_Node)); elsif Nkind (Parent_Node) = N_Subprogram_Renaming_Declaration or else Nkind (Parent_Node) in N_Formal_Subprogram_Declaration then Parameter_Number := List_Length (Parameter_Specifications (Specification (Parent_Node))); elsif Nkind (Parent_Node) = N_Indexed_Component then Parameter_Number := List_Length (Sinfo.Expressions (Parent_Node)); elsif Nkind (Parent_Node) = N_Pragma_Argument_Association then -- this is for pragma inline ("+"); Parameter_Number := 2; -- this choice is somewhat arbitrary :) elsif Nkind (Parent_Node) = N_Generic_Association then Tmp := Defining_Gen_Parameter (Node); Parameter_Number := List_Length (Parameter_Specifications (Parent (Tmp))); else -- Impossible case raise Internal_Implementation_Error; end if; end if; if Operator_Chars = Name_Op_Add then if Parameter_Number = 1 then return A_Unary_Plus_Operator; else return A_Plus_Operator; end if; else -- Operator_Chars = "-" if Parameter_Number = 1 then return A_Unary_Minus_Operator; else return A_Minus_Operator; end if; end if; end if; end N_Operator_Symbol_Mapping; ---------------------- -- N_Pragma_Mapping -- ---------------------- function N_Pragma_Mapping (Node : Node_Id) return Internal_Element_Kinds is Pragma_Chars : constant Name_Id := Pragma_Name (Node); begin -- Language-Defined Pragmas -- if Pragma_Chars = Name_All_Calls_Remote then return An_All_Calls_Remote_Pragma; -- I.2.3(6) elsif Pragma_Chars = Name_Asynchronous then return An_Asynchronous_Pragma; -- I.4.1(3) elsif Pragma_Chars = Name_Atomic then return An_Atomic_Pragma; -- G.5(3) elsif Pragma_Chars = Name_Atomic_Components then return An_Atomic_Components_Pragma; -- G.5(3) elsif Pragma_Chars = Name_Attach_Handler then return An_Attach_Handler_Pragma; -- G.3.1(3) elsif Pragma_Chars = Name_Controlled then return A_Controlled_Pragma; -- 13.11.3(3), B(12) elsif Pragma_Chars = Name_Convention then return A_Convention_Pragma; -- B(16), M.1(5) elsif Pragma_Chars = Name_Discard_Names then return A_Discard_Names_Pragma; -- C.5(2) elsif Pragma_Chars = Name_Elaborate then return An_Elaborate_Pragma; -- 10.2.1(20) elsif Pragma_Chars = Name_Elaborate_All then return An_Elaborate_All_Pragma; -- 10.2.1(19), B(8) elsif Pragma_Chars = Name_Elaborate_Body then return An_Elaborate_Body_Pragma; -- 10.2.1(21), B(9) elsif Pragma_Chars = Name_Export then return An_Export_Pragma; -- B(15), M.1(5) elsif Pragma_Chars = Name_Import then return An_Import_Pragma; -- B(14), M.1(5) elsif Pragma_Chars = Name_Inline then return An_Inline_Pragma; -- 6.3.2(4), B(5) elsif Pragma_Chars = Name_Inspection_Point then return An_Inspection_Point_Pragma; -- L.2.2(2) elsif Pragma_Chars = Name_Interrupt_Handler then return An_Interrupt_Handler_Pragma; -- G.3.1(2) elsif Pragma_Chars = Name_Interrupt_Priority then return An_Interrupt_Priority_Pragma; -- H.1(4) elsif Pragma_Chars = Name_Linker_Options then return A_Linker_Options_Pragma; -- B.1(8) elsif Pragma_Chars = Snames.Name_List then return A_List_Pragma; -- 2.8(18), B(2) elsif Pragma_Chars = Name_Locking_Policy then return A_Locking_Policy_Pragma; -- H.3(3) elsif Pragma_Chars = Name_Normalize_Scalars then return A_Normalize_Scalars_Pragma; -- L.1.1(2) elsif Pragma_Chars = Name_Optimize then return An_Optimize_Pragma; -- 2.8(18), B(4) elsif Pragma_Chars = Name_Pack then return A_Pack_Pragma; -- 13.2(2), B(11) elsif Pragma_Chars = Name_Page then return A_Page_Pragma; -- 2.8(18), B(3) elsif Pragma_Chars = Name_Preelaborate then return A_Preelaborate_Pragma; -- 10.2.1(3), B(6) elsif Pragma_Chars = Name_Priority then return A_Priority_Pragma; -- H.1(3) elsif Pragma_Chars = Name_Pure then return A_Pure_Pragma; -- 10.2.1(13), B(7) elsif Pragma_Chars = Name_Queuing_Policy then return A_Queuing_Policy_Pragma; -- H.4(3) elsif Pragma_Chars = Name_Remote_Call_Interface then return A_Remote_Call_Interface_Pragma; -- I.2.3(4) elsif Pragma_Chars = Name_Remote_Types then return A_Remote_Types_Pragma; -- I.2.2(4) elsif Pragma_Chars = Name_Restrictions then return A_Restrictions_Pragma; -- 13.12(2), B(13) elsif Pragma_Chars = Name_Reviewable then return A_Reviewable_Pragma; -- L.2.1(2) elsif Pragma_Chars = Name_Shared_Passive then return A_Shared_Passive_Pragma; -- I.2.1(4) elsif Pragma_Chars = Name_Storage_Size then -- the same name entry as for 'Storage_Size attribute! return A_Storage_Size_Pragma; -- 13.3(62) elsif Pragma_Chars = Name_Suppress then return A_Suppress_Pragma; -- 11.5(4), B(10) elsif Pragma_Chars = Name_Task_Dispatching_Policy then return A_Task_Dispatching_Policy_Pragma; -- H.2.2(2) elsif Pragma_Chars = Name_Volatile then return A_Volatile_Pragma; -- G.5(3) elsif Pragma_Chars = Name_Volatile_Components then return A_Volatile_Components_Pragma; -- G.5(3) -- --|A2005 start -- New Ada 2005 pragmas. To be alphabetically ordered later elsif Pragma_Chars = Name_Assert then return An_Assert_Pragma; elsif Pragma_Chars = Name_Assertion_Policy then return An_Assertion_Policy_Pragma; elsif Pragma_Chars = Name_Detect_Blocking then return A_Detect_Blocking_Pragma; elsif Pragma_Chars = Name_No_Return then return A_No_Return_Pragma; -- A_Partition_Elaboration_Policy_Pragma - not implemented yet! elsif Pragma_Chars = Name_Preelaborable_Initialization then return A_Preelaborable_Initialization_Pragma; elsif Pragma_Chars = Name_Priority_Specific_Dispatching then return A_Priority_Specific_Dispatching_Pragma; elsif Pragma_Chars = Name_Profile then return A_Profile_Pragma; elsif Pragma_Chars = Name_Relative_Deadline then return A_Relative_Deadline_Pragma; elsif Pragma_Chars = Name_Unchecked_Union then return An_Unchecked_Union_Pragma; elsif Pragma_Chars = Name_Unsuppress then return An_Unsuppress_Pragma; -- --|A2005 end -- --|A2012 start -- New Ada 2012 pragmas. To be alphabetically ordered later elsif Pragma_Chars = Name_Default_Storage_Pool then return A_Default_Storage_Pool_Pragma; -- elsif Pragma_Chars = Name_Dispatching_Domain then SCz -- return A_Dispatching_Domain_Pragma; elsif Pragma_Chars = Name_CPU then return A_CPU_Pragma; elsif Pragma_Chars = Name_Independent then return An_Independent_Pragma; elsif Pragma_Chars = Name_Independent_Components then return A_Independent_Components_Pragma; -- To be continued... -- --|A2012 end -- Implementation(GNAT)-Defined Pragmas -- elsif Pragma_Chars in First_Pragma_Name .. Last_Pragma_Name then -- We have already checked for all the standard pragma names, so -- all the rest known as pragma name should be GNAT-specific pragmas. return An_Implementation_Defined_Pragma; -- Vendor Appendix M else return An_Unknown_Pragma; -- Unknown to the compiler. end if; end N_Pragma_Mapping; ---------------------------------------- -- N_Procedure_Call_Statement_Mapping -- ---------------------------------------- function N_Procedure_Call_Statement_Mapping (Node : Node_Id) return Internal_Element_Kinds is Parent_N : Node_Id := Parent (Parent (Node)); Result : Internal_Element_Kinds := A_Procedure_Call_Statement; begin -- The only special case we have to process is a procedure call that is -- an argument of a pragma Debug. To satisfy the Ada syntax, we have to -- classify it as A_Function_Call (see G330-002). if Nkind (Parent_N) = N_Block_Statement and then not Comes_From_Source (Parent_N) then Parent_N := Parent (Parent_N); if Nkind (Parent_N) = N_If_Statement and then Nkind (Original_Node (Parent_N)) = N_Pragma and then Pragma_Name (Original_Node (Parent_N)) = Name_Debug then Result := A_Function_Call; end if; end if; return Result; end N_Procedure_Call_Statement_Mapping; ------------------------------------- -- N_Quantified_Expression_Mapping -- ------------------------------------- function N_Quantified_Expression_Mapping (Node : Node_Id) return Internal_Element_Kinds is Result : Internal_Element_Kinds := A_For_Some_Quantified_Expression; begin if All_Present (Node) then Result := A_For_All_Quantified_Expression; end if; return Result; end N_Quantified_Expression_Mapping; -------------------------------- -- N_Range_Constraint_Mapping -- -------------------------------- function N_Range_Constraint_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Range_Attribute_Reference -- A_Simple_Expression_Range if Nkind (Original_Node (Range_Expression (Node))) = N_Range then return A_Simple_Expression_Range; else return A_Range_Attribute_Reference; end if; end N_Range_Constraint_Mapping; --------------------- -- N_Range_Mapping -- --------------------- function N_Range_Mapping (Node : Node_Id) return Internal_Element_Kinds is Context_Kind : constant Node_Kind := Nkind (Original_Node (Parent_Node)); begin -- The following Internal_Element_Kinds values may be possible: -- A_Discrete_Simple_Expression_Range_As_Subtype_Definition -- A_Discrete_Simple_Expression_Range -- ??? -- Other values should be added during constructing the -- full implementation case Context_Kind is when N_Constrained_Array_Definition | N_Entry_Declaration => return A_Discrete_Simple_Expression_Range_As_Subtype_Definition; when N_Index_Or_Discriminant_Constraint | N_Slice | N_Case_Statement_Alternative | N_Component_Association => return A_Discrete_Simple_Expression_Range; when N_In | N_Not_In => return A_Simple_Expression_Range; when others => -- not implemented cases (???) Not_Implemented_Mapping (Nkind (Node)); end case; end N_Range_Mapping; --------------------------------- -- N_Record_Definition_Mapping -- --------------------------------- function N_Record_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds is Result : Internal_Element_Kinds := A_Record_Type_Definition; Is_Formal : constant Boolean := Nkind (Original_Node (Parent (Node))) = N_Formal_Type_Declaration; begin -- Two Internal_Element_Kinds values may be possible (Ada 95): -- A_Record_Type_Definition -- A_Tagged_Record_Type_Definition -- --|A2005 start -- Plus the following values for Ada 2005: -- -- An_Ordinary_Interface -- A_Limited_Interface -- A_Task_Interface -- A_Protected_Interface -- A_Synchronized_Interface -- -- A_Formal_Ordinary_Interface -- A_Formal_Limited_Interface -- A_Formal_Task_Interface -- A_Formal_Protected_Interface -- A_Formal_Synchronized_Interface -- --|A2005 end -- Implementation revised for Ada 2005 if Interface_Present (Node) then if Limited_Present (Node) then if Is_Formal then Result := A_Formal_Limited_Interface; else Result := A_Limited_Interface; end if; elsif Task_Present (Node) then if Is_Formal then Result := A_Formal_Task_Interface; else Result := A_Task_Interface; end if; elsif Protected_Present (Node) then if Is_Formal then Result := A_Formal_Protected_Interface; else Result := A_Protected_Interface; end if; elsif Synchronized_Present (Node) then if Is_Formal then Result := A_Formal_Synchronized_Interface; else Result := A_Synchronized_Interface; end if; else if Is_Formal then Result := A_Formal_Ordinary_Interface; else Result := An_Ordinary_Interface; end if; end if; elsif Tagged_Present (Node) then Result := A_Tagged_Record_Type_Definition; end if; return Result; -- --|A2005 end end N_Record_Definition_Mapping; --------------------------------- -- N_Requeue_Statement_Mapping -- --------------------------------- function N_Requeue_Statement_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Requeue_Statement -- A_Requeue_Statement_With_Abort if Abort_Present (Node) then return A_Requeue_Statement_With_Abort; else return A_Requeue_Statement; end if; end N_Requeue_Statement_Mapping; ------------------------------- -- N_Subprogram_Body_Mapping -- ------------------------------- function N_Subprogram_Body_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Procedure_Body_Declaration and A_Function_Body_Declaration if Nkind (Specification (Node)) = N_Function_Specification then return A_Function_Body_Declaration; else return A_Procedure_Body_Declaration; end if; end N_Subprogram_Body_Mapping; ------------------------------------ -- N_Subprogram_Body_Stub_Mapping -- ------------------------------------ function N_Subprogram_Body_Stub_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Procedure_Body_Stub and A_Function_Body_Stub, if Nkind (Specification (Node)) = N_Function_Specification then return A_Function_Body_Stub; else return A_Procedure_Body_Stub; end if; end N_Subprogram_Body_Stub_Mapping; -------------------------------------- -- N_Subprogram_Declaration_Mapping -- -------------------------------------- function N_Subprogram_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Procedure_Declaration -- A_Function_Declaration if Nkind (Specification (Node)) = N_Function_Specification then return A_Function_Declaration; -- --|A2005 start elsif Null_Present (Specification (Node)) then return A_Null_Procedure_Declaration; -- --|A2005 end else return A_Procedure_Declaration; end if; end N_Subprogram_Declaration_Mapping; ----------------------------------------------- -- N_Subprogram_Renaming_Declaration_Mapping -- ----------------------------------------------- function N_Subprogram_Renaming_Declaration_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- A_Procedure_Renaming_Declaration and A_Function_Renaming_Declaration if Nkind (Specification (Node)) = N_Function_Specification then return A_Function_Renaming_Declaration; else return A_Procedure_Renaming_Declaration; end if; end N_Subprogram_Renaming_Declaration_Mapping; ---------------------------------- -- N_Subtype_Indication_Mapping -- ---------------------------------- function N_Subtype_Indication_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- The following Internal_Element_Kinds values may be possible: -- A_Discrete_Subtype_Indication_As_Subtype_Definition -- A_Discrete_Subtype_Indication -- A_Subtype_Indication case Nkind (Parent_Node) is when N_Constrained_Array_Definition => if Is_List_Member (Node) then return A_Discrete_Subtype_Indication_As_Subtype_Definition; end if; when N_Entry_Declaration => return A_Discrete_Subtype_Indication_As_Subtype_Definition; when N_Index_Or_Discriminant_Constraint | N_Slice => return A_Discrete_Subtype_Indication; when others => null; end case; return A_Subtype_Indication; end N_Subtype_Indication_Mapping; ------------------------------- -- N_Use_Type_Clause_Mapping -- ------------------------------- function N_Use_Type_Clause_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin if All_Present (Node) then return A_Use_All_Type_Clause; else return A_Use_Type_Clause; end if; end N_Use_Type_Clause_Mapping; ---------------------- -- N_To_E_List_New -- ---------------------- function N_To_E_List_New (List : List_Id; Include_Pragmas : Boolean := False; Starting_Element : Asis.Element := Asis.Nil_Element; Node_Knd : Node_Kind := N_Empty; Internal_Kind : Internal_Element_Kinds := Not_An_Element; Special_Case : Special_Cases := Not_A_Special_Case; Norm_Case : Normalization_Cases := Is_Not_Normalized; In_Unit : Asis.Compilation_Unit := Asis.Nil_Compilation_Unit) return Asis.Element_List is begin Set_Element_List (List, Include_Pragmas, Starting_Element, Node_Knd, Internal_Kind, Special_Case, Norm_Case, In_Unit); return Asis.Association_List (Internal_Asis_Element_Table.Table (1 .. Internal_Asis_Element_Table.Last)); end N_To_E_List_New; ---------------------------------------------- -- N_Unconstrained_Array_Definition_Mapping -- ---------------------------------------------- function N_Unconstrained_Array_Definition_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin -- Two Internal_Element_Kinds values may be possible: -- An_Unconstrained_Array_Definition -- A_Formal_Unconstrained_Array_Definition if Nkind (Parent (Node)) = N_Formal_Type_Declaration then return A_Formal_Unconstrained_Array_Definition; else return An_Unconstrained_Array_Definition; end if; end N_Unconstrained_Array_Definition_Mapping; ---------------- -- No_Mapping -- ---------------- procedure No_Mapping (Node : Node_Id) is begin -- This function should never be called! raise Internal_Implementation_Error; end No_Mapping; ------------------------- -- Node_To_Element_New -- ------------------------- function Node_To_Element_New (Node : Node_Id; Node_Field_1 : Node_Id := Empty; Node_Field_2 : Node_Id := Empty; Starting_Element : Asis.Element := Asis.Nil_Element; Internal_Kind : Internal_Element_Kinds := Not_An_Element; Spec_Case : Special_Cases := Not_A_Special_Case; Norm_Case : Normalization_Cases := Is_Not_Normalized; Considering_Parent_Count : Boolean := True; Using_Original_Node : Boolean := True; Inherited : Boolean := False; In_Unit : Asis.Compilation_Unit := Asis.Nil_Compilation_Unit) return Asis.Element is R_Node : Node_Id; Res_Node : Node_Id; Res_Node_Field_1 : Node_Id := Empty; Res_Node_Field_2 : Node_Id := Empty; Res_Internal_Kind : Internal_Element_Kinds := Internal_Kind; Res_Enclosing_Unit : Asis.Compilation_Unit; Res_Is_Part_Of_Implicit : Boolean := False; Res_Is_Part_Of_Inherited : Boolean := False; Res_Is_Part_Of_Instance : Boolean := False; Res_Spec_Case : Special_Cases := Spec_Case; Res_Char_Code : Char_Code := 0; Res_Parenth_Count : Nat := 0; begin -- first, check if Node is not Empty and return Nil_Element otherwise: if No (Node) then return Nil_Element; end if; if Using_Original_Node and then Is_Rewrite_Substitution (Node) and then not Is_Rewritten_Function_Prefix_Notation (Node) then -- Note that for a function call in Object.Operation notation we do -- not use the original node at all, because the original tree -- structure is not properly decorated and analyzed, but the -- rewritten subtree contains all we need Res_Node := Original_Node (Node); if Is_Rewrite_Substitution (Res_Node) then Res_Node := Original_Node (Res_Node); end if; else Res_Node := Node; end if; -- setting the global Parent_Node needed for computing the kind of -- the returned Element Parent_Node := Parent (Node); if not Is_Nil (Starting_Element) then -- We need this to define the enclosing unit for the new Element Res_Spec_Case := Special_Case (Starting_Element); end if; -- setting result's enclosing unit: if Exists (In_Unit) then -- if In_Unit is set, we take information about the result's -- enclosing unit from it, unless we have to create a configuration -- pragma or component thereof. if Spec_Case = Configuration_File_Pragma then Res_Enclosing_Unit := Get_Configuration_CU (In_Unit); else Res_Enclosing_Unit := In_Unit; end if; elsif not Is_Nil (Starting_Element) then -- if Starting_Element is set, but In_Unit is not, we take -- information about the result's enclosing unit from -- Starting_Element Res_Enclosing_Unit := Encl_Unit (Starting_Element); else -- we can be here only if both Starting_Element and In_Unit are -- nor set. This is definitely an error. raise Internal_Implementation_Error; end if; -- if Starting_Element is set, we "transfer" everything what is -- possible from it to the result: if not Is_Nil (Starting_Element) then if Nkind (Res_Node) = N_Null_Statement and then not (Comes_From_Source (Res_Node)) then -- Implicit NULL statement'floating' labels are attached to Res_Is_Part_Of_Implicit := True; elsif Nkind (Res_Node) = N_Label then -- Needed in case of 'floating' labels Res_Is_Part_Of_Implicit := False; else Res_Is_Part_Of_Implicit := Is_From_Implicit (Starting_Element); end if; Res_Is_Part_Of_Inherited := Is_From_Inherited (Starting_Element); Res_Is_Part_Of_Instance := Is_From_Instance (Starting_Element); -- Res_Spec_Case is already set! if Present (Node_Field_1_Value (Starting_Element)) then Res_Node_Field_1 := Node_Field_1_Value (Starting_Element); pragma Assert (Get_Current_Tree = Encl_Tree (Starting_Element)); -- We can not use Asis.Set_Get.Node_Field_1 here, because it -- might reset the tree. end if; if Present (Node_Field_2_Value (Starting_Element)) then Res_Node_Field_2 := Node_Field_2_Value (Starting_Element); pragma Assert (Get_Current_Tree = Encl_Tree (Starting_Element)); -- We can not use Asis.Set_Get.Node_Field_2 here, because it -- might reset the tree. end if; if Internal_Kind = A_Defining_Character_Literal or else Internal_Kind = An_Enumeration_Literal_Specification then -- We keep Character_Code unless the result is type definition -- (it that case keeping Character_Code would make Is_Equal test -- not work properly Res_Char_Code := Character_Code (Starting_Element); end if; if Res_Spec_Case in Expanded_Spec then -- We have to reset Res_Spec_Case from -- Expanded_Package_Instantiation or -- Expanded_Subprogram_Instantiation to Not_A_Special_Case; -- because only (the whole) expanded generic declarations can have -- the value of Special_Case from Expanded_Spec Res_Spec_Case := Not_A_Special_Case; end if; elsif Res_Spec_Case in Expanded_Spec then Res_Is_Part_Of_Implicit := False; else if Is_From_Instance (Original_Node (Node)) or else Is_Name_Of_Expanded_Subprogram (Res_Node) or else Part_Of_Pass_Generic_Actual (Original_Node (Node)) or else Is_Stub_To_Body_Instanse_Replacement (Node) or else Spec_Case = Expanded_Package_Instantiation or else Spec_Case = Expanded_Subprogram_Instantiation then Res_Is_Part_Of_Instance := True; end if; if Inherited then Res_Is_Part_Of_Inherited := True; Res_Is_Part_Of_Implicit := True; end if; if not Comes_From_Source (Res_Node) and then (not Part_Of_Pass_Generic_Actual (Res_Node) or else Norm_Case = Is_Normalized_Defaulted_For_Box) and then not Is_Name_Of_Expanded_Subprogram (Res_Node) then Res_Is_Part_Of_Implicit := True; end if; end if; -- This patch below is really terrible!!! requires revising!!! -- ??? if Spec_Case = Expanded_Package_Instantiation or else Spec_Case = Expanded_Subprogram_Instantiation then Res_Is_Part_Of_Instance := True; end if; -- if Spec_Case is set explicitly, we should set (or reset) -- Res_Spec_Case from it if Spec_Case /= Not_A_Special_Case then Res_Spec_Case := Spec_Case; end if; -- computing the kind of the result and correcting Special_Case, -- if needed if Res_Internal_Kind = Not_An_Element then -- Res_Internal_Kind is initialized by the value of the -- Internal_Kind parameter. If this value differs from -- Not_An_Element, we simply does not change it if Considering_Parent_Count and then (Parenth_Count (Res_Node, Node) > 0 or else Requires_Parentheses (Res_Node)) then -- special processing for A_Parenthesized_Expression Res_Internal_Kind := A_Parenthesized_Expression; if Parenth_Count (Res_Node, Node) > 0 then Res_Parenth_Count := Parenth_Count (Res_Node, Node); if Requires_Parentheses (Res_Node) then Res_Parenth_Count := Res_Parenth_Count + 1; end if; else -- (conditional expression) Res_Parenth_Count := 1; end if; else -- from Sinfo (spec, rev. 1.334): --------------------------------- -- 9.5.3 Entry Call Statement -- --------------------------------- -- ENTRY_CALL_STATEMENT ::= entry_NAME [ACTUAL_PARAMETER_PART]; -- The parser may generate a procedure call for this construct. The -- semantic pass must correct this misidentification where needed. if Res_Node /= Node and then ((Nkind (Res_Node) = N_Procedure_Call_Statement and then Nkind (Node) = N_Entry_Call_Statement and then not Is_Protected_Procedure_Call (Node)) or else (Nkind (Res_Node) = N_Explicit_Dereference and then Nkind (Node) = N_Function_Call)) then Res_Node := Node; -- ??? -- There is no need to keep the original structure in this -- case, it is definitely wrong if Nkind (Node) = N_Entry_Call_Statement then Res_Internal_Kind := An_Entry_Call_Statement; else Res_Internal_Kind := A_Function_Call; end if; else if (Nkind (Node) = N_Integer_Literal or else Nkind (Node) = N_Real_Literal) and then ((not Is_Rewrite_Substitution (Node)) or else Nkind (Original_Node (Node)) = N_Identifier) and then Comes_From_Source (Node) = False and then Is_Static_Expression (Node) and then Present (Original_Entity (Node)) then -- See BB10-002: The special case of named numbers rewritten -- into numeric literals. Res_Spec_Case := Rewritten_Named_Number; Res_Internal_Kind := An_Identifier; else Res_Internal_Kind := Asis_Internal_Element_Kind (Res_Node); end if; end if; end if; end if; -- and now we have to check if the Element to be returned is from the -- Standard package, and if it is, we have to correct Res_Spec_Case: if Res_Spec_Case = Not_A_Special_Case and then Sloc (Res_Node) <= Standard_Location then if Nkind (Node) = N_Defining_Character_Literal then Res_Spec_Case := Stand_Char_Literal; else Res_Spec_Case := Explicit_From_Standard; end if; end if; if Res_Spec_Case = Explicit_From_Standard or else Res_Spec_Case = Stand_Char_Literal then Res_Is_Part_Of_Implicit := False; end if; -- ??? This assignment is not necessary and has been -- introduced to workaround a problem with the sgi n32 compiler R_Node := Node; if Nkind (Node) = N_Function_Call and then (Res_Internal_Kind = A_Selected_Component or else Res_Internal_Kind = An_Enumeration_Literal) then -- a reference to an overloaded enumeration literal represented as a -- function call, we have to go one step down: R_Node := Sinfo.Name (Node); Res_Node := R_Node; else R_Node := Node; end if; if Present (Node_Field_1) then Res_Node_Field_1 := Node_Field_1; end if; if Present (Node_Field_2) then Res_Node_Field_2 := Node_Field_2; end if; if Res_Spec_Case = From_Limited_View then Res_Is_Part_Of_Implicit := True; end if; return Set_Element ( Node => Res_Node, R_Node => R_Node, Node_Field_1 => Res_Node_Field_1, Node_Field_2 => Res_Node_Field_2, Encl_Unit => Res_Enclosing_Unit, Int_Kind => Res_Internal_Kind, Implicit => Res_Is_Part_Of_Implicit, Inherited => Res_Is_Part_Of_Inherited, Instance => Res_Is_Part_Of_Instance, Spec_Case => Res_Spec_Case, Norm_Case => Norm_Case, Par_Count => Res_Parenth_Count, Character_Code => Res_Char_Code); end Node_To_Element_New; -------------------- -- Normalize_Name -- -------------------- procedure Normalize_Name (Capitalized : Boolean := False) is begin if Namet.Name_Len = 0 then return; end if; Namet.Name_Buffer (1) := To_Upper (Namet.Name_Buffer (1)); for I in 1 .. Namet.Name_Len - 1 loop if Capitalized or else Namet.Name_Buffer (I) = '_' then Namet.Name_Buffer (I + 1) := To_Upper (Namet.Name_Buffer (I + 1)); end if; end loop; end Normalize_Name; ----------------------------- -- Normalized_Namet_String -- ----------------------------- function Normalized_Namet_String (Node : Node_Id) return String is Capitalize : Boolean := False; begin Namet.Get_Name_String (Chars (Node)); if Node = Standard_ASCII or else Node in SE (S_LC_A) .. SE (S_LC_Z) or else Node in SE (S_NUL) .. SE (S_US) or else Node = SE (S_DEL) then Capitalize := True; end if; Normalize_Name (Capitalize); return Namet.Name_Buffer (1 .. Namet.Name_Len); end Normalized_Namet_String; ----------------------------- -- Not_Implemented_Mapping -- ----------------------------- function Not_Implemented_Mapping (Node : Node_Id) return Internal_Element_Kinds is begin Not_Implemented_Yet (Diagnosis => "AST Node -> Asis.Element mapping for the " & Node_Kind'Image (Nkind (Node)) & " Node Kind value has not been implemented yet"); return Not_An_Element; -- to make the code syntactically correct; end Not_Implemented_Mapping; procedure Not_Implemented_Mapping (Source_Node_Kind : Node_Kind) is begin Not_Implemented_Yet (Diagnosis => "AST Node -> Asis.Element mapping for the " & Node_Kind'Image (Source_Node_Kind) & " Node Kind value has not been implemented yet"); end Not_Implemented_Mapping; ---------------------------------- -- Ordinary_Inclusion_Condition -- ---------------------------------- function Ordinary_Inclusion_Condition (Node : Node_Id) return Boolean is O_Node : constant Node_Id := Original_Node (Node); Arg_Kind : constant Node_Kind := Nkind (Node); Result : Boolean := True; begin if Is_Rewrite_Insertion (Node) or else May_Be_Included_Switch (Nkind (Node)) = False or else (Nkind (Node) = N_With_Clause and then Implicit_With (Node)) or else (Nkind (Node) = N_Entry_Call_Statement and then Node = O_Node) then Result := False; elsif not Comes_From_Source (O_Node) then if Arg_Kind = N_Null_Statement then -- We have to include implicit null statements 'floating' labels -- are attached to if not (No (Next (Node)) and then Present (Prev (Node)) and then Nkind (Prev (Node)) = N_Label and then Comes_From_Source (Prev (Node))) then Result := False; end if; elsif Arg_Kind = N_Object_Renaming_Declaration then -- For FB02-008 if (Nkind (Sinfo.Name (Node)) = N_Identifier and then Is_Internal_Name (Chars (Sinfo.Name (Node)))) or else (Nkind (Sinfo.Subtype_Mark (Node)) = N_Identifier and then Is_Internal_Name (Chars (Sinfo.Subtype_Mark (Node)))) then Result := False; end if; elsif not ((Arg_Kind = N_Object_Declaration and then not Is_Internal_Name (Chars (Defining_Identifier (O_Node)))) or else Arg_Kind = N_Component_Declaration or else Arg_Kind = N_Discriminant_Specification or else Arg_Kind = N_Parameter_Specification or else Arg_Kind = N_Component_Association or else ((Arg_Kind = N_Integer_Literal or else Arg_Kind = N_Real_Literal) and then Is_Static_Expression (Node)) -- This condition describes the special case of a named -- number rewritten into a literal node, see BB10-002 or else Sloc (Node) <= Standard_Location or else Is_Rewritten_Function_Prefix_Notation (Parent (Node)) or else Pass_Generic_Actual (Node)) then Result := False; end if; end if; return Result; end Ordinary_Inclusion_Condition; ------------------- -- Parenth_Count -- ------------------- function Parenth_Count (N : Node_Id; Original_N : Node_Id) return Nat is Result : Nat := Paren_Count (N); begin if Result > 0 and then Nkind (Original_Node (Parent (Original_N))) = N_Qualified_Expression then Result := Result - 1; end if; return Result; end Parenth_Count; -------------------------- -- Requires_Parentheses -- -------------------------- function Requires_Parentheses (N : Node_Id) return Boolean is Left_Par_Sloc : Source_Ptr; Result : Boolean := False; begin if Nkind (N) = N_Conditional_Expression or else Nkind (N) = N_Case_Expression or else Nkind (N) = N_Quantified_Expression then Result := True; -- And now - cases when the expression does not require parentheses: if Nkind (Parent (N)) = N_Qualified_Expression or else Nkind (Parent (N)) = N_Type_Conversion or else (Is_List_Member (N) and then List_Length (List_Containing (N)) = 1) then -- There is a corner case here: -- P ((if A then B else C)); Left_Par_Sloc := Sloc (N); Left_Par_Sloc := Search_Prev_Word (Left_Par_Sloc); pragma Assert (Get_Character (Left_Par_Sloc) = '('); Left_Par_Sloc := Search_Prev_Word (Left_Par_Sloc); if Get_Character (Left_Par_Sloc) /= '(' then Result := False; end if; end if; end if; -- if Nkind (N) = N_Conditional_Expression -- or else -- Nkind (N) = N_Case_Expression -- or else -- Nkind (N) = N_Quantified_Expression -- then -- Left_Par_Sloc := Sloc (N); -- Left_Par_Sloc := Search_Prev_Word (Left_Par_Sloc); -- Result := Get_Character (Left_Par_Sloc) = '('; -- end if; -- if Result then -- -- We have to check if this '(' belongs to some other construct: -- Left_Par_Sloc := Search_Prev_Word (Left_Par_Sloc); -- if Get_Character (Left_Par_Sloc) /= '(' then -- case Nkind (Parent (N)) is -- when N_Qualified_Expression | -- N_Type_Conversion => -- Result := False; -- when N_Function_Call | -- N_Indexed_Component | -- N_Procedure_Call_Statement | -- N_Entry_Call_Statement => -- -- ??? Is this list complete??? -- if Get_Character (Left_Par_Sloc) /= ',' then -- Result := False; -- end if; -- when others => -- null; -- end case; -- end if; -- end if; return Result; end Requires_Parentheses; ----------------------------------------- -- Set_Concurrent_Inherited_Components -- ----------------------------------------- procedure Set_Concurrent_Inherited_Components (Type_Def : Asis.Element; Include_Discs : Boolean := True) is Type_Entity : Entity_Id; Next_Comp_Node : Node_Id; begin Asis_Element_Table.Init; Type_Entity := Defining_Identifier (Parent (R_Node (Type_Def))); if Present (First_Entity (Type_Entity)) then if Include_Discs then Next_Comp_Node := First_Entity (Type_Entity); while Ekind (Next_Comp_Node) = E_Discriminant loop Asis_Element_Table.Append (Node_To_Element_New (Node => Parent (Next_Comp_Node), Starting_Element => Type_Def)); Set_Node_Field_2 (Asis_Element_Table.Table (Asis_Element_Table.Last), Next_Comp_Node); -- This is needed to unify the processing of inherited -- discriminants in Asis.Declarations.Names Next_Comp_Node := Next_Entity (Next_Comp_Node); end loop; end if; -- To set all the non-discriminant components, we have to go to the -- definition of the root concurrent type and to traverse it to -- grab all this components, because the (non-discrimiinant) -- entities attached to the entity of the derived concurrent type -- are artificial entities created for further tree expansion while Type_Entity /= Etype (Type_Entity) loop Type_Entity := Etype (Type_Entity); end loop; Type_Entity := Parent (Type_Entity); if Nkind (Type_Entity) = N_Task_Type_Declaration then Type_Entity := Task_Definition (Type_Entity); else Type_Entity := Protected_Definition (Type_Entity); end if; Next_Comp_Node := First_Non_Pragma (Visible_Declarations (Type_Entity)); while Present (Next_Comp_Node) loop Asis_Element_Table.Append (Node_To_Element_New (Node => Next_Comp_Node, Starting_Element => Type_Def)); Next_Comp_Node := Next_Non_Pragma (Next_Comp_Node); end loop; if Present (Private_Declarations (Type_Entity)) then Next_Comp_Node := First_Non_Pragma (Private_Declarations (Type_Entity)); while Present (Next_Comp_Node) loop Asis_Element_Table.Append (Node_To_Element_New (Node => Next_Comp_Node, Starting_Element => Type_Def)); Next_Comp_Node := Next_Non_Pragma (Next_Comp_Node); end loop; end if; end if; end Set_Concurrent_Inherited_Components; ---------------------- -- Set_Element_List -- ---------------------- -- At the moment, the implementation is just a copy from N_To_E_List_New -- with changes related to building the result list in Element Table procedure Set_Element_List (List : List_Id; Include_Pragmas : Boolean := False; Starting_Element : Asis.Element := Asis.Nil_Element; Node_Knd : Node_Kind := N_Empty; Internal_Kind : Internal_Element_Kinds := Not_An_Element; Special_Case : Special_Cases := Not_A_Special_Case; Norm_Case : Normalization_Cases := Is_Not_Normalized; In_Unit : Asis.Compilation_Unit := Asis.Nil_Compilation_Unit; Append : Boolean := False) is List_El : Node_Id; List_El_Kind : Node_Kind; function First_List_Element (List : List_Id) return Node_Id; -- returns the first element of List, taking into account -- the value of Include_Pragmas function Next_List_Element (Node : Node_Id) return Node_Id; -- returns the first element of List, taking into account -- the value of Include_Pragmas procedure Skip_Pragmas (N : in out Node_Id); -- Supposes that Is_List_Member (N). If N is of N_Pragma kind and if -- Include_Pragmas is set OFF, moves N to the next element of the same -- list that is not of N_Pragma kinds or set it to Empty if there is no -- such node. We can not just use Nlists.First_Non_Pragma and -- Nlists.Next_Non_Pragma, because they also skip N_Null_Statement -- nodes. ------------------------ -- First_List_Element -- ------------------------ function First_List_Element (List : List_Id) return Node_Id is Result : Node_Id; begin Result := First (List); Skip_Pragmas (Result); if Is_Rewrite_Substitution (Result) and then Nkind (Result) = N_Loop_Statement and then Nkind (Original_Node (Result)) = N_Goto_Statement then -- This is the case when infinite loop implemented as -- -- <<Target>> ... -- ... -- goto Target; -- -- Is rewritten into N_Loop_Statement if not Is_Empty_List (Statements (Result)) then Result := First (Statements (Result)); end if; end if; return Result; end First_List_Element; ----------------------- -- Next_List_Element -- ----------------------- function Next_List_Element (Node : Node_Id) return Node_Id is Tmp : Node_Id; Result : Node_Id; begin Result := Next (Node); Skip_Pragmas (Result); if Is_Rewrite_Substitution (Result) and then Nkind (Result) = N_Loop_Statement and then Nkind (Original_Node (Result)) = N_Goto_Statement then -- This is the case when infinite loop implemented as -- -- <<Target>> ... -- ... -- goto Target; -- -- Is rewritten into N_Loop_Statement if not Is_Empty_List (Statements (Result)) then Result := First (Statements (Result)); end if; end if; if No (Result) then Tmp := Parent (Node); if Is_Rewrite_Substitution (Tmp) and then Nkind (Tmp) = N_Loop_Statement and then Nkind (Original_Node (Tmp)) = N_Goto_Statement then -- We have just finished traversing of the artificial loop -- statement created for goto, so it's tome to -- return this goto itself. Note, that we are returning the -- rewritten N_Loop_Statement to keep list and parent -- references Result := Tmp; end if; end if; return Result; end Next_List_Element; ------------------ -- Skip_Pragmas -- ------------------ procedure Skip_Pragmas (N : in out Node_Id) is begin if not Include_Pragmas then while Present (N) and then Nkind (Original_Node (N)) = N_Pragma loop N := Next (N); end loop; end if; end Skip_Pragmas; begin if not Append then Internal_Asis_Element_Table.Init; end if; if No (List) or else Is_Empty_List (List) then return; end if; List_El := First_List_Element (List); while Present (List_El) loop if Debug_Flag_L then Write_Node (N => List_El, Prefix => "Set_Element_List debug info-> "); Write_Str ("May_Be_Included is "); Write_Str (Boolean'Image (May_Be_Included (List_El))); Write_Eol; Write_Eol; end if; List_El_Kind := Nkind (List_El); if May_Be_Included (List_El) and then not ((Node_Knd /= N_Empty) and then (List_El_Kind /= Node_Knd)) then Internal_Asis_Element_Table.Append (Node_To_Element_New (Starting_Element => Starting_Element, Node => List_El, Internal_Kind => Internal_Kind, Spec_Case => Special_Case, Norm_Case => Norm_Case, In_Unit => In_Unit)); if List_El_Kind = N_Object_Declaration or else List_El_Kind = N_Number_Declaration or else List_El_Kind = N_Discriminant_Specification or else List_El_Kind = N_Component_Declaration or else List_El_Kind = N_Parameter_Specification or else List_El_Kind = N_Exception_Declaration or else List_El_Kind = N_Formal_Object_Declaration or else List_El_Kind = N_With_Clause then Skip_Normalized_Declarations (List_El); end if; end if; List_El := Next_List_Element (List_El); end loop; end Set_Element_List; --------------------------------- -- Set_Inherited_Discriminants -- --------------------------------- procedure Set_Inherited_Discriminants (Type_Def : Asis.Element) is Next_Discr_Elmt : Elmt_Id; Next_Elem_Node : Node_Id; begin Next_Elem_Node := Defining_Identifier (Parent (R_Node (Type_Def))); if Present (Stored_Constraint (Next_Elem_Node)) then Asis_Element_Table.Init; Next_Discr_Elmt := First_Elmt (Stored_Constraint (Next_Elem_Node)); while Present (Next_Discr_Elmt) loop Next_Elem_Node := Parent (Entity (Node (Next_Discr_Elmt))); Asis_Element_Table.Append (Node_To_Element_New (Node => Next_Elem_Node, Internal_Kind => A_Discriminant_Specification, Starting_Element => Type_Def)); Next_Discr_Elmt := Next_Elmt (Next_Discr_Elmt); end loop; end if; end Set_Inherited_Discriminants; ------------------------------ -- Set_Inherited_Components -- ------------------------------ procedure Set_Inherited_Components (Type_Def : Asis.Element; Include_Discs : Boolean := True) is Next_Comp_Node : Node_Id; function Is_Implicit_Component (E : Entity_Id) return Boolean; -- Checks if E is an entity representing implicit inherited -- component function Is_Implicit_Component (E : Entity_Id) return Boolean is Result : Boolean := False; begin if Ekind (E) = E_Component then Result := (E /= Original_Record_Component (E)) or else not Comes_From_Source (Parent (E)); elsif Ekind (E) = E_Discriminant and then Include_Discs then Result := not Is_Completely_Hidden (E); end if; return Result; end Is_Implicit_Component; begin Asis_Element_Table.Init; Next_Comp_Node := Defining_Identifier (Parent (R_Node (Type_Def))); if Ekind (Next_Comp_Node) = E_Record_Subtype then -- For subtypes we may have components depending on discriminants -- skipped in case of static discriminant constraints Next_Comp_Node := Etype (Next_Comp_Node); end if; if Present (First_Entity (Next_Comp_Node)) then Next_Comp_Node := First_Entity (Next_Comp_Node); while Present (Next_Comp_Node) loop if Is_Implicit_Component (Next_Comp_Node) then Asis_Element_Table.Append (Node_To_Element_New (Node => Parent (Next_Comp_Node), Starting_Element => Type_Def)); Set_Node_Field_2 (Asis_Element_Table.Table (Asis_Element_Table.Last), Next_Comp_Node); Set_From_Implicit (Asis_Element_Table.Table (Asis_Element_Table.Last), True); Set_From_Inherited (Asis_Element_Table.Table (Asis_Element_Table.Last), True); end if; Next_Comp_Node := Next_Entity (Next_Comp_Node); end loop; end if; end Set_Inherited_Components; ---------------------------- -- Set_Inherited_Literals -- ---------------------------- procedure Set_Inherited_Literals (Type_Def : Asis.Element) is Next_Literal_Node : Node_Id; Res_Etype : Entity_Id; Encl_Type : constant Node_Id := Parent (R_Node (Type_Def)); begin Asis_Element_Table.Init; Next_Literal_Node := Defining_Identifier (Parent (R_Node (Type_Def))); if Present (First_Literal (Next_Literal_Node)) then Next_Literal_Node := First_Literal (Next_Literal_Node); Res_Etype := Etype (Next_Literal_Node); while Present (Next_Literal_Node) and then Etype (Next_Literal_Node) = Res_Etype loop Asis_Element_Table.Append (Node_To_Element_New (Node => Next_Literal_Node, Internal_Kind => An_Enumeration_Literal_Specification, Starting_Element => Type_Def)); Set_Node_Field_1 (Asis_Element_Table.Table (Asis_Element_Table.Last), Encl_Type); Set_From_Implicit (Asis_Element_Table.Table (Asis_Element_Table.Last), True); Set_From_Inherited (Asis_Element_Table.Table (Asis_Element_Table.Last), True); Next_Literal_Node := Next_Entity (Next_Literal_Node); end loop; else Not_Implemented_Yet (Diagnosis => "Asis.Definitions.Implicit_Inherited_Declarations " & "(derived from Standard character type)"); end if; end Set_Inherited_Literals; ---------------------------------- -- Skip_Normalized_Declarations -- ---------------------------------- procedure Skip_Normalized_Declarations (Node : in out Node_Id) is Arg_Kind : constant Node_Kind := Nkind (Node); begin loop if Arg_Kind = N_Object_Declaration or else Arg_Kind = N_Number_Declaration or else Arg_Kind = N_Discriminant_Specification or else Arg_Kind = N_Component_Declaration or else Arg_Kind = N_Parameter_Specification or else Arg_Kind = N_Exception_Declaration or else Arg_Kind = N_Formal_Object_Declaration then if More_Ids (Node) then Node := Next (Node); while Nkind (Node) /= Arg_Kind loop -- some implicit subtype declarations may be inserted by -- the compiler in between the normalized declarations, so: Node := Next (Node); end loop; else return; end if; else -- Arg_Kind = N_With_Clause. -- Note that we should skip implicit clauses that can be added by -- front-end. if Comes_From_Source (Node) and then Last_Name (Node) then return; else Node := Next (Node); end if; end if; end loop; end Skip_Normalized_Declarations; ------------------------------- -- Subprogram_Attribute_Kind -- ------------------------------- function Subprogram_Attribute_Kind (Node : Node_Id) return Internal_Element_Kinds is Attribute_Chars : Name_Id; begin Attribute_Chars := Attribute_Name (Node); -- language-defined attributes which are functions: if Attribute_Chars = Name_Adjacent then return An_Adjacent_Attribute; elsif Attribute_Chars = Name_Ceiling then return A_Ceiling_Attribute; elsif Attribute_Chars = Name_Compose then return A_Compose_Attribute; elsif Attribute_Chars = Name_Copy_Sign then return A_Copy_Sign_Attribute; elsif Attribute_Chars = Name_Exponent then return An_Exponent_Attribute; elsif Attribute_Chars = Name_Floor then return A_Floor_Attribute; elsif Attribute_Chars = Name_Fraction then return A_Fraction_Attribute; elsif Attribute_Chars = Name_Image then return An_Image_Attribute; elsif Attribute_Chars = Name_Input then return An_Input_Attribute; elsif Attribute_Chars = Name_Leading_Part then return A_Leading_Part_Attribute; elsif Attribute_Chars = Name_Machine then return A_Machine_Attribute; elsif Attribute_Chars = Name_Max then return A_Max_Attribute; elsif Attribute_Chars = Name_Min then return A_Min_Attribute; elsif Attribute_Chars = Name_Model then return A_Model_Attribute; elsif Attribute_Chars = Name_Pos then return A_Pos_Attribute; elsif Attribute_Chars = Name_Pred then return A_Pred_Attribute; elsif Attribute_Chars = Name_Remainder then return A_Remainder_Attribute; elsif Attribute_Chars = Name_Round then return A_Round_Attribute; elsif Attribute_Chars = Name_Rounding then return A_Rounding_Attribute; elsif Attribute_Chars = Name_Scaling then return A_Scaling_Attribute; elsif Attribute_Chars = Name_Succ then return A_Succ_Attribute; elsif Attribute_Chars = Name_Truncation then return A_Truncation_Attribute; elsif Attribute_Chars = Name_Unbiased_Rounding then return An_Unbiased_Rounding_Attribute; elsif Attribute_Chars = Name_Val then return A_Val_Attribute; elsif Attribute_Chars = Name_Value then return A_Value_Attribute; elsif Attribute_Chars = Name_Wide_Image then return A_Wide_Image_Attribute; elsif Attribute_Chars = Name_Wide_Value then return A_Wide_Value_Attribute; -- |A2005 start -- Ada 2005 attributes that are functions: elsif Attribute_Chars = Name_Machine_Rounding then return A_Machine_Rounding_Attribute; elsif Attribute_Chars = Name_Mod then return A_Mod_Attribute; elsif Attribute_Chars = Name_Wide_Wide_Image then return A_Wide_Wide_Image_Attribute; elsif Attribute_Chars = Name_Wide_Wide_Value then return A_Wide_Wide_Value_Attribute; -- |A2005 end -- |A2012 start -- Ada 2012 attributes that are functions: -- elsif Attribute_Chars = Name_Overlaps_Storage then (SCz) -- return An_Overlaps_Storage_Attribute; -- |A2012 end -- language-defined attributes which are procedures: elsif Attribute_Chars = Name_Output then return An_Output_Attribute; elsif Attribute_Chars = Name_Read then return A_Read_Attribute; elsif Attribute_Chars = Name_Write then return A_Write_Attribute; -- Implementation Dependent Attributes-Functions -- elsif Attribute_Chars = Name_Asm_Input or else Attribute_Chars = Name_Asm_Output or else Attribute_Chars = Name_Enum_Rep or else Attribute_Chars = Name_Enum_Val or else Attribute_Chars = Name_Fixed_Value or else Attribute_Chars = Name_Integer_Value or else Attribute_Chars = Name_Ref then return An_Implementation_Defined_Attribute; else return An_Unknown_Attribute; end if; end Subprogram_Attribute_Kind; ----------------- -- Ureal_Image -- ----------------- function Ureal_Image (N : Node_Id) return String is Result : String (1 .. 256); Res_Len : Natural range 0 .. 256 := 0; -- bad solution!!! ASIS needs a general-purpose String buffer -- somewhere!!! ??? Real : constant Ureal := Realval (N); Nom : constant Uint := Norm_Num (Real); Den : constant Uint := Norm_Den (Real); Dot_Outputed : Boolean := False; begin if UR_Is_Negative (Real) then Res_Len := Res_Len + 1; Result (Res_Len) := '('; Res_Len := Res_Len + 1; Result (Res_Len) := '-'; end if; UI_Image (Nom, Decimal); for I in 1 .. UI_Image_Length loop if UI_Image_Buffer (I) = 'E' then Res_Len := Res_Len + 1; Result (Res_Len) := '.'; Res_Len := Res_Len + 1; Result (Res_Len) := '0'; Res_Len := Res_Len + 1; Result (Res_Len) := 'E'; Dot_Outputed := True; else Res_Len := Res_Len + 1; Result (Res_Len) := UI_Image_Buffer (I); end if; end loop; if not Dot_Outputed then Res_Len := Res_Len + 1; Result (Res_Len) := '.'; Res_Len := Res_Len + 1; Result (Res_Len) := '0'; end if; Dot_Outputed := False; Res_Len := Res_Len + 1; Result (Res_Len) := '/'; UI_Image (Den, Decimal); for I in 1 .. UI_Image_Length loop if UI_Image_Buffer (I) = 'E' then Res_Len := Res_Len + 1; Result (Res_Len) := '.'; Res_Len := Res_Len + 1; Result (Res_Len) := '0'; Res_Len := Res_Len + 1; Result (Res_Len) := 'E'; Dot_Outputed := True; else Res_Len := Res_Len + 1; Result (Res_Len) := UI_Image_Buffer (I); end if; end loop; if not Dot_Outputed then Res_Len := Res_Len + 1; Result (Res_Len) := '.'; Res_Len := Res_Len + 1; Result (Res_Len) := '0'; end if; if UR_Is_Negative (Real) then Res_Len := Res_Len + 1; Result (Res_Len) := ')'; end if; return Result (1 .. Res_Len); end Ureal_Image; end A4G.Mapping;
----------------------------------------------------------------------- -- gen-commands-database -- Database creation from application model -- Copyright (C) 2011, 2012 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with GNAT.Command_Line; with GNAT.Expect; with GNAT.OS_Lib; with Ada.Text_IO; with Ada.Strings.Fixed; with Ada.IO_Exceptions; with Ada.Directories; with Ada.Exceptions; with Util.Strings; with Util.Files; with Util.Log.Loggers; with ADO.Drivers.Connections; with ADO.Sessions.Factory; with ADO.Statements; with ADO.Queries; with ADO.Parameters; with System; with Gen.Database.Model; package body Gen.Commands.Database is use GNAT.Command_Line; use Util.Log; Log : constant Loggers.Logger := Loggers.Create ("Gen.Commands.Database"); -- Check if the database with the given name exists. function Has_Database (DB : in ADO.Sessions.Session'Class; Name : in String) return Boolean; -- Check if the database with the given name has some tables. function Has_Tables (DB : in ADO.Sessions.Session'Class; Name : in String) return Boolean; -- Expect filter to print the command output/error procedure Command_Output (Descriptor : in GNAT.Expect.Process_Descriptor'Class; Data : in String; Closure : in System.Address); -- Execute the external command <b>Name</b> with the arguments in <b>Args</b> -- and send the content of the file <b>Input</b> to that command. procedure Execute_Command (Name : in String; Args : in GNAT.OS_Lib.Argument_List; Input : in String); -- Create the MySQL tables in the database. The tables are created by launching -- the external command 'mysql' and using the create-xxx-mysql.sql generated scripts. procedure Create_Mysql_Tables (Name : in String; Model : in String; Config : in ADO.Drivers.Connections.Configuration; Generator : in out Gen.Generator.Handler); -- Create the database identified by the given name. procedure Create_Database (DB : in ADO.Sessions.Master_Session; Name : in String); -- Create the user and grant him access to the database. procedure Create_User_Grant (DB : in ADO.Sessions.Master_Session; Name : in String; User : in String; Password : in String); -- ------------------------------ -- Check if the database with the given name exists. -- ------------------------------ function Has_Database (DB : in ADO.Sessions.Session'Class; Name : in String) return Boolean is Query : ADO.Queries.Context; Stmt : ADO.Statements.Query_Statement; begin Query.Set_Query (Gen.Database.Model.Query_Database_List); Stmt := DB.Create_Statement (Query); Stmt.Execute; while Stmt.Has_Elements loop declare D : constant String := Stmt.Get_String (0); begin if Name = D then return True; end if; end; Stmt.Next; end loop; return False; end Has_Database; -- ------------------------------ -- Check if the database with the given name has some tables. -- ------------------------------ function Has_Tables (DB : in ADO.Sessions.Session'Class; Name : in String) return Boolean is Query : ADO.Queries.Context; Stmt : ADO.Statements.Query_Statement; begin Query.Set_Query (Gen.Database.Model.Query_Table_List); Stmt := DB.Create_Statement (Query); Stmt.Bind_Param ("name", ADO.Parameters.Token (Name)); Stmt.Execute; return Stmt.Has_Elements; end Has_Tables; -- ------------------------------ -- Create the database identified by the given name. -- ------------------------------ procedure Create_Database (DB : in ADO.Sessions.Master_Session; Name : in String) is use Ada.Strings.Unbounded; Query : ADO.Queries.Context; Stmt : ADO.Statements.Query_Statement; begin Log.Info ("Creating database '{0}'", Name); Query.Set_Query (Gen.Database.Model.Query_Create_Database); Stmt := DB.Create_Statement (Query); Stmt.Bind_Param ("name", ADO.Parameters.Token (Name)); Stmt.Execute; end Create_Database; -- ------------------------------ -- Create the user and grant him access to the database. -- ------------------------------ procedure Create_User_Grant (DB : in ADO.Sessions.Master_Session; Name : in String; User : in String; Password : in String) is use Ada.Strings.Unbounded; Query : ADO.Queries.Context; Stmt : ADO.Statements.Query_Statement; begin Log.Info ("Granting access for user '{0}' to database '{1}'", User, Name); if Password'Length > 0 then Query.Set_Query (Gen.Database.Model.Query_Create_User_With_Password); else Query.Set_Query (Gen.Database.Model.Query_Create_User_No_Password); end if; Stmt := DB.Create_Statement (Query); Stmt.Bind_Param ("name", ADO.Parameters.Token (Name)); Stmt.Bind_Param ("user", ADO.Parameters.Token (User)); if Password'Length > 0 then Stmt.Bind_Param ("password", Password); end if; Stmt.Execute; Query.Set_Query (Gen.Database.Model.Query_Flush_Privileges); Stmt := DB.Create_Statement (Query); Stmt.Execute; end Create_User_Grant; -- ------------------------------ -- Expect filter to print the command output/error -- ------------------------------ procedure Command_Output (Descriptor : in GNAT.Expect.Process_Descriptor'Class; Data : in String; Closure : in System.Address) is pragma Unreferenced (Descriptor, Closure); begin Log.Error ("{0}", Data); end Command_Output; -- ------------------------------ -- Execute the external command <b>Name</b> with the arguments in <b>Args</b> -- and send the content of the file <b>Input</b> to that command. -- ------------------------------ procedure Execute_Command (Name : in String; Args : in GNAT.OS_Lib.Argument_List; Input : in String) is Proc : GNAT.Expect.Process_Descriptor; Status : Integer; Func : constant GNAT.Expect.Filter_Function := Command_Output'Access; Result : GNAT.Expect.Expect_Match; Content : Ada.Strings.Unbounded.Unbounded_String; begin Util.Files.Read_File (Path => Input, Into => Content); GNAT.Expect.Non_Blocking_Spawn (Descriptor => Proc, Command => Name, Args => Args, Buffer_Size => 4096, Err_To_Out => True); GNAT.Expect.Add_Filter (Descriptor => Proc, Filter => Func, Filter_On => GNAT.Expect.Output); GNAT.Expect.Send (Descriptor => Proc, Str => Ada.Strings.Unbounded.To_String (Content), Add_LF => False, Empty_Buffer => False); GNAT.Expect.Expect (Proc, Result, ".*"); GNAT.Expect.Close (Descriptor => Proc, Status => Status); if Status = 0 then Log.Info ("Database schema created successfully."); else Log.Error ("Error while creating the database schema."); end if; exception when Ada.IO_Exceptions.Name_Error => Log.Error ("Cannot read {0}", Input); end Execute_Command; -- ------------------------------ -- Create the MySQL tables in the database. The tables are created by launching -- the external command 'mysql' and using the create-xxx-mysql.sql generated scripts. -- ------------------------------ procedure Create_Mysql_Tables (Name : in String; Model : in String; Config : in ADO.Drivers.Connections.Configuration; Generator : in out Gen.Generator.Handler) is Database : constant String := Config.Get_Database; Username : constant String := Config.Get_Property ("user"); Password : constant String := Config.Get_Property ("password"); Dir : constant String := Util.Files.Compose (Model, "mysql"); File : constant String := Util.Files.Compose (Dir, "create-" & Name & "-mysql.sql"); begin Log.Info ("Creating database tables using schema '{0}'", File); if not Ada.Directories.Exists (File) then Generator.Error ("SQL file '{0}' does not exist.", File); Generator.Error ("Please, run the following command: dynamo generate db"); return; end if; if Password'Length > 0 then declare Args : GNAT.OS_Lib.Argument_List (1 .. 3); begin Args (1) := new String '("--user=" & Username); Args (2) := new String '("--password=" & Password); Args (3) := new String '(Database); Execute_Command ("mysql", Args, File); end; else declare Args : GNAT.OS_Lib.Argument_List (1 .. 2); begin Args (1) := new String '("--user=" & Username); Args (2) := new String '(Database); Execute_Command ("mysql", Args, File); end; end if; end Create_Mysql_Tables; -- ------------------------------ -- Execute the command with the arguments. -- ------------------------------ procedure Execute (Cmd : in Command; Generator : in out Gen.Generator.Handler) is pragma Unreferenced (Cmd); use Ada.Strings.Unbounded; procedure Create_Database (Model : in String; Database : in String; Username : in String; Password : in String); -- ------------------------------ -- Create the database, the user and the tables. -- ------------------------------ procedure Create_Database (Model : in String; Database : in String; Username : in String; Password : in String) is Factory : ADO.Sessions.Factory.Session_Factory; Config : ADO.Drivers.Connections.Configuration; Root_Connection : Unbounded_String; Pos : Natural; begin Config.Set_Connection (Database); if Config.Get_Property ("user") = "" then Generator.Error ("Invalid database connection: missing user property"); return; end if; if Config.Get_Database = "" then Generator.Error ("Invalid database connection: no database name specified"); return; end if; -- Build a connection string to create the database. Pos := Util.Strings.Index (Database, ':'); Append (Root_Connection, Database (Database'First .. Pos)); Append (Root_Connection, "//"); Append (Root_Connection, Config.Get_Server); if Config.Get_Port > 0 then Append (Root_Connection, ':'); Append (Root_Connection, Util.Strings.Image (Config.Get_Port)); end if; Append (Root_Connection, "/?user="); Append (Root_Connection, Username); if Password'Length > 0 then Append (Root_Connection, "&password="); Append (Root_Connection, Password); end if; Log.Info ("Connecting to {0} for database setup", Root_Connection); -- Initialize the session factory to connect to the -- database defined by root connection (which should allow the database creation). Factory.Create (To_String (Root_Connection)); declare Name : constant String := Generator.Get_Project_Name; DB : constant ADO.Sessions.Master_Session := Factory.Get_Master_Session; begin -- Create the database only if it does not already exists. if not Has_Database (DB, Config.Get_Database) then Create_Database (DB, Config.Get_Database); end if; -- If some tables exist, don't try to create tables again. -- We could improve by reading the current database schema, comparing with our -- schema and create what is missing (new tables, new columns). if Has_Tables (DB, Config.Get_Database) then Generator.Error ("The database {0} exists", Config.Get_Database); else -- Create the user grant. On MySQL, it is safe to do this several times. Create_User_Grant (DB, Config.Get_Database, Config.Get_Property ("user"), Config.Get_Property ("password")); -- And now create the tables by using the SQL script generated by Dyanmo. Create_Mysql_Tables (Name, Model, Config, Generator); end if; -- Remember the database connection string. Generator.Set_Project_Property ("database", Database); Generator.Save_Project; exception when E : others => Generator.Error (Ada.Exceptions.Exception_Message (E)); end; end Create_Database; Model : constant String := Get_Argument; Arg1 : constant String := Get_Argument; Arg2 : constant String := Get_Argument; Arg3 : constant String := Get_Argument; begin Generator.Read_Project ("dynamo.xml"); -- Initialize the database drivers. ADO.Drivers.Initialize (Generator.Get_Properties); -- Check if a database is specified in the command line and use it. if Ada.Strings.Fixed.Index (Arg1, "://") > 0 or Arg3'Length > 0 then Create_Database (Model, Arg1, Arg2, Arg3); else declare Database : constant String := Generator.Get_Project_Property ("database"); begin -- Otherwise, get the database identification from dynamo.xml configuration. if Ada.Strings.Fixed.Index (Database, "://") = 0 then Generator.Error ("No database specified."); return; end if; Create_Database (Model, Database, Arg1, Arg2); end; end if; end Execute; -- ------------------------------ -- Write the help associated with the command. -- ------------------------------ procedure Help (Cmd : in Command; Generator : in out Gen.Generator.Handler) is pragma Unreferenced (Cmd, Generator); use Ada.Text_IO; begin Put_Line ("create-database: Creates the database"); Put_Line ("Usage: create-database MODEL [CONNECTION] ADMIN-USER [ADMIN-PASSWORD]"); New_Line; Put_Line (" Create the database specified by the connection string."); Put_Line (" The connection string has the form:"); Put_Line (" driver://host[:port]/database"); New_Line; Put_Line (" The database must not exist. The user specified in the connection string"); Put_Line (" is granted the access to the new database."); end Help; end Gen.Commands.Database;
package body Receiver is task body ReceiverTask is receivedMessagesCount: Natural := 0; begin loop accept ReceiveMessage do receivedMessagesCount := Natural'Succ(receivedMessagesCount); end ReceiveMessage; if k = receivedMessagesCount then exit; end if; end loop; accept Ended do null; end Ended; end ReceiverTask; end Receiver;
-- { dg-do compile } -- { dg-options "-O" } with Sizetype3_Pkg; use Sizetype3_Pkg; package body Sizetype3 is procedure Handle_Enum_Values is Values : constant List := F; L : Values_Array_Access; begin L := new Values_Array (1 .. Values'Length); end Handle_Enum_Values; procedure Simplify_Type_Of is begin Handle_Enum_Values; end Simplify_Type_Of; end Sizetype3;
generic type Base is abstract tagged limited private; package DDS.Request_Reply.Replier.Typed_Replier_Generic.Passive_Replier_Generic is package Listners is type Ref is limited interface; type Ref_Access is access all Ref'Class; procedure Compute_And_Reply (Self : not null access Ref; Replier : Typed_Replier_Generic.Ref_Access; Data : Request_DataReader.Treats.Data_Type; Id : DDS.SampleIdentity_T) is abstract; end Listners; type Ref (Listner : not null Listners.Ref_Access) is abstract new Base and Replyer_Listeners.Ref with null record; type Ref_Access is access all Ref'Class; procedure On_Request_Avalible (Self : not null access Ref; Replier : not null access Typed_Replier_Generic.Ref'Class); end DDS.Request_Reply.Replier.Typed_Replier_Generic.Passive_Replier_Generic;
-- Generated at 2017-03-29 14:57:31 +0000 by Natools.Static_Hash_Maps -- from src/natools-web-sites-maps.sx package Natools.Static_Maps.Web.Sites is pragma Pure; type Command is (Error, Set_ACL, Set_Backends, Set_Default_Template, Set_File_Prefix, Set_File_Suffix, Set_Filters, Set_Named_Element_File, Set_Named_Elements, Set_Path_Prefix, Set_Path_Suffix, Set_Printer, Set_Static_Paths, Set_Template_File, Set_Templates); function To_Command (Key : String) return Command; private Map_1_Key_0 : aliased constant String := "acl"; Map_1_Key_1 : aliased constant String := "users"; Map_1_Key_2 : aliased constant String := "backends"; Map_1_Key_3 : aliased constant String := "back-ends"; Map_1_Key_4 : aliased constant String := "default-template"; Map_1_Key_5 : aliased constant String := "file-prefix"; Map_1_Key_6 : aliased constant String := "file-suffix"; Map_1_Key_7 : aliased constant String := "filters"; Map_1_Key_8 : aliased constant String := "named-element-file"; Map_1_Key_9 : aliased constant String := "named-elements"; Map_1_Key_10 : aliased constant String := "path-prefix"; Map_1_Key_11 : aliased constant String := "path-suffix"; Map_1_Key_12 : aliased constant String := "printer"; Map_1_Key_13 : aliased constant String := "printer-parameters"; Map_1_Key_14 : aliased constant String := "static"; Map_1_Key_15 : aliased constant String := "static-path"; Map_1_Key_16 : aliased constant String := "static-paths"; Map_1_Key_17 : aliased constant String := "template-file"; Map_1_Key_18 : aliased constant String := "templates"; Map_1_Keys : constant array (0 .. 18) of access constant String := (Map_1_Key_0'Access, Map_1_Key_1'Access, Map_1_Key_2'Access, Map_1_Key_3'Access, Map_1_Key_4'Access, Map_1_Key_5'Access, Map_1_Key_6'Access, Map_1_Key_7'Access, Map_1_Key_8'Access, Map_1_Key_9'Access, Map_1_Key_10'Access, Map_1_Key_11'Access, Map_1_Key_12'Access, Map_1_Key_13'Access, Map_1_Key_14'Access, Map_1_Key_15'Access, Map_1_Key_16'Access, Map_1_Key_17'Access, Map_1_Key_18'Access); Map_1_Elements : constant array (0 .. 18) of Command := (Set_ACL, Set_ACL, Set_Backends, Set_Backends, Set_Default_Template, Set_File_Prefix, Set_File_Suffix, Set_Filters, Set_Named_Element_File, Set_Named_Elements, Set_Path_Prefix, Set_Path_Suffix, Set_Printer, Set_Printer, Set_Static_Paths, Set_Static_Paths, Set_Static_Paths, Set_Template_File, Set_Templates); end Natools.Static_Maps.Web.Sites;
pragma Ada_2012; pragma Style_Checks (Off); with Interfaces.C; use Interfaces.C; package xcb_util is end xcb_util;
package Loop_Optimization3_Pkg is function F (n : Integer) return Integer; end Loop_Optimization3_Pkg;
package body Ada.Strings.Naked_Maps.Debug is -- implementation of sets function Valid (Set : Character_Set_Data) return Boolean is begin for I in Set.Items'First .. Set.Items'Last loop if Set.Items (I).High < Set.Items (I).Low then return False; end if; end loop; for I in Set.Items'First .. Set.Items'Last - 1 loop if Set.Items (I).High >= Wide_Wide_Character'Pred (Set.Items (I + 1).Low) then return False; end if; end loop; return True; end Valid; -- implementation of maps function Valid (Map : Character_Mapping_Data) return Boolean is begin for I in Map.From'First .. Map.From'Last - 1 loop if Map.From (I) >= Map.From (I + 1) then return False; end if; end loop; return True; end Valid; end Ada.Strings.Naked_Maps.Debug;
----------------------------------------------------------------------- -- components-core -- ASF Core Components -- Copyright (C) 2009, 2010, 2011, 2012, 2018 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Unchecked_Deallocation; package body ASF.Components.Core is use EL.Objects; -- ------------------------------ -- Return a client-side identifier for this component, generating -- one if necessary. -- ------------------------------ function Get_Client_Id (UI : UIComponentBase) return Unbounded_String is Id : constant access ASF.Views.Nodes.Tag_Attribute := UI.Get_Attribute ("id"); begin if Id /= null then return To_Unbounded_String (Views.Nodes.Get_Value (Id.all, UI.Get_Context.all)); end if; -- return UI.Id; return Base.UIComponent (UI).Get_Client_Id; end Get_Client_Id; -- ------------------------------ -- Renders the UIText evaluating the EL expressions it may contain. -- ------------------------------ procedure Encode_Begin (UI : in UIText; Context : in out Faces_Context'Class) is begin UI.Text.Encode_All (UI.Expr_Table, Context); end Encode_Begin; -- ------------------------------ -- Set the expression array that contains reduced expressions. -- ------------------------------ procedure Set_Expression_Table (UI : in out UIText; Expr_Table : in Views.Nodes.Expression_Access_Array_Access) is use type ASF.Views.Nodes.Expression_Access_Array_Access; begin if UI.Expr_Table /= null then UI.Log_Error ("Expression table already initialized"); raise Program_Error with "Expression table already initialized"; end if; UI.Expr_Table := Expr_Table; end Set_Expression_Table; -- ------------------------------ -- Finalize the object. -- ------------------------------ overriding procedure Finalize (UI : in out UIText) is use type ASF.Views.Nodes.Expression_Access_Array_Access; procedure Free is new Ada.Unchecked_Deallocation (EL.Expressions.Expression'Class, EL.Expressions.Expression_Access); procedure Free is new Ada.Unchecked_Deallocation (ASF.Views.Nodes.Expression_Access_Array, ASF.Views.Nodes.Expression_Access_Array_Access); begin if UI.Expr_Table /= null then for I in UI.Expr_Table'Range loop Free (UI.Expr_Table (I)); end loop; Free (UI.Expr_Table); end if; Base.UIComponent (UI).Finalize; end Finalize; function Create_UIText (Tag : ASF.Views.Nodes.Text_Tag_Node_Access) return UIText_Access is Result : constant UIText_Access := new UIText; begin Result.Text := Tag; return Result; end Create_UIText; -- ------------------------------ -- Get the parameter name -- ------------------------------ function Get_Name (UI : UIParameter; Context : Faces_Context'Class) return String is Name : constant EL.Objects.Object := UI.Get_Attribute (Name => "name", Context => Context); begin return EL.Objects.To_String (Name); end Get_Name; -- ------------------------------ -- Get the parameter value -- ------------------------------ function Get_Value (UI : UIParameter; Context : Faces_Context'Class) return EL.Objects.Object is begin return UI.Get_Attribute (Name => "value", Context => Context); end Get_Value; -- ------------------------------ -- Get the list of parameters associated with a component. -- ------------------------------ function Get_Parameters (UI : Base.UIComponent'Class) return UIParameter_Access_Array is Result : UIParameter_Access_Array (1 .. UI.Get_Children_Count); Last : Natural := 0; procedure Collect (Child : in Base.UIComponent_Access); pragma Inline (Collect); procedure Collect (Child : in Base.UIComponent_Access) is begin if Child.all in UIParameter'Class then Last := Last + 1; Result (Last) := UIParameter (Child.all)'Access; end if; end Collect; procedure Iter is new ASF.Components.Base.Iterate (Process => Collect); pragma Inline (Iter); begin Iter (UI); return Result (1 .. Last); end Get_Parameters; end ASF.Components.Core;
-- -- Tiny_Text demo board setup -- -- This is a STM32-H405 dev board with a PCD8544 LCD. -- with STM32.GPIO; use STM32.GPIO; with STM32.Device; use STM32.Device; with PCD8544; use PCD8544; with Ravenscar_Time; package Board is LCD_CLK : GPIO_Point renames PB13; -- EXT2_16 LCD_DIN : GPIO_Point renames PB15; -- EXT2_19 LCD_RST : GPIO_Point renames PC3; -- EXT2_9 LCD_CS : GPIO_Point renames PB12; -- EXT2_17 LCD_DC : GPIO_Point renames PC2; -- EXT2_2 Display : PCD8544_Device (Port => SPI_2'Access, RST => LCD_RST'Access, CS => LCD_CS'Access, DC => LCD_DC'Access, Time => Ravenscar_Time.Delays); procedure Initialize; end Board;
-- { dg-do compile } -- { dg-options "-O" } with Modular4_Pkg; use Modular4_Pkg; procedure Modular4 is begin for I in Zero .. F mod 8 loop raise Program_Error; end loop; end;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- G N A T M E M -- -- -- -- B o d y -- -- -- -- $Revision$ -- -- -- Copyright (C) 1997-2001, Ada Core Technologies, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- GNATMEM is a utility that tracks memory leaks. It is based on a simple -- idea: -- - run the application under gdb -- - set a breakpoint on __gnat_malloc and __gnat_free -- - record a reference to the allocated memory on each allocation call -- - suppress this reference on deallocation -- - at the end of the program, remaining references are potential leaks. -- sort them out the best possible way in order to locate the root of -- the leak. -- -- GNATMEM can also be used with instrumented allocation/deallocation -- routine (see a-raise.c with symbol GMEM defined). This is not supported -- in all platforms, again refer to a-raise.c for further information. -- In this case the application must be relinked with library libgmem.a: -- -- $ gnatmake my_prog -largs -lgmem -- -- The running my_prog will produce a file named gmem.out that will be -- parsed by gnatmem. -- -- In order to help finding out the real leaks, the notion of "allocation -- root" is defined. An allocation root is a specific point in the program -- execution generating memory allocation where data is collected (such as -- number of allocations, quantify of memory allocated, high water mark, -- etc.). with Ada.Command_Line; use Ada.Command_Line; with Ada.Text_IO; use Ada.Text_IO; with Ada.Text_IO.C_Streams; with Ada.Float_Text_IO; with Ada.Integer_Text_IO; with Gnatvsn; use Gnatvsn; with GNAT.Heap_Sort_G; with GNAT.OS_Lib; with GNAT.HTable; use GNAT.HTable; with Interfaces.C_Streams; use Interfaces.C_Streams; with System; use System; with System.Storage_Elements; use System.Storage_Elements; with Memroot; use Memroot; procedure Gnatmem is ------------------------------------------------ -- Potentially Target Dependent Subprograms. -- ------------------------------------------------ function Get_Current_TTY return String; -- Give the current tty on which the program is run. This is needed to -- separate the output of the debugger from the output of the program. -- The output of this function will be used to call the gdb command "tty" -- in the gdb script in order to get the program output on the current tty -- while the gdb output is redirected and processed by gnatmem. function popen (File, Mode : System.Address) return FILEs; pragma Import (C, popen, "popen"); -- Execute the program 'File'. If the mode is "r" the standard output -- of the program is redirected and the FILEs handler of the -- redirection is returned. procedure System_Cmd (X : System.Address); pragma Import (C, System_Cmd, "system"); -- Execute the program "X". subtype Cstring is String (1 .. Integer'Last); type Cstring_Ptr is access all Cstring; function ttyname (Dec : Integer) return Cstring_Ptr; pragma Import (C, ttyname, "__gnat_ttyname"); -- Return a null-terminated string containing the current tty Dir_Sep : constant Character := '/'; ------------------------ -- Other Declarations -- ------------------------ type Gdb_Output_Elmt is (Eof, Alloc, Deall); -- Eof = End of gdb output file -- Alloc = found a ALLOC mark in the gdb output -- Deall = found a DEALL mark in the gdb output Gdb_Output_Format_Error : exception; function Read_Next return Gdb_Output_Elmt; -- Read the output of the debugger till it finds either the end of the -- output, or the 'ALLOC' mark or the 'DEALL' mark. In the second case, -- it sets the Tmp_Size and Tmp_Address global variables, in the -- third case it sets the Tmp_Address variable. procedure Create_Gdb_Script; -- Create the GDB script and save it in a temporary file function Mem_Image (X : Storage_Count) return String; -- X is a size in storage_element. Returns a value -- in Megabytes, Kiloytes or Bytes as appropriate. procedure Process_Arguments; -- Read command line arguments; procedure Usage; -- Prints out the option help function Gmem_Initialize (Dumpname : String) return Boolean; -- Opens the file represented by Dumpname and prepares it for -- work. Returns False if the file does not have the correct format, True -- otherwise. procedure Gmem_A2l_Initialize (Exename : String); -- Initialises the convert_addresses interface by supplying it with -- the name of the executable file Exename procedure Gmem_Read_Next (Buf : out String; Last : out Natural); -- Reads the next allocation/deallocation entry and its backtrace -- and prepares in the string Buf (up to the position of Last) the -- expression compatible with gnatmem parser: -- Allocation entry produces the expression "ALLOC^[size]^0x[address]^" -- Deallocation entry produces the expression "DEALLOC^0x[address]^" Argc : constant Integer := Argument_Count; Gnatmem_Tmp : aliased constant String := "gnatmem.tmp"; Mode_R : aliased constant String (1 .. 2) := 'r' & ASCII.NUL; Mode_W : aliased constant String (1 .. 3) := "w+" & ASCII.NUL; ----------------------------------- -- HTable address --> Allocation -- ----------------------------------- type Allocation is record Root : Root_Id; Size : Storage_Count; end record; type Address_Range is range 0 .. 4097; function H (A : Integer_Address) return Address_Range; No_Alloc : constant Allocation := (No_Root_Id, 0); package Address_HTable is new GNAT.HTable.Simple_HTable ( Header_Num => Address_Range, Element => Allocation, No_Element => No_Alloc, Key => Integer_Address, Hash => H, Equal => "="); BT_Depth : Integer := 1; FD : FILEs; FT : File_Type; File_Pos : Integer := 0; Exec_Pos : Integer := 0; Target_Pos : Integer := 0; Run_Gdb : Boolean := True; Global_Alloc_Size : Storage_Count := 0; Global_High_Water_Mark : Storage_Count := 0; Global_Nb_Alloc : Integer := 0; Global_Nb_Dealloc : Integer := 0; Nb_Root : Integer := 0; Nb_Wrong_Deall : Integer := 0; Target_Name : String (1 .. 80); Target_Protocol : String (1 .. 80); Target_Name_Len : Integer; Target_Protocol_Len : Integer; Cross_Case : Boolean := False; Tmp_Size : Storage_Count := 0; Tmp_Address : Integer_Address; Tmp_Alloc : Allocation; Quiet_Mode : Boolean := False; -------------------------------- -- GMEM functionality binding -- -------------------------------- function Gmem_Initialize (Dumpname : String) return Boolean is function Initialize (Dumpname : System.Address) return Boolean; pragma Import (C, Initialize, "__gnat_gmem_initialize"); S : aliased String := Dumpname & ASCII.NUL; begin return Initialize (S'Address); end Gmem_Initialize; procedure Gmem_A2l_Initialize (Exename : String) is procedure A2l_Initialize (Exename : System.Address); pragma Import (C, A2l_Initialize, "__gnat_gmem_a2l_initialize"); S : aliased String := Exename & ASCII.NUL; begin A2l_Initialize (S'Address); end Gmem_A2l_Initialize; procedure Gmem_Read_Next (Buf : out String; Last : out Natural) is procedure Read_Next (buf : System.Address); pragma Import (C, Read_Next, "__gnat_gmem_read_next"); function Strlen (str : System.Address) return Natural; pragma Import (C, Strlen, "strlen"); S : String (1 .. 1000); begin Read_Next (S'Address); Last := Strlen (S'Address); Buf (1 .. Last) := S (1 .. Last); end Gmem_Read_Next; --------------------- -- Get_Current_TTY -- --------------------- function Get_Current_TTY return String is Res : Cstring_Ptr; stdout : constant Integer := 1; Max_TTY_Name : constant Integer := 500; begin if isatty (stdout) /= 1 then return ""; end if; Res := ttyname (1); if Res /= null then for J in Cstring'First .. Max_TTY_Name loop if Res (J) = ASCII.NUL then return Res (Cstring'First .. J - 1); end if; end loop; end if; -- if we fall thru the ttyname result was dubious. Just forget it. return ""; end Get_Current_TTY; ------- -- H -- ------- function H (A : Integer_Address) return Address_Range is begin return Address_Range (A mod Integer_Address (Address_Range'Last)); end H; ----------------------- -- Create_Gdb_Script -- ----------------------- procedure Create_Gdb_Script is FD : File_Type; begin begin Create (FD, Out_File, Gnatmem_Tmp); exception when others => Put_Line ("Cannot create temporary file : " & Gnatmem_Tmp); GNAT.OS_Lib.OS_Exit (1); end; declare TTY : constant String := Get_Current_TTY; begin if TTY'Length > 0 then Put_Line (FD, "tty " & TTY); end if; end; if Cross_Case then Put (FD, "target "); Put (FD, Target_Protocol (1 .. Target_Protocol_Len)); Put (FD, " "); Put (FD, Argument (Target_Pos)); New_Line (FD); Put (FD, "load "); Put_Line (FD, Argument (Exec_Pos)); else -- In the native case, run the program before setting the -- breakpoints so that gnatmem will also work with shared -- libraries. Put_Line (FD, "set lang c"); Put_Line (FD, "break main"); Put_Line (FD, "set lang auto"); Put (FD, "run"); for J in Exec_Pos + 1 .. Argc loop Put (FD, " "); Put (FD, Argument (J)); end loop; New_Line (FD); -- At this point, gdb knows about __gnat_malloc and __gnat_free end if; -- Make sure that outputing long backtraces do not pause Put_Line (FD, "set height 0"); Put_Line (FD, "set width 0"); if Quiet_Mode then Put_Line (FD, "break __gnat_malloc"); Put_Line (FD, "command"); Put_Line (FD, " silent"); Put_Line (FD, " set lang c"); Put_Line (FD, " set print address on"); Put_Line (FD, " finish"); Put_Line (FD, " set $gm_addr = $"); Put_Line (FD, " printf ""\n\n"""); Put_Line (FD, " printf ""ALLOC^0x%x^\n"", $gm_addr"); Put_Line (FD, " set print address off"); Put_Line (FD, " set lang auto"); else Put_Line (FD, "break __gnat_malloc"); Put_Line (FD, "command"); Put_Line (FD, " silent"); Put_Line (FD, " set lang c"); Put_Line (FD, " set $gm_size = size"); Put_Line (FD, " set print address on"); Put_Line (FD, " finish"); Put_Line (FD, " set $gm_addr = $"); Put_Line (FD, " printf ""\n\n"""); Put_Line (FD, " printf ""ALLOC^%d^0x%x^\n"", $gm_size, $gm_addr"); Put_Line (FD, " set print address off"); Put_Line (FD, " set lang auto"); end if; Put (FD, " backtrace"); if BT_Depth /= 0 then Put (FD, Integer'Image (BT_Depth)); end if; New_Line (FD); Put_Line (FD, " printf ""\n\n"""); Put_Line (FD, " continue"); Put_Line (FD, "end"); Put_Line (FD, "#"); Put_Line (FD, "#"); Put_Line (FD, "break __gnat_free"); Put_Line (FD, "command"); Put_Line (FD, " silent"); Put_Line (FD, " set print address on"); Put_Line (FD, " printf ""\n\n"""); Put_Line (FD, " printf ""DEALL^0x%x^\n"", ptr"); Put_Line (FD, " set print address off"); Put_Line (FD, " finish"); Put (FD, " backtrace"); if BT_Depth /= 0 then Put (FD, Integer'Image (BT_Depth)); end if; New_Line (FD); Put_Line (FD, " printf ""\n\n"""); Put_Line (FD, " continue"); Put_Line (FD, "end"); Put_Line (FD, "#"); Put_Line (FD, "#"); Put_Line (FD, "#"); if Cross_Case then Put (FD, "run "); Put_Line (FD, Argument (Exec_Pos)); if Target_Protocol (1 .. Target_Protocol_Len) = "wtx" then Put (FD, "unload "); Put_Line (FD, Argument (Exec_Pos)); end if; else Put_Line (FD, "continue"); end if; Close (FD); end Create_Gdb_Script; --------------- -- Mem_Image -- --------------- function Mem_Image (X : Storage_Count) return String is Ks : constant Storage_Count := X / 1024; Megs : constant Storage_Count := Ks / 1024; Buff : String (1 .. 7); begin if Megs /= 0 then Ada.Float_Text_IO.Put (Buff, Float (X) / 1024.0 / 1024.0, 2, 0); return Buff & " Megabytes"; elsif Ks /= 0 then Ada.Float_Text_IO.Put (Buff, Float (X) / 1024.0, 2, 0); return Buff & " Kilobytes"; else Ada.Integer_Text_IO.Put (Buff (1 .. 4), Integer (X)); return Buff (1 .. 4) & " Bytes"; end if; end Mem_Image; ----------- -- Usage -- ----------- procedure Usage is begin New_Line; Put ("GNATMEM "); Put (Gnat_Version_String); Put_Line (" Copyright 1997-2000 Free Software Foundation, Inc."); New_Line; if Cross_Case then Put_Line (Command_Name & " [-q] [n] [-o file] target entry_point ..."); Put_Line (Command_Name & " [-q] [n] [-i file]"); else Put_Line ("GDB mode"); Put_Line (" " & Command_Name & " [-q] [n] [-o file] program arg1 arg2 ..."); Put_Line (" " & Command_Name & " [-q] [n] [-i file]"); New_Line; Put_Line ("GMEM mode"); Put_Line (" " & Command_Name & " [-q] [n] -i gmem.out program arg1 arg2 ..."); New_Line; end if; Put_Line (" -q quiet, minimum output"); Put_Line (" n number of frames for allocation root backtraces"); Put_Line (" default is 1."); Put_Line (" -o file save gdb output in 'file' and process data"); Put_Line (" post mortem. also keep the gdb script around"); Put_Line (" -i file don't run gdb output. Do only post mortem"); Put_Line (" processing from file"); GNAT.OS_Lib.OS_Exit (1); end Usage; ----------------------- -- Process_Arguments -- ----------------------- procedure Process_Arguments is Arg : Integer; procedure Check_File (Arg_Pos : Integer; For_Creat : Boolean := False); -- Check that Argument (Arg_Pos) is an existing file if For_Creat is -- false or if it is possible to create it if For_Creat is true procedure Check_File (Arg_Pos : Integer; For_Creat : Boolean := False) is Name : aliased constant String := Argument (Arg_Pos) & ASCII.NUL; X : int; begin if For_Creat then FD := fopen (Name'Address, Mode_W'Address); else FD := fopen (Name'Address, Mode_R'Address); end if; if FD = NULL_Stream then New_Line; if For_Creat then Put_Line ("Cannot create file : " & Argument (Arg_Pos)); else Put_Line ("Cannot locate file : " & Argument (Arg_Pos)); end if; New_Line; Usage; else X := fclose (FD); end if; end Check_File; -- Start of processing for Process_Arguments begin -- Is it a cross version? declare Std_Name : constant String := "gnatmem"; Name : constant String := Command_Name; End_Pref : constant Integer := Name'Last - Std_Name'Length; begin if Name'Length > Std_Name'Length + 9 and then Name (End_Pref + 1 .. Name'Last) = Std_Name and then Name (End_Pref - 8 .. End_Pref) = "-vxworks-" then Cross_Case := True; Target_Name_Len := End_Pref - 1; for J in reverse Name'First .. End_Pref - 1 loop if Name (J) = Dir_Sep then Target_Name_Len := Target_Name_Len - J; exit; end if; end loop; Target_Name (1 .. Target_Name_Len) := Name (End_Pref - Target_Name_Len .. End_Pref - 1); if Target_Name (1 .. 5) = "alpha" then Target_Protocol (1 .. 7) := "vxworks"; Target_Protocol_Len := 7; else Target_Protocol (1 .. 3) := "wtx"; Target_Protocol_Len := 3; end if; end if; end; Arg := 1; if Argc < Arg then Usage; end if; -- Deal with "-q" if Argument (Arg) = "-q" then Quiet_Mode := True; Arg := Arg + 1; if Argc < Arg then Usage; end if; end if; -- Deal with back trace depth if Argument (Arg) (1) in '0' .. '9' then begin BT_Depth := Integer'Value (Argument (Arg)); exception when others => Usage; end; Arg := Arg + 1; if Argc < Arg then Usage; end if; end if; -- Deal with "-o file" or "-i file" while Arg <= Argc and then Argument (Arg) (1) = '-' loop Arg := Arg + 1; if Argc < Arg then Usage; end if; case Argument (Arg - 1) (2) is when 'o' => Check_File (Arg, For_Creat => True); File_Pos := Arg; when 'i' => Check_File (Arg); File_Pos := Arg; Run_Gdb := False; if Gmem_Initialize (Argument (Arg)) then Gmem_Mode := True; end if; when others => Put_Line ("Unknown option : " & Argument (Arg)); Usage; end case; Arg := Arg + 1; if Argc < Arg and then Run_Gdb then Usage; end if; end loop; -- In the cross case, we first get the target if Cross_Case then Target_Pos := Arg; Arg := Arg + 1; if Argc < Arg and then Run_Gdb then Usage; end if; end if; -- Now all the following arguments are to be passed to gdb if Run_Gdb then Exec_Pos := Arg; Check_File (Exec_Pos); elsif Gmem_Mode then if Arg > Argc then Usage; else Exec_Pos := Arg; Check_File (Exec_Pos); Gmem_A2l_Initialize (Argument (Exec_Pos)); end if; -- ... in other cases further arguments are disallowed elsif Arg <= Argc then Usage; end if; end Process_Arguments; --------------- -- Read_Next -- --------------- function Read_Next return Gdb_Output_Elmt is Max_Line : constant Integer := 100; Line : String (1 .. Max_Line); Last : Integer := 0; Curs1, Curs2 : Integer; Separator : constant Character := '^'; function Next_Separator return Integer; -- Return the index of the next separator after Curs1 in Line function Next_Separator return Integer is Curs : Integer := Curs1; begin loop if Curs > Last then raise Gdb_Output_Format_Error; elsif Line (Curs) = Separator then return Curs; end if; Curs := Curs + 1; end loop; end Next_Separator; -- Start of processing for Read_Next begin Line (1) := ' '; loop if Gmem_Mode then Gmem_Read_Next (Line, Last); else Get_Line (FT, Line, Last); end if; if Line (1 .. 14) = "Program exited" then return Eof; elsif Line (1 .. 5) = "ALLOC" then -- ALLOC ^ <size> ^0x <addr> ^ -- Read the size Curs1 := 7; Curs2 := Next_Separator - 1; if not Quiet_Mode then Tmp_Size := Storage_Count'Value (Line (Curs1 .. Curs2)); end if; -- Read the address, skip "^0x" Curs1 := Curs2 + 4; Curs2 := Next_Separator - 1; Tmp_Address := Integer_Address'Value ( "16#" & Line (Curs1 .. Curs2) & "#"); return Alloc; elsif Line (1 .. 5) = "DEALL" then -- DEALL ^ 0x <addr> ^ -- Read the address, skip "^0x" Curs1 := 9; Curs2 := Next_Separator - 1; Tmp_Address := Integer_Address'Value ( "16#" & Line (Curs1 .. Curs2) & "#"); return Deall; end if; end loop; exception when End_Error => New_Line; Put_Line ("### incorrect user program termination detected."); Put_Line (" following data may not be meaningful"); New_Line; return Eof; end Read_Next; -- Start of processing for Gnatmem begin Process_Arguments; if Run_Gdb then Create_Gdb_Script; end if; -- Now we start the gdb session using the following syntax -- gdb --nx --nw -batch -x gnatmem.tmp -- If there is a -o option we redirect the gdb output in the specified -- file, otherwise we just read directly from a pipe. if File_Pos /= 0 then declare Name : aliased String := Argument (File_Pos) & ASCII.NUL; begin if Run_Gdb then if Cross_Case then declare Cmd : aliased String := Target_Name (1 .. Target_Name_Len) & "-gdb --nx --nw -batch -x " & Gnatmem_Tmp & " > " & Name; begin System_Cmd (Cmd'Address); end; else declare Cmd : aliased String := "gdb --nx --nw " & Argument (Exec_Pos) & " -batch -x " & Gnatmem_Tmp & " > " & Name; begin System_Cmd (Cmd'Address); end; end if; end if; if not Gmem_Mode then FD := fopen (Name'Address, Mode_R'Address); end if; end; else if Cross_Case then declare Cmd : aliased String := Target_Name (1 .. Target_Name_Len) & "-gdb --nx --nw -batch -x " & Gnatmem_Tmp & ASCII.NUL; begin FD := popen (Cmd'Address, Mode_R'Address); end; else declare Cmd : aliased String := "gdb --nx --nw " & Argument (Exec_Pos) & " -batch -x " & Gnatmem_Tmp & ASCII.NUL; begin FD := popen (Cmd'Address, Mode_R'Address); end; end if; end if; -- Open the FD file as a regular Text_IO file if not Gmem_Mode then Ada.Text_IO.C_Streams.Open (FT, In_File, FD); end if; -- Main loop analysing the data generated by the debugger -- for each allocation, the backtrace is kept and stored in a htable -- whose entry is the address. Fore ach deallocation, we look for the -- corresponding allocation and cancel it. Main : loop case Read_Next is when EOF => exit Main; when Alloc => -- Update global counters if the allocated size is meaningful if Quiet_Mode then Tmp_Alloc.Root := Read_BT (BT_Depth, FT); if Nb_Alloc (Tmp_Alloc.Root) = 0 then Nb_Root := Nb_Root + 1; end if; Set_Nb_Alloc (Tmp_Alloc.Root, Nb_Alloc (Tmp_Alloc.Root) + 1); Address_HTable.Set (Tmp_Address, Tmp_Alloc); elsif Tmp_Size > 0 then Global_Alloc_Size := Global_Alloc_Size + Tmp_Size; Global_Nb_Alloc := Global_Nb_Alloc + 1; if Global_High_Water_Mark < Global_Alloc_Size then Global_High_Water_Mark := Global_Alloc_Size; end if; -- Read the corresponding back trace Tmp_Alloc.Root := Read_BT (BT_Depth, FT); -- Update the number of allocation root if this is a new one if Nb_Alloc (Tmp_Alloc.Root) = 0 then Nb_Root := Nb_Root + 1; end if; -- Update allocation root specific counters Set_Alloc_Size (Tmp_Alloc.Root, Alloc_Size (Tmp_Alloc.Root) + Tmp_Size); Set_Nb_Alloc (Tmp_Alloc.Root, Nb_Alloc (Tmp_Alloc.Root) + 1); if High_Water_Mark (Tmp_Alloc.Root) < Alloc_Size (Tmp_Alloc.Root) then Set_High_Water_Mark (Tmp_Alloc.Root, Alloc_Size (Tmp_Alloc.Root)); end if; -- Associate this allocation root to the allocated address Tmp_Alloc.Size := Tmp_Size; Address_HTable.Set (Tmp_Address, Tmp_Alloc); -- non meaninful output, just consumes the backtrace else Tmp_Alloc.Root := Read_BT (BT_Depth, FT); end if; when Deall => -- Get the corresponding Dealloc_Size and Root Tmp_Alloc := Address_HTable.Get (Tmp_Address); if Tmp_Alloc.Root = No_Root_Id then -- There was no prior allocation at this address, something is -- very wrong. Mark this allocation root as problematic a Tmp_Alloc.Root := Read_BT (BT_Depth, FT); if Nb_Alloc (Tmp_Alloc.Root) = 0 then Set_Nb_Alloc (Tmp_Alloc.Root, Nb_Alloc (Tmp_Alloc.Root) - 1); Nb_Wrong_Deall := Nb_Wrong_Deall + 1; end if; else -- Update global counters if not Quiet_Mode then Global_Alloc_Size := Global_Alloc_Size - Tmp_Alloc.Size; end if; Global_Nb_Dealloc := Global_Nb_Dealloc + 1; -- Update allocation root specific counters if not Quiet_Mode then Set_Alloc_Size (Tmp_Alloc.Root, Alloc_Size (Tmp_Alloc.Root) - Tmp_Alloc.Size); end if; Set_Nb_Alloc (Tmp_Alloc.Root, Nb_Alloc (Tmp_Alloc.Root) - 1); -- update the number of allocation root if this one disappear if Nb_Alloc (Tmp_Alloc.Root) = 0 then Nb_Root := Nb_Root - 1; end if; -- De-associate the deallocated address Address_HTable.Remove (Tmp_Address); end if; end case; end loop Main; -- We can get rid of the temp file now if Run_Gdb and then File_Pos = 0 then declare X : int; begin X := unlink (Gnatmem_Tmp'Address); end; end if; -- Print out general information about overall allocation if not Quiet_Mode then Put_Line ("Global information"); Put_Line ("------------------"); Put (" Total number of allocations :"); Ada.Integer_Text_IO.Put (Global_Nb_Alloc, 4); New_Line; Put (" Total number of deallocations :"); Ada.Integer_Text_IO.Put (Global_Nb_Dealloc, 4); New_Line; Put_Line (" Final Water Mark (non freed mem) :" & Mem_Image (Global_Alloc_Size)); Put_Line (" High Water Mark :" & Mem_Image (Global_High_Water_Mark)); New_Line; end if; -- Print out the back traces corresponding to potential leaks in order -- greatest number of non-deallocated allocations Print_Back_Traces : declare type Root_Array is array (Natural range <>) of Root_Id; Leaks : Root_Array (0 .. Nb_Root); Leak_Index : Natural := 0; Bogus_Dealls : Root_Array (1 .. Nb_Wrong_Deall); Deall_Index : Natural := 0; procedure Move (From : Natural; To : Natural); function Lt (Op1, Op2 : Natural) return Boolean; package Root_Sort is new GNAT.Heap_Sort_G (Move, Lt); procedure Move (From : Natural; To : Natural) is begin Leaks (To) := Leaks (From); end Move; function Lt (Op1, Op2 : Natural) return Boolean is begin if Nb_Alloc (Leaks (Op1)) > Nb_Alloc (Leaks (Op2)) then return True; elsif Nb_Alloc (Leaks (Op1)) = Nb_Alloc (Leaks (Op2)) then return Alloc_Size (Leaks (Op1)) > Alloc_Size (Leaks (Op2)); else return False; end if; end Lt; -- Start of processing for Print_Back_Traces begin -- Transfer all the relevant Roots in the Leaks and a -- Bogus_Deall arrays Tmp_Alloc.Root := Get_First; while Tmp_Alloc.Root /= No_Root_Id loop if Nb_Alloc (Tmp_Alloc.Root) = 0 then null; elsif Nb_Alloc (Tmp_Alloc.Root) < 0 then Deall_Index := Deall_Index + 1; Bogus_Dealls (Deall_Index) := Tmp_Alloc.Root; else Leak_Index := Leak_Index + 1; Leaks (Leak_Index) := Tmp_Alloc.Root; end if; Tmp_Alloc.Root := Get_Next; end loop; -- Print out wrong deallocations if Nb_Wrong_Deall > 0 then Put_Line ("Releasing deallocated memory at :"); if not Quiet_Mode then Put_Line ("--------------------------------"); end if; for J in 1 .. Bogus_Dealls'Last loop Print_BT (Bogus_Dealls (J)); New_Line; end loop; end if; -- Print out all allocation Leaks if Nb_Root > 0 then -- Sort the Leaks so that potentially important leaks appear first Root_Sort.Sort (Nb_Root); for J in 1 .. Leaks'Last loop if Quiet_Mode then if Nb_Alloc (Leaks (J)) = 1 then Put_Line (Integer'Image (Nb_Alloc (Leaks (J))) & " leak at :"); else Put_Line (Integer'Image (Nb_Alloc (Leaks (J))) & " leaks at :"); end if; else Put_Line ("Allocation Root #" & Integer'Image (J)); Put_Line ("-------------------"); Put (" Number of non freed allocations :"); Ada.Integer_Text_IO.Put (Nb_Alloc (Leaks (J)), 4); New_Line; Put_Line (" Final Water Mark (non freed mem) :" & Mem_Image (Alloc_Size (Leaks (J)))); Put_Line (" High Water Mark :" & Mem_Image (High_Water_Mark (Leaks (J)))); Put_Line (" Backtrace :"); end if; Print_BT (Leaks (J)); New_Line; end loop; end if; end Print_Back_Traces; end Gnatmem;
private with System; private with ACO.Utils.DS.Generic_Collection; private with ACO.Utils.Scope_Locks; generic type Item_Type is private; Max_Nof_Subscribers : Positive; package ACO.Utils.Generic_Pubsub is pragma Preelaborate; type Sub is abstract tagged null record; type Sub_Access is access all Sub'Class; procedure Update (This : access Sub; Data : in Item_Type) is abstract; type Pub is abstract tagged limited private; procedure Update (This : in out Pub; Data : in Item_Type); function Nof_Subscribers (This : in out Pub) return Natural; procedure Attach (This : in out Pub; Subscriber : in Sub_Access) with Pre => This.Nof_Subscribers < Max_Nof_Subscribers; procedure Detach (This : in out Pub; Subscriber : in Sub_Access); private package C is new ACO.Utils.DS.Generic_Collection (Item_Type => Sub_Access, "=" => "="); type Pub is tagged limited record Subscribers : C.Collection (Max_Size => Max_Nof_Subscribers); Mutex : aliased ACO.Utils.Scope_Locks.Mutex (System.Priority'Last); end record; type Sub_Array is array (Positive range <>) of Sub_Access; function Get_Subscribers (This : in out Pub) return Sub_Array; end ACO.Utils.Generic_Pubsub;
with Ada.Text_IO, Bin_Trees.Traverse; procedure Main is package B_Trees is new Bin_Trees(Character); use B_Trees; function Same_Fringe(T1, T2: Tree_Type) return Boolean is protected type Buffer_Type is entry Write(Item: Character); entry Write_Done; entry Read_And_Compare(Item: Character); entry Read_Done; entry Wait_For_The_End; function Early_Abort return Boolean; function The_Same return Boolean; private Current: Character; Readable: Boolean := False; Done: Boolean := False; Same: Boolean := True; Finished: Boolean := False; end Buffer_Type; protected body Buffer_Type is entry Write(Item: Character) when not Readable is begin Readable := True; Current := Item; end Write; entry Write_Done when not Readable is begin Readable := True; Done := True; end Write_Done; entry Read_And_Compare(Item: Character) when Readable is begin if Done then -- Producer is already out of items Same := False; Finished := True; -- Readable remains True, else Consumer might lock itself out elsif Item /= Current then Same := False; Finished := True; Readable := False; else Readable := False; end if; end Read_And_Compare; entry Read_Done when Readable is begin Readable := False; Same := Same and Done; Finished := True; end Read_Done; entry Wait_For_The_End when (Finished) or (not Same) is begin null; -- "when ..." is all we need end Wait_For_The_End; function The_Same return Boolean is begin return Same; end The_Same; function Early_Abort return Boolean is begin return not The_Same or Finished; end Early_Abort; end Buffer_Type; Buffer: Buffer_Type; -- some wrapper subprogram needed to instantiate the generics below procedure Prod_Write(Item: Character) is begin Buffer.Write(Item); end Prod_Write; function Stop return Boolean is begin return Buffer.Early_Abort; end Stop; procedure Prod_Stop is begin Buffer.Write_Done; end Prod_Stop; procedure Cons_Write(Item: Character) is begin Buffer.Read_And_Compare(Item); end Cons_Write; procedure Cons_Stop is begin Buffer.Read_Done; end Cons_Stop; package Producer is new B_Trees.Traverse(Prod_Write, Stop, Prod_Stop); package Consumer is new B_Trees.Traverse(Cons_Write, Stop, Cons_Stop); begin Producer.Inorder_Task.Run(T1); Consumer.Inorder_Task.Run(T2); Buffer.Wait_For_The_End; return Buffer.The_Same; end Same_Fringe; procedure Show_Preorder(Tree: Tree_Type; Prefix: String := "") is use Ada.Text_IO; begin if Prefix /= "" then Ada.Text_IO.Put(Prefix); end if; if not Empty(Tree) then Put("(" & Item(Tree)); Put(", "); Show_Preorder(Left(Tree)); Put(", "); Show_Preorder(Right(Tree)); Put(")"); end if; if Prefix /= "" then New_Line; end if; end Show_Preorder; T_0: Tree_Type := Tree('a', Empty, Tree('b')); T: array(1 .. 5) of Tree_Type; begin T(1) := Tree('d', Tree('c'), T_0); T(2) := Tree('c', Empty, Tree('a', Tree('d'), Tree('b'))); T(3) := Tree('e', T(1), T(2)); T(4) := Tree('e', T(2), T(1)); T(5) := Tree('e', T_0, Tree('c', Tree('d'), T(1))); -- First display the trees you have (in preorder) for I in T'Range loop Show_Preorder(T(I), "Tree(" & Integer'Image(I) & " ) is "); end loop; Ada.Text_IO.New_Line; -- Now compare them, which have the same fringe? for I in T'Range loop for J in T'Range loop if Same_Fringe(T(J), T(I)) then Ada.Text_IO.Put("same("); else Ada.Text_IO.Put("DIFF("); end if; Ada.Text_IO.Put(Integer'Image(I) & "," & Integer'Image(J) & " ); "); end loop; Ada.Text_IO.New_Line; end loop; end Main;
pragma Ada_2005; pragma Style_Checks (Off); with Interfaces.C; use Interfaces.C; package avxintrin_h is -- Copyright (C) 2008-2017 Free Software Foundation, Inc. -- This file is part of GCC. -- GCC 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, or (at your option) -- any later version. -- GCC 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. -- 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/>. -- Implemented from the specification included in the Intel C++ Compiler -- User Guide and Reference, version 11.0. -- Internal data types for implementing the intrinsics. subtype uu_v4df is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:41 subtype uu_v8sf is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:42 subtype uu_v4di is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:43 subtype uu_v4du is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:44 subtype uu_v8si is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:45 subtype uu_v8su is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:46 subtype uu_v16hi is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:47 subtype uu_v16hu is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:48 subtype uu_v32qi is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:49 subtype uu_v32qu is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:50 -- The Intel API is flexible enough that we must allow aliasing with other -- vector types, and their scalar components. subtype uu_m256 is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:54 subtype uu_m256i is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:56 subtype uu_m256d is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:58 -- Unaligned version of the same types. subtype uu_m256_u is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:62 subtype uu_m256i_u is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:65 subtype uu_m256d_u is <vector>; -- d:\install\gpl2018\lib\gcc\x86_64-pc-mingw32\7.3.1\include\avxintrin.h:68 -- Compare predicates for scalar and packed compare intrinsics. -- Equal (ordered, non-signaling) -- Less-than (ordered, signaling) -- Less-than-or-equal (ordered, signaling) -- Unordered (non-signaling) -- Not-equal (unordered, non-signaling) -- Not-less-than (unordered, signaling) -- Not-less-than-or-equal (unordered, signaling) -- Ordered (nonsignaling) -- Equal (unordered, non-signaling) -- Not-greater-than-or-equal (unordered, signaling) -- Not-greater-than (unordered, signaling) -- False (ordered, non-signaling) -- Not-equal (ordered, non-signaling) -- Greater-than-or-equal (ordered, signaling) -- Greater-than (ordered, signaling) -- True (unordered, non-signaling) -- Equal (ordered, signaling) -- Less-than (ordered, non-signaling) -- Less-than-or-equal (ordered, non-signaling) -- Unordered (signaling) -- Not-equal (unordered, signaling) -- Not-less-than (unordered, non-signaling) -- Not-less-than-or-equal (unordered, non-signaling) -- Ordered (signaling) -- Equal (unordered, signaling) -- Not-greater-than-or-equal (unordered, non-signaling) -- Not-greater-than (unordered, non-signaling) -- False (ordered, signaling) -- Not-equal (ordered, signaling) -- Greater-than-or-equal (ordered, non-signaling) -- Greater-than (ordered, non-signaling) -- True (unordered, signaling) -- skipped func _mm256_add_pd -- skipped func _mm256_add_ps -- skipped func _mm256_addsub_pd -- skipped func _mm256_addsub_ps -- skipped func _mm256_and_pd -- skipped func _mm256_and_ps -- skipped func _mm256_andnot_pd -- skipped func _mm256_andnot_ps -- Double/single precision floating point blend instructions - select -- data from 2 sources using constant/variable mask. -- skipped func _mm256_blendv_pd -- skipped func _mm256_blendv_ps -- skipped func _mm256_div_pd -- skipped func _mm256_div_ps -- Dot product instructions with mask-defined summing and zeroing parts -- of result. -- skipped func _mm256_hadd_pd -- skipped func _mm256_hadd_ps -- skipped func _mm256_hsub_pd -- skipped func _mm256_hsub_ps -- skipped func _mm256_max_pd -- skipped func _mm256_max_ps -- skipped func _mm256_min_pd -- skipped func _mm256_min_ps -- skipped func _mm256_mul_pd -- skipped func _mm256_mul_ps -- skipped func _mm256_or_pd -- skipped func _mm256_or_ps -- skipped func _mm256_sub_pd -- skipped func _mm256_sub_ps -- skipped func _mm256_xor_pd -- skipped func _mm256_xor_ps -- skipped func _mm256_cvtepi32_pd -- skipped func _mm256_cvtepi32_ps -- skipped func _mm256_cvtpd_ps -- skipped func _mm256_cvtps_epi32 -- skipped func _mm256_cvtps_pd -- skipped func _mm256_cvttpd_epi32 -- skipped func _mm256_cvtpd_epi32 -- skipped func _mm256_cvttps_epi32 -- skipped func _mm256_cvtsd_f64 -- skipped func _mm256_cvtss_f32 -- skipped func _mm256_zeroall -- skipped func _mm256_zeroupper -- skipped func _mm_permutevar_pd -- skipped func _mm256_permutevar_pd -- skipped func _mm_permutevar_ps -- skipped func _mm256_permutevar_ps -- skipped func _mm_broadcast_ss -- skipped func _mm256_broadcast_sd -- skipped func _mm256_broadcast_ss -- skipped func _mm256_broadcast_pd -- skipped func _mm256_broadcast_ps -- skipped func _mm256_load_pd -- skipped func _mm256_store_pd -- skipped func _mm256_load_ps -- skipped func _mm256_store_ps -- skipped func _mm256_loadu_pd -- skipped func _mm256_storeu_pd -- skipped func _mm256_loadu_ps -- skipped func _mm256_storeu_ps -- skipped func _mm256_load_si256 -- skipped func _mm256_store_si256 -- skipped func _mm256_loadu_si256 -- skipped func _mm256_storeu_si256 -- skipped func _mm_maskload_pd -- skipped func _mm_maskstore_pd -- skipped func _mm256_maskload_pd -- skipped func _mm256_maskstore_pd -- skipped func _mm_maskload_ps -- skipped func _mm_maskstore_ps -- skipped func _mm256_maskload_ps -- skipped func _mm256_maskstore_ps -- skipped func _mm256_movehdup_ps -- skipped func _mm256_moveldup_ps -- skipped func _mm256_movedup_pd -- skipped func _mm256_lddqu_si256 -- skipped func _mm256_stream_si256 -- skipped func _mm256_stream_pd -- skipped func _mm256_stream_ps -- skipped func _mm256_rcp_ps -- skipped func _mm256_rsqrt_ps -- skipped func _mm256_sqrt_pd -- skipped func _mm256_sqrt_ps -- skipped func _mm256_unpackhi_pd -- skipped func _mm256_unpacklo_pd -- skipped func _mm256_unpackhi_ps -- skipped func _mm256_unpacklo_ps -- skipped func _mm_testz_pd -- skipped func _mm_testc_pd -- skipped func _mm_testnzc_pd -- skipped func _mm_testz_ps -- skipped func _mm_testc_ps -- skipped func _mm_testnzc_ps -- skipped func _mm256_testz_pd -- skipped func _mm256_testc_pd -- skipped func _mm256_testnzc_pd -- skipped func _mm256_testz_ps -- skipped func _mm256_testc_ps -- skipped func _mm256_testnzc_ps -- skipped func _mm256_testz_si256 -- skipped func _mm256_testc_si256 -- skipped func _mm256_testnzc_si256 -- skipped func _mm256_movemask_pd -- skipped func _mm256_movemask_ps -- skipped func _mm256_undefined_pd -- skipped func _mm256_undefined_ps -- skipped func _mm256_undefined_si256 -- skipped func _mm256_setzero_pd -- skipped func _mm256_setzero_ps -- skipped func _mm256_setzero_si256 -- Create the vector [A B C D]. -- skipped func _mm256_set_pd -- Create the vector [A B C D E F G H]. -- skipped func _mm256_set_ps -- Create the vector [A B C D E F G H]. -- skipped func _mm256_set_epi32 -- skipped func _mm256_set_epi16 -- skipped func _mm256_set_epi8 -- skipped func _mm256_set_epi64x -- Create a vector with all elements equal to A. -- skipped func _mm256_set1_pd -- Create a vector with all elements equal to A. -- skipped func _mm256_set1_ps -- Create a vector with all elements equal to A. -- skipped func _mm256_set1_epi32 -- skipped func _mm256_set1_epi16 -- skipped func _mm256_set1_epi8 -- skipped func _mm256_set1_epi64x -- Create vectors of elements in the reversed order from the -- _mm256_set_XXX functions. -- skipped func _mm256_setr_pd -- skipped func _mm256_setr_ps -- skipped func _mm256_setr_epi32 -- skipped func _mm256_setr_epi16 -- skipped func _mm256_setr_epi8 -- skipped func _mm256_setr_epi64x -- Casts between various SP, DP, INT vector types. Note that these do no -- conversion of values, they just change the type. -- skipped func _mm256_castpd_ps -- skipped func _mm256_castpd_si256 -- skipped func _mm256_castps_pd -- skipped func _mm256_castps_si256 -- skipped func _mm256_castsi256_ps -- skipped func _mm256_castsi256_pd -- skipped func _mm256_castpd256_pd128 -- skipped func _mm256_castps256_ps128 -- skipped func _mm256_castsi256_si128 -- When cast is done from a 128 to 256-bit type, the low 128 bits of -- the 256-bit result contain source parameter value and the upper 128 -- bits of the result are undefined. Those intrinsics shouldn't -- generate any extra moves. -- skipped func _mm256_castpd128_pd256 -- skipped func _mm256_castps128_ps256 -- skipped func _mm256_castsi128_si256 end avxintrin_h;
package body WFC is function Modular_Index (Matrix : in Element_Matrix; X, Y : Natural) return Element_Type with Inline is Matrix_X : constant Natural := ((X - Matrix'First(1)) mod Matrix'Length(1)) + Matrix'First(1); Matrix_Y : constant Natural := ((Y - Matrix'First(2)) mod Matrix'Length(2)) + Matrix'First(2); begin return Matrix(Matrix_X, Matrix_Y); end; function Invert_Horizontal (Matrix : in Element_Matrix) return Element_Matrix with Inline is Out_Matrix : Element_Matrix (Matrix'Range(1), Matrix'Range(2)); Out_X : Natural; begin for The_X in Matrix'Range(1) loop for The_Y in Matrix'Range(2) loop Out_X := Matrix'First(1) + Matrix'Last(1) - The_X; Out_Matrix(Out_X, The_Y) := Matrix(The_X, The_Y); end loop; end loop; return Out_Matrix; end; function Invert_Vertical (Matrix : in Element_Matrix) return Element_Matrix with Inline is Out_Matrix : Element_Matrix (Matrix'Range(1), Matrix'Range(2)); Out_Y : Natural; begin for The_X in Matrix'Range(1) loop for The_Y in Matrix'Range(2) loop Out_Y := Matrix'First(2) + Matrix'Last(2) - The_Y; Out_Matrix(The_X, Out_Y) := Matrix(The_X, The_Y); end loop; end loop; return Out_Matrix; end; function Rotate_Clockwise (Matrix : in Element_Matrix) return Element_Matrix with Inline is Out_Matrix : Element_Matrix (Matrix'Range(2), Matrix'Range(1)); Out_X : Natural; begin for The_X in Matrix'Range(1) loop for The_Y in Matrix'Range(2) loop Out_X := Matrix'First(2) + Matrix'Last(2) - The_Y; Out_Matrix(Out_X, The_X) := Matrix(The_X, The_Y); end loop; end loop; return Out_Matrix; end; function Opposite_Direction(Dir : Adjacency_Direction) return Adjacency_Direction is (case Dir is when Upwards => Downwards, when Downwards => Upwards, when Leftwards => Rightwards, when Rightwards => Leftwards) with Inline; function Initialize_From_Sample ( Sample : in Element_Matrix; Include_Rotations : in Boolean := False; Include_Reflections : in Boolean := False; N, M : in Positive := 2 ) return Instance is separate; package body Extended_Interfaces is separate; function Collapse_Within (Parameters : in Instance; World : out Element_Matrix) return Boolean is subtype X_Dim is Natural range World'First(1) .. World'Last(1); subtype Y_Dim is Natural range World'First(2) .. World'Last(2); package Extended is new Extended_Interfaces(X_Dim, Y_Dim); subtype Collapse_Info is Extended.Collapse_Info'Class; procedure Set_Resulting_Element (X : X_Dim; Y : Y_Dim; Element : Element_Type) with Inline is begin World(X, Y) := Element; end; procedure Upon_Collapse (X : X_Dim; Y : Y_Dim; Info : in Collapse_Info'Class) is null; function Collapse is new Extended.Generic_Collapse_Within ( Set_Resulting_Element => Set_Resulting_Element , Upon_Collapse => Upon_Collapse ); begin return Collapse(Parameters); end; end;
with STM_Board; use STM_Board; with Inverter_PWM; package body Error_Handling is procedure Make_Safe is begin if not STM_Board.Is_Initialized then STM_Board.Initialize_GPIO; end if; -- Force the gate driver into a safe state Inverter_PWM.Safe_State; -- Signal error to the user STM_Board.Turn_On (Red_LED); STM_Board.Turn_Off (Green_LED); end Make_Safe; end Error_Handling;
package Generic_Root is type Number is range 0 .. 2**63-1; type Number_Array is array(Positive range <>) of Number; type Base_Type is range 2 .. 16; -- any reasonable base to write down numb generic with function "&"(X, Y: Number) return Number; -- instantiate with "+" for additive digital roots -- instantiate with "*" for multiplicative digital roots procedure Compute_Root(N: Number; Root, Persistence: out Number; Base: Base_Type := 10); -- computes Root and Persistence of N; end Generic_Root;
-- { dg-do run } with System, NAT1; use NAT1; procedure Nat1R is use type System.Address; begin if One_Address /= Nat_One_Storage'Address then raise Constraint_Error; end if; end;
with Ada.Text_IO; with Ada.Integer_Text_IO; with Ada.Numerics.Elementary_Functions; -- Copyright 2021 Melwyn Francis Carlo procedure A042 is use Ada.Text_IO; use Ada.Integer_Text_IO; use Ada.Numerics.Elementary_Functions; -- File Reference: http://www.naturalnumbers.org/primes.html FT : File_Type; Ch : Character; File_Name : constant String := "problems/042/p042_words.txt"; Count_Val : Integer := 0; Index_Val : Integer := -1; Word_Val : Integer := 0; Is_Incremented : Boolean := False; Sqrt_Term, N_Term : Float; begin Open (FT, In_File, File_Name); Get (FT, Ch); while not End_Of_File (FT) loop Get (FT, Ch); if Ch in 'A' .. 'Z' or Ch in 'a' .. 'z' then Word_Val := Word_Val + Character'Pos (Ch) - 64; Index_Val := Index_Val + 1; Is_Incremented := False; else if not Is_Incremented then Index_Val := 0; Is_Incremented := True; Sqrt_Term := Sqrt (1.0 + (8.0 * Float (Word_Val))); Word_Val := 0; if (Sqrt_Term - Float (Integer (Sqrt_Term))) = 0.0 then N_Term := (Sqrt_Term - 1.0) / 2.0; if (N_Term - Float (Integer (N_Term))) = 0.0 then Count_Val := Count_Val + 1; end if; end if; end if; end if; end loop; Close (FT); Put (Count_Val, Width => 0); end A042;
-- { dg-do compile } -- { dg-options "-O3 -gnatn -Winline" } package body Warn10 is procedure Do_Something(Driver : My_Driver) is X : Float; begin X := Get_Input_Value( Driver, 1, 1); end; end Warn10;
package body Utility is procedure While_1 is begin loop null; end loop; end While_1; procedure Delay_random is Iterations : constant := 100_000; begin for I in 1 .. Iterations loop null; end loop; end Delay_random; end Utility;
----------------------------------------------------------------------- -- awa-comments-module -- Comments module -- Copyright (C) 2011, 2012, 2013, 2014 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with ASF.Applications; with ADO; with AWA.Modules; with AWA.Modules.Get; with AWA.Modules.Lifecycles; with AWA.Comments.Models; -- == Integration == -- The <tt>Comment_Module</tt> manages the comments associated with entities. It provides -- operations that are used by the comment beans to manage the comments. -- An instance of the <tt>Comment_Module</tt> must be declared and registered in the -- AWA application. The module instance can be defined as follows: -- -- type Application is new AWA.Applications.Application with record -- Comment_Module : aliased AWA.Comments.Modules.Comment_Module; -- end record; -- -- And registered in the `Initialize_Modules` procedure by using: -- -- Register (App => App.Self.all'Access, -- Name => AWA.Comments.Modules.NAME, -- URI => "comments", -- Module => App.Comment_Module'Access); -- package AWA.Comments.Modules is NAME : constant String := "comments"; Not_Found : exception; -- The <tt>Comment_Lifecycle</tt> package allows to receive life cycle events related -- to the <tt>Comment</tt> object. package Comment_Lifecycle is new AWA.Modules.Lifecycles (Element_Type => AWA.Comments.Models.Comment_Ref'Class); subtype Listener is Comment_Lifecycle.Listener; type Comment_Module is new AWA.Modules.Module with null record; type Comment_Module_Access is access all Comment_Module'Class; overriding procedure Initialize (Plugin : in out Comment_Module; App : in AWA.Modules.Application_Access; Props : in ASF.Applications.Config); -- Load the comment identified by the given identifier. procedure Load_Comment (Model : in Comment_Module; Comment : in out AWA.Comments.Models.Comment_Ref'Class; Id : in ADO.Identifier); -- Create a new comment for the associated database entity. procedure Create_Comment (Model : in Comment_Module; Permission : in String; Entity_Type : in String; Comment : in out AWA.Comments.Models.Comment_Ref'Class); -- Update the comment represented by <tt>Comment</tt> if the current user has the -- permission identified by <tt>Permission</tt>. procedure Update_Comment (Model : in Comment_Module; Permission : in String; Comment : in out AWA.Comments.Models.Comment_Ref'Class); -- Delete the comment represented by <tt>Comment</tt> if the current user has the -- permission identified by <tt>Permission</tt>. procedure Delete_Comment (Model : in Comment_Module; Permission : in String; Comment : in out AWA.Comments.Models.Comment_Ref'Class); -- Set the publication status of the comment represented by <tt>Comment</tt> -- if the current user has the permission identified by <tt>Permission</tt>. procedure Publish_Comment (Model : in Comment_Module; Permission : in String; Id : in ADO.Identifier; Status : in AWA.Comments.Models.Status_Type; Comment : in out AWA.Comments.Models.Comment_Ref'Class); function Get_Comment_Module is new AWA.Modules.Get (Comment_Module, Comment_Module_Access, NAME); end AWA.Comments.Modules;
with Extraction.Node_Edge_Types; with Extraction.Utilities; package body Extraction.Generic_Instantiations is use type LALCO.Ada_Node_Kind_Type; function Is_Generic_Instantiation (Node : LAL.Ada_Node'Class) return Boolean is (Node.Kind in LALCO.Ada_Generic_Package_Instantiation | LALCO.Ada_Generic_Subp_Instantiation); function Get_Instantiated_Decl (Basic_Decl : LAL.Basic_Decl'Class) return LAL.Basic_Decl; function Get_Instantiated_Decl (Basic_Decl : LAL.Basic_Decl'Class) return LAL.Basic_Decl is begin case LALCO.Ada_Basic_Decl (Basic_Decl.Kind) is when LALCO.Ada_Generic_Package_Instantiation => return Utilities.Get_Referenced_Decl (Basic_Decl.As_Generic_Package_Instantiation .F_Generic_Pkg_Name); when LALCO.Ada_Generic_Subp_Instantiation => return Utilities.Get_Referenced_Decl (Basic_Decl.As_Generic_Subp_Instantiation.F_Generic_Subp_Name); when others => raise Internal_Extraction_Error with "Cases in Is_Generic_Instantiation " & "and Get_Instantiated_Decl do not match"; end case; end Get_Instantiated_Decl; procedure Extract_Edges (Node : LAL.Ada_Node'Class; Graph : Graph_Operations.Graph_Context) is begin if Is_Generic_Instantiation (Node) then declare Instantiation : constant LAL.Basic_Decl := Node.As_Basic_Decl; Instantiated_Decl : constant LAL.Basic_Decl := Get_Instantiated_Decl (Instantiation); begin Graph.Write_Edge (Instantiation, Instantiated_Decl, Node_Edge_Types.Edge_Type_Instantiates); end; end if; end Extract_Edges; end Extraction.Generic_Instantiations;
-- Copyright 2019 Michael Casadevall <michael@casadevall.pro> -- -- 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 DNSCatcher.Network; with DNSCatcher.Datasets; use DNSCatcher.Datasets; -- @summary -- Implements the Sender interface queue for UDP messages -- -- @description -- The outbound packet queue is used to handle all requests either being sent -- to a client, or sending requests to upstream servers for results -- package DNSCatcher.Network.UDP.Sender is -- Send queue management task task type Send_Packet_Task is -- Initializes the sender queue -- -- @value Socket -- GNAT.Sockets Socket_Type -- -- @value Packet_Queue -- Raw package queue to use with the sender module entry Initialize (Socket : Socket_Type; Packet_Queue : DNS_Raw_Packet_Queue_Ptr); -- Starts the sender task entry Start; -- Stops the sender task entry Stop; end Send_Packet_Task; type Send_Packet_Task_Ptr is access Send_Packet_Task; -- UDP Sender interface used to queue outbound packets -- -- @value Config -- Configuration Pointer -- -- @value Sender_Socket -- Socket for the UDP port -- -- @value Sender_Task -- Internal pointer to the Sender task -- -- @value Packet_Queue -- Internal queue for packets to be sent -- type UDP_Sender_Interface is new DNSCatcher.Network.Sender_Interface with record Sender_Socket : Socket_Type; Sender_Task : Send_Packet_Task_Ptr; Packet_Queue : DNS_Raw_Packet_Queue_Ptr; end record; type IPv4_UDP_Receiver_Interface_Ptr is access UDP_Sender_Interface; -- Initializes the sender class interface -- -- @value This -- Class object -- -- @value Config -- Pointer to the configuration object -- -- @value Socket -- GNAT.Socket to use for UDP connections procedure Initialize (This : in out UDP_Sender_Interface; Socket : Socket_Type); -- Starts the interface -- -- @value This -- Class Object procedure Start (This : in out UDP_Sender_Interface); -- Cleanly shuts down the interface -- -- @value This -- Class Object procedure Shutdown (This : in out UDP_Sender_Interface); -- Returns the internal packet queue for this interface -- -- @value This -- Clas object -- -- @returns -- Pointer to the packet queue -- function Get_Packet_Queue_Ptr (This : in out UDP_Sender_Interface) return DNS_Raw_Packet_Queue_Ptr; end DNSCatcher.Network.UDP.Sender;
with PIN; with PasswordDatabase; with Ada.Containers; use Ada.Containers; with Ada.Text_IO; use Ada.Text_IO; package PasswordManager with SPARK_Mode is type Information is private; -- Private function returns length of database in Password Manager function StoredDatabaseLength(Manager_Information : in Information) return Ada.Containers.Count_Type; -- Private function returns Master Pin in Password Manager function GetMasterPin(Manager_Information: in Information) return PIN.PIN; -- Private function returns database in Password Manager function GetDatabase(Manager_Information: in Information) return PasswordDatabase.Database; -- Private function returns status of Password Manager function IsLocked(Manager_Information: in Information) return Boolean; -- Inital Password Manager Setup procedure Init(Pin_Input : in String; Manager_Information : out Information) with Pre => (Pin_Input' Length = 4 and (for all I in Pin_Input'Range => Pin_Input(I) >= '0' and Pin_Input(I) <= '9')); -- Gets the current status of the Password Manager function Lock_Status(Manager_Information : in Information) return Boolean; -- Only executes Unlock_Manager if the current state is unlocked procedure Execute_Unlock(Manager_Information : in out Information; Pin_Input : in PIN.PIN); -- Procedure changes state of the Password Manager to Unlocked procedure Unlock_Manager(Manager_Information : in out Information; Pin_Input : in PIN.PIN) with Pre => (IsLocked(Manager_Information)), Post =>(if PIN."="(GetMasterPin(Manager_Information), Pin_Input) then IsLocked(Manager_Information) = False); -- Only executes Lock_Manager if the current state is unlocked procedure Execute_Lock(Manager_Information : in out Information; Pin_Input : in PIN.PIN); -- Procedure changes state of the Password Manager to Locked procedure Lock_Manager(Manager_Information : in out Information; Pin_Input : in PIN.PIN) with Pre => (IsLocked(Manager_Information) = False), Post => PIN."="(GetMasterPin(Manager_Information), Pin_Input) and IsLocked(Manager_Information); -- Only executes Get Command if requirements are met procedure Execute_Get_Command(Manager_Information : in Information; Input_Url : in PasswordDatabase.URL); -- Get Command executed procedure Get_Database(Manager_Information : in Information; Input_Url : in PasswordDatabase.URL) with Pre => (IsLocked(Manager_Information) = False and PasswordDatabase.Has_Password_For (GetDatabase(Manager_Information), Input_Url)); -- Only executes Put Command if requirements are met procedure Execute_Put_Command(Manager_Information : in out Information; Input_Url : in PasswordDatabase.URL; Input_Pwd : in PasswordDatabase.Password); -- Put Command executed procedure Put_Database(Manager_Information : in out Information; Input_Url : in PasswordDatabase.URL; Input_Pwd : in PasswordDatabase.Password) with Pre => (IsLocked(Manager_Information) = False and StoredDatabaseLength(Manager_Information) < PasswordDatabase.Max_Entries); -- Only executes Rem Command if requirements are met procedure Execute_Rem_Command(Manager_Information : in out Information; Input_Url : in PasswordDatabase.URL); -- Rem Command executed procedure Rem_Database(Manager_Information : in out Information; Input_Url : in PasswordDatabase.URL) with Pre => (IsLocked(Manager_Information) = False and PasswordDatabase.Has_Password_For (GetDatabase(Manager_Information), Input_Url)); private -- Password Manager is Record which encapsulates -- Locked status, Master Pin and Master Database type Information is record Is_Locked : Boolean; Master_Pin : PIN.PIN; Master_Database : PasswordDatabase.Database; end record; -- private function declarations function GetMasterPin(Manager_Information: in Information) return PIN.PIN is (Manager_Information.Master_Pin); function StoredDatabaseLength(Manager_Information : in Information) return Ada.Containers.Count_Type is (PasswordDatabase.Length(Manager_Information.Master_Database)); function GetDatabase(Manager_Information: in Information) return PasswordDatabase.Database is (Manager_Information.Master_Database); function IsLocked(Manager_Information: in Information) return Boolean is (Manager_Information.Is_Locked); end PasswordManager;
pragma Ada_2012; pragma Style_Checks (Off); with Interfaces.C; use Interfaces.C; with Interfaces.C.Extensions; package bits_thread_shared_types_h is -- Common threading primitives definitions for both POSIX and C11. -- Copyright (C) 2017-2021 Free Software Foundation, Inc. -- This file is part of the GNU C Library. -- The GNU C Library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Lesser General Public -- License as published by the Free Software Foundation; either -- version 2.1 of the License, or (at your option) any later version. -- The GNU C Library is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- Lesser General Public License for more details. -- You should have received a copy of the GNU Lesser General Public -- License along with the GNU C Library; if not, see -- <https://www.gnu.org/licenses/>. -- Arch-specific definitions. Each architecture must define the following -- macros to define the expected sizes of pthread data types: -- __SIZEOF_PTHREAD_ATTR_T - size of pthread_attr_t. -- __SIZEOF_PTHREAD_MUTEX_T - size of pthread_mutex_t. -- __SIZEOF_PTHREAD_MUTEXATTR_T - size of pthread_mutexattr_t. -- __SIZEOF_PTHREAD_COND_T - size of pthread_cond_t. -- __SIZEOF_PTHREAD_CONDATTR_T - size of pthread_condattr_t. -- __SIZEOF_PTHREAD_RWLOCK_T - size of pthread_rwlock_t. -- __SIZEOF_PTHREAD_RWLOCKATTR_T - size of pthread_rwlockattr_t. -- __SIZEOF_PTHREAD_BARRIER_T - size of pthread_barrier_t. -- __SIZEOF_PTHREAD_BARRIERATTR_T - size of pthread_barrierattr_t. -- The additional macro defines any constraint for the lock alignment -- inside the thread structures: -- __LOCK_ALIGNMENT - for internal lock/futex usage. -- Same idea but for the once locking primitive: -- __ONCE_ALIGNMENT - for pthread_once_t/once_flag definition. -- Common definition of pthread_mutex_t. type uu_pthread_internal_list; type uu_pthread_internal_list is record uu_prev : access uu_pthread_internal_list; -- /usr/include/bits/thread-shared-types.h:51 uu_next : access uu_pthread_internal_list; -- /usr/include/bits/thread-shared-types.h:52 end record with Convention => C_Pass_By_Copy; -- /usr/include/bits/thread-shared-types.h:49 subtype uu_pthread_list_t is uu_pthread_internal_list; -- /usr/include/bits/thread-shared-types.h:53 type uu_pthread_internal_slist; type uu_pthread_internal_slist is record uu_next : access uu_pthread_internal_slist; -- /usr/include/bits/thread-shared-types.h:57 end record with Convention => C_Pass_By_Copy; -- /usr/include/bits/thread-shared-types.h:55 subtype uu_pthread_slist_t is uu_pthread_internal_slist; -- /usr/include/bits/thread-shared-types.h:58 -- Arch-specific mutex definitions. A generic implementation is provided -- by sysdeps/nptl/bits/struct_mutex.h. If required, an architecture -- can override it by defining: -- 1. struct __pthread_mutex_s (used on both pthread_mutex_t and mtx_t -- definition). It should contains at least the internal members -- defined in the generic version. -- 2. __LOCK_ALIGNMENT for any extra attribute for internal lock used with -- atomic operations. -- 3. The macro __PTHREAD_MUTEX_INITIALIZER used for static initialization. -- It should initialize the mutex internal flag. -- Arch-sepecific read-write lock definitions. A generic implementation is -- provided by struct_rwlock.h. If required, an architecture can override it -- by defining: -- 1. struct __pthread_rwlock_arch_t (used on pthread_rwlock_t definition). -- It should contain at least the internal members defined in the -- generic version. -- 2. The macro __PTHREAD_RWLOCK_INITIALIZER used for static initialization. -- It should initialize the rwlock internal type. -- Common definition of pthread_cond_t. type anon_4 is record uu_low : aliased unsigned; -- /usr/include/bits/thread-shared-types.h:99 uu_high : aliased unsigned; -- /usr/include/bits/thread-shared-types.h:100 end record with Convention => C_Pass_By_Copy; type anon_3 (discr : unsigned := 0) is record case discr is when 0 => uu_wseq : aliased Extensions.unsigned_long_long; -- /usr/include/bits/thread-shared-types.h:96 when others => uu_wseq32 : aliased anon_4; -- /usr/include/bits/thread-shared-types.h:101 end case; end record with Convention => C_Pass_By_Copy, Unchecked_Union => True; type anon_6 is record uu_low : aliased unsigned; -- /usr/include/bits/thread-shared-types.h:108 uu_high : aliased unsigned; -- /usr/include/bits/thread-shared-types.h:109 end record with Convention => C_Pass_By_Copy; type anon_5 (discr : unsigned := 0) is record case discr is when 0 => uu_g1_start : aliased Extensions.unsigned_long_long; -- /usr/include/bits/thread-shared-types.h:105 when others => uu_g1_start32 : aliased anon_6; -- /usr/include/bits/thread-shared-types.h:110 end case; end record with Convention => C_Pass_By_Copy, Unchecked_Union => True; type uu_pthread_cond_s_array992 is array (0 .. 1) of aliased unsigned; type uu_pthread_cond_s is record parent : aliased anon_3; field_2 : aliased anon_5; uu_g_refs : aliased uu_pthread_cond_s_array992; -- /usr/include/bits/thread-shared-types.h:112 uu_g_size : aliased uu_pthread_cond_s_array992; -- /usr/include/bits/thread-shared-types.h:113 uu_g1_orig_size : aliased unsigned; -- /usr/include/bits/thread-shared-types.h:114 uu_wrefs : aliased unsigned; -- /usr/include/bits/thread-shared-types.h:115 uu_g_signals : aliased uu_pthread_cond_s_array992; -- /usr/include/bits/thread-shared-types.h:116 end record with Convention => C_Pass_By_Copy; -- /usr/include/bits/thread-shared-types.h:92 subtype uu_tss_t is unsigned; -- /usr/include/bits/thread-shared-types.h:119 subtype uu_thrd_t is unsigned_long; -- /usr/include/bits/thread-shared-types.h:120 -- skipped anonymous struct anon_7 type uu_once_flag is record uu_data : aliased int; -- /usr/include/bits/thread-shared-types.h:124 end record with Convention => C_Pass_By_Copy; -- /usr/include/bits/thread-shared-types.h:125 end bits_thread_shared_types_h;
package Tkmrpc.Operations.Ees is Esa_Acquire : constant Operations.Operation_Type := 16#0100#; Esa_Expire : constant Operations.Operation_Type := 16#0101#; end Tkmrpc.Operations.Ees;
-- SPDX-FileCopyrightText: 2022 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- with Ada.Containers.Hashed_Maps; with Ada.Unchecked_Deallocation; with Regions.Entities; with Regions.Shared_Hashed_Maps; private package Regions.Contexts.Environments.Nodes is pragma Preelaborate; type Entity_Node is tagged limited null record; type Entity_Node_Access is access all Entity_Node'Class; function Hash (List : Selected_Entity_Name) return Ada.Containers.Hash_Type is (Ada.Containers.Hash_Type'Mod (List)); procedure Free is new Ada.Unchecked_Deallocation (Entity_Node'Class, Entity_Node_Access); package Node_Maps is new Regions.Shared_Hashed_Maps (Selected_Entity_Name, Entity_Node_Access, Ada.Containers.Hash_Type, Regions.Contexts.Change_Count, Hash, "=", "=", Free); package Entity_Maps is new Ada.Containers.Hashed_Maps (Selected_Entity_Name, Regions.Entities.Entity_Access, Hash, "=", Regions.Entities."="); type Environment_Node; function Empty_Map (Self : access Environment_Node) return Node_Maps.Map; type Environment_Node (Context : access Regions.Contexts.Context) is tagged limited record Counter : Natural := 1; Nodes : Node_Maps.Map := Empty_Map (Environment_Node'Unchecked_Access); Cache : Entity_Maps.Map; Nested : Selected_Entity_Name_Lists.List; end record; function Get_Entity (Self : in out Environment_Node'Class; Name : Selected_Entity_Name) return Regions.Entities.Entity_Access; procedure Reference (Self : in out Environment_Node'Class); procedure Unreference (Self : in out Environment_Node'Class; Last : out Boolean); type Base_Entity (Env : not null Environment_Node_Access) is abstract limited new Regions.Entities.Entity with record Name : Selected_Entity_Name; end record; end Regions.Contexts.Environments.Nodes;
with Ada.Unchecked_Deallocation; package body Spark_Unbound.Safe_Alloc with SPARK_Mode is package body Definite with SPARK_Mode is function Alloc return T_Acc is pragma SPARK_Mode (Off); -- Spark OFF for exception handling begin return new T; exception when Storage_Error => return null; end Alloc; procedure Free (Pointer : in out T_Acc) is procedure Dealloc is new Ada.Unchecked_Deallocation (T, T_Acc); begin Dealloc (Pointer); end Free; end Definite; package body Arrays with SPARK_Mode is function Alloc (First, Last : Index_Type) return Array_Type_Acc is pragma SPARK_Mode (Off); -- Spark OFF for exception handling begin return new Array_Type(First .. Last); exception when Storage_Error => return null; end Alloc; procedure Free (Pointer : in out Array_Type_Acc) is procedure Dealloc is new Ada.Unchecked_Deallocation (Array_Type, Array_Type_Acc); begin Dealloc (Pointer); end Free; end Arrays; end Spark_Unbound.Safe_Alloc;
with Ada.Text_IO; procedure Numbers is package Int_IO is new Ada.Text_IO.Integer_IO (Integer); package Float_IO is new Ada.Text_IO.Float_IO (Float); begin Int_IO.Put (Integer'Value ("16#ABCF123#")); Ada.Text_IO.New_Line; Int_IO.Put (Integer'Value ("8#7651#")); Ada.Text_IO.New_Line; Int_IO.Put (Integer'Value ("2#1010011010#")); Ada.Text_IO.New_Line; Float_IO.Put (Float'Value ("16#F.FF#E+2")); Ada.Text_IO.New_Line; end Numbers;
-- -- Copyright (C) 2015-2016 secunet Security Networks AG -- Copyright (C) 2016 Nico Huber <nico.h@gmx.de> -- -- 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 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- with HW.GFX.GMA.Config; with HW.GFX.GMA.Registers; with HW.Debug; with GNAT.Source_Info; package body HW.GFX.GMA.PCH.LVDS is PCH_LVDS_ENABLE : constant := 1 * 2 ** 31; PCH_LVDS_VSYNC_POLARITY_INVERT : constant := 1 * 2 ** 21; PCH_LVDS_HSYNC_POLARITY_INVERT : constant := 1 * 2 ** 20; PCH_LVDS_CLK_A_DATA_A0A2_POWER_MASK : constant := 3 * 2 ** 8; PCH_LVDS_CLK_A_DATA_A0A2_POWER_DOWN : constant := 0 * 2 ** 8; PCH_LVDS_CLK_A_DATA_A0A2_POWER_UP : constant := 3 * 2 ** 8; PCH_LVDS_CLK_B_POWER_MASK : constant := 3 * 2 ** 4; PCH_LVDS_CLK_B_POWER_DOWN : constant := 0 * 2 ** 4; PCH_LVDS_CLK_B_POWER_UP : constant := 3 * 2 ** 4; PCH_LVDS_DATA_B0B2_POWER_MASK : constant := 3 * 2 ** 2; PCH_LVDS_DATA_B0B2_POWER_DOWN : constant := 0 * 2 ** 2; PCH_LVDS_DATA_B0B2_POWER_UP : constant := 3 * 2 ** 2; ---------------------------------------------------------------------------- procedure On (Port_Cfg : Port_Config; FDI_Port : FDI_Port_Type) is Sync_Polarity : constant Word32 := (if Port_Cfg.Mode.H_Sync_Active_High then 0 else PCH_LVDS_HSYNC_POLARITY_INVERT) or (if Port_Cfg.Mode.V_Sync_Active_High then 0 else PCH_LVDS_VSYNC_POLARITY_INVERT); Two_Channel : constant Word32 := (if Port_Cfg.Mode.Dotclock >= Config.LVDS_Dual_Threshold then PCH_LVDS_CLK_B_POWER_UP or PCH_LVDS_DATA_B0B2_POWER_UP else 0); begin pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); pragma Debug (Port_Cfg.Mode.BPC /= 6, Debug.Put_Line ("WARNING: Only 18bpp LVDS mode implemented.")); Registers.Write (Register => Registers.PCH_LVDS, Value => PCH_LVDS_ENABLE or PCH_TRANSCODER_SELECT (FDI_Port) or Sync_Polarity or PCH_LVDS_CLK_A_DATA_A0A2_POWER_UP or Two_Channel); end On; ---------------------------------------------------------------------------- procedure Off is begin pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); Registers.Write (Register => Registers.PCH_LVDS, Value => PCH_LVDS_CLK_A_DATA_A0A2_POWER_DOWN or PCH_LVDS_CLK_B_POWER_DOWN or PCH_LVDS_DATA_B0B2_POWER_DOWN); end Off; end HW.GFX.GMA.PCH.LVDS;