content stringlengths 23 1.05M |
|---|
with Ada.IO_Exceptions;
with Interfaces.C.Strings;
with System.Program.Dynamic_Linking;
with System.Storage_Elements.Formatting;
procedure dll_client is
begin
Ada.Debug.Put (System.Program.Full_Name);
Ada.Debug.Put (System.Storage_Elements.Formatting.Image (System.Program.Load_Address));
use_zlib : declare
zlib : System.Program.Dynamic_Linking.Library;
begin
begin
System.Program.Dynamic_Linking.Open (zlib, "libz.so");
pragma Debug (Ada.Debug.Put ("in BSD or Linux"));
exception
when Ada.IO_Exceptions.Name_Error =>
begin
System.Program.Dynamic_Linking.Open (zlib, "libz.dylib");
pragma Debug (Ada.Debug.Put ("in Darwin"));
exception
when Ada.IO_Exceptions.Name_Error =>
System.Program.Dynamic_Linking.Open (zlib, "libz.dll");
pragma Debug (Ada.Debug.Put ("in Windows"));
end;
end;
declare
function zlibVersion return Interfaces.C.Strings.const_chars_ptr
with Import, Convention => C;
for zlibVersion'Address use
System.Program.Dynamic_Linking.Import (zlib, "zlibVersion");
begin
Ada.Debug.Put (Interfaces.C.Strings.Value (zlibVersion));
end;
end use_zlib;
pragma Debug (Ada.Debug.Put ("OK"));
end dll_client;
|
package Offmt_Lib.Decoding is
procedure Decode (Map_Filename : String);
-- Decode from stdin
end Offmt_Lib.Decoding;
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . V C H E C K --
-- --
-- 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.adaccore.com). --
-- --
------------------------------------------------------------------------------
with Ada.Characters.Handling; use Ada.Characters.Handling;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with Asis.Compilation_Units; use Asis.Compilation_Units;
with Asis.Elements; use Asis.Elements;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Implementation; use Asis.Implementation;
with Asis.Set_Get; use Asis.Set_Get;
with Asis.Text.Set_Get; use Asis.Text.Set_Get;
with A4G.A_Debug; use A4G.A_Debug;
with A4G.A_Opt; use A4G.A_Opt;
with A4G.A_Output; use A4G.A_Output;
with Fname; use Fname;
with Gnatvsn; use Gnatvsn;
with Lib; use Lib;
with Namet; use Namet;
with Output; use Output;
with Sinput; use Sinput;
with Types; use Types;
package body A4G.Vcheck is
----------------
-- Local Data --
----------------
Recursion_Count : Natural := 0;
-- Used in Report_ASIS_Bug to prevent too many runaway recursion steps to
-- be done if something bad happens while reporting an ASIS bug. The
-- problem is that ASIS queries are used to form the diagnostic message,
-- and some circularities are possible here.
Max_Recursions_Allowed : constant Positive := 1;
-- This constant limits the number of recursion calls of Report_ASIS_Bug.
-- When this limit is achieved, we try once again, but with turning OFF
-- including the text position into Element's debug image. If this last
-- step also results in resursive call to Report_ASIS_Bug, we
-- unconditionally do OS_Abort.
--
-- Until we finish the revising of all the exception handlers in the
-- ASIS implementation code, we limit the recursion depth by one, because
-- some circularities are possible in the routines that are not "terminal"
-- ASIS queries but which make use of ASIS queries and contain exception
-- handlers forming or modifying diagnostic info.
LT : String renames A4G.A_Types.ASIS_Line_Terminator;
Current_Pos : Natural range 0 .. Diagnosis_String_Length;
-- The pointer to the last filled position in the logical text line
-- in the Diagnosis buffer
-----------------------
-- Local subprograms --
-----------------------
procedure Add_Str (Str : String);
-- This procedure is similar to Add, but it tries to keep the lengths
-- of strings stores in Diagnosis_Buffer under 76 characters. Str should
-- not contain any character(s) caused line breaks. If (a part of) the
-- argument can be added to the current Diagnosis string and if this string
-- already contains some text, (a part of) the argument is separated by a
-- space character.
procedure Close_Str;
-- Closes a current string in the Diagnosis buffer
procedure Reset_Diagnosis_Buffer;
-- Resets the Diagnosis buffer
-- ??? The diagnosis buffer needs a proper documentation!!!!
procedure Set_Error_Status_Internal
(Status : Error_Kinds := Not_An_Error;
Diagnosis : String := Nil_Asis_String;
Query : String := Nil_Asis_String);
-- This procedure allows to avoid dynamicaly allocated strings in calls
-- to Set_Error_Status in Check_Validity. Check_Validity is called in
-- all ASIS structural and semantic queries, so a dynamic string as an
-- argument of internal call results in significant performance penalties.
-- (See E705-008).
---------
-- Add --
---------
procedure Add (Phrase : String) is
begin
if Diagnosis_Len = Max_Diagnosis_Length then
return;
end if;
for I in Phrase'Range loop
Diagnosis_Len := Diagnosis_Len + 1;
Diagnosis_Buffer (Diagnosis_Len) := Phrase (I);
if Diagnosis_Len = Max_Diagnosis_Length then
exit;
end if;
end loop;
end Add;
-------------
-- Add_Str --
-------------
procedure Add_Str (Str : String) is
First_Idx : Natural := Str'First;
Last_Idx : Natural := First_Idx;
-- Indexes of the first and last subwords in Str
Word_Len : Positive;
Available : Positive;
Str_Last : constant Positive := Str'Last;
begin
while Last_Idx < Str_Last loop
Last_Idx := Str_Last;
for J in First_Idx .. Str_Last loop
if Str (J) = ' ' then
Last_Idx := J - 1;
exit;
end if;
end loop;
Word_Len := Last_Idx - First_Idx;
if Current_Pos = 0 then
Available := Diagnosis_String_Length;
else
Available := Diagnosis_String_Length - (Current_Pos + 1);
end if;
if Word_Len <= Available then
if Current_Pos > 0 then
Add (" ");
Current_Pos := Current_Pos + 1;
end if;
Add (Str (First_Idx .. Last_Idx));
Current_Pos := Current_Pos + Word_Len;
else
Add (ASIS_Line_Terminator);
Add (Str (First_Idx .. Last_Idx));
Current_Pos := Word_Len;
end if;
if Current_Pos >=
Diagnosis_String_Length - ASIS_Line_Terminator'Length
then
Add (ASIS_Line_Terminator);
Current_Pos := 0;
end if;
First_Idx := Last_Idx + 2;
end loop;
end Add_Str;
----------------------
-- Check_Validity --
----------------------
procedure Check_Validity
(Compilation_Unit : Asis.Compilation_Unit;
Query : String) is
begin
if Not_Nil (Compilation_Unit) and then
not Valid (Compilation_Unit)
then
Set_Error_Status_Internal
(Status => Value_Error,
Diagnosis => "Invalid Unit value in ",
Query => Query);
raise ASIS_Inappropriate_Compilation_Unit;
end if;
end Check_Validity;
procedure Check_Validity (Element : Asis.Element;
Query : String) is
begin
if Kind (Element) /= Not_An_Element and then
not Valid (Element)
then
Set_Error_Status_Internal
(Status => Value_Error,
Diagnosis => "Invalid Element value in ",
Query => Query);
raise ASIS_Inappropriate_Element;
end if;
end Check_Validity;
procedure Check_Validity
(Line : Asis.Text.Line;
Query : String)
is
begin
if not Asis.Text.Is_Nil (Line) and then not Valid (Line) then
Set_Error_Status_Internal
(Status => Value_Error,
Diagnosis => "Invalid Line value in ",
Query => Query);
raise ASIS_Inappropriate_Line;
end if;
end Check_Validity;
procedure Check_Validity (Context : Asis.Context;
Query : String) is
begin
if not Valid (Context) then
Set_Error_Status_Internal
(Status => Value_Error,
Diagnosis => "Unopened Context argument in ",
Query => Query);
raise ASIS_Inappropriate_Context;
end if;
end Check_Validity;
---------------
-- Close_Str --
---------------
procedure Close_Str is
begin
Add (ASIS_Line_Terminator);
Current_Pos := 0;
end Close_Str;
---------------------
-- Report_ASIS_Bug --
---------------------
procedure Report_ASIS_Bug
(Query_Name : String;
Ex : Exception_Occurrence;
Arg_Element : Asis.Element := Nil_Element;
Arg_Element_2 : Asis.Element := Nil_Element;
Arg_CU : Asis.Compilation_Unit := Nil_Compilation_Unit;
Arg_CU_2 : Asis.Compilation_Unit := Nil_Compilation_Unit;
Arg_Line : Asis.Text.Line := Nil_Line;
Arg_Span : Asis.Text.Span := Nil_Span;
Bool_Par_ON : Boolean := False;
Context_Par : Boolean := False
-- What else???
)
is
Is_GPL_Version : constant Boolean := Gnatvsn.Build_Type = GPL;
Is_FSF_Version : constant Boolean := Gnatvsn.Build_Type = FSF;
procedure Repeat_Char (Char : Character; Col : Nat; After : Character);
-- This procedure is similar to Comperr.Repeat_Char, but it does nothing
-- if Generate_Bug_Box is set OFF.
--
-- Output Char until current column is at or past Col, and then output
-- the character given by After (if column is already past Col on entry,
-- then the effect is simply to output the After character).
procedure End_Line;
-- This procedure is similar to Comperr.End_Line, but it does nothing
-- if Generate_Bug_Box is set OFF.
--
-- Add blanks up to column 76, and then a final vertical bar
procedure Write_Char (C : Character);
procedure Write_Str (S : String);
procedure Write_Eol;
-- These three subprograms are similar to the procedures with the same
-- names from the GNAT Output package except that they do nothing in
-- case if Generate_Bug_Box is set OFF.
procedure End_Line is
begin
if Generate_Bug_Box then
Repeat_Char (' ', 76, '|');
Write_Eol;
end if;
end End_Line;
procedure Repeat_Char (Char : Character; Col : Nat; After : Character) is
begin
if Generate_Bug_Box then
while Column < Col loop
Write_Char (Char);
end loop;
Write_Char (After);
end if;
end Repeat_Char;
procedure Write_Char (C : Character) is
begin
if Generate_Bug_Box then
Output.Write_Char (C);
end if;
end Write_Char;
procedure Write_Str (S : String) is
begin
if Generate_Bug_Box then
Output.Write_Str (S);
end if;
end Write_Str;
procedure Write_Eol is
begin
if Generate_Bug_Box then
Output.Write_Eol;
end if;
end Write_Eol;
begin
if Recursion_Count >= Max_Recursions_Allowed then
if Debug_Flag_I then
-- We can not do anything reasonable any more:
OS_Abort;
else
-- We will try the last time with turning off span computing
-- as a part of debug output
Debug_Flag_I := True;
-- It is not safe to put this flag OFF (it it was set OFF before
-- the call to Report_ASIS_Bug), because it may be some
-- circularities (see the comment for Max_Recursions_Allowed
-- global variable). We may want to revise this decision when
-- the revision of all the exception handlers in the ASIS code
-- is complete.
end if;
end if;
Recursion_Count := Recursion_Count + 1;
-- This procedure is called in case of an ASIS implementation bug, so
-- we do not care very much about efficiency
Set_Standard_Error;
-- Generate header for bug box
Write_Eol;
Write_Char ('+');
Repeat_Char ('=', 29, 'A');
Write_Str ("SIS BUG DETECTED");
Repeat_Char ('=', 76, '+');
Write_Eol;
-- Output ASIS version identification
Write_Str ("| ");
Write_Str (To_String (ASIS_Implementor_Version));
-- Output the exception info:
Write_Str (" ");
Write_Str (Exception_Name (Ex));
Write_Char (' ');
Write_Str (Exception_Message (Ex));
End_Line;
-- Output the query name and call details
Write_Str ("| when processing ");
Write_Str (Query_Name);
if Bool_Par_ON then
Write_Str (" (Boolean par => ON)");
elsif Context_Par then
Write_Str (" (with Context parameter)");
end if;
End_Line;
-- Add to ASIS Diagnosis:
Reset_Diagnosis_Buffer;
Add_Str ("ASIS internal implementation error detected for");
Close_Str;
Add_Str (Query_Name);
if Bool_Par_ON then
Add_Str ("(Boolean par => ON)");
elsif Context_Par then
Add_Str ("(with Context parameter)");
end if;
Close_Str;
-- Add information about the argument of the call (bug box)
if not Is_Nil (Arg_Element) or else
not Is_Nil (Arg_CU)
then
Write_Str ("| ");
Write_Str ("called with ");
if not Is_Nil (Arg_Element) then
Write_Str (Int_Kind (Arg_Element)'Img);
Write_Str (" Element");
End_Line;
elsif not Is_Nil (Arg_CU) then
Write_Str (Kind (Arg_CU)'Img);
Write_Str (" Compilation Unit");
End_Line;
end if;
Write_Str ("| (for full details see the debug image after the box)");
End_Line;
end if;
-- Add information about the argument of the call (Diagnosis string)
if not Is_Nil (Arg_Element) or else
not Is_Nil (Arg_CU)
then
Add_Str ("called with");
Close_Str;
if not Is_Nil (Arg_Element) then
Debug_String (Arg_Element, No_Abort => True);
Add (Debug_Buffer (1 .. Debug_Buffer_Len));
elsif not Is_Nil (Arg_CU) then
Debug_String (Arg_CU, No_Abort => True);
Add (Debug_Buffer (1 .. Debug_Buffer_Len));
end if;
Close_Str;
-- Note, that if we do not generate the bug box, in case if the query
-- have two Element or CU parameters, the information about the
-- second parameter is missed in the ASIS Diagnosis
end if;
Add_Str (Exception_Name (Ex));
Add (" ");
Add_Str (Exception_Message (Ex));
if not Generate_Bug_Box then
Close_Str;
Add_Str ("For more details activate the ASIS bug box");
end if;
-- Completing the bug box
if Is_FSF_Version then
Write_Str
("| Please submit a bug report; see" &
" http://gcc.gnu.org/bugs.html.");
End_Line;
elsif Is_GPL_Version then
Write_Str
("| Please submit a bug report by email " &
"to report@adacore.com.");
End_Line;
Write_Str
("| GAP members can alternatively use GNAT Tracker:");
End_Line;
Write_Str
("| http://www.adacore.com/ " &
"section 'send a report'.");
End_Line;
Write_Str
("| See gnatinfo.txt for full info on procedure " &
"for submitting bugs.");
End_Line;
else
Write_Str
("| Please submit a bug report using GNAT Tracker:");
End_Line;
Write_Str
("| http://www.adacore.com/gnattracker/ " &
"section 'send a report'.");
End_Line;
Write_Str
("| alternatively submit a bug report by email " &
"to report@adacore.com,");
End_Line;
Write_Str
("| including your customer number #nnn " &
"in the subject line.");
End_Line;
end if;
Write_Str
("| Use a subject line meaningful to you and us to track the bug.");
End_Line;
Write_Str
("| Include the entire contents of this bug " &
"box and the ASIS debug info");
End_Line;
Write_Str ("| in the report.");
End_Line;
Write_Str
("| Include the exact list of the parameters of the ASIS queries ");
End_Line;
Write_Str
("| Asis.Implementation.Initialize and " &
"Asis.Ada_Environments.Associate");
End_Line;
Write_Str
("| from the ASIS application for which the bug is detected");
End_Line;
Write_Str
("| Also include sources listed below in gnatchop format");
End_Line;
Write_Str
("| (concatenated together with no headers between files).");
End_Line;
if not Is_FSF_Version then
Write_Str ("| Use plain ASCII or MIME attachment.");
End_Line;
end if;
Write_Str
("| NOTE: ASIS bugs may be submitted to asis-report@adacore.com");
End_Line;
-- Complete output of bug box
Write_Char ('+');
Repeat_Char ('=', 76, '+');
Write_Eol;
Write_Eol;
-- Argument debug image(s)
if not Is_Nil (Arg_Element) or else
not Is_Nil (Arg_CU) or else
not Is_Nil (Arg_Line)
then
Write_Str ("The debug image(s) of the argument(s) of the call");
Write_Eol;
if not (Is_Nil (Arg_Element_2) and then Is_Nil (Arg_CU_2)) then
Write_Str ("***First argument***");
Write_Eol;
end if;
Write_Str (Debug_Buffer (1 .. Debug_Buffer_Len));
Write_Eol;
Write_Eol;
if not Is_Nil (Arg_Element_2) then
Debug_String (Arg_Element_2, No_Abort => True);
elsif not Is_Nil (Arg_CU_2) then
Debug_String (Arg_CU_2, No_Abort => True);
end if;
if not (Is_Nil (Arg_Element_2) and then Is_Nil (Arg_CU_2)) then
Write_Str ("***Second argument***");
Write_Eol;
Write_Str (Debug_Buffer (1 .. Debug_Buffer_Len));
Write_Eol;
Write_Eol;
end if;
if not Is_Nil (Arg_Line) then
if not Is_Nil (Arg_Element) then
Write_Str ("***Line argument***");
Write_Eol;
end if;
if Recursion_Count >= Max_Recursions_Allowed and then
Debug_Flag_I
then
-- There is a real possibility that we can not output the
-- debug image of the argument line because of the bug being
-- reported:
Write_Str ("Line image can not be reported ");
Write_Str ("because of the internal error");
Write_Eol;
Write_Eol;
else
Write_Str (To_String (Debug_Image (Arg_Line)));
Write_Eol;
Write_Eol;
end if;
end if;
if not Is_Nil (Arg_Span) then
if not Is_Nil (Arg_Element) then
Write_Str ("***Span argument***");
Write_Eol;
end if;
Write_Str ("First_Line =>");
Write_Str (Arg_Span.First_Line'Img);
Write_Eol;
Write_Str ("First_Column =>");
Write_Str (Arg_Span.First_Column'Img);
Write_Eol;
Write_Str ("Last_Line =>");
Write_Str (Arg_Span.Last_Line'Img);
Write_Eol;
Write_Str ("Last_Column =>");
Write_Str (Arg_Span.Last_Column'Img);
Write_Eol;
Write_Eol;
end if;
end if;
Write_Str ("Please include these source files with error report");
Write_Eol;
Write_Str ("Note that list may not be accurate in some cases, ");
Write_Eol;
Write_Str ("so please double check that the problem can still ");
Write_Eol;
Write_Str ("be reproduced with the set of files listed.");
Write_Eol;
Write_Eol;
if Generate_Bug_Box then
for U in Main_Unit .. Last_Unit loop
begin
if not Is_Internal_File_Name
(File_Name (Source_Index (U)))
then
Write_Name (Full_File_Name (Source_Index (U)));
Write_Eol;
end if;
-- No point in double bug box if we blow up trying to print
-- the list of file names! Output informative msg and quit.
exception
when others =>
Write_Str ("list may be incomplete");
exit;
end;
end loop;
end if;
Write_Eol;
Set_Standard_Output;
if Keep_Going then
-- Raise ASIS_Failed and go ahead (the Diagnosis is already formed)
Status_Indicator := Unhandled_Exception_Error;
Recursion_Count := Recursion_Count - 1;
raise ASIS_Failed;
else
OS_Exit (1);
end if;
exception
when ASIS_Failed =>
raise;
when Internal_Ex : others =>
Write_Eol;
Write_Str ("The diagnostis can not be completed because of " &
"the following error:");
Write_Eol;
Write_Str (Exception_Name (Ex));
Write_Char (' ');
Write_Str (Exception_Message (Ex));
Write_Eol;
Close_Str;
Add_Str ("The diagnostis can not be completed because of " &
"the following error:");
Close_Str;
Add_Str (Exception_Name (Ex));
Add (" ");
Add_Str (Exception_Message (Ex));
Add_Str (Exception_Information (Internal_Ex));
Set_Standard_Output;
if Keep_Going then
Status_Indicator := Unhandled_Exception_Error;
-- Debug_Flag_I := Skip_Span_In_Debug_Image;
raise ASIS_Failed;
else
OS_Exit (1);
end if;
end Report_ASIS_Bug;
----------------------------
-- Reset_Diagnosis_Buffer --
----------------------------
procedure Reset_Diagnosis_Buffer is
begin
Diagnosis_Len := 0;
Current_Pos := 0;
end Reset_Diagnosis_Buffer;
-----------------------------
-- Raise_ASIS_Failed (new) --
-----------------------------
procedure Raise_ASIS_Failed
(Diagnosis : String;
Argument : Asis.Element := Nil_Element;
Stat : Asis.Errors.Error_Kinds := Internal_Error;
Bool_Par : Boolean := False;
Internal_Bug : Boolean := True)
is
begin
Diagnosis_Len := 0;
if Internal_Bug then
Add ("Internal implementation error: ");
end if;
Add (Diagnosis);
if Bool_Par then
Add (LT & "(Boolean parameter is TRUE)");
end if;
if not Is_Nil (Argument) then
Add (LT & "when processing ");
Debug_String (Argument);
Add (Debug_Buffer (1 .. Debug_Buffer_Len));
end if;
Status_Indicator := Stat;
raise ASIS_Failed;
end Raise_ASIS_Failed;
-------------------------------------
-- Raise_ASIS_Failed_In_Traversing --
-------------------------------------
procedure Raise_ASIS_Failed_In_Traversing
(Start_Element : Asis.Element;
Failure_At : Asis.Element;
Pre_Op : Boolean;
Exception_Info : String)
is
begin
Diagnosis_Len := 0;
Add ("Traversal failure. Tarversal started at:" & LT);
Debug_String (Start_Element);
Add (Debug_Buffer (1 .. Debug_Buffer_Len) & LT);
if Pre_Op then
Add ("Pre-operation");
else
Add ("Post-operation");
end if;
Add (" failed at:" & LT);
Debug_String (Failure_At);
Add (Debug_Buffer (1 .. Debug_Buffer_Len));
Add (LT & Exception_Info);
Status_Indicator := Unhandled_Exception_Error;
raise ASIS_Failed;
end Raise_ASIS_Failed_In_Traversing;
---------------------------------------------------------------
procedure Raise_ASIS_Inappropriate_Compilation_Unit
(Diagnosis : String) is
begin
Set_Error_Status (Status => Value_Error,
Diagnosis => "Inappropriate Unit Kind in "
& Diagnosis);
raise ASIS_Inappropriate_Compilation_Unit;
end Raise_ASIS_Inappropriate_Compilation_Unit;
----------------------------------------------------------------------
procedure Raise_ASIS_Inappropriate_Element
(Diagnosis : String;
Wrong_Kind : Internal_Element_Kinds;
Status : Error_Kinds := Value_Error) is
begin
Set_Error_Status (Status => Status,
Diagnosis => "Inappropriate Element Kind in " &
Diagnosis &
" (" & Wrong_Kind'Img & ")");
raise ASIS_Inappropriate_Element;
end Raise_ASIS_Inappropriate_Element;
----------------------------------------------------------------------
procedure Raise_ASIS_Inappropriate_Line_Number
(Diagnosis : String;
Status : Error_Kinds := Value_Error) is
begin
Set_Error_Status (Status => Status,
Diagnosis => "Inappropriate Lines/Span Kind in "
& Diagnosis);
raise ASIS_Inappropriate_Line_Number;
end Raise_ASIS_Inappropriate_Line_Number;
----------------------------------------------------------------------
procedure Not_Implemented_Yet (Diagnosis : String) is
begin
Set_Error_Status (Status => Not_Implemented_Error,
Diagnosis => "Not Implemented Query:" & LT
& Diagnosis);
raise ASIS_Failed;
end Not_Implemented_Yet;
--------------------------------------------------------------------
procedure Set_Error_Status
(Status : Error_Kinds := Not_An_Error;
Diagnosis : String := Nil_Asis_String)
is
begin
if Status = Not_An_Error and then
Diagnosis /= Nil_Asis_String
then
Status_Indicator := Internal_Error;
Diagnosis_Len := Incorrect_Setting_Len + ASIS_Line_Terminator_Len;
Diagnosis_Buffer (1 .. Diagnosis_Len)
:= Incorrect_Setting & ASIS_Line_Terminator;
raise ASIS_Failed;
end if;
Status_Indicator := Status;
Diagnosis_Len := Diagnosis'Length;
Diagnosis_Buffer (1 .. Diagnosis_Len) := Diagnosis;
end Set_Error_Status;
procedure Set_Error_Status_Internal
(Status : Error_Kinds := Not_An_Error;
Diagnosis : String := Nil_Asis_String;
Query : String := Nil_Asis_String)
is
begin
Set_Error_Status
(Status => Status,
Diagnosis => Diagnosis & Query);
end Set_Error_Status_Internal;
----------------------------------------------------------------------
--------------------------
-- Add_Call_Information --
--------------------------
procedure Add_Call_Information
(Outer_Call : String;
Argument : Asis.Element := Nil_Element;
Bool_Par : Boolean := False)
is
begin
Add (LT & "called in " & Outer_Call);
if Bool_Par then
Add (LT & "(Boolean parameter is TRUE)");
end if;
if not Is_Nil (Argument) then
Add (LT & "with the argument : ");
Debug_String (Argument);
Add (Debug_Buffer (1 .. Debug_Buffer_Len));
end if;
end Add_Call_Information;
end A4G.Vcheck;
|
-----------------------------------------------------------------------
-- wiki-parsers-html -- Wiki HTML parser
-- Copyright (C) 2015, 2016, 2018, 2020, 2021 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Interfaces;
with Wiki.Helpers;
with Wiki.Parsers.Html.Entities;
package body Wiki.Parsers.Html is
-- Parse an HTML attribute
procedure Parse_Attribute_Name (P : in out Parser;
Name : in out Wiki.Strings.BString);
-- Parse a HTML/XML comment to strip it.
procedure Parse_Comment (P : in out Parser);
-- Parse a simple DOCTYPE declaration and ignore it.
procedure Parse_Doctype (P : in out Parser);
procedure Collect_Attributes (P : in out Parser);
function Is_Letter (C : in Wiki.Strings.WChar) return Boolean;
function From_Hex (Value : in String) return Wiki.Strings.WChar;
procedure Collect_Attribute_Value (P : in out Parser;
Value : in out Wiki.Strings.BString);
function Is_Letter (C : in Wiki.Strings.WChar) return Boolean is
begin
return C > ' ' and C /= ':' and C /= '>' and C /= ''' and C /= '"'
and C /= '/' and C /= '=' and C /= '<';
end Is_Letter;
-- ------------------------------
-- Parse an HTML attribute
-- ------------------------------
procedure Parse_Attribute_Name (P : in out Parser;
Name : in out Wiki.Strings.BString) is
C : Wiki.Strings.WChar;
begin
Skip_Spaces (P);
while not P.Is_Eof loop
Peek (P, C);
if not Is_Letter (C) then
Put_Back (P, C);
return;
end if;
Wiki.Strings.Wide_Wide_Builders.Append (Name, C);
end loop;
end Parse_Attribute_Name;
procedure Collect_Attribute_Value (P : in out Parser;
Value : in out Wiki.Strings.BString) is
C : Wiki.Strings.WChar;
Token : Wiki.Strings.WChar;
begin
Peek (P, Token);
if Wiki.Helpers.Is_Space_Or_Newline (Token) then
Skip_Spaces (P);
Peek (P, Token);
if Token /= ''' and Token /= '"' then
Put_Back (P, Token);
return;
end if;
elsif Token = '>' then
Put_Back (P, Token);
return;
end if;
if Token /= ''' and Token /= '"' then
Wiki.Strings.Wide_Wide_Builders.Append (Value, Token);
while not P.Is_Eof loop
Peek (P, C);
if C = ''' or C = '"' or C = ' ' or C = '=' or C = '>' or C = '<' or C = '`' then
Put_Back (P, C);
return;
end if;
Wiki.Strings.Wide_Wide_Builders.Append (Value, C);
end loop;
else
while not P.Is_Eof loop
Peek (P, C);
if C = Token then
return;
end if;
Wiki.Strings.Wide_Wide_Builders.Append (Value, C);
end loop;
end if;
end Collect_Attribute_Value;
-- ------------------------------
-- Parse a list of HTML attributes up to the first '>'.
-- attr-name
-- attr-name=
-- attr-name=value
-- attr-name='value'
-- attr-name="value"
-- <name name='value' ...>
-- ------------------------------
procedure Collect_Attributes (P : in out Parser) is
procedure Append_Attribute (Name : in Wiki.Strings.WString);
C : Wiki.Strings.WChar;
Name : Wiki.Strings.BString (64);
Value : Wiki.Strings.BString (256);
procedure Append_Attribute (Name : in Wiki.Strings.WString) is
procedure Attribute_Value (Value : in Wiki.Strings.WString);
procedure Attribute_Value (Value : in Wiki.Strings.WString) is
begin
Attributes.Append (P.Attributes, Name, Value);
end Attribute_Value;
procedure Attribute_Value is
new Wiki.Strings.Wide_Wide_Builders.Get (Attribute_Value);
pragma Inline (Attribute_Value);
begin
Attribute_Value (Value);
end Append_Attribute;
pragma Inline (Append_Attribute);
procedure Append_Attribute is
new Wiki.Strings.Wide_Wide_Builders.Get (Append_Attribute);
begin
Wiki.Attributes.Clear (P.Attributes);
while not P.Is_Eof loop
Parse_Attribute_Name (P, Name);
Skip_Spaces (P);
Peek (P, C);
if C = '>' or C = '<' or C = '/' then
Put_Back (P, C);
exit;
end if;
if C = '=' then
Collect_Attribute_Value (P, Value);
Append_Attribute (Name);
Wiki.Strings.Wide_Wide_Builders.Clear (Name);
Wiki.Strings.Wide_Wide_Builders.Clear (Value);
elsif Wiki.Strings.Wide_Wide_Builders.Length (Name) > 0 then
Put_Back (P, C);
Append_Attribute (Name);
Wiki.Strings.Wide_Wide_Builders.Clear (Name);
end if;
end loop;
-- Add any pending attribute.
if Wiki.Strings.Wide_Wide_Builders.Length (Name) > 0 then
Append_Attribute (Name);
end if;
end Collect_Attributes;
-- ------------------------------
-- Parse a HTML/XML comment to strip it.
-- ------------------------------
procedure Parse_Comment (P : in out Parser) is
C : Wiki.Strings.WChar;
begin
Peek (P, C);
while not P.Is_Eof loop
Peek (P, C);
if C = '-' then
declare
Count : Natural := 1;
begin
Peek (P, C);
while not P.Is_Eof and C = '-' loop
Peek (P, C);
Count := Count + 1;
end loop;
exit when C = '>' and Count >= 2;
end;
end if;
end loop;
end Parse_Comment;
-- ------------------------------
-- Parse a simple DOCTYPE declaration and ignore it.
-- ------------------------------
procedure Parse_Doctype (P : in out Parser) is
C : Wiki.Strings.WChar;
begin
while not P.Is_Eof loop
Peek (P, C);
exit when C = '>';
end loop;
end Parse_Doctype;
-- ------------------------------
-- Parse a HTML element <XXX attributes>
-- or parse an end of HTML element </XXX>
-- ------------------------------
procedure Parse_Element (P : in out Parser) is
C : Wiki.Strings.WChar;
procedure Add_Element (Token : in Wiki.Strings.WString);
procedure Add_Element (Token : in Wiki.Strings.WString) is
Tag : Wiki.Html_Tag;
begin
Tag := Wiki.Find_Tag (Token);
if C = '/' then
Skip_Spaces (P);
Peek (P, C);
if C /= '>' then
Put_Back (P, C);
end if;
Flush_Text (P);
if Tag = Wiki.UNKNOWN_TAG then
if Token = "noinclude" then
P.Context.Is_Hidden := not P.Context.Is_Included;
elsif Token = "includeonly" then
P.Context.Is_Hidden := P.Context.Is_Included;
end if;
else
End_Element (P, Tag);
end if;
else
Collect_Attributes (P);
Peek (P, C);
if C = '/' then
Peek (P, C);
if C = '>' then
Start_Element (P, Tag, P.Attributes);
End_Element (P, Tag);
return;
end if;
elsif C /= '>' then
Put_Back (P, C);
end if;
if Tag = UNKNOWN_TAG then
if Token = "noinclude" then
P.Context.Is_Hidden := P.Context.Is_Included;
elsif Token = "includeonly" then
P.Context.Is_Hidden := not P.Context.Is_Included;
end if;
else
Start_Element (P, Tag, P.Attributes);
end if;
end if;
end Add_Element;
pragma Inline (Add_Element);
procedure Add_Element is
new Wiki.Strings.Wide_Wide_Builders.Get (Add_Element);
pragma Inline (Add_Element);
Name : Wiki.Strings.BString (64);
begin
Peek (P, C);
if C = '!' then
Peek (P, C);
if C = '-' then
Parse_Comment (P);
else
Parse_Doctype (P);
end if;
return;
end if;
if C /= '/' then
Put_Back (P, C);
end if;
Parse_Attribute_Name (P, Name);
Add_Element (Name);
end Parse_Element;
use Interfaces;
function From_Hex (C : in Character) return Interfaces.Unsigned_8 is
(if C >= '0' and C <= '9' then Character'Pos (C) - Character'Pos ('0')
elsif C >= 'A' and C <= 'F' then Character'Pos (C) - Character'Pos ('A') + 10
elsif C >= 'a' and C <= 'f' then Character'Pos (C) - Character'Pos ('a') + 10
else raise Constraint_Error);
function From_Hex (Value : in String) return Wiki.Strings.WChar is
Result : Interfaces.Unsigned_32 := 0;
begin
for C of Value loop
Result := Interfaces.Shift_Left (Result, 4);
Result := Result + Interfaces.Unsigned_32 (From_Hex (C));
end loop;
return Wiki.Strings.WChar'Val (Result);
end From_Hex;
-- ------------------------------
-- Parse an HTML entity such as and replace it with the corresponding code.
-- ------------------------------
procedure Parse_Entity (P : in out Parser;
Token : in Wiki.Strings.WChar) is
pragma Unreferenced (Token);
Name : String (1 .. 10);
Len : Natural := 0;
High : Natural := Wiki.Parsers.Html.Entities.Keywords'Last;
Low : Natural := Wiki.Parsers.Html.Entities.Keywords'First;
Pos : Natural;
C : Wiki.Strings.WChar;
begin
while Len < Name'Last loop
Peek (P, C);
exit when C = ';' or else P.Is_Eof;
Len := Len + 1;
Name (Len) := Wiki.Strings.To_Char (C);
end loop;
while Low <= High loop
Pos := (Low + High) / 2;
if Wiki.Parsers.Html.Entities.Keywords (Pos).all = Name (1 .. Len) then
Parse_Text (P, Entities.Mapping (Pos));
return;
elsif Entities.Keywords (Pos).all < Name (1 .. Len) then
Low := Pos + 1;
else
High := Pos - 1;
end if;
end loop;
if Len > 0 and then Name (Name'First) = '#' then
if Name (Name'First + 1) >= '0' and then Name (Name'First + 1) <= '9' then
begin
C := Wiki.Strings.WChar'Val (Natural'Value (Name (Name'First + 1 .. Len)));
Parse_Text (P, C);
return;
exception
when Constraint_Error =>
null;
end;
elsif Name (Name'First + 1) = 'x' then
begin
C := From_Hex (Name (Name'First + 2 .. Len));
Parse_Text (P, C);
return;
exception
when Constraint_Error =>
null;
end;
end if;
end if;
-- The HTML entity is not recognized: we must treat it as plain wiki text.
Parse_Text (P, '&');
for I in 1 .. Len loop
Parse_Text (P, Wiki.Strings.To_WChar (Name (I)));
end loop;
if Len > 0 and then Len < Name'Last and then C = ';' then
Parse_Text (P, ';');
end if;
end Parse_Entity;
end Wiki.Parsers.Html;
|
--
--
-- **********************************
-- * *
-- * T e x t *
-- * *
-- * Input / Output Package *
-- * *
-- * and other *
-- * *
-- * Predefined Units *
-- * *
-- * *
-- * ADA Project *
-- * Courant Institute *
-- * New York University *
-- * 251 Mercer Street, *
-- * New York, NY 10012 *
-- * *
-- **********************************
--
--
--
pragma page;
-- This file contains several of the predefined Ada package spec-
-- ifications. They do not actually implement the package's
-- operations, which are coded in the implementation language C,
-- but they provide an interface to them through the standard
-- procedure/function calling mechanism. The predefined packages are:
--
-- . The SYSTEM package.
--
-- . The IO_EXCEPTIONS package.
--
-- . The generic SEQUENTIAL_IO package.
--
-- . The generic DIRECT_IO package.
--
-- . The TEXT_IO package.
--
-- . The CALENDAR package and the predefined subprograms
-- UNCHECKED_CONVERSION and UNCHECKED_DEALLOCATION.
--
--
pragma page;
package SYSTEM is
type NAME is (ELXSI_BSD, ELXSI_ENIX, PC_DOS,
SUN_UNIX, VAX_UNIX, VAX_VMS) ;
SYSTEM_NAME : constant NAME := SUN_UNIX;
STORAGE_UNIT : constant := 32;
MEMORY_SIZE : constant := 2**16 - 1;
-- System Dependent Named Numbers:
MIN_INT : constant := -2**31;
MAX_INT : constant := 2**31-1;
MAX_DIGITS : constant := 6;
MAX_MANTISSA : constant := 31;
FINE_DELTA : constant := 2.0**(-30);
TICK : constant := 0.01;
-- Other System Dependent Declarations
subtype PRIORITY is INTEGER range 1 .. 4;
type SEGMENT_TYPE is new INTEGER range 0..255;
type OFFSET_TYPE is new INTEGER range 0..32767;
type ADDRESS is record
SEGMENT : SEGMENT_TYPE := SEGMENT_TYPE'LAST;
OFFSET : OFFSET_TYPE := OFFSET_TYPE'LAST;
end record;
SYSTEM_ERROR : exception;
end SYSTEM;
package IO_EXCEPTIONS is
STATUS_ERROR : exception;
MODE_ERROR : exception;
NAME_ERROR : exception;
USE_ERROR : exception;
DEVICE_ERROR : exception;
END_ERROR : exception;
DATA_ERROR : exception;
LAYOUT_ERROR : exception;
end IO_EXCEPTIONS;
pragma page;
with IO_EXCEPTIONS;
generic
type ELEMENT_TYPE is private;
package SEQUENTIAL_IO is
type FILE_TYPE is limited private;
type FILE_MODE is (IN_FILE, OUT_FILE);
-- File management
procedure CREATE (FILE : in out FILE_TYPE;
MODE : in FILE_MODE := OUT_FILE;
NAME : in STRING := "";
FORM : in STRING := "");
pragma IO_interface(CREATE,SIO_CREATE,ELEMENT_TYPE);
procedure OPEN (FILE : in out FILE_TYPE;
MODE : in FILE_MODE;
NAME : in STRING;
FORM : in STRING := "");
pragma IO_interface(OPEN,SIO_OPEN,ELEMENT_TYPE);
procedure CLOSE (FILE : in out FILE_TYPE);
pragma IO_interface(CLOSE,SIO_CLOSE);
procedure DELETE (FILE : in out FILE_TYPE);
pragma IO_interface(DELETE,SIO_DELETE);
procedure RESET (FILE : in out FILE_TYPE; MODE : in FILE_MODE);
pragma IO_interface(RESET,SIO_RESET_MODE,ELEMENT_TYPE);
procedure RESET (FILE : in out FILE_TYPE);
pragma IO_interface(RESET,SIO_RESET,ELEMENT_TYPE);
function MODE (FILE : in FILE_TYPE) return FILE_MODE;
pragma IO_interface(MODE,SIO_MODE);
function NAME (FILE : in FILE_TYPE) return STRING;
pragma IO_interface(NAME,SIO_NAME);
function FORM (FILE : in FILE_TYPE) return STRING;
pragma IO_interface(FORM,SIO_FORM);
function IS_OPEN (FILE : in FILE_TYPE) return BOOLEAN;
pragma IO_interface(IS_OPEN,SIO_IS_OPEN);
-- Input and Output Operations:
procedure READ (FILE : in FILE_TYPE; ITEM : out ELEMENT_TYPE);
pragma IO_interface(READ,SIO_READ,ELEMENT_TYPE);
procedure WRITE (FILE : in FILE_TYPE; ITEM : in ELEMENT_TYPE);
pragma IO_interface(WRITE,SIO_WRITE,ELEMENT_TYPE);
function END_OF_FILE(FILE : in FILE_TYPE) return BOOLEAN;
pragma IO_interface(END_OF_FILE,SIO_END_OF_FILE);
-- Exceptions:
STATUS_ERROR : exception renames IO_EXCEPTIONS.STATUS_ERROR;
MODE_ERROR : exception renames IO_EXCEPTIONS.MODE_ERROR;
NAME_ERROR : exception renames IO_EXCEPTIONS.NAME_ERROR;
USE_ERROR : exception renames IO_EXCEPTIONS.USE_ERROR;
DEVICE_ERROR : exception renames IO_EXCEPTIONS.DEVICE_ERROR;
END_ERROR : exception renames IO_EXCEPTIONS.END_ERROR;
DATA_ERROR : exception renames IO_EXCEPTIONS.DATA_ERROR;
private
UNINITIALIZED: constant := 0;
type FILE_TYPE is record
FILENUM: INTEGER := UNINITIALIZED;
end record;
end SEQUENTIAL_IO;
package body SEQUENTIAL_IO is
end SEQUENTIAL_IO;
pragma page;
with IO_EXCEPTIONS;
generic
type ELEMENT_TYPE is private;
package DIRECT_IO is
type FILE_TYPE is limited private;
type FILE_MODE is (IN_FILE, INOUT_FILE, OUT_FILE);
type COUNT is range 0 .. INTEGER'LAST;
subtype POSITIVE_COUNT is COUNT range 1 .. COUNT'LAST;
-- File management
procedure CREATE (FILE : in out FILE_TYPE;
MODE : in FILE_MODE := INOUT_FILE;
NAME : in STRING := "";
FORM : in STRING := "");
pragma IO_interface(CREATE,DIO_CREATE,ELEMENT_TYPE);
procedure OPEN (FILE : in out FILE_TYPE;
MODE : in FILE_MODE;
NAME : in STRING;
FORM : in STRING := "");
pragma IO_interface(OPEN,DIO_OPEN,ELEMENT_TYPE);
procedure CLOSE (FILE : in out FILE_TYPE);
pragma IO_interface(CLOSE,DIO_CLOSE);
procedure DELETE (FILE : in out FILE_TYPE);
pragma IO_interface(DELETE,DIO_DELETE);
procedure RESET (FILE : in out FILE_TYPE; MODE : in FILE_MODE);
pragma IO_interface(RESET,DIO_RESET_MODE,ELEMENT_TYPE);
procedure RESET (FILE : in out FILE_TYPE);
pragma IO_interface(RESET,DIO_RESET,ELEMENT_TYPE);
function MODE (FILE : in FILE_TYPE) return FILE_MODE;
pragma IO_interface(MODE,DIO_MODE);
function NAME (FILE : in FILE_TYPE) return STRING;
pragma IO_interface(NAME,DIO_NAME);
function FORM (FILE : in FILE_TYPE) return STRING;
pragma IO_interface(FORM,DIO_FORM);
function IS_OPEN (FILE : in FILE_TYPE) return BOOLEAN;
pragma IO_interface(IS_OPEN,DIO_IS_OPEN);
-- Input and Output Operations:
procedure READ (FILE : in FILE_TYPE; ITEM : out ELEMENT_TYPE);
pragma IO_interface(READ,DIO_READ,ELEMENT_TYPE);
procedure READ (FILE : in FILE_TYPE; ITEM : out ELEMENT_TYPE;
FROM : in POSITIVE_COUNT);
pragma IO_interface(READ,DIO_READ_FROM,ELEMENT_TYPE);
procedure WRITE (FILE : in FILE_TYPE; ITEM : in ELEMENT_TYPE);
pragma IO_interface(WRITE,DIO_WRITE,ELEMENT_TYPE);
procedure WRITE (FILE : in FILE_TYPE; ITEM : in ELEMENT_TYPE;
TO : in POSITIVE_COUNT);
pragma IO_interface(WRITE,DIO_WRITE_TO,ELEMENT_TYPE);
procedure SET_INDEX(FILE : in FILE_TYPE; TO :in POSITIVE_COUNT);
pragma IO_interface(SET_INDEX,DIO_SET_INDEX);
function INDEX (FILE : in FILE_TYPE) return POSITIVE_COUNT;
pragma IO_interface(INDEX,DIO_INDEX);
function SIZE (FILE : in FILE_TYPE) return COUNT;
pragma IO_interface(SIZE,DIO_SIZE);
function END_OF_FILE(FILE : in FILE_TYPE) return BOOLEAN;
pragma IO_interface(END_OF_FILE,DIO_END_OF_FILE);
-- Exceptions:
STATUS_ERROR : exception renames IO_EXCEPTIONS.STATUS_ERROR;
MODE_ERROR : exception renames IO_EXCEPTIONS.MODE_ERROR;
NAME_ERROR : exception renames IO_EXCEPTIONS.NAME_ERROR;
USE_ERROR : exception renames IO_EXCEPTIONS.USE_ERROR;
DEVICE_ERROR : exception renames IO_EXCEPTIONS.DEVICE_ERROR;
END_ERROR : exception renames IO_EXCEPTIONS.END_ERROR;
DATA_ERROR : exception renames IO_EXCEPTIONS.DATA_ERROR;
private
UNINITIALIZED: constant := 0;
type FILE_TYPE is record
FILENUM: INTEGER := UNINITIALIZED;
end record;
end DIRECT_IO;
package body DIRECT_IO is
end DIRECT_IO;
pragma page;
with IO_EXCEPTIONS;
package TEXT_IO is
type FILE_TYPE is limited private;
type FILE_MODE is (IN_FILE, OUT_FILE);
type COUNT is range 0 .. 32767;
subtype POSITIVE_COUNT IS COUNT range 1 .. COUNT'LAST;
UNBOUNDED : constant COUNT := 0; -- line and page length
subtype FIELD is INTEGER range 0 .. 100 ;
subtype NUMBER_BASE is INTEGER range 2 .. 16;
type TYPE_SET is (LOWER_CASE, UPPER_CASE);
-- File Management
procedure CREATE (FILE : in out FILE_TYPE;
MODE : in FILE_MODE := OUT_FILE;
NAME : in STRING := "";
FORM : in STRING := "");
pragma IO_interface(CREATE,TIO_CREATE);
procedure OPEN (FILE : in out FILE_TYPE;
MODE : in FILE_MODE;
NAME : in STRING;
FORM : in STRING := "");
pragma IO_interface(OPEN,TIO_OPEN);
procedure CLOSE (FILE : in out FILE_TYPE);
pragma IO_interface(CLOSE,TIO_CLOSE);
procedure DELETE (FILE : in out FILE_TYPE);
pragma IO_interface(DELETE,TIO_DELETE);
procedure RESET (FILE : in out FILE_TYPE; MODE : in FILE_MODE);
pragma IO_interface(RESET,TIO_RESET_MODE);
procedure RESET (FILE : in out FILE_TYPE);
pragma IO_interface(RESET,TIO_RESET);
function MODE (FILE : in FILE_TYPE) return FILE_MODE;
pragma IO_interface(MODE,TIO_MODE);
function NAME (FILE : in FILE_TYPE) return STRING;
pragma IO_interface(NAME,TIO_NAME);
function FORM (FILE : in FILE_TYPE) return STRING;
pragma IO_interface(FORM,TIO_FORM);
function IS_OPEN (FILE : in FILE_TYPE) return BOOLEAN;
pragma IO_interface(IS_OPEN,TIO_IS_OPEN);
-- Control of default input and output files
procedure SET_INPUT (FILE : in FILE_TYPE);
pragma IO_interface(SET_INPUT,SET_INPUT);
procedure SET_OUTPUT (FILE : in FILE_TYPE);
pragma IO_interface(SET_OUTPUT,SET_OUTPUT);
function STANDARD_INPUT return FILE_TYPE;
pragma IO_interface(STANDARD_INPUT,STANDARD_INPUT);
function STANDARD_OUTPUT return FILE_TYPE;
pragma IO_interface(STANDARD_OUTPUT,STANDARD_OUTPUT);
function CURRENT_INPUT return FILE_TYPE;
pragma IO_interface(CURRENT_INPUT,CURRENT_INPUT);
function CURRENT_OUTPUT return FILE_TYPE;
pragma IO_interface(CURRENT_OUTPUT,CURRENT_OUTPUT);
-- Specification of line and page lengths
procedure SET_LINE_LENGTH (FILE : in FILE_TYPE; TO : in COUNT);
pragma IO_interface(SET_LINE_LENGTH,SET_LINE_LENGTH_FILE);
procedure SET_LINE_LENGTH (TO : in COUNT); -- default output file
pragma IO_interface(SET_LINE_LENGTH,SET_LINE_LENGTH);
procedure SET_PAGE_LENGTH (FILE : in FILE_TYPE; TO : in COUNT);
pragma IO_interface(SET_PAGE_LENGTH,SET_PAGE_LENGTH_FILE);
procedure SET_PAGE_LENGTH (TO : in COUNT); -- default output file
pragma IO_interface(SET_PAGE_LENGTH,SET_PAGE_LENGTH);
function LINE_LENGTH (FILE : in FILE_TYPE) return COUNT;
pragma IO_interface(LINE_LENGTH,LINE_LENGTH_FILE);
function LINE_LENGTH return COUNT; -- default output file
pragma IO_interface(LINE_LENGTH,LINE_LENGTH);
function PAGE_LENGTH (FILE : in FILE_TYPE) return COUNT;
pragma IO_interface(PAGE_LENGTH,PAGE_LENGTH_FILE);
function PAGE_LENGTH return COUNT; -- default output file
pragma IO_interface(PAGE_LENGTH,PAGE_LENGTH);
-- Column, Line and Page Control
procedure NEW_LINE (FILE : in FILE_TYPE; SPACING : in POSITIVE_COUNT := 1);
pragma IO_interface(NEW_LINE,NEW_LINE_FILE);
procedure NEW_LINE (SPACING : in POSITIVE_COUNT := 1);
pragma IO_interface(NEW_LINE,NEW_LINE);
procedure SKIP_LINE (FILE : in FILE_TYPE; SPACING : in POSITIVE_COUNT := 1);
pragma IO_interface(SKIP_LINE,SKIP_LINE_FILE);
procedure SKIP_LINE (SPACING : in POSITIVE_COUNT := 1);
pragma IO_interface(SKIP_LINE,SKIP_LINE);
function END_OF_LINE (FILE : in FILE_TYPE) return BOOLEAN;
pragma IO_interface(END_OF_LINE,END_OF_LINE_FILE);
function END_OF_LINE return BOOLEAN; -- default input file
pragma IO_interface(END_OF_LINE,END_OF_LINE);
procedure NEW_PAGE (FILE : in FILE_TYPE);
pragma IO_interface(NEW_PAGE,NEW_PAGE_FILE);
procedure NEW_PAGE; -- default output file
pragma IO_interface(NEW_PAGE,NEW_PAGE);
procedure SKIP_PAGE (FILE : in FILE_TYPE);
pragma IO_interface(SKIP_PAGE,SKIP_PAGE_FILE);
procedure SKIP_PAGE; -- default input file
pragma IO_interface(SKIP_PAGE,SKIP_PAGE);
function END_OF_PAGE (FILE : in FILE_TYPE) return BOOLEAN;
pragma IO_interface(END_OF_PAGE,END_OF_PAGE_FILE);
function END_OF_PAGE return BOOLEAN;
pragma IO_interface(END_OF_PAGE,END_OF_PAGE);
function END_OF_FILE (FILE : in FILE_TYPE) return BOOLEAN;
pragma IO_interface(END_OF_FILE,TIO_END_OF_FILE_FILE);
function END_OF_FILE return BOOLEAN;
pragma IO_interface(END_OF_FILE,TIO_END_OF_FILE);
procedure SET_COL(FILE : in FILE_TYPE; TO : in POSITIVE_COUNT);
pragma IO_interface(SET_COL,SET_COL_FILE);
procedure SET_COL(TO : in POSITIVE_COUNT); -- default output file
pragma IO_interface(SET_COL,SET_COL);
procedure SET_LINE(FILE : in FILE_TYPE; TO : in POSITIVE_COUNT);
pragma IO_interface(SET_LINE,SET_LINE_FILE);
procedure SET_LINE(TO : in POSITIVE_COUNT); -- default output file
pragma IO_interface(SET_LINE,SET_LINE);
function COL(FILE : in FILE_TYPE) return POSITIVE_COUNT;
pragma IO_interface(COL,COL_FILE);
function COL return POSITIVE_COUNT; -- default output file
pragma IO_interface(COL,COL);
function LINE(FILE : in FILE_TYPE) return POSITIVE_COUNT;
pragma IO_interface(LINE,LINE_FILE);
function LINE return POSITIVE_COUNT; -- default output file
pragma IO_interface(LINE,LINE);
function PAGE(FILE : in FILE_TYPE) return POSITIVE_COUNT;
pragma IO_interface(PAGE,PAGE_FILE);
function PAGE return POSITIVE_COUNT; -- default output file
pragma IO_interface(PAGE,PAGE);
-- Character Input-Output
procedure GET (FILE : in FILE_TYPE; ITEM : out CHARACTER);
pragma IO_interface(GET,GET_CHAR_FILE_ITEM);
procedure GET (ITEM : out CHARACTER);
pragma IO_interface(GET,GET_CHAR_ITEM);
procedure PUT (FILE : in FILE_TYPE; ITEM : in CHARACTER);
pragma IO_interface(PUT,PUT_CHAR_FILE_ITEM);
procedure PUT (ITEM : in CHARACTER);
pragma IO_interface(PUT,PUT_CHAR_ITEM);
-- String Input-Output
procedure GET (FILE : in FILE_TYPE; ITEM : out STRING);
pragma IO_interface(GET,GET_STRING_FILE_ITEM);
procedure GET (ITEM : out STRING);
pragma IO_interface(GET,GET_STRING_ITEM);
procedure PUT (FILE : in FILE_TYPE; ITEM : in STRING);
pragma IO_interface(PUT,PUT_STRING_FILE_ITEM);
procedure PUT (ITEM : in STRING);
pragma IO_interface(PUT,PUT_STRING_ITEM);
procedure GET_LINE (FILE : in FILE_TYPE; ITEM : out STRING;
LAST : out NATURAL);
pragma IO_interface(GET_LINE,GET_LINE_FILE);
procedure GET_LINE (ITEM : out STRING; LAST : out NATURAL);
pragma IO_interface(GET_LINE,GET_LINE);
procedure PUT_LINE (FILE : in FILE_TYPE; ITEM : in STRING);
pragma IO_interface(PUT_LINE,PUT_LINE_FILE);
procedure PUT_LINE (ITEM : in STRING);
pragma IO_interface(PUT_LINE,PUT_LINE);
-- Generic package for Input-Output of Integer Types
generic
type NUM is range <>;
package INTEGER_IO is
DEFAULT_WIDTH : FIELD := NUM'WIDTH;
DEFAULT_BASE : NUMBER_BASE := 10;
procedure GET (FILE : in FILE_TYPE; ITEM : out NUM;
WIDTH : in FIELD := 0);
pragma IO_interface(GET,GET_INTEGER_FILE_ITEM,NUM);
procedure GET (ITEM : out NUM; WIDTH : in FIELD := 0);
pragma IO_interface(GET,GET_INTEGER_ITEM,NUM);
procedure PUT (FILE : in FILE_TYPE;
ITEM : in NUM;
WIDTH : in FIELD := DEFAULT_WIDTH;
BASE : in NUMBER_BASE := DEFAULT_BASE);
pragma IO_interface(PUT,PUT_INTEGER_FILE_ITEM,NUM);
procedure PUT (ITEM : in NUM;
WIDTH : in FIELD := DEFAULT_WIDTH;
BASE : in NUMBER_BASE := DEFAULT_BASE);
pragma IO_interface(PUT,PUT_INTEGER_ITEM,NUM);
procedure GET (FROM : in STRING; ITEM: out NUM; LAST: out POSITIVE);
pragma IO_interface(GET,GET_INTEGER_STRING,NUM);
procedure PUT (TO : out STRING;
ITEM : in NUM;
BASE : in NUMBER_BASE := DEFAULT_BASE);
pragma IO_interface(PUT,PUT_INTEGER_STRING,NUM);
end INTEGER_IO;
-- Generic packages for Input-Output of Real Types
generic
type NUM is digits <>;
package FLOAT_IO is
DEFAULT_FORE : FIELD := 2;
DEFAULT_AFT : FIELD := NUM'DIGITS-1;
DEFAULT_EXP : FIELD := 3;
procedure GET (FILE : in FILE_TYPE; ITEM : out NUM;
WIDTH : in FIELD := 0);
pragma IO_interface(GET,GET_FLOAT_FILE_ITEM,NUM);
procedure GET (ITEM : out NUM; WIDTH : in FIELD := 0);
pragma IO_interface(GET,GET_FLOAT_ITEM,NUM);
procedure PUT (FILE : in FILE_TYPE;
ITEM : in NUM;
FORE : in FIELD := DEFAULT_FORE;
AFT : in FIELD := DEFAULT_AFT;
EXP : in FIELD := DEFAULT_EXP);
pragma IO_interface(PUT,PUT_FLOAT_FILE_ITEM,NUM);
procedure PUT (ITEM : in NUM;
FORE : in FIELD := DEFAULT_FORE;
AFT : in FIELD := DEFAULT_AFT;
EXP : in FIELD := DEFAULT_EXP);
pragma IO_interface(PUT,PUT_FLOAT_ITEM,NUM);
procedure GET (FROM : in STRING; ITEM: out NUM; LAST: out POSITIVE);
pragma IO_interface(GET,GET_FLOAT_STRING,NUM);
procedure PUT (TO : out STRING;
ITEM : in NUM;
AFT : in FIELD := DEFAULT_AFT;
EXP : in FIELD := DEFAULT_EXP);
pragma IO_interface(PUT,PUT_FLOAT_STRING,NUM);
end FLOAT_IO;
generic
type NUM is delta <>;
package FIXED_IO is
DEFAULT_FORE : FIELD := NUM'FORE;
DEFAULT_AFT : FIELD := NUM'AFT;
DEFAULT_EXP : FIELD := 0;
procedure GET (FILE : in FILE_TYPE; ITEM : out NUM;
WIDTH : in FIELD := 0);
pragma IO_interface(GET,GET_FIXED_FILE_ITEM,NUM);
procedure GET (ITEM : out NUM; WIDTH : in FIELD := 0);
pragma IO_interface(GET,GET_FIXED_ITEM,NUM);
procedure PUT (FILE : in FILE_TYPE;
ITEM : in NUM;
FORE : in FIELD := DEFAULT_FORE;
AFT : in FIELD := DEFAULT_AFT;
EXP : in FIELD := DEFAULT_EXP);
pragma IO_interface(PUT,PUT_FIXED_FILE_ITEM,NUM);
procedure PUT (ITEM : in NUM;
FORE : in FIELD := DEFAULT_FORE;
AFT : in FIELD := DEFAULT_AFT;
EXP : in FIELD := DEFAULT_EXP);
pragma IO_interface(PUT,PUT_FIXED_ITEM,NUM);
procedure GET (FROM : in STRING; ITEM: out NUM; LAST: out POSITIVE);
pragma IO_interface(GET,GET_FIXED_STRING,NUM);
procedure PUT (TO : out STRING;
ITEM : in NUM;
AFT : in FIELD := DEFAULT_AFT;
EXP : in FIELD := DEFAULT_EXP);
pragma IO_interface(PUT,PUT_FIXED_STRING,NUM);
end FIXED_IO;
-- Generic package for Input-Output of Enumeration Types
generic
type ENUM is (<>);
package ENUMERATION_IO is
DEFAULT_WIDTH : FIELD := 0;
DEFAULT_SETTING : TYPE_SET := UPPER_CASE;
procedure GET (FILE : in FILE_TYPE; ITEM : out ENUM);
pragma IO_interface(GET,GET_ENUM_FILE_ITEM,ENUM);
procedure GET (ITEM : out ENUM);
pragma IO_interface(GET,GET_ENUM_ITEM,ENUM);
procedure PUT (FILE : in FILE_TYPE;
ITEM : in ENUM;
WIDTH : in FIELD := DEFAULT_WIDTH;
SET : in TYPE_SET := DEFAULT_SETTING);
pragma IO_interface(PUT,PUT_ENUM_FILE_ITEM,ENUM);
procedure PUT (ITEM : in ENUM;
WIDTH : in FIELD := DEFAULT_WIDTH;
SET : in TYPE_SET := DEFAULT_SETTING);
pragma IO_interface(PUT,PUT_ENUM_ITEM,ENUM);
procedure GET(FROM : in STRING; ITEM: out ENUM; LAST: out POSITIVE);
pragma IO_interface(GET,GET_ENUM_STRING,ENUM);
procedure PUT (TO : out STRING;
ITEM : in ENUM;
SET : in TYPE_SET := DEFAULT_SETTING);
pragma IO_interface(PUT,PUT_ENUM_STRING,ENUM);
end ENUMERATION_IO;
-- Exceptions:
--
-- These are the exceptions whose names are visible to the
-- calling environment.
STATUS_ERROR : exception renames IO_EXCEPTIONS.STATUS_ERROR;
MODE_ERROR : exception renames IO_EXCEPTIONS.MODE_ERROR;
NAME_ERROR : exception renames IO_EXCEPTIONS.NAME_ERROR;
USE_ERROR : exception renames IO_EXCEPTIONS.USE_ERROR;
DEVICE_ERROR : exception renames IO_EXCEPTIONS.DEVICE_ERROR;
END_ERROR : exception renames IO_EXCEPTIONS.END_ERROR;
DATA_ERROR : exception renames IO_EXCEPTIONS.DATA_ERROR;
LAYOUT_ERROR : exception renames IO_EXCEPTIONS.LAYOUT_ERROR;
private
UNINITIALIZED: constant := 0;
type FILE_TYPE is record
FILENUM: INTEGER := UNINITIALIZED;
end record;
end TEXT_IO;
package body TEXT_IO is
package body INTEGER_IO is
end INTEGER_IO;
package body FLOAT_IO is
end FLOAT_IO;
package body FIXED_IO is
end FIXED_IO;
package body ENUMERATION_IO is
end ENUMERATION_IO;
end TEXT_IO;
pragma page;
-- Predefined library units: calendar & generic subprograms
package CALENDAR is
type TIME is private;
subtype YEAR_NUMBER is INTEGER range 1901 .. 2099;
subtype MONTH_NUMBER is INTEGER range 1 .. 12;
subtype DAY_NUMBER is INTEGER range 1 .. 31;
subtype DAY_DURATION is DURATION range 0.0 .. 86_400.0;
function CLOCK return TIME;
pragma IO_interface(CLOCK,CLOCK);
function YEAR (DATE : TIME) return YEAR_NUMBER;
pragma IO_interface(YEAR,YEAR);
function MONTH (DATE : TIME) return MONTH_NUMBER;
pragma IO_interface(MONTH,MONTH);
function DAY (DATE : TIME) return DAY_NUMBER;
pragma IO_interface(DAY,DAY);
function SECONDS(DATE : TIME) return DAY_DURATION;
pragma IO_interface(SECONDS,SECONDS);
procedure SPLIT (DATE : in TIME;
YEAR : out YEAR_NUMBER;
MONTH : out MONTH_NUMBER;
DAY : out DAY_NUMBER;
SECONDS : out DAY_DURATION);
pragma IO_interface(SPLIT,SPLIT);
function TIME_OF(YEAR : YEAR_NUMBER;
MONTH : MONTH_NUMBER;
DAY : DAY_NUMBER;
SECONDS : DAY_DURATION := 0.0) return TIME;
pragma IO_interface(TIME_OF,TIME_OF);
function "+" (LEFT : TIME; RIGHT : DURATION) return TIME;
pragma IO_interface("+",ADD_TIME_DUR);
function "+" (LEFT : DURATION; RIGHT : TIME) return TIME;
pragma IO_interface("+",ADD_DUR_TIME);
function "-" (LEFT : TIME; RIGHT : DURATION) return TIME;
pragma IO_interface("-",SUB_TIME_DUR);
function "-" (LEFT : TIME; RIGHT : TIME) return DURATION;
pragma IO_interface("-",SUB_TIME_TIME,DURATION);
function "<" (LEFT, RIGHT : TIME) return BOOLEAN;
pragma IO_interface("<",LT_TIME);
function "<=" (LEFT, RIGHT : TIME) return BOOLEAN;
pragma IO_interface("<=",LE_TIME);
function ">" (LEFT, RIGHT : TIME) return BOOLEAN;
pragma IO_interface(">",GT_TIME);
function ">=" (LEFT, RIGHT : TIME) return BOOLEAN;
pragma IO_interface(">=",GE_TIME);
TIME_ERROR : exception; -- can be raised by TIME_OF, "+", "-"
private
type TIME is record
Y_N : YEAR_NUMBER;
M_N : MONTH_NUMBER;
D_N : DAY_NUMBER;
D_D : DURATION;
end record;
end CALENDAR;
package body CALENDAR is
end CALENDAR;
pragma page;
generic
type OBJECT is limited private;
type NAME is access OBJECT;
procedure UNCHECKED_DEALLOCATION(X : in out NAME);
procedure UNCHECKED_DEALLOCATION(X : in out NAME) is
begin
X := null;
end;
generic
type SOURCE is limited private;
type TARGET is limited private;
function UNCHECKED_CONVERSION(S : SOURCE) return TARGET;
function UNCHECKED_CONVERSION(S : SOURCE) return TARGET is
NOT_USED_ANYWAY: TARGET;
begin
raise PROGRAM_ERROR;
return NOT_USED_ANYWAY;
end;
|
-- C45282B.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 IN AND NOT IN ARE EVALUATED CORRECTLY FOR :
-- D) ACCESS TO RECORD, PRIVATE, AND LIMITED PRIVATE TYPES WITH
-- DISCRIMINANTS (WITH AND WITHOUT DEFAULT VALUES), WHERE THE
-- TYPE MARK DENOTES A CONSTRAINED AND UNCONSTRAINED TYPE;
-- E) ACCESS TO TASK TYPES.
-- TBN 8/8/86
WITH REPORT; USE REPORT;
PROCEDURE C45282B IS
SUBTYPE INT IS INTEGER RANGE 1 .. 5;
PACKAGE P IS
TYPE PRI_REC1 (D : INT) IS PRIVATE;
TYPE PRI_REC2 (D : INT := 2) IS PRIVATE;
FUNCTION INIT_PREC1 (A : INT; B : STRING) RETURN PRI_REC1;
FUNCTION INIT_PREC2 (A : INT; B : STRING) RETURN PRI_REC2;
TYPE LIM_REC1 (D : INT) IS LIMITED PRIVATE;
TYPE ACC_LIM1 IS ACCESS LIM_REC1;
SUBTYPE ACC_SUB_LIM1 IS ACC_LIM1 (2);
PROCEDURE ASSIGN_LIM1 (A : ACC_LIM1; B : INT; C : STRING);
TYPE LIM_REC2 (D : INT := 2) IS LIMITED PRIVATE;
TYPE ACC_LIM2 IS ACCESS LIM_REC2;
SUBTYPE ACC_SUB_LIM2 IS ACC_LIM2 (2);
PROCEDURE ASSIGN_LIM2 (A : ACC_LIM2; B : INT; C : STRING);
PRIVATE
TYPE PRI_REC1 (D : INT) IS
RECORD
STR : STRING (1 .. D);
END RECORD;
TYPE PRI_REC2 (D : INT := 2) IS
RECORD
STR : STRING (1 .. D);
END RECORD;
TYPE LIM_REC1 (D : INT) IS
RECORD
STR : STRING (1 .. D);
END RECORD;
TYPE LIM_REC2 (D : INT := 2) IS
RECORD
STR : STRING (1 .. D);
END RECORD;
END P;
USE P;
TYPE DIS_REC1 (D : INT) IS
RECORD
STR : STRING (1 .. D);
END RECORD;
TYPE DIS_REC2 (D : INT := 5) IS
RECORD
STR : STRING (D .. 8);
END RECORD;
TYPE ACC1_REC1 IS ACCESS DIS_REC1;
SUBTYPE ACC2_REC1 IS ACC1_REC1 (2);
TYPE ACC1_REC2 IS ACCESS DIS_REC2;
SUBTYPE ACC2_REC2 IS ACC1_REC2 (2);
REC1 : ACC1_REC1;
REC2 : ACC2_REC1;
REC3 : ACC1_REC2;
REC4 : ACC2_REC2;
TYPE ACC_PREC1 IS ACCESS PRI_REC1;
SUBTYPE ACC_SREC1 IS ACC_PREC1 (2);
REC5 : ACC_PREC1;
REC6 : ACC_SREC1;
TYPE ACC_PREC2 IS ACCESS PRI_REC2;
SUBTYPE ACC_SREC2 IS ACC_PREC2 (2);
REC7 : ACC_PREC2;
REC8 : ACC_SREC2;
REC9 : ACC_LIM1;
REC10 : ACC_SUB_LIM1;
REC11 : ACC_LIM2;
REC12 : ACC_SUB_LIM2;
TASK TYPE T IS
ENTRY E (X : INTEGER);
END T;
TASK BODY T IS
BEGIN
ACCEPT E (X : INTEGER) DO
IF X /= IDENT_INT(1) THEN
FAILED ("INCORRECT VALUE PASSED TO TASK");
END IF;
END E;
END T;
PACKAGE BODY P IS
FUNCTION INIT_PREC1 (A : INT; B : STRING) RETURN PRI_REC1 IS
REC : PRI_REC1 (A);
BEGIN
REC := (A, B);
RETURN (REC);
END INIT_PREC1;
FUNCTION INIT_PREC2 (A : INT; B : STRING) RETURN PRI_REC2 IS
REC : PRI_REC2;
BEGIN
REC := (A, B);
RETURN (REC);
END INIT_PREC2;
PROCEDURE ASSIGN_LIM1 (A : ACC_LIM1; B : INT; C : STRING) IS
BEGIN
A.ALL := (B, C);
END ASSIGN_LIM1;
PROCEDURE ASSIGN_LIM2 (A : ACC_LIM2; B : INT; C : STRING) IS
BEGIN
A.ALL := (B, C);
END ASSIGN_LIM2;
END P;
BEGIN
TEST ("C45282B", "CHECK THAT IN AND NOT IN ARE EVALUATED FOR " &
"ACCESS TYPES TO RECORD TYPES, PRIVATE TYPES, " &
"LIMITED PRIVATE TYPES WITH DISCRIMINANTS, AND " &
"TASK TYPES");
-- CASE D
------------------------------------------------------------------------
IF REC1 NOT IN ACC1_REC1 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 1");
END IF;
IF REC1 IN ACC2_REC1 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 2");
END IF;
IF REC2 NOT IN ACC1_REC1 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 3");
END IF;
REC1 := NEW DIS_REC1'(5, "12345");
IF REC1 IN ACC1_REC1 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 4");
END IF;
IF REC1 IN ACC2_REC1 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 5");
END IF;
REC2 := NEW DIS_REC1'(2, "HI");
IF REC2 IN ACC1_REC1 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 6");
END IF;
------------------------------------------------------------------------
IF REC3 IN ACC1_REC2 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 7");
END IF;
IF REC3 NOT IN ACC2_REC2 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 8");
END IF;
IF REC4 IN ACC1_REC2 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 9");
END IF;
REC3 := NEW DIS_REC2'(5, "5678");
IF REC3 IN ACC1_REC2 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 10");
END IF;
IF REC3 IN ACC2_REC2 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 11");
END IF;
REC4 := NEW DIS_REC2'(2, "2345678");
IF REC4 IN ACC1_REC2 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 12");
END IF;
IF REC4 NOT IN ACC2_REC2 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 13");
END IF;
------------------------------------------------------------------------
IF REC5 NOT IN ACC_PREC1 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 14");
END IF;
IF REC5 NOT IN ACC_SREC1 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 15");
END IF;
IF REC6 NOT IN ACC_PREC1 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 16");
END IF;
REC5 := NEW PRI_REC1'(INIT_PREC1 (5, "12345"));
IF REC5 IN ACC_PREC1 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 17");
END IF;
IF REC5 IN ACC_SREC1 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 18");
END IF;
REC6 := NEW PRI_REC1'(INIT_PREC1 (2, "HI"));
IF REC6 IN ACC_PREC1 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 19");
END IF;
------------------------------------------------------------------------
IF REC7 NOT IN ACC_PREC2 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 20");
END IF;
IF REC7 NOT IN ACC_SREC2 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 21");
END IF;
IF REC8 NOT IN ACC_PREC2 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 22");
END IF;
REC7 := NEW PRI_REC2'(INIT_PREC2 (5, "12345"));
IF REC7 IN ACC_PREC2 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 23");
END IF;
IF REC7 IN ACC_SREC2 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 24");
END IF;
REC8 := NEW PRI_REC2'(INIT_PREC2 (2, "HI"));
IF REC8 IN ACC_PREC2 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 25");
END IF;
------------------------------------------------------------------------
IF REC9 NOT IN ACC_LIM1 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 26");
END IF;
IF REC9 NOT IN ACC_SUB_LIM1 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 27");
END IF;
IF REC10 NOT IN ACC_LIM1 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 28");
END IF;
REC9 := NEW LIM_REC1 (5);
ASSIGN_LIM1 (REC9, 5, "12345");
IF REC9 IN ACC_LIM1 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 29");
END IF;
IF REC9 IN ACC_SUB_LIM1 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 30");
END IF;
REC10 := NEW LIM_REC1 (2);
ASSIGN_LIM1 (REC10, 2, "12");
IF REC10 IN ACC_LIM1 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 31");
END IF;
------------------------------------------------------------------------
IF REC11 NOT IN ACC_LIM2 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 32");
END IF;
IF REC11 NOT IN ACC_SUB_LIM2 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 33");
END IF;
IF REC12 NOT IN ACC_LIM2 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 34");
END IF;
REC11 := NEW LIM_REC2;
IF REC11 NOT IN ACC_SUB_LIM2 THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 35");
END IF;
ASSIGN_LIM2 (REC11, 2, "12");
IF REC11 IN ACC_LIM2 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 36");
END IF;
IF REC11 IN ACC_SUB_LIM2 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 37");
END IF;
REC12 := NEW LIM_REC2;
ASSIGN_LIM2 (REC12, 2, "12");
IF REC12 IN ACC_LIM2 THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 38");
END IF;
-- CASE E
------------------------------------------------------------------------
DECLARE
TYPE ACC_TASK IS ACCESS T;
T1 : ACC_TASK;
BEGIN
IF T1 NOT IN ACC_TASK THEN
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 39");
END IF;
T1 := NEW T;
IF T1 IN ACC_TASK THEN
NULL;
ELSE
FAILED ("INCORRECT RESULTS FOR ACCESS TYPES - 38");
END IF;
T1.E (1);
END;
RESULT;
END C45282B;
|
package GLOBE_3D.Options is
-- Visual checks:
show_normals : constant Boolean := False;
show_portals : constant Boolean := False;
filter_portal_depth : constant Boolean := False;
-- Formal checks:
full_check_objects : constant Boolean := False;
strict_geometry : constant Boolean := False;
function Is_debug_mode return Boolean;
arrow_inflator : constant := 10.0;
end GLOBE_3D.Options;
|
-- Procedure multi_var_deviates_demo_1, test and demonstrate random deviates.
--
-- Uses a giant array, so may need to set stacksize large at (eg) Linux
-- prompt, as in: ulimit -s unlimited
with Text_io; Use Text_io;
with Disorderly.Basic_Rand; use Disorderly.Basic_Rand;
with Disorderly.Basic_Rand.Clock_Entropy;
with Disorderly.Basic_Rand.Deviates;
-- To use Random.Deviates, you need to "with" Disorderly.Basic_Rand.
-- which provides the random num generator (which you just ignore),
-- and the essential Reset (Stream_x, Seeds ...)
-- which allows you to create multiple independent streams
-- of Random nums.
--
-- Below we use the Clock version of Reset to get the initial state (Stream).
-- The clock provides the Seeds. You can get all the streams you want:
--
-- Disorderly.Basic_Rand.Clock_Entropy.Reset (Stream_1);
-- Disorderly.Basic_Rand.Clock_Entropy.Reset (Stream_2);
-- Disorderly.Basic_Rand.Clock_Entropy.Reset (Stream_3);
procedure multi_var_deviates_demo_1 is
type Integer64 is range -2**63+1..2**63-1;
type Real is digits 15;
package dev is new Disorderly.Basic_Rand.Deviates (Real);
use dev;
Stream_1 : State; -- exported by Disorderly.Basic_Rand
Delta_X_stnd : constant Real := 0.01;
-- If you change parameters in the distributions, may have make this much
-- smaller. (For example, the Beta distribution becomes very sharply
-- peaked if aa<1, or if aa>>1; same with bb. Same with Gamma distribution
-- if you make s<1; etc. For example, with Beta distribution b = .9, needed
-- Delta_X_stnd = 0.00004, and HalfBins = 4.0 / Delta_X_stnd)
HalfBins : constant Integer64 := Integer64 (25.0 / Delta_X_stnd);
Delta_X : Real := Delta_X_stnd;
-- Delta_X must be 1 for Poisson, Binomial, Neg_Binomial!
-- For Multivariate_Normal:
Index_First : constant Positive := 1;
Index_Last : constant Positive := 2;
Mean : constant Vector(Index_First..Index_Last) := (1.0, 2.0);
X_vec : Vector(Index_First..Index_Last);
Covariance : Matrix(Mean'Range, Mean'Range) := (others => (others => 1.0));
LU_of_Covariance : Matrix(Mean'Range, Mean'Range) := (others => (others => 0.0));
MVN_Init : MV_Normal_Initializer;
Sample_Size : Integer64;
subtype Bin_Range is Integer64 range -HalfBins+1 .. HalfBins;
type Data is array(Bin_Range, Bin_Range) of Real;
Histogram : Data;
Distribution : Data;
Norm, Sum : Real := 0.0;
X, D : Real := 0.0;
begin
-- Init covariance matrix for multivariate normal.
-- Try to make a positive definite matrix:
X := 0.12345;
for i in Index_First .. Index_Last loop
for j in Index_First .. Index_Last loop
X := X + 0.12345;
Covariance(i,j) := X;
end loop;
end loop;
for i in Index_First .. Index_Last loop
for j in i .. Index_Last loop
Covariance(i,j) := Covariance(j,i);
end loop;
end loop;
for i in Index_First .. Index_Last loop
Covariance(i,i) := Covariance(i,i) + 3.0 * Real (i);
end loop;
-- For this we need the Cholesky (LU) Decomposition of the Covariance matrix:
Choleski_Decompose
(Covariance,
LU_of_Covariance); -- Choleski Decomp of Covariance matrix.
-- use Calendar to get initial state: Stream_1:
Disorderly.Basic_Rand.Clock_Entropy.Reset (Stream_1);
-- Next make normalized distribution:
Distribution := (others => (others => 0.0));
for Bin_id_2 in Bin_Range loop
for Bin_id_1 in Bin_Range loop
X_vec(1) := Delta_X * (Real (Bin_id_1) - 0.5);
X_vec(2) := Delta_X * (Real (Bin_id_2) - 0.5);
D := Multivariate_Normal_Probability (Mean, LU_of_Covariance, X_Vec);
Distribution (Bin_id_1, Bin_id_2) := D;
end loop;
end loop;
new_line(2);
put ("Presently calculating variance of distance between the observed");
new_line(1);
put ("distribution of a sample of N random deviates, and the exact");
new_line(1);
put ("distribution they are meant to obey:");
new_line(1);
Delta_X := Delta_X_stnd;
Sample_Size := 2_000; -- initial sample size is 10x this.
for Resized_Sample_Size in 1 .. 16 loop
Histogram := (others => (others => 0.0));
Sample_Size := Sample_Size * 10;
new_line(2);
put ("Using Sample size N = ");
put (Integer64'Image (Sample_Size));
for i in Integer64 range 1 .. Sample_Size loop
Get_Multivariate_Normal (Mean, LU_of_Covariance, MVN_Init, Stream_1, X_vec);
declare
Bin_id_1 : constant Integer64 := Integer64 (X_vec(1) / Delta_X + 0.5);
Bin_id_2 : constant Integer64 := Integer64 (X_vec(2) / Delta_X + 0.5);
begin
if Bin_id_1 in Bin_Range then
if Bin_id_2 in Bin_Range then
Histogram(Bin_id_1, Bin_id_2) := Histogram(Bin_id_1, Bin_id_2) + 1.0;
end if;
end if;
end;
end loop;
-- Normalize the curves. (Normalize the curves
-- the same way that the distribution curves generated below
-- are normalized: integrate over X with dX.) Here
-- dX is Delta_X, so multiply by Delta_X at the end.
Norm := 0.0;
for Bin_id_2 in Bin_Range loop
for Bin_id_1 in Bin_Range loop
Norm := Norm + Histogram(Bin_id_1, Bin_id_2);
end loop;
end loop;
Norm := Norm*Delta_X**2;
for Bin_id_2 in Bin_Range loop
for Bin_id_1 in Bin_Range loop
Histogram(Bin_id_1, Bin_id_2) := Histogram(Bin_id_1, Bin_id_2) / Norm;
end loop;
end loop;
Sum := 0.0;
for Bin_id_2 in Bin_Range loop
for Bin_id_1 in Bin_Range loop
Sum := Sum + (Distribution(Bin_id_1, Bin_id_2)-Histogram(Bin_id_1, Bin_id_2))**2;
end loop;
end loop;
Sum := Sum*Delta_X**2;
new_line;
put ("Variance (standard deviation squared) =");
put (" "); put (Real'Image (Sum));
new_line;
put ("Stnd_Deviation**2 should go approximately as 1/N.");
new_line;
put ("The actual value of the variance will fluctuate statistically.");
new_line;
put ("It will run as long as you let it. Control-c to escape");
new_line;
end loop;
end;
|
package GESTE_Fonts.FreeMonoOblique8pt7b is
Font : constant Bitmap_Font_Ref;
private
FreeMonoOblique8pt7bBitmaps : aliased constant Font_Bitmap := (
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#04#, 16#00#,
16#80#, 16#10#, 16#04#, 16#00#, 16#80#, 16#10#, 16#00#, 16#00#, 16#00#,
16#18#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#D8#, 16#12#, 16#02#, 16#40#, 16#48#, 16#02#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#48#, 16#0A#, 16#01#, 16#40#,
16#FC#, 16#0A#, 16#01#, 16#40#, 16#FE#, 16#09#, 16#01#, 16#40#, 16#28#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#0F#, 16#02#, 16#20#, 16#80#, 16#0E#, 16#00#, 16#20#, 16#02#,
16#10#, 16#83#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#E0#, 16#24#, 16#04#, 16#80#, 16#60#,
16#01#, 16#81#, 16#C0#, 16#5C#, 16#04#, 16#80#, 16#90#, 16#0C#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#0E#, 16#02#, 16#00#, 16#40#, 16#08#, 16#01#, 16#00#, 16#54#, 16#13#,
16#02#, 16#40#, 16#36#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#30#, 16#04#, 16#00#, 16#80#, 16#10#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#,
16#00#, 16#40#, 16#10#, 16#02#, 16#00#, 16#40#, 16#10#, 16#02#, 16#00#,
16#40#, 16#08#, 16#00#, 16#80#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#80#, 16#10#, 16#01#, 16#00#, 16#20#, 16#04#, 16#00#,
16#80#, 16#10#, 16#04#, 16#00#, 16#80#, 16#20#, 16#04#, 16#01#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#04#, 16#06#,
16#A0#, 16#38#, 16#06#, 16#01#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#80#, 16#10#, 16#04#, 16#07#, 16#F0#,
16#10#, 16#02#, 16#00#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#01#, 16#80#, 16#20#,
16#08#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#F0#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#C0#, 16#18#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#08#,
16#01#, 16#00#, 16#40#, 16#10#, 16#02#, 16#00#, 16#80#, 16#20#, 16#04#,
16#01#, 16#00#, 16#40#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#70#, 16#11#, 16#04#, 16#20#, 16#84#, 16#10#,
16#82#, 16#10#, 16#44#, 16#08#, 16#81#, 16#30#, 16#38#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#0C#,
16#02#, 16#80#, 16#20#, 16#04#, 16#00#, 16#80#, 16#10#, 16#02#, 16#00#,
16#80#, 16#7E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#70#, 16#11#, 16#04#, 16#20#, 16#04#, 16#01#, 16#00#,
16#40#, 16#10#, 16#0C#, 16#02#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F8#, 16#01#, 16#00#,
16#20#, 16#04#, 16#07#, 16#00#, 16#20#, 16#02#, 16#00#, 16#82#, 16#10#,
16#3C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#18#, 16#06#, 16#01#, 16#40#, 16#28#, 16#09#, 16#02#, 16#20#,
16#88#, 16#1F#, 16#80#, 16#20#, 16#1E#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F8#, 16#10#, 16#02#, 16#00#,
16#B8#, 16#08#, 16#80#, 16#10#, 16#02#, 16#00#, 16#80#, 16#10#, 16#7C#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#1C#, 16#0C#, 16#02#, 16#00#, 16#40#, 16#17#, 16#03#, 16#10#, 16#42#,
16#08#, 16#41#, 16#10#, 16#1C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#FC#, 16#21#, 16#00#, 16#20#, 16#08#,
16#01#, 16#00#, 16#40#, 16#08#, 16#02#, 16#00#, 16#40#, 16#10#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#,
16#11#, 16#04#, 16#20#, 16#84#, 16#0F#, 16#03#, 16#20#, 16#84#, 16#10#,
16#82#, 16#10#, 16#3C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#70#, 16#11#, 16#04#, 16#20#, 16#84#, 16#09#,
16#81#, 16#D0#, 16#02#, 16#00#, 16#80#, 16#20#, 16#78#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#30#, 16#06#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#C0#, 16#18#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#30#, 16#0E#, 16#00#,
16#00#, 16#00#, 16#00#, 16#01#, 16#C0#, 16#30#, 16#0C#, 16#01#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#30#, 16#18#, 16#0C#, 16#06#, 16#00#, 16#60#, 16#03#, 16#00#, 16#10#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3F#, 16#C0#, 16#00#,
16#FE#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#00#,
16#20#, 16#03#, 16#00#, 16#10#, 16#0C#, 16#06#, 16#03#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#0F#, 16#02#, 16#20#, 16#04#, 16#00#, 16#80#, 16#60#, 16#10#,
16#00#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#11#, 16#04#, 16#20#, 16#9C#,
16#24#, 16#85#, 16#20#, 16#94#, 16#13#, 16#82#, 16#00#, 16#40#, 16#07#,
16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#3C#, 16#01#, 16#80#, 16#48#, 16#09#, 16#02#, 16#20#, 16#7C#, 16#10#,
16#84#, 16#11#, 16#C7#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#3F#, 16#04#, 16#20#, 16#84#, 16#10#,
16#83#, 16#E0#, 16#82#, 16#10#, 16#42#, 16#08#, 16#FE#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#,
16#86#, 16#31#, 16#02#, 16#20#, 16#04#, 16#00#, 16#80#, 16#10#, 16#02#,
16#08#, 16#3E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#3E#, 16#04#, 16#20#, 16#84#, 16#10#, 16#84#,
16#10#, 16#82#, 16#10#, 16#42#, 16#10#, 16#FC#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3F#, 16#84#,
16#10#, 16#80#, 16#12#, 16#03#, 16#C0#, 16#90#, 16#10#, 16#02#, 16#08#,
16#FE#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#3F#, 16#84#, 16#10#, 16#80#, 16#12#, 16#03#, 16#C0#,
16#90#, 16#10#, 16#02#, 16#00#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#86#, 16#10#,
16#82#, 16#20#, 16#04#, 16#00#, 16#8F#, 16#10#, 16#42#, 16#08#, 16#3E#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#39#, 16#84#, 16#20#, 16#84#, 16#10#, 16#83#, 16#F0#, 16#84#,
16#10#, 16#82#, 16#10#, 16#E7#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#80#, 16#10#,
16#04#, 16#00#, 16#80#, 16#10#, 16#02#, 16#00#, 16#80#, 16#7E#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#C0#, 16#20#, 16#04#, 16#00#, 16#80#, 16#20#, 16#84#, 16#10#,
16#82#, 16#20#, 16#78#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#39#, 16#C4#, 16#20#, 16#88#, 16#16#,
16#03#, 16#C0#, 16#88#, 16#10#, 16#82#, 16#10#, 16#E3#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3C#,
16#02#, 16#00#, 16#40#, 16#08#, 16#01#, 16#00#, 16#40#, 16#08#, 16#41#,
16#08#, 16#FF#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#60#, 16#CA#, 16#31#, 16#4A#, 16#29#, 16#45#,
16#50#, 16#92#, 16#20#, 16#44#, 16#09#, 16#E7#, 16#80#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#71#, 16#C6#,
16#10#, 16#C4#, 16#24#, 16#84#, 16#90#, 16#8A#, 16#11#, 16#42#, 16#30#,
16#E2#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#0E#, 16#06#, 16#21#, 16#02#, 16#20#, 16#44#, 16#08#,
16#82#, 16#10#, 16#42#, 16#10#, 16#3C#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3E#, 16#04#, 16#20#,
16#84#, 16#10#, 16#82#, 16#30#, 16#78#, 16#10#, 16#02#, 16#00#, 16#F0#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#0E#, 16#06#, 16#21#, 16#02#, 16#20#, 16#44#, 16#08#, 16#82#,
16#10#, 16#42#, 16#10#, 16#3C#, 16#07#, 16#21#, 16#18#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3F#, 16#04#, 16#20#, 16#84#,
16#10#, 16#83#, 16#E0#, 16#88#, 16#10#, 16#82#, 16#10#, 16#E1#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#0E#, 16#82#, 16#20#, 16#80#, 16#18#, 16#00#, 16#E0#, 16#02#, 16#10#,
16#42#, 16#10#, 16#7C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#3F#, 16#88#, 16#90#, 16#10#, 16#04#,
16#00#, 16#80#, 16#10#, 16#02#, 16#00#, 16#80#, 16#7C#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#79#,
16#C4#, 16#10#, 16#84#, 16#10#, 16#84#, 16#10#, 16#82#, 16#10#, 16#82#,
16#10#, 16#3C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#71#, 16#C4#, 16#10#, 16#84#, 16#10#, 16#82#,
16#20#, 16#48#, 16#05#, 16#00#, 16#C0#, 16#18#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#71#, 16#C8#,
16#11#, 16#12#, 16#26#, 16#45#, 16#50#, 16#AA#, 16#19#, 16#83#, 16#30#,
16#42#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#31#, 16#C4#, 16#20#, 16#48#, 16#06#, 16#00#, 16#80#,
16#28#, 16#09#, 16#02#, 16#10#, 16#E7#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#31#, 16#C4#, 16#20#,
16#48#, 16#0A#, 16#00#, 16#80#, 16#10#, 16#02#, 16#00#, 16#80#, 16#7C#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#1F#, 16#04#, 16#20#, 16#08#, 16#02#, 16#00#, 16#80#, 16#20#,
16#08#, 16#82#, 16#10#, 16#7E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#38#, 16#04#, 16#00#, 16#80#, 16#10#,
16#04#, 16#00#, 16#80#, 16#10#, 16#02#, 16#00#, 16#80#, 16#10#, 16#02#,
16#00#, 16#70#, 16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#00#, 16#80#,
16#10#, 16#02#, 16#00#, 16#20#, 16#04#, 16#00#, 16#80#, 16#10#, 16#01#,
16#00#, 16#20#, 16#04#, 16#00#, 16#40#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#E0#, 16#04#, 16#00#, 16#80#, 16#20#, 16#04#,
16#00#, 16#80#, 16#10#, 16#02#, 16#00#, 16#80#, 16#10#, 16#02#, 16#01#,
16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#0A#,
16#02#, 16#40#, 16#84#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#FC#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#80#, 16#08#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#78#, 16#01#, 16#03#, 16#E0#,
16#84#, 16#20#, 16#84#, 16#30#, 16#7B#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#00#, 16#20#, 16#04#, 16#00#,
16#B8#, 16#18#, 16#82#, 16#10#, 16#82#, 16#10#, 16#43#, 16#11#, 16#BC#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#7A#, 16#10#, 16#84#, 16#00#, 16#80#,
16#10#, 16#02#, 16#08#, 16#3E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#00#, 16#80#, 16#10#, 16#7C#,
16#11#, 16#84#, 16#10#, 16#82#, 16#10#, 16#82#, 16#30#, 16#3B#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#78#, 16#10#, 16#84#, 16#10#, 16#FE#, 16#10#,
16#02#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#1E#, 16#0C#, 16#01#, 16#00#, 16#FC#, 16#08#,
16#01#, 16#00#, 16#20#, 16#04#, 16#00#, 16#80#, 16#7E#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#76#, 16#11#, 16#84#, 16#10#, 16#84#, 16#10#, 16#82#,
16#30#, 16#3A#, 16#00#, 16#40#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#01#, 16#80#, 16#20#, 16#04#, 16#00#, 16#B8#, 16#18#, 16#82#,
16#10#, 16#82#, 16#10#, 16#82#, 16#10#, 16#E7#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#04#, 16#00#,
16#00#, 16#E0#, 16#04#, 16#00#, 16#80#, 16#10#, 16#02#, 16#00#, 16#80#,
16#7E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#10#, 16#02#, 16#00#, 16#00#, 16#F8#, 16#01#, 16#00#, 16#20#,
16#04#, 16#01#, 16#00#, 16#20#, 16#04#, 16#00#, 16#80#, 16#20#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#80#, 16#10#, 16#02#, 16#00#,
16#9C#, 16#12#, 16#02#, 16#80#, 16#60#, 16#12#, 16#02#, 16#20#, 16#C7#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#E0#, 16#04#, 16#00#, 16#80#, 16#20#, 16#04#, 16#00#, 16#80#, 16#10#,
16#02#, 16#00#, 16#80#, 16#7E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#6C#,
16#32#, 16#44#, 16#90#, 16#92#, 16#22#, 16#44#, 16#89#, 16#C9#, 16#80#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#01#, 16#B8#, 16#18#, 16#82#, 16#10#, 16#82#, 16#10#,
16#82#, 16#10#, 16#E7#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#78#, 16#10#,
16#84#, 16#10#, 16#82#, 16#10#, 16#42#, 16#10#, 16#3C#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#01#, 16#B8#, 16#28#, 16#86#, 16#10#, 16#82#, 16#10#, 16#43#,
16#10#, 16#9C#, 16#10#, 16#02#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#7B#, 16#11#, 16#84#,
16#10#, 16#82#, 16#10#, 16#42#, 16#30#, 16#3A#, 16#00#, 16#40#, 16#08#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#CE#, 16#0E#, 16#01#, 16#00#, 16#20#, 16#08#, 16#01#, 16#00#,
16#FC#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#7C#, 16#10#, 16#82#, 16#00#,
16#3C#, 16#10#, 16#82#, 16#10#, 16#7C#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#10#, 16#02#, 16#01#,
16#F8#, 16#10#, 16#02#, 16#00#, 16#40#, 16#08#, 16#01#, 16#00#, 16#3E#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#01#, 16#8C#, 16#10#, 16#82#, 16#10#, 16#84#,
16#10#, 16#82#, 16#10#, 16#3F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#CE#,
16#10#, 16#82#, 16#20#, 16#44#, 16#09#, 16#00#, 16#C0#, 16#18#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#01#, 16#86#, 16#20#, 16#84#, 16#90#, 16#B2#, 16#15#,
16#83#, 16#30#, 16#24#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#CE#, 16#11#,
16#01#, 16#40#, 16#10#, 16#0D#, 16#02#, 16#10#, 16#E7#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#01#, 16#C6#, 16#10#, 16#82#, 16#20#, 16#44#, 16#05#, 16#00#,
16#C0#, 16#10#, 16#02#, 16#00#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FC#, 16#11#, 16#00#,
16#40#, 16#10#, 16#04#, 16#03#, 16#10#, 16#7E#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#18#, 16#04#, 16#00#,
16#80#, 16#10#, 16#04#, 16#03#, 16#00#, 16#10#, 16#02#, 16#00#, 16#40#,
16#08#, 16#02#, 16#00#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#04#, 16#00#, 16#80#, 16#20#, 16#04#, 16#00#, 16#80#,
16#10#, 16#02#, 16#00#, 16#80#, 16#10#, 16#02#, 16#00#, 16#40#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#40#, 16#04#, 16#00#, 16#80#,
16#20#, 16#04#, 16#00#, 16#60#, 16#10#, 16#02#, 16#00#, 16#80#, 16#10#,
16#02#, 16#00#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#08#, 16#02#, 16#90#, 16#8C#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#);
Font_D : aliased constant Bitmap_Font :=
(
Bytes_Per_Glyph => 22,
Glyph_Width => 11,
Glyph_Height => 16,
Data => FreeMonoOblique8pt7bBitmaps'Access);
Font : constant Bitmap_Font_Ref := Font_D'Access;
end GESTE_Fonts.FreeMonoOblique8pt7b;
|
pragma License (Unrestricted);
-- runtime unit
package System.Startup is
pragma Preelaborate;
-- command arguments (initialize.c)
argc : Integer
with Export, Convention => C, External_Name => "gnat_argc";
argv : Address
with Export, Convention => C, External_Name => "gnat_argv";
envp : Address
with Export, Convention => C, External_Name => "gnat_envp";
-- command status (exit.c)
Exit_Status : Integer := 0
with Export, Convention => C, External_Name => "gnat_exit_status";
-- initialize system (initialize.c)
procedure Initialize (SEH : Address)
with Export, Convention => C, External_Name => "__gnat_initialize";
-- filled by gnatbind (init.c)
Main_Priority : Integer := -1
with Export, Convention => C, External_Name => "__gl_main_priority";
Main_CPU : Integer := -1
with Export, Convention => C, External_Name => "__gl_main_cpu";
Time_Slice_Value : Integer := -1
with Export, Convention => C, External_Name => "__gl_time_slice_val";
WC_Encoding : Character := 'n'
with Export, Convention => C, External_Name => "__gl_wc_encoding";
Locking_Policy : Character := ' '
with Export, Convention => C, External_Name => "__gl_locking_policy";
Queuing_Policy : Character := ' '
with Export, Convention => C, External_Name => "__gl_queuing_policy";
Task_Dispatching_Policy : Character := ' '
with Export,
Convention => C, External_Name => "__gl_task_dispatching_policy";
Priority_Specific_Dispatching : Address := Null_Address
with Export,
Convention => C,
External_Name => "__gl_priority_specific_dispatching";
Num_Specific_Dispatching : Integer := 0
with Export,
Convention => C, External_Name => "__gl_num_specific_dispatching";
Interrupt_States : Address := Null_Address
with Export, Convention => C, External_Name => "__gl_interrupt_states";
Num_Interrupt_States : Integer := 0
with Export,
Convention => C, External_Name => "__gl_num_interrupt_states";
Unreserve_All_Interrupts : Integer := 0
with Export,
Convention => C, External_Name => "__gl_unreserve_all_interrupts";
Detect_Blocking : Integer := 0
with Export, Convention => C, External_Name => "__gl_detect_blocking";
Default_Stack_Size : Integer := -1
with Export, Convention => C, External_Name => "__gl_default_stack_size";
Leap_Seconds_Support : Integer := 0
with Export,
Convention => C, External_Name => "__gl_leap_seconds_support";
Bind_Env_Addr : Address := Null_Address
with Export, Convention => C, External_Name => "__gl_bind_env_addr";
-- initialize Ada runtime (rtinit.c)
procedure Runtime_Initialize (Install_Handler : Integer) is null
with Export,
Convention => C, External_Name => "__gnat_runtime_initialize";
-- finalize Ada runtime 1 (rtfinal.c)
procedure Runtime_Finalize is null
with Export, Convention => C, External_Name => "__gnat_runtime_finalize";
-- finalize Ada runtime 2 (s-stalib.adb)
procedure AdaFinal is null
with Export,
Convention => C,
External_Name => "system__standard_library__adafinal";
-- finalize system (final.c)
procedure Finalize is null
with Export, Convention => C, External_Name => "__gnat_finalize";
-- finalize library-level controlled objects (s-soflin.ads)
type Finalize_Library_Objects_Handler is access procedure;
pragma Favor_Top_Level (Finalize_Library_Objects_Handler);
pragma Suppress (Access_Check, Finalize_Library_Objects_Handler);
Finalize_Library_Objects : Finalize_Library_Objects_Handler
with Export,
Convention => Ada, External_Name => "__gnat_finalize_library_objects";
pragma Suppress (Access_Check, Finalize_Library_Objects);
end System.Startup;
|
-- Some 2D GL utility functions based on GL, GLUT
with GL;
package GLUT_2D is
----------
-- Text --
----------
type Font_type is (
Screen_9_by_15,
Screen_8_by_13,
Times_Roman_10,
Times_Roman_24,
Helvetica_10,
Helvetica_12,
Helvetica_18
);
procedure Text_Output (
s : String;
font : Font_type
);
-- Text output from 2D, screen coordinates
procedure Text_output (
x, y : GL.Int;
main_size_x,
main_size_y : GL.Sizei;
s : String;
font : Font_type
);
-- Text output from 3D coordinates
procedure Text_output (
p : GL.Double_Vector_3D;
s : String;
font : Font_type
);
-----------
-- Image --
-----------
procedure Put_Image (
Image_ID : Integer;
x, y : GL.Int;
size_x,
size_y : GL.Int;
main_size_x,
main_size_y : GL.Sizei
);
end GLUT_2D;
|
--
-- 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.Strings.Fixed;
with Ada.Characters.Handling;
package body Auxiliary is
procedure Recreate
(File : in out File_Type;
Mode : in File_Mode;
File_Name : in String)
is
begin
Create (File, Mode, File_Name);
exception
when others =>
Open (File, Mode, File_Name);
end Recreate;
function To_Ada_Symbol (Text : in String) return String is
use Ada.Characters.Handling;
Result : String (Text'Range);
Start : Boolean := True;
begin
for I in Result'Range loop
if Start then
Result (I) := To_Upper (Text (I));
Start := False;
else
Result (I) := To_Lower (Text (I));
end if;
-- '_' leads to upper case
if Text (I) = '_' then
Start := True;
end if;
-- Replace '-' with '.' from GNAT style file names to child package names.
if Text (I) = '-' then
Result (I) := '.';
Start := True;
end if;
end loop;
return Result;
end To_Ada_Symbol;
function Is_Upper (C : in Character) return Boolean is
begin
case C is
when 'A' .. 'Z' =>
return True;
when others =>
return False;
end case;
end Is_Upper;
function Is_Lower (C : in Character) return Boolean is
begin
case C is
when 'a' .. 'z' =>
return True;
when others =>
return False;
end case;
end Is_Lower;
function Is_Alpha (C : in Character) return Boolean is
begin
case C is
when 'A' .. 'Z' =>
return True;
when 'a' .. 'z' =>
return True;
when others =>
return False;
end case;
end Is_Alpha;
function Is_Alnum (C : in Character) return Boolean
is
begin
return
C in 'a' .. 'z' or
C in 'A' .. 'Z' or
C in '0' .. '9';
end Is_Alnum;
----------------
-- Trim_Image --
----------------
function Trim_Image (Value : in Num) return String is
use Ada.Strings;
begin
return Fixed.Trim (Num'Image (Value), Left);
end Trim_Image;
------------------
-- Resize_Array --
------------------
-- generic
-- type Index_Type is (<>);
-- type Element_Type is private;
-- type Array_Type is array (Index_Type range <>) of Element_Type;
-- type Array_Access is access Array_Type;
procedure Resize_Array (Item : in out Array_Access;
New_Last : in Index_Type;
Default : in Element_Type)
is
begin
if New_Last > Item'Last then
declare
subtype New_Range is Index_Type range Item'First .. New_Last;
New_Item : constant Array_Access :=
new Array_Type'(New_Range => Default);
begin
New_Item (New_Range'Range) := Item.all;
Item := New_Item;
end;
elsif New_Last < Item'Last then
declare
subtype New_Range is Index_Type range Item'First .. New_Last;
New_Item : constant Array_Access :=
new Array_Type'(New_Range => Default);
begin
New_Item.all := Item (New_Range'Range);
Item := New_Item;
end;
else
null; -- Keep item
end if;
end Resize_Array;
end Auxiliary;
|
-- Copyright (c) Mark J. Kilgard, 1994.
-- Ported to Ada by Antonio F. Vargas
-- http://www.adapower.net/~avargas
-- mailto: avargas@adapower.net
-- /**
-- * (c) Copyright 1993, Silicon Graphics, Inc.
-- * ALL RIGHTS RESERVED
-- * Permission to use, copy, modify, and distribute this software for
-- * any purpose and without fee is hereby granted, provided that the above
-- * copyright notice appear in all copies and that both the copyright notice
-- * and this permission notice appear in supporting documentation, and that
-- * the name of Silicon Graphics, Inc. not be used in advertising
-- * or publicity pertaining to distribution of the software without specific,
-- * written prior permission.
-- *
-- * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
-- * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
-- * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
-- * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-- * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
-- * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
-- * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
-- * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
-- * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
-- * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
-- * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
-- * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
-- *
-- * US Government Users Restricted Rights
-- * Use, duplication, or disclosure by the Government is subject to
-- * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
-- * (c)(1)(ii) of the Rights in Technical Data and Computer Software
-- * clause at DFARS 252.227-7013 and/or in similar or successor
-- * clauses in the FAR or the DOD or NASA FAR Supplement.
-- * Unpublished-- rights reserved under the copyright laws of the
-- * United States. Contractor/manufacturer is Silicon Graphics,
-- * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
-- *
-- * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
-- /* abgr.c - Demonstrates the use of the extension EXT_abgr.
--
-- The same image data is used for both ABGR and RGBA formats
-- in glDrawPixels and glTexImage2D. The left side uses ABGR,
-- the right side RGBA. The top polygon demonstrates use of texture,
-- and the bottom image is drawn with glDrawPixels.
-- Note that the textures are defined as 3 component, so the alpha
-- value is not used in applying the DECAL environment. */
with Interfaces.C;
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Command_Line;
with GNAT.OS_Lib;
with gl_h;
use gl_h;
with glu_h;
use glu_h;
with AdaGL;
use AdaGL;
with SDL.Types; use SDL.Types;
with SDL.Video;
with SDL.Error;
with SDL.Events;
with SDL.Quit;
with SDL.Keyboard;
with SDL.Keysym;
procedure abgr is
package C renames Interfaces.C;
use type C.int;
package CL renames Ada.Command_Line;
package Vd renames SDL.Video;
use type Vd.Surface_Flags;
use type Vd.Surface_ptr;
package Er renames SDL.Error;
package Ev renames SDL.Events;
package Kb renames SDL.Keyboard;
package Ks renames SDL.Keysym;
doubleBuffer : GLenum;
ubImage : GLubyte_Array (0 .. 65535);
-- ===================================================================
procedure Init is
img_index : Integer;
imgWidth : GLsizei := 128;
begin
glMatrixMode (GL_PROJECTION);
glLoadIdentity;
gluPerspective (60.0, 1.0, 0.1, 1000.0);
glMatrixMode (GL_MODELVIEW);
glDisable (GL_DITHER);
-- Create image
img_index := 0;
for j in 0 .. 31 * imgWidth loop
ubImage (img_index .. img_index + 3) := (16#ff#, 16#00#, 16#00#, 16#ff#);
img_index := img_index + 4;
end loop;
for j in 0 .. 31 * imgWidth loop
ubImage (img_index .. img_index + 3) := (16#ff#, 16#00#, 16#ff#, 16#00#);
img_index := img_index + 4;
end loop;
for j in 0 .. 31 * imgWidth loop
ubImage (img_index .. img_index + 3) := (16#ff#, 16#ff#, 16#00#, 16#00#);
img_index := img_index + 4;
end loop;
for j in 0 .. 31 * imgWidth loop
ubImage (img_index .. img_index + 3) := (16#00#, 16#ff#, 16#00#, 16#ff#);
img_index := img_index + 4;
end loop;
end Init;
-- ===================================================================
procedure TextFunc is
begin
glEnable (GL_TEXTURE_2D);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, Float (GL_REPEAT));
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, Float (GL_REPEAT));
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Float (GL_NEAREST));
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, Float (GL_DECAL));
-- #if GL_EXT_abgr
glTexImage2D (GL_TEXTURE_2D, 0, 3, 128, 128, 0,
GL_ABGR_EXT, GL_UNSIGNED_BYTE, ubImage);
glBegin (GL_POLYGON);
glTexCoord2f (1.0, 1.0);
glVertex3f (-0.2, 0.8, -100.0);
glTexCoord2f (0.0, 1.0);
glVertex3f (-0.8, 0.8, -2.0);
glTexCoord2f (0.0, 0.0);
glVertex3f (-0.8, 0.2, -2.0);
glTexCoord2f (1.0, 0.0);
glVertex3f (-0.2, 0.2, -100.0);
glEnd;
-- #endif
glTexImage2D (GL_TEXTURE_2D, 0, 3, 128, 128, 0, GL_RGBA,
GL_UNSIGNED_BYTE, ubImage);
glBegin (GL_POLYGON);
glTexCoord2f (1.0, 1.0);
glVertex3f (0.8, 0.8, -2.0);
glTexCoord2f (0.0, 1.0);
glVertex3f (0.2, 0.8, -100.0);
glTexCoord2f (0.0, 0.0);
glVertex3f (0.2, 0.2, -100.0);
glTexCoord2f (1.0, 0.0);
glVertex3f (0.8, 0.2, -2.0);
glEnd;
glDisable (GL_TEXTURE_2D);
end TextFunc;
-- ===================================================================
procedure Draw is
begin
glClearColor (0.0, 0.0, 0.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT);
-- #if GL_EXT_abgr
glRasterPos3f (-0.8, -0.8, -1.5);
glDrawPixels (128, 128, GL_ABGR_EXT, GL_UNSIGNED_BYTE, ubImage);
-- #endif
glRasterPos3f (0.2, -0.8, -1.5);
glDrawPixels (128, 128, GL_RGBA, GL_UNSIGNED_BYTE, ubImage);
TextFunc;
if doubleBuffer /= 0 then
Vd.GL_SwapBuffers;
else
glFlush;
end if;
end Draw;
-- ===================================================================
argc : Integer := CL.Argument_Count;
Screen_Width : C.int := 640;
Screen_Hight : C.int := 480;
Full_Screen : Boolean := True;
-- ===================================================================
procedure Args is
begin
doubleBuffer := GL_TRUE;
for i in 1 .. argc loop
if argc >= 1 then
if CL.Argument (argc) = "-sb" then
doubleBuffer := GL_FALSE;
argc := argc - 1;
elsif CL.Argument (argc) = "-db" then
doubleBuffer := GL_TRUE;
argc := argc - 1;
elsif CL.Argument (argc) = "-window" then
Full_Screen := False;
argc := argc - 1;
elsif CL.Argument (argc) = "-1024x768" then
Screen_Width := 1024;
Screen_Hight := 768;
argc := argc - 1;
elsif CL.Argument (argc) = "-800x600" then
Screen_Width := 800;
Screen_Hight := 600;
argc := argc - 1;
else
Put_Line ("Usage: " & CL.Command_Name & " " &
"[ -sb | -db ] [-window] [-h] " &
"[-800x600 | -1024x768]");
GNAT.OS_Lib.OS_Exit (0);
end if;
end if;
end loop;
end Args;
-- ===================================================================
screen : Vd.Surface_ptr;
Video_Flags : Vd.Surface_Flags;
keys : Uint8_ptr;
Done : Boolean := False;
-- ===================================================================
procedure Main_System_Loop is
begin
while not Done loop
declare
event : Ev.Event;
PollEvent_Result : C.int;
begin
loop
Ev.PollEventVP (PollEvent_Result, event);
exit when PollEvent_Result = 0;
case event.the_type is
when Ev.QUIT =>
Done := True;
when others => null;
end case;
end loop;
keys := Kb.GetKeyState (null);
if Kb.Is_Key_Pressed (keys, Ks.K_ESCAPE) then
Done := True;
end if;
Draw;
end; -- declare
end loop;
end Main_System_Loop;
-- ===================================================================
-- Abgr Procedure body
-- ===================================================================
begin
Args;
if SDL.Init (SDL.INIT_VIDEO) < 0 then
Put_Line ("Couldn't load SDL: " & Er.Get_Error);
GNAT.OS_Lib.OS_Exit (1);
end if;
Video_Flags := Vd.OPENGL;
if Full_Screen then
Video_Flags := Video_Flags or Vd.FULLSCREEN;
end if;
screen := Vd.SetVideoMode (Screen_Width, Screen_Hight, 16, Video_Flags);
if screen = null then
Put_Line ("Couldn't set " & C.int'Image (Screen_Width) & "x" &
C.int'Image (Screen_Hight) & " GL video mode: " & Er.Get_Error);
SDL.SDL_Quit;
GNAT.OS_Lib.OS_Exit (2);
end if;
Vd.WM_Set_Caption ("ABGR extension", "abgr");
Init;
Main_System_Loop;
SDL.SDL_Quit;
end abgr;
|
-- AOC, Day 1
package Day1 is
type Mass is new Natural;
procedure load_modules(filename : in String);
function fuel_for_modules return Mass;
function total_fuel return Mass;
private
function fuel_required(weight : in Mass) return Integer;
function recursive_fuel_required(weight : in Mass) return Mass;
end Day1;
|
-- Copyright (c) 2017 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with League.JSON.Streams;
with League.JSON.Values;
package body LSP.Generic_Optional is
----------
-- Read --
----------
not overriding procedure Read
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out Optional_Type)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
Value : constant League.JSON.Values.JSON_Value := JS.Read;
begin
if Value.Is_Empty then
V := (Is_Set => False);
else
V := (Is_Set => True, Value => <>);
Element_Type'Read (S, V.Value);
end if;
end Read;
-----------
-- Write --
-----------
not overriding procedure Write
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Optional_Type) is
begin
if V.Is_Set then
Element_Type'Write (S, V.Value);
end if;
end Write;
end LSP.Generic_Optional;
|
pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
package sgxintrin_h is
-- skipped func _encls_u32
-- skipped func _enclu_u32
end sgxintrin_h;
|
package Taft_Type2_Pkg is
type T is private;
function Open return T;
private
type Buffer_T;
type T is access Buffer_T;
end Taft_Type2_Pkg;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- P R J . P R O C --
-- --
-- S p e c --
-- --
-- Copyright (C) 2001-2014, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package is used to convert a project file tree (see prj-tree.ads) to
-- project file data structures (see prj.ads), taking into account the
-- environment (external references).
with Prj.Tree; use Prj.Tree;
package Prj.Proc is
type Tree_Loaded_Callback is access procedure
(Node_Tree : Project_Node_Tree_Ref;
Tree : Project_Tree_Ref;
Project_Node : Project_Node_Id;
Project : Project_Id);
-- Callback used after the phase 1 of the processing of each aggregated
-- project to get access to project trees of aggregated projects.
procedure Process_Project_Tree_Phase_1
(In_Tree : Project_Tree_Ref;
Project : out Project_Id;
Packages_To_Check : String_List_Access;
Success : out Boolean;
From_Project_Node : Project_Node_Id;
From_Project_Node_Tree : Project_Node_Tree_Ref;
Env : in out Prj.Tree.Environment;
Reset_Tree : Boolean := True;
On_New_Tree_Loaded : Tree_Loaded_Callback := null);
-- Process a project tree (ie the direct resulting of parsing a .gpr file)
-- based on the current external references.
--
-- The result of this phase_1 is a partial project tree (Project) where
-- only a few fields have been initialized (in particular the list of
-- languages). These are the fields that are necessary to run gprconfig if
-- needed to automatically generate a configuration file. This first phase
-- of the processing does not require a configuration file.
--
-- When Reset_Tree is True, all the project data are removed from the
-- project table before processing.
--
-- If specified, On_New_Tree_Loaded is called after each aggregated project
-- has been processed succesfully.
procedure Process_Project_Tree_Phase_2
(In_Tree : Project_Tree_Ref;
Project : Project_Id;
Success : out Boolean;
From_Project_Node : Project_Node_Id;
From_Project_Node_Tree : Project_Node_Tree_Ref;
Env : Prj.Tree.Environment);
-- Perform the second phase of the processing, filling the rest of the
-- project with the information extracted from the project tree. This phase
-- requires that the configuration file has already been parsed (in fact
-- we currently assume that the contents of the configuration file has
-- been included in Project through Confgpr.Apply_Config_File). The
-- parameters are the same as for phase_1, with the addition of:
procedure Process
(In_Tree : Project_Tree_Ref;
Project : out Project_Id;
Packages_To_Check : String_List_Access;
Success : out Boolean;
From_Project_Node : Project_Node_Id;
From_Project_Node_Tree : Project_Node_Tree_Ref;
Env : in out Prj.Tree.Environment;
Reset_Tree : Boolean := True;
On_New_Tree_Loaded : Tree_Loaded_Callback := null);
-- Performs the two phases of the processing
procedure Set_Default_Runtime_For (Language : Name_Id; Value : String);
-- Set the default value for the runtime of Language. To be used for the
-- value of 'Runtime(<Language>) when Runtime (<language>) is not declared.
end Prj.Proc;
|
with PixelArray;
with StbiWrapper;
package ImageIO is
pragma Assertion_Policy (Pre => Check,
Post => Check,
Type_Invariant => Check);
function load(filename: String) return PixelArray.ImagePlane;
function save(filename: String; image: PixelArray.ImagePlane) return Boolean;
procedure save(filename: String; image: PixelArray.ImagePlane);
end ImageIO;
|
package body agar.gui.widget.tlist is
package cbinds is
procedure set_item_height
(tlist : tlist_access_t;
height : c.int);
pragma import (c, set_item_height, "AG_TlistSetItemHeight");
procedure size_hint
(tlist : tlist_access_t;
text : cs.chars_ptr;
num_items : c.int);
pragma import (c, size_hint, "AG_TlistSizeHint");
procedure size_hint_pixels
(tlist : tlist_access_t;
width : c.int;
num_items : c.int);
pragma import (c, size_hint_pixels, "AG_TlistSizeHintPixels");
procedure size_hint_largest
(tlist : tlist_access_t;
num_items : c.int);
pragma import (c, size_hint_largest, "AG_TlistSizeHintLargest");
procedure set_double_click_callback
(tlist : tlist_access_t;
callback : agar.core.event.callback_t;
fmt : agar.core.types.void_ptr_t);
pragma import (c, set_double_click_callback, "AG_TlistSetDblClickFn");
procedure set_changed_callback
(tlist : tlist_access_t;
callback : agar.core.event.callback_t;
fmt : agar.core.types.void_ptr_t);
pragma import (c, set_changed_callback, "AG_TlistSetChangedFn");
function list_select_text
(tlist : tlist_access_t;
text : cs.chars_ptr) return item_access_t;
pragma import (c, list_select_text, "AG_TlistSelectText");
function list_find_by_index
(tlist : tlist_access_t;
index : c.int) return item_access_t;
pragma import (c, list_find_by_index, "AG_TlistFindByIndex");
function set_popup_callback
(tlist : tlist_access_t;
callback : agar.core.event.callback_t;
fmt : agar.core.types.void_ptr_t) return agar.gui.widget.menu.item_access_t;
pragma import (c, set_popup_callback, "AG_TlistSetPopupFn");
function set_popup
(tlist : tlist_access_t;
category : cs.chars_ptr) return agar.gui.widget.menu.item_access_t;
pragma import (c, set_popup, "AG_TlistSetPopup");
end cbinds;
procedure set_item_height
(tlist : tlist_access_t;
height : natural) is
begin
cbinds.set_item_height
(tlist => tlist,
height => c.int (height));
end set_item_height;
procedure size_hint
(tlist : tlist_access_t;
text : string;
num_items : natural)
is
c_text : aliased c.char_array := c.to_c (text);
begin
cbinds.size_hint
(tlist => tlist,
text => cs.to_chars_ptr (c_text'unchecked_access),
num_items => c.int (num_items));
end size_hint;
procedure size_hint_pixels
(tlist : tlist_access_t;
width : natural;
num_items : natural) is
begin
cbinds.size_hint_pixels
(tlist => tlist,
width => c.int (width),
num_items => c.int (num_items));
end size_hint_pixels;
procedure size_hint_largest
(tlist : tlist_access_t;
num_items : natural) is
begin
cbinds.size_hint_largest
(tlist => tlist,
num_items => c.int (num_items));
end size_hint_largest;
procedure set_double_click_callback
(tlist : tlist_access_t;
callback : agar.core.event.callback_t) is
begin
cbinds.set_double_click_callback
(tlist => tlist,
callback => callback,
fmt => agar.core.types.null_ptr);
end set_double_click_callback;
procedure set_changed_callback
(tlist : tlist_access_t;
callback : agar.core.event.callback_t) is
begin
cbinds.set_changed_callback
(tlist => tlist,
callback => callback,
fmt => agar.core.types.null_ptr);
end set_changed_callback;
function list_select_text
(tlist : tlist_access_t;
text : string) return item_access_t
is
c_text : aliased c.char_array := c.to_c (text);
begin
return cbinds.list_select_text
(tlist => tlist,
text => cs.to_chars_ptr (c_text'unchecked_access));
end list_select_text;
function list_find_by_index
(tlist : tlist_access_t;
index : integer) return item_access_t is
begin
return cbinds.list_find_by_index
(tlist => tlist,
index => c.int (index));
end list_find_by_index;
function set_popup_callback
(tlist : tlist_access_t;
callback : agar.core.event.callback_t) return agar.gui.widget.menu.item_access_t is
begin
return cbinds.set_popup_callback
(tlist => tlist,
callback => callback,
fmt => agar.core.types.null_ptr);
end set_popup_callback;
function set_popup
(tlist : tlist_access_t;
category : string) return agar.gui.widget.menu.item_access_t
is
c_cat : aliased c.char_array := c.to_c (category);
begin
return cbinds.set_popup
(tlist => tlist,
category => cs.to_chars_ptr (c_cat'unchecked_access));
end set_popup;
function widget (tlist : tlist_access_t) return widget_access_t is
begin
return tlist.widget'access;
end widget;
end agar.gui.widget.tlist;
|
-----------------------------------------------------------------------
-- gen-artifacts -- Artifacts for Code Generator
-- Copyright (C) 2011, 2012, 2018 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Finalization;
with DOM.Core;
with Util.Log;
with Gen.Model;
with Gen.Model.Packages;
with Gen.Model.Projects;
-- The <b>Gen.Artifacts</b> package represents the methods and process to prepare,
-- control and realize the code generation.
package Gen.Artifacts is
type Iteration_Mode is (ITERATION_PACKAGE, ITERATION_TABLE);
type Generator is limited interface and Util.Log.Logging;
-- Report an error and set the exit status accordingly
procedure Error (Handler : in out Generator;
Message : in String;
Arg1 : in String;
Arg2 : in String := "") is abstract;
-- Get the config directory path.
function Get_Config_Directory (Handler : in Generator) return String is abstract;
-- Get the result directory path.
function Get_Result_Directory (Handler : in Generator) return String is abstract;
-- Get the configuration parameter.
function Get_Parameter (Handler : in Generator;
Name : in String;
Default : in String := "") return String is abstract;
-- Get the configuration parameter.
function Get_Parameter (Handler : in Generator;
Name : in String;
Default : in Boolean := False) return Boolean is abstract;
-- Tell the generator to activate the generation of the given template name.
-- The name is a property name that must be defined in generator.properties to
-- indicate the template file. Several artifacts can trigger the generation
-- of a given template. The template is generated only once.
procedure Add_Generation (Handler : in out Generator;
Name : in String;
Mode : in Iteration_Mode;
Mapping : in String) is abstract;
-- Scan the dynamo directories and execute the <b>Process</b> procedure with the
-- directory path.
procedure Scan_Directories (Handler : in Generator;
Process : not null access
procedure (Dir : in String)) is abstract;
-- ------------------------------
-- Model Definition
-- ------------------------------
type Artifact is abstract new Ada.Finalization.Limited_Controlled with private;
-- After the configuration file is read, processes the node whose root
-- is passed in <b>Node</b> and initializes the <b>Model</b> with the information.
procedure Initialize (Handler : in out Artifact;
Path : in String;
Node : in DOM.Core.Node;
Model : in out Gen.Model.Packages.Model_Definition'Class;
Context : in out Generator'Class);
-- Prepare the model after all the configuration files have been read and before
-- actually invoking the generation.
procedure Prepare (Handler : in out Artifact;
Model : in out Gen.Model.Packages.Model_Definition'Class;
Context : in out Generator'Class) is null;
-- After the generation, perform a finalization step for the generation process.
procedure Finish (Handler : in out Artifact;
Model : in out Gen.Model.Packages.Model_Definition'Class;
Project : in out Gen.Model.Projects.Project_Definition'Class;
Context : in out Generator'Class) is null;
-- Check whether this artifact has been initialized.
function Is_Initialized (Handler : in Artifact) return Boolean;
private
type Artifact is abstract new Ada.Finalization.Limited_Controlled with record
Initialized : Boolean := False;
end record;
end Gen.Artifacts;
|
-- The Village of Vampire by YT, このソースコードはNYSLです
with Ada.Calendar.Time_Zones;
with Ada.Calendar.Formatting;
package Tabula.Calendar is
use type Ada.Calendar.Time_Zones.Time_Offset;
Null_Time : constant Ada.Calendar.Time;
Time_Offset : constant Ada.Calendar.Time_Zones.Time_Offset := 9 * 60;
-- GMT+9 日本
private
Null_Time : constant Ada.Calendar.Time :=
Ada.Calendar.Formatting.Time_Of (
Year => Ada.Calendar.Year_Number'First,
Month => Ada.Calendar.Month_Number'First,
Day => Ada.Calendar.Day_Number'First,
Time_Zone => 0);
end Tabula.Calendar;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with GL.Types; use GL.Types;
package GL.Uniforms is
pragma Preelaborate;
type Uniform is new Int;
procedure Set_Single (Location : Uniform; Value : Single);
procedure Set_Single (Location : Uniform; V1, V2 : Single);
procedure Set_Single (Location : Uniform; Value : Singles.Vector2);
procedure Set_Single (Location : Uniform; V1, V2, V3 : Single);
procedure Set_Single (Location : Uniform; Value : Singles.Vector3);
procedure Set_Single (Location : Uniform; V1, V2, V3, V4 : Single);
procedure Set_Single (Location : Uniform; Value : Singles.Vector4);
procedure Set_Single (Location : Uniform; Value : Single_Array);
procedure Set_Single (Location : Uniform; Value : Singles.Vector2_Array);
procedure Set_Single (Location : Uniform; Value : Singles.Vector3_Array);
procedure Set_Single (Location : Uniform; Value : Singles.Vector4_Array);
procedure Set_Single (Location : Uniform; Value : Singles.Matrix2);
procedure Set_Single (Location : Uniform; Value : Singles.Matrix3);
procedure Set_Single (Location : Uniform; Value : Singles.Matrix4);
procedure Set_Single (Location : Uniform; Value : Singles.Matrix2_Array);
procedure Set_Single (Location : Uniform; Value : Singles.Matrix3_Array);
procedure Set_Single (Location : Uniform; Value : Singles.Matrix4_Array);
procedure Set_Int (Location : Uniform; Value : Int);
procedure Set_Int (Location : Uniform; V1, V2 : Int);
procedure Set_Int (Location : Uniform; Value : Ints.Vector2);
procedure Set_Int (Location : Uniform; V1, V2, V3 : Int);
procedure Set_Int (Location : Uniform; Value : Ints.Vector3);
procedure Set_Int (Location : Uniform; V1, V2, V3, V4 : Int);
procedure Set_Int (Location : Uniform; Value : Ints.Vector4);
procedure Set_Int (Location : Uniform; Value : Int_Array);
procedure Set_Int (Location : Uniform; Value : Ints.Vector2_Array);
procedure Set_Int (Location : Uniform; Value : Ints.Vector3_Array);
procedure Set_Int (Location : Uniform; Value : Ints.Vector4_Array);
procedure Set_Int (Location : Uniform; Value : Ints.Matrix2);
procedure Set_Int (Location : Uniform; Value : Ints.Matrix3);
procedure Set_Int (Location : Uniform; Value : Ints.Matrix4);
procedure Set_Int (Location : Uniform; Value : Ints.Matrix2_Array);
procedure Set_Int (Location : Uniform; Value : Ints.Matrix3_Array);
procedure Set_Int (Location : Uniform; Value : Ints.Matrix4_Array);
procedure Set_UInt (Location : Uniform; Value : UInt);
procedure Set_UInt (Location : Uniform; V1, V2 : UInt);
procedure Set_UInt (Location : Uniform; Value : UInts.Vector2);
procedure Set_UInt (Location : Uniform; V1, V2, V3 : UInt);
procedure Set_UInt (Location : Uniform; Value : UInts.Vector3);
procedure Set_UInt (Location : Uniform; V1, V2, V3, V4 : UInt);
procedure Set_UInt (Location : Uniform; Value : UInts.Vector4);
procedure Set_UInt (Location : Uniform; Value : UInt_Array);
procedure Set_UInt (Location : Uniform; Value : UInts.Vector2_Array);
procedure Set_UInt (Location : Uniform; Value : UInts.Vector3_Array);
procedure Set_UInt (Location : Uniform; Value : UInts.Vector4_Array);
procedure Set_UInt (Location : Uniform; Value : UInts.Matrix2);
procedure Set_UInt (Location : Uniform; Value : UInts.Matrix3);
procedure Set_UInt (Location : Uniform; Value : UInts.Matrix4);
procedure Set_UInt (Location : Uniform; Value : UInts.Matrix2_Array);
procedure Set_UInt (Location : Uniform; Value : UInts.Matrix3_Array);
procedure Set_UInt (Location : Uniform; Value : UInts.Matrix4_Array);
end GL.Uniforms;
|
package CLIC.Config.Edit is
function Unset (Path : String;
Key : Config_Key)
return Boolean;
-- Unset/Remove a key from a configuration file. Return True in case of
-- success or False when the configuration file or the key don't exist.
function Set (Path : String;
Key : Config_Key;
Value : String;
Check : Check_Import := null)
return Boolean;
-- Set a key in a configuration file. Return True in case of success or
-- False when the value is invalid or rejected by the Check function.
--
-- When a Check function is provided, it will be called on the
-- config key/value. If Check return False, Set returns False and the
-- configuration file is not modified. In addition the Check function
-- can print an error message explaining why the key/value is invalid.
end CLIC.Config.Edit;
|
-----------------------------------------------------------------------
-- akt-commands-info -- Info command of 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 Keystore.Verifier;
package body AKT.Commands.Info is
use type Keystore.Header_Slot_Count_Type;
use type Keystore.Passwords.Keys.Key_Provider_Access;
-- ------------------------------
-- List the value entries of 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 (Command, Name);
Path : constant String := Context.Get_Keystore_Path (Args);
Stats : Keystore.Wallet_Stats;
Is_Keystore : Boolean;
begin
Keystore.Verifier.Print_Information (Path, Is_Keystore);
-- No need to proceed if this is not a keystore file.
if not Is_Keystore then
return;
end if;
Setup_Password_Provider (Context);
Setup_Key_Provider (Context);
Context.Wallet.Open (Path => Path,
Data_Path => Context.Data_Path.all,
Info => Context.Info);
if Context.No_Password_Opt and Context.Info.Header_Count = 0 then
return;
end if;
if not Context.No_Password_Opt then
if Context.Key_Provider /= null then
Context.Wallet.Set_Master_Key (Context.Key_Provider.all);
end if;
Context.Wallet.Unlock (Context.Provider.all, Context.Slot);
else
Context.GPG.Load_Secrets (Context.Wallet);
Context.Wallet.Set_Master_Key (Context.GPG);
Context.Wallet.Unlock (Context.GPG, Context.Slot);
end if;
Context.Wallet.Get_Stats (Stats);
Ada.Text_IO.Put ("Key slots used: ");
Ada.Text_IO.Set_Col (29);
for Slot in Stats.Keys'Range loop
if Stats.Keys (Slot) then
Ada.Text_IO.Put (Keystore.Key_Slot'Image (Slot));
end if;
end loop;
Ada.Text_IO.New_Line;
Ada.Text_IO.Put ("Entry count: ");
Ada.Text_IO.Set_Col (29);
Ada.Text_IO.Put_Line (Natural'Image (Stats.Entry_Count));
end Execute;
end AKT.Commands.Info;
|
---------------------------------
-- GID - Generic Image Decoder --
---------------------------------
--
-- Copyright (c) Gautier de Montmollin 2010 .. 2019
--
-- 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.
--
-- NB: this is the MIT License, as found 2-May-2010 on the site
-- http://www.opensource.org/licenses/mit-license.php
with GID.Headers,
GID.Decoding_BMP,
GID.Decoding_GIF,
GID.Decoding_JPG,
GID.Decoding_PNG,
GID.Decoding_PNM,
GID.Decoding_TGA;
with Ada.Unchecked_Deallocation;
package body GID is
-- Internal: a few header items (palette, some large JPEG tables)
-- are heap allocated; we need to release them upon finalization
-- or descriptor reuse.
procedure Clear_heap_allocated_memory (Object : in out Image_descriptor) is
procedure Dispose is
new Ada.Unchecked_Deallocation(Color_table, p_Color_table);
procedure Dispose is
new Ada.Unchecked_Deallocation(
JPEG_defs.VLC_table,
JPEG_defs.p_VLC_table
);
begin
-- Deterministic garbage collection of heap allocated objects.
-- -> Palette
Dispose (Object.palette);
-- -> JPEG tables
for ad in JPEG_defs.VLC_defs_type'Range(1) loop
for idx in JPEG_defs.VLC_defs_type'Range(2) loop
Dispose (Object.JPEG_stuff.vlc_defs (ad, idx));
end loop;
end loop;
end Clear_heap_allocated_memory;
-----------------------
-- Load_image_header --
-----------------------
procedure Load_image_header (
image : out Image_descriptor;
from : in out Ada.Streams.Root_Stream_Type'Class;
try_tga : Boolean:= False
)
is
begin
Clear_heap_allocated_memory (image);
image.stream:= from'Unchecked_Access;
--
-- Load the very first symbols of the header,
-- this identifies the image format.
--
Headers.Load_signature(image, try_tga);
--
case image.format is
when BMP =>
Headers.Load_BMP_header(image);
when FITS =>
Headers.Load_FITS_header(image);
when GIF =>
Headers.Load_GIF_header(image);
when JPEG =>
Headers.Load_JPEG_header(image);
when PNG =>
Headers.Load_PNG_header(image);
when PNM =>
Headers.Load_PNM_header(image);
when TGA =>
Headers.Load_TGA_header(image);
when TIFF =>
Headers.Load_TIFF_header(image);
end case;
end Load_image_header;
-----------------
-- Pixel_width --
-----------------
function Pixel_width (image: Image_descriptor) return Positive is
begin
return Positive (image.width);
end Pixel_width;
------------------
-- Pixel_height --
------------------
function Pixel_height (image: Image_descriptor) return Positive is
begin
return Positive (image.height);
end Pixel_height;
function Display_orientation (image: Image_descriptor) return Orientation is
begin
return image.display_orientation;
end Display_orientation;
-------------------------
-- Load_image_contents --
-------------------------
procedure Load_image_contents (
image : in out Image_descriptor;
next_frame: out Ada.Calendar.Day_Duration
)
is
procedure BMP_Load is
new Decoding_BMP.Load( Primary_color_range, Set_X_Y, Put_Pixel, Feedback );
procedure GIF_Load is
new Decoding_GIF.Load( Primary_color_range, Set_X_Y, Put_Pixel, Feedback, mode );
procedure JPG_Load is
new Decoding_JPG.Load( Primary_color_range, Set_X_Y, Put_Pixel, Feedback );
procedure PNG_Load is
new Decoding_PNG.Load( Primary_color_range, Set_X_Y, Put_Pixel, Feedback );
procedure PNM_Load is
new Decoding_PNM.Load( Primary_color_range, Set_X_Y, Put_Pixel, Feedback );
procedure TGA_Load is
new Decoding_TGA.Load( Primary_color_range, Set_X_Y, Put_Pixel, Feedback );
begin
next_frame:= 0.0;
-- ^ value updated in case of animation and when
-- current frame is not the last frame
case image.format is
when BMP =>
BMP_Load(image);
when GIF =>
GIF_Load(image, next_frame);
when JPEG =>
JPG_Load(image, next_frame);
when PNG =>
PNG_Load(image);
when PNM =>
PNM_Load(image);
when TGA =>
TGA_Load(image);
when others =>
raise known_but_unsupported_image_format;
end case;
end Load_image_contents;
---------------------------------------
-- Some informations about the image --
---------------------------------------
function Format (image: Image_descriptor) return Image_format_type is
begin
return image.format;
end Format;
function Detailed_format (image: Image_descriptor) return String is
begin
return Bounded_255.To_String(image.detailed_format);
end Detailed_format;
function Subformat (image: Image_descriptor) return Integer is
begin
return image.subformat_id;
end Subformat;
function Bits_per_pixel (image: Image_descriptor) return Positive is
begin
return image.bits_per_pixel;
end Bits_per_pixel;
function RLE_encoded (image: Image_descriptor) return Boolean is
begin
return image.RLE_encoded;
end RLE_encoded;
function Is_Interlaced (image: Image_descriptor) return Boolean is
begin
return image.interlaced;
end Is_Interlaced;
function Greyscale (image: Image_descriptor) return Boolean is
begin
return image.greyscale;
end Greyscale;
function Has_palette (image: Image_descriptor) return Boolean is
begin
return image.palette /= null;
end Has_palette;
function Expect_transparency (image: Image_descriptor) return Boolean is
begin
return image.transparency;
end Expect_transparency;
overriding procedure Adjust (Object : in out Image_descriptor) is
use JPEG_defs;
begin
-- Clone heap allocated objects, if any.
-- -> Palette
if Object.palette /= null then
Object.palette := new Color_table'(Object.palette.all);
end if;
-- -> JPEG tables
for ad in JPEG_defs.VLC_defs_type'Range(1) loop
for idx in JPEG_defs.VLC_defs_type'Range(2) loop
if Object.JPEG_stuff.vlc_defs (ad, idx) /= null then
Object.JPEG_stuff.vlc_defs (ad, idx) :=
new VLC_table'(Object.JPEG_stuff.vlc_defs (ad, idx).all);
end if;
end loop;
end loop;
end Adjust;
overriding procedure Finalize (Object : in out Image_descriptor) is
begin
Clear_heap_allocated_memory (Object);
end Finalize;
end GID;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with GL.API;
with GL.Enums;
package body GL.Objects.Shaders is
procedure Set_Source (Subject : Shader; Source : String) is
C_Source : C.char_array := C.To_C (Source);
begin
API.Shader_Source (Subject.Reference.GL_Id, 1,
(1 => C_Source (0)'Unchecked_Access),
(1 => Source'Length));
Raise_Exception_On_OpenGL_Error;
end Set_Source;
function Source (Subject : Shader) return String is
Source_Length : Size := 0;
begin
API.Get_Shader_Param (Subject.Reference.GL_Id,
Enums.Shader_Source_Length, Source_Length);
Raise_Exception_On_OpenGL_Error;
if Source_Length = 0 then
return "";
else
declare
Shader_Source : String (1 .. Integer (Source_Length));
begin
API.Get_Shader_Source (Subject.Reference.GL_Id, Source_Length,
Source_Length, Shader_Source);
Raise_Exception_On_OpenGL_Error;
return Shader_Source (1 .. Integer (Source_Length));
end;
end if;
end Source;
procedure Compile (Subject : Shader) is
begin
API.Compile_Shader (Subject.Reference.GL_Id);
Raise_Exception_On_OpenGL_Error;
end Compile;
procedure Release_Shader_Compiler is
begin
API.Release_Shader_Compiler.all;
end Release_Shader_Compiler;
function Compile_Status (Subject : Shader) return Boolean is
Value : Int := 0;
begin
API.Get_Shader_Param (Subject.Reference.GL_Id, Enums.Compile_Status,
Value);
Raise_Exception_On_OpenGL_Error;
return Value /= 0;
end Compile_Status;
function Info_Log (Subject : Shader) return String is
Log_Length : Size := 0;
begin
API.Get_Shader_Param (Subject.Reference.GL_Id,
Enums.Info_Log_Length, Log_Length);
Raise_Exception_On_OpenGL_Error;
if Log_Length = 0 then
return "";
else
declare
Info_Log : String (1 .. Integer (Log_Length));
begin
API.Get_Shader_Info_Log (Subject.Reference.GL_Id, Log_Length,
Log_Length, Info_Log);
Raise_Exception_On_OpenGL_Error;
return Info_Log (1 .. Integer (Log_Length));
end;
end if;
end Info_Log;
overriding
procedure Internal_Create_Id (Object : Shader; Id : out UInt) is
begin
Id := API.Create_Shader (Object.Kind);
Raise_Exception_On_OpenGL_Error;
end Internal_Create_Id;
overriding
procedure Internal_Release_Id (Object : Shader; Id : UInt) is
pragma Unreferenced (Object);
begin
API.Delete_Shader (Id);
Raise_Exception_On_OpenGL_Error;
end Internal_Release_Id;
function Create_From_Id (Id : UInt) return Shader is
Kind : Shader_Type := Shader_Type'First;
begin
API.Get_Shader_Type (Id, Enums.Shader_Type, Kind);
Raise_Exception_On_OpenGL_Error;
return Object : Shader (Kind) do
Object.Set_Raw_Id (Id, False);
end return;
end Create_From_Id;
end GL.Objects.Shaders;
|
with OpenAL.Buffer;
with OpenAL.Types;
package OpenAL.Source is
--
-- Types
--
type Source_t is private;
type Source_Array_t is array (Positive range <>) of Source_t;
No_Source : constant Source_t;
--
-- API
--
-- proc_map : alGenSources
procedure Generate_Sources
(Sources : in out Source_Array_t);
-- proc_map : alDeleteSources
procedure Delete_Sources
(Sources : in Source_Array_t);
-- proc_map : alIsSource
function Is_Valid (Source : in Source_t) return Boolean;
--
-- Position
--
-- proc_map : alSource3f
procedure Set_Position_Float
(Source : in Source_t;
X : in Types.Float_t;
Y : in Types.Float_t;
Z : in Types.Float_t);
-- proc_map : alSource3i
procedure Set_Position_Discrete
(Source : in Source_t;
X : in Types.Integer_t;
Y : in Types.Integer_t;
Z : in Types.Integer_t);
-- proc_map : alSourcefv
procedure Set_Position_Float_List
(Source : in Source_t;
Position : in Types.Vector_3f_t);
-- proc_map : alSourceiv
procedure Set_Position_Discrete_List
(Source : in Source_t;
Position : in Types.Vector_3i_t);
-- proc_map : alGetSource3f
procedure Get_Position_Float
(Source : in Source_t;
X : out Types.Float_t;
Y : out Types.Float_t;
Z : out Types.Float_t);
-- proc_map : alGetSource3i
procedure Get_Position_Discrete
(Source : in Source_t;
X : out Types.Integer_t;
Y : out Types.Integer_t;
Z : out Types.Integer_t);
-- proc_map : alGetSourcefv
procedure Get_Position_Float_List
(Source : in Source_t;
Position : out Types.Vector_3f_t);
-- proc_map : alGetSourceiv
procedure Get_Position_Discrete_List
(Source : in Source_t;
Position : out Types.Vector_3i_t);
--
-- Velocity
--
-- proc_map : alSource3f
procedure Set_Velocity_Float
(Source : in Source_t;
X : in Types.Float_t;
Y : in Types.Float_t;
Z : in Types.Float_t);
-- proc_map : alSource3i
procedure Set_Velocity_Discrete
(Source : in Source_t;
X : in Types.Integer_t;
Y : in Types.Integer_t;
Z : in Types.Integer_t);
-- proc_map : alSourcefv
procedure Set_Velocity_Float_List
(Source : in Source_t;
Velocity : in Types.Vector_3f_t);
-- proc_map : alSourceiv
procedure Set_Velocity_Discrete_List
(Source : in Source_t;
Velocity : in Types.Vector_3i_t);
-- proc_map : alGetSource3f
procedure Get_Velocity_Float
(Source : in Source_t;
X : out Types.Float_t;
Y : out Types.Float_t;
Z : out Types.Float_t);
-- proc_map : alGetSource3i
procedure Get_Velocity_Discrete
(Source : in Source_t;
X : out Types.Integer_t;
Y : out Types.Integer_t;
Z : out Types.Integer_t);
-- proc_map : alGetSourcefv
procedure Get_Velocity_Float_List
(Source : in Source_t;
Velocity : out Types.Vector_3f_t);
-- proc_map : alGetSourceiv
procedure Get_Velocity_Discrete_List
(Source : in Source_t;
Velocity : out Types.Vector_3i_t);
--
-- Gain
--
-- proc_map : alSource
procedure Set_Gain
(Source : in Source_t;
Gain : in Types.Float_t);
-- proc_map : alGetSource
procedure Get_Gain
(Source : in Source_t;
Gain : out Types.Float_t);
--
-- Positioning
--
-- proc_map : alSource
procedure Set_Positioning
(Source : in Source_t;
Relative : in Boolean);
-- proc_map : alGetSource
procedure Get_Positioning
(Source : in Source_t;
Relative : out Boolean);
--
-- Type
--
type Source_Type_t is (Undetermined, Static, Streaming, Unknown);
-- proc_map : alSource
procedure Get_Type
(Source : in Source_t;
Source_Type : out Source_Type_t);
--
-- Looping
--
-- proc_map : alSource
procedure Set_Looping
(Source : in Source_t;
Looping : in Boolean);
-- proc_map : alGetSource
procedure Get_Looping
(Source : in Source_t;
Looping : out Boolean);
--
-- Current_Buffer
--
-- proc_map : alSource
procedure Set_Current_Buffer
(Source : in Source_t;
Buffer : in OpenAL.Buffer.Buffer_t);
-- proc_map : alGetSource
procedure Get_Current_Buffer
(Source : in Source_t;
Buffer : out OpenAL.Buffer.Buffer_t);
--
-- Buffers_Queued
--
-- proc_map : alGetSource
procedure Get_Buffers_Queued
(Source : in Source_t;
Buffers : out Natural);
--
-- Buffers_Processed
--
-- proc_map : alGetSource
procedure Get_Buffers_Processed
(Source : in Source_t;
Buffers : out Natural);
--
-- Gain
--
subtype Gain_t is Types.Float_t range 0.0 .. 1.0;
-- proc_map : alSource
procedure Set_Minimum_Gain
(Source : in Source_t;
Gain : in Gain_t);
-- proc_map : alGetSource
procedure Get_Minimum_Gain
(Source : in Source_t;
Gain : out Gain_t);
-- proc_map : alSource
procedure Set_Maximum_Gain
(Source : in Source_t;
Gain : in Gain_t);
-- proc_map : alGetSource
procedure Get_Maximum_Gain
(Source : in Source_t;
Gain : out Gain_t);
--
-- Reference_Distance
--
-- proc_map : alSource
procedure Set_Reference_Distance_Float
(Source : in Source_t;
Distance : in Types.Float_t);
-- proc_map : alSource
procedure Set_Reference_Distance_Discrete
(Source : in Source_t;
Distance : in Types.Integer_t);
-- proc_map : alGetSource
procedure Get_Reference_Distance_Float
(Source : in Source_t;
Distance : out Types.Float_t);
-- proc_map : alGetSource
procedure Get_Reference_Distance_Discrete
(Source : in Source_t;
Distance : out Types.Integer_t);
--
-- Rolloff_Factor
--
-- proc_map : alSource
procedure Set_Rolloff_Factor_Float
(Source : in Source_t;
Distance : in Types.Float_t);
-- proc_map : alSource
procedure Set_Rolloff_Factor_Discrete
(Source : in Source_t;
Distance : in Types.Integer_t);
-- proc_map : alGetSource
procedure Get_Rolloff_Factor_Float
(Source : in Source_t;
Distance : out Types.Float_t);
-- proc_map : alGetSource
procedure Get_Rolloff_Factor_Discrete
(Source : in Source_t;
Distance : out Types.Integer_t);
--
-- Maximum_Distance
--
-- proc_map : alSource
procedure Set_Maximum_Distance_Float
(Source : in Source_t;
Distance : in Types.Float_t);
-- proc_map : alSource
procedure Set_Maximum_Distance_Discrete
(Source : in Source_t;
Distance : in Types.Integer_t);
-- proc_map : alGetSource
procedure Get_Maximum_Distance_Float
(Source : in Source_t;
Distance : out Types.Float_t);
-- proc_map : alGetSource
procedure Get_Maximum_Distance_Discrete
(Source : in Source_t;
Distance : out Types.Integer_t);
--
-- Pitch
--
subtype Pitch_t is Types.Float_t range 0.00001 .. Types.Float_t'Last;
-- proc_map : alSource
procedure Set_Pitch
(Source : in Source_t;
Pitch : in Pitch_t);
-- proc_map : alGetSource
procedure Get_Pitch
(Source : in Source_t;
Pitch : out Pitch_t);
--
-- Direction
--
-- proc_map : alSource3f
procedure Set_Direction_Float
(Source : in Source_t;
X : in Types.Float_t;
Y : in Types.Float_t;
Z : in Types.Float_t);
-- proc_map : alSource3i
procedure Set_Direction_Discrete
(Source : in Source_t;
X : in Types.Integer_t;
Y : in Types.Integer_t;
Z : in Types.Integer_t);
-- proc_map : alSourcefv
procedure Set_Direction_Float_List
(Source : in Source_t;
Direction : in Types.Vector_3f_t);
-- proc_map : alSourceiv
procedure Set_Direction_Discrete_List
(Source : in Source_t;
Direction : in Types.Vector_3i_t);
-- proc_map : alGetSource3f
procedure Get_Direction_Float
(Source : in Source_t;
X : out Types.Float_t;
Y : out Types.Float_t;
Z : out Types.Float_t);
-- proc_map : alGetSource3i
procedure Get_Direction_Discrete
(Source : in Source_t;
X : out Types.Integer_t;
Y : out Types.Integer_t;
Z : out Types.Integer_t);
-- proc_map : alGetSourcefv
procedure Get_Direction_Float_List
(Source : in Source_t;
Direction : out Types.Vector_3f_t);
-- proc_map : alGetSourceiv
procedure Get_Direction_Discrete_List
(Source : in Source_t;
Direction : out Types.Vector_3i_t);
--
-- Cone_Inner_Angle
--
-- proc_map : alSource
procedure Set_Cone_Inner_Angle_Float
(Source : in Source_t;
Distance : in Types.Float_t);
-- proc_map : alSource
procedure Set_Cone_Inner_Angle_Discrete
(Source : in Source_t;
Distance : in Types.Integer_t);
-- proc_map : alGetSource
procedure Get_Cone_Inner_Angle_Float
(Source : in Source_t;
Distance : out Types.Float_t);
-- proc_map : alGetSource
procedure Get_Cone_Inner_Angle_Discrete
(Source : in Source_t;
Distance : out Types.Integer_t);
--
-- Cone_Outer_Angle
--
-- proc_map : alSource
procedure Set_Cone_Outer_Angle_Float
(Source : in Source_t;
Distance : in Types.Float_t);
-- proc_map : alSource
procedure Set_Cone_Outer_Angle_Discrete
(Source : in Source_t;
Distance : in Types.Integer_t);
-- proc_map : alGetSource
procedure Get_Cone_Outer_Angle_Float
(Source : in Source_t;
Distance : out Types.Float_t);
-- proc_map : alGetSource
procedure Get_Cone_Outer_Angle_Discrete
(Source : in Source_t;
Distance : out Types.Integer_t);
--
-- Cone_Outer_Gain
--
-- proc_map : alSource
procedure Set_Cone_Outer_Gain
(Source : in Source_t;
Gain : in Types.Float_t);
-- proc_map : alGetSource
procedure Get_Cone_Outer_Gain
(Source : in Source_t;
Gain : out Types.Float_t);
--
-- Seconds_Offset
--
-- proc_map : alSource
procedure Set_Seconds_Offset_Float
(Source : in Source_t;
Distance : in Types.Float_t);
-- proc_map : alSource
procedure Set_Seconds_Offset_Discrete
(Source : in Source_t;
Distance : in Types.Integer_t);
-- proc_map : alGetSource
procedure Get_Seconds_Offset_Float
(Source : in Source_t;
Distance : out Types.Float_t);
-- proc_map : alGetSource
procedure Get_Seconds_Offset_Discrete
(Source : in Source_t;
Distance : out Types.Integer_t);
--
-- Sample_Offset
--
-- proc_map : alSource
procedure Set_Sample_Offset_Float
(Source : in Source_t;
Distance : in Types.Float_t);
-- proc_map : alSource
procedure Set_Sample_Offset_Discrete
(Source : in Source_t;
Distance : in Types.Integer_t);
-- proc_map : alGetSource
procedure Get_Sample_Offset_Float
(Source : in Source_t;
Distance : out Types.Float_t);
-- proc_map : alGetSource
procedure Get_Sample_Offset_Discrete
(Source : in Source_t;
Distance : out Types.Integer_t);
--
-- Byte_Offset
--
-- proc_map : alSource
procedure Set_Byte_Offset_Float
(Source : in Source_t;
Distance : in Types.Float_t);
-- proc_map : alSource
procedure Set_Byte_Offset_Discrete
(Source : in Source_t;
Distance : in Types.Integer_t);
-- proc_map : alGetSource
procedure Get_Byte_Offset_Float
(Source : in Source_t;
Distance : out Types.Float_t);
-- proc_map : alGetSource
procedure Get_Byte_Offset_Discrete
(Source : in Source_t;
Distance : out Types.Integer_t);
--
-- Queue_Buffers
--
-- proc_map : alSourceQueueBuffers
procedure Queue_Buffers
(Source : in Source_t;
Buffers : in OpenAL.Buffer.Buffer_Array_t);
--
-- Unqueue_Buffers
--
-- proc_map : alSourceUnqueueBuffers
procedure Unqueue_Buffers
(Source : in Source_t;
Buffers : in OpenAL.Buffer.Buffer_Array_t);
--
-- Play
--
-- proc_map : alSourcePlay
procedure Play (Source : in Source_t);
-- proc_map : alSourcePlayv
procedure Play_List (Sources : in Source_Array_t);
--
-- Pause
--
-- proc_map : alSourcePause
procedure Pause (Source : in Source_t);
-- proc_map : alSourcePausev
procedure Pause_List (Sources : in Source_Array_t);
--
-- Stop
--
-- proc_map : alSourceStop
procedure Stop (Source : in Source_t);
-- proc_map : alSourceStopv
procedure Stop_List (Sources : in Source_Array_t);
--
-- Rewind
--
-- proc_map : alSourceRewind
procedure Rewind (Source : in Source_t);
-- proc_map : alSourceRewindv
procedure Rewind_List (Sources : in Source_Array_t);
--
-- Private conveniences.
--
function To_Integer (Source : in Source_t) return Types.Unsigned_Integer_t;
private
type Source_t is new Types.Unsigned_Integer_t;
No_Source : constant Source_t := 0;
end OpenAL.Source;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- I N T E R F A C E S . C . P O I N T E R S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2015, 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 Interfaces.C.Strings; use Interfaces.C.Strings;
with System; use System;
with Ada.Unchecked_Conversion;
package body Interfaces.C.Pointers is
type Addr is mod 2 ** System.Parameters.ptr_bits;
function To_Pointer is new Ada.Unchecked_Conversion (Addr, Pointer);
function To_Addr is new Ada.Unchecked_Conversion (Pointer, Addr);
function To_Addr is new Ada.Unchecked_Conversion (ptrdiff_t, Addr);
function To_Ptrdiff is new Ada.Unchecked_Conversion (Addr, ptrdiff_t);
Elmt_Size : constant ptrdiff_t :=
(Element_Array'Component_Size
+ Storage_Unit - 1) / Storage_Unit;
subtype Index_Base is Index'Base;
---------
-- "+" --
---------
function "+" (Left : Pointer; Right : ptrdiff_t) return Pointer is
begin
if Left = null then
raise Pointer_Error;
end if;
return To_Pointer (To_Addr (Left) + To_Addr (Elmt_Size * Right));
end "+";
function "+" (Left : ptrdiff_t; Right : Pointer) return Pointer is
begin
if Right = null then
raise Pointer_Error;
end if;
return To_Pointer (To_Addr (Elmt_Size * Left) + To_Addr (Right));
end "+";
---------
-- "-" --
---------
function "-" (Left : Pointer; Right : ptrdiff_t) return Pointer is
begin
if Left = null then
raise Pointer_Error;
end if;
return To_Pointer (To_Addr (Left) - To_Addr (Right * Elmt_Size));
end "-";
function "-" (Left : Pointer; Right : Pointer) return ptrdiff_t is
begin
if Left = null or else Right = null then
raise Pointer_Error;
end if;
return To_Ptrdiff (To_Addr (Left) - To_Addr (Right)) / Elmt_Size;
end "-";
----------------
-- Copy_Array --
----------------
procedure Copy_Array
(Source : Pointer;
Target : Pointer;
Length : ptrdiff_t)
is
T : Pointer;
S : Pointer;
begin
if Source = null or else Target = null then
raise Dereference_Error;
-- Forward copy
elsif To_Addr (Target) <= To_Addr (Source) then
T := Target;
S := Source;
for J in 1 .. Length loop
T.all := S.all;
Increment (T);
Increment (S);
end loop;
-- Backward copy
else
T := Target + Length;
S := Source + Length;
for J in 1 .. Length loop
Decrement (T);
Decrement (S);
T.all := S.all;
end loop;
end if;
end Copy_Array;
---------------------------
-- Copy_Terminated_Array --
---------------------------
procedure Copy_Terminated_Array
(Source : Pointer;
Target : Pointer;
Limit : ptrdiff_t := ptrdiff_t'Last;
Terminator : Element := Default_Terminator)
is
L : ptrdiff_t;
S : Pointer := Source;
begin
if Source = null or Target = null then
raise Dereference_Error;
end if;
-- Compute array limited length (including the terminator)
L := 0;
while L < Limit loop
L := L + 1;
exit when S.all = Terminator;
Increment (S);
end loop;
Copy_Array (Source, Target, L);
end Copy_Terminated_Array;
---------------
-- Decrement --
---------------
procedure Decrement (Ref : in out Pointer) is
begin
Ref := Ref - 1;
end Decrement;
---------------
-- Increment --
---------------
procedure Increment (Ref : in out Pointer) is
begin
Ref := Ref + 1;
end Increment;
-----------
-- Value --
-----------
function Value
(Ref : Pointer;
Terminator : Element := Default_Terminator) return Element_Array
is
P : Pointer;
L : constant Index_Base := Index'First;
H : Index_Base;
begin
if Ref = null then
raise Dereference_Error;
else
H := L;
P := Ref;
loop
exit when P.all = Terminator;
H := Index_Base'Succ (H);
Increment (P);
end loop;
declare
subtype A is Element_Array (L .. H);
type PA is access A;
for PA'Size use System.Parameters.ptr_bits;
function To_PA is new Ada.Unchecked_Conversion (Pointer, PA);
begin
return To_PA (Ref).all;
end;
end if;
end Value;
function Value
(Ref : Pointer;
Length : ptrdiff_t) return Element_Array
is
L : Index_Base;
H : Index_Base;
begin
if Ref = null then
raise Dereference_Error;
-- For length zero, we need to return a null slice, but we can't make
-- the bounds of this slice Index'First, since this could cause a
-- Constraint_Error if Index'First = Index'Base'First.
elsif Length <= 0 then
declare
pragma Warnings (Off); -- kill warnings since X not assigned
X : Element_Array (Index'Succ (Index'First) .. Index'First);
pragma Warnings (On);
begin
return X;
end;
-- Normal case (length non-zero)
else
L := Index'First;
H := Index'Val (Index'Pos (Index'First) + Length - 1);
declare
subtype A is Element_Array (L .. H);
type PA is access A;
for PA'Size use System.Parameters.ptr_bits;
function To_PA is new Ada.Unchecked_Conversion (Pointer, PA);
begin
return To_PA (Ref).all;
end;
end if;
end Value;
--------------------
-- Virtual_Length --
--------------------
function Virtual_Length
(Ref : Pointer;
Terminator : Element := Default_Terminator) return ptrdiff_t
is
P : Pointer;
C : ptrdiff_t;
begin
if Ref = null then
raise Dereference_Error;
else
C := 0;
P := Ref;
while P.all /= Terminator loop
C := C + 1;
Increment (P);
end loop;
return C;
end if;
end Virtual_Length;
end Interfaces.C.Pointers;
|
-----------------------------------------------------------------------
-- servlet-servlets-mappers -- Read servlet configuration files
-- Copyright (C) 2011, 2012, 2013, 2015, 2017 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Containers;
with EL.Utils;
package body Servlet.Core.Mappers is
-- ------------------------------
-- Save in the servlet config object the value associated with the given field.
-- When the <b>FILTER_MAPPING</b>, <b>SERVLET_MAPPING</b> or <b>CONTEXT_PARAM</b> field
-- is reached, insert the new configuration rule in the servlet registry.
-- ------------------------------
procedure Set_Member (N : in out Servlet_Config;
Field : in Servlet_Fields;
Value : in Util.Beans.Objects.Object) is
use Util.Beans.Objects;
use type Ada.Containers.Count_Type;
procedure Add_Filter (Pattern : in Util.Beans.Objects.Object);
procedure Add_Mapping (Pattern : in Util.Beans.Objects.Object);
procedure Add_Mapping (Handler : access procedure (Pattern : in Util.Beans.Objects.Object);
Message : in String);
procedure Add_Filter (Pattern : in Util.Beans.Objects.Object) is
begin
N.Handler.Add_Filter_Mapping (Pattern => To_String (Pattern),
Name => To_String (N.Filter_Name));
end Add_Filter;
procedure Add_Mapping (Pattern : in Util.Beans.Objects.Object) is
begin
N.Handler.Add_Mapping (Pattern => To_String (Pattern),
Name => To_String (N.Servlet_Name));
end Add_Mapping;
procedure Add_Mapping (Handler : access procedure (Pattern : in Util.Beans.Objects.Object);
Message : in String) is
Last : constant Ada.Containers.Count_Type := N.URL_Patterns.Length;
begin
if Last = 0 then
raise Util.Serialize.Mappers.Field_Error with Message;
end if;
for I in 1 .. Last loop
N.URL_Patterns.Query_Element (Positive (I), Handler);
end loop;
N.URL_Patterns.Clear;
end Add_Mapping;
begin
-- <context-param>
-- <param-name>property</param-name>
-- <param-value>false</param-value>
-- </context-param>
-- <filter-mapping>
-- <filter-name>Dump Filter</filter-name>
-- <servlet-name>Faces Servlet</servlet-name>
-- </filter-mapping>
case Field is
when FILTER_NAME =>
N.Filter_Name := Value;
when SERVLET_NAME =>
N.Servlet_Name := Value;
when URL_PATTERN =>
N.URL_Patterns.Append (Value);
when PARAM_NAME =>
N.Param_Name := Value;
when PARAM_VALUE =>
N.Param_Value := EL.Utils.Eval (To_String (Value), N.Context.all);
when MIME_TYPE =>
N.Mime_Type := Value;
when EXTENSION =>
N.Extension := Value;
when ERROR_CODE =>
N.Error_Code := Value;
when LOCATION =>
N.Location := Value;
when FILTER_MAPPING =>
Add_Mapping (Add_Filter'Access, "Missing url-pattern for the filter mapping");
when SERVLET_MAPPING =>
Add_Mapping (Add_Mapping'Access, "Missing url-pattern for the servlet mapping");
when CONTEXT_PARAM =>
declare
Name : constant String := To_String (N.Param_Name);
begin
-- If the context parameter already has a value, do not set it again.
-- The value comes from an application setting and we want to keep it.
if N.Override_Context
or else String '(N.Handler.all.Get_Init_Parameter (Name)) = ""
then
if Util.Beans.Objects.Is_Null (N.Param_Value) then
N.Handler.Set_Init_Parameter (Name => Name,
Value => "");
else
N.Handler.Set_Init_Parameter (Name => Name,
Value => To_String (N.Param_Value));
end if;
end if;
end;
when MIME_MAPPING =>
null;
when ERROR_PAGE =>
N.Handler.Set_Error_Page (Error => To_Integer (N.Error_Code),
Page => To_String (N.Location));
end case;
end Set_Member;
SMapper : aliased Servlet_Mapper.Mapper;
-- ------------------------------
-- Setup the XML parser to read the servlet and mapping rules <b>context-param</b>,
-- <b>filter-mapping</b> and <b>servlet-mapping</b>.
-- ------------------------------
package body Reader_Config is
begin
Mapper.Add_Mapping ("faces-config", SMapper'Access);
Mapper.Add_Mapping ("module", SMapper'Access);
Mapper.Add_Mapping ("web-app", SMapper'Access);
Config.Handler := Handler;
Config.Context := Context;
Servlet_Mapper.Set_Context (Mapper, Config'Unchecked_Access);
end Reader_Config;
begin
SMapper.Add_Mapping ("filter-mapping", FILTER_MAPPING);
SMapper.Add_Mapping ("filter-mapping/filter-name", FILTER_NAME);
SMapper.Add_Mapping ("filter-mapping/servlet-name", SERVLET_NAME);
SMapper.Add_Mapping ("filter-mapping/url-pattern", URL_PATTERN);
SMapper.Add_Mapping ("servlet-mapping", SERVLET_MAPPING);
SMapper.Add_Mapping ("servlet-mapping/servlet-name", SERVLET_NAME);
SMapper.Add_Mapping ("servlet-mapping/url-pattern", URL_PATTERN);
SMapper.Add_Mapping ("context-param", CONTEXT_PARAM);
SMapper.Add_Mapping ("context-param/param-name", PARAM_NAME);
SMapper.Add_Mapping ("context-param/param-value", PARAM_VALUE);
SMapper.Add_Mapping ("error-page", ERROR_PAGE);
SMapper.Add_Mapping ("error-page/error-code", ERROR_CODE);
SMapper.Add_Mapping ("error-page/location", LOCATION);
end Servlet.Core.Mappers;
|
with ZMQ;
package ZHelper is
function Rand_Of (First : Integer; Last : Integer) return Integer;
function Rand_Of (First : Float; Last : Float) return Float;
-- Provide random number from First .. Last
procedure Dump (S : ZMQ.Socket_Type'Class);
-- Receives all message parts from socket, prints neatly
function Set_Id (S : ZMQ.Socket_Type'Class) return String;
procedure Set_Id (S : ZMQ.Socket_Type'Class);
-- Set simple random printable identity on socket
end ZHelper;
|
-- ------------------------------------------------
-- Programa de prova
-- ------------------------------------------------
-- Versio : 0.1
-- Autors : Jose Ruiz Bravo
-- Biel Moya Alcover
-- Alvaro Medina Ballester
-- ------------------------------------------------
-- Programa per comprovar les funcionalitats
-- de la taula de simbols.
--
-- ------------------------------------------------
with Ada.Text_IO,
Ada.Command_Line,
Decls.D_Taula_De_Noms,
Decls.Tn,
Decls.Dgenerals,
D_Token,
Pk_Ulexica_Io,
U_Lexica,
Semantica.Dtsimbols,
Delcs.Dtdesc;
use Ada.Text_IO,
Ada.Command_Line,
Decls.D_Taula_De_Noms,
Decls.Tn,
Decls.Dgenerals,
D_Token,
Pk_Ulexica_Io,
U_Lexica,
Semantica.Dtsimbols,
Decls.Dtdesc;
procedure compiprueba is
ts: tsimbols;
id: id_nom := 1;
d1: descrip(dproc);
d2: descrip(dproc);
d3: descrip(dvar);
d4: descrip(dtipus);
d5: descrip(dtipus);
D6: Descrip(Dvar);
e: boolean;
np1 : num_proc := 5;
np2 : num_proc := 7;
desctip : descriptipus(tsrec);
descarr : descriptipus(tsarr);
begin
--Tbuida
tbuida(ts);
--Posa
d1.np := np1;
d2.np := np2;
id := 1;
posa(ts, id, d1, e);
id := 7;
posa(ts, id, d2, e);
--Cons
--New_Line;
--case cons(ts, 7).td is
-- when dnula => Put_Line("dnula");
-- when dtipus => Put_Line("dtipus");
-- when dvar => Put_Line("dvar");
-- when dproc => Put_Line("dproc");
-- when dconst => Put_Line("dconst");
-- when dargc => Put_Line("dargc");
-- when dcamp => Put_Line("dcamp");
--end case;
--Put_Line("np: "&cons(ts, 7).np'img);
--Entra bloc
entrabloc(ts);
D3.tr := 4;
d3.nv := 3;
posa(ts, id, d3, e);
--Surt bloc
surtbloc(ts);
printts(ts);
--Un altre entra bloc
--entrabloc(ts);
--posa(ts, id, d3, e);
--Comencam amb records
desctip.ocup := 8;
d4.dt := desctip;
id := 8;
posa(ts, id, d4, e);
--Ficam un posa camp
posacamp(ts, 8, 1, d3, e);
printts(ts);
posacamp(ts,8,7,d3,e);
printts(ts);
--Consulta camp
Put_Line("Cons camp: "&conscamp(ts,8,1).nv'img);
Put_Line("Cons camp: "&conscamp(ts,8,7).nv'img);
--Comencam amb els arrays
descarr.ocup := 8;
d5.dt := descarr;
posa(ts, 5, d5, e); --Ficam l'array
posa_idx(ts, 5, 31, e); --Afegim un camp a l'array
printts(ts);
posa_idx(ts, 5, 32, e); --Afegim un altre camp
--a l'array
printts(ts);
--Primer_idx i idx_valid
Put_Line("PRIMER IDX: "
&primer_idx(ts, 5)'img);
Put_Line("IDX VALID: "
&idx_valid(primer_idx(ts, 5))'img);
--Provam el successor del camp 1
Put_Line("SUCCESSOR IDX: "
&succ_idx(ts, primer_idx(ts, 5))'img);
Put_Line("SUCCESSOR IDX: "
&succ_idx(ts, succ_idx(ts,
primer_idx(ts, 5)))'img);
--Consultam idx
Put_Line("CONS IDX: "
&cons_idx(ts, primer_idx(ts, 5))'img);
Put_Line("CONS IDX: "
&cons_idx(ts, succ_idx(ts,
primer_idx(ts, 5)))'img);
--Posa_arg
D6.Tr := 9;
d6.Nv := 5;
Posa(Ts, 9, D6, E); --Parametre variable 8 (argument)
Posa_Arg(Ts, 7, 9, D6, E); --Passam per primera vegada
--l'argument
Posa_Arg(Ts, 7, 9, D6, E); --El passam per segona
--vegada
Printts(Ts);
--Primer_arg
--Actualitza
Put_Line("Antes act: ");
case cons(ts, 7).td is
when dnula => Put_Line("dnula");
when dtipus => Put_Line("dtipus");
when dvar => Put_Line("dvar");
when dproc => Put_Line("dproc");
when dconst => Put_Line("dconst");
when dargc => Put_Line("dargc");
when dcamp => Put_Line("dcamp");
end case;
Actualitza(Ts, 7, D6);
Put_Line("Act dvar: ");
case cons(ts, 7).td is
when dnula => Put_Line("dnula");
when dtipus => Put_Line("dtipus");
when dvar => Put_Line("dvar");
when dproc => Put_Line("dproc");
when dconst => Put_Line("dconst");
when dargc => Put_Line("dargc");
when dcamp => Put_Line("dcamp");
end case;
if e then
put_line("ERROR");
end if;
end compiprueba;
|
-------------------------------------------------------------------------------
-- Copyright (c) 2016, Daniel King
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
-- * Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
-- * The name of the copyright holder may not be used to endorse or promote
-- Products derived from this software without specific prior written
-- permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------------
with Ada.Command_Line;
with Timing; use Timing;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Long_Float_Text_IO;
with Interfaces; use Interfaces;
with KangarooTwelve;
with MarsupilamiFourteen;
with Keccak.Parallel_Keccak_1600;
with Keccak.Parallel_Keccak_1600.Rounds_24;
with Keccak.Parallel_Keccak_1600.Rounds_12;
with Keccak.Generic_KangarooTwelve;
with Keccak.Generic_KeccakF;
with Keccak.Generic_MonkeyWrap;
with Keccak.Generic_Parallel_Hash;
with Keccak.Keccak_25;
with Keccak.Keccak_25.Rounds_12;
with Keccak.Keccak_50;
with Keccak.Keccak_50.Rounds_14;
with Keccak.Keccak_100;
with Keccak.Keccak_100.Rounds_16;
with Keccak.Keccak_200;
with Keccak.Keccak_200.Rounds_18;
with Keccak.Keccak_400;
with Keccak.Keccak_400.Rounds_20;
with Keccak.Keccak_800;
with Keccak.Keccak_800.Rounds_22;
with Keccak.Keccak_1600;
with Keccak.Types;
with Keccak.Generic_XOF;
with Keccak.Generic_Hash;
with Keccak.Generic_Duplex;
with Keccak.Keccak_1600;
with Keccak.Keccak_1600.Rounds_24;
with Keccak.Keccak_1600.Rounds_12;
with Parallel_Hash;
with SHA3;
with SHAKE;
with RawSHAKE;
with Ketje;
with Gimli;
with Gimli.Hash;
with Ascon;
with Ascon.Permutations;
with Ascon.Hash;
with Ascon.XOF;
procedure Benchmark
is
Benchmark_Data_Size : constant := 512 * 1024; -- size of the benchmark data in bytes
Repeat : constant := 200; -- number of benchmark iterations
-- A 1 MiB data chunk to use as an input to the algorithms.
type Byte_Array_Access is access Keccak.Types.Byte_Array;
Data_Chunk : Byte_Array_Access := new Keccak.Types.Byte_Array (1 .. Benchmark_Data_Size);
package Cycles_Count_IO is new Ada.Text_IO.Modular_IO (Cycles_Count);
procedure Print_Cycles_Per_Byte (Data_Size : in Natural;
Cycles : in Cycles_Count)
is
CPB : Long_Float;
begin
CPB := Long_Float (Cycles) / Long_Float (Data_Size);
Ada.Long_Float_Text_IO.Put
(Item => CPB,
Fore => 0,
Aft => 1,
Exp => 0);
Ada.Text_IO.Put (" cycles/byte");
Ada.Text_IO.New_Line;
end Print_Cycles_Per_Byte;
procedure Print_Cycles (Cycles : in Cycles_Count)
is
begin
Cycles_Count_IO.Put (Cycles, Width => 0);
Ada.Text_IO.Put (" cycles");
Ada.Text_IO.New_Line;
end Print_Cycles;
----------------------------------------------------------------------------
-- Hash_Benchmark
--
-- Generic procedure to run a benchmark for any hash algorithm (e.g. SHA3-224,
-- Keccak-256, etc...).
----------------------------------------------------------------------------
generic
Name : String;
with package Hash_Package is new Keccak.Generic_Hash(<>);
procedure Hash_Benchmark;
procedure Hash_Benchmark
is
Ctx : Hash_Package.Context;
Digest : Hash_Package.Digest_Type;
Start_Time : Timing.Time;
Cycles : Cycles_Count;
Min_Cycles : Cycles_Count := Cycles_Count'Last;
begin
Ada.Text_IO.Put (Name & ": ");
Timing.Calibrate;
for I in Positive range 1 .. Repeat loop
Start_Measurement (Start_Time);
Hash_Package.Init(Ctx);
Hash_Package.Update(Ctx, Data_Chunk.all, Data_Chunk.all'Length*8);
Hash_Package.Final(Ctx, Digest);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles_Per_Byte (Data_Chunk.all'Length, Min_Cycles);
end Hash_Benchmark;
----------------------------------------------------------------------------
-- XOF_Benchmark
--
-- Generic procedure to run a benchmark for any XOF algorithm (e.g. SHAKE128,
-- RawSHAKE256, etc...).
----------------------------------------------------------------------------
generic
Name : String;
with package XOF_Package is new Keccak.Generic_XOF(<>);
procedure XOF_Benchmark;
procedure XOF_Benchmark
is
Ctx : XOF_Package.Context;
Start_Time : Timing.Time;
Cycles : Cycles_Count;
Min_Cycles : Cycles_Count := Cycles_Count'Last;
begin
Ada.Text_IO.Put(Name & " (Absorbing): ");
Timing.Calibrate;
-- Benchmark Absorbing
for I in Positive range 1 .. Repeat loop
Start_Measurement (Start_Time);
XOF_Package.Init(Ctx);
XOF_Package.Update(Ctx, Data_Chunk.all, Data_Chunk.all'Length*8);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles_Per_Byte (Data_Chunk.all'Length, Min_Cycles);
Min_Cycles := Cycles_Count'Last;
Ada.Text_IO.Put(Name & " (Squeezing): ");
Timing.Calibrate;
-- Benchmark squeezing
for I in Positive range 1 .. Repeat loop
Start_Measurement (Start_Time);
XOF_Package.Extract(Ctx, Data_Chunk.all);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles_Per_Byte (Data_Chunk.all'Length, Min_Cycles);
end XOF_Benchmark;
----------------------------------------------------------------------------
-- Duplex_Benchmark
--
-- Generic procedure to run a benchmark for any Duplex algorithm.
----------------------------------------------------------------------------
generic
Name : String;
Capacity : Positive;
with package Duplex is new Keccak.Generic_Duplex(<>);
procedure Duplex_Benchmark;
procedure Duplex_Benchmark
is
Ctx : Duplex.Context;
Out_Data : Keccak.Types.Byte_Array(1 .. 1600/8);
Start_Time : Timing.Time;
Cycles : Cycles_Count;
Min_Cycles : Cycles_Count := Cycles_Count'Last;
begin
Ada.Text_IO.Put(Name & ": ");
Duplex.Init(Ctx, Capacity);
Timing.Calibrate;
for I in Positive range 1 .. Repeat loop
Start_Measurement (Start_Time);
Duplex.Duplex(Ctx,
Data_Chunk.all(1 .. Duplex.Rate_Of(Ctx)/8),
Duplex.Rate_Of(Ctx) - Duplex.Min_Padding_Bits,
Out_Data(1 .. Duplex.Rate_Of(Ctx)/8),
Duplex.Rate_Of(Ctx) - Duplex.Min_Padding_Bits);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles (Min_Cycles);
end Duplex_Benchmark;
----------------------------------------------------------------------------
-- KeccakF_Benchmark
--
-- Generic procedure to run a benchmark for a KeccakF permutation.
----------------------------------------------------------------------------
generic
Name : String;
type State_Type is private;
with procedure Init (A : out State_Type);
with procedure Permute(A : in out State_Type);
procedure KeccakF_Benchmark;
procedure KeccakF_Benchmark
is
package Duration_IO is new Ada.Text_IO.Fixed_IO(Duration);
package Integer_IO is new Ada.Text_IO.Integer_IO(Integer);
State : State_Type;
Start_Time : Timing.Time;
Cycles : Cycles_Count;
Min_Cycles : Cycles_Count := Cycles_Count'Last;
Num_Iterations : Natural := Repeat * 100;
begin
Ada.Text_IO.Put(Name & ": ");
Init(State);
Timing.Calibrate;
for I in Positive range 1 .. Num_Iterations loop
Start_Measurement (Start_Time);
Permute(State);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles (Min_Cycles);
end KeccakF_Benchmark;
----------------------------------------------------------------------------
-- K12_Benchmark
--
-- Generic procedure to run a benchmark for a KangarooTwelve
----------------------------------------------------------------------------
generic
Name : String;
with package K12 is new Keccak.Generic_KangarooTwelve(<>);
procedure K12_Benchmark;
procedure K12_Benchmark
is
Ctx : K12.Context;
Start_Time : Timing.Time;
Cycles : Cycles_Count;
Min_Cycles : Cycles_Count := Cycles_Count'Last;
begin
Ada.Text_IO.Put(Name & " (Absorbing): ");
Timing.Calibrate;
-- Benchmark Absorbing
for I in Positive range 1 .. Repeat loop
Start_Measurement (Start_Time);
K12.Init(Ctx);
K12.Update(Ctx, Data_Chunk.all);
K12.Finish (Ctx, "");
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles_Per_Byte (Data_Chunk.all'Length, Min_Cycles);
Min_Cycles := Cycles_Count'Last;
Ada.Text_IO.Put(Name & " (Squeezing): ");
Timing.Calibrate;
-- Benchmark squeezing
for I in Positive range 1 .. Repeat loop
Start_Measurement (Start_Time);
K12.Extract(Ctx, Data_Chunk.all);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles_Per_Byte (Data_Chunk.all'Length, Min_Cycles);
end K12_Benchmark;
----------------------------------------------------------------------------
-- ParallelHash_Benchmark
--
-- Generic procedure to run a benchmark for a ParallelHash
----------------------------------------------------------------------------
generic
Name : String;
with package ParallelHash is new Keccak.Generic_Parallel_Hash(<>);
procedure ParallelHash_Benchmark;
procedure ParallelHash_Benchmark
is
Ctx : ParallelHash.Context;
Start_Time : Timing.Time;
Cycles : Cycles_Count;
Min_Cycles : Cycles_Count := Cycles_Count'Last;
begin
Ada.Text_IO.Put(Name & " (Absorbing): ");
Timing.Calibrate;
-- Benchmark Absorbing
for I in Positive range 1 .. Repeat loop
Start_Measurement (Start_Time);
ParallelHash.Init(Ctx, 8192, "");
ParallelHash.Update(Ctx, Data_Chunk.all);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles_Per_Byte (Data_Chunk.all'Length, Min_Cycles);
Min_Cycles := Cycles_Count'Last;
Ada.Text_IO.Put(Name & " (Squeezing): ");
Timing.Calibrate;
-- Benchmark squeezing
for I in Positive range 1 .. Repeat loop
Start_Measurement (Start_Time);
ParallelHash.Extract(Ctx, Data_Chunk.all);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles_Per_Byte (Data_Chunk.all'Length, Min_Cycles);
end ParallelHash_Benchmark;
----------------------------------------------------------------------------
-- Ketje_Benchmark
--
-- Generic procedure to run a benchmark for Ketje (instances of MonkeyWrap)
----------------------------------------------------------------------------
generic
Name : String;
with package MonkeyWrap is new Keccak.Generic_MonkeyWrap(<>);
procedure Ketje_Benchmark;
procedure Ketje_Benchmark
is
Ctx : MonkeyWrap.Context;
Start_Time : Timing.Time;
Cycles : Cycles_Count;
Min_Cycles : Cycles_Count := Cycles_Count'Last;
Empty : Keccak.Types.Byte_Array (1 .. 0) := (others => 0);
begin
Ada.Text_IO.Put(Name & " (AAD): ");
Timing.Calibrate;
-- Benchmark AAD
for I in Positive range 1 .. Repeat loop
MonkeyWrap.Init (Ctx, Empty, Empty);
Start_Measurement (Start_Time);
MonkeyWrap.Update_Auth_Data (Ctx, Data_Chunk.all);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles_Per_Byte (Data_Chunk.all'Length, Min_Cycles);
Min_Cycles := Cycles_Count'Last;
Ada.Text_IO.Put(Name & " (Encrypt): ");
Timing.Calibrate;
-- Benchmark Encrypt
for I in Positive range 1 .. Repeat loop
MonkeyWrap.Init (Ctx, Empty, Empty);
Start_Measurement (Start_Time);
MonkeyWrap.Update_Encrypt (Ctx, Data_Chunk.all, Data_Chunk.all);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles_Per_Byte (Data_Chunk.all'Length, Min_Cycles);
Ada.Text_IO.Put(Name & " (Decrypt): ");
-- Benchmark Decrypt
for I in Positive range 1 .. Repeat loop
MonkeyWrap.Init (Ctx, Empty, Empty);
Start_Measurement (Start_Time);
MonkeyWrap.Update_Decrypt (Ctx, Data_Chunk.all, Data_Chunk.all);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles_Per_Byte (Data_Chunk.all'Length, Min_Cycles);
Ada.Text_IO.Put(Name & " (Tag): ");
-- Benchmark Tag
for I in Positive range 1 .. Repeat loop
MonkeyWrap.Init (Ctx, Empty, Empty);
Start_Measurement (Start_Time);
MonkeyWrap.Extract_Tag (Ctx, Data_Chunk.all);
Cycles := End_Measurement (Start_Time);
if Cycles < Min_Cycles then
Min_Cycles := Cycles;
end if;
end loop;
Print_Cycles_Per_Byte (Data_Chunk.all'Length, Min_Cycles);
end Ketje_Benchmark;
----------------------------------------------------------------------------
-- Benchmark procedure instantiations.
----------------------------------------------------------------------------
procedure Benchmark_SHA_224 is new Hash_Benchmark
("SHA3-224", SHA3.SHA3_224);
procedure Benchmark_SHA_256 is new Hash_Benchmark
("SHA3-256", SHA3.SHA3_256);
procedure Benchmark_SHA_384 is new Hash_Benchmark
("SHA3-384", SHA3.SHA3_384);
procedure Benchmark_SHA_512 is new Hash_Benchmark
("SHA3-512", SHA3.SHA3_512);
procedure Benchmark_Keccak_224 is new Hash_Benchmark
("Keccak-224", SHA3.Keccak_224);
procedure Benchmark_Keccak_256 is new Hash_Benchmark
("Keccak-256", SHA3.Keccak_256);
procedure Benchmark_Keccak_384 is new Hash_Benchmark
("Keccak-384", SHA3.Keccak_384);
procedure Benchmark_Keccak_512 is new Hash_Benchmark
("Keccak-512", SHA3.Keccak_512);
procedure Benchmark_SHAKE128 is new XOF_Benchmark
("SHAKE128", SHAKE.SHAKE128);
procedure Benchmark_SHAKE256 is new XOF_Benchmark
("SHAKE256", SHAKE.SHAKE256);
procedure Benchmark_RawSHAKE128 is new XOF_Benchmark
("RawSHAKE128", RawSHAKE.RawSHAKE128);
procedure Benchmark_RawSHAKE256 is new XOF_Benchmark
("RawSHAKE256", RawSHAKE.RawSHAKE256);
procedure Benchmark_Duplex_r1152c448 is new Duplex_Benchmark
("Duplex r1152c448", 448, Keccak.Keccak_1600.Rounds_24.Duplex);
procedure Benchmark_Duplex_r1088c512 is new Duplex_Benchmark
("Duplex r1088c512", 512, Keccak.Keccak_1600.Rounds_24.Duplex);
procedure Benchmark_Duplex_r832c768 is new Duplex_Benchmark
("Duplex r832c768", 768, Keccak.Keccak_1600.Rounds_24.Duplex);
procedure Benchmark_Duplex_r576c1024 is new Duplex_Benchmark
("Duplex r576c1024", 1024, Keccak.Keccak_1600.Rounds_24.Duplex);
procedure Benchmark_KeccakF_25 is new KeccakF_Benchmark
("Keccak-p[25,12]",
Keccak.Keccak_25.State,
Keccak.Keccak_25.KeccakF_25.Init,
Keccak.Keccak_25.Rounds_12.Permute);
procedure Benchmark_KeccakF_50 is new KeccakF_Benchmark
("Keccak-p[50,14]",
Keccak.Keccak_50.State,
Keccak.Keccak_50.KeccakF_50.Init,
Keccak.Keccak_50.Rounds_14.Permute);
procedure Benchmark_KeccakF_100 is new KeccakF_Benchmark
("Keccak-p[100,16]",
Keccak.Keccak_100.State,
Keccak.Keccak_100.KeccakF_100.Init,
Keccak.Keccak_100.Rounds_16.Permute);
procedure Benchmark_KeccakF_200 is new KeccakF_Benchmark
("Keccak-p[200,18]",
Keccak.Keccak_200.State,
Keccak.Keccak_200.KeccakF_200.Init,
Keccak.Keccak_200.Rounds_18.Permute);
procedure Benchmark_KeccakF_400 is new KeccakF_Benchmark
("Keccak-p[400,20]",
Keccak.Keccak_400.State,
Keccak.Keccak_400.KeccakF_400.Init,
Keccak.Keccak_400.Rounds_20.Permute);
procedure Benchmark_KeccakF_800 is new KeccakF_Benchmark
("Keccak-p[800,22]",
Keccak.Keccak_800.State,
Keccak.Keccak_800.KeccakF_800.Init,
Keccak.Keccak_800.Rounds_22.Permute);
procedure Benchmark_KeccakF_1600_R24 is new KeccakF_Benchmark
("Keccak-p[1600,24]",
Keccak.Keccak_1600.State,
Keccak.Keccak_1600.KeccakF_1600.Init,
Keccak.Keccak_1600.Rounds_24.Permute);
procedure Benchmark_KeccakF_1600_P2_R24 is new KeccakF_Benchmark
("Keccak-p[1600,24]×2",
Keccak.Parallel_Keccak_1600.Parallel_State_P2,
Keccak.Parallel_Keccak_1600.Init_P2,
Keccak.Parallel_Keccak_1600.Rounds_24.Permute_All_P2);
procedure Benchmark_KeccakF_1600_P4_R24 is new KeccakF_Benchmark
("Keccak-p[1600,24]×4",
Keccak.Parallel_Keccak_1600.Parallel_State_P4,
Keccak.Parallel_Keccak_1600.Init_P4,
Keccak.Parallel_Keccak_1600.Rounds_24.Permute_All_P4);
procedure Benchmark_KeccakF_1600_P8_R24 is new KeccakF_Benchmark
("Keccak-p[1600,24]×8",
Keccak.Parallel_Keccak_1600.Parallel_State_P8,
Keccak.Parallel_Keccak_1600.Init_P8,
Keccak.Parallel_Keccak_1600.Rounds_24.Permute_All_P8);
procedure Benchmark_KeccakF_1600_R12 is new KeccakF_Benchmark
("Keccak-p[1600,12]",
Keccak.Keccak_1600.State,
Keccak.Keccak_1600.KeccakF_1600.Init,
Keccak.Keccak_1600.Rounds_12.Permute);
procedure Benchmark_KeccakF_1600_P2_R12 is new KeccakF_Benchmark
("Keccak-p[1600,12]×2",
Keccak.Parallel_Keccak_1600.Parallel_State_P2,
Keccak.Parallel_Keccak_1600.Init_P2,
Keccak.Parallel_Keccak_1600.Rounds_12.Permute_All_P2);
procedure Benchmark_KeccakF_1600_P4_R12 is new KeccakF_Benchmark
("Keccak-p[1600,12]×4",
Keccak.Parallel_Keccak_1600.Parallel_State_P4,
Keccak.Parallel_Keccak_1600.Init_P4,
Keccak.Parallel_Keccak_1600.Rounds_12.Permute_All_P4);
procedure Benchmark_KeccakF_1600_P8_R12 is new KeccakF_Benchmark
("Keccak-p[1600,12]×8",
Keccak.Parallel_Keccak_1600.Parallel_State_P8,
Keccak.Parallel_Keccak_1600.Init_P8,
Keccak.Parallel_Keccak_1600.Rounds_12.Permute_All_P8);
procedure Benchmark_K12 is new K12_Benchmark
("KangarooTwelve",
KangarooTwelve.K12);
procedure Benchmark_M14 is new K12_Benchmark
("MarsupilamiFourteen",
MarsupilamiFourteen.M14);
procedure Benchmark_ParallelHash128 is new ParallelHash_Benchmark
("ParallelHash128",
Parallel_Hash.ParallelHash128);
procedure Benchmark_ParallelHash256 is new ParallelHash_Benchmark
("ParallelHash256",
Parallel_Hash.ParallelHash256);
procedure Benchmark_Ketje_Jr is new Ketje_Benchmark
("Ketje Jr", Ketje.Jr);
procedure Benchmark_Ketje_Sr is new Ketje_Benchmark
("Ketje Sr", Ketje.Sr);
procedure Benchmark_Ketje_Minor is new Ketje_Benchmark
("Ketje Minor", Ketje.Minor);
procedure Benchmark_Ketje_Major is new Ketje_Benchmark
("Ketje Major", Ketje.Major);
procedure Benchmark_Gimli is new KeccakF_Benchmark
("Gimli",
Gimli.State,
Gimli.Init,
Gimli.Permute);
procedure Benchmark_Gimli_Hash is new Hash_Benchmark
("Gimli Hash",
Gimli.Hash);
procedure Benchmark_Ascon12 is new KeccakF_Benchmark
("Ascon (12 rounds)",
Ascon.State,
Ascon.Init,
Ascon.Permutations.Permute_12);
procedure Benchmark_Ascon8 is new KeccakF_Benchmark
("Ascon (8 rounds)",
Ascon.State,
Ascon.Init,
Ascon.Permutations.Permute_8);
procedure Benchmark_Ascon6 is new KeccakF_Benchmark
("Ascon (6 rounds)",
Ascon.State,
Ascon.Init,
Ascon.Permutations.Permute_6);
procedure Benchmark_Ascon_Hash is new Hash_Benchmark
("Ascon-Hash",
Ascon.Hash);
begin
Data_Chunk.all := (others => 16#A7#);
Put ("Message size: ");
Ada.Integer_Text_IO.Put (Data_Chunk.all'Length, Width => 0);
Put (" bytes");
New_Line;
Put ("Performing ");
Ada.Integer_Text_IO.Put (Repeat, Width => 0);
Put (" measurements for each test");
New_Line;
New_Line;
Benchmark_Gimli;
Benchmark_Gimli_Hash;
Benchmark_Ascon12;
Benchmark_Ascon8;
Benchmark_Ascon6;
Benchmark_Ascon_Hash;
Benchmark_K12;
Benchmark_M14;
Benchmark_ParallelHash128;
Benchmark_ParallelHash256;
Benchmark_SHA_224;
Benchmark_SHA_256;
Benchmark_SHA_384;
Benchmark_SHA_512;
Benchmark_Keccak_224;
Benchmark_Keccak_256;
Benchmark_Keccak_384;
Benchmark_Keccak_512;
Benchmark_SHAKE128;
Benchmark_SHAKE256;
Benchmark_RawSHAKE128;
Benchmark_RawSHAKE256;
Benchmark_Duplex_r1152c448;
Benchmark_Duplex_r1088c512;
Benchmark_Duplex_r832c768;
Benchmark_Duplex_r576c1024;
Benchmark_KeccakF_1600_R24;
Benchmark_KeccakF_1600_P2_R24;
Benchmark_KeccakF_1600_P4_R24;
Benchmark_KeccakF_1600_P8_R24;
Benchmark_KeccakF_1600_R12;
Benchmark_KeccakF_1600_P2_R12;
Benchmark_KeccakF_1600_P4_R12;
Benchmark_KeccakF_1600_P8_R12;
Benchmark_KeccakF_800;
Benchmark_KeccakF_400;
Benchmark_KeccakF_200;
Benchmark_KeccakF_100;
Benchmark_KeccakF_50;
Benchmark_KeccakF_25;
Benchmark_Ketje_Jr;
Benchmark_Ketje_Sr;
Benchmark_Ketje_Minor;
Benchmark_Ketje_Major;
end Benchmark;
|
-- Standard Ada library specification
-- Copyright (c) 2003-2018 Maxim Reznik <reznikmm@gmail.com>
-- Copyright (c) 2004-2016 AXE Consultants
-- Copyright (c) 2004, 2005, 2006 Ada-Europe
-- Copyright (c) 2000 The MITRE Corporation, Inc.
-- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc.
-- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual
---------------------------------------------------------------------------
package Ada.Assertions is
pragma Pure (Assertions);
Assertion_Error : exception;
procedure Assert (Check : in Boolean);
procedure Assert (Check : in Boolean; Message : in String);
end Ada.Assertions;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2017 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with Ada.Exceptions;
-- with Ada.Real_Time;
with Ada.Tags;
-- with Ada.Text_IO;
with Orka.Containers.Bounded_Vectors;
with Orka.Futures;
with Orka.Loggers;
with Orka.Logging;
package body Orka.Jobs.Executors is
use all type Orka.Logging.Source;
use all type Orka.Logging.Severity;
package Messages is new Orka.Logging.Messages (Worker);
function Get_Root_Dependent (Element : Job_Ptr) return Job_Ptr is
Result : Job_Ptr := Element;
begin
while Result.Dependent /= Null_Job loop
Result := Result.Dependent;
end loop;
return Result;
end Get_Root_Dependent;
procedure Execute_Jobs
(Name : String;
Kind : Queues.Executor_Kind;
Queue : Queues.Queue_Ptr)
is
-- use type Ada.Real_Time.Time;
use type Futures.Status;
use Ada.Exceptions;
Pair : Queues.Pair;
Stop : Boolean := False;
Null_Pair : constant Queues.Pair := (others => <>);
package Vectors is new Orka.Containers.Bounded_Vectors (Positive, Job_Ptr);
-- T0, T1, T2 : Ada.Real_Time.Time;
begin
loop
-- T0 := Ada.Real_Time.Clock;
Queue.Dequeue (Kind) (Pair, Stop);
exit when Stop;
declare
Job : Job_Ptr renames Pair.Job;
Future : Futures.Pointers.Reference renames Pair.Future.Get;
Promise : Futures.Promise'Class renames Futures.Promise'Class (Future.Value.all);
Jobs : Vectors.Vector (Capacity => Maximum_Enqueued_By_Job);
type Executor_Context is new Execution_Context with null record;
overriding
procedure Enqueue (Object : Executor_Context; Element : Job_Ptr) is
begin
Jobs.Append (Element);
end Enqueue;
Context : Executor_Context;
procedure Set_Root_Dependent (Last_Job : Job_Ptr) is
Root_Dependents : Vectors.Vector (Capacity => Jobs.Length);
procedure Set_Dependencies (Elements : Vectors.Element_Array) is
begin
Last_Job.Set_Dependencies (Dependency_Array (Elements));
end Set_Dependencies;
begin
for Job of Jobs loop
declare
Root : constant Job_Ptr := Get_Root_Dependent (Job);
begin
if not (for some Dependent of Root_Dependents => Root = Dependent) then
Root_Dependents.Append (Root);
end if;
end;
end loop;
Root_Dependents.Query (Set_Dependencies'Access);
end Set_Root_Dependent;
Tag : String renames Ada.Tags.Expanded_Name (Job'Tag);
begin
-- T1 := Ada.Real_Time.Clock;
-- Ada.Text_IO.Put_Line (Name & " executing job " & Tag);
if Future.Current_Status = Futures.Waiting then
Promise.Set_Status (Futures.Running);
end if;
if Future.Current_Status = Futures.Running then
begin
Job.Execute (Context);
exception
when Error : others =>
Promise.Set_Failed (Error);
Messages.Log (Loggers.Error,
Kind'Image & " job " & Tag & " " & Exception_Information (Error));
end;
else
Messages.Log (Warning,
Kind'Image & " job " & Tag & " already " & Future.Current_Status'Image);
end if;
-- T2 := Ada.Real_Time.Clock;
-- declare
-- Waiting_Time : constant Duration := 1e3 * Ada.Real_Time.To_Duration (T1 - T0);
-- Running_Time : constant Duration := 1e3 * Ada.Real_Time.To_Duration (T2 - T1);
-- begin
-- Ada.Text_IO.Put_Line (Name & " (blocked" & Waiting_Time'Image & " ms)" &
-- " executed job " & Tag & " in" & Running_Time'Image & " ms");
-- end;
if Job.Dependent /= Null_Job then
-- Make the root dependents of the jobs in Jobs
-- dependencies of Job.Dependent
if not Jobs.Is_Empty then
Set_Root_Dependent (Job.Dependent);
end if;
-- If another job depends on this job, decrement its dependencies counter
-- and if it has reached zero then it can be scheduled
if Job.Dependent.Decrement_Dependencies then
pragma Assert (Jobs.Is_Empty);
-- Ada.Text_IO.Put_Line (Name & " job " & Tag & " enqueuing dependent " &
-- Ada.Tags.Expanded_Name (Job.Dependent'Tag));
Queue.Enqueue (Job.Dependent, Pair.Future);
end if;
elsif Jobs.Is_Empty then
Promise.Set_Status (Futures.Done);
-- Ada.Text_IO.Put_Line (Name & " completed graph with job " & Tag);
else
-- If the job has enqueued new jobs, we need to create an
-- empty job which has the root dependents of these new jobs
-- as dependencies. This is so that the empty job will be the
-- last job that is given Pair.Future
Set_Root_Dependent (Create_Empty_Job);
end if;
if not Jobs.Is_Empty then
for Job of Jobs loop
-- Ada.Text_IO.Put_Line (Name & " job " & Tag & " enqueuing job " &
-- Ada.Tags.Expanded_Name (Job'Tag));
Queue.Enqueue (Job, Pair.Future);
end loop;
end if;
Free (Job);
end;
-- Finalize the smart pointer (Pair.Future) to reduce the number
-- of references to the Future object
Pair := Null_Pair;
end loop;
exception
when Error : others =>
Messages.Log (Loggers.Error, Exception_Information (Error));
end Execute_Jobs;
end Orka.Jobs.Executors;
|
-- { dg-do run }
-- { dg-options "-O2 -gnatp" }
procedure Bit_Packed_Array3 is
type Bitmap_T is array (1 .. 10) of Boolean;
pragma Pack (Bitmap_T);
type Maps_T is record
M1 : Bitmap_T;
end record;
pragma Pack (Maps_T);
for Maps_T'Size use 10;
pragma Suppress_Initialization (Maps_T);
Tmap : constant Bitmap_T := (others => True);
Fmap : constant Bitmap_T := (others => False);
Amap : constant Bitmap_T :=
(1 => False, 2 => True, 3 => False, 4 => True, 5 => False,
6 => True, 7 => False, 8 => True, 9 => False, 10 => True);
function Some_Maps return Maps_T is
Value : Maps_T := (M1 => Amap);
begin
return Value;
end;
pragma Inline (Some_Maps);
Maps : Maps_T;
begin
Maps := Some_Maps;
for I in Maps.M1'Range loop
if (I mod 2 = 0 and then not Maps.M1 (I))
or else (I mod 2 /= 0 and then Maps.M1 (I))
then
raise Program_Error;
end if;
end loop;
end;
|
with Ada.Text_IO.Formatting;
with System.Formatting.Literals;
with System.Long_Long_Integer_Types;
package body Ada.Text_IO.Integer_IO is
subtype Word_Integer is System.Long_Long_Integer_Types.Word_Integer;
procedure Put_To_Field (
To : out String;
Last : out Natural;
Item : Num;
Base : Number_Base);
procedure Put_To_Field (
To : out String;
Last : out Natural;
Item : Num;
Base : Number_Base) is
begin
if Num'Size > Standard'Word_Size then
Formatting.Integer_Image (To, Last, Long_Long_Integer (Item), Base);
else
Formatting.Integer_Image (To, Last, Word_Integer (Item), Base);
end if;
end Put_To_Field;
procedure Get_From_Field (
From : String;
Item : out Num;
Last : out Positive);
procedure Get_From_Field (
From : String;
Item : out Num;
Last : out Positive) is
begin
if Num'Size > Standard'Word_Size then
declare
Base_Item : Long_Long_Integer;
Error : Boolean;
begin
System.Formatting.Literals.Get_Literal (
From,
Last,
Base_Item,
Error => Error);
if Error
or else Base_Item not in
Long_Long_Integer (Num'First) .. Long_Long_Integer (Num'Last)
then
raise Data_Error;
end if;
Item := Num (Base_Item);
end;
else
declare
Base_Item : Word_Integer;
Error : Boolean;
begin
System.Formatting.Literals.Get_Literal (
From,
Last,
Base_Item,
Error => Error);
if Error
or else Base_Item not in
Word_Integer (Num'First) .. Word_Integer (Num'Last)
then
raise Data_Error;
end if;
Item := Num (Base_Item);
end;
end if;
end Get_From_Field;
-- implementation
procedure Get (
File : File_Type;
Item : out Num;
Width : Field := 0) is
begin
if Width /= 0 then
declare
S : String (1 .. Width);
Last_1 : Natural;
Last_2 : Natural;
begin
Formatting.Get_Field (File, S, Last_1); -- checking the predicate
Get_From_Field (S (1 .. Last_1), Item, Last_2);
if Last_2 /= Last_1 then
raise Data_Error;
end if;
end;
else
declare
S : constant String :=
Formatting.Get_Numeric_Literal (
File, -- checking the predicate
Real => False);
Last : Natural;
begin
Get_From_Field (S, Item, Last);
if Last /= S'Last then
raise Data_Error;
end if;
end;
end if;
end Get;
procedure Get (
Item : out Num;
Width : Field := 0) is
begin
Get (Current_Input.all, Item, Width);
end Get;
procedure Get (
File : not null File_Access;
Item : out Num;
Width : Field := 0) is
begin
Get (File.all, Item, Width);
end Get;
procedure Put (
File : File_Type;
Item : Num;
Width : Field := Default_Width;
Base : Number_Base := Default_Base)
is
S : String (1 .. 4 + Num'Width + Width); -- "16##"
Last : Natural;
begin
Put_To_Field (S, Last, Item, Base);
Formatting.Tail (File, S (1 .. Last), Width); -- checking the predicate
end Put;
procedure Put (
Item : Num;
Width : Field := Default_Width;
Base : Number_Base := Default_Base) is
begin
Put (Current_Output.all, Item, Width, Base);
end Put;
procedure Put (
File : not null File_Access;
Item : Num;
Width : Field := Default_Width;
Base : Number_Base := Default_Base) is
begin
Put (File.all, Item, Width, Base);
end Put;
procedure Get (
From : String;
Item : out Num;
Last : out Positive) is
begin
Formatting.Get_Tail (From, First => Last);
Get_From_Field (From (Last .. From'Last), Item, Last);
end Get;
procedure Put (
To : out String;
Item : Num;
Base : Number_Base := Default_Base)
is
S : String (1 .. To'Length);
Last : Natural;
begin
Put_To_Field (S, Last, Item, Base);
Formatting.Tail (To, S (1 .. Last));
end Put;
end Ada.Text_IO.Integer_IO;
|
-- Shoot'n'loot
-- Copyright (c) 2020 Fabien Chouteau
with Game_Assets.Tileset;
with Game_Assets.Tileset_Collisions;
with Game_Assets.Misc_Objects;
with GESTE_Config; use GESTE_Config;
with GESTE.Tile_Bank;
with GESTE.Sprite.Animated;
with Sound;
package body Monsters is
package Item renames Game_Assets.Misc_Objects.Item;
Tile_Bank : aliased GESTE.Tile_Bank.Instance
(Game_Assets.Tileset.Tiles'Access,
Game_Assets.Tileset_Collisions.Tiles'Access,
Game_Assets.Palette'Access);
Empty_Tile : constant GESTE_Config.Tile_Index := Item.Empty_Tile.Tile_Id;
type Monster_Rec is record
Sprite : aliased GESTE.Sprite.Animated.Instance
(Tile_Bank'Access,
GESTE_Config.No_Tile);
Origin : GESTE.Pix_Point;
Pos : GESTE.Pix_Point;
Alive : Boolean := False;
Going_Right : Boolean := True;
Offset : Natural := 0;
end record;
Monster_Array : array (1 .. Max_Nbr_Of_Monsters) of Monster_Rec;
Last_Monster : Natural := 0;
Nbr_Killed : Natural := 0;
Anim_Step_Duration : constant := 10;
Monster_Animation : aliased constant GESTE.Sprite.Animated.Animation_Array :=
((Item.M1.Tile_Id, Anim_Step_Duration),
(Item.M2.Tile_Id, Anim_Step_Duration),
(Item.M3.Tile_Id, Anim_Step_Duration),
(Item.M4.Tile_Id, Anim_Step_Duration),
(Item.M5.Tile_Id, Anim_Step_Duration),
(Item.M6.Tile_Id, Anim_Step_Duration),
(Item.M7.Tile_Id, Anim_Step_Duration));
----------
-- Init --
----------
procedure Init (Objects : Object_Array) is
begin
Last_Monster := 0;
Nbr_Killed := 0;
for Monster of Objects loop
Last_Monster := Last_Monster + 1;
declare
M : Monster_Rec renames Monster_Array (Last_Monster);
begin
M.Sprite.Set_Animation (Monster_Animation'Access, Looping => True);
M.Alive := True;
M.Origin := (Integer (Monster.X), Integer (Monster.Y) - 8);
M.Pos := M.Origin;
M.Sprite.Move (M.Origin);
GESTE.Add (M.Sprite'Access, 2);
end;
end loop;
end Init;
---------------
-- Check_Hit --
---------------
function Check_Hit (Pt : GESTE.Pix_Point;
Lethal : Boolean)
return Boolean
is
begin
for M of Monster_Array (Monster_Array'First .. Last_Monster) loop
if M.Alive
and then
Pt.X in M.Pos.X .. M.Pos.X + Tile_Size
and then
Pt.Y in M.Pos.Y .. M.Pos.Y + Tile_Size
then
if Lethal then
-- Replace the monster by an empty tile to erase it from the
-- screen.
M.Sprite.Set_Animation (GESTE.Sprite.Animated.No_Animation,
Looping => False);
M.Sprite.Set_Tile (Empty_Tile);
M.Alive := False;
Nbr_Killed := Nbr_Killed + 1;
Sound.Play_Monster_Dead;
end if;
return True;
end if;
end loop;
return False;
end Check_Hit;
----------------
-- All_Killed --
----------------
function All_Killed return Boolean
is (Nbr_Killed = Last_Monster);
------------
-- Update --
------------
procedure Update is
begin
for M of Monster_Array (Monster_Array'First .. Last_Monster) loop
if M.Alive then
M.Sprite.Signal_Frame;
M.Pos := (M.Origin.X + M.Offset / 5, M.Origin.Y);
M.Sprite.Move (M.Pos);
if M.Going_Right then
if M.Offset >= GESTE_Config.Tile_Size * 2 * 5 then
M.Going_Right := False;
else
M.Offset := M.Offset + 1;
end if;
else
if M.Offset = 0 then
M.Going_Right := True;
else
M.Offset := M.Offset - 1;
end if;
end if;
end if;
end loop;
end Update;
end Monsters;
|
pragma Ada_2012;
with Protypo.Code_Trees.Interpreter.Expressions;
with Protypo.Code_Trees.Interpreter.Symbol_Table_References;
pragma Warnings (Off, "no entities of ""Ada.Text_IO"" are referenced");
with Ada.Text_Io; use Ada.Text_Io;
package body Protypo.Code_Trees.Interpreter.Names is
---------------
-- Eval_Name --
---------------
function Eval_Name (Status : Interpreter_Access;
Expr : not null Node_Access)
return Name_Reference
is
---------
-- "+" --
---------
function "+" (X : Handler_Value) return Name_Reference
is
begin
if not (X.Class in Handler_Classes) then
raise Program_Error with X.Class'Image & "is not handler class";
end if;
case Handler_Classes (X.Class) is
when Array_Handler =>
return Name_Reference'(Class => Array_Reference,
Array_Handler => Handlers.Get_Array (X));
when Record_Handler =>
return Name_Reference'(Class => Record_Reference,
Record_Handler => Handlers.Get_Record (X));
when Ambivalent_Handler =>
return Name_Reference'(Class => Ambivalent_Reference,
Ambivalent_Handler => Handlers.Get_Ambivalent (X));
when Function_Handler =>
return Name_Reference'(Class => Function_Reference,
Function_Handler => Handlers.Get_Function (X),
Parameters => <>);
when Reference_Handler =>
return Name_Reference'(Class => Variable_Reference,
Variable_Handler => Handlers.Get_Reference (X));
when Constant_Handler =>
return Name_Reference'(Class => Constant_Reference,
Costant_Handler => Handlers.Get_Constant (X));
end case;
end "+";
begin
-- Put_Line ("#1" & Expr.Class'Image);
if not (Expr.Class in Name) then
raise Program_Error;
end if;
case Name (Expr.Class) is
when Selected =>
declare
Head : constant Name_Reference := Eval_Name (Status, Expr.Record_Var);
Field : constant Id := Id (To_String (Expr.Field_Name));
begin
case Head.Class is
when Record_Reference =>
if not Head.Record_Handler.Is_Field (Field) then
raise Bad_Field with "Unknown field '" & String (Field) & "'";
end if;
return + Head.Record_Handler.Get (Field);
when Ambivalent_Reference =>
if not Head.Ambivalent_Handler.Is_Field (Field) then
raise Bad_Field with "Unknown field '" & String (Field) & "'";
end if;
return + Head.Ambivalent_Handler.Get (Field);
when others =>
raise Run_Time_Error
with
"Record access to non-record value, class="
& Head.Class'Image;
end case;
end;
when Indexed =>
declare
subtype Indexed_References is Value_Name_Class
with Static_Predicate =>
Indexed_References
in Array_Reference |
Function_Reference |
Ambivalent_Reference;
Head : constant Name_Reference :=
Eval_Name (Status, Expr.Indexed_Var);
Indexes : constant Engine_Value_Vectors.Vector :=
Expressions.Eval_Vector (Status, Expr.Indexes);
begin
if not (Head.Class in Indexed_References) then
raise Run_Time_Error
with
"Indexed access to a value of class="
& Head.Class'Image
& " at " & Tokens.Image (Expr.Source_Position)
& " in an expression of class="
& Expr.Class'Image;
end if;
case Indexed_References (Head.Class) is
when Array_Reference =>
return + Head.Array_Handler.Get (Indexes);
when Function_Reference =>
return Name_Reference'(Class => Function_Call,
Function_Handler => Head.Function_Handler,
Parameters => Indexes);
when Ambivalent_Reference =>
-- Put_Line ("@@@ index");
return + Head.Ambivalent_Handler.Get (Indexes);
end case;
end;
when Identifier =>
declare
use Api.Symbols.Protypo_Tables;
use Protypo.Code_Trees.Interpreter.Symbol_Table_References;
Ident : constant Id := To_Id (Expr.Id_Value);
Position : Cursor := Status.Symbol_Table.Find (Ident);
begin
-- Put_Line ("@@@ searching '" & String(IDent) & "'");
if Position = No_Element then
-- Put_Line ("@@@ not found '" & ID & "'");
--
-- The name is not in the symbol table: create it
-- but leave it not initialized, it can be used only
-- as a LHS.
--
Status.Symbol_Table.Create (Name => Ident,
Position => Position,
Initial_Value => Void_Value);
-- Put_Line ("@@@ inserted '" & ID & "' @" & Image (Position));
if Position = No_Element then
raise Program_Error with "something bad";
end if;
declare
X : constant Api.Engine_Values.Handlers.Reference_Interface_Access :=
Symbol_Table_Reference (Position);
Result : Name_Reference :=
(Class => Variable_Reference,
Variable_Handler => X);
begin
-- Put_Line ("@@@ hh");
Result.Variable_Handler := X;
-- Put_Line ("@@@ hhh");
return Result;
end;
else
--
-- The name is in the symbol table. If its value is an
-- handler, returnt the handler; otherwise return the
-- reference to the symbol table. Remember that the
-- result of the evaluation of a name is always a reference.
--
declare
Val : constant Engine_Value := Value (Position);
begin
if Val.Class in Handler_Classes then
return + Val;
else
return Name_Reference'
(Class => Variable_Reference,
Variable_Handler => Symbol_Table_Reference (Position));
end if;
end;
end if;
end;
end case;
exception
when Handlers.Unknown_Field =>
raise Run_Time_Error with "Unknown field at " & Tokens.Image (Expr.Source_Position);
end Eval_Name;
end Protypo.Code_Trees.Interpreter.Names;
|
--
-- Copyright (C) 2015-2018 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.GMA.Registers;
with HW.GFX.GMA.Config;
private package HW.GFX.GMA.Transcoder
is
procedure Setup (Pipe : Pipe_Index; Port_Cfg : Port_Config);
procedure On
(Pipe : Pipe_Index;
Port_Cfg : Port_Config;
Dither : Boolean;
Scale : Boolean);
procedure Off (Pipe : Pipe_Index);
procedure Clk_Off (Pipe : Pipe_Index);
function BPC_Conf (BPC : BPC_Type; Dither : Boolean) return Word32;
private
type Transcoder_Index is (Trans_EDP, Trans_A, Trans_B, Trans_C);
type Transcoder_Regs is
record
HTOTAL : Registers.Registers_Index;
HBLANK : Registers.Registers_Index;
HSYNC : Registers.Registers_Index;
VTOTAL : Registers.Registers_Index;
VBLANK : Registers.Registers_Index;
VSYNC : Registers.Registers_Index;
CONF : Registers.Registers_Index;
DATA_M1 : Registers.Registers_Index;
DATA_N1 : Registers.Registers_Index;
LINK_M1 : Registers.Registers_Index;
LINK_N1 : Registers.Registers_Index;
DDI_FUNC_CTL : Registers.Registers_Index;
MSA_MISC : Registers.Registers_Index;
CLK_SEL : Registers.Registers_Invalid_Index;
end record;
type Transcoder_Array is array (Transcoder_Index) of Transcoder_Regs;
PIPE_DATA_M1 : constant array (0 .. 1) of Registers.Registers_Index :=
(if Config.Has_GMCH_DP_Transcoder then
(0 => Registers.PIPEA_GMCH_DATA_M,
1 => Registers.PIPEB_GMCH_DATA_M)
else
(0 => Registers.PIPEA_DATA_M1,
1 => Registers.PIPEB_DATA_M1));
PIPE_DATA_N1 : constant array (0 .. 1) of Registers.Registers_Index :=
(if Config.Has_GMCH_DP_Transcoder then
(0 => Registers.PIPEA_GMCH_DATA_N,
1 => Registers.PIPEB_GMCH_DATA_N)
else
(0 => Registers.PIPEA_DATA_N1,
1 => Registers.PIPEB_DATA_N1));
PIPE_LINK_M1 : constant array (0 .. 1) of Registers.Registers_Index :=
(if Config.Has_GMCH_DP_Transcoder then
(0 => Registers.PIPEA_GMCH_LINK_M,
1 => Registers.PIPEB_GMCH_LINK_M)
else
(0 => Registers.PIPEA_LINK_M1,
1 => Registers.PIPEB_LINK_M1));
PIPE_LINK_N1 : constant array (0 .. 1) of Registers.Registers_Index :=
(if Config.Has_GMCH_DP_Transcoder then
(0 => Registers.PIPEA_GMCH_LINK_N,
1 => Registers.PIPEB_GMCH_LINK_N)
else
(0 => Registers.PIPEA_LINK_N1,
1 => Registers.PIPEB_LINK_N1));
Transcoders : constant Transcoder_Array :=
(Trans_EDP =>
(HTOTAL => Registers.HTOTAL_EDP,
HBLANK => Registers.HBLANK_EDP,
HSYNC => Registers.HSYNC_EDP,
VTOTAL => Registers.VTOTAL_EDP,
VBLANK => Registers.VBLANK_EDP,
VSYNC => Registers.VSYNC_EDP,
CONF => Registers.PIPE_EDP_CONF,
DATA_M1 => Registers.PIPE_EDP_DATA_M1,
DATA_N1 => Registers.PIPE_EDP_DATA_N1,
LINK_M1 => Registers.PIPE_EDP_LINK_M1,
LINK_N1 => Registers.PIPE_EDP_LINK_N1,
DDI_FUNC_CTL => Registers.PIPE_EDP_DDI_FUNC_CTL,
MSA_MISC => Registers.PIPE_EDP_MSA_MISC,
CLK_SEL => Registers.Invalid_Register),
Trans_A =>
(HTOTAL => Registers.HTOTAL_A,
HBLANK => Registers.HBLANK_A,
HSYNC => Registers.HSYNC_A,
VTOTAL => Registers.VTOTAL_A,
VBLANK => Registers.VBLANK_A,
VSYNC => Registers.VSYNC_A,
CONF => Registers.PIPEACONF,
DATA_M1 => PIPE_DATA_M1 (0),
DATA_N1 => PIPE_DATA_N1 (0),
LINK_M1 => PIPE_LINK_M1 (0),
LINK_N1 => PIPE_LINK_N1 (0),
DDI_FUNC_CTL => Registers.PIPEA_DDI_FUNC_CTL,
MSA_MISC => Registers.PIPEA_MSA_MISC,
CLK_SEL => Registers.TRANSA_CLK_SEL),
Trans_B =>
(HTOTAL => Registers.HTOTAL_B,
HBLANK => Registers.HBLANK_B,
HSYNC => Registers.HSYNC_B,
VTOTAL => Registers.VTOTAL_B,
VBLANK => Registers.VBLANK_B,
VSYNC => Registers.VSYNC_B,
CONF => Registers.PIPEBCONF,
DATA_M1 => PIPE_DATA_M1 (1),
DATA_N1 => PIPE_DATA_N1 (1),
LINK_M1 => PIPE_LINK_M1 (1),
LINK_N1 => PIPE_LINK_N1 (1),
DDI_FUNC_CTL => Registers.PIPEB_DDI_FUNC_CTL,
MSA_MISC => Registers.PIPEB_MSA_MISC,
CLK_SEL => Registers.TRANSB_CLK_SEL),
Trans_C =>
(HTOTAL => Registers.HTOTAL_C,
HBLANK => Registers.HBLANK_C,
HSYNC => Registers.HSYNC_C,
VTOTAL => Registers.VTOTAL_C,
VBLANK => Registers.VBLANK_C,
VSYNC => Registers.VSYNC_C,
CONF => Registers.PIPECCONF,
DATA_M1 => Registers.PIPEC_DATA_M1,
DATA_N1 => Registers.PIPEC_DATA_N1,
LINK_M1 => Registers.PIPEC_LINK_M1,
LINK_N1 => Registers.PIPEC_LINK_N1,
DDI_FUNC_CTL => Registers.PIPEC_DDI_FUNC_CTL,
MSA_MISC => Registers.PIPEC_MSA_MISC,
CLK_SEL => Registers.TRANSC_CLK_SEL));
end HW.GFX.GMA.Transcoder;
|
with Ada.Finalization;
with Ada.Streams;
with League.Stream_Element_Vectors;
with League.String_Vectors;
with League.Strings;
with PB_Support.Vectors;
package Conformance.Conformance is
type Wire_Format is (UNSPECIFIED, PROTOBUF, JSON, JSPB, TEXT_FORMAT);
for Wire_Format use
(UNSPECIFIED => 0, PROTOBUF => 1, JSON => 2, JSPB => 3,
TEXT_FORMAT => 4);
package Wire_Format_Vectors is new PB_Support.Vectors (Wire_Format);
type Test_Category is
(UNSPECIFIED_TEST, BINARY_TEST, JSON_TEST,
JSON_IGNORE_UNKNOWN_PARSING_TEST, JSPB_TEST, TEXT_FORMAT_TEST);
for Test_Category use
(UNSPECIFIED_TEST => 0,
BINARY_TEST => 1,
JSON_TEST => 2,
JSON_IGNORE_UNKNOWN_PARSING_TEST => 3,
JSPB_TEST => 4,
TEXT_FORMAT_TEST => 5);
package Test_Category_Vectors is new PB_Support.Vectors (Test_Category);
type Failure_Set_Vector is tagged private
with Variable_Indexing => Get_Failure_Set_Variable_Reference,
Constant_Indexing => Get_Failure_Set_Constant_Reference;
type Conformance_Request_Vector is tagged private
with Variable_Indexing => Get_Conformance_Request_Variable_Reference,
Constant_Indexing => Get_Conformance_Request_Constant_Reference;
type Conformance_Response_Vector is tagged private
with Variable_Indexing => Get_Conformance_Response_Variable_Reference,
Constant_Indexing => Get_Conformance_Response_Constant_Reference;
type Jspb_Encoding_Config_Vector is tagged private
with Variable_Indexing => Get_Jspb_Encoding_Config_Variable_Reference,
Constant_Indexing => Get_Jspb_Encoding_Config_Constant_Reference;
type Failure_Set is
record
Failure : League.String_Vectors.Universal_String_Vector;
end record;
type Optional_Failure_Set (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Conformance.Failure_Set;
when False =>
null;
end case;
end record;
function Length (Self : Failure_Set_Vector) return Natural;
procedure Clear (Self : in out Failure_Set_Vector);
procedure Append (Self : in out Failure_Set_Vector; V : Failure_Set);
type Failure_Set_Variable_Reference
(Element : not null access Failure_Set) is null record
with Implicit_Dereference => Element;
not overriding function Get_Failure_Set_Variable_Reference
(Self : aliased in out Failure_Set_Vector;
Index : Positive)
return Failure_Set_Variable_Reference
with Inline;
type Failure_Set_Constant_Reference
(Element : not null access constant Failure_Set) is null record
with Implicit_Dereference => Element;
not overriding function Get_Failure_Set_Constant_Reference
(Self : aliased Failure_Set_Vector;
Index : Positive)
return Failure_Set_Constant_Reference
with Inline;
type Conformance_Response_Variant_Kind is
(Result_Not_Set,
Parse_Error_Kind,
Serialize_Error_Kind,
Runtime_Error_Kind,
Protobuf_Payload_Kind,
Json_Payload_Kind,
Skipped_Kind ,
Jspb_Payload_Kind,
Text_Payload_Kind);
type Conformance_Response_Variant
(Result : Conformance_Response_Variant_Kind := Result_Not_Set) is
record
case Result is
when Result_Not_Set =>
null;
when Parse_Error_Kind =>
Parse_Error : League.Strings.Universal_String;
when Serialize_Error_Kind =>
Serialize_Error : League.Strings.Universal_String;
when Runtime_Error_Kind =>
Runtime_Error : League.Strings.Universal_String;
when Protobuf_Payload_Kind =>
Protobuf_Payload : League.Stream_Element_Vectors
.Stream_Element_Vector;
when Json_Payload_Kind =>
Json_Payload : League.Strings.Universal_String;
when Skipped_Kind =>
Skipped : League.Strings.Universal_String;
when Jspb_Payload_Kind =>
Jspb_Payload : League.Strings.Universal_String;
when Text_Payload_Kind =>
Text_Payload : League.Strings.Universal_String;
end case;
end record;
type Conformance_Response is
record
Variant : Conformance_Response_Variant;
end record;
type Optional_Conformance_Response (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Conformance.Conformance_Response;
when False =>
null;
end case;
end record;
function Length (Self : Conformance_Response_Vector) return Natural;
procedure Clear (Self : in out Conformance_Response_Vector);
procedure Append
(Self : in out Conformance_Response_Vector;
V : Conformance_Response);
type Conformance_Response_Variable_Reference
(Element : not null access Conformance_Response) is null record
with Implicit_Dereference => Element;
not overriding function Get_Conformance_Response_Variable_Reference
(Self : aliased in out Conformance_Response_Vector;
Index : Positive)
return Conformance_Response_Variable_Reference
with Inline;
type Conformance_Response_Constant_Reference
(Element : not null access constant Conformance_Response) is null record
with Implicit_Dereference => Element;
not overriding function Get_Conformance_Response_Constant_Reference
(Self : aliased Conformance_Response_Vector;
Index : Positive)
return Conformance_Response_Constant_Reference
with Inline;
type Jspb_Encoding_Config is
record
Use_Jspb_Array_Any_Format : Boolean := False;
end record;
type Optional_Jspb_Encoding_Config (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Conformance.Jspb_Encoding_Config;
when False =>
null;
end case;
end record;
function Length (Self : Jspb_Encoding_Config_Vector) return Natural;
procedure Clear (Self : in out Jspb_Encoding_Config_Vector);
procedure Append
(Self : in out Jspb_Encoding_Config_Vector;
V : Jspb_Encoding_Config);
type Jspb_Encoding_Config_Variable_Reference
(Element : not null access Jspb_Encoding_Config) is null record
with Implicit_Dereference => Element;
not overriding function Get_Jspb_Encoding_Config_Variable_Reference
(Self : aliased in out Jspb_Encoding_Config_Vector;
Index : Positive)
return Jspb_Encoding_Config_Variable_Reference
with Inline;
type Jspb_Encoding_Config_Constant_Reference
(Element : not null access constant Jspb_Encoding_Config) is null record
with Implicit_Dereference => Element;
not overriding function Get_Jspb_Encoding_Config_Constant_Reference
(Self : aliased Jspb_Encoding_Config_Vector;
Index : Positive)
return Jspb_Encoding_Config_Constant_Reference
with Inline;
type Conformance_Request_Variant_Kind is
(Payload_Not_Set,
Protobuf_Payload_Kind,
Json_Payload_Kind,
Jspb_Payload_Kind,
Text_Payload_Kind);
type Conformance_Request_Variant
(Payload : Conformance_Request_Variant_Kind := Payload_Not_Set) is
record
case Payload is
when Payload_Not_Set =>
null;
when Protobuf_Payload_Kind =>
Protobuf_Payload : League.Stream_Element_Vectors
.Stream_Element_Vector;
when Json_Payload_Kind =>
Json_Payload : League.Strings.Universal_String;
when Jspb_Payload_Kind =>
Jspb_Payload : League.Strings.Universal_String;
when Text_Payload_Kind =>
Text_Payload : League.Strings.Universal_String;
end case;
end record;
type Conformance_Request is
record
Requested_Output_Format : Conformance.Wire_Format :=
Conformance.UNSPECIFIED;
Message_Type : League.Strings.Universal_String;
Test_Category : Conformance.Test_Category :=
Conformance.UNSPECIFIED_TEST;
Jspb_Encoding_Options : Conformance.Optional_Jspb_Encoding_Config;
Print_Unknown_Fields : Boolean := False;
Variant : Conformance_Request_Variant;
end record;
type Optional_Conformance_Request (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Conformance.Conformance_Request;
when False =>
null;
end case;
end record;
function Length (Self : Conformance_Request_Vector) return Natural;
procedure Clear (Self : in out Conformance_Request_Vector);
procedure Append
(Self : in out Conformance_Request_Vector;
V : Conformance_Request);
type Conformance_Request_Variable_Reference
(Element : not null access Conformance_Request) is null record
with Implicit_Dereference => Element;
not overriding function Get_Conformance_Request_Variable_Reference
(Self : aliased in out Conformance_Request_Vector;
Index : Positive)
return Conformance_Request_Variable_Reference
with Inline;
type Conformance_Request_Constant_Reference
(Element : not null access constant Conformance_Request) is null record
with Implicit_Dereference => Element;
not overriding function Get_Conformance_Request_Constant_Reference
(Self : aliased Conformance_Request_Vector;
Index : Positive)
return Conformance_Request_Constant_Reference
with Inline;
private
procedure Read_Failure_Set
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Failure_Set);
procedure Write_Failure_Set
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Failure_Set);
for Failure_Set'Read use Read_Failure_Set;
for Failure_Set'Write use Write_Failure_Set;
type Failure_Set_Array is array (Positive range <>) of aliased Failure_Set;
type Failure_Set_Array_Access is access Failure_Set_Array;
type Failure_Set_Vector is
new Ada.Finalization.Controlled
with record
Data : Failure_Set_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Failure_Set_Vector);
overriding procedure Finalize (Self : in out Failure_Set_Vector);
procedure Read_Conformance_Request
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Conformance_Request);
procedure Write_Conformance_Request
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Conformance_Request);
for Conformance_Request'Read use Read_Conformance_Request;
for Conformance_Request'Write use Write_Conformance_Request;
type Conformance_Request_Array is
array (Positive range <>) of aliased Conformance_Request;
type Conformance_Request_Array_Access is access Conformance_Request_Array;
type Conformance_Request_Vector is
new Ada.Finalization.Controlled
with record
Data : Conformance_Request_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Conformance_Request_Vector);
overriding procedure Finalize (Self : in out Conformance_Request_Vector);
procedure Read_Conformance_Response
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Conformance_Response);
procedure Write_Conformance_Response
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Conformance_Response);
for Conformance_Response'Read use Read_Conformance_Response;
for Conformance_Response'Write use Write_Conformance_Response;
type Conformance_Response_Array is
array (Positive range <>) of aliased Conformance_Response;
type Conformance_Response_Array_Access is access Conformance_Response_Array;
type Conformance_Response_Vector is
new Ada.Finalization.Controlled
with record
Data : Conformance_Response_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Conformance_Response_Vector);
overriding procedure Finalize (Self : in out Conformance_Response_Vector);
procedure Read_Jspb_Encoding_Config
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Jspb_Encoding_Config);
procedure Write_Jspb_Encoding_Config
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Jspb_Encoding_Config);
for Jspb_Encoding_Config'Read use Read_Jspb_Encoding_Config;
for Jspb_Encoding_Config'Write use Write_Jspb_Encoding_Config;
type Jspb_Encoding_Config_Array is
array (Positive range <>) of aliased Jspb_Encoding_Config;
type Jspb_Encoding_Config_Array_Access is access Jspb_Encoding_Config_Array;
type Jspb_Encoding_Config_Vector is
new Ada.Finalization.Controlled
with record
Data : Jspb_Encoding_Config_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Jspb_Encoding_Config_Vector);
overriding procedure Finalize (Self : in out Jspb_Encoding_Config_Vector);
end Conformance.Conformance; |
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2016, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
with Ada.Real_Time; use Ada.Real_Time;
with System; use System;
with System.Machine_Code;
with STM32.Device; use STM32.Device;
with STM32_SVD.RCC; use STM32_SVD.RCC;
with SDMMC_Init;
package body STM32.SDMMC is
-- Mask for errors Card Status R1 (OCR Register)
SD_OCR_ADDR_OUT_OF_RANGE : constant := 16#8000_0000#;
SD_OCR_ADDR_MISALIGNED : constant := 16#4000_0000#;
SD_OCR_BLOCK_LEN_ERR : constant := 16#2000_0000#;
SD_OCR_ERASE_SEQ_ERR : constant := 16#1000_0000#;
SD_OCR_BAD_ERASE_PARAM : constant := 16#0800_0000#;
SD_OCR_WRITE_PROT_VIOLATION : constant := 16#0400_0000#;
SD_OCR_LOCK_UNLOCK_FAILED : constant := 16#0100_0000#;
SD_OCR_COM_CRC_FAILED : constant := 16#0080_0000#;
SD_OCR_ILLEGAL_CMD : constant := 16#0040_0000#;
SD_OCR_CARD_ECC_FAILED : constant := 16#0020_0000#;
SD_OCR_CC_ERROR : constant := 16#0010_0000#;
SD_OCR_GENERAL_UNKNOWN_ERROR : constant := 16#0008_0000#;
SD_OCR_STREAM_READ_UNDERRUN : constant := 16#0004_0000#;
SD_OCR_STREAM_WRITE_UNDERRUN : constant := 16#0002_0000#;
SD_OCR_CID_CSD_OVERWRITE : constant := 16#0001_0000#;
SD_OCR_WP_ERASE_SKIP : constant := 16#0000_8000#;
SD_OCR_CARD_ECC_DISABLED : constant := 16#0000_4000#;
SD_OCR_ERASE_RESET : constant := 16#0000_2000#;
SD_OCR_AKE_SEQ_ERROR : constant := 16#0000_0008#;
SD_OCR_ERRORMASK : constant := 16#FDFF_E008#;
-- Masks for R6 responses.
SD_R6_General_Unknown_Error : constant := 16#0000_2000#;
SD_R6_Illegal_Cmd : constant := 16#0000_4000#;
SD_R6_Com_CRC_Failed : constant := 16#0000_8000#;
SD_DATATIMEOUT : constant := 16#FFFF_FFFF#;
procedure Configure_Data
(Controller : in out SDMMC_Controller;
Data_Length : UInt25;
Data_Block_Size : DCTRL_DBLOCKSIZE_Field;
Transfer_Direction : Data_Direction;
Transfer_Mode : DCTRL_DTMODE_Field;
DPSM : Boolean;
DMA_Enabled : Boolean);
function Read_FIFO
(Controller : in out SDMMC_Controller) return UInt32;
function Response_R1_Error
(Controller : in out SDMMC_Controller;
Command_Index : SD_Command) return SD_Error;
-- Checks for error conditions for R1 response
function Response_R2_Error
(Controller : in out SDMMC_Controller) return SD_Error;
-- Checks for error conditions for R2 (CID or CSD) response.
function Response_R3_Error
(Controller : in out SDMMC_Controller) return SD_Error;
-- Checks for error conditions for R3 (OCR) response.
function Response_R6_Error
(Controller : in out SDMMC_Controller;
Command_Index : SD_Command;
RCA : out UInt32) return SD_Error;
function Response_R7_Error
(Controller : in out SDMMC_Controller) return SD_Error;
-- Checks for error conditions for R7 response.
procedure DCTRL_Write_Delay with Inline_Always;
-- The DCFGR register cannot be written 2 times in a row: we need to
-- wait 3 48MHz periods + 2 90MHz periods. So instead of inserting a 1ms
-- delay statement (which would be overkill), we just issue a few
-- nop instructions to let the CPU wait this period.
-----------------------
-- DCTRL_Write_Delay --
-----------------------
procedure DCTRL_Write_Delay
is
use System.Machine_Code;
begin
for J in 1 .. 20 loop
Asm ("nop", Volatile => True);
end loop;
end DCTRL_Write_Delay;
------------------------
-- Clear_Static_Flags --
------------------------
procedure Clear_Static_Flags (This : in out SDMMC_Controller)
is
begin
This.Periph.ICR :=
(CCRCFAILC => True,
DCRCFAILC => True,
CTIMEOUTC => True,
DTIMEOUTC => True,
TXUNDERRC => True,
RXOVERRC => True,
CMDRENDC => True,
CMDSENTC => True,
DATAENDC => True,
STBITERRC => True,
DBCKENDC => True,
SDIOITC => True,
CEATAENDC => True,
others => <>);
end Clear_Static_Flags;
----------------
-- Clear_Flag --
----------------
procedure Clear_Flag
(This : in out SDMMC_Controller;
Flag : SDMMC_Clearable_Flags)
is
begin
case Flag is
when Data_End =>
This.Periph.ICR.DATAENDC := True;
when Data_CRC_Fail =>
This.Periph.ICR.DCRCFAILC := True;
when Data_Timeout =>
This.Periph.ICR.DTIMEOUTC := True;
when RX_Overrun =>
This.Periph.ICR.RXOVERRC := True;
when TX_Underrun =>
This.Periph.ICR.TXUNDERRC := True;
end case;
end Clear_Flag;
----------------------
-- Enable_Interrupt --
----------------------
procedure Enable_Interrupt
(This : in out SDMMC_Controller;
Interrupt : SDMMC_Interrupts)
is
begin
case Interrupt is
when Data_End_Interrupt =>
This.Periph.MASK.DATAENDIE := True;
when Data_CRC_Fail_Interrupt =>
This.Periph.MASK.DCRCFAILIE := True;
when Data_Timeout_Interrupt =>
This.Periph.MASK.DTIMEOUTIE := True;
when TX_FIFO_Empty_Interrupt =>
This.Periph.MASK.TXFIFOEIE := True;
when RX_FIFO_Full_Interrupt =>
This.Periph.MASK.RXFIFOFIE := True;
when TX_Underrun_Interrupt =>
This.Periph.MASK.TXUNDERRIE := True;
when RX_Overrun_Interrupt =>
This.Periph.MASK.RXOVERRIE := True;
end case;
end Enable_Interrupt;
-----------------------
-- Disable_Interrupt --
-----------------------
procedure Disable_Interrupt
(This : in out SDMMC_Controller;
Interrupt : SDMMC_Interrupts)
is
begin
case Interrupt is
when Data_End_Interrupt =>
This.Periph.MASK.DATAENDIE := False;
when Data_CRC_Fail_Interrupt =>
This.Periph.MASK.DCRCFAILIE := False;
when Data_Timeout_Interrupt =>
This.Periph.MASK.DTIMEOUTIE := False;
when TX_FIFO_Empty_Interrupt =>
This.Periph.MASK.TXFIFOEIE := False;
when RX_FIFO_Full_Interrupt =>
This.Periph.MASK.RXFIFOFIE := False;
when TX_Underrun_Interrupt =>
This.Periph.MASK.TXUNDERRIE := False;
when RX_Overrun_Interrupt =>
This.Periph.MASK.RXOVERRIE := False;
end case;
end Disable_Interrupt;
------------------------
-- Delay_Milliseconds --
------------------------
overriding procedure Delay_Milliseconds
(This : SDMMC_Controller;
Amount : Natural)
is
pragma Unreferenced (This);
begin
delay until Clock + Milliseconds (Amount);
end Delay_Milliseconds;
-----------
-- Reset --
-----------
overriding procedure Reset
(This : in out SDMMC_Controller;
Status : out SD_Error)
is
begin
-- Make sure the POWER register is writable by waiting a bit after
-- the Power_Off command
DCTRL_Write_Delay;
This.Periph.POWER.PWRCTRL := Power_Off;
-- Use the Default SDMMC peripheral configuration for SD card init
This.Periph.CLKCR := (others => <>);
This.Set_Clock (400_000);
This.Periph.DTIMER := SD_DATATIMEOUT;
This.Periph.CLKCR.CLKEN := False;
DCTRL_Write_Delay;
This.Periph.POWER.PWRCTRL := Power_On;
-- Wait for the clock to stabilize.
DCTRL_Write_Delay;
This.Periph.CLKCR.CLKEN := True;
delay until Clock + Milliseconds (20);
Status := OK;
end Reset;
---------------
-- Set_Clock --
---------------
overriding procedure Set_Clock
(This : in out SDMMC_Controller;
Freq : Natural)
is
Div : UInt32;
begin
Div := (This.CLK_In + UInt32 (Freq) - 1) / UInt32 (Freq);
-- Make sure the POWER register is writable by waiting a bit after
-- the Power_Off command
DCTRL_Write_Delay;
if Div <= 1 then
This.Periph.CLKCR.BYPASS := True;
else
Div := Div - 2;
if Div > UInt32 (CLKCR_CLKDIV_Field'Last) then
This.Periph.CLKCR.CLKDIV := CLKCR_CLKDIV_Field'Last;
else
This.Periph.CLKCR.CLKDIV := CLKCR_CLKDIV_Field (Div);
end if;
This.Periph.CLKCR.BYPASS := False;
end if;
end Set_Clock;
------------------
-- Set_Bus_Size --
------------------
overriding procedure Set_Bus_Size
(This : in out SDMMC_Controller;
Mode : Wide_Bus_Mode)
is
function To_WIDBUS_Field is new Ada.Unchecked_Conversion
(Wide_Bus_Mode, CLKCR_WIDBUS_Field);
begin
This.Periph.CLKCR.WIDBUS := To_WIDBUS_Field (Mode);
end Set_Bus_Size;
------------------
-- Send_Command --
------------------
overriding procedure Send_Cmd
(This : in out SDMMC_Controller;
Cmd : Cmd_Desc_Type;
Arg : UInt32;
Status : out SD_Error)
is
CMD_Reg : CMD_Register := This.Periph.CMD;
begin
This.Periph.ARG := Arg;
CMD_Reg.CMDINDEX := CMD_CMDINDEX_Field (Cmd.Cmd);
CMD_Reg.WAITRESP := (case Cmd.Rsp is
when Rsp_No => No_Response,
when Rsp_R2 => Long_Response,
when others => Short_Response);
CMD_Reg.WAITINT := False;
CMD_Reg.CPSMEN := True;
This.Periph.CMD := CMD_Reg;
case Cmd.Rsp is
when Rsp_No =>
Status := This.Command_Error;
when Rsp_R1 | Rsp_R1B =>
Status := This.Response_R1_Error (Cmd.Cmd);
when Rsp_R2 =>
Status := This.Response_R2_Error;
when Rsp_R3 =>
Status := This.Response_R3_Error;
when Rsp_R6 =>
declare
RCA : UInt32;
begin
Status := This.Response_R6_Error (Cmd.Cmd, RCA);
This.RCA := UInt16 (Shift_Right (RCA, 16));
end;
when Rsp_R7 =>
Status := This.Response_R7_Error;
when Rsp_Invalid =>
Status := HAL.SDMMC.Error;
end case;
end Send_Cmd;
--------------
-- Read_Cmd --
--------------
overriding procedure Read_Cmd
(This : in out SDMMC_Controller;
Cmd : Cmd_Desc_Type;
Arg : UInt32;
Buf : out UInt32_Array;
Status : out SD_Error)
is
Block_Size : DCTRL_DBLOCKSIZE_Field;
BS : UInt32;
Dead : UInt32 with Unreferenced;
Idx : Natural;
begin
if Buf'Length = 0 then
Status := Error;
return;
end if;
for J in DCTRL_DBLOCKSIZE_Field'Range loop
BS := 2 ** J'Enum_Rep;
exit when Buf'Length < BS;
if Buf'Length mod BS = 0 then
Block_Size := J;
end if;
end loop;
Configure_Data
(This,
Data_Length => UInt25 (Buf'Length),
Data_Block_Size => Block_Size,
Transfer_Direction => Read,
Transfer_Mode => Block,
DPSM => True,
DMA_Enabled => False);
This.Send_Cmd (Cmd, Arg, Status);
if Status /= OK then
return;
end if;
Idx := Buf'First;
while not This.Periph.STA.RXOVERR
and then not This.Periph.STA.DCRCFAIL
and then not This.Periph.STA.DTIMEOUT
and then not This.Periph.STA.DBCKEND
loop
if Buf'Last - Idx >= 8
and then This.Periph.STA.RXFIFOHF
then
-- The FIFO is 16 words. So with RXFIFO Half full, we can read
-- 8 consecutive words
for J in 0 .. 7 loop
Buf (Idx + J) := Read_FIFO (This);
end loop;
Idx := Idx + 8;
elsif Idx <= Buf'Last
and then This.Periph.STA.RXDAVL
then
Buf (Idx) := Read_FIFO (This);
Idx := Idx + 1;
end if;
end loop;
while This.Periph.STA.RXDAVL loop
-- Empty the FIFO if needed
Dead := Read_FIFO (This);
end loop;
if This.Periph.STA.DTIMEOUT then
This.Periph.ICR.DTIMEOUTC := True;
Status := Timeout_Error;
elsif This.Periph.STA.DCRCFAIL then
This.Periph.ICR.DCRCFAILC := True;
Status := CRC_Check_Fail;
elsif This.Periph.STA.RXOVERR then
This.Periph.ICR.RXOVERRC := True;
Status := Rx_Overrun;
else
Status := OK;
end if;
Clear_Static_Flags (This);
end Read_Cmd;
----------------
-- Read_Rsp48 --
----------------
overriding procedure Read_Rsp48
(This : in out SDMMC_Controller;
Rsp : out UInt32)
is
begin
Rsp := This.Periph.RESP1;
end Read_Rsp48;
overriding procedure Read_Rsp136
(This : in out SDMMC_Controller;
W0, W1, W2, W3 : out UInt32)
is
begin
W0 := This.Periph.RESP1;
W1 := This.Periph.RESP2;
W2 := This.Periph.RESP3;
W3 := This.Periph.RESP4;
end Read_Rsp136;
--------------------
-- Configure_Data --
--------------------
procedure Configure_Data
(Controller : in out SDMMC_Controller;
Data_Length : UInt25;
Data_Block_Size : DCTRL_DBLOCKSIZE_Field;
Transfer_Direction : Data_Direction;
Transfer_Mode : DCTRL_DTMODE_Field;
DPSM : Boolean;
DMA_Enabled : Boolean)
is
Tmp : DCTRL_Register;
begin
Controller.Periph.DLEN.DATALENGTH := Data_Length;
-- DCTRL cannot be written during 3 SDMMCCLK (48MHz) clock periods
-- Minimum wait time is 1 Milliseconds, so let's do that
DCTRL_Write_Delay;
Tmp := Controller.Periph.DCTRL;
Tmp.DTDIR :=
(if Transfer_Direction = Read then Card_To_Controller
else Controller_To_Card);
Tmp.DTMODE := Transfer_Mode;
Tmp.DBLOCKSIZE := Data_Block_Size;
Tmp.DTEN := DPSM;
Tmp.DMAEN := DMA_Enabled;
Controller.Periph.DCTRL := Tmp;
end Configure_Data;
------------------
-- Disable_Data --
------------------
procedure Disable_Data
(This : in out SDMMC_Controller)
is
begin
This.Periph.DCTRL := (others => <>);
end Disable_Data;
---------------
-- Read_FIFO --
---------------
function Read_FIFO
(Controller : in out SDMMC_Controller) return UInt32
is
begin
return Controller.Periph.FIFO;
end Read_FIFO;
-------------------
-- Command_Error --
-------------------
function Command_Error
(Controller : in out SDMMC_Controller) return SD_Error
is
Start : constant Time := Clock;
begin
while not Controller.Periph.STA.CMDSENT loop
if Clock - Start > Milliseconds (1000) then
return Timeout_Error;
end if;
end loop;
Clear_Static_Flags (Controller);
return OK;
end Command_Error;
-----------------------
-- Response_R1_Error --
-----------------------
function Response_R1_Error
(Controller : in out SDMMC_Controller;
Command_Index : SD_Command) return SD_Error
is
Start : constant Time := Clock;
Timeout : Boolean := False;
R1 : UInt32;
begin
while not Controller.Periph.STA.CCRCFAIL
and then not Controller.Periph.STA.CMDREND
and then not Controller.Periph.STA.CTIMEOUT
loop
if Clock - Start > Milliseconds (1000) then
Timeout := True;
exit;
end if;
end loop;
if Timeout or else Controller.Periph.STA.CTIMEOUT then
-- Card is not v2.0 compliant or card does not support the set
-- voltage range
Controller.Periph.ICR.CTIMEOUTC := True;
return Timeout_Error;
elsif Controller.Periph.STA.CCRCFAIL then
Controller.Periph.ICR.CCRCFAILC := True;
return CRC_Check_Fail;
end if;
if SD_Command (Controller.Periph.RESPCMD.RESPCMD) /=
Command_Index
then
return Illegal_Cmd;
end if;
Clear_Static_Flags (Controller);
R1 := Controller.Periph.RESP1;
if (R1 and SD_OCR_ERRORMASK) = 0 then
return OK;
end if;
if (R1 and SD_OCR_ADDR_OUT_OF_RANGE) /= 0 then
return Address_Out_Of_Range;
elsif (R1 and SD_OCR_ADDR_MISALIGNED) /= 0 then
return Address_Missaligned;
elsif (R1 and SD_OCR_BLOCK_LEN_ERR) /= 0 then
return Block_Length_Error;
elsif (R1 and SD_OCR_ERASE_SEQ_ERR) /= 0 then
return Erase_Seq_Error;
elsif (R1 and SD_OCR_BAD_ERASE_PARAM) /= 0 then
return Bad_Erase_Parameter;
elsif (R1 and SD_OCR_WRITE_PROT_VIOLATION) /= 0 then
return Write_Protection_Violation;
elsif (R1 and SD_OCR_LOCK_UNLOCK_FAILED) /= 0 then
return Lock_Unlock_Failed;
elsif (R1 and SD_OCR_COM_CRC_FAILED) /= 0 then
return CRC_Check_Fail;
elsif (R1 and SD_OCR_ILLEGAL_CMD) /= 0 then
return Illegal_Cmd;
elsif (R1 and SD_OCR_CARD_ECC_FAILED) /= 0 then
return Card_ECC_Failed;
elsif (R1 and SD_OCR_CC_ERROR) /= 0 then
return CC_Error;
elsif (R1 and SD_OCR_GENERAL_UNKNOWN_ERROR) /= 0 then
return General_Unknown_Error;
elsif (R1 and SD_OCR_STREAM_READ_UNDERRUN) /= 0 then
return Stream_Read_Underrun;
elsif (R1 and SD_OCR_STREAM_WRITE_UNDERRUN) /= 0 then
return Stream_Write_Underrun;
elsif (R1 and SD_OCR_CID_CSD_OVERWRITE) /= 0 then
return CID_CSD_Overwrite;
elsif (R1 and SD_OCR_WP_ERASE_SKIP) /= 0 then
return WP_Erase_Skip;
elsif (R1 and SD_OCR_CARD_ECC_DISABLED) /= 0 then
return Card_ECC_Disabled;
elsif (R1 and SD_OCR_ERASE_RESET) /= 0 then
return Erase_Reset;
elsif (R1 and SD_OCR_AKE_SEQ_ERROR) /= 0 then
return AKE_SEQ_Error;
else
return General_Unknown_Error;
end if;
end Response_R1_Error;
-----------------------
-- Response_R2_Error --
-----------------------
function Response_R2_Error
(Controller : in out SDMMC_Controller) return SD_Error
is
begin
while not Controller.Periph.STA.CCRCFAIL
and then not Controller.Periph.STA.CMDREND
and then not Controller.Periph.STA.CTIMEOUT
loop
null;
end loop;
if Controller.Periph.STA.CTIMEOUT then
-- Card is not v2.0 compliant or card does not support the set
-- voltage range
Controller.Periph.ICR.CTIMEOUTC := True;
return Timeout_Error;
elsif Controller.Periph.STA.CCRCFAIL then
Controller.Periph.ICR.CCRCFAILC := True;
return CRC_Check_Fail;
end if;
Clear_Static_Flags (Controller);
return OK;
end Response_R2_Error;
-----------------------
-- Response_R3_Error --
-----------------------
function Response_R3_Error
(Controller : in out SDMMC_Controller) return SD_Error
is
begin
while not Controller.Periph.STA.CCRCFAIL
and then not Controller.Periph.STA.CMDREND
and then not Controller.Periph.STA.CTIMEOUT
loop
null;
end loop;
if Controller.Periph.STA.CTIMEOUT then
-- Card is not v2.0 compliant or card does not support the set
-- voltage range
Controller.Periph.ICR.CTIMEOUTC := True;
return Timeout_Error;
end if;
Clear_Static_Flags (Controller);
return OK;
end Response_R3_Error;
-----------------------
-- Response_R6_Error --
-----------------------
function Response_R6_Error
(Controller : in out SDMMC_Controller;
Command_Index : SD_Command;
RCA : out UInt32) return SD_Error
is
Response : UInt32;
begin
while not Controller.Periph.STA.CCRCFAIL
and then not Controller.Periph.STA.CMDREND
and then not Controller.Periph.STA.CTIMEOUT
loop
null;
end loop;
if Controller.Periph.STA.CTIMEOUT then
-- Card is not v2.0 compliant or card does not support the set
-- voltage range
Controller.Periph.ICR.CTIMEOUTC := True;
return Timeout_Error;
elsif Controller.Periph.STA.CCRCFAIL then
Controller.Periph.ICR.CCRCFAILC := True;
return CRC_Check_Fail;
end if;
if SD_Command (Controller.Periph.RESPCMD.RESPCMD) /=
Command_Index
then
return Illegal_Cmd;
end if;
Clear_Static_Flags (Controller);
Response := Controller.Periph.RESP1;
if (Response and SD_R6_Illegal_Cmd) = SD_R6_Illegal_Cmd then
return Illegal_Cmd;
elsif (Response and SD_R6_General_Unknown_Error) =
SD_R6_General_Unknown_Error
then
return General_Unknown_Error;
elsif (Response and SD_R6_Com_CRC_Failed) = SD_R6_Com_CRC_Failed then
return CRC_Check_Fail;
end if;
RCA := Response and 16#FFFF_0000#;
return OK;
end Response_R6_Error;
-----------------------
-- Response_R7_Error --
-----------------------
function Response_R7_Error
(Controller : in out SDMMC_Controller) return SD_Error
is
Start : constant Time := Clock;
Timeout : Boolean := False;
begin
while not Controller.Periph.STA.CCRCFAIL
and then not Controller.Periph.STA.CMDREND
and then not Controller.Periph.STA.CTIMEOUT
loop
if Clock - Start > Milliseconds (1000) then
Timeout := True;
exit;
end if;
end loop;
if Timeout or else Controller.Periph.STA.CTIMEOUT then
-- Card is not v2.0 compliant or card does not support the set
-- voltage range
Controller.Periph.ICR.CTIMEOUTC := True;
return Timeout_Error;
elsif Controller.Periph.STA.CCRCFAIL then
Controller.Periph.ICR.CCRCFAILC := True;
return CRC_Check_Fail;
elsif Controller.Periph.STA.CMDREND then
Controller.Periph.ICR.CMDRENDC := True;
return OK;
else
return Error;
end if;
end Response_R7_Error;
-------------------
-- Stop_Transfer --
-------------------
function Stop_Transfer
(This : in out SDMMC_Controller) return SD_Error
is
Ret : SD_Error;
begin
Send_Cmd (This, Cmd_Desc (Stop_Transmission), 0, Ret);
return Ret;
end Stop_Transfer;
----------------
-- Initialize --
----------------
function Initialize
(This : in out SDMMC_Controller;
SDMMC_CLK : UInt32;
Info : out Card_Information) return SD_Error
is
Ret : SD_Error;
begin
This.CLK_In := SDMMC_CLK;
SDMMC_Init.Card_Identification_Process (This, Info, Ret);
This.Card_Type := Info.Card_Type;
This.RCA := Info.RCA;
return Ret;
end Initialize;
-----------------
-- Read_Blocks --
-----------------
function Read_Blocks
(This : in out SDMMC_Controller;
Addr : UInt64;
Data : out SD_Data) return SD_Error
is
subtype UInt32_Data is SD_Data (1 .. 4);
function To_Data is new Ada.Unchecked_Conversion
(UInt32, UInt32_Data);
R_Addr : UInt64 := Addr;
N_Blocks : Positive;
Err : SD_Error;
Idx : UInt16 := Data'First;
Dead : UInt32 with Unreferenced;
begin
DCTRL_Write_Delay;
This.Periph.DCTRL := (others => <>);
if This.Card_Type = High_Capacity_SD_Card then
R_Addr := Addr / 512;
end if;
N_Blocks := Data'Length / 512;
Send_Cmd
(This,
Cmd => Set_Blocklen,
Arg => 512,
Status => Err);
if Err /= OK then
return Err;
end if;
Configure_Data
(This,
Data_Length => Data'Length,
Data_Block_Size => Block_512B,
Transfer_Direction => Read,
Transfer_Mode => Block,
DPSM => True,
DMA_Enabled => False);
if N_Blocks > 1 then
This.Operation := Read_Multiple_Blocks_Operation;
Send_Cmd (This, Read_Multi_Block, UInt32 (R_Addr), Err);
else
This.Operation := Read_Single_Block_Operation;
Send_Cmd (This, Read_Single_Block, UInt32 (R_Addr), Err);
end if;
if Err /= OK then
return Err;
end if;
if N_Blocks > 1 then
-- Poll on SDMMC flags
while not This.Periph.STA.RXOVERR
and then not This.Periph.STA.DCRCFAIL
and then not This.Periph.STA.DTIMEOUT
and then not This.Periph.STA.DATAEND
loop
if This.Periph.STA.RXFIFOHF then
for J in 1 .. 8 loop
Data (Idx .. Idx + 3) :=
To_Data (Read_FIFO (This));
Idx := Idx + 4;
end loop;
end if;
end loop;
else
-- Poll on SDMMC flags
while not This.Periph.STA.RXOVERR
and then not This.Periph.STA.DCRCFAIL
and then not This.Periph.STA.DTIMEOUT
and then not This.Periph.STA.DBCKEND
loop
if This.Periph.STA.RXFIFOHF then
for J in 1 .. 8 loop
Data (Idx .. Idx + 3) :=
To_Data (Read_FIFO (This));
Idx := Idx + 4;
end loop;
end if;
end loop;
end if;
if N_Blocks > 1 and then This.Periph.STA.DATAEND then
Err := Stop_Transfer (This);
end if;
if This.Periph.STA.DTIMEOUT then
This.Periph.ICR.DTIMEOUTC := True;
return Timeout_Error;
elsif This.Periph.STA.DCRCFAIL then
This.Periph.ICR.DCRCFAILC := True;
return CRC_Check_Fail;
elsif This.Periph.STA.RXOVERR then
This.Periph.ICR.RXOVERRC := True;
return Rx_Overrun;
elsif This.Periph.STA.STBITERR then
This.Periph.ICR.STBITERRC := True;
return Startbit_Not_Detected;
end if;
for J in UInt32'(1) .. SD_DATATIMEOUT loop
exit when not This.Periph.STA.RXDAVL;
Dead := Read_FIFO (This);
end loop;
Clear_Static_Flags (This);
return Err;
end Read_Blocks;
---------------------
-- Read_Blocks_DMA --
---------------------
function Read_Blocks_DMA
(This : in out SDMMC_Controller;
Addr : UInt64;
DMA : STM32.DMA.DMA_Controller;
Stream : STM32.DMA.DMA_Stream_Selector;
Data : out SD_Data) return SD_Error
is
Read_Address : constant UInt64 :=
(if This.Card_Type = High_Capacity_SD_Card
then Addr / 512 else Addr);
Data_Len_Bytes : constant Natural := (Data'Length / 512) * 512;
Data_Len_Words : constant Natural := Data_Len_Bytes / 4;
N_Blocks : constant Natural := Data_Len_Bytes / 512;
Data_Addr : constant Address := Data (Data'First)'Address;
Err : SD_Error;
Command : SD_Command;
use STM32.DMA;
begin
if not STM32.DMA.Compatible_Alignments
(DMA,
Stream,
This.Periph.FIFO'Address,
Data_Addr)
then
return DMA_Alignment_Error;
end if;
-- After a data write, data cannot be written to this register
-- for three SDMMCCLK (@ 48 MHz) clock periods plus two PCLK2 clock
-- periods (@ ~90MHz).
-- So here we make sure the DCTRL is writable
DCTRL_Write_Delay;
This.Periph.DCTRL := (DTEN => False,
others => <>);
Enable_Interrupt (This, Data_CRC_Fail_Interrupt);
Enable_Interrupt (This, Data_Timeout_Interrupt);
Enable_Interrupt (This, Data_End_Interrupt);
Enable_Interrupt (This, RX_Overrun_Interrupt);
STM32.DMA.Start_Transfer_with_Interrupts
(This => DMA,
Stream => Stream,
Source => This.Periph.FIFO'Address,
Destination => Data_Addr,
Data_Count => UInt16 (Data_Len_Words), -- because DMA is set up with words
Enabled_Interrupts => (Transfer_Error_Interrupt => True,
FIFO_Error_Interrupt => True,
Transfer_Complete_Interrupt => True,
others => False));
Send_Cmd (This, Set_Blocklen, 512, Err);
if Err /= OK then
return Err;
end if;
Configure_Data
(This,
Data_Length => UInt25 (N_Blocks) * 512,
Data_Block_Size => Block_512B,
Transfer_Direction => Read,
Transfer_Mode => Block,
DPSM => True,
DMA_Enabled => True);
if N_Blocks > 1 then
Command := Read_Multi_Block;
This.Operation := Read_Multiple_Blocks_Operation;
else
Command := Read_Single_Block;
This.Operation := Read_Single_Block_Operation;
end if;
Send_Cmd (This, Command, UInt32 (Read_Address), Err);
return Err;
end Read_Blocks_DMA;
---------------------
-- Write_Blocks_DMA
---------------------
function Write_Blocks_DMA
(This : in out SDMMC_Controller;
Addr : UInt64;
DMA : STM32.DMA.DMA_Controller;
Stream : STM32.DMA.DMA_Stream_Selector;
Data : SD_Data) return SD_Error
is
Write_Address : constant UInt64 :=
(if This.Card_Type = High_Capacity_SD_Card
then Addr / 512 else Addr);
-- 512 is the min. block size of SD 2.0 card
Data_Len_Bytes : constant Natural := (Data'Length / 512) * 512;
Data_Len_Words : constant Natural := Data_Len_Bytes / 4;
N_Blocks : constant Natural := Data_Len_Bytes / 512;
Data_Addr : constant Address := Data (Data'First)'Address;
Err : SD_Error;
Cardstatus : HAL.UInt32;
Start : constant Time := Clock;
Timeout : Boolean := False;
Command : SD_Command;
Rca : constant UInt32 := Shift_Left (UInt32 (This.RCA), 16);
use STM32.DMA;
begin
if not STM32.DMA.Compatible_Alignments
(DMA,
Stream,
This.Periph.FIFO'Address,
Data_Addr)
then
return DMA_Alignment_Error;
end if;
DCTRL_Write_Delay;
This.Periph.DCTRL := (DTEN => False,
others => <>);
-- After a data write, data cannot be written to this register
-- for three SDMMCCLK (48 MHz) clock periods plus two PCLK2 clock
-- periods.
DCTRL_Write_Delay;
Clear_Static_Flags (This);
-- wait until card is ready for data added
Wait_Ready_Loop :
loop
if Clock - Start > Milliseconds (100) then
Timeout := True;
exit Wait_Ready_Loop;
end if;
Send_Cmd (This, Send_Status, Rca, Err);
if Err /= OK then
return Err;
end if;
Cardstatus := This.Periph.RESP1;
exit Wait_Ready_Loop when (Cardstatus and 16#100#) /= 0;
end loop Wait_Ready_Loop;
if Timeout then
return Timeout_Error;
end if;
Enable_Interrupt (This, Data_CRC_Fail_Interrupt);
Enable_Interrupt (This, Data_Timeout_Interrupt);
Enable_Interrupt (This, Data_End_Interrupt);
Enable_Interrupt (This, TX_Underrun_Interrupt);
-- start DMA first (gives time to setup)
STM32.DMA.Start_Transfer_with_Interrupts
(This => DMA,
Stream => Stream,
Destination => This.Periph.FIFO'Address,
Source => Data_Addr,
Data_Count => UInt16 (Data_Len_Words), -- DMA uses words
Enabled_Interrupts => (Transfer_Error_Interrupt => True,
FIFO_Error_Interrupt => True,
Transfer_Complete_Interrupt => True,
others => False));
-- set block size
Send_Cmd (This, Set_Blocklen, 512, Err);
if Err /= OK then
return Err;
end if;
-- set write address & single/multi mode
if N_Blocks > 1 then
Command := Write_Multi_Block;
This.Operation := Write_Multiple_Blocks_Operation;
else
Command := Write_Single_Block;
This.Operation := Write_Single_Block_Operation;
end if;
Send_Cmd (This, Command, UInt32 (Write_Address), Err);
if Err /= OK then
return Err;
end if;
-- and now enable the card with DTEN, which is this:
Configure_Data
(This,
Data_Length => UInt25 (N_Blocks) * 512,
Data_Block_Size => Block_512B,
Transfer_Direction => Write,
Transfer_Mode => Block,
DPSM => True,
DMA_Enabled => True);
-- according to RM0090: wait for STA[10]=DBCKEND
-- check that no channels are still enabled by polling DMA Enabled
-- Channel Status Reg
return Err;
end Write_Blocks_DMA;
-------------------------
-- Get_Transfer_Status --
-------------------------
function Get_Transfer_Status
(This : in out SDMMC_Controller) return SD_Error
is
begin
if This.Periph.STA.DTIMEOUT then
This.Periph.ICR.DTIMEOUTC := True;
return Timeout_Error;
elsif This.Periph.STA.DCRCFAIL then
This.Periph.ICR.DCRCFAILC := True; -- clear
return CRC_Check_Fail;
elsif This.Periph.STA.TXUNDERR then
This.Periph.ICR.TXUNDERRC := True;
return Tx_Underrun;
elsif This.Periph.STA.STBITERR then
This.Periph.ICR.STBITERRC := True;
return Startbit_Not_Detected;
elsif This.Periph.STA.RXOVERR then
This.Periph.ICR.RXOVERRC := True;
return Rx_Overrun;
end if;
return OK;
end Get_Transfer_Status;
end STM32.SDMMC;
|
with Ada.IO_Exceptions;
private with C.yaml;
private with Ada.Finalization;
package YAML is
pragma Preelaborate;
pragma Linker_Options ("-lyaml");
function Version return String;
type Version_Directive is record
Major : Natural;
Minor : Natural;
end record;
type Tag_Directive is record
Handle : not null access constant String;
Prefix : not null access constant String;
end record;
type Tag_Directive_Array is array (Positive range <>) of Tag_Directive;
type Encoding is (Any, UTF_8, UTF_16LE, UTF_16BE);
type Line_Break is (Any, CR, LN, CRLN);
subtype Indent_Width is Integer range 1 .. 10;
subtype Line_Width is Integer range -1 .. Integer'Last;
type Mark is record
Index : Natural;
Line : Natural;
Column : Natural;
end record;
type Scalar_Style is
(Any, Plain, Single_Quoted, Double_Quoted, Literal, Folded);
type Sequence_Style is (Any, Block, Flow);
type Mapping_Style is (Any, Block, Flow);
package Event_Types is
type Event_Type is (
No_Event, -- An empty event.
Stream_Start, -- A STREAM-START event.
Stream_End, -- A STREAM-END event.
Document_Start, -- A DOCUMENT-START event.
Document_End, -- A DOCUMENT-END event.
Alias, -- An ALIAS event.
Scalar, -- A SCALAR event.
Sequence_Start, -- A SEQUENCE-START event.
Sequence_End, -- A SEQUENCE-END event.
Mapping_Start, -- A MAPPING-START event.
Mapping_End); -- A MAPPING-END event.
private
for Event_Type use (
No_Event =>
C.yaml.yaml_event_type_t'Enum_Rep (C.yaml.YAML_NO_EVENT),
Stream_Start =>
C.yaml.yaml_event_type_t'Enum_Rep (C.yaml.YAML_STREAM_START_EVENT),
Stream_End =>
C.yaml.yaml_event_type_t'Enum_Rep (C.yaml.YAML_STREAM_END_EVENT),
Document_Start =>
C.yaml.yaml_event_type_t'Enum_Rep (C.yaml.YAML_DOCUMENT_START_EVENT),
Document_End =>
C.yaml.yaml_event_type_t'Enum_Rep (C.yaml.YAML_DOCUMENT_END_EVENT),
Alias =>
C.yaml.yaml_event_type_t'Enum_Rep (C.yaml.YAML_ALIAS_EVENT),
Scalar =>
C.yaml.yaml_event_type_t'Enum_Rep (C.yaml.YAML_SCALAR_EVENT),
Sequence_Start =>
C.yaml.yaml_event_type_t'Enum_Rep (C.yaml.YAML_SEQUENCE_START_EVENT),
Sequence_End =>
C.yaml.yaml_event_type_t'Enum_Rep (C.yaml.YAML_SEQUENCE_END_EVENT),
Mapping_Start =>
C.yaml.yaml_event_type_t'Enum_Rep (C.yaml.YAML_MAPPING_START_EVENT),
Mapping_End =>
C.yaml.yaml_event_type_t'Enum_Rep (C.yaml.YAML_MAPPING_END_EVENT));
end Event_Types;
type Event_Type is new Event_Types.Event_Type;
type Event (Event_Type : YAML.Event_Type := No_Event) is record
case Event_Type is
when Stream_Start =>
Encoding : YAML.Encoding;
when Document_Start | Document_End =>
Implicit_Indicator : Boolean;
case Event_Type is
when Document_Start =>
Version_Directive : access constant YAML.Version_Directive;
Tag_Directives : access constant YAML.Tag_Directive_Array;
when others =>
null;
end case;
when Alias | Scalar | Sequence_Start | Mapping_Start =>
Anchor : access constant String;
case Event_Type is
when Scalar | Sequence_Start | Mapping_Start =>
Tag : access constant String;
case Event_Type is
when Scalar =>
Value : not null access constant String;
Plain_Implicit_Tag : Boolean;
Quoted_Implicit_Tag : Boolean;
Scalar_Style : YAML.Scalar_Style;
when Sequence_Start | Mapping_Start =>
Implicit_Tag : Boolean;
case Event_Type is
when Sequence_Start =>
Sequence_Style : YAML.Sequence_Style;
when Mapping_Start =>
Mapping_Style : YAML.Mapping_Style;
when others =>
null;
end case;
when others =>
null;
end case;
when others =>
null;
end case;
when No_Event | Stream_End | Sequence_End | Mapping_End =>
null;
end case;
end record;
-- scalar
Binary_Tag : constant String := "tag:yaml.org,2002:binary";
Boolean_Tag : constant String := "tag:yaml.org,2002:bool";
Float_Tag : constant String := "tag:yaml.org,2002:float"; -- Floating-Point
Integer_Tag : constant String := "tag:yaml.org,2002:int";
Merge_Key_Tag : constant String := "tag:yaml.org,2002:merge";
Null_Tag : constant String := "tag:yaml.org,2002:null";
String_Tag : constant String := "tag:yaml.org,2002:str";
Time_Tag : constant String := "tag:yaml.org,2002:timestamp"; -- Timestamp
Value_Key_Tag : constant String := "tag:yaml.org,2002:value";
YAML_Encoding_Key_Tag : constant String := "tag:yaml.org,2002:yaml";
-- sequence
Ordered_Mapping_Tag : constant String := "tag:yaml.org,2002:omap";
Pairs_Tag : constant String := "tag:yaml.org,2002:pairs";
Sequence_Tag : constant String := "tag:yaml.org,2002:seq";
-- mapping
Mapping_Tag : constant String := "tag:yaml.org,2002:map"; -- Unordered Mapping
Set_Tag : constant String := "tag:yaml.org,2002:set";
-- parser
type Parsing_Entry_Type is limited private;
pragma Preelaborable_Initialization (Parsing_Entry_Type);
function Is_Assigned (Parsing_Entry : Parsing_Entry_Type) return Boolean;
pragma Inline (Is_Assigned);
type Event_Reference_Type (
Element : not null access constant Event) is null record
with Implicit_Dereference => Element;
type Mark_Reference_Type (
Element : not null access constant Mark) is null record
with Implicit_Dereference => Element;
function Value (Parsing_Entry : aliased Parsing_Entry_Type)
return Event_Reference_Type;
function Start_Mark (Parsing_Entry : aliased Parsing_Entry_Type)
return Mark_Reference_Type;
function End_Mark (Parsing_Entry : aliased Parsing_Entry_Type)
return Mark_Reference_Type;
pragma Inline (Value);
pragma Inline (Start_Mark);
pragma Inline (End_Mark);
type Parser (<>) is limited private;
function Create (
Input : not null access procedure (Item : out String; Last : out Natural))
return Parser;
procedure Set_Encoding (Object : in out Parser; Encoding : in YAML.Encoding);
procedure Get (
Object : in out Parser;
Process : not null access procedure (
Event : in YAML.Event;
Start_Mark, End_Mark : in Mark));
procedure Get (
Object : in out Parser;
Parsing_Entry : out Parsing_Entry_Type);
procedure Get_Document_Start (Object : in out Parser);
procedure Get_Document_End (Object : in out Parser);
procedure Finish (Object : in out Parser);
function Last_Error_Mark (Object : Parser) return Mark;
function Last_Error_Message (Object : Parser) return String;
-- emitter
type Emitter (<>) is limited private;
function Create (Output : not null access procedure (Item : in String))
return Emitter;
procedure Flush (Object : in out Emitter);
procedure Set_Encoding (
Object : in out Emitter;
Encoding : in YAML.Encoding);
procedure Set_Canonical (Object : in out Emitter; Canonical : in Boolean);
procedure Set_Indent (Object : in out Emitter; Indent : in Indent_Width);
procedure Set_Width (Object : in out Emitter; Width : in Line_Width);
procedure Set_Unicode (Object : in out Emitter; Unicode : in Boolean);
procedure Set_Break (Object : in out Emitter; Break : in Line_Break);
procedure Put (Object : in out Emitter; Event : in YAML.Event);
procedure Put_Document_Start (
Object : in out Emitter;
Implicit_Indicator : in Boolean := False;
Version_Directive : access constant YAML.Version_Directive := null;
Tag_Directives : access constant YAML.Tag_Directive_Array := null);
procedure Put_Document_End (
Object : in out Emitter;
Implicit_Indicator : in Boolean := True);
procedure Finish (Object : in out Emitter);
-- exceptions
Status_Error : exception
renames Ada.IO_Exceptions.Status_Error;
Use_Error : exception
renames Ada.IO_Exceptions.Use_Error;
Data_Error : exception
renames Ada.IO_Exceptions.Data_Error;
private
for Encoding use (
Any => C.yaml.yaml_encoding_t'Enum_Rep (C.yaml.YAML_ANY_ENCODING),
UTF_8 => C.yaml.yaml_encoding_t'Enum_Rep (C.yaml.YAML_UTF8_ENCODING),
UTF_16LE => C.yaml.yaml_encoding_t'Enum_Rep (C.yaml.YAML_UTF16LE_ENCODING),
UTF_16BE => C.yaml.yaml_encoding_t'Enum_Rep (C.yaml.YAML_UTF16BE_ENCODING));
for Line_Break use (
Any => C.yaml.yaml_break_t'Enum_Rep (C.yaml.YAML_ANY_BREAK),
CR => C.yaml.yaml_break_t'Enum_Rep (C.yaml.YAML_CR_BREAK),
LN => C.yaml.yaml_break_t'Enum_Rep (C.yaml.YAML_LN_BREAK),
CRLN => C.yaml.yaml_break_t'Enum_Rep (C.yaml.YAML_CRLN_BREAK));
for Scalar_Style use (
Any =>
C.yaml.yaml_scalar_style_t'Enum_Rep (C.yaml.YAML_ANY_SCALAR_STYLE),
Plain =>
C.yaml.yaml_scalar_style_t'Enum_Rep (C.yaml.YAML_PLAIN_SCALAR_STYLE),
Single_Quoted =>
C.yaml.yaml_scalar_style_t'Enum_Rep (C.yaml.YAML_SINGLE_QUOTED_SCALAR_STYLE),
Double_Quoted =>
C.yaml.yaml_scalar_style_t'Enum_Rep (C.yaml.YAML_DOUBLE_QUOTED_SCALAR_STYLE),
Literal =>
C.yaml.yaml_scalar_style_t'Enum_Rep (C.yaml.YAML_LITERAL_SCALAR_STYLE),
Folded =>
C.yaml.yaml_scalar_style_t'Enum_Rep (C.yaml.YAML_FOLDED_SCALAR_STYLE));
for Sequence_Style use (
Any =>
C.yaml.yaml_sequence_style_t'Enum_Rep (C.yaml.YAML_ANY_SEQUENCE_STYLE),
Block =>
C.yaml.yaml_sequence_style_t'Enum_Rep (C.yaml.YAML_BLOCK_SEQUENCE_STYLE),
Flow =>
C.yaml.yaml_sequence_style_t'Enum_Rep (C.yaml.YAML_FLOW_SEQUENCE_STYLE));
for Mapping_Style use (
Any =>
C.yaml.yaml_mapping_style_t'Enum_Rep (C.yaml.YAML_ANY_MAPPING_STYLE),
Block =>
C.yaml.yaml_mapping_style_t'Enum_Rep (C.yaml.YAML_BLOCK_MAPPING_STYLE),
Flow =>
C.yaml.yaml_mapping_style_t'Enum_Rep (C.yaml.YAML_FLOW_MAPPING_STYLE));
-- parser
type String_Constraint is record
First : Positive;
Last : Natural;
end record;
pragma Suppress_Initialization (String_Constraint);
type Uninitialized_Parsing_Data is limited record
Event : aliased YAML.Event;
Start_Mark, End_Mark : aliased Mark;
Version_Directive : aliased YAML.Version_Directive;
Anchor_Constraint : aliased String_Constraint;
Tag_Constraint : aliased String_Constraint;
Value_Constraint : aliased String_Constraint;
yaml_event : aliased C.yaml.yaml_event_t;
end record;
pragma Suppress_Initialization (Uninitialized_Parsing_Data);
type Parsed_Data_Type is limited record
-- uninitialized
U : aliased Uninitialized_Parsing_Data;
-- initialized
Delete : access procedure (Parsed_Data : in out Parsed_Data_Type) := null;
end record;
package Controlled_Parsing_Entries is
type Parsing_Entry_Type is limited private;
pragma Preelaborable_Initialization (Parsing_Entry_Type);
function Constant_Reference (Object : aliased YAML.Parsing_Entry_Type)
return not null access constant Parsed_Data_Type;
pragma Inline (Constant_Reference);
generic
type Result_Type (<>) is limited private;
with function Process (Raw : Parsed_Data_Type) return Result_Type;
function Query (Object : YAML.Parsing_Entry_Type) return Result_Type;
pragma Inline (Query);
generic
with procedure Process (Raw : in out Parsed_Data_Type);
procedure Update (Object : in out YAML.Parsing_Entry_Type);
pragma Inline (Update);
private
type Parsing_Entry_Type is limited new Ada.Finalization.Limited_Controlled
with record
Data : aliased Parsed_Data_Type;
end record;
overriding procedure Finalize (Object : in out Parsing_Entry_Type);
end Controlled_Parsing_Entries;
type Parsing_Entry_Type is new Controlled_Parsing_Entries.Parsing_Entry_Type;
package Controlled_Parsers is
type Parser is limited private;
generic
type Result_Type (<>) is limited private;
with function Process (Raw : not null access constant C.yaml.yaml_parser_t)
return Result_Type;
function Query (Object : YAML.Parser) return Result_Type;
pragma Inline (Query);
generic
with procedure Process (Raw : not null access C.yaml.yaml_parser_t);
procedure Update (Object : in out YAML.Parser);
pragma Inline (Update);
private
type Uninitialized_yaml_parser_t is record
X : aliased C.yaml.yaml_parser_t;
end record;
pragma Suppress_Initialization (Uninitialized_yaml_parser_t);
type Parser is limited new Ada.Finalization.Limited_Controlled
with record
Raw : aliased Uninitialized_yaml_parser_t;
end record;
overriding procedure Finalize (Object : in out Parser);
end Controlled_Parsers;
type Parser is new Controlled_Parsers.Parser;
-- emitter
package Controlled_Emitters is
type Emitter is limited private;
generic
with procedure Process (Raw : not null access C.yaml.yaml_emitter_t);
procedure Update (Object : in out YAML.Emitter);
pragma Inline (Update);
private
type Uninitialized_yaml_emitter_t is record
X : aliased C.yaml.yaml_emitter_t;
end record;
pragma Suppress_Initialization (Uninitialized_yaml_emitter_t);
type Emitter is limited new Ada.Finalization.Limited_Controlled
with record
Raw : aliased Uninitialized_yaml_emitter_t;
end record;
overriding procedure Finalize (Object : in out Emitter);
end Controlled_Emitters;
type Emitter is new Controlled_Emitters.Emitter;
-- exceptions
procedure Raise_Error (
Error : in C.yaml.yaml_error_type_t;
Problem : access constant C.char;
Mark : access constant C.yaml.yaml_mark_t);
pragma No_Return (Raise_Error);
end YAML;
|
package body Common with SPARK_Mode is
-------------------
-- Append_To_Msg --
-------------------
procedure Append_To_Msg (Msg : in out Unbounded_String; Tail : String) is
begin
if Length (Msg) < Natural'Last and then Tail'Length > 0 then
declare
Max_Length : constant Positive := Natural'Last - Length (Msg);
begin
if Max_Length <= Tail'Length then
Append (Msg, Tail (Tail'First .. Tail'First - 1 + Max_Length));
else
Append (Msg, Tail);
end if;
end;
end if;
end Append_To_Msg;
procedure Append_To_Msg (Msg : in out Unbounded_String; Tail : Unbounded_String) is
begin
if Length (Msg) < Natural'Last then
declare
Max_Length : constant Positive := Natural'Last - Length (Msg);
begin
Append (Msg, Slice (Tail, 1, Natural'Min (Length (Tail), Max_Length)));
end;
end if;
end Append_To_Msg;
procedure Append_To_Msg (Msg : in out Unbounded_String; Tail : Character) is
begin
if Length (Msg) < Natural'Last then
Append (Msg, Tail);
end if;
end Append_To_Msg;
end Common;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . R A N D O M _ N U M B E R S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2007-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- --
-- The implementation here is derived from a C-program for MT19937, with --
-- initialization improved 2002/1/26. As required, the following notice is --
-- copied from the original program. --
-- --
-- Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution.--
-- --
-- 3. The names of its contributors may not be used to endorse or promote --
-- products derived from this software without specific prior written --
-- permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- --
-- This is an implementation of the Mersenne Twister, twisted generalized --
-- feedback shift register of rational normal form, with state-bit --
-- reflection and tempering. This version generates 32-bit integers with a --
-- period of 2**19937 - 1 (a Mersenne prime, hence the name). For --
-- applications requiring more than 32 bits (up to 64), we concatenate two --
-- 32-bit numbers. --
-- --
-- See http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html for --
-- details. --
-- --
-- In contrast to the original code, we do not generate random numbers in --
-- batches of N. Measurement seems to show this has very little if any --
-- effect on performance, and it may be marginally better for real-time --
-- applications with hard deadlines. --
-- --
------------------------------------------------------------------------------
with Ada.Strings.Text_Output.Utils;
with Ada.Unchecked_Conversion;
with System.Random_Seed;
with Interfaces; use Interfaces;
use Ada;
package body System.Random_Numbers with
SPARK_Mode => Off
is
Image_Numeral_Length : constant := Max_Image_Width / N;
subtype Image_String is String (1 .. Max_Image_Width);
----------------------------
-- Algorithmic Parameters --
----------------------------
Lower_Mask : constant := 2**31 - 1;
Upper_Mask : constant := 2**31;
Matrix_A : constant array (State_Val range 0 .. 1) of State_Val
:= (0, 16#9908b0df#);
-- The twist transformation is represented by a matrix of the form
--
-- [ 0 I(31) ]
-- [ _a ]
--
-- where 0 is a 31x31 block of 0s, I(31) is the 31x31 identity matrix and
-- _a is a particular bit row-vector, represented here by a 32-bit integer.
-- If integer x represents a row vector of bits (with x(0), the units bit,
-- last), then
-- x * A = [0 x(31..1)] xor Matrix_A(x(0)).
U : constant := 11;
S : constant := 7;
B_Mask : constant := 16#9d2c5680#;
T : constant := 15;
C_Mask : constant := 16#efc60000#;
L : constant := 18;
-- The tempering shifts and bit masks, in the order applied
Seed0 : constant := 5489;
-- Default seed, used to initialize the state vector when Reset not called
Seed1 : constant := 19650218;
-- Seed used to initialize the state vector when calling Reset with an
-- initialization vector.
Mult0 : constant := 1812433253;
-- Multiplier for a modified linear congruential generator used to
-- initialize the state vector when calling Reset with a single integer
-- seed.
Mult1 : constant := 1664525;
Mult2 : constant := 1566083941;
-- Multipliers for two modified linear congruential generators used to
-- initialize the state vector when calling Reset with an initialization
-- vector.
-----------------------
-- Local Subprograms --
-----------------------
procedure Init (Gen : Generator; Initiator : Unsigned_32);
-- Perform a default initialization of the state of Gen. The resulting
-- state is identical for identical values of Initiator.
procedure Insert_Image
(S : in out Image_String;
Index : Integer;
V : State_Val);
-- Insert image of V into S, in the Index'th 11-character substring
function Extract_Value (S : String; Index : Integer) return State_Val;
-- Treat S as a sequence of 11-character decimal numerals and return
-- the result of converting numeral #Index (numbering from 0)
function To_Unsigned is
new Unchecked_Conversion (Integer_32, Unsigned_32);
function To_Unsigned is
new Unchecked_Conversion (Integer_64, Unsigned_64);
------------
-- Random --
------------
function Random (Gen : Generator) return Unsigned_32 is
G : Generator renames Gen.Writable.Self.all;
Y : State_Val;
I : Integer; -- should avoid use of identifier I ???
begin
I := G.I;
if I < N - M then
Y := (G.S (I) and Upper_Mask) or (G.S (I + 1) and Lower_Mask);
Y := G.S (I + M) xor Shift_Right (Y, 1) xor Matrix_A (Y and 1);
I := I + 1;
elsif I < N - 1 then
Y := (G.S (I) and Upper_Mask) or (G.S (I + 1) and Lower_Mask);
Y := G.S (I + (M - N))
xor Shift_Right (Y, 1)
xor Matrix_A (Y and 1);
I := I + 1;
elsif I = N - 1 then
Y := (G.S (I) and Upper_Mask) or (G.S (0) and Lower_Mask);
Y := G.S (M - 1) xor Shift_Right (Y, 1) xor Matrix_A (Y and 1);
I := 0;
else
Init (G, Seed0);
return Random (Gen);
end if;
G.S (G.I) := Y;
G.I := I;
Y := Y xor Shift_Right (Y, U);
Y := Y xor (Shift_Left (Y, S) and B_Mask);
Y := Y xor (Shift_Left (Y, T) and C_Mask);
Y := Y xor Shift_Right (Y, L);
return Y;
end Random;
generic
type Unsigned is mod <>;
type Real is digits <>;
with function Random (G : Generator) return Unsigned is <>;
function Random_Float_Template (Gen : Generator) return Real;
pragma Inline (Random_Float_Template);
-- Template for a random-number generator implementation that delivers
-- values of type Real in the range [0 .. 1], using values from Gen,
-- assuming that Unsigned is large enough to hold the bits of a mantissa
-- for type Real.
---------------------------
-- Random_Float_Template --
---------------------------
function Random_Float_Template (Gen : Generator) return Real is
pragma Compile_Time_Error
(Unsigned'Last <= 2**(Real'Machine_Mantissa - 1),
"insufficiently large modular type used to hold mantissa");
begin
-- This code generates random floating-point numbers from unsigned
-- integers. Assuming that Real'Machine_Radix = 2, it can deliver all
-- machine values of type Real (as implied by Real'Machine_Mantissa and
-- Real'Machine_Emin), which is not true of the standard method (to
-- which we fall back for nonbinary radix): computing Real(<random
-- integer>) / (<max random integer>+1). To do so, we first extract an
-- (M-1)-bit significand (where M is Real'Machine_Mantissa), and then
-- decide on a normalized exponent by repeated coin flips, decrementing
-- from 0 as long as we flip heads (1 bits). This process yields the
-- proper geometric distribution for the exponent: in a uniformly
-- distributed set of floating-point numbers, 1/2 of them will be in
-- (0.5, 1], 1/4 will be in (0.25, 0.5], and so forth. It makes a
-- further adjustment at binade boundaries (see comments below) to give
-- the effect of selecting a uniformly distributed real deviate in
-- [0..1] and then rounding to the nearest representable floating-point
-- number. The algorithm attempts to be stingy with random integers. In
-- the worst case, it can consume roughly -Real'Machine_Emin/32 32-bit
-- integers, but this case occurs with probability around
-- 2**Machine_Emin, and the expected number of calls to integer-valued
-- Random is 1. For another discussion of the issues addressed by this
-- process, see Allen Downey's unpublished paper at
-- http://allendowney.com/research/rand/downey07randfloat.pdf.
if Real'Machine_Radix /= 2 then
return Real'Machine
(Real (Unsigned'(Random (Gen))) * 2.0**(-Unsigned'Size));
else
declare
type Bit_Count is range 0 .. 4;
subtype T is Real'Base;
Trailing_Ones : constant array (Unsigned_32 range 0 .. 15)
of Bit_Count :=
(2#00000# => 0, 2#00001# => 1, 2#00010# => 0, 2#00011# => 2,
2#00100# => 0, 2#00101# => 1, 2#00110# => 0, 2#00111# => 3,
2#01000# => 0, 2#01001# => 1, 2#01010# => 0, 2#01011# => 2,
2#01100# => 0, 2#01101# => 1, 2#01110# => 0, 2#01111# => 4);
Pow_Tab : constant array (Bit_Count range 0 .. 3) of Real
:= (0 => 2.0**(0 - T'Machine_Mantissa),
1 => 2.0**(-1 - T'Machine_Mantissa),
2 => 2.0**(-2 - T'Machine_Mantissa),
3 => 2.0**(-3 - T'Machine_Mantissa));
Extra_Bits : constant Natural :=
(Unsigned'Size - T'Machine_Mantissa + 1);
-- Random bits left over after selecting mantissa
Mantissa : Unsigned;
X : Real; -- Scaled mantissa
R : Unsigned_32; -- Supply of random bits
R_Bits : Natural; -- Number of bits left in R
K : Bit_Count; -- Next decrement to exponent
begin
K := 0;
Mantissa := Random (Gen) / 2**Extra_Bits;
R := Unsigned_32 (Mantissa mod 2**Extra_Bits);
R_Bits := Extra_Bits;
X := Real (2**(T'Machine_Mantissa - 1) + Mantissa); -- Exact
if Extra_Bits < 4 and then R < 2 ** Extra_Bits - 1 then
-- We got lucky and got a zero in our few extra bits
K := Trailing_Ones (R);
else
Find_Zero : loop
-- R has R_Bits unprocessed random bits, a multiple of 4.
-- X needs to be halved for each trailing one bit. The
-- process stops as soon as a 0 bit is found. If R_Bits
-- becomes zero, reload R.
-- Process 4 bits at a time for speed: the two iterations
-- on average with three tests each was still too slow,
-- probably because the branches are not predictable.
-- This loop now will only execute once 94% of the cases,
-- doing more bits at a time will not help.
while R_Bits >= 4 loop
K := Trailing_Ones (R mod 16);
exit Find_Zero when K < 4; -- Exits 94% of the time
R_Bits := R_Bits - 4;
X := X / 16.0;
R := R / 16;
end loop;
-- Do not allow us to loop endlessly even in the (very
-- unlikely) case that Random (Gen) keeps yielding all ones.
exit Find_Zero when X = 0.0;
R := Random (Gen);
R_Bits := 32;
end loop Find_Zero;
end if;
-- K has the count of trailing ones not reflected yet in X. The
-- following multiplication takes care of that, as well as the
-- correction to move the radix point to the left of the mantissa.
-- Doing it at the end avoids repeated rounding errors in the
-- exceedingly unlikely case of ever having a subnormal result.
X := X * Pow_Tab (K);
-- The smallest value in each binade is rounded to by 0.75 of
-- the span of real numbers as its next larger neighbor, and
-- 1.0 is rounded to by half of the span of real numbers as its
-- next smaller neighbor. To account for this, when we encounter
-- the smallest number in a binade, we substitute the smallest
-- value in the next larger binade with probability 1/2.
if Mantissa = 0 and then Unsigned_32'(Random (Gen)) mod 2 = 0 then
X := 2.0 * X;
end if;
return X;
end;
end if;
end Random_Float_Template;
------------
-- Random --
------------
function Random (Gen : Generator) return Float is
function F is new Random_Float_Template (Unsigned_32, Float);
begin
return F (Gen);
end Random;
function Random (Gen : Generator) return Long_Float is
function F is new Random_Float_Template (Unsigned_64, Long_Float);
begin
return F (Gen);
end Random;
function Random (Gen : Generator) return Unsigned_64 is
begin
return Shift_Left (Unsigned_64 (Unsigned_32'(Random (Gen))), 32)
or Unsigned_64 (Unsigned_32'(Random (Gen)));
end Random;
---------------------
-- Random_Discrete --
---------------------
function Random_Discrete
(Gen : Generator;
Min : Result_Subtype := Default_Min;
Max : Result_Subtype := Result_Subtype'Last) return Result_Subtype
is
begin
if Max = Min then
return Max;
elsif Max < Min then
raise Constraint_Error;
-- In the 64-bit case, we have to be careful since not all 64-bit
-- unsigned values are representable in GNAT's universal integer.
elsif Result_Subtype'Base'Size > 32 then
declare
-- Ignore unequal-size warnings since GNAT's handling is correct.
pragma Warnings ("Z");
function Conv_To_Unsigned is
new Unchecked_Conversion (Result_Subtype'Base, Unsigned_64);
function Conv_To_Result is
new Unchecked_Conversion (Unsigned_64, Result_Subtype'Base);
pragma Warnings ("z");
N : constant Unsigned_64 :=
Conv_To_Unsigned (Max) - Conv_To_Unsigned (Min) + 1;
X, Slop : Unsigned_64;
begin
if N = 0 then
return Conv_To_Result (Conv_To_Unsigned (Min) + Random (Gen));
else
Slop := Unsigned_64'Last rem N + 1;
loop
X := Random (Gen);
exit when Slop = N or else X <= Unsigned_64'Last - Slop;
end loop;
return Conv_To_Result (Conv_To_Unsigned (Min) + X rem N);
end if;
end;
-- In the 32-bit case, we need to handle both integer and enumeration
-- types and, therefore, rely on 'Pos and 'Val in the computation.
elsif Result_Subtype'Pos (Max) - Result_Subtype'Pos (Min) = 2 ** 32 - 1
then
return Result_Subtype'Val
(Result_Subtype'Pos (Min) + Unsigned_32'Pos (Random (Gen)));
else
declare
N : constant Unsigned_32 :=
Unsigned_32 (Result_Subtype'Pos (Max) -
Result_Subtype'Pos (Min) + 1);
Slop : constant Unsigned_32 := Unsigned_32'Last rem N + 1;
X : Unsigned_32;
begin
loop
X := Random (Gen);
exit when Slop = N or else X <= Unsigned_32'Last - Slop;
end loop;
return
Result_Subtype'Val
(Result_Subtype'Pos (Min) + Unsigned_32'Pos (X rem N));
end;
end if;
end Random_Discrete;
------------------
-- Random_Float --
------------------
function Random_Float (Gen : Generator) return Result_Subtype is
begin
if Result_Subtype'Base'Digits > Float'Digits then
return Result_Subtype'Machine (Result_Subtype
(Long_Float'(Random (Gen))));
else
return Result_Subtype'Machine (Result_Subtype
(Float'(Random (Gen))));
end if;
end Random_Float;
-----------
-- Reset --
-----------
procedure Reset (Gen : Generator) is
begin
Init (Gen, Unsigned_32'Mod (Random_Seed.Get_Seed));
end Reset;
procedure Reset (Gen : Generator; Initiator : Integer_32) is
begin
Init (Gen, To_Unsigned (Initiator));
end Reset;
procedure Reset (Gen : Generator; Initiator : Unsigned_32) is
begin
Init (Gen, Initiator);
end Reset;
procedure Reset (Gen : Generator; Initiator : Integer) is
begin
-- This is probably an unnecessary precaution against future change, but
-- since the test is a static expression, no extra code is involved.
if Integer'Size <= 32 then
Init (Gen, To_Unsigned (Integer_32 (Initiator)));
else
declare
Initiator1 : constant Unsigned_64 :=
To_Unsigned (Integer_64 (Initiator));
Init0 : constant Unsigned_32 :=
Unsigned_32 (Initiator1 mod 2 ** 32);
Init1 : constant Unsigned_32 :=
Unsigned_32 (Shift_Right (Initiator1, 32));
begin
Reset (Gen, Initialization_Vector'(Init0, Init1));
end;
end if;
end Reset;
procedure Reset (Gen : Generator; Initiator : Initialization_Vector) is
G : Generator renames Gen.Writable.Self.all;
I, J : Integer;
begin
Init (G, Seed1);
I := 1;
J := 0;
if Initiator'Length > 0 then
for K in reverse 1 .. Integer'Max (N, Initiator'Length) loop
G.S (I) :=
(G.S (I) xor ((G.S (I - 1)
xor Shift_Right (G.S (I - 1), 30)) * Mult1))
+ Initiator (J + Initiator'First) + Unsigned_32 (J);
I := I + 1;
J := J + 1;
if I >= N then
G.S (0) := G.S (N - 1);
I := 1;
end if;
if J >= Initiator'Length then
J := 0;
end if;
end loop;
end if;
for K in reverse 1 .. N - 1 loop
G.S (I) :=
(G.S (I) xor ((G.S (I - 1)
xor Shift_Right (G.S (I - 1), 30)) * Mult2))
- Unsigned_32 (I);
I := I + 1;
if I >= N then
G.S (0) := G.S (N - 1);
I := 1;
end if;
end loop;
G.S (0) := Upper_Mask;
end Reset;
procedure Reset (Gen : Generator; From_State : Generator) is
G : Generator renames Gen.Writable.Self.all;
begin
G.S := From_State.S;
G.I := From_State.I;
end Reset;
procedure Reset (Gen : Generator; From_State : State) is
G : Generator renames Gen.Writable.Self.all;
begin
G.I := 0;
G.S := From_State;
end Reset;
procedure Reset (Gen : Generator; From_Image : String) is
G : Generator renames Gen.Writable.Self.all;
begin
G.I := 0;
for J in 0 .. N - 1 loop
G.S (J) := Extract_Value (From_Image, J);
end loop;
end Reset;
----------
-- Save --
----------
procedure Save (Gen : Generator; To_State : out State) is
Gen2 : Generator;
begin
if Gen.I = N then
Init (Gen2, 5489);
To_State := Gen2.S;
else
To_State (0 .. N - 1 - Gen.I) := Gen.S (Gen.I .. N - 1);
To_State (N - Gen.I .. N - 1) := Gen.S (0 .. Gen.I - 1);
end if;
end Save;
-----------
-- Image --
-----------
function Image (Of_State : State) return String is
Result : Image_String;
begin
Result := (others => ' ');
for J in Of_State'Range loop
Insert_Image (Result, J, Of_State (J));
end loop;
return Result;
end Image;
function Image (Gen : Generator) return String is
Result : Image_String;
begin
Result := (others => ' ');
for J in 0 .. N - 1 loop
Insert_Image (Result, J, Gen.S ((J + Gen.I) mod N));
end loop;
return Result;
end Image;
---------------
-- Put_Image --
---------------
procedure Put_Image
(S : in out Strings.Text_Output.Sink'Class; V : State) is
begin
Strings.Text_Output.Utils.Put_String (S, Image (V));
end Put_Image;
-----------
-- Value --
-----------
function Value (Coded_State : String) return State is
Gen : Generator;
S : State;
begin
Reset (Gen, Coded_State);
Save (Gen, S);
return S;
end Value;
----------
-- Init --
----------
procedure Init (Gen : Generator; Initiator : Unsigned_32) is
G : Generator renames Gen.Writable.Self.all;
begin
G.S (0) := Initiator;
for I in 1 .. N - 1 loop
G.S (I) :=
(G.S (I - 1) xor Shift_Right (G.S (I - 1), 30)) * Mult0
+ Unsigned_32 (I);
end loop;
G.I := 0;
end Init;
------------------
-- Insert_Image --
------------------
procedure Insert_Image
(S : in out Image_String;
Index : Integer;
V : State_Val)
is
Value : constant String := State_Val'Image (V);
begin
S (Index * 11 + 1 .. Index * 11 + Value'Length) := Value;
end Insert_Image;
-------------------
-- Extract_Value --
-------------------
function Extract_Value (S : String; Index : Integer) return State_Val is
Start : constant Integer := S'First + Index * Image_Numeral_Length;
begin
return State_Val'Value (S (Start .. Start + Image_Numeral_Length - 1));
end Extract_Value;
end System.Random_Numbers;
|
------------------------------------------------------------------------------
-- Copyright (c) 2014-2017, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Natools.Constant_Indefinite_Ordered_Sets provides an implementation of --
-- indefinite ordered maps with immutable mapping, based on a sorted array. --
-- This makes it task-safe as long as the mapping is only read. --
-- --
-- All the types exposed have referential semantics, in that assignment is --
-- cheap and uses the same actual object. It is as task-safe as the current --
-- implementation of Natools.References. --
-- Cursors also hold a reference, which is used to identify the parent map, --
-- so after an assignment or a call to Clear or Move, the link between the --
-- map object and the cursor is broken, but the cursor is still usable and --
-- behaves as the original version of the maps. --
-- --
-- There are two types defined here, depending on their restrictions and --
-- safety against concurrent accesses: --
-- * Constant_Map cannot be changed in any way, but is completely --
-- task-safe (unless some referential magic is performed, like --
-- tampering checks in standard containers) --
-- * Updatable_Map allows read-write operations on stored elements, but --
-- it is up to the client to ensure there operations are task-safe, --
-- e.g. by using an atomic or protected Element_Type. --
-- --
-- Insertion and deletion primitives are provided as function rather than --
-- procedures, to emphasize that they actually create a new map with the --
-- requested change. Since most of the map is blindly duplicated, they are --
-- all in O(n) time, which makes them a quite inefficient way to build --
-- maps. For a significant number of changes, it's probably better to go --
-- through an unsafe map. --
-- --
-- All the subprograms here have the semantics of standard indefinite --
-- ordered maps (see ARM A.18.6), except for tampering, which becomes --
-- irrelevant. --
------------------------------------------------------------------------------
with Ada.Containers.Indefinite_Ordered_Maps;
with Ada.Iterator_Interfaces;
private with Ada.Finalization;
private with Ada.Unchecked_Deallocation;
private with Natools.References;
private with Natools.Storage_Pools;
generic
type Key_Type (<>) is private;
type Element_Type (<>) is private;
with function "<" (Left, Right : Key_Type) return Boolean is <>;
with function "=" (Left, Right : Element_Type) return Boolean is <>;
package Natools.Constant_Indefinite_Ordered_Maps is
pragma Preelaborate;
package Unsafe_Maps is new Ada.Containers.Indefinite_Ordered_Maps
(Key_Type, Element_Type);
type Cursor is private; -- with Type_Invariant => Is_Valid (Cursor);
pragma Preelaborable_Initialization (Cursor);
No_Element : constant Cursor;
procedure Clear (Position : in out Cursor);
function Is_Valid (Position : Cursor) return Boolean;
function Has_Element (Position : Cursor) return Boolean;
function Element (Position : Cursor) return Element_Type
with Pre => Has_Element (Position) or else raise Constraint_Error;
function Key (Position : Cursor) return Key_Type
with Pre => Has_Element (Position) or else raise Constraint_Error;
procedure Query_Element
(Position : in Cursor;
Process : not null access procedure (Key : in Key_Type;
Element : in Element_Type))
with Pre => Has_Element (Position) or else raise Constraint_Error;
function Next (Position : Cursor) return Cursor;
procedure Next (Position : in out Cursor);
function Previous (Position : Cursor) return Cursor;
procedure Previous (Position : in out Cursor);
function "<" (Left, Right : Cursor) return Boolean
with Pre => (Has_Element (Left) and then Has_Element (Right))
or else raise Constraint_Error;
function ">" (Left, Right : Cursor) return Boolean
with Pre => (Has_Element (Left) and then Has_Element (Right))
or else raise Constraint_Error;
function "<" (Left : Cursor; Right : Key_Type) return Boolean
with Pre => Has_Element (Left) or else raise Constraint_Error;
function ">" (Left : Cursor; Right : Key_Type) return Boolean
with Pre => Has_Element (Left) or else raise Constraint_Error;
function "<" (Left : Key_Type; Right : Cursor) return Boolean
with Pre => Has_Element (Right) or else raise Constraint_Error;
function ">" (Left : Key_Type; Right : Cursor) return Boolean
with Pre => Has_Element (Right) or else raise Constraint_Error;
function Rank (Position : Cursor) return Ada.Containers.Count_Type;
-- Return 1-based numeric position of the element designated by Position
-- or zero when Position is empty.
package Map_Iterator_Interfaces is new Ada.Iterator_Interfaces
(Cursor, Has_Element);
type Constant_Map is tagged private;
-- TODO: add aspects when they don't put GNAT in an infinite loop
-- with Constant_Indexing => Constant_Reference,
-- Default_Iterator => Iterate,
-- Iterator_Element => Element_Type;
pragma Preelaborable_Initialization (Constant_Map);
procedure Clear (Container : in out Constant_Map);
function Create (Source : Unsafe_Maps.Map) return Constant_Map;
procedure Move (Target : in out Constant_Map; Source : in out Constant_Map);
procedure Replace
(Container : in out Constant_Map;
New_Items : in Unsafe_Maps.Map);
function To_Unsafe_Map (Container : Constant_Map) return Unsafe_Maps.Map;
function Is_Related (Container : Constant_Map; Position : Cursor)
return Boolean;
function "=" (Left, Right : Constant_Map) return Boolean;
function Length (Container : Constant_Map) return Ada.Containers.Count_Type;
function Is_Empty (Container : Constant_Map) return Boolean;
function First (Container : Constant_Map) return Cursor;
function First_Element (Container : Constant_Map) return Element_Type
with Pre => (not Is_Empty (Container)) or else raise Constraint_Error;
function First_Key (Container : Constant_Map) return Key_Type
with Pre => (not Is_Empty (Container)) or else raise Constraint_Error;
function Last (Container : Constant_Map) return Cursor;
function Last_Element (Container : Constant_Map) return Element_Type
with Pre => (not Is_Empty (Container)) or else raise Constraint_Error;
function Last_Key (Container : Constant_Map) return Key_Type
with Pre => (not Is_Empty (Container)) or else raise Constraint_Error;
function Find (Container : Constant_Map; Key : Key_Type) return Cursor;
function Element
(Container : Constant_Map;
Key : Key_Type)
return Element_Type;
function Floor (Container : Constant_Map; Key : Key_Type) return Cursor;
function Ceiling (Container : Constant_Map; Key : Key_Type) return Cursor;
function Contains (Container : Constant_Map; Key : Key_Type) return Boolean;
procedure Iterate
(Container : in Constant_Map;
Process : not null access procedure (Position : in Cursor));
procedure Reverse_Iterate
(Container : in Constant_Map;
Process : not null access procedure (Position : in Cursor));
function Iterate (Container : in Constant_Map)
return Map_Iterator_Interfaces.Reversible_Iterator'Class;
function Iterate (Container : in Constant_Map; Start : in Cursor)
return Map_Iterator_Interfaces.Reversible_Iterator'Class;
function Iterate (Container : in Constant_Map; First, Last : in Cursor)
return Map_Iterator_Interfaces.Reversible_Iterator'Class;
type Constant_Reference_Type
(Element : not null access constant Element_Type) is private
with Implicit_Dereference => Element;
function Constant_Reference
(Container : aliased in Constant_Map;
Position : in Cursor)
return Constant_Reference_Type;
function Constant_Reference
(Container : aliased in Constant_Map;
Key : in Key_Type)
return Constant_Reference_Type;
function Insert
(Source : in Constant_Map;
Key : in Key_Type;
New_Item : in Element_Type;
Position : out Cursor;
Inserted : out Boolean)
return Constant_Map;
function Insert
(Source : in Constant_Map;
Key : in Key_Type;
New_Item : in Element_Type)
return Constant_Map;
function Include
(Source : in Constant_Map;
Key : in Key_Type;
New_Item : in Element_Type)
return Constant_Map;
function Replace
(Source : in Constant_Map;
Key : in Key_Type;
New_Item : in Element_Type)
return Constant_Map;
function Replace_Element
(Source : in Constant_Map;
Position : in Cursor;
New_Item : in Element_Type)
return Constant_Map;
function Replace_Element
(Source : in Constant_Map;
Position : in Cursor;
New_Item : in Element_Type;
New_Position : out Cursor)
return Constant_Map;
function Exclude
(Source : in Constant_Map;
Key : in Key_Type)
return Constant_Map;
function Delete
(Source : in Constant_Map;
Key : in Key_Type)
return Constant_Map;
function Delete
(Source : in Constant_Map;
Position : in Cursor)
return Constant_Map;
type Updatable_Map is new Constant_Map with private
with Constant_Indexing => Constant_Reference_For_Bugged_GNAT,
Variable_Indexing => Reference,
Default_Iterator => Iterate,
Iterator_Element => Element_Type;
pragma Preelaborable_Initialization (Updatable_Map);
function Constant_Reference_For_Bugged_GNAT
(Container : aliased in Updatable_Map;
Position : in Cursor)
return Constant_Reference_Type;
function Constant_Reference_For_Bugged_GNAT
(Container : aliased in Updatable_Map;
Key : in Key_Type)
return Constant_Reference_Type;
procedure Update_Element
(Container : in out Updatable_Map;
Position : in Cursor;
Process : not null access procedure (Key : in Key_Type;
Element : in out Element_Type))
with Pre => (Has_Element (Position) or else raise Constraint_Error)
and then (Is_Related (Container, Position) or else raise Program_Error);
type Reference_Type (Element : not null access Element_Type) is private
with Implicit_Dereference => Element;
function Reference
(Container : aliased in out Updatable_Map;
Position : in Cursor)
return Reference_Type;
function Reference
(Container : aliased in out Updatable_Map;
Key : in Key_Type)
return Reference_Type;
Empty_Constant_Map : constant Constant_Map;
Empty_Updatable_Map : constant Updatable_Map;
private
type Key_Access is access Key_Type;
type Element_Access is access Element_Type;
type Node is record
Key : not null Key_Access;
Element : not null Element_Access;
end record;
use type Ada.Containers.Count_Type;
subtype Count_Type is Ada.Containers.Count_Type;
subtype Index_Type is Count_Type range 1 .. Count_Type'Last;
type Node_Array is array (Index_Type range <>) of Node;
procedure Free is new Ada.Unchecked_Deallocation
(Key_Type, Key_Access);
procedure Free is new Ada.Unchecked_Deallocation
(Element_Type, Element_Access);
type Backend_Array (Size : Index_Type) -- cannot be empty
is new Ada.Finalization.Limited_Controlled with
record
Nodes : Node_Array (1 .. Size);
Finalized : Boolean := False;
end record;
function Create
(Size : Index_Type;
Key_Factory : not null access function (Index : Index_Type)
return Key_Type;
Element_Factory : not null access function (Index : Index_Type)
return Element_Type)
return Backend_Array;
overriding procedure Finalize (Object : in out Backend_Array);
package Backend_Refs is new References
(Backend_Array,
Storage_Pools.Access_In_Default_Pool'Storage_Pool,
Storage_Pools.Access_In_Default_Pool'Storage_Pool);
function Make_Backend
(Size : Count_Type;
Key_Factory : not null access function (Index : Index_Type)
return Key_Type;
Element_Factory : not null access function (Index : Index_Type)
return Element_Type)
return Backend_Refs.Immutable_Reference;
function Make_Backend (Map : Unsafe_Maps.Map)
return Backend_Refs.Immutable_Reference;
procedure Search
(Nodes : in Node_Array;
Key : in Key_Type;
Floor : out Count_Type;
Ceiling : out Count_Type);
type Constant_Map is tagged record
Backend : Backend_Refs.Immutable_Reference;
end record;
function Is_Empty (Container : Constant_Map) return Boolean
is (Container.Backend.Is_Empty);
type Updatable_Map is new Constant_Map with null record;
type Cursor (Is_Empty : Boolean := True) is record
case Is_Empty is
when True => null;
when False =>
Index : Index_Type;
Backend : Backend_Refs.Immutable_Reference;
end case;
end record;
function Is_Valid (Position : Cursor) return Boolean
is (Position.Is_Empty
or else (not Position.Backend.Is_Empty
and then Position.Index <= Position.Backend.Query.Data.Size));
function Has_Element (Position : Cursor) return Boolean
is (not Position.Is_Empty);
function Is_Related (Container : Constant_Map; Position : Cursor)
return Boolean
is (Backend_Refs."=" (Container.Backend, Position.Backend));
type Constant_Reference_Type
(Element : not null access constant Element_Type)
is record
Backend : Backend_Refs.Immutable_Reference;
end record;
type Reference_Type (Element : not null access Element_Type) is record
Backend : Backend_Refs.Immutable_Reference;
end record;
type Iterator is new Map_Iterator_Interfaces.Reversible_Iterator with record
Backend : Backend_Refs.Immutable_Reference;
Start : Cursor := No_Element;
end record;
overriding function First (Object : Iterator) return Cursor;
overriding function Last (Object : Iterator) return Cursor;
overriding function Next
(Object : Iterator;
Position : Cursor) return Cursor
is (Next (Position))
with Pre => Position.Is_Empty
or else Backend_Refs."=" (Position.Backend, Object.Backend);
overriding function Previous
(Object : Iterator;
Position : Cursor) return Cursor
is (Previous (Position))
with Pre => Position.Is_Empty
or else Backend_Refs."=" (Position.Backend, Object.Backend);
type Range_Iterator is new Map_Iterator_Interfaces.Reversible_Iterator
with record
Backend : Backend_Refs.Immutable_Reference;
First_Position : Cursor;
Last_Position : Cursor;
end record;
-- with Dynamic_Predicate => not Range_Iterator.Backend.Is_Empty
-- and then Has_Element (Range_Iterator.First_Position)
-- and then Has_Element (Range_Iterator.Last_Position)
-- and then not Range_Iterator.First_Position
-- > Range_Iterator.Last_Position;
overriding function First (Object : Range_Iterator) return Cursor;
overriding function Last (Object : Range_Iterator) return Cursor;
overriding function Next
(Object : Range_Iterator;
Position : Cursor) return Cursor
with Pre => Position.Is_Empty
or else Backend_Refs."=" (Position.Backend, Object.Backend);
overriding function Previous
(Object : Range_Iterator;
Position : Cursor) return Cursor
with Pre => Position.Is_Empty
or else Backend_Refs."=" (Position.Backend, Object.Backend);
Empty_Constant_Map : constant Constant_Map := (Backend => <>);
Empty_Updatable_Map : constant Updatable_Map := (Backend => <>);
No_Element : constant Cursor := (Is_Empty => True);
end Natools.Constant_Indefinite_Ordered_Maps;
|
-----------------------------------------------------------------------
-- ADO Sequences Hilo-- HiLo Database sequence generator
-- Copyright (C) 2009, 2010, 2011, 2012, 2017 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
-- === HiLo Sequence Generator ===
-- The HiLo sequence generator. This sequence generator uses a database table
-- `sequence` to allocate blocks of identifiers for a given sequence name.
-- The sequence table contains one row for each sequence. It keeps track of
-- the next available sequence identifier (in the `value column).
--
-- To allocate a sequence block, the HiLo generator obtains the next available
-- sequence identified and updates it by adding the sequence block size. The
-- HiLo sequence generator will allocate the identifiers until the block is
-- full after which a new block will be allocated.
package ADO.Sequences.Hilo is
-- ------------------------------
-- High Low sequence generator
-- ------------------------------
type HiLoGenerator is new Generator with private;
DEFAULT_BLOCK_SIZE : constant Identifier := 100;
-- Allocate an identifier using the generator.
-- The generator allocates blocks of sequences by using a sequence
-- table stored in the database. One database access is necessary
-- every N allocations.
overriding
procedure Allocate (Gen : in out HiLoGenerator;
Id : in out Objects.Object_Record'Class);
-- Allocate a new sequence block.
procedure Allocate_Sequence (Gen : in out HiLoGenerator);
function Create_HiLo_Generator
(Sess_Factory : in Session_Factory_Access)
return Generator_Access;
private
type HiLoGenerator is new Generator with record
Last_Id : Identifier := NO_IDENTIFIER;
Next_Id : Identifier := NO_IDENTIFIER;
Block_Size : Identifier := DEFAULT_BLOCK_SIZE;
end record;
end ADO.Sequences.Hilo;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- U I N T P --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Output; use Output;
with Tree_IO; use Tree_IO;
with GNAT.HTable; use GNAT.HTable;
package body Uintp is
------------------------
-- Local Declarations --
------------------------
Uint_Int_First : Uint := Uint_0;
-- Uint value containing Int'First value, set by Initialize. The initial
-- value of Uint_0 is used for an assertion check that ensures that this
-- value is not used before it is initialized. This value is used in the
-- UI_Is_In_Int_Range predicate, and it is right that this is a host value,
-- since the issue is host representation of integer values.
Uint_Int_Last : Uint;
-- Uint value containing Int'Last value set by Initialize
UI_Power_2 : array (Int range 0 .. 64) of Uint;
-- This table is used to memoize exponentiations by powers of 2. The Nth
-- entry, if set, contains the Uint value 2 ** N. Initially UI_Power_2_Set
-- is zero and only the 0'th entry is set, the invariant being that all
-- entries in the range 0 .. UI_Power_2_Set are initialized.
UI_Power_2_Set : Nat;
-- Number of entries set in UI_Power_2;
UI_Power_10 : array (Int range 0 .. 64) of Uint;
-- This table is used to memoize exponentiations by powers of 10 in the
-- same manner as described above for UI_Power_2.
UI_Power_10_Set : Nat;
-- Number of entries set in UI_Power_10;
Uints_Min : Uint;
Udigits_Min : Int;
-- These values are used to make sure that the mark/release mechanism does
-- not destroy values saved in the U_Power tables or in the hash table used
-- by UI_From_Int. Whenever an entry is made in either of these tables,
-- Uints_Min and Udigits_Min are updated to protect the entry, and Release
-- never cuts back beyond these minimum values.
Int_0 : constant Int := 0;
Int_1 : constant Int := 1;
Int_2 : constant Int := 2;
-- These values are used in some cases where the use of numeric literals
-- would cause ambiguities (integer vs Uint).
----------------------------
-- UI_From_Int Hash Table --
----------------------------
-- UI_From_Int uses a hash table to avoid duplicating entries and wasting
-- storage. This is particularly important for complex cases of back
-- annotation.
subtype Hnum is Nat range 0 .. 1022;
function Hash_Num (F : Int) return Hnum;
-- Hashing function
package UI_Ints is new Simple_HTable (
Header_Num => Hnum,
Element => Uint,
No_Element => No_Uint,
Key => Int,
Hash => Hash_Num,
Equal => "=");
-----------------------
-- Local Subprograms --
-----------------------
function Direct (U : Uint) return Boolean;
pragma Inline (Direct);
-- Returns True if U is represented directly
function Direct_Val (U : Uint) return Int;
-- U is a Uint for is represented directly. The returned result is the
-- value represented.
function GCD (Jin, Kin : Int) return Int;
-- Compute GCD of two integers. Assumes that Jin >= Kin >= 0
procedure Image_Out
(Input : Uint;
To_Buffer : Boolean;
Format : UI_Format);
-- Common processing for UI_Image and UI_Write, To_Buffer is set True for
-- UI_Image, and false for UI_Write, and Format is copied from the Format
-- parameter to UI_Image or UI_Write.
procedure Init_Operand (UI : Uint; Vec : out UI_Vector);
pragma Inline (Init_Operand);
-- This procedure puts the value of UI into the vector in canonical
-- multiple precision format. The parameter should be of the correct size
-- as determined by a previous call to N_Digits (UI). The first digit of
-- Vec contains the sign, all other digits are always non-negative. Note
-- that the input may be directly represented, and in this case Vec will
-- contain the corresponding one or two digit value. The low bound of Vec
-- is always 1.
function Least_Sig_Digit (Arg : Uint) return Int;
pragma Inline (Least_Sig_Digit);
-- Returns the Least Significant Digit of Arg quickly. When the given Uint
-- is less than 2**15, the value returned is the input value, in this case
-- the result may be negative. It is expected that any use will mask off
-- unnecessary bits. This is used for finding Arg mod B where B is a power
-- of two. Hence the actual base is irrelevant as long as it is a power of
-- two.
procedure Most_Sig_2_Digits
(Left : Uint;
Right : Uint;
Left_Hat : out Int;
Right_Hat : out Int);
-- Returns leading two significant digits from the given pair of Uint's.
-- Mathematically: returns Left / (Base ** K) and Right / (Base ** K) where
-- K is as small as possible S.T. Right_Hat < Base * Base. It is required
-- that Left > Right for the algorithm to work.
function N_Digits (Input : Uint) return Int;
pragma Inline (N_Digits);
-- Returns number of "digits" in a Uint
procedure UI_Div_Rem
(Left, Right : Uint;
Quotient : out Uint;
Remainder : out Uint;
Discard_Quotient : Boolean := False;
Discard_Remainder : Boolean := False);
-- Compute Euclidean division of Left by Right. If Discard_Quotient is
-- False then the quotient is returned in Quotient (otherwise Quotient is
-- set to No_Uint). If Discard_Remainder is False, then the remainder is
-- returned in Remainder (otherwise Remainder is set to No_Uint).
--
-- If Discard_Quotient is True, Quotient is set to No_Uint
-- If Discard_Remainder is True, Remainder is set to No_Uint
------------
-- Direct --
------------
function Direct (U : Uint) return Boolean is
begin
return Int (U) <= Int (Uint_Direct_Last);
end Direct;
----------------
-- Direct_Val --
----------------
function Direct_Val (U : Uint) return Int is
begin
pragma Assert (Direct (U));
return Int (U) - Int (Uint_Direct_Bias);
end Direct_Val;
---------
-- GCD --
---------
function GCD (Jin, Kin : Int) return Int is
J, K, Tmp : Int;
begin
pragma Assert (Jin >= Kin);
pragma Assert (Kin >= Int_0);
J := Jin;
K := Kin;
while K /= Uint_0 loop
Tmp := J mod K;
J := K;
K := Tmp;
end loop;
return J;
end GCD;
--------------
-- Hash_Num --
--------------
function Hash_Num (F : Int) return Hnum is
begin
return Types."mod" (F, Hnum'Range_Length);
end Hash_Num;
---------------
-- Image_Out --
---------------
procedure Image_Out
(Input : Uint;
To_Buffer : Boolean;
Format : UI_Format)
is
Marks : constant Uintp.Save_Mark := Uintp.Mark;
Base : Uint;
Ainput : Uint;
Digs_Output : Natural := 0;
-- Counts digits output. In hex mode, but not in decimal mode, we
-- put an underline after every four hex digits that are output.
Exponent : Natural := 0;
-- If the number is too long to fit in the buffer, we switch to an
-- approximate output format with an exponent. This variable records
-- the exponent value.
function Better_In_Hex return Boolean;
-- Determines if it is better to generate digits in base 16 (result
-- is true) or base 10 (result is false). The choice is purely a
-- matter of convenience and aesthetics, so it does not matter which
-- value is returned from a correctness point of view.
procedure Image_Char (C : Character);
-- Internal procedure to output one character
procedure Image_Exponent (N : Natural);
-- Output non-zero exponent. Note that we only use the exponent form in
-- the buffer case, so we know that To_Buffer is true.
procedure Image_Uint (U : Uint);
-- Internal procedure to output characters of non-negative Uint
-------------------
-- Better_In_Hex --
-------------------
function Better_In_Hex return Boolean is
T16 : constant Uint := Uint_2 ** Int'(16);
A : Uint;
begin
A := UI_Abs (Input);
-- Small values up to 2**16 can always be in decimal
if A < T16 then
return False;
end if;
-- Otherwise, see if we are a power of 2 or one less than a power
-- of 2. For the moment these are the only cases printed in hex.
if A mod Uint_2 = Uint_1 then
A := A + Uint_1;
end if;
loop
if A mod T16 /= Uint_0 then
return False;
else
A := A / T16;
end if;
exit when A < T16;
end loop;
while A > Uint_2 loop
if A mod Uint_2 /= Uint_0 then
return False;
else
A := A / Uint_2;
end if;
end loop;
return True;
end Better_In_Hex;
----------------
-- Image_Char --
----------------
procedure Image_Char (C : Character) is
begin
if To_Buffer then
if UI_Image_Length + 6 > UI_Image_Max then
Exponent := Exponent + 1;
else
UI_Image_Length := UI_Image_Length + 1;
UI_Image_Buffer (UI_Image_Length) := C;
end if;
else
Write_Char (C);
end if;
end Image_Char;
--------------------
-- Image_Exponent --
--------------------
procedure Image_Exponent (N : Natural) is
begin
if N >= 10 then
Image_Exponent (N / 10);
end if;
UI_Image_Length := UI_Image_Length + 1;
UI_Image_Buffer (UI_Image_Length) :=
Character'Val (Character'Pos ('0') + N mod 10);
end Image_Exponent;
----------------
-- Image_Uint --
----------------
procedure Image_Uint (U : Uint) is
H : constant array (Int range 0 .. 15) of Character :=
"0123456789ABCDEF";
Q, R : Uint;
begin
UI_Div_Rem (U, Base, Q, R);
if Q > Uint_0 then
Image_Uint (Q);
end if;
if Digs_Output = 4 and then Base = Uint_16 then
Image_Char ('_');
Digs_Output := 0;
end if;
Image_Char (H (UI_To_Int (R)));
Digs_Output := Digs_Output + 1;
end Image_Uint;
-- Start of processing for Image_Out
begin
if Input = No_Uint then
Image_Char ('?');
return;
end if;
UI_Image_Length := 0;
if Input < Uint_0 then
Image_Char ('-');
Ainput := -Input;
else
Ainput := Input;
end if;
if Format = Hex
or else (Format = Auto and then Better_In_Hex)
then
Base := Uint_16;
Image_Char ('1');
Image_Char ('6');
Image_Char ('#');
Image_Uint (Ainput);
Image_Char ('#');
else
Base := Uint_10;
Image_Uint (Ainput);
end if;
if Exponent /= 0 then
UI_Image_Length := UI_Image_Length + 1;
UI_Image_Buffer (UI_Image_Length) := 'E';
Image_Exponent (Exponent);
end if;
Uintp.Release (Marks);
end Image_Out;
-------------------
-- Init_Operand --
-------------------
procedure Init_Operand (UI : Uint; Vec : out UI_Vector) is
Loc : Int;
pragma Assert (Vec'First = Int'(1));
begin
if Direct (UI) then
Vec (1) := Direct_Val (UI);
if Vec (1) >= Base then
Vec (2) := Vec (1) rem Base;
Vec (1) := Vec (1) / Base;
end if;
else
Loc := Uints.Table (UI).Loc;
for J in 1 .. Uints.Table (UI).Length loop
Vec (J) := Udigits.Table (Loc + J - 1);
end loop;
end if;
end Init_Operand;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
Uints.Init;
Udigits.Init;
Uint_Int_First := UI_From_Int (Int'First);
Uint_Int_Last := UI_From_Int (Int'Last);
UI_Power_2 (0) := Uint_1;
UI_Power_2_Set := 0;
UI_Power_10 (0) := Uint_1;
UI_Power_10_Set := 0;
Uints_Min := Uints.Last;
Udigits_Min := Udigits.Last;
UI_Ints.Reset;
end Initialize;
---------------------
-- Least_Sig_Digit --
---------------------
function Least_Sig_Digit (Arg : Uint) return Int is
V : Int;
begin
if Direct (Arg) then
V := Direct_Val (Arg);
if V >= Base then
V := V mod Base;
end if;
-- Note that this result may be negative
return V;
else
return
Udigits.Table
(Uints.Table (Arg).Loc + Uints.Table (Arg).Length - 1);
end if;
end Least_Sig_Digit;
----------
-- Mark --
----------
function Mark return Save_Mark is
begin
return (Save_Uint => Uints.Last, Save_Udigit => Udigits.Last);
end Mark;
-----------------------
-- Most_Sig_2_Digits --
-----------------------
procedure Most_Sig_2_Digits
(Left : Uint;
Right : Uint;
Left_Hat : out Int;
Right_Hat : out Int)
is
begin
pragma Assert (Left >= Right);
if Direct (Left) then
Left_Hat := Direct_Val (Left);
Right_Hat := Direct_Val (Right);
return;
else
declare
L1 : constant Int :=
Udigits.Table (Uints.Table (Left).Loc);
L2 : constant Int :=
Udigits.Table (Uints.Table (Left).Loc + 1);
begin
-- It is not so clear what to return when Arg is negative???
Left_Hat := abs (L1) * Base + L2;
end;
end if;
declare
Length_L : constant Int := Uints.Table (Left).Length;
Length_R : Int;
R1 : Int;
R2 : Int;
T : Int;
begin
if Direct (Right) then
T := Direct_Val (Left);
R1 := abs (T / Base);
R2 := T rem Base;
Length_R := 2;
else
R1 := abs (Udigits.Table (Uints.Table (Right).Loc));
R2 := Udigits.Table (Uints.Table (Right).Loc + 1);
Length_R := Uints.Table (Right).Length;
end if;
if Length_L = Length_R then
Right_Hat := R1 * Base + R2;
elsif Length_L = Length_R + Int_1 then
Right_Hat := R1;
else
Right_Hat := 0;
end if;
end;
end Most_Sig_2_Digits;
---------------
-- N_Digits --
---------------
-- Note: N_Digits returns 1 for No_Uint
function N_Digits (Input : Uint) return Int is
begin
if Direct (Input) then
if Direct_Val (Input) >= Base then
return 2;
else
return 1;
end if;
else
return Uints.Table (Input).Length;
end if;
end N_Digits;
--------------
-- Num_Bits --
--------------
function Num_Bits (Input : Uint) return Nat is
Bits : Nat;
Num : Nat;
begin
-- Largest negative number has to be handled specially, since it is in
-- Int_Range, but we cannot take the absolute value.
if Input = Uint_Int_First then
return Int'Size;
-- For any other number in Int_Range, get absolute value of number
elsif UI_Is_In_Int_Range (Input) then
Num := abs (UI_To_Int (Input));
Bits := 0;
-- If not in Int_Range then initialize bit count for all low order
-- words, and set number to high order digit.
else
Bits := Base_Bits * (Uints.Table (Input).Length - 1);
Num := abs (Udigits.Table (Uints.Table (Input).Loc));
end if;
-- Increase bit count for remaining value in Num
while Types.">" (Num, 0) loop
Num := Num / 2;
Bits := Bits + 1;
end loop;
return Bits;
end Num_Bits;
---------
-- pid --
---------
procedure pid (Input : Uint) is
begin
UI_Write (Input, Decimal);
Write_Eol;
end pid;
---------
-- pih --
---------
procedure pih (Input : Uint) is
begin
UI_Write (Input, Hex);
Write_Eol;
end pih;
-------------
-- Release --
-------------
procedure Release (M : Save_Mark) is
begin
Uints.Set_Last (Uint'Max (M.Save_Uint, Uints_Min));
Udigits.Set_Last (Int'Max (M.Save_Udigit, Udigits_Min));
end Release;
----------------------
-- Release_And_Save --
----------------------
procedure Release_And_Save (M : Save_Mark; UI : in out Uint) is
begin
if Direct (UI) then
Release (M);
else
declare
UE_Len : constant Pos := Uints.Table (UI).Length;
UE_Loc : constant Int := Uints.Table (UI).Loc;
UD : constant Udigits.Table_Type (1 .. UE_Len) :=
Udigits.Table (UE_Loc .. UE_Loc + UE_Len - 1);
begin
Release (M);
Uints.Append ((Length => UE_Len, Loc => Udigits.Last + 1));
UI := Uints.Last;
for J in 1 .. UE_Len loop
Udigits.Append (UD (J));
end loop;
end;
end if;
end Release_And_Save;
procedure Release_And_Save (M : Save_Mark; UI1, UI2 : in out Uint) is
begin
if Direct (UI1) then
Release_And_Save (M, UI2);
elsif Direct (UI2) then
Release_And_Save (M, UI1);
else
declare
UE1_Len : constant Pos := Uints.Table (UI1).Length;
UE1_Loc : constant Int := Uints.Table (UI1).Loc;
UD1 : constant Udigits.Table_Type (1 .. UE1_Len) :=
Udigits.Table (UE1_Loc .. UE1_Loc + UE1_Len - 1);
UE2_Len : constant Pos := Uints.Table (UI2).Length;
UE2_Loc : constant Int := Uints.Table (UI2).Loc;
UD2 : constant Udigits.Table_Type (1 .. UE2_Len) :=
Udigits.Table (UE2_Loc .. UE2_Loc + UE2_Len - 1);
begin
Release (M);
Uints.Append ((Length => UE1_Len, Loc => Udigits.Last + 1));
UI1 := Uints.Last;
for J in 1 .. UE1_Len loop
Udigits.Append (UD1 (J));
end loop;
Uints.Append ((Length => UE2_Len, Loc => Udigits.Last + 1));
UI2 := Uints.Last;
for J in 1 .. UE2_Len loop
Udigits.Append (UD2 (J));
end loop;
end;
end if;
end Release_And_Save;
---------------
-- Tree_Read --
---------------
procedure Tree_Read is
begin
Uints.Tree_Read;
Udigits.Tree_Read;
Tree_Read_Int (Int (Uint_Int_First));
Tree_Read_Int (Int (Uint_Int_Last));
Tree_Read_Int (UI_Power_2_Set);
Tree_Read_Int (UI_Power_10_Set);
Tree_Read_Int (Int (Uints_Min));
Tree_Read_Int (Udigits_Min);
for J in 0 .. UI_Power_2_Set loop
Tree_Read_Int (Int (UI_Power_2 (J)));
end loop;
for J in 0 .. UI_Power_10_Set loop
Tree_Read_Int (Int (UI_Power_10 (J)));
end loop;
end Tree_Read;
----------------
-- Tree_Write --
----------------
procedure Tree_Write is
begin
Uints.Tree_Write;
Udigits.Tree_Write;
Tree_Write_Int (Int (Uint_Int_First));
Tree_Write_Int (Int (Uint_Int_Last));
Tree_Write_Int (UI_Power_2_Set);
Tree_Write_Int (UI_Power_10_Set);
Tree_Write_Int (Int (Uints_Min));
Tree_Write_Int (Udigits_Min);
for J in 0 .. UI_Power_2_Set loop
Tree_Write_Int (Int (UI_Power_2 (J)));
end loop;
for J in 0 .. UI_Power_10_Set loop
Tree_Write_Int (Int (UI_Power_10 (J)));
end loop;
end Tree_Write;
-------------
-- UI_Abs --
-------------
function UI_Abs (Right : Uint) return Uint is
begin
if Right < Uint_0 then
return -Right;
else
return Right;
end if;
end UI_Abs;
-------------
-- UI_Add --
-------------
function UI_Add (Left : Int; Right : Uint) return Uint is
begin
return UI_Add (UI_From_Int (Left), Right);
end UI_Add;
function UI_Add (Left : Uint; Right : Int) return Uint is
begin
return UI_Add (Left, UI_From_Int (Right));
end UI_Add;
function UI_Add (Left : Uint; Right : Uint) return Uint is
begin
-- Simple cases of direct operands and addition of zero
if Direct (Left) then
if Direct (Right) then
return UI_From_Int (Direct_Val (Left) + Direct_Val (Right));
elsif Int (Left) = Int (Uint_0) then
return Right;
end if;
elsif Direct (Right) and then Int (Right) = Int (Uint_0) then
return Left;
end if;
-- Otherwise full circuit is needed
declare
L_Length : constant Int := N_Digits (Left);
R_Length : constant Int := N_Digits (Right);
L_Vec : UI_Vector (1 .. L_Length);
R_Vec : UI_Vector (1 .. R_Length);
Sum_Length : Int;
Tmp_Int : Int;
Carry : Int;
Borrow : Int;
X_Bigger : Boolean := False;
Y_Bigger : Boolean := False;
Result_Neg : Boolean := False;
begin
Init_Operand (Left, L_Vec);
Init_Operand (Right, R_Vec);
-- At least one of the two operands is in multi-digit form.
-- Calculate the number of digits sufficient to hold result.
if L_Length > R_Length then
Sum_Length := L_Length + 1;
X_Bigger := True;
else
Sum_Length := R_Length + 1;
if R_Length > L_Length then
Y_Bigger := True;
end if;
end if;
-- Make copies of the absolute values of L_Vec and R_Vec into X and Y
-- both with lengths equal to the maximum possibly needed. This makes
-- looping over the digits much simpler.
declare
X : UI_Vector (1 .. Sum_Length);
Y : UI_Vector (1 .. Sum_Length);
Tmp_UI : UI_Vector (1 .. Sum_Length);
begin
for J in 1 .. Sum_Length - L_Length loop
X (J) := 0;
end loop;
X (Sum_Length - L_Length + 1) := abs L_Vec (1);
for J in 2 .. L_Length loop
X (J + (Sum_Length - L_Length)) := L_Vec (J);
end loop;
for J in 1 .. Sum_Length - R_Length loop
Y (J) := 0;
end loop;
Y (Sum_Length - R_Length + 1) := abs R_Vec (1);
for J in 2 .. R_Length loop
Y (J + (Sum_Length - R_Length)) := R_Vec (J);
end loop;
if (L_Vec (1) < Int_0) = (R_Vec (1) < Int_0) then
-- Same sign so just add
Carry := 0;
for J in reverse 1 .. Sum_Length loop
Tmp_Int := X (J) + Y (J) + Carry;
if Tmp_Int >= Base then
Tmp_Int := Tmp_Int - Base;
Carry := 1;
else
Carry := 0;
end if;
X (J) := Tmp_Int;
end loop;
return Vector_To_Uint (X, L_Vec (1) < Int_0);
else
-- Find which one has bigger magnitude
if not (X_Bigger or Y_Bigger) then
for J in L_Vec'Range loop
if abs L_Vec (J) > abs R_Vec (J) then
X_Bigger := True;
exit;
elsif abs R_Vec (J) > abs L_Vec (J) then
Y_Bigger := True;
exit;
end if;
end loop;
end if;
-- If they have identical magnitude, just return 0, else swap
-- if necessary so that X had the bigger magnitude. Determine
-- if result is negative at this time.
Result_Neg := False;
if not (X_Bigger or Y_Bigger) then
return Uint_0;
elsif Y_Bigger then
if R_Vec (1) < Int_0 then
Result_Neg := True;
end if;
Tmp_UI := X;
X := Y;
Y := Tmp_UI;
else
if L_Vec (1) < Int_0 then
Result_Neg := True;
end if;
end if;
-- Subtract Y from the bigger X
Borrow := 0;
for J in reverse 1 .. Sum_Length loop
Tmp_Int := X (J) - Y (J) + Borrow;
if Tmp_Int < Int_0 then
Tmp_Int := Tmp_Int + Base;
Borrow := -1;
else
Borrow := 0;
end if;
X (J) := Tmp_Int;
end loop;
return Vector_To_Uint (X, Result_Neg);
end if;
end;
end;
end UI_Add;
--------------------------
-- UI_Decimal_Digits_Hi --
--------------------------
function UI_Decimal_Digits_Hi (U : Uint) return Nat is
begin
-- The maximum value of a "digit" is 32767, which is 5 decimal digits,
-- so an N_Digit number could take up to 5 times this number of digits.
-- This is certainly too high for large numbers but it is not worth
-- worrying about.
return 5 * N_Digits (U);
end UI_Decimal_Digits_Hi;
--------------------------
-- UI_Decimal_Digits_Lo --
--------------------------
function UI_Decimal_Digits_Lo (U : Uint) return Nat is
begin
-- The maximum value of a "digit" is 32767, which is more than four
-- decimal digits, but not a full five digits. The easily computed
-- minimum number of decimal digits is thus 1 + 4 * the number of
-- digits. This is certainly too low for large numbers but it is not
-- worth worrying about.
return 1 + 4 * (N_Digits (U) - 1);
end UI_Decimal_Digits_Lo;
------------
-- UI_Div --
------------
function UI_Div (Left : Int; Right : Uint) return Uint is
begin
return UI_Div (UI_From_Int (Left), Right);
end UI_Div;
function UI_Div (Left : Uint; Right : Int) return Uint is
begin
return UI_Div (Left, UI_From_Int (Right));
end UI_Div;
function UI_Div (Left, Right : Uint) return Uint is
Quotient : Uint;
Remainder : Uint;
pragma Warnings (Off, Remainder);
begin
UI_Div_Rem
(Left, Right,
Quotient, Remainder,
Discard_Remainder => True);
return Quotient;
end UI_Div;
----------------
-- UI_Div_Rem --
----------------
procedure UI_Div_Rem
(Left, Right : Uint;
Quotient : out Uint;
Remainder : out Uint;
Discard_Quotient : Boolean := False;
Discard_Remainder : Boolean := False)
is
begin
pragma Assert (Right /= Uint_0);
Quotient := No_Uint;
Remainder := No_Uint;
-- Cases where both operands are represented directly
if Direct (Left) and then Direct (Right) then
declare
DV_Left : constant Int := Direct_Val (Left);
DV_Right : constant Int := Direct_Val (Right);
begin
if not Discard_Quotient then
Quotient := UI_From_Int (DV_Left / DV_Right);
end if;
if not Discard_Remainder then
Remainder := UI_From_Int (DV_Left rem DV_Right);
end if;
return;
end;
end if;
declare
L_Length : constant Int := N_Digits (Left);
R_Length : constant Int := N_Digits (Right);
Q_Length : constant Int := L_Length - R_Length + 1;
L_Vec : UI_Vector (1 .. L_Length);
R_Vec : UI_Vector (1 .. R_Length);
D : Int;
Remainder_I : Int;
Tmp_Divisor : Int;
Carry : Int;
Tmp_Int : Int;
Tmp_Dig : Int;
procedure UI_Div_Vector
(L_Vec : UI_Vector;
R_Int : Int;
Quotient : out UI_Vector;
Remainder : out Int);
pragma Inline (UI_Div_Vector);
-- Specialised variant for case where the divisor is a single digit
procedure UI_Div_Vector
(L_Vec : UI_Vector;
R_Int : Int;
Quotient : out UI_Vector;
Remainder : out Int)
is
Tmp_Int : Int;
begin
Remainder := 0;
for J in L_Vec'Range loop
Tmp_Int := Remainder * Base + abs L_Vec (J);
Quotient (Quotient'First + J - L_Vec'First) := Tmp_Int / R_Int;
Remainder := Tmp_Int rem R_Int;
end loop;
if L_Vec (L_Vec'First) < Int_0 then
Remainder := -Remainder;
end if;
end UI_Div_Vector;
-- Start of processing for UI_Div_Rem
begin
-- Result is zero if left operand is shorter than right
if L_Length < R_Length then
if not Discard_Quotient then
Quotient := Uint_0;
end if;
if not Discard_Remainder then
Remainder := Left;
end if;
return;
end if;
Init_Operand (Left, L_Vec);
Init_Operand (Right, R_Vec);
-- Case of right operand is single digit. Here we can simply divide
-- each digit of the left operand by the divisor, from most to least
-- significant, carrying the remainder to the next digit (just like
-- ordinary long division by hand).
if R_Length = Int_1 then
Tmp_Divisor := abs R_Vec (1);
declare
Quotient_V : UI_Vector (1 .. L_Length);
begin
UI_Div_Vector (L_Vec, Tmp_Divisor, Quotient_V, Remainder_I);
if not Discard_Quotient then
Quotient :=
Vector_To_Uint
(Quotient_V, (L_Vec (1) < Int_0 xor R_Vec (1) < Int_0));
end if;
if not Discard_Remainder then
Remainder := UI_From_Int (Remainder_I);
end if;
return;
end;
end if;
-- The possible simple cases have been exhausted. Now turn to the
-- algorithm D from the section of Knuth mentioned at the top of
-- this package.
Algorithm_D : declare
Dividend : UI_Vector (1 .. L_Length + 1);
Divisor : UI_Vector (1 .. R_Length);
Quotient_V : UI_Vector (1 .. Q_Length);
Divisor_Dig1 : Int;
Divisor_Dig2 : Int;
Q_Guess : Int;
R_Guess : Int;
begin
-- [ NORMALIZE ] (step D1 in the algorithm). First calculate the
-- scale d, and then multiply Left and Right (u and v in the book)
-- by d to get the dividend and divisor to work with.
D := Base / (abs R_Vec (1) + 1);
Dividend (1) := 0;
Dividend (2) := abs L_Vec (1);
for J in 3 .. L_Length + Int_1 loop
Dividend (J) := L_Vec (J - 1);
end loop;
Divisor (1) := abs R_Vec (1);
for J in Int_2 .. R_Length loop
Divisor (J) := R_Vec (J);
end loop;
if D > Int_1 then
-- Multiply Dividend by d
Carry := 0;
for J in reverse Dividend'Range loop
Tmp_Int := Dividend (J) * D + Carry;
Dividend (J) := Tmp_Int rem Base;
Carry := Tmp_Int / Base;
end loop;
-- Multiply Divisor by d
Carry := 0;
for J in reverse Divisor'Range loop
Tmp_Int := Divisor (J) * D + Carry;
Divisor (J) := Tmp_Int rem Base;
Carry := Tmp_Int / Base;
end loop;
end if;
-- Main loop of long division algorithm
Divisor_Dig1 := Divisor (1);
Divisor_Dig2 := Divisor (2);
for J in Quotient_V'Range loop
-- [ CALCULATE Q (hat) ] (step D3 in the algorithm)
-- Note: this version of step D3 is from the original published
-- algorithm, which is known to have a bug causing overflows.
-- See: http://www-cs-faculty.stanford.edu/~uno/err2-2e.ps.gz
-- and http://www-cs-faculty.stanford.edu/~uno/all2-pre.ps.gz.
-- The code below is the fixed version of this step.
Tmp_Int := Dividend (J) * Base + Dividend (J + 1);
-- Initial guess
Q_Guess := Tmp_Int / Divisor_Dig1;
R_Guess := Tmp_Int rem Divisor_Dig1;
-- Refine the guess
while Q_Guess >= Base
or else Divisor_Dig2 * Q_Guess >
R_Guess * Base + Dividend (J + 2)
loop
Q_Guess := Q_Guess - 1;
R_Guess := R_Guess + Divisor_Dig1;
exit when R_Guess >= Base;
end loop;
-- [ MULTIPLY & SUBTRACT ] (step D4). Q_Guess * Divisor is
-- subtracted from the remaining dividend.
Carry := 0;
for K in reverse Divisor'Range loop
Tmp_Int := Dividend (J + K) - Q_Guess * Divisor (K) + Carry;
Tmp_Dig := Tmp_Int rem Base;
Carry := Tmp_Int / Base;
if Tmp_Dig < Int_0 then
Tmp_Dig := Tmp_Dig + Base;
Carry := Carry - 1;
end if;
Dividend (J + K) := Tmp_Dig;
end loop;
Dividend (J) := Dividend (J) + Carry;
-- [ TEST REMAINDER ] & [ ADD BACK ] (steps D5 and D6)
-- Here there is a slight difference from the book: the last
-- carry is always added in above and below (cancelling each
-- other). In fact the dividend going negative is used as
-- the test.
-- If the Dividend went negative, then Q_Guess was off by
-- one, so it is decremented, and the divisor is added back
-- into the relevant portion of the dividend.
if Dividend (J) < Int_0 then
Q_Guess := Q_Guess - 1;
Carry := 0;
for K in reverse Divisor'Range loop
Tmp_Int := Dividend (J + K) + Divisor (K) + Carry;
if Tmp_Int >= Base then
Tmp_Int := Tmp_Int - Base;
Carry := 1;
else
Carry := 0;
end if;
Dividend (J + K) := Tmp_Int;
end loop;
Dividend (J) := Dividend (J) + Carry;
end if;
-- Finally we can get the next quotient digit
Quotient_V (J) := Q_Guess;
end loop;
-- [ UNNORMALIZE ] (step D8)
if not Discard_Quotient then
Quotient := Vector_To_Uint
(Quotient_V, (L_Vec (1) < Int_0 xor R_Vec (1) < Int_0));
end if;
if not Discard_Remainder then
declare
Remainder_V : UI_Vector (1 .. R_Length);
Discard_Int : Int;
pragma Warnings (Off, Discard_Int);
begin
UI_Div_Vector
(Dividend (Dividend'Last - R_Length + 1 .. Dividend'Last),
D,
Remainder_V, Discard_Int);
Remainder := Vector_To_Uint (Remainder_V, L_Vec (1) < Int_0);
end;
end if;
end Algorithm_D;
end;
end UI_Div_Rem;
------------
-- UI_Eq --
------------
function UI_Eq (Left : Int; Right : Uint) return Boolean is
begin
return not UI_Ne (UI_From_Int (Left), Right);
end UI_Eq;
function UI_Eq (Left : Uint; Right : Int) return Boolean is
begin
return not UI_Ne (Left, UI_From_Int (Right));
end UI_Eq;
function UI_Eq (Left : Uint; Right : Uint) return Boolean is
begin
return not UI_Ne (Left, Right);
end UI_Eq;
--------------
-- UI_Expon --
--------------
function UI_Expon (Left : Int; Right : Uint) return Uint is
begin
return UI_Expon (UI_From_Int (Left), Right);
end UI_Expon;
function UI_Expon (Left : Uint; Right : Int) return Uint is
begin
return UI_Expon (Left, UI_From_Int (Right));
end UI_Expon;
function UI_Expon (Left : Int; Right : Int) return Uint is
begin
return UI_Expon (UI_From_Int (Left), UI_From_Int (Right));
end UI_Expon;
function UI_Expon (Left : Uint; Right : Uint) return Uint is
begin
pragma Assert (Right >= Uint_0);
-- Any value raised to power of 0 is 1
if Right = Uint_0 then
return Uint_1;
-- 0 to any positive power is 0
elsif Left = Uint_0 then
return Uint_0;
-- 1 to any power is 1
elsif Left = Uint_1 then
return Uint_1;
-- Any value raised to power of 1 is that value
elsif Right = Uint_1 then
return Left;
-- Cases which can be done by table lookup
elsif Right <= Uint_64 then
-- 2 ** N for N in 2 .. 64
if Left = Uint_2 then
declare
Right_Int : constant Int := Direct_Val (Right);
begin
if Right_Int > UI_Power_2_Set then
for J in UI_Power_2_Set + Int_1 .. Right_Int loop
UI_Power_2 (J) := UI_Power_2 (J - Int_1) * Int_2;
Uints_Min := Uints.Last;
Udigits_Min := Udigits.Last;
end loop;
UI_Power_2_Set := Right_Int;
end if;
return UI_Power_2 (Right_Int);
end;
-- 10 ** N for N in 2 .. 64
elsif Left = Uint_10 then
declare
Right_Int : constant Int := Direct_Val (Right);
begin
if Right_Int > UI_Power_10_Set then
for J in UI_Power_10_Set + Int_1 .. Right_Int loop
UI_Power_10 (J) := UI_Power_10 (J - Int_1) * Int (10);
Uints_Min := Uints.Last;
Udigits_Min := Udigits.Last;
end loop;
UI_Power_10_Set := Right_Int;
end if;
return UI_Power_10 (Right_Int);
end;
end if;
end if;
-- If we fall through, then we have the general case (see Knuth 4.6.3)
declare
N : Uint := Right;
Squares : Uint := Left;
Result : Uint := Uint_1;
M : constant Uintp.Save_Mark := Uintp.Mark;
begin
loop
if (Least_Sig_Digit (N) mod Int_2) = Int_1 then
Result := Result * Squares;
end if;
N := N / Uint_2;
exit when N = Uint_0;
Squares := Squares * Squares;
end loop;
Uintp.Release_And_Save (M, Result);
return Result;
end;
end UI_Expon;
----------------
-- UI_From_CC --
----------------
function UI_From_CC (Input : Char_Code) return Uint is
begin
return UI_From_Int (Int (Input));
end UI_From_CC;
-----------------
-- UI_From_Int --
-----------------
function UI_From_Int (Input : Int) return Uint is
U : Uint;
begin
if Min_Direct <= Input and then Input <= Max_Direct then
return Uint (Int (Uint_Direct_Bias) + Input);
end if;
-- If already in the hash table, return entry
U := UI_Ints.Get (Input);
if U /= No_Uint then
return U;
end if;
-- For values of larger magnitude, compute digits into a vector and call
-- Vector_To_Uint.
declare
Max_For_Int : constant := 3;
-- Base is defined so that 3 Uint digits is sufficient to hold the
-- largest possible Int value.
V : UI_Vector (1 .. Max_For_Int);
Temp_Integer : Int := Input;
begin
for J in reverse V'Range loop
V (J) := abs (Temp_Integer rem Base);
Temp_Integer := Temp_Integer / Base;
end loop;
U := Vector_To_Uint (V, Input < Int_0);
UI_Ints.Set (Input, U);
Uints_Min := Uints.Last;
Udigits_Min := Udigits.Last;
return U;
end;
end UI_From_Int;
------------
-- UI_GCD --
------------
-- Lehmer's algorithm for GCD
-- The idea is to avoid using multiple precision arithmetic wherever
-- possible, substituting Int arithmetic instead. See Knuth volume II,
-- Algorithm L (page 329).
-- We use the same notation as Knuth (U_Hat standing for the obvious)
function UI_GCD (Uin, Vin : Uint) return Uint is
U, V : Uint;
-- Copies of Uin and Vin
U_Hat, V_Hat : Int;
-- The most Significant digits of U,V
A, B, C, D, T, Q, Den1, Den2 : Int;
Tmp_UI : Uint;
Marks : constant Uintp.Save_Mark := Uintp.Mark;
Iterations : Integer := 0;
begin
pragma Assert (Uin >= Vin);
pragma Assert (Vin >= Uint_0);
U := Uin;
V := Vin;
loop
Iterations := Iterations + 1;
if Direct (V) then
if V = Uint_0 then
return U;
else
return
UI_From_Int (GCD (Direct_Val (V), UI_To_Int (U rem V)));
end if;
end if;
Most_Sig_2_Digits (U, V, U_Hat, V_Hat);
A := 1;
B := 0;
C := 0;
D := 1;
loop
-- We might overflow and get division by zero here. This just
-- means we cannot take the single precision step
Den1 := V_Hat + C;
Den2 := V_Hat + D;
exit when Den1 = Int_0 or else Den2 = Int_0;
-- Compute Q, the trial quotient
Q := (U_Hat + A) / Den1;
exit when Q /= ((U_Hat + B) / Den2);
-- A single precision step Euclid step will give same answer as a
-- multiprecision one.
T := A - (Q * C);
A := C;
C := T;
T := B - (Q * D);
B := D;
D := T;
T := U_Hat - (Q * V_Hat);
U_Hat := V_Hat;
V_Hat := T;
end loop;
-- Take a multiprecision Euclid step
if B = Int_0 then
-- No single precision steps take a regular Euclid step
Tmp_UI := U rem V;
U := V;
V := Tmp_UI;
else
-- Use prior single precision steps to compute this Euclid step
-- For constructs such as:
-- sqrt_2: constant := 1.41421_35623_73095_04880_16887_24209_698;
-- sqrt_eps: constant long_float := long_float( 1.0 / sqrt_2)
-- ** long_float'machine_mantissa;
--
-- we spend 80% of our time working on this step. Perhaps we need
-- a special case Int / Uint dot product to speed things up. ???
-- Alternatively we could increase the single precision iterations
-- to handle Uint's of some small size ( <5 digits?). Then we
-- would have more iterations on small Uint. On the code above, we
-- only get 5 (on average) single precision iterations per large
-- iteration. ???
Tmp_UI := (UI_From_Int (A) * U) + (UI_From_Int (B) * V);
V := (UI_From_Int (C) * U) + (UI_From_Int (D) * V);
U := Tmp_UI;
end if;
-- If the operands are very different in magnitude, the loop will
-- generate large amounts of short-lived data, which it is worth
-- removing periodically.
if Iterations > 100 then
Release_And_Save (Marks, U, V);
Iterations := 0;
end if;
end loop;
end UI_GCD;
------------
-- UI_Ge --
------------
function UI_Ge (Left : Int; Right : Uint) return Boolean is
begin
return not UI_Lt (UI_From_Int (Left), Right);
end UI_Ge;
function UI_Ge (Left : Uint; Right : Int) return Boolean is
begin
return not UI_Lt (Left, UI_From_Int (Right));
end UI_Ge;
function UI_Ge (Left : Uint; Right : Uint) return Boolean is
begin
return not UI_Lt (Left, Right);
end UI_Ge;
------------
-- UI_Gt --
------------
function UI_Gt (Left : Int; Right : Uint) return Boolean is
begin
return UI_Lt (Right, UI_From_Int (Left));
end UI_Gt;
function UI_Gt (Left : Uint; Right : Int) return Boolean is
begin
return UI_Lt (UI_From_Int (Right), Left);
end UI_Gt;
function UI_Gt (Left : Uint; Right : Uint) return Boolean is
begin
return UI_Lt (Left => Right, Right => Left);
end UI_Gt;
---------------
-- UI_Image --
---------------
procedure UI_Image (Input : Uint; Format : UI_Format := Auto) is
begin
Image_Out (Input, True, Format);
end UI_Image;
function UI_Image
(Input : Uint;
Format : UI_Format := Auto) return String
is
begin
Image_Out (Input, True, Format);
return UI_Image_Buffer (1 .. UI_Image_Length);
end UI_Image;
-------------------------
-- UI_Is_In_Int_Range --
-------------------------
function UI_Is_In_Int_Range (Input : Uint) return Boolean is
begin
-- Make sure we don't get called before Initialize
pragma Assert (Uint_Int_First /= Uint_0);
if Direct (Input) then
return True;
else
return Input >= Uint_Int_First
and then Input <= Uint_Int_Last;
end if;
end UI_Is_In_Int_Range;
------------
-- UI_Le --
------------
function UI_Le (Left : Int; Right : Uint) return Boolean is
begin
return not UI_Lt (Right, UI_From_Int (Left));
end UI_Le;
function UI_Le (Left : Uint; Right : Int) return Boolean is
begin
return not UI_Lt (UI_From_Int (Right), Left);
end UI_Le;
function UI_Le (Left : Uint; Right : Uint) return Boolean is
begin
return not UI_Lt (Left => Right, Right => Left);
end UI_Le;
------------
-- UI_Lt --
------------
function UI_Lt (Left : Int; Right : Uint) return Boolean is
begin
return UI_Lt (UI_From_Int (Left), Right);
end UI_Lt;
function UI_Lt (Left : Uint; Right : Int) return Boolean is
begin
return UI_Lt (Left, UI_From_Int (Right));
end UI_Lt;
function UI_Lt (Left : Uint; Right : Uint) return Boolean is
begin
-- Quick processing for identical arguments
if Int (Left) = Int (Right) then
return False;
-- Quick processing for both arguments directly represented
elsif Direct (Left) and then Direct (Right) then
return Int (Left) < Int (Right);
-- At least one argument is more than one digit long
else
declare
L_Length : constant Int := N_Digits (Left);
R_Length : constant Int := N_Digits (Right);
L_Vec : UI_Vector (1 .. L_Length);
R_Vec : UI_Vector (1 .. R_Length);
begin
Init_Operand (Left, L_Vec);
Init_Operand (Right, R_Vec);
if L_Vec (1) < Int_0 then
-- First argument negative, second argument non-negative
if R_Vec (1) >= Int_0 then
return True;
-- Both arguments negative
else
if L_Length /= R_Length then
return L_Length > R_Length;
elsif L_Vec (1) /= R_Vec (1) then
return L_Vec (1) < R_Vec (1);
else
for J in 2 .. L_Vec'Last loop
if L_Vec (J) /= R_Vec (J) then
return L_Vec (J) > R_Vec (J);
end if;
end loop;
return False;
end if;
end if;
else
-- First argument non-negative, second argument negative
if R_Vec (1) < Int_0 then
return False;
-- Both arguments non-negative
else
if L_Length /= R_Length then
return L_Length < R_Length;
else
for J in L_Vec'Range loop
if L_Vec (J) /= R_Vec (J) then
return L_Vec (J) < R_Vec (J);
end if;
end loop;
return False;
end if;
end if;
end if;
end;
end if;
end UI_Lt;
------------
-- UI_Max --
------------
function UI_Max (Left : Int; Right : Uint) return Uint is
begin
return UI_Max (UI_From_Int (Left), Right);
end UI_Max;
function UI_Max (Left : Uint; Right : Int) return Uint is
begin
return UI_Max (Left, UI_From_Int (Right));
end UI_Max;
function UI_Max (Left : Uint; Right : Uint) return Uint is
begin
if Left >= Right then
return Left;
else
return Right;
end if;
end UI_Max;
------------
-- UI_Min --
------------
function UI_Min (Left : Int; Right : Uint) return Uint is
begin
return UI_Min (UI_From_Int (Left), Right);
end UI_Min;
function UI_Min (Left : Uint; Right : Int) return Uint is
begin
return UI_Min (Left, UI_From_Int (Right));
end UI_Min;
function UI_Min (Left : Uint; Right : Uint) return Uint is
begin
if Left <= Right then
return Left;
else
return Right;
end if;
end UI_Min;
-------------
-- UI_Mod --
-------------
function UI_Mod (Left : Int; Right : Uint) return Uint is
begin
return UI_Mod (UI_From_Int (Left), Right);
end UI_Mod;
function UI_Mod (Left : Uint; Right : Int) return Uint is
begin
return UI_Mod (Left, UI_From_Int (Right));
end UI_Mod;
function UI_Mod (Left : Uint; Right : Uint) return Uint is
Urem : constant Uint := Left rem Right;
begin
if (Left < Uint_0) = (Right < Uint_0)
or else Urem = Uint_0
then
return Urem;
else
return Right + Urem;
end if;
end UI_Mod;
-------------------------------
-- UI_Modular_Exponentiation --
-------------------------------
function UI_Modular_Exponentiation
(B : Uint;
E : Uint;
Modulo : Uint) return Uint
is
M : constant Save_Mark := Mark;
Result : Uint := Uint_1;
Base : Uint := B;
Exponent : Uint := E;
begin
while Exponent /= Uint_0 loop
if Least_Sig_Digit (Exponent) rem Int'(2) = Int'(1) then
Result := (Result * Base) rem Modulo;
end if;
Exponent := Exponent / Uint_2;
Base := (Base * Base) rem Modulo;
end loop;
Release_And_Save (M, Result);
return Result;
end UI_Modular_Exponentiation;
------------------------
-- UI_Modular_Inverse --
------------------------
function UI_Modular_Inverse (N : Uint; Modulo : Uint) return Uint is
M : constant Save_Mark := Mark;
U : Uint;
V : Uint;
Q : Uint;
R : Uint;
X : Uint;
Y : Uint;
T : Uint;
S : Int := 1;
begin
U := Modulo;
V := N;
X := Uint_1;
Y := Uint_0;
loop
UI_Div_Rem (U, V, Quotient => Q, Remainder => R);
U := V;
V := R;
T := X;
X := Y + Q * X;
Y := T;
S := -S;
exit when R = Uint_1;
end loop;
if S = Int'(-1) then
X := Modulo - X;
end if;
Release_And_Save (M, X);
return X;
end UI_Modular_Inverse;
------------
-- UI_Mul --
------------
function UI_Mul (Left : Int; Right : Uint) return Uint is
begin
return UI_Mul (UI_From_Int (Left), Right);
end UI_Mul;
function UI_Mul (Left : Uint; Right : Int) return Uint is
begin
return UI_Mul (Left, UI_From_Int (Right));
end UI_Mul;
function UI_Mul (Left : Uint; Right : Uint) return Uint is
begin
-- Case where product fits in the range of a 32-bit integer
if Int (Left) <= Int (Uint_Max_Simple_Mul)
and then
Int (Right) <= Int (Uint_Max_Simple_Mul)
then
return UI_From_Int (Direct_Val (Left) * Direct_Val (Right));
end if;
-- Otherwise we have the general case (Algorithm M in Knuth)
declare
L_Length : constant Int := N_Digits (Left);
R_Length : constant Int := N_Digits (Right);
L_Vec : UI_Vector (1 .. L_Length);
R_Vec : UI_Vector (1 .. R_Length);
Neg : Boolean;
begin
Init_Operand (Left, L_Vec);
Init_Operand (Right, R_Vec);
Neg := (L_Vec (1) < Int_0) xor (R_Vec (1) < Int_0);
L_Vec (1) := abs (L_Vec (1));
R_Vec (1) := abs (R_Vec (1));
Algorithm_M : declare
Product : UI_Vector (1 .. L_Length + R_Length);
Tmp_Sum : Int;
Carry : Int;
begin
for J in Product'Range loop
Product (J) := 0;
end loop;
for J in reverse R_Vec'Range loop
Carry := 0;
for K in reverse L_Vec'Range loop
Tmp_Sum :=
L_Vec (K) * R_Vec (J) + Product (J + K) + Carry;
Product (J + K) := Tmp_Sum rem Base;
Carry := Tmp_Sum / Base;
end loop;
Product (J) := Carry;
end loop;
return Vector_To_Uint (Product, Neg);
end Algorithm_M;
end;
end UI_Mul;
------------
-- UI_Ne --
------------
function UI_Ne (Left : Int; Right : Uint) return Boolean is
begin
return UI_Ne (UI_From_Int (Left), Right);
end UI_Ne;
function UI_Ne (Left : Uint; Right : Int) return Boolean is
begin
return UI_Ne (Left, UI_From_Int (Right));
end UI_Ne;
function UI_Ne (Left : Uint; Right : Uint) return Boolean is
begin
-- Quick processing for identical arguments. Note that this takes
-- care of the case of two No_Uint arguments.
if Int (Left) = Int (Right) then
return False;
end if;
-- See if left operand directly represented
if Direct (Left) then
-- If right operand directly represented then compare
if Direct (Right) then
return Int (Left) /= Int (Right);
-- Left operand directly represented, right not, must be unequal
else
return True;
end if;
-- Right operand directly represented, left not, must be unequal
elsif Direct (Right) then
return True;
end if;
-- Otherwise both multi-word, do comparison
declare
Size : constant Int := N_Digits (Left);
Left_Loc : Int;
Right_Loc : Int;
begin
if Size /= N_Digits (Right) then
return True;
end if;
Left_Loc := Uints.Table (Left).Loc;
Right_Loc := Uints.Table (Right).Loc;
for J in Int_0 .. Size - Int_1 loop
if Udigits.Table (Left_Loc + J) /=
Udigits.Table (Right_Loc + J)
then
return True;
end if;
end loop;
return False;
end;
end UI_Ne;
----------------
-- UI_Negate --
----------------
function UI_Negate (Right : Uint) return Uint is
begin
-- Case where input is directly represented. Note that since the range
-- of Direct values is non-symmetrical, the result may not be directly
-- represented, this is taken care of in UI_From_Int.
if Direct (Right) then
return UI_From_Int (-Direct_Val (Right));
-- Full processing for multi-digit case. Note that we cannot just copy
-- the value to the end of the table negating the first digit, since the
-- range of Direct values is non-symmetrical, so we can have a negative
-- value that is not Direct whose negation can be represented directly.
else
declare
R_Length : constant Int := N_Digits (Right);
R_Vec : UI_Vector (1 .. R_Length);
Neg : Boolean;
begin
Init_Operand (Right, R_Vec);
Neg := R_Vec (1) > Int_0;
R_Vec (1) := abs R_Vec (1);
return Vector_To_Uint (R_Vec, Neg);
end;
end if;
end UI_Negate;
-------------
-- UI_Rem --
-------------
function UI_Rem (Left : Int; Right : Uint) return Uint is
begin
return UI_Rem (UI_From_Int (Left), Right);
end UI_Rem;
function UI_Rem (Left : Uint; Right : Int) return Uint is
begin
return UI_Rem (Left, UI_From_Int (Right));
end UI_Rem;
function UI_Rem (Left, Right : Uint) return Uint is
Remainder : Uint;
Quotient : Uint;
pragma Warnings (Off, Quotient);
begin
pragma Assert (Right /= Uint_0);
if Direct (Right) and then Direct (Left) then
return UI_From_Int (Direct_Val (Left) rem Direct_Val (Right));
else
UI_Div_Rem
(Left, Right, Quotient, Remainder, Discard_Quotient => True);
return Remainder;
end if;
end UI_Rem;
------------
-- UI_Sub --
------------
function UI_Sub (Left : Int; Right : Uint) return Uint is
begin
return UI_Add (Left, -Right);
end UI_Sub;
function UI_Sub (Left : Uint; Right : Int) return Uint is
begin
return UI_Add (Left, -Right);
end UI_Sub;
function UI_Sub (Left : Uint; Right : Uint) return Uint is
begin
if Direct (Left) and then Direct (Right) then
return UI_From_Int (Direct_Val (Left) - Direct_Val (Right));
else
return UI_Add (Left, -Right);
end if;
end UI_Sub;
--------------
-- UI_To_CC --
--------------
function UI_To_CC (Input : Uint) return Char_Code is
begin
if Direct (Input) then
return Char_Code (Direct_Val (Input));
-- Case of input is more than one digit
else
declare
In_Length : constant Int := N_Digits (Input);
In_Vec : UI_Vector (1 .. In_Length);
Ret_CC : Char_Code;
begin
Init_Operand (Input, In_Vec);
-- We assume value is positive
Ret_CC := 0;
for Idx in In_Vec'Range loop
Ret_CC := Ret_CC * Char_Code (Base) +
Char_Code (abs In_Vec (Idx));
end loop;
return Ret_CC;
end;
end if;
end UI_To_CC;
----------------
-- UI_To_Int --
----------------
function UI_To_Int (Input : Uint) return Int is
pragma Assert (Input /= No_Uint);
begin
if Direct (Input) then
return Direct_Val (Input);
-- Case of input is more than one digit
else
declare
In_Length : constant Int := N_Digits (Input);
In_Vec : UI_Vector (1 .. In_Length);
Ret_Int : Int;
begin
-- Uints of more than one digit could be outside the range for
-- Ints. Caller should have checked for this if not certain.
-- Fatal error to attempt to convert from value outside Int'Range.
pragma Assert (UI_Is_In_Int_Range (Input));
-- Otherwise, proceed ahead, we are OK
Init_Operand (Input, In_Vec);
Ret_Int := 0;
-- Calculate -|Input| and then negates if value is positive. This
-- handles our current definition of Int (based on 2s complement).
-- Is it secure enough???
for Idx in In_Vec'Range loop
Ret_Int := Ret_Int * Base - abs In_Vec (Idx);
end loop;
if In_Vec (1) < Int_0 then
return Ret_Int;
else
return -Ret_Int;
end if;
end;
end if;
end UI_To_Int;
--------------
-- UI_Write --
--------------
procedure UI_Write (Input : Uint; Format : UI_Format := Auto) is
begin
Image_Out (Input, False, Format);
end UI_Write;
---------------------
-- Vector_To_Uint --
---------------------
function Vector_To_Uint
(In_Vec : UI_Vector;
Negative : Boolean)
return Uint
is
Size : Int;
Val : Int;
begin
-- The vector can contain leading zeros. These are not stored in the
-- table, so loop through the vector looking for first non-zero digit
for J in In_Vec'Range loop
if In_Vec (J) /= Int_0 then
-- The length of the value is the length of the rest of the vector
Size := In_Vec'Last - J + 1;
-- One digit value can always be represented directly
if Size = Int_1 then
if Negative then
return Uint (Int (Uint_Direct_Bias) - In_Vec (J));
else
return Uint (Int (Uint_Direct_Bias) + In_Vec (J));
end if;
-- Positive two digit values may be in direct representation range
elsif Size = Int_2 and then not Negative then
Val := In_Vec (J) * Base + In_Vec (J + 1);
if Val <= Max_Direct then
return Uint (Int (Uint_Direct_Bias) + Val);
end if;
end if;
-- The value is outside the direct representation range and must
-- therefore be stored in the table. Expand the table to contain
-- the count and digits. The index of the new table entry will be
-- returned as the result.
Uints.Append ((Length => Size, Loc => Udigits.Last + 1));
if Negative then
Val := -In_Vec (J);
else
Val := +In_Vec (J);
end if;
Udigits.Append (Val);
for K in 2 .. Size loop
Udigits.Append (In_Vec (J + K - 1));
end loop;
return Uints.Last;
end if;
end loop;
-- Dropped through loop only if vector contained all zeros
return Uint_0;
end Vector_To_Uint;
end Uintp;
|
--
-- Copyright 2018 The wookey project team <wookey@ssi.gouv.fr>
-- - Ryad Benadjila
-- - Arnauld Michelizza
-- - Mathieu Renard
-- - Philippe Thierry
-- - Philippe Trebuchet
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
--
with types.c;
with c.kernel;
#if CONFIG_KERNEL_PANIC_WIPE
with soc;
with soc.layout; use soc.layout;
#end if;
#if not CONFIG_KERNEL_PANIC_FREEZE
with m4;
with m4.scb;
#end if;
package body ewok.debug
with spark_mode => off
is
procedure log (s : string; nl : boolean := true)
is
c_string : types.c.c_string (1 .. s'length + 3);
begin
for i in s'range loop
c_string(1 + i - s'first) := s(i);
end loop;
if nl then
c_string(c_string'last - 2) := ASCII.CR;
c_string(c_string'last - 1) := ASCII.LF;
c_string(c_string'last) := ASCII.NUL;
else
c_string(c_string'last - 2) := ASCII.NUL;
end if;
c.kernel.log (c_string);
c.kernel.flush;
end log;
procedure log (level : t_level; s : string)
is
begin
case level is
when DEBUG =>
log (BG_COLOR_ORANGE & s & BG_COLOR_BLACK);
when INFO =>
log (BG_COLOR_BLUE & s & BG_COLOR_BLACK);
when WARNING =>
log (BG_COLOR_ORANGE & s & BG_COLOR_BLACK);
when ERROR .. ALERT =>
log (BG_COLOR_RED & s & BG_COLOR_BLACK);
end case;
end log;
procedure alert (s : string)
is
begin
log (BG_COLOR_RED & s & BG_COLOR_BLACK, false);
end alert;
procedure newline
is
s : constant types.c.c_string (1 .. 3) := (ASCII.CR, ASCII.LF, ASCII.NUL);
begin
c.kernel.log (s);
c.kernel.flush;
end newline;
procedure panic (s : string)
is
begin
log (BG_COLOR_RED & "panic: " & s & BG_COLOR_BLACK);
#if CONFIG_KERNEL_PANIC_FREEZE
loop null; end loop;
#end if;
#if CONFIG_KERNEL_PANIC_REBOOT
m4.scb.reset;
#end if;
#if CONFIG_KERNEL_PANIC_WIPE
declare
sram : array (0 .. soc.layout.USER_RAM_SIZE) of types.byte
with address => to_address(USER_RAM_BASE);
begin
-- Wiping the user applications in RAM before reseting. Kernel data
-- and bss are not cleared because the are in use and there should
-- be no sensible content in kernel data (secrets are hold by user tasks).
-- TODO: Clearing IPC content
sram := (others => 0);
m4.scb.reset;
end;
#end if;
end panic;
end ewok.debug;
|
package body Points is
function Set_Draw_Colour (Colour : Singles.Vector4) return Colour_Data is
begin
return (others => Colour);
end Set_Draw_Colour;
end Points;
|
package kv.avm.vole_parser is
Unimplemented_Error : exception;
procedure YYParse;
Verbose : Boolean := False;
end kv.avm.vole_parser;
|
-----------------------------------------------------------------------
-- babel-strategies -- Strategies to backup files
-- Copyright (C) 2014, 2015, 2016 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.
-----------------------------------------------------------------------
pragma Ada_2012;
with Babel.Files.Signatures;
with Util.Encoders.SHA1;
with Util.Log.Loggers;
with Babel.Streams.Refs;
package body Babel.Strategies.Default is
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Babel.Strategies.Default");
-- Returns true if there is a directory that must be processed by the current strategy.
overriding
function Has_Directory (Strategy : in Default_Strategy_Type) return Boolean is
begin
return false; -- not Strategy.Queue.Directories.Is_Empty;
end Has_Directory;
-- Get the next directory that must be processed by the strategy.
overriding
procedure Peek_Directory (Strategy : in out Default_Strategy_Type;
Directory : out Babel.Files.Directory_Type) is
Last : constant String := ""; -- Strategy.Queue.Directories.Last_Element;
begin
-- Strategy.Queue.Directories.Delete_Last;
null;
end Peek_Directory;
-- Set the file queue that the strategy must use.
procedure Set_Queue (Strategy : in out Default_Strategy_Type;
Queue : in Babel.Files.Queues.File_Queue_Access) is
begin
Strategy.Queue := Queue;
end Set_Queue;
overriding
procedure Execute (Strategy : in out Default_Strategy_Type) is
use type Babel.Files.File_Type;
File : Babel.Files.File_Type;
SHA1 : Util.Encoders.SHA1.Hash_Array;
Stream : Babel.Streams.Refs.Stream_Ref;
begin
Strategy.Queue.Queue.Dequeue (File, 0.1);
if File = Babel.Files.NO_FILE then
Log.Debug ("Dequeue NO_FILE");
else
Log.Debug ("Dequeue {0}", Babel.Files.Get_Path (File));
Strategy.Read_File (File, Stream);
Babel.Files.Signatures.Sha1 (Stream, SHA1);
Babel.Files.Set_Signature (File, SHA1);
if Babel.Files.Is_Modified (File) then
Strategy.Backup_File (File, Stream);
end if;
end if;
end Execute;
-- Scan the directory
overriding
procedure Scan (Strategy : in out Default_Strategy_Type;
Directory : in Babel.Files.Directory_Type;
Container : in out Babel.Files.File_Container'Class) is
procedure Add_Queue (File : in Babel.Files.File_Type) is
begin
Log.Debug ("Queueing {0}", Babel.Files.Get_Path (File));
Strategy.Queue.Add_File (File);
end Add_Queue;
begin
Strategy_Type (Strategy).Scan (Directory, Container);
Container.Each_File (Add_Queue'Access);
end Scan;
-- overriding
-- procedure Add_File (Into : in out Default_Strategy_Type;
-- Path : in String;
-- Element : in Babel.Files.File) is
-- begin
-- Into.Queue.Add_File (Path, Element);
-- end Add_File;
--
-- overriding
-- procedure Add_Directory (Into : in out Default_Strategy_Type;
-- Path : in String;
-- Name : in String) is
-- begin
-- Into.Queue.Add_Directory (Path, Name);
-- end Add_Directory;
end Babel.Strategies.Default;
|
with Generic_Sensor;
with Units;
with Units.Navigation; use Units.Navigation;
with Interfaces; use Interfaces;
with ublox8.Driver;
package GPS with SPARK_Mode,
Abstract_State => State
is
subtype GPS_Data_Type is GPS_Loacation_Type;
subtype GPS_DateTime is ublox8.Driver.GPS_DateTime_Type;
package GPS_Sensor is new Generic_Sensor(GPS_Data_Type); use GPS_Sensor;
type GPS_Tag is new GPS_Sensor.Sensor_Tag with record
Protocol_UBX : Boolean;
end record;
--overriding
procedure initialize (Self : in out GPS_Tag);
--with Global => (Output => GPS_Sensor.Sensor_State);
--overriding
procedure read_Measurement(Self : in out GPS_Tag);
--with Global => (In_Out => GPS_Sensor.Sensor_State);
function get_Position(Self : GPS_Tag) return GPS_Data_Type;
function get_GPS_Fix(Self : GPS_Tag) return GPS_Fix_Type;
function get_Num_Sats(Self : GPS_Tag) return Unsigned_8;
function get_Pos_Accuracy(Self : GPS_Tag) return Units.Length_Type;
function get_Speed(Self : GPS_Tag) return Units.Linear_Velocity_Type;
function get_Time(Self : GPS_Tag) return GPS_DateTime;
-- function get_Angular_Velocity (Self : GPS_Tag)
function Image (tm : GPS_DateTime) return String
with Post => Image'Result'Length <= 60;
Sensor : GPS_Tag;
end GPS;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E X P _ T S S --
-- --
-- S p e c --
-- --
-- $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. --
-- --
------------------------------------------------------------------------------
-- Type Support Subprogram (TSS) handling
with Types; use Types;
package Exp_Tss is
-- A type support subprogram (TSS) is an internally generated function or
-- procedure that is associated with a particular type. Examples are the
-- implicit initialization procedure, and subprograms for the Input and
-- Output attributes.
-- A given TSS is either generated once at the point of the declaration of
-- the type, or it is generated as needed in clients, but only one copy is
-- required in any one generated object file. The choice between these two
-- possibilities is made on a TSS-by-TSS basis depending on the estimation
-- of how likely the TSS is to be used. Initialization procedures fall in
-- the first category, for example, since it is likely that any declared
-- type will be used in a context requiring initialization, but the stream
-- attributes use the second approach, since it is more likely that they
-- will not be used at all, or will only be used in one client in any case.
-- A TSS is identified by its Chars name, i.e. for a given TSS type, the
-- same name is used for all types, e.g. the initialization routine has
-- the name _init for all types.
-- The TSS's for a given type are stored in an element list associated with
-- the type, and referenced from the TSS_Elist field of the N_Freeze_Entity
-- node associated with the type (all types that need TSS's always need to
-- be explicitly frozen, so the N_Freeze_Entity node always exists).
function TSS (Typ : Entity_Id; Nam : Name_Id) return Entity_Id;
-- Finds the TSS with the given name associated with the given type. If
-- no such TSS exists, then Empty is returned.
procedure Set_TSS (Typ : Entity_Id; TSS : Entity_Id);
-- This procedure is used to install a newly created TSS. The second
-- argument is the entity for such a new TSS. This entity is placed in
-- the TSS list for the type given as the first argument, replacing an
-- old entry of the same name if one was present. The tree for the body
-- of this TSS, which is not analyzed yet, is placed in the actions field
-- of the freeze node for the type. All such bodies are inserted into the
-- main tree and analyzed at the point at which the freeze node itself is
-- is expanded.
procedure Copy_TSS (TSS : Entity_Id; Typ : Entity_Id);
-- Given an existing TSS for another type (which is already installed,
-- analyzed and expanded), install it as the corresponding TSS for Typ.
-- Note that this just copies a reference, not the tree. This can also
-- be used to initially install a TSS in the case where the subprogram
-- for the TSS has already been created and its declaration processed.
function Init_Proc (Typ : Entity_Id) return Entity_Id;
pragma Inline (Init_Proc);
-- Obtains the _init TSS entry for the given type. This function call is
-- equivalent to TSS (Typ, Name_uInit). The _init TSS is the procedure
-- used to initialize otherwise uninitialized instances of a type. If
-- there is no _init TSS, then the type requires no initialization. Note
-- that subtypes and implicit types never have an _init TSS since subtype
-- objects are always initialized using the initialization procedure for
-- the corresponding base type (see Base_Init_Proc function). A special
-- case arises for concurrent types. Such types do not themselves have an
-- _init TSR, but initialization is required. The initialization procedure
-- used is the one fot the corresponding record type (see Base_Init_Proc).
function Base_Init_Proc (Typ : Entity_Id) return Entity_Id;
-- Obtains the _Init TSS entry from the base type of the entity, and also
-- deals with going indirect through the Corresponding_Record_Type field
-- for concurrent objects (which are initialized with the initialization
-- routine for the corresponding record type). Returns Empty if there is
-- no _Init TSS entry for the base type.
procedure Set_Init_Proc (Typ : Entity_Id; Init : Entity_Id);
pragma Inline (Set_Init_Proc);
-- The second argument is the _init TSS to be established for the type
-- given as the first argument. Equivalent to Set_TSS (Typ, Init).
function Has_Non_Null_Base_Init_Proc (Typ : Entity_Id) return Boolean;
-- Returns true if the given type has a defined Base_Init_Proc and
-- this init proc is not a null init proc (null init procs occur as
-- a result of the processing for Initialize_Scalars. This function
-- is used to test for the presence of an Init_Proc in cases where
-- a null init proc is considered equivalent to no Init_Proc.
end Exp_Tss;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . I N T E R R U P T _ M A N A G E M E N T --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-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. --
-- --
------------------------------------------------------------------------------
-- This package encapsulates and centralizes information about all uses of
-- interrupts (or signals), including the target-dependent mapping of
-- interrupts (or signals) to exceptions.
-- Unlike the original design, System.Interrupt_Management can only be used
-- for tasking systems.
-- PLEASE DO NOT put any subprogram declarations with arguments of type
-- Interrupt_ID into the visible part of this package. The type Interrupt_ID
-- is used to derive the type in Ada.Interrupts, and adding more operations
-- to that type would be illegal according to the Ada Reference Manual. This
-- is the reason why the signals sets are implemented using visible arrays
-- rather than functions.
with System.OS_Interface;
with Interfaces.C;
package System.Interrupt_Management is
pragma Preelaborate;
type Interrupt_Mask is limited private;
type Interrupt_ID is new Interfaces.C.int
range 0 .. System.OS_Interface.Max_Interrupt;
type Interrupt_Set is array (Interrupt_ID) of Boolean;
-- The following objects serve as constants, but are initialized in the
-- body to aid portability. This permits us to use more portable names for
-- interrupts, where distinct names may map to the same interrupt ID
-- value.
-- For example, suppose SIGRARE is a signal that is not defined on all
-- systems, but is always reserved when it is defined. If we have the
-- convention that ID zero is not used for any "real" signals, and SIGRARE
-- = 0 when SIGRARE is not one of the locally supported signals, we can
-- write:
-- Reserved (SIGRARE) := True;
-- and the initialization code will be portable.
Abort_Task_Interrupt : Interrupt_ID;
-- The interrupt that is used to implement task abort if an interrupt is
-- used for that purpose. This is one of the reserved interrupts.
Keep_Unmasked : Interrupt_Set := (others => False);
-- Keep_Unmasked (I) is true iff the interrupt I is one that must be kept
-- unmasked at all times, except (perhaps) for short critical sections.
-- This includes interrupts that are mapped to exceptions (see
-- System.Interrupt_Exceptions.Is_Exception), but may also include
-- interrupts (e.g. timer) that need to be kept unmasked for other
-- reasons. Where interrupts are implemented as OS signals, and signal
-- masking is per-task, the interrupt should be unmasked in ALL TASKS.
Reserve : Interrupt_Set := (others => False);
-- Reserve (I) is true iff the interrupt I is one that cannot be permitted
-- to be attached to a user handler. The possible reasons are many. For
-- example, it may be mapped to an exception used to implement task abort,
-- or used to implement time delays.
procedure Initialize;
-- Initialize the various variables defined in this package. This procedure
-- must be called before accessing any object from this package, and can be
-- called multiple times.
private
type Interrupt_Mask is new System.OS_Interface.sigset_t;
-- In some implementations Interrupt_Mask is represented as a linked list
procedure Adjust_Context_For_Raise
(Signo : System.OS_Interface.Signal;
Ucontext : System.Address);
pragma Import
(C, Adjust_Context_For_Raise, "__gnat_adjust_context_for_raise");
-- Target specific hook performing adjustments to the signal's machine
-- context, to be called before an exception may be raised from a signal
-- handler. This service is provided by init.c, together with the
-- non-tasking signal handler.
end System.Interrupt_Management;
|
package Opt37 is
type T_Bit is range 0 .. 1;
for T_Bit'Size use 1;
type Positive is range 0 .. (2 ** 31) - 1;
type Unsigned32 is mod 2 ** 32;
subtype T_Bit_Count is Positive;
subtype T_Bit_Index is T_Bit_Count range 1 .. T_Bit_Count'Last;
type T_Bit_Array is array (T_Bit_Count range <>) of T_Bit;
pragma Pack (T_Bit_Array);
function Func (Bit_Array : in T_Bit_Array;
Bit_Index : in T_Bit_Index) return Positive;
end Opt37;
|
pragma License (Unrestricted);
-- implementation unit
package Ada.Strings.Naked_Maps.Canonical_Composites is
pragma Preelaborate;
-- not-decomposable characters.
function Base_Set return not null Character_Set_Access;
-- decomposes and extracts the base character.
function Basic_Map return not null Character_Mapping_Access;
end Ada.Strings.Naked_Maps.Canonical_Composites;
|
with
Interfaces.C,
System;
use type
System.Address;
package body FLTK.Widgets.Groups.Tabbed is
procedure tabs_set_draw_hook
(W, D : in System.Address);
pragma Import (C, tabs_set_draw_hook, "tabs_set_draw_hook");
pragma Inline (tabs_set_draw_hook);
procedure tabs_set_handle_hook
(W, H : in System.Address);
pragma Import (C, tabs_set_handle_hook, "tabs_set_handle_hook");
pragma Inline (tabs_set_handle_hook);
function new_fl_tabs
(X, Y, W, H : in Interfaces.C.int;
Text : in Interfaces.C.char_array)
return System.Address;
pragma Import (C, new_fl_tabs, "new_fl_tabs");
pragma Inline (new_fl_tabs);
procedure free_fl_tabs
(S : in System.Address);
pragma Import (C, free_fl_tabs, "free_fl_tabs");
pragma Inline (free_fl_tabs);
procedure fl_tabs_client_area
(T : in System.Address;
X, Y, W, H : out Interfaces.C.int;
I : in Interfaces.C.int);
pragma Import (C, fl_tabs_client_area, "fl_tabs_client_area");
pragma Inline (fl_tabs_client_area);
function fl_tabs_get_push
(T : in System.Address)
return System.Address;
pragma Import (C, fl_tabs_get_push, "fl_tabs_get_push");
pragma Inline (fl_tabs_get_push);
procedure fl_tabs_set_push
(T, I : in System.Address);
pragma Import (C, fl_tabs_set_push, "fl_tabs_set_push");
pragma Inline (fl_tabs_set_push);
function fl_tabs_get_value
(T : in System.Address)
return System.Address;
pragma Import (C, fl_tabs_get_value, "fl_tabs_get_value");
pragma Inline (fl_tabs_get_value);
procedure fl_tabs_set_value
(T, V : in System.Address);
pragma Import (C, fl_tabs_set_value, "fl_tabs_set_value");
pragma Inline (fl_tabs_set_value);
function fl_tabs_which
(T : in System.Address;
X, Y : in Interfaces.C.int)
return System.Address;
pragma Import (C, fl_tabs_which, "fl_tabs_which");
pragma Inline (fl_tabs_which);
procedure fl_tabs_draw
(W : in System.Address);
pragma Import (C, fl_tabs_draw, "fl_tabs_draw");
pragma Inline (fl_tabs_draw);
function fl_tabs_handle
(W : in System.Address;
E : in Interfaces.C.int)
return Interfaces.C.int;
pragma Import (C, fl_tabs_handle, "fl_tabs_handle");
pragma Inline (fl_tabs_handle);
procedure Finalize
(This : in out Tabbed_Group) is
begin
if This.Void_Ptr /= System.Null_Address and then
This in Tabbed_Group'Class
then
This.Clear;
free_fl_tabs (This.Void_Ptr);
This.Void_Ptr := System.Null_Address;
end if;
Finalize (Group (This));
end Finalize;
package body Forge is
function Create
(X, Y, W, H : in Integer;
Text : in String)
return Tabbed_Group is
begin
return This : Tabbed_Group do
This.Void_Ptr := new_fl_tabs
(Interfaces.C.int (X),
Interfaces.C.int (Y),
Interfaces.C.int (W),
Interfaces.C.int (H),
Interfaces.C.To_C (Text));
fl_group_end (This.Void_Ptr);
fl_widget_set_user_data
(This.Void_Ptr,
Widget_Convert.To_Address (This'Unchecked_Access));
tabs_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
tabs_set_handle_hook (This.Void_Ptr, Handle_Hook'Address);
end return;
end Create;
end Forge;
procedure Get_Client_Area
(This : in Tabbed_Group;
Tab_Height : in Natural;
X, Y, W, H : out Integer) is
begin
fl_tabs_client_area
(This.Void_Ptr,
Interfaces.C.int (X),
Interfaces.C.int (Y),
Interfaces.C.int (W),
Interfaces.C.int (H),
Interfaces.C.int (Tab_Height));
end Get_Client_Area;
function Get_Push
(This : in Tabbed_Group)
return access Widget'Class
is
Widget_Ptr : System.Address :=
fl_tabs_get_push (This.Void_Ptr);
Actual_Widget : access Widget'Class :=
Widget_Convert.To_Pointer (fl_widget_get_user_data (Widget_Ptr));
begin
return Actual_Widget;
end Get_Push;
procedure Set_Push
(This : in out Tabbed_Group;
Item : in out Widget'Class) is
begin
fl_tabs_set_push (This.Void_Ptr, Item.Void_Ptr);
end Set_Push;
function Get_Visible
(This : in Tabbed_Group)
return access Widget'Class
is
Widget_Ptr : System.Address :=
fl_tabs_get_value (This.Void_Ptr);
Actual_Widget : access Widget'Class :=
Widget_Convert.To_Pointer (fl_widget_get_user_data (Widget_Ptr));
begin
return Actual_Widget;
end Get_Visible;
procedure Set_Visible
(This : in out Tabbed_Group;
Item : in out Widget'Class) is
begin
fl_tabs_set_value (This.Void_Ptr, Item.Void_Ptr);
end Set_Visible;
function Get_Which
(This : in Tabbed_Group;
Event_X, Event_Y : in Integer)
return access Widget'Class
is
Widget_Ptr : System.Address :=
fl_tabs_which (This.Void_Ptr, Interfaces.C.int (Event_X), Interfaces.C.int (Event_Y));
Actual_Widget : access Widget'Class :=
Widget_Convert.To_Pointer (fl_widget_get_user_data (Widget_Ptr));
begin
return Actual_Widget;
end Get_Which;
procedure Draw
(This : in out Tabbed_Group) is
begin
fl_tabs_draw (This.Void_Ptr);
end Draw;
function Handle
(This : in out Tabbed_Group;
Event : in Event_Kind)
return Event_Outcome is
begin
return Event_Outcome'Val
(fl_tabs_handle (This.Void_Ptr, Event_Kind'Pos (Event)));
end Handle;
end FLTK.Widgets.Groups.Tabbed;
|
procedure One (X : in out Integer) is
begin
X := X + 1;
end One;
|
-----------------------------------------------------------------------
-- package body Bidiagonal; bidiagonalizes real valued matrices.
-- Copyright (C) 2015-2018 Jonathan S. Parker
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-----------------------------------------------------------------------
with Ada.Numerics;
with Ada.Numerics.Generic_Elementary_Functions;
with Givens_Rotation;
package body Bidiagonal is
package math is new Ada.Numerics.Generic_Elementary_Functions (Real); use math;
package Rotate is new Givens_Rotation (Real); use Rotate;
Zero : constant Real := +0.0;
One : constant Real := +1.0;
Two : constant Real := +2.0;
----------------
-- U_Identity --
----------------
function U_Identity return U_Matrix is
U : U_Matrix := (others => (others => Zero));
begin
for r in Row_Index loop
U(r, r) := One;
end loop;
return U;
end U_Identity;
----------------
-- V_Identity --
----------------
function V_Identity return V_Matrix is
V : V_Matrix := (others => (others => Zero));
begin
for c in Col_Index loop
V(c, c) := One;
end loop;
return V;
end V_Identity;
--------------------
-- Bi_Diagonalize --
--------------------
-- Operates only on square real blocks.
--
-- Want to use orthogonal transforms to make A into B,
-- a bi-diagonal matrix with the 1st sub-diagonal non-zero.
-- Let Uj be a 2x2 givens rotation matrix,
-- and let Uj' be its transpose (and inverse). Then form
--
-- A = non-zero
--
-- (U1*...*Un) * (Un'*...*U1') * A * (V1*...*Vn) * (Vn'*...*V1') =
--
-- U * B * V,
--
-- where B = U' * A * V'.
-- and A = U * B * V.
--
-- A = U * B * V where B is bi-diagonal, with the 1st lower off-diagonal
-- non-zero, and all upper off-diagonals zero. (So B is lower triangular.)
--
procedure Bi_Diagonalize
(A : in out A_Matrix; -- A becomes the B in A = U * B * V'
V : out V_Matrix; --
U : out U_Matrix; -- Initialized with Identity
Initial_V_Matrix : in V_Matrix; -- Normally just use function V_Identity.
Initial_U_Matrix : in U_Matrix; -- Normally just use function U_Identity.
Starting_Col : in Col_Index := Col_Index'First;
Final_Col : in Col_Index := Col_Index'Last;
Final_Row : in Row_Index := Row_Index'Last;
Matrix_U_Desired : in Boolean := True;
Matrix_V_Desired : in Boolean := True)
is
Starting_Row : constant Row_Index := Row_Index (Starting_Col);
type Integer64 is range -2**63+1 .. 2**63-1;
No_of_Rows : constant Integer64 := Integer64(Final_Row)-Integer64(Starting_Row)+1;
No_of_Cols : constant Integer64 := Integer64(Final_Col)-Integer64(Starting_Col)+1;
pragma Assert (No_of_Rows >= No_of_Cols);
Pivot_Row : Row_Index;
Final_Pivot_Col, Lo_Col : Col_Index;
---------------------------------------
-- Rotate_to_Kill_Element_Lo_of_pCol --
---------------------------------------
-- Zero out A(Lo_Row, pCol)
procedure Rotate_to_Kill_Element_Lo_of_pCol
(pCol : in Col_Index;
Hi_Row : in Row_Index;
Lo_Row : in Row_Index)
is
Pivot_Col : Col_Index renames pCol;
Pivot_Row : Row_Index renames Hi_Row;
Low_Row : Row_Index renames Lo_Row;
pragma Assert(Row_Index (Pivot_Col) = Pivot_Row);
-- R_index contains Col_Index
sn, cs, cs_minus_1, sn_minus_1 : Real;
hypot : Real;
P_bigger_than_L : Boolean;
Skip_Rotation : Boolean;
P : constant Real := A(Pivot_Row, Pivot_Col); -- P is for Pivot
L : constant Real := A(Low_Row, Pivot_Col);
A_pvt, A_low, U_pvt, U_low : Real;
begin
Get_Rotation_That_Zeros_Out_Low
(P, L, sn, cs, cs_minus_1, sn_minus_1, hypot, P_bigger_than_L, Skip_Rotation);
if Skip_Rotation then return; end if;
-- Rotate rows.
--
-- Want U B V' = A (B = bi-diagonal.)
--
-- So generally, I A I = A becomes,
-- (I * G' * G) * A * (F * F' * I) = A
-- U * B * V' = A
--
-- So the desired U will be the product of the G' matrices
-- which we obtain by repeatedly multiplying I on the RHS by G'.
--
-- Start by multiplying A on LHS by givens rotation G.
if P_bigger_than_L then -- |s| < |c|
for c in Pivot_Col .. Final_Col loop
A_pvt := A(Pivot_Row, c);
A_low := A(Low_Row, c);
A(Pivot_Row, c) := A_pvt + ( cs_minus_1*A_pvt + sn*A_low);
A(Low_Row, c) := A_low + (-sn*A_pvt + cs_minus_1*A_low);
end loop;
else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1
for c in Pivot_Col .. Final_Col loop
A_pvt := A(Pivot_Row, c);
A_low := A(Low_Row, c);
A(Pivot_Row, c) := A_low + ( cs*A_pvt + sn_minus_1*A_low);
A(Low_Row, c) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_low);
end loop;
end if;
A(Pivot_Row, Pivot_Col) := Real'Copy_Sign(hypot, A(Pivot_Row, Pivot_Col));
-- Rotate corresponding columns of U. (Multiply on RHS by G', the
-- transpose of above givens matrix to accumulate full U.)
--
-- U is (Row_Index x Row_Index).
if Matrix_U_Desired then
if P_bigger_than_L then -- |s| < |c|
for r in Starting_Row .. Final_Row loop
U_pvt := U(r, Pivot_Row);
U_low := U(r, Low_Row);
U(r, Pivot_Row) := U_pvt + ( cs_minus_1*U_pvt + sn*U_low);
U(r, Low_Row) := U_low + (-sn*U_pvt + cs_minus_1*U_low);
end loop;
else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1
for r in Starting_Row .. Final_Row loop
U_pvt := U(r, Pivot_Row);
U_low := U(r, Low_Row);
U(r, Pivot_Row) := U_low + ( cs*U_pvt + sn_minus_1*U_low);
U(r, Low_Row) :=-U_pvt + (-sn_minus_1*U_pvt + cs*U_low);
end loop;
end if;
end if;
end Rotate_to_Kill_Element_Lo_of_pCol;
---------------------------------------
-- Rotate_to_Kill_Element_Hi_of_pRow --
---------------------------------------
-- Zero out A(pRow, Hi_Col)
procedure Rotate_to_Kill_Element_Hi_of_pRow
(pRow : in Row_Index;
Lo_Col : in Col_Index;
Hi_Col : in Col_Index)
is
sn, cs, cs_minus_1, sn_minus_1 : Real;
hypot : Real;
P_bigger_than_H : Boolean;
Skip_Rotation : Boolean;
Pivot_Row : Row_Index renames pRow;
Pivot_Col : Col_Index renames Lo_Col;
A_pvt, A_hi , V_pvt, V_hi : Real;
P : constant Real := A(Pivot_Row, Pivot_Col); -- P is for Pivot
H : constant Real := A(Pivot_Row, Hi_Col);
pragma Assert(Row_Index (Pivot_Col) = Pivot_Row+1);
begin
Get_Rotation_That_Zeros_Out_Low
(P, H, sn, cs, cs_minus_1, sn_minus_1, hypot, P_bigger_than_H, Skip_Rotation);
if Skip_Rotation then return; end if;
-- Rotate columns. Multiply on RHS by the above Givens matrix. (Hi_Col
-- is to the rt. visually, and its index is higher than Pivot's.)
if P_bigger_than_H then -- |s| < |c|
for r in Pivot_Row .. Final_Row loop
A_pvt := A(r, Pivot_Col);
A_hi := A(r, Hi_Col);
A(r, Pivot_Col) := A_pvt + ( cs_minus_1*A_pvt + sn*A_hi);
A(r, Hi_Col) := A_hi + (-sn*A_pvt + cs_minus_1*A_hi);
end loop;
else -- Abs_P <= Abs_H, so abs t := abs (P / H) <= 1
for r in Pivot_Row .. Final_Row loop
A_pvt := A(r, Pivot_Col);
A_hi := A(r, Hi_Col);
A(r, Pivot_Col) := A_hi + ( cs*A_pvt + sn_minus_1*A_hi);
A(r, Hi_Col) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_hi);
end loop;
end if;
A(Pivot_Row, Pivot_Col) := Real'Copy_Sign(hypot, A(Pivot_Row, Pivot_Col));
-- Rotate corresponding rows of V', hence the columns of V.
-- (Multiply on LHS of V' by transpose of above givens matrix to
-- accumulate full V.)
--
-- V is (Col_Index x Col_Index).
--
-- We are calculating U * B * V' by inserting pairs of givens
-- rotation matrices between the B and the V'. When we rotate rows
-- of V', we are rotating the 2 columns (Pivot_Col, Hi_Col) of V:
if Matrix_V_Desired then
if P_bigger_than_H then -- |s| < |c|
for r in Starting_Col .. Final_Col loop
V_pvt := V(r, Pivot_Col);
V_hi := V(r, Hi_Col);
V(r, Pivot_Col) := V_pvt + ( cs_minus_1*V_pvt + sn*V_hi);
V(r, Hi_Col) := V_hi + (-sn*V_pvt + cs_minus_1*V_hi);
end loop;
else -- Abs_P <= Abs_H, so abs t := abs (P / H) <= 1
for r in Starting_Col .. Final_Col loop
V_pvt := V(r, Pivot_Col);
V_hi := V(r, Hi_Col);
V(r, Pivot_Col) := V_hi + ( cs*V_pvt + sn_minus_1*V_hi);
V(r, Hi_Col) :=-V_pvt + (-sn_minus_1*V_pvt + cs*V_hi);
end loop;
end if;
end if;
end Rotate_to_Kill_Element_Hi_of_pRow;
type Column is array(Row_Index) of Real;
procedure Get_Sqrt_of_Sum_of_Sqrs_of_Col
(Col_Id : in Col_Index;
Starting_Row : in Row_Index;
Ending_Row : in Row_Index;
Col_Sums : out Column)
is
Max : Real := Zero;
Un_Scale, Scale : Real := Zero;
Emin : constant Integer := Real'Machine_Emin;
Emax : constant Integer := Real'Machine_Emax;
Abs_A : Real := Zero;
M_exp : Integer := 0;
begin
Max := Abs A(Starting_Row, Col_Id);
if Ending_Row > Starting_Row then
for i in Starting_Row+1 .. Ending_Row loop
Abs_A := Abs A(i, Col_Id);
if Abs_A > Max then Max := Abs_A; end if;
end loop;
end if;
if Max < Two**Emin then Col_Sums := (others => Zero); return; end if;
if Max < Two**(Emin / 2) or else Max > Two**(Emax / 4) then
M_Exp := Real'Exponent (Max);
Scale := Two ** (-M_Exp);
Un_Scale := Two ** ( M_Exp);
else
Scale := One;
Un_Scale := One;
end if;
Col_Sums(Starting_Row) := Abs A(Starting_Row, Col_Id);
if Ending_Row > Starting_Row then
Compensated_Sum:
declare
val, Sum_tmp, Err, Sum : Real := Zero;
begin
for r in Starting_Row .. Ending_Row loop
Val := (Scale * A(r, Col_Id)) ** 2;
Val := Val - Err; -- correction to Val, next term in sum.
Sum_tmp := Sum + Val; -- now increment Sum
Err := (Sum_tmp - Sum) - Val;
Sum := Sum_tmp;
Col_Sums(r) := Un_Scale * Sqrt (Sum);
end loop;
end Compensated_Sum;
end if;
end Get_Sqrt_of_Sum_of_Sqrs_of_Col;
type Row is array(Col_Index) of Real;
procedure Get_Sqrt_of_Sum_of_Sqrs_of_Row
(Row_Id : in Row_Index;
Starting_Col : in Col_Index;
Ending_Col : in Col_Index;
Row_Sums : out Row)
is
Emin : constant Integer := Real'Machine_Emin;
Emax : constant Integer := Real'Machine_Emax;
Max : Real := Zero;
Un_Scale, Scale : Real := Zero;
Abs_A : Real := Zero;
M_exp : Integer := 0;
begin
Max := Abs A(Row_Id, Starting_Col);
if Ending_Col > Starting_Col then
for c in Starting_Col+1 .. Ending_Col loop
Abs_A := Abs A(Row_Id, c);
if Abs_A > Max then Max := Abs_A; end if;
end loop;
end if;
if Max < Two**Emin then Row_Sums := (others => Zero); return; end if;
if Max < Two**(Emin / 2) or else Max > Two**(Emax / 4) then
M_Exp := Real'Exponent (Max);
Scale := Two ** (-M_Exp);
Un_Scale := Two ** ( M_Exp);
else
Scale := One;
Un_Scale := One;
end if;
Row_Sums(Starting_Col) := Abs A(Row_Id, Starting_Col);
if Ending_Col > Starting_Col then
Compensated_Sum:
declare
Term, Sum_tmp, Err, Sum : Real := Zero;
begin
for c in Starting_Col .. Ending_Col loop
Term := (Scale * A(Row_Id, c)) ** 2;
Term := Term - Err; -- correction to Term, next term in sum.
Sum_tmp := Sum + Term; -- now increment Sum
Err := (Sum_tmp - Sum) - Term;
Sum := Sum_tmp;
Row_Sums(c) := Un_Scale * Sqrt (Sum);
end loop;
end Compensated_Sum;
end if;
end Get_Sqrt_of_Sum_of_Sqrs_of_Row;
Row_Sums : Row := (others => Zero);
Col_Sums : Column := (others => Zero);
begin
V := Initial_V_Matrix;
U := Initial_U_Matrix;
-- Always identity unless you preprocessed A with an L*Q transform etc.
if No_of_Cols < 2 then return; end if; -- can do a 2x2
if Row_Index (Final_Col) < Final_Row then
Final_Pivot_Col := Final_Col;
else
Final_Pivot_Col := Final_Col - 1; -- A is square
end if;
for Pivot_Col in Starting_Col .. Final_Pivot_Col loop
-- take lo elements in col = Pivot_Col, and rotate them to diagonal.
Pivot_Row := Row_Index (Pivot_Col);
-- rotate element from Low_Row to Pivot_Row
Get_Sqrt_of_Sum_of_Sqrs_of_Col -- gd
(Col_id => Pivot_Col,
Starting_Row => Pivot_Row,
Ending_Row => Final_Row,
Col_Sums => Col_Sums);
for Low_Row in Pivot_Row+1 .. Final_Row loop -- order important.
-- 50% slower because of M(r,c) c stuff
Rotate_to_Kill_Element_Lo_of_pCol -- zero out A(Lo_Row, pCol)
(pCol => Pivot_Col,
Hi_Row => Pivot_Row, -- Hi = high to eye; its id is lower than Lo_Row.
Lo_Row => Low_Row);
A(Low_Row, Pivot_Col) := Zero;
A(Pivot_Row, Pivot_Col) :=
Real'Copy_Sign (Col_Sums(Low_Row), A(Pivot_Row, Pivot_Col));
end loop;
-- A(Pivot_Row, Pivot_Col) :=
-- Real'Copy_Sign (Col_Sums(Final_Row), A(Pivot_Row, Pivot_Col));
-- Rotate columns.
-- Take hi elements in row = Pivot_Col, and Zero them out by
-- rotating them to 1st superdiagonal (column Pivot_Col + 1).
if Pivot_Col < Final_Col-1 then -- Lo_Col+1 below is Pivot_Col+2
Pivot_Row := Row_Index (Pivot_Col);
Lo_Col := Pivot_Col + 1; -- low to the eye
Get_Sqrt_of_Sum_of_Sqrs_of_Row
(Row_Id => Pivot_Row,
Starting_Col => Lo_Col,
Ending_Col => Final_Col,
Row_Sums => Row_Sums);
for Hi_Col in Lo_Col+1 .. Final_Col loop
Rotate_to_Kill_Element_Hi_of_pRow -- zero out A(pRow, Hi_Col)
(pRow => Pivot_Row,
Lo_Col => Lo_Col,
Hi_Col => Hi_Col);
A(Pivot_Row, Hi_Col) := Zero;
A(Pivot_Row, Lo_Col) :=
Real'Copy_Sign (Row_Sums(Hi_Col), A(Pivot_Row, Lo_Col));
end loop; -- over Hi_Col
-- A(Pivot_Row, Lo_Col) :=
-- Real'Copy_Sign (Row_Sums(Final_Col), A(Pivot_Row, Lo_Col));
end if;
end loop; -- over Pivot_Col
end Bi_Diagonalize;
-- Must input matrices V and U. A must be bidiagonal - zero everywhere,
-- except the diagonal and the superdiagonal. This isn't checked.
-- Not optimized for speed.
procedure Zero_Shift_Bidiagonal_QR
(A : in out A_Matrix; -- A becomes the B in A = U * B * V'
V : in out V_Matrix; --
U : in out U_Matrix; -- Initialized with Identity
Starting_Col : in Col_Index := Col_Index'First;
Final_Col : in Col_Index := Col_Index'Last;
Final_Row : in Row_Index := Row_Index'Last;
Matrix_U_Desired : in Boolean := True;
Matrix_V_Desired : in Boolean := True)
is
Starting_Row : constant Row_Index := Row_Index (Starting_Col);
type Integer64 is range -2**63+1 .. 2**63-1;
No_of_Rows : constant Integer64 := Integer64(Final_Row)-Integer64(Starting_Row)+1;
No_of_Cols : constant Integer64 := Integer64(Final_Col)-Integer64(Starting_Col)+1;
pragma Assert (No_of_Rows >= No_of_Cols);
Pivot_Row : Row_Index;
Final_Pivot_Col : Col_Index;
---------------------------------------
-- Rotate_to_Kill_Element_Lo_of_pCol --
---------------------------------------
-- Zero out A(Lo_Row, pCol)
procedure Rotate_to_Kill_Element_Lo_of_pCol
(pCol : in Col_Index;
Hi_Row : in Row_Index;
Lo_Row : in Row_Index)
is
Pivot_Col : Col_Index renames pCol;
Pivot_Row : Row_Index renames Hi_Row;
Low_Row : Row_Index renames Lo_Row;
pragma Assert(Row_Index (Pivot_Col) = Pivot_Row);
sn, cs, cs_minus_1, sn_minus_1 : Real;
hypot : Real;
P_bigger_than_L : Boolean;
Skip_Rotation : Boolean;
P : constant Real := A(Pivot_Row, Pivot_Col); -- P is for Pivot
L : constant Real := A(Low_Row, Pivot_Col);
A_pvt, A_low, U_pvt, U_low : Real;
begin
Get_Rotation_That_Zeros_Out_Low
(P, L, sn, cs, cs_minus_1, sn_minus_1, hypot, P_bigger_than_L, Skip_Rotation);
if Skip_Rotation then return; end if;
-- Rotate rows.
--
-- Want U B V' = A (B = bi-diagonal.)
--
-- So generally, I A I = A becomes,
-- (I * G' * G) * A * (F * F' * I) = A
-- U * B * V' = A
--
-- So the desired U will be the product of the G' matrices
-- which we obtain by repeatedly multiplying I on the RHS by G'.
--
-- Start by multiplying A on LHS by givens rotation G.
if P_bigger_than_L then -- |s| < |c|
for c in Pivot_Col .. Pivot_Col+1 loop
A_pvt := A(Pivot_Row, c);
A_low := A(Low_Row, c);
A(Pivot_Row, c) := A_pvt + ( cs_minus_1*A_pvt + sn*A_low);
A(Low_Row, c) := A_low + (-sn*A_pvt + cs_minus_1*A_low);
end loop;
else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1
for c in Pivot_Col .. Pivot_Col+1 loop
A_pvt := A(Pivot_Row, c);
A_low := A(Low_Row, c);
A(Pivot_Row, c) := A_low + ( cs*A_pvt + sn_minus_1*A_low);
A(Low_Row, c) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_low);
end loop;
end if;
A(Pivot_Row, Pivot_Col) := Real'Copy_Sign(hypot, A(Pivot_Row, Pivot_Col));
-- Rotate corresponding columns of U. (Multiply on RHS by G', the
-- transpose of above givens matrix to accumulate full U.)
--
-- U is (Row_Index x Row_Index).
if Matrix_U_Desired then
if P_bigger_than_L then -- |s| < |c|
for r in Starting_Row .. Final_Row loop
U_pvt := U(r, Pivot_Row);
U_low := U(r, Low_Row);
U(r, Pivot_Row) := U_pvt + ( cs_minus_1*U_pvt + sn*U_low);
U(r, Low_Row) := U_low + (-sn*U_pvt + cs_minus_1*U_low);
end loop;
else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1
for r in Starting_Row .. Final_Row loop
U_pvt := U(r, Pivot_Row);
U_low := U(r, Low_Row);
U(r, Pivot_Row) := U_low + ( cs*U_pvt + sn_minus_1*U_low);
U(r, Low_Row) :=-U_pvt + (-sn_minus_1*U_pvt + cs*U_low);
end loop;
end if;
end if;
end Rotate_to_Kill_Element_Lo_of_pCol;
---------------------------------------
-- Rotate_to_Kill_Element_Hi_of_pRow --
---------------------------------------
-- Zero out A(pRow, Hi_Col)
procedure Rotate_to_Kill_Element_Hi_of_pRow
(pRow : in Row_Index;
Lo_Col : in Col_Index;
Hi_Col : in Col_Index)
is
sn, cs, cs_minus_1, sn_minus_1 : Real;
hypot : Real;
P_bigger_than_H : Boolean;
Skip_Rotation : Boolean;
Pivot_Row : Row_Index renames pRow;
Pivot_Col : Col_Index renames Lo_Col;
A_pvt, A_hi , V_pvt, V_hi : Real;
P : constant Real := A(Pivot_Row, Pivot_Col); -- P is for Pivot
H : constant Real := A(Pivot_Row, Hi_Col);
pragma Assert(Row_Index (Pivot_Col) = Pivot_Row);
begin
Get_Rotation_That_Zeros_Out_Low
(P, H, sn, cs, cs_minus_1, sn_minus_1, hypot, P_bigger_than_H, Skip_Rotation);
if Skip_Rotation then return; end if;
-- Rotate columns. Multiply on RHS by the above Givens matrix. (Hi_Col
-- is to the rt. visually, and its index is higher than Pivot's.)
if P_bigger_than_H then -- |s| < |c|
for r in Pivot_Row .. Pivot_Row+1 loop
A_pvt := A(r, Pivot_Col);
A_hi := A(r, Hi_Col);
A(r, Pivot_Col) := A_pvt + ( cs_minus_1*A_pvt + sn*A_hi);
A(r, Hi_Col) := A_hi + (-sn*A_pvt + cs_minus_1*A_hi);
end loop;
else -- Abs_P <= Abs_H, so abs t := abs (P / H) <= 1
for r in Pivot_Row .. Pivot_Row+1 loop
A_pvt := A(r, Pivot_Col);
A_hi := A(r, Hi_Col);
A(r, Pivot_Col) := A_hi + ( cs*A_pvt + sn_minus_1*A_hi);
A(r, Hi_Col) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_hi);
end loop;
end if;
A(Pivot_Row, Pivot_Col) := Real'Copy_Sign(hypot, A(Pivot_Row, Pivot_Col));
-- Rotate corresponding rows of V', hence the columns of V.
-- (Multiply on LHS of V' by transpose of above givens matrix to
-- accumulate full V.)
--
-- V is (Col_Index x Col_Index).
--
-- We are calculating U * B * V' by inserting pairs of givens
-- rotation matrices between the B and the V'. When we rotate rows
-- of V', we are rotating the 2 columns (Pivot_Col, Hi_Col) of V:
if Matrix_V_Desired then
if P_bigger_than_H then -- |s| < |c|
for r in Starting_Col .. Final_Col loop
V_pvt := V(r, Pivot_Col);
V_hi := V(r, Hi_Col);
V(r, Pivot_Col) := V_pvt + ( cs_minus_1*V_pvt + sn*V_hi);
V(r, Hi_Col) := V_hi + (-sn*V_pvt + cs_minus_1*V_hi);
end loop;
else -- Abs_P <= Abs_H, so abs t := abs (P / H) <= 1
for r in Starting_Col .. Final_Col loop
V_pvt := V(r, Pivot_Col);
V_hi := V(r, Hi_Col);
V(r, Pivot_Col) := V_hi + ( cs*V_pvt + sn_minus_1*V_hi);
V(r, Hi_Col) :=-V_pvt + (-sn_minus_1*V_pvt + cs*V_hi);
end loop;
end if;
end if;
end Rotate_to_Kill_Element_Hi_of_pRow;
begin
if No_of_Cols < 2 then return; end if; -- can do a 2x2
if Row_Index (Final_Col) < Final_Row then
Final_Pivot_Col := Final_Col;
else
Final_Pivot_Col := Final_Col - 1; -- A is square
end if;
-- Rotate away the superdiagonal by rotating Pivot_Col and Pivot_Col+1
for Pivot_Col in Starting_Col .. Final_Col-1 loop
-- Rotate columns.
-- Take hi element in (row, col) = (Pivot_Col, Pivot_Col+1) and
-- Zero it out by rotating to diagonal (column Pivot_Col).
Pivot_Row := Row_Index (Pivot_Col);
Rotate_to_Kill_Element_Hi_of_pRow -- zero out A(pRow, Hi_Col)
(pRow => Pivot_Row,
Lo_Col => Pivot_Col,
Hi_Col => Pivot_Col + 1);
A(Pivot_Row, Pivot_Col + 1) := Zero;
end loop; -- over Pivot_Col
-- Rotate away the subdiagonal by rotating Pivot_Row and Pivot_Row+1
for Pivot_Col in Starting_Col .. Final_Pivot_Col loop
-- Rotate rows.
-- take lo element in col = Pivot_Col, and rotate it to diagonal.
Pivot_Row := Row_Index (Pivot_Col);
Rotate_to_Kill_Element_Lo_of_pCol -- zero out A(Lo_Row, pCol)
(pCol => Pivot_Col,
Hi_Row => Pivot_Row, -- Hi = high to eye; its id is lower than Lo_Row.
Lo_Row => Pivot_Row + 1);
A(Pivot_Row + 1, Pivot_Col) := Zero;
end loop;
end Zero_Shift_Bidiagonal_QR;
end Bidiagonal;
|
package Semaphores is
protected type Counting_Semaphore(Max : Positive) is
entry Acquire;
procedure Release;
function Count return Natural;
private
Lock_Count : Natural := 0;
end Counting_Semaphore;
end Semaphores;
|
-----------------------------------------------------------------------
-- writer -- Response stream writer
-- Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Strings.Transforms;
with Unicode;
package body ASF.Contexts.Writer is
use Unicode;
-- Internal method to write a character on the response stream
-- and escape that character as necessary. Unlike 'Write_Char',
-- this operation does not closes the current XML entity.
procedure Write_Escape (Stream : in out Response_Writer'Class;
Char : in Character);
procedure Write_Escape (Stream : in out Response_Writer'Class;
Char : in Wide_Wide_Character);
-- ------------------------------
-- Response Writer
-- ------------------------------
-- ------------------------------
-- Initialize the response stream for the given content type and
-- encoding. An internal buffer is allocated for writing the stream.
-- ------------------------------
procedure Initialize (Stream : in out Response_Writer;
Content_Type : in String;
Encoding : in String;
Output : in ASF.Streams.Print_Stream) is
begin
Stream.Initialize (Output);
Stream.Content_Type := To_Unbounded_String (Content_Type);
Stream.Encoding := Unicode.Encodings.Get_By_Name (Encoding);
end Initialize;
-- ------------------------------
-- Flush the response stream and release the buffer.
-- ------------------------------
procedure Finalize (Object : in out Response_Writer) is
begin
Object.Flush;
end Finalize;
-- ------------------------------
-- Get the content type.
-- ------------------------------
function Get_Content_Type (Stream : in Response_Writer) return String is
begin
return To_String (Stream.Content_Type);
end Get_Content_Type;
-- ------------------------------
-- Get the character encoding.
-- ------------------------------
function Get_Encoding (Stream : in Response_Writer) return String is
begin
return Stream.Encoding.Name.all;
end Get_Encoding;
-- ------------------------------
-- Close the current XML entity if an entity was started
-- ------------------------------
procedure Close_Current (Stream : in out Response_Writer'Class) is
begin
if Stream.Close_Start then
Stream.Write ('>');
Stream.Close_Start := False;
end if;
Stream.Optional_Element_Size := 0;
end Close_Current;
-- ------------------------------
-- Start an XML element with the given name.
-- ------------------------------
procedure Start_Element (Stream : in out Response_Writer;
Name : in String) is
begin
Close_Current (Stream);
Stream.Write ('<');
Stream.Write (Name);
Stream.Close_Start := True;
end Start_Element;
-- ------------------------------
-- Start an XML element with the given name.
-- ------------------------------
procedure Start_Optional_Element (Stream : in out Response_Writer;
Name : in String) is
begin
Close_Current (Stream);
Stream.Optional_Element (1 .. Name'Length) := Name;
Stream.Optional_Element_Size := Name'Length;
end Start_Optional_Element;
-- ------------------------------
-- Closes an XML element of the given name.
-- ------------------------------
procedure End_Element (Stream : in out Response_Writer;
Name : in String) is
begin
Close_Current (Stream);
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
end End_Element;
-- ------------------------------
-- Closes an XML element of the given name.
-- ------------------------------
procedure End_Optional_Element (Stream : in out Response_Writer;
Name : in String) is
begin
Close_Current (Stream);
if Stream.Optional_Element_Written then
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
end if;
Stream.Optional_Element_Written := False;
Stream.Optional_Element_Size := 0;
end End_Optional_Element;
-- ------------------------------
-- Write an XML element using the given name and with the content.
-- This is similar to calling <b>Start_Element</b>, <b>Write_Text</b>
-- and <b>End_Element</b>.
-- ------------------------------
procedure Write_Element (Stream : in out Response_Writer;
Name : in String;
Content : in String) is
begin
Stream.Start_Element (Name);
Stream.Write_Text (Content);
Stream.End_Element (Name);
end Write_Element;
procedure Write_Wide_Element (Stream : in out Response_Writer;
Name : in String;
Content : in Wide_Wide_String) is
begin
Stream.Start_Element (Name);
Stream.Write_Wide_Text (Content);
Stream.End_Element (Name);
end Write_Wide_Element;
procedure Write_Wide_Element (Stream : in out Response_Writer;
Name : in String;
Content : in Unbounded_Wide_Wide_String) is
begin
Stream.Start_Element (Name);
Stream.Write_Wide_Text (Content);
Stream.End_Element (Name);
end Write_Wide_Element;
procedure Write_Attribute (Stream : in out Response_Writer;
Name : in String;
Value : in String) is
begin
-- If we have an optional element, start it.
if Stream.Optional_Element_Size > 0 and not Stream.Optional_Element_Written then
Stream.Write ('<');
Stream.Write (Stream.Optional_Element (1 .. Stream.Optional_Element_Size));
Stream.Close_Start := True;
Stream.Optional_Element_Written := True;
end if;
if Stream.Close_Start then
Stream.Write (' ');
Stream.Write (Name);
Stream.Write ('=');
Stream.Write ('"');
for I in Value'Range loop
declare
C : constant Character := Value (I);
begin
if C = '"' then
Stream.Write (""");
else
Stream.Write_Escape (C);
end if;
end;
end loop;
Stream.Write ('"');
end if;
end Write_Attribute;
procedure Write_Attribute (Stream : in out Response_Writer;
Name : in String;
Value : in Unbounded_String) is
begin
Stream.Write_Attribute (Name, To_String (Value));
end Write_Attribute;
procedure Write_Attribute (Stream : in out Response_Writer;
Name : in String;
Value : in EL.Objects.Object) is
S : constant String := EL.Objects.To_String (Value);
begin
Stream.Write_Attribute (Name, S);
end Write_Attribute;
procedure Write_Wide_Attribute (Stream : in out Response_Writer;
Name : in String;
Value : in Wide_Wide_String) is
begin
-- If we have an optional element, start it.
if Stream.Optional_Element_Size > 0 and not Stream.Optional_Element_Written then
Stream.Write ('<');
Stream.Write (Stream.Optional_Element (1 .. Stream.Optional_Element_Size));
Stream.Close_Start := True;
Stream.Optional_Element_Written := True;
end if;
if Stream.Close_Start then
Stream.Write (' ');
Stream.Write (Name);
Stream.Write ('=');
Stream.Write ('"');
for I in Value'Range loop
declare
C : constant Wide_Wide_Character := Value (I);
begin
if C = '"' then
Stream.Write (""");
else
Stream.Write_Escape (C);
end if;
end;
end loop;
Stream.Write ('"');
end if;
end Write_Wide_Attribute;
procedure Write_Wide_Attribute (Stream : in out Response_Writer;
Name : in String;
Value : in Unbounded_Wide_Wide_String) is
begin
Stream.Write_Wide_Attribute (Name, To_Wide_Wide_String (Value));
end Write_Wide_Attribute;
-- ------------------------------
-- Write a text escaping any character as necessary.
-- ------------------------------
procedure Write_Text (Stream : in out Response_Writer;
Text : in String) is
begin
for I in Text'Range loop
Response_Writer'Class (Stream).Write_Char (Text (I));
end loop;
end Write_Text;
procedure Write_Text (Stream : in out Response_Writer;
Text : in Unbounded_String) is
Count : constant Natural := Length (Text);
begin
if Count > 0 then
for I in 1 .. Count loop
Response_Writer'Class (Stream).Write_Char (Element (Text, I));
end loop;
end if;
end Write_Text;
procedure Write_Wide_Text (Stream : in out Response_Writer;
Text : in Wide_Wide_String) is
begin
for I in Text'Range loop
Response_Writer'Class (Stream).Write_Wide_Char (Text (I));
end loop;
end Write_Wide_Text;
procedure Write_Wide_Text (Stream : in out Response_Writer;
Text : in Unbounded_Wide_Wide_String) is
Count : constant Natural := Length (Text);
begin
if Count > 0 then
for I in 1 .. Count loop
Response_Writer'Class (Stream).Write_Wide_Char (Element (Text, I));
end loop;
end if;
end Write_Wide_Text;
procedure Write_Text (Stream : in out Response_Writer;
Value : in EL.Objects.Object) is
use EL.Objects;
Of_Type : constant EL.Objects.Data_Type := EL.Objects.Get_Type (Value);
begin
case Of_Type is
when TYPE_BOOLEAN =>
Close_Current (Stream);
if To_Boolean (Value) then
Response_Writer'Class (Stream).Write ("true");
else
Response_Writer'Class (Stream).Write ("false");
end if;
when TYPE_INTEGER | TYPE_FLOAT =>
Close_Current (Stream);
Response_Writer'Class (Stream).Write (To_String (Value));
when TYPE_STRING =>
Response_Writer'Class (Stream).Write_Text (To_String (Value));
when others =>
Response_Writer'Class (Stream).Write_Wide_Text (To_Wide_Wide_String (Value));
end case;
end Write_Text;
-- ------------------------------
-- Write a character on the response stream and escape that character
-- as necessary.
-- ------------------------------
procedure Write_Char (Stream : in out Response_Writer;
Char : in Character) is
begin
Close_Current (Stream);
Write_Escape (Stream, Char);
end Write_Char;
-- ------------------------------
-- Internal method to write a character on the response stream
-- and escape that character as necessary. Unlike 'Write_Char',
-- this operation does not closes the current XML entity.
-- ------------------------------
procedure Write_Escape (Stream : in out Response_Writer'Class;
Char : in Character) is
Code : constant Unicode_Char := Character'Pos (Char);
begin
-- If "?" or over, no escaping is needed (this covers
-- most of the Latin alphabet)
if Code > 16#3F# or Code <= 16#20# then
Stream.Write (Char);
elsif Char = '<' then
Stream.Write ("<");
elsif Char = '>' then
Stream.Write (">");
elsif Char = '&' then
Stream.Write ("&");
else
Stream.Write (Char);
end if;
end Write_Escape;
-- ------------------------------
-- Internal method to write a character on the response stream
-- and escape that character as necessary. Unlike 'Write_Char',
-- this operation does not closes the current XML entity.
-- ------------------------------
procedure Write_Escape (Stream : in out Response_Writer'Class;
Char : in Wide_Wide_Character) is
Code : constant Unicode_Char := Wide_Wide_Character'Pos (Char);
begin
-- Tilde or less...
if Code < 16#A0# then
-- If "?" or over, no escaping is needed (this covers
-- most of the Latin alphabet)
if Code > 16#3F# or Code <= 16#20# then
Stream.Write (Character'Val (Code));
elsif Char = '<' then
Stream.Write ("<");
elsif Char = '>' then
Stream.Write (">");
elsif Char = '&' then
Stream.Write ("&");
else
Stream.Write (Character'Val (Code));
end if;
else
declare
S : String (1 .. 5) := "�";
C : Unicode_Char;
begin
C := Code and 16#0F#;
if C > 10 then
S (4) := Character'Val (C - 10 + Character'Pos ('A'));
else
S (4) := Character'Val (C + Character'Pos ('0'));
end if;
C := (Code / 16) and 16#0F#;
if C > 10 then
S (3) := Character'Val (C - 10 + Character'Pos ('A'));
else
S (3) := Character'Val (C + Character'Pos ('0'));
end if;
Stream.Write (S);
end;
end if;
end Write_Escape;
-- ------------------------------
-- Write a character on the response stream and escape that character
-- as necessary.
-- ------------------------------
procedure Write_Wide_Char (Stream : in out Response_Writer;
Char : in Wide_Wide_Character) is
Code : constant Unicode_Char := Wide_Wide_Character'Pos (Char);
begin
Close_Current (Stream);
-- Tilde or less...
if Code < 16#100# then
Stream.Write_Char (Character'Val (Code));
else
declare
S : String (1 .. 5) := "�";
C : Unicode_Char;
begin
C := Code and 16#0F#;
if C > 10 then
S (4) := Character'Val (C - 10 + Character'Pos ('A'));
else
S (4) := Character'Val (C + Character'Pos ('0'));
end if;
C := (Code / 16) and 16#0F#;
if C > 10 then
S (3) := Character'Val (C - 10 + Character'Pos ('A'));
else
S (3) := Character'Val (C + Character'Pos ('0'));
end if;
Stream.Write (S);
end;
end if;
end Write_Wide_Char;
-- ------------------------------
-- Write a string on the stream.
-- ------------------------------
procedure Write (Stream : in out Response_Writer;
Item : in Ada.Strings.Unbounded.Unbounded_String) is
begin
Close_Current (Stream);
ASF.Streams.Print_Stream (Stream).Write (Item);
end Write;
-- ------------------------------
-- Write a raw string on the stream.
-- ------------------------------
procedure Write_Raw (Stream : in out Response_Writer;
Item : in String) is
begin
Close_Current (Stream);
ASF.Streams.Print_Stream (Stream).Write (Item);
end Write_Raw;
-- ------------------------------
-- Write a raw wide string on the stream.
-- ------------------------------
procedure Write_Raw (Stream : in out Response_Writer;
Item : in Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String) is
begin
Close_Current (Stream);
ASF.Streams.Print_Stream (Stream).Write (Item);
end Write_Raw;
-- ------------------------------
-- Write a raw wide string on the stream.
-- ------------------------------
procedure Write_Wide_Raw (Stream : in out Response_Writer;
Item : in Wide_Wide_String) is
begin
Close_Current (Stream);
ASF.Streams.Print_Stream (Stream).Write_Wide (Item);
end Write_Wide_Raw;
-- ------------------------------
-- Write the java scripts that have been queued by <b>Queue_Script</b>
-- ------------------------------
procedure Write_Scripts (Stream : in out Response_Writer) is
procedure Write (Content : in String);
procedure Write (Content : in String) is
begin
Stream.Write (Content);
end Write;
begin
if Util.Strings.Builders.Length (Stream.Include_Queue) > 0 then
Util.Strings.Builders.Iterate (Stream.Include_Queue, Write'Access);
Util.Strings.Builders.Clear (Stream.Include_Queue);
end if;
if Length (Stream.Script_Queue) = 0 then
return;
end if;
Stream.Start_Element ("script");
Stream.Write_Attribute ("type", "text/javascript");
Close_Current (Stream);
Stream.Write (Stream.Script_Queue);
Stream.End_Element ("script");
Stream.Script_Queue := Ada.Strings.Unbounded.Null_Unbounded_String;
end Write_Scripts;
-- ------------------------------
-- Append the <b>Script</b> to the javascript buffer queue. The <b>Script</b> is not escaped.
-- ------------------------------
procedure Queue_Script (Stream : in out Response_Writer;
Script : in String) is
begin
Append (Stream.Script_Queue, Script);
end Queue_Script;
-- ------------------------------
-- Append the <b>Script</b> to the javascript buffer queue. The <b>Script</b> is not escaped.
-- ------------------------------
procedure Queue_Script (Stream : in out Response_Writer;
Script : in Ada.Strings.Unbounded.Unbounded_String) is
begin
Append (Stream.Script_Queue, Script);
end Queue_Script;
-- ------------------------------
-- Append the <b>Value</b> to the javascript buffer queue. The value is escaped according
-- to Javascript escape rules.
-- ------------------------------
procedure Queue_Script (Stream : in out Response_Writer;
Value : in Util.Beans.Objects.Object) is
use Util.Beans.Objects;
Of_Type : constant Util.Beans.Objects.Data_Type := Util.Beans.Objects.Get_Type (Value);
begin
case Of_Type is
when TYPE_BOOLEAN =>
if To_Boolean (Value) then
Append (Stream.Script_Queue, "true");
else
Append (Stream.Script_Queue, "false");
end if;
when TYPE_INTEGER | TYPE_FLOAT =>
Append (Stream.Script_Queue, To_String (Value));
when TYPE_STRING =>
Util.Strings.Transforms.Escape_Javascript (Content => To_String (Value),
Into => Stream.Script_Queue);
when others =>
Util.Strings.Transforms.Escape_Javascript (Content => To_String (Value),
Into => Stream.Script_Queue);
end case;
end Queue_Script;
-- ------------------------------
-- Append a <b>script</b> include command to include the Javascript file at the given URL.
-- The include scripts are flushed by <b>Flush</b> or <b>Write_Scripts</b>.
-- ------------------------------
procedure Queue_Include_Script (Stream : in out Response_Writer;
URL : in String;
Async : in Boolean := False) is
begin
Util.Strings.Builders.Append (Stream.Include_Queue,
"<script type=""text/javascript"" src=""");
Util.Strings.Builders.Append (Stream.Include_Queue, URL);
if Async then
Util.Strings.Builders.Append (Stream.Include_Queue, """ async></script>");
else
Util.Strings.Builders.Append (Stream.Include_Queue, """></script>");
end if;
end Queue_Include_Script;
-- ------------------------------
-- Flush the response.
-- Before flusing the response, the javascript are also flushed
-- by calling <b>Write_Scripts</b>.
-- ------------------------------
overriding
procedure Flush (Stream : in out Response_Writer) is
begin
Stream.Write_Scripts;
ASF.Streams.Print_Stream (Stream).Flush;
end Flush;
end ASF.Contexts.Writer;
|
procedure default_function_argument is
function plus_defaulted(x, y: Integer := 0) return Integer is
begin
return x + y;
end plus_defaulted;
z : Integer := plus_defaulted;
begin
null;
end default_function_argument;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Reverse_String is
function Reverse_It (Item : String) return String is
Result : String (Item'Range);
begin
for I in Item'range loop
Result (Result'Last - I + Item'First) := Item (I);
end loop;
return Result;
end Reverse_It;
begin
Put_Line (Reverse_It (Get_Line));
end Reverse_String;
|
------------------------------------------------------------------------------
-- --
-- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . T A S K _ P R I M I T I V E S --
-- --
-- S p e c --
-- --
-- $Revision$
-- --
-- Copyright (C) 1991-2001, Florida State University --
-- --
-- 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 2, or (at your option) any later ver- --
-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNARL; 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. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. It is --
-- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
-- State University (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
-- RT_GNU/Linux version
pragma Polling (Off);
-- Turn off polling, we do not want ATC polling to take place during
-- tasking operations. It causes infinite loops and other problems.
with System.OS_Interface;
package System.Task_Primitives is
type Lock is limited private;
-- Used for implementation of protected objects.
type Lock_Ptr is limited private;
type RTS_Lock is limited private;
-- Used inside the runtime system. The difference between Lock and the
-- RTS_Lock is that the later one serves only as a semaphore so that do
-- not check for ceiling violations.
type RTS_Lock_Ptr is limited private;
type Task_Body_Access is access procedure;
-- Pointer to the task body's entry point (or possibly a wrapper
-- declared local to the GNARL).
type Private_Data is limited private;
-- Any information that the GNULLI needs maintained on a per-task
-- basis. A component of this type is guaranteed to be included
-- in the Ada_Task_Control_Block.
private
type RT_GNU_Linux_Lock is record
Ceiling_Priority : System.Any_Priority;
Pre_Locking_Priority : System.Any_Priority;
-- Used to store the task's active priority before it
-- acquires the lock
Owner : System.Address;
-- This is really a Task_ID, but we can't use that type
-- here because this System.Tasking is "with"
-- the current package -- a circularity.
end record;
type Lock is new RT_GNU_Linux_Lock;
type RTS_Lock is new RT_GNU_Linux_Lock;
type RTS_Lock_Ptr is access all RTS_Lock;
type Lock_Ptr is access all Lock;
type Private_Data is record
Stack : System.Address;
-- A stack space needed for the task. the space is allocated
-- when the task is being created and is deallocated when
-- the TCB for the task is finalized
Uses_Fp : Integer;
-- A flag to indicate whether the task is going to use floating-
-- point unit. It's set to 1, indicating FP unit is always going
-- to be used. The reason is that it is in this private record and
-- necessary operation has to be provided for a user to call so as
-- to change its value
Magic : Integer;
-- A special value is going to be stored in it when a task is
-- created. The value is RT_TASK_MAGIC (16#754d2774#) as declared
-- in System.OS_Interface
State : System.OS_Interface.Rt_Task_States;
-- Shows whether the task is RT_TASK_READY, RT_TASK_DELAYED or
-- RT_TASK_DORMANT to support suspend, wait, wakeup.
Stack_Bottom : System.Address;
Active_Priority : System.Any_Priority;
-- Active priority of the task
Period : System.OS_Interface.RTIME;
-- Intended originally to store the period of the task, but not used
-- in the current implementation
Resume_Time : System.OS_Interface.RTIME;
-- Store the time the task has to be awakened
Next : System.Address;
-- This really is a Task_ID, used to link the Available_TCBs.
Succ : System.Address;
pragma Volatile (Succ);
Pred : System.Address;
pragma Volatile (Pred);
-- These really are Task_ID, used to implement a circular doubly
-- linked list for task queue
L : aliased RTS_Lock;
Outer_Lock : RTS_Lock_Ptr := null;
-- Used to track which Lock the task is holding is the outermost
-- one in order to implement priority setting and inheritance
end record;
-- ???? May need to use pragma Atomic or Volatile on some
-- components; may also need to specify aliased for some.
end System.Task_Primitives;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
private with Ada.Containers.Vectors;
private with Ada.Containers.Indefinite_Vectors;
private with Ada.Strings.Unbounded;
package Specs is
-- This package implements parsing and applying .spec files.
-- These are used to easily generate parts of the low-level OpenGL
-- binding code. This package is not part of the OpenGLAda API nor
-- implementation - it is only used for generating part of its
-- source code.
type Processor is limited private;
type Spec is private;
No_Spec : constant Spec;
Parsing_Error : exception;
procedure Parse_File (Proc : in out Processor; Path : String);
function First (Proc : Processor) return Spec;
function Next (Proc : Processor; Cur : Spec) return Spec;
procedure Write_API (Proc : Processor; Cur : Spec;
Dir_Path : String);
procedure Write_Init (Proc : Processor; Dir_Path : String);
procedure Write_Wrapper_Table (Proc : Processor;
Dir_Path, Interface_Folder : String);
private
use Ada.Strings.Unbounded;
type Param_Mode is
(Mode_In, Mode_Out, Mode_In_Out, Mode_Access, Mode_Access_Constant);
package String_Lists is new Ada.Containers.Indefinite_Vectors
(Positive, String);
type Parameter is record
Mode : Param_Mode;
Names : String_Lists.Vector;
Type_Name : Unbounded_String;
end record;
package Param_Lists is new Ada.Containers.Vectors
(Positive, Parameter);
type Signature is record
Params : Param_Lists.Vector;
Return_Type : Unbounded_String;
end record;
package Sig_Lists is new Ada.Containers.Vectors (Positive, Signature);
type Body_Item_Kind is (Copy, Static, Dynamic);
type Body_Item (Kind : Body_Item_Kind) is record
case Kind is
when Copy => To_Copy : Unbounded_String;
when Static =>
S_Name, S_GL_Name : Unbounded_String;
Sigs : Sig_Lists.Vector;
when Dynamic =>
D_Name, D_GL_Name : Unbounded_String;
Sig_Id : Positive;
end case;
end record;
package Item_Lists is
new Ada.Containers.Indefinite_Vectors (Positive, Body_Item);
package Wrapper_Lists is new Ada.Containers.Indefinite_Vectors
(Positive, String_Lists.Vector, String_Lists."=");
type Spec_Data is record
Name, File_Base_Name : Unbounded_String;
Withs : String_Lists.Vector;
Uses : String_Lists.Vector;
Items : Item_Lists.Vector;
Wrappers : Wrapper_Lists.Vector;
end record;
type Spec is new Natural;
subtype Valid_Spec is Spec range 1 .. Spec'Last;
No_Spec : constant Spec := 0;
package Spec_Lists is new Ada.Containers.Vectors (Valid_Spec, Spec_Data);
type Processor is record
Dynamic_Subprogram_Types : Sig_Lists.Vector;
List : Spec_Lists.Vector;
end record;
end Specs; |
-- { dg-do compile }
-- { dg-options "-O -gnatws" }
procedure Opt43 is
function Func return Integer is
begin
if False then
return 0;
end if;
end;
begin
if Func = Func then
raise Program_Error;
end if;
exception
when Program_Error => null;
end;
|
with Ada.Strings.Unbounded;
with Config_File_Parser;
pragma Elaborate_All (Config_File_Parser);
package Config is
function TUS (S : String) return Ada.Strings.Unbounded.Unbounded_String
renames Ada.Strings.Unbounded.To_Unbounded_String;
-- Convenience rename. TUS is much shorter than To_Unbounded_String.
type Keys is (
FULLNAME,
FAVOURITEFRUIT,
NEEDSPEELING,
SEEDSREMOVED,
OTHERFAMILY);
-- These are the valid configuration keys.
type Defaults_Array is
array (Keys) of Ada.Strings.Unbounded.Unbounded_String;
-- The array type we'll use to hold our default configuration settings.
Defaults_Conf : Defaults_Array :=
(FULLNAME => TUS ("John Doe"),
FAVOURITEFRUIT => TUS ("blackberry"),
NEEDSPEELING => TUS ("False"),
SEEDSREMOVED => TUS ("False"),
OTHERFAMILY => TUS ("Daniel Defoe, Ada Byron"));
-- Default values for the Program object. These can be overwritten by
-- the contents of the rosetta.cfg file(see below).
package Rosetta_Config is new Config_File_Parser (
Keys => Keys,
Defaults_Array => Defaults_Array,
Defaults => Defaults_Conf,
Config_File => "rosetta.cfg");
-- Instantiate the Config configuration object.
end Config;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . I M G _ D E C --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-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. --
-- --
------------------------------------------------------------------------------
-- Image for decimal fixed types where the size of the corresponding integer
-- type does not exceed Integer'Size (also used for Text_IO.Decimal_IO output)
package System.Img_Dec is
pragma Pure;
procedure Image_Decimal
(V : Integer;
S : in out String;
P : out Natural;
Scale : Integer);
-- Computes fixed_type'Image (V), where V is the integer value (in units of
-- delta) of a decimal type whose Scale is as given and stores the result
-- S (1 .. P), updating P to the value of L. The image is given by the
-- rules in RM 3.5(34) for fixed-point type image functions. The caller
-- guarantees that S is long enough to hold the result. S need not have a
-- lower bound of 1.
procedure Set_Image_Decimal
(V : Integer;
S : in out String;
P : in out Natural;
Scale : Integer;
Fore : Natural;
Aft : Natural;
Exp : Natural);
-- Sets the image of V, where V is the integer value (in units of delta)
-- of a decimal type with the given Scale, starting at S (P + 1), updating
-- P to point to the last character stored, the caller promises that the
-- buffer is large enough and no check is made for this. Constraint_Error
-- will not necessarily be raised if this requirement is violated, since
-- it is perfectly valid to compile this unit with checks off. The Fore,
-- Aft and Exp values can be set to any valid values for the case of use
-- by Text_IO.Decimal_IO. Note that there is no leading space stored.
procedure Set_Decimal_Digits
(Digs : in out String;
NDigs : Natural;
S : out String;
P : in out Natural;
Scale : Integer;
Fore : Natural;
Aft : Natural;
Exp : Natural);
-- This procedure has the same semantics as Set_Image_Decimal, except that
-- the value in Digs (1 .. NDigs) is given as a string of decimal digits
-- preceded by either a minus sign or a space (i.e. the integer image of
-- the value in units of delta). The call may destroy the value in Digs,
-- which is why Digs is in-out (this happens if rounding is required).
-- Set_Decimal_Digits is shared by all the decimal image routines.
end System.Img_Dec;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- ADA.STRINGS.TEXT_BUFFERS.BOUNDED --
-- --
-- S p e c --
-- --
-- Copyright (C) 2020-2021, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. In accordance with the copyright of that document, you can freely --
-- copy and modify this specification, provided that if you redistribute a --
-- modified version, any changes that you have made are clearly indicated. --
-- --
------------------------------------------------------------------------------
package Ada.Strings.Text_Buffers.Bounded with
Pure
is
type Buffer_Type (Max_Characters : Text_Buffer_Count) is
new Root_Buffer_Type with private with
Default_Initial_Condition => not Text_Truncated (Buffer_Type);
function Text_Truncated (Buffer : Buffer_Type) return Boolean;
function Get (Buffer : in out Buffer_Type) return String with
Post'Class => Get'Result'First = 1 and then Current_Indent (Buffer) = 0;
function Wide_Get (Buffer : in out Buffer_Type) return Wide_String with
Post'Class => Wide_Get'Result'First = 1
and then Current_Indent (Buffer) = 0;
function Wide_Wide_Get
(Buffer : in out Buffer_Type) return Wide_Wide_String with
Post'Class => Wide_Wide_Get'Result'First = 1
and then Current_Indent (Buffer) = 0;
function Get_UTF_8
(Buffer : in out Buffer_Type) return UTF_Encoding.UTF_8_String with
Post'Class => Get_UTF_8'Result'First = 1
and then Current_Indent (Buffer) = 0;
function Wide_Get_UTF_16
(Buffer : in out Buffer_Type) return UTF_Encoding.UTF_16_Wide_String with
Post'Class => Wide_Get_UTF_16'Result'First = 1
and then Current_Indent (Buffer) = 0;
private
procedure Put_UTF_8_Implementation
(Buffer : in out Root_Buffer_Type'Class;
Item : UTF_Encoding.UTF_8_String)
with Pre => Buffer in Buffer_Type'Class;
package Mapping is new Output_Mapping (Put_UTF_8_Implementation);
subtype Positive_Text_Buffer_Count is
Text_Buffer_Count range 1 .. Text_Buffer_Count'Last;
type Convertible_To_UTF_8_String is
array (Positive_Text_Buffer_Count range <>) of Character;
type Buffer_Type (Max_Characters : Text_Buffer_Count)
is new Mapping.Buffer_Type with record
Truncated : Boolean := False;
-- True if we ran out of space on a Put
Chars : Convertible_To_UTF_8_String (1 .. Max_Characters);
end record;
end Ada.Strings.Text_Buffers.Bounded;
|
with GNAT.OS_Lib;
with FSmaker.Source;
with FSmaker.Sink;
package FSmaker.Target is
type Filesystem is interface;
type Any_Filesystem_Ref is access all Filesystem'Class;
procedure Format (This : in out Filesystem;
FD : GNAT.OS_Lib.File_Descriptor;
Size : Natural)
is abstract;
procedure Mount (This : in out Filesystem;
FD : GNAT.OS_Lib.File_Descriptor)
is abstract;
procedure Make_Dir (This : in out Filesystem;
Path : Target_Path)
is abstract;
function Tree (This : in out Filesystem;
Path : Target_Path)
return Directory_Tree
is abstract;
procedure Import (This : in out Filesystem;
Path : Target_Path;
Src : in out Source.Instance)
is abstract;
procedure Cat (This : in out Filesystem;
Path : Target_Path;
Dst : in out FSmaker.Sink.Class)
is abstract;
end FSmaker.Target;
|
with BitOperations.Types;
with BitOperations.Shift;
with BitOperations.Mask;
generic
with package Types is new BitOperations.Types (<>);
package BitOperations.Extract with
SPARK_Mode, Pure, Preelaborate is
package Shift is new BitOperations.Shift(Types);
package Mask is new BitOperations.Mask(Types);
use Types;
function Extract (Value : Modular; From, To : Bit_Position) return Modular
with Pre => To >= From,
Post => Extract'Result =
(Shift.Logic_Right(Value, From) and Mask.Make(To - From + 1))
and then Extract'Result <= 2 ** (To - From + 1) - 1;
end BitOperations.Extract;
|
package body Prime_Numbers is
-- auxiliary (internal) functions
function First_Factor (N : Number; Start : Number) return Number is
K : Number := Start;
begin
while ((N mod K) /= Zero) and then (N > (K*K)) loop
K := K + One;
end loop;
if (N mod K) = Zero then
return K;
else
return N;
end if;
end First_Factor;
function Decompose (N : Number; Start : Number) return Number_List is
F: Number := First_Factor(N, Start);
M: Number := N / F;
begin
if M = One then -- F is the last factor
return (1 => F);
else
return F & Decompose(M, Start);
end if;
end Decompose;
-- functions visible from the outside
function Decompose (N : Number) return Number_List is (Decompose(N, Two));
function Is_Prime (N : Number) return Boolean is
(N > One and then First_Factor(N, Two)=N);
end Prime_Numbers;
|
generic
type Real is digits <>;
type Index is range <>;
type A_Matrix is array(Index, Index) of Real;
package Givens_QR_Method is
subtype C_Index is Index;
subtype R_Index is Index;
function Identity return A_Matrix;
-- Input matrix A (in Upper Hessenberg form) and also matrix Q.
--
-- The original A was transformed by:
--
-- A_original = Q * A * Q_transpose where A is hessenberg.
--
-- (i.e., want eventually: Q_transpose * A_original * Q = A = A_diagonal, so
-- that the column vectors of Q (called Z in Peters_Eigen) are eigvecs of A.)
--
-- Let G be a Givens rotation matrix. (Actually it will be a series of them.)
--
-- We develop the decomposition further by inserting G_transpose * G and
-- its transpose on both sides of A in Q * A * Q_transpose:
--
-- (Q_transpose * G_transpose) * (G * A * G_transpose) * (G * Q)
--
-- = Q_new_transpose * A_new * Q_new
--
-- So to develop A we find
--
-- A := G * A * G_transpose
--
-- And to develop Q we find
--
-- Q := G * Q
--
-- (With shift "s", shift A first: B = A - s * I;
-- Use QR to calculate G*R where R is upper triangular:
--
-- G * R = B
-- R * G = G' * B * G
-- R * G + s * I = G' * A * G
--
-- So the matrix returned as the new A is R*G + s*I.)
-- works only for Upper Hessenberg matrices A:
procedure Lower_Diagonal_QR_Iteration
(A : in out A_Matrix;
Q : in out A_Matrix;
Shift : in Real;
Starting_Col : in C_Index := C_Index'First;
Final_Col : in C_Index := C_Index'Last);
end Givens_QR_Method;
|
-- Copyright (c) 2017 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with League.Holders;
with League.JSON.Arrays;
with League.JSON.Streams;
with League.JSON.Values;
package body LSP.Messages is
function "+" (Text : Wide_Wide_String)
return League.Strings.Universal_String renames
League.Strings.To_Universal_String;
procedure Read_IRI
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : out LSP.Messages.DocumentUri);
procedure Read_Optional_Boolean
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : out LSP.Types.Optional_Boolean);
procedure Read_Optional_Number
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : out LSP.Types.Optional_Number);
procedure Read_Number
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : out LSP.Types.LSP_Number);
procedure Write_Response_Prexif
(S : access Ada.Streams.Root_Stream_Type'Class;
V : LSP.Messages.ResponseMessage'Class);
procedure Write_Request_Prexif
(S : access Ada.Streams.Root_Stream_Type'Class;
V : LSP.Messages.RequestMessage'Class);
procedure Write_Number
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.LSP_Number);
procedure Write_Optional_Boolean
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.Optional_Boolean);
procedure Write_Optional_Number
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.Optional_Number);
procedure Write_String
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.LSP_String);
procedure Write_Optional_String
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.Optional_String);
procedure Write_String_Vector
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.LSP_String_Vector);
use type League.Holders.Universal_Integer;
Error_Map : constant array (ErrorCodes) of League.Holders.Universal_Integer
:=
(ParseError => -32700,
InvalidRequest => -32600,
MethodNotFound => -32601,
InvalidParams => -32602,
InternalError => -32603,
serverErrorStart => -32099,
serverErrorEnd => -32000,
ServerNotInitialized => -32002,
UnknownErrorCode => -32001,
RequestCancelled => -32800);
----------
-- Read --
----------
not overriding procedure Read_completion
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out completion)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Read_Optional_Boolean
(JS, +"dynamicRegistration", V.dynamicRegistration);
Read_Optional_Boolean (JS, +"snippetSupport", V.snippetSupport);
JS.End_Object;
end Read_completion;
---------------------
-- Read_Diagnostic --
---------------------
not overriding procedure Read_Diagnostic
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out Diagnostic)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"range");
Span'Read (S, V.span);
JS.Key (+"severity");
Optional_DiagnosticSeverity'Read (S, V.severity);
LSP.Types.Read_Number_Or_String (JS, +"code", V.code);
Read_Optional_String (JS, +"source", V.source);
Read_String (JS, +"message", V.message);
JS.End_Object;
end Read_Diagnostic;
----------------------------
-- Read_Diagnostic_Vector --
----------------------------
not overriding procedure Read_Diagnostic_Vector
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out Diagnostic_Vector)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
V.Clear;
JS.Start_Array;
while not JS.End_Of_Array loop
declare
Item : Diagnostic;
begin
Diagnostic'Read (S, Item);
V.Append (Item);
end;
end loop;
JS.End_Array;
end Read_Diagnostic_Vector;
-----------------------------
-- Read_ClientCapabilities --
-----------------------------
not overriding procedure Read_ClientCapabilities
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out ClientCapabilities)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"workspace");
WorkspaceClientCapabilities'Read (S, V.workspace);
JS.Key (+"textDocument");
TextDocumentClientCapabilities'Read (S, V.textDocument);
JS.End_Object;
end Read_ClientCapabilities;
----------------------------
-- Read_CodeActionContext --
----------------------------
not overriding procedure Read_CodeActionContext
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out CodeActionContext)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"diagnostics");
Diagnostic_Vector'Read (S, V.diagnostics);
JS.End_Object;
end Read_CodeActionContext;
---------------------------
-- Read_CodeActionParams --
---------------------------
not overriding procedure Read_CodeActionParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out CodeActionParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"textDocument");
TextDocumentIdentifier'Read (S, V.textDocument);
JS.Key (+"range");
Span'Read (S, V.span);
JS.Key (+"context");
CodeActionContext'Read (S, V.context);
JS.End_Object;
end Read_CodeActionParams;
----------------------
-- Write_Diagnostic --
----------------------
not overriding procedure Write_Diagnostic
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Diagnostic)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"range");
Span'Write (S, V.span);
JS.Key (+"severity");
Optional_DiagnosticSeverity'Write (S, V.severity);
if V.code.Is_Number then
Write_Number (JS, +"code", V.code.Number);
elsif not V.code.String.Is_Empty then
Write_String (JS, +"code", V.code.String);
end if;
Write_Optional_String (JS, +"source", V.source);
Write_String (JS, +"message", V.message);
JS.End_Object;
end Write_Diagnostic;
-----------------------------
-- Write_Diagnostic_Vector --
-----------------------------
not overriding procedure Write_Diagnostic_Vector
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Diagnostic_Vector)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Array;
for Item of V loop
Diagnostic'Write (S, Item);
end loop;
JS.End_Array;
end Write_Diagnostic_Vector;
---------------------------------------
-- Read_DidChangeConfigurationParams --
---------------------------------------
not overriding procedure Read_DidChangeConfigurationParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out DidChangeConfigurationParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"settings");
V.settings := JS.Read;
JS.End_Object;
end Read_DidChangeConfigurationParams;
--------------------------------------
-- Read_DidChangeTextDocumentParams --
--------------------------------------
not overriding procedure Read_DidChangeTextDocumentParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out DidChangeTextDocumentParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"textDocument");
VersionedTextDocumentIdentifier'Read (S, V.textDocument);
JS.Key (+"contentChanges");
TextDocumentContentChangeEvent_Vector'Read (S, V.contentChanges);
JS.End_Object;
end Read_DidChangeTextDocumentParams;
-------------------------------------
-- Read_DidCloseTextDocumentParams --
-------------------------------------
not overriding procedure Read_DidCloseTextDocumentParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out DidCloseTextDocumentParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"textDocument");
TextDocumentIdentifier'Read (S, V.textDocument);
JS.End_Object;
end Read_DidCloseTextDocumentParams;
------------------------------------
-- Read_DidOpenTextDocumentParams --
------------------------------------
not overriding procedure Read_DidOpenTextDocumentParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out DidOpenTextDocumentParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"textDocument");
TextDocumentItem'Read (S, V.textDocument);
JS.End_Object;
end Read_DidOpenTextDocumentParams;
------------------------------------
-- Read_DidSaveTextDocumentParams --
------------------------------------
not overriding procedure Read_DidSaveTextDocumentParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out DidSaveTextDocumentParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"textDocument");
TextDocumentIdentifier'Read (S, V.textDocument);
Read_Optional_String (JS, +"text", V.text);
JS.End_Object;
end Read_DidSaveTextDocumentParams;
-------------------------------
-- Read_DocumentSymbolParams --
-------------------------------
not overriding procedure Read_DocumentSymbolParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out DocumentSymbolParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"textDocument");
TextDocumentIdentifier'Read (S, V.textDocument);
JS.End_Object;
end Read_DocumentSymbolParams;
---------------------------
-- Read_TextDocumentEdit --
---------------------------
not overriding procedure Read_TextDocumentEdit
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out TextDocumentEdit)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"textDocument");
VersionedTextDocumentIdentifier'Read (S, V.textDocument);
JS.Key (+"edits");
TextEdit_Vector'Read (S, V.edits);
JS.End_Object;
end Read_TextDocumentEdit;
---------------------------------
-- Read_TextDocumentIdentifier --
---------------------------------
not overriding procedure Read_TextDocumentIdentifier
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out TextDocumentIdentifier)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"uri");
DocumentUri'Read (S, V.uri);
JS.End_Object;
end Read_TextDocumentIdentifier;
---------------------------
-- Read_TextDocumentItem --
---------------------------
not overriding procedure Read_TextDocumentItem
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out TextDocumentItem)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Read_IRI (JS, +"uri", V.uri);
Read_String (JS, +"languageId", V.languageId);
Read_Number (JS, +"version", LSP.Types.LSP_Number (V.version));
Read_String (JS, +"text", V.text);
JS.End_Object;
end Read_TextDocumentItem;
-------------------------------------
-- Read_TextDocumentPositionParams --
-------------------------------------
not overriding procedure Read_TextDocumentPositionParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out TextDocumentPositionParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"textDocument");
TextDocumentIdentifier'Read (S, V.textDocument);
JS.Key (+"position");
Position'Read (S, V.position);
JS.End_Object;
end Read_TextDocumentPositionParams;
-------------------
-- Read_TextEdit --
-------------------
not overriding procedure Read_TextEdit
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out TextEdit)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"range");
Span'Read (S, V.span);
Read_String (JS, +"newText", V.newText);
JS.End_Object;
end Read_TextEdit;
--------------------------
-- Read_TextEdit_Vector --
--------------------------
not overriding procedure Read_TextEdit_Vector
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out TextEdit_Vector)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Array;
while not JS.End_Of_Array loop
declare
Item : TextEdit;
begin
TextEdit'Read (S, Item);
V.Append (Item);
end;
end loop;
JS.End_Array;
end Read_TextEdit_Vector;
------------------------------
-- Read_dynamicRegistration --
------------------------------
not overriding procedure Read_dynamicRegistration
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out dynamicRegistration)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Read_Optional_Boolean
(JS, +"dynamicRegistration", Optional_Boolean (V));
JS.End_Object;
end Read_dynamicRegistration;
-------------------------------
-- Read_ExecuteCommandParams --
-------------------------------
not overriding procedure Read_ExecuteCommandParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out ExecuteCommandParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Read_String (JS, +"command", V.command);
JS.Key (+"arguments");
V.arguments := JS.Read;
JS.End_Object;
end Read_ExecuteCommandParams;
---------------------------
-- Read_InitializeParams --
---------------------------
procedure Read_InitializeParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out InitializeParams)
is
use type League.Strings.Universal_String;
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
Trace : LSP.Types.Optional_String;
begin
JS.Start_Object;
Read_Optional_Number (JS, +"processId", V.processId);
Read_String (JS, +"rootPath", V.rootPath);
Read_IRI (JS, +"rootUri", V.rootUri);
JS.Key (+"capabilities");
LSP.Messages.ClientCapabilities'Read (S, V.capabilities);
Read_Optional_String (JS, +"trace", Trace);
if not Trace.Is_Set then
V.trace := LSP.Types.Unspecified;
elsif Trace.Value = +"off" then
V.trace := LSP.Types.Off;
elsif Trace.Value = +"messages" then
V.trace := LSP.Types.Messages;
elsif Trace.Value = +"verbose" then
V.trace := LSP.Types.Verbose;
end if;
JS.End_Object;
end Read_InitializeParams;
--------------------------
-- Read_synchronization --
--------------------------
not overriding procedure Read_synchronization
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out synchronization)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Read_Optional_Boolean
(JS, +"dynamicRegistration", V.dynamicRegistration);
Read_Optional_Boolean (JS, +"willSave", V.willSave);
Read_Optional_Boolean (JS, +"willSaveWaitUntil", V.willSaveWaitUntil);
Read_Optional_Boolean (JS, +"didSave", V.didSave);
JS.End_Object;
end Read_synchronization;
-----------------------------------------
-- Read_TextDocumentClientCapabilities --
-----------------------------------------
not overriding procedure Read_TextDocumentClientCapabilities
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out TextDocumentClientCapabilities)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"synchronization");
synchronization'Read (S, V.synchronization);
JS.Key (+"completion");
completion'Read (S, V.completion);
JS.Key (+"hover");
dynamicRegistration'Read (S, V.hover);
JS.Key (+"signatureHelp");
dynamicRegistration'Read (S, V.signatureHelp);
JS.Key (+"references");
dynamicRegistration'Read (S, V.references);
JS.Key (+"documentHighlight");
dynamicRegistration'Read (S, V.documentHighlight);
JS.Key (+"documentSymbol");
dynamicRegistration'Read (S, V.documentSymbol);
JS.Key (+"formatting");
dynamicRegistration'Read (S, V.formatting);
JS.Key (+"rangeFormatting");
dynamicRegistration'Read (S, V.rangeFormatting);
JS.Key (+"onTypeFormatting");
dynamicRegistration'Read (S, V.onTypeFormatting);
JS.Key (+"definition");
dynamicRegistration'Read (S, V.definition);
JS.Key (+"codeAction");
dynamicRegistration'Read (S, V.codeAction);
JS.Key (+"codeLens");
dynamicRegistration'Read (S, V.codeLens);
JS.Key (+"documentLink");
dynamicRegistration'Read (S, V.documentLink);
JS.Key (+"rename");
dynamicRegistration'Read (S, V.rename);
JS.End_Object;
end Read_TextDocumentClientCapabilities;
-----------------------------------------
-- Read_TextDocumentContentChangeEvent --
-----------------------------------------
not overriding procedure Read_TextDocumentContentChangeEvent
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out TextDocumentContentChangeEvent)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"range");
Optional_Span'Read (S, V.span);
Read_Optional_Number (JS, +"rangeLength", V.rangeLength);
Read_String (JS, +"text", V.text);
JS.End_Object;
end Read_TextDocumentContentChangeEvent;
------------------------------------------------
-- Read_TextDocumentContentChangeEvent_Vector --
------------------------------------------------
not overriding procedure Read_TextDocumentContentChangeEvent_Vector
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out TextDocumentContentChangeEvent_Vector)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
V.Clear;
JS.Start_Array;
while not JS.End_Of_Array loop
declare
Item : TextDocumentContentChangeEvent;
begin
TextDocumentContentChangeEvent'Read (S, Item);
V.Append (Item);
end;
end loop;
JS.End_Array;
end Read_TextDocumentContentChangeEvent_Vector;
------------------------------------------
-- Read_VersionedTextDocumentIdentifier --
------------------------------------------
not overriding procedure Read_VersionedTextDocumentIdentifier
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out VersionedTextDocumentIdentifier)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"uri");
DocumentUri'Read (S, V.uri);
Read_Number (JS, +"version", LSP_Number (V.version));
JS.End_Object;
end Read_VersionedTextDocumentIdentifier;
--------------------------------------
-- Read_WorkspaceClientCapabilities --
--------------------------------------
not overriding procedure Read_WorkspaceClientCapabilities
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out WorkspaceClientCapabilities)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Read_Optional_Boolean (JS, +"applyEdit", V.applyEdit);
Read_Optional_Boolean (JS, +"workspaceEdit", V.workspaceEdit);
JS.Key (+"didChangeConfiguration");
dynamicRegistration'Read (S, V.didChangeConfiguration);
JS.Key (+"didChangeWatchedFiles");
dynamicRegistration'Read (S, V.didChangeWatchedFiles);
JS.Key (+"symbol");
dynamicRegistration'Read (S, V.symbol);
JS.Key (+"executeCommand");
dynamicRegistration'Read (S, V.executeCommand);
JS.End_Object;
end Read_WorkspaceClientCapabilities;
--------------
-- Read_IRI --
--------------
procedure Read_IRI
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : out LSP.Messages.DocumentUri)
is
Value : League.JSON.Values.JSON_Value;
begin
Stream.Key (Key);
Value := Stream.Read;
if Value.Is_Null then
Item.Clear;
else
-- Item := League.IRIs.From_Universal_String (Stream.Read.To_String);
Item := Stream.Read.To_String;
end if;
end Read_IRI;
-----------------
-- Read_Number --
-----------------
procedure Read_Number
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : out LSP.Types.LSP_Number) is
begin
Stream.Key (Key);
Item := LSP.Types.LSP_Number (Stream.Read.To_Integer);
end Read_Number;
---------------------------
-- Read_Optional_Boolean --
---------------------------
procedure Read_Optional_Boolean
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : out LSP.Types.Optional_Boolean)
is
Value : League.JSON.Values.JSON_Value;
begin
Stream.Key (Key);
Value := Stream.Read;
if Value.Is_Null then
Item := (Is_Set => False);
else
Item := (Is_Set => True, Value => Value.To_Boolean);
end if;
end Read_Optional_Boolean;
--------------------------
-- Read_Optional_Number --
--------------------------
procedure Read_Optional_Number
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : out LSP.Types.Optional_Number)
is
Value : League.JSON.Values.JSON_Value;
begin
Stream.Key (Key);
Value := Stream.Read;
if Value.Is_Null then
Item := (Is_Set => False);
else
Item := (Is_Set => True, Value => Integer (Value.To_Integer));
end if;
end Read_Optional_Number;
-------------------
-- Read_Position --
-------------------
not overriding procedure Read_Position
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out Position)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Read_Number (JS, +"line", LSP_Number (V.line));
Read_Number (JS, +"character", LSP_Number (V.character));
JS.End_Object;
end Read_Position;
---------------------------
-- Read_ReferenceContext --
---------------------------
not overriding procedure Read_ReferenceContext
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out ReferenceContext)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"includeDeclaration");
V.includeDeclaration := JS.Read.To_Boolean;
JS.End_Object;
end Read_ReferenceContext;
--------------------------
-- Read_ReferenceParams --
--------------------------
not overriding procedure Read_ReferenceParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out ReferenceParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"textDocument");
TextDocumentIdentifier'Read (S, V.textDocument);
JS.Key (+"position");
Position'Read (S, V.position);
JS.Key (+"context");
ReferenceContext'Read (S, V.context);
JS.End_Object;
end Read_ReferenceParams;
------------------------
-- Read_ResponseError --
------------------------
not overriding procedure Read_ResponseError
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out ResponseError)
is
Code : League.Holders.Universal_Integer;
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"code");
Code := JS.Read.To_Integer;
for J in Error_Map'Range loop
if Error_Map (J) = Code then
V.code := J;
exit;
end if;
end loop;
Read_String (JS, +"message", V.message);
JS.Key (+"data");
V.data := JS.Read;
JS.End_Object;
end Read_ResponseError;
---------------
-- Read_Span --
---------------
not overriding procedure Read_Span
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out Span)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"start");
Position'Read (S, V.first);
JS.Key (+"end");
Position'Read (S, V.last);
JS.End_Object;
end Read_Span;
--------------------------------
-- Read_WorkspaceSymbolParams --
--------------------------------
not overriding procedure Read_WorkspaceSymbolParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : out WorkspaceSymbolParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Read_String (JS, +"query", V.query);
JS.End_Object;
end Read_WorkspaceSymbolParams;
---------------------------
-- Write_CodeLensOptions --
---------------------------
not overriding procedure Write_CodeLensOptions
(S : access Ada.Streams.Root_Stream_Type'Class;
V : CodeLensOptions)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Optional_Boolean (JS, +"resolveProvider", V.resolveProvider);
JS.End_Object;
end Write_CodeLensOptions;
-------------------
-- Write_Command --
-------------------
not overriding procedure Write_Command
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Command)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
if V.command.Is_Empty then
return;
end if;
JS.Start_Object;
Write_String (JS, +"title", V.title);
Write_String (JS, +"command", V.command);
if not V.arguments.Is_Empty then
JS.Key (+"arguments");
JS.Write (V.arguments);
end if;
JS.End_Object;
end Write_Command;
--------------------------------------
-- Write_ApplyWorkspaceEdit_Request --
--------------------------------------
not overriding procedure Write_ApplyWorkspaceEdit_Request
(S : access Ada.Streams.Root_Stream_Type'Class;
V : ApplyWorkspaceEdit_Request)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Request_Prexif (S, V);
Write_String (JS, +"method", V.method);
JS.Key (+"params");
ApplyWorkspaceEditParams'Write (S, V.params);
JS.End_Object;
end Write_ApplyWorkspaceEdit_Request;
------------------------------------
-- Write_ApplyWorkspaceEditParams --
------------------------------------
not overriding procedure Write_ApplyWorkspaceEditParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : ApplyWorkspaceEditParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"edit");
WorkspaceEdit'Write (S, V.edit);
JS.End_Object;
end Write_ApplyWorkspaceEditParams;
-------------------------------
-- Write_CodeAction_Response --
-------------------------------
not overriding procedure Write_CodeAction_Response
(S : access Ada.Streams.Root_Stream_Type'Class;
V : CodeAction_Response)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Response_Prexif (S, V);
JS.Key (+"result");
if V.result.Is_Empty then
JS.Write (League.JSON.Arrays.Empty_JSON_Array.To_JSON_Value);
else
Command_Vector'Write (S, V.result);
end if;
JS.End_Object;
end Write_CodeAction_Response;
--------------------------
-- Write_Command_Vector --
--------------------------
not overriding procedure Write_Command_Vector
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Command_Vector)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Array;
for Item of V loop
Command'Write (S, Item);
end loop;
JS.End_Array;
end Write_Command_Vector;
-------------------------------
-- Write_Completion_Response --
-------------------------------
not overriding procedure Write_Completion_Response
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Completion_Response)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Response_Prexif (S, V);
JS.Key (+"result");
CompletionList'Write (S, V.result);
JS.End_Object;
end Write_Completion_Response;
--------------------------
-- Write_CompletionItem --
--------------------------
not overriding procedure Write_CompletionItem
(S : access Ada.Streams.Root_Stream_Type'Class;
V : CompletionItem)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_String (JS, +"label", V.label);
JS.Key (+"kind");
Optional_CompletionItemKind'Write (S, V.kind);
Write_Optional_String (JS, +"detail", V.detail);
Write_Optional_String (JS, +"documentation", V.documentation);
Write_Optional_String (JS, +"sortText", V.sortText);
Write_Optional_String (JS, +"filterText", V.filterText);
Write_Optional_String (JS, +"insertText", V.insertText);
JS.Key (+"insertTextFormat");
Optional_InsertTextFormat'Write (S, V.insertTextFormat);
JS.Key (+"textEdit");
Optional_TextEdit'Write (S, V.textEdit);
JS.Key (+"additionalTextEdits");
TextEdit_Vector'Write (S, V.additionalTextEdits);
if not V.commitCharacters.Is_Empty then
Write_String_Vector (JS, +"commitCharacters", V.commitCharacters);
end if;
JS.Key (+"command");
Command'Write (S, V.command);
JS.End_Object;
end Write_CompletionItem;
------------------------------
-- Write_CompletionItemKind --
------------------------------
not overriding procedure Write_CompletionItemKind
(S : access Ada.Streams.Root_Stream_Type'Class;
V : CompletionItemKind)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Write
(League.JSON.Values.To_JSON_Value
(League.Holders.Universal_Integer
(CompletionItemKind'Pos (V)) + 1));
end Write_CompletionItemKind;
--------------------------
-- Write_CompletionList --
--------------------------
not overriding procedure Write_CompletionList
(S : access Ada.Streams.Root_Stream_Type'Class;
V : CompletionList)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Optional_Boolean (JS, +"isIncomplete", (True, V.isIncomplete));
JS.Key (+"items");
JS.Start_Array;
for Item of V.items loop
CompletionItem'Write (S, Item);
end loop;
JS.End_Array;
JS.End_Object;
end Write_CompletionList;
-----------------------------
-- Write_CompletionOptions --
-----------------------------
not overriding procedure Write_CompletionOptions
(S : access Ada.Streams.Root_Stream_Type'Class;
V : CompletionOptions)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Optional_Boolean (JS, +"resolveProvider", V.resolveProvider);
Write_String_Vector (JS, +"triggerCharacters", V.triggerCharacters);
JS.End_Object;
end Write_CompletionOptions;
------------------------------
-- Write_DiagnosticSeverity --
------------------------------
not overriding procedure Write_DiagnosticSeverity
(S : access Ada.Streams.Root_Stream_Type'Class;
V : DiagnosticSeverity)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Write
(League.JSON.Values.To_JSON_Value
(League.Holders.Universal_Integer
(DiagnosticSeverity'Pos (V)) + 1));
end Write_DiagnosticSeverity;
-----------------------------
-- Write_DocumentHighlight --
-----------------------------
not overriding procedure Write_DocumentHighlight
(S : access Ada.Streams.Root_Stream_Type'Class;
V : DocumentHighlight)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"range");
Span'Write (S, V.span);
JS.Key (+"kind");
JS.Write
(League.JSON.Values.To_JSON_Value
(League.Holders.Universal_Integer
(DocumentHighlightKind'Pos (V.kind)) + 1));
JS.End_Object;
end Write_DocumentHighlight;
-------------------------------
-- Write_DocumentLinkOptions --
-------------------------------
not overriding procedure Write_DocumentLinkOptions
(S : access Ada.Streams.Root_Stream_Type'Class;
V : DocumentLinkOptions)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Optional_Boolean (JS, +"resolveProvider", V.resolveProvider);
JS.End_Object;
end Write_DocumentLinkOptions;
-------------------------------------------
-- Write_DocumentOnTypeFormattingOptions --
-------------------------------------------
not overriding procedure Write_DocumentOnTypeFormattingOptions
(S : access Ada.Streams.Root_Stream_Type'Class;
V : DocumentOnTypeFormattingOptions)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_String (JS, +"firstTriggerCharacter", V.firstTriggerCharacter);
Write_String_Vector
(JS, +"moreTriggerCharacter", V.moreTriggerCharacter);
JS.End_Object;
end Write_DocumentOnTypeFormattingOptions;
-----------------------------------
-- Write_ExecuteCommand_Response --
-----------------------------------
not overriding procedure Write_ExecuteCommand_Response
(S : access Ada.Streams.Root_Stream_Type'Class;
V : ExecuteCommand_Response)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Response_Prexif (S, V);
JS.Key (+"result");
JS.Write (League.JSON.Values.Null_JSON_Value);
JS.End_Object;
end Write_ExecuteCommand_Response;
---------------------------------
-- Write_ExecuteCommandOptions --
---------------------------------
not overriding procedure Write_ExecuteCommandOptions
(S : access Ada.Streams.Root_Stream_Type'Class;
V : ExecuteCommandOptions)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_String_Vector (JS, +"commands", V.commands);
JS.End_Object;
end Write_ExecuteCommandOptions;
------------------------------
-- Write_Highlight_Response --
------------------------------
not overriding procedure Write_Highlight_Response
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Highlight_Response)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Response_Prexif (S, V);
JS.Key (+"result");
if V.result.Is_Empty then
JS.Write (League.JSON.Arrays.Empty_JSON_Array.To_JSON_Value);
else
JS.Start_Array;
for Item of V.result loop
DocumentHighlight'Write (S, Item);
end loop;
JS.End_Array;
end if;
JS.End_Object;
end Write_Highlight_Response;
-----------------
-- Write_Hover --
-----------------
not overriding procedure Write_Hover
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Hover)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"contents");
if V.contents.Is_Empty then
JS.Write (League.JSON.Arrays.Empty_JSON_Array.To_JSON_Value);
else
JS.Start_Array;
for Item of V.contents loop
MarkedString'Write (S, Item);
end loop;
JS.End_Array;
end if;
JS.Key (+"range");
Optional_Span'Write (S, V.Span);
JS.End_Object;
end Write_Hover;
--------------------------
-- Write_Hover_Response --
--------------------------
not overriding procedure Write_Hover_Response
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Hover_Response)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Response_Prexif (S, V);
JS.Key (+"result");
Hover'Write (S, V.result);
JS.End_Object;
end Write_Hover_Response;
-------------------------------
-- Write_Initialize_Response --
-------------------------------
not overriding procedure Write_Initialize_Response
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Initialize_Response)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Response_Prexif (S, V);
JS.Key (+"result");
InitializeResult'Write (S, V.result);
JS.End_Object;
end Write_Initialize_Response;
----------------------------
-- Write_InitializeResult --
----------------------------
not overriding procedure Write_InitializeResult
(S : access Ada.Streams.Root_Stream_Type'Class;
V : InitializeResult)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"capabilities");
ServerCapabilities'Write (S, V.capabilities);
JS.End_Object;
end Write_InitializeResult;
----------------------------
-- Write_InsertTextFormat --
----------------------------
not overriding procedure Write_InsertTextFormat
(S : access Ada.Streams.Root_Stream_Type'Class;
V : InsertTextFormat)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Write
(League.JSON.Values.To_JSON_Value
(League.Holders.Universal_Integer
(InsertTextFormat'Pos (V)) + 1));
end Write_InsertTextFormat;
--------------------
-- Write_Location --
--------------------
not overriding procedure Write_Location
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Location)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"uri");
DocumentUri'Write (S, V.uri);
JS.Key (+"range");
Span'Write (S, V.span);
JS.End_Object;
end Write_Location;
-----------------------------
-- Write_Location_Response --
-----------------------------
not overriding procedure Write_Location_Response
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Location_Response)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Response_Prexif (S, V);
JS.Key (+"result");
if V.result.Is_Empty then
JS.Write (League.JSON.Arrays.Empty_JSON_Array.To_JSON_Value);
else
JS.Start_Array;
for Item of V.result loop
Location'Write (S, Item);
end loop;
JS.End_Array;
end if;
JS.End_Object;
end Write_Location_Response;
------------------------
-- Write_MarkedString --
------------------------
not overriding procedure Write_MarkedString
(S : access Ada.Streams.Root_Stream_Type'Class;
V : MarkedString)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
if V.Is_String then
JS.Write (League.JSON.Values.To_JSON_Value (V.value));
else
JS.Start_Object;
Write_String (JS, +"language", V.language);
Write_String (JS, +"value", V.value);
JS.End_Object;
end if;
end Write_MarkedString;
------------------
-- Write_Number --
------------------
procedure Write_Number
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.LSP_Number) is
begin
Stream.Key (Key);
Stream.Write
(League.JSON.Values.To_JSON_Value
(League.Holders.Universal_Integer (Item)));
end Write_Number;
----------------------------
-- Write_Optional_Boolean --
----------------------------
procedure Write_Optional_Boolean
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.Optional_Boolean) is
begin
if Item.Is_Set then
Stream.Key (Key);
Stream.Write (League.JSON.Values.To_JSON_Value (Item.Value));
end if;
end Write_Optional_Boolean;
---------------------------
-- Write_Optional_Number --
---------------------------
procedure Write_Optional_Number
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.Optional_Number) is
begin
if Item.Is_Set then
Write_Number (Stream, Key, Item.Value);
end if;
end Write_Optional_Number;
---------------------------
-- Write_Optional_String --
---------------------------
procedure Write_Optional_String
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.Optional_String) is
begin
if Item.Is_Set then
Write_String (Stream, Key, Item.Value);
end if;
end Write_Optional_String;
--------------------------------------------
-- Write_Optional_TextDocumentSyncOptions --
--------------------------------------------
not overriding procedure Write_Optional_TextDocumentSyncOptions
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Optional_TextDocumentSyncOptions) is
begin
if not V.Is_Set then
return;
elsif V.Is_Number then
TextDocumentSyncKind'Write (S, V.Value);
else
TextDocumentSyncOptions'Write (S, V.Options);
end if;
end Write_Optional_TextDocumentSyncOptions;
--------------------------------
-- Write_ParameterInformation --
--------------------------------
not overriding procedure Write_ParameterInformation
(S : access Ada.Streams.Root_Stream_Type'Class;
V : ParameterInformation)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_String (JS, +"label", V.label);
Write_Optional_String (JS, +"documentation", V.documentation);
JS.End_Object;
end Write_ParameterInformation;
--------------------
-- Write_Position --
--------------------
not overriding procedure Write_Position
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Position)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Number (JS, +"line", LSP_Number (V.line));
Write_Number (JS, +"character", LSP_Number (V.character));
JS.End_Object;
end Write_Position;
--------------------------
-- Write_Request_Prexif --
--------------------------
procedure Write_Request_Prexif
(S : access Ada.Streams.Root_Stream_Type'Class;
V : LSP.Messages.RequestMessage'Class)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
Write_String (JS, +"jsonrpc", V.jsonrpc);
if V.id.Is_Number then
Write_Number (JS, +"id", V.id.Number);
elsif not V.id.String.Is_Empty then
Write_String (JS, +"id", V.id.String);
end if;
end Write_Request_Prexif;
--------------------
-- Write_Response --
--------------------
procedure Write_Response_Prexif
(S : access Ada.Streams.Root_Stream_Type'Class;
V : LSP.Messages.ResponseMessage'Class)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
Write_String (JS, +"jsonrpc", V.jsonrpc);
if V.id.Is_Number then
Write_Number (JS, +"id", V.id.Number);
elsif not V.id.String.Is_Empty then
Write_String (JS, +"id", V.id.String);
end if;
JS.Key (+"error");
Optional_ResponseError'Write (S, V.error);
end Write_Response_Prexif;
-------------------------
-- Write_ResponseError --
-------------------------
not overriding procedure Write_ResponseError
(S : access Ada.Streams.Root_Stream_Type'Class;
V : ResponseError)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"code");
JS.Write (League.JSON.Values.To_JSON_Value (Error_Map (V.code)));
Write_String (JS, +"message", V.message);
if not V.data.Is_Empty and not V.data.Is_Empty then
JS.Key (+"data");
JS.Write (V.data);
end if;
JS.End_Object;
end Write_ResponseError;
---------------------------
-- Write_ResponseMessage --
---------------------------
not overriding procedure Write_ResponseMessage
(S : access Ada.Streams.Root_Stream_Type'Class;
V : ResponseMessage)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Response_Prexif (S, V);
JS.End_Object;
end Write_ResponseMessage;
-------------------------------------------
-- Write_PublishDiagnostics_Notification --
-------------------------------------------
not overriding procedure Write_PublishDiagnostics_Notification
(S : access Ada.Streams.Root_Stream_Type'Class;
V : PublishDiagnostics_Notification)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_String (JS, +"jsonrpc", V.jsonrpc);
Write_String (JS, +"method", V.method);
JS.Key (+"params");
PublishDiagnosticsParams'Write (S, V.params);
JS.End_Object;
end Write_PublishDiagnostics_Notification;
------------------------------------
-- Write_PublishDiagnosticsParams --
------------------------------------
not overriding procedure Write_PublishDiagnosticsParams
(S : access Ada.Streams.Root_Stream_Type'Class;
V : PublishDiagnosticsParams)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"uri");
DocumentUri'Write (S, V.uri);
JS.Key (+"diagnostics");
if V.diagnostics.Is_Empty then
JS.Write (League.JSON.Arrays.Empty_JSON_Array.To_JSON_Value);
else
Diagnostic_Vector'Write (S, V.diagnostics);
end if;
JS.End_Object;
end Write_PublishDiagnosticsParams;
------------------------------
-- Write_ServerCapabilities --
------------------------------
not overriding procedure Write_ServerCapabilities
(S : access Ada.Streams.Root_Stream_Type'Class;
V : ServerCapabilities)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"textDocumentSync");
Optional_TextDocumentSyncOptions'Write (S, V.textDocumentSync);
Write_Optional_Boolean (JS, +"hoverProvider", V.hoverProvider);
JS.Key (+"completionProvider");
Optional_CompletionOptions'Write (S, V.completionProvider);
JS.Key (+"signatureHelpProvider");
Optional_SignatureHelpOptions'Write (S, V.signatureHelpProvider);
Write_Optional_Boolean (JS, +"definitionProvider", V.definitionProvider);
Write_Optional_Boolean (JS, +"referencesProvider", V.referencesProvider);
Write_Optional_Boolean
(JS, +"documentHighlightProvider", V.documentHighlightProvider);
Write_Optional_Boolean
(JS, +"documentSymbolProvider", V.documentSymbolProvider);
Write_Optional_Boolean
(JS, +"workspaceSymbolProvider", V.workspaceSymbolProvider);
Write_Optional_Boolean (JS, +"codeActionProvider", V.codeActionProvider);
Write_Optional_Boolean
(JS, +"documentFormattingProvider", V.documentFormattingProvider);
Write_Optional_Boolean
(JS,
+"documentRangeFormattingProvider",
V.documentRangeFormattingProvider);
JS.Key (+"documentOnTypeFormattingProvider");
Optional_DocumentOnTypeFormattingOptions'Write
(S, V.documentOnTypeFormattingProvider);
Write_Optional_Boolean (JS, +"renameProvider", V.renameProvider);
JS.Key (+"documentLinkProvider");
DocumentLinkOptions'Write (S, V.documentLinkProvider);
JS.Key (+"executeCommandProvider");
ExecuteCommandOptions'Write (S, V.executeCommandProvider);
JS.End_Object;
end Write_ServerCapabilities;
-------------------------
-- Write_SignatureHelp --
-------------------------
not overriding procedure Write_SignatureHelp
(S : access Ada.Streams.Root_Stream_Type'Class;
V : SignatureHelp)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"signatures");
if V.signatures.Is_Empty then
JS.Write (League.JSON.Arrays.Empty_JSON_Array.To_JSON_Value);
else
JS.Start_Array;
for Item of V.signatures loop
SignatureInformation'Write (S, Item);
end loop;
JS.End_Array;
end if;
Write_Optional_Number (JS, +"activeSignature", V.activeSignature);
Write_Optional_Number (JS, +"activeParameter", V.activeParameter);
JS.End_Object;
end Write_SignatureHelp;
----------------------------------
-- Write_SignatureHelp_Response --
----------------------------------
not overriding procedure Write_SignatureHelp_Response
(S : access Ada.Streams.Root_Stream_Type'Class;
V : SignatureHelp_Response)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Response_Prexif (S, V);
JS.Key (+"result");
SignatureHelp'Write (S, V.result);
JS.End_Object;
end Write_SignatureHelp_Response;
--------------------------------
-- Write_SignatureHelpOptions --
--------------------------------
not overriding procedure Write_SignatureHelpOptions
(S : access Ada.Streams.Root_Stream_Type'Class;
V : SignatureHelpOptions)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_String_Vector (JS, +"triggerCharacters", V.triggerCharacters);
JS.End_Object;
end Write_SignatureHelpOptions;
--------------------------------
-- Write_SignatureInformation --
--------------------------------
not overriding procedure Write_SignatureInformation
(S : access Ada.Streams.Root_Stream_Type'Class;
V : SignatureInformation)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_String (JS, +"label", V.label);
Write_Optional_String (JS, +"documentation", V.documentation);
JS.Key (+"parameters");
if V.parameters.Is_Empty then
JS.Write (League.JSON.Arrays.Empty_JSON_Array.To_JSON_Value);
else
JS.Start_Array;
for Item of V.parameters loop
ParameterInformation'Write (S, Item);
end loop;
JS.End_Array;
end if;
JS.End_Object;
end Write_SignatureInformation;
----------------
-- Write_Span --
----------------
not overriding procedure Write_Span
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Span)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"start");
Position'Write (S, V.first);
JS.Key (+"end");
Position'Write (S, V.last);
JS.End_Object;
end Write_Span;
------------------
-- Write_String --
------------------
procedure Write_String
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.LSP_String) is
begin
Stream.Key (Key);
Stream.Write (League.JSON.Values.To_JSON_Value (Item));
end Write_String;
-------------------------
-- Write_String_Vector --
-------------------------
procedure Write_String_Vector
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : LSP.Types.LSP_String_Vector) is
begin
Stream.Key (Key);
Stream.Start_Array;
for J in 1 .. Item.Length loop
Stream.Write (League.JSON.Values.To_JSON_Value (Item.Element (J)));
end loop;
Stream.End_Array;
end Write_String_Vector;
---------------------------
-- Write_Symbol_Response --
---------------------------
not overriding procedure Write_Symbol_Response
(S : access Ada.Streams.Root_Stream_Type'Class;
V : Symbol_Response)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Response_Prexif (S, V);
JS.Key (+"result");
SymbolInformation_Vector'Write (S, V.result);
JS.End_Object;
end Write_Symbol_Response;
-----------------------------
-- Write_SymbolInformation --
-----------------------------
not overriding procedure Write_SymbolInformation
(S : access Ada.Streams.Root_Stream_Type'Class;
V : SymbolInformation)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_String (JS, +"name", V.name);
JS.Key (+"kind");
JS.Write
(League.JSON.Values.To_JSON_Value
(League.Holders.Universal_Integer
(SymbolKind'Pos (V.kind)) + 1));
JS.Key (+"location");
Location'Write (S, V.location);
JS.Key (+"edits");
Write_Optional_String (JS, +"containerName", V.containerName);
JS.End_Object;
end Write_SymbolInformation;
------------------------------------
-- Write_SymbolInformation_Vector --
------------------------------------
not overriding procedure Write_SymbolInformation_Vector
(S : access Ada.Streams.Root_Stream_Type'Class;
V : SymbolInformation_Vector)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
if V.Is_Empty then
JS.Write (League.JSON.Arrays.Empty_JSON_Array.To_JSON_Value);
else
JS.Start_Array;
for Item of V loop
SymbolInformation'Write (S, Item);
end loop;
JS.End_Array;
end if;
end Write_SymbolInformation_Vector;
----------------------------
-- Write_TextDocumentEdit --
----------------------------
not overriding procedure Write_TextDocumentEdit
(S : access Ada.Streams.Root_Stream_Type'Class;
V : TextDocumentEdit)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"textDocument");
VersionedTextDocumentIdentifier'Write (S, V.textDocument);
JS.Key (+"edits");
TextEdit_Vector'Write (S, V.edits);
JS.End_Object;
end Write_TextDocumentEdit;
--------------------------------
-- Write_TextDocumentSyncKind --
--------------------------------
not overriding procedure Write_TextDocumentSyncKind
(S : access Ada.Streams.Root_Stream_Type'Class;
V : TextDocumentSyncKind)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
Map : constant array (TextDocumentSyncKind) of
League.Holders.Universal_Integer :=
(None => 0, Full => 1, Incremental => 2);
begin
JS.Write (League.JSON.Values.To_JSON_Value (Map (V)));
end Write_TextDocumentSyncKind;
-----------------------------------
-- Write_TextDocumentSyncOptions --
-----------------------------------
not overriding procedure Write_TextDocumentSyncOptions
(S : access Ada.Streams.Root_Stream_Type'Class;
V : TextDocumentSyncOptions)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
Write_Optional_Boolean (JS, +"openClose", V.openClose);
JS.Key (+"change");
Optional_TextDocumentSyncKind'Write (S, V.change);
Write_Optional_Boolean (JS, +"willSave", V.willSave);
Write_Optional_Boolean (JS, +"willSaveWaitUntil", V.willSaveWaitUntil);
Write_Optional_Boolean (JS, +"save", V.save);
JS.End_Object;
end Write_TextDocumentSyncOptions;
--------------------
-- Write_TextEdit --
--------------------
not overriding procedure Write_TextEdit
(S : access Ada.Streams.Root_Stream_Type'Class;
V : TextEdit)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"range");
Span'Write (S, V.span);
Write_String (JS, +"newText", V.newText);
JS.End_Object;
end Write_TextEdit;
---------------------------
-- Write_TextEdit_Vector --
---------------------------
not overriding procedure Write_TextEdit_Vector
(S : access Ada.Streams.Root_Stream_Type'Class;
V : TextEdit_Vector)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Array;
for Item of V loop
TextEdit'Write (S, Item);
end loop;
JS.End_Array;
end Write_TextEdit_Vector;
-------------------------------------------
-- Write_VersionedTextDocumentIdentifier --
-------------------------------------------
not overriding procedure Write_VersionedTextDocumentIdentifier
(S : access Ada.Streams.Root_Stream_Type'Class;
V : VersionedTextDocumentIdentifier)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
JS.Key (+"uri");
DocumentUri'Write (S, V.uri);
Write_Number (JS, +"version", LSP_Number (V.version));
JS.End_Object;
end Write_VersionedTextDocumentIdentifier;
-------------------------
-- Write_WorkspaceEdit --
-------------------------
not overriding procedure Write_WorkspaceEdit
(S : access Ada.Streams.Root_Stream_Type'Class;
V : WorkspaceEdit)
is
JS : League.JSON.Streams.JSON_Stream'Class renames
League.JSON.Streams.JSON_Stream'Class (S.all);
begin
JS.Start_Object;
if V.documentChanges.Is_Empty then
JS.Key (+"changes");
JS.Start_Object;
for Cursor in V.changes.Iterate loop
JS.Key (TextDocumentEdit_Maps.Key (Cursor));
JS.Start_Array;
for Edit of V.changes (Cursor) loop
TextEdit'Write (S, Edit);
end loop;
JS.End_Array;
end loop;
JS.End_Object;
else
JS.Key (+"documentChanges");
if V.documentChanges.Is_Empty then
JS.Write (League.JSON.Arrays.Empty_JSON_Array.To_JSON_Value);
else
JS.Start_Array;
for Edit of V.documentChanges loop
TextDocumentEdit'Write (S, Edit);
end loop;
JS.End_Array;
end if;
end if;
JS.End_Object;
end Write_WorkspaceEdit;
end LSP.Messages;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
-- GCC 6.0 only
-- pragma Suppress (Tampering_Check);
private with HelperText;
private with Ada.Containers.Vectors;
private with Ada.Containers.Hashed_Maps;
package Port_Specification is
type Portspecs is tagged private;
misordered : exception;
contains_spaces : exception;
wrong_type : exception;
wrong_value : exception;
dupe_spec_key : exception;
dupe_list_value : exception;
missing_group : exception;
invalid_option : exception;
missing_extract : exception;
missing_require : exception;
type spec_field is (sp_namebase, sp_version, sp_revision, sp_epoch, sp_keywords,
sp_variants, sp_taglines, sp_homepage, sp_contacts, sp_dl_groups,
sp_dl_sites, sp_distfiles, sp_distsubdir, sp_df_index, sp_subpackages,
sp_opts_avail, sp_opts_standard, sp_vopts, sp_exc_opsys, sp_inc_opsys,
sp_exc_arch, sp_ext_only, sp_ext_zip, sp_ext_7z, sp_ext_lha, sp_ext_head,
sp_ext_tail, sp_ext_dirty, sp_distname, sp_skip_build, sp_single_job,
sp_destdir_env, sp_destdirname, sp_build_wrksrc, sp_makefile,
sp_make_args, sp_make_env, sp_build_target, sp_cflags, sp_cxxflags,
sp_cppflags, sp_ldflags, sp_makefile_targets, sp_skip_install,
sp_opt_level, sp_options_on, sp_broken, sp_opt_helper, sp_patchfiles,
sp_uses, sp_sub_list, sp_sub_files, sp_config_args, sp_config_env,
sp_build_deps, sp_buildrun_deps, sp_run_deps, sp_cmake_args, sp_qmake_args,
sp_info, sp_install_tgt, sp_patch_strip, sp_pfiles_strip,
sp_patch_wrksrc, sp_extra_patches, sp_must_config,
sp_config_wrksrc, sp_config_script, sp_gnu_cfg_prefix, sp_cfg_outsrc,
sp_config_target, sp_deprecated, sp_expiration, sp_install_wrksrc,
sp_plist_sub, sp_prefix, sp_licenses, sp_users, sp_groups, sp_catchall,
sp_notes, sp_inst_tchain, sp_var_opsys, sp_var_arch, sp_lic_name,
sp_lic_file, sp_lic_scheme, sp_skip_ccache, sp_test_tgt, sp_exrun,
sp_mandirs, sp_rpath_warning, sp_debugging, sp_broken_ssl, sp_test_args,
sp_gnome, sp_rcscript, sp_ug_pkg, sp_broken_mysql, sp_broken_pgsql,
sp_og_radio, sp_og_unlimited, sp_og_restrict, sp_opt_descr, sp_opt_group,
sp_ext_deb, sp_os_bdep, sp_os_rdep, sp_os_brdep, sp_test_env, sp_generated,
sp_xorg, sp_sdl, sp_phpext, sp_job_limit, sp_soversion, sp_os_uses,
sp_lic_terms, sp_lic_awk, sp_lic_src, sp_repsucks, sp_killdog,
sp_cgo_conf, sp_cgo_build, sp_cgo_inst, sp_cgo_cargs, sp_cgo_bargs,
sp_cgo_iargs, sp_cgo_feat, sp_verbatim);
type spec_option is (not_helper_format, not_supported_helper, broken_on, buildrun_depends_off,
buildrun_depends_on, build_depends_off, build_depends_on,
build_target_off, build_target_on, cflags_off, cflags_on,
cmake_args_off, cmake_args_on, cmake_bool_f_both, cmake_bool_t_both,
configure_args_off, configure_args_on,
configure_enable_both, configure_env_off, configure_env_on,
configure_with_both, cppflags_off, cppflags_on,
cxxflags_off, cxxflags_on, df_index_off, df_index_on,
extract_only_off, extract_only_on, extra_patches_off, extra_patches_on,
implies_on, info_off, info_on,
install_target_off, install_target_on, keywords_off, keywords_on,
ldflags_off, ldflags_on, make_args_off, make_args_on,
make_env_off, make_env_on, patchfiles_off, patchfiles_on,
plist_sub_off, plist_sub_on, prevents_on,
qmake_args_off, qmake_args_on, run_depends_off, run_depends_on,
sub_files_off, sub_files_on, sub_list_off, sub_list_on,
test_target_off, test_target_on,
uses_off, uses_on, makefile_off, makefile_on, description,
only_for_opsys_on, xorg_comp_off, xorg_comp_on,
gnome_comp_off, gnome_comp_on, php_ext_off, php_ext_on);
-- Initialize specification data
procedure initialize (specs : out Portspecs);
-- Generic function to set single string types.
-- Throws misordered exception if set too early (or late depending on perspective)
-- Throws contains spaces exception if space found anywhere in string
-- Throws wrong_type exception if field isn't a single string type.
procedure set_single_string
(specs : in out Portspecs;
field : spec_field;
value : String);
-- Generic function to populate lists
-- Throws misordered exception if set out of order.
-- Throws contains spaces exception if space found anywhere in string
-- Throws wrong_type exception if field isn't a list type.
procedure append_list
(specs : in out Portspecs;
field : spec_field;
value : String);
-- Generic function to set integers
-- Throws misordered exception if set out of order.
-- Throws wrong_type exception if field isn't a natural integer type
procedure set_natural_integer
(specs : in out Portspecs;
field : spec_field;
value : Natural);
-- Generic function to set boolean values
-- Throws wrong_type exception if field isn't a boolean type
procedure set_boolean
(specs : in out Portspecs;
field : spec_field;
value : Boolean);
-- Generic function to populate arrays
-- Throws misordered exception if set out of order.
-- Throws contains spaces exception if space found anywhere in string
-- Throws wrong_type exception if field isn't a list type.
-- Throws duplicate exception if key has already been seen.
procedure append_array
(specs : in out Portspecs;
field : spec_field;
key : String;
value : String;
allow_spaces : Boolean);
-- Generic function to establish groups of string arrays.
-- Throws misordered exception if set out of order.
-- Throws contains spaces exception if space found anywhere in string
-- Throws wrong_type exception if field isn't a list type.
-- Throws duplicate exception if key has already been seen.
procedure establish_group
(specs : in out Portspecs;
field : spec_field;
group : String);
-- Generic function to populate option helper
-- Throws misordered exception if called before standard options
-- Throws contains spaces exception if spaces aren't permitted but found
-- Throws wrong_type exception if field isn't supported
-- Throws wrong_value exception if option doesn't exist (caller should check first)
procedure build_option_helper
(specs : in out Portspecs;
field : spec_option;
option : String;
value : String);
-- Return True if provided variant is known
function variant_exists (specs : Portspecs; variant : String) return Boolean;
-- Return True if provided option name is known
function option_exists (specs : Portspecs; option : String) return Boolean;
-- Given the provided option name, return True if setting is "ON" and False otherwise
-- If option name is not valid, raise invalid option
function option_current_setting (specs : Portspecs; option : String) return Boolean;
-- Generic function to determine if group exists, returns True if so
function group_exists
(specs : Portspecs;
field : spec_field;
group : String) return Boolean;
-- Developer routine which shows contents of specification
procedure dump_specification (specs : Portspecs);
-- Iterate through all non-standard variants to check if all options are accounted for.
-- Return blank string if all of them pass or the name of the first variant that doesn't
-- concatenated with the missing option.
function check_variants (specs : Portspecs) return String;
-- Return False if deprecation set without expiration or vice versa.
function deprecation_valid (specs : Portspecs) return Boolean;
-- Perform any post-parsing adjustments necessary
procedure adjust_defaults_port_parse (specs : in out Portspecs);
-- Returns true if indicated option helper is empty
function option_helper_unset
(specs : Portspecs;
field : spec_option;
option : String) return Boolean;
-- After parsing, this is used to return the port name
function get_namebase (specs : Portspecs) return String;
-- Generic retrieve data function
function get_field_value (specs : Portspecs; field : spec_field) return String;
-- Specialized variant-specific list esp. for package manifest
function get_options_list (specs : Portspecs; variant : String) return String;
-- Retrieve the tagline on a given variant
function get_tagline (specs : Portspecs; variant : String) return String;
-- Calculate the surprisingly complex pkgversion string
function calculate_pkgversion (specs : Portspecs) return String;
-- Return count on variants list
function get_number_of_variants (specs : Portspecs) return Natural;
-- Return the list length of the data indicated by field
function get_list_length (specs : Portspecs; field : spec_field) return Natural;
-- Return item given by number when the list is indicated by the field
function get_list_item (specs : Portspecs; field : spec_field; item : Natural) return String;
-- Return number of subpackage for a given variant
function get_subpackage_length (specs : Portspecs; variant : String) return Natural;
-- Return subpackage given a variant and index
function get_subpackage_item
(specs : Portspecs;
variant : String;
item : Natural) return String;
-- Return number of extra runtime dependences on a named subpackage
function get_number_extra_run (specs : Portspecs; subpackage : String) return Natural;
-- Return extra runtime specification of a named subpackage given an index
function get_extra_runtime
(specs : Portspecs;
subpackage : String;
item : Natural) return String;
-- Return aggregate and formatted reason(s) for ignoring the port.
function aggregated_ignore_reason (specs : Portspecs) return String;
-- Returns a formatted block of lines to represent the current option settings
function options_summary (specs : Portspecs; variant : String) return String;
-- Returns True if one or more variants have no defined subpackages.
function missing_subpackage_definition (specs : Portspecs) return Boolean;
-- Return string block (delimited by LF) of unique build + buildrun + run depends (optional)
-- If limit_to_run is true, only run dependencies are returned
function combined_dependency_origins
(specs : Portspecs;
include_run : Boolean;
limit_to_run : Boolean) return String;
-- Runs through specs to ensure all license framework information is present.
function post_parse_license_check_passes (specs : Portspecs) return Boolean;
-- Ensures USERGROUP_SPKG is set if USERS or GROUP is set.
function post_parse_usergroup_check_passes (specs : Portspecs) return Boolean;
-- Return "single", "dual" or "multi";
function get_license_scheme (specs : Portspecs) return String;
-- Return True if rpath check failures need to break the build.
function rpath_check_errors_are_fatal (specs : Portspecs) return Boolean;
-- Return True if debugging is set on.
function debugging_is_on (specs : Portspecs) return Boolean;
-- Returns the key of the last catchall insertion
function last_catchall_key (specs : Portspecs) return String;
-- Returns true if all the options have a description
-- It also outputs to standard out which ones fail
function post_parse_opt_desc_check_passes (specs : Portspecs) return Boolean;
-- Returns true if all the option groups have at least 2 members
-- It also outputs to standard out which groups have only one member
function post_parse_option_group_size_passes (specs : Portspecs) return Boolean;
-- Checks radio and restricted groups. Radio groups have to have exactly one option
-- set by (by default) and restricted groups need at least one.
function post_transform_option_group_defaults_passes (specs : Portspecs) return Boolean;
-- Return "joined" table of group + options
function option_block_for_dialog (specs : Portspecs) return String;
-- Return true if options_avail is not "none"
function global_options_present (specs : Portspecs) return Boolean;
-- Return true if ops_standard is not "none"
function standard_options_present (specs : Portspecs) return Boolean;
-- Return True if the port is generated
function port_is_generated (specs : Portspecs) return Boolean;
-- If catchall FPC_EQUIVALENT is defined, return its value, otherwise return "N/A".
function equivalent_fpc_port (specs : Portspecs) return String;
-- Returns True if given dependency is present as run_depends or buildrun_depends
function run_dependency (specs : Portspecs; dependency : String) return Boolean;
-- Used for json-repology report only (returns full download URL (1) given distfile number)
function get_repology_distfile (specs : Portspecs; item : Natural) return String;
-- Format contacts with html (span, mailto)
function get_web_contacts (specs : Portspecs; subject : String) return String;
-- Provides json-formatted contacts
-- If contact is "nobody" then it returns a blank string
function get_json_contacts (specs : Portspecs) return String;
-- Ensure opsys dependencies are not applied (only for web page generation)
procedure do_not_apply_opsys_dependencies (specs : in out Portspecs);
-- Return true if broken_all key present in the broken array
function broken_all_set (specs : Portspecs) return Boolean;
-- Return true if BLOCK_WATCHDOG set by specification
function watchdog_disabled (specs : Portspecs) return Boolean;
-- store error seen during specification parsing
procedure set_parse_error (specs : in out Portspecs; error : String);
-- Retrieve parse error
function get_parse_error (specs : Portspecs) return String;
-- Insert new variable definition
procedure define (specs : in out Portspecs; variable : String; value : String);
-- Returns true if variable already defined
function definition_exists (specs : Portspecs; variable : String) return Boolean;
-- Returns value of defined variable
function definition (specs : Portspecs; variable : String) return String;
-- Return true if no definition are defined
function no_definitions (specs : Portspecs) return Boolean;
-- Detects SSL variant override by checking module arguments
function get_ssl_variant (specs : Portspecs; normal_variant : String) return String;
private
package HT renames HelperText;
package CON renames Ada.Containers;
type spec_order is (so_initialized, so_namebase, so_version, so_revision, so_epoch,
so_keywords, so_variants, so_taglines, so_homepage, so_contacts,
so_dl_groups, so_dl_sites, so_distfiles, so_distsubdir, so_df_index,
so_subpackages, so_opts_avail, so_opts_std, so_vopts);
type license_type is
(AGPLv3, AGPLv3x, APACHE10, APACHE11, APACHE20, ART10, ART20, ARTPERL10,
BSD2CLAUSE, BSD3CLAUSE, BSD4CLAUSE, BSDGROUP,
CUSTOM1, CUSTOM2, CUSTOM3, CUSTOM4,
GPLv1, GPLv1x, GPLv2, GPLv2x, GPLv3, GPLv3x,
GPLv3RLE, GPLv3RLEx, GMGPL, GMGPL3, INVALID, ISCL,
LGPL20, LGPL20x, LGPL21, LGPL21x, LGPL3, LGPL3x,
MIT, MPL, POSTGRESQL, PSFL, PUBDOM, OPENSSL, RUBY, ZLIB, HPND, AFL, CDDL, GFDL,
CC0_10, CC_30, CC_40, CC_NC_30, CC_NC_40,
CC_NCND_30, CC_NCND_40, CC_NCSA_30, CC_NCSA_40,
CC_ND_30, CC_ND_40, CC_SA_30, CC_SA_40);
type described_option_set is
(AALIB, ALSA, ASM, COLORD, CUPS, DBUS, DEBUG, DOCS, FIREBIRD, ICONV, IDN, IPV4, IPV6, JAVA,
LANG_CN, LANG_KO, LANG_RU,
LDAP, LDAPS, MYSQL, NAS, NLS, OPENGL, OSS, PERL532, PERL534, PGSQL, PNG, PULSEAUDIO,
PY27, PY38, PY39,
READLINE, RUBY26, RUBY27, RUBY30,
SNDIO, SOUND, SQLITE, STATIC, SYSLOG, TCL, TCLTK, THREADS, X11, ZLIB,
OPT_NOT_DEFINED);
type gnome_type is
(atk, cairo, glib, gtk2, gtk3, gtk4, gtksourceview3, gdkpixbuf, intltool, introspection,
pango, pygobject, libcroco, libglade, libgsf, librsvg, libxml2, libxslt,
dconf, gconf, libidl, orbit2, vte, libxmlxx2, libsigcxx2, glibmm, glibmm24,
cairomm, cairomm10, atkmm, atkmm16, pangomm, pangomm14, gtkmm30, gtkmm40,
invalid_component);
type xorg_type is
(xorgproto, fontcacheproto, printproto, xtransproto,
dmx, fontenc, fontutil, ice, pciaccess, pixman, sm, x11, xau, xaw, xcb,
xcb_util, xcb_util_cursor, xcb_util_image, xcb_util_keysyms, xcb_util_wm, xcb_util_xrm,
xcb_render_util, xcomposite, xcursor, xdamage, xdmcp, xext, xfixes, xfont, xfont2,
xfontcache, xft, xi, xinerama, xkbfile, xmu, xpm, xprop, xrandr, xrender, xres,
xscrnsaver, xset, xshmfence, xt, xtst, xv, xvmc, xxf86dga, xxf86vm, xbitmaps,
invalid_component);
type sdl_type is
(sdl1, sdl2, gfx1, gfx2, image1, image2, mixer1, mixer2, net1, net2, ttf1, ttf2,
invalid_component);
type phpext_type is
(bcmath, bitset, bz2, calendar, ctype, curl, dba, dom, enchant, exif, fileinfo, filter,
ftp, gd, gettext, gmp, hash, iconv, igbinary, imap, interbase, intl, jsonext, ldap, mbstring,
mcrypt, memcache, memcached, mysqli, odbc, opcache, openssl, pcntl, pdf, pdo,
pdo_dblib, pdo_firebird, pdo_mysql, pdo_odbc, pdo_pgsql, pdo_sqlite, pgsql, phar, posix,
pspell, radius, readline, recode, redis, session, shmop, simplexml, snmp, soap, sockets,
sqlite3, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, wddx, xml, xmlreader, xmlrpc,
xmlwriter, xsl, zip, zlib, ffi, sodium, invalid_extension);
package string_crate is new CON.Vectors
(Element_Type => HT.Text,
Index_Type => Positive,
"=" => HT.SU."=");
package sorter is new string_crate.Generic_Sorting ("<" => HT.SU."<");
package def_crate is new CON.Hashed_Maps
(Key_Type => HT.Text,
Element_Type => HT.Text,
Hash => HT.hash,
Equivalent_Keys => HT.equivalent,
"=" => HT.SU."=");
type group_list is
record
group : HT.Text;
list : string_crate.Vector;
end record;
package list_crate is new CON.Hashed_Maps
(Key_Type => HT.Text,
Element_Type => group_list,
Hash => HT.hash,
Equivalent_Keys => HT.equivalent);
type Option_Helper is
record
option_name : HT.Text;
option_description : HT.Text;
currently_set_ON : Boolean := False;
set_ON_by_default : Boolean := False;
standard_option : Boolean := False;
BROKEN_ON : HT.Text;
BUILDRUN_DEPENDS_OFF : string_crate.Vector;
BUILDRUN_DEPENDS_ON : string_crate.Vector;
BUILD_DEPENDS_OFF : string_crate.Vector;
BUILD_DEPENDS_ON : string_crate.Vector;
BUILD_TARGET_OFF : string_crate.Vector;
BUILD_TARGET_ON : string_crate.Vector;
CFLAGS_OFF : string_crate.Vector;
CFLAGS_ON : string_crate.Vector;
CMAKE_ARGS_OFF : string_crate.Vector;
CMAKE_ARGS_ON : string_crate.Vector;
CMAKE_BOOL_F_BOTH : string_crate.Vector;
CMAKE_BOOL_T_BOTH : string_crate.Vector;
CONFIGURE_ARGS_OFF : string_crate.Vector;
CONFIGURE_ARGS_ON : string_crate.Vector;
CONFIGURE_ENABLE_BOTH : string_crate.Vector;
CONFIGURE_ENV_OFF : string_crate.Vector;
CONFIGURE_ENV_ON : string_crate.Vector;
CONFIGURE_WITH_BOTH : string_crate.Vector;
CPPFLAGS_OFF : string_crate.Vector;
CPPFLAGS_ON : string_crate.Vector;
CXXFLAGS_OFF : string_crate.Vector;
CXXFLAGS_ON : string_crate.Vector;
DF_INDEX_OFF : string_crate.Vector;
DF_INDEX_ON : string_crate.Vector;
EXTRACT_ONLY_OFF : string_crate.Vector;
EXTRACT_ONLY_ON : string_crate.Vector;
EXTRA_PATCHES_OFF : string_crate.Vector;
EXTRA_PATCHES_ON : string_crate.Vector;
IMPLIES_ON : string_crate.Vector;
INFO_OFF : string_crate.Vector;
INFO_ON : string_crate.Vector;
INSTALL_TARGET_OFF : string_crate.Vector;
INSTALL_TARGET_ON : string_crate.Vector;
KEYWORDS_OFF : string_crate.Vector;
KEYWORDS_ON : string_crate.Vector;
LDFLAGS_OFF : string_crate.Vector;
LDFLAGS_ON : string_crate.Vector;
MAKEFILE_OFF : string_crate.Vector;
MAKEFILE_ON : string_crate.Vector;
MAKE_ARGS_OFF : string_crate.Vector;
MAKE_ARGS_ON : string_crate.Vector;
MAKE_ENV_OFF : string_crate.Vector;
MAKE_ENV_ON : string_crate.Vector;
ONLY_FOR_OPSYS_ON : string_crate.Vector;
PATCHFILES_OFF : string_crate.Vector;
PATCHFILES_ON : string_crate.Vector;
PLIST_SUB_OFF : string_crate.Vector;
PLIST_SUB_ON : string_crate.Vector;
PREVENTS_ON : string_crate.Vector;
QMAKE_ARGS_OFF : string_crate.Vector;
QMAKE_ARGS_ON : string_crate.Vector;
RUN_DEPENDS_OFF : string_crate.Vector;
RUN_DEPENDS_ON : string_crate.Vector;
SUB_FILES_OFF : string_crate.Vector;
SUB_FILES_ON : string_crate.Vector;
SUB_LIST_OFF : string_crate.Vector;
SUB_LIST_ON : string_crate.Vector;
TEST_TARGET_OFF : string_crate.Vector;
TEST_TARGET_ON : string_crate.Vector;
USES_OFF : string_crate.Vector;
USES_ON : string_crate.Vector;
XORG_COMPONENTS_OFF : string_crate.Vector;
XORG_COMPONENTS_ON : string_crate.Vector;
GNOME_COMPONENTS_OFF : string_crate.Vector;
GNOME_COMPONENTS_ON : string_crate.Vector;
PHP_EXTENSIONS_OFF : string_crate.Vector;
PHP_EXTENSIONS_ON : string_crate.Vector;
end record;
package option_crate is new CON.Hashed_Maps
(Key_Type => HT.Text,
Element_Type => Option_Helper,
Hash => HT.hash,
Equivalent_Keys => HT.equivalent);
type Portspecs is tagged
record
definitions : def_crate.Map;
namebase : HT.Text;
version : HT.Text;
revision : Natural;
epoch : Natural;
job_limit : Natural;
keywords : string_crate.Vector;
variants : string_crate.Vector;
taglines : def_crate.Map;
homepage : HT.Text;
contacts : string_crate.Vector;
dl_sites : list_crate.Map;
distfiles : string_crate.Vector;
dist_subdir : HT.Text;
df_index : string_crate.Vector;
subpackages : list_crate.Map;
ops_avail : string_crate.Vector;
ops_standard : string_crate.Vector;
ops_helpers : option_crate.Map;
last_set : spec_order;
variantopts : list_crate.Map;
options_on : list_crate.Map;
broken : list_crate.Map;
exc_opsys : string_crate.Vector;
inc_opsys : string_crate.Vector;
exc_arch : string_crate.Vector;
deprecated : HT.Text;
expire_date : HT.Text;
uses : string_crate.Vector;
uses_base : string_crate.Vector;
sub_list : string_crate.Vector;
sub_files : string_crate.Vector;
extract_only : string_crate.Vector;
extract_zip : string_crate.Vector;
extract_lha : string_crate.Vector;
extract_7z : string_crate.Vector;
extract_deb : string_crate.Vector;
extract_dirty : string_crate.Vector;
extract_head : list_crate.Map;
extract_tail : list_crate.Map;
distname : HT.Text;
patchfiles : string_crate.Vector;
extra_patches : string_crate.Vector;
patch_strip : string_crate.Vector;
pfiles_strip : string_crate.Vector;
patch_wrksrc : HT.Text;
config_args : string_crate.Vector;
config_env : string_crate.Vector;
config_must : HT.Text;
config_prefix : HT.Text;
config_script : HT.Text;
config_target : HT.Text;
config_wrksrc : HT.Text;
config_outsrc : Boolean;
skip_build : Boolean;
skip_install : Boolean;
skip_ccache : Boolean;
destdir_env : Boolean;
single_job : Boolean;
shift_install : Boolean;
fatal_rpath : Boolean;
debugging_on : Boolean;
generated : Boolean;
opt_df_index : Boolean;
skip_opsys_dep : Boolean;
repology_sucks : Boolean;
kill_watchdog : Boolean;
prefix : HT.Text;
build_wrksrc : HT.Text;
makefile : HT.Text;
destdirname : HT.Text;
make_env : string_crate.Vector;
make_args : string_crate.Vector;
build_target : string_crate.Vector;
build_deps : string_crate.Vector;
buildrun_deps : string_crate.Vector;
run_deps : string_crate.Vector;
opsys_b_deps : list_crate.Map;
opsys_r_deps : list_crate.Map;
opsys_br_deps : list_crate.Map;
opsys_c_uses : list_crate.Map;
cflags : string_crate.Vector;
cxxflags : string_crate.Vector;
cppflags : string_crate.Vector;
ldflags : string_crate.Vector;
optimizer_lvl : Natural;
cmake_args : string_crate.Vector;
qmake_args : string_crate.Vector;
gnome_comps : string_crate.Vector;
xorg_comps : string_crate.Vector;
sdl_comps : string_crate.Vector;
php_extensions : string_crate.Vector;
info : string_crate.Vector;
install_tgt : string_crate.Vector;
test_tgt : string_crate.Vector;
test_args : string_crate.Vector;
test_env : string_crate.Vector;
install_wrksrc : HT.Text;
plist_sub : string_crate.Vector;
make_targets : list_crate.Map;
licenses : string_crate.Vector;
lic_names : string_crate.Vector;
lic_files : string_crate.Vector;
lic_terms : string_crate.Vector;
lic_awk : string_crate.Vector;
lic_source : string_crate.Vector;
lic_scheme : HT.Text;
usergroup_pkg : HT.Text;
users : string_crate.Vector;
groups : string_crate.Vector;
mandirs : string_crate.Vector;
mk_verbatim : string_crate.Vector;
subr_scripts : string_crate.Vector;
broken_ssl : string_crate.Vector;
broken_mysql : string_crate.Vector;
broken_pgsql : string_crate.Vector;
catch_all : list_crate.Map;
pkg_notes : def_crate.Map;
var_opsys : list_crate.Map;
var_arch : list_crate.Map;
extra_rundeps : list_crate.Map;
last_catchkey : HT.Text;
soversion : HT.Text;
used_python : HT.Text;
used_perl : HT.Text;
used_ruby : HT.Text;
used_lua : HT.Text;
parse_error : HT.Text;
cgo_skip_conf : Boolean;
cgo_skip_build : Boolean;
cgo_skip_inst : Boolean;
cgo_cargolock : HT.Text;
cgo_cargotoml : HT.Text;
cgo_cargo_bin : HT.Text;
cgo_target_dir : HT.Text;
cgo_vendor_dir : HT.Text;
cgo_build_args : string_crate.Vector;
cgo_conf_args : string_crate.Vector;
cgo_inst_args : string_crate.Vector;
cgo_features : string_crate.Vector;
opt_radio : string_crate.Vector;
opt_restrict : string_crate.Vector;
opt_unlimited : string_crate.Vector;
optgroup_desc : list_crate.Map;
optgroups : list_crate.Map;
end record;
-- Ordinal type representing numbers that have subpackage arguments
type smodules is range 1 .. 5;
-- Returns the name of the module associated with the smodules index
function base_module (index : smodules) return String;
-- Compares given keyword against known values
function keyword_is_valid (keyword : String) return Boolean;
-- Returns true if there is a short description defined for each variant.
function all_taglines_defined (specs : Portspecs) return Boolean;
-- Returns true if given string can convert to an integer between 1 and
-- distfiles count.
function dist_index_is_valid (specs : Portspecs; test_index : String) return Boolean;
-- Returns true if space exists outside of quotation marks
function contains_nonquoted_spaces (word : String) return Boolean;
-- OPT_ON can only match existing option names exactly, or
-- have "/" separator with digits and full_stop only or
-- have above with "/" followed by one or more valid arch separated by "|" or
-- same as above except nothing between the two "/" separators
function valid_OPT_ON_value (specs : Portspecs;
key : String;
word : String) return Boolean;
-- Return True if same option is already defined in all.
function option_present_in_OPT_ON_all (specs : Portspecs;
option_name : String) return Boolean;
-- Return True if in format YYYY-MM-DD and YYYY > 2016 and MM is 01..12 and DD is 01..31
-- and it succesfully converts to a date.
function ISO8601_format (value : String) return Boolean;
-- checks for exactly two colons
-- checks the three components are not empty strings
-- Does not do existence checks on namebase, variants or subpackages.
function valid_dependency_format (value : String) return Boolean;
-- If illegal characters in the namebase are detected, return True.
function invalid_namebase (value : String; allow_comma : Boolean) return Boolean;
-- Returns true if value is a known USES module.
function valid_uses_module (value : String) return Boolean;
-- Returns true if value is a known mysql group setting
function valid_broken_mysql_value (value : String) return Boolean;
-- Returns true if value is a known postgresql setting
function valid_broken_pgsql_value (value : String) return Boolean;
-- Return true if INFO appendum is valid (compared against existing entries)
-- Specifically it's checking the subdirectory (if it exists) to make sure it matches
-- previous entries. It will define INFO_SUBDIR in catchall (once)
function valid_info_page (specs : in out Portspecs; value : String) return Boolean;
-- Checks against a list of known licenses or CUSTOM(1,2,3,4)
function determine_license (value : String) return license_type;
-- Returns enumeration of described option or OPT_NOT_FOUND if the option isn't described
function described_option (value : String) return described_option_set;
-- Returns true if subpackage exists in any variant.
function subpackage_exists (specs : Portspecs; subpackage : String) return Boolean;
-- Returns True if given_module matches the base_module exists, but it doesn't have
-- an argument or the argument doesn't match a known subpackage.
function module_subpackage_failed
(specs : Portspecs;
base_module : String;
given_module : String) return Boolean;
-- Checks against known list of gnome components and identifies it
function determine_gnome_component (component : String) return gnome_type;
-- Checks against known list of xorg components and identifies it
function determine_xorg_component (component : String) return xorg_type;
-- Checks against known list of SDL components and identifies it
function determine_sdl_component (component : String) return sdl_type;
-- Checks against known list of PHP extensions and identifies it
function determine_php_extension (component : String) return phpext_type;
-- Given a string XXXX/account:project:tag(:directory) return a standard
-- distribution file name.
function generate_github_distfile (download_site : String) return String;
-- Like generate_github_distfile, but doesn't filter/modify out leading v's and plus signs
function generate_gitlab_distfile (download_site : String) return String;
-- Given a string XXXX/project:version return a standard
function generate_crates_distfile (download_site : String) return String;
-- Returns True if a given option already present in radio, restricted or unlimited group
function option_already_in_group (specs : Portspecs; option_name : String) return Boolean;
-- Given an option enumeration, return the default option description
function default_description (option : described_option_set) return String;
-- Split distfile translation to separate function (needed more than once)
-- It converts "generated" to a filename mainly
function translate_distfile (specs : Portspecs; distfile : String) return String;
-- Give full download URL (one) for each distfile.
-- Represent macros with "mirror://" prefix
function repology_distfile (specs : Portspecs; distfile : String) return String;
-- split out info entry validation (returns non-black on failed check)
function info_page_check_message (specs : Portspecs; value : String) return String;
-- Return True if uses module is fully specified (mainly for compiler modules)
function extra_uses_modules_sanity_check_passes
(specs : Portspecs;
module : String;
errmsg : out HT.Text) return Boolean;
end Port_Specification;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- Copyright (C) 2012-2021, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System.BB.Parameters;
with Interfaces.STM32; use Interfaces.STM32;
with Interfaces.STM32.RCC; use Interfaces.STM32.RCC;
package body System.STM32 is
package Params renames System.BB.Parameters;
subtype Divisor is UInt32;
HPRE_Prescaler_Divisors : constant array (AHB_Prescalers) of Divisor :=
(1, 2, 4, 8, 16, 64, 128, 256, 512);
-- per RM0438 Rev 6 pg 353/2194
PPRE_Prescaler_Divisors : constant array (APB_Prescalers) of Divisor :=
(1, 2, 4, 8, 16);
MSI_Range_Table : constant array (UInt4) of UInt32 :=
(0 => 100_000,
1 => 200_000,
2 => 400_000,
3 => 800_000,
4 => 1_000_000,
5 => 2_000_000,
6 => 4_000_000,
7 => 8_000_000,
8 => 16_000_000,
9 => 24_000_000,
10 => 32_000_000,
11 => 48_000_000,
others => 0);
procedure Get_All_But_SYSCLK (This : in out RCC_System_Clocks);
-------------------
-- System_Clocks --
-------------------
function System_Clocks return RCC_System_Clocks is
Result : RCC_System_Clocks;
begin
case SYSCLK_Source'Enum_Val (RCC_Periph.CFGR.SWS) is
when SYSCLK_SRC_MSI =>
Result.SYSCLK := Params.MSI_Clock;
when SYSCLK_SRC_HSI =>
Result.SYSCLK := HSICLK;
when SYSCLK_SRC_HSE =>
Result.SYSCLK := Params.HSE_Clock; -- note: HSE is optional
when SYSCLK_SRC_PLL =>
Result.SYSCLK := Computed_SYSCLK_From_PLL;
end case;
Get_All_But_SYSCLK (Result);
return Result;
end System_Clocks;
------------------------------
-- Computed_SYSCLK_From_PLL --
------------------------------
function Computed_SYSCLK_From_PLL return Frequency is
PLLM : constant UInt32 := UInt32 (RCC_Periph.PLLCFGR.PLLM) + 1;
PLLN : constant UInt32 := UInt32 (RCC_Periph.PLLCFGR.PLLN);
PLLR : constant UInt32 := (case RCC_Periph.PLLCFGR.PLLR is
when 2#00# => 2,
when 2#01# => 4,
when 2#10# => 6,
when 2#11# => 8);
MSI_Value : UInt32;
MSI_Index : UInt4;
PLL_VCO : UInt32;
Result : Frequency;
begin
if PLL_Source'Enum_Val (RCC_Periph.PLLCFGR.PLLSRC) = PLL_SRC_MSI then
if not RCC_Periph.CR.MSIRGSEL then
-- MSISRANGE from RCC_CSR applies
MSI_Index := RCC_Periph.CSR.MSISRANGE;
else
-- MSIRANGE from RCC_CR applies
MSI_Index := RCC_Periph.CR.MSIRANGE;
end if;
MSI_Value := MSI_Range_Table (MSI_Index);
end if;
-- See RM0438 Rev 6, pg 354/2194, section 9.8.4 RCC PLL configuration
case PLL_Source'Enum_Val (RCC_Periph.PLLCFGR.PLLSRC) is
when PLL_SRC_None =>
PLL_VCO := 0;
when PLL_SRC_HSE =>
PLL_VCO := Params.HSE_Clock;
when PLL_SRC_HSI =>
PLL_VCO := HSICLK;
when PLL_SRC_MSI =>
PLL_VCO := MSI_Value;
end case;
if PLL_VCO = 0 then
-- the PLL is not really selected as the SYSCLK source
Result := 0;
else
Result := ((PLL_VCO / PLLM) * PLLN) / PLLR;
end if;
return Result;
end Computed_SYSCLK_From_PLL;
------------------------
-- Get_All_But_SYSCLK --
------------------------
procedure Get_All_But_SYSCLK (This : in out RCC_System_Clocks) is
HPRE : constant AHB_Prescalers :=
AHB_Prescalers'Enum_Val (RCC_Periph.CFGR.HPRE);
HPRE_Div : constant Divisor := HPRE_Prescaler_Divisors (HPRE);
PPRE1 : constant APB_Prescalers :=
APB_Prescalers'Enum_Val (RCC_Periph.CFGR.PPRE.Arr (1));
PPRE1_Div : constant Divisor := PPRE_Prescaler_Divisors (PPRE1);
PPRE2 : constant APB_Prescalers :=
APB_Prescalers'Enum_Val (RCC_Periph.CFGR.PPRE.Arr (2));
PPRE2_Div : constant Divisor := PPRE_Prescaler_Divisors (PPRE2);
begin
This.HCLK := This.SYSCLK / HPRE_Div;
This.PCLK1 := This.HCLK / PPRE1_Div;
This.PCLK2 := This.HCLK / PPRE2_Div;
if PPRE1 = RCC_HCLK_DIV1 then
This.TIMCLK1 := This.PCLK1;
else
This.TIMCLK1 := This.PCLK1 * 2;
end if;
if PPRE2 = RCC_HCLK_DIV1 then
This.TIMCLK2 := This.PCLK2;
else
This.TIMCLK2 := This.PCLK2 * 2;
end if;
end Get_All_But_SYSCLK;
end System.STM32;
|
package Atomic
with Preelaborate,
Spark_Mode
is
type Mem_Order is
(Relaxed, -- Implies no inter-thread ordering constraints
Consume,
-- This is currently implemented using the stronger __ATOMIC_ACQUIRE
-- memory order because of a deficiency in C++11's semantics for
-- memory_order_consume.
Acquire,
-- Creates an inter-thread happens-before constraint from the release
-- (or stronger) semantic store to this acquire load. Can prevent
-- hoisting of code to before the operation.
Release,
-- Creates an inter-thread happens-before constraint to acquire (or
-- stronger) semantic loads that read from this release store. Can
-- prevent sinking of code to after the operation.
Acq_Rel, -- Combines the effects of both Acquire and Release
Seq_Cst); -- Enforces total ordering with all other Seq_Cst operations
for Mem_Order use
(Relaxed => 0,
Consume => 1,
Acquire => 2,
Release => 3,
Acq_Rel => 4,
Seq_Cst => 5);
function Stronger (A, B : Mem_Order) return Boolean;
----------
-- Flag --
----------
type Flag is limited private;
function Init (Val : Boolean) return Flag
with Post => Value (Init'Result) = Val;
-- Can be used to initialize an Atomic_Flag:
--
-- A : Atomic.Flag := Atomic.Init (0);
function Set (This : aliased Flag;
Order : Mem_Order := Seq_Cst)
return Boolean
with Pre => Order in Relaxed | Consume | Acquire | Seq_Cst,
Post => Set'Result = Value (This);
procedure Test_And_Set (This : aliased in out Flag;
Result : out Boolean;
Order : Mem_Order := Seq_Cst)
with Post => Result = Value (This)'Old
and then Value (This) = True;
procedure Clear (This : aliased in out Flag;
Order : Mem_Order := Seq_Cst)
with Pre => Order in Relaxed | Release | Seq_Cst,
Post => Value (This) = False;
function Value (This : Flag) return Boolean
with Ghost;
-- Ghost function to get the value of an Flag without needing it aliased.
-- This doesn't use the atomic built-ins.
private
function Stronger (A, B : Mem_Order) return Boolean
is (A > B);
type Flag is mod 2 ** 8
with Size => 8;
-----------
-- Value --
-----------
function Value (This : Flag) return Boolean
is (This /= 0);
pragma Inline (Init);
pragma Inline (Set);
pragma Inline (Test_And_Set);
pragma Inline (Clear);
pragma Inline (Value);
end Atomic;
|
-----------------------------------------------------------------------
-- messages - A simple memory-based forum
-- Copyright (C) 2012 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings.Unbounded;
with Ada.Containers.Vectors;
with Util.Beans.Objects;
with Util.Beans.Basic;
with Util.Beans.Methods;
package Messages is
-- Identifies a message in the forum.
type Message_Id is new Positive;
type Message_Bean is new Util.Beans.Basic.Bean and Util.Beans.Methods.Method_Bean with private;
type Message_Bean_Access is access all Message_Bean'Class;
-- Get the value identified by the name.
overriding
function Get_Value (From : Message_Bean;
Name : String) return Util.Beans.Objects.Object;
-- Set the value identified by the name.
overriding
procedure Set_Value (From : in out Message_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object);
-- Post the message.
procedure Post (From : in out Message_Bean;
Outcome : in out Ada.Strings.Unbounded.Unbounded_String);
-- This bean provides some methods that can be used in a Method_Expression
overriding
function Get_Method_Bindings (From : in Message_Bean)
return Util.Beans.Methods.Method_Binding_Array_Access;
-- Create a message bean instance.
function Create_Message_Bean return Util.Beans.Basic.Readonly_Bean_Access;
-- The <tt>Forum_Bean</tt> contains a list of messages.
-- It is intended to be shared by every user, hence there will be only one instance
-- in the server.
type Forum_Bean is new Util.Beans.Basic.List_Bean with private;
-- Get the value identified by the name.
overriding
function Get_Value (From : Forum_Bean;
Name : String) return Util.Beans.Objects.Object;
-- Get the number of elements in the list.
overriding
function Get_Count (From : in Forum_Bean) return Natural;
-- Set the current row index. Valid row indexes start at 1.
overriding
procedure Set_Row_Index (From : in out Forum_Bean;
Index : in Natural);
-- Get the element at the current row index.
overriding
function Get_Row (From : in Forum_Bean) return Util.Beans.Objects.Object;
-- Create the list of messages.
function Create_Message_List return Util.Beans.Basic.Readonly_Bean_Access;
private
type Message_Bean is new Util.Beans.Basic.Bean and Util.Beans.Methods.Method_Bean with record
Id : Message_Id;
Text : Ada.Strings.Unbounded.Unbounded_String;
Email : Ada.Strings.Unbounded.Unbounded_String;
end record;
package Message_Vector is
new Ada.Containers.Vectors (Index_Type => Message_Id,
Element_Type => Message_Bean,
"=" => "=");
protected type Forum is
-- Post the message in the forum.
procedure Post (Message : in Message_Bean);
-- Delete the message identified by <b>Id</b>.
procedure Delete (Id : in Message_Id);
-- Get the message identified by <b>Id</b>.
function Get_Message (Id : in Message_Id) return Message_Bean;
-- Get the number of messages in the forum.
function Get_Message_Count return Natural;
private
Messages : Message_Vector.Vector;
end Forum;
type Forum_Bean is new Util.Beans.Basic.List_Bean with record
Msg : aliased Message_Bean;
Pos : Message_Id;
Current : Util.Beans.Objects.Object;
end record;
type Forum_Bean_Access is access all Forum_Bean'Class;
end Messages;
|
package body STM32GD.Vectors is
procedure Default_Handler is
begin
null;
end Default_Handler;
end STM32GD.Vectors;
|
-------------------------------------------------------------------------------
-- Copyright 2021, The Septum Developers (see AUTHORS file)
-- 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.Containers.Ordered_Sets;
with Ada.Containers.Vectors;
with Ada.Strings.Unbounded;
-- A lot of what happens in Septum is related to strings. It reads them from
-- file, uses them as input for commands, looks for them with filters, attempts
-- to match them with regular expressions and prints them to users.
--
-- ## UTF-8 Compatibility
--
-- Any solution to handling all of these in a UTF-8 compatible manner, must
-- then deal appropriately with all of the interfaces with which these things
-- touch. Due to the tight binding within Septum of all of these behaviors,
-- it may not be possible to extricate enough of string handling for a drop in
-- replacement, and a complete refactoring to properly handle UTF-8 in all
-- situations may be impossible.
--
-- The binding of strings to fixed sizes also remains painful, as it requires
-- the use of an additional unbounded type, and often semantically meaningless
-- and inefficient conversions between the two types. In many situations,
-- fixed strings aren't possible, such as being stored in vectors, sets or used
-- as keys in maps. This often results in doubling the size of the interface,
-- or clumsily converting as needed.
--
-- My approach thus far has been to write interfaces using `String` as much as
-- possible, falling back to unbounded strings only when absolutely necessary.
-- There is likely a considerable amount of time needed to convert due to this
-- approach.
--
-- What I probably should have done initially was to define a private string
-- type to use everywhere with easy conversions and use either string interning
-- or underlying unbounded strings. The current form of `Unbounded_String` is
-- also somewhat unwieldly.
--
-- The [VSS](https://github.com/AdaCore/VSS) library looks like a viable
-- alternative to `Unbounded_String`, though it is marked with "Warning: This is
-- experimental work in progress, everything is subject to change. It may be or
-- may be not part of GNATCOLL or standard Ada library in the future."
--
-- Known systems which use strings:
-- - Terminal I/O (Trendy Terminal)
-- - Formatting
-- - Hinting system
-- - Autocomplete
-- - Search
-- - Regular expressions
-- - File I/O
-- - Command interpretation
--
package SP.Strings
with Preelaborate
is
package ASU renames Ada.Strings.Unbounded;
package String_Sets is new Ada.Containers.Ordered_Sets
(Element_Type => ASU.Unbounded_String, "<" => ASU."<",
"=" => ASU."=");
package String_Vectors is new Ada.Containers.Vectors
(Index_Type => Positive, Element_Type => ASU.Unbounded_String,
"=" => ASU."=");
function Zip (Left, Right : String_Vectors.Vector) return ASU.Unbounded_String;
function Format_Array (S : String_Vectors.Vector) return ASU.Unbounded_String;
function Common_Prefix_Length (A, B : ASU.Unbounded_String) return Natural
with
Post => Common_Prefix_Length'Result <= Natural'Max (ASU.Length (A), ASU.Length (B));
function Matching_Suffix (Current, Desired : ASU.Unbounded_String) return ASU.Unbounded_String;
-- Quoted strings must start and end with either a single or a double quote.
function Is_Quoted (S : String) return Boolean;
function Split_Command (Input : ASU.Unbounded_String) return SP.Strings.String_Vectors.Vector;
-- An exploded form of a line which allows the line to be recombined
-- transparently to a user, by reapplying the appropriate amounts and types
-- of spacing between words.
--
-- This looks like:
-- [_space_]*[WORD][_space_][WORD][_space_][WORD][_space_]
--
-- To prevent complications regarding whether a word or space is first, and
-- simplify iteration over words, the leading space is always stored, and
-- may be empty.
type Exploded_Line is record
-- The first space is "Leading spacing"
-- Spaces(i) is what preceeds Words(i)
Spacers : String_Vectors.Vector;
Words : String_Vectors.Vector;
end record;
-- TODO: This will eventually need to be rewritten to account for multi-byte
-- sequences in UTF-8. Incurring technical debt here on purpose to try to get
-- the command line formatter stood up more quickly.
function Make (S : String) return Exploded_Line;
function Get_Word (E : Exploded_Line; Index : Positive) return String is (ASU.To_String (E.Words.Element (Index)));
function Num_Words (E : Exploded_Line) return Natural is (Natural (E.Words.Length));
function Get_Cursor_Word (E : SP.Strings.Exploded_Line; Cursor_Position : Positive) return Natural;
function Cursor_Position_At_End_Of_Word (E : SP.Strings.Exploded_Line; Word : Positive) return Positive;
end SP.Strings;
|
-- Task 2 of RTPL WS17/18
-- Team members: Hannes B. and Gabriel Z.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; -- For float input
package body convert with SPARK_Mode is
-- Procedure for option 2
procedure opt2 is
begin
-- User input
Put ("Please input a Celsius value: ");
Ada.Float_Text_IO.Get (F1);
-- Calculate
F2 := myCel2Fahr (F1);
-- Make sure calculation was correct
pragma Assert (F2 = F1 * (9.0 / 5.0) + 32.0);
-- Print results
Ada.Float_Text_IO.Put (F1, 2, 2, 0);
Put (" C = ");
Ada.Float_Text_IO.Put (F2, 2, 2, 0);
Put_Line (" F");
end opt2;
-- Procedure of option 3
procedure opt3 is
begin
-- User input
Put ("Please input Fahrenheit value: ");
Ada.Float_Text_IO.Get (F1);
-- Calculate
F2 := myFahr2Cel (F1);
-- Make sure calculation was correct
pragma Assert (F2 = (F1 - 32.0) * (5.0 / 9.0));
-- Print results
Ada.Float_Text_IO.Put (F1, 2, 2, 0);
Put (" F = ");
Ada.Float_Text_IO.Put (F2, 2, 2, 0);
Put_Line (" C");
end opt3;
-- Convert Celsius to Fahrenheit
function myCel2Fahr (cel : Float) return Float is
begin
return (cel * (9.0 / 5.0) + 32.0);
end myCel2Fahr;
-- Convert Fahrenheit to Celsius
function myFahr2Cel (fahr : Float) return Float is
begin
return ((fahr - 32.0) * (5.0 / 9.0));
end myFahr2Cel;
end convert;
|
-- This file is generated by SWIG. Please do *not* modify by hand.
--
with interfaces.c;
with interfaces.c.strings;
with swig;
with interfaces.C;
package Festival is
-- FILE
--
subtype FILE is swig.opaque_structure;
type FILE_array is array (interfaces.C.Size_t range <>) of aliased festival.FILE;
-- ostream
--
subtype ostream is swig.incomplete_class;
type ostream_array is array (interfaces.C.Size_t range <>) of aliased festival.ostream;
-- ModuleDescription
--
subtype ModuleDescription is swig.opaque_structure;
type ModuleDescription_array is array (interfaces.C.Size_t range <>) of aliased festival.ModuleDescription;
ft_server_socket : aliased interfaces.c.int;
festival_version : aliased interfaces.c.strings.chars_ptr;
FESTIVAL_DEFAULT_PORT : constant := 1314;
FESTIVAL_HEAP_SIZE : constant := 1000000;
private
pragma import (CPP, ft_server_socket, "_ZN8festival16ft_server_socketE");
pragma import (CPP, festival_version, "_ZN8festival16festival_versionE");
end Festival;
|
-- This file is generated by SWIG. Please do *not* modify by hand.
--
with osmesa_c.Pointers;
with Interfaces.C;
package osmesa_c.pointer_Pointers is
-- GLenum_Pointer_Pointer
--
type GLenum_Pointer_Pointer is access all osmesa_c.Pointers.GLenum_Pointer;
-- GLint_Pointer_Pointer
--
type GLint_Pointer_Pointer is access all osmesa_c.Pointers.GLint_Pointer;
-- GLsizei_Pointer_Pointer
--
type GLsizei_Pointer_Pointer is
access all osmesa_c.Pointers.GLsizei_Pointer;
-- GLboolean_Pointer_Pointer
--
type GLboolean_Pointer_Pointer is
access all osmesa_c.Pointers.GLboolean_Pointer;
-- OSMesaContext_Pointer_Pointer
--
type OSMesaContext_Pointer_Pointer is
access all osmesa_c.Pointers.OSMesaContext_Pointer;
-- OSMESAproc_Pointer_Pointer
--
type OSMESAproc_Pointer_Pointer is
access all osmesa_c.Pointers.OSMESAproc_Pointer;
end osmesa_c.pointer_Pointers;
|
package body openGL.surface_Profile.privvy
is
-- function to_glx (Self : in Item'Class) return GLX.GLXFBConfig
-- is
-- begin
-- return Self.glx_Config;
-- end to_glx;
procedure dummy is begin null; end;
end openGL.surface_Profile.privvy;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with Port_Specification;
private with Parameters;
package PortScan.Operations is
-- Call before executing sanity check. It checks the present of build
-- hooks at the synth_conf location and caches the results.
procedure initialize_hooks;
-- Fire off first hook (run_start) as a bulk build starts
procedure run_start_hook;
-- For the pkg(8), trigger a success or failure hook based on if it built or not.
procedure run_hook_after_build (built : Boolean; id : port_id);
-- Removes ??_history.json files from previous runs
procedure delete_existing_web_history_files;
-- Figure package names from portlist and remove all existing packages from that set.
procedure delete_existing_packages_of_ports_list;
-- Look in build queue and return the next ignore port in the queue (if it exists).
function next_ignored_port return port_id;
-- Returns true if every port in the queue has all of ports listed in the
-- blocks and blocked_by containers are all also present in the queue
function integrity_intact return Boolean;
-- This removes the first reverse dependency port from all_ports that is
-- found the complete reverse deps list and return the port_id of the
-- deleted port. If the list is empty, return port_match_failed instead.
function skip_next_reverse_dependency (pinnacle : port_id) return port_id;
-- Exposed for pilot which eliminated ignored ports during the sanity check
procedure record_history_ignored
(elapsed : String;
bucket : String;
origin : String;
reason : String;
skips : Natural);
-- The port build failed, so set all reverse dependences as skipped
-- Remove the port from the queue when this is done.
-- Exposed for pilot
procedure cascade_failed_build (id : port_id; numskipped : out Natural);
-- removes processed port from the top of ranking queue and returns the port id
function unlist_first_port return port_id;
-- Returns True on success; stores value in global external_repository
function located_external_repository return Boolean;
-- Returns the value of the stored external repository
function top_external_repository return String;
-- If performing a limited build run (likely 99% of the use cases), only
-- the queued packages will be checked. The checks are limited to finding
-- options changes and dependency changes. Obsolete packages (related or
-- unrelated to upcoming build) are not removed; this would occur in
-- clean_repository(). These old packages will not interfere at this step.
procedure limited_sanity_check
(repository : String;
dry_run : Boolean;
rebuild_compiler : Boolean;
rebuild_binutils : Boolean;
suppress_remote : Boolean;
major_release : String;
architecture : supported_arch);
-- Unconditionally copies web assets to <log directory/report directory
-- It also provides an initial summary.json data file just the report has something to load
procedure initialize_web_report (num_builders : builders);
-- Kicks off curses or sets color support off. Do it before
-- calling parallel_bulk_run.
procedure initialize_display (num_builders : builders);
-- Kick off bulk run using the given number of builders
-- The rank_queue and all_ports must be already set up (it's recommended
-- To eliminate the ignored ports and subsequent skips first.
procedure parallel_bulk_run (num_builders : builders; sysrootver : sysroot_characteristics);
-- Explodes the buildsheet after applying directives, and returns True if all the subpackges
-- were successfully built. Exposes for use by test mode from pilot
function build_subpackages
(builder : builders;
sequence_id : port_id;
sysrootver : sysroot_characteristics;
interactive : Boolean := False;
enterafter : String := "") return Boolean;
function skip_verified (id : port_id) return Boolean;
-- Generic parse/transform routine for a given buildsheet or specification file
-- With a specification file.
procedure parse_and_transform_buildsheet
(specification : in out Port_Specification.Portspecs;
successful : out Boolean;
buildsheet : String;
variant : String;
portloc : String;
excl_targets : Boolean;
avoid_dialog : Boolean;
for_webpage : Boolean;
sysrootver : sysroot_characteristics);
-- Using a populated package_list, cross off all package names that are found in the current
-- all_ports data. Whatever is left represents obsolete packages which are then removed.
procedure eliminate_obsolete_packages;
-- Using a populated package list, print out all subpackages for each package
procedure list_subpackages_of_queued_ports;
private
package PM renames Parameters;
type hook_type is (run_start, run_end, pkg_success, pkg_failure, pkg_skipped, pkg_ignored);
type dim_hooks is array (hook_type) of Boolean;
type dim_hooksloc is array (hook_type) of HT.Text;
type machine_state is (idle, tasked, busy, done_failure, done_success, shutdown);
type dim_instruction is array (builders) of port_id;
type dim_builder_state is array (builders) of machine_state;
active_hook : dim_hooks := (False, False, False, False, False, False);
hook_location : constant dim_hooksloc :=
(HT.SUS (PM.raven_confdir & "/hook_run_start"),
HT.SUS (PM.raven_confdir & "/hook_run_end"),
HT.SUS (PM.raven_confdir & "/hook_pkg_success"),
HT.SUS (PM.raven_confdir & "/hook_pkg_failure"),
HT.SUS (PM.raven_confdir & "/hook_pkg_skipped"),
HT.SUS (PM.raven_confdir & "/hook_pkg_ignored"));
-- History log entries average less than 200 bytes. Allot more than twice this amount.
kfile_unit_maxsize : constant Positive := 512;
-- Each history segment is limited to this many log lines
kfile_units_limit : constant Positive := 500;
subtype filearch is String (1 .. 11);
subtype impulse_range is Integer range 1 .. 500;
subtype kfile_content is String (1 .. kfile_unit_maxsize * kfile_units_limit);
type progress_history is
record
segment : Natural := 0;
segment_count : Natural := 0;
log_entry : Natural := 0;
last_index : Natural := 0;
last_written : Natural := 0;
content : kfile_content;
end record;
type package_abi is
record
calculated_abi : HT.Text;
calculated_alt_abi : HT.Text;
calc_abi_noarch : HT.Text;
calc_alt_abi_noarch : HT.Text;
end record;
type subpackage_identifier is
record
id : port_index;
subpackage : HT.Text;
end record;
package subpackage_queue is new CON.Vectors
(Element_Type => subpackage_identifier,
Index_Type => port_index);
pkgscan_progress : dim_progress := (others => 0);
pkgscan_total : Natural := 0;
history : progress_history;
abi_formats : package_abi;
curses_support : Boolean := False;
external_repository : HT.Text;
-- Debugging purposes only, can be turned on by environment variable
debug_dep_check : Boolean := False;
debug_opt_check : Boolean := False;
-- Return true if file is executable (platform-specific)
function file_is_executable (filename : String) return Boolean;
procedure run_hook (hook : hook_type; envvar_list : String);
procedure run_package_hook (hook : hook_type; id : port_id);
function nv (name, value : String) return String;
function nv (name : String; value : Integer) return String;
procedure assimulate_substring (history : in out progress_history; substring : String);
procedure handle_first_history_entry;
procedure check_history_segment_capacity;
procedure delete_rank (id : port_id);
function still_ranked (id : port_id) return Boolean;
function rank_arrow (id : port_id) return ranking_crate.Cursor;
function get_swap_status return Float;
function swapinfo_command return String;
function nothing_left (num_builders : builders) return Boolean;
function shutdown_recommended (active_builders : Positive) return Boolean;
procedure write_history_json;
procedure write_summary_json
(active : Boolean;
states : dim_builder_state;
num_builders : builders;
num_history_files : Natural);
procedure record_history_skipped
(elapsed : String;
bucket : String;
origin : String;
reason : String);
procedure record_history_built
(elapsed : String;
slave_id : builders;
bucket : String;
origin : String;
duration : String);
procedure record_history_failed
(elapsed : String;
slave_id : builders;
bucket : String;
origin : String;
duration : String;
die_phase : String;
skips : Natural);
-- This calculates the ABI for the platform and stores it. The value is
-- used by passed_abi_check()
procedure establish_package_architecture (release : String; architecture : supported_arch);
-- Use file to determine arch on ELF platforms
function isolate_arch_from_file_type (fileinfo : String) return filearch;
-- Use file to dtermine arch on MacOS
function isolate_arch_from_macho_file (fileinfo : String) return filearch;
-- This function returns "True" if the scanned dependencies match exactly
-- what the current ports tree has.
function passed_dependency_check
(subpackage : String;
query_result : HT.Text;
id : port_id) return Boolean;
-- Turn on option and dependency debug checks programmatically
procedure activate_debugging_code;
-- The result of the dependency query giving "id" port_id
function result_of_dependency_query
(repository : String;
id : port_id;
subpackage : String) return HT.Text;
-- Dedicated progress meter for prescanning packages
function package_scan_progress return String;
-- For each package in the query, check the ABI and options (this is the
-- only time they are checked). If those pass, query the dependencies,
-- store the result, and check them. Set the "deletion" flag as needed.
-- The dependency check is NOT performed yet.
procedure initial_package_scan (repository : String; id : port_id; subpackage : String);
-- Same as above, but for packages in the external repository
procedure remote_package_scan (id : port_id; subpackage : String);
-- Using the same make_queue as was used to scan the ports, use tasks (up to 32) to do the
-- initial scanning of the ports, including getting the pkg dependency query.
procedure parallel_package_scan
(repository : String;
remote_scan : Boolean;
show_progress : Boolean);
-- The port build succeeded, so remove the "blocked_by" designation
-- for all the immediate reverse dependencies.
-- Remove the port from the queue when this is done.
procedure cascade_successful_build (id : port_id);
-- This function returns "True" if the scanned package has the expected
-- package ABI, e.g. dragonfly:4.6:x86:64, freebsd:10:amd64
function passed_abi_check
(repository : String;
id : port_id;
subpackage : String;
skip_exist_check : Boolean := False) return Boolean;
-- This function returns "True" if the scanned options exactly match
-- the options in the already-built package. Usually it's already known
-- that a package exists before the function is called, but an existence
-- check will be performed just in case (failure returns "False")
function passed_option_check
(repository : String;
id : port_id;
subpackage : String;
skip_exist_check : Boolean := False) return Boolean;
-- Before starting to build a port, lock it. This is required for
-- parallel building.
procedure lock_package (id : port_id);
-- Returns the highly priority buildable port
function top_buildable_port return port_id;
-- removes processed port from the ranking queue.
procedure unlist_port (id : port_id);
end PortScan.Operations;
|
-- WORDS, a Latin dictionary, by Colonel William Whitaker (USAF, Retired)
--
-- Copyright William A. Whitaker (1936–2010)
--
-- This is a free program, which means it is proper to copy it and pass
-- it on to your friends. Consider it a developmental item for which
-- there is no charge. However, just for form, it is Copyrighted
-- (c). Permission is hereby freely given for any and all use of program
-- and data. You can sell it as your own, but at least tell me.
--
-- This version is distributed without obligation, but the developer
-- would appreciate comments and suggestions.
--
-- All parts of the WORDS system, source code and data files, are made freely
-- available to anyone who wishes to use them, for whatever purpose.
with Ada.Text_IO;
with Latin_Utils.Dictionary_Package; use Latin_Utils.Dictionary_Package;
with Latin_Utils.Config; use Latin_Utils.Config;
with Latin_Utils.Inflections_Package; use Latin_Utils.Inflections_Package;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Words_Engine.Explanation_Package; use Words_Engine.Explanation_Package;
package Words_Engine.List_Package is
-- SCROLL_LINE_NUMBER : INTEGER := 0;
-- OUTPUT_SCROLL_COUNT : INTEGER := 0;
--
type Word_Analysis is private;
function Analyse_Word (Pa : Parse_Array;
Pa_Last : Integer;
Raw_Word : String;
Xp : Explanations)
return Word_Analysis;
procedure List_Stems (Configuration : Configuration_Type;
Output : Ada.Text_IO.File_Type;
WA : Word_Analysis;
Input_Line : String);
procedure Unknown_Search (Unknown : in String;
Unknown_Count : out Dict_IO.Count);
procedure List_Neighborhood
(Output : Ada.Text_IO.File_Type;
Input_Word : String);
private
type Stem_Inflection_Record is
record
Stem : Stem_Type := Null_Stem_Type;
Ir : Inflection_Record := Null_Inflection_Record;
end record;
Stem_Inflection_Array_Size : constant := 12;
Stem_Inflection_Array_Array_Size : constant := 40;
type Stem_Inflection_Array is
array (Integer range <>) of Stem_Inflection_Record;
type Stem_Inflection_Array_Array is array (Integer range <>)
of Stem_Inflection_Array (1 .. Stem_Inflection_Array_Size);
type Dictionary_MNPC_Record is record
D_K : Dictionary_Kind := Default_Dictionary_Kind;
MNPC : MNPC_Type := Null_MNPC;
De : Dictionary_Entry := Null_Dictionary_Entry;
end record;
Dictionary_MNPC_Array_Size : constant := 40;
type Dictionary_MNPC_Array is array (1 .. Dictionary_MNPC_Array_Size)
of Dictionary_MNPC_Record;
type Word_Analysis is
record
Stem_IAA : Stem_Inflection_Array_Array
(1 .. Stem_Inflection_Array_Array_Size);
Dict : Dictionary_MNPC_Array;
I_Is_Pa_Last : Boolean;
Unknowns : Boolean;
The_Word : Unbounded_String;
Was_Trimmed : Boolean;
Xp : Explanations;
end record;
end Words_Engine.List_Package;
|
with Limited_With4;
package Limited_With4_Pkg is
P1 : Limited_With4.Ptr1 := Limited_With4.Proc1'Access;
P2 : Limited_With4.Ptr2 := Limited_With4.Proc2'Access;
type Rec12 is record
I : Integer;
R : Limited_With4.Rec1;
end record;
type Rec22 is record
I : Integer;
R : Limited_With4.Rec2;
end record;
end Limited_With4_Pkg;
|
with Text_IO;
with Ada.Command_Line;
with AWS.Client;
with AWS.Headers;
with AWS.Response;
with AWS.Messages;
use AWS.Messages;
procedure main is
hdrs : AWS.Headers.List := AWS.Headers.Empty_List;
server_url : constant String := Ada.Command_Line.Argument(1);
player_key : constant String := Ada.Command_Line.Argument(2);
result : AWS.Response.Data;
status : AWS.Messages.Status_Code;
begin
Text_IO.Put_Line("ServerURL: " & server_url & ", PlayerKey: " & player_key);
AWS.Headers.Add(hdrs, "Content-Type", "text/plain");
result := AWS.Client.Post(URL => server_url, Data => player_key, Headers => hdrs);
status := AWS.Response.Status_Code(result);
if status = AWS.Messages.S200 then
Text_IO.Put_Line("Server response: " & AWS.Response.Message_Body(result));
else
Text_IO.Put_Line("Unexpected server response:");
Text_IO.Put_Line("HTTP code: " & AWS.Messages.Image(status) & " (" & AWS.Messages.Reason_Phrase(status) & ")");
Text_IO.Put_Line("Response body: " & AWS.Response.Message_Body(result));
Ada.Command_Line.Set_Exit_Status(2);
end if;
end main;
|
-------------------------------------------------------------------------------
-- --
-- 0MQ Ada-binding --
-- --
-- Z M Q . S O C K E T S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2020-2030, per.s.sandberg@bahnhof.se --
-- --
-- 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 ZMQ.Low_Level;
with Interfaces.C.Strings;
with GNAT.OS_Lib;
with GNAT.Source_Info;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package body ZMQ.Sockets is
use Interfaces.C.Strings;
use Interfaces.C;
use System;
----------------
-- Initialize --
----------------
not overriding procedure Initialize
(This : in out Socket;
With_Context : Contexts.Context;
Kind : Socket_Type)
is
begin
if With_Context.GetImpl = Null_Address then
raise ZMQ_Error with "Contecxt Not Initialized";
end if;
if This.C /= Null_Address then
raise ZMQ_Error with "Socket Initialized";
end if;
This.C := Low_Level.zmq_socket (With_Context.GetImpl,
Socket_Type'Pos (Kind));
if This.C = Null_Address then
raise ZMQ_Error with "Unable to initialize";
end if;
end Initialize;
----------
-- Bind --
----------
not overriding procedure Bind
(This : in out Socket;
Address : String)
is
Addr : chars_ptr := Interfaces.C.Strings.New_String (Address);
Ret : int;
begin
Ret := Low_Level.zmq_bind (This.C, Addr);
Free (Addr);
if Ret /= 0 then
raise ZMQ_Error with Error_Message (GNAT.OS_Lib.Errno) & " in " &
GNAT.Source_Info.Enclosing_Entity & "(" & Address & ")";
end if;
end Bind;
procedure Bind (This : in out Socket;
Address : Ada.Strings.Unbounded.Unbounded_String) is
begin
This.Bind (To_String (Address));
end Bind;
not overriding procedure Unbind
(This : in out Socket;
Address : String)
is
Addr : chars_ptr := Interfaces.C.Strings.New_String (Address);
Ret : int;
begin
Ret := Low_Level.zmq_unbind (This.C, Addr);
Free (Addr);
if Ret /= 0 then
raise ZMQ_Error with Error_Message (GNAT.OS_Lib.Errno) & " in " &
GNAT.Source_Info.Enclosing_Entity & "(" & Address & ")";
end if;
end Unbind;
procedure Unbind (This : in out Socket;
Address : Ada.Strings.Unbounded.Unbounded_String) is
begin
This.Unbind (To_String (Address));
end Unbind;
procedure Setsockopt (This : in out Socket;
Option : Interfaces.C.int;
Value : System.Address;
Value_Size : Natural) is
Ret : int;
begin
Ret := Low_Level.zmq_setsockopt
(This.C,
Option,
Value,
size_t (Value_Size));
if Ret /= 0 then
raise ZMQ_Error with Error_Message (GNAT.OS_Lib.Errno) & " in " &
GNAT.Source_Info.Enclosing_Entity & "(" & Option'Img & ")";
end if;
end Setsockopt;
----------------
-- setsockopt --
----------------
not overriding procedure Setsockopt
(This : in out Socket;
Option : Interfaces.C.int;
Value : String)
is
begin
This.Setsockopt (Option, Value'Address, Value'Length);
end Setsockopt;
----------------
-- setsockopt --
----------------
not overriding procedure Setsockopt
(This : in out Socket;
Option : Interfaces.C.int;
Value : Boolean)
is
begin
This.Setsockopt (Option, Value'Address, 1);
end Setsockopt;
----------------
-- setsockopt --
----------------
not overriding procedure Setsockopt
(This : in out Socket;
Option : Interfaces.C.int;
Value : Integer)
is
begin
This.Setsockopt (Option, Value'Address, 4);
end Setsockopt;
not overriding procedure Setsockopt
(This : in out Socket;
Option : Interfaces.C.int;
Value : Long_Long_Integer)
is
begin
This.Setsockopt (Option, Value'Address, 8);
end Setsockopt;
----------------
-- setsockopt --
----------------
not overriding
procedure Setsockopt
(This : in out Socket;
Option : Interfaces.C.int;
Value : Ada.Streams.Stream_Element_Array)
is
begin
This.Setsockopt (Option, Value (Value'First)'Address, Value'Length);
end Setsockopt;
not overriding procedure Setsockopt
(This : in out Socket;
Option : Interfaces.C.int;
Value : Interfaces.C.unsigned_long) is
begin
This.Setsockopt (Option, Value'Address, 8);
end Setsockopt;
not overriding procedure Setsockopt
(This : in out Socket;
Option : Interfaces.C.int;
Value : Duration) is
begin
if Value = Duration'Last or Value = -1.0 then
This.Setsockopt (Option, Integer'(-1));
else
This.Setsockopt (Option, Integer (Value * 1000.0));
end if;
end Setsockopt;
not overriding
-------------
-- Connect --
-------------
procedure Connect
(This : in out Socket;
Address : String)
is
Addr : chars_ptr := Interfaces.C.Strings.New_String (Address);
Ret : int;
begin
Ret := Low_Level.zmq_connect (This.C, Addr);
Free (Addr);
if Ret /= 0 then
raise ZMQ_Error with Error_Message (GNAT.OS_Lib.Errno) & " in " &
GNAT.Source_Info.Enclosing_Entity & "(" & Address & ")";
end if;
end Connect;
procedure Connect (This : in out Socket;
Address : Ada.Strings.Unbounded.Unbounded_String) is
begin
This.Connect (To_String (Address));
end Connect;
----------
-- Send --
----------
not overriding procedure Send
(This : in out Socket;
Msg : Messages.Message'Class;
Flags : Socket_Flags := No_Flags)
is
Ret : int;
begin
Ret := Low_Level.zmq_msg_send (Msg.GetImpl, This.C, int (Flags));
if Ret = -1 then
raise ZMQ_Error with Error_Message (GNAT.OS_Lib.Errno) & " in " &
GNAT.Source_Info.Enclosing_Entity;
end if;
end Send;
not overriding
procedure Send (This : in out Socket;
Msg : String;
Flags : Socket_Flags := No_Flags) is
begin
This.Send (Msg'Address, Msg'Length, Flags);
end Send;
not overriding
procedure Send (This : in out Socket;
Msg : Ada.Streams.Stream_Element_Array;
Flags : Socket_Flags := No_Flags) is
begin
This.Send (Msg'Address, Msg'Length, Flags);
end Send;
not overriding
procedure Send (This : in out Socket;
Msg : Ada.Strings.Unbounded.Unbounded_String;
Flags : Socket_Flags := No_Flags) is
M : Messages.Message;
begin
M.Initialize (Ada.Strings.Unbounded.To_String (Msg));
This.Send (M, Flags);
end Send;
procedure Send_Generic (This : in out Socket;
Msg : Element;
Flags : Socket_Flags := No_Flags) is
begin
This.Send
(Msg'Address,
(Msg'Size + Ada.Streams.Stream_Element'Size - 1) /
Ada.Streams.Stream_Element'Size,
Flags);
end Send_Generic;
not overriding
procedure Send (This : in out Socket;
Msg_Address : System.Address;
Msg_Length : Natural;
Flags : Socket_Flags := No_Flags) is
Ret : int;
begin
Ret := Low_Level.zmq_send
(This.C, Msg_Address, Interfaces.C.size_t (Msg_Length), int (Flags));
if Ret = -1 then
raise ZMQ_Error with Error_Message (GNAT.OS_Lib.Errno) & " in " &
GNAT.Source_Info.Enclosing_Entity;
end if;
end Send;
-- -----------
-- -- flush --
-- -----------
--
-- not overriding procedure flush
-- (This : in out Socket)
-- is
-- ret : int;
-- begin
-- ret := Low_Level.zmq_flush (This.c);
-- if ret /= 0 then
-- raise ZMQ_Error with Error_Message (GNAT.OS_Lib.Errno) & " in "
-- & GNAT.Source_Info.Enclosing_Entity;
-- end if;
-- end flush;
----------
-- recv --
----------
not overriding procedure Recv
(This : in Socket;
Msg : in out Messages.Message'Class;
Flags : Socket_Flags := No_Flags)
is
Ret : int;
begin
Ret := Low_Level.zmq_msg_recv (Msg.GetImpl,
This.C,
int (Flags));
if Ret = -1 then
raise ZMQ_Error with Error_Message (GNAT.OS_Lib.Errno) & " in "
& GNAT.Source_Info.Enclosing_Entity;
end if;
end Recv;
procedure Recv (This : in Socket;
Flags : Socket_Flags := No_Flags) is
Dummy_Msg : Messages.Message;
begin
Dummy_Msg.Initialize (0);
This.Recv (Dummy_Msg, Flags);
end Recv;
not overriding
function Recv (This : in Socket;
Flags : Socket_Flags := No_Flags) return String is
Msg : Messages.Message;
begin
Msg.Initialize (0);
This.Recv (Msg, Flags);
return Ret : String (1 .. Msg.GetSize) do
Ret := Msg.GetData;
end return;
end Recv;
procedure Recv (This : in Socket;
Msg : out Ada.Strings.Unbounded.Unbounded_String;
Flags : Socket_Flags := No_Flags) is
begin
Msg := Ada.Strings.Unbounded.To_Unbounded_String (This.Recv (Flags));
end Recv;
function Recv
(This : in Socket;
Max_Length : Natural;
Flags : Socket_Flags := No_Flags)
return String is
Msg : Messages.Message;
begin
This.Recv (Msg, Flags);
if Msg.GetSize > Max_Length then
raise Constraint_Error with "message size out of bounds" &
Msg.GetSize'Img & ">" & Max_Length'Img;
end if;
return Ret : String (1 .. Msg.GetSize) do
Ret := Msg.GetData;
end return;
end Recv;
not overriding
function Recv (This : in Socket;
Flags : Socket_Flags := No_Flags)
return Ada.Strings.Unbounded.Unbounded_String is
begin
return Ret : Ada.Strings.Unbounded.Unbounded_String do
This.Recv (Ret, Flags);
end return;
end Recv;
--------------
-- Finalize --
--------------
overriding procedure Finalize
(This : in out Socket)
is
Ret : int;
begin
if This.C /= Null_Address then
Ret := Low_Level.zmq_close (This.C);
if Ret /= 0 then
raise ZMQ_Error with Error_Message (GNAT.OS_Lib.Errno);
end if;
This.C := Null_Address;
end if;
end Finalize;
procedure Proxy (Frontend : not null access Socket;
Backend : not null access Socket'Class;
Capture : access Socket'Class) is
Ret : int;
begin
Ret := Low_Level.zmq_proxy
(Frontend.C,
Backend.C,
(if Capture /= null then Capture.C else System.Null_Address));
if Ret /= 0 then
raise ZMQ_Error with Error_Message (GNAT.OS_Lib.Errno);
end if;
end Proxy;
not overriding
procedure Set_High_Water_Mark_For_Outbound_Messages
(This : in out Socket;
Messages : Natural := 1_000)
is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_SNDHWM, Messages);
end Set_High_Water_Mark_For_Outbound_Messages;
not overriding
procedure Set_High_Water_Mark_For_Inbound_Messages
(This : in out Socket;
Messages : Natural := 1_000)
is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_RCVHWM, Messages);
end Set_High_Water_Mark_For_Inbound_Messages;
not overriding
procedure Set_Disk_Offload_Size (This : in out Socket;
Value : Natural) is
begin
null; -- This.setsockopt (ZMQ.Low_Level.Defs.SWAP, Value);
end Set_Disk_Offload_Size;
not overriding
procedure Set_IO_Thread_Affinity (This : in out Socket;
Threads : Thread_Bitmap) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_AFFINITY, Threads'Address, 4);
end Set_IO_Thread_Affinity;
not overriding
procedure Set_Socket_Identity
(This : in out Socket;
Value : Ada.Streams.Stream_Element_Array) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_IDENTITY, Value);
end Set_Socket_Identity;
procedure Set_Socket_Identity
(This : in out Socket;
Value : String) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_IDENTITY, Value);
end Set_Socket_Identity;
not overriding
procedure Establish_Message_Filter (This : in out Socket;
Value : String) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_SUBSCRIBE, Value);
end Establish_Message_Filter;
not overriding
procedure Establish_Message_Filter
(This : in out Socket;
Value : Ada.Streams.Stream_Element_Array) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_SUBSCRIBE, Value);
end Establish_Message_Filter;
procedure Establish_Message_Filter
(This : in out Socket;
Value : Ada.Strings.Unbounded.Unbounded_String) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_SUBSCRIBE, To_String (Value));
end Establish_Message_Filter;
not overriding
procedure Remove_Message_Filter (This : in out Socket;
Value : String) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_UNSUBSCRIBE, Value);
end Remove_Message_Filter;
procedure Remove_Message_Filter
(This : in out Socket;
Value : Ada.Strings.Unbounded.Unbounded_String) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_UNSUBSCRIBE, To_String (Value));
end Remove_Message_Filter;
procedure Remove_Message_Filter
(This : in out Socket;
Value : Ada.Streams.Stream_Element_Array) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_UNSUBSCRIBE, Value);
end Remove_Message_Filter;
not overriding
procedure Set_Multicast_Data_Rate
(This : in out Socket;
Kilobits_Per_Second : Natural := 100) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_RATE, Kilobits_Per_Second);
end Set_Multicast_Data_Rate;
not overriding
procedure Set_Multicast_Recovery_Interval (This : in out Socket;
Time : Duration := 10.0) is
begin
This.Setsockopt
(ZMQ.Low_Level.Defs.ZMQ_RECOVERY_IVL, Integer (Time * 1000));
end Set_Multicast_Recovery_Interval;
not overriding
procedure Set_Multicast_Loopback (This : in out Socket;
Enable : Boolean) is
begin
null; -- This.setsockopt (ZMQ.Low_Level.Defs.ZMQ_HWM, Enable);
end Set_Multicast_Loopback;
not overriding
procedure Set_Kernel_Transmit_Buffer_Size (This : in out Socket;
Bytes : Natural) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_SNDBUF, Bytes);
end Set_Kernel_Transmit_Buffer_Size;
not overriding
procedure Set_Kernel_Receive_Buffer_Size (This : in out Socket;
Bytes : Natural) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_RCVBUF, Bytes);
end Set_Kernel_Receive_Buffer_Size;
not overriding
function Get_Linger_Period_For_Socket_Shutdown
(This : Socket) return Duration is
begin
return This.Getsockopt (ZMQ.Low_Level.Defs.ZMQ_LINGER);
end Get_Linger_Period_For_Socket_Shutdown;
not overriding
procedure Set_Linger_Period_For_Socket_Shutdown
(This : in out Socket;
Period : Duration := Duration'Last) is
begin
This.Setsockopt (ZMQ.Low_Level.Defs.ZMQ_LINGER, Period);
end Set_Linger_Period_For_Socket_Shutdown;
not overriding
function Get_Reconnection_Interval
(This : Socket) return Duration is
begin
return Duration (Natural'(This.Getsockopt
(ZMQ.Low_Level.Defs.ZMQ_RECONNECT_IVL))) / 1000.0;
end Get_Reconnection_Interval;
not overriding
procedure Set_Reconnection_Interval
(This : in out Socket;
Period : Duration := 0.100) is
begin
if Period < 0.0 then
This.Setsockopt
(ZMQ.Low_Level.Defs.ZMQ_RECONNECT_IVL, Integer'(-1));
else
This.Setsockopt
(ZMQ.Low_Level.Defs.ZMQ_RECONNECT_IVL, Natural (Period * 1000.0));
end if;
end Set_Reconnection_Interval;
not overriding
function Get_Maximum_Reconnection_Interval
(This : Socket) return Duration is
begin
return Duration (Natural'(This.Getsockopt
(ZMQ.Low_Level.Defs.ZMQ_RECONNECT_IVL))) / 1000.0;
end Get_Maximum_Reconnection_Interval;
not overriding
procedure Set_Maximum_Reconnection_Interval
(This : in out Socket;
Period : Duration := 0.0) is
begin
if Period < 0.0 then
This.Setsockopt
(Low_Level.Defs.ZMQ_RECONNECT_IVL, Integer'(-1));
else
This.Setsockopt
(Low_Level.Defs.ZMQ_RECONNECT_IVL, Natural (Period * 1000.0));
end if;
end Set_Maximum_Reconnection_Interval;
not overriding
function Get_Maximum_Length_Of_The_Queue_Of_Outstanding_Connections
(This : Socket) return Natural is
begin
return This.Getsockopt (Low_Level.Defs.ZMQ_BACKLOG);
end Get_Maximum_Length_Of_The_Queue_Of_Outstanding_Connections;
not overriding
procedure Set_Maximum_Length_Of_The_Queue_Of_Outstanding_Connections
(This : in out Socket;
Connections : Natural := 100) is
begin
This.Setsockopt (Low_Level.Defs.ZMQ_BACKLOG, Connections);
end Set_Maximum_Length_Of_The_Queue_Of_Outstanding_Connections;
not overriding
function Get_Maximum_Acceptable_Inbound_Message_Size
(This : Socket) return Long_Long_Integer is
begin
return This.Getsockopt (Low_Level.Defs.ZMQ_MAXMSGSIZE);
end Get_Maximum_Acceptable_Inbound_Message_Size;
not overriding
procedure Set_Maximum_Acceptable_Inbound_Message_Size
(This : in out Socket;
Bytes : Long_Long_Integer := 0) is
begin
This.Setsockopt (Low_Level.Defs.ZMQ_MAXMSGSIZE, Bytes);
end Set_Maximum_Acceptable_Inbound_Message_Size;
not overriding
function Get_Maximum_Network_Hops_For_Multicast_Packets
(This : Socket) return Positive is
begin
return This.Getsockopt (Low_Level.Defs.ZMQ_MULTICAST_HOPS);
end Get_Maximum_Network_Hops_For_Multicast_Packets;
not overriding
procedure Set_Maximum_Network_Hops_For_Multicast_Packets
(This : in out Socket;
Network_Hops : Positive := 1) is
begin
This.Setsockopt (Low_Level.Defs.ZMQ_MULTICAST_HOPS, Network_Hops);
end Set_Maximum_Network_Hops_For_Multicast_Packets;
not overriding
function Get_Recieve_Timeout
(This : Socket) return Duration is
begin
return Duration (Integer'(This.Getsockopt
(Low_Level.Defs.ZMQ_RCVTIMEO))) * 1000.0;
end Get_Recieve_Timeout;
not overriding
procedure Set_Recieve_Timeout
(This : in out Socket;
Timeout : Duration := Duration'Last) is
begin
if Timeout = Duration'Last then
This.Setsockopt (Low_Level.Defs.ZMQ_RCVTIMEO, Integer (-1));
else
This.Setsockopt
(Low_Level.Defs.ZMQ_RCVTIMEO, Integer (Timeout * 1000.0));
end if;
end Set_Recieve_Timeout;
not overriding
function Get_Send_Timeout
(This : Socket) return Duration is
begin
return Duration (Integer'(This.Getsockopt
(Low_Level.Defs.ZMQ_SNDTIMEO))) * 1000.0;
end Get_Send_Timeout;
not overriding
procedure Set_Send_Timeout
(This : in out Socket;
Timeout : Duration := Duration'Last) is
begin
if Timeout = Duration'Last then
This.Setsockopt (Low_Level.Defs.ZMQ_SNDTIMEO, Integer (-1));
else
This.Setsockopt
(Low_Level.Defs.ZMQ_SNDTIMEO, Integer (Timeout * 1000.0));
end if;
end Set_Send_Timeout;
not overriding
function Get_Use_IPv4_Only
(This : Socket) return Boolean is
begin
return This.Getsockopt (Low_Level.Defs.ZMQ_IPV4ONLY);
end Get_Use_IPv4_Only;
not overriding
procedure Set_Use_IPv4_Only
(This : in out Socket;
IPv4 : Boolean := True) is
begin
This.Setsockopt (Low_Level.Defs.ZMQ_IPV4ONLY, IPv4);
end Set_Use_IPv4_Only;
-- ========================================================================
-- ========================================================================
function Get_Impl (This : in Socket) return System.Address is
begin
return This.C;
end Get_Impl;
-------------
not overriding
procedure Getsockopt (This : in Socket;
Option : Interfaces.C.int;
Value : System.Address;
Value_Size : in out Natural) is
Ret : int;
Value_Size_I : aliased size_t;
begin
Ret := Low_Level.zmq_getsockopt
(This.C,
Option,
Value,
Value_Size_I'Access);
Value_Size := Natural (Value_Size_I);
if Ret /= 0 then
raise ZMQ_Error with Error_Message (GNAT.OS_Lib.Errno) & " in " &
GNAT.Source_Info.Enclosing_Entity & "(" & Option'Img & ")";
end if;
end Getsockopt;
not overriding
function Getsockopt (This : in Socket;
Option : Interfaces.C.int) return unsigned_long is
Dummy_Value_Size : Natural := unsigned_long'Size / System.Storage_Unit;
begin
return Ret : unsigned_long do
This.Getsockopt (Option, Ret'Address, Dummy_Value_Size);
if Dummy_Value_Size /= 8 then
raise Program_Error with "Invalid getsockopt for this type";
end if;
end return;
end Getsockopt;
function Getsockopt (This : in Socket;
Option : Interfaces.C.int) return String is
Buffer : aliased String (1 .. MAX_OPTION_SIZE);
Value_Size : Natural := Buffer'Length;
begin
This.Getsockopt (Option, Buffer'Address, Value_Size);
return Buffer (1 .. Value_Size);
end Getsockopt;
not overriding
function Getsockopt (This : in Socket;
Option : Interfaces.C.int) return Boolean is
begin
return Ret : Boolean do
Ret := unsigned_long'(This.Getsockopt (Option)) /= 0;
end return;
end Getsockopt;
not overriding
function Getsockopt (This : in Socket;
Option : Interfaces.C.int) return Integer is
begin
return Ret : Integer do
Ret := Integer (unsigned_long'(This.Getsockopt (Option)));
end return;
end Getsockopt;
function Getsockopt
(This : in Socket;
Option : Interfaces.C.int) return Long_Long_Integer is
begin
return Ret : Long_Long_Integer do
Ret := Long_Long_Integer (unsigned_long'(This.Getsockopt (Option)));
end return;
end Getsockopt;
not overriding
function Getsockopt
(This : in Socket;
Option : Interfaces.C.int) return Ada.Streams.Stream_Element_Array is
Buffer : aliased Stream_Element_Array (1 .. MAX_OPTION_SIZE);
Value_Size : Ada.Streams.Stream_Element_Offset := Buffer'Length;
begin
This.Getsockopt (Option, Buffer'Address, Natural (Value_Size));
return Buffer (1 .. Value_Size);
end Getsockopt;
not overriding
function Getsockopt
(This : in Socket;
Option : Interfaces.C.int) return Duration is
begin
return Duration (Integer'(This.Getsockopt (Option))) * 1000.0;
end Getsockopt;
function More_Message_Parts_To_Follow (This : Socket) return Boolean is
begin
return Ret : Boolean do
Ret := This.Getsockopt (ZMQ.Low_Level.Defs.ZMQ_RCVMORE);
end return;
end More_Message_Parts_To_Follow;
function Get_High_Water_Mark_For_Outbound_Messages
(This : Socket) return Natural is
begin
return This.Getsockopt (ZMQ.Low_Level.Defs.ZMQ_SNDHWM);
end Get_High_Water_Mark_For_Outbound_Messages;
function Get_High_Water_Mark_For_Inbound_Messages
(This : Socket) return Natural is
begin
return This.Getsockopt (ZMQ.Low_Level.Defs.ZMQ_RCVHWM);
end Get_High_Water_Mark_For_Inbound_Messages;
function Get_IO_Thread_Affinity (This : Socket) return Thread_Bitmap is
Value_Size : Natural := Thread_Bitmap'Size / System.Storage_Unit;
begin
return Ret : Thread_Bitmap do
This.Getsockopt
(ZMQ.Low_Level.Defs.ZMQ_AFFINITY, Ret'Address, Value_Size);
if Value_Size /= 8 then
raise Program_Error with "Invalid bitmap size " & Value_Size'Img;
end if;
end return;
end Get_IO_Thread_Affinity;
function Get_Socket_Identity
(This : Socket) return Ada.Streams.Stream_Element_Array is
begin
return This.Getsockopt (ZMQ.Low_Level.Defs.ZMQ_IDENTITY);
end Get_Socket_Identity;
function Get_Multicast_Data_Rate (This : Socket) return Natural is
begin
return This.Getsockopt (ZMQ.Low_Level.Defs.ZMQ_RATE);
end Get_Multicast_Data_Rate;
function Get_Multicast_Recovery_Interval (This : Socket) return Duration is
begin
return Duration
(unsigned_long'(
This.Getsockopt (ZMQ.Low_Level.Defs.ZMQ_RECOVERY_IVL)));
end Get_Multicast_Recovery_Interval;
function Get_Multicast_Loopback (This : Socket) return Boolean is
pragma Unreferenced (This);
begin
return False; -- This.getsockopt (ZMQ.Low_Level.Defs.ZMQ_MCAST_LOOP);
end Get_Multicast_Loopback;
function Get_Kernel_Transmit_Buffer_Size (This : Socket) return Natural is
begin
return This.Getsockopt (ZMQ.Low_Level.Defs.ZMQ_SNDBUF);
end Get_Kernel_Transmit_Buffer_Size;
function Get_Kernel_Receive_Buffer_Size (This : Socket) return Natural is
begin
return This.Getsockopt (ZMQ.Low_Level.Defs.ZMQ_RCVBUF);
end Get_Kernel_Receive_Buffer_Size;
not overriding function Retrieve_Socket_Type
(This : in Socket)
return Socket_Type is
begin
return Socket_Type'Val
(Natural'(This.Getsockopt (Low_Level.Defs.ZMQ_TYPE)));
end Retrieve_Socket_Type;
procedure Read
(Stream : in out Socket_Stream;
Item : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset) is
begin
raise Program_Error with "unimplemented function Read";
end Read;
procedure Write
(Stream : in out Socket_Stream;
Item : Ada.Streams.Stream_Element_Array) is
begin
raise Program_Error with "unimplemented function Write";
end Write;
procedure Read_Socket
(Stream : not null access Ada.Streams.Root_Stream_Type'Class;
S : out Socket) is
begin
raise Program_Error with "Sockets are not streameble";
end Read_Socket;
procedure Write_Socket
(Stream : not null access Ada.Streams.Root_Stream_Type'Class;
S : Socket) is
begin
raise Program_Error with "Sockets are not streameble";
end Write_Socket;
function Stream
(This : Socket)
return not null access Ada.Streams.Root_Stream_Type'Class is
begin
return This.S'Unrestricted_Access;
end Stream;
end ZMQ.Sockets;
|
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with AUnit.Assertions; use AUnit.Assertions;
with Libadalang.Analysis; use Libadalang.Analysis;
with Libadalang.Common; use Libadalang.Common;
with Missing.AUnit.Assertions; use Missing.AUnit.Assertions;
with Rejuvenation.Indentation; use Rejuvenation.Indentation;
with Rejuvenation.Simple_Factory; use Rejuvenation.Simple_Factory;
with Make_Ada; use Make_Ada;
package body Test_Indentation is
procedure Assert is new Generic_Assert (Integer);
-- Test Functions
procedure Test_No_Indentation (T : in out Test_Case'Class);
procedure Test_No_Indentation (T : in out Test_Case'Class) is
pragma Unreferenced (T);
begin
for Index in 0 .. 10 loop
declare
Actual_Spacing : constant String := Index * " ";
Instance : constant Analysis_Unit :=
Analyze_Fragment
(Make_Procedure_Call_Statement & Actual_Spacing &
Make_Procedure_Call_Statement,
Stmts_Rule);
begin
Assert
(Expected => 2, Actual => Instance.Root.Children_Count,
Message => "Two statements expected");
Assert
(Expected => No_Indentation,
Actual =>
Indentation_Of_Node
(Instance.Root.Child (Instance.Root.Last_Child_Index)),
Message => "Mismatch at " & Index'Image);
end;
end loop;
end Test_No_Indentation;
procedure Test_Indentation (T : in out Test_Case'Class);
procedure Test_Indentation (T : in out Test_Case'Class) is
pragma Unreferenced (T);
begin
for Index in 0 .. 10 loop
declare
Actual_Indentation : constant String := Index * " ";
Instance : constant Analysis_Unit :=
Analyze_Fragment
(ASCII.LF & Actual_Indentation & Make_Procedure_Call_Statement,
Call_Stmt_Rule);
begin
Assert
(Expected => Index,
Actual => Indentation_Of_Node (Instance.Root),
Message => "Mismatch at " & Index'Image);
end;
end loop;
end Test_Indentation;
procedure Test_Initial_Indentation (T : in out Test_Case'Class);
procedure Test_Initial_Indentation (T : in out Test_Case'Class) is
pragma Unreferenced (T);
begin
for Index in 0 .. 10 loop
declare
Actual_Indentation : constant String := Index * " ";
Instance : constant Analysis_Unit :=
Analyze_Fragment
(Actual_Indentation & Make_Procedure_Call_Statement,
Call_Stmt_Rule);
begin
Assert
(Expected => Index,
Actual => Indentation_Of_Node (Instance.Root),
Message => "Mismatch at " & Index'Image);
end;
end loop;
end Test_Initial_Indentation;
procedure Test_Root_On_Separate_Lines (T : in out Test_Case'Class);
procedure Test_Root_On_Separate_Lines (T : in out Test_Case'Class) is
pragma Unreferenced (T);
Instance : constant Analysis_Unit :=
Analyze_Fragment (Make_Procedure_Call_Statement, Call_Stmt_Rule);
begin
Assert
(Condition => Node_On_Separate_Lines (Instance.Root),
Message => "Expect that root is on separate lines");
end Test_Root_On_Separate_Lines;
-- Test plumbing
overriding function Name
(T : Indentation_Test_Case) return AUnit.Message_String
is
pragma Unreferenced (T);
begin
return AUnit.Format ("Indentation");
end Name;
overriding procedure Register_Tests (T : in out Indentation_Test_Case) is
begin
Registration.Register_Routine
(T, Test_No_Indentation'Access,
"No Indentation - Earlier node on same line");
Registration.Register_Routine
(T, Test_Indentation'Access, "Indentation");
Registration.Register_Routine
(T, Test_Initial_Indentation'Access,
"Initial Indentation - Node on first line / at beginning of text");
Registration.Register_Routine
(T, Test_Root_On_Separate_Lines'Access, "Root on separate lines");
end Register_Tests;
end Test_Indentation;
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . K N D _ C O N V --
-- --
-- B o d y --
-- --
-- $Revision: 15351 $
-- --
-- Copyright (c) 1995-2002, 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, 59 Temple Place --
-- - Suite 330, Boston, MA 02111-1307, 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 Ada Core Technologies Inc --
-- (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
with Asis.Set_Get;
with A4G.Knd_Conv; use A4G.Knd_Conv;
with A4G.Vcheck; use A4G.Vcheck;
package body Asis.Extensions.Flat_Kinds is
use Asis;
-----------------------
-- Flat_Element_Kind --
-----------------------
function Flat_Element_Kind
(Element : Asis.Element)
return Flat_Element_Kinds
is
begin
Check_Validity (Element, "Asis.Extensions.Flat_Kinds.Flat_Element_Kind");
return Flat_Element_Kinds (Asis.Set_Get.Int_Kind (Element));
end Flat_Element_Kind;
-------------------------------------------------
-- Flat Element Kinds Conversion Functions --
-------------------------------------------------
function Asis_From_Flat_Kind
(Flat_Kind : Flat_Element_Kinds)
return Asis.Element_Kinds
is
begin
return Asis_From_Internal_Kind (Internal_Element_Kinds (Flat_Kind));
end Asis_From_Flat_Kind;
function Pragma_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Pragma_Kinds
is
begin
return Pragma_Kind_From_Internal (Internal_Element_Kinds (Flat_Kind));
end Pragma_Kind_From_Flat;
function Defining_Name_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Defining_Name_Kinds
is
begin
return Defining_Name_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Defining_Name_Kind_From_Flat;
function Declaration_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Declaration_Kinds
is
begin
return Declaration_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Declaration_Kind_From_Flat;
function Definition_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Definition_Kinds
is
begin
return Definition_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Definition_Kind_From_Flat;
function Type_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Type_Kinds
is
begin
return Type_Kind_From_Internal (Internal_Element_Kinds (Flat_Kind));
end Type_Kind_From_Flat;
function Formal_Type_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Formal_Type_Kinds
is
begin
return Formal_Type_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Formal_Type_Kind_From_Flat;
function Access_Type_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Access_Type_Kinds
is
begin
return Access_Type_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Access_Type_Kind_From_Flat;
function Root_Type_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Root_Type_Kinds
is
begin
return Root_Type_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Root_Type_Kind_From_Flat;
function Constraint_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Constraint_Kinds
is
begin
return Constraint_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Constraint_Kind_From_Flat;
function Discrete_Range_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Discrete_Range_Kinds
is
begin
return Discrete_Range_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Discrete_Range_Kind_From_Flat;
function Expression_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Expression_Kinds
is
begin
return Expression_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Expression_Kind_From_Flat;
function Operator_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Operator_Kinds
is
begin
return Operator_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Operator_Kind_From_Flat;
function Attribute_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Attribute_Kinds
is
begin
return Attribute_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Attribute_Kind_From_Flat;
function Association_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Association_Kinds
is
begin
return Association_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Association_Kind_From_Flat;
function Statement_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Statement_Kinds
is
begin
return Statement_Kind_From_Internal (Internal_Element_Kinds (Flat_Kind));
end Statement_Kind_From_Flat;
function Path_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Path_Kinds
is
begin
return Path_Kind_From_Internal (Internal_Element_Kinds (Flat_Kind));
end Path_Kind_From_Flat;
function Clause_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Clause_Kinds
is
begin
return Clause_Kind_From_Internal (Internal_Element_Kinds (Flat_Kind));
end Clause_Kind_From_Flat;
function Representation_Clause_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Representation_Clause_Kinds
is
begin
return Representation_Clause_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Representation_Clause_Kind_From_Flat;
-------------------------------------
-- Additional Classification items --
-------------------------------------
-----------------------
-- Def_Operator_Kind --
-----------------------
function Def_Operator_Kind
(Op_Kind : Flat_Element_Kinds)
return Flat_Element_Kinds
is
begin
return Flat_Element_Kinds (Def_Operator_Kind
(Internal_Element_Kinds (Op_Kind)));
end Def_Operator_Kind;
end Asis.Extensions.Flat_Kinds;
|
with agar.gui.widget.box;
package agar.gui.widget.pane is
use type c.unsigned;
type type_t is (PANE_HORIZ, PANE_VERT);
for type_t use (PANE_HORIZ => 0, PANE_VERT => 1);
for type_t'size use c.unsigned'size;
pragma convention (c, type_t);
type pane_t is limited private;
type pane_access_t is access all pane_t;
pragma convention (c, pane_access_t);
type flags_t is new c.unsigned;
PANE_HFILL : constant flags_t := 16#001#;
PANE_VFILL : constant flags_t := 16#002#;
PANE_DIV1FILL : constant flags_t := 16#004#;
PANE_FRAME : constant flags_t := 16#008#;
PANE_FORCE_DIV1FILL : constant flags_t := 16#010#;
PANE_FORCE_DIV2FILL : constant flags_t := 16#020#;
PANE_DIV : constant flags_t := 16#040#;
PANE_FORCE_DIV : constant flags_t := 16#080#;
PANE_INITSCALE : constant flags_t := 16#100#;
PANE_EXPAND : constant flags_t := PANE_HFILL or PANE_VFILL;
type partition_t is (NONE, FIRST, SECOND);
for partition_t use (NONE => -1, FIRST => 0, SECOND => 1);
for partition_t'size use c.int'size;
pragma convention (c, partition_t);
-- API
function allocate
(parent : widget_access_t;
pane_type : type_t;
flags : flags_t) return pane_access_t;
pragma import (c, allocate, "AG_PaneNew");
function allocate_horizontal
(parent : widget_access_t;
flags : flags_t) return pane_access_t;
pragma import (c, allocate_horizontal, "AG_PaneNewHoriz");
function allocate_vertical
(parent : widget_access_t;
flags : flags_t) return pane_access_t;
pragma import (c, allocate_vertical, "AG_PaneNewVert");
procedure attach_box
(pane : pane_access_t;
which : partition_t;
box : agar.gui.widget.box.box_access_t);
pragma import (c, attach_box, "AG_PaneAttachBox");
procedure attach_boxes
(pane : pane_access_t;
box1 : agar.gui.widget.box.box_access_t;
box2 : agar.gui.widget.box.box_access_t);
pragma import (c, attach_boxes, "AG_PaneAttachBoxes");
procedure set_divider_width
(pane : pane_access_t;
pixels : positive);
pragma inline (set_divider_width);
procedure set_division_minimum
(pane : pane_access_t;
which : partition_t;
min_width : positive;
max_width : positive);
pragma inline (set_division_minimum);
function move_divider
(pane : pane_access_t;
x : positive) return positive;
pragma inline (move_divider);
function widget (pane : pane_access_t) return widget_access_t;
pragma inline (widget);
private
type pane_div_t is array (1 .. 2) of aliased agar.gui.widget.box.box_access_t;
pragma convention (c, pane_div_t);
type pane_geom_t is array (1 .. 2) of aliased c.int;
pragma convention (c, pane_geom_t);
type pane_t is record
widget : aliased widget_t;
pane_type : type_t;
flags : flags_t;
div : pane_div_t;
minw : pane_geom_t;
minh : pane_geom_t;
dmoving : c.int;
dx : c.int;
rx : c.int;
wdiv : c.int;
end record;
pragma convention (c, pane_t);
end agar.gui.widget.pane;
|
-- --
-- package Copyright (c) Dmitry A. Kazakov --
-- Strings_Edit.Streams Luebeck --
-- Interface Spring, 2009 --
-- --
-- Last revision : 14:23 11 Feb 2012 --
-- --
-- This library 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 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 --
-- General Public License for more details. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- 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. --
--____________________________________________________________________--
--
-- The package provides stream interface to string. A string can be
-- read and written using stream I/O attributes.
--
with Ada.Streams; use Ada.Streams;
with System.Storage_Elements;
package Strings_Edit.Streams is
--
-- String_Stream -- A string stream, when read, Data (Position..Length)
-- is amount of data available to read/write. Note that
-- before reading from the stream is must be initialized using Set.
-- Otherwise the result of reading will be the unitialized contents of
-- the Data field.
--
type String_Stream (Length : Natural) is
new Root_Stream_Type with
record
Position : Positive := 1;
Data : String (1..Length);
end record;
--
-- Get -- Written contents of the stream
--
-- Stream - The stream object
--
-- Get is an operation inverse to T'Write.
--
-- Returns :
--
-- String written
--
function Get (Stream : String_Stream) return String;
--
-- Get_Size -- Number of stream elements available to write or to read
--
-- Stream - The stream object
--
function Get_Size (Stream : String_Stream)
return Stream_Element_Count;
--
-- Read -- Overrides Ada.Streams...
--
procedure Read
( Stream : in out String_Stream;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset
);
--
-- Rewind -- The stream
--
-- Stream - The stream object
--
-- This procedure moves Stream.Position to the beginning. This undoes
-- all reading/writing actions.
--
procedure Rewind (Stream : in out String_Stream);
--
-- Set -- Contents
--
-- Stream - The stream object
-- Content - String to read
--
-- The stream is changed to contain Content. The next read operation
-- will yield the first character of Content. Set is an operation
-- inverse to T'Read.
--
-- Exceptions :
--
-- Contraint_Error - no room in Stream
--
procedure Set (Stream : in out String_Stream; Content : String);
--
-- Write -- Overrides Ada.Streams...
--
-- Exceptions :
--
-- End_Error - No room in the string
--
procedure Write
( Stream : in out String_Stream;
Item : Stream_Element_Array
);
private
use System.Storage_Elements;
pragma Inline (Get_Size);
--
-- Char_Count -- Number of characters per string elements
--
Char_Count : constant := Stream_Element'Size / Character'Size;
--
-- Stream_Element'Size must be a multiple of Character'Size and the
-- later be a multiple of Storage_Element'Size.
--
subtype Confirmed is Boolean range True..True;
Assert : constant Confirmed :=
( Char_Count * Character'Size = Stream_Element'Size
and then
Character'Size mod Storage_Element'Size = 0
);
end Strings_Edit.Streams;
|
-- { dg-do compile }
-- { dg-options "-gnat12" }
function Cond_Expr1 (Dir : in String) return String is
begin
return (if Dir (Dir'Last) = '\' then Dir else Dir & '\');
end;
|
------------------------------------------------------------------------------
-- --
-- Hardware Abstraction Layer for STM32 Targets --
-- --
-- Copyright (C) 2014, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with STM32F4.RCC; use STM32F4.RCC;
package body STM32F4.SPI is
Baud_Rate_Value : constant array (SPI_Baud_Rate_Prescaler) of Bits_3 :=
(BRP_2 => 2#000#,
BRP_4 => 2#001#,
BRP_8 => 2#010#,
BRP_16 => 2#011#,
BRP_32 => 2#100#,
BRP_64 => 2#101#,
BRP_128 => 2#110#,
BRP_256 => 2#111#);
---------------
-- Configure --
---------------
procedure Configure (Port : in out SPI_Port; Conf : SPI_Configuration) is
CTRL1 : SPI_Control_Register := Port.CTRL1;
I2S_Conf : SPI_I2S_Config_Register := Port.I2S_Conf;
begin
case Conf.Mode is
when Master =>
CTRL1.Master_Select := 1;
CTRL1.Slave_Select := 1;
when Slave =>
CTRL1.Master_Select := 0;
CTRL1.Slave_Select := 0;
end case;
case Conf.Direction is
when D2Lines_FullDuplex =>
CTRL1.BiDir_Mode := 0;
CTRL1.Output_BiDir := 0;
CTRL1.RXOnly := 0;
when D2Lines_RxOnly =>
CTRL1.BiDir_Mode := 0;
CTRL1.Output_BiDir := 0;
CTRL1.RXOnly := 1;
when D1Line_Rx =>
CTRL1.BiDir_Mode := 1;
CTRL1.Output_BiDir := 0;
CTRL1.RXOnly := 0;
when D1Line_Tx =>
CTRL1.BiDir_Mode := 1;
CTRL1.Output_BiDir := 1;
CTRL1.RXOnly := 0;
end case;
CTRL1.Data_Frame_Fmt := (if Conf.Data_Size = Data_16 then 1 else 0);
CTRL1.Clock_Polarity := (if Conf.Clock_Polarity = High then 1 else 0);
CTRL1.Clock_Phase := (if Conf.Clock_Phase = P2Edge then 1 else 0);
CTRL1.Soft_Slave_Mgt := (if Conf.Slave_Management = Soft then 1 else 0);
CTRL1.Baud_Rate_Ctrl := Baud_Rate_Value (Conf.Baud_Rate_Prescaler);
CTRL1.LSB_First := (if Conf.First_Bit = LSB then 1 else 0);
Port.CTRL1 := CTRL1;
-- Activate the SPI mode (Reset I2SMOD bit in I2SCFGR register)
I2S_Conf := Port.I2S_Conf;
I2S_Conf.Mode_Select := 0;
Port.I2S_Conf := I2S_Conf;
Port.CRC_Poly := Conf.CRC_Poly;
end Configure;
------------
-- Enable --
------------
procedure Enable (Port : in out SPI_Port) is
CTRL1 : SPI_Control_Register := Port.CTRL1;
begin
CTRL1.SPI_Enable := 1;
Port.CTRL1 := CTRL1;
end Enable;
-------------
-- Disable --
-------------
procedure Disable (Port : in out SPI_Port) is
CTRL1 : SPI_Control_Register := Port.CTRL1;
begin
CTRL1.SPI_Enable := 0;
Port.CTRL1 := CTRL1;
end Disable;
-------------
-- Enabled --
-------------
function Enabled (Port : SPI_Port) return Boolean is
begin
return Port.CTRL1.SPI_Enable = 1;
end Enabled;
----------
-- Send --
----------
procedure Send (Port : in out SPI_Port; Data : Half_Word) is
begin
Port.Data := Data;
end Send;
----------
-- Data --
----------
function Data (Port : SPI_Port) return Half_Word is
begin
return Port.Data;
end Data;
----------
-- Send --
----------
procedure Send (Port : in out SPI_Port; Data : Byte) is
begin
Send (Port, Half_Word (Data));
end Send;
----------
-- Data --
----------
function Data (Port : SPI_Port) return Byte is
begin
return Byte (Half_Word'(Data (Port)));
end Data;
-----------------
-- Tx_Is_Empty --
-----------------
function Tx_Is_Empty (Port : SPI_Port) return Boolean is
begin
return Port.Status.TX_Buffer_Empty;
end Tx_Is_Empty;
-----------------
-- Rx_Is_Empty --
-----------------
function Rx_Is_Empty (Port : SPI_Port) return Boolean is
begin
return not Port.Status.RX_Buffer_Not_Empty;
end Rx_Is_Empty;
----------
-- Busy --
----------
function Busy (Port : SPI_Port) return Boolean is
begin
return Port.Status.Busy_Flag;
end Busy;
----------------------------
-- Channel_Side_Indicated --
----------------------------
function Channel_Side_Indicated (Port : SPI_Port) return Boolean is
begin
return Port.Status.Channel_Side;
end Channel_Side_Indicated;
------------------------
-- Underrun_Indicated --
------------------------
function Underrun_Indicated (Port : SPI_Port) return Boolean is
begin
return Port.Status.Underrun_Flag;
end Underrun_Indicated;
-------------------------
-- CRC_Error_Indicated --
-------------------------
function CRC_Error_Indicated (Port : SPI_Port) return Boolean is
begin
return Port.Status.CRC_Error_Flag;
end CRC_Error_Indicated;
--------------------------
-- Mode_Fault_Indicated --
--------------------------
function Mode_Fault_Indicated (Port : SPI_Port) return Boolean is
begin
return Port.Status.Mode_Fault;
end Mode_Fault_Indicated;
-----------------------
-- Overrun_Indicated --
-----------------------
function Overrun_Indicated (Port : SPI_Port) return Boolean is
begin
return Port.Status.Overrun_Flag;
end Overrun_Indicated;
-------------------------------
-- Frame_Fmt_Error_Indicated --
-------------------------------
function Frame_Fmt_Error_Indicated (Port : SPI_Port) return Boolean is
begin
return Port.Status.Frame_Fmt_Error;
end Frame_Fmt_Error_Indicated;
end STM32F4.SPI;
|
package Tictactoe
with SPARK_Mode => On
is
type Slot is (Empty, Player, Computer);
type Pos is new Integer range 1 .. 3;
type Column is array (Pos) of Slot;
type Board is array (Pos) of Column;
My_Board : Board := (others => (others => Empty));
-- Game operations
procedure Initialize
with Post => Num_Free_Slots = 9;
procedure Player_Play (S : String)
with Pre => not Is_Full and Won = Empty,
Post => Num_Free_Slots = Num_Free_Slots'Old - 1;
procedure Computer_Play
with Pre => not Is_Full and Won = Empty,
Post => Num_Free_Slots = Num_Free_Slots'Old - 1;
procedure Display;
function Won return Slot;
function One_Free_Slot (X, Y : Pos) return Integer is
(if My_Board(X)(Y) = Empty then 1 else 0);
function Count_Free_Slots (X, Y : Pos) return Integer is
(One_Free_Slot(1,1) +
(if Y >= 2 then One_Free_Slot(1,2) else 0) +
(if Y >= 3 then One_Free_Slot(1,3) else 0) +
(if X >= 2 then
One_Free_Slot(2,1) +
(if Y >= 2 then One_Free_Slot(2,2) else 0) +
(if Y >= 3 then One_Free_Slot(2,3) else 0)
else 0) +
(if X >= 3 then
One_Free_Slot(3,1) +
(if Y >= 2 then One_Free_Slot(3,2) else 0) +
(if Y >= 3 then One_Free_Slot(3,3) else 0)
else 0));
function Num_Free_Slots return Natural is
(Count_Free_Slots(3,3));
function Is_Full return Boolean is (Num_Free_Slots = 0);
end Tictactoe;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Tools Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2015-2018, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Asis.Compilation_Units;
with Asis.Declarations;
with Asis.Elements;
with Asis.Expressions;
with League.String_Vectors;
with Properties.Tools;
package body Properties.Expressions.Identifiers is
function Is_Current_Instance_Of_Type
(Id : Asis.Identifier;
Decl : Asis.Declaration) return Boolean;
-------------
-- Address --
-------------
function Address
(Engine : access Engines.Contexts.Context;
Element : Asis.Declaration;
Name : Engines.Text_Property) return League.Strings.Universal_String
is
pragma Unreferenced (Name);
Text : League.Strings.Universal_String;
Decl : constant Asis.Declaration :=
Asis.Expressions.Corresponding_Name_Declaration (Element);
Is_Simple_Ref : Boolean;
begin
if Asis.Elements.Is_Nil (Decl) then
return Engine.Text.Get_Property (Element, Engines.Code);
end if;
Is_Simple_Ref :=
Engine.Boolean.Get_Property (Decl, Engines.Is_Simple_Ref);
if Is_Simple_Ref then
Text := Name_Prefix (Engine, Element, Decl);
Text.Append
(Engine.Text.Get_Property
(Asis.Declarations.Names (Decl) (1), Engines.Code));
return Text;
else
return Engine.Text.Get_Property (Element, Engines.Code);
end if;
end Address;
---------------
-- Alignment --
---------------
function Alignment
(Engine : access Engines.Contexts.Context;
Element : Asis.Expression;
Name : Engines.Integer_Property) return Integer
is
-- Expecting identifier as subtype name of subtype_mark
Decl : constant Asis.Declaration :=
Asis.Expressions.Corresponding_Name_Declaration (Element);
begin
return Engine.Integer.Get_Property (Decl, Name);
end Alignment;
------------
-- Bounds --
------------
function Bounds
(Engine : access Engines.Contexts.Context;
Element : Asis.Expression;
Name : Engines.Text_Property) return League.Strings.Universal_String
is
-- Expecting identifier as subtype name of subtype_mark
Decl : constant Asis.Declaration :=
Asis.Expressions.Corresponding_Name_Declaration (Element);
begin
return Engine.Text.Get_Property (Decl, Name);
end Bounds;
---------------------
-- Call_Convention --
---------------------
function Call_Convention
(Engine : access Engines.Contexts.Context;
Element : Asis.Declaration;
Name : Engines.Convention_Property)
return Engines.Convention_Kind
is
use type Asis.Expression_Kinds;
Def : constant Asis.Defining_Name :=
Asis.Expressions.Corresponding_Name_Definition (Element);
begin
if Asis.Elements.Is_Nil (Def) then
if Asis.Elements.Expression_Kind (Element) =
Asis.An_Operator_Symbol
then
return Engines.Intrinsic;
end if;
return Engines.Unspecified;
end if;
return Engine.Call_Convention.Get_Property
(Asis.Elements.Enclosing_Element (Def), Name);
end Call_Convention;
----------
-- Code --
----------
function Code
(Engine : access Engines.Contexts.Context;
Element : Asis.Declaration;
Name : Engines.Text_Property) return League.Strings.Universal_String
is
Decl : Asis.Declaration :=
Asis.Expressions.Corresponding_Name_Declaration (Element);
Decl_Kind : Asis.Declaration_Kinds :=
Asis.Elements.Declaration_Kind (Decl);
Impl : Asis.Declaration;
Image : constant Wide_String :=
Asis.Expressions.Name_Image (Element);
Text : League.Strings.Universal_String;
Is_Simple_Ref : Boolean;
begin
if Asis.Elements.Is_Nil (Decl) then
Text := League.Strings.From_UTF_16_Wide_String (Image);
return Text.To_Lowercase;
elsif Is_Current_Instance_Of_Type (Element, Decl) then
return League.Strings.To_Universal_String ("this");
elsif Decl_Kind in Asis.A_Renaming_Declaration then
return Engine.Text.Get_Property
(Asis.Declarations.Renamed_Entity (Decl), Name);
elsif Decl_Kind in
Asis.A_Function_Declaration | Asis.A_Procedure_Declaration
then
Impl := Asis.Declarations.Corresponding_Body (Decl);
if Asis.Elements.Declaration_Kind (Impl) in
Asis.A_Renaming_Declaration
then
return Engine.Text.Get_Property
(Asis.Declarations.Renamed_Entity (Impl), Name);
end if;
elsif Decl_Kind in
Asis.A_Private_Extension_Declaration | Asis.A_Private_Type_Declaration
then
-- Use full type view instead of private type
Decl := Asis.Declarations.Corresponding_Type_Declaration (Decl);
Decl_Kind := Asis.Elements.Declaration_Kind (Decl);
end if;
while Asis.Elements.Is_Part_Of_Inherited (Decl)
and then Decl_Kind in
Asis.A_Function_Declaration | Asis.A_Procedure_Declaration
loop
Decl := Asis.Declarations.Corresponding_Subprogram_Derivation (Decl);
Decl_Kind := Asis.Elements.Declaration_Kind (Decl);
end loop;
Is_Simple_Ref :=
Engine.Boolean.Get_Property (Decl, Engines.Is_Simple_Ref);
if Decl_Kind in
Asis.A_Procedure_Declaration |
Asis.A_Null_Procedure_Declaration |
Asis.A_Function_Declaration |
Asis.A_Procedure_Body_Declaration |
Asis.A_Function_Body_Declaration
and then Engine.Boolean.Get_Property (Decl, Engines.Is_Dispatching)
then
-- Dispatching operation has no prefix
return Engine.Text.Get_Property
(Asis.Declarations.Names (Decl) (1), Name);
elsif Decl_Kind in
Asis.An_Integer_Number_Declaration |
Asis.A_Real_Number_Declaration
then
Text := Engine.Text.Get_Property
(Asis.Declarations.Initialization_Expression (Decl), Name);
return Text;
else
Text := Name_Prefix (Engine, Element, Decl);
Text.Append
(Engine.Text.Get_Property
(Asis.Declarations.Names (Decl) (1), Name));
if Is_Simple_Ref then
Text.Append (".all");
end if;
return Text;
end if;
end Code;
----------------
-- Initialize --
----------------
function Initialize
(Engine : access Engines.Contexts.Context;
Element : Asis.Expression;
Name : Engines.Text_Property) return League.Strings.Universal_String
is
Decl : constant Asis.Declaration :=
Asis.Expressions.Corresponding_Name_Declaration (Element);
begin
if Asis.Elements.Is_Nil (Decl) then
return League.Strings.To_Universal_String ("undefined");
else
return Engine.Text.Get_Property (Decl, Name);
end if;
end Initialize;
--------------------
-- Intrinsic_Name --
--------------------
function Intrinsic_Name
(Engine : access Engines.Contexts.Context;
Element : Asis.Declaration;
Name : Engines.Text_Property) return League.Strings.Universal_String
is
use type Asis.Expression_Kinds;
Def : Asis.Defining_Name :=
Asis.Expressions.Corresponding_Name_Definition (Element);
begin
if Asis.Elements.Is_Nil (Def) then
if Asis.Elements.Expression_Kind (Element) =
Asis.An_Operator_Symbol
then
declare
Text : constant League.Strings.Universal_String :=
League.Strings.From_UTF_16_Wide_String
(Asis.Expressions.Name_Image (Element));
begin
return Text;
end;
end if;
return League.Strings.Empty_Universal_String;
elsif Asis.Elements.Is_Part_Of_Instance (Def) then
Def := Asis.Declarations.Corresponding_Generic_Element (Def);
end if;
return Engine.Text.Get_Property
(Asis.Elements.Enclosing_Element (Def), Name);
end Intrinsic_Name;
---------------------------------
-- Is_Current_Instance_Of_Type --
---------------------------------
function Is_Current_Instance_Of_Type
(Id : Asis.Identifier;
Decl : Asis.Declaration) return Boolean
is
Node : Asis.Declaration := Properties.Tools.Enclosing_Declaration (Id);
begin
while not Asis.Elements.Is_Nil (Node) loop
if Properties.Tools.Is_Equal_Type (Decl, Node) then
return True;
end if;
Node := Properties.Tools.Enclosing_Declaration (Node);
end loop;
return False;
end Is_Current_Instance_Of_Type;
--------------------
-- Is_Dispatching --
--------------------
function Is_Dispatching
(Engine : access Engines.Contexts.Context;
Element : Asis.Declaration;
Name : Engines.Boolean_Property) return Boolean
is
Decl : constant Asis.Declaration :=
Asis.Expressions.Corresponding_Name_Declaration (Element);
begin
if Asis.Elements.Is_Nil (Decl) then
return False;
else
return Engine.Boolean.Get_Property (Decl, Name);
end if;
end Is_Dispatching;
-----------------
-- Name_Prefix --
-----------------
function Name_Prefix
(Engine : access Engines.Contexts.Context;
Name : Asis.Identifier;
Decl : Asis.Declaration) return League.Strings.Universal_String
is
pragma Unreferenced (Name);
procedure Add_Parent_Name
(Result : in out League.Strings.Universal_String);
function Is_Imported (Item : Asis.Declaration) return Boolean;
procedure Prepend_Decl_List (Value : League.Strings.Universal_String);
----------------
-- Add_Prefix --
----------------
procedure Add_Parent_Name
(Result : in out League.Strings.Universal_String)
is
Unit : constant Asis.Compilation_Unit :=
Asis.Elements.Enclosing_Compilation_Unit (Decl);
Parent : constant Asis.Compilation_Unit :=
Asis.Compilation_Units.Corresponding_Parent_Declaration (Unit);
Parent_Name : constant League.Strings.Universal_String :=
League.Strings.From_UTF_16_Wide_String
(Asis.Compilation_Units.Unit_Full_Name (Parent)).To_Lowercase;
begin
Result.Prepend (".");
Result.Prepend (Parent_Name);
Result.Prepend ("_ec.");
end Add_Parent_Name;
-----------------
-- Is_Imported --
-----------------
function Is_Imported (Item : Asis.Declaration) return Boolean is
Import : constant Wide_String :=
Properties.Tools.Get_Aspect (Item, "Import");
Export : constant Wide_String :=
Properties.Tools.Get_Aspect (Item, "Export");
begin
return Import = "True" or Export = "True";
end Is_Imported;
Decl_List : League.String_Vectors.Universal_String_Vector;
-----------------------
-- Prepend_Decl_List --
-----------------------
procedure Prepend_Decl_List (Value : League.Strings.Universal_String) is
Tmp : League.String_Vectors.Universal_String_Vector;
begin
Tmp.Append (Value);
Decl_List.Prepend (Tmp);
end Prepend_Decl_List;
Top_Item : Boolean := True;
Is_Package : Boolean := False;
Item : Asis.Element := Decl;
Result : League.Strings.Universal_String;
Kind : Asis.Declaration_Kinds;
begin
while not Asis.Elements.Is_Nil (Item) loop
Kind := Asis.Elements.Declaration_Kind (Item);
case Kind is
when Asis.A_Package_Instantiation =>
null;
when Asis.An_Ordinary_Type_Declaration |
Asis.A_Subtype_Declaration | -- ???
Asis.A_Private_Type_Declaration |
Asis.A_Private_Extension_Declaration =>
exit when Is_Imported (Item);
when Asis.A_Discriminant_Specification |
Asis.A_Component_Declaration |
Asis.A_Loop_Parameter_Specification |
Asis.An_Element_Iterator_Specification |
Asis.A_Parameter_Specification =>
exit;
when Asis.A_Deferred_Constant_Declaration |
Asis.A_Constant_Declaration |
Asis.A_Variable_Declaration |
Asis.An_Integer_Number_Declaration |
Asis.A_Return_Variable_Specification |
Asis.A_Return_Constant_Specification =>
exit when Is_Imported (Item);
when Asis.A_Procedure_Declaration |
Asis.A_Procedure_Renaming_Declaration |
Asis.A_Null_Procedure_Declaration |
Asis.A_Function_Declaration |
Asis.A_Function_Renaming_Declaration |
Asis.A_Procedure_Body_Declaration |
Asis.A_Function_Body_Declaration =>
if not Top_Item then
-- Some declaration inside subprogram
Is_Package := False;
exit;
elsif Is_Imported (Item) then
-- Imported operation has no prefix
exit;
elsif Asis.Elements.Is_Nil
(Asis.Elements.Enclosing_Element (Item))
then
-- Top item library level subprograms should be qualified
-- by parent package name
Add_Parent_Name (Result);
return Result;
end if;
when Asis.A_Package_Declaration |
Asis.A_Package_Body_Declaration =>
declare
Names : constant Asis.Defining_Name_List :=
Asis.Declarations.Names (Item);
begin
if not Top_Item then
Result :=
Engine.Text.Get_Property (Names (1), Engines.Code);
Prepend_Decl_List (Result);
Is_Package := True;
end if;
end;
when Asis.A_Procedure_Instantiation |
Asis.A_Function_Instantiation =>
null; -- Skip instantiation element
when Asis.Not_A_Declaration =>
null;
when others =>
raise Program_Error;
end case;
Item := Asis.Elements.Enclosing_Element (Item);
Top_Item := False;
end loop;
if Decl_List.Is_Empty then
return League.Strings.Empty_Universal_String;
end if;
Result := Decl_List.Join ('.');
if Is_Package then
Add_Parent_Name (Result);
end if;
Result.Append (".");
return Result;
end Name_Prefix;
end Properties.Expressions.Identifiers;
|
------------------------------------------------------------------------------
-- EMAIL: <darkestkhan@gmail.com> --
-- License: ISC --
-- --
-- Copyright © 2015 - 2016 darkestkhan --
------------------------------------------------------------------------------
-- Permission to use, copy, modify, and/or distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- The software is provided "as is" and the author disclaims all warranties --
-- with regard to this software including all implied warranties of --
-- merchantability and fitness. In no event shall the author be liable for --
-- any special, direct, indirect, or consequential damages or any damages --
-- whatsoever resulting from loss of use, data or profits, whether in an --
-- action of contract, negligence or other tortious action, arising out of --
-- or in connection with the use or performance of this software. --
------------------------------------------------------------------------------
with Ada.Characters.Latin_1;
with Interfaces.C;
with Interfaces.C.Strings;
package body Imago.IL is
--------------------------------------------------------------------------
-------------------
-- R E N A M E S --
-------------------
--------------------------------------------------------------------------
package ASCII renames Ada.Characters.Latin_1;
package IC renames Interfaces.C;
package CStrings renames Interfaces.C.Strings;
--------------------------------------------------------------------------
-------------------------------------------
-- S U B P R O G R A M S ' B O D I E S --
-------------------------------------------
--------------------------------------------------------------------------
function Apply_Pal (File_Name: in String) return Bool
is
function ilApplyPal (FileName: in Pointer) return Bool
with Import => True, Convention => StdCall, External_Name => "ilApplyPal";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilApplyPal (CString'Address);
end Apply_Pal;
--------------------------------------------------------------------------
function Apply_Profile
( In_Profile: in String; Out_Profile: in String
) return Bool
is
function ilApplyProfile
( InProfile : in Pointer;
OutProfile: in Pointer
) return Bool
with Import => True, Convention => StdCall,
External_Name => "ilApplyProfile";
C_In_Profile : constant String := In_Profile & ASCII.NUL;
C_Out_Profile: constant String := Out_Profile & ASCII.NUL;
begin
return ilApplyProfile (C_In_Profile'Address, C_Out_Profile'Address);
end Apply_Profile;
--------------------------------------------------------------------------
function Determine_Type (File_Name: in String) return Enum
is
function ilDetermineType (FileName: in Pointer) return Enum
with Import => True, Convention => StdCall,
External_Name => "ilDetermineType";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilDetermineType (CString'Address);
end Determine_Type;
--------------------------------------------------------------------------
function Get_String (String_Name: in Enum) return String
is
function ilGetString (String_Name: in Enum) return CStrings.chars_ptr
with Import => True, Convention => StdCall,
External_Name => "ilGetString";
begin
return IC.To_Ada (CStrings.Value (ilGetString (String_Name)));
end Get_String;
--------------------------------------------------------------------------
function Is_Valid (Type_Of: in Enum; File_Name: in String) return Bool
is
function ilIsValid (T: in Enum; F: in Pointer) return Bool
with Import => True, Convention => StdCall, External_Name => "ilIsValid";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilIsValid (Type_Of, CString'Address);
end Is_Valid;
--------------------------------------------------------------------------
function Load (Type_Of: in Enum; File_Name: in String) return Bool
is
function ilLoad (T: in Enum; F: in Pointer) return Bool
with Import => True, Convention => StdCall, External_Name => "ilLoad";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilLoad (Type_Of, CString'Address);
end Load;
--------------------------------------------------------------------------
function Load_Data
( File_Name: in String;
Width: in UInt; Height: in UInt;
Depth: in UInt; BPP: in UByte
) return Bool
is
function ilLoadData
( FileName: in Pointer;
Width: in UInt; Height: in UInt;
Depth: in UInt; BPP: in UByte
) return Bool
with Import => True, Convention => StdCall, External_Name => "ilLoadData";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilLoadData (CString'Address, Width, Height, Depth, BPP);
end Load_Data;
--------------------------------------------------------------------------
function Load_Image (File_Name: in String) return Bool
is
function ilLoadImage (FileName: in Pointer) return Bool
with Import => True, Convention => StdCall,
External_Name => "ilLoadImage";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilLoadImage (CString'Address);
end Load_Image;
--------------------------------------------------------------------------
function Load_Pal (File_Name: in String) return Bool
is
function ilLoadPal (FileName: in Pointer) return Bool
with Import => True, Convention => StdCall,
External_Name => "ilLoadImage";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilLoadPal (CString'Address);
end Load_Pal;
--------------------------------------------------------------------------
function Remove_Load (Ext: in String) return Bool
is
function ilRemoveLoad (Ext: in Pointer) return Bool
with Import => True, Convention => StdCall,
External_Name => "ilRemoveLoad";
CString: constant String := Ext & ASCII.NUL;
begin
return ilRemoveLoad (CString'Address);
end Remove_Load;
--------------------------------------------------------------------------
function Remove_Save (Ext: in String) return Bool
is
function ilRemoveSave (Ext: in Pointer) return Bool
with Import => True, Convention => StdCall,
External_Name => "ilRemoveSave";
CString: constant String := Ext & ASCII.NUL;
begin
return ilRemoveSave (CString'Address);
end Remove_Save;
--------------------------------------------------------------------------
function Save (Type_Of: in Enum; File_Name: in String) return Bool
is
function ilSave
( Type_Of: in Enum; FileName: in Pointer
) return Bool
with Import => True, Convention => StdCall, External_Name => "ilSave";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilSave (Type_Of, CString'Address);
end Save;
--------------------------------------------------------------------------
function Save_Data (File_Name: in String) return Bool
is
function ilSaveData (FileName: in Pointer) return Bool
with Import => True, Convention => StdCall, External_Name => "ilSaveData";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilSaveData (CString'Address);
end Save_Data;
--------------------------------------------------------------------------
function Save_Image (File_Name: in String) return Bool
is
function ilSaveImage (FileName: in Pointer) return Bool
with Import => True, Convention => StdCall,
External_Name => "ilSaveImage";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilSaveImage (CString'Address);
end Save_Image;
--------------------------------------------------------------------------
function Save_Pal (File_Name: in String) return Bool
is
function ilSavePal (FileName: in Pointer) return Bool
with Import => True, Convention => StdCall, External_Name => "ilSavePal";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilSavePal (CString'Address);
end Save_Pal;
--------------------------------------------------------------------------
procedure Set_String (Mode: in Enum; Value: in String)
is
procedure ilSetString (Mode : in Enum; Value: in Pointer)
with Import => True, Convention => StdCall,
External_Name => "ilSetString";
CString: constant String := Value & ASCII.NUL;
begin
ilSetString (Mode, CString'Address);
end Set_String;
---------------------------------------------------------------------------
function Type_From_Ext (File_Name: in String) return Enum
is
function ilTypeFromExt (FileName: in Pointer) return Enum
with Import => True, Convention => StdCall,
External_Name => "ilTypeFromExt";
CString: constant String := File_Name & ASCII.NUL;
begin
return ilTypeFromExt (CString'Address);
end Type_From_Ext;
--------------------------------------------------------------------------
end Imago.IL;
|
pragma Ada_2012;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
package Pixtend.wiringPiSPI_h is
function wiringPiSPIGetFd (channel : int) return int -- wiringPiSPI.h:29
with Import => True,
Convention => C,
External_Name => "wiringPiSPIGetFd";
function wiringPiSPIDataRW
(channel : int;
data : access unsigned_char;
len : int) return int -- wiringPiSPI.h:30
with Import => True,
Convention => C,
External_Name => "wiringPiSPIDataRW";
function wiringPiSPISetupMode
(channel : int;
speed : int;
mode : int) return int -- wiringPiSPI.h:31
with Import => True,
Convention => C,
External_Name => "wiringPiSPISetupMode";
function wiringPiSPISetup (channel : int; speed : int) return int -- wiringPiSPI.h:32
with Import => True,
Convention => C,
External_Name => "wiringPiSPISetup";
end Pixtend.wiringPiSPI_h;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.