content
stringlengths 23
1.05M
|
|---|
-- C41203A.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 THE NAME PART OF A SLICE MAY BE:
-- AN IDENTIFIER DENOTING A ONE DIMENSIONAL ARRAY OBJECT - N1;
-- AN IDENTIFIER DENOTING AN ACCESS OBJECT WHOSE VALUE
-- DESIGNATES A ONE DIMENSIONAL ARRAY OBJECT - N2;
-- A FUNCTION CALL DELIVERING A ONE DIMENSIONAL ARRAY OBJECT USING
-- A PREDEFINED FUNCTION - &,
-- A USER-DEFINED FUNCTION - F1;
-- A FUNCTION CALL DELIVERING AN ACCESS VALUE THAT
-- DESIGNATES A ONE DIMENSIONAL ARRAY - F2;
-- A SLICE - N3;
-- AN INDEXED COMPONENT DENOTING A ONE DIMENSIONAL ARRAY OBJECT
-- (ARRAY OF ARRAYS) - N4;
-- AN IDENTIFIER PREFIXED BY THE NAME OF THE INNERMOST UNIT
-- ENCLOSING ITS DECLARATION - C41203A.N1;
-- A RECORD COMPONENT (OF A RECORD CONTAINING ONE OR MORE
-- ARRAYS WHOSE BOUNDS DEPEND ON A DISCRIMINANT) - N5.
-- CHECK THAT THE APPROPRIATE SLICE IS ACCESSED (FOR
-- STATIC INDICES).
-- WKB 8/5/81
-- SPS 11/1/82
-- PWN 11/30/94 SUBTYPE QUALIFIED LITERALS FOR ADA 9X.
WITH REPORT;
USE REPORT;
PROCEDURE C41203A IS
TYPE T1 IS ARRAY (INTEGER RANGE <> ) OF INTEGER;
SUBTYPE A1 IS T1 (1..6);
N1 : A1 := (1,2,3,4,5,6);
BEGIN
TEST ("C41203A", "CHECK THAT THE NAME PART OF A SLICE MAY BE " &
"OF CERTAIN FORMS AND THAT THE APPROPRIATE " &
"SLICE IS ACCESSED (FOR STATIC INDICES)");
DECLARE
TYPE T2 IS ARRAY (INTEGER RANGE <> ) OF BOOLEAN;
SUBTYPE A2 IS T2 (1..6);
TYPE A3 IS ACCESS A1;
SUBTYPE SI IS INTEGER RANGE 1 .. 3;
TYPE A4 IS ARRAY (SI) OF A1;
TYPE R (LENGTH : INTEGER) IS
RECORD
S : STRING (1..LENGTH);
END RECORD;
N2 : A3 := NEW A1' (1,2,3,4,5,6);
N3 : T1 (1..7) := (1,2,3,4,5,6,7);
N4 : A4 := (1 => (1,2,3,4,5,6), 2 => (7,8,9,10,11,12),
3 => (13,14,15,16,17,18));
N5 : R(6) := (LENGTH => 6, S => "ABCDEF");
FUNCTION F1 RETURN A2 IS
BEGIN
RETURN (FALSE,FALSE,TRUE,FALSE,TRUE,TRUE);
END F1;
FUNCTION F2 RETURN A3 IS
BEGIN
RETURN N2;
END F2;
PROCEDURE P1 (X : IN T1; Y : IN OUT T1;
Z : OUT T1; W : IN STRING) IS
BEGIN
IF X /= (1,2) THEN
FAILED ("WRONG VALUE FOR IN PARAMETER - " & W);
END IF;
IF Y /= (3,4) THEN
FAILED ("WRONG VALUE FOR IN OUT PARAMETER - " & W);
END IF;
Y := (10,11);
Z := (12,13);
END P1;
PROCEDURE P2 (X : STRING) IS
BEGIN
IF X /= "BC" THEN
FAILED ("WRONG VALUE FOR IN PARAMETER - '&'");
END IF;
END P2;
PROCEDURE P3 (X : T2) IS
BEGIN
IF X /= (FALSE,TRUE,FALSE) THEN
FAILED ("WRONG VALUE FOR IN PARAMETER - F1");
END IF;
END P3;
PROCEDURE P5 (X : IN STRING; Y : IN OUT STRING;
Z : OUT STRING) IS
BEGIN
IF X /= "EF" THEN
FAILED ("WRONG VALUE FOR IN PARAMETER - N5");
END IF;
IF Y /= "CD" THEN
FAILED ("WRONG VALUE FOR IN OUT PARAMETER - N5");
END IF;
Y := "XY";
Z := "WZ";
END P5;
BEGIN
IF N1(1..2) /= (1,2) THEN
FAILED ("WRONG VALUE FOR EXPRESSION - N1");
END IF;
N1(1..2) := (7,8);
IF N1 /= (7,8,3,4,5,6) THEN
FAILED ("WRONG TARGET FOR ASSIGNMENT - N1");
END IF;
N1 := (1,2,3,4,5,6);
P1 (N1(1..2), N1(3..4), N1(5..6), "N1");
IF N1 /= (1,2,10,11,12,13) THEN
FAILED ("WRONG TARGET FOR (IN) OUT PARAMETER - N1");
END IF;
IF N2(4..6) /= (4,5,6) THEN
FAILED ("WRONG VALUE FOR EXPRESSION - N2");
END IF;
N2(4..6) := (7,8,9);
IF N2.ALL /= (1,2,3,7,8,9) THEN
FAILED ("WRONG TARGET FOR ASSIGNMENT - N2");
END IF;
N2.ALL := (1,2,5,6,3,4);
P1 (N2(1..2), N2(5..6), N2(3..4), "N2");
IF N2.ALL /= (1,2,12,13,10,11) THEN
FAILED ("WRONG TARGET FOR (IN) OUT PARAMETER - N2");
END IF;
IF "&" (STRING'("AB"), STRING'("CDEF"))(4..6) /= STRING'("DEF") THEN
FAILED ("WRONG VALUE FOR EXPRESSION - '&'");
END IF;
P2 ("&" ("AB", "CD")(2..3));
IF F1(1..2) /= (FALSE,FALSE) THEN
FAILED ("WRONG VALUE FOR EXPRESSION - F1");
END IF;
P3 (F1(2..4));
N2 := NEW A1' (1,2,3,4,5,6);
IF F2(2..6) /= (2,3,4,5,6) THEN
FAILED ("WRONG VALUE FOR EXPRESSION - F2");
END IF;
F2(3..3) := (5 => 7);
IF N2.ALL /= (1,2,7,4,5,6) THEN
FAILED ("WRONG TARGET FOR ASSIGNMENT - F2");
END IF;
N2.ALL := (5,6,1,2,3,4);
P1 (F2(3..4), F2(5..6), F2(1..2), "F2");
IF N2.ALL /= (12,13,1,2,10,11) THEN
FAILED ("WRONG TARGET FOR (IN) OUT PARAMETER - F2");
END IF;
IF N3(2..7)(2..4) /= (2,3,4) THEN
FAILED ("WRONG VALUE FOR EXPRESSION - N3");
END IF;
N3(2..7)(4..5) := (8,9);
IF N3 /= (1,2,3,8,9,6,7) THEN
FAILED ("WRONG TARGET FOR ASSIGNMENT - N3");
END IF;
N3 := (5,3,4,1,2,6,7);
P1 (N3(2..7)(4..5), N3(2..7)(2..3), N3(2..7)(6..7), "N3");
IF N3 /= (5,10,11,1,2,12,13) THEN
FAILED ("WRONG TARGET FOR (IN) OUT PARAMETER - N3");
END IF;
IF N4(1)(3..5) /= (3,4,5) THEN
FAILED ("WRONG VALUE FOR EXPRESSION - N4");
END IF;
N4(2)(1..3) := (21,22,23);
IF N4 /= ((1,2,3,4,5,6),(21,22,23,10,11,12),
(13,14,15,16,17,18)) THEN
FAILED ("WRONG TARGET FOR ASSIGNMENT - N4");
END IF;
N4 := (1 => (18,19,20,21,22,23), 2 => (17,16,15,1,2,14),
3 => (7,3,4,5,6,8));
P1 (N4(2)(4..5), N4(3)(2..3), N4(1)(5..6), "N4");
IF N4 /= ((18,19,20,21,12,13),(17,16,15,1,2,14),
(7,10,11,5,6,8)) THEN
FAILED ("WRONG TARGET FOR (IN) OUT PARAMETER - N4");
END IF;
N1 := (1,2,3,4,5,6);
IF C41203A.N1(1..2) /= (1,2) THEN
FAILED ("WRONG VALUE FOR EXPRESSION - C41203A.N1");
END IF;
C41203A.N1(1..2) := (7,8);
IF N1 /= (7,8,3,4,5,6) THEN
FAILED ("WRONG TARGET FOR ASSIGNMENT - C41203A.N1");
END IF;
N1 := (1,2,3,4,5,6);
P1 (C41203A.N1(1..2), C41203A.N1(3..4), C41203A.N1(5..6),
"C41203A.N1");
IF N1 /= (1,2,10,11,12,13) THEN
FAILED ("WRONG TARGET FOR (IN) OUT PARAMETER " &
"- C41203A.N1");
END IF;
IF N5.S(1..5) /= "ABCDE" THEN
FAILED ("WRONG VALUE FOR EXPRESSION - N5");
END IF;
N5.S(4..6) := "PQR";
IF N5.S /= "ABCPQR" THEN
FAILED ("WRONG TARGET FOR ASSIGNMENT - N5");
END IF;
N5.S := "ABCDEF";
P5 (N5.S(5..6), N5.S(3..4), N5.S(1..2));
IF N5.S /= "WZXYEF" THEN
FAILED ("WRONG TARGET FOR (IN) OUT PARAMETER - N5");
END IF;
END;
RESULT;
END C41203A;
|
with constants;
use constants;
package objects is
type Mode is (CALM,TALKATIVE);
type operatorT is ('+', '-', '*');
type operatorsArray is array(0..2) of operatorT;
NL : constant String := Character'Val(13) & Character'Val(10);
protected type ProtectedCounter is
function Get return Integer;
procedure Increment;
private
value : Integer := 0;
end ProtectedCounter;
type taskk is record
first : Float;
second : Float;
operator : operatorT;
result : Float;
end record;
type product is record
value : Float;
end record;
-- type machineRecord is record
-- operation: operatorT;
-- end record;
task type machine is
entry Create (op : in operatorT);
entry DelegateTask (tsk : in out taskk);
end machine;
type employeeRecord is record
isPatient: Boolean;
numberOfTaskDone: ProtectedCounter;
end record;
task type employee is
entry Start (index : in Integer);
end employee;
task type chairman;
task type client;
type StorageListRange is new Positive range 1 .. MAX_STORAGE_CAPACITY;
type StorageArray is array(StorageListRange) of product;
type TaskListRange is new Positive range 1 .. MAX_TASKLIST_SIZE;
type TaskArray is array(TaskListRange) of taskk;
type MachinesListRange is new Positive range 1 .. NUMBER_OF_MACHINES;
type MachinesArray is array(MachinesListRange) of machine;
type MachinesSetArray is array(operatorT) of MachinesArray;
type chairman_array is array(1..MAX_CHAIRMEN) of chairman;
type clients_array is array(1..MAX_CLIENTS) of client;
type employee_array is array(1..MAX_EMPLOYEES) of employee;
type employeeRecord_array is array(1..MAX_EMPLOYEES) of employeeRecord;
procedure inform(message : String);
function doTask(tsk : in out taskk) return Float;
procedure printTaksArray(arr : TaskArray);
procedure printStorageArrat(arr : StorageArray);
protected type TaskBufferType is
entry Insert (An_Item : in taskk);
entry Remove (An_Item : out taskk);
function seeTaskList(len : out Natural;head1 : out TaskListRange) return TaskArray;
private
Length : Natural range 0 .. MAX_TASKLIST_SIZE := 0;
Head, Tail : TaskListRange := 1;
Data : TaskArray;
end TaskBufferType;
protected type StorageBufferType is
entry Insert (An_Item : in product);
entry Remove (An_Item : out product);
function seeStorage(len : out Natural;head1 : out StorageListRange) return StorageArray;
private
Length : Natural range 0 .. MAX_TASKLIST_SIZE := 0;
Head, Tail : StorageListRange := 1;
Data : StorageArray;
end StorageBufferType;
modee : Mode := CALM;
operators : operatorsArray := ('+', '-', '*');
tasks : TaskBufferType;
storage: StorageBufferType;
chairmen : chairman_array;
clients : clients_array;
employeeRecords : employeeRecord_array;
employees : employee_array;
machinesSet : MachinesSetArray;
end objects;
|
-----------------------------------------------------------------------
-- util-serialize-io -- IO Drivers for serialization
-- Copyright (C) 2010, 2011 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 Ada.Strings.Unbounded;
with Util.Beans.Objects;
with Util.Streams;
with Util.Streams.Buffered;
with Util.Serialize.Contexts;
with Util.Serialize.Mappers;
with Util.Log.Loggers;
with Util.Stacks;
package Util.Serialize.IO is
Parse_Error : exception;
-- ------------------------------
-- Output stream for serialization
-- ------------------------------
-- The <b>Output_Stream</b> interface defines the abstract operations for
-- the serialization framework to write objects on the stream according to
-- a target format such as XML or JSON.
type Output_Stream is limited interface and Util.Streams.Output_Stream;
procedure Start_Entity (Stream : in out Output_Stream;
Name : in String) is null;
procedure End_Entity (Stream : in out Output_Stream;
Name : in String) is null;
procedure Write_Attribute (Stream : in out Output_Stream;
Name : in String;
Value : in Util.Beans.Objects.Object) is abstract;
procedure Write_Entity (Stream : in out Output_Stream;
Name : in String;
Value : in Util.Beans.Objects.Object) is abstract;
procedure Start_Array (Stream : in out Output_Stream;
Length : in Ada.Containers.Count_Type) is null;
procedure End_Array (Stream : in out Output_Stream) is null;
type Parser is abstract new Util.Serialize.Contexts.Context with private;
-- Parse the stream using the JSON parser.
procedure Parse (Handler : in out Parser;
Stream : in out Util.Streams.Buffered.Buffered_Stream'Class) is abstract;
-- Read the file and parse it using the parser.
procedure Parse (Handler : in out Parser;
File : in String);
-- Parse the content string.
procedure Parse_String (Handler : in out Parser;
Content : in String);
-- Returns true if the <b>Parse</b> operation detected at least one error.
function Has_Error (Handler : in Parser) return Boolean;
-- Set the error logger to report messages while parsing and reading the input file.
procedure Set_Logger (Handler : in out Parser;
Logger : in Util.Log.Loggers.Logger_Access);
-- Start a new object associated with the given name. This is called when
-- the '{' is reached. The reader must be updated so that the next
-- <b>Set_Member</b> procedure will associate the name/value pair on the
-- new object.
procedure Start_Object (Handler : in out Parser;
Name : in String);
-- Finish an object associated with the given name. The reader must be
-- updated to be associated with the previous object.
procedure Finish_Object (Handler : in out Parser;
Name : in String);
procedure Start_Array (Handler : in out Parser;
Name : in String);
procedure Finish_Array (Handler : in out Parser;
Name : in String);
-- Set the name/value pair on the current object. For each active mapping,
-- find whether a rule matches our name and execute it.
procedure Set_Member (Handler : in out Parser;
Name : in String;
Value : in Util.Beans.Objects.Object;
Attribute : in Boolean := False);
-- Get the current location (file and line) to report an error message.
function Get_Location (Handler : in Parser) return String;
-- Report an error while parsing the input stream. The error message will be reported
-- on the logger associated with the parser. The parser will be set as in error so that
-- the <b>Has_Error</b> function will return True after parsing the whole file.
procedure Error (Handler : in out Parser;
Message : in String);
procedure Add_Mapping (Handler : in out Parser;
Path : in String;
Mapper : in Util.Serialize.Mappers.Mapper_Access);
-- Dump the mapping tree on the logger using the INFO log level.
procedure Dump (Handler : in Parser'Class;
Logger : in Util.Log.Loggers.Logger'Class);
private
-- Implementation limitation: the max number of active mapping nodes
MAX_NODES : constant Positive := 10;
type Mapper_Access_Array is array (1 .. MAX_NODES) of Serialize.Mappers.Mapper_Access;
procedure Push (Handler : in out Parser);
-- Pop the context and restore the previous context when leaving an element
procedure Pop (Handler : in out Parser);
function Find_Mapper (Handler : in Parser;
Name : in String) return Util.Serialize.Mappers.Mapper_Access;
type Element_Context is record
-- The object mapper being process.
Object_Mapper : Util.Serialize.Mappers.Mapper_Access;
-- The active mapping nodes.
Active_Nodes : Mapper_Access_Array;
end record;
type Element_Context_Access is access all Element_Context;
package Context_Stack is new Util.Stacks (Element_Type => Element_Context,
Element_Type_Access => Element_Context_Access);
type Parser is abstract new Util.Serialize.Contexts.Context with record
Error_Flag : Boolean := False;
Stack : Context_Stack.Stack;
Mapping_Tree : aliased Mappers.Mapper;
Current_Mapper : Util.Serialize.Mappers.Mapper_Access;
-- The file name to use when reporting errors.
File : Ada.Strings.Unbounded.Unbounded_String;
-- The logger which is used to report error messages when parsing an input file.
Error_Logger : Util.Log.Loggers.Logger_Access := null;
end record;
end Util.Serialize.IO;
|
-- { dg-do run }
with System;
procedure Interface1 is
package Pkg is
type I1 is interface;
type Root is tagged record
Data : string (1 .. 300);
end record;
type DT is new Root and I1 with null record;
end Pkg;
use Pkg;
use type System.Address;
Obj : DT;
procedure IW (O : I1'Class) is
begin
if O'Address /= Obj'Address then
raise Program_Error;
end if;
end IW;
begin
IW (Obj);
end Interface1;
|
-- This package has been generated automatically by GNATtest.
-- Do not edit any part of it, see GNATtest documentation for more details.
-- begin read only
with Gnattest_Generated;
package Bases.Ship.Test_Data.Tests is
type Test is new GNATtest_Generated.GNATtest_Standard.Bases.Ship.Test_Data
.Test with
null record;
procedure Test_Repair_Ship_a28a55_2d5600(Gnattest_T: in out Test);
-- bases-ship.ads:60:4:Repair_Ship:Test_RepairShip
procedure Test_Upgrade_Ship_a05e89_cdbb2e(Gnattest_T: in out Test);
-- bases-ship.ads:73:4:Upgrade_Ship:Test_UpdgradeShip
procedure Test_Pay_For_Dock_9dddef_d92d34(Gnattest_T: in out Test);
-- bases-ship.ads:83:4:Pay_For_Dock:Test_PayForDock
procedure Test_Repair_Cost_eb3d7e_6cc7b1(Gnattest_T: in out Test);
-- bases-ship.ads:99:4:Repair_Cost:Test_RepairCost
end Bases.Ship.Test_Data.Tests;
-- end read only
|
------------------------------------------------------------------------------
-- Copyright (c) 2015-2017, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Natools.Web.Sites.Updates provides types representing an update to a --
-- site object. --
------------------------------------------------------------------------------
package Natools.Web.Sites.Updates is
type Site_Update is interface;
procedure Update (Self : in Site_Update; Object : in out Site) is abstract;
-- Actually perform the update
type Expiration_Purger is new Site_Update with private;
overriding procedure Update
(Self : in Expiration_Purger;
Object : in out Site);
-- Purge expiration data
procedure Purge_Expiration (Object : in Site);
-- Enqueue a purger in Object
type Reloader is new Site_Update with private;
overriding procedure Update (Self : in Reloader; Object : in out Site);
-- Reload site data
procedure Reload (Object : in Site);
-- Enqueue a reloader in Object
private
type Expiration_Purger is new Site_Update with null record;
type Reloader is new Site_Update with null record;
end Natools.Web.Sites.Updates;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- M L I B . T G T . S P E C I F I C --
-- (AIX Version) --
-- --
-- B o d y --
-- --
-- Copyright (C) 2003-2008, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. 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 is the AIX version of the body
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with MLib.Fil;
with MLib.Utl;
with Opt;
with Output; use Output;
with Prj.Com;
with Prj.Util; use Prj.Util;
package body MLib.Tgt.Specific is
-- Local subprograms
-- These *ALL* require comments ???
function Archive_Indexer return String;
-- What is this???
procedure Build_Dynamic_Library
(Ofiles : Argument_List;
Options : Argument_List;
Interfaces : Argument_List;
Lib_Filename : String;
Lib_Dir : String;
Symbol_Data : Symbol_Record;
Driver_Name : Name_Id := No_Name;
Lib_Version : String := "";
Auto_Init : Boolean := False);
function DLL_Ext return String;
function Library_Major_Minor_Id_Supported return Boolean;
function Support_For_Libraries return Library_Support;
-- Local variables
No_Arguments : aliased Argument_List := (1 .. 0 => null);
Empty_Argument_List : constant Argument_List_Access := No_Arguments'Access;
Bexpall : aliased String := "-Wl,-bexpall";
Bexpall_Option : constant String_Access := Bexpall'Access;
-- The switch to export all symbols
Lpthreads : aliased String := "-lpthreads";
Native_Thread_Options : aliased Argument_List := (1 => Lpthreads'Access);
-- The switch to use when linking a library against libgnarl when using
-- Native threads.
Lgthreads : aliased String := "-lgthreads";
Lmalloc : aliased String := "-lmalloc";
FSU_Thread_Options : aliased Argument_List :=
(1 => Lgthreads'Access, 2 => Lmalloc'Access);
-- The switches to use when linking a library against libgnarl when using
-- FSU threads.
Thread_Options : Argument_List_Access := Empty_Argument_List;
-- Designate the thread switches to used when linking a library against
-- libgnarl. Depends on the thread library (Native or FSU). Resolved for
-- the first library linked against libgnarl.
---------------------
-- Archive_Indexer --
---------------------
function Archive_Indexer return String is
begin
return "";
end Archive_Indexer;
---------------------------
-- Build_Dynamic_Library --
---------------------------
procedure Build_Dynamic_Library
(Ofiles : Argument_List;
Options : Argument_List;
Interfaces : Argument_List;
Lib_Filename : String;
Lib_Dir : String;
Symbol_Data : Symbol_Record;
Driver_Name : Name_Id := No_Name;
Lib_Version : String := "";
Auto_Init : Boolean := False)
is
pragma Unreferenced (Interfaces);
pragma Unreferenced (Symbol_Data);
pragma Unreferenced (Lib_Version);
pragma Unreferenced (Auto_Init);
Lib_File : constant String :=
Lib_Dir & Directory_Separator & "lib" &
MLib.Fil.Append_To (Lib_Filename, DLL_Ext);
-- The file name of the library
Thread_Opts : Argument_List_Access := Empty_Argument_List;
-- Set to Thread_Options if -lgnarl is found in the Options
begin
if Opt.Verbose_Mode then
Write_Str ("building relocatable shared library ");
Write_Line (Lib_File);
end if;
-- Look for -lgnarl in Options. If found, set the thread options
for J in Options'Range loop
if Options (J).all = "-lgnarl" then
-- If Thread_Options is null, read s-osinte.ads to discover the
-- thread library and set Thread_Options accordingly.
if Thread_Options = null then
declare
File : Text_File;
Line : String (1 .. 100);
Last : Natural;
begin
Open
(File, Include_Dir_Default_Prefix & "/s-osinte.ads");
while not End_Of_File (File) loop
Get_Line (File, Line, Last);
if Index (Line (1 .. Last), "-lpthreads") /= 0 then
Thread_Options := Native_Thread_Options'Access;
exit;
elsif Index (Line (1 .. Last), "-lgthreads") /= 0 then
Thread_Options := FSU_Thread_Options'Access;
exit;
end if;
end loop;
Close (File);
if Thread_Options = null then
Prj.Com.Fail ("cannot find the thread library in use");
end if;
exception
when others =>
Prj.Com.Fail ("cannot open s-osinte.ads");
end;
end if;
Thread_Opts := Thread_Options;
exit;
end if;
end loop;
-- Finally, call GCC (or the driver specified) to build the library
MLib.Utl.Gcc
(Output_File => Lib_File,
Objects => Ofiles,
Options => Options & Bexpall_Option,
Driver_Name => Driver_Name,
Options_2 => Thread_Opts.all);
end Build_Dynamic_Library;
-------------
-- DLL_Ext --
-------------
function DLL_Ext return String is
begin
return "a";
end DLL_Ext;
--------------------------------------
-- Library_Major_Minor_Id_Supported --
--------------------------------------
function Library_Major_Minor_Id_Supported return Boolean is
begin
return False;
end Library_Major_Minor_Id_Supported;
---------------------------
-- Support_For_Libraries --
---------------------------
function Support_For_Libraries return Library_Support is
begin
return Static_Only;
end Support_For_Libraries;
begin
Archive_Indexer_Ptr := Archive_Indexer'Access;
Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
DLL_Ext_Ptr := DLL_Ext'Access;
Library_Major_Minor_Id_Supported_Ptr :=
Library_Major_Minor_Id_Supported'Access;
Support_For_Libraries_Ptr := Support_For_Libraries'Access;
end MLib.Tgt.Specific;
|
with Giza.Colors; use Giza.Colors;
with Giza.Widget;
with Giza.Widget.Button;
with Giza.Types; use Giza.Types;
use Giza;
package body Test_Tiles_Window is
-------------
-- On_Init --
-------------
overriding procedure On_Init
(This : in out Tiles_Window)
is
function New_Text (Str : String) return Widget.Reference;
--------------
-- New_Text --
--------------
function New_Text (Str : String) return Widget.Reference is
Txt : Button.Ref;
begin
Txt := new Button.Instance;
Txt.Set_Text (Str);
Txt.Set_Background (White);
Txt.Set_Foreground (Black);
return Widget.Reference (Txt);
end New_Text;
Size : constant Size_T := This.Get_Size;
begin
On_Init (Test_Window (This));
This.Tile_Top_Down := new Tiles.Instance (3, Tiles.Top_Down);
This.Tile_Bottom_Up := new Tiles.Instance (3, Tiles.Bottom_Up);
This.Tile_Right_Left := new Tiles.Instance (3, Tiles.Right_Left);
This.Tile_Left_Right := new Tiles.Instance (3, Tiles.Left_Right);
This.Tile_Top_Down.Set_Size ((Size.W / 2,
Size.H / 2));
This.Tile_Bottom_Up.Set_Size (This.Tile_Top_Down.Get_Size);
This.Tile_Right_Left.Set_Size (This.Tile_Top_Down.Get_Size);
This.Tile_Left_Right.Set_Size (This.Tile_Top_Down.Get_Size);
for Index in 1 .. 3 loop
This.Tile_Top_Down.Set_Child (Index, New_Text ("TD" & Index'Img));
This.Tile_Bottom_Up.Set_Child (Index, New_Text ("BU" & Index'Img));
This.Tile_Right_Left.Set_Child (Index, New_Text ("RL" & Index'Img));
This.Tile_Left_Right.Set_Child (Index, New_Text ("LR" & Index'Img));
end loop;
This.Add_Child (Widget.Reference (This.Tile_Top_Down),
(0, 0));
This.Add_Child (Widget.Reference (This.Tile_Bottom_Up),
(Size.W / 2, 0));
This.Add_Child (Widget.Reference (This.Tile_Right_Left),
(0, Size.H / 2));
This.Add_Child (Widget.Reference (This.Tile_Left_Right),
(Size.W / 2, Size.H / 2));
end On_Init;
------------------
-- On_Displayed --
------------------
overriding procedure On_Displayed
(This : in out Tiles_Window)
is
pragma Unreferenced (This);
begin
null;
end On_Displayed;
---------------
-- On_Hidden --
---------------
overriding procedure On_Hidden
(This : in out Tiles_Window)
is
pragma Unreferenced (This);
begin
null;
end On_Hidden;
end Test_Tiles_Window;
|
with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Calendar.Time_Zones; use Ada.Calendar.Time_Zones;
with Ada.Text_IO; use Ada.Text_IO;
with Net_Times;
procedure Test is
-- use type Time_Offset;
Now : Time := Clock;
PST : Net_Times.Net_Time := Net_Times.Net_Time'(2019, 7, 20, 16, 6, 21,
Sub_Second => 0.0, TZ_Valid => True, Time_Zone => -8 * 60);
EST : Net_Times.Net_Time := Net_Times.Net_Time'(2019, 7, 20, 16, 6, 21,
Sub_Second => 0.0, TZ_Valid => True, Time_Zone => -5 * 60);
begin
Put ("Now: ");
Put_Line (Net_Times.Image (Now));
Put ("PST: ");
Put_Line (Net_Times.Image (PST));
Put ("EST: ");
Put_Line (Net_Times.Image (EST));
end Test;
|
package body Tkmrpc.Contexts.isa
is
pragma Warnings
(Off, "* already use-visible through previous use type clause");
use type Types.isa_id_type;
use type Types.ae_id_type;
use type Types.ia_id_type;
use type Types.key_type;
use type Types.rel_time_type;
use type Types.duration_type;
pragma Warnings
(On, "* already use-visible through previous use type clause");
type isa_FSM_Type is record
State : isa_State_Type;
ae_id : Types.ae_id_type;
ia_id : Types.ia_id_type;
sk_d : Types.key_type;
creation_time : Types.rel_time_type;
max_rekey_age : Types.duration_type;
end record;
-- IKE SA Context
Null_isa_FSM : constant isa_FSM_Type
:= isa_FSM_Type'
(State => clean,
ae_id => Types.ae_id_type'First,
ia_id => Types.ia_id_type'First,
sk_d => Types.Null_key_type,
creation_time => Types.rel_time_type'First,
max_rekey_age => Types.duration_type'First);
type Context_Array_Type is
array (Types.isa_id_type) of isa_FSM_Type;
Context_Array : Context_Array_Type := Context_Array_Type'
(others => (Null_isa_FSM));
-------------------------------------------------------------------------
function Get_State
(Id : Types.isa_id_type)
return isa_State_Type
is
begin
return Context_Array (Id).State;
end Get_State;
-------------------------------------------------------------------------
function Has_ae_id
(Id : Types.isa_id_type;
ae_id : Types.ae_id_type)
return Boolean
is (Context_Array (Id).ae_id = ae_id);
-------------------------------------------------------------------------
function Has_creation_time
(Id : Types.isa_id_type;
creation_time : Types.rel_time_type)
return Boolean
is (Context_Array (Id).creation_time = creation_time);
-------------------------------------------------------------------------
function Has_ia_id
(Id : Types.isa_id_type;
ia_id : Types.ia_id_type)
return Boolean
is (Context_Array (Id).ia_id = ia_id);
-------------------------------------------------------------------------
function Has_max_rekey_age
(Id : Types.isa_id_type;
max_rekey_age : Types.duration_type)
return Boolean
is (Context_Array (Id).max_rekey_age = max_rekey_age);
-------------------------------------------------------------------------
function Has_sk_d
(Id : Types.isa_id_type;
sk_d : Types.key_type)
return Boolean
is (Context_Array (Id).sk_d = sk_d);
-------------------------------------------------------------------------
function Has_State
(Id : Types.isa_id_type;
State : isa_State_Type)
return Boolean
is (Context_Array (Id).State = State);
-------------------------------------------------------------------------
pragma Warnings
(Off, "condition can only be False if invalid values present");
function Is_Valid (Id : Types.isa_id_type) return Boolean
is (Context_Array'First <= Id and Id <= Context_Array'Last);
pragma Warnings
(On, "condition can only be False if invalid values present");
-------------------------------------------------------------------------
procedure create
(Id : Types.isa_id_type;
ae_id : Types.ae_id_type;
ia_id : Types.ia_id_type;
sk_d : Types.key_type;
creation_time : Types.rel_time_type)
is
begin
Context_Array (Id).ae_id := ae_id;
Context_Array (Id).ia_id := ia_id;
Context_Array (Id).sk_d := sk_d;
Context_Array (Id).creation_time := creation_time;
Context_Array (Id).State := active;
end create;
-------------------------------------------------------------------------
function get_ae_id
(Id : Types.isa_id_type)
return Types.ae_id_type
is
begin
return Context_Array (Id).ae_id;
end get_ae_id;
-------------------------------------------------------------------------
function get_sk_d
(Id : Types.isa_id_type)
return Types.key_type
is
begin
return Context_Array (Id).sk_d;
end get_sk_d;
-------------------------------------------------------------------------
procedure invalidate
(Id : Types.isa_id_type)
is
begin
Context_Array (Id).State := invalid;
end invalidate;
-------------------------------------------------------------------------
procedure reset
(Id : Types.isa_id_type)
is
begin
Context_Array (Id).ae_id := Types.ae_id_type'First;
Context_Array (Id).ia_id := Types.ia_id_type'First;
Context_Array (Id).sk_d := Types.Null_key_type;
Context_Array (Id).creation_time := Types.rel_time_type'First;
Context_Array (Id).max_rekey_age := Types.duration_type'First;
Context_Array (Id).State := clean;
end reset;
end Tkmrpc.Contexts.isa;
|
-- { dg-do run { target i?86-*-* x86_64-*-* alpha*-*-* ia64-*-* } }
-- { dg-options "-O2" }
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Interfaces; use Interfaces;
with Ada.Unchecked_Conversion;
procedure Opt47 is
subtype String4 is String (1 .. 4);
function To_String4 is new Ada.Unchecked_Conversion (Unsigned_32, String4);
type Arr is array (Integer range <>) of Unsigned_32;
Leaf : Arr (1 .. 4) := (1349478766, 1948272498, 1702436946, 1702061409);
Value : Unsigned_32;
Result : String (1 .. 32);
Last : Integer := 0;
begin
for I in 1 .. 4 loop
Value := Leaf (I);
for J in reverse String4'Range loop
if Is_Graphic (To_String4 (Value)(J)) then
Last := Last + 1;
Result (Last) := To_String4 (Value)(J);
end if;
end loop;
end loop;
if Result (1) /= 'P' then
raise Program_Error;
end if;
end;
|
pragma Style_Checks (Off);
-- This spec has been automatically generated from ATSAMD51G19A.svd
pragma Restrictions (No_Elaboration_Code);
with HAL;
with System;
package SAM_SVD.WDT is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- Control
type WDT_CTRLA_Register is record
-- unspecified
Reserved_0_0 : HAL.Bit := 16#0#;
-- Enable
ENABLE : Boolean := False;
-- Watchdog Timer Window Mode Enable
WEN : Boolean := False;
-- unspecified
Reserved_3_6 : HAL.UInt4 := 16#0#;
-- Always-On
ALWAYSON : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for WDT_CTRLA_Register use record
Reserved_0_0 at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
WEN at 0 range 2 .. 2;
Reserved_3_6 at 0 range 3 .. 6;
ALWAYSON at 0 range 7 .. 7;
end record;
-- Time-Out Period
type CONFIG_PERSelect is
(-- 8 clock cycles
CYC8,
-- 16 clock cycles
CYC16,
-- 32 clock cycles
CYC32,
-- 64 clock cycles
CYC64,
-- 128 clock cycles
CYC128,
-- 256 clock cycles
CYC256,
-- 512 clock cycles
CYC512,
-- 1024 clock cycles
CYC1024,
-- 2048 clock cycles
CYC2048,
-- 4096 clock cycles
CYC4096,
-- 8192 clock cycles
CYC8192,
-- 16384 clock cycles
CYC16384)
with Size => 4;
for CONFIG_PERSelect use
(CYC8 => 0,
CYC16 => 1,
CYC32 => 2,
CYC64 => 3,
CYC128 => 4,
CYC256 => 5,
CYC512 => 6,
CYC1024 => 7,
CYC2048 => 8,
CYC4096 => 9,
CYC8192 => 10,
CYC16384 => 11);
-- Window Mode Time-Out Period
type CONFIG_WINDOWSelect is
(-- 8 clock cycles
CYC8,
-- 16 clock cycles
CYC16,
-- 32 clock cycles
CYC32,
-- 64 clock cycles
CYC64,
-- 128 clock cycles
CYC128,
-- 256 clock cycles
CYC256,
-- 512 clock cycles
CYC512,
-- 1024 clock cycles
CYC1024,
-- 2048 clock cycles
CYC2048,
-- 4096 clock cycles
CYC4096,
-- 8192 clock cycles
CYC8192,
-- 16384 clock cycles
CYC16384)
with Size => 4;
for CONFIG_WINDOWSelect use
(CYC8 => 0,
CYC16 => 1,
CYC32 => 2,
CYC64 => 3,
CYC128 => 4,
CYC256 => 5,
CYC512 => 6,
CYC1024 => 7,
CYC2048 => 8,
CYC4096 => 9,
CYC8192 => 10,
CYC16384 => 11);
-- Configuration
type WDT_CONFIG_Register is record
-- Time-Out Period
PER : CONFIG_PERSelect := SAM_SVD.WDT.CYC16384;
-- Window Mode Time-Out Period
WINDOW : CONFIG_WINDOWSelect := SAM_SVD.WDT.CYC16384;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for WDT_CONFIG_Register use record
PER at 0 range 0 .. 3;
WINDOW at 0 range 4 .. 7;
end record;
-- Early Warning Interrupt Time Offset
type EWCTRL_EWOFFSETSelect is
(-- 8 clock cycles
CYC8,
-- 16 clock cycles
CYC16,
-- 32 clock cycles
CYC32,
-- 64 clock cycles
CYC64,
-- 128 clock cycles
CYC128,
-- 256 clock cycles
CYC256,
-- 512 clock cycles
CYC512,
-- 1024 clock cycles
CYC1024,
-- 2048 clock cycles
CYC2048,
-- 4096 clock cycles
CYC4096,
-- 8192 clock cycles
CYC8192,
-- 16384 clock cycles
CYC16384)
with Size => 4;
for EWCTRL_EWOFFSETSelect use
(CYC8 => 0,
CYC16 => 1,
CYC32 => 2,
CYC64 => 3,
CYC128 => 4,
CYC256 => 5,
CYC512 => 6,
CYC1024 => 7,
CYC2048 => 8,
CYC4096 => 9,
CYC8192 => 10,
CYC16384 => 11);
-- Early Warning Interrupt Control
type WDT_EWCTRL_Register is record
-- Early Warning Interrupt Time Offset
EWOFFSET : EWCTRL_EWOFFSETSelect := SAM_SVD.WDT.CYC16384;
-- unspecified
Reserved_4_7 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for WDT_EWCTRL_Register use record
EWOFFSET at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
end record;
-- Interrupt Enable Clear
type WDT_INTENCLR_Register is record
-- Early Warning Interrupt Enable
EW : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for WDT_INTENCLR_Register use record
EW at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Interrupt Enable Set
type WDT_INTENSET_Register is record
-- Early Warning Interrupt Enable
EW : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for WDT_INTENSET_Register use record
EW at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Interrupt Flag Status and Clear
type WDT_INTFLAG_Register is record
-- Early Warning
EW : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for WDT_INTFLAG_Register use record
EW at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Synchronization Busy
type WDT_SYNCBUSY_Register is record
-- unspecified
Reserved_0_0 : HAL.Bit;
-- Read-only. Enable Synchronization Busy
ENABLE : Boolean;
-- Read-only. Window Enable Synchronization Busy
WEN : Boolean;
-- Read-only. Always-On Synchronization Busy
ALWAYSON : Boolean;
-- Read-only. Clear Synchronization Busy
CLEAR : Boolean;
-- unspecified
Reserved_5_31 : HAL.UInt27;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for WDT_SYNCBUSY_Register use record
Reserved_0_0 at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
WEN at 0 range 2 .. 2;
ALWAYSON at 0 range 3 .. 3;
CLEAR at 0 range 4 .. 4;
Reserved_5_31 at 0 range 5 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Watchdog Timer
type WDT_Peripheral is record
-- Control
CTRLA : aliased WDT_CTRLA_Register;
-- Configuration
CONFIG : aliased WDT_CONFIG_Register;
-- Early Warning Interrupt Control
EWCTRL : aliased WDT_EWCTRL_Register;
-- Interrupt Enable Clear
INTENCLR : aliased WDT_INTENCLR_Register;
-- Interrupt Enable Set
INTENSET : aliased WDT_INTENSET_Register;
-- Interrupt Flag Status and Clear
INTFLAG : aliased WDT_INTFLAG_Register;
-- Synchronization Busy
SYNCBUSY : aliased WDT_SYNCBUSY_Register;
-- Clear
CLEAR : aliased HAL.UInt8;
end record
with Volatile;
for WDT_Peripheral use record
CTRLA at 16#0# range 0 .. 7;
CONFIG at 16#1# range 0 .. 7;
EWCTRL at 16#2# range 0 .. 7;
INTENCLR at 16#4# range 0 .. 7;
INTENSET at 16#5# range 0 .. 7;
INTFLAG at 16#6# range 0 .. 7;
SYNCBUSY at 16#8# range 0 .. 31;
CLEAR at 16#C# range 0 .. 7;
end record;
-- Watchdog Timer
WDT_Periph : aliased WDT_Peripheral
with Import, Address => WDT_Base;
end SAM_SVD.WDT;
|
with Ada.Long_Integer_Text_IO;
-- Copyright 2021 Melwyn Francis Carlo
procedure A008 is
use Ada.Long_Integer_Text_IO;
Thousand_Digit_Num : constant String :=
"73167176531330624919225119674426574742355349194934" &
"96983520312774506326239578318016984801869478851843" &
"85861560789112949495459501737958331952853208805511" &
"12540698747158523863050715693290963295227443043557" &
"66896648950445244523161731856403098711121722383113" &
"62229893423380308135336276614282806444486645238749" &
"30358907296290491560440772390713810515859307960866" &
"70172427121883998797908792274921901699720888093776" &
"65727333001053367881220235421809751254540594752243" &
"52584907711670556013604839586446706324415722155397" &
"53697817977846174064955149290862569321978468622482" &
"83972241375657056057490261407972968652414535100474" &
"82166370484403199890008895243450658541227588666881" &
"16427171479924442928230863465674813919123162824586" &
"17866458359124566529476545682848912883142607690042" &
"24219022671055626321111109370544217506941658960408" &
"07198403850962455444362981230987879927244284909188" &
"84580156166097919133875499200524063689912560717606" &
"05886116467109405077541002256983155200055935729725" &
"71636269561882670428252483600823257530420752963450";
Temp_Pos : Integer;
Product, Temp_Val : Long_Integer;
begin
Product := 0;
for I in 1 .. Thousand_Digit_Num'Length - 13 loop
Temp_Pos := Thousand_Digit_Num'First + I - 1;
if Integer'Value (Thousand_Digit_Num (Temp_Pos .. Temp_Pos)) >= 5 then
Temp_Val := 1;
for J in 0 .. 13 - 1 loop
Temp_Pos := Thousand_Digit_Num'First + I + J - 1;
Temp_Val := Temp_Val * Long_Integer'Value (Thousand_Digit_Num (
Temp_Pos .. Temp_Pos));
if Temp_Val > Product then
Product := Temp_Val;
end if;
end loop;
end if;
end loop;
Put (Product, Width => 0);
end A008;
|
with Extraction.Node_Edge_Types;
with Extraction.Utilities;
package body Extraction.With_Clauses is
use type LALCO.Ada_Node_Kind_Type;
procedure Extract_Edges
(Node : LAL.Ada_Node'Class; Graph : Graph_Operations.Graph_Context)
is
begin
if Node.Kind = LALCO.Ada_With_Clause then
declare
With_Clause : constant LAL.With_Clause := Node.As_With_Clause;
begin
for Package_Name of With_Clause.F_Packages loop
if not Utilities.Get_Referenced_Decl (Package_Name).Is_Null
then -- TODO: Remove after TB01-005 has been fixed
declare
Target_Name : constant LAL.Defining_Name :=
Utilities.Get_Referenced_Defining_Name (Package_Name);
Target_Decl : constant LAL.Basic_Decl :=
Utilities.Get_Referenced_Decl (Package_Name);
begin
Graph.Write_Edge
(Package_Name.Unit, Target_Name, Target_Decl,
Node_Edge_Types.Edge_Type_Imports);
end;
end if;
end loop;
end;
end if;
end Extract_Edges;
end Extraction.With_Clauses;
|
-------------------------------------------------------------------------------
-- Copyright 2021, The Trendy Terminal 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 Interfaces.C.Strings;
with System;
package Trendy_Terminal.Linux is
---------------------------------------------------------------------------
-- Interfacing with C
---------------------------------------------------------------------------
-- Crash course in how this works.
-- https://en.wikibooks.org/wiki/Ada_Programming/Types/access#Access_vs._System.Address
type BOOL is new Interfaces.C.int;
type FD is new Interfaces.C.int;
type FILE_Ptr is new System.Address;
function fileno (Stream : FILE_Ptr) return FD with
Import => True,
Convention => C;
function isatty (File_Descriptor : FD) return BOOL with
Import => True,
Convention => C;
stdin : aliased FILE_Ptr;
stdout : aliased FILE_Ptr;
stderr : aliased FILE_Ptr;
pragma Import (C, stdin, "stdin");
pragma Import (C, stdout, "stdout");
pragma Import (C, stderr, "stderr");
NCCS : constant := 32;
type tcflag_t is new Interfaces.C.unsigned;
type cc_t is new Interfaces.C.unsigned_char;
type speed_t is new Interfaces.C.unsigned;
type cc_array is array (Natural range 0 .. NCCS - 1) of cc_t;
--!pp off
type c_lflag_t is (ISIG,
ICANON,
XCASE,
ECHO,
ECHOE,
ECHOK,
ECHONL,
NOFLSH,
TOSTOP,
ECHOCTL,
ECHOPRT,
ECHOKE,
FLUSHO,
PENDIN);
for c_lflag_t use
(ISIG => 16#0000001#,
ICANON => 16#0000002#,
XCASE => 16#0000004#,
ECHO => 16#0000010#,
ECHOE => 16#0000020#,
ECHOK => 16#0000040#,
ECHONL => 16#0000100#,
NOFLSH => 16#0000200#,
TOSTOP => 16#0000400#,
ECHOCTL => 16#0001000#,
ECHOPRT => 16#0002000#,
ECHOKE => 16#0004000#,
FLUSHO => 16#0010000#,
PENDIN => 16#0040000#
);
--!pp on
pragma Warnings (Off, "bits of *unused");
type Local_Flags is array (c_lflag_t) of Boolean with
Pack,
Size => 32;
pragma Warnings (On, "bits of *unused");
type Termios is record
c_iflag : tcflag_t;
c_oflag : tcflag_t;
c_cflag : tcflag_t;
c_lflag : Local_Flags;
c_line : cc_t;
c_cc : cc_array;
c_ispeed : speed_t;
c_ospeed : speed_t;
end record with
Convention => C;
function tcgetattr (File_Descriptor : FD; Terminal : System.Address) return BOOL with
Import => True,
Convention => C;
type Application_Time is
(TCSANOW, -- immediate effect
TCSADRAIN, -- after all output written
TCSAFLUSH -- like drain, except input received as well
);
for Application_Time use (TCSANOW => 0, TCSADRAIN => 1, TCSAFLUSH => 2);
function tcsetattr
(File_Descriptor : FD; Effect_Time : Application_Time; Terminal : System.Address) return BOOL with
Import => True,
Convention => C;
end Trendy_Terminal.Linux;
|
-- Ada_GUI implementation based on Gnoga. Adapted 2021
-- --
-- GNOGA - The GNU Omnificent GUI for Ada --
-- --
-- G N O G A . G U I . E L E M E N T . L I S T S --
-- --
-- B o d y --
-- --
-- --
-- Copyright (C) 2014 David Botton --
-- --
-- This library is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 3, or (at your option) any --
-- later version. This library is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are --
-- granted additional permissions described in the GCC Runtime Library --
-- Exception, version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- For more information please go to http://www.gnoga.com --
------------------------------------------------------------------------------
with Ada.Strings.Fixed;
package body Ada_GUI.Gnoga.Gui.Element.List is
------------
-- Create --
------------
procedure Create
(List : in out Ordered_List_Type;
Parent : in out Gnoga.Gui.Base_Type'Class;
ID : in String := "")
is
begin
List.Create_From_HTML (Parent, "<ol />", ID);
end Create;
---------------
-- List_Kind --
---------------
procedure List_Kind
(List : in out Ordered_List_Type;
Value : in List_Kind_Type)
is
function Adjusted_Image (S : String) return String;
function Adjusted_Image (S : String) return String is
P : constant Integer := Ada.Strings.Fixed.Index (S, "_");
begin
if P = 0 then
return S;
else
return Adjusted_Image (S (S'First .. (P - 1)) &
"-" & S ((P + 1) .. S'Last));
end if;
end Adjusted_Image;
begin
List.Style ("list-style-type", Adjusted_Image (Value'Img));
end List_Kind;
-------------------
-- List_Location --
-------------------
procedure List_Location
(List : in out Ordered_List_Type;
Value : in List_Location_Type)
is
begin
List.Style ("list-style-position", Value'Img);
end List_Location;
------------
-- Create --
------------
overriding
procedure Create
(List : in out Unordered_List_Type;
Parent : in out Gnoga.Gui.Base_Type'Class;
ID : in String := "")
is
begin
List.Create_From_HTML (Parent, "<ul />", ID);
end Create;
------------
-- Create --
------------
procedure Create
(Item : in out List_Item_Type;
Parent : in out Ordered_List_Type'Class;
Text : in String := "";
ID : in String := "")
is
begin
Item.Create_From_HTML
(Parent, "<li>" & Escape_Quotes (Text) & "</li>", ID);
end Create;
-----------
-- Value --
-----------
procedure Value (Element : in out List_Item_Type; Value : in String) is
begin
Element.Property ("value", Value);
end Value;
function Value (Element : List_Item_Type) return String is
begin
return Element.Property ("value");
end Value;
------------
-- Create --
------------
procedure Create
(List : in out Definition_List_Type;
Parent : in out Gnoga.Gui.Base_Type'Class;
ID : in String := "")
is
begin
List.Create_From_HTML (Parent, "<dl />", ID);
end Create;
------------
-- Create --
------------
procedure Create
(Item : in out Term_Type;
Parent : in out Definition_List_Type'Class;
Text : in String := "";
ID : in String := "")
is
begin
Item.Create_From_HTML
(Parent, "<dt>" & Escape_Quotes (Text) & "</dt>", ID);
end Create;
------------
-- Create --
------------
procedure Create
(Item : in out Description_Type;
Parent : in out Definition_List_Type'Class;
Text : in String := "";
ID : in String := "")
is
begin
Item.Create_From_HTML
(Parent, "<dd>" & Escape_Quotes (Text) & "</dd>", ID);
end Create;
end Ada_GUI.Gnoga.Gui.Element.List;
|
-----------------------------------------------------------------------
-- util-systems-dlls -- Windows shared library support
-- Copyright (C) 2013 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with System;
with Interfaces.C;
package Util.Systems.DLLs is
-- The shared library handle.
type Handle is private;
Null_Handle : constant Handle;
-- Exception raised when there is a problem loading a shared library.
Load_Error : exception;
-- Exception raised when a symbol cannot be found in a shared library.
Not_Found : exception;
Extension : constant String := ".dll";
subtype Flags is Interfaces.C.int;
-- Load the shared library with the given name or path and return a library handle.
-- Raises the <tt>Load_Error</tt> exception if the library cannot be loaded.
function Load (Path : in String;
Mode : in Flags := 0) return Handle;
-- Unload the shared library.
procedure Unload (Lib : in Handle);
-- Get a global symbol with the given name in the library.
-- Raises the <tt>Not_Found</tt> exception if the symbol does not exist.
function Get_Symbol (Lib : in Handle;
Name : in String) return System.Address;
private
type Handle is new System.Address;
Null_Handle : constant Handle := Handle (System.Null_Address);
end Util.Systems.DLLs;
|
------------------------------------------------------------------------------
-- Copyright (c) 2014-2015, 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. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Common package holds a single Natools.Web.Sites.Site object and --
-- provides an AWS callback to respond with it. --
------------------------------------------------------------------------------
with AWS.Response;
with AWS.Status;
with Natools.S_Expressions;
with Natools.Web.Sites.Holders;
with Natools.Web.Sites.Updates;
private with GNAT.SHA256;
package Common is
function SHA256_Digest (Message : in Natools.S_Expressions.Atom)
return Natools.S_Expressions.Atom;
type Holder is new Natools.Web.Sites.Holders.Holder with null record;
overriding procedure Queue
(Object : in out Holder;
Update : in Natools.Web.Sites.Updates.Site_Update'Class);
overriding procedure Load
(Self : in out Holder;
File_Name : in String);
not overriding procedure Purge (Self : in out Holder);
Site : Holder;
function Respond (Request : AWS.Status.Data) return AWS.Response.Data;
procedure Text_IO_Log
(Severity : in Natools.Web.Severities.Code;
Message : in String);
procedure Syslog_Log
(Severity : in Natools.Web.Severities.Code;
Message : in String);
private
protected Counter is
function Get_Value return Natural;
entry Wait_Version (Minimum : in Natural);
entry Increment;
private
entry Block_Until_Increment (Minimum : in Natural);
entry Release_Block;
Value : Natural := 0;
end Counter;
type Increment_Count is new Natools.Web.Sites.Updates.Site_Update
with null record;
overriding procedure Update
(Self : in Increment_Count;
Object : in out Natools.Web.Sites.Site);
function SHA256_Digest (Message : in Natools.S_Expressions.Atom)
return Natools.S_Expressions.Atom
is (GNAT.SHA256.Digest (Message));
end Common;
|
pragma License (Unrestricted);
-- implementation unit specialized for Darwin (or FreeBSD)
with C.signal;
package System.Interrupt_Numbers is
pragma Preelaborate;
use type C.signed_int;
First_Interrupt_Id : constant := C.signal.SIGHUP;
Last_Interrupt_Id : constant :=
Boolean'Pos (C.signal.SIGRTMAX > C.signal.NSIG - 1)
* C.signal.SIGRTMAX
+ Boolean'Pos (C.signal.SIGRTMAX <= C.signal.NSIG - 1)
* (C.signal.NSIG - 1);
-- SIGUSR2 = NSIG - 1 = 31 in Darwin
-- SIGRTMAX = 126 > NSIG - 1 = 31 in FreeBSD
function Is_Reserved (Interrupt : C.signed_int) return Boolean;
end System.Interrupt_Numbers;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- A D A . C O N T A I N E R S . D O U B L Y _ L I N K E D _ L I S T S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2004-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/>. --
-- --
-- This unit was originally developed by Matthew J Heaney. --
------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
with System; use type System.Address;
package body Ada.Containers.Doubly_Linked_Lists is
pragma Warnings (Off, "variable ""Busy*"" is not referenced");
pragma Warnings (Off, "variable ""Lock*"" is not referenced");
-- See comment in Ada.Containers.Helpers
-----------------------
-- Local Subprograms --
-----------------------
procedure Free (X : in out Node_Access);
procedure Insert_Internal
(Container : in out List;
Before : Node_Access;
New_Node : Node_Access);
procedure Splice_Internal
(Target : in out List;
Before : Node_Access;
Source : in out List);
procedure Splice_Internal
(Target : in out List;
Before : Node_Access;
Source : in out List;
Position : Node_Access);
function Vet (Position : Cursor) return Boolean;
-- Checks invariants of the cursor and its designated container, as a
-- simple way of detecting dangling references (see operation Free for a
-- description of the detection mechanism), returning True if all checks
-- pass. Invocations of Vet are used here as the argument of pragma Assert,
-- so the checks are performed only when assertions are enabled.
---------
-- "=" --
---------
function "=" (Left, Right : List) return Boolean is
begin
if Left.Length /= Right.Length then
return False;
end if;
if Left.Length = 0 then
return True;
end if;
declare
-- Per AI05-0022, the container implementation is required to detect
-- element tampering by a generic actual subprogram.
Lock_Left : With_Lock (Left.TC'Unrestricted_Access);
Lock_Right : With_Lock (Right.TC'Unrestricted_Access);
L : Node_Access := Left.First;
R : Node_Access := Right.First;
begin
for J in 1 .. Left.Length loop
if L.Element /= R.Element then
return False;
end if;
L := L.Next;
R := R.Next;
end loop;
end;
return True;
end "=";
------------
-- Adjust --
------------
procedure Adjust (Container : in out List) is
Src : Node_Access := Container.First;
begin
-- If the counts are nonzero, execution is technically erroneous, but
-- it seems friendly to allow things like concurrent "=" on shared
-- constants.
Zero_Counts (Container.TC);
if Src = null then
pragma Assert (Container.Last = null);
pragma Assert (Container.Length = 0);
return;
end if;
pragma Assert (Container.First.Prev = null);
pragma Assert (Container.Last.Next = null);
pragma Assert (Container.Length > 0);
Container.First := null;
Container.Last := null;
Container.Length := 0;
Zero_Counts (Container.TC);
Container.First := new Node_Type'(Src.Element, null, null);
Container.Last := Container.First;
Container.Length := 1;
Src := Src.Next;
while Src /= null loop
Container.Last.Next := new Node_Type'(Element => Src.Element,
Prev => Container.Last,
Next => null);
Container.Last := Container.Last.Next;
Container.Length := Container.Length + 1;
Src := Src.Next;
end loop;
end Adjust;
------------
-- Append --
------------
procedure Append
(Container : in out List;
New_Item : Element_Type;
Count : Count_Type := 1)
is
begin
Insert (Container, No_Element, New_Item, Count);
end Append;
------------
-- Assign --
------------
procedure Assign (Target : in out List; Source : List) is
Node : Node_Access;
begin
if Target'Address = Source'Address then
return;
end if;
Target.Clear;
Node := Source.First;
while Node /= null loop
Target.Append (Node.Element);
Node := Node.Next;
end loop;
end Assign;
-----------
-- Clear --
-----------
procedure Clear (Container : in out List) is
X : Node_Access;
begin
if Container.Length = 0 then
pragma Assert (Container.First = null);
pragma Assert (Container.Last = null);
pragma Assert (Container.TC = (Busy => 0, Lock => 0));
return;
end if;
pragma Assert (Container.First.Prev = null);
pragma Assert (Container.Last.Next = null);
TC_Check (Container.TC);
while Container.Length > 1 loop
X := Container.First;
pragma Assert (X.Next.Prev = Container.First);
Container.First := X.Next;
Container.First.Prev := null;
Container.Length := Container.Length - 1;
Free (X);
end loop;
X := Container.First;
pragma Assert (X = Container.Last);
Container.First := null;
Container.Last := null;
Container.Length := 0;
pragma Warnings (Off);
Free (X);
pragma Warnings (On);
end Clear;
------------------------
-- Constant_Reference --
------------------------
function Constant_Reference
(Container : aliased List;
Position : Cursor) return Constant_Reference_Type
is
begin
if Checks and then Position.Container = null then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with
"Position cursor designates wrong container";
end if;
pragma Assert (Vet (Position), "bad cursor in Constant_Reference");
declare
TC : constant Tamper_Counts_Access :=
Container.TC'Unrestricted_Access;
begin
return R : constant Constant_Reference_Type :=
(Element => Position.Node.Element'Access,
Control => (Controlled with TC))
do
Lock (TC.all);
end return;
end;
end Constant_Reference;
--------------
-- Contains --
--------------
function Contains
(Container : List;
Item : Element_Type) return Boolean
is
begin
return Find (Container, Item) /= No_Element;
end Contains;
----------
-- Copy --
----------
function Copy (Source : List) return List is
begin
return Target : List do
Target.Assign (Source);
end return;
end Copy;
------------
-- Delete --
------------
procedure Delete
(Container : in out List;
Position : in out Cursor;
Count : Count_Type := 1)
is
X : Node_Access;
begin
if Checks and then Position.Node = null then
raise Constraint_Error with
"Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with
"Position cursor designates wrong container";
end if;
pragma Assert (Vet (Position), "bad cursor in Delete");
if Position.Node = Container.First then
Delete_First (Container, Count);
Position := No_Element; -- Post-York behavior
return;
end if;
if Count = 0 then
Position := No_Element; -- Post-York behavior
return;
end if;
TC_Check (Container.TC);
for Index in 1 .. Count loop
X := Position.Node;
Container.Length := Container.Length - 1;
if X = Container.Last then
Position := No_Element;
Container.Last := X.Prev;
Container.Last.Next := null;
Free (X);
return;
end if;
Position.Node := X.Next;
X.Next.Prev := X.Prev;
X.Prev.Next := X.Next;
Free (X);
end loop;
-- The following comment is unacceptable, more detail needed ???
Position := No_Element; -- Post-York behavior
end Delete;
------------------
-- Delete_First --
------------------
procedure Delete_First
(Container : in out List;
Count : Count_Type := 1)
is
X : Node_Access;
begin
if Count >= Container.Length then
Clear (Container);
return;
end if;
if Count = 0 then
return;
end if;
TC_Check (Container.TC);
for J in 1 .. Count loop
X := Container.First;
pragma Assert (X.Next.Prev = Container.First);
Container.First := X.Next;
Container.First.Prev := null;
Container.Length := Container.Length - 1;
Free (X);
end loop;
end Delete_First;
-----------------
-- Delete_Last --
-----------------
procedure Delete_Last
(Container : in out List;
Count : Count_Type := 1)
is
X : Node_Access;
begin
if Count >= Container.Length then
Clear (Container);
return;
end if;
if Count = 0 then
return;
end if;
TC_Check (Container.TC);
for J in 1 .. Count loop
X := Container.Last;
pragma Assert (X.Prev.Next = Container.Last);
Container.Last := X.Prev;
Container.Last.Next := null;
Container.Length := Container.Length - 1;
Free (X);
end loop;
end Delete_Last;
-------------
-- Element --
-------------
function Element (Position : Cursor) return Element_Type is
begin
if Checks and then Position.Node = null then
raise Constraint_Error with
"Position cursor has no element";
end if;
pragma Assert (Vet (Position), "bad cursor in Element");
return Position.Node.Element;
end Element;
--------------
-- Finalize --
--------------
procedure Finalize (Object : in out Iterator) is
begin
if Object.Container /= null then
Unbusy (Object.Container.TC);
end if;
end Finalize;
----------
-- Find --
----------
function Find
(Container : List;
Item : Element_Type;
Position : Cursor := No_Element) return Cursor
is
Node : Node_Access := Position.Node;
begin
if Node = null then
Node := Container.First;
else
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with
"Position cursor designates wrong container";
end if;
pragma Assert (Vet (Position), "bad cursor in Find");
end if;
-- Per AI05-0022, the container implementation is required to detect
-- element tampering by a generic actual subprogram.
declare
Lock : With_Lock (Container.TC'Unrestricted_Access);
begin
while Node /= null loop
if Node.Element = Item then
return Cursor'(Container'Unrestricted_Access, Node);
end if;
Node := Node.Next;
end loop;
return No_Element;
end;
end Find;
-----------
-- First --
-----------
function First (Container : List) return Cursor is
begin
if Container.First = null then
return No_Element;
else
return Cursor'(Container'Unrestricted_Access, Container.First);
end if;
end First;
function First (Object : Iterator) return Cursor is
begin
-- The value of the iterator object's Node component influences the
-- behavior of the First (and Last) selector function.
-- When the Node component is null, this means the iterator object was
-- constructed without a start expression, in which case the (forward)
-- iteration starts from the (logical) beginning of the entire sequence
-- of items (corresponding to Container.First, for a forward iterator).
-- Otherwise, this is iteration over a partial sequence of items. When
-- the Node component is non-null, the iterator object was constructed
-- with a start expression, that specifies the position from which the
-- (forward) partial iteration begins.
if Object.Node = null then
return Doubly_Linked_Lists.First (Object.Container.all);
else
return Cursor'(Object.Container, Object.Node);
end if;
end First;
-------------------
-- First_Element --
-------------------
function First_Element (Container : List) return Element_Type is
begin
if Checks and then Container.First = null then
raise Constraint_Error with "list is empty";
end if;
return Container.First.Element;
end First_Element;
----------
-- Free --
----------
procedure Free (X : in out Node_Access) is
procedure Deallocate is
new Ada.Unchecked_Deallocation (Node_Type, Node_Access);
begin
-- While a node is in use, as an active link in a list, its Previous and
-- Next components must be null, or designate a different node; this is
-- a node invariant. Before actually deallocating the node, we set both
-- access value components of the node to point to the node itself, thus
-- falsifying the node invariant. Subprogram Vet inspects the value of
-- the node components when interrogating the node, in order to detect
-- whether the cursor's node access value is dangling.
-- Note that we have no guarantee that the storage for the node isn't
-- modified when it is deallocated, but there are other tests that Vet
-- does if node invariants appear to be satisifed. However, in practice
-- this simple test works well enough, detecting dangling references
-- immediately, without needing further interrogation.
X.Prev := X;
X.Next := X;
Deallocate (X);
end Free;
---------------------
-- Generic_Sorting --
---------------------
package body Generic_Sorting is
---------------
-- Is_Sorted --
---------------
function Is_Sorted (Container : List) return Boolean is
-- Per AI05-0022, the container implementation is required to detect
-- element tampering by a generic actual subprogram.
Lock : With_Lock (Container.TC'Unrestricted_Access);
Node : Node_Access;
begin
Node := Container.First;
for Idx in 2 .. Container.Length loop
if Node.Next.Element < Node.Element then
return False;
end if;
Node := Node.Next;
end loop;
return True;
end Is_Sorted;
-----------
-- Merge --
-----------
procedure Merge
(Target : in out List;
Source : in out List)
is
begin
-- The semantics of Merge changed slightly per AI05-0021. It was
-- originally the case that if Target and Source denoted the same
-- container object, then the GNAT implementation of Merge did
-- nothing. However, it was argued that RM05 did not precisely
-- specify the semantics for this corner case. The decision of the
-- ARG was that if Target and Source denote the same non-empty
-- container object, then Program_Error is raised.
if Source.Is_Empty then
return;
end if;
if Checks and then Target'Address = Source'Address then
raise Program_Error with
"Target and Source denote same non-empty container";
end if;
if Checks and then Target.Length > Count_Type'Last - Source.Length
then
raise Constraint_Error with "new length exceeds maximum";
end if;
TC_Check (Target.TC);
TC_Check (Source.TC);
-- Per AI05-0022, the container implementation is required to detect
-- element tampering by a generic actual subprogram.
declare
Lock_Target : With_Lock (Target.TC'Unchecked_Access);
Lock_Source : With_Lock (Source.TC'Unchecked_Access);
LI, RI, RJ : Node_Access;
begin
LI := Target.First;
RI := Source.First;
while RI /= null loop
pragma Assert (RI.Next = null
or else not (RI.Next.Element < RI.Element));
if LI = null then
Splice_Internal (Target, null, Source);
exit;
end if;
pragma Assert (LI.Next = null
or else not (LI.Next.Element < LI.Element));
if RI.Element < LI.Element then
RJ := RI;
RI := RI.Next;
Splice_Internal (Target, LI, Source, RJ);
else
LI := LI.Next;
end if;
end loop;
end;
end Merge;
----------
-- Sort --
----------
procedure Sort (Container : in out List) is
procedure Partition (Pivot : Node_Access; Back : Node_Access);
procedure Sort (Front, Back : Node_Access);
---------------
-- Partition --
---------------
procedure Partition (Pivot : Node_Access; Back : Node_Access) is
Node : Node_Access;
begin
Node := Pivot.Next;
while Node /= Back loop
if Node.Element < Pivot.Element then
declare
Prev : constant Node_Access := Node.Prev;
Next : constant Node_Access := Node.Next;
begin
Prev.Next := Next;
if Next = null then
Container.Last := Prev;
else
Next.Prev := Prev;
end if;
Node.Next := Pivot;
Node.Prev := Pivot.Prev;
Pivot.Prev := Node;
if Node.Prev = null then
Container.First := Node;
else
Node.Prev.Next := Node;
end if;
Node := Next;
end;
else
Node := Node.Next;
end if;
end loop;
end Partition;
----------
-- Sort --
----------
procedure Sort (Front, Back : Node_Access) is
Pivot : constant Node_Access :=
(if Front = null then Container.First else Front.Next);
begin
if Pivot /= Back then
Partition (Pivot, Back);
Sort (Front, Pivot);
Sort (Pivot, Back);
end if;
end Sort;
-- Start of processing for Sort
begin
if Container.Length <= 1 then
return;
end if;
pragma Assert (Container.First.Prev = null);
pragma Assert (Container.Last.Next = null);
TC_Check (Container.TC);
-- Per AI05-0022, the container implementation is required to detect
-- element tampering by a generic actual subprogram.
declare
Lock : With_Lock (Container.TC'Unchecked_Access);
begin
Sort (Front => null, Back => null);
end;
pragma Assert (Container.First.Prev = null);
pragma Assert (Container.Last.Next = null);
end Sort;
end Generic_Sorting;
------------------------
-- Get_Element_Access --
------------------------
function Get_Element_Access
(Position : Cursor) return not null Element_Access is
begin
return Position.Node.Element'Access;
end Get_Element_Access;
-----------------
-- Has_Element --
-----------------
function Has_Element (Position : Cursor) return Boolean is
begin
pragma Assert (Vet (Position), "bad cursor in Has_Element");
return Position.Node /= null;
end Has_Element;
------------
-- Insert --
------------
procedure Insert
(Container : in out List;
Before : Cursor;
New_Item : Element_Type;
Position : out Cursor;
Count : Count_Type := 1)
is
First_Node : Node_Access;
New_Node : Node_Access;
begin
if Before.Container /= null then
if Checks and then Before.Container /= Container'Unrestricted_Access
then
raise Program_Error with
"Before cursor designates wrong list";
end if;
pragma Assert (Vet (Before), "bad cursor in Insert");
end if;
if Count = 0 then
Position := Before;
return;
end if;
if Checks and then Container.Length > Count_Type'Last - Count then
raise Constraint_Error with "new length exceeds maximum";
end if;
TC_Check (Container.TC);
New_Node := new Node_Type'(New_Item, null, null);
First_Node := New_Node;
Insert_Internal (Container, Before.Node, New_Node);
for J in 2 .. Count loop
New_Node := new Node_Type'(New_Item, null, null);
Insert_Internal (Container, Before.Node, New_Node);
end loop;
Position := Cursor'(Container'Unchecked_Access, First_Node);
end Insert;
procedure Insert
(Container : in out List;
Before : Cursor;
New_Item : Element_Type;
Count : Count_Type := 1)
is
Position : Cursor;
pragma Unreferenced (Position);
begin
Insert (Container, Before, New_Item, Position, Count);
end Insert;
procedure Insert
(Container : in out List;
Before : Cursor;
Position : out Cursor;
Count : Count_Type := 1)
is
First_Node : Node_Access;
New_Node : Node_Access;
begin
if Before.Container /= null then
if Checks and then Before.Container /= Container'Unrestricted_Access
then
raise Program_Error with
"Before cursor designates wrong list";
end if;
pragma Assert (Vet (Before), "bad cursor in Insert");
end if;
if Count = 0 then
Position := Before;
return;
end if;
if Checks and then Container.Length > Count_Type'Last - Count then
raise Constraint_Error with "new length exceeds maximum";
end if;
TC_Check (Container.TC);
New_Node := new Node_Type;
First_Node := New_Node;
Insert_Internal (Container, Before.Node, New_Node);
for J in 2 .. Count loop
New_Node := new Node_Type;
Insert_Internal (Container, Before.Node, New_Node);
end loop;
Position := Cursor'(Container'Unchecked_Access, First_Node);
end Insert;
---------------------
-- Insert_Internal --
---------------------
procedure Insert_Internal
(Container : in out List;
Before : Node_Access;
New_Node : Node_Access)
is
begin
if Container.Length = 0 then
pragma Assert (Before = null);
pragma Assert (Container.First = null);
pragma Assert (Container.Last = null);
Container.First := New_Node;
Container.Last := New_Node;
elsif Before = null then
pragma Assert (Container.Last.Next = null);
Container.Last.Next := New_Node;
New_Node.Prev := Container.Last;
Container.Last := New_Node;
elsif Before = Container.First then
pragma Assert (Container.First.Prev = null);
Container.First.Prev := New_Node;
New_Node.Next := Container.First;
Container.First := New_Node;
else
pragma Assert (Container.First.Prev = null);
pragma Assert (Container.Last.Next = null);
New_Node.Next := Before;
New_Node.Prev := Before.Prev;
Before.Prev.Next := New_Node;
Before.Prev := New_Node;
end if;
Container.Length := Container.Length + 1;
end Insert_Internal;
--------------
-- Is_Empty --
--------------
function Is_Empty (Container : List) return Boolean is
begin
return Container.Length = 0;
end Is_Empty;
-------------
-- Iterate --
-------------
procedure Iterate
(Container : List;
Process : not null access procedure (Position : Cursor))
is
Busy : With_Busy (Container.TC'Unrestricted_Access);
Node : Node_Access := Container.First;
begin
while Node /= null loop
Process (Cursor'(Container'Unrestricted_Access, Node));
Node := Node.Next;
end loop;
end Iterate;
function Iterate (Container : List)
return List_Iterator_Interfaces.Reversible_Iterator'Class
is
begin
-- The value of the Node component influences the behavior of the First
-- and Last selector functions of the iterator object. When the Node
-- component is null (as is the case here), this means the iterator
-- object was constructed without a start expression. This is a
-- complete iterator, meaning that the iteration starts from the
-- (logical) beginning of the sequence of items.
-- Note: For a forward iterator, Container.First is the beginning, and
-- for a reverse iterator, Container.Last is the beginning.
return It : constant Iterator :=
Iterator'(Limited_Controlled with
Container => Container'Unrestricted_Access,
Node => null)
do
Busy (Container.TC'Unrestricted_Access.all);
end return;
end Iterate;
function Iterate (Container : List; Start : Cursor)
return List_Iterator_Interfaces.Reversible_Iterator'Class
is
begin
-- It was formerly the case that when Start = No_Element, the partial
-- iterator was defined to behave the same as for a complete iterator,
-- and iterate over the entire sequence of items. However, those
-- semantics were unintuitive and arguably error-prone (it is too easy
-- to accidentally create an endless loop), and so they were changed,
-- per the ARG meeting in Denver on 2011/11. However, there was no
-- consensus about what positive meaning this corner case should have,
-- and so it was decided to simply raise an exception. This does imply,
-- however, that it is not possible to use a partial iterator to specify
-- an empty sequence of items.
if Checks and then Start = No_Element then
raise Constraint_Error with
"Start position for iterator equals No_Element";
end if;
if Checks and then Start.Container /= Container'Unrestricted_Access then
raise Program_Error with
"Start cursor of Iterate designates wrong list";
end if;
pragma Assert (Vet (Start), "Start cursor of Iterate is bad");
-- The value of the Node component influences the behavior of the First
-- and Last selector functions of the iterator object. When the Node
-- component is non-null (as is the case here), it means that this is a
-- partial iteration, over a subset of the complete sequence of items.
-- The iterator object was constructed with a start expression,
-- indicating the position from which the iteration begins. Note that
-- the start position has the same value irrespective of whether this is
-- a forward or reverse iteration.
return It : constant Iterator :=
Iterator'(Limited_Controlled with
Container => Container'Unrestricted_Access,
Node => Start.Node)
do
Busy (Container.TC'Unrestricted_Access.all);
end return;
end Iterate;
----------
-- Last --
----------
function Last (Container : List) return Cursor is
begin
if Container.Last = null then
return No_Element;
else
return Cursor'(Container'Unrestricted_Access, Container.Last);
end if;
end Last;
function Last (Object : Iterator) return Cursor is
begin
-- The value of the iterator object's Node component influences the
-- behavior of the Last (and First) selector function.
-- When the Node component is null, this means the iterator object was
-- constructed without a start expression, in which case the (reverse)
-- iteration starts from the (logical) beginning of the entire sequence
-- (corresponding to Container.Last, for a reverse iterator).
-- Otherwise, this is iteration over a partial sequence of items. When
-- the Node component is non-null, the iterator object was constructed
-- with a start expression, that specifies the position from which the
-- (reverse) partial iteration begins.
if Object.Node = null then
return Doubly_Linked_Lists.Last (Object.Container.all);
else
return Cursor'(Object.Container, Object.Node);
end if;
end Last;
------------------
-- Last_Element --
------------------
function Last_Element (Container : List) return Element_Type is
begin
if Checks and then Container.Last = null then
raise Constraint_Error with "list is empty";
end if;
return Container.Last.Element;
end Last_Element;
------------
-- Length --
------------
function Length (Container : List) return Count_Type is
begin
return Container.Length;
end Length;
----------
-- Move --
----------
procedure Move
(Target : in out List;
Source : in out List)
is
begin
if Target'Address = Source'Address then
return;
end if;
TC_Check (Source.TC);
Clear (Target);
Target.First := Source.First;
Source.First := null;
Target.Last := Source.Last;
Source.Last := null;
Target.Length := Source.Length;
Source.Length := 0;
end Move;
----------
-- Next --
----------
procedure Next (Position : in out Cursor) is
begin
Position := Next (Position);
end Next;
function Next (Position : Cursor) return Cursor is
begin
if Position.Node = null then
return No_Element;
else
pragma Assert (Vet (Position), "bad cursor in Next");
declare
Next_Node : constant Node_Access := Position.Node.Next;
begin
if Next_Node = null then
return No_Element;
else
return Cursor'(Position.Container, Next_Node);
end if;
end;
end if;
end Next;
function Next
(Object : Iterator;
Position : Cursor) return Cursor
is
begin
if Position.Container = null then
return No_Element;
end if;
if Checks and then Position.Container /= Object.Container then
raise Program_Error with
"Position cursor of Next designates wrong list";
end if;
return Next (Position);
end Next;
-------------
-- Prepend --
-------------
procedure Prepend
(Container : in out List;
New_Item : Element_Type;
Count : Count_Type := 1)
is
begin
Insert (Container, First (Container), New_Item, Count);
end Prepend;
--------------
-- Previous --
--------------
procedure Previous (Position : in out Cursor) is
begin
Position := Previous (Position);
end Previous;
function Previous (Position : Cursor) return Cursor is
begin
if Position.Node = null then
return No_Element;
else
pragma Assert (Vet (Position), "bad cursor in Previous");
declare
Prev_Node : constant Node_Access := Position.Node.Prev;
begin
if Prev_Node = null then
return No_Element;
else
return Cursor'(Position.Container, Prev_Node);
end if;
end;
end if;
end Previous;
function Previous
(Object : Iterator;
Position : Cursor) return Cursor
is
begin
if Position.Container = null then
return No_Element;
end if;
if Checks and then Position.Container /= Object.Container then
raise Program_Error with
"Position cursor of Previous designates wrong list";
end if;
return Previous (Position);
end Previous;
----------------------
-- Pseudo_Reference --
----------------------
function Pseudo_Reference
(Container : aliased List'Class) return Reference_Control_Type
is
TC : constant Tamper_Counts_Access := Container.TC'Unrestricted_Access;
begin
return R : constant Reference_Control_Type := (Controlled with TC) do
Lock (TC.all);
end return;
end Pseudo_Reference;
-------------------
-- Query_Element --
-------------------
procedure Query_Element
(Position : Cursor;
Process : not null access procedure (Element : Element_Type))
is
begin
if Checks and then Position.Node = null then
raise Constraint_Error with
"Position cursor has no element";
end if;
pragma Assert (Vet (Position), "bad cursor in Query_Element");
declare
Lock : With_Lock (Position.Container.TC'Unrestricted_Access);
begin
Process (Position.Node.Element);
end;
end Query_Element;
----------
-- Read --
----------
procedure Read
(Stream : not null access Root_Stream_Type'Class;
Item : out List)
is
N : Count_Type'Base;
X : Node_Access;
begin
Clear (Item);
Count_Type'Base'Read (Stream, N);
if N = 0 then
return;
end if;
X := new Node_Type;
begin
Element_Type'Read (Stream, X.Element);
exception
when others =>
Free (X);
raise;
end;
Item.First := X;
Item.Last := X;
loop
Item.Length := Item.Length + 1;
exit when Item.Length = N;
X := new Node_Type;
begin
Element_Type'Read (Stream, X.Element);
exception
when others =>
Free (X);
raise;
end;
X.Prev := Item.Last;
Item.Last.Next := X;
Item.Last := X;
end loop;
end Read;
procedure Read
(Stream : not null access Root_Stream_Type'Class;
Item : out Cursor)
is
begin
raise Program_Error with "attempt to stream list cursor";
end Read;
procedure Read
(Stream : not null access Root_Stream_Type'Class;
Item : out Reference_Type)
is
begin
raise Program_Error with "attempt to stream reference";
end Read;
procedure Read
(Stream : not null access Root_Stream_Type'Class;
Item : out Constant_Reference_Type)
is
begin
raise Program_Error with "attempt to stream reference";
end Read;
---------------
-- Reference --
---------------
function Reference
(Container : aliased in out List;
Position : Cursor) return Reference_Type
is
begin
if Checks and then Position.Container = null then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unchecked_Access then
raise Program_Error with
"Position cursor designates wrong container";
end if;
pragma Assert (Vet (Position), "bad cursor in function Reference");
declare
TC : constant Tamper_Counts_Access :=
Container.TC'Unrestricted_Access;
begin
return R : constant Reference_Type :=
(Element => Position.Node.Element'Access,
Control => (Controlled with TC))
do
Lock (TC.all);
end return;
end;
end Reference;
---------------------
-- Replace_Element --
---------------------
procedure Replace_Element
(Container : in out List;
Position : Cursor;
New_Item : Element_Type)
is
begin
if Checks and then Position.Container = null then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unchecked_Access then
raise Program_Error with
"Position cursor designates wrong container";
end if;
TE_Check (Container.TC);
pragma Assert (Vet (Position), "bad cursor in Replace_Element");
Position.Node.Element := New_Item;
end Replace_Element;
----------------------
-- Reverse_Elements --
----------------------
procedure Reverse_Elements (Container : in out List) is
I : Node_Access := Container.First;
J : Node_Access := Container.Last;
procedure Swap (L, R : Node_Access);
----------
-- Swap --
----------
procedure Swap (L, R : Node_Access) is
LN : constant Node_Access := L.Next;
LP : constant Node_Access := L.Prev;
RN : constant Node_Access := R.Next;
RP : constant Node_Access := R.Prev;
begin
if LP /= null then
LP.Next := R;
end if;
if RN /= null then
RN.Prev := L;
end if;
L.Next := RN;
R.Prev := LP;
if LN = R then
pragma Assert (RP = L);
L.Prev := R;
R.Next := L;
else
L.Prev := RP;
RP.Next := L;
R.Next := LN;
LN.Prev := R;
end if;
end Swap;
-- Start of processing for Reverse_Elements
begin
if Container.Length <= 1 then
return;
end if;
pragma Assert (Container.First.Prev = null);
pragma Assert (Container.Last.Next = null);
TC_Check (Container.TC);
Container.First := J;
Container.Last := I;
loop
Swap (L => I, R => J);
J := J.Next;
exit when I = J;
I := I.Prev;
exit when I = J;
Swap (L => J, R => I);
I := I.Next;
exit when I = J;
J := J.Prev;
exit when I = J;
end loop;
pragma Assert (Container.First.Prev = null);
pragma Assert (Container.Last.Next = null);
end Reverse_Elements;
------------------
-- Reverse_Find --
------------------
function Reverse_Find
(Container : List;
Item : Element_Type;
Position : Cursor := No_Element) return Cursor
is
Node : Node_Access := Position.Node;
begin
if Node = null then
Node := Container.Last;
else
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with
"Position cursor designates wrong container";
end if;
pragma Assert (Vet (Position), "bad cursor in Reverse_Find");
end if;
-- Per AI05-0022, the container implementation is required to detect
-- element tampering by a generic actual subprogram.
declare
Lock : With_Lock (Container.TC'Unrestricted_Access);
begin
while Node /= null loop
if Node.Element = Item then
return Cursor'(Container'Unrestricted_Access, Node);
end if;
Node := Node.Prev;
end loop;
return No_Element;
end;
end Reverse_Find;
---------------------
-- Reverse_Iterate --
---------------------
procedure Reverse_Iterate
(Container : List;
Process : not null access procedure (Position : Cursor))
is
Busy : With_Busy (Container.TC'Unrestricted_Access);
Node : Node_Access := Container.Last;
begin
while Node /= null loop
Process (Cursor'(Container'Unrestricted_Access, Node));
Node := Node.Prev;
end loop;
end Reverse_Iterate;
------------
-- Splice --
------------
procedure Splice
(Target : in out List;
Before : Cursor;
Source : in out List)
is
begin
if Before.Container /= null then
if Checks and then Before.Container /= Target'Unrestricted_Access then
raise Program_Error with
"Before cursor designates wrong container";
end if;
pragma Assert (Vet (Before), "bad cursor in Splice");
end if;
if Target'Address = Source'Address or else Source.Length = 0 then
return;
end if;
if Checks and then Target.Length > Count_Type'Last - Source.Length then
raise Constraint_Error with "new length exceeds maximum";
end if;
TC_Check (Target.TC);
TC_Check (Source.TC);
Splice_Internal (Target, Before.Node, Source);
end Splice;
procedure Splice
(Container : in out List;
Before : Cursor;
Position : Cursor)
is
begin
if Before.Container /= null then
if Checks and then Before.Container /= Container'Unchecked_Access then
raise Program_Error with
"Before cursor designates wrong container";
end if;
pragma Assert (Vet (Before), "bad Before cursor in Splice");
end if;
if Checks and then Position.Node = null then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with
"Position cursor designates wrong container";
end if;
pragma Assert (Vet (Position), "bad Position cursor in Splice");
if Position.Node = Before.Node
or else Position.Node.Next = Before.Node
then
return;
end if;
pragma Assert (Container.Length >= 2);
TC_Check (Container.TC);
if Before.Node = null then
pragma Assert (Position.Node /= Container.Last);
if Position.Node = Container.First then
Container.First := Position.Node.Next;
Container.First.Prev := null;
else
Position.Node.Prev.Next := Position.Node.Next;
Position.Node.Next.Prev := Position.Node.Prev;
end if;
Container.Last.Next := Position.Node;
Position.Node.Prev := Container.Last;
Container.Last := Position.Node;
Container.Last.Next := null;
return;
end if;
if Before.Node = Container.First then
pragma Assert (Position.Node /= Container.First);
if Position.Node = Container.Last then
Container.Last := Position.Node.Prev;
Container.Last.Next := null;
else
Position.Node.Prev.Next := Position.Node.Next;
Position.Node.Next.Prev := Position.Node.Prev;
end if;
Container.First.Prev := Position.Node;
Position.Node.Next := Container.First;
Container.First := Position.Node;
Container.First.Prev := null;
return;
end if;
if Position.Node = Container.First then
Container.First := Position.Node.Next;
Container.First.Prev := null;
elsif Position.Node = Container.Last then
Container.Last := Position.Node.Prev;
Container.Last.Next := null;
else
Position.Node.Prev.Next := Position.Node.Next;
Position.Node.Next.Prev := Position.Node.Prev;
end if;
Before.Node.Prev.Next := Position.Node;
Position.Node.Prev := Before.Node.Prev;
Before.Node.Prev := Position.Node;
Position.Node.Next := Before.Node;
pragma Assert (Container.First.Prev = null);
pragma Assert (Container.Last.Next = null);
end Splice;
procedure Splice
(Target : in out List;
Before : Cursor;
Source : in out List;
Position : in out Cursor)
is
begin
if Target'Address = Source'Address then
Splice (Target, Before, Position);
return;
end if;
if Before.Container /= null then
if Checks and then Before.Container /= Target'Unrestricted_Access then
raise Program_Error with
"Before cursor designates wrong container";
end if;
pragma Assert (Vet (Before), "bad Before cursor in Splice");
end if;
if Checks and then Position.Node = null then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Source'Unrestricted_Access then
raise Program_Error with
"Position cursor designates wrong container";
end if;
pragma Assert (Vet (Position), "bad Position cursor in Splice");
if Checks and then Target.Length = Count_Type'Last then
raise Constraint_Error with "Target is full";
end if;
TC_Check (Target.TC);
TC_Check (Source.TC);
Splice_Internal (Target, Before.Node, Source, Position.Node);
Position.Container := Target'Unchecked_Access;
end Splice;
---------------------
-- Splice_Internal --
---------------------
procedure Splice_Internal
(Target : in out List;
Before : Node_Access;
Source : in out List)
is
begin
-- This implements the corresponding Splice operation, after the
-- parameters have been vetted, and corner-cases disposed of.
pragma Assert (Target'Address /= Source'Address);
pragma Assert (Source.Length > 0);
pragma Assert (Source.First /= null);
pragma Assert (Source.First.Prev = null);
pragma Assert (Source.Last /= null);
pragma Assert (Source.Last.Next = null);
pragma Assert (Target.Length <= Count_Type'Last - Source.Length);
if Target.Length = 0 then
pragma Assert (Target.First = null);
pragma Assert (Target.Last = null);
pragma Assert (Before = null);
Target.First := Source.First;
Target.Last := Source.Last;
elsif Before = null then
pragma Assert (Target.Last.Next = null);
Target.Last.Next := Source.First;
Source.First.Prev := Target.Last;
Target.Last := Source.Last;
elsif Before = Target.First then
pragma Assert (Target.First.Prev = null);
Source.Last.Next := Target.First;
Target.First.Prev := Source.Last;
Target.First := Source.First;
else
pragma Assert (Target.Length >= 2);
Before.Prev.Next := Source.First;
Source.First.Prev := Before.Prev;
Before.Prev := Source.Last;
Source.Last.Next := Before;
end if;
Source.First := null;
Source.Last := null;
Target.Length := Target.Length + Source.Length;
Source.Length := 0;
end Splice_Internal;
procedure Splice_Internal
(Target : in out List;
Before : Node_Access; -- node of Target
Source : in out List;
Position : Node_Access) -- node of Source
is
begin
-- This implements the corresponding Splice operation, after the
-- parameters have been vetted.
pragma Assert (Target'Address /= Source'Address);
pragma Assert (Target.Length < Count_Type'Last);
pragma Assert (Source.Length > 0);
pragma Assert (Source.First /= null);
pragma Assert (Source.First.Prev = null);
pragma Assert (Source.Last /= null);
pragma Assert (Source.Last.Next = null);
pragma Assert (Position /= null);
if Position = Source.First then
Source.First := Position.Next;
if Position = Source.Last then
pragma Assert (Source.First = null);
pragma Assert (Source.Length = 1);
Source.Last := null;
else
Source.First.Prev := null;
end if;
elsif Position = Source.Last then
pragma Assert (Source.Length >= 2);
Source.Last := Position.Prev;
Source.Last.Next := null;
else
pragma Assert (Source.Length >= 3);
Position.Prev.Next := Position.Next;
Position.Next.Prev := Position.Prev;
end if;
if Target.Length = 0 then
pragma Assert (Target.First = null);
pragma Assert (Target.Last = null);
pragma Assert (Before = null);
Target.First := Position;
Target.Last := Position;
Target.First.Prev := null;
Target.Last.Next := null;
elsif Before = null then
pragma Assert (Target.Last.Next = null);
Target.Last.Next := Position;
Position.Prev := Target.Last;
Target.Last := Position;
Target.Last.Next := null;
elsif Before = Target.First then
pragma Assert (Target.First.Prev = null);
Target.First.Prev := Position;
Position.Next := Target.First;
Target.First := Position;
Target.First.Prev := null;
else
pragma Assert (Target.Length >= 2);
Before.Prev.Next := Position;
Position.Prev := Before.Prev;
Before.Prev := Position;
Position.Next := Before;
end if;
Target.Length := Target.Length + 1;
Source.Length := Source.Length - 1;
end Splice_Internal;
----------
-- Swap --
----------
procedure Swap
(Container : in out List;
I, J : Cursor)
is
begin
if Checks and then I.Node = null then
raise Constraint_Error with "I cursor has no element";
end if;
if Checks and then J.Node = null then
raise Constraint_Error with "J cursor has no element";
end if;
if Checks and then I.Container /= Container'Unchecked_Access then
raise Program_Error with "I cursor designates wrong container";
end if;
if Checks and then J.Container /= Container'Unchecked_Access then
raise Program_Error with "J cursor designates wrong container";
end if;
if I.Node = J.Node then
return;
end if;
TE_Check (Container.TC);
pragma Assert (Vet (I), "bad I cursor in Swap");
pragma Assert (Vet (J), "bad J cursor in Swap");
declare
EI : Element_Type renames I.Node.Element;
EJ : Element_Type renames J.Node.Element;
EI_Copy : constant Element_Type := EI;
begin
EI := EJ;
EJ := EI_Copy;
end;
end Swap;
----------------
-- Swap_Links --
----------------
procedure Swap_Links
(Container : in out List;
I, J : Cursor)
is
begin
if Checks and then I.Node = null then
raise Constraint_Error with "I cursor has no element";
end if;
if Checks and then J.Node = null then
raise Constraint_Error with "J cursor has no element";
end if;
if Checks and then I.Container /= Container'Unrestricted_Access then
raise Program_Error with "I cursor designates wrong container";
end if;
if Checks and then J.Container /= Container'Unrestricted_Access then
raise Program_Error with "J cursor designates wrong container";
end if;
if I.Node = J.Node then
return;
end if;
TC_Check (Container.TC);
pragma Assert (Vet (I), "bad I cursor in Swap_Links");
pragma Assert (Vet (J), "bad J cursor in Swap_Links");
declare
I_Next : constant Cursor := Next (I);
begin
if I_Next = J then
Splice (Container, Before => I, Position => J);
else
declare
J_Next : constant Cursor := Next (J);
begin
if J_Next = I then
Splice (Container, Before => J, Position => I);
else
pragma Assert (Container.Length >= 3);
Splice (Container, Before => I_Next, Position => J);
Splice (Container, Before => J_Next, Position => I);
end if;
end;
end if;
end;
end Swap_Links;
--------------------
-- Update_Element --
--------------------
procedure Update_Element
(Container : in out List;
Position : Cursor;
Process : not null access procedure (Element : in out Element_Type))
is
begin
if Checks and then Position.Node = null then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unchecked_Access then
raise Program_Error with
"Position cursor designates wrong container";
end if;
pragma Assert (Vet (Position), "bad cursor in Update_Element");
declare
Lock : With_Lock (Container.TC'Unchecked_Access);
begin
Process (Position.Node.Element);
end;
end Update_Element;
---------
-- Vet --
---------
function Vet (Position : Cursor) return Boolean is
begin
if Position.Node = null then
return Position.Container = null;
end if;
if Position.Container = null then
return False;
end if;
-- An invariant of a node is that its Previous and Next components can
-- be null, or designate a different node. Operation Free sets the
-- access value components of the node to designate the node itself
-- before actually deallocating the node, thus deliberately violating
-- the node invariant. This gives us a simple way to detect a dangling
-- reference to a node.
if Position.Node.Next = Position.Node then
return False;
end if;
if Position.Node.Prev = Position.Node then
return False;
end if;
-- In practice the tests above will detect most instances of a dangling
-- reference. If we get here, it means that the invariants of the
-- designated node are satisfied (they at least appear to be satisfied),
-- so we perform some more tests, to determine whether invariants of the
-- designated list are satisfied too.
declare
L : List renames Position.Container.all;
begin
if L.Length = 0 then
return False;
end if;
if L.First = null then
return False;
end if;
if L.Last = null then
return False;
end if;
if L.First.Prev /= null then
return False;
end if;
if L.Last.Next /= null then
return False;
end if;
if Position.Node.Prev = null and then Position.Node /= L.First then
return False;
end if;
pragma Assert
(Position.Node.Prev /= null or else Position.Node = L.First);
if Position.Node.Next = null and then Position.Node /= L.Last then
return False;
end if;
pragma Assert
(Position.Node.Next /= null
or else Position.Node = L.Last);
if L.Length = 1 then
return L.First = L.Last;
end if;
if L.First = L.Last then
return False;
end if;
if L.First.Next = null then
return False;
end if;
if L.Last.Prev = null then
return False;
end if;
if L.First.Next.Prev /= L.First then
return False;
end if;
if L.Last.Prev.Next /= L.Last then
return False;
end if;
if L.Length = 2 then
if L.First.Next /= L.Last then
return False;
elsif L.Last.Prev /= L.First then
return False;
else
return True;
end if;
end if;
if L.First.Next = L.Last then
return False;
end if;
if L.Last.Prev = L.First then
return False;
end if;
-- Eliminate earlier possibility
if Position.Node = L.First then
return True;
end if;
pragma Assert (Position.Node.Prev /= null);
-- Eliminate earlier possibility
if Position.Node = L.Last then
return True;
end if;
pragma Assert (Position.Node.Next /= null);
if Position.Node.Next.Prev /= Position.Node then
return False;
end if;
if Position.Node.Prev.Next /= Position.Node then
return False;
end if;
if L.Length = 3 then
if L.First.Next /= Position.Node then
return False;
elsif L.Last.Prev /= Position.Node then
return False;
end if;
end if;
return True;
end;
end Vet;
-----------
-- Write --
-----------
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Item : List)
is
Node : Node_Access;
begin
Count_Type'Base'Write (Stream, Item.Length);
Node := Item.First;
while Node /= null loop
Element_Type'Write (Stream, Node.Element);
Node := Node.Next;
end loop;
end Write;
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Item : Cursor)
is
begin
raise Program_Error with "attempt to stream list cursor";
end Write;
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Item : Reference_Type)
is
begin
raise Program_Error with "attempt to stream reference";
end Write;
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Item : Constant_Reference_Type)
is
begin
raise Program_Error with "attempt to stream reference";
end Write;
end Ada.Containers.Doubly_Linked_Lists;
|
with Ada.Text_IO, suma_impar_montana;
use Ada.Text_IO;
procedure Prueba_suma_impar_montana is
--Programa de pruebas para el laboratorio 5
F: File_Type;
begin
-- IMPORTANTE
-- Como te comente, he probado a guardar los txt en una carpeta y modificado la ruta, en caso de
-- querer utilizarlos sin la carpeta solamente hay que eliminar -( PruebasTXT/ )- donde se indica
Put_Line("SUMA IMPAR MONTANA - PRUEBAS");
Put_Line("--------------------------------------");
Open(F,In_File, "PruebasTXT/Lab10_02_entrada_01.txt"); -- Eliminar aqui
Put_Line("Lab10_02_entrada_01.txt: ");
Put_line("162 1331 4 121 356 0 --> (287, TRUE)");
Set_Input(F);
Suma_impar_montana;
Close(F);
New_Line(3);
Open(F,in_file, "PruebasTXT/Lab10_02_entrada_02.txt"); -- Eliminar aqui
Put_Line("Lab10_02_entrada_02.txt:");
Put_line("0 --> (0, TRUE)");
Set_Input(F);
Suma_impar_montana;
Close(F);
New_Line(3);
Open(F,in_file, "PruebasTXT/Lab10_02_entrada_03.txt"); -- Eliminar aqui
Put_Line("Lab10_02_entrada_03.txt: ");
Put_line("162 121 0 --> (283, TRUE)");
Set_Input(F);
Suma_impar_montana;
Close(F);
New_Line(3);
Open(F,in_file, "PruebasTXT/Lab10_02_entrada_04.txt"); -- Eliminar aqui
Put_Line("Lab10_02_entrada_04.txt: ");
Put_line("162 121 4 121 356 0 -->(408, FALSE)");
Set_Input(F);
Suma_impar_montana;
Close(F);
Set_Input(Ada.Text_Io.Standard_Input);
New_Line(3);
end Prueba_suma_impar_montana;
|
pragma Ada_2012;
with GNAT.Source_Info;
package body GStreamer.Rtsp.Transport.Tests is
----------
-- Name --
----------
Test_Name : constant String := GNAT.Source_Info.Enclosing_Entity;
function Name (Test : Test_Case) return Message_String is
pragma Unreferenced (Test);
begin
return Format(Test_Name);
end Name;
--------------------
-- Register_Tests --
--------------------
procedure Register_Tests (Test : in out Test_Case) is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Register_Tests unimplemented");
-- raise Program_Error with "Unimplemented procedure Register_Tests";
end Register_Tests;
end GStreamer.Rtsp.transport.Tests;
|
-----------------------------------------------------------------------
-- util-log-locations -- General purpose source file location
-- Copyright (C) 2009, 2010, 2011, 2012, 2013, 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 Util.Strings;
package body Util.Log.Locations is
-- ------------------------------
-- Create a <b>File_Info</b> record to identify the file whose path is <b>Path</b>
-- and whose relative path portion starts at <b>Relative_Position</b>.
-- ------------------------------
function Create_File_Info (Path : in String;
Relative_Position : in Natural) return File_Info_Access is
begin
return new File_Info '(Length => Path'Length,
Path => Path,
Relative_Pos => Relative_Position);
end Create_File_Info;
-- ------------------------------
-- Get the relative path name
-- ------------------------------
function Relative_Path (File : in File_Info) return String is
begin
return File.Path (File.Relative_Pos .. File.Path'Last);
end Relative_Path;
-- ------------------------------
-- Get the line number
-- ------------------------------
function Line (Info : Line_Info) return Natural is
begin
return Info.Line;
end Line;
-- ------------------------------
-- Get the column number
-- ------------------------------
function Column (Info : Line_Info) return Natural is
begin
return Info.Column;
end Column;
-- ------------------------------
-- Get the source file
-- ------------------------------
function File (Info : Line_Info) return String is
begin
return Info.File.Path;
end File;
-- ------------------------------
-- Compare the two source location. The comparison is made on:
-- o the source file,
-- o the line number,
-- o the column.
-- ------------------------------
function "<" (Left, Right : in Line_Info) return Boolean is
begin
if Left.File.Path < Right.File.Path then
return True;
elsif Left.File.Path > Right.File.Path then
return False;
elsif Left.Line < Right.Line then
return True;
elsif Left.Line > Right.Line then
return False;
else
return Left.Column < Right.Column;
end if;
end "<";
-- ------------------------------
-- Create a source line information.
-- ------------------------------
function Create_Line_Info (File : in File_Info_Access;
Line : in Natural;
Column : in Natural := 0) return Line_Info is
Result : Line_Info;
begin
Result.Line := Line;
Result.Column := Column;
if File = null then
Result.File := NO_FILE'Access;
else
Result.File := File;
end if;
return Result;
end Create_Line_Info;
-- ------------------------------
-- Get a printable representation of the line information using
-- the format:
-- <path>:<line>[:<column>]
-- The path can be reported as relative or absolute path.
-- The column is optional and reported by default.
-- ------------------------------
function To_String (Info : in Line_Info;
Relative : in Boolean := True;
Column : in Boolean := True) return String is
begin
if Relative then
if Column then
return Relative_Path (Info.File.all) & ":" & Util.Strings.Image (Info.Line)
& ":" & Util.Strings.Image (Info.Column);
else
return Relative_Path (Info.File.all) & ":" & Util.Strings.Image (Info.Line);
end if;
else
if Column then
return Info.File.Path & ":" & Util.Strings.Image (Info.Line)
& ":" & Util.Strings.Image (Info.Column);
else
return Info.File.Path & ":" & Util.Strings.Image (Info.Line);
end if;
end if;
end To_String;
end Util.Log.Locations;
|
-- AoC 2020, Day 7
-- with Ada.Text_IO;
with Bag; use Bag;
with Ada.Containers;
with Ada.Containers.Ordered_Sets;
with Ada.Containers.Indefinite_Ordered_Maps;
package body Day is
-- package TIO renames Ada.Text_IO;
use Bag.Bag_Maps;
package Color_Sets is new Ada.Containers.Ordered_Sets
(Element_Type => Bag_Color);
use Color_Sets;
package Reverse_Bag_Maps is new Ada.Containers.Indefinite_Ordered_Maps
(Key_Type => Bag_Color,
Element_Type => Color_Sets.Set);
use Reverse_Bag_Maps;
function build_reverse_map(m : in Bag_Maps.Map) return Reverse_Bag_Maps.Map is
rev : Reverse_Bag_Maps.Map;
begin
for c in m.Iterate loop
for s of element(c) loop
if not rev.contains(s.Color) then
rev.include(s.Color, Empty_Set);
end if;
declare
curr : Color_Sets.Set := rev(s.Color);
begin
curr.include(key(c));
rev(s.color) := curr;
end;
end loop;
end loop;
return rev;
end build_reverse_map;
-- procedure print_rev(m : in Reverse_Bag_Maps.Map) is
-- begin
-- for c in m.Iterate loop
-- TIO.put_line(Bag_Color'Image(key(c)));
-- for s of element(c) loop
-- TIO.put_line(" " & Bag_Color'Image(s));
-- end loop;
-- end loop;
-- end print_rev;
procedure dfs(curr : in Bag_Color; rev : in Reverse_Bag_Maps.Map; reach : in out Color_Sets.Set) is
parents : Color_Sets.Set := Empty_Set;
begin
if rev.contains(curr) then
parents := rev(curr);
for p of parents loop
if not reach.contains(p) then
reach.insert(p);
dfs(p, rev, reach);
end if;
end loop;
end if;
end dfs;
function count_valid(m : in Bag_Maps.Map) return Natural is
rev : constant Reverse_Bag_Maps.Map := build_reverse_map(m);
reach : Color_Sets.Set := Empty_Set;
begin
-- print_rev(rev);
dfs(Bag.my_color, rev, reach);
return Natural(Color_Sets.length(reach));
end count_valid;
function valid_bag_colors return Natural is
b : constant Bag_Maps.Map := Bag.input_data;
begin
return count_valid(b);
end valid_bag_colors;
function valid_test_bag_colors return Natural is
b : constant Bag_Maps.Map := Bag.test_data;
begin
return count_valid(b);
end valid_test_bag_colors;
function count_nested(curr : in Bag_Color; bags : in Bag_Maps.Map) return Natural is
subs : Bag_Sets.Set;
sum : Natural := 0;
begin
if bags.contains(curr) then
subs := bags(curr);
for s of subs loop
sum := sum + s.count + (s.count * count_nested(s.color, bags));
end loop;
return sum;
else
return 0;
end if;
end count_nested;
function nested_bags return Natural is
b : constant Bag_Maps.Map := Bag.input_data;
begin
return count_nested(my_color, b);
end nested_bags;
function nested_test_bags return Natural is
b : constant Bag_Maps.Map := Bag.test_data;
begin
return count_nested(my_color, b);
end nested_test_bags;
end Day;
|
-----------------------------------------------------------------------
-- awa-wikis-parsers -- Wiki parser
-- Copyright (C) 2011, 2015 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings.Wide_Wide_Unbounded;
with AWA.Wikis.Documents;
-- The <b>AWA.Wikis.Parsers</b> package implements a parser for several well known wiki formats.
-- The parser works with the <b>Document_Reader</b> interface type which defines several
-- procedures that are called by the parser when the wiki text is scanned.
package AWA.Wikis.Parsers is
pragma Preelaborate;
-- Defines the possible wiki syntax supported by the parser.
type Wiki_Syntax_Type
is (
-- Google wiki syntax http://code.google.com/p/support/wiki/WikiSyntax
SYNTAX_GOOGLE,
-- Creole wiki syntax http://www.wikicreole.org/wiki/Creole1.0
SYNTAX_CREOLE,
-- Dotclear syntax http://dotclear.org/documentation/2.0/usage/syntaxes
SYNTAX_DOTCLEAR,
-- PhpBB syntax http://wiki.phpbb.com/Help:Formatting
SYNTAX_PHPBB,
-- MediaWiki syntax http://www.mediawiki.org/wiki/Help:Formatting
SYNTAX_MEDIA_WIKI,
-- A mix of the above
SYNTAX_MIX);
-- Parse the wiki text contained in <b>Text</b> according to the wiki syntax
-- specified in <b>Syntax</b> and invoke the document reader procedures defined
-- by <b>into</b>.
procedure Parse (Into : in AWA.Wikis.Documents.Document_Reader_Access;
Text : in Wide_Wide_String;
Syntax : in Wiki_Syntax_Type := SYNTAX_MIX);
private
HT : constant Wide_Wide_Character := Wide_Wide_Character'Val (16#09#);
LF : constant Wide_Wide_Character := Wide_Wide_Character'Val (16#0A#);
CR : constant Wide_Wide_Character := Wide_Wide_Character'Val (16#0D#);
type Input is interface;
type Input_Access is access all Input'Class;
procedure Read_Char (From : in out Input;
Token : out Wide_Wide_Character;
Eof : out Boolean) is abstract;
type Parser is limited record
Pending : Wide_Wide_Character;
Has_Pending : Boolean;
Document : AWA.Wikis.Documents.Document_Reader_Access;
Format : AWA.Wikis.Documents.Format_Map;
Text : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
Empty_Line : Boolean := True;
Is_Eof : Boolean := False;
In_Paragraph : Boolean := False;
Need_Paragraph : Boolean := True;
Link_Double_Bracket : Boolean := False;
Is_Dotclear : Boolean := False;
Header_Offset : Integer := 0;
Quote_Level : Natural := 0;
Escape_Char : Wide_Wide_Character;
List_Level : Natural := 0;
Reader : Input_Access := null;
end record;
type Parser_Handler is access procedure (P : in out Parser;
Token : in Wide_Wide_Character);
type Parser_Table is array (0 .. 127) of Parser_Handler;
type Parser_Table_Access is access Parser_Table;
end AWA.Wikis.Parsers;
|
-- This spec has been automatically generated from STM32F46_79x.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.DBG is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype DBGMCU_IDCODE_DEV_ID_Field is HAL.UInt12;
subtype DBGMCU_IDCODE_REV_ID_Field is HAL.UInt16;
-- IDCODE
type DBGMCU_IDCODE_Register is record
-- Read-only. DEV_ID
DEV_ID : DBGMCU_IDCODE_DEV_ID_Field;
-- unspecified
Reserved_12_15 : HAL.UInt4;
-- Read-only. REV_ID
REV_ID : DBGMCU_IDCODE_REV_ID_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DBGMCU_IDCODE_Register use record
DEV_ID at 0 range 0 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
REV_ID at 0 range 16 .. 31;
end record;
subtype DBGMCU_CR_TRACE_MODE_Field is HAL.UInt2;
-- Control Register
type DBGMCU_CR_Register is record
-- DBG_SLEEP
DBG_SLEEP : Boolean := False;
-- DBG_STOP
DBG_STOP : Boolean := False;
-- DBG_STANDBY
DBG_STANDBY : Boolean := False;
-- unspecified
Reserved_3_4 : HAL.UInt2 := 16#0#;
-- TRACE_IOEN
TRACE_IOEN : Boolean := False;
-- TRACE_MODE
TRACE_MODE : DBGMCU_CR_TRACE_MODE_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DBGMCU_CR_Register use record
DBG_SLEEP at 0 range 0 .. 0;
DBG_STOP at 0 range 1 .. 1;
DBG_STANDBY at 0 range 2 .. 2;
Reserved_3_4 at 0 range 3 .. 4;
TRACE_IOEN at 0 range 5 .. 5;
TRACE_MODE at 0 range 6 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-- Debug MCU APB1 Freeze registe
type DBGMCU_APB1_FZ_Register is record
-- DBG_TIM2_STOP
DBG_TIM2_STOP : Boolean := False;
-- DBG_TIM3 _STOP
DBG_TIM3_STOP : Boolean := False;
-- DBG_TIM4_STOP
DBG_TIM4_STOP : Boolean := False;
-- DBG_TIM5_STOP
DBG_TIM5_STOP : Boolean := False;
-- DBG_TIM6_STOP
DBG_TIM6_STOP : Boolean := False;
-- DBG_TIM7_STOP
DBG_TIM7_STOP : Boolean := False;
-- DBG_TIM12_STOP
DBG_TIM12_STOP : Boolean := False;
-- DBG_TIM13_STOP
DBG_TIM13_STOP : Boolean := False;
-- DBG_TIM14_STOP
DBG_TIM14_STOP : Boolean := False;
-- unspecified
Reserved_9_10 : HAL.UInt2 := 16#0#;
-- DBG_WWDG_STOP
DBG_WWDG_STOP : Boolean := False;
-- DBG_IWDEG_STOP
DBG_IWDEG_STOP : Boolean := False;
-- unspecified
Reserved_13_20 : HAL.UInt8 := 16#0#;
-- DBG_J2C1_SMBUS_TIMEOUT
DBG_J2C1_SMBUS_TIMEOUT : Boolean := False;
-- DBG_J2C2_SMBUS_TIMEOUT
DBG_J2C2_SMBUS_TIMEOUT : Boolean := False;
-- DBG_J2C3SMBUS_TIMEOUT
DBG_J2C3SMBUS_TIMEOUT : Boolean := False;
-- unspecified
Reserved_24_24 : HAL.Bit := 16#0#;
-- DBG_CAN1_STOP
DBG_CAN1_STOP : Boolean := False;
-- DBG_CAN2_STOP
DBG_CAN2_STOP : Boolean := False;
-- unspecified
Reserved_27_31 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DBGMCU_APB1_FZ_Register use record
DBG_TIM2_STOP at 0 range 0 .. 0;
DBG_TIM3_STOP at 0 range 1 .. 1;
DBG_TIM4_STOP at 0 range 2 .. 2;
DBG_TIM5_STOP at 0 range 3 .. 3;
DBG_TIM6_STOP at 0 range 4 .. 4;
DBG_TIM7_STOP at 0 range 5 .. 5;
DBG_TIM12_STOP at 0 range 6 .. 6;
DBG_TIM13_STOP at 0 range 7 .. 7;
DBG_TIM14_STOP at 0 range 8 .. 8;
Reserved_9_10 at 0 range 9 .. 10;
DBG_WWDG_STOP at 0 range 11 .. 11;
DBG_IWDEG_STOP at 0 range 12 .. 12;
Reserved_13_20 at 0 range 13 .. 20;
DBG_J2C1_SMBUS_TIMEOUT at 0 range 21 .. 21;
DBG_J2C2_SMBUS_TIMEOUT at 0 range 22 .. 22;
DBG_J2C3SMBUS_TIMEOUT at 0 range 23 .. 23;
Reserved_24_24 at 0 range 24 .. 24;
DBG_CAN1_STOP at 0 range 25 .. 25;
DBG_CAN2_STOP at 0 range 26 .. 26;
Reserved_27_31 at 0 range 27 .. 31;
end record;
-- Debug MCU APB2 Freeze registe
type DBGMCU_APB2_FZ_Register is record
-- TIM1 counter stopped when core is halted
DBG_TIM1_STOP : Boolean := False;
-- TIM8 counter stopped when core is halted
DBG_TIM8_STOP : Boolean := False;
-- unspecified
Reserved_2_15 : HAL.UInt14 := 16#0#;
-- TIM9 counter stopped when core is halted
DBG_TIM9_STOP : Boolean := False;
-- TIM10 counter stopped when core is halted
DBG_TIM10_STOP : Boolean := False;
-- TIM11 counter stopped when core is halted
DBG_TIM11_STOP : Boolean := False;
-- unspecified
Reserved_19_31 : HAL.UInt13 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DBGMCU_APB2_FZ_Register use record
DBG_TIM1_STOP at 0 range 0 .. 0;
DBG_TIM8_STOP at 0 range 1 .. 1;
Reserved_2_15 at 0 range 2 .. 15;
DBG_TIM9_STOP at 0 range 16 .. 16;
DBG_TIM10_STOP at 0 range 17 .. 17;
DBG_TIM11_STOP at 0 range 18 .. 18;
Reserved_19_31 at 0 range 19 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Debug support
type DBG_Peripheral is record
-- IDCODE
DBGMCU_IDCODE : aliased DBGMCU_IDCODE_Register;
-- Control Register
DBGMCU_CR : aliased DBGMCU_CR_Register;
-- Debug MCU APB1 Freeze registe
DBGMCU_APB1_FZ : aliased DBGMCU_APB1_FZ_Register;
-- Debug MCU APB2 Freeze registe
DBGMCU_APB2_FZ : aliased DBGMCU_APB2_FZ_Register;
end record
with Volatile;
for DBG_Peripheral use record
DBGMCU_IDCODE at 16#0# range 0 .. 31;
DBGMCU_CR at 16#4# range 0 .. 31;
DBGMCU_APB1_FZ at 16#8# range 0 .. 31;
DBGMCU_APB2_FZ at 16#C# range 0 .. 31;
end record;
-- Debug support
DBG_Periph : aliased DBG_Peripheral
with Import, Address => System'To_Address (16#E0042000#);
end STM32_SVD.DBG;
|
package Command_Line with SPARK_Mode is
type Exit_Status is new Integer;
function Argument_Count return Natural with
Global => null;
procedure Set_Exit_Status (Code : Exit_Status) with
Global => null;
function Argument (Number : Positive) return String with
Global => null,
Pre => Number >= 1 and then Number <= Argument_Count;
end Command_Line;
|
--
-- Copyright (C) 2016 secunet Security Networks AG
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
with HW.Time;
with HW.GFX.GMA.Config;
with HW.GFX.GMA.PCH.FDI;
with HW.GFX.GMA.Registers;
with HW.Debug;
with GNAT.Source_Info;
package body HW.GFX.GMA.Connectors.FDI
is
PCH_FDI_CHICKEN_B_AND_C : constant := 1 * 2 ** 12;
type TX_CTL_Regs is array (GPU_FDI_Port) of Registers.Registers_Index;
TX_CTL : constant TX_CTL_Regs :=
(DIGI_B => Registers.FDI_TX_CTL_A,
DIGI_C => Registers.FDI_TX_CTL_B,
DIGI_D => Registers.FDI_TX_CTL_C);
FDI_TX_CTL_FDI_TX_ENABLE : constant := 1 * 2 ** 31;
FDI_TX_CTL_VP_MASK : constant := 16#3f# * 2 ** 22;
FDI_TX_CTL_PORT_WIDTH_SEL_SHIFT : constant := 19;
FDI_TX_CTL_ENHANCED_FRAMING_ENABLE : constant := 1 * 2 ** 18;
FDI_TX_CTL_FDI_PLL_ENABLE : constant := 1 * 2 ** 14;
FDI_TX_CTL_COMPOSITE_SYNC_SELECT : constant := 1 * 2 ** 11;
FDI_TX_CTL_AUTO_TRAIN_ENABLE : constant := 1 * 2 ** 10;
FDI_TX_CTL_AUTO_TRAIN_DONE : constant := 1 * 2 ** 1;
TP_SHIFT : constant := (if Config.CPU <= Sandybridge then 28 else 8);
FDI_TX_CTL_TRAINING_PATTERN_MASK : constant := 3 * 2 ** TP_SHIFT;
FDI_TX_CTL_TRAINING_PATTERN_1 : constant := 0 * 2 ** TP_SHIFT;
FDI_TX_CTL_TRAINING_PATTERN_2 : constant := 1 * 2 ** TP_SHIFT;
FDI_TX_CTL_TRAINING_PATTERN_IDLE : constant := 2 * 2 ** TP_SHIFT;
FDI_TX_CTL_TRAINING_PATTERN_NORMAL : constant := 3 * 2 ** TP_SHIFT;
subtype FDI_TX_CTL_VP_T is Natural range 0 .. 3;
type Vswing_Preemph_Values is array (FDI_TX_CTL_VP_T) of Word32;
FDI_TX_CTL_VSWING_PREEMPH : constant Vswing_Preemph_Values :=
(0 => 16#00# * 2 ** 22,
1 => 16#3a# * 2 ** 22,
2 => 16#39# * 2 ** 22,
3 => 16#38# * 2 ** 22);
function FDI_TX_CTL_PORT_WIDTH_SEL (Lane_Count : DP_Lane_Count) return Word32
is
begin
return Shift_Left
(Word32 (Lane_Count_As_Integer (Lane_Count)) - 1,
FDI_TX_CTL_PORT_WIDTH_SEL_SHIFT);
end FDI_TX_CTL_PORT_WIDTH_SEL;
----------------------------------------------------------------------------
--
-- This is usually used with Ivy Bridge.
--
procedure Auto_Training
(Port_Cfg : in Port_Config;
Success : out Boolean)
with
Pre => Port_Cfg.Port in GPU_FDI_Port
is
PCH_FDI_Port : constant PCH.FDI_Port_Type := PCH_FDIs (Port_Cfg.Port);
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
-- try each preemph/voltage pair twice
for VP2 in Natural range 0 .. FDI_TX_CTL_VP_T'Last * 2 + 1
loop
Registers.Unset_And_Set_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask_Unset => FDI_TX_CTL_VP_MASK or
FDI_TX_CTL_TRAINING_PATTERN_MASK,
Mask_Set => FDI_TX_CTL_FDI_TX_ENABLE or
FDI_TX_CTL_VSWING_PREEMPH (VP2 / 2) or
FDI_TX_CTL_AUTO_TRAIN_ENABLE or
FDI_TX_CTL_TRAINING_PATTERN_1);
Registers.Posting_Read (TX_CTL (Port_Cfg.Port));
PCH.FDI.Auto_Train (PCH_FDI_Port);
-- read at least twice
for I in 0 .. 3 loop
Registers.Is_Set_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask => FDI_TX_CTL_AUTO_TRAIN_DONE,
Result => Success);
exit when Success or I = 3;
Time.U_Delay (1);
end loop;
exit when Success;
Registers.Unset_And_Set_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask_Unset => FDI_TX_CTL_FDI_TX_ENABLE or
FDI_TX_CTL_AUTO_TRAIN_ENABLE or
FDI_TX_CTL_TRAINING_PATTERN_MASK,
Mask_Set => FDI_TX_CTL_TRAINING_PATTERN_1);
PCH.FDI.Off (PCH_FDI_Port, PCH.FDI.Rx_Off);
end loop;
if Success then
PCH.FDI.Enable_EC (PCH_FDI_Port);
else
Registers.Unset_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask => FDI_TX_CTL_FDI_PLL_ENABLE);
PCH.FDI.Off (PCH_FDI_Port, PCH.FDI.Clock_Off);
end if;
end Auto_Training;
----------------------------------------------------------------------------
--
-- Used with Sandy Bridge (should work with Ivy Bridge too)
--
procedure Full_Training
(Port_Cfg : in Port_Config;
Success : out Boolean)
with
Pre => Port_Cfg.Port in GPU_FDI_Port
is
PCH_FDI_Port : constant PCH.FDI_Port_Type := PCH_FDIs (Port_Cfg.Port);
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
-- try each preemph/voltage pair twice
for VP2 in Natural range 0 .. FDI_TX_CTL_VP_T'Last * 2 + 1
loop
Registers.Unset_And_Set_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask_Unset => FDI_TX_CTL_VP_MASK or
FDI_TX_CTL_TRAINING_PATTERN_MASK,
Mask_Set => FDI_TX_CTL_FDI_TX_ENABLE or
FDI_TX_CTL_VSWING_PREEMPH (VP2 / 2) or
FDI_TX_CTL_TRAINING_PATTERN_1);
Registers.Posting_Read (TX_CTL (Port_Cfg.Port));
PCH.FDI.Train (PCH_FDI_Port, PCH.FDI.TP_1, Success);
if Success then
Registers.Unset_And_Set_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask_Unset => FDI_TX_CTL_TRAINING_PATTERN_MASK,
Mask_Set => FDI_TX_CTL_TRAINING_PATTERN_2);
Registers.Posting_Read (TX_CTL (Port_Cfg.Port));
PCH.FDI.Train (PCH_FDI_Port, PCH.FDI.TP_2, Success);
end if;
exit when Success;
Registers.Unset_And_Set_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask_Unset => FDI_TX_CTL_FDI_TX_ENABLE or
FDI_TX_CTL_TRAINING_PATTERN_MASK,
Mask_Set => FDI_TX_CTL_TRAINING_PATTERN_1);
PCH.FDI.Off (PCH_FDI_Port, PCH.FDI.Rx_Off);
end loop;
if Success then
Registers.Unset_And_Set_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask_Unset => FDI_TX_CTL_TRAINING_PATTERN_MASK,
Mask_Set => FDI_TX_CTL_TRAINING_PATTERN_NORMAL);
Registers.Posting_Read (TX_CTL (Port_Cfg.Port));
PCH.FDI.Train (PCH_FDI_Port, PCH.FDI.TP_None, Success);
else
Registers.Unset_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask => FDI_TX_CTL_FDI_PLL_ENABLE);
PCH.FDI.Off (PCH_FDI_Port, PCH.FDI.Clock_Off);
end if;
end Full_Training;
----------------------------------------------------------------------------
--
-- Used with original Ironlake (Nehalem CPU)
--
-- This is close to what Linux' i915 does. A comment in i915_reg.h
-- states that it uses only the lowest voltage / pre-emphasis levels
-- which is why we leave them at zero here and don't try different
-- values.
--
-- It's actually not clear from i915's code if the values really are
-- at zero or if it's just reusing what the Video BIOS set. Some code
-- in coreboot sets them to zero explicitly.
--
procedure Simple_Training
(Port_Cfg : in Port_Config;
Success : out Boolean)
with
Pre => Port_Cfg.Port in GPU_FDI_Port
is
PCH_FDI_Port : constant PCH.FDI_Port_Type := PCH_FDIs (Port_Cfg.Port);
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
Registers.Unset_And_Set_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask_Unset => FDI_TX_CTL_TRAINING_PATTERN_MASK,
Mask_Set => FDI_TX_CTL_FDI_TX_ENABLE or
FDI_TX_CTL_TRAINING_PATTERN_1);
Registers.Posting_Read (TX_CTL (Port_Cfg.Port));
PCH.FDI.Train (PCH_FDI_Port, PCH.FDI.TP_1, Success);
if Success then
Registers.Unset_And_Set_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask_Unset => FDI_TX_CTL_TRAINING_PATTERN_MASK,
Mask_Set => FDI_TX_CTL_TRAINING_PATTERN_2);
Registers.Posting_Read (TX_CTL (Port_Cfg.Port));
PCH.FDI.Train (PCH_FDI_Port, PCH.FDI.TP_2, Success);
end if;
if Success then
Registers.Unset_And_Set_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask_Unset => FDI_TX_CTL_TRAINING_PATTERN_MASK,
Mask_Set => FDI_TX_CTL_TRAINING_PATTERN_NORMAL);
Registers.Posting_Read (TX_CTL (Port_Cfg.Port));
PCH.FDI.Train (PCH_FDI_Port, PCH.FDI.TP_None, Success);
else
Registers.Unset_And_Set_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask_Unset => FDI_TX_CTL_FDI_TX_ENABLE or
FDI_TX_CTL_TRAINING_PATTERN_MASK,
Mask_Set => FDI_TX_CTL_TRAINING_PATTERN_1);
PCH.FDI.Off (PCH_FDI_Port, PCH.FDI.Rx_Off);
Registers.Unset_Mask
(Register => TX_CTL (Port_Cfg.Port),
Mask => FDI_TX_CTL_FDI_PLL_ENABLE);
PCH.FDI.Off (PCH_FDI_Port, PCH.FDI.Clock_Off);
end if;
end Simple_Training;
----------------------------------------------------------------------------
procedure Pre_On (Port_Cfg : Port_Config)
is
Composite_Sel : constant :=
(if Config.Has_FDI_Composite_Sel then
FDI_TX_CTL_COMPOSITE_SYNC_SELECT else 0);
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
-- The PCH_FDI_CHICKEN_B_AND_C bit may not be changed when any of
-- both ports is active. Bandwidth calculations before calling us
-- should ensure this.
if Config.Has_FDI_C then
if Port_Cfg.Port = DIGI_D or
(Port_Cfg.Port = DIGI_C and
Port_Cfg.FDI.Lane_Count <= DP_Lane_Count_2)
then
Registers.Set_Mask
(Register => Registers.PCH_FDI_CHICKEN_B_C,
Mask => PCH_FDI_CHICKEN_B_AND_C);
elsif Port_Cfg.Port = DIGI_C then
Registers.Unset_Mask
(Register => Registers.PCH_FDI_CHICKEN_B_C,
Mask => PCH_FDI_CHICKEN_B_AND_C);
end if;
end if;
PCH.FDI.Pre_Train (PCH_FDIs (Port_Cfg.Port), Port_Cfg);
Registers.Write
(Register => TX_CTL (Port_Cfg.Port),
Value => FDI_TX_CTL_PORT_WIDTH_SEL (Port_Cfg.FDI.Lane_Count) or
FDI_TX_CTL_ENHANCED_FRAMING_ENABLE or
FDI_TX_CTL_FDI_PLL_ENABLE or
Composite_Sel or
FDI_TX_CTL_TRAINING_PATTERN_1);
Registers.Posting_Read (TX_CTL (Port_Cfg.Port));
Time.U_Delay (100);
end Pre_On;
----------------------------------------------------------------------------
procedure Post_On
(Port_Cfg : in Port_Config;
Success : out Boolean)
is
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
case Config.FDI_Training is
when GMA.Simple_Training => Simple_Training (Port_Cfg, Success);
when GMA.Full_Training => Full_Training (Port_Cfg, Success);
when GMA.Auto_Training => Auto_Training (Port_Cfg, Success);
end case;
end Post_On;
----------------------------------------------------------------------------
procedure Off (Port : GPU_FDI_Port; OT : Off_Type)
is
PCH_FDI_Port : constant PCH.FDI_Port_Type := PCH_FDIs (Port);
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
Registers.Unset_And_Set_Mask
(Register => TX_CTL (Port),
Mask_Unset => FDI_TX_CTL_FDI_TX_ENABLE or
FDI_TX_CTL_AUTO_TRAIN_ENABLE or
FDI_TX_CTL_TRAINING_PATTERN_MASK,
Mask_Set => FDI_TX_CTL_TRAINING_PATTERN_1);
PCH.FDI.Off (PCH_FDI_Port, PCH.FDI.Rx_Off);
if OT >= Clock_Off then
Registers.Unset_Mask
(Register => TX_CTL (Port),
Mask => FDI_TX_CTL_FDI_PLL_ENABLE);
PCH.FDI.Off (PCH_FDI_Port, PCH.FDI.Clock_Off);
end if;
end Off;
end HW.GFX.GMA.Connectors.FDI;
|
generic
type Element_Type is private;
package Container is
type Tree is tagged private;
procedure Replace_All(The_Tree : in out Tree; New_Value : Element_Type);
private
type Node;
type Node_Access is access Node;
type Tree tagged record
Value : Element_type;
Left : Node_Access := null;
Right : Node_Access := null;
end record;
end Container;
|
with kv.avm.Test;
with kv.avm.Asm_Tests;
with kv.avm.Comm_Tests;
with kv.avm.Vole_Tests;
package body avm_suite is
function Suite return Access_Test_Suite is
Answer : constant Access_Test_Suite := new Test_Suite;
begin
Answer.Add_Test(new kv.avm.Test.Test_1);
Answer.Add_Test(new kv.avm.Test.Test_2);
Answer.Add_Test(new kv.avm.Test.Test_3);
Answer.Add_Test(new kv.avm.Test.Test_4);
Answer.Add_Test(new kv.avm.Test.Test_4b);
Answer.Add_Test(new kv.avm.Test.Test_5);
Answer.Add_Test(new kv.avm.Test.Test_6);
Answer.Add_Test(new kv.avm.Test.Test_6b);
Answer.Add_Test(new kv.avm.Test.Test_7);
Answer.Add_Test(new kv.avm.Test.Test_8);
Answer.Add_Test(new kv.avm.Test.Test_9);
Answer.Add_Test(new kv.avm.Test.Test_9b);
Answer.Add_Test(new kv.avm.Test.Test_9c);
Answer.Add_Test(new kv.avm.Test.Test_9d);
Answer.Add_Test(new kv.avm.Test.Test_10);
Answer.Add_Test(new kv.avm.Test.Test_11);
Answer.Add_Test(new kv.avm.Test.Test_12);
Answer.Add_Test(new kv.avm.Test.Test_13);
Answer.Add_Test(new kv.avm.Test.Test_14);
Answer.Add_Test(new kv.avm.Test.Test_15);
Answer.Add_Test(new kv.avm.Test.Test_16);
Answer.Add_Test(new kv.avm.Test.Test_17);
Answer.Add_Test(new kv.avm.Test.Test_18);
Answer.Add_Test(new kv.avm.Test.Test_19);
Answer.Add_Test(new kv.avm.Test.Test_20);
Answer.Add_Test(new kv.avm.Test.Test_21);
Answer.Add_Test(new kv.avm.Test.Test_22);
Answer.Add_Test(new kv.avm.Test.Test_23);
Answer.Add_Test(new kv.avm.Test.Test_24);
Answer.Add_Test(new kv.avm.Test.Test_25);
Answer.Add_Test(new kv.avm.Test.Test_26);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A1);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A2);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A3);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A4);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A5);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A6);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A7);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A8);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A9);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A10);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A11);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A12);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A13);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A14);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A15);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A16);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A17);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A18);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A19);
Answer.Add_Test(new kv.avm.Asm_Tests.Test_A20);
Answer.Add_Test(new kv.avm.Comm_Tests.Test_01);
Answer.Add_Test(new kv.avm.Comm_Tests.Test_02);
Answer.Add_Test(new kv.avm.Comm_Tests.Test_03);
Answer.Add_Test(new kv.avm.Comm_Tests.Test_04);
Answer.Add_Test(new kv.avm.Comm_Tests.Test_05);
Answer.Add_Test(new kv.avm.Comm_Tests.Test_06);
Answer.Add_Test(new kv.avm.Comm_Tests.Test_07);
Answer.Add_Test(new kv.avm.Comm_Tests.Test_08);
Answer.Add_Test(new kv.avm.Comm_Tests.Test_09);
Answer.Add_Test(new kv.avm.Vole_Tests.Test_01);
Answer.Add_Test(new kv.avm.Vole_Tests.Test_02);
Answer.Add_Test(new kv.avm.Vole_Tests.Test_03);
Answer.Add_Test(new kv.avm.Vole_Tests.Test_04);
Answer.Add_Test(new kv.avm.Vole_Tests.Test_05);
Answer.Add_Test(new kv.avm.Vole_Tests.Test_06);
Answer.Add_Test(new kv.avm.Vole_Tests.Test_07);
Answer.Add_Test(new kv.avm.Vole_Tests.Test_08);
return Answer;
end Suite;
end avm_suite;
|
-- Copyright (c) 2021 Devin Hill
-- zlib License -- see LICENSE for details.
package GBA.BIOS.Raw is
pragma Preelaborate;
end GBA.BIOS.Raw;
|
with HWIF;use HWIF;
with HWIF_Types; use HWIF_Types;
--with Ada.Text_IO; use Ada.Text_IO;
procedure TrafficLightSwitcher (dir : in Direction) is
begin
if Traffic_Light(dir) = 4 then --If Red Light.
delay 1.0;
Traffic_Light(dir) := 6; --Amber/Red
delay 3.0; --Safety Req: Amber phase must last at least 3 seconds
Traffic_Light(dir) := 1; --Green Light
delay 5.0; --Safety Req: Green phase must last at least 5 seconds
elsif Traffic_Light(dir) = 1 then --If Green light.
Traffic_Light(dir) := 2; --Amber
delay 3.0 ; --Safety Req; Amber phase must last at least 3 seconds
Traffic_Light(dir) := 4; --Red Light
end if;
end;
|
------------------------------------------------------------------------------
-- Copyright (c) 2013-2014, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Natools.References implements reference-counted smart pointer to any --
-- type of objects. --
-- This is a basic implementation that does not support weak references, --
-- but uses protected counters to ensure task safe operations. --
-- Beware though that there is still no guarantee on the task-safety of the --
-- operations performed on the referred objects. --
------------------------------------------------------------------------------
with Ada.Finalization;
with System.Storage_Pools;
generic
type Held_Data (<>) is limited private;
Counter_Pool : in out System.Storage_Pools.Root_Storage_Pool'Class;
Data_Pool : in out System.Storage_Pools.Root_Storage_Pool'Class;
package Natools.References is
pragma Preelaborate (References);
type Accessor (Data : not null access constant Held_Data) is
limited private with Implicit_Dereference => Data;
type Mutator (Data : not null access Held_Data) is
limited private with Implicit_Dereference => Data;
type Data_Access is access Held_Data;
for Data_Access'Storage_Pool use Data_Pool;
type Immutable_Reference is new Ada.Finalization.Controlled with private;
pragma Preelaborable_Initialization (Immutable_Reference);
function Create
(Constructor : not null access function return Held_Data)
return Immutable_Reference;
-- Create a new held object and return a reference to it
procedure Replace
(Ref : in out Immutable_Reference;
Constructor : not null access function return Held_Data);
-- Replace the object held in Ref with a newly created object
function Create (Data : in Data_Access) return Immutable_Reference;
-- Create a new reference from Data.
-- From this point the referred object is owned by this
-- package and must NOT be freed or changed or accessed.
procedure Replace (Ref : in out Immutable_Reference; Data : in Data_Access);
-- Integrate Data into Ref.
-- From this point the referred object is owned by this
-- package and must NOT be freed or changed or accessed.
procedure Reset (Ref : in out Immutable_Reference);
-- Empty Ref
function Is_Empty (Ref : Immutable_Reference) return Boolean;
-- Check whether Ref refers to an actual object
function Is_Last (Ref : Immutable_Reference) return Boolean;
-- Check whether Ref is the last reference to its object.
-- WARNING: This is inherently not task-safe if Ref can be
-- concurrently accessed.
function "=" (Left, Right : Immutable_Reference) return Boolean;
-- Check whether Left and Right refer to the same object
function Query (Ref : in Immutable_Reference) return Accessor;
pragma Inline (Query);
-- Return a derefenciable constant access to the held object
procedure Query
(Ref : in Immutable_Reference;
Process : not null access procedure (Object : in Held_Data));
-- Call Process with the held object
Null_Immutable_Reference : constant Immutable_Reference;
type Reference is new Immutable_Reference with private;
pragma Preelaborable_Initialization (Reference);
function Update (Ref : in Reference) return Mutator;
pragma Inline (Update);
-- Return a ereferenciable mutable access to the held object
procedure Update
(Ref : in Reference;
Process : not null access procedure (Object : in out Held_Data));
-- Call Process with the held object
Null_Reference : constant Reference;
private
protected type Counter is
procedure Increment;
procedure Decrement (Zero : out Boolean);
function Get_Value return Natural;
private
Value : Natural := 1;
end Counter;
type Counter_Access is access Counter;
for Counter_Access'Storage_Pool use Counter_Pool;
type Immutable_Reference is new Ada.Finalization.Controlled with record
Count : Counter_Access := null;
Data : Data_Access := null;
end record;
overriding procedure Adjust (Object : in out Immutable_Reference);
-- Increate reference counter
overriding procedure Finalize (Object : in out Immutable_Reference);
-- Decrease reference counter and release memory if needed
type Reference is new Immutable_Reference with null record;
type Accessor (Data : not null access constant Held_Data) is limited record
Parent : Immutable_Reference;
end record;
type Mutator (Data : not null access Held_Data) is limited record
Parent : Reference;
end record;
Null_Immutable_Reference : constant Immutable_Reference
:= (Ada.Finalization.Controlled with Count => null, Data => null);
Null_Reference : constant Reference
:= (Null_Immutable_Reference with null record);
end Natools.References;
|
with Extraction.Graph_Operations;
private package Extraction.Project_Files is
procedure Extract_Nodes
(Project : GPR.Project_Type;
Graph : Graph_Operations.Graph_Context);
procedure Extract_Edges
(Project : GPR.Project_Type;
Recurse_Projects : Boolean;
Graph : Graph_Operations.Graph_Context);
end Extraction.Project_Files;
|
X : Image (1..16, 1..16);
begin
Fill (X, White);
Quadratic_Bezier (X, (8, 2), (13, 8), (2, 15), Black);
Print (X);
|
package body Test_Date.Append is
File_Name : constant String := "tmp/test-append-date.sf";
procedure Initialize (T : in out Test) is
begin
Set_Name (T, "Test_Date.Append");
Ahven.Framework.Add_Test_Routine (T, Read_Append_Read'Access, "read, append, read");
Ahven.Framework.Add_Test_Routine (T, Create_Write_4xAppend_Read'Access, "create, write, 4x append, read");
end Initialize;
procedure Set_Up (T : in out Test) is
State : access Skill_State := new Skill_State;
begin
Skill.Read (State, "resources/date-example.sf");
Skill.Write (State, File_Name);
end Set_Up;
procedure Tear_Down (T : in out Test) is
begin
Ada.Directories.Delete_File (File_Name);
end Tear_Down;
procedure Read_Append_Read (T : in out Ahven.Framework.Test_Case'Class) is
begin
declare
State : access Skill_State := new Skill_State;
begin
Skill.Read (State, File_Name);
New_Date (State, 23);
New_Date (State, 42);
Skill.Append (State);
end;
declare
State : access Skill_State := new Skill_State;
begin
Read (State, File_Name);
Ahven.Assert (Get_Date (State, 1).Get_Date = 1, "Get_Date is not 1.");
Ahven.Assert (Get_Date (State, 2).Get_Date = -1, "Get_Date is not -1.");
Ahven.Assert (Get_Date (State, 3).Get_Date = 23, "Get_Date is not 23.");
Ahven.Assert (Get_Date (State, 4).Get_Date = 42, "Get_Date is not 42.");
end;
end Read_Append_Read;
procedure Create_Write_4xAppend_Read (T : in out Ahven.Framework.Test_Case'Class) is
begin
declare
State : access Skill_State := new Skill_State;
begin
Create (State);
New_Date (State, 1);
New_Date (State, 2);
Write (State, File_Name);
New_Date (State, 3);
New_Date (State, 4);
Skill.Append (State);
Skill.Append (State);
Skill.Append (State);
New_Date (State, 5);
Skill.Append (State);
end;
declare
State : access Skill_State := new Skill_State;
begin
Skill.Read (State, File_Name);
Ahven.Assert (Get_Date (State, 1).Get_Date = 1, "Get_Date is not 1.");
Ahven.Assert (Get_Date (State, 2).Get_Date = 2, "Get_Date is not 2.");
Ahven.Assert (Get_Date (State, 3).Get_Date = 3, "Get_Date is not 3.");
Ahven.Assert (Get_Date (State, 4).Get_Date = 4, "Get_Date is not 4.");
Ahven.Assert (Get_Date (State, 5).Get_Date = 5, "Get_Date is not 5.");
end;
end Create_Write_4xAppend_Read;
end Test_Date.Append;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T . A R R A Y _ S P L I T --
-- --
-- B o d y --
-- --
-- Copyright (C) 2002-2005, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
package body GNAT.Array_Split is
procedure Free is
new Ada.Unchecked_Deallocation (Slices_Indexes, Slices_Access);
procedure Free is
new Ada.Unchecked_Deallocation (Separators_Indexes, Indexes_Access);
function Count
(Source : Element_Sequence;
Pattern : Element_Set) return Natural;
-- Returns the number of occurences of Pattern elements in Source, 0 is
-- returned if no occurence is found in Source.
------------
-- Adjust --
------------
procedure Adjust (S : in out Slice_Set) is
begin
S.Ref_Counter.all := S.Ref_Counter.all + 1;
end Adjust;
------------
-- Create --
------------
procedure Create
(S : out Slice_Set;
From : Element_Sequence;
Separators : Element_Sequence;
Mode : Separator_Mode := Single)
is
begin
Create (S, From, To_Set (Separators), Mode);
end Create;
------------
-- Create --
------------
procedure Create
(S : out Slice_Set;
From : Element_Sequence;
Separators : Element_Set;
Mode : Separator_Mode := Single)
is
begin
S.Source := new Element_Sequence'(From);
Set (S, Separators, Mode);
end Create;
-----------
-- Count --
-----------
function Count
(Source : Element_Sequence;
Pattern : Element_Set) return Natural
is
C : Natural := 0;
begin
for K in Source'Range loop
if Is_In (Source (K), Pattern) then
C := C + 1;
end if;
end loop;
return C;
end Count;
--------------
-- Finalize --
--------------
procedure Finalize (S : in out Slice_Set) is
procedure Free is
new Ada.Unchecked_Deallocation (Element_Sequence, Element_Access);
procedure Free is
new Ada.Unchecked_Deallocation (Natural, Counter);
begin
S.Ref_Counter.all := S.Ref_Counter.all - 1;
if S.Ref_Counter.all = 0 then
Free (S.Source);
Free (S.Indexes);
Free (S.Slices);
Free (S.Ref_Counter);
end if;
end Finalize;
----------------
-- Initialize --
----------------
procedure Initialize (S : in out Slice_Set) is
begin
S.Ref_Counter := new Natural'(1);
end Initialize;
----------------
-- Separators --
----------------
function Separators
(S : Slice_Set;
Index : Slice_Number) return Slice_Separators
is
begin
if Index > S.N_Slice then
raise Index_Error;
elsif Index = 0
or else (Index = 1 and then S.N_Slice = 1)
then
-- Whole string, or no separator used
return (Before => Array_End,
After => Array_End);
elsif Index = 1 then
return (Before => Array_End,
After => S.Source (S.Slices (Index).Stop + 1));
elsif Index = S.N_Slice then
return (Before => S.Source (S.Slices (Index).Start - 1),
After => Array_End);
else
return (Before => S.Source (S.Slices (Index).Start - 1),
After => S.Source (S.Slices (Index).Stop + 1));
end if;
end Separators;
----------------
-- Separators --
----------------
function Separators (S : Slice_Set) return Separators_Indexes is
begin
return S.Indexes.all;
end Separators;
---------
-- Set --
---------
procedure Set
(S : in out Slice_Set;
Separators : Element_Sequence;
Mode : Separator_Mode := Single)
is
begin
Set (S, To_Set (Separators), Mode);
end Set;
---------
-- Set --
---------
procedure Set
(S : in out Slice_Set;
Separators : Element_Set;
Mode : Separator_Mode := Single)
is
Count_Sep : constant Natural := Count (S.Source.all, Separators);
J : Positive;
begin
-- Free old structure
Free (S.Indexes);
Free (S.Slices);
-- Compute all separator's indexes
S.Indexes := new Separators_Indexes (1 .. Count_Sep);
J := S.Indexes'First;
for K in S.Source'Range loop
if Is_In (S.Source (K), Separators) then
S.Indexes (J) := K;
J := J + 1;
end if;
end loop;
-- Compute slice info for fast slice access
declare
S_Info : Slices_Indexes (1 .. Slice_Number (Count_Sep) + 1);
K : Natural := 1;
Start, Stop : Natural;
begin
S.N_Slice := 0;
Start := S.Source'First;
Stop := 0;
loop
if K > Count_Sep then
-- No more separators, last slice ends at the end of the source
-- string.
Stop := S.Source'Last;
else
Stop := S.Indexes (K) - 1;
end if;
-- Add slice to the table
S.N_Slice := S.N_Slice + 1;
S_Info (S.N_Slice) := (Start, Stop);
exit when K > Count_Sep;
case Mode is
when Single =>
-- In this mode just set start to character next to the
-- current separator, advance the separator index.
Start := S.Indexes (K) + 1;
K := K + 1;
when Multiple =>
-- In this mode skip separators following each other
loop
Start := S.Indexes (K) + 1;
K := K + 1;
exit when K > Count_Sep
or else S.Indexes (K) > S.Indexes (K - 1) + 1;
end loop;
end case;
end loop;
S.Slices := new Slices_Indexes'(S_Info (1 .. S.N_Slice));
end;
end Set;
-----------
-- Slice --
-----------
function Slice
(S : Slice_Set;
Index : Slice_Number) return Element_Sequence
is
begin
if Index = 0 then
return S.Source.all;
elsif Index > S.N_Slice then
raise Index_Error;
else
return S.Source (S.Slices (Index).Start .. S.Slices (Index).Stop);
end if;
end Slice;
-----------------
-- Slice_Count --
-----------------
function Slice_Count (S : Slice_Set) return Slice_Number is
begin
return S.N_Slice;
end Slice_Count;
end GNAT.Array_Split;
|
generic
type Swap_Type is private; -- Generic parameter
procedure Generic_Swap(Left : in out Swap_Type; Right : in out Swap_Type);
procedure Generic_Swap(Left : in out Swap_Type; Right : in out Swap_Type) is
Temp : Swap_Type := Left;
begin
Left := Right;
Right := Temp;
end Generic_Swap;
|
with Memory.Transform.Flip; use Memory.Transform.Flip;
with Parser.Transform_Parser;
separate (Parser)
procedure Parse_Flip(parser : in out Parser_Type;
result : out Memory_Pointer) is
package Flip_Parser is new Transform_Parser(
T_Type => Flip_Type,
T_Pointer => Flip_Pointer,
Create_Transform => Create_Flip
);
begin
Flip_Parser.Parse(parser, result);
end Parse_Flip;
|
-- SPDX-FileCopyrightText: 2019-2021 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Cross_Reference_Updaters;
with Program.Element_Vector_Factories;
with Program.Element_Vectors;
with Program.Implicit_Element_Factories;
with Program.Visibility;
package Program.Predefined_Operators is
pragma Preelaborate;
procedure Create_Operators_For_Array
(Self : in out Program.Visibility.Context'Class;
Type_View : Program.Visibility.View;
Setter : not null
Program.Cross_Reference_Updaters.Cross_Reference_Updater_Access;
Factory : Program.Implicit_Element_Factories.Element_Factory;
Vectors : Program.Element_Vector_Factories.Element_Vector_Factory;
Result : out Program.Element_Vectors.Element_Vector_Access);
procedure Create_Operators_For_Integer
(Self : in out Program.Visibility.Context'Class;
Type_View : Program.Visibility.View;
Setter : not null
Program.Cross_Reference_Updaters.Cross_Reference_Updater_Access;
Factory : Program.Implicit_Element_Factories.Element_Factory;
Vectors : Program.Element_Vector_Factories.Element_Vector_Factory;
Result : out Program.Element_Vectors.Element_Vector_Access);
end Program.Predefined_Operators;
|
package openGL.IO.lat_long_Radius
--
-- Provides a function to convert a model file containing longitude, latitude
-- and radius triplets (one triplet per line) to an openGL IO model.
--
is
function to_Model (model_File : in String) return IO.Model;
function to_Model (math_Model : access Geometry_3d.a_Model) return IO.Model;
end openGL.IO.lat_long_Radius;
|
with System.Storage_Elements; use System.Storage_Elements;
package Slice7_Pkg is
procedure Put (The_Object : in Storage_Array);
end Slice7_Pkg;
|
with Test_Solution; use Test_Solution;
package Problem_11 is
type Grid is array(Natural range <>, Natural range <>) of Natural;
function Solution_1( G : Grid ) return Integer
with Pre => G'Length(1) = G'Length(2);
procedure Test_Solution_1;
function Get_Solutions return Solution_Case;
end Problem_11;
|
package pointer_variable_bounds_q is
type A_SIZE_TYPE is new INTEGER range 0 .. 65536;
function A_MAX_COMPS return A_SIZE_TYPE;
end pointer_variable_bounds_q;
|
package openGL.Light
--
-- Models a light.
--
is
type Item is abstract tagged private;
function is_On (Self : in Item) return Boolean;
procedure is_On (Self : in out Item; Now : in Boolean := True);
function Site (Self : in Item) return openGL.Site;
procedure Site_is (Self : in out Item; Now : in openGL.Site);
private
type Item is abstract tagged
record
On : Boolean := False;
Site : openGL.Site := (0.0, 0.0, 1.0); -- The GL default.
end record;
end openGL.Light;
|
with AUnit.Test_Fixtures;
with AUnit.Test_Suites;
package Tests is
function Suite return AUnit.Test_Suites.Access_Test_Suite;
private
type Fixture is new AUnit.Test_Fixtures.Test_Fixture with null record;
procedure Swap_Endian_Test (Object : in out Fixture);
procedure Native_To_Big_Endian_And_Back_Test (Object : in out Fixture);
procedure Native_To_Little_Endian_And_Back_Test (Object : in out Fixture);
end Tests;
|
-- Test Jacobi Eigendecomposition of real valued square matrices.
with Ada.Numerics.Generic_elementary_functions;
with Jacobi_Eigen;
with Test_Matrices;
with Text_IO; use Text_IO;
procedure jacobi_eigen_tst_1 is
type Real is digits 15;
--Matrix_Size : constant := 2277;
--Matrix_Size : constant := 597;
Matrix_Size : constant := 137;
Index_First : constant := 1;
-- Sometimes it's faster if you use a storage matrix that's a little
-- larger than the original matrix. (Depends on the hardware, the problem,
-- and the size of the matrix.) A rule of thumb: Width of storage matrix
-- should be an even number, greater than matrix size, and never 2**n.
--
-- Most important thing is to avoid 2**n matrix width.
--
-- Padding usually doesn't help a lot, but just in case let's add 1 or 2:
Padding : constant := 2 - (Matrix_Size - Index_First + 1) mod 2;
subtype Index is Integer range 1 .. Matrix_Size + Padding;
-- the test matrix is square-shaped matrix on: Index x Index.
-- eg Hilbert's matrix is a square matrix with unique elements on the range
-- Index'First .. Index'Last. However, you have the option or using any
-- diagonal sub-block of the matrix defined by Index x Index
subtype Col_Index is Index;
Starting_Col : constant Index := Index'First + 0;
Final_Col : constant Index := Index'Last - Padding;
-- Can't change:
Starting_Row : constant Index := Starting_Col;
Final_Row : constant Index := Final_Col;
type Matrix is array(Index, Index) of Real;
--pragma Convention (Fortran, Matrix); --No! prefers Ada convention.
package math is new Ada.Numerics.Generic_Elementary_Functions (Real);
use math;
package Eig is new Jacobi_Eigen
(Real => Real,
Index => Index,
Matrix => Matrix);
use Eig;
-- Eig exports Col_Vector
package Make_Square_Matrix is new Test_Matrices (Real, Index, Matrix);
use Make_Square_Matrix;
package rio is new Float_IO(Real);
use rio;
--subtype Real_Extended is Real; -- general case, works fine
type Real_Extended is digits 18; -- 18 ok on intel
Zero : constant Real := +0.0;
One : constant Real := +1.0;
Two : constant Real := +2.0;
A, A_true, Q_tr : Matrix;
Eigenvals : Col_Vector;
Frobenius_QtrQ_Err, Frobenius_QQtr_Err, Frobenius_QEQ_Err : Real;
No_of_Sweeps_Done, No_of_Rotations : Natural;
N : constant Real := Real (Starting_Col) - Real (Final_Col) + 1.0;
--------------------
-- Frobenius_Norm --
--------------------
function Frobenius_Norm
(A : in Matrix)
return Real
is
Max_A_Val : Real := Zero;
Sum, Scaling, tmp : Real := Zero;
begin
Max_A_Val := Zero;
for Row in Starting_Row .. Final_Row loop
for Col in Starting_Col .. Final_Col loop
if Max_A_Val < Abs A(Row, Col) then Max_A_Val := Abs A(Row, Col); end if;
end loop;
end loop;
Max_A_Val := Max_A_Val + Two ** (Real'Machine_Emin + 4);
Scaling := One / Max_A_Val;
Sum := Zero;
for Row in Starting_Row .. Final_Row loop
for Col in Starting_Col .. Final_Col loop
tmp := Scaling * A(Row, Col);
Sum := Sum + tmp * tmp;
end loop;
end loop;
return Sqrt (Sum) * Max_A_Val;
end Frobenius_Norm;
------------------------------------
-- Get_Err_in_Reassembled_Q_and_A --
------------------------------------
-- check that A = V*E*Q_tr
-- E is diagonal with the eigs along the diag.
-- V is orthogonal with the eig vecs as columns.
procedure Get_Err_in_Reassembled_Q_and_A
(A : in Matrix; -- true original A
Q_tr : in Matrix;
E : in Col_Vector;
Final_Col : in Col_Index;
Starting_Col : in Col_Index;
Frobenius_QtrQ_Err : out Real;
Frobenius_QQtr_Err : out Real;
Frobenius_QEQ_Err : out Real)
is
Err, S : Real;
Min_Real : constant Real := +2.0 **(Real'Machine_Emin + 4);
Sum : Real_Extended;
Identity : Matrix := (others => (others => Zero));
Product_QQ : Matrix := (others => (others => Zero));
Product_QEQ : Matrix := (others => (others => Zero));
subtype Index_Subrange is Index range Starting_Col .. Final_Col;
begin
for r in Index_Subrange loop
Identity(r, r) := 1.0;
end loop;
-- Find error in I - Q*Q' etc.
-- Notation: Q' == Q_tr == transpose of Q.
for Col in Index_Subrange loop
for Row in Index_Subrange loop
Sum := +0.0;
for j in Index_Subrange loop
Sum := Sum + Real_Extended (Q_tr(j, Row)) * Real_Extended (Q_tr(j, Col));
end loop;
Product_QQ(Row, Col) := Real (Sum);
end loop;
end loop;
-- Get Frobenius norm of: Product_QQ - I:
S := Zero;
for Col in Index_Subrange loop
for Row in Index_Subrange loop
Err := Identity(Row, Col) - Product_QQ(Row, Col);
S := S + Err * Err;
end loop;
end loop;
-- Get fractional Frobenius : Frobenius (Product_QQ - I) / Frobenius (I):
Frobenius_QQtr_Err := Sqrt(S) / Sqrt (-Real(Starting_Col)+Real(Final_Col)+1.0);
-- Find error in I - Q'*Q.
-- reuse array Product_QQ:
for Col in Index_Subrange loop
for Row in Index_Subrange loop
Sum := +0.0;
for j in Index_Subrange loop
Sum := Sum + Real_Extended (Q_tr(Row, j)) * Real_Extended (Q_tr(Col, j));
end loop;
Product_QQ(Row, Col) := Real (Sum);
end loop;
end loop;
-- Get Frobenius norm of: Product_QQ - I:
S := Zero;
for Col in Index_Subrange loop
for Row in Index_Subrange loop
Err := Identity(Row, Col) - Product_QQ(Row, Col);
S := S + Err * Err;
end loop;
end loop;
-- Get fractional Frobenius : Frobenius (Product_QQ - I) / Frobenius (I):
Frobenius_QtrQ_Err := Sqrt(S) / Sqrt (-Real(Starting_Col)+Real(Final_Col)+1.0);
-- check that A = Q*E*Q_tr
-- E is diagonal with the eigs along the diag.
-- Q is orthogonal with the eig vecs as columns.
-- explicitly calculate Q*E*Q_tr:
for Col in Index_Subrange loop
for Row in Index_Subrange loop
Sum := +0.0;
for j in Index_Subrange loop
Sum := Sum +
Real_Extended (Q_tr(j, Row)) * -- Q(Row, j)
Real_Extended (E(j)) * -- j-th eig is const along Q col
Real_Extended (Q_tr(j, Col));
end loop;
Product_QEQ(Row, Col) := Real (Sum);
end loop;
end loop;
-- resuse array Product_QEQ to get Error Matrix := Product_QEQ - A:
for Col in Starting_Col .. Final_Col loop
for Row in Starting_Row .. Final_Row loop
Product_QEQ(Row, Col) := A(Row, Col) - Product_QEQ(Row, Col);
end loop;
end loop;
Frobenius_QEQ_Err := Frobenius_Norm (Product_QEQ) /
(Frobenius_Norm (A) + Min_Real);
end Get_Err_in_Reassembled_Q_and_A;
-----------
-- Pause --
-----------
procedure Pause (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9 : string := "") is
Continue : Character := ' ';
begin
new_line;
if S0 /= "" then put_line (S0); end if;
if S1 /= "" then put_line (S1); end if;
if S2 /= "" then put_line (S2); end if;
if S3 /= "" then put_line (S3); end if;
if S4 /= "" then put_line (S4); end if;
if S5 /= "" then put_line (S5); end if;
if S6 /= "" then put_line (S6); end if;
if S7 /= "" then put_line (S7); end if;
if S8 /= "" then put_line (S8); end if;
if S9 /= "" then put_line (S9); end if;
new_line;
begin
put ("Type a character to continue: ");
get_immediate (Continue);
exception
when others => null;
end;
end pause;
begin
Pause(
"Test 1: Jacobi Eigendecomposition of matrix A.",
" ",
"The Jacobi Eigendecomposition of A is successful if the identities Q*Q' = I,",
"Q'*Q = I and Q*E*Q' = A are satisfied. Here Q' denotes the transpose of Q, and",
"E is any diagonal matrix. (E will hold the Eigvals.) If 15 digit Reals are used,",
"then we expect the error in the calculation of A = Q*E*Q' to be (hopefully)",
"a few parts per 10**15. In other words ||Q*E*Q' - A|| / ||A|| should be a few",
"multiples of 10**(-15). Here ||*|| denotes the Frobenius Norm. Other matrix",
"norms give slightly different answers, so its an order of magnitude estimate."
);
-- Get A = Q*E*Q_tr, or E = Q_tr*A*Q.
-- E is diagonal with the eigs along the diag.
-- V is orthogonal with the eig vecs as columns.
for Chosen_Matrix in Matrix_Id loop
Init_Matrix (A, Chosen_Matrix, Starting_Col, Final_Col);
-- Usually A is not symmetric. Eigen_Decompose doesn't care about
-- that. It uses the upper triangle of A, and pretends that A is
-- symmetric. But for subsequent analysis, we want it symmetrized:
for c in Starting_Col .. Final_Col loop
for r in Starting_Row .. Final_Row loop
A_true(r, c) := 0.5 * (A(c, r) + A(r, c));
end loop;
end loop;
A := A_true; -- A will be destroyed, so save A_true
Eigen_Decompose
(A => A, -- A is destroyed
Q_tr => Q_tr,
Eigenvals => Eigenvals,
No_of_Sweeps_Performed => No_of_Sweeps_Done,
Total_No_of_Rotations => No_of_Rotations,
Final_Col => Final_Col,
Start_Col => Starting_Col,
Eigenvectors_Desired => True);
Sort_Eigs
(Eigenvals => Eigenvals,
Q_tr => Q_tr,
Start_Col => Starting_Col,
Final_Col => Final_Col,
Sort_Eigvecs_Also => True);
--put(Q_tr(1,1));
if False then
for I in Starting_Col .. Final_Col loop
put(Eigenvals(I));
end loop;
new_line(2);
end if;
new_line;
put("For matrix A of type "); put(Matrix_id'Image(Chosen_Matrix));
Get_Err_in_Reassembled_Q_and_A
(A => A_True,
Q_tr => Q_tr,
E => Eigenvals,
Final_Col => Final_Col,
Starting_Col => Starting_Col,
Frobenius_QtrQ_Err => Frobenius_QtrQ_Err,
Frobenius_QQtr_Err => Frobenius_QQtr_Err,
Frobenius_QEQ_Err => Frobenius_QEQ_Err);
-- Froebenius norm fractional error:
-- Max_Error_F = ||Err_Matrix|| / ||A||
new_line;
put(" No of sweeps performed, and Total_No_of_Rotations / (N*(N-1)/2) =");
new_line;
put(Real (No_of_Sweeps_Done));
put(Real (No_of_Rotations) / (N*(N-1.0)/2.0));
new_line;
put(" Err in I-Q*Q' (Q = orthogonal) is ||I-Q*Q'|| / ||I|| =");
put(Frobenius_QQtr_Err);
new_line;
put(" Err in I-Q'*Q (Q = orthogonal) is ||I-Q'*Q|| / ||I|| =");
put(Frobenius_QtrQ_Err);
new_line;
put(" Err in A-Q*E*Q' (E = eigenvals) is ||A-Q*E*Q'|| / ||A|| =");
put(Frobenius_QEQ_Err);
new_line;
--Pause; new_line;
end loop;
end jacobi_eigen_tst_1;
|
pragma License (Unrestricted);
-- implementation unit required by compiler
with Interfaces;
package System.Arith_64 is
pragma Pure;
-- implementation for multiplication with Overflow_Check (arit64.c)
function Multiply (X, Y : Interfaces.Integer_64)
return Interfaces.Integer_64
with Export, Convention => C, External_Name => "__gnat_mulv64";
-- required for fixed-decimal (X * Y) / Z by compiler (s-arit64.ads)
procedure Scaled_Divide (
X, Y, Z : Interfaces.Integer_64; -- X * Y / Z
Q, R : out Interfaces.Integer_64;
Round : Boolean);
-- required for fixed-decimal X / (Y * Z) by compiler (s-arit64.ads)
procedure Double_Divide (
X, Y, Z : Interfaces.Integer_64;
Q, R : out Interfaces.Integer_64;
Round : Boolean);
-- required if Long_Long_Integer'Size > 64 (s-arit64.ads)
-- function Add_With_Ovflo_Check (X, Y : Interfaces.Integer_64)
-- return Interfaces.Integer_64;
-- function Subtract_With_Ovflo_Check (X, Y : Interfaces.Integer_64)
-- return Interfaces.Integer_64;
-- function Multiply_With_Ovflo_Check (X, Y : Interfaces.Integer_64)
-- return Interfaces.Integer_64;
end System.Arith_64;
|
-- ////////////////////////////////////////////////////////////
-- //
-- // SFML - Simple and Fast Multimedia Library
-- // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
-- //
-- // This software is provided 'as-is', without any express or implied warranty.
-- // In no event will the authors be held liable for any damages arising from the use of this software.
-- //
-- // Permission is granted to anyone to use this software for any purpose,
-- // including commercial applications, and to alter it and redistribute it freely,
-- // subject to the following restrictions:
-- //
-- // 1. The origin of this software must not be misrepresented;
-- // you must not claim that you wrote the original software.
-- // If you use this software in a product, an acknowledgment
-- // in the product documentation would be appreciated but is not required.
-- //
-- // 2. Altered source versions must be plainly marked as such,
-- // and must not be misrepresented as being the original software.
-- //
-- // 3. This notice may not be removed or altered from any source distribution.
-- //
-- ////////////////////////////////////////////////////////////
-- ////////////////////////////////////////////////////////////
-- // Headers
-- ////////////////////////////////////////////////////////////
with Sf.Config;
with Sf.Network.Types;
package Sf.Network.Packet is
use Sf.Config;
use Sf.Network.Types;
-- ////////////////////////////////////////////////////////////
-- /// Create a new empty packet
-- ///
-- /// \return A new sfPacket object
-- ///
-- ////////////////////////////////////////////////////////////
function sfPacket_Create return sfPacket_Ptr;
-- ////////////////////////////////////////////////////////////
-- /// Destroy an existing packet
-- ///
-- /// \param Packet : Packet to delete
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfPacket_Destroy (Packet : sfPacket_Ptr);
-- ////////////////////////////////////////////////////////////
-- /// Append data to the end of a packet
-- ///
-- /// \param Packet : Packet to fill
-- /// \param Data : Pointer to the bytes to append
-- /// \param SizeInBytes : Number of bytes to append
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfPacket_Append (Packet : sfPacket_Ptr; Data : sfVoid_Ptr; SizeInBytes : sfSize_t);
-- ////////////////////////////////////////////////////////////
-- /// Clear all the data of a packet
-- ///
-- /// \param Packet : Packet to clear
-- ///
-- ///////////////////////////////////////////////////////////
procedure sfPacket_Clear (Packet : sfPacket_Ptr);
-- ////////////////////////////////////////////////////////////
-- /// Get a pointer to the data contained in a packet
-- /// Warning : the returned pointer may be invalid after you
-- /// append data to the packet
-- ///
-- /// \param Packet : Packet to get data from
-- ///
-- /// \return Pointer to the data
-- ///
-- ////////////////////////////////////////////////////////////
function sfPacket_GetData (Packet : sfPacket_Ptr) return sfInt8_Ptr;
-- ////////////////////////////////////////////////////////////
-- /// Get the size of the data contained in a packet
-- ///
-- /// \param Packet : Packet to get data size from
-- ///
-- /// \return Data size, in bytes
-- ///
-- ////////////////////////////////////////////////////////////
function sfPacket_GetDataSize (Packet : sfPacket_Ptr) return sfSize_t;
-- ////////////////////////////////////////////////////////////
-- /// Tell if the reading position has reached the end of the packet
-- ///
-- /// \param Packet : Packet to check
-- ///
-- /// \return sfTrue if all data have been read into the packet
-- ///
-- ////////////////////////////////////////////////////////////
function sfPacket_EndOfPacket (Packet : sfPacket_Ptr) return sfBool;
-- ////////////////////////////////////////////////////////////
-- /// Return the validity of packet
-- ///
-- /// \param Packet : Packet to check
-- ///
-- /// \return sfTrue if last data extraction from packet was successful
-- ///
-- ////////////////////////////////////////////////////////////
function sfPacket_CanRead (Packet : sfPacket_Ptr) return sfBool;
-- ////////////////////////////////////////////////////////////
-- /// Functions to extract data from a packet
-- ///
-- /// \param Packet : Packet to read
-- ///
-- ////////////////////////////////////////////////////////////
function sfPacket_ReadBool (Packet : sfPacket_Ptr) return sfBool;
function sfPacket_ReadInt8 (Packet : sfPacket_Ptr) return sfInt8;
function sfPacket_ReadUint8 (Packet : sfPacket_Ptr) return sfUint8;
function sfPacket_ReadInt16 (Packet : sfPacket_Ptr) return sfInt16;
function sfPacket_ReadUint16 (Packet : sfPacket_Ptr) return sfUint16;
function sfPacket_ReadInt32 (Packet : sfPacket_Ptr) return sfInt32;
function sfPacket_ReadUint32 (Packet : sfPacket_Ptr) return sfUint32;
function sfPacket_ReadFloat (Packet : sfPacket_Ptr) return Float;
function sfPacket_ReadDouble (Packet : sfPacket_Ptr) return Long_Float;
procedure sfPacket_ReadString (Packet : sfPacket_Ptr; Str : out String);
procedure sfPacket_ReadWideString (Packet : sfPacket_Ptr; Str : sfUint32_Ptr);
-- ////////////////////////////////////////////////////////////
-- /// Functions to insert data into a packet
-- ///
-- /// \param Packet : Packet to write
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfPacket_WriteBool (Packet : sfPacket_Ptr; arg2 : sfBool);
procedure sfPacket_WriteInt8 (Packet : sfPacket_Ptr; arg2 : sfInt8);
procedure sfPacket_WriteUint8 (Packet : sfPacket_Ptr; arg2 : sfUint8);
procedure sfPacket_WriteInt16 (Packet : sfPacket_Ptr; arg2 : sfInt16);
procedure sfPacket_WriteUint16 (Packet : sfPacket_Ptr; arg2 : sfUint16);
procedure sfPacket_WriteInt32 (Packet : sfPacket_Ptr; arg2 : sfInt32);
procedure sfPacket_WriteUint32 (Packet : sfPacket_Ptr; arg2 : sfUint32);
procedure sfPacket_WriteFloat (Packet : sfPacket_Ptr; arg2 : Float);
procedure sfPacket_WriteDouble (Packet : sfPacket_Ptr; arg2 : Long_Float);
procedure sfPacket_WriteString (Packet : sfPacket_Ptr; Str : String);
procedure sfPacket_WriteWideString (Packet : sfPacket_Ptr; Str : sfUint32_Ptr);
private
pragma Import (C, sfPacket_Create, "sfPacket_Create");
pragma Import (C, sfPacket_Destroy, "sfPacket_Destroy");
pragma Import (C, sfPacket_Append, "sfPacket_Append");
pragma Import (C, sfPacket_Clear, "sfPacket_Clear");
pragma Import (C, sfPacket_GetData, "sfPacket_GetData");
pragma Import (C, sfPacket_GetDataSize, "sfPacket_GetDataSize");
pragma Import (C, sfPacket_EndOfPacket, "sfPacket_EndOfPacket");
pragma Import (C, sfPacket_CanRead, "sfPacket_CanRead");
pragma Import (C, sfPacket_ReadBool, "sfPacket_ReadBool");
pragma Import (C, sfPacket_ReadInt8, "sfPacket_ReadInt8");
pragma Import (C, sfPacket_ReadUint8, "sfPacket_ReadUint8");
pragma Import (C, sfPacket_ReadInt16, "sfPacket_ReadInt16");
pragma Import (C, sfPacket_ReadUint16, "sfPacket_ReadUint16");
pragma Import (C, sfPacket_ReadInt32, "sfPacket_ReadInt32");
pragma Import (C, sfPacket_ReadUint32, "sfPacket_ReadUint32");
pragma Import (C, sfPacket_ReadFloat, "sfPacket_ReadFloat");
pragma Import (C, sfPacket_ReadDouble, "sfPacket_ReadDouble");
pragma Import (C, sfPacket_ReadWideString, "sfPacket_ReadWideString");
pragma Import (C, sfPacket_WriteBool, "sfPacket_WriteBool");
pragma Import (C, sfPacket_WriteInt8, "sfPacket_WriteInt8");
pragma Import (C, sfPacket_WriteUint8, "sfPacket_WriteUint8");
pragma Import (C, sfPacket_WriteInt16, "sfPacket_WriteInt16");
pragma Import (C, sfPacket_WriteUint16, "sfPacket_WriteUint16");
pragma Import (C, sfPacket_WriteInt32, "sfPacket_WriteInt32");
pragma Import (C, sfPacket_WriteUint32, "sfPacket_WriteUint32");
pragma Import (C, sfPacket_WriteFloat, "sfPacket_WriteFloat");
pragma Import (C, sfPacket_WriteDouble, "sfPacket_WriteDouble");
pragma Import (C, sfPacket_WriteWideString, "sfPacket_WriteWideString");
end Sf.Network.Packet;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . S E Q U E N T I A L _ I O --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
-- apply solely to the contents of the part following the private keyword. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.IO_Exceptions;
with System.Sequential_IO;
generic
type Element_Type (<>) is private;
package Ada.Sequential_IO is
pragma Compile_Time_Warning
(Element_Type'Has_Access_Values,
"Element_Type for Sequential_IO instance has access values");
pragma Compile_Time_Warning
(Element_Type'Has_Tagged_Values,
"Element_Type for Sequential_IO instance has tagged values");
type File_Type is limited private with Default_Initial_Condition;
type File_Mode is (In_File, Out_File, Append_File);
-- The following representation clause allows the use of unchecked
-- conversion for rapid translation between the File_Mode type
-- used in this package and System.File_IO.
for File_Mode use
(In_File => 0, -- System.File_IO.File_Mode'Pos (In_File)
Out_File => 2, -- System.File_IO.File_Mode'Pos (Out_File)
Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
---------------------
-- File management --
---------------------
procedure Create
(File : in out File_Type;
Mode : File_Mode := Out_File;
Name : String := "";
Form : String := "");
procedure Open
(File : in out File_Type;
Mode : File_Mode;
Name : String;
Form : String := "");
procedure Close (File : in out File_Type);
procedure Delete (File : in out File_Type);
procedure Reset (File : in out File_Type; Mode : File_Mode);
procedure Reset (File : in out File_Type);
function Mode (File : File_Type) return File_Mode;
function Name (File : File_Type) return String;
function Form (File : File_Type) return String;
function Is_Open (File : File_Type) return Boolean;
procedure Flush (File : File_Type);
---------------------------------
-- Input and output operations --
---------------------------------
procedure Read (File : File_Type; Item : out Element_Type);
procedure Write (File : File_Type; Item : Element_Type);
function End_Of_File (File : File_Type) return Boolean;
----------------
-- 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
-- The following procedures have a File_Type formal of mode IN OUT because
-- they may close the original file. The Close operation may raise an
-- exception, but in that case we want any assignment to the formal to
-- be effective anyway, so it must be passed by reference (or the caller
-- will be left with a dangling pointer).
pragma Export_Procedure
(Internal => Close,
External => "",
Mechanism => Reference);
pragma Export_Procedure
(Internal => Delete,
External => "",
Mechanism => Reference);
pragma Export_Procedure
(Internal => Reset,
External => "",
Parameter_Types => (File_Type),
Mechanism => Reference);
pragma Export_Procedure
(Internal => Reset,
External => "",
Parameter_Types => (File_Type, File_Mode),
Mechanism => (File => Reference));
type File_Type is new System.Sequential_IO.File_Type;
-- All subprograms are inlined
pragma Inline (Close);
pragma Inline (Create);
pragma Inline (Delete);
pragma Inline (End_Of_File);
pragma Inline (Form);
pragma Inline (Is_Open);
pragma Inline (Mode);
pragma Inline (Name);
pragma Inline (Open);
pragma Inline (Read);
pragma Inline (Reset);
pragma Inline (Write);
end Ada.Sequential_IO;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_a is
procedure R(N: Integer) is
begin
if N = 0 then return; end if;
Put('a');
R(N - 1);
end;
begin
R(42);
New_Line;
end TEST_a;
|
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Program.Elements.Definitions;
package Program.Elements.Formal_Type_Definitions is
pragma Pure (Program.Elements.Formal_Type_Definitions);
type Formal_Type_Definition is
limited interface and Program.Elements.Definitions.Definition;
type Formal_Type_Definition_Access is
access all Formal_Type_Definition'Class with Storage_Size => 0;
end Program.Elements.Formal_Type_Definitions;
|
package Benchmark.Matrix.LU is
type LU_Type is new Matrix_Type with private;
function Create_LU return Benchmark_Pointer;
overriding
procedure Run(benchmark : in LU_Type);
private
type LU_Type is new Matrix_Type with null record;
end Benchmark.Matrix.LU;
|
-- Copyright (c) 2014 onox <denkpadje@gmail.com>
--
-- 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 Interfaces.C.Strings;
package body Opus is
function Get_Version return String is
function Opus_Get_Version_String return Interfaces.C.Strings.chars_ptr
with Import, Convention => C, External_Name => "opus_get_version_string";
begin
return Interfaces.C.Strings.Value (Opus_Get_Version_String);
end Get_Version;
procedure Check_Error (Error : in Interfaces.C.int) is
begin
case Error is
when -1 => raise Bad_Argument;
when -2 => raise Buffer_Too_Small;
when -3 => raise Internal_Error;
when -4 => raise Invalid_Packet;
when -5 => raise Unimplemented;
when -6 => raise Invalid_State;
when -7 => raise Allocation_Fail;
when others => null;
end case;
end Check_Error;
end Opus;
|
package body Pack22_Pkg is
package body Bit_Map_Generic is
function "xor" (L, R : List) return List is
Temp : List;
for Temp'address use Temp_buffer'address;
begin
Temp.Bits := L.Bits xor R.Bits;
Temp.Counter.Counter := 0;
return Temp;
end;
end Bit_Map_Generic;
end Pack22_Pkg;
|
package Opt23_Pkg is
function N return Positive;
pragma Import (Ada, N);
type Path is array(1 .. N) of Long_Float;
type Path_Vector is array (Positive range <>) of Path;
type Path_Vector_P is access all Path_Vector;
type Path_Vector_PV is array(Positive range <>) of Path_Vector_P;
type Path_Vector_P2 is access all Path_Vector_PV;
type Vector is array (Positive range <>) of Natural;
type Vector_Access is access Vector;
type Rec is record
Val : Path_Vector_P2;
Step : Vector_Access;
end record;
function Get (R : Rec; I : Positive; M : Natural) return Path;
pragma Inline (Get);
end Opt23_Pkg;
|
-- This spec has been automatically generated from msp430g2553.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with System;
-- USCI_A0 UART Mode
package MSP430_SVD.USCI_A0_UART_MODE is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- UCA0ABCTL_UCDELIM array
type UCA0ABCTL_UCDELIM_Field_Array is array (0 .. 1) of MSP430_SVD.Bit
with Component_Size => 1, Size => 2;
-- Type definition for UCA0ABCTL_UCDELIM
type UCA0ABCTL_UCDELIM_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- UCDELIM as a value
Val : MSP430_SVD.UInt2;
when True =>
-- UCDELIM as an array
Arr : UCA0ABCTL_UCDELIM_Field_Array;
end case;
end record
with Unchecked_Union, Size => 2;
for UCA0ABCTL_UCDELIM_Field use record
Val at 0 range 0 .. 1;
Arr at 0 range 0 .. 1;
end record;
-- USCI A0 LIN Control
type UCA0ABCTL_Register is record
-- Auto Baud Rate detect enable
UCABDEN : MSP430_SVD.Bit := 16#0#;
-- unspecified
Reserved_1_1 : MSP430_SVD.Bit := 16#0#;
-- Break Timeout error
UCBTOE : MSP430_SVD.Bit := 16#0#;
-- Sync-Field Timeout error
UCSTOE : MSP430_SVD.Bit := 16#0#;
-- Break Sync Delimiter 0
UCDELIM : UCA0ABCTL_UCDELIM_Field :=
(As_Array => False, Val => 16#0#);
-- unspecified
Reserved_6_7 : MSP430_SVD.UInt2 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for UCA0ABCTL_Register use record
UCABDEN at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
UCBTOE at 0 range 2 .. 2;
UCSTOE at 0 range 3 .. 3;
UCDELIM at 0 range 4 .. 5;
Reserved_6_7 at 0 range 6 .. 7;
end record;
-- UCA0IRTCTL_UCIRTXPL array
type UCA0IRTCTL_UCIRTXPL_Field_Array is array (0 .. 5) of MSP430_SVD.Bit
with Component_Size => 1, Size => 6;
-- Type definition for UCA0IRTCTL_UCIRTXPL
type UCA0IRTCTL_UCIRTXPL_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- UCIRTXPL as a value
Val : MSP430_SVD.UInt6;
when True =>
-- UCIRTXPL as an array
Arr : UCA0IRTCTL_UCIRTXPL_Field_Array;
end case;
end record
with Unchecked_Union, Size => 6;
for UCA0IRTCTL_UCIRTXPL_Field use record
Val at 0 range 0 .. 5;
Arr at 0 range 0 .. 5;
end record;
-- USCI A0 IrDA Transmit Control
type UCA0IRTCTL_Register is record
-- IRDA Encoder/Decoder enable
UCIREN : MSP430_SVD.Bit := 16#0#;
-- IRDA Transmit Pulse Clock Select
UCIRTXCLK : MSP430_SVD.Bit := 16#0#;
-- IRDA Transmit Pulse Length 0
UCIRTXPL : UCA0IRTCTL_UCIRTXPL_Field :=
(As_Array => False, Val => 16#0#);
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for UCA0IRTCTL_Register use record
UCIREN at 0 range 0 .. 0;
UCIRTXCLK at 0 range 1 .. 1;
UCIRTXPL at 0 range 2 .. 7;
end record;
-- UCA0IRRCTL_UCIRRXFL array
type UCA0IRRCTL_UCIRRXFL_Field_Array is array (0 .. 5) of MSP430_SVD.Bit
with Component_Size => 1, Size => 6;
-- Type definition for UCA0IRRCTL_UCIRRXFL
type UCA0IRRCTL_UCIRRXFL_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- UCIRRXFL as a value
Val : MSP430_SVD.UInt6;
when True =>
-- UCIRRXFL as an array
Arr : UCA0IRRCTL_UCIRRXFL_Field_Array;
end case;
end record
with Unchecked_Union, Size => 6;
for UCA0IRRCTL_UCIRRXFL_Field use record
Val at 0 range 0 .. 5;
Arr at 0 range 0 .. 5;
end record;
-- USCI A0 IrDA Receive Control
type UCA0IRRCTL_Register is record
-- IRDA Receive Filter enable
UCIRRXFE : MSP430_SVD.Bit := 16#0#;
-- IRDA Receive Input Polarity
UCIRRXPL : MSP430_SVD.Bit := 16#0#;
-- IRDA Receive Filter Length 0
UCIRRXFL : UCA0IRRCTL_UCIRRXFL_Field :=
(As_Array => False, Val => 16#0#);
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for UCA0IRRCTL_Register use record
UCIRRXFE at 0 range 0 .. 0;
UCIRRXPL at 0 range 1 .. 1;
UCIRRXFL at 0 range 2 .. 7;
end record;
-- Async. Mode: USCI Mode 1
type UCA0CTL0_UCMODE_Field is
(-- Sync. Mode: USCI Mode: 0
Ucmode_0,
-- Sync. Mode: USCI Mode: 1
Ucmode_1,
-- Sync. Mode: USCI Mode: 2
Ucmode_2,
-- Sync. Mode: USCI Mode: 3
Ucmode_3)
with Size => 2;
for UCA0CTL0_UCMODE_Field use
(Ucmode_0 => 0,
Ucmode_1 => 1,
Ucmode_2 => 2,
Ucmode_3 => 3);
-- USCI A0 Control Register 0
type UCA0CTL0_Register is record
-- Sync-Mode 0:UART-Mode / 1:SPI-Mode
UCSYNC : MSP430_SVD.Bit := 16#0#;
-- Async. Mode: USCI Mode 1
UCMODE : UCA0CTL0_UCMODE_Field := MSP430_SVD.USCI_A0_UART_MODE.Ucmode_0;
-- Async. Mode: Stop Bits 0:one / 1: two
UCSPB : MSP430_SVD.Bit := 16#0#;
-- Async. Mode: Data Bits 0:8-bits / 1:7-bits
UC7BIT : MSP430_SVD.Bit := 16#0#;
-- Async. Mode: MSB first 0:LSB / 1:MSB
UCMSB : MSP430_SVD.Bit := 16#0#;
-- Async. Mode: Parity 0:odd / 1:even
UCPAR : MSP430_SVD.Bit := 16#0#;
-- Async. Mode: Parity enable
UCPEN : MSP430_SVD.Bit := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for UCA0CTL0_Register use record
UCSYNC at 0 range 0 .. 0;
UCMODE at 0 range 1 .. 2;
UCSPB at 0 range 3 .. 3;
UC7BIT at 0 range 4 .. 4;
UCMSB at 0 range 5 .. 5;
UCPAR at 0 range 6 .. 6;
UCPEN at 0 range 7 .. 7;
end record;
-- USCI 0 Clock Source Select 1
type UCA0CTL1_UCSSEL_Field is
(-- USCI 0 Clock Source: 0
Ucssel_0,
-- USCI 0 Clock Source: 1
Ucssel_1,
-- USCI 0 Clock Source: 2
Ucssel_2,
-- USCI 0 Clock Source: 3
Ucssel_3)
with Size => 2;
for UCA0CTL1_UCSSEL_Field use
(Ucssel_0 => 0,
Ucssel_1 => 1,
Ucssel_2 => 2,
Ucssel_3 => 3);
-- USCI A0 Control Register 1
type UCA0CTL1_Register is record
-- USCI Software Reset
UCSWRST : MSP430_SVD.Bit := 16#0#;
-- Send next Data as Break
UCTXBRK : MSP430_SVD.Bit := 16#0#;
-- Send next Data as Address
UCTXADDR : MSP430_SVD.Bit := 16#0#;
-- Dormant (Sleep) Mode
UCDORM : MSP430_SVD.Bit := 16#0#;
-- Break interrupt enable
UCBRKIE : MSP430_SVD.Bit := 16#0#;
-- RX Error interrupt enable
UCRXEIE : MSP430_SVD.Bit := 16#0#;
-- USCI 0 Clock Source Select 1
UCSSEL : UCA0CTL1_UCSSEL_Field :=
MSP430_SVD.USCI_A0_UART_MODE.Ucssel_0;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for UCA0CTL1_Register use record
UCSWRST at 0 range 0 .. 0;
UCTXBRK at 0 range 1 .. 1;
UCTXADDR at 0 range 2 .. 2;
UCDORM at 0 range 3 .. 3;
UCBRKIE at 0 range 4 .. 4;
UCRXEIE at 0 range 5 .. 5;
UCSSEL at 0 range 6 .. 7;
end record;
-- USCI Second Stage Modulation Select 2
type UCA0MCTL_UCBRS_Field is
(-- USCI Second Stage Modulation: 0
Ucbrs_0,
-- USCI Second Stage Modulation: 1
Ucbrs_1,
-- USCI Second Stage Modulation: 2
Ucbrs_2,
-- USCI Second Stage Modulation: 3
Ucbrs_3,
-- USCI Second Stage Modulation: 4
Ucbrs_4,
-- USCI Second Stage Modulation: 5
Ucbrs_5,
-- USCI Second Stage Modulation: 6
Ucbrs_6,
-- USCI Second Stage Modulation: 7
Ucbrs_7)
with Size => 3;
for UCA0MCTL_UCBRS_Field use
(Ucbrs_0 => 0,
Ucbrs_1 => 1,
Ucbrs_2 => 2,
Ucbrs_3 => 3,
Ucbrs_4 => 4,
Ucbrs_5 => 5,
Ucbrs_6 => 6,
Ucbrs_7 => 7);
-- USCI First Stage Modulation Select 3
type UCA0MCTL_UCBRF_Field is
(-- USCI First Stage Modulation: 0
Ucbrf_0,
-- USCI First Stage Modulation: 1
Ucbrf_1,
-- USCI First Stage Modulation: 2
Ucbrf_2,
-- USCI First Stage Modulation: 3
Ucbrf_3,
-- USCI First Stage Modulation: 4
Ucbrf_4,
-- USCI First Stage Modulation: 5
Ucbrf_5,
-- USCI First Stage Modulation: 6
Ucbrf_6,
-- USCI First Stage Modulation: 7
Ucbrf_7,
-- USCI First Stage Modulation: 8
Ucbrf_8,
-- USCI First Stage Modulation: 9
Ucbrf_9,
-- USCI First Stage Modulation: A
Ucbrf_10,
-- USCI First Stage Modulation: B
Ucbrf_11,
-- USCI First Stage Modulation: C
Ucbrf_12,
-- USCI First Stage Modulation: D
Ucbrf_13,
-- USCI First Stage Modulation: E
Ucbrf_14,
-- USCI First Stage Modulation: F
Ucbrf_15)
with Size => 4;
for UCA0MCTL_UCBRF_Field use
(Ucbrf_0 => 0,
Ucbrf_1 => 1,
Ucbrf_2 => 2,
Ucbrf_3 => 3,
Ucbrf_4 => 4,
Ucbrf_5 => 5,
Ucbrf_6 => 6,
Ucbrf_7 => 7,
Ucbrf_8 => 8,
Ucbrf_9 => 9,
Ucbrf_10 => 10,
Ucbrf_11 => 11,
Ucbrf_12 => 12,
Ucbrf_13 => 13,
Ucbrf_14 => 14,
Ucbrf_15 => 15);
-- USCI A0 Modulation Control
type UCA0MCTL_Register is record
-- USCI 16-times Oversampling enable
UCOS16 : MSP430_SVD.Bit := 16#0#;
-- USCI Second Stage Modulation Select 2
UCBRS : UCA0MCTL_UCBRS_Field := MSP430_SVD.USCI_A0_UART_MODE.Ucbrs_0;
-- USCI First Stage Modulation Select 3
UCBRF : UCA0MCTL_UCBRF_Field := MSP430_SVD.USCI_A0_UART_MODE.Ucbrf_0;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for UCA0MCTL_Register use record
UCOS16 at 0 range 0 .. 0;
UCBRS at 0 range 1 .. 3;
UCBRF at 0 range 4 .. 7;
end record;
-- USCI A0 Status Register
type UCA0STAT_Register is record
-- USCI Busy Flag
UCBUSY : MSP430_SVD.Bit := 16#0#;
-- USCI Address received Flag
UCADDR : MSP430_SVD.Bit := 16#0#;
-- USCI RX Error Flag
UCRXERR : MSP430_SVD.Bit := 16#0#;
-- USCI Break received
UCBRK : MSP430_SVD.Bit := 16#0#;
-- USCI Parity Error Flag
UCPE : MSP430_SVD.Bit := 16#0#;
-- USCI Overrun Error Flag
UCOE : MSP430_SVD.Bit := 16#0#;
-- USCI Frame Error Flag
UCFE : MSP430_SVD.Bit := 16#0#;
-- USCI Listen mode
UCLISTEN : MSP430_SVD.Bit := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for UCA0STAT_Register use record
UCBUSY at 0 range 0 .. 0;
UCADDR at 0 range 1 .. 1;
UCRXERR at 0 range 2 .. 2;
UCBRK at 0 range 3 .. 3;
UCPE at 0 range 4 .. 4;
UCOE at 0 range 5 .. 5;
UCFE at 0 range 6 .. 6;
UCLISTEN at 0 range 7 .. 7;
end record;
-----------------
-- Peripherals --
-----------------
-- USCI_A0 UART Mode
type USCI_A0_UART_MODE_Peripheral is record
-- USCI A0 LIN Control
UCA0ABCTL : aliased UCA0ABCTL_Register;
-- USCI A0 IrDA Transmit Control
UCA0IRTCTL : aliased UCA0IRTCTL_Register;
-- USCI A0 IrDA Receive Control
UCA0IRRCTL : aliased UCA0IRRCTL_Register;
-- USCI A0 Control Register 0
UCA0CTL0 : aliased UCA0CTL0_Register;
-- USCI A0 Control Register 1
UCA0CTL1 : aliased UCA0CTL1_Register;
-- USCI A0 Baud Rate 0
UCA0BR0 : aliased MSP430_SVD.Byte;
-- USCI A0 Baud Rate 1
UCA0BR1 : aliased MSP430_SVD.Byte;
-- USCI A0 Modulation Control
UCA0MCTL : aliased UCA0MCTL_Register;
-- USCI A0 Status Register
UCA0STAT : aliased UCA0STAT_Register;
-- USCI A0 Receive Buffer
UCA0RXBUF : aliased MSP430_SVD.Byte;
-- USCI A0 Transmit Buffer
UCA0TXBUF : aliased MSP430_SVD.Byte;
end record
with Volatile;
for USCI_A0_UART_MODE_Peripheral use record
UCA0ABCTL at 16#1# range 0 .. 7;
UCA0IRTCTL at 16#2# range 0 .. 7;
UCA0IRRCTL at 16#3# range 0 .. 7;
UCA0CTL0 at 16#4# range 0 .. 7;
UCA0CTL1 at 16#5# range 0 .. 7;
UCA0BR0 at 16#6# range 0 .. 7;
UCA0BR1 at 16#7# range 0 .. 7;
UCA0MCTL at 16#8# range 0 .. 7;
UCA0STAT at 16#9# range 0 .. 7;
UCA0RXBUF at 16#A# range 0 .. 7;
UCA0TXBUF at 16#B# range 0 .. 7;
end record;
-- USCI_A0 UART Mode
USCI_A0_UART_MODE_Periph : aliased USCI_A0_UART_MODE_Peripheral
with Import, Address => USCI_A0_UART_MODE_Base;
end MSP430_SVD.USCI_A0_UART_MODE;
|
with Units.Vectors; use Units.Vectors;
with Units; use Units;
package Dynamics3D is
-- Rotation Systems
type Tait_Bryan_Angle_Type is (ROLL, PITCH, YAW);
type Euler_Angle_Type is (X1, Z2, X3);
subtype Wind_Speed is
Units.Linear_Velocity_Type range 0.0 .. 50.0; -- 180 km/h
--
--
-- type Pose_Type is record
-- position : GPS_Loacation_Type;
-- -- velocity :
-- orientation : Orientation_Vector;
-- end record;
--
--
-- type Shape_Type is (SPHERE, BOX);
--
--
-- procedure transform( pose : Pose_Type; transformation : Transformation_Vector) is null;
-- function Orientation (gravity_vector : Linear_Acceleration_Vector) return Orientation_Vector is null;
end Dynamics3D;
|
--
-- 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 system.machine_code;
with m4.systick;
with soc.interrupts; use soc.interrupts;
with ewok.debug;
with ewok.tasks; use ewok.tasks;
with ewok.tasks.debug;
with ewok.sched;
with ewok.tasks_shared; use ewok.tasks_shared;
with ewok.devices_shared; use type ewok.devices_shared.t_device_id;
with ewok.isr;
package body ewok.interrupts.handler
with spark_mode => off
is
function busfault_handler
(frame_a : ewok.t_stack_frame_access) return ewok.t_stack_frame_access
is
begin
pragma DEBUG (ewok.tasks.debug.crashdump (frame_a));
debug.panic ("Bus fault!");
return frame_a;
end busfault_handler;
function usagefault_handler
(frame_a : ewok.t_stack_frame_access) return ewok.t_stack_frame_access
is
begin
pragma DEBUG (ewok.tasks.debug.crashdump (frame_a));
debug.panic ("Usage fault!");
return frame_a;
end usagefault_handler;
function hardfault_handler
(frame_a : ewok.t_stack_frame_access) return ewok.t_stack_frame_access
is
begin
pragma DEBUG (ewok.tasks.debug.crashdump (frame_a));
debug.panic ("Hard fault!");
return frame_a;
end hardfault_handler;
function systick_default_handler
(frame_a : ewok.t_stack_frame_access)
return ewok.t_stack_frame_access
is
begin
m4.systick.increment;
return frame_a;
end systick_default_handler;
function default_sub_handler
(frame_a : t_stack_frame_access)
return t_stack_frame_access
is
it : t_interrupt;
new_frame_a : t_stack_frame_access;
ttype : t_task_type;
begin
it := soc.interrupts.get_interrupt;
--
-- Exceptions and interrupts (not nested)
--
if frame_a.all.exc_return = 16#FFFF_FFFD# then
-- System exceptions
if it < INT_WWDG then
if interrupt_table(it).task_id = ewok.tasks_shared.ID_KERNEL then
new_frame_a := interrupt_table(it).task_switch_handler (frame_a);
else
debug.panic ("Unhandled exception " & t_interrupt'image (it));
end if;
else
-- External interrupts
-- Execute kernel ISR
if interrupt_table(it).task_id = ewok.tasks_shared.ID_KERNEL then
interrupt_table(it).handler (frame_a);
new_frame_a := frame_a;
-- User ISR are postponed (asynchronous execution)
elsif interrupt_table(it).task_id /= ewok.tasks_shared.ID_UNUSED then
ewok.isr.postpone_isr
(it,
interrupt_table(it).handler,
interrupt_table(it).task_id);
new_frame_a := ewok.sched.do_schedule (frame_a);
else
pragma DEBUG (debug.log (debug.ALERT,
"Unhandled interrupt " & t_interrupt'image (it)));
end if;
end if;
-- Task's execution mode must be transmitted to the Default_Handler
-- to run it with the proper privilege (set in the CONTROL register).
-- The current function uses R0 and R1 registers to return the
-- following values:
-- R0 - address of the task frame
-- R1 - execution mode
if ewok.sched.current_task_id /= ID_UNUSED then
ttype := ewok.tasks.tasks_list(ewok.sched.current_task_id).ttype;
else
ttype := TASK_TYPE_KERNEL;
end if;
system.machine_code.asm
("mov r1, %0",
inputs => t_task_type'asm_input ("r", ttype),
clobber => "r1",
volatile => true);
return new_frame_a;
--
-- Nested exceptions
--
elsif frame_a.all.exc_return = 16#FFFF_FFF1# then
-- System exceptions
if it < INT_WWDG then
case it is
when INT_PENDSV => debug.panic ("Nested PendSV not handled.");
when INT_SYSTICK => null;
when others =>
if interrupt_table(it).task_id = ewok.tasks_shared.ID_KERNEL then
new_frame_a :=
interrupt_table(it).task_switch_handler (frame_a);
else
debug.panic
("Unhandled exception " & t_interrupt'image (it));
end if;
end case;
else
-- External interrupts
-- Execute kernel ISR
if interrupt_table(it).task_id = ewok.tasks_shared.ID_KERNEL then
interrupt_table(it).handler (frame_a);
-- User ISR are postponed (asynchronous execution)
elsif interrupt_table(it).task_id /= ewok.tasks_shared.ID_UNUSED then
ewok.isr.postpone_isr
(it,
interrupt_table(it).handler,
interrupt_table(it).task_id);
else
pragma DEBUG (debug.log (debug.ALERT,
"Unhandled interrupt " & t_interrupt'image (it)));
end if;
end if;
return frame_a;
-- Privileged exceptions should never happen because threads never
-- use the main stack (MSP) but the process stack (PSP).
elsif frame_a.all.exc_return = 16#FFFF_FFF9# then
debug.panic ("Privileged exception " & t_interrupt'image (it));
raise program_error;
-- Unsupported EXC_RETURN
else
debug.panic ("EXC_RETURN not supported");
raise program_error;
end if;
end default_sub_handler;
end ewok.interrupts.handler;
|
with GESTE;
with GESTE.Maths_Types;
with GESTE_Config;
pragma Style_Checks (Off);
package Game_Assets is
Palette : aliased GESTE.Palette_Type := (
0 => 391,
1 => 59147,
2 => 22089,
3 => 58727,
4 => 52303,
5 => 4907,
6 => 41834,
7 => 39694,
8 => 16847,
9 => 35372,
10 => 17208,
11 => 14856,
12 => 21228,
13 => 29681,
14 => 63423,
15 => 42326,
16 => 57613,
17 => 11414,
18 => 65535,
19 => 46486,
20 => 0);
type Object_Kind is (Rectangle_Obj, Point_Obj,
Ellipse_Obj, Polygon_Obj, Tile_Obj, Text_Obj);
type String_Access is access all String;
type Object
(Kind : Object_Kind := Rectangle_Obj)
is record
Name : String_Access;
Id : Natural;
X : GESTE.Maths_Types.Value;
Y : GESTE.Maths_Types.Value;
Width : GESTE.Maths_Types.Value;
Height : GESTE.Maths_Types.Value;
Str : String_Access;
Tile_Id : GESTE_Config.Tile_Index;
end record;
type Object_Array is array (Natural range <>)
of Object;
end Game_Assets;
|
with Types; use Types;
package Inputs is
subtype Position_X is Integer range 160 .. 239;
subtype Position_Y is Integer range 0 .. 319;
type Layout_Array is array (0 .. 1, 0 .. 7) of Integer;
Layout : constant Layout_Array := ((1, 2, 3, 16#C#, 7, 8, 9, 16#E#),
(4, 5, 6, 16#D#, 16#A#, 0, 16#B#, 16#F#));
procedure Update_Pressed_Keys(Keys : in out Keys_List);
function Get_Key(X : Position_X; Y : Position_Y) return Integer
with Post => Get_Key'Result = Layout((X - Position_X'First) / 40, Y / 40);
end Inputs;
|
-- Ascon
-- an Ada / SPARK implementation of the Ascon Authenticated Encryption Algorithm
-- created by Christoph Dobraunig, Maria Eichlseder, Florian Mendel and
-- Martin Schläffer
-- Copyright (c) 2016-2018, James Humphry - see LICENSE file for details
pragma Restrictions(No_Implementation_Attributes,
No_Implementation_Units,
No_Obsolescent_Features);
with System.Storage_Elements;
private with Interfaces;
with Ascon_Definitions;
use Ascon_Definitions;
generic
a_rounds : Round_Count := 12;
b_rounds : Round_Count := 6;
b_round_constants_offset : Round_Offset := 6;
rate : Rate_Bits := 64;
package Ascon
with SPARK_Mode => On
is
-- These constants are the same for all variants of Ascon
key_bits : constant := 128;
nonce_bits : constant := 128;
tag_bits : constant := 128;
use System.Storage_Elements;
subtype Key_Type is Storage_Array(0..Storage_Offset(key_bits/8)-1);
-- A Storage_Array subtype containing key material.
subtype Nonce_Type is Storage_Array(0..Storage_Offset(nonce_bits/8)-1);
-- A Storage_Array subtype containing the nonce material. This must be unique
-- per-message.
subtype Tag_Type is Storage_Array(0..Storage_Offset(tag_bits/8)-1);
-- A Storage_Array subtype containing an authentication tag.
Null_Storage_Array : constant Storage_Array(1..0) := (others => 0);
-- A null Storage_Array that can be passed to AEADEnc and AEADDec if one of
-- the associated data or message parameters is not required.
-- High-level API for Ascon
procedure AEADEnc(K : in Key_Type;
N : in Nonce_Type;
A : in Storage_Array;
M : in Storage_Array;
C : out Storage_Array;
T : out Tag_Type)
with Pre => (
(Valid_Storage_Array_Parameter(A) and
Valid_Storage_Array_Parameter(M) and
Valid_Storage_Array_Parameter(C'First, C'Last))
and then C'Length = M'Length
);
-- AEADEnc carries out an authenticated encryption
-- K : key data
-- N : nonce
-- A : optional (unencrypted) associated data
-- M : optional message to be encrypted
-- C : encrypted version of M
-- T : authentication tag for (A,M,Z)
procedure AEADDec(K : in Key_Type;
N : in Nonce_Type;
A : in Storage_Array;
C : in Storage_Array;
T : in Tag_Type;
M : out Storage_Array;
Valid : out Boolean)
with Pre => (
(Valid_Storage_Array_Parameter(A) and
Valid_Storage_Array_Parameter(C) and
Valid_Storage_Array_Parameter(M'First, M'Last))
and then M'Length = C'Length
),
Post => (Valid or (for all I in M'Range => M(I) = 0));
-- AEADEnc carries out an authenticated decryption
-- K : key data
-- N : nonce
-- A : optional (unencrypted) associated data
-- C : optional ciphertext to be decrypted
-- T : authentication tag
-- M : contains the decrypted C or zero if the input does not authenticate
-- Valid : indicates if the input authenticates correctly
type State is private;
-- This type declaration makes the Ascon.Access_Internals package easier to
-- write. It is not intended for normal use.
function Valid_Storage_Array_Parameter(X : in Storage_Array)
return Boolean
with Ghost;
-- This ghost function simplifies the preconditions
function Valid_Storage_Array_Parameter(First : in Storage_Offset;
Last : in Storage_Offset)
return Boolean
with Ghost;
-- This ghost function simplifies the preconditions
private
function Valid_Storage_Array_Parameter(X : in Storage_Array)
return Boolean is
(
if X'First <= 0 then
((Long_Long_Integer (X'Last) < Long_Long_Integer'Last +
Long_Long_Integer (X'First))
and then
X'Last < Storage_Offset'Last - Storage_Offset(rate/8))
else
X'Last < Storage_Offset'Last - Storage_Offset(rate/8)
);
function Valid_Storage_Array_Parameter(First : in Storage_Offset;
Last : in Storage_Offset)
return Boolean is
(
if First <= 0 then
((Long_Long_Integer (Last) < Long_Long_Integer'Last +
Long_Long_Integer (First))
and then
Last < Storage_Offset'Last - Storage_Offset(rate/8))
else
Last < Storage_Offset'Last - Storage_Offset(rate/8)
);
subtype Word is Interfaces.Unsigned_64;
type State is array (Integer range 0..4) of Word;
-- Low-level API for Ascon. These routines can be accessed by instantiating
-- the Ascon.Access_Internals child package
function Make_State return State;
function Initialise (Key : in Key_Type; Nonce : in Nonce_Type) return State;
procedure Absorb (S : in out State; X : in Storage_Array)
with Pre=> (Valid_Storage_Array_Parameter(X));
procedure Encrypt (S : in out State;
M : in Storage_Array;
C : out Storage_Array)
with Relaxed_Initialization => C,
Pre => (
(Valid_Storage_Array_Parameter(M) and
Valid_Storage_Array_Parameter(C'First, C'Last))
and then C'Length = M'Length
),
Post => C'Initialized;
procedure Decrypt (S : in out State;
C : in Storage_Array;
M : out Storage_Array)
with Relaxed_Initialization => M,
Pre => (
(Valid_Storage_Array_Parameter(C) and
Valid_Storage_Array_Parameter(M'First, M'Last))
and then C'Length = M'Length
),
Post => M'Initialized;
procedure Finalise (S : in out State; Key : in Key_Type; Tag : out Tag_Type)
with Relaxed_Initialization => Tag, Post => Tag'Initialized;
-- These compile-time checks test requirements that cannot be expressed
-- in the generic formal parameters. Currently compile-time checks are
-- not supported in GNATprove so the related warnings are suppressed.
pragma Warnings (GNATprove, Off, "Compile_Time_Error");
pragma Compile_Time_Error (key_bits /= tag_bits,
"The tag has to be the same length as the key");
pragma Compile_Time_Error (rate mod 64 /= 0,
"The rate is not a multiple of 64 bits");
pragma Compile_Time_Error (System.Storage_Elements.Storage_Element'Size /= 8,
"This implementation of Ascon cannot work " &
"with Storage_Element'Size /= 8");
pragma Compile_Time_Error (b_rounds + b_round_constants_offset > 12,
"Ascon requires b_rounds +" &
" b_round_constants_offset to be <= 12");
pragma Warnings (GNATprove, On, "Compile_Time_Error");
end Ascon;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . S O F T _ L I N K S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
--
--
--
--
--
--
--
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package contains a set of subprogram access variables that access
-- some low-level primitives that are called different depending whether
-- tasking is involved or not (e.g. the Get/Set_Jmpbuf_Address that needs
-- to provide a different value for each task). To avoid dragging in the
-- tasking all the time, we use a system of soft links where the links are
-- initialized to non-tasking versions, and then if the tasking is
-- initialized, they are reset to the real tasking versions.
with Ada.Exceptions;
with System.Stack_Checking;
package System.Soft_Links is
pragma Warnings (Off);
pragma Preelaborate_05;
pragma Warnings (On);
subtype EOA is Ada.Exceptions.Exception_Occurrence_Access;
subtype EO is Ada.Exceptions.Exception_Occurrence;
function Current_Target_Exception return EO;
pragma Import
(Ada, Current_Target_Exception,
"__gnat_current_target_exception");
-- Import this subprogram from the private part of Ada.Exceptions
-- First we have the access subprogram types used to establish the links.
-- The approach is to establish variables containing access subprogram
-- values which by default point to dummy no tasking versions of routines.
type No_Param_Proc is access procedure;
type Addr_Param_Proc is access procedure (Addr : Address);
type EO_Param_Proc is access procedure (Excep : EO);
type Get_Address_Call is access function return Address;
type Set_Address_Call is access procedure (Addr : Address);
type Set_Address_Call2 is access procedure
(Self_ID : Address; Addr : Address);
type Get_Integer_Call is access function return Integer;
type Set_Integer_Call is access procedure (Len : Integer);
type Get_EOA_Call is access function return EOA;
type Set_EOA_Call is access procedure (Excep : EOA);
type Set_EO_Call is access procedure (Excep : EO);
type Special_EO_Call is access
procedure (Excep : EO := Current_Target_Exception);
type Timed_Delay_Call is access
procedure (Time : Duration; Mode : Integer);
type Get_Stack_Access_Call is access
function return Stack_Checking.Stack_Access;
type Task_Name_Call is access
function return String;
-- Suppress checks on all these types, since we know corrresponding
-- values can never be null (the soft links are always initialized).
pragma Suppress (Access_Check, No_Param_Proc);
pragma Suppress (Access_Check, Addr_Param_Proc);
pragma Suppress (Access_Check, EO_Param_Proc);
pragma Suppress (Access_Check, Get_Address_Call);
pragma Suppress (Access_Check, Set_Address_Call);
pragma Suppress (Access_Check, Set_Address_Call2);
pragma Suppress (Access_Check, Get_Integer_Call);
pragma Suppress (Access_Check, Set_Integer_Call);
pragma Suppress (Access_Check, Get_EOA_Call);
pragma Suppress (Access_Check, Set_EOA_Call);
pragma Suppress (Access_Check, Timed_Delay_Call);
pragma Suppress (Access_Check, Get_Stack_Access_Call);
pragma Suppress (Access_Check, Task_Name_Call);
-- The following one is not related to tasking/no-tasking but to the
-- traceback decorators for exceptions.
type Traceback_Decorator_Wrapper_Call is access
function (Traceback : System.Address;
Len : Natural)
return String;
-- Declarations for the no tasking versions of the required routines
procedure Abort_Defer_NT;
-- Defer task abort (non-tasking case, does nothing)
procedure Abort_Undefer_NT;
-- Undefer task abort (non-tasking case, does nothing)
procedure Abort_Handler_NT;
-- Handle task abort (non-tasking case, does nothing). Currently, only VMS
-- uses this.
procedure Update_Exception_NT (X : EO := Current_Target_Exception);
-- Handle exception setting. This routine is provided for targets which
-- have built-in exception handling such as the Java Virtual Machine.
-- Currently, only JGNAT uses this. See 4jexcept.ads for an explanation on
-- how this routine is used.
function Check_Abort_Status_NT return Integer;
-- Returns Boolean'Pos (True) iff abort signal should raise
-- Standard.Abort_Signal.
procedure Task_Lock_NT;
-- Lock out other tasks (non-tasking case, does nothing)
procedure Task_Unlock_NT;
-- Release lock set by Task_Lock (non-tasking case, does nothing)
procedure Task_Termination_NT (Excep : EO);
-- Handle task termination routines for the environment task (non-tasking
-- case, does nothing).
procedure Null_Finalize_Global_List;
-- Finalize global list for controlled objects (does nothing)
procedure Adafinal_NT;
-- Shuts down the runtime system (non-tasking case)
Abort_Defer : No_Param_Proc := Abort_Defer_NT'Access;
pragma Suppress (Access_Check, Abort_Defer);
-- Defer task abort (task/non-task case as appropriate)
Abort_Undefer : No_Param_Proc := Abort_Undefer_NT'Access;
pragma Suppress (Access_Check, Abort_Undefer);
-- Undefer task abort (task/non-task case as appropriate)
Abort_Handler : No_Param_Proc := Abort_Handler_NT'Access;
-- Handle task abort (task/non-task case as appropriate)
Update_Exception : Special_EO_Call := Update_Exception_NT'Access;
-- Handle exception setting and tasking polling when appropriate
Check_Abort_Status : Get_Integer_Call := Check_Abort_Status_NT'Access;
-- Called when Abort_Signal is delivered to the process. Checks to
-- see if signal should result in raising Standard.Abort_Signal.
Lock_Task : No_Param_Proc := Task_Lock_NT'Access;
-- Locks out other tasks. Preceding a section of code by Task_Lock and
-- following it by Task_Unlock creates a critical region. This is used
-- for ensuring that a region of non-tasking code (such as code used to
-- allocate memory) is tasking safe. Note that it is valid for calls to
-- Task_Lock/Task_Unlock to be nested, and this must work properly, i.e.
-- only the corresponding outer level Task_Unlock will actually unlock.
-- This routine also prevents against asynchronous aborts (abort is
-- deferred).
Unlock_Task : No_Param_Proc := Task_Unlock_NT'Access;
-- Releases lock previously set by call to Lock_Task. In the nested case,
-- all nested locks must be released before other tasks competing for the
-- tasking lock are released.
--
-- In the non nested case, this routine terminates the protection against
-- asynchronous aborts introduced by Lock_Task (unless abort was already
-- deferred before the call to Lock_Task (e.g in a protected procedures).
--
-- Note: the recommended protocol for using Lock_Task and Unlock_Task
-- is as follows:
--
-- Locked_Processing : begin
-- System.Soft_Links.Lock_Task.all;
-- ...
-- System.Soft_Links..Unlock_Task.all;
--
-- exception
-- when others =>
-- System.Soft_Links..Unlock_Task.all;
-- raise;
-- end Locked_Processing;
--
-- This ensures that the lock is not left set if an exception is raised
-- explicitly or implicitly during the critical locked region.
Task_Termination_Handler : EO_Param_Proc := Task_Termination_NT'Access;
-- Handle task termination routines (task/non-task case as appropriate)
Finalize_Global_List : No_Param_Proc := Null_Finalize_Global_List'Access;
-- Performs finalization of global list for controlled objects
Adafinal : No_Param_Proc := Adafinal_NT'Access;
-- Performs the finalization of the Ada Runtime
function Get_Jmpbuf_Address_NT return Address;
procedure Set_Jmpbuf_Address_NT (Addr : Address);
Get_Jmpbuf_Address : Get_Address_Call := Get_Jmpbuf_Address_NT'Access;
Set_Jmpbuf_Address : Set_Address_Call := Set_Jmpbuf_Address_NT'Access;
function Get_Sec_Stack_Addr_NT return Address;
procedure Set_Sec_Stack_Addr_NT (Addr : Address);
Get_Sec_Stack_Addr : Get_Address_Call := Get_Sec_Stack_Addr_NT'Access;
Set_Sec_Stack_Addr : Set_Address_Call := Set_Sec_Stack_Addr_NT'Access;
function Get_Exc_Stack_Addr_NT return Address;
Get_Exc_Stack_Addr : Get_Address_Call := Get_Exc_Stack_Addr_NT'Access;
function Get_Current_Excep_NT return EOA;
Get_Current_Excep : Get_EOA_Call := Get_Current_Excep_NT'Access;
function Get_Stack_Info_NT return Stack_Checking.Stack_Access;
Get_Stack_Info : Get_Stack_Access_Call := Get_Stack_Info_NT'Access;
--------------------------
-- Master_Id Soft-Links --
--------------------------
-- Soft-Links are used for procedures that manipulate Master_Ids because
-- a Master_Id must be generated for access to limited class-wide types,
-- whose root may be extended with task components.
function Current_Master_NT return Integer;
procedure Enter_Master_NT;
procedure Complete_Master_NT;
Current_Master : Get_Integer_Call := Current_Master_NT'Access;
Enter_Master : No_Param_Proc := Enter_Master_NT'Access;
Complete_Master : No_Param_Proc := Complete_Master_NT'Access;
----------------------
-- Delay Soft-Links --
----------------------
-- Soft-Links are used for procedures that manipulate time to avoid
-- dragging the tasking run time when using delay statements.
Timed_Delay : Timed_Delay_Call;
--------------------------
-- Task Name Soft-Links --
--------------------------
function Task_Name_NT return String;
Task_Name : Task_Name_Call := Task_Name_NT'Access;
-------------------------------------
-- Exception Tracebacks Soft-Links --
-------------------------------------
Traceback_Decorator_Wrapper : Traceback_Decorator_Wrapper_Call;
-- Wrapper to the possible user specified traceback decorator to be
-- called during automatic output of exception data.
-- The nullity of this wrapper shall correspond to the nullity of the
-- current actual decorator. This is ensured first by the null initial
-- value of the corresponding variables, and then by Set_Trace_Decorator
-- in g-exctra.adb.
pragma Atomic (Traceback_Decorator_Wrapper);
-- Since concurrent read/write operations may occur on this variable.
-- See the body of Tailored_Exception_Traceback in Ada.Exceptions for
-- a more detailed description of the potential problems.
------------------------
-- Task Specific Data --
------------------------
-- Here we define a single type that encapsulates the various task
-- specific data. This type is used to store the necessary data into
-- the Task_Control_Block or into a global variable in the non tasking
-- case.
type TSD is record
Pri_Stack_Info : aliased Stack_Checking.Stack_Info;
-- Information on stack (Base/Limit/Size) that is used
-- by System.Stack_Checking. If this TSD does not belong to
-- the environment task, the Size field must be initialized
-- to the tasks requested stack size before the task can do
-- its first stack check.
pragma Warnings (Off);
Jmpbuf_Address : System.Address := System.Null_Address;
-- Address of jump buffer used to store the address of the
-- current longjmp/setjmp buffer for exception management.
-- These buffers are threaded into a stack, and the address
-- here is the top of the stack. A null address means that
-- no exception handler is currently active.
Sec_Stack_Addr : System.Address := System.Null_Address;
pragma Warnings (On);
-- Address of currently allocated secondary stack
Current_Excep : aliased EO;
-- Exception occurrence that contains the information for the
-- current exception. Note that any exception in the same task
-- destroys this information, so the data in this variable must
-- be copied out before another exception can occur.
--
-- Also act as a list of the active exceptions in the case of the GCC
-- exception mechanism, organized as a stack with the most recent first.
end record;
procedure Create_TSD (New_TSD : in out TSD);
pragma Inline (Create_TSD);
-- Called from s-tassta when a new thread is created to perform
-- any required initialization of the TSD.
procedure Destroy_TSD (Old_TSD : in out TSD);
pragma Inline (Destroy_TSD);
-- Called from s-tassta just before a thread is destroyed to perform
-- any required finalization.
function Get_GNAT_Exception return Ada.Exceptions.Exception_Id;
pragma Inline (Get_GNAT_Exception);
-- This function obtains the Exception_Id from the Exception_Occurrence
-- referenced by the Current_Excep field of the task specific data, i.e.
-- the call is equivalent to
-- Exception_Identity (Get_Current_Exception.all)
-- Export the Get/Set routines for the various Task Specific Data (TSD)
-- elements as callable subprograms instead of objects of access to
-- subprogram types.
function Get_Jmpbuf_Address_Soft return Address;
procedure Set_Jmpbuf_Address_Soft (Addr : Address);
pragma Inline (Get_Jmpbuf_Address_Soft);
pragma Inline (Set_Jmpbuf_Address_Soft);
function Get_Sec_Stack_Addr_Soft return Address;
procedure Set_Sec_Stack_Addr_Soft (Addr : Address);
pragma Inline (Get_Sec_Stack_Addr_Soft);
pragma Inline (Set_Sec_Stack_Addr_Soft);
function Get_Exc_Stack_Addr_Soft return Address;
end System.Soft_Links;
|
pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings;
with System;
private package CUPS.cups_sidechannel_h is
CUPS_SC_FD : constant := 4; -- cups/sidechannel.h:41
-- * "$Id: sidechannel.h 10996 2013-05-29 11:51:34Z msweet $"
-- *
-- * Side-channel API definitions for CUPS.
-- *
-- * Copyright 2007-2012 by Apple Inc.
-- * Copyright 2006 by Easy Software Products.
-- *
-- * These coded instructions, statements, and computer programs are the
-- * property of Apple Inc. and are protected by Federal copyright
-- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
-- * which should have been included with this file. If this file is
-- * file is missing or damaged, see the license at "http://www.cups.org/".
-- *
-- * This file is subject to the Apple OS-Developed Software exception.
--
-- * Include necessary headers...
--
-- * C++ magic...
--
-- * Constants...
--
-- * Enumerations...
--
--*** Bidirectional capability values ***
type cups_sc_bidi_e is
(CUPS_SC_BIDI_NOT_SUPPORTED,
CUPS_SC_BIDI_SUPPORTED);
pragma Convention (C, cups_sc_bidi_e); -- cups/sidechannel.h:48
-- Bidirectional I/O is not supported
-- Bidirectional I/O is supported
subtype cups_sc_bidi_t is cups_sc_bidi_e;
--*** Bidirectional capabilities ***
--*** Request command codes ***
type cups_sc_command_e is
(CUPS_SC_CMD_NONE,
CUPS_SC_CMD_SOFT_RESET,
CUPS_SC_CMD_DRAIN_OUTPUT,
CUPS_SC_CMD_GET_BIDI,
CUPS_SC_CMD_GET_DEVICE_ID,
CUPS_SC_CMD_GET_STATE,
CUPS_SC_CMD_SNMP_GET,
CUPS_SC_CMD_SNMP_GET_NEXT,
CUPS_SC_CMD_GET_CONNECTED,
CUPS_SC_CMD_MAX);
pragma Convention (C, cups_sc_command_e); -- cups/sidechannel.h:56
-- No command @private@
-- Do a soft reset
-- Drain all pending output
-- Return bidirectional capabilities
-- Return the IEEE-1284 device ID
-- Return the device state
-- Query an SNMP OID @since CUPS 1.4/OS X 10.6@
-- Query the next SNMP OID @since CUPS 1.4/OS X 10.6@
-- Return whether the backend is "connected" to the printer @since CUPS 1.5/OS X 10.7@
-- End of valid values @private@
subtype cups_sc_command_t is cups_sc_command_e;
--*** Request command codes ***
--*** Connectivity values ***
type cups_sc_connected_e is
(CUPS_SC_NOT_CONNECTED,
CUPS_SC_CONNECTED);
pragma Convention (C, cups_sc_connected_e); -- cups/sidechannel.h:72
-- Backend is not "connected" to printer
-- Backend is "connected" to printer
subtype cups_sc_connected_t is cups_sc_connected_e;
--*** Connectivity values ***
--*** Printer state bits ***
subtype cups_sc_state_e is unsigned;
CUPS_SC_STATE_OFFLINE : constant cups_sc_state_e := 0;
CUPS_SC_STATE_ONLINE : constant cups_sc_state_e := 1;
CUPS_SC_STATE_BUSY : constant cups_sc_state_e := 2;
CUPS_SC_STATE_ERROR : constant cups_sc_state_e := 4;
CUPS_SC_STATE_MEDIA_LOW : constant cups_sc_state_e := 16;
CUPS_SC_STATE_MEDIA_EMPTY : constant cups_sc_state_e := 32;
CUPS_SC_STATE_MARKER_LOW : constant cups_sc_state_e := 64;
CUPS_SC_STATE_MARKER_EMPTY : constant cups_sc_state_e := 128; -- cups/sidechannel.h:81
-- Device is offline
-- Device is online
-- Device is busy
-- Other error condition
-- Paper low condition
-- Paper out condition
-- Toner/ink low condition
-- Toner/ink out condition
subtype cups_sc_state_t is cups_sc_state_e;
--*** Printer state bits ***
--*** Response status codes ***
type cups_sc_status_e is
(CUPS_SC_STATUS_NONE,
CUPS_SC_STATUS_OK,
CUPS_SC_STATUS_IO_ERROR,
CUPS_SC_STATUS_TIMEOUT,
CUPS_SC_STATUS_NO_RESPONSE,
CUPS_SC_STATUS_BAD_MESSAGE,
CUPS_SC_STATUS_TOO_BIG,
CUPS_SC_STATUS_NOT_IMPLEMENTED);
pragma Convention (C, cups_sc_status_e); -- cups/sidechannel.h:95
-- No status
-- Operation succeeded
-- An I/O error occurred
-- The backend did not respond
-- The device did not respond
-- The command/response message was invalid
-- Response too big
-- Command not implemented
subtype cups_sc_status_t is cups_sc_status_e;
--*** Response status codes ***
type cups_sc_walk_func_t is access procedure
(arg1 : Interfaces.C.Strings.chars_ptr;
arg2 : Interfaces.C.Strings.chars_ptr;
arg3 : int;
arg4 : System.Address);
pragma Convention (C, cups_sc_walk_func_t); -- cups/sidechannel.h:109
--*** SNMP walk callback ***
-- * Prototypes...
--
function cupsSideChannelDoRequest
(command : cups_sc_command_t;
data : Interfaces.C.Strings.chars_ptr;
datalen : access int;
timeout : double) return cups_sc_status_t; -- cups/sidechannel.h:118
pragma Import (C, cupsSideChannelDoRequest, "cupsSideChannelDoRequest");
function cupsSideChannelRead
(command : access cups_sc_command_t;
status : access cups_sc_status_t;
data : Interfaces.C.Strings.chars_ptr;
datalen : access int;
timeout : double) return int; -- cups/sidechannel.h:121
pragma Import (C, cupsSideChannelRead, "cupsSideChannelRead");
function cupsSideChannelWrite
(command : cups_sc_command_t;
status : cups_sc_status_t;
data : Interfaces.C.Strings.chars_ptr;
datalen : int;
timeout : double) return int; -- cups/sidechannel.h:125
pragma Import (C, cupsSideChannelWrite, "cupsSideChannelWrite");
--*** New in CUPS 1.4 ***
function cupsSideChannelSNMPGet
(oid : Interfaces.C.Strings.chars_ptr;
data : Interfaces.C.Strings.chars_ptr;
datalen : access int;
timeout : double) return cups_sc_status_t; -- cups/sidechannel.h:131
pragma Import (C, cupsSideChannelSNMPGet, "cupsSideChannelSNMPGet");
function cupsSideChannelSNMPWalk
(oid : Interfaces.C.Strings.chars_ptr;
timeout : double;
cb : cups_sc_walk_func_t;
context : System.Address) return cups_sc_status_t; -- cups/sidechannel.h:134
pragma Import (C, cupsSideChannelSNMPWalk, "cupsSideChannelSNMPWalk");
-- * End of "$Id: sidechannel.h 10996 2013-05-29 11:51:34Z msweet $".
--
end CUPS.cups_sidechannel_h;
|
-- POK header
--
-- The following file is a part of the POK project. Any modification should
-- be made according to the POK licence. You CANNOT use this file or a part
-- of a file for your own project.
--
-- For more information on the POK licence, please see our LICENCE FILE
--
-- Please follow the coding guidelines described in doc/CODING_GUIDELINES
--
-- Copyright (c) 2007-2021 POK team
-- ---------------------------------------------------------------------------
-- --
-- PROCESS constant and type definitions and management services --
-- --
-- ---------------------------------------------------------------------------
package APEX.Processes is
Max_Number_Of_Processes : constant := System_Limit_Number_Of_Processes;
Min_Priority_Value : constant := 0;
Max_Priority_Value : constant := 249;
Max_Lock_Level : constant := 32;
subtype Process_Name_Type is Name_Type;
type Process_Id_Type is private;
Null_Process_Id : constant Process_Id_Type;
subtype Lock_Level_Type is APEX_Integer range 0 .. Max_Lock_Level;
subtype Stack_Size_Type is APEX_Unsigned;
subtype Waiting_Range_Type is APEX_Integer range
0 .. Max_Number_Of_Processes;
subtype Priority_Type is APEX_Integer range
Min_Priority_Value .. Max_Priority_Value;
type Process_State_Type is (Dormant, Ready, Running, Waiting);
type Deadline_Type is (Soft, Hard);
type Process_Attribute_Type is record
Period : System_Time_Type;
Time_Capacity : System_Time_Type;
Entry_Point : System_Address_Type;
Stack_Size : Stack_Size_Type;
Base_Priority : Priority_Type;
Deadline : Deadline_Type;
Name : Process_Name_Type;
end record;
type Process_Status_Type is record
Deadline_Time : System_Time_Type;
Current_Priority : Priority_Type;
Process_State : Process_State_Type;
Attributes : Process_Attribute_Type;
end record;
procedure Create_Process
(Attributes : in Process_Attribute_Type;
Process_Id : out Process_Id_Type;
Return_Code : out Return_Code_Type);
procedure Set_Priority
(Process_Id : in Process_Id_Type;
Priority : in Priority_Type;
Return_Code : out Return_Code_Type);
procedure Suspend_Self
(Time_Out : in System_Time_Type;
Return_Code : out Return_Code_Type);
procedure Suspend
(Process_Id : in Process_Id_Type;
Return_Code : out Return_Code_Type);
procedure Resume
(Process_Id : in Process_Id_Type;
Return_Code : out Return_Code_Type);
procedure Stop_Self;
procedure Stop
(Process_Id : in Process_Id_Type;
Return_Code : out Return_Code_Type);
procedure Start
(Process_Id : in Process_Id_Type;
Return_Code : out Return_Code_Type);
procedure Delayed_Start
(Process_Id : in Process_Id_Type;
Delay_Time : in System_Time_Type;
Return_Code : out Return_Code_Type);
procedure Lock_Preemption
(Lock_Level : out Lock_Level_Type;
Return_Code : out Return_Code_Type);
procedure Unlock_Preemption
(Lock_Level : out Lock_Level_Type;
Return_Code : out Return_Code_Type);
procedure Get_My_Id
(Process_Id : out Process_Id_Type;
Return_Code : out Return_Code_Type);
procedure Get_Process_Id
(Process_Name : in Process_Name_Type;
Process_Id : out Process_Id_Type;
Return_Code : out Return_Code_Type);
procedure Get_Process_Status
(Process_Id : in Process_Id_Type;
Process_Status : out Process_Status_Type;
Return_Code : out Return_Code_Type);
private
type Process_ID_Type is new APEX_Integer;
Null_Process_Id : constant Process_Id_Type := 0;
pragma Convention (C, Process_State_Type);
pragma Convention (C, Deadline_Type);
pragma Convention (C, Process_Attribute_Type);
pragma Convention (C, Process_Status_Type);
-- POK BINDINGS
pragma Import (C, Create_Process, "CREATE_PROCESS");
pragma Import (C, Set_Priority, "SET_PRIORITY");
pragma Import (C, Suspend_Self, "SUSPEND_SELF");
pragma Import (C, Suspend, "SUSPEND");
pragma Import (C, Resume, "SUSPEND");
pragma Import (C, Stop_Self, "STOP_SELF");
pragma Import (C, Stop, "STOP");
pragma Import (C, Start, "START");
pragma Import (C, Delayed_Start, "DELAYED_START");
pragma Import (C, Lock_Preemption, "LOCK_PREEMPTION");
pragma Import (C, Unlock_Preemption, "UNLOCK_PREEMPTION");
pragma Import (C, Get_My_Id, "GET_MY_ID");
pragma Import (C, Get_Process_Id, "GET_PROCESS_ID");
pragma Import (C, Get_Process_Status, "GET_PROCESS_STATUS");
-- END OF POK BINDINGS
end APEX.Processes;
|
with Ada.Wide_Wide_Text_IO;
package body Handlers is
use type League.Strings.Universal_String;
function "+"
(Item : Wide_Wide_String) return League.Strings.Universal_String
renames League.Strings.To_Universal_String;
------------------
-- Error_String --
------------------
overriding function Error_String
(Self : Handler) return League.Strings.Universal_String is
begin
return League.Strings.Empty_Universal_String;
end Error_String;
-------------------
-- Start_Element --
-------------------
overriding procedure Start_Element
(Self : in out Handler;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String;
Qualified_Name : League.Strings.Universal_String;
Attributes : XML.SAX.Attributes.SAX_Attributes;
Success : in out Boolean) is
begin
if Qualified_Name = +"Student" then
Ada.Wide_Wide_Text_IO.Put_Line
(Attributes.Value (+"Name").To_Wide_Wide_String);
end if;
end Start_Element;
end Handlers;
|
generic
Size : in Positive;
type Element_Type (<>) is private;
type Element_Ptr is access all Element_Type;
package Lto9_Pkg2 is
subtype Index is Positive range 1 .. (Size + 1);
type List_Array is array (Index) of Element_Ptr;
type List_Type is record
Elements : List_Array;
end record;
procedure Put (List : in out List_Type;
Elem_Ptr : in Element_Ptr;
Location : in Index);
end Lto9_Pkg2;
|
with System; use System;
with AVTAS.LMCP.Types; use AVTAS.LMCP.Types;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package AVTAS.LMCP.ByteBuffers is
Maximum_Length : constant := UInt32'Last - 1;
subtype Index is UInt32 range 1 .. Maximum_Length;
type ByteBuffer (Capacity : Index) is tagged private with
Default_Initial_Condition =>
Position (ByteBuffer) = 1 and
Length (ByteBuffer) = 0;
procedure Rewind (This : in out ByteBuffer) with
Post'Class => Position (This) = 1 and
Length (This) = Length (This)'Old;
-- For reading, resetting the buffer position would allow reading of
-- existing content from the beginning, presumably after writing
-- values into it (via the Put_* routines).
--
-- For writing, resetting the buffer position would make subsequent calls
-- to Put_* start over at the beginning, overwriting any existing values,
-- but NOTE that this does not reset the length, i.e., new Put_* calls
-- would increase the Length determined by any Put_* calls made prior
-- to Rewind. As a result, for writing you probably want to call Clear
-- instead.
procedure Clear (This : in out ByteBuffer) with
Post'Class => Position (This) = 1 and
Length (This) = 0;
function Remaining (This : ByteBuffer) return UInt32;
function Has_Remaining (This : ByteBuffer) return Boolean with
Post => ((Has_Remaining'Result) = (Remaining (This) > 0));
function Position (This : ByteBuffer) return UInt32;
-- Position always returns the next place within the buffer for reading or
-- for writing.
--
-- Both Put_* and Get_* routines affect the value of Position. Only the
-- Put_* routines affect the Length.
function Length (This : ByteBuffer) return UInt32;
-- The logical length of the content of the buffer, i.e., the "high water
-- mark" for values placed into the buffer by the various Put_* routines.
-- Not affected by the Get_* routines. The logical length of the content
-- may not be equal the Capacity.
-- We use procedures rather than functions for the sake of SPARK, if proof
-- is to be applied
procedure Get_Byte (This : in out ByteBuffer; Value : out Byte) with
Pre'Class => Remaining (This) >= 1,
Post'Class => Position (This) = Position (This)'Old + 1 and
Length (This) = Length (This)'Old;
procedure Get_Boolean (This : in out ByteBuffer; Value : out Boolean) with
Pre'Class => Remaining (This) >= 1,
Post'Class => Position (This) = Position (This)'Old + 1 and
Length (This) = Length (This)'Old;
procedure Get_Int16 (This : in out ByteBuffer; Value : out Int16) with
Pre'Class => Remaining (This) >= 2,
Post'Class => Position (This) = Position (This)'Old + 2 and
Length (This) = Length (This)'Old;
procedure Get_Short (This : in out ByteBuffer; Value : out Int16) renames Get_Int16;
procedure Get_UInt16 (This : in out ByteBuffer; Value : out UInt16) with
Pre'Class => Remaining (This) >= 2,
Post'Class => Position (This) = Position (This)'Old + 2 and
Length (This) = Length (This)'Old;
procedure Get_UShort (This : in out ByteBuffer; Value : out UInt16) renames Get_UInt16;
procedure Get_Int32 (This : in out ByteBuffer; Value : out Int32) with
Pre'Class => Remaining (This) >= 4,
Post'Class => Position (This) = Position (This)'Old + 4 and
Length (This) = Length (This)'Old;
procedure Get_Int (This : in out ByteBuffer; Value : out Int32) renames Get_Int32;
procedure Get_UInt32
(This : in ByteBuffer;
Value : out UInt32;
First : Index)
with
Pre'Class => First <= Length (This) - 3,
Post'Class => Position (This) = Position (This)'Old and
Length (This) = Length (This)'Old;
-- Gets a UInt32 value from This buffer, at indexes First .. First + 3
-- rather than from This.Position .. This.Positon + 3
procedure Get_UInt32 (This : in out ByteBuffer; Value : out UInt32) with
Pre'Class => Remaining (This) >= 4,
Post'Class => Position (This) = Position (This)'Old + 4 and
Length (This) = Length (This)'Old;
procedure Get_UInt (This : in out ByteBuffer; Value : out UInt32) renames Get_UInt32;
procedure Get_Int64 (This : in out ByteBuffer; Value : out Int64) with
Pre'Class => Remaining (This) >= 8,
Post'Class => Position (This) = Position (This)'Old + 8 and
Length (This) = Length (This)'Old;
procedure Get_Long (This : in out ByteBuffer; Value : out Int64) renames Get_Int64;
procedure Get_UInt64 (This : in out ByteBuffer; Value : out UInt64) with
Pre'Class => Remaining (This) >= 8,
Post'Class => Position (This) = Position (This)'Old + 8 and
Length (This) = Length (This)'Old;
procedure Get_ULong (This : in out ByteBuffer; Value : out UInt64) renames Get_UInt64;
procedure Get_Real32 (This : in out ByteBuffer; Value : out Real32) with
Pre'Class => Remaining (This) >= 4,
Post'Class => Position (This) = Position (This)'Old + 4 and
Length (This) = Length (This)'Old;
procedure Get_Real64 (This : in out ByteBuffer; Value : out Real64) with
Pre'Class => Remaining (This) >= 8,
Post'Class => Position (This) = Position (This)'Old + 8 and
Length (This) = Length (This)'Old;
procedure Get_String
(This : in out ByteBuffer;
Value : out String;
Last : out Natural)
with
Pre'Class => Remaining (This) >= 2,
Post'Class =>
-- Last is Value'First - 1 when the number of characters is read as zero, otherwise it is in Value'Range
Last in Value'First - 1 .. Value'Last and
-- we read the length, which was zero, so nothing else was read
(if Last = Value'First - 1 then Position (This) = Position (This'Old) + 2) and
-- we read the length, which was nonzero, and then that many characters
(if Last /= Value'First - 1 then Position (This) = Position (This'Old) + 2 + UInt32(Last - Value'First + 1)) and
Length (This) = Length (This)'Old;
-- The string content is preceeded in the buffer by a two-byte length,
-- even when zero, so the precondition checks that there are least
-- that many bytes available.
procedure Get_Unbounded_String
(This : in out ByteBuffer;
Value : out Unbounded_String)
with
Pre'Class => Remaining (This) >= 3,
Post'Class =>
-- we read the length, which was zero, so nothing else was read
(if Value = Null_Unbounded_String then Position (This) = Position (This'Old) + 2) and
-- we read the length, which was nonzero, and then that many characters
(if Value /= Null_Unbounded_String then Position (This) = Position (This'Old) + 2 + UInt32 (Length (Value))) and
Length (This) = Length (This)'Old;
procedure Put_Byte (This : in out ByteBuffer; Value : Byte) with
Pre'Class => Remaining (This) >= 1,
Post'Class => Position (This) = Position (This)'Old + 1 and
Length (This) = Length (This)'Old + 1;
procedure Put_Boolean (This : in out ByteBuffer; Value : Boolean) with
Pre'Class => Remaining (This) >= 1,
Post'Class => Position (This) = Position (This)'Old + 1 and
Length (This) = Length (This)'Old + 1;
procedure Put_Int16 (This : in out ByteBuffer; Value : Int16) with
Pre'Class => Remaining (This) >= 2,
Post'Class => Position (This) = Position (This)'Old + 2 and
Length (This) = Length (This)'Old + 2;
procedure Put_Short (This : in out ByteBuffer; Value : Int16) renames Put_Int16;
procedure Put_UInt16 (This : in out ByteBuffer; Value : UInt16) with
Pre'Class => Remaining (This) >= 2,
Post'Class => Position (This) = Position (This)'Old + 2 and
Length (This) = Length (This)'Old + 2;
procedure Put_UShort (This : in out ByteBuffer; Value : UInt16) renames Put_UInt16;
procedure Put_Int32 (This : in out ByteBuffer; Value : Int32) with
Pre'Class => Remaining (This) >= 4,
Post'Class => Position (This) = Position (This)'Old + 4 and
Length (This) = Length (This)'Old + 4;
procedure Put_Int (This : in out ByteBuffer; Value : Int32) renames Put_Int32;
procedure Put_UInt32 (This : in out ByteBuffer; Value : UInt32) with
Pre'Class => Remaining (This) >= 4,
Post'Class => Position (This) = Position (This)'Old + 4 and
Length (This) = Length (This)'Old + 4;
procedure Put_UInt (This : in out ByteBuffer; Value : UInt32) renames Put_UInt32;
procedure Put_Int64 (This : in out ByteBuffer; Value : Int64) with
Pre'Class => Remaining (This) >= 8,
Post'Class => Position (This) = Position (This)'Old + 8 and
Length (This) = Length (This)'Old + 8;
procedure Put_Long (This : in out ByteBuffer; Value : Int64) renames Put_Int64;
procedure Put_UInt64 (This : in out ByteBuffer; Value : UInt64) with
Pre'Class => Remaining (This) >= 8,
Post'Class => Position (This) = Position (This)'Old + 8 and
Length (This) = Length (This)'Old + 8;
procedure Put_ULong (This : in out ByteBuffer; Value : UInt64) renames Put_UInt64;
-- ByteBuffer & putFloat(float f);
procedure Put_Real32 (This : in out ByteBuffer; Value : Real32) with
Pre'Class => Remaining (This) >= 4,
Post'Class => Position (This) = Position (This)'Old + 4 and
Length (This) = Length (This)'Old + 4;
-- ByteBuffer & putDouble(double d);
procedure Put_Real64 (This : in out ByteBuffer; Value : Real64) with
Pre'Class => Remaining (This) >= 8,
Post'Class => Position (This) = Position (This)'Old + 8 and
Length (This) = Length (This)'Old + 8;
procedure Put_String (This : in out ByteBuffer; Value : String) with
Pre'Class => Remaining (This) >= Value'Length + 2, -- 2 bytes for the length
Post'Class => Position (This) = Position (This)'Old + 2 + Value'Length and
Length (This) = Length (This)'Old + Value'Length + 2;
-- Populate the ByteBuffer from the bytes in a String. Useful for then
-- rewinding and reading back out meaningful objects. The input Value is a
-- String because that's the most convenient choice, based on client usage.
procedure Put_Raw_Bytes (This : in out ByteBuffer; Value : String) with
Pre'Class => Value /= "" and Remaining (This) >= Value'Length, -- we don't write the length attr
Post'Class =>
Position (This) = Position (This)'Old + Value'Length and -- we don't write the length attr
Length (This) = Length (This)'Old + Value'Length; -- we don't write the length attr
procedure Put_Unbounded_String (This : in out ByteBuffer; Value : Unbounded_String) with
Pre'Class => Integer (Remaining (This)) >= 2 + Length (Value), -- 2 bytes for the length
Post'Class =>
Position (This) = Position (This)'Old + 2 + UInt32 (Length (Value)) and
Length (This) = Length (This)'Old + 2 + UInt32 (Length (Value));
type Byte_Array is array (Index range <>) of Byte
with Component_Size => 1 * Storage_Unit; -- confirming
function Raw_Bytes (This : ByteBuffer) return Byte_Array;
-- Returns the full internal byte array content
function Raw_Bytes (This : ByteBuffer) return String;
-- Returns the full internal byte array content, as a String
function Checksum (This : ByteBuffer; From, To : Index) return UInt32 with
Pre'Class =>
From <= To and -- null ranges are not useful
From <= This.Capacity and -- physically possible
To <= This.Capacity and
From <= This.Length and -- logically possible
To <= This.Length;
-- Computes the checksum of the slice of the internal byte array From .. To.
private
subtype Natural_Index is UInt32 range 0 .. Maximum_Length;
type ByteBuffer (Capacity : Index) is tagged record
Content : Byte_Array (1 .. Capacity) := (others => 0);
Position : Index := 1; -- reset to 1 by Rewind
Length : Natural_Index := 0; -- reset to by Clear
end record;
end AVTAS.LMCP.ByteBuffers;
|
-- Copyright (c) 1990 Regents of the University of California.
-- All rights reserved.
--
-- The primary authors of ayacc were David Taback and Deepak Tolani.
-- Enhancements were made by Ronald J. Schmalz.
--
-- Send requests for ayacc information to ayacc-info@ics.uci.edu
-- Send bug reports for ayacc to ayacc-bugs@ics.uci.edu
--
-- Redistribution and use in source and binary forms are permitted
-- provided that the above copyright notice and this paragraph are
-- duplicated in all such forms and that any documentation,
-- advertising materials, and other materials related to such
-- distribution and use acknowledge that the software was developed
-- by the University of California, Irvine. The name of the
-- University may not be used to endorse or promote products derived
-- from this software without specific prior written permission.
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
-- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-- WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-- Module : rule_table_body.ada
-- Component of : ayacc
-- Version : 1.2
-- Date : 11/21/86 12:34:28
-- SCCS File : disk21~/rschm/hasee/sccs/ayacc/sccs/sxrule_table_body.ada
-- $Header: rule_table_body.a,v 0.1 86/04/01 15:11:44 ada Exp $
-- $Log: rule_table_body.a,v $
-- Revision 0.1 86/04/01 15:11:44 ada
-- This version fixes some minor bugs with empty grammars
-- and $$ expansion. It also uses vads5.1b enhancements
-- such as pragma inline.
--
--
-- Revision 0.0 86/02/19 18:41:08 ada
--
-- These files comprise the initial version of Ayacc
-- designed and implemented by David Taback and Deepak Tolani.
-- Ayacc has been compiled and tested under the Verdix Ada compiler
-- version 4.06 on a vax 11/750 running Unix 4.2BSD.
--
package body Rule_Table is
SCCS_ID : constant String := "@(#) rule_table_body.ada, Version 1.2";
Rcs_ID : constant String := "$Header: rule_table_body.a,v 0.1 86/04/01 15:11:44 ada Exp $";
-- Rules are implemented as an array of linked lists
Number_of_Nested_Rules : Integer := 0;
type RHS_Element;
type RHS_Pointer is access RHS_Element;
type RHS_Element is
record
RHS_Symbol: Grammar_Symbol;
Next : RHS_Pointer;
end record;
type Rule_Entry is
record
LHS_Symbol : Grammar_Symbol;
RHS : RHS_Pointer;
Length : Natural;
Null_Pos : Natural;
Prec : Precedence;
end record;
Rule_List: array(Rule) of Rule_Entry;
Next_Free_Rule: Rule := 0;
function Get_Rule_Precedence(R : Rule) return Precedence is
begin
return Rule_List(R).Prec;
end Get_Rule_Precedence;
function Make_Rule(LHS: Grammar_Symbol) return Rule is
R : Rule := Next_Free_Rule;
begin
Rule_List(R) :=
(LHS, RHS => null, Length => 0, Null_Pos => 0, Prec => 0);
Next_Free_Rule := Next_Free_Rule + 1;
return R;
end Make_Rule;
procedure Append_RHS(R: in Rule; RHS: in Grammar_Symbol) is
Temp_Pointer: RHS_Pointer;
begin
if Is_Terminal(RHS) then
Rule_List(R).Prec := Get_Precedence(RHS);
end if;
if Rule_List(R).RHS = null then
Rule_List(R).RHS := new RHS_Element'(RHS, null);
else
Temp_Pointer := Rule_List(R).RHS;
while Temp_Pointer.Next /= null loop
Temp_Pointer := Temp_Pointer.Next;
end loop;
Temp_Pointer.Next := new RHS_Element'(RHS, null);
end if;
Rule_List(R).Length := Rule_List(R).Length + 1;
end Append_RHS;
function Get_LHS(R: Rule) return Grammar_Symbol is
begin
return Rule_List(R).LHS_Symbol;
end Get_LHS;
function Get_Null_Pos(R: Rule) return Natural is
begin
return Rule_List(R).Null_Pos;
end Get_Null_Pos;
procedure Set_Null_Pos(R : in Rule; Position: in Natural) is
begin
Rule_List(R).Null_Pos := Position;
end Set_Null_Pos;
function Get_RHS(R: Rule; Position: Positive) return Grammar_Symbol is
Temp_Pointer: RHS_Pointer;
begin
Temp_Pointer := Rule_List(R).RHS;
for I in 2..Position loop
Temp_Pointer := Temp_Pointer.Next;
end loop;
return Temp_Pointer.RHS_Symbol;
end Get_RHS;
function Length_of(R: Rule) return Natural is
begin
return Rule_List(R).Length;
end Length_of;
function First_Rule return Rule is
begin
return 0;
end First_Rule;
function Last_Rule return Rule is
begin
return Next_Free_Rule - 1;
end Last_Rule;
function Number_of_Rules return Natural is
begin
return Natural(Next_Free_Rule) - 1;
end Number_of_Rules;
procedure Handle_Nested_Rule(Current_Rule : in out Rule) is
Temp : Rule_Entry;
LHS : Grammar_Symbol;
New_Rule : Rule;
begin
-- Make a new rule prefixed by $$N
Number_of_Nested_Rules := Number_of_Nested_Rules + 1;
LHS := Insert_Identifier("$$" & Integer'Image(Number_of_Nested_Rules));
New_Rule := Make_Rule(LHS);
Append_RHS(Current_Rule,LHS);
-- Exchange the rule positions of the new rule and the current rule
-- by swapping contents and exchanging the rule positions
Temp := Rule_List(Current_Rule);
Rule_List(Current_Rule) := Rule_List(New_Rule);
Rule_List(New_Rule) := Temp;
Current_Rule := New_Rule;
end Handle_Nested_Rule;
procedure Set_Rule_Precedence(R: in Rule; Prec: in Precedence) is
begin
Rule_List(R).Prec := Prec;
end Set_Rule_Precedence;
end Rule_Table;
|
with Ada.Text_IO;
use Ada.Text_IO;
procedure Fizzbuzz is
i : Integer;
begin
i := 1;
for i in Integer range 1 .. 100 loop
if i mod 3 = 0 and i mod 5 = 0 then
Put_Line ("FizzBuzz");
elsif i mod 5 = 0 then
Put_Line("Buzz");
elsif i mod 3 = 0 then
Put_Line("Fizz");
else
Put_Line(Integer'Image(i));
end if;
end loop;
end Fizzbuzz;
|
-- Copyright 2021 Jeff Foley. All rights reserved.
-- Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
name = "SpyOnWeb"
type = "scrape"
function start()
set_rate_limit(2)
end
function horizontal(ctx, domain)
local page, err = request(ctx, {url=build_url(domain)})
if (err ~= nil and err ~= "") then
log(ctx, "horizontal request to service failed: " .. err)
return
end
local pattern = "\"/go/([a-z0-9-]{2,63}[.][a-z]{2,3}([a-z]{2}|))\""
local matches = submatch(page, pattern)
if (matches == nil or #matches == 0) then
return
end
for i, match in pairs(matches) do
if (match ~= nil and #match >= 2 and match[2] ~= "") then
associated(ctx, domain, match[2])
end
end
end
function build_url(domain)
return "https://spyonweb.com/" .. domain
end
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . V M S _ E X C E P T I O N _ T A B L E --
-- --
-- B o d y --
-- --
-- Copyright (C) 1997-2004, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This is an Alpha/VMS package.
with System.HTable;
pragma Elaborate_All (System.HTable);
package body System.VMS_Exception_Table is
use type SSL.Exception_Code;
type HTable_Headers is range 1 .. 37;
type Exception_Code_Data;
type Exception_Code_Data_Ptr is access all Exception_Code_Data;
-- The following record maps an imported VMS condition to an
-- Ada exception.
type Exception_Code_Data is record
Code : SSL.Exception_Code;
Except : SSL.Exception_Data_Ptr;
HTable_Ptr : Exception_Code_Data_Ptr;
end record;
procedure Set_HT_Link
(T : Exception_Code_Data_Ptr;
Next : Exception_Code_Data_Ptr);
function Get_HT_Link (T : Exception_Code_Data_Ptr)
return Exception_Code_Data_Ptr;
function Hash (F : SSL.Exception_Code) return HTable_Headers;
function Get_Key (T : Exception_Code_Data_Ptr) return SSL.Exception_Code;
package Exception_Code_HTable is new System.HTable.Static_HTable (
Header_Num => HTable_Headers,
Element => Exception_Code_Data,
Elmt_Ptr => Exception_Code_Data_Ptr,
Null_Ptr => null,
Set_Next => Set_HT_Link,
Next => Get_HT_Link,
Key => SSL.Exception_Code,
Get_Key => Get_Key,
Hash => Hash,
Equal => "=");
------------------
-- Base_Code_In --
------------------
function Base_Code_In
(Code : SSL.Exception_Code) return SSL.Exception_Code
is
begin
return Code and not 2#0111#;
end Base_Code_In;
---------------------
-- Coded_Exception --
---------------------
function Coded_Exception
(X : SSL.Exception_Code) return SSL.Exception_Data_Ptr
is
Res : Exception_Code_Data_Ptr;
begin
Res := Exception_Code_HTable.Get (X);
if Res /= null then
return Res.Except;
else
return null;
end if;
end Coded_Exception;
-----------------
-- Get_HT_Link --
-----------------
function Get_HT_Link
(T : Exception_Code_Data_Ptr) return Exception_Code_Data_Ptr
is
begin
return T.HTable_Ptr;
end Get_HT_Link;
-------------
-- Get_Key --
-------------
function Get_Key (T : Exception_Code_Data_Ptr)
return SSL.Exception_Code
is
begin
return T.Code;
end Get_Key;
----------
-- Hash --
----------
function Hash
(F : SSL.Exception_Code) return HTable_Headers
is
Headers_Magnitude : constant SSL.Exception_Code :=
SSL.Exception_Code (HTable_Headers'Last - HTable_Headers'First + 1);
begin
return HTable_Headers (F mod Headers_Magnitude + 1);
end Hash;
----------------------------
-- Register_VMS_Exception --
----------------------------
procedure Register_VMS_Exception
(Code : SSL.Exception_Code;
E : SSL.Exception_Data_Ptr)
is
-- We bind the exception data with the base code found in the
-- input value, that is with the severity bits masked off.
Excode : constant SSL.Exception_Code := Base_Code_In (Code);
begin
-- The exception data registered here is mostly filled prior to this
-- call and by __gnat_error_handler when the exception is raised. We
-- still need to fill a couple of components for exceptions that will
-- be used as propagation filters (exception data pointer registered
-- as choices in the unwind tables): in some import/export cases, the
-- exception pointers for the choice and the propagated occurrence may
-- indeed be different for a single import code, and the personality
-- routine attempts to match the import codes in this case.
E.Lang := 'V';
E.Import_Code := Excode;
if Exception_Code_HTable.Get (Excode) = null then
Exception_Code_HTable.Set (new Exception_Code_Data'(Excode, E, null));
end if;
end Register_VMS_Exception;
-----------------
-- Set_HT_Link --
-----------------
procedure Set_HT_Link
(T : Exception_Code_Data_Ptr;
Next : Exception_Code_Data_Ptr)
is
begin
T.HTable_Ptr := Next;
end Set_HT_Link;
end System.VMS_Exception_Table;
|
-- Abstract :
--
-- Output Elisp code implementing the grammar defined by the parameters.
--
-- Copyright (C) 2012 - 2015, 2017 - 2019 Free Software Foundation, Inc.
--
-- The WisiToken package is free software; you can redistribute it
-- and/or modify it under terms of the GNU General Public License as
-- published by the Free Software Foundation; either version 3, or
-- (at your option) any later version. This library is distributed in
-- the hope that it will be useful, but WITHOUT ANY WARRANTY; without
-- even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-- PARTICULAR PURPOSE.
--
-- As a special exception under Section 7 of GPL version 3, you are granted
-- additional permissions described in the GCC Runtime Library Exception,
-- version 3.1, as published by the Free Software Foundation.
pragma License (Modified_GPL);
with Ada.Text_IO; use Ada.Text_IO;
with WisiToken.BNF.Generate_Utils;
with WisiToken.BNF.Output_Elisp_Common;
with WisiToken.Generate.Packrat;
with WisiToken.Parse.LR;
with WisiToken_Grammar_Runtime;
procedure WisiToken.BNF.Output_Elisp
(Input_Data : in WisiToken_Grammar_Runtime.User_Data_Type;
Elisp_Package : in String;
Generate_Data : aliased in WisiToken.BNF.Generate_Utils.Generate_Data;
Packrat_Data : in WisiToken.Generate.Packrat.Data;
Tuple : in Generate_Tuple)
is
pragma Unreferenced (Packrat_Data);
procedure Action_Table (Table : in WisiToken.Parse.LR.Parse_Table; Descriptor : in WisiToken.Descriptor)
is
use WisiToken.Parse.LR;
begin
Put (" [");
for State in Table.States'Range loop
if State = Table.States'First then
Put ("(");
else
Put (" (");
end if;
Put ("(default . error)");
declare
Action : Action_Node_Ptr := Table.States (State).Action_List;
begin
loop
declare
Parse_Action_Node : Parse_Action_Node_Ptr := Action.Action;
Conflict : constant Boolean := Parse_Action_Node.Next /= null;
begin
Put (" (" & Image (Action.Symbol, Descriptor) & " . ");
if Conflict then
Put ("(");
end if;
loop
declare
Parse_Action : Parse_Action_Rec renames Parse_Action_Node.Item;
begin
case Parse_Action.Verb is
when Accept_It =>
Put ("accept");
when Error =>
Put ("error");
when Reduce =>
Put
("(" & Image (Parse_Action.Production.LHS, Descriptor) & " ." &
Integer'Image (Parse_Action.Production.RHS) & ")");
when Shift =>
Put (State_Index'Image (Parse_Action.State));
end case;
if Parse_Action_Node.Next = null then
if Conflict then
Put (")");
end if;
Put (")");
exit;
else
Put (" ");
Parse_Action_Node := Parse_Action_Node.Next;
end if;
end;
end loop;
end;
Action := Action.Next;
if Action.Next = null then
if Action.Action.Item.Verb /= Error then
raise SAL.Programmer_Error with "state" &
State_Index'Image (State) & ": default action is not error";
end if;
-- let default handle it
Action := null;
end if;
if Action = null then
if State = Table.States'Last then
Put (")");
else
Put_Line (")");
end if;
exit;
end if;
end loop;
end;
end loop;
Put_Line ("]");
end Action_Table;
procedure Goto_Table (Table : in WisiToken.Parse.LR.Parse_Table; Descriptor : in WisiToken.Descriptor)
is
use WisiToken.Parse.LR;
subtype Nonterminals is Token_ID range Descriptor.First_Nonterminal .. Descriptor.Last_Nonterminal;
function Count_Nonterminals (List : in Goto_Node_Ptr) return Integer
is
Item : Goto_Node_Ptr := List;
Count : Integer := 0;
begin
while Item /= null loop
if Symbol (Item) in Nonterminals then
Count := Count + 1;
end if;
Item := Next (Item);
end loop;
return Count;
end Count_Nonterminals;
begin
Put (" [");
for State in Table.States'Range loop
declare
Nonterminal_Count : constant Integer := Count_Nonterminals (Table.States (State).Goto_List);
Gotos : Goto_Node_Ptr := Table.States (State).Goto_List;
begin
if Nonterminal_Count = 0 then
if State = Table.States'First then
Put_Line ("nil");
else
if State = Table.States'Last then
Put (" nil");
else
Put_Line (" nil");
end if;
end if;
else
if State = Table.States'First then
Put ("(");
else
Put (" (");
end if;
loop
if Symbol (Gotos) in Nonterminals then
Put ("(" & Image (Symbol (Gotos), Descriptor) & " ." &
State_Index'Image (Parse.LR.State (Gotos)) & ")");
end if;
Gotos := Next (Gotos);
exit when Gotos = null;
end loop;
if State = Table.States'Last then
Put (")");
else
Put_Line (")");
end if;
end if;
end;
end loop;
Put ("]");
end Goto_Table;
procedure Output
(Elisp_Package : in String;
Tokens : in WisiToken.BNF.Tokens;
Parser : in WisiToken.Parse.LR.Parse_Table_Ptr;
Descriptor : in WisiToken.Descriptor)
is
use Ada.Strings.Unbounded;
use Ada.Containers; -- count_type
Rule_Length : constant Count_Type := Tokens.Rules.Length;
Rule_Count : Count_Type := 1;
RHS_Length : Count_Type;
RHS_Count : Count_Type;
begin
Put_Line ("(defconst " & Elisp_Package & "-elisp-parse-table");
Put_Line (" (wisi-compile-grammar");
-- nonterminal productions
Put (" '((");
for Rule of Tokens.Rules loop
if Rule_Count = 1 then
Put ("(");
else
Put (" (");
end if;
Put_Line (-Rule.Left_Hand_Side);
RHS_Length := Rule.Right_Hand_Sides.Length;
RHS_Count := 1;
for RHS of Rule.Right_Hand_Sides loop
Put (" ((");
for Token of RHS.Tokens loop
Put (-Token.Identifier & " ");
end loop;
if Length (RHS.Action) = 0 then
Put (")");
else
Put_Line (")");
Put (" " & (-RHS.Action));
end if;
if RHS_Count = RHS_Length then
Put (")");
else
Put_Line (")");
end if;
RHS_Count := RHS_Count + 1;
end loop;
if Rule_Count = Rule_Length then
Put (")");
else
Put_Line (")");
end if;
Rule_Count := Rule_Count + 1;
end loop;
Put_Line (")");
Action_Table (Parser.all, Descriptor);
Goto_Table (Parser.all, Descriptor);
Put_Line ("))");
Put_Line (" ""Parser table."")");
end Output;
procedure Create_Elisp (Algorithm : in LR_Generate_Algorithm)
is
use Ada.Strings.Unbounded;
File : File_Type;
Elisp_Package_1 : constant String :=
(case Algorithm is
when LALR => Elisp_Package & "-lalr",
when LR1 => Elisp_Package & "-lr1");
begin
Create (File, Out_File, Elisp_Package_1 & "-elisp.el");
Set_Output (File);
Put_Line (";;; " & Elisp_Package_1 & "-elisp.el --- Generated parser support file -*- lexical-binding:t -*-");
Put_Command_Line (Elisp_Comment & " ", Use_Tuple => True, Tuple => Tuple);
Put_Raw_Code (Elisp_Comment, Input_Data.Raw_Code (Copyright_License));
Put_Raw_Code (Elisp_Comment, Input_Data.Raw_Code (Actions_Spec_Context));
New_Line;
Put_Line ("(require 'wisi)");
Put_Line ("(require 'wisi-compile)");
Put_Line ("(require 'wisi-elisp-parse)");
New_Line;
Output_Elisp_Common.Indent_Keyword_Table
(Elisp_Package_1, "elisp", Input_Data.Tokens.Keywords, To_String'Access);
New_Line;
Output_Elisp_Common.Indent_Token_Table (Elisp_Package_1, "elisp", Input_Data.Tokens.Tokens, To_String'Access);
New_Line;
Output (Elisp_Package_1, Input_Data.Tokens, Generate_Data.LR_Parse_Table, Generate_Data.Descriptor.all);
New_Line;
Put_Line ("(provide '" & Elisp_Package_1 & "-elisp)");
Put_Line (";; end of file");
Close (File);
Set_Output (Standard_Output);
end Create_Elisp;
begin
Create_Elisp (Tuple.Gen_Alg);
if WisiToken.Trace_Generate > 0 then
WisiToken.BNF.Generate_Utils.Put_Stats (Input_Data, Generate_Data);
end if;
end WisiToken.BNF.Output_Elisp;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . I M G _ R E A L --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- 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.Img_LLU; use System.Img_LLU;
with System.Img_Uns; use System.Img_Uns;
with System.Powten_Table; use System.Powten_Table;
with System.Unsigned_Types; use System.Unsigned_Types;
with System.Float_Control;
package body System.Img_Real is
-- The following defines the maximum number of digits that we can convert
-- accurately. This is limited by the precision of Long_Long_Float, and
-- also by the number of digits we can hold in Long_Long_Unsigned, which
-- is the integer type we use as an intermediate for the result.
-- We assume that in practice, the limitation will come from the digits
-- value, rather than the integer value. This is true for typical IEEE
-- implementations, and at worst, the only loss is for some precision
-- in very high precision floating-point output.
-- Note that in the following, the "-2" accounts for the sign and one
-- extra digits, since we need the maximum number of 9's that can be
-- supported, e.g. for the normal 64 bit case, Long_Long_Integer'Width
-- is 21, since the maximum value (approx 1.6 * 10**19) has 20 digits,
-- but the maximum number of 9's that can be supported is 19.
Maxdigs : constant :=
Natural'Min
(Long_Long_Unsigned'Width - 2, Long_Long_Float'Digits);
Unsdigs : constant := Unsigned'Width - 2;
-- Number of digits that can be converted using type Unsigned
-- See above for the explanation of the -2.
Maxscaling : constant := 5000;
-- Max decimal scaling required during conversion of floating-point
-- numbers to decimal. This is used to defend against infinite
-- looping in the conversion, as can be caused by erroneous executions.
-- The largest exponent used on any current system is 2**16383, which
-- is approximately 10**4932, and the highest number of decimal digits
-- is about 35 for 128-bit floating-point formats, so 5000 leaves
-- enough room for scaling such values
function Is_Negative (V : Long_Long_Float) return Boolean;
pragma Import (Intrinsic, Is_Negative);
--------------------------
-- Image_Floating_Point --
--------------------------
procedure Image_Floating_Point
(V : Long_Long_Float;
S : in out String;
P : out Natural;
Digs : Natural)
is
pragma Assert (S'First = 1);
begin
-- Decide whether a blank should be prepended before the call to
-- Set_Image_Real. We generate a blank for positive values, and
-- also for positive zeroes. For negative zeroes, we generate a
-- space only if Signed_Zeroes is True (the RM only permits the
-- output of -0.0 on targets where this is the case). We can of
-- course still see a -0.0 on a target where Signed_Zeroes is
-- False (since this attribute refers to the proper handling of
-- negative zeroes, not to their existence). We do not generate
-- a blank for positive infinity, since we output an explicit +.
if (not Is_Negative (V) and then V <= Long_Long_Float'Last)
or else (not Long_Long_Float'Signed_Zeros and then V = -0.0)
then
S (1) := ' ';
P := 1;
else
P := 0;
end if;
Set_Image_Real (V, S, P, 1, Digs - 1, 3);
end Image_Floating_Point;
--------------------------------
-- Image_Ordinary_Fixed_Point --
--------------------------------
procedure Image_Ordinary_Fixed_Point
(V : Long_Long_Float;
S : in out String;
P : out Natural;
Aft : Natural)
is
pragma Assert (S'First = 1);
begin
-- Output space at start if non-negative
if V >= 0.0 then
S (1) := ' ';
P := 1;
else
P := 0;
end if;
Set_Image_Real (V, S, P, 1, Aft, 0);
end Image_Ordinary_Fixed_Point;
--------------------
-- Set_Image_Real --
--------------------
procedure Set_Image_Real
(V : Long_Long_Float;
S : out String;
P : in out Natural;
Fore : Natural;
Aft : Natural;
Exp : Natural)
is
NFrac : constant Natural := Natural'Max (Aft, 1);
Sign : Character;
X : Long_Long_Float;
Scale : Integer;
Expon : Integer;
Field_Max : constant := 255;
-- This should be the same value as Ada.[Wide_]Text_IO.Field'Last.
-- It is not worth dragging in Ada.Text_IO to pick up this value,
-- since it really should never be necessary to change it.
Digs : String (1 .. 2 * Field_Max + 16);
-- Array used to hold digits of converted integer value. This is a
-- large enough buffer to accommodate ludicrous values of Fore and Aft.
Ndigs : Natural;
-- Number of digits stored in Digs (and also subscript of last digit)
procedure Adjust_Scale (S : Natural);
-- Adjusts the value in X by multiplying or dividing by a power of
-- ten so that it is in the range 10**(S-1) <= X < 10**S. Includes
-- adding 0.5 to round the result, readjusting if the rounding causes
-- the result to wander out of the range. Scale is adjusted to reflect
-- the power of ten used to divide the result (i.e. one is added to
-- the scale value for each division by 10.0, or one is subtracted
-- for each multiplication by 10.0).
procedure Convert_Integer;
-- Takes the value in X, outputs integer digits into Digs. On return,
-- Ndigs is set to the number of digits stored. The digits are stored
-- in Digs (1 .. Ndigs),
procedure Set (C : Character);
-- Sets character C in output buffer
procedure Set_Blanks_And_Sign (N : Integer);
-- Sets leading blanks and minus sign if needed. N is the number of
-- positions to be filled (a minus sign is output even if N is zero
-- or negative, but for a positive value, if N is non-positive, then
-- the call has no effect).
procedure Set_Digs (S, E : Natural);
-- Set digits S through E from Digs buffer. No effect if S > E
procedure Set_Special_Fill (N : Natural);
-- After outputting +Inf, -Inf or NaN, this routine fills out the
-- rest of the field with * characters. The argument is the number
-- of characters output so far (either 3 or 4)
procedure Set_Zeros (N : Integer);
-- Set N zeros, no effect if N is negative
pragma Inline (Set);
pragma Inline (Set_Digs);
pragma Inline (Set_Zeros);
------------------
-- Adjust_Scale --
------------------
procedure Adjust_Scale (S : Natural) is
Lo : Natural;
Hi : Natural;
Mid : Natural;
XP : Long_Long_Float;
begin
-- Cases where scaling up is required
if X < Powten (S - 1) then
-- What we are looking for is a power of ten to multiply X by
-- so that the result lies within the required range.
loop
XP := X * Powten (Maxpow);
exit when XP >= Powten (S - 1) or else Scale < -Maxscaling;
X := XP;
Scale := Scale - Maxpow;
end loop;
-- The following exception is only raised in case of erroneous
-- execution, where a number was considered valid but still
-- fails to scale up. One situation where this can happen is
-- when a system which is supposed to be IEEE-compliant, but
-- has been reconfigured to flush denormals to zero.
if Scale < -Maxscaling then
raise Constraint_Error;
end if;
-- Here we know that we must multiply by at least 10**1 and that
-- 10**Maxpow takes us too far: binary search to find right one.
-- Because of roundoff errors, it is possible for the value
-- of XP to be just outside of the interval when Lo >= Hi. In
-- that case we adjust explicitly by a factor of 10. This
-- can only happen with a value that is very close to an
-- exact power of 10.
Lo := 1;
Hi := Maxpow;
loop
Mid := (Lo + Hi) / 2;
XP := X * Powten (Mid);
if XP < Powten (S - 1) then
if Lo >= Hi then
Mid := Mid + 1;
XP := XP * 10.0;
exit;
else
Lo := Mid + 1;
end if;
elsif XP >= Powten (S) then
if Lo >= Hi then
Mid := Mid - 1;
XP := XP / 10.0;
exit;
else
Hi := Mid - 1;
end if;
else
exit;
end if;
end loop;
X := XP;
Scale := Scale - Mid;
-- Cases where scaling down is required
elsif X >= Powten (S) then
-- What we are looking for is a power of ten to divide X by
-- so that the result lies within the required range.
loop
XP := X / Powten (Maxpow);
exit when XP < Powten (S) or else Scale > Maxscaling;
X := XP;
Scale := Scale + Maxpow;
end loop;
-- The following exception is only raised in case of erroneous
-- execution, where a number was considered valid but still
-- fails to scale up. One situation where this can happen is
-- when a system which is supposed to be IEEE-compliant, but
-- has been reconfigured to flush denormals to zero.
if Scale > Maxscaling then
raise Constraint_Error;
end if;
-- Here we know that we must divide by at least 10**1 and that
-- 10**Maxpow takes us too far, binary search to find right one.
Lo := 1;
Hi := Maxpow;
loop
Mid := (Lo + Hi) / 2;
XP := X / Powten (Mid);
if XP < Powten (S - 1) then
if Lo >= Hi then
XP := XP * 10.0;
Mid := Mid - 1;
exit;
else
Hi := Mid - 1;
end if;
elsif XP >= Powten (S) then
if Lo >= Hi then
XP := XP / 10.0;
Mid := Mid + 1;
exit;
else
Lo := Mid + 1;
end if;
else
exit;
end if;
end loop;
X := XP;
Scale := Scale + Mid;
-- Here we are already scaled right
else
null;
end if;
-- Round, readjusting scale if needed. Note that if a readjustment
-- occurs, then it is never necessary to round again, because there
-- is no possibility of such a second rounding causing a change.
X := X + 0.5;
if X >= Powten (S) then
X := X / 10.0;
Scale := Scale + 1;
end if;
end Adjust_Scale;
---------------------
-- Convert_Integer --
---------------------
procedure Convert_Integer is
begin
-- Use Unsigned routine if possible, since on many machines it will
-- be significantly more efficient than the Long_Long_Unsigned one.
if X < Powten (Unsdigs) then
Ndigs := 0;
Set_Image_Unsigned
(Unsigned (Long_Long_Float'Truncation (X)),
Digs, Ndigs);
-- But if we want more digits than fit in Unsigned, we have to use
-- the Long_Long_Unsigned routine after all.
else
Ndigs := 0;
Set_Image_Long_Long_Unsigned
(Long_Long_Unsigned (Long_Long_Float'Truncation (X)),
Digs, Ndigs);
end if;
end Convert_Integer;
---------
-- Set --
---------
procedure Set (C : Character) is
begin
P := P + 1;
S (P) := C;
end Set;
-------------------------
-- Set_Blanks_And_Sign --
-------------------------
procedure Set_Blanks_And_Sign (N : Integer) is
begin
if Sign = '-' then
for J in 1 .. N - 1 loop
Set (' ');
end loop;
Set ('-');
else
for J in 1 .. N loop
Set (' ');
end loop;
end if;
end Set_Blanks_And_Sign;
--------------
-- Set_Digs --
--------------
procedure Set_Digs (S, E : Natural) is
begin
for J in S .. E loop
Set (Digs (J));
end loop;
end Set_Digs;
----------------------
-- Set_Special_Fill --
----------------------
procedure Set_Special_Fill (N : Natural) is
F : Natural;
begin
F := Fore + 1 + Aft - N;
if Exp /= 0 then
F := F + Exp + 1;
end if;
for J in 1 .. F loop
Set ('*');
end loop;
end Set_Special_Fill;
---------------
-- Set_Zeros --
---------------
procedure Set_Zeros (N : Integer) is
begin
for J in 1 .. N loop
Set ('0');
end loop;
end Set_Zeros;
-- Start of processing for Set_Image_Real
begin
-- We call the floating-point processor reset routine so that we can
-- be sure the floating-point processor is properly set for conversion
-- calls. This is notably need on Windows, where calls to the operating
-- system randomly reset the processor into 64-bit mode.
System.Float_Control.Reset;
Scale := 0;
-- Deal with invalid values first,
if not V'Valid then
-- Note that we're taking our chances here, as V might be
-- an invalid bit pattern resulting from erroneous execution
-- (caused by using uninitialized variables for example).
-- No matter what, we'll at least get reasonable behavior,
-- converting to infinity or some other value, or causing an
-- exception to be raised is fine.
-- If the following test succeeds, then we definitely have
-- an infinite value, so we print Inf.
if V > Long_Long_Float'Last then
Set ('+');
Set ('I');
Set ('n');
Set ('f');
Set_Special_Fill (4);
-- In all other cases we print NaN
elsif V < Long_Long_Float'First then
Set ('-');
Set ('I');
Set ('n');
Set ('f');
Set_Special_Fill (4);
else
Set ('N');
Set ('a');
Set ('N');
Set_Special_Fill (3);
end if;
return;
end if;
-- Positive values
if V > 0.0 then
X := V;
Sign := '+';
-- Negative values
elsif V < 0.0 then
X := -V;
Sign := '-';
-- Zero values
elsif V = 0.0 then
if Long_Long_Float'Signed_Zeros and then Is_Negative (V) then
Sign := '-';
else
Sign := '+';
end if;
Set_Blanks_And_Sign (Fore - 1);
Set ('0');
Set ('.');
Set_Zeros (NFrac);
if Exp /= 0 then
Set ('E');
Set ('+');
Set_Zeros (Natural'Max (1, Exp - 1));
end if;
return;
else
-- It should not be possible for a NaN to end up here.
-- Either the 'Valid test has failed, or we have some form
-- of erroneous execution. Raise Constraint_Error instead of
-- attempting to go ahead printing the value.
raise Constraint_Error;
end if;
-- X and Sign are set here, and X is known to be a valid,
-- non-zero floating-point number.
-- Case of non-zero value with Exp = 0
if Exp = 0 then
-- First step is to multiply by 10 ** Nfrac to get an integer
-- value to be output, an then add 0.5 to round the result.
declare
NF : Natural := NFrac;
begin
loop
-- If we are larger than Powten (Maxdigs) now, then
-- we have too many significant digits, and we have
-- not even finished multiplying by NFrac (NF shows
-- the number of unaccounted-for digits).
if X >= Powten (Maxdigs) then
-- In this situation, we only to generate a reasonable
-- number of significant digits, and then zeroes after.
-- So first we rescale to get:
-- 10 ** (Maxdigs - 1) <= X < 10 ** Maxdigs
-- and then convert the resulting integer
Adjust_Scale (Maxdigs);
Convert_Integer;
-- If that caused rescaling, then add zeros to the end
-- of the number to account for this scaling. Also add
-- zeroes to account for the undone multiplications
for J in 1 .. Scale + NF loop
Ndigs := Ndigs + 1;
Digs (Ndigs) := '0';
end loop;
exit;
-- If multiplication is complete, then convert the resulting
-- integer after rounding (note that X is non-negative)
elsif NF = 0 then
X := X + 0.5;
Convert_Integer;
exit;
-- Otherwise we can go ahead with the multiplication. If it
-- can be done in one step, then do it in one step.
elsif NF < Maxpow then
X := X * Powten (NF);
NF := 0;
-- If it cannot be done in one step, then do partial scaling
else
X := X * Powten (Maxpow);
NF := NF - Maxpow;
end if;
end loop;
end;
-- If number of available digits is less or equal to NFrac,
-- then we need an extra zero before the decimal point.
if Ndigs <= NFrac then
Set_Blanks_And_Sign (Fore - 1);
Set ('0');
Set ('.');
Set_Zeros (NFrac - Ndigs);
Set_Digs (1, Ndigs);
-- Normal case with some digits before the decimal point
else
Set_Blanks_And_Sign (Fore - (Ndigs - NFrac));
Set_Digs (1, Ndigs - NFrac);
Set ('.');
Set_Digs (Ndigs - NFrac + 1, Ndigs);
end if;
-- Case of non-zero value with non-zero Exp value
else
-- If NFrac is less than Maxdigs, then all the fraction digits are
-- significant, so we can scale the resulting integer accordingly.
if NFrac < Maxdigs then
Adjust_Scale (NFrac + 1);
Convert_Integer;
-- Otherwise, we get the maximum number of digits available
else
Adjust_Scale (Maxdigs);
Convert_Integer;
for J in 1 .. NFrac - Maxdigs + 1 loop
Ndigs := Ndigs + 1;
Digs (Ndigs) := '0';
Scale := Scale - 1;
end loop;
end if;
Set_Blanks_And_Sign (Fore - 1);
Set (Digs (1));
Set ('.');
Set_Digs (2, Ndigs);
-- The exponent is the scaling factor adjusted for the digits
-- that we output after the decimal point, since these were
-- included in the scaled digits that we output.
Expon := Scale + NFrac;
Set ('E');
Ndigs := 0;
if Expon >= 0 then
Set ('+');
Set_Image_Unsigned (Unsigned (Expon), Digs, Ndigs);
else
Set ('-');
Set_Image_Unsigned (Unsigned (-Expon), Digs, Ndigs);
end if;
Set_Zeros (Exp - Ndigs - 1);
Set_Digs (1, Ndigs);
end if;
end Set_Image_Real;
end System.Img_Real;
|
with Ada.Text_IO; use Ada.Text_IO;
-- les N reines
procedure NQueens is
procedure PrintInt(N: Integer) is
C: Integer := N rem 10;
begin
if N > 9 then PrintInt(N / 10); end if;
Put(Character'Val(48 + C));
end;
-- des ensembles représentés par des entiers
Empty: Integer := 0;
function Mem(X, S: Integer) return Boolean is
begin
-- X est une puissance de 2
return (S / X) rem 2 = 1;
end;
-- décompte récursif
function Q(N: Integer) return Integer is
Full : Integer;
function T(A, B, C: Integer) return Integer is
F,D : Integer;
begin
if A = Empty then return 1; end if;
F := 0;
D := 1;
for I in 0 .. N-1 loop
if Mem(D, A) and then not Mem(D, B) and then not Mem(D, C) then
F := F + T(A-D, (B+D) * 2, (C+D) / 2);
end if;
D := 2 * D;
end loop;
return F;
end;
begin
Full := 0;
for I in 0 .. N-1 loop Full := 2 * Full + 1; end loop;
return T(Full, Empty, Empty);
end;
begin
for N in 1 .. 10 loop
Printint(N); Put(' ');
Printint(Q(N)); New_Line;
end loop;
end;
-- Local Variables:
-- compile-command: "gnatmake queens.adb && ./queens"
-- End:
|
with SPARKNaCl; use SPARKNaCl;
with SPARKNaCl.Debug; use SPARKNaCl.Debug;
with SPARKNaCl.Hashing; use SPARKNaCl.Hashing;
with Interfaces; use Interfaces;
procedure Hash
is
R1 : Bytes_64;
-- Case 1: same as NaCl standard test suite
M3 : constant String (1 .. 8) := "testing" & ASCII.LF;
M4 : Byte_Seq (0 .. 7);
-- Case 2: two blocks, with final block >= 112 bytes to cover
-- final block padding
M5 : constant Byte_Seq (0 .. 240) := (16#AA#, others => 0);
begin
for I in M4'Range loop
M4 (I) := Character'Pos (M3 (Integer (I + 1)));
end loop;
Hash (R1, M4);
DH ("Hash is", R1);
-- Functional style interface
R1 := Hash (M5);
DH ("Hash is", R1);
end Hash;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.DOM_Lists;
with XML.DOM.Entity_References;
with XML.DOM.Texts;
package body Matreshka.DOM_Attributes is
use type Matreshka.DOM_Nodes.Node_Access;
------------------
-- Constructors --
------------------
package body Constructors is
----------------
-- Initialize --
----------------
procedure Initialize
(Self : not null access Attribute_L1_Node'Class;
Document : not null Matreshka.DOM_Nodes.Document_Access) is
begin
Matreshka.DOM_Nodes.Constructors.Initialize (Self, Document);
end Initialize;
----------------
-- Initialize --
----------------
procedure Initialize
(Self : not null access Abstract_Attribute_L2_Node'Class;
Document : not null Matreshka.DOM_Nodes.Document_Access) is
begin
Matreshka.DOM_Nodes.Constructors.Initialize (Self, Document);
end Initialize;
end Constructors;
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Attribute_L2_Parameters)
return Attribute_L2_Node is
begin
return Self : Attribute_L2_Node do
Matreshka.DOM_Attributes.Constructors.Initialize
(Self'Unchecked_Access, Parameters.Document);
Self.Namespace_URI := Parameters.Namespace_URI;
Self.Prefix := Parameters.Prefix;
Self.Local_Name := Parameters.Local_Name;
end return;
end Create;
----------------
-- Enter_Node --
----------------
overriding procedure Enter_Node
(Self : not null access Abstract_Attribute_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control)
is
pragma Unreferenced (Self);
pragma Unreferenced (Visitor);
pragma Unreferenced (Control);
begin
raise Program_Error;
end Enter_Node;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Attribute_L2_Node)
return League.Strings.Universal_String is
begin
return Self.Local_Name;
end Get_Local_Name;
--------------
-- Get_Name --
--------------
overriding function Get_Name
(Self : not null access constant Attribute_L1_Node)
return League.Strings.Universal_String is
begin
raise Program_Error;
return League.Strings.Empty_Universal_String;
end Get_Name;
--------------
-- Get_Name --
--------------
overriding function Get_Name
(Self : not null access constant Abstract_Attribute_L2_Node)
return League.Strings.Universal_String is
begin
-- return Self.Get_Prefix & ':' & Self.Get_Local_Name;
raise Program_Error;
return League.Strings.Empty_Universal_String;
end Get_Name;
-----------------------
-- Get_Namespace_URI --
-----------------------
overriding function Get_Namespace_URI
(Self : not null access constant Attribute_L2_Node)
return League.Strings.Universal_String is
begin
return Self.Namespace_URI;
end Get_Namespace_URI;
----------------------
-- Get_Next_Sibling --
----------------------
overriding function Get_Next_Sibling
(Self : not null access constant Abstract_Attribute_Node)
return XML.DOM.Nodes.DOM_Node_Access
is
pragma Unreferenced (Self);
begin
return null;
end Get_Next_Sibling;
-------------------
-- Get_Node_Type --
-------------------
overriding function Get_Node_Type
(Self : not null access constant Abstract_Attribute_Node)
return XML.DOM.Node_Type
is
pragma Unreferenced (Self);
begin
return XML.DOM.Attribute_Node;
end Get_Node_Type;
-----------------------
-- Get_Owner_Element --
-----------------------
overriding function Get_Owner_Element
(Self : not null access constant Abstract_Attribute_Node)
return XML.DOM.Elements.DOM_Element_Access is
begin
return XML.DOM.Elements.DOM_Element_Access (Self.Parent);
end Get_Owner_Element;
---------------------
-- Get_Parent_Node --
---------------------
overriding function Get_Parent_Node
(Self : not null access constant Abstract_Attribute_Node)
return XML.DOM.Nodes.DOM_Node_Access
is
pragma Unreferenced (Self);
begin
return null;
end Get_Parent_Node;
--------------------------
-- Get_Previous_Sibling --
--------------------------
overriding function Get_Previous_Sibling
(Self : not null access constant Abstract_Attribute_Node)
return XML.DOM.Nodes.DOM_Node_Access
is
pragma Unreferenced (Self);
begin
return null;
end Get_Previous_Sibling;
---------------
-- Get_Value --
---------------
overriding function Get_Value
(Self : not null access constant Abstract_Attribute_Node)
return League.Strings.Universal_String
is
N : Matreshka.DOM_Nodes.Node_Access := Self.First;
begin
-- Lookup for the first DOM::Text child node by unwinding all
-- DOM::EntityReference nodes. Returns its whole text if it is found.
while N /= null loop
if N.all in XML.DOM.Texts.DOM_Text'Class then
return XML.DOM.Texts.DOM_Text_Access (N).Get_Whole_Text;
else
N := N.First;
end if;
end loop;
return League.Strings.Empty_Universal_String;
end Get_Value;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Abstract_Attribute_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control)
is
pragma Unreferenced (Self);
pragma Unreferenced (Visitor);
pragma Unreferenced (Control);
begin
raise Program_Error;
end Leave_Node;
---------------
-- Set_Value --
---------------
overriding procedure Set_Value
(Self : not null access Abstract_Attribute_Node;
New_Value : League.Strings.Universal_String)
is
Node : Matreshka.DOM_Nodes.Node_Access;
Text : XML.DOM.Texts.DOM_Text_Access;
begin
-- Remove all existing child nodes.
while Self.First /= null loop
Node := Self.First;
Matreshka.DOM_Lists.Remove_From_Children (Node);
Matreshka.DOM_Lists.Insert_Into_Detached (Node);
end loop;
-- Create new text node and set its value.
Text := Self.Document.Create_Text_Node (New_Value);
Self.Append_Child (XML.DOM.Nodes.DOM_Node_Access (Text));
end Set_Value;
----------------
-- Visit_Node --
----------------
overriding procedure Visit_Node
(Self : not null access Abstract_Attribute_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control)
is
pragma Unreferenced (Self);
pragma Unreferenced (Visitor);
pragma Unreferenced (Control);
begin
raise Program_Error;
end Visit_Node;
end Matreshka.DOM_Attributes;
|
with
Ada.Integer_Text_IO,
Ada.Text_IO;
with
JSA.Intermediate_Backups;
package body JSA.Tests.Intermediate_Backups is
overriding
procedure Initialize (T : in out Test) is
use Ahven.Framework;
begin
T.Set_Name ("Intermediate backups");
Add_Test_Routine (T, Run'Access, "Run");
end Initialize;
procedure Run is
Counter : Natural := 0;
procedure Save_Counter;
procedure Save_Counter is
begin
Ada.Text_IO.Put ("Backup of counter: ");
Ada.Integer_Text_IO.Put (Counter);
Ada.Text_IO.New_Line;
end Save_Counter;
package Backups is
new JSA.Intermediate_Backups (Fraction => 0.01,
Save_State => Save_Counter);
begin
Backups.Begin_Loop;
for I in 1 .. 1_000 loop
Counter := Counter + 1;
for J in 1 .. 100_000 loop
if J mod 2 = 0 then
Counter := Counter + 1;
else
Counter := Counter - 1;
end if;
end loop;
Backups.End_Of_Iteration;
end loop;
Backups.End_Loop;
end Run;
end JSA.Tests.Intermediate_Backups;
|
-- Copyright 2015 Steven Stewart-Gallus
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-- implied. See the License for the specific language governing
-- permissions and limitations under the License.
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings;
package Libc.Locale with
Spark_Mode => Off is
pragma Preelaborate;
-- unsupported macro: LC_ALL __LC_ALL
-- unsupported macro: LC_CTYPE __LC_CTYPE
-- unsupported macro: LC_NUMERIC __LC_NUMERIC
-- unsupported macro: LC_COLLATE __LC_COLLATE
-- unsupported macro: LC_MONETARY __LC_MONETARY
-- unsupported macro: LC_TIME __LC_TIME
type lconv is record
decimal_point : Interfaces.C.Strings
.chars_ptr; -- /usr/include/locale.h:57
thousands_sep : Interfaces.C.Strings
.chars_ptr; -- /usr/include/locale.h:58
grouping : Interfaces.C.Strings.chars_ptr; -- /usr/include/locale.h:64
int_curr_symbol : Interfaces.C.Strings
.chars_ptr; -- /usr/include/locale.h:70
currency_symbol : Interfaces.C.Strings
.chars_ptr; -- /usr/include/locale.h:71
mon_decimal_point : Interfaces.C.Strings
.chars_ptr; -- /usr/include/locale.h:72
mon_thousands_sep : Interfaces.C.Strings
.chars_ptr; -- /usr/include/locale.h:73
mon_grouping : Interfaces.C.Strings
.chars_ptr; -- /usr/include/locale.h:74
positive_sign : Interfaces.C.Strings
.chars_ptr; -- /usr/include/locale.h:75
negative_sign : Interfaces.C.Strings
.chars_ptr; -- /usr/include/locale.h:76
int_frac_digits : aliased char; -- /usr/include/locale.h:77
frac_digits : aliased char; -- /usr/include/locale.h:78
p_cs_precedes : aliased char; -- /usr/include/locale.h:80
p_sep_by_space : aliased char; -- /usr/include/locale.h:82
n_cs_precedes : aliased char; -- /usr/include/locale.h:84
n_sep_by_space : aliased char; -- /usr/include/locale.h:86
p_sign_posn : aliased char; -- /usr/include/locale.h:93
n_sign_posn : aliased char; -- /usr/include/locale.h:94
int_p_cs_precedes : aliased char; -- /usr/include/locale.h:97
int_p_sep_by_space : aliased char; -- /usr/include/locale.h:99
int_n_cs_precedes : aliased char; -- /usr/include/locale.h:101
int_n_sep_by_space : aliased char; -- /usr/include/locale.h:103
int_p_sign_posn : aliased char; -- /usr/include/locale.h:110
int_n_sign_posn : aliased char; -- /usr/include/locale.h:111
end record;
pragma Convention (C_Pass_By_Copy, lconv); -- /usr/include/locale.h:53
function setlocale
(category : int;
locale : Interfaces.C.Strings.chars_ptr)
return Interfaces.C.Strings.chars_ptr; -- /usr/include/locale.h:124
pragma Import (C, setlocale, "setlocale");
function localeconv return access lconv; -- /usr/include/locale.h:127
pragma Import (C, localeconv, "localeconv");
end Libc.Locale;
|
with System; use System;
with SAM.TC; use SAM.TC;
with SAM.SERCOM.USART; use SAM.SERCOM.USART;
with SAM.SERCOM.SPI; use SAM.SERCOM.SPI;
with SAM.SERCOM.I2C; use SAM.SERCOM.I2C;
with SAM.SERCOM; use SAM.SERCOM;
with SAM.Port; use SAM.Port;
with SAM.ADC; use SAM.ADC;
-- Generated by a script from an "avr tools device file" (atdf)
package SAM.Device is
-- ADC0 --
ADC0_Internal : aliased SAM.ADC.ADC_Internal
with Import, Address => System'To_Address (16#43001C00#);
ADC0 : aliased SAM.ADC.ADC_Device (ADC0_Internal'Access);
-- ADC1 --
ADC1_Internal : aliased SAM.ADC.ADC_Internal
with Import, Address => System'To_Address (16#43002000#);
ADC1 : aliased SAM.ADC.ADC_Device (ADC1_Internal'Access);
-- PORTA --
PORTA_Internal : aliased Port_Internal
with Import, Address => System'To_Address (16#41008000# + 16#000#);
PORTA : aliased Port_Controller (PORTA_Internal'Access);
PA00 : aliased GPIO_Point (PORTA'Access, 0);
PA01 : aliased GPIO_Point (PORTA'Access, 1);
PA02 : aliased GPIO_Point (PORTA'Access, 2);
PA03 : aliased GPIO_Point (PORTA'Access, 3);
PA04 : aliased GPIO_Point (PORTA'Access, 4);
PA05 : aliased GPIO_Point (PORTA'Access, 5);
PA06 : aliased GPIO_Point (PORTA'Access, 6);
PA07 : aliased GPIO_Point (PORTA'Access, 7);
PA08 : aliased GPIO_Point (PORTA'Access, 8);
PA09 : aliased GPIO_Point (PORTA'Access, 9);
PA10 : aliased GPIO_Point (PORTA'Access, 10);
PA11 : aliased GPIO_Point (PORTA'Access, 11);
PA12 : aliased GPIO_Point (PORTA'Access, 12);
PA13 : aliased GPIO_Point (PORTA'Access, 13);
PA14 : aliased GPIO_Point (PORTA'Access, 14);
PA15 : aliased GPIO_Point (PORTA'Access, 15);
PA16 : aliased GPIO_Point (PORTA'Access, 16);
PA17 : aliased GPIO_Point (PORTA'Access, 17);
PA18 : aliased GPIO_Point (PORTA'Access, 18);
PA19 : aliased GPIO_Point (PORTA'Access, 19);
PA20 : aliased GPIO_Point (PORTA'Access, 20);
PA21 : aliased GPIO_Point (PORTA'Access, 21);
PA22 : aliased GPIO_Point (PORTA'Access, 22);
PA23 : aliased GPIO_Point (PORTA'Access, 23);
PA24 : aliased GPIO_Point (PORTA'Access, 24);
PA25 : aliased GPIO_Point (PORTA'Access, 25);
PA26 : aliased GPIO_Point (PORTA'Access, 26);
PA27 : aliased GPIO_Point (PORTA'Access, 27);
PA28 : aliased GPIO_Point (PORTA'Access, 28);
PA29 : aliased GPIO_Point (PORTA'Access, 29);
PA30 : aliased GPIO_Point (PORTA'Access, 30);
PA31 : aliased GPIO_Point (PORTA'Access, 31);
-- PORTB --
PORTB_Internal : aliased Port_Internal
with Import, Address => System'To_Address (16#41008000# + 16#080#);
PORTB : aliased Port_Controller (PORTB_Internal'Access);
PB00 : aliased GPIO_Point (PORTB'Access, 0);
PB01 : aliased GPIO_Point (PORTB'Access, 1);
PB02 : aliased GPIO_Point (PORTB'Access, 2);
PB03 : aliased GPIO_Point (PORTB'Access, 3);
PB04 : aliased GPIO_Point (PORTB'Access, 4);
PB05 : aliased GPIO_Point (PORTB'Access, 5);
PB06 : aliased GPIO_Point (PORTB'Access, 6);
PB07 : aliased GPIO_Point (PORTB'Access, 7);
PB08 : aliased GPIO_Point (PORTB'Access, 8);
PB09 : aliased GPIO_Point (PORTB'Access, 9);
PB10 : aliased GPIO_Point (PORTB'Access, 10);
PB11 : aliased GPIO_Point (PORTB'Access, 11);
PB12 : aliased GPIO_Point (PORTB'Access, 12);
PB13 : aliased GPIO_Point (PORTB'Access, 13);
PB14 : aliased GPIO_Point (PORTB'Access, 14);
PB15 : aliased GPIO_Point (PORTB'Access, 15);
PB16 : aliased GPIO_Point (PORTB'Access, 16);
PB17 : aliased GPIO_Point (PORTB'Access, 17);
PB18 : aliased GPIO_Point (PORTB'Access, 18);
PB19 : aliased GPIO_Point (PORTB'Access, 19);
PB20 : aliased GPIO_Point (PORTB'Access, 20);
PB21 : aliased GPIO_Point (PORTB'Access, 21);
PB22 : aliased GPIO_Point (PORTB'Access, 22);
PB23 : aliased GPIO_Point (PORTB'Access, 23);
PB24 : aliased GPIO_Point (PORTB'Access, 24);
PB25 : aliased GPIO_Point (PORTB'Access, 25);
PB26 : aliased GPIO_Point (PORTB'Access, 26);
PB27 : aliased GPIO_Point (PORTB'Access, 27);
PB28 : aliased GPIO_Point (PORTB'Access, 28);
PB29 : aliased GPIO_Point (PORTB'Access, 29);
PB30 : aliased GPIO_Point (PORTB'Access, 30);
PB31 : aliased GPIO_Point (PORTB'Access, 31);
-- PORTC --
PORTC_Internal : aliased Port_Internal
with Import, Address => System'To_Address (16#41008000# + 16#100#);
PORTC : aliased Port_Controller (PORTC_Internal'Access);
PC00 : aliased GPIO_Point (PORTC'Access, 0);
PC01 : aliased GPIO_Point (PORTC'Access, 1);
PC02 : aliased GPIO_Point (PORTC'Access, 2);
PC03 : aliased GPIO_Point (PORTC'Access, 3);
PC04 : aliased GPIO_Point (PORTC'Access, 4);
PC05 : aliased GPIO_Point (PORTC'Access, 5);
PC06 : aliased GPIO_Point (PORTC'Access, 6);
PC07 : aliased GPIO_Point (PORTC'Access, 7);
PC08 : aliased GPIO_Point (PORTC'Access, 8);
PC09 : aliased GPIO_Point (PORTC'Access, 9);
PC10 : aliased GPIO_Point (PORTC'Access, 10);
PC11 : aliased GPIO_Point (PORTC'Access, 11);
PC12 : aliased GPIO_Point (PORTC'Access, 12);
PC13 : aliased GPIO_Point (PORTC'Access, 13);
PC14 : aliased GPIO_Point (PORTC'Access, 14);
PC15 : aliased GPIO_Point (PORTC'Access, 15);
PC16 : aliased GPIO_Point (PORTC'Access, 16);
PC17 : aliased GPIO_Point (PORTC'Access, 17);
PC18 : aliased GPIO_Point (PORTC'Access, 18);
PC19 : aliased GPIO_Point (PORTC'Access, 19);
PC20 : aliased GPIO_Point (PORTC'Access, 20);
PC21 : aliased GPIO_Point (PORTC'Access, 21);
PC22 : aliased GPIO_Point (PORTC'Access, 22);
PC23 : aliased GPIO_Point (PORTC'Access, 23);
PC24 : aliased GPIO_Point (PORTC'Access, 24);
PC25 : aliased GPIO_Point (PORTC'Access, 25);
PC26 : aliased GPIO_Point (PORTC'Access, 26);
PC27 : aliased GPIO_Point (PORTC'Access, 27);
PC28 : aliased GPIO_Point (PORTC'Access, 28);
PC29 : aliased GPIO_Point (PORTC'Access, 29);
PC30 : aliased GPIO_Point (PORTC'Access, 30);
PC31 : aliased GPIO_Point (PORTC'Access, 31);
-- SERCOM0 --
SERCOM0_Internal : aliased SAM.SERCOM.SERCOM_Internal
with Import, Address => System'To_Address (16#40003000#);
SPI0 : aliased SAM.SERCOM.SPI.SPI_Device (SERCOM0_Internal'Access);
I2C0 : aliased SAM.SERCOM.I2C.I2C_Device (SERCOM0_Internal'Access);
USART0 : aliased SAM.SERCOM.USART.USART_Device (SERCOM0_Internal'Access);
-- SERCOM1 --
SERCOM1_Internal : aliased SAM.SERCOM.SERCOM_Internal
with Import, Address => System'To_Address (16#40003400#);
SPI1 : aliased SAM.SERCOM.SPI.SPI_Device (SERCOM1_Internal'Access);
I2C1 : aliased SAM.SERCOM.I2C.I2C_Device (SERCOM1_Internal'Access);
USART1 : aliased SAM.SERCOM.USART.USART_Device (SERCOM1_Internal'Access);
-- SERCOM2 --
SERCOM2_Internal : aliased SAM.SERCOM.SERCOM_Internal
with Import, Address => System'To_Address (16#41012000#);
SPI2 : aliased SAM.SERCOM.SPI.SPI_Device (SERCOM2_Internal'Access);
I2C2 : aliased SAM.SERCOM.I2C.I2C_Device (SERCOM2_Internal'Access);
USART2 : aliased SAM.SERCOM.USART.USART_Device (SERCOM2_Internal'Access);
-- SERCOM3 --
SERCOM3_Internal : aliased SAM.SERCOM.SERCOM_Internal
with Import, Address => System'To_Address (16#41014000#);
SPI3 : aliased SAM.SERCOM.SPI.SPI_Device (SERCOM3_Internal'Access);
I2C3 : aliased SAM.SERCOM.I2C.I2C_Device (SERCOM3_Internal'Access);
USART3 : aliased SAM.SERCOM.USART.USART_Device (SERCOM3_Internal'Access);
-- SERCOM4 --
SERCOM4_Internal : aliased SAM.SERCOM.SERCOM_Internal
with Import, Address => System'To_Address (16#43000000#);
SPI4 : aliased SAM.SERCOM.SPI.SPI_Device (SERCOM4_Internal'Access);
I2C4 : aliased SAM.SERCOM.I2C.I2C_Device (SERCOM4_Internal'Access);
USART4 : aliased SAM.SERCOM.USART.USART_Device (SERCOM4_Internal'Access);
-- SERCOM5 --
SERCOM5_Internal : aliased SAM.SERCOM.SERCOM_Internal
with Import, Address => System'To_Address (16#43000400#);
SPI5 : aliased SAM.SERCOM.SPI.SPI_Device (SERCOM5_Internal'Access);
I2C5 : aliased SAM.SERCOM.I2C.I2C_Device (SERCOM5_Internal'Access);
USART5 : aliased SAM.SERCOM.USART.USART_Device (SERCOM5_Internal'Access);
-- SERCOM6 --
SERCOM6_Internal : aliased SAM.SERCOM.SERCOM_Internal
with Import, Address => System'To_Address (16#43000800#);
SPI6 : aliased SAM.SERCOM.SPI.SPI_Device (SERCOM6_Internal'Access);
I2C6 : aliased SAM.SERCOM.I2C.I2C_Device (SERCOM6_Internal'Access);
USART6 : aliased SAM.SERCOM.USART.USART_Device (SERCOM6_Internal'Access);
-- SERCOM7 --
SERCOM7_Internal : aliased SAM.SERCOM.SERCOM_Internal
with Import, Address => System'To_Address (16#43000C00#);
SPI7 : aliased SAM.SERCOM.SPI.SPI_Device (SERCOM7_Internal'Access);
I2C7 : aliased SAM.SERCOM.I2C.I2C_Device (SERCOM7_Internal'Access);
USART7 : aliased SAM.SERCOM.USART.USART_Device (SERCOM7_Internal'Access);
-- TC0 --
TC0_Internal : aliased SAM.TC.TC_Internal
with Import, Address => System'To_Address (16#40003800#);
TC0 : aliased SAM.TC.TC_Device (TC0_Internal'Access, Master => True);
-- TC1 --
TC1_Internal : aliased SAM.TC.TC_Internal
with Import, Address => System'To_Address (16#40003C00#);
TC1 : aliased SAM.TC.TC_Device (TC1_Internal'Access, Master => False);
-- TC2 --
TC2_Internal : aliased SAM.TC.TC_Internal
with Import, Address => System'To_Address (16#4101A000#);
TC2 : aliased SAM.TC.TC_Device (TC2_Internal'Access, Master => True);
-- TC3 --
TC3_Internal : aliased SAM.TC.TC_Internal
with Import, Address => System'To_Address (16#4101C000#);
TC3 : aliased SAM.TC.TC_Device (TC3_Internal'Access, Master => False);
-- TC4 --
TC4_Internal : aliased SAM.TC.TC_Internal
with Import, Address => System'To_Address (16#42001400#);
TC4 : aliased SAM.TC.TC_Device (TC4_Internal'Access, Master => True);
-- TC5 --
TC5_Internal : aliased SAM.TC.TC_Internal
with Import, Address => System'To_Address (16#42001800#);
TC5 : aliased SAM.TC.TC_Device (TC5_Internal'Access, Master => False);
-- TC6 --
TC6_Internal : aliased SAM.TC.TC_Internal
with Import, Address => System'To_Address (16#43001400#);
TC6 : aliased SAM.TC.TC_Device (TC6_Internal'Access, Master => True);
-- TC7 --
TC7_Internal : aliased SAM.TC.TC_Internal
with Import, Address => System'To_Address (16#43001800#);
TC7 : aliased SAM.TC.TC_Device (TC7_Internal'Access, Master => False);
end SAM.Device;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../../License.txt
package body AdaBase.Driver.Base is
------------------------
-- trait_autocommit --
------------------------
overriding
function trait_autocommit (driver : Base_Driver) return Boolean is
begin
return driver.connection.autoCommit;
end trait_autocommit;
-------------------------
-- trait_column_case --
-------------------------
overriding
function trait_column_case (driver : Base_Driver) return Case_Modes is
begin
return driver.connection.getCaseMode;
end trait_column_case;
------------------------
-- trait_error_mode --
------------------------
overriding
function trait_error_mode (driver : Base_Driver) return Error_Modes is
begin
return logger.error_mode;
end trait_error_mode;
-----------------------
-- trait_connected --
-----------------------
overriding
function trait_connected (driver : Base_Driver) return Boolean is
begin
return driver.connection.connected;
end trait_connected;
--------------------
-- trait_driver --
--------------------
overriding
function trait_driver (driver : Base_Driver) return String is
begin
return driver.connection.description;
end trait_driver;
-------------------------
-- trait_client_info --
-------------------------
overriding
function trait_client_info (driver : Base_Driver) return String is
begin
return driver.connection.clientInfo;
end trait_client_info;
----------------------------
-- trait_client_version --
----------------------------
overriding
function trait_client_version (driver : Base_Driver) return String is
begin
return driver.connection.clientVersion;
end trait_client_version;
-------------------------
-- trait_server_info --
-------------------------
overriding
function trait_server_info (driver : Base_Driver) return String is
begin
return driver.connection.serverInfo;
end trait_server_info;
----------------------------
-- trait_server_version --
----------------------------
overriding
function trait_server_version (driver : Base_Driver) return String is
begin
return driver.connection.serverVersion;
end trait_server_version;
---------------------------
-- trait_max_blob_size --
---------------------------
overriding
function trait_max_blob_size (driver : Base_Driver) return BLOB_Maximum is
begin
return driver.connection.maxBlobSize;
end trait_max_blob_size;
---------------------------
-- trait_character_set --
---------------------------
overriding
function trait_character_set (driver : Base_Driver) return String is
begin
return driver.connection.character_set;
end trait_character_set;
----------------------------
-- set_trait_autocommit --
----------------------------
overriding
procedure set_trait_autocommit (driver : Base_Driver; trait : Boolean) is
begin
driver.connection.setAutoCommit (auto => trait);
end set_trait_autocommit;
-----------------------------
-- set_trait_column_case --
-----------------------------
overriding
procedure set_trait_column_case (driver : Base_Driver; trait : Case_Modes)
is
begin
driver.connection.setCaseMode (mode => trait);
end set_trait_column_case;
----------------------------
-- set_trait_error_mode --
----------------------------
overriding
procedure set_trait_error_mode (driver : Base_Driver; trait : Error_Modes)
is
begin
logger.set_error_mode (mode => trait);
end set_trait_error_mode;
-------------------------------
-- set_trait_max_blob_size --
-------------------------------
overriding
procedure set_trait_max_blob_size (driver : Base_Driver;
trait : BLOB_Maximum) is
begin
driver.connection.setMaxBlobSize (maxsize => trait);
end set_trait_max_blob_size;
------------------------------------
-- set_trait_multiquery_enabled --
------------------------------------
overriding
procedure set_trait_multiquery_enabled (driver : Base_Driver;
trait : Boolean)
is
begin
driver.connection.setMultiQuery (multiple => trait);
end set_trait_multiquery_enabled;
-------------------------------
-- set_trait_character_set --
-------------------------------
overriding
procedure set_trait_character_set (driver : Base_Driver; trait : String) is
begin
driver.connection.set_character_set (charset => trait);
end set_trait_character_set;
--------------------------------
-- trait_multiquery_enabled --
--------------------------------
overriding
function trait_multiquery_enabled (driver : Base_Driver) return Boolean is
begin
return driver.connection.multiquery;
end trait_multiquery_enabled;
-----------------------
-- standard_logger --
-----------------------
overriding
procedure command_standard_logger (driver : Base_Driver;
device : ALF.TLogger;
action : ALF.TAction) is
begin
logger.standard_logger (logger => device, action => action);
end command_standard_logger;
---------------------------
-- set_logger_filename --
---------------------------
overriding
procedure set_logger_filename (driver : Base_Driver; filename : String) is
begin
logger.set_log_file (filename);
end set_logger_filename;
----------------------------
-- detach_custom_logger --
----------------------------
overriding
procedure detach_custom_logger (driver : Base_Driver) is
begin
logger.detach_custom_logger;
end detach_custom_logger;
----------------------------
-- attach_custom_logger --
----------------------------
overriding
procedure attach_custom_logger
(driver : Base_Driver;
logger_access : ALF.AL.BaseClass_Logger_access) is
begin
logger.attach_custom_logger (logger_access => logger_access);
end attach_custom_logger;
-------------------------
-- query_clear_table --
-------------------------
overriding
procedure query_clear_table (driver : Base_Driver; table : String)
is
sql : constant String := "TRUNCATE " & table;
AR : Affected_Rows;
begin
AR := execute (driver => Base_Driver'Class (driver), sql => sql);
end query_clear_table;
------------------------
-- query_drop_table --
------------------------
overriding
procedure query_drop_table (driver : Base_Driver;
tables : String;
when_exists : Boolean := False;
cascade : Boolean := False)
is
use type Driver_Type;
-- MySQL accepts CASCADE but ignores it
-- MySQL and PostgreSQL can use this versions, but Firebird
-- needs if_exists implementation and doesn't know CASCADE, so it
-- needs an overriding implementation.
sql : CT.Text;
AR : Affected_Rows;
begin
if cascade and then driver.dialect = driver_mysql
then
driver.log_nominal (category => note, message =>
CT.SUS ("Requested CASCADE has no effect on MySQL"));
end if;
case when_exists is
when True => sql := CT.SUS ("DROP TABLE IF EXISTS " & tables);
when False => sql := CT.SUS ("DROP TABLE " & tables);
end case;
if cascade then
CT.SU.Append (Source => sql, New_Item => " CASCADE");
end if;
AR := execute (driver => Base_Driver'Class (driver),
sql => CT.USS (sql));
end query_drop_table;
------------------
-- disconnect --
------------------
overriding
procedure disconnect (driver : out Base_Driver)
is
msg : constant CT.Text :=
CT.SUS ("Disconnect From " & CT.USS (driver.database) & "database");
err : constant CT.Text :=
CT.SUS ("ACK! Disconnect attempted on inactive connection");
begin
if driver.connection_active then
driver.connection.disconnect;
driver.connection_active := False;
driver.log_nominal (category => disconnecting,
message => msg);
else
-- Non-fatal attempt to disconnect db when none is connected
driver.log_problem (category => disconnecting,
message => err);
end if;
end disconnect;
----------------
-- rollback --
----------------
overriding
procedure rollback (driver : Base_Driver)
is
use type Trax_Isolation;
err1 : constant CT.Text :=
CT.SUS ("ACK! Rollback attempted on inactive connection");
err2 : constant CT.Text :=
CT.SUS ("ACK! Rollback attempted when autocommit mode set on");
err3 : constant CT.Text :=
CT.SUS ("Rollback attempt failed");
msg1 : constant CT.Text := CT.SUS ("ROLLBACK TRANSACTION");
begin
if not driver.connection_active then
-- Non-fatal attempt to roll back when no database is connected
driver.log_problem (category => miscellaneous,
message => err1);
return;
end if;
if driver.connection.autoCommit then
-- Non-fatal attempt to roll back when autocommit is on
driver.log_problem (category => miscellaneous,
message => err2);
return;
end if;
driver.connection.rollback;
driver.log_nominal (category => transaction, message => msg1);
exception
when others =>
driver.log_problem (category => miscellaneous,
message => err3,
pull_codes => True);
end rollback;
--------------
-- commit --
--------------
overriding
procedure commit (driver : Base_Driver)
is
use type Trax_Isolation;
err1 : constant CT.Text :=
CT.SUS ("ACK! Commit attempted on inactive connection");
err2 : constant CT.Text :=
CT.SUS ("ACK! Commit attempted when autocommit mode set on");
err3 : constant CT.Text := CT.SUS ("Commit attempt failed");
msg1 : constant CT.Text := CT.SUS ("END TRANSACTION (COMMIT)");
begin
if not driver.connection_active then
-- Non-fatal attempt to commit when no database is connected
driver.log_problem (category => transaction, message => err1);
return;
end if;
if driver.connection.autoCommit then
-- Non-fatal attempt to commit when autocommit is on
driver.log_problem (category => transaction, message => err2);
return;
end if;
driver.connection.commit;
driver.log_nominal (category => transaction, message => msg1);
exception
when others =>
driver.log_problem (category => transaction,
message => err3,
pull_codes => True);
end commit;
------------------------
-- last_driver_code --
------------------------
overriding
function last_sql_state (driver : Base_Driver) return SQL_State is
begin
return driver.connection.SqlState;
end last_sql_state;
------------------------
-- last_driver_code --
------------------------
overriding
function last_driver_code (driver : Base_Driver) return Driver_Codes is
begin
return driver.connection.driverCode;
end last_driver_code;
---------------------------
-- last_driver_message --
---------------------------
overriding
function last_driver_message (driver : Base_Driver) return String is
begin
return driver.connection.driverMessage;
end last_driver_message;
----------------------
-- last_insert_id --
----------------------
overriding
function last_insert_id (driver : Base_Driver) return Trax_ID is
begin
return driver.connection.lastInsertID;
end last_insert_id;
------------------------------------------------------------------------
-- PUBLIC ROUTINES NOT COVERED BY INTERFACES --
------------------------------------------------------------------------
------------------------
-- basic_connect #1 --
------------------------
overriding
procedure basic_connect (driver : out Base_Driver;
database : String;
username : String := blankstring;
password : String := blankstring;
socket : String := blankstring)
is
begin
private_connect (driver => Base_Driver'Class (driver),
database => database,
username => username,
password => password,
socket => socket);
end basic_connect;
------------------------
-- basic_connect #2 --
------------------------
overriding
procedure basic_connect (driver : out Base_Driver;
database : String;
username : String := blankstring;
password : String := blankstring;
hostname : String := blankstring;
port : Posix_Port)
is
begin
private_connect (driver => Base_Driver'Class (driver),
database => database,
username => username,
password => password,
hostname => hostname,
port => port);
end basic_connect;
-----------------------------------------------------------------------
-- PRIVATE ROUTINES NOT COVERED BY INTERFACES --
------------------------------------------------------------------------
------------------
-- log_nominal --
------------------
procedure log_nominal (driver : Base_Driver;
category : Log_Category;
message : CT.Text)
is
begin
logger.log_nominal (driver => driver.dialect,
category => category,
message => message);
end log_nominal;
------------------
-- log_problem --
------------------
procedure log_problem
(driver : Base_Driver;
category : Log_Category;
message : CT.Text;
pull_codes : Boolean := False;
break : Boolean := False)
is
error_msg : CT.Text := CT.blank;
error_code : Driver_Codes := 0;
sqlstate : SQL_State := stateless;
begin
if pull_codes then
error_msg := CT.SUS (driver.connection.driverMessage);
error_code := driver.connection.driverCode;
sqlstate := driver.connection.SqlState;
end if;
logger.log_problem (driver => driver.dialect,
category => category,
message => message,
error_msg => error_msg,
error_code => error_code,
sqlstate => sqlstate,
break => break);
end log_problem;
------------------------------
-- assembly_common_select --
------------------------------
function assembly_common_select (distinct : Boolean;
tables : String;
columns : String;
conditions : String;
groupby : String;
having : String;
order : String) return String
is
function proc_distinct (given : Boolean) return String;
function proc_conditions (given : String) return String;
function proc_groupby (given : String) return String;
function proc_having (given : String) return String;
function proc_order (given : String) return String;
function proc_distinct (given : Boolean) return String is
begin
if given then
return "DISTINCT ";
end if;
return "ALL ";
end proc_distinct;
function proc_conditions (given : String) return String is
begin
if CT.IsBlank (given) then
return blankstring;
end if;
return " WHERE " & given;
end proc_conditions;
function proc_groupby (given : String) return String is
begin
if CT.IsBlank (given) then
return blankstring;
end if;
return " GROUP BY " & given;
end proc_groupby;
function proc_having (given : String) return String is
begin
if CT.IsBlank (given) then
return blankstring;
end if;
return " HAVING " & given;
end proc_having;
function proc_order (given : String) return String is
begin
if CT.IsBlank (given) then
return blankstring;
end if;
return " ORDER BY " & given;
end proc_order;
begin
return "SELECT " & proc_distinct (distinct) & columns &
" FROM " & tables &
proc_conditions (conditions) &
proc_groupby (groupby) &
proc_having (having) &
proc_order (order);
end assembly_common_select;
end AdaBase.Driver.Base;
|
with Interfaces;
with Ada.Finalization;
with Ada.Streams;
with kv.avm.references; use kv.avm.references;
limited with kv.avm.Memories;
limited with kv.avm.Registers;
with kv.avm.Actor_References.Sets;
package kv.avm.Tuples is
use Interfaces;
Immutability_Error : exception;
-- A (constant) register map used to create a tuple
type Map_Type is new Ada.Finalization.Controlled with private;
overriding
procedure Adjust
(Self : in out Map_Type);
overriding
procedure Finalize
(Self : in out Map_Type);
not overriding
procedure Set
(Self : in out Map_Type;
Data : access constant kv.avm.References.Reference_Array_Type);
not overriding
function Get(Self : Map_Type) return access constant kv.avm.References.Reference_Array_Type;
procedure Tuple_Map_Write(Stream : not null access Ada.Streams.Root_Stream_Type'CLASS; Item : in Map_Type);
for Map_Type'WRITE use Tuple_Map_Write;
procedure Tuple_Map_Read(Stream : not null access Ada.Streams.Root_Stream_Type'CLASS; Item : out Map_Type);
for Map_Type'READ use Tuple_Map_Read;
overriding
function "="(L, R: Map_Type) return Boolean;
type Tuple_Type is new Ada.Finalization.Controlled with private;
overriding
procedure Initialize
(Self : in out Tuple_Type);
overriding
procedure Adjust
(Self : in out Tuple_Type);
overriding
procedure Finalize
(Self : in out Tuple_Type);
not overriding
procedure Fold
(Self : in out Tuple_Type;
Data : in kv.avm.Memories.Register_Array_Type);
not overriding
procedure Fold_Empty
(Self : in out Tuple_Type);
not overriding
procedure Fold_One
(Self : in out Tuple_Type;
Data : access kv.avm.Registers.Register_Type);
not overriding
procedure Fold
(Self : in out Tuple_Type;
Data : in kv.avm.Memories.Memory_Type;
Map : in Map_Type'CLASS);
not overriding
function Peek
(Self : in Tuple_Type;
Index : in Interfaces.Unsigned_32) return access constant kv.avm.Registers.Register_Type;
not overriding
function Unfolded(Self : Tuple_Type) return access constant kv.avm.Memories.Register_Set_Type;
not overriding
function To_String(Self : Tuple_Type) return String;
not overriding
function Reachable(Self : Tuple_Type) return kv.avm.Actor_References.Sets.Set;
not overriding
function Length(Self : Tuple_Type) return Natural;
overriding
function "="(L, R: Tuple_Type) return Boolean;
procedure Tuple_Write(Stream : not null access Ada.Streams.Root_Stream_Type'CLASS; Item : in Tuple_Type);
for Tuple_Type'WRITE use Tuple_Write;
procedure Tuple_Read(Stream : not null access Ada.Streams.Root_Stream_Type'CLASS; Item : out Tuple_Type);
for Tuple_Type'READ use Tuple_Read;
-- A (constant) abstract ("definition" because "abstract" is a reserved word)
-- of a tuple.
type Definition_Type is new Ada.Finalization.Controlled with private;
overriding
procedure Initialize
(Self : in out Definition_Type);
overriding
procedure Adjust
(Self : in out Definition_Type);
overriding
procedure Finalize
(Self : in out Definition_Type);
overriding
function "="(L, R: Definition_Type) return Boolean;
not overriding
procedure Make
(Self : in out Definition_Type;
Tuple : in Tuple_Type'CLASS);
not overriding
function To_String(Self : Definition_Type) return String;
not overriding
function Length(Self : Definition_Type) return Natural;
private
type Tuple_Reference_Counter_Type;
type Tuple_Reference_Counter_Access is access all Tuple_Reference_Counter_Type;
type Tuple_Type is new Ada.Finalization.Controlled with
record
Ref : Tuple_Reference_Counter_Access;
end record;
type Map_Reference_Counter_Type;
type Map_Reference_Counter_Access is access all Map_Reference_Counter_Type;
type Map_Type is new Ada.Finalization.Controlled with
record
Ref : Map_Reference_Counter_Access;
end record;
type Definition_Reference_Counter_Type;
type Definition_Reference_Counter_Access is access all Definition_Reference_Counter_Type;
type Definition_Type is new Ada.Finalization.Controlled with
record
Ref : Definition_Reference_Counter_Access;
end record;
end kv.avm.Tuples;
|
with System.Tasks;
with System.Debug; -- assertions
with C.winbase;
with C.windef;
with C.winerror;
package body System.Synchronous_Objects.Abortable is
use type C.windef.DWORD;
-- queue
procedure Take (
Object : in out Queue;
Item : out Queue_Node_Access;
Params : Address;
Filter : Queue_Filter;
Aborted : out Boolean) is
begin
Aborted := Tasks.Is_Aborted;
Enter (Object.Mutex.all);
declare
Previous : Queue_Node_Access := null;
I : Queue_Node_Access := Object.Head;
begin
Taking : loop
Take_No_Sync (Object, Item, Params, Filter, Previous, I);
exit Taking when Item /= null;
-- not found
declare
Tail_On_Waiting : constant Queue_Node_Access := Object.Tail;
begin
Object.Params := Params;
Object.Filter := Filter;
loop
Object.Waiting := True;
Leave (Object.Mutex.all);
Wait (Object.Event, Aborted => Aborted);
Enter (Object.Mutex.all);
Object.Waiting := False;
exit Taking when Aborted;
exit when Object.Tail /= Tail_On_Waiting;
end loop;
if Tail_On_Waiting /= null then
Previous := Tail_On_Waiting;
I := Tail_On_Waiting.Next;
else
Previous := null;
I := Object.Head;
end if;
end;
end loop Taking;
end;
Leave (Object.Mutex.all);
end Take;
-- event
procedure Wait (
Object : in out Event;
Aborted : out Boolean)
is
Abort_Event : constant access Event := Tasks.Abort_Event;
begin
if Abort_Event /= null then
declare
Handles : aliased array (0 .. 1) of aliased C.winnt.HANDLE :=
(Object.Handle, Abort_Event.Handle);
Signaled : C.windef.DWORD;
begin
Signaled :=
C.winbase.WaitForMultipleObjects (
2,
Handles (0)'Access,
0,
C.winbase.INFINITE);
pragma Check (Debug,
Check =>
Signaled = C.winbase.WAIT_OBJECT_0
or else Signaled = C.winbase.WAIT_OBJECT_0 + 1
or else Debug.Runtime_Error (
"WaitForMultipleObjects failed"));
Aborted := Signaled = C.winbase.WAIT_OBJECT_0 + 1;
end;
else
Wait (Object);
Aborted := Tasks.Is_Aborted;
end if;
end Wait;
procedure Wait (
Object : in out Event;
Timeout : Duration;
Value : out Boolean;
Aborted : out Boolean)
is
Abort_Event : constant access Event := Tasks.Abort_Event;
begin
if Abort_Event /= null then
declare
Handles : aliased array (0 .. 1) of aliased C.winnt.HANDLE :=
(Object.Handle, Abort_Event.Handle);
Milliseconds : constant C.windef.DWORD :=
C.windef.DWORD (Timeout * 1_000);
Signaled : C.windef.DWORD;
begin
Signaled :=
C.winbase.WaitForMultipleObjects (
2,
Handles (0)'Access,
0,
Milliseconds);
pragma Check (Debug,
Check =>
Signaled = C.winbase.WAIT_OBJECT_0
or else Signaled = C.winbase.WAIT_OBJECT_0 + 1
or else Signaled = C.winerror.WAIT_TIMEOUT
or else Debug.Runtime_Error (
"WaitForMultipleObjects failed"));
Value := Signaled = C.winbase.WAIT_OBJECT_0 or else Get (Object);
Aborted := Signaled = C.winbase.WAIT_OBJECT_0 + 1;
end;
else
Wait (Object, Timeout, Value);
Aborted := Tasks.Is_Aborted;
end if;
end Wait;
end System.Synchronous_Objects.Abortable;
|
package Unicode is
pragma Pure;
subtype Unicode_Character is Wide_Wide_Character
range Wide_Wide_Character'Val (16#00_0000#)
.. Wide_Wide_Character'Val (16#10_FFFF#);
BEL : constant Unicode_Character
:= Wide_Wide_Character'Val (Character'Pos (ASCII.BEL));
BS : constant Unicode_Character
:= Wide_Wide_Character'Val (Character'Pos (ASCII.BS));
CR : constant Unicode_Character
:= Wide_Wide_Character'Val (Character'Pos (ASCII.CR));
FF : constant Unicode_Character
:= Wide_Wide_Character'Val (Character'Pos (ASCII.FF));
HT : constant Unicode_Character
:= Wide_Wide_Character'Val (Character'Pos (ASCII.HT));
LF : constant Unicode_Character
:= Wide_Wide_Character'Val (Character'Pos (ASCII.LF));
NUL : constant Unicode_Character
:= Wide_Wide_Character'Val (Character'Pos (ASCII.NUL));
SOH : constant Unicode_Character
:= Wide_Wide_Character'Val (Character'Pos (ASCII.SOH));
VT : constant Unicode_Character
:= Wide_Wide_Character'Val (Character'Pos (ASCII.VT));
DEL : constant Unicode_Character
:= Wide_Wide_Character'Val (Character'Pos (ASCII.DEL));
type Secondary_Stage_Index is range 16#00# .. 16#FF#;
type Primary_Stage_Index is range 16#0000# .. 16#10FF#;
type Code_Unit_32 is mod 2 ** 32;
subtype Code_Point is Code_Unit_32 range 0 .. 16#10_FFFF#;
end Unicode;
|
------------------------------------------------------------------------------
-- --
-- Ada User Repository Annex (AURA) --
-- ANNEXI-STRAYLINE Reference Implementation --
-- --
-- Command Line Interface --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2020, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * Richard Wai (ANNEXI-STRAYLINE) --
-- --
-- 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 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 --
-- 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 subsystem handles all operations associated with compilation and
-- linking
with Ada.Directories;
with Ada.Strings.Unbounded;
with Progress;
with Registrar.Library_Units;
with Child_Processes.Wait_And_Buffer;
package Build is
package UBS renames Ada.Strings.Unbounded;
-------------------------
-- Build_Configuration --
-------------------------
-- Various global configuration data for the build process, set from the
-- command line. This configuration affects the compilation artifacts,
-- and so is stored between successive runs. If any of the build
-- configuration changes,
type Build_Mode is
(Systemize,
-- The build process will be creating a System repository out of the
-- project
Library,
-- The build process will be creating a stand-alone shared library, or
-- an archive of all compilation objects
Image);
-- The build process will be creating a standard executable image
type Link_Mode is
(Shared,
-- Link to as many shared libraries as possible. This requires "pic"
-- during compilation.
Static_RT,
-- Ada runtime is linked statically, as well as libgcc in the case of
-- GNAT
Static);
-- Build a fully statically-linked image. Applicable only to Image mode
-- builds.
type Compile_Optimization_Mode is
(None,
-- No optimization (typically means -O0, unless set by the compiler
-- options of any configuration units
Level_1,
Level_2,
Level_3,
-- The classic -O1 -O2 -O3 optimization levels
Size,
-- Optimize for size (-Os)
Debug);
-- Optimize for debugging (-Og)
type Build_Configuration is
record
Mode: Build_Mode := Image;
Position_Independent: Boolean := True;
-- Use -fPIC for compilation and -fPIE for linking
-- if False, use -fno-PIC and -fno-PIE
--
-- This value must be true for Shared and Static_RT Link_Modes,
-- or if Mode is Systemize
Debug_Enabled: Boolean := False;
-- If True, '-g' is passed to the compiler and linker.
All_Assertions: Boolean := False;
-- If True, forces all assertions on for all Ada units
Optimization: Compile_Optimization_Mode := None;
Linking: Link_Mode := Shared;
end record;
procedure Load_Last_Build_Config (Configuration: out Build_Configuration);
-- Loads the last run's build configuration, if available. If not available,
-- Configuration is not modified
procedure Store_Build_Config (Current_Config: in Build_Configuration);
-- Stores Current_Config such that Load_Last_Build_Config will retrive the
-- stored data
-----------------
-- Preparation --
-----------------
procedure Init_Paths;
-- Shall be called before executing any of the build steps
-- (Compile, Bind, Link).
--
-- Ensures that the Build_Root and Build_Output_Root paths exist.
--
-- If Last_Run is empty, the Build_Root is first destroyed.
procedure Hash_Compilation_Products;
Compilation_Hash_Progress: aliased Progress.Progress_Tracker;
-- Searches for and hashes any existing compilation products for units with
-- a state of "Available. All such units that have compilation units will be
-- set to a state of "Compiled", indicating the Compilation_Hash value is
-- valid.
procedure Compute_Recompilations (Configuration: Build_Configuration);
Compute_Recompilations_Progress : aliased Progress.Progress_Tracker;
Compute_Recompilations_Completion: Progress.Sequence_Beacon;
-- Compare existing Source and Compilation Hashes (if State = Compiled) with
-- Last_Run to determine which units need to be recompiled. After
-- Compute_Recompilations completes, any units that need recompilation will
-- be changed to a state of "Available".
--
-- If any specification is modified, or if an object file is invalidated,
-- a "pessemistic" recompilation is computed - this triggers recursive
-- recompilation of all units depending on the unit to be pressemistically
-- recompiled (including dependents of the dependents).
--
-- If only an implementation of a target unit has changed between
-- compilations, an attempt is made to approve an "isolated" recompilation.
-- In the case of GNAT, this means scanning the specification of the target
-- unit for any generic declarations or inlined subprograms. If any generic
-- declarations or inlined subprograms are found, a "pessemistic"
-- recompilation is computed, otherwise the "isolated" recompilation will
-- select only the target unit for recompilation.
--
-- If
-- * Last_Run.All_Library_Units is an empty set; or,
-- * Configuration is different from Load_Last_Build_Config
-- all units with a state of "Compiled" will be set to Available (except for
-- units that are members of subsystems that are checked out from "system"
-- repositories) - causing them to be recompiled.
--
-- The Compute_Recompilation process has two phases. Phase one is tracked by
-- the Compute_Recompilations_Progress tracker. Phase two is executed
-- by a Phase Trigger. On call to Compute_Recompilations, the
-- Compute_Recompilations_Completion beacon is entered, and is the left
-- and the completion of the phase trigger.
--
-- The user should for the beacon to be left before continuing
--
-- If approach of the beacon fails, Compute_Recompilation returns
-- immediately.
-- Build_Root --
----------------
-- The root subdirectory under which all compilation products and information
-- is stored
Build_Root: constant String
:= Ada.Directories.Current_Directory & "/aura-build";
-- This directory is always destroyed in the Compile phase if Last_Run
-- is empty
private
Build_Output_Root: constant String := Build_Root & "/build-output";
-- Output from all processes involved in the build process.
procedure Wait_And_Buffer is new Child_Processes.Wait_And_Buffer
(Buffer_Type => UBS.Unbounded_String,
Append => UBS.Append,
Empty_Buffer => UBS.Null_Unbounded_String);
procedure Direct_Hash_Compilation_Products
(Unit: in Registrar.Library_Units.Library_Unit);
-- Directly hashes
use type Registrar.Library_Units.Library_Unit_Kind;
function Object_File_Name (Unit: Registrar.Library_Units.Library_Unit)
return String with
Pre => Unit.Kind /= Registrar.Library_Units.Subunit;
-- Computes the Full Name of the object file that is expected to be inside
-- of Build_Root, for the designated unit.
--
-- If the designated unit is a member of an AURA Subsystem that belongs
-- to a "System" Repository, then the expected name of the shared library
-- object is given
function ALI_File_Name (Unit: Registrar.Library_Units.Library_Unit)
return String with
Pre => Unit.Kind not in Registrar.Library_Units.Subunit;
-- Computes the Full Name of an ALI file (GNAT-specific) that is expected
-- to be inside of Build_Root, for the designated unit
end Build;
|
with Tkmrpc.Servers.Cfg;
with Tkmrpc.Response.Cfg.Tkm_Limits.Convert;
package body Tkmrpc.Operation_Handlers.Cfg.Tkm_Limits is
-------------------------------------------------------------------------
procedure Handle (Req : Request.Data_Type; Res : out Response.Data_Type) is
pragma Unreferenced (Req);
Specific_Res : Response.Cfg.Tkm_Limits.Response_Type;
begin
Specific_Res := Response.Cfg.Tkm_Limits.Null_Response;
Servers.Cfg.Tkm_Limits
(Result => Specific_Res.Header.Result,
Max_Active_Requests => Specific_Res.Data.Max_Active_Requests,
Authag_Contexts => Specific_Res.Data.Authag_Contexts,
Cag_Contexts => Specific_Res.Data.Cag_Contexts,
Li_Contexts => Specific_Res.Data.Li_Contexts,
Ri_Contexts => Specific_Res.Data.Ri_Contexts,
Iag_Contexts => Specific_Res.Data.Iag_Contexts,
Eag_Contexts => Specific_Res.Data.Eag_Contexts,
Dhag_Contexts => Specific_Res.Data.Dhag_Contexts,
Sp_Contexts => Specific_Res.Data.Sp_Contexts,
Authp_Contexts => Specific_Res.Data.Authp_Contexts,
Dhp_Contexts => Specific_Res.Data.Dhp_Contexts,
Autha_Contexts => Specific_Res.Data.Autha_Contexts,
Ca_Contexts => Specific_Res.Data.Ca_Contexts,
Lc_Contexts => Specific_Res.Data.Lc_Contexts,
Ia_Contexts => Specific_Res.Data.Ia_Contexts,
Ea_Contexts => Specific_Res.Data.Ea_Contexts,
Dha_Contexts => Specific_Res.Data.Dha_Contexts);
Res := Response.Cfg.Tkm_Limits.Convert.To_Response (S => Specific_Res);
end Handle;
end Tkmrpc.Operation_Handlers.Cfg.Tkm_Limits;
|
with
ada.Containers.Vectors;
generic
with package Vectors is new ada.Containers.Vectors (<>);
procedure lace.Containers.shuffle_Vector (the_Vector : in out vectors.Vector);
|
with System;
with Ada.Real_Time; use Ada.Real_Time;
with Time_Triggered_Scheduling; -- use Time_Triggered_Scheduling;
-- The following packages are for tracing and timing support
with Ada.Exceptions; use Ada.Exceptions;
with Logging_Support; use Logging_Support;
with Use_CPU; use Use_CPU;
with Ada.Text_IO; use Ada.Text_IO;
with Epoch_Support; use Epoch_Support;
with STM32.Board; use STM32.Board;
-- with Stats;
package body TTS_Example2 is
-- package MyStats is new Stats (5);
-- Instantiation of generic TT scheduler
No_Of_TT_Works : constant := 3;
package TT_Scheduler is new Time_Triggered_Scheduling (No_Of_TT_Works);
use TT_Scheduler;
function New_Slot (ms : Natural;
WId : Any_Work_Id;
Slot_Separation : Natural := 0) return Time_Slot;
function New_Slot (ms : Natural;
WId : Any_Work_Id;
Slot_Separation : Natural := 0) return Time_Slot is
Slot : Time_Slot;
begin
Slot.Slot_Duration := Milliseconds (ms);
Slot.Work_Id := WId;
Slot.Next_Slot_Separation := Milliseconds (Slot_Separation);
return Slot;
end New_Slot;
----------------------------
-- Time-triggered plans --
----------------------------
TTP1 : aliased Time_Triggered_Plan :=
(
New_Slot (30, 1),
New_Slot (70, Empty_Slot),
New_Slot (60, 2),
New_Slot (40, Empty_Slot),
New_Slot (90, 3),
New_Slot (10, Mode_Change_Slot)
);
TTP2 : aliased Time_Triggered_Plan :=
(
New_Slot (90, 3),
New_Slot (10, Empty_Slot),
New_Slot (60, 2),
New_Slot (40, Empty_Slot),
New_Slot (30, 1),
New_Slot (70, Mode_Change_Slot)
);
Null_Plan : aliased Time_Triggered_Plan :=
(
0 => New_Slot (100, Empty_Slot),
1 => New_Slot (100, Mode_Change_Slot)
);
-------------------
-- Task Patterns --
-------------------
-- A basic TT task
task type Basic_TT_Task (Work_Id : Regular_Work_Id;
Execution_Time_MS : Natural)
with Priority => System.Priority'Last is
end Basic_TT_Task;
task body Basic_TT_Task is
Work_To_Be_Done : constant Natural := Execution_Time_MS;
LED_To_Turn : User_LED;
When_Was_Released : Time;
-- Jitter : Time_Span;
begin
case Work_Id is
when 1 =>
LED_To_Turn := Red_LED;
when 2 =>
LED_To_Turn := Blue_LED;
when 3 =>
LED_To_Turn := Green_LED;
end case;
loop
Wait_For_Activation (Work_Id, When_Was_Released);
-- Jitter := Clock - When_Was_Released;
-- Log (No_Event, "|---> Jitter of Worker" & Integer'Image (Integer (Work_Id)) &
-- " = " & Duration'Image (1000.0 * To_Duration (Jitter)) & " ms.");
-- MyStats.Register_Time(Integer(Work_Id)*2-1, Jitter);
Set (Probe_TT_Point);
Turn_On (LED_To_Turn);
Work (Work_To_Be_Done);
Turn_Off (LED_To_Turn);
Clear (Probe_TT_Point);
-- Log (Stop_Task, "W" & Character'Val (Character'Pos ('0') + Integer (Work_Id)));
end loop;
exception
when E : others =>
Put_Line ("Periodic worker W" & Character'Val (Character'Pos ('0') + Integer (Work_Id)) &
": " & Exception_Message (E));
end Basic_TT_Task;
-------------------------------
-- Priority scheduled tasks --
-------------------------------
task type DM_Task (Id : Natural; Period : Integer; Prio : System.Priority)
with Priority => Prio;
task body DM_Task is
Next : Time := Epoch;
Per : constant Time_Span := Milliseconds (Period);
Jitter : Time_Span;
begin
loop
delay until Next;
Jitter := Clock - Next;
Log (No_Event, "|---------> Jitter of DM Task" & Integer'Image (Id) &
" = " & Duration'Image (1000.0 * To_Duration (Jitter)) & " ms.");
-- MyStats.Register_Time(Integer(Id)*2-1, Jitter);
-- Log (Start_Task, "T" & Character'Val (Character'Pos ('0') + Integer (Id)));
Set (Probe_ET_Point);
Turn_On (Orange_LED);
Work (5);
Next := Next + Per;
Turn_Off (Orange_LED);
Clear (Probe_ET_Point);
-- Log (Stop_Task, "T" & Character'Val (Character'Pos ('0') + Integer (Id)));
end loop;
exception
when E : others =>
Put_Line (Exception_Message (E));
end DM_Task;
-- Event-triggered tasks
T4 : DM_Task (Id => 4, Period => 90, Prio => System.Priority'First + 1);
T5 : DM_Task (Id => 5, Period => 210, Prio => System.Priority'First);
-- Time-triggered tasks
-- Work_ID, Execution (ms)
Wk1 : Basic_TT_Task (1, 20);
Wk2 : Basic_TT_Task (2, 40);
Wk3 : Basic_TT_Task (3, 60);
procedure Main is
K : Integer := 0; -- Number of iterations in main loop
begin
-- Generate trace header --
Log (No_Event, "1 M1"); -- Nr of modes
Log (No_Event, "5"); -- Nr of works + Nr of tasks
Log (No_Event, "W1 9.200 9.200 0.0 10"); -- Task_name Period Deadline Phasing Priority
Log (No_Event, "W2 9.200 9.200 0.0 9");
Log (No_Event, "W3 9.200 9.200 0.0 8");
Log (No_Event, "T4 0.600 0.600 0.0 5");
Log (No_Event, "T5 0.800 0.800 0.0 4");
Log (No_Event, ":BODY");
delay until Epoch;
loop
Log (Mode_Change, "M1");
Set_Plan (TTP1'Access);
delay until Epoch + Seconds (K * 30 + 10);
Log (Mode_Change, "Null Plan");
Set_Plan (Null_Plan'Access);
delay until Epoch + Seconds (K * 30 + 15);
Log (Mode_Change, "M2");
Set_Plan (TTP2'Access);
delay until Epoch + Seconds (K * 30 + 25);
Log (Mode_Change, "Null Plan");
Set_Plan (Null_Plan'Access);
delay until Epoch + Seconds (K * 30 + 30);
K := K + 1;
end loop;
-- MyStats.Print_Stats;
-- delay until Time_Last;
end Main;
procedure Configure_Probe_Points;
procedure Configure_Probe_Points is
Configuration : GPIO_Port_Configuration;
begin
Configuration.Mode := Mode_Out;
Configuration.Output_Type := Push_Pull;
Configuration.Speed := Speed_50MHz;
Configuration.Resistors := Floating;
Enable_Clock (Probe_TT_Point & Probe_ET_Point);
Configure_IO (Probe_TT_Point & Probe_ET_Point, Configuration);
Clear (Probe_TT_Point);
Clear (Probe_ET_Point);
end Configure_Probe_Points;
begin
Configure_Probe_Points;
Initialize_LEDs;
All_LEDs_Off;
end TTS_Example2;
|
package Oalign1 is
Klunk1 : Integer := 12;
for Klunk1'Alignment use Standard'Maximum_Alignment;
end;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . P A R T I T I O N _ I N T E R F A C E --
-- --
-- B o d y --
-- (Dummy body for non-distributed case) --
-- --
-- $Revision$
-- --
-- Copyright (C) 1995-2000 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 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. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package body System.Partition_Interface is
M : constant := 7;
type String_Access is access String;
-- To have a minimal implementation of U'Partition_ID.
type Pkg_Node;
type Pkg_List is access Pkg_Node;
type Pkg_Node is record
Name : String_Access;
Next : Pkg_List;
end record;
Pkg_Head : Pkg_List;
Pkg_Tail : Pkg_List;
function getpid return Integer;
pragma Import (C, getpid);
PID : constant Integer := getpid;
function Lower (S : String) return String;
Passive_Prefix : constant String := "SP__";
-- String prepended in top of shared passive packages
procedure Check
(Name : in Unit_Name;
Version : in String;
RCI : in Boolean := True)
is
begin
null;
end Check;
-----------------------------
-- Get_Active_Partition_Id --
-----------------------------
function Get_Active_Partition_ID
(Name : Unit_Name)
return System.RPC.Partition_ID
is
P : Pkg_List := Pkg_Head;
N : String := Lower (Name);
begin
while P /= null loop
if P.Name.all = N then
return Get_Local_Partition_ID;
end if;
P := P.Next;
end loop;
return M;
end Get_Active_Partition_ID;
------------------------
-- Get_Active_Version --
------------------------
function Get_Active_Version
(Name : Unit_Name)
return String
is
begin
return "";
end Get_Active_Version;
----------------------------
-- Get_Local_Partition_Id --
----------------------------
function Get_Local_Partition_ID return System.RPC.Partition_ID is
begin
return System.RPC.Partition_ID (PID mod M);
end Get_Local_Partition_ID;
------------------------------
-- Get_Passive_Partition_ID --
------------------------------
function Get_Passive_Partition_ID
(Name : Unit_Name)
return System.RPC.Partition_ID
is
begin
return Get_Local_Partition_ID;
end Get_Passive_Partition_ID;
-------------------------
-- Get_Passive_Version --
-------------------------
function Get_Passive_Version
(Name : Unit_Name)
return String
is
begin
return "";
end Get_Passive_Version;
------------------------------
-- Get_RCI_Package_Receiver --
------------------------------
function Get_RCI_Package_Receiver
(Name : Unit_Name)
return Interfaces.Unsigned_64
is
begin
return 0;
end Get_RCI_Package_Receiver;
-------------------------------
-- Get_Unique_Remote_Pointer --
-------------------------------
procedure Get_Unique_Remote_Pointer
(Handler : in out RACW_Stub_Type_Access)
is
begin
null;
end Get_Unique_Remote_Pointer;
------------
-- Launch --
------------
procedure Launch
(Rsh_Command : in String;
Name_Is_Host : in Boolean;
General_Name : in String;
Command_Line : in String)
is
begin
null;
end Launch;
-----------
-- Lower --
-----------
function Lower (S : String) return String is
T : String := S;
begin
for J in T'Range loop
if T (J) in 'A' .. 'Z' then
T (J) := Character'Val (Character'Pos (T (J)) -
Character'Pos ('A') +
Character'Pos ('a'));
end if;
end loop;
return T;
end Lower;
------------------------------------
-- Raise_Program_Error_For_E_4_18 --
------------------------------------
procedure Raise_Program_Error_For_E_4_18 is
begin
Ada.Exceptions.Raise_Exception
(Program_Error'Identity,
"Illegal usage of remote access to class-wide type. See RM E.4(18)");
end Raise_Program_Error_For_E_4_18;
-------------------------------------
-- Raise_Program_Error_Unknown_Tag --
-------------------------------------
procedure Raise_Program_Error_Unknown_Tag
(E : in Ada.Exceptions.Exception_Occurrence)
is
begin
Ada.Exceptions.Raise_Exception
(Program_Error'Identity, Ada.Exceptions.Exception_Message (E));
end Raise_Program_Error_Unknown_Tag;
--------------
-- RCI_Info --
--------------
package body RCI_Info is
-----------------------------
-- Get_Active_Partition_ID --
-----------------------------
function Get_Active_Partition_ID return System.RPC.Partition_ID is
P : Pkg_List := Pkg_Head;
N : String := Lower (RCI_Name);
begin
while P /= null loop
if P.Name.all = N then
return Get_Local_Partition_ID;
end if;
P := P.Next;
end loop;
return M;
end Get_Active_Partition_ID;
------------------------------
-- Get_RCI_Package_Receiver --
------------------------------
function Get_RCI_Package_Receiver return Interfaces.Unsigned_64 is
begin
return 0;
end Get_RCI_Package_Receiver;
end RCI_Info;
------------------------------
-- Register_Passive_Package --
------------------------------
procedure Register_Passive_Package
(Name : in Unit_Name;
Version : in String := "")
is
begin
Register_Receiving_Stub (Passive_Prefix & Name, null, Version);
end Register_Passive_Package;
-----------------------------
-- Register_Receiving_Stub --
-----------------------------
procedure Register_Receiving_Stub
(Name : in Unit_Name;
Receiver : in RPC.RPC_Receiver;
Version : in String := "")
is
begin
if Pkg_Tail = null then
Pkg_Head := new Pkg_Node'(new String'(Lower (Name)), null);
Pkg_Tail := Pkg_Head;
else
Pkg_Tail.Next := new Pkg_Node'(new String'(Lower (Name)), null);
Pkg_Tail := Pkg_Tail.Next;
end if;
end Register_Receiving_Stub;
---------
-- Run --
---------
procedure Run
(Main : in Main_Subprogram_Type := null)
is
begin
if Main /= null then
Main.all;
end if;
end Run;
end System.Partition_Interface;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- Testsuite Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2010-2012, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
package body XML.SAX.Input_Sources.Streams is
procedure Free is
new Ada.Unchecked_Deallocation
(Matreshka.Internals.Text_Codecs.Abstract_Decoder'Class,
Matreshka.Internals.Text_Codecs.Decoder_Access);
-- not overriding function Encoding
-- (Self : SAX_Input_Source) return League.Strings.Universal_String;
--------------
-- Finalize --
--------------
overriding procedure Finalize (Self : in out Stream_Input_Source) is
begin
Free (Self.Buffer);
Free (Self.Decoder);
end Finalize;
----------
-- Next --
----------
overriding procedure Next
(Self : in out Stream_Input_Source;
Buffer : in out
not null Matreshka.Internals.Strings.Shared_String_Access;
End_Of_Data : out Boolean)
is
use type Ada.Streams.Stream_Element;
use type Matreshka.Internals.Text_Codecs.Decoder_Access;
type Encodings is
(Unknown,
UCS4LE,
UCS4BE,
UCS42143,
UCS43412,
UTF16LE,
UTF16BE,
EBCDIC,
UTF8);
First : Ada.Streams.Stream_Element_Offset := Self.Last + 1;
Encoding : Encodings := Unknown;
Factory : Matreshka.Internals.Text_Codecs.Decoder_Factory;
begin
-- Restart decoding when requested.
if Self.Restart then
Self.Restart := False;
Self.Decoder.Decode_Append
(Self.Buffer (Self.First .. Self.Last), Buffer);
end if;
-- Reallocate buffer when necessary.
if First > Self.Buffer'Last then
declare
Old : Stream_Element_Array_Access := Self.Buffer;
begin
Self.Buffer :=
new Ada.Streams.Stream_Element_Array
(Old'First .. Old'Last + 1024);
Self.Buffer (Old'Range) := Old.all;
Free (Old);
end;
end if;
-- Read next portion of data from the source.
Stream_Input_Source'Class (Self).Read
(Self.Buffer (First .. Self.Buffer'Last), Self.Last, End_Of_Data);
-- Detect encoding automatically when four first bytes are readed.
if Self.Decoder = null then
if Self.Last >= 3 then
First := 0;
-- Try to recognize Byte Order Mark.
if Self.Buffer (0) = 16#00#
and Self.Buffer (1) = 16#00#
and Self.Buffer (2) = 16#FE#
and Self.Buffer (3) = 16#FF#
then
-- UCS-4, big-endian machine (1234 order)
Encoding := UCS4BE;
First := 4;
elsif Self.Buffer (0) = 16#FF#
and Self.Buffer (1) = 16#FE#
and Self.Buffer (2) = 16#00#
and Self.Buffer (3) = 16#00#
then
-- UCS-4, little-endian machine (4321 order)
Encoding := UCS4LE;
First := 4;
elsif Self.Buffer (0) = 16#00#
and Self.Buffer (1) = 16#00#
and Self.Buffer (2) = 16#FF#
and Self.Buffer (3) = 16#FE#
then
-- UCS-4, unusual octet order (2143)
Encoding := UCS42143;
First := 4;
elsif Self.Buffer (0) = 16#FE#
and Self.Buffer (1) = 16#FF#
and Self.Buffer (2) = 16#00#
and Self.Buffer (3) = 16#00#
then
-- UCS-4, unusual octet order (3412)
Encoding := UCS43412;
First := 4;
elsif Self.Buffer (0) = 16#FE#
and Self.Buffer (1) = 16#FF#
and (Self.Buffer (2) /= 16#00#
or Self.Buffer (3) /= 16#00#)
then
-- UTF-16, big-endian
Encoding := UTF16BE;
First := 2;
elsif Self.Buffer (0) = 16#FF#
and Self.Buffer (1) = 16#FE#
and (Self.Buffer (2) /= 16#00#
or Self.Buffer (3) /= 16#00#)
then
-- UTF-16, little-endian
Encoding := UTF16LE;
First := 2;
elsif Self.Buffer (0) = 16#EF#
and Self.Buffer (1) = 16#BB#
and Self.Buffer (2) = 16#BF#
then
-- UTF-8
Encoding := UTF8;
First := 3;
-- Byte Order Mark is not recognized, try to detect encoding
-- without Byte Order Mark.
elsif Self.Buffer (0) = 16#00#
and Self.Buffer (1) = 16#00#
and Self.Buffer (2) = 16#00#
and Self.Buffer (3) = 16#3C#
then
-- UCS-4 or other encoding with a 32-bit code unit and ASCII
-- characters encoded as ASCII values, big-endian (1234).
Encoding := UCS4BE;
elsif Self.Buffer (0) = 16#3C#
and Self.Buffer (1) = 16#00#
and Self.Buffer (2) = 16#00#
and Self.Buffer (3) = 16#00#
then
-- UCS-4 or other encoding with a 32-bit code unit and ASCII
-- characters encoded as ASCII values, little-endian (4321).
Encoding := UCS4LE;
elsif Self.Buffer (0) = 16#00#
and Self.Buffer (1) = 16#00#
and Self.Buffer (2) = 16#3C#
and Self.Buffer (3) = 16#00#
then
-- UCS-4 or other encoding with a 32-bit code unit and ASCII
-- characters encoded as ASCII values, unusual byte order
-- (2143).
Encoding := UCS42143;
elsif Self.Buffer (0) = 16#00#
and Self.Buffer (1) = 16#3C#
and Self.Buffer (2) = 16#00#
and Self.Buffer (3) = 16#00#
then
-- UCS-4 or other encoding with a 32-bit code unit and ASCII
-- characters encoded as ASCII values, unusual byte order
-- (3412).
Encoding := UCS43412;
elsif Self.Buffer (0) = 16#00#
and Self.Buffer (1) = 16#3C#
and Self.Buffer (2) = 16#00#
and Self.Buffer (3) = 16#3F#
then
-- UTF-16BE or big-endian ISO-10646-UCS-2 or other encoding
-- with a 16-bit code unit in big-endian order and ASCII
-- characters encoded as ASCII values.
Encoding := UTF16BE;
elsif Self.Buffer (0) = 16#3C#
and Self.Buffer (1) = 16#00#
and Self.Buffer (2) = 16#3F#
and Self.Buffer (3) = 16#00#
then
-- UTF-16LE or little-endian ISO-10646-UCS-2 or other encoding
-- with a 16-bit code unit in little-endian order and ASCII
-- characters encoded as ASCII values.
Encoding := UTF16LE;
elsif Self.Buffer (0) = 16#3C#
and Self.Buffer (1) = 16#3F#
and Self.Buffer (2) = 16#78#
and Self.Buffer (3) = 16#6D#
then
-- UTF-8, ISO 646, ASCII, some part of ISO 8859, Shift-JIS,
-- EUC, or any other 7-bit, 8-bit, or mixed-width encoding
-- which ensures that the characters of ASCII have their normal
-- positions, width, and values.
Encoding := UTF8;
elsif Self.Buffer (0) = 16#4C#
and Self.Buffer (1) = 16#6F#
and Self.Buffer (2) = 16#A7#
and Self.Buffer (3) = 16#94#
then
-- EBCDIC (in some flavor).
Encoding := EBCDIC;
else
-- UTF-8 without an encoding declaration, or else the data
-- stream is mislabeled (lacking a required encoding
-- declaration), corrupt, fragmentary, or enclosed in a wrapper
-- of some kind.
Encoding := UTF8;
end if;
elsif End_Of_Data then
-- This is just a guess, entity is too small to detect encoding
-- more precisely.
First := 0;
Encoding := UTF8;
end if;
if Encoding /= Unknown then
-- Create appropriate decoder.
case Encoding is
when Unknown =>
raise Program_Error;
when UCS4LE =>
raise Program_Error;
when UCS4BE =>
raise Program_Error;
when UCS42143 =>
raise Program_Error;
when UCS43412 =>
raise Program_Error;
when UTF16LE =>
Self.Encoding :=
League.Strings.To_Universal_String ("UTF-16");
Factory :=
Matreshka.Internals.Text_Codecs.Decoder
(Matreshka.Internals.Text_Codecs.MIB_UTF16LE);
when UTF16BE =>
Self.Encoding :=
League.Strings.To_Universal_String ("UTF-16");
Factory :=
Matreshka.Internals.Text_Codecs.Decoder
(Matreshka.Internals.Text_Codecs.MIB_UTF16BE);
when EBCDIC =>
raise Program_Error;
when UTF8 =>
Self.Encoding :=
League.Strings.To_Universal_String ("UTF-8");
Factory :=
Matreshka.Internals.Text_Codecs.Decoder
(Matreshka.Internals.Text_Codecs.MIB_UTF8);
end case;
-- Create decoder's state object.
Self.Decoder :=
new Matreshka.Internals.Text_Codecs.Abstract_Decoder'Class'
(Factory (Self.Version_Mode));
-- Decode all readed data (not last chunk only) except possible
-- leading byte order mark, but protect from decoding empty
-- sequence of bytes.
if First <= Self.Last then
Self.Decoder.Decode_Append
(Self.Buffer (First .. Self.Last), Buffer);
end if;
Self.First := First;
end if;
-- Decode received portion of data.
elsif Self.Last >= First then
Self.Decoder.Decode_Append
(Self.Buffer (First .. Self.Last), Buffer);
if not Self.Accumulate then
Self.Last := -1;
else
Self.First := Self.Last + 1;
end if;
end if;
end Next;
---------------
-- Public_Id --
---------------
overriding function Public_Id
(Self : Stream_Input_Source) return League.Strings.Universal_String is
begin
return Self.Public_Id;
end Public_Id;
-- not overriding procedure Set_Encoding
-- (Self : in out SAX_Input_Source;
-- Encoding : League.Strings.Universal_String);
----------
-- Read --
----------
not overriding procedure Read
(Self : in out Stream_Input_Source;
Buffer : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset;
End_Of_Data : out Boolean) is
begin
Self.Stream.Read (Buffer, Last);
if Last < Buffer'First then
Last := Buffer'First - 1;
End_Of_Data := True;
else
End_Of_Data := False;
end if;
end Read;
-----------
-- Reset --
-----------
not overriding procedure Reset (Self : in out Stream_Input_Source) is
begin
Self.First := 0;
Self.Last := -1;
Self.Accumulate := True;
Self.Restart := False;
Self.Decoder := null;
Self.Stream := null;
Self.Version_Mode := Matreshka.Internals.Text_Codecs.XML_1_0;
Free (Self.Decoder);
end Reset;
-----------
-- Reset --
-----------
overriding procedure Reset
(Self : in out Stream_Input_Source;
Version : League.Strings.Universal_String;
Encoding : League.Strings.Universal_String;
Rescan : out Boolean;
Success : out Boolean)
is
use type Matreshka.Internals.Text_Codecs.Decoder_Factory;
use type Matreshka.Internals.Text_Codecs.Decoder_Mode;
use type League.Strings.Universal_String;
Old_Version_Mode : constant Matreshka.Internals.Text_Codecs.Decoder_Mode
:= Self.Version_Mode;
Old_Encoding : constant League.Strings.Universal_String
:= Self.Encoding;
Factory : Matreshka.Internals.Text_Codecs.Decoder_Factory;
begin
Self.Accumulate := False;
if not Version.Is_Empty then
Self.Set_Version (Version);
end if;
if not Encoding.Is_Empty then
Self.Set_Encoding (Encoding);
end if;
Rescan :=
Self.Version_Mode /= Old_Version_Mode
or Self.Encoding /= Old_Encoding;
Success := True;
if Rescan then
-- Release decoder object.
Free (Self.Decoder);
-- Resolve new decoder and create its state.
Factory :=
Matreshka.Internals.Text_Codecs.Decoder
(Matreshka.Internals.Text_Codecs.To_Character_Set (Self.Encoding));
if Factory = null then
Success := False;
else
Self.Decoder :=
new Matreshka.Internals.Text_Codecs.Abstract_Decoder'Class'
(Factory (Self.Version_Mode));
end if;
Self.Restart := True;
end if;
end Reset;
------------------
-- Set_Encoding --
------------------
not overriding procedure Set_Encoding
(Self : in out Stream_Input_Source;
Encoding : League.Strings.Universal_String) is
begin
Self.Encoding := Encoding;
end Set_Encoding;
-------------------
-- Set_Public_Id --
-------------------
not overriding procedure Set_Public_Id
(Self : in out Stream_Input_Source;
Id : League.Strings.Universal_String) is
begin
Self.Public_Id := Id;
end Set_Public_Id;
----------------
-- Set_Stream --
----------------
not overriding procedure Set_Stream
(Self : in out Stream_Input_Source;
Stream : not null Stream_Access) is
begin
Self.Stream := Stream;
end Set_Stream;
-------------------
-- Set_System_Id --
-------------------
overriding procedure Set_System_Id
(Self : in out Stream_Input_Source;
Id : League.Strings.Universal_String) is
begin
Self.System_Id := Id;
end Set_System_Id;
-----------------
-- Set_Version --
-----------------
overriding procedure Set_Version
(Self : in out Stream_Input_Source;
Version : League.Strings.Universal_String)
is
use League.Strings;
begin
if Version = To_Universal_String ("1.0") then
Self.Version_Mode := Matreshka.Internals.Text_Codecs.XML_1_0;
elsif Version = To_Universal_String ("1.1") then
Self.Version_Mode := Matreshka.Internals.Text_Codecs.XML_1_1;
else
raise Constraint_Error with "unsupported XML version";
end if;
end Set_Version;
---------------
-- System_Id --
---------------
overriding function System_Id
(Self : Stream_Input_Source) return League.Strings.Universal_String is
begin
return Self.System_Id;
end System_Id;
end XML.SAX.Input_Sources.Streams;
|
package openGL.Program.lit_colored_textured_skinned
--
-- Provides a program for lit, colored, textured and skinned vertices.
--
is
type Item is new openGL.Program.item with private;
type View is access all Item'Class;
overriding
procedure define (Self : in out Item; use_vertex_Shader : in Shader.view;
use_fragment_Shader : in Shader.view);
overriding
procedure set_Uniforms (Self : in Item);
procedure bone_Transform_is (Self : in Item; Which : in Integer;
Now : in Matrix_4x4);
private
type bone_transform_Uniforms is array (1 .. 120) of Variable.uniform.mat4;
type Item is new openGL.Program.item with
record
bone_transform_Uniforms : lit_colored_textured_skinned.bone_transform_Uniforms;
end record;
end openGL.Program.lit_colored_textured_skinned;
|
-- =============================================================================
-- Package AVR.IO_MEMORY
--
-- Handles the external memory.
-- - EEPROM
-- - GPIO
-- - XMCR
-- =============================================================================
package AVR.IO_MEMORY is
type EEPROM_Address_Word_Type is new Byte_Array_Type (0 .. 1);
Reg_EEAR : EEPROM_Address_Word_Type;
for Reg_EEAR'Address use System'To_Address (16#41#);
type EEPROM_Data_Register_Type is new Byte_Type;
Reg_EEDR : EEPROM_Data_Register_Type;
for Reg_EEDR'Address use System'To_Address (16#40#);
type Eeprom_Control_Register_Type is
record
EERE : Boolean; -- EEPROM Read Enable
EEPE : Boolean; -- EEPROM Programming Enable
EEMPE : Boolean; -- EEPROM Master Programming Enable
EERIE : Boolean; -- EEPROM Ready Interrupt Enable
EEPM0 : Boolean; -- EEPROM Programming Mode Bit 0
EEPM1 : Boolean; -- EEPROM Programming Mode Bit 1
Spare : Spare_Type (0 .. 1);
end record;
pragma Pack (Eeprom_Control_Register_Type);
for Eeprom_Control_Register_Type'Size use BYTE_SIZE;
Reg_EECR : Eeprom_Control_Register_Type;
for Reg_EECR'Address use System'To_Address (16#3F#);
-- =============================
-- General Purpose I/O Registers
-- =============================
type GPIO_Type is new Byte_Type;
Reg_GPIOR0 : GPIO_Type;
for Reg_GPIOR0'Address use System'To_Address (16#3E#);
Reg_GPIOR1 : GPIO_Type;
for Reg_GPIOR1'Address use System'To_Address (16#4A#);
Reg_GPIOR2 : GPIO_Type;
for Reg_GPIOR2'Address use System'To_Address (16#4B#);
-- =========================
-- External Memory registers
-- =========================
#if MCU="ATMEGA2560" then
type External_Memory_Control_A_Type is
record
SRWL : Bit_Array_Type (0 .. 1); -- Wait-state Select Bits for Lower Sector
SRWH : Bit_Array_Type (0 .. 1); -- Wait-state Select Bits for Upper Sector
SRL0 : Bit_Array_Type (0 .. 2); -- Wait-state Sector Limit Bits
SRE : Boolean; -- External SRAM/XMEM Enable
end record;
pragma Pack (External_Memory_Control_A_Type);
for External_Memory_Control_A_Type'Size use BYTE_SIZE;
type External_Memory_Control_B_Type is
record
XMM : Bit_Array_Type (0 .. 2); -- External Memory High Mask Bits
Spare : Spare_Type (0 .. 3);
XMBK : Boolean; -- External Memory Bus-keeper Enable
end record;
pragma Pack (External_Memory_Control_B_Type);
for External_Memory_Control_B_Type'Size use BYTE_SIZE;
#end if;
Reg_XMCRA : External_Memory_Control_A_Type;
for Reg_XMCRA'Address use System'To_Address (16#74#);
Reg_XMCRB : External_Memory_Control_B_Type;
for Reg_XMCRB'Address use System'To_Address (16#75#);
end AVR.IO_MEMORY;
|
package body Return4_Pkg is
function Get_Value (I : Integer) return Rec is
Value : Rec := (I1 => I, I2 => I, I3 => I);
begin
return Value;
end;
end Return4_Pkg;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with Unix;
with Utilities;
with Parameters;
with File_Operations.Heap;
with Package_Manifests;
with Ada.Directories;
with Ada.Characters.Latin_1;
with Ada.Strings.Fixed;
with Ada.Exceptions;
package body Specification_Parser is
package UTL renames Utilities;
package FOP renames File_Operations;
package MAN renames Package_Manifests;
package LAT renames Ada.Characters.Latin_1;
package DIR renames Ada.Directories;
package AS renames Ada.Strings;
package EX renames Ada.Exceptions;
--------------------------------------------------------------------------------------------
-- parse_specification_file
--------------------------------------------------------------------------------------------
procedure parse_specification_file
(dossier : String;
spec : out PSP.Portspecs;
success : out Boolean;
opsys_focus : supported_opsys;
arch_focus : supported_arch;
stop_at_targets : Boolean;
extraction_dir : String := "")
is
package FOPH is new FOP.Heap (Natural (DIR.Size (dossier)));
stop_at_files : constant Boolean := (extraction_dir = "");
converting : constant Boolean := not stop_at_targets and then stop_at_files;
match_opsys : constant String := UTL.lower_opsys (opsys_focus);
match_arch : constant String := UTL.cpu_arch (arch_focus);
markers : HT.Line_Markers;
linenum : Natural := 0;
seen_namebase : Boolean := False;
line_array : spec_array;
line_singlet : spec_singlet;
line_target : spec_target;
line_option : PSP.spec_option;
line_file : Boolean;
last_array : spec_array := not_array;
last_singlet : spec_singlet := not_singlet;
last_option : PSP.spec_option := PSP.not_helper_format;
last_seen : type_category := cat_none;
last_df : Integer := 0;
last_index : HT.Text;
last_optindex : HT.Text;
seen_singlet : array (spec_singlet) of Boolean := (others => False);
quad_tab : Boolean;
use type PSP.spec_option;
begin
FOPH.slurp_file (dossier);
success := False;
spec.initialize;
HT.initialize_markers (FOPH.file_contents.all, markers);
loop
exit when not HT.next_line_present (FOPH.file_contents.all, markers);
quad_tab := False;
linenum := linenum + 1;
declare
line : constant String := HT.extract_line (FOPH.file_contents.all, markers);
LN : constant String := "Line" & linenum'Img & ": ";
begin
if HT.IsBlank (line) then
goto line_done;
end if;
if HT.trailing_whitespace_present (line) then
spec.set_parse_error (LN & "Detected trailing white space");
exit;
end if;
if HT.trapped_space_character_present (line) then
spec.set_parse_error (LN & "Detected trapped space before hard tab");
exit;
end if;
if line (line'First) = '#' then
if line'Length = 1 then
goto line_done;
end if;
if not spec.port_is_generated then
if line'Length > 79 then
spec.set_parse_error (LN & "Comment length exceeds 79 columns");
exit;
end if;
end if;
if line (line'First + 1) /= LAT.Space then
spec.set_parse_error (LN & "Space does not follow hash in comment");
exit;
end if;
goto line_done;
end if;
line_target := determine_target (spec, line, last_seen);
if line_target = bad_target then
spec.set_parse_error (LN & "Make target detected, but not recognized");
exit;
end if;
-- Short-circuit the rest if the first character is a tab.
if line_target = not_target or else
line (line'First) = LAT.HT
then
line_file := is_file_capsule (line);
if not line_file then
line_option := determine_option (line);
if line_option = PSP.not_supported_helper then
spec.set_parse_error (LN & "Option format, but helper not recognized.");
exit;
end if;
if line_option = PSP.not_helper_format then
line_array := determine_array (line);
if line_array = not_array then
line_singlet := determine_singlet (line);
case line_singlet is
when not_singlet | catchall | diode => null;
when others =>
if seen_singlet (line_singlet) then
spec.set_parse_error
(LN & "variable previously defined (use triple tab)");
exit;
end if;
end case;
seen_singlet (line_singlet) := True;
else
line_singlet := not_singlet;
end if;
else
line_array := not_array;
line_singlet := not_singlet;
end if;
else
line_option := PSP.not_helper_format;
line_array := not_array;
line_singlet := not_singlet;
end if;
else
line_file := False;
line_option := PSP.not_helper_format;
line_array := not_array;
line_singlet := not_singlet;
end if;
if not line_file and then
line_target = not_target and then
line_option = PSP.not_helper_format and then
line_array = not_array and then
line_singlet = not_singlet
then
if (
last_seen = cat_option and then
line'Length > 4 and then
line (line'First .. line'First + 3) = LAT.HT & LAT.HT & LAT.HT & LAT.HT
) or else
(line'Length > 3 and then
line (line'First .. line'First + 2) = LAT.HT & LAT.HT & LAT.HT)
then
case last_seen is
when cat_array => line_array := last_array;
when cat_singlet => line_singlet := last_singlet;
when cat_none => null;
when cat_target => null;
when cat_file => null;
when cat_option => line_option := last_option;
quad_tab := True;
end case;
else
spec.set_parse_error (LN & "Parse failed, content unrecognized.");
exit;
end if;
end if;
begin
if line_array /= not_array then
declare
tvalue : String := retrieve_single_value (spec, line);
defkey : HT.Text := retrieve_key (line, last_index);
defvalue : HT.Text := HT.SUS (tvalue);
tkey : String := HT.USS (defkey);
begin
last_index := defkey;
case line_array is
when def =>
if seen_namebase then
spec.set_parse_error (LN & "DEF can't appear after NAMEBASE");
exit;
end if;
if spec.definition_exists (tkey) then
raise duplicate_key with tkey;
end if;
if HT.trails (tvalue, ")") then
if HT.leads (tvalue, "EXTRACT_VERSION(") then
spec.define
(tkey, extract_version (HT.substring (tvalue, 16, 1)));
elsif HT.leads (tvalue, "EXTRACT_INFO(") then
spec.define
(tkey, extract_information (HT.substring (tvalue, 13, 1)));
else
spec.define (tkey, tvalue);
end if;
else
spec.define (tkey, tvalue);
end if;
when sdesc =>
if HT.SU.Length (defvalue) > 50 then
spec.set_parse_error (LN & "SDESC longer than 50 chars");
exit;
end if;
if HT.SU.Length (defvalue) < 12 then
spec.set_parse_error
(LN & "SDESC does not meet 12-character length minimum");
exit;
end if;
declare
onestr : String (1 .. 1);
trestr : String (1 .. 3);
begin
onestr (1) := tvalue (tvalue'First);
if onestr /= HT.uppercase (onestr) then
spec.set_parse_error
(LN & "SDESC does not start with a capital letter");
exit;
end if;
if tvalue (tvalue'Last) = LAT.Full_Stop then
spec.set_parse_error (LN & "SDESC ends in a period");
exit;
end if;
trestr := tvalue (tvalue'First .. tvalue'First + 2);
if trestr = "An " or else
trestr (1 .. 2) = "A "
then
spec.set_parse_error
(LN & "SDESC starts with an indefinite article");
exit;
end if;
if spec.variant_exists (tkey) then
spec.append_array (field => PSP.sp_taglines,
key => tkey,
value => tvalue,
allow_spaces => True);
else
spec.set_parse_error
(LN & "variant '" & tkey & "' was not previously defined.");
exit;
end if;
end;
when distfile =>
declare
new_index : Integer := Integer'Value (tkey);
begin
if new_index /= last_df + 1 then
spec.set_parse_error
(LN & "'" & tkey & "' index is not in order 1,2,3,..,n");
exit;
end if;
last_df := new_index;
exception
when Constraint_Error =>
spec.set_parse_error
(LN & "'" & tkey & "' index is not an integer as required.");
exit;
end;
spec.append_list (PSP.sp_distfiles, tvalue);
when sites =>
if tkey = dlgroup_none then
spec.set_parse_error
(LN & "cannot set site group to '" & dlgroup_none & "'");
exit;
else
transform_download_sites (site => defvalue);
build_group_list (spec => spec,
field => PSP.sp_dl_sites,
key => tkey,
value => HT.USS (defvalue));
end if;
when spkgs =>
build_group_list (spec => spec,
field => PSP.sp_subpackages,
key => tkey,
value => tvalue);
when vopts =>
build_group_list (spec => spec,
field => PSP.sp_vopts,
key => tkey,
value => tvalue);
when ext_head =>
spec.append_array (field => PSP.sp_ext_head,
key => tkey,
value => tvalue,
allow_spaces => True);
when ext_tail =>
spec.append_array (field => PSP.sp_ext_tail,
key => tkey,
value => tvalue,
allow_spaces => True);
when extra_rundep =>
build_group_list (spec => spec,
field => PSP.sp_exrun,
key => tkey,
value => tvalue);
when option_on =>
if tkey = options_all or else
UTL.valid_lower_opsys (tkey) or else
UTL.valid_cpu_arch (tkey)
then
build_group_list (spec => spec,
field => PSP.sp_options_on,
key => tkey,
value => tvalue);
else
spec.set_parse_error
(LN & "group '" & tkey & "' is not valid (all, <opsys>, <arch>)");
exit;
end if;
when broken =>
if tkey = broken_all or else
UTL.valid_lower_opsys (tkey) or else
UTL.valid_cpu_arch (tkey)
then
spec.append_array (field => PSP.sp_broken,
key => tkey,
value => tvalue,
allow_spaces => True);
else
spec.set_parse_error
(LN & "group '" & tkey & "' is not valid (all, <opsys>, <arch>)");
exit;
end if;
when var_opsys =>
if UTL.valid_lower_opsys (tkey) then
if valid_conditional_variable (tvalue) then
spec.append_array (field => PSP.sp_var_opsys,
key => tkey,
value => tvalue,
allow_spaces => True);
else
spec.set_parse_error
(LN & " VAR_OPSYS definition failed validity check.");
exit;
end if;
else
spec.set_parse_error
(LN & "group '" & tkey & "' is not a valid opsys value");
exit;
end if;
when var_arch =>
if UTL.valid_cpu_arch (tkey) then
if valid_conditional_variable (tvalue) then
spec.append_array (field => PSP.sp_var_arch,
key => tkey,
value => tvalue,
allow_spaces => True);
else
spec.set_parse_error
(LN & " VAR_ARCH definition failed validity check.");
exit;
end if;
else
spec.set_parse_error
(LN & "group '" & tkey & "' is not a valid arch value");
exit;
end if;
when opt_descr =>
spec.append_array (field => PSP.sp_opt_descr,
key => tkey,
value => tvalue,
allow_spaces => True);
when opt_group =>
build_group_list (spec => spec,
field => PSP.sp_opt_group,
key => tkey,
value => tvalue);
when b_deps =>
build_group_list (spec => spec,
field => PSP.sp_os_bdep,
key => tkey,
value => tvalue);
when r_deps =>
build_group_list (spec => spec,
field => PSP.sp_os_rdep,
key => tkey,
value => tvalue);
when br_deps =>
build_group_list (spec => spec,
field => PSP.sp_os_brdep,
key => tkey,
value => tvalue);
when c_uses =>
build_group_list (spec => spec,
field => PSP.sp_os_uses,
key => tkey,
value => tvalue);
when not_array => null;
end case;
end;
last_array := line_array;
last_seen := cat_array;
end if;
if line_singlet /= not_singlet then
case line_singlet is
when namebase =>
seen_namebase := True;
build_string (spec, PSP.sp_namebase, line);
when version => build_string (spec, PSP.sp_version, line);
when dist_subdir => build_string (spec, PSP.sp_distsubdir, line);
when distname => build_string (spec, PSP.sp_distname, line);
when build_wrksrc => build_string (spec, PSP.sp_build_wrksrc, line);
when patch_wrksrc => build_string (spec, PSP.sp_patch_wrksrc, line);
when configure_wrksrc => build_string (spec, PSP.sp_config_wrksrc, line);
when install_wrksrc => build_string (spec, PSP.sp_install_wrksrc, line);
when makefile => build_string (spec, PSP.sp_makefile, line);
when destdirname => build_string (spec, PSP.sp_destdirname, line);
when homepage => build_string (spec, PSP.sp_homepage, line);
when configure_script => build_string (spec, PSP.sp_config_script, line);
when gnu_cfg_prefix => build_string (spec, PSP.sp_gnu_cfg_prefix, line);
when must_configure => build_string (spec, PSP.sp_must_config, line);
when deprecated => build_string (spec, PSP.sp_deprecated, line);
when expiration => build_string (spec, PSP.sp_expiration, line);
when prefix => build_string (spec, PSP.sp_prefix, line);
when lic_scheme => build_string (spec, PSP.sp_lic_scheme, line);
when configure_target => build_string (spec, PSP.sp_config_target, line);
when ug_subpackage => build_string (spec, PSP.sp_ug_pkg, line);
when so_version => build_string (spec, PSP.sp_soversion, line);
when revision => set_natural (spec, PSP.sp_revision, line);
when epoch => set_natural (spec, PSP.sp_epoch, line);
when opt_level => set_natural (spec, PSP.sp_opt_level, line);
when job_limit => set_natural (spec, PSP.sp_job_limit, line);
when skip_build => set_boolean (spec, PSP.sp_skip_build, line);
when skip_install => set_boolean (spec, PSP.sp_skip_install, line);
when skip_ccache => set_boolean (spec, PSP.sp_skip_ccache, line);
when single_job => set_boolean (spec, PSP.sp_single_job, line);
when destdir_env => set_boolean (spec, PSP.sp_destdir_env, line);
when config_outsource => set_boolean (spec, PSP.sp_cfg_outsrc, line);
when shift_install => set_boolean (spec, PSP.sp_inst_tchain, line);
when invalid_rpath => set_boolean (spec, PSP.sp_rpath_warning, line);
when debugging => set_boolean (spec, PSP.sp_debugging, line);
when generated => set_boolean (spec, PSP.sp_generated, line);
when repsucks => set_boolean (spec, PSP.sp_repsucks, line);
when killdog => set_boolean (spec, PSP.sp_killdog, line);
when cgo_conf => set_boolean (spec, PSP.sp_cgo_conf, line);
when cgo_build => set_boolean (spec, PSP.sp_cgo_build, line);
when cgo_inst => set_boolean (spec, PSP.sp_cgo_inst, line);
when keywords => build_list (spec, PSP.sp_keywords, line);
when variants => build_list (spec, PSP.sp_variants, line);
when contacts => build_list (spec, PSP.sp_contacts, line);
when dl_groups => build_list (spec, PSP.sp_dl_groups, line);
when df_index => build_list (spec, PSP.sp_df_index, line);
when opt_avail => build_list (spec, PSP.sp_opts_avail, line);
when opt_standard => build_list (spec, PSP.sp_opts_standard, line);
when exc_opsys => build_list (spec, PSP.sp_exc_opsys, line);
when inc_opsys => build_list (spec, PSP.sp_inc_opsys, line);
when exc_arch => build_list (spec, PSP.sp_exc_arch, line);
when ext_only => build_list (spec, PSP.sp_ext_only, line);
when ext_zip => build_list (spec, PSP.sp_ext_zip, line);
when ext_7z => build_list (spec, PSP.sp_ext_7z, line);
when ext_lha => build_list (spec, PSP.sp_ext_lha, line);
when ext_deb => build_list (spec, PSP.sp_ext_deb, line);
when ext_dirty => build_list (spec, PSP.sp_ext_dirty, line);
when make_args => build_list (spec, PSP.sp_make_args, line);
when make_env => build_list (spec, PSP.sp_make_env, line);
when build_target => build_list (spec, PSP.sp_build_target, line);
when cflags => build_list (spec, PSP.sp_cflags, line);
when cxxflags => build_list (spec, PSP.sp_cxxflags, line);
when cppflags => build_list (spec, PSP.sp_cppflags, line);
when ldflags => build_list (spec, PSP.sp_ldflags, line);
when patchfiles => build_list (spec, PSP.sp_patchfiles, line);
when uses => build_list (spec, PSP.sp_uses, line);
when sub_list => build_list (spec, PSP.sp_sub_list, line);
when config_args => build_list (spec, PSP.sp_config_args, line);
when config_env => build_list (spec, PSP.sp_config_env, line);
when build_deps => build_list (spec, PSP.sp_build_deps, line);
when buildrun_deps => build_list (spec, PSP.sp_buildrun_deps, line);
when run_deps => build_list (spec, PSP.sp_run_deps, line);
when cmake_args => build_list (spec, PSP.sp_cmake_args, line);
when qmake_args => build_list (spec, PSP.sp_qmake_args, line);
when info => build_list (spec, PSP.sp_info, line);
when install_tgt => build_list (spec, PSP.sp_install_tgt, line);
when test_target => build_list (spec, PSP.sp_test_tgt, line);
when test_args => build_list (spec, PSP.sp_test_args, line);
when test_env => build_list (spec, PSP.sp_test_env, line);
when patch_strip => build_list (spec, PSP.sp_patch_strip, line);
when patchfiles_strip => build_list (spec, PSP.sp_pfiles_strip, line);
when plist_sub => build_list (spec, PSP.sp_plist_sub, line);
when licenses => build_list (spec, PSP.sp_licenses, line);
when users => build_list (spec, PSP.sp_users, line);
when groups => build_list (spec, PSP.sp_groups, line);
when lic_file => build_list (spec, PSP.sp_lic_file, line);
when lic_name => build_list (spec, PSP.sp_lic_name, line);
when lic_terms => build_list (spec, PSP.sp_lic_terms, line);
when lic_awk => build_list (spec, PSP.sp_lic_awk, line);
when lic_source => build_list (spec, PSP.sp_lic_src, line);
when mandirs => build_list (spec, PSP.sp_mandirs, line);
when broken_ssl => build_list (spec, PSP.sp_broken_ssl, line);
when broken_mysql => build_list (spec, PSP.sp_broken_mysql, line);
when broken_pgsql => build_list (spec, PSP.sp_broken_pgsql, line);
when gnome_comp => build_list (spec, PSP.sp_gnome, line);
when xorg_comp => build_list (spec, PSP.sp_xorg, line);
when sdl_comp => build_list (spec, PSP.sp_sdl, line);
when phpext => build_list (spec, PSP.sp_phpext, line);
when rc_scripts => build_list (spec, PSP.sp_rcscript, line);
when og_radio => build_list (spec, PSP.sp_og_radio, line);
when og_restrict => build_list (spec, PSP.sp_og_restrict, line);
when og_unlimited => build_list (spec, PSP.sp_og_unlimited, line);
when cgo_cargs => build_list (spec, PSP.sp_cgo_cargs, line);
when cgo_bargs => build_list (spec, PSP.sp_cgo_bargs, line);
when cgo_iargs => build_list (spec, PSP.sp_cgo_iargs, line);
when cgo_feat => build_list (spec, PSP.sp_cgo_feat, line);
when catchall => build_nvpair (spec, line);
when extra_patches =>
build_list (spec, PSP.sp_extra_patches, line);
if converting then
verify_extra_file_exists (spec => spec,
specfile => dossier,
line => line,
is_option => False,
sub_file => False);
end if;
when sub_files =>
build_list (spec, PSP.sp_sub_files, line);
if converting then
verify_extra_file_exists (spec => spec,
specfile => dossier,
line => line,
is_option => False,
sub_file => True);
end if;
when diode => null;
when not_singlet => null;
end case;
last_singlet := line_singlet;
last_seen := cat_singlet;
end if;
if line_target /= not_target then
if stop_at_targets then
exit;
end if;
case line_target is
when target_title =>
declare
target : String := line (line'First .. line'Last - 1);
begin
if spec.group_exists (PSP.sp_makefile_targets, target) then
spec.set_parse_error
(LN & "Duplicate makefile target '" & target & "' detected.");
exit;
end if;
spec.establish_group (PSP.sp_makefile_targets, target);
last_index := HT.SUS (target);
end;
when target_body =>
spec.append_array
(field => PSP.sp_makefile_targets,
key => HT.USS (last_index),
value => transform_target_line (spec, line, not converting),
allow_spaces => True);
when bad_target => null;
when not_target => null;
end case;
last_seen := cat_target;
end if;
if line_option /= PSP.not_helper_format then
declare
option_name : String := extract_option_name (spec, line, last_optindex);
begin
if option_name = "" then
spec.set_parse_error
(LN & "Valid helper, but option has never been defined " &
"(also seen when continuation line doesn't start with 5 tabs)");
exit;
end if;
if not quad_tab and then
not spec.option_helper_unset (field => line_option,
option => option_name)
then
spec.set_parse_error
(LN & "option helper previously defined (use quintuple tab)");
exit;
end if;
build_list (spec, line_option, option_name, line);
last_optindex := HT.SUS (option_name);
if converting then
if line_option = PSP.extra_patches_on then
verify_extra_file_exists (spec => spec,
specfile => dossier,
line => line,
is_option => True,
sub_file => False);
end if;
if line_option = PSP.sub_files_on then
verify_extra_file_exists (spec => spec,
specfile => dossier,
line => line,
is_option => True,
sub_file => True);
end if;
end if;
end;
last_option := line_option;
last_seen := cat_option;
end if;
if line_file then
if stop_at_files then
exit;
end if;
declare
filename : String := retrieve_file_name (line);
filesize : Natural := retrieve_file_size (line);
fileguts : String := HT.extract_file (FOPH.file_contents.all,
markers,
filesize);
subdir : String := HT.partial_search (filename, 0, "/");
-- only acceptable subdir:
-- 1. ""
-- 2. "patches"
-- 3. "files"
-- 4. "scripts"
-- 5. current lower opsys (saves to "opsys")
begin
if subdir = "" or else
subdir = "patches" or else
subdir = "scripts" or else
subdir = "descriptions"
then
FOP.dump_contents_to_file (fileguts, extraction_dir & "/" & filename);
elsif subdir = "files" then
declare
newname : constant String :=
tranform_filename (filename => filename,
match_opsys => match_opsys,
match_arch => match_arch);
begin
if newname = "" then
FOP.dump_contents_to_file (fileguts,
extraction_dir & "/" & filename);
else
FOP.dump_contents_to_file (fileguts, extraction_dir & "/" & newname);
end if;
end;
elsif subdir = match_opsys then
declare
newname : String :=
extraction_dir & "/opsys/" & HT.part_2 (filename, "/");
begin
FOP.dump_contents_to_file (fileguts, newname);
end;
elsif subdir = "manifests" then
FOP.create_subdirectory (extraction_dir, subdir);
MAN.decompress_manifest
(compressed_string => fileguts,
save_to_file => MAN.Filename (extraction_dir & "/" & filename));
end if;
end;
end if;
exception
when F1 : PSP.misordered =>
spec.set_parse_error
(LN & "Field " & EX.Exception_Message (F1) & " appears out of order");
exit;
when F2 : PSP.contains_spaces =>
spec.set_parse_error (LN & "Multiple values found");
exit;
when F3 : PSP.wrong_type =>
spec.set_parse_error
(LN & "Field " & EX.Exception_Message (F3) &
" DEV ISSUE: matched to wrong type");
exit;
-- F4 merged to FF
when F5 : mistabbed =>
spec.set_parse_error (LN & "value not aligned to column-24 (tab issue)");
exit;
when F6 : missing_definition
| expansion_too_long
| bad_modifier =>
spec.set_parse_error
(LN & "Variable expansion: " & EX.Exception_Message (F6));
exit;
when F7 : extra_spaces =>
spec.set_parse_error (LN & "extra spaces detected between list items.");
exit;
-- F8 merged to F6
when F9 : duplicate_key =>
spec.set_parse_error
(LN & "array key '" & EX.Exception_Message (F9) & "' duplicated.");
exit;
when FA : PSP.dupe_spec_key =>
spec.set_parse_error (LN & EX.Exception_Message (FA) & " key duplicated.");
exit;
-- FB merged to FF
when FC : PSP.missing_group =>
spec.set_parse_error
(LN & EX.Exception_Message (FC) & " group has not yet been established.");
when FD : PSP.dupe_list_value =>
spec.set_parse_error
(LN & "list item '" & EX.Exception_Message (FD) & "' is duplicate.");
exit;
when FE : mistabbed_40 =>
spec.set_parse_error (LN & "option value not aligned to column-40 (tab issue)");
exit;
when FF : missing_file
| generic_format
| PSP.wrong_value
| PSP.missing_extract
| PSP.missing_require =>
spec.set_parse_error (LN & EX.Exception_Message (FF));
exit;
end;
<<line_done>>
end;
end loop;
if spec.get_parse_error = "" then
spec.set_parse_error (late_validity_check_error (spec));
if spec.get_parse_error = "" then
spec.adjust_defaults_port_parse;
success := True;
end if;
end if;
exception
when FX : FOP.file_handling =>
success := False;
spec.set_parse_error (EX.Exception_Message (FX));
end parse_specification_file;
--------------------------------------------------------------------------------------------
-- expand_value
--------------------------------------------------------------------------------------------
function expand_value (specification : PSP.Portspecs; value : String) return String
is
function translate (variable : String) return String;
function will_fit (CL, CR : Natural; new_text : String) return Boolean;
procedure exchange (CL, CR : Natural; new_text : String);
function modify (curvalue : HT.Text;
modifier : String;
valid : out Boolean) return HT.Text;
canvas : String (1 .. 512);
found : Boolean;
front_marker : Natural;
curly_left : Natural;
curly_right : Natural;
trans_error : Natural;
delimiter : HT.Text := HT.SUS ("/");
function will_fit (CL, CR : Natural; new_text : String) return Boolean
is
old_length : Natural := CR - CL + 1;
new_marker : Natural := front_marker - old_length + new_text'Length;
begin
return (new_marker < canvas'Length);
end will_fit;
procedure exchange (CL, CR : Natural; new_text : String)
is
old_length : Natural := CR - CL + 1;
begin
if old_length = new_text'Length then
canvas (CL .. CR) := new_text;
return;
end if;
declare
final_segment : String := canvas (CR + 1 .. front_marker);
begin
-- if old_length < new_text'Length then
-- Shift later text to the right from the end (expand)
-- else
-- Shift later text to the left from the beginning (shrink)
front_marker := front_marker + (new_text'Length - old_length);
canvas (CL .. front_marker) := new_text & final_segment;
end;
end exchange;
function translate (variable : String) return String
is
basename : HT.Text;
result : HT.Text := HT.blank;
colon_pos : Natural := AS.Fixed.Index (variable, ":");
colon_next : Natural;
end_mark : Natural;
found : Boolean;
valid : Boolean;
begin
if colon_pos = 0 then
basename := HT.SUS (variable);
else
basename := HT.SUS (variable (variable'First .. colon_pos - 1));
end if;
declare
tbasename : constant String := HT.USS (basename);
begin
if specification.definition_exists (tbasename) then
result := HT.SUS (specification.definition (tbasename));
else
trans_error := 1; -- missing_definition
return "";
end if;
end;
loop
exit when colon_pos = 0;
colon_next := colon_pos + 1;
found := False;
loop
exit when colon_next > variable'Last;
if variable (colon_next) = LAT.Colon then
found := True;
exit;
end if;
colon_next := colon_next + 1;
end loop;
if found then
end_mark := colon_next - 1;
else
end_mark := variable'Last;
colon_next := 0;
end if;
if end_mark = colon_pos then
trans_error := 2; -- bad_modifier
return "";
end if;
result := modify (result, variable (colon_pos + 1 .. end_mark), valid);
if not valid then
trans_error := 2; -- bad_modifier
return "";
end if;
colon_pos := colon_next;
end loop;
trans_error := 0;
return HT.USS (result);
end translate;
function modify (curvalue : HT.Text;
modifier : String;
valid : out Boolean) return HT.Text
is
ml : Natural := modifier'Length;
dot : HT.Text := HT.SUS (".");
begin
valid := True;
if modifier = "LC" then
return HT.lowercase (curvalue);
elsif modifier = "UC" then
return HT.uppercase (curvalue);
elsif modifier = "H" then
return HT.head (curvalue, delimiter);
elsif modifier = "T" then
return HT.tail (curvalue, delimiter);
elsif modifier = "R" then
return HT.head (curvalue, dot);
elsif modifier = "E" then
return HT.tail (curvalue, dot);
elsif ml >= 6 and then
modifier (modifier'First .. modifier'First + 3) = "DL=" & LAT.Quotation and then
modifier (modifier'Last) = LAT.Quotation
then
delimiter := HT.SUS (modifier (modifier'First + 4 .. modifier'Last - 1));
return curvalue;
elsif ml >= 5 and then modifier (modifier'First) = 'S' then
declare
separator : Character;
position_2 : Natural := 0;
position_3 : Natural := 0;
repeat : Boolean := False;
its_bad : Boolean := False;
new_value : HT.Text := curvalue;
begin
if modifier (modifier'First + 1) = LAT.Solidus or else
modifier (modifier'First + 1) = LAT.Vertical_Line
then
separator := modifier (modifier'First + 1);
for arrow in Natural range modifier'First + 2 .. modifier'Last loop
if modifier (arrow) = separator then
if position_2 = 0 then
position_2 := arrow;
elsif position_3 = 0 then
position_3 := arrow;
else
its_bad := True;
end if;
end if;
end loop;
if position_3 = 0 then
its_bad := True;
else
if position_3 < modifier'Last then
if (position_3 = modifier'Last - 1) and then
modifier (modifier'Last) = 'g'
then
repeat := True;
else
its_bad := True;
end if;
end if;
end if;
if not its_bad then
declare
oldst : String := modifier (modifier'First + 2 .. position_2 - 1);
newst : String := modifier (position_2 + 1 .. position_3 - 1);
begin
loop
exit when not HT.contains (new_value, oldst);
new_value := HT.replace_substring (US => new_value,
old_string => oldst,
new_string => newst);
exit when not repeat;
end loop;
end;
return new_value;
end if;
end if;
end;
end if;
valid := False;
return HT.blank;
end modify;
begin
if not HT.contains (S => value, fragment => "${") then
return value;
end if;
if value'Length > canvas'Length then
raise expansion_too_long;
end if;
front_marker := value'Length;
canvas (1 .. front_marker) := value;
loop
curly_left := AS.Fixed.Index (canvas (1 .. front_marker), "${");
if curly_left = 0 then
return canvas (1 .. front_marker);
end if;
found := False;
curly_right := curly_left + 2;
loop
exit when curly_right > front_marker;
if canvas (curly_right) = LAT.Right_Curly_Bracket then
found := True;
exit;
end if;
curly_right := curly_right + 1;
end loop;
if found then
if curly_right - curly_left - 2 = 0 then
raise missing_definition with "zero-length variable name";
end if;
declare
varname : String := canvas (curly_left + 2 .. curly_right - 1);
expanded : String := translate (varname);
begin
if trans_error = 0 then
if will_fit (curly_left, curly_right, expanded) then
exchange (curly_left, curly_right, expanded);
else
raise expansion_too_long
with HT.DQ (varname) & " expansion exceeds 512-char maximum.";
end if;
elsif trans_error = 1 then
raise missing_definition
with HT.DQ (varname) & " variable undefined.";
elsif trans_error = 2 then
raise bad_modifier
with HT.DQ (varname) & " variable has unrecognized modifier.";
end if;
end;
end if;
end loop;
end expand_value;
--------------------------------------------------------------------------------------------
-- determine_array
--------------------------------------------------------------------------------------------
function determine_array (line : String) return spec_array
is
subtype array_string is String (1 .. 12);
total_arrays : constant Positive := 19;
type array_pair is
record
varname : array_string;
sparray : spec_array;
end record;
-- Keep in alphabetical order for future conversion to binary search
all_arrays : constant array (1 .. total_arrays) of array_pair :=
(
("BROKEN ", broken),
("BR_DEPS ", br_deps),
("B_DEPS ", b_deps),
("C_USES ", c_uses),
("DEF ", def),
("DISTFILE ", distfile),
("EXRUN ", extra_rundep),
("EXTRACT_HEAD", ext_head),
("EXTRACT_TAIL", ext_tail),
("OPTDESCR ", opt_descr),
("OPTGROUP ", opt_group),
("OPT_ON ", option_on),
("R_DEPS ", r_deps),
("SDESC ", sdesc),
("SITES ", sites),
("SPKGS ", spkgs),
("VAR_ARCH ", var_arch),
("VAR_OPSYS ", var_opsys),
("VOPTS ", vopts)
);
bandolier : array_string := (others => LAT.Space);
Low : Natural := all_arrays'First;
High : Natural := all_arrays'Last;
Mid : Natural;
end_varname : Natural;
bullet_len : Natural;
begin
if not HT.contains (S => line, fragment => "]=" & LAT.HT) then
return not_array;
end if;
end_varname := AS.Fixed.Index (Source => line, Pattern => "[");
if end_varname = 0 then
return not_array;
end if;
bullet_len := end_varname - line'First;
if bullet_len < 3 or else bullet_len > array_string'Length then
return not_array;
end if;
bandolier (1 .. bullet_len) := line (line'First .. end_varname - 1);
loop
Mid := (Low + High) / 2;
if bandolier = all_arrays (Mid).varname then
return all_arrays (Mid).sparray;
elsif bandolier < all_arrays (Mid).varname then
exit when Low = Mid;
High := Mid - 1;
else
exit when High = Mid;
Low := Mid + 1;
end if;
end loop;
return not_array;
end determine_array;
--------------------------------------------------------------------------------------------
-- determine_singlet
--------------------------------------------------------------------------------------------
function determine_singlet (line : String) return spec_singlet
is
function nailed (index : Natural) return Boolean;
function less_than (index : Natural) return Boolean;
total_singlets : constant Positive := 190;
type singlet_pair is
record
varname : String (1 .. 22);
len : Natural;
singlet : spec_singlet;
end record;
-- It is critical that this list be alphabetized correctly.
all_singlets : constant array (1 .. total_singlets) of singlet_pair :=
(
("BLOCK_WATCHDOG ", 14, killdog),
("BROKEN_MYSQL ", 12, broken_mysql),
("BROKEN_PGSQL ", 12, broken_pgsql),
("BROKEN_SSL ", 10, broken_ssl),
("BUILDRUN_DEPENDS ", 16, buildrun_deps),
("BUILD_DEPENDS ", 13, build_deps),
("BUILD_TARGET ", 12, build_target),
("BUILD_WRKSRC ", 12, build_wrksrc),
("CARGO_BUILD_ARGS ", 16, cgo_bargs),
("CARGO_CARGOLOCK ", 15, catchall),
("CARGO_CARGOTOML ", 15, catchall),
("CARGO_CARGO_BIN ", 15, catchall),
("CARGO_CONFIG_ARGS ", 17, cgo_cargs),
("CARGO_FEATURES ", 14, cgo_feat),
("CARGO_INSTALL_ARGS ", 18, cgo_iargs),
("CARGO_SKIP_BUILD ", 16, cgo_build),
("CARGO_SKIP_CONFIGURE ", 20, cgo_conf),
("CARGO_SKIP_INSTALL ", 18, cgo_inst),
("CARGO_TARGET_DIR ", 16, catchall),
("CARGO_VENDOR_DIR ", 16, catchall),
("CC ", 2, catchall),
("CFLAGS ", 6, cflags),
("CHARSETFIX_MAKEFILEIN ", 21, catchall),
("CMAKE_ARGS ", 10, cmake_args),
("CMAKE_BUILD_TYPE ", 16, catchall),
("CMAKE_INSTALL_PREFIX ", 20, catchall),
("CMAKE_SOURCE_PATH ", 17, catchall),
("CONFIGURE_ARGS ", 14, config_args),
("CONFIGURE_ENV ", 13, config_env),
("CONFIGURE_OUTSOURCE ", 19, config_outsource),
("CONFIGURE_SCRIPT ", 16, configure_script),
("CONFIGURE_TARGET ", 16, configure_target),
("CONFIGURE_WRKSRC ", 16, configure_wrksrc),
("CONTACT ", 7, contacts),
("CPE_EDITION ", 11, catchall),
("CPE_LANG ", 8, catchall),
("CPE_OTHER ", 9, catchall),
("CPE_PART ", 8, catchall),
("CPE_PRODUCT ", 11, catchall),
("CPE_SW_EDITION ", 14, catchall),
("CPE_TARGET_HW ", 13, catchall),
("CPE_TARGET_SW ", 13, catchall),
("CPE_UPDATE ", 10, catchall),
("CPE_VENDOR ", 10, catchall),
("CPE_VERSION ", 11, catchall),
("CPP ", 3, catchall),
("CPPFLAGS ", 8, cppflags),
("CXX ", 3, catchall),
("CXXFLAGS ", 8, cxxflags),
("DEBUG_FLAGS ", 11, catchall),
("DEPRECATED ", 10, deprecated),
("DESTDIRNAME ", 11, destdirname),
("DESTDIR_VIA_ENV ", 15, destdir_env),
("DF_INDEX ", 8, df_index),
("DISTNAME ", 8, distname),
("DIST_SUBDIR ", 11, dist_subdir),
("DOS2UNIX_FILES ", 14, catchall),
("DOS2UNIX_GLOB ", 13, catchall),
("DOS2UNIX_REGEX ", 14, catchall),
("DOS2UNIX_WRKSRC ", 15, catchall),
("DOWNLOAD_GROUPS ", 15, dl_groups),
("EPOCH ", 5, epoch),
("EXPIRATION_DATE ", 15, expiration),
("EXTRACT_DEB_PACKAGE ", 19, ext_deb),
("EXTRACT_DIRTY ", 13, ext_dirty),
("EXTRACT_ONLY ", 12, ext_only),
("EXTRACT_WITH_7Z ", 15, ext_7z),
("EXTRACT_WITH_LHA ", 16, ext_lha),
("EXTRACT_WITH_UNZIP ", 18, ext_zip),
("EXTRA_PATCHES ", 13, extra_patches),
("FONTNAME ", 8, catchall),
("FONTROOTDIR ", 11, catchall),
("FONTSDIR ", 8, catchall),
("FPC_EQUIVALENT ", 14, catchall),
("GCONF_CONFIG_DIRECTORY", 22, catchall),
("GCONF_CONFIG_OPTIONS ", 20, catchall),
("GCONF_SCHEMAS ", 13, catchall),
("GENERATED ", 9, generated),
("GLIB_SCHEMAS ", 12, catchall),
("GNOME_COMPONENTS ", 16, gnome_comp),
("GNU_CONFIGURE_PREFIX ", 20, gnu_cfg_prefix),
("GROUPS ", 6, groups),
("GTKDOC_INTERMED_DIR ", 19, catchall),
("GTKDOC_OUTPUT_BASEDIR ", 21, catchall),
("HOMEPAGE ", 8, homepage),
("INFO ", 4, info),
("INFO_PATH ", 9, catchall),
("INFO_SUBDIR ", 11, diode),
("INSTALL_REQ_TOOLCHAIN ", 21, shift_install),
("INSTALL_TARGET ", 14, install_tgt),
("INSTALL_WRKSRC ", 14, install_wrksrc),
("INVALID_RPATH ", 13, invalid_rpath),
("KEYWORDS ", 8, keywords),
("LDFLAGS ", 7, ldflags),
("LICENSE ", 7, licenses),
("LICENSE_AWK ", 11, lic_awk),
("LICENSE_FILE ", 12, lic_file),
("LICENSE_NAME ", 12, lic_name),
("LICENSE_SCHEME ", 14, lic_scheme),
("LICENSE_SOURCE ", 14, lic_source),
("LICENSE_TERMS ", 13, lic_terms),
("MAKEFILE ", 8, makefile),
("MAKE_ARGS ", 9, make_args),
("MAKE_ENV ", 8, make_env),
("MAKE_JOBS_NUMBER_LIMIT", 22, job_limit),
("MANDIRS ", 7, mandirs),
("MESON_ARGS ", 10, catchall),
("MESON_BUILD_DIR ", 15, catchall),
("MESON_INSERT_RPATH ", 18, catchall),
("MUST_CONFIGURE ", 14, must_configure),
("NAMEBASE ", 8, namebase),
("NCURSES_RPATH ", 13, catchall),
("NOT_FOR_ARCH ", 12, exc_arch),
("NOT_FOR_OPSYS ", 13, exc_opsys),
("ONLY_FOR_OPSYS ", 14, inc_opsys),
("OPTGROUP_RADIO ", 14, og_radio),
("OPTGROUP_RESTRICTED ", 19, og_restrict),
("OPTGROUP_UNLIMITED ", 18, og_unlimited),
("OPTIMIZER_LEVEL ", 15, opt_level),
("OPTIONS_AVAILABLE ", 17, opt_avail),
("OPTIONS_STANDARD ", 16, opt_standard),
("PATCHFILES ", 10, patchfiles),
("PATCHFILES_STRIP ", 16, patchfiles_strip),
("PATCH_STRIP ", 11, patch_strip),
("PATCH_WRKSRC ", 12, patch_wrksrc),
("PHP_EXTENSIONS ", 14, phpext),
("PHP_HEADER_DIRS ", 15, catchall),
("PHP_MODNAME ", 11, catchall),
("PHP_MOD_PRIORITY ", 16, catchall),
("PLIST_SUB ", 9, plist_sub),
("PREFIX ", 6, prefix),
("PYD_BUILDARGS ", 13, catchall),
("PYD_BUILD_TARGET ", 16, catchall),
("PYD_CONFIGUREARGS ", 17, catchall),
("PYD_CONFIGURE_TARGET ", 20, catchall),
("PYD_INSTALLARGS ", 15, catchall),
("PYD_INSTALL_TARGET ", 18, catchall),
("PYSETUP ", 7, catchall),
("QMAKE_ARGS ", 10, qmake_args),
("RC_SUBR ", 7, rc_scripts),
("REPOLOGY_SUCKS ", 14, repsucks),
("REVISION ", 8, revision),
("RUBY_EXTCONF ", 12, catchall),
("RUBY_FLAGS ", 10, catchall),
("RUBY_SETUP ", 10, catchall),
("RUN_DEPENDS ", 11, run_deps),
("SDL_COMPONENTS ", 14, sdl_comp),
("SET_DEBUGGING_ON ", 16, debugging),
("SHEBANG_ADD_SH ", 14, catchall),
("SHEBANG_FILES ", 13, catchall),
("SHEBANG_GLOB ", 12, catchall),
("SHEBANG_LANG ", 12, catchall),
("SHEBANG_NEW_BASH ", 16, catchall),
("SHEBANG_NEW_JAVA ", 16, catchall),
("SHEBANG_NEW_KSH ", 15, catchall),
("SHEBANG_NEW_PERL ", 16, catchall),
("SHEBANG_NEW_PHP ", 15, catchall),
("SHEBANG_NEW_PYTHON ", 18, catchall),
("SHEBANG_NEW_RUBY ", 16, catchall),
("SHEBANG_NEW_TCL ", 15, catchall),
("SHEBANG_NEW_TK ", 14, catchall),
("SHEBANG_NEW_ZSH ", 15, catchall),
("SHEBANG_OLD_BASH ", 16, catchall),
("SHEBANG_OLD_JAVA ", 16, catchall),
("SHEBANG_OLD_KSH ", 15, catchall),
("SHEBANG_OLD_PERL ", 16, catchall),
("SHEBANG_OLD_PHP ", 15, catchall),
("SHEBANG_OLD_PYTHON ", 18, catchall),
("SHEBANG_OLD_RUBY ", 16, catchall),
("SHEBANG_OLD_TCL ", 15, catchall),
("SHEBANG_OLD_TK ", 14, catchall),
("SHEBANG_OLD_ZSH ", 15, catchall),
("SHEBANG_REGEX ", 13, catchall),
("SINGLE_JOB ", 10, single_job),
("SKIP_BUILD ", 10, skip_build),
("SKIP_CCACHE ", 11, skip_ccache),
("SKIP_INSTALL ", 12, skip_install),
("SOL_FUNCTIONS ", 13, catchall),
("SOVERSION ", 9, so_version),
("SUB_FILES ", 9, sub_files),
("SUB_LIST ", 8, sub_list),
("TEST_ARGS ", 9, test_args),
("TEST_ENV ", 8, test_env),
("TEST_TARGET ", 11, test_target),
("USERGROUP_SPKG ", 14, ug_subpackage),
("USERS ", 5, users),
("USES ", 4, uses),
("VARIANTS ", 8, variants),
("VERSION ", 7, version),
("XORG_COMPONENTS ", 15, xorg_comp)
);
function nailed (index : Natural) return Boolean
is
len : Natural renames all_singlets (index).len;
apple : constant String := all_singlets (index).varname (1 .. len) & LAT.Equals_Sign;
begin
return line'Length > len + 2 and then
line (line'First .. line'First + len) = apple;
end nailed;
function less_than (index : Natural) return Boolean
is
len : Natural renames all_singlets (index).len;
apple : constant String := all_singlets (index).varname (1 .. len) & LAT.Equals_Sign;
begin
if line'Length > len + 2 then
return line (line'First .. line'First + len) < apple;
else
return line < apple;
end if;
end less_than;
Low : Natural := all_singlets'First;
High : Natural := all_singlets'Last;
Mid : Natural;
begin
if not HT.contains (S => line, fragment => "=" & LAT.HT) then
return not_singlet;
end if;
loop
Mid := (Low + High) / 2;
if nailed (Mid) then
return all_singlets (Mid).singlet;
elsif less_than (Mid) then
exit when Low = Mid;
High := Mid - 1;
else
exit when High = Mid;
Low := Mid + 1;
end if;
end loop;
return not_singlet;
end determine_singlet;
--------------------------------------------------------------------------------------------
-- determine_option
--------------------------------------------------------------------------------------------
function determine_option (line : String) return PSP.spec_option
is
total_helpers : constant Positive := 67;
subtype helper_string is String (1 .. 21);
type helper_pair is
record
varname : helper_string;
singlet : PSP.spec_option;
end record;
-- It is critical that this list be alphabetized correctly.
all_helpers : constant array (1 .. total_helpers) of helper_pair :=
(
("BROKEN_ON ", PSP.broken_on),
("BUILDRUN_DEPENDS_OFF ", PSP.buildrun_depends_off),
("BUILDRUN_DEPENDS_ON ", PSP.buildrun_depends_on),
("BUILD_DEPENDS_OFF ", PSP.build_depends_off),
("BUILD_DEPENDS_ON ", PSP.build_depends_on),
("BUILD_TARGET_OFF ", PSP.build_target_off),
("BUILD_TARGET_ON ", PSP.build_target_on),
("CFLAGS_OFF ", PSP.cflags_off),
("CFLAGS_ON ", PSP.cflags_on),
("CMAKE_ARGS_OFF ", PSP.cmake_args_off),
("CMAKE_ARGS_ON ", PSP.cmake_args_on),
("CMAKE_BOOL_F_BOTH ", PSP.cmake_bool_f_both),
("CMAKE_BOOL_T_BOTH ", PSP.cmake_bool_t_both),
("CONFIGURE_ARGS_OFF ", PSP.configure_args_off),
("CONFIGURE_ARGS_ON ", PSP.configure_args_on),
("CONFIGURE_ENABLE_BOTH", PSP.configure_enable_both),
("CONFIGURE_ENV_OFF ", PSP.configure_env_off),
("CONFIGURE_ENV_ON ", PSP.configure_env_on),
("CONFIGURE_WITH_BOTH ", PSP.configure_with_both),
("CPPFLAGS_OFF ", PSP.cppflags_off),
("CPPFLAGS_ON ", PSP.cppflags_on),
("CXXFLAGS_OFF ", PSP.cxxflags_off),
("CXXFLAGS_ON ", PSP.cxxflags_on),
("DESCRIPTION ", PSP.description),
("DF_INDEX_OFF ", PSP.df_index_off),
("DF_INDEX_ON ", PSP.df_index_on),
("EXTRACT_ONLY_OFF ", PSP.extract_only_off),
("EXTRACT_ONLY_ON ", PSP.extract_only_on),
("EXTRA_PATCHES_OFF ", PSP.extra_patches_off),
("EXTRA_PATCHES_ON ", PSP.extra_patches_on),
("GNOME_COMPONENTS_OFF ", PSP.gnome_comp_off),
("GNOME_COMPONENTS_ON ", PSP.gnome_comp_on),
("IMPLIES_ON ", PSP.implies_on),
("INFO_OFF ", PSP.info_off),
("INFO_ON ", PSP.info_on),
("INSTALL_TARGET_OFF ", PSP.install_target_off),
("INSTALL_TARGET_ON ", PSP.install_target_on),
("KEYWORDS_OFF ", PSP.keywords_off),
("KEYWORDS_ON ", PSP.keywords_on),
("LDFLAGS_OFF ", PSP.ldflags_off),
("LDFLAGS_ON ", PSP.ldflags_on),
("MAKEFILE_OFF ", PSP.makefile_off),
("MAKEFILE_ON ", PSP.makefile_on),
("MAKE_ARGS_OFF ", PSP.make_args_off),
("MAKE_ARGS_ON ", PSP.make_args_on),
("MAKE_ENV_OFF ", PSP.make_env_off),
("MAKE_ENV_ON ", PSP.make_env_on),
("ONLY_FOR_OPSYS_ON ", PSP.only_for_opsys_on),
("PATCHFILES_OFF ", PSP.patchfiles_off),
("PATCHFILES_ON ", PSP.patchfiles_on),
("PLIST_SUB_OFF ", PSP.plist_sub_off),
("PLIST_SUB_ON ", PSP.plist_sub_on),
("PREVENTS_ON ", PSP.prevents_on),
("QMAKE_ARGS_OFF ", PSP.qmake_args_off),
("QMAKE_ARGS_ON ", PSP.qmake_args_on),
("RUN_DEPENDS_OFF ", PSP.run_depends_off),
("RUN_DEPENDS_ON ", PSP.run_depends_on),
("SUB_FILES_OFF ", PSP.sub_files_off),
("SUB_FILES_ON ", PSP.sub_files_on),
("SUB_LIST_OFF ", PSP.sub_list_off),
("SUB_LIST_ON ", PSP.sub_list_on),
("TEST_TARGET_OFF ", PSP.test_target_off),
("TEST_TARGET_ON ", PSP.test_target_on),
("USES_OFF ", PSP.uses_off),
("USES_ON ", PSP.uses_on),
("XORG_COMPONENTS_OFF ", PSP.xorg_comp_off),
("XORG_COMPONENTS_ON ", PSP.xorg_comp_on)
);
end_opt_name : Natural;
end_varname : Natural;
testword_len : Natural;
bandolier : helper_string := (others => LAT.Space);
Low : Natural := all_helpers'First;
High : Natural := all_helpers'Last;
Mid : Natural;
begin
if line (line'First) /= LAT.Left_Square_Bracket then
return PSP.not_helper_format;
end if;
end_opt_name := AS.Fixed.Index (Source => line, Pattern => "].");
if end_opt_name = 0 then
return PSP.not_helper_format;
end if;
end_varname := AS.Fixed.Index (Source => line, Pattern => "=");
if end_varname = 0 or else end_varname < end_opt_name then
return PSP.not_helper_format;
end if;
testword_len := end_varname - end_opt_name - 2;
if testword_len < 6 or else testword_len > helper_string'Length then
return PSP.not_supported_helper;
end if;
bandolier (1 .. testword_len) := line (end_opt_name + 2 .. end_varname - 1);
loop
Mid := (Low + High) / 2;
if bandolier = all_helpers (Mid).varname then
return all_helpers (Mid).singlet;
elsif bandolier < all_helpers (Mid).varname then
exit when Low = Mid;
High := Mid - 1;
else
exit when High = Mid;
Low := Mid + 1;
end if;
end loop;
return PSP.not_supported_helper;
end determine_option;
--------------------------------------------------------------------------------------------
-- retrieve_single_value
--------------------------------------------------------------------------------------------
function retrieve_single_value (spec : PSP.Portspecs; line : String) return String
is
wrkstr : String (1 .. line'Length) := line;
equals : Natural := AS.Fixed.Index (wrkstr, LAT.Equals_Sign & LAT.HT);
c81624 : Natural := ((equals / 8) + 1) * 8;
-- f(4) = 8 ( 2 .. 7)
-- f(8) = 16; ( 8 .. 15)
-- f(18) = 24; (16 .. 23)
-- We are looking for an exact number of tabs starting at equals + 2:
-- if c81624 = 8, then we need 2 tabs. IF it's 16 then we need 1 tab,
-- if it's 24 then there can be no tabs, and if it's higher, that's a problem.
begin
if equals = 0 then
-- Support triple-tab line too.
if wrkstr'Length > 3 and then
wrkstr (wrkstr'First .. wrkstr'First + 2) = LAT.HT & LAT.HT & LAT.HT
then
equals := wrkstr'First + 1;
c81624 := 24;
else
raise missing_definition with "No triple-tab or equals+tab detected.";
end if;
end if;
if c81624 > 24 then
raise mistabbed;
end if;
declare
rest : constant String := wrkstr (equals + 2 .. wrkstr'Last);
contig_tabs : Natural := 0;
arrow : Natural := rest'First;
begin
loop
exit when arrow > rest'Last;
exit when rest (arrow) /= LAT.HT;
contig_tabs := contig_tabs + 1;
arrow := arrow + 1;
end loop;
if ((c81624 = 8) and then (contig_tabs /= 2)) or else
((c81624 = 16) and then (contig_tabs /= 1)) or else
((c81624 = 24) and then (contig_tabs /= 0))
then
raise mistabbed;
end if;
return expand_value (spec, rest (rest'First + contig_tabs .. rest'Last));
end;
end retrieve_single_value;
--------------------------------------------------------------------------------------------
-- retrieve_single_integer
--------------------------------------------------------------------------------------------
function retrieve_single_integer (spec : PSP.Portspecs; line : String) return Natural
is
result : Natural;
strvalue : constant String := retrieve_single_value (spec, line);
-- let any exceptions cascade
begin
result := Integer'Value (strvalue);
return result;
exception
when Constraint_Error =>
raise integer_expected;
end retrieve_single_integer;
--------------------------------------------------------------------------------------------
-- retrieve_key
--------------------------------------------------------------------------------------------
function retrieve_key (line : String; previous_index : HT.Text) return HT.Text
is
LB : Natural := AS.Fixed.Index (line, "[");
RB : Natural := AS.Fixed.Index (line, "]");
begin
if line'Length > 3 and then
line (line'First .. line'First + 2) = LAT.HT & LAT.HT & LAT.HT
then
return previous_index;
end if;
if LB = 0 or else
RB = 0 or else
RB <= LB + 1
then
return HT.SUS ("BOGUS"); -- should be impossible
end if;
return HT.SUS (line (LB + 1 .. RB - 1));
end retrieve_key;
--------------------------------------------------------------------------------------------
-- set_boolean
--------------------------------------------------------------------------------------------
procedure set_boolean (spec : in out PSP.Portspecs; field : PSP.spec_field; line : String)
is
value : String := retrieve_single_value (spec, line);
begin
if value = boolean_yes then
spec.set_boolean (field, True);
else
raise PSP.wrong_value with "boolean variables may only be set to '" & boolean_yes
& "' (was given '" & value & "')";
end if;
end set_boolean;
--------------------------------------------------------------------------------------------
-- set_natural
--------------------------------------------------------------------------------------------
procedure set_natural (spec : in out PSP.Portspecs; field : PSP.spec_field; line : String) is
begin
spec.set_natural_integer (field, retrieve_single_integer (spec, line));
end set_natural;
--------------------------------------------------------------------------------------------
-- build_string
--------------------------------------------------------------------------------------------
procedure build_string (spec : in out PSP.Portspecs; field : PSP.spec_field; line : String) is
begin
spec.set_single_string (field, retrieve_single_value (spec, line));
end build_string;
--------------------------------------------------------------------------------------------
-- build_nvpair
--------------------------------------------------------------------------------------------
procedure build_nvpair (spec : in out PSP.Portspecs; line : String)
is
function getkey return String;
strvalue : constant String := retrieve_single_value (spec, line);
function getkey return String is
begin
if HT.leads (line, LAT.HT & LAT.HT & LAT.HT) then
return spec.last_catchall_key;
else
return HT.part_1 (line, LAT.Equals_Sign & LAT.HT);
end if;
end getkey;
strkey : constant String := getkey;
begin
if HT.contains (S => strvalue, fragment => " ") then
declare
mask : constant String := UTL.mask_quoted_string (strvalue);
begin
if HT.contains (S => mask, fragment => " ") then
raise extra_spaces;
end if;
end;
end if;
spec.append_array (field => PSP.sp_catchall,
key => strkey,
value => strvalue,
allow_spaces => True);
end build_nvpair;
--------------------------------------------------------------------------------------------
-- build_list
--------------------------------------------------------------------------------------------
procedure build_list (spec : in out PSP.Portspecs; field : PSP.spec_field; line : String)
is
procedure insert_item (data : String);
arrow : Natural;
word_start : Natural;
strvalue : constant String := retrieve_single_value (spec, line);
-- let any exceptions cascade
procedure insert_item (data : String) is
begin
case field is
when PSP.sp_dl_groups =>
spec.establish_group (field, data);
when PSP.sp_variants =>
spec.append_list (field, data);
spec.establish_group (PSP.sp_subpackages, data);
if data /= variant_standard then
spec.establish_group (PSP.sp_vopts, data);
end if;
when others =>
spec.append_list (field, data);
end case;
end insert_item;
begin
-- Handle single item case
if not HT.contains (S => strvalue, fragment => " ") then
insert_item (strvalue);
return;
end if;
declare
mask : constant String := UTL.mask_quoted_string (strvalue);
begin
if HT.contains (S => mask, fragment => " ") or else
mask (mask'First) = LAT.Space
then
raise extra_spaces;
end if;
-- Now we have multiple list items separated by single spaces
-- We know the original line has no trailing spaces too, btw.
word_start := strvalue'First;
arrow := word_start;
loop
exit when arrow > strvalue'Last;
if mask (arrow) = LAT.Space then
insert_item (strvalue (word_start .. arrow - 1));
word_start := arrow + 1;
end if;
arrow := arrow + 1;
end loop;
end;
insert_item (strvalue (word_start .. strvalue'Last));
end build_list;
--------------------------------------------------------------------------------------------
-- build_group_list
--------------------------------------------------------------------------------------------
procedure build_group_list
(spec : in out PSP.Portspecs;
field : PSP.spec_field;
key : String;
value : String)
is
procedure insert_item (data : String);
arrow : Natural;
word_start : Natural;
procedure insert_item (data : String) is
begin
spec.append_array (field => field,
key => key,
value => data,
allow_spaces => False);
end insert_item;
begin
-- Handle single item case
if not HT.contains (S => value, fragment => " ") then
insert_item (value);
return;
end if;
declare
mask : constant String := UTL.mask_quoted_string (value);
begin
if HT.contains (S => mask, fragment => " ") or else
mask (mask'First) = LAT.Space
then
raise extra_spaces;
end if;
-- Now we have multiple list items separated by single spaces
-- We know the original line has no trailing spaces too, btw.
word_start := value'First;
arrow := word_start;
loop
exit when arrow > value'Last;
if mask (arrow) = LAT.Space then
insert_item (value (word_start .. arrow - 1));
word_start := arrow + 1;
end if;
arrow := arrow + 1;
end loop;
end;
insert_item (value (word_start .. value'Last));
end build_group_list;
--------------------------------------------------------------------------------------------
-- passed_late_validity_checks
--------------------------------------------------------------------------------------------
function late_validity_check_error (spec : PSP.Portspecs) return String
is
variant_check_result : String := spec.check_variants;
begin
if variant_check_result /= "" then
return "Variant '" & HT.part_1 (variant_check_result, ":") &
"' is missing the required '" & HT.part_2 (variant_check_result, ":") &
"' option configuration.";
end if;
if not spec.deprecation_valid then
return "DEPRECATED and EXPIRATION must both be set.";
end if;
if spec.missing_subpackage_definition then
return "At least one variant has no subpackages defined.";
end if;
if not spec.post_parse_license_check_passes then
return "The LICENSE settings are not valid.";
end if;
if not spec.post_parse_usergroup_check_passes then
return "The USERGROUP_SPKG definition is required when USERS or GROUPS is set";
end if;
if not spec.post_parse_opt_desc_check_passes then
return "Check above errors to determine which options have no descriptions";
end if;
if not spec.post_parse_option_group_size_passes then
return "check above errors to determine which option groups are too small";
end if;
return "";
end late_validity_check_error;
--------------------------------------------------------------------------------------------
-- determine_target
--------------------------------------------------------------------------------------------
function determine_target
(spec : PSP.Portspecs;
line : String;
last_seen : type_category) return spec_target
is
function active_prefix return String;
function extract_option (prefix, line : String) return String;
lead_pre : Boolean := False;
lead_do : Boolean := False;
lead_post : Boolean := False;
fetch : constant String := "fetch";
extract : constant String := "extract";
patch : constant String := "patch";
configure : constant String := "configure";
build : constant String := "build";
install : constant String := "install";
stage : constant String := "stage";
test : constant String := "test";
opt_on : constant String := "-ON:";
opt_off : constant String := "-OFF:";
pre_pre : constant String := "pre-";
pre_do : constant String := "do-";
pre_post : constant String := "post-";
function active_prefix return String is
begin
if lead_pre then
return pre_pre;
elsif lead_do then
return pre_do;
else
return pre_post;
end if;
end active_prefix;
function extract_option (prefix, line : String) return String
is
function first_set_successful (substring : String) return Boolean;
-- Given: Line terminates in "-ON:" or "-OFF:"
last : Natural;
first : Natural := 0;
function first_set_successful (substring : String) return Boolean is
begin
if HT.leads (line, substring) then
first := line'First + substring'Length;
return True;
else
return False;
end if;
end first_set_successful;
begin
if HT.trails (line, opt_on) then
last := line'Last - opt_on'Length;
else
last := line'Last - opt_off'Length;
end if;
if first_set_successful (prefix & fetch & LAT.Hyphen) or else
first_set_successful (prefix & extract & LAT.Hyphen) or else
first_set_successful (prefix & patch & LAT.Hyphen) or else
first_set_successful (prefix & configure & LAT.Hyphen) or else
first_set_successful (prefix & build & LAT.Hyphen) or else
first_set_successful (prefix & install & LAT.Hyphen) or else
first_set_successful (prefix & stage & LAT.Hyphen) or else
first_set_successful (prefix & test & LAT.Hyphen)
then
return line (first .. last);
else
return "";
end if;
end extract_option;
begin
if last_seen = cat_target then
-- If the line starts with a period or if it has a single tab, then mark it as
-- as a target body and leave. We don't need to check more.
if line (line'First) = LAT.Full_Stop or else
line (line'First) = LAT.HT
then
return target_body;
end if;
end if;
-- Check if line has format of a target (ends in a colon)
if not HT.trails (line, ":") then
return not_target;
end if;
-- From this point forward, we're either a target_title or bad_target
lead_pre := HT.leads (line, pre_pre);
if not lead_pre then
lead_do := HT.leads (line, pre_do);
if not lead_do then
lead_post := HT.leads (line, pre_post);
if not lead_post then
return bad_target;
end if;
end if;
end if;
declare
prefix : constant String := active_prefix;
begin
-- Handle pre-, do-, post- target overrides
if line = prefix & fetch & LAT.Colon or else
line = prefix & fetch & LAT.Colon or else
line = prefix & extract & LAT.Colon or else
line = prefix & patch & LAT.Colon or else
line = prefix & configure & LAT.Colon or else
line = prefix & build & LAT.Colon or else
line = prefix & install & LAT.Colon or else
line = prefix & stage & LAT.Colon or else
line = prefix & test & LAT.Colon
then
return target_title;
end if;
-- Opsys also applies to pre-, do-, and post-
for opsys in supported_opsys'Range loop
declare
lowsys : String := '-' & UTL.lower_opsys (opsys) & LAT.Colon;
begin
if line = prefix & fetch & lowsys or else
line = prefix & extract & lowsys or else
line = prefix & patch & lowsys or else
line = prefix & configure & lowsys or else
line = prefix & build & lowsys or else
line = prefix & install & lowsys or else
line = prefix & install & lowsys or else
line = prefix & test & lowsys
then
return target_title;
end if;
end;
end loop;
-- The only targets left to check are options which end in "-ON:" and "-OFF:".
-- If these suffices aren't found, it's a bad target.
if not HT.trails (line, opt_on) and then
not HT.trails (line, opt_off)
then
return bad_target;
end if;
declare
option_name : String := extract_option (prefix, line);
begin
if spec.option_exists (option_name) then
return target_title;
else
return bad_target;
end if;
end;
end;
end determine_target;
--------------------------------------------------------------------------------------------
-- extract_option_name
--------------------------------------------------------------------------------------------
function extract_option_name
(spec : PSP.Portspecs;
line : String;
last_name : HT.Text) return String
is
-- Already known: first character = "]" and there's "]." present
candidate : String := HT.partial_search (fullstr => line,
offset => 1,
end_marker => "].");
tabs5 : String (1 .. 5) := (others => LAT.HT);
begin
if candidate = "" and then
line'Length > 5 and then
line (line'First .. line'First + 4) = tabs5
then
return HT.USS (last_name);
end if;
if spec.option_exists (candidate) then
return candidate;
else
return "";
end if;
end extract_option_name;
--------------------------------------------------------------------------------------------
-- build_list
--------------------------------------------------------------------------------------------
procedure build_list
(spec : in out PSP.Portspecs;
field : PSP.spec_option;
option : String;
line : String)
is
procedure insert_item (data : String);
arrow : Natural;
word_start : Natural;
strvalue : constant String := retrieve_single_option_value (spec, line);
-- let any exceptions cascade
procedure insert_item (data : String) is
begin
spec.build_option_helper (field => field,
option => option,
value => data);
end insert_item;
use type PSP.spec_option;
begin
if field = PSP.broken_on or else field = PSP.description then
spec.build_option_helper (field => field,
option => option,
value => strvalue);
return;
end if;
-- Handle single item case
if not HT.contains (S => strvalue, fragment => " ") then
insert_item (strvalue);
return;
end if;
declare
mask : constant String := UTL.mask_quoted_string (strvalue);
begin
if HT.contains (S => mask, fragment => " ") or else
mask (mask'First) = LAT.Space
then
raise extra_spaces;
end if;
-- Now we have multiple list items separated by single spaces
-- We know the original line has no trailing spaces too, btw.
word_start := strvalue'First;
arrow := word_start;
loop
exit when arrow > strvalue'Last;
if mask (arrow) = LAT.Space then
insert_item (strvalue (word_start .. arrow - 1));
word_start := arrow + 1;
end if;
arrow := arrow + 1;
end loop;
end;
insert_item (strvalue (word_start .. strvalue'Last));
end build_list;
--------------------------------------------------------------------------------------------
-- retrieve_single_option_value
--------------------------------------------------------------------------------------------
function retrieve_single_option_value (spec : PSP.Portspecs; line : String) return String
is
wrkstr : String (1 .. line'Length) := line;
equals : Natural := AS.Fixed.Index (wrkstr, LAT.Equals_Sign & LAT.HT);
c81624 : Natural := ((equals / 8) + 1) * 8;
tabs5 : String (1 .. 5) := (others => LAT.HT);
-- f(4) = 8 ( 2 .. 7)
-- f(8) = 16; ( 8 .. 15)
-- f(18) = 24; (16 .. 23)
-- We are looking for an exact number of tabs starting at equals + 2:
-- if c81624 = 8, then we need 2 tabs. IF it's 16 then we need 1 tab,
-- if it's 24 then there can be no tabs, and if it's higher, that's a problem.
begin
if equals = 0 then
-- Support quintuple-tab line too.
if wrkstr'Length > 5 and then
wrkstr (wrkstr'First .. wrkstr'First + 4) = tabs5
then
equals := wrkstr'First + 3;
c81624 := 40;
else
raise missing_definition with "No quintuple-tab or equals+tab detected.";
end if;
end if;
if c81624 > 40 then
raise mistabbed_40;
end if;
declare
rest : constant String := wrkstr (equals + 2 .. wrkstr'Last);
contig_tabs : Natural := 0;
arrow : Natural := rest'First;
begin
loop
exit when arrow > rest'Last;
exit when rest (arrow) /= LAT.HT;
contig_tabs := contig_tabs + 1;
arrow := arrow + 1;
end loop;
if ((c81624 = 8) and then (contig_tabs /= 4)) or else
((c81624 = 16) and then (contig_tabs /= 3)) or else
((c81624 = 24) and then (contig_tabs /= 2)) or else
((c81624 = 32) and then (contig_tabs /= 1)) or else
((c81624 = 40) and then (contig_tabs /= 0))
then
raise mistabbed_40;
end if;
return expand_value (spec, rest (rest'First + contig_tabs .. rest'Last));
end;
end retrieve_single_option_value;
--------------------------------------------------------------------------------------------
-- is_file_capsule
--------------------------------------------------------------------------------------------
function is_file_capsule (line : String) return Boolean
is
-- format: [FILE:XXXX:filename]
dummy : Integer;
begin
if line (line'Last) /= LAT.Right_Square_Bracket then
return False;
end if;
if not HT.leads (line, "[FILE:") then
return False;
end if;
if HT.count_char (line, LAT.Colon) /= 2 then
return False;
end if;
dummy := Integer'Value (HT.partial_search (line, 6, ":"));
return True;
exception
when others =>
return False;
end is_file_capsule;
--------------------------------------------------------------------------------------------
-- retrieve_file_size
--------------------------------------------------------------------------------------------
function retrieve_file_size (capsule_label : String) return Natural
is
result : Natural;
begin
result := Integer'Value (HT.partial_search (capsule_label, 6, ":"));
if result > 0 then
return result;
else
return 0;
end if;
exception
when others =>
return 0;
end retrieve_file_size;
--------------------------------------------------------------------------------------------
-- retrieve_file_name
--------------------------------------------------------------------------------------------
function retrieve_file_name (capsule_label : String) return String is
begin
return HT.part_2 (HT.partial_search (capsule_label, 6, "]"), ":");
end retrieve_file_name;
--------------------------------------------------------------------------------------------
-- tranform_filenames
--------------------------------------------------------------------------------------------
function tranform_filename
(filename : String;
match_opsys : String;
match_arch : String) return String
is
pm : constant String := "pkg-message-";
sys : constant String := "opsys";
arc : constant String := "arch";
files : constant String := "files/";
pmlen : constant Natural := pm'Length;
justfile : constant String := HT.part_2 (filename, "/");
begin
if justfile'Length < pmlen + 4 or else
justfile (justfile'First .. justfile'First + pmlen - 1) /= pm
then
return "";
end if;
return HT.USS (HT.replace_substring
(US => HT.replace_substring (HT.SUS (filename), match_opsys, sys),
old_string => match_arch,
new_string => arc));
end tranform_filename;
--------------------------------------------------------------------------------------------
-- valid_conditional_variable
--------------------------------------------------------------------------------------------
function valid_conditional_variable (candidate : String) return Boolean
is
is_namepair : constant Boolean := HT.contains (candidate, "=");
part_name : constant String := HT.part_1 (candidate, "=");
begin
if not is_namepair then
return False;
end if;
declare
possible_singlet : String := part_name & LAT.Equals_Sign & LAT.HT & 'x';
this_singlet : spec_singlet := determine_singlet (possible_singlet);
begin
case this_singlet is
when cflags | cppflags | cxxflags | ldflags | plist_sub |
config_args | config_env | make_args | make_env |
cmake_args | qmake_args =>
null;
when not_singlet =>
if not (part_name = "VAR1" or else
part_name = "VAR2" or else
part_name = "VAR3" or else
part_name = "VAR4" or else
part_name = "MAKEFILE_LINE")
then
return False;
end if;
when others =>
return False;
end case;
declare
payload : String := HT.part_2 (candidate, "=");
mask : String := UTL.mask_quoted_string (payload);
found_spaces : Boolean := HT.contains (payload, " ");
begin
if found_spaces then
return not HT.contains (mask, " ");
else
return True;
end if;
end;
end;
end valid_conditional_variable;
--------------------------------------------------------------------------------------------
-- transform_target_line
--------------------------------------------------------------------------------------------
function transform_target_line
(spec : PSP.Portspecs;
line : String;
skip_transform : Boolean) return String
is
arrow1 : Natural := 0;
arrow2 : Natural := 0;
back_marker : Natural := 0;
canvas : HT.Text := HT.blank;
begin
if skip_transform or else
spec.no_definitions or else
line = ""
then
return line;
end if;
back_marker := line'First;
loop
arrow1 := AS.Fixed.Index (Source => line,
Pattern => "${",
From => back_marker);
if arrow1 = 0 then
HT.SU.Append (canvas, line (back_marker .. line'Last));
exit;
end if;
arrow2 := AS.Fixed.Index (Source => line,
Pattern => "}",
From => arrow1 + 2);
if arrow2 = 0 then
HT.SU.Append (canvas, line (back_marker .. line'Last));
exit;
end if;
-- We've found a candidate. Save the leader and attempt to replace.
if arrow1 > back_marker then
HT.SU.Append (canvas, line (back_marker .. arrow1 - 1));
end if;
back_marker := arrow2 + 1;
if arrow2 - 1 > arrow1 + 2 then
begin
declare
newval : HT.Text := HT.SUS (expand_value (spec, line (arrow1 .. arrow2)));
begin
UTL.apply_cbc_string (newval);
HT.SU.Append (canvas, newval);
end;
exception
when others =>
-- It didn't expand, so keep it.
HT.SU.Append (canvas, line (arrow1 .. arrow2));
end;
else
-- This is "${}", just keep it.
HT.SU.Append (canvas, line (arrow1 .. arrow2));
end if;
exit when back_marker > line'Last;
end loop;
return HT.USS (canvas);
end transform_target_line;
--------------------------------------------------------------------------------------------
-- extract_version
--------------------------------------------------------------------------------------------
function extract_version (varname : String) return String
is
consdir : String := HT.USS (Parameters.configuration.dir_conspiracy);
extmake : String := HT.USS (Parameters.configuration.dir_sysroot) & "/usr/bin/make -m " &
consdir & "/Mk";
command : String := extmake & " -f " & consdir & "/Mk/raven.versions.mk -V " & varname;
status : Integer;
result : HT.Text := Unix.piped_command (command, status);
begin
return HT.first_line (HT.USS (result));
end extract_version;
--------------------------------------------------------------------------------------------
-- extract_information
--------------------------------------------------------------------------------------------
function extract_information (varname : String) return String
is
consdir : String := HT.USS (Parameters.configuration.dir_conspiracy);
extmake : String := HT.USS (Parameters.configuration.dir_sysroot) & "/usr/bin/make -m " &
consdir & "/Mk";
command : String := extmake & " -f " & consdir & "/Mk/raven.information.mk -V " & varname;
status : Integer;
result : HT.Text := Unix.piped_command (command, status);
begin
return HT.first_line (HT.USS (result));
end extract_information;
--------------------------------------------------------------------------------------------
-- verify_extra_file_exists
--------------------------------------------------------------------------------------------
procedure verify_extra_file_exists
(spec : PSP.Portspecs;
specfile : String;
line : String;
is_option : Boolean;
sub_file : Boolean)
is
function get_payload return String;
function get_full_filename (basename : String) return String;
procedure perform_check (filename : String);
arrow : Natural;
word_start : Natural;
filesdir : String := DIR.Containing_Directory (specfile) & "/files";
function get_payload return String is
begin
if is_option then
return retrieve_single_option_value (spec, line);
else
return retrieve_single_value (spec, line);
end if;
end get_payload;
function get_full_filename (basename : String) return String is
begin
if sub_file then
return basename & ".in";
else
return basename;
end if;
end get_full_filename;
procedure perform_check (filename : String)
is
adjusted_filename : String := get_full_filename (filename);
begin
if not DIR.Exists (filesdir & "/" & adjusted_filename) then
raise missing_file with "'" & adjusted_filename & "' is missing from files directory";
end if;
end perform_check;
strvalue : String := get_payload;
begin
-- Handle single item case
if not HT.contains (S => strvalue, fragment => " ") then
perform_check (strvalue);
return;
end if;
declare
mask : constant String := UTL.mask_quoted_string (strvalue);
begin
if HT.contains (S => mask, fragment => " ") or else
mask (mask'First) = LAT.Space
then
raise extra_spaces;
end if;
-- Now we have multiple list items separated by single spaces
-- We know the original line has no trailing spaces too, btw.
word_start := strvalue'First;
arrow := word_start;
loop
exit when arrow > strvalue'Last;
if mask (arrow) = LAT.Space then
perform_check (strvalue (word_start .. arrow - 1));
word_start := arrow + 1;
end if;
arrow := arrow + 1;
end loop;
end;
perform_check (strvalue (word_start .. strvalue'Last));
end verify_extra_file_exists;
--------------------------------------------------------------------------------------------
-- transform_download_sites
--------------------------------------------------------------------------------------------
procedure transform_download_sites (site : in out HT.Text) is
begin
-- special case, GITHUB_PRIVATE (aka GHPRIV).
-- If found, append with site with ":<token>" where <token> is the contents of
-- confdir/tokens/account-project (or ":missing-security-token" if not found)
-- With this case, there is always 4 colons / 5 fields. The 4th (extraction directory)
-- is often blank
if HT.leads (site, "GITHUB_PRIVATE/") or else HT.leads (site, "GHPRIV/") then
declare
notoken : constant String := ":missing-security-token";
triplet : constant String := HT.part_2 (HT.USS (site), "/");
ncolons : constant Natural := HT.count_char (triplet, ':');
begin
if ncolons < 3 then
HT.SU.Append (site, ':');
end if;
if ncolons >= 2 then
declare
account : constant String := HT.specific_field (triplet, 1, ":");
project : constant String := HT.specific_field (triplet, 2, ":");
tfile : constant String := Parameters.raven_confdir &
"/tokens/" & account & '-' & project;
token : constant String := FOP.get_file_contents (tfile);
begin
HT.SU.Append (site, ':' & token);
end;
end if;
exception
when others =>
HT.SU.Append (site, notoken);
end;
end if;
end transform_download_sites;
end Specification_Parser;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . B B . P A R A M E T E R S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1999-2002 Universidad Politecnica de Madrid --
-- Copyright (C) 2003-2005 The European Space Agency --
-- Copyright (C) 2003-2016, AdaCore --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- 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. --
-- --
-- The port of GNARL to bare board targets was initially developed by the --
-- Real-Time Systems Group at the Technical University of Madrid. --
-- --
------------------------------------------------------------------------------
-- This package defines basic parameters used by the low level tasking system
-- This is the ERC32/LEON/LEON3 version of this package
pragma Restrictions (No_Elaboration_Code);
with System.BB.Board_Parameters;
package System.BB.Parameters is
pragma Pure;
--------------------
-- Hardware clock --
--------------------
Clock_Frequency : constant := System.BB.Board_Parameters.Clock_Frequency;
-- Frequency of the system clock
Ticks_Per_Second : constant :=
Clock_Frequency / (Board_Parameters.Prescaler_Min + 1);
-- The prescaler is clocked by the system clock. When it underflows, it
-- is reloaded from the prescaler reload register and a timer tick is
-- generated. The effective division rate is therefore equal to the
-- prescaler reload register value plus 1.
----------------
-- Interrupts --
----------------
-- The following are ERC32/LEON/LEON3 definitions and they cannot be
-- modified.
-- These definitions are in this package in order to isolate target
-- dependencies.
Interrupt_Range_Last : constant :=
(if Board_Parameters.Extended_Interrupts_Level /= 0 then 31 else 15);
subtype Interrupt_Range is Natural range 1 .. Interrupt_Range_Last;
-- Number of interrupts in the SPARC architecture
Trap_Vectors : constant := 256;
-- The SPARC arquitecture supports 256 vectors
------------------------
-- Context Management --
------------------------
-- The SPARC processor needs to save:
--
-- * 18 integer registers of 32 bits (7 global, 8 output, PSR, Y, and WIM)
-- for normal processing
--
-- * 33 floating point registers of 32 bits
--
-- * the number of register windows saved to the stack
-- (the input and local registers are saved to the stack).
--
-- * interrupt nesting level corresponding to the task
--
-- * for LEON, to slots for the Cache Control Register
--
-- This would be 55 slots for LEON/LEON3 and 53 otherwise, but
-- this need to be rounded up to an even number to allow more
-- efficient access.
--
-- For LEON, we store the Cache Control Register to be able to keep the
-- cache status per task. We keep the base Cache Control Register (which
-- is not affected by automatic changes related to the freeze-on-interrupt
-- capability) and the actual Cache Control Register (the one directly
-- extracted from the hardware).
Base_CCR_Context_Index : constant := 53;
CCR_Context_Index : constant := 54;
Context_Buffer_Capacity : constant := 56;
------------
-- Stacks --
------------
Interrupt_Stack_Size : constant := 8 * 1024; -- bytes
-- Size of each of the interrupt stacks
----------
-- CPUS --
----------
Max_Number_Of_CPUs : constant := Board_Parameters.Max_Number_Of_CPUs;
-- Maximum number of CPUs
Multiprocessor : constant Boolean := Max_Number_Of_CPUs /= 1;
-- Are we on a multiprocessor board?
end System.BB.Parameters;
|
with GNATCOLL.Strings_Impl;
with Ada.Wide_Wide_Characters.Handling, Ada.Characters;
use Ada.Wide_Wide_Characters.Handling;
with Ada.Characters.Conversions;
with Ada.Containers.Doubly_Linked_Lists;
with GNATCOLL.Config;
with Templates_Parser;
with Ada.Strings.Maps;
package Generator is
use Templates_Parser;
package aString is new GNATCOLL.Strings_Impl.Strings
(SSize => GNATCOLL.Strings_Impl.Optimal_String_Size,
Character_Type => Wide_Wide_Character,
Character_String => Wide_Wide_String);
use Generator.aString;
type Document is record
Filepath : XString := Null_XString;
Targetpath : XString := Null_XString;
Filename : XString := Null_XString;
Basename : XString := Null_XString;
Linkpath : XString := Null_XString;
Layout : XString := Null_XString;
Content : XString := Null_XString;
T : Translate_Set;
end record;
package Document_Container is new Ada.Containers.Doubly_Linked_Lists
(Document);
use Document_Container;
function "<" (Left, Right : Document) return Boolean;
package Document_List_Sorting is new Document_Container.Generic_Sorting;
use Document_List_Sorting;
Slash : constant Ada.Strings.Maps.Character_Set :=
Ada.Strings.Maps.To_Set ("/");
Debug : Boolean := False;
procedure Process_File
(List : out Document_Container.List;
Filepath : String;
Targetpath : String;
Linkpath : String);
procedure Process_Directory
(List : out Document_Container.List;
Source_Directory : String;
Target_Directory : String;
LinkpathIn : String);
procedure Process_Documents (
List : Document_Container.List;
Set : Translate_Set;
Layoutfolder : String;
Source_Directory : String;
Targetpath : String);
function Create_Vector (
List : Document_Container.List;
Prefix : String) return Translate_Set;
function Get_Nav_Links (
Document : Cursor;
List : Document_Container.List) return Translate_Set;
function Read_From_Set (Set : Translate_Set; Token : String) return String;
procedure Start (Source_Directory : String; Target_Directory : String);
private
end Generator;
|
pragma Ada_2012;
package body Protypo.Api.Field_Names is
--------------
-- Is_Field --
--------------
function Is_Field (X : ID) return Boolean is
Ignored : Field_Enumerator;
begin
Ignored := To_Field (x);
return True;
-- Yes, I know, it is not the best practice to use exceptions
-- to do flow control, but this is the easiest way
exception
when Constraint_Error =>
return False;
end Is_Field;
--------------
-- To_Field --
--------------
function To_Field (X : ID) return Field_Enumerator
is (Field_Enumerator'Value (Prefix & String (X)));
end Protypo.Api.Field_Names;
|
-- This package has been generated automatically by GNATtest.
-- Do not edit any part of it, see GNATtest documentation for more details.
-- begin read only
with GNATtest_Generated;
package Tk.Frame.Frame_Create_Options_Test_Data.Frame_Create_Options_Tests is
type Test_Frame_Create_Options is new GNATtest_Generated.GNATtest_Standard
.Tk
.Frame
.Frame_Create_Options_Test_Data
.Test_Frame_Create_Options with
null record;
procedure Test_Create_32e405_154917
(Gnattest_T: in out Test_Frame_Create_Options);
-- tk-frame.ads:147:4:Create:Test_Create_Frame1
procedure Test_Create_ebbdc1_471f4e
(Gnattest_T: in out Test_Frame_Create_Options);
-- tk-frame.ads:180:4:Create:Test_Create_Frame2
procedure Test_Get_Options_ded36e_ce77f0
(Gnattest_T: in out Test_Frame_Create_Options);
-- tk-frame.ads:204:4:Get_Options:Test_Get_Options_Frame
end Tk.Frame.Frame_Create_Options_Test_Data.Frame_Create_Options_Tests;
-- end read only
|
with Ada.Interrupts.Names; use Ada.Interrupts.Names;
with Ada.Synchronous_Task_Control; use Ada.Synchronous_Task_Control;
package RTC_IRQ is
Alarm_Occurred : Suspension_Object;
protected Handler is
pragma Interrupt_Priority;
private
procedure IRQ_Handler;
pragma Attach_Handler (IRQ_Handler, RTC);
end Handler;
end RTC_IRQ;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.