repo_name
stringlengths 9
74
| language
stringclasses 1
value | length_bytes
int64 11
9.34M
| extension
stringclasses 2
values | content
stringlengths 11
9.34M
|
---|---|---|---|---|
charlie5/lace | Ada | 666 | ads | package lace.Dice with Pure
--
-- Provides an abstract model of any sided dice.
--
is
type Item is abstract tagged private;
type an_Extent is
record
Min, Max : Integer;
end record;
-- Attributes
--
function side_Count (Self : in Item) return Positive is abstract;
function Roll (Self : in Item) return Natural is abstract;
function Extent (Self : in Item'Class) return an_Extent;
function Image (Self : in Item'Class) return String;
private
type Item is abstract tagged
record
roll_Count : Positive;
Modifier : Integer;
end record;
end lace.Dice;
|
AdaCore/training_material | Ada | 116 | ads | package Types is
Max_Int : constant := 2**15;
type Integer_T is range -(Max_Int) .. Max_Int - 1;
end Types;
|
reznikmm/matreshka | Ada | 3,630 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Elements.Generic_Hash;
function AMF.CMOF.Opaque_Expressions.Hash is
new AMF.Elements.Generic_Hash (CMOF_Opaque_Expression, CMOF_Opaque_Expression_Access);
|
joakim-strandberg/wayland_ada_binding | Ada | 2,735 | ads | with Interfaces.C;
package C_Binding.Linux.Posix_Select is
type File_Descriptor_Count is range 1 .. 1024;
type Fds_Bits_Index is range 0 .. 1023;
-- The interval is chosen 0 .. 1023 to be able to use file descriptors
-- as index into the Fds_Bits_Array.
type File_Descriptor_Set is limited private;
procedure Clear (This : in out File_Descriptor_Set);
procedure Set_File_Descriptor
(This : in out File_Descriptor_Set;
Descriptor : Integer);
type Time_Seconds is new Interfaces.C.long;
type Time_Micro_Seconds is new Interfaces.C.long;
type Time_Value is record
Seconds : Time_Seconds;
Micro_Seconds : Time_Micro_Seconds;
end record;
type Call_Select_Result_Id is
(
Select_Failure, -- Check errno
Select_Timeout, -- Select timed out, no file descriptor events detected
Select_Success
);
type Call_Select_Result (Id : Call_Select_Result_Id) is record
case Id is
when Select_Failure =>
null;
when Select_Timeout =>
null;
when Select_Success =>
Descriptor_Count : File_Descriptor_Count;
end case;
end record;
function Call_Select
(File_Descriptor : Integer;
Read_File_Descriptors : access File_Descriptor_Set;
Write_File_Descriptors : access File_Descriptor_Set;
Except_File_Descriptors : access File_Descriptor_Set;
Time : Time_Value) return Call_Select_Result;
private
type Fds_Bits_Array is array (Fds_Bits_Index) of Boolean with Pack;
type fd_set is record
Fds_Bits : aliased Fds_Bits_Array;
end record with
Convention => C_Pass_By_Copy,
Size => 1024;
type File_Descriptor_Set is limited record
Descriptors : aliased fd_set;
end record;
type timeval is record
tv_sec : aliased long;
tv_usec : aliased long; -- Microseconds!
end record with
Convention => C_Pass_By_Copy;
function C_Select
(File_Descriptor : Integer;
Readfds : access fd_set;
Writefds : access fd_set;
Exceptfds : access fd_set;
Time : access timeval) return Interfaces.C.int;
pragma Import (C, C_Select, "select");
-- On success, returns the number of file descriptors contained
-- in the three returned descriptor sets (that is,
-- the total number of bits that are set in readfds, writefds, exceptfds)
-- which may be zero if the timeout expires before
-- anything interesting happens. On error, -1 is returned,
-- and errno is set appropriately; the sets and timeout become undefined,
-- so do not rely on their contents after an error.
end C_Binding.Linux.Posix_Select;
|
AdaCore/training_material | Ada | 194 | ads | package Solar_System.Graphics is
procedure Draw_All (Bodies : Bodies_Array_T; Canvas : Canvas_ID);
procedure Draw_Body (Object : Body_T; Canvas : Canvas_ID);
end Solar_System.Graphics;
|
AdaCore/gpr | Ada | 21,374 | adb | --
-- Copyright (C) 2019-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
--
with GPR2.Project.Tree;
with GPR2.Project.Definition;
package body GPR2.Project.Source.Artifact is
type Artifact_Dir is (Object_Dir, Library_ALI_Dir);
function At_Suffix (At_Pos : Unit_Index) return Filename_Type;
-- Returns 'at' index from attribute value or index prefixed with '~'
-- character to use in filenames.
function From_Hierarchy
(View : Project.View.Object;
Source : Project.Source.Object;
Filename : Filename_Type;
Dir_Attr : Artifact_Dir;
Full_Closure : Boolean := False) return GPR2.Path_Name.Object
with Pre => View.Is_Defined and then Source.Is_Defined;
-- Find Filename in directory defined in attribute Dir_Attr in this
-- source view and in the extended views if the Source is inherited.
-- If Full_Closure is set, then the full closure of the extended
-- projects (in case of extends all) will be searched.
procedure Insert_If_Defined
(Map : in out Index_Path_Name_Map.Map;
Index : Unit_Index;
Path : GPR2.Path_Name.Object);
-- If Path is defined, include it in Map with index Index, else do
-- nothing.
---------------
-- At_Suffix --
---------------
function At_Suffix (At_Pos : Unit_Index) return Filename_Type is
Result : String := At_Pos'Img;
begin
Result (Result'First) := '~';
return Filename_Type (Result);
end At_Suffix;
---------------
-- Callgraph --
---------------
function Callgraph
(Self : Object;
Index : Unit_Index := No_Index) return GPR2.Path_Name.Object is
begin
return Self.Callgraph (Index);
end Callgraph;
--------------
-- Coverage --
--------------
function Coverage
(Self : Object;
Index : Unit_Index := No_Index) return GPR2.Path_Name.Object is
begin
return Self.Coverage (Index);
end Coverage;
------------
-- Create --
------------
function Create
(Source : Project.Source.Object;
Force_Spec : Boolean := False;
Filter : Artifact.Filter := All_Artifacts) return Artifact.Object
is
procedure Get_Object_Artifacts
(BN : Filename_Type;
Index : Unit_Index);
-- Retrieve object and ali files for a given unit, if any
procedure Get_Source_Artifacts;
-- Retrieve preprocessed source, callgraph, coverage and switches
-- artifacts
Lang : constant Language_Id := Source.Language;
View : constant Project.View.Object :=
Definition.Strong (Source.View);
O_Suffix : constant Filename_Type := View.Tree.Object_Suffix (Lang);
D_Suffix : constant Filename_Type :=
View.Tree.Dependency_Suffix (Lang);
C_Suffix : constant Filename_Type := ".ci";
P_Suffix : constant Filename_Type := ".prep";
S_Suffix : constant Filename_Type := ".cswi";
Cov_Suffix : constant Filename_Type := ".sid";
Object_Files : Index_Path_Name_Map.Map;
Deps_Lib : Index_Path_Name_Map.Map;
Deps_Obj : Index_Path_Name_Map.Map;
Preprocessed : GPR2.Path_Name.Object;
Callgraph : Index_Path_Name_Map.Map;
Coverage : Index_Path_Name_Map.Map;
Switches : Index_Path_Name_Map.Map;
--------------------------
-- Get_Object_Artifacts --
--------------------------
procedure Get_Object_Artifacts
(BN : Filename_Type;
Index : Unit_Index) is
begin
if Filter (Dependency_File) then
if Force_Spec then
Deps_Lib.Include
(Index, GPR2.Path_Name.Create_File (BN & D_Suffix));
else
Insert_If_Defined
(Deps_Lib,
Index,
From_Hierarchy
(View, Source, BN & D_Suffix, Library_ALI_Dir, True));
end if;
end if;
if View.Kind /= K_Aggregate_Library then
if Filter (Object_File) then
if Force_Spec then
Object_Files.Include
(Index, GPR2.Path_Name.Create_File (BN & O_Suffix));
else
Insert_If_Defined
(Object_Files,
Index,
From_Hierarchy
(View, Source, BN & O_Suffix, Object_Dir, True));
end if;
end if;
if Filter (Dependency_File) then
if Force_Spec then
Deps_Obj.Include
(Index, GPR2.Path_Name.Create_File (BN & D_Suffix));
else
Insert_If_Defined
(Deps_Obj,
Index,
From_Hierarchy
(View, Source, BN & D_Suffix, Object_Dir, True));
end if;
end if;
if Filter (Artifact.Callgraph) then
Callgraph.Include
(Index,
GPR2.Path_Name.Create_File
(BN & C_Suffix,
Filename_Type (View.Object_Directory.Value)));
end if;
if Filter (Artifact.Coverage) then
Coverage.Include
(Index,
GPR2.Path_Name.Create_File
(BN & Cov_Suffix,
Filename_Type (View.Object_Directory.Value)));
end if;
if Filter (Artifact.Switches) then
Switches.Include
(Index,
GPR2.Path_Name.Create_File
(BN & S_Suffix,
Filename_Type (View.Object_Directory.Value)));
end if;
end if;
end Get_Object_Artifacts;
--------------------------
-- Get_Source_Artifacts --
--------------------------
procedure Get_Source_Artifacts is
begin
if Filter (Preprocessed_Source) then
Preprocessed := GPR2.Path_Name.Create_File
(Source.Path_Name.Simple_Name & P_Suffix,
Filename_Optional (View.Object_Directory.Value));
end if;
end Get_Source_Artifacts;
BN : constant Filename_Type := Source.Path_Name.Base_Filename;
begin
if Source.Has_Units then
for CU of Source.Units loop
-- Only consider object artifacts for the body part or if the
-- spec has no body, except when Force_Spec is set (in which case
-- don't check anything and just return the simple name).
if (CU.Kind in GPR2.Unit.Body_Kind | GPR2.Unit.S_Spec_Only)
or else (Force_Spec and then CU.Kind = GPR2.Unit.S_Spec)
then
declare
Base : constant Filename_Type :=
(if Source.Has_Index
then BN & At_Suffix (CU.Index)
else BN);
begin
Get_Object_Artifacts (Base, CU.Index);
end;
end if;
end loop;
else
Get_Object_Artifacts (BN, No_Index);
end if;
Get_Source_Artifacts;
return Artifact.Object'
(Source => Source,
Object_Files => Object_Files,
Deps_Lib_Files => Deps_Lib,
Deps_Obj_Files => Deps_Obj,
Switches => Switches,
Preprocessed_Src => Preprocessed,
Callgraph => Callgraph,
Coverage => Coverage);
end Create;
----------------
-- Dependency --
----------------
function Dependency
(Source : Project.Source.Object;
Index : Unit_Index := No_Index;
Location : Dependency_Location := In_Both;
Actual_File : Boolean := False;
Maybe_No_Body : Boolean := False)
return GPR2.Path_Name.Object
is
function Get_Dep (F : Filename_Type) return GPR2.Path_Name.Object;
BN : constant Filename_Type :=
Source.Path_Name.Base_Filename;
Lang : constant Language_Id := Source.Language;
View : constant Project.View.Object :=
Definition.Strong (Source.View);
D_Suffix : constant Filename_Type :=
View.Tree.Dependency_Suffix (Lang);
-------------
-- Get_Dep --
-------------
function Get_Dep (F : Filename_Type) return GPR2.Path_Name.Object is
Candidate, Candidate2 : GPR2.Path_Name.Object;
begin
if Location in In_Both | In_Library then
Candidate := From_Hierarchy
(View,
Source,
F & D_Suffix,
Library_ALI_Dir, True);
end if;
if Location = In_Library then
if not Actual_File then
return Candidate;
elsif Candidate.Is_Defined
and then Candidate.Exists
then
return Candidate;
else
return GPR2.Path_Name.Undefined;
end if;
end if;
Candidate2 := From_Hierarchy
(View,
Source,
F & D_Suffix,
Object_Dir, True);
-- Priorities:
-- 1- return the location, if set to a unique one
-- 1b- if Location is Both, always favor the Library_ALI_Dir one
-- 2- if Actual_File is set, return immediately if one is found, else
-- return Undefined.
-- 3- if one of the location is undefined, return the other
-- 4- if both are defined, return the one that exists
-- 5- return the Library_Ali_Dir path
if Location = In_Objects then
if not Actual_File then
return Candidate2;
elsif Candidate2.Is_Defined and then Candidate2.Exists then
return Candidate2;
else
return GPR2.Path_Name.Undefined;
end if;
-- At this point, Location is In_Both, and no if Actual_File is set
-- then no LI file exists.
elsif Actual_File then
if Candidate.Is_Defined and then Candidate.Exists then
return Candidate;
elsif Candidate2.Is_Defined and then Candidate2.Exists then
return Candidate2;
else
return GPR2.Path_Name.Undefined;
end if;
elsif not Candidate2.Is_Defined then
return Candidate;
elsif not Candidate.Is_Defined then
return Candidate2;
elsif Candidate.Exists then
return Candidate;
elsif Candidate2.Exists then
return Candidate2;
else
return Candidate;
end if;
end Get_Dep;
begin
if Source.Has_Units and then Source.Has_Index then
declare
CU : GPR2.Unit.Object renames Source.Unit (Index);
Other : GPR2.Project.Source.Source_Part;
begin
if CU.Kind in GPR2.Unit.Body_Kind | GPR2.Unit.S_Spec_Only
or else (Maybe_No_Body and then CU.Kind = GPR2.Unit.S_Spec)
then
declare
Base : constant Filename_Type :=
BN & At_Suffix (Index);
begin
return Get_Dep (Base);
end;
elsif Source.Has_Other_Part (Index) then
Other := Source.Other_Part (Index);
return Dependency
(Other.Source,
Other.Index,
Location,
Actual_File,
Maybe_No_Body);
else
return GPR2.Path_Name.Undefined;
end if;
end;
else
return Get_Dep (BN);
end if;
end Dependency;
----------------
-- Dependency --
----------------
function Dependency
(Self : Object;
Index : Unit_Index := No_Index;
Location : Dependency_Location := In_Both)
return GPR2.Path_Name.Object is
begin
if Index <= 1 then
case Location is
when In_Library =>
return Self.Deps_Lib_Files.First_Element;
when In_Objects =>
return Self.Deps_Obj_Files.First_Element;
when In_Both =>
return
(if Self.Deps_Lib_Files.Is_Empty
then Self.Deps_Obj_Files.First_Element
elsif Self.Deps_Obj_Files.Is_Empty
then Self.Deps_Lib_Files.First_Element
elsif Self.Deps_Lib_Files.First_Element.Exists
then Self.Deps_Lib_Files.First_Element
elsif Self.Deps_Obj_Files.First_Element.Exists
then Self.Deps_Obj_Files.First_Element
else Self.Deps_Lib_Files.First_Element);
end case;
else
case Location is
when In_Library =>
return Self.Deps_Lib_Files (Index);
when In_Objects =>
return Self.Deps_Obj_Files (Index);
when In_Both =>
return
(if not Self.Deps_Lib_Files.Contains (Index)
then Self.Deps_Obj_Files (Index)
elsif not Self.Deps_Obj_Files.Contains (Index)
then Self.Deps_Lib_Files (Index)
elsif Self.Deps_Lib_Files (Index).Exists
then Self.Deps_Lib_Files (Index)
elsif Self.Deps_Obj_Files (Index).Exists
then Self.Deps_Obj_Files (Index)
else Self.Deps_Lib_Files (Index));
end case;
end if;
end Dependency;
-------------------
-- From_Hierarhy --
-------------------
function From_Hierarchy
(View : Project.View.Object;
Source : Project.Source.Object;
Filename : Filename_Type;
Dir_Attr : Artifact_Dir;
Full_Closure : Boolean := False) return GPR2.Path_Name.Object
is
function Get_Candidate
(View : Project.View.Object) return GPR2.Path_Name.Object;
-- If View has Dir_Attr defined, then returns the candidate file
-- within this directory. Returns Undefined otherwise.
-------------------
-- Get_Candidate --
-------------------
function Get_Candidate
(View : Project.View.Object) return GPR2.Path_Name.Object is
begin
case Dir_Attr is
when Object_Dir =>
if View.Kind not in K_Configuration | K_Abstract then
return View.Object_Directory.Compose (Filename);
else
return GPR2.Path_Name.Undefined;
end if;
when Library_ALI_Dir =>
if View.Is_Library then
return View.Library_Ali_Directory.Compose (Filename);
else
return GPR2.Path_Name.Undefined;
end if;
end case;
end Get_Candidate;
Candidate : GPR2.Path_Name.Object;
New_Candidate : GPR2.Path_Name.Object;
begin
Candidate := Get_Candidate (View);
if not Source.Inherited
or else (Candidate.Is_Defined and then Candidate.Exists)
then
return Candidate;
end if;
if View.Is_Extending then
if Full_Closure then
for Ext of View.Extended loop
declare
Ext_Source : Project.Source.Object renames
Ext.Source (Source.Path_Name);
begin
if Ext_Source.Is_Defined then
New_Candidate := From_Hierarchy
(Ext, Ext_Source, Filename, Dir_Attr, True);
exit when New_Candidate.Is_Defined
and then New_Candidate.Exists;
end if;
end;
end loop;
else
New_Candidate := From_Hierarchy
(View.Extended_Root,
View.Extended_Root.Source (Source.Path_Name),
Filename, Dir_Attr);
end if;
end if;
if New_Candidate.Is_Defined and then New_Candidate.Exists then
-- Found from hierarchy
return New_Candidate;
else
-- Project's own candidate
return Candidate;
end if;
end From_Hierarchy;
--------------------
-- Has_Dependency --
--------------------
function Has_Dependency
(Self : Object;
Index : Unit_Index := No_Index;
Location : Dependency_Location := In_Both) return Boolean is
begin
if Index = No_Index then
return
(case Location is
when In_Objects => not Self.Deps_Obj_Files.Is_Empty,
when In_Library => not Self.Deps_Lib_Files.Is_Empty,
when In_Both => not (Self.Deps_Lib_Files.Is_Empty
and then Self.Deps_Obj_Files.Is_Empty));
else
return
(case Location is
when In_Objects => Self.Deps_Obj_Files.Contains (Index),
when In_Library => Self.Deps_Lib_Files.Contains (Index),
when In_Both => Self.Deps_Lib_Files.Contains (Index)
or else Self.Deps_Obj_Files.Contains
(Index));
end if;
end Has_Dependency;
-----------------------
-- Insert_If_Defined --
-----------------------
procedure Insert_If_Defined
(Map : in out Index_Path_Name_Map.Map;
Index : Unit_Index;
Path : GPR2.Path_Name.Object) is
begin
if Path.Is_Defined then
Map.Insert (Index, Path);
end if;
end Insert_If_Defined;
----------
-- List --
----------
function List (Self : Object) return GPR2.Path_Name.Set.Object is
Result : GPR2.Path_Name.Set.Object := Self.List_To_Clean;
begin
if Self.Has_Coverage then
for C of Self.Coverage loop
Result.Append (C);
end loop;
end if;
return Result;
end List;
-------------------
-- List_To_Clean --
-------------------
function List_To_Clean (Self : Object) return GPR2.Path_Name.Set.Object is
Source : constant GPR2.Project.Source.Object := Self.Source;
Lang : constant Language_Id := Source.Language;
View : constant Project.View.Object :=
Definition.Strong (Source.View);
Name : constant Filename_Type := Source.Path_Name.Simple_Name;
O_Dir : constant Filename_Type :=
Filename_Type (View.Object_Directory.Value);
Result : GPR2.Path_Name.Set.Object;
procedure Append_File (Name : Filename_Type);
-- Append full filename constructed from Name and Object_Dir to result
-----------------
-- Append_File --
-----------------
procedure Append_File (Name : Filename_Type) is
begin
Result.Append (GPR2.Path_Name.Create_File (Name, O_Dir));
end Append_File;
begin
for E of View.Source_Artifact_Extensions (Lang) loop
Append_File (Name & Filename_Type (E));
end loop;
if not Self.Object_Files.Is_Empty then
-- Object themselves
for O of Self.Object_Files loop
Result.Append (O);
end loop;
-- The generated artifacts
Append_File (Name & ".stdout");
Append_File (Name & ".stderr");
Append_File (Source.Path_Name.Base_Filename & ".adt");
for E of View.Object_Artifact_Extensions (Lang) loop
Append_File (Source.Path_Name.Base_Filename & Filename_Type (E));
end loop;
end if;
-- Append the dependencies
for D of Self.Deps_Lib_Files loop
Result.Append (D);
end loop;
for D of Self.Deps_Obj_Files loop
Result.Append (D);
end loop;
-- Append preprocessed sources
if Self.Has_Preprocessed_Source then
Result.Append (Self.Preprocessed_Source);
end if;
for S of Self.Switches loop
if S.Exists then
Result.Append (S);
end if;
end loop;
for C of Self.Callgraph loop
if C.Exists then
Result.Append (C);
end if;
end loop;
return Result;
end List_To_Clean;
-----------------
-- Object_Code --
-----------------
function Object_Code
(Self : Object;
Index : Unit_Index := No_Index) return GPR2.Path_Name.Object is
begin
return (if Index = 0
then Self.Object_Files.First_Element
else Self.Object_Files (Index));
end Object_Code;
-------------------------
-- Preprocessed_Source --
-------------------------
function Preprocessed_Source
(Self : Object) return GPR2.Path_Name.Object is
begin
return Self.Preprocessed_Src;
end Preprocessed_Source;
------------
-- Source --
------------
function Source (Self : Object) return GPR2.Project.Source.Object is
begin
return Self.Source;
end Source;
end GPR2.Project.Source.Artifact;
|
silky/synth | Ada | 51,777 | adb | -- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with Ada.Numerics.Discrete_Random;
with GNAT.String_Split;
with PortScan.Buildcycle.Pkgsrc;
with PortScan.Buildcycle.Ports;
with Replicant.Platform;
with Signals;
with Unix;
package body PortScan.Ops is
package GSS renames GNAT.String_Split;
package CYC renames PortScan.Buildcycle;
package FPC renames PortScan.Buildcycle.Ports;
package NPS renames PortScan.Buildcycle.Pkgsrc;
package REP renames Replicant;
package SIG renames Signals;
--------------------------
-- initialize_display --
--------------------------
procedure initialize_display (num_builders : builders) is
begin
if PM.configuration.avec_ncurses then
curses_support := DPY.launch_monitor (num_builders);
end if;
end initialize_display;
-------------------------
-- parallel_bulk_run --
-------------------------
procedure parallel_bulk_run (num_builders : builders; logs : dim_handlers)
is
subtype cycle_count is Natural range 1 .. 9;
subtype refresh_count is Natural range 1 .. 4;
subtype www_count is Natural range 1 .. 3;
subtype alert_count is Natural range 1 .. 200;
instructions : dim_instruction := (others => port_match_failed);
builder_states : dim_builder_state := (others => idle);
cntcycle : cycle_count := cycle_count'First;
cntrefresh : refresh_count := refresh_count'First;
cntalert : alert_count := alert_count'First;
cntwww : www_count := www_count'First;
run_complete : Boolean := False;
available : Positive := Integer (num_builders);
target : port_id;
all_idle : Boolean;
cntskip : Natural;
sumdata : DPY.summary_rec;
task type build (builder : builders);
task body build
is
type Rand_Draw is range 1 .. 20;
package Rand20 is new Ada.Numerics.Discrete_Random (Rand_Draw);
seed : Rand20.Generator;
build_result : Boolean;
opts : REP.slave_options;
begin
if builder <= num_builders then
if not curses_support then
TIO.Put_Line (CYC.elapsed_now & " => [" &
JT.zeropad (Integer (builder), 2) &
"] Builder launched");
end if;
loop
exit when builder_states (builder) = shutdown;
if builder_states (builder) = tasked then
builder_states (builder) := busy;
opts.need_procfs :=
all_ports (instructions (builder)).use_procfs;
opts.need_linprocfs :=
all_ports (instructions (builder)).use_linprocfs;
REP.launch_slave (id => builder, opts => opts);
case software_framework is
when ports_collection =>
build_result :=
FPC.build_package (builder, instructions (builder));
when pkgsrc =>
if not REP.Platform.standalone_pkg8_install (builder)
then
build_result := False;
else
build_result := NPS.build_package
(builder, instructions (builder));
end if;
end case;
REP.destroy_slave (id => builder, opts => opts);
if build_result then
builder_states (builder) := done_success;
else
builder_states (builder) := done_failure;
end if;
else
-- idle or done-(failure|success), just wait a bit
delay 0.1;
end if;
end loop;
if not curses_support then
TIO.Put_Line (CYC.elapsed_now & " => [" &
JT.zeropad (Integer (builder), 2) &
"] Shutting down");
end if;
end if;
end build;
builder_01 : build (builder => 1);
builder_02 : build (builder => 2);
builder_03 : build (builder => 3);
builder_04 : build (builder => 4);
builder_05 : build (builder => 5);
builder_06 : build (builder => 6);
builder_07 : build (builder => 7);
builder_08 : build (builder => 8);
builder_09 : build (builder => 9);
builder_10 : build (builder => 10);
builder_11 : build (builder => 11);
builder_12 : build (builder => 12);
builder_13 : build (builder => 13);
builder_14 : build (builder => 14);
builder_15 : build (builder => 15);
builder_16 : build (builder => 16);
builder_17 : build (builder => 17);
builder_18 : build (builder => 18);
builder_19 : build (builder => 19);
builder_20 : build (builder => 20);
builder_21 : build (builder => 21);
builder_22 : build (builder => 22);
builder_23 : build (builder => 23);
builder_24 : build (builder => 24);
builder_25 : build (builder => 25);
builder_26 : build (builder => 26);
builder_27 : build (builder => 27);
builder_28 : build (builder => 28);
builder_29 : build (builder => 29);
builder_30 : build (builder => 30);
builder_31 : build (builder => 31);
builder_32 : build (builder => 32);
builder_33 : build (builder => 33);
builder_34 : build (builder => 34);
builder_35 : build (builder => 35);
builder_36 : build (builder => 36);
builder_37 : build (builder => 37);
builder_38 : build (builder => 38);
builder_39 : build (builder => 39);
builder_40 : build (builder => 40);
builder_41 : build (builder => 41);
builder_42 : build (builder => 42);
builder_43 : build (builder => 43);
builder_44 : build (builder => 44);
builder_45 : build (builder => 45);
builder_46 : build (builder => 46);
builder_47 : build (builder => 47);
builder_48 : build (builder => 48);
builder_49 : build (builder => 49);
builder_50 : build (builder => 50);
builder_51 : build (builder => 51);
builder_52 : build (builder => 52);
builder_53 : build (builder => 53);
builder_54 : build (builder => 54);
builder_55 : build (builder => 55);
builder_56 : build (builder => 56);
builder_57 : build (builder => 57);
builder_58 : build (builder => 58);
builder_59 : build (builder => 59);
builder_60 : build (builder => 60);
builder_61 : build (builder => 61);
builder_62 : build (builder => 62);
builder_63 : build (builder => 63);
builder_64 : build (builder => 64);
begin
loop
all_idle := True;
for slave in 1 .. num_builders loop
declare
begin
case builder_states (slave) is
when busy | tasked =>
all_idle := False;
when shutdown =>
null;
when idle =>
if run_complete then
builder_states (slave) := shutdown;
else
target := top_buildable_port;
if target = port_match_failed then
if SIG.graceful_shutdown_requested or else
nothing_left (num_builders)
then
run_complete := True;
builder_states (slave) := shutdown;
DPY.insert_history (assemble_HR (slave, 0,
DPY.action_shutdown));
else
if shutdown_recommended (available) then
builder_states (slave) := shutdown;
DPY.insert_history (assemble_HR (slave, 0,
DPY.action_shutdown));
available := available - 1;
end if;
end if;
else
lock_package (target);
instructions (slave) := target;
builder_states (slave) := tasked;
TIO.Put_Line (logs (total), CYC.elapsed_now & " [" &
JT.zeropad (Integer (slave), 2) & "] => " &
port_name (instructions (slave)));
if not curses_support then
TIO.Put_Line (CYC.elapsed_now & " => [" &
JT.zeropad (Integer (slave), 2) &
"] Kickoff " &
port_name (instructions (slave)));
end if;
end if;
end if;
when done_success | done_failure =>
all_idle := False;
if builder_states (slave) = done_success then
if curses_support then
DPY.insert_history
(assemble_HR (slave, instructions (slave),
DPY.action_success));
else
TIO.Put_Line (CYC.elapsed_now & " => [" &
JT.zeropad (Integer (slave), 2) &
"] " & CYC.elapsed_build (slave) &
" Success " &
port_name (instructions (slave)));
end if;
record_history_built (elapsed => CYC.elapsed_now,
slave_id => slave,
origin => port_name (instructions (slave)),
duration => CYC.elapsed_build (slave));
run_package_hook (pkg_success, instructions (slave));
cascade_successful_build (instructions (slave));
bld_counter (success) := bld_counter (success) + 1;
TIO.Put_Line (logs (success), CYC.elapsed_now & " " &
port_name (instructions (slave)));
TIO.Put_Line (logs (total), CYC.elapsed_now & " " &
port_name (instructions (slave)) &
" success");
else
TIO.Put_Line (logs (total), CYC.elapsed_now & " " &
port_name (instructions (slave)) &
" FAILED!");
cascade_failed_build (instructions (slave), cntskip, logs);
bld_counter (skipped) := bld_counter (skipped) + cntskip;
bld_counter (failure) := bld_counter (failure) + 1;
TIO.Put_Line (logs (total), CYC.elapsed_now & " " &
port_name (instructions (slave)) &
" failure skips:" & JT.int2str (cntskip));
TIO.Put_Line (logs (failure), CYC.elapsed_now & " " &
port_name (instructions (slave)) &
" (skipped" & cntskip'Img & ")");
if curses_support then
DPY.insert_history
(assemble_HR (slave, instructions (slave),
DPY.action_failure));
else
TIO.Put_Line (CYC.elapsed_now & " => [" &
JT.zeropad (Integer (slave), 2) &
"] " & CYC.elapsed_build (slave) &
" Failure " &
port_name (instructions (slave)));
end if;
case software_framework is
when ports_collection =>
record_history_failed
(elapsed => CYC.elapsed_now,
slave_id => slave,
origin => port_name (instructions (slave)),
duration => CYC.elapsed_build (slave),
die_phase => FPC.last_build_phase (slave),
skips => cntskip);
when pkgsrc =>
record_history_failed
(elapsed => CYC.elapsed_now,
slave_id => slave,
origin => port_name (instructions (slave)),
duration => CYC.elapsed_build (slave),
die_phase => NPS.last_build_phase (slave),
skips => cntskip);
end case;
run_package_hook (pkg_failure, instructions (slave));
end if;
instructions (slave) := port_match_failed;
if run_complete then
builder_states (slave) := shutdown;
DPY.insert_history (assemble_HR (slave, 0,
DPY.action_shutdown));
else
builder_states (slave) := idle;
end if;
end case;
exception
when earthquake : others => TIO.Put_Line
(logs (total), CYC.elapsed_now & " UNHANDLED EXCEPTION: " &
EX.Exception_Information (earthquake));
end;
end loop;
exit when run_complete and all_idle;
if cntcycle = cycle_count'Last then
cntcycle := cycle_count'First;
TIO.Flush (logs (success));
TIO.Flush (logs (failure));
TIO.Flush (logs (skipped));
TIO.Flush (logs (total));
if curses_support then
if cntrefresh = refresh_count'Last then
cntrefresh := refresh_count'First;
DPY.set_full_redraw_next_update;
else
cntrefresh := cntrefresh + 1;
end if;
sumdata.Initially := bld_counter (total);
sumdata.Built := bld_counter (success);
sumdata.Failed := bld_counter (failure);
sumdata.Ignored := bld_counter (ignored);
sumdata.Skipped := bld_counter (skipped);
sumdata.elapsed := CYC.elapsed_now;
sumdata.swap := get_swap_status;
sumdata.load := REP.Platform.get_instant_load;
sumdata.pkg_hour := hourly_build_rate;
sumdata.impulse := impulse_rate;
DPY.summarize (sumdata);
for b in builders'First .. num_builders loop
case software_framework is
when ports_collection =>
if builder_states (b) = shutdown then
DPY.update_builder (FPC.builder_status (b, True, False));
elsif builder_states (b) = idle then
DPY.update_builder (FPC.builder_status (b, False, True));
else
CYC.set_log_lines (b);
DPY.update_builder (FPC.builder_status (b));
end if;
when pkgsrc =>
if builder_states (b) = shutdown then
DPY.update_builder (NPS.builder_status (b, True, False));
elsif builder_states (b) = idle then
DPY.update_builder (NPS.builder_status (b, False, True));
else
CYC.set_log_lines (b);
DPY.update_builder (NPS.builder_status (b));
end if;
end case;
end loop;
DPY.refresh_builder_window;
DPY.refresh_history_window;
else
-- text mode support, periodic status reports
if cntalert = alert_count'Last then
cntalert := alert_count'First;
declare
Remaining : constant Integer := bld_counter (total) -
bld_counter (success) - bld_counter (failure) -
bld_counter (ignored) - bld_counter (skipped);
begin
TIO.Put_Line (CYC.elapsed_now & " => " &
" Left:" & Remaining'Img &
" Succ:" & bld_counter (success)'Img &
" Fail:" & bld_counter (failure)'Img &
" Skip:" & bld_counter (skipped)'Img &
" Ign:" & bld_counter (ignored)'Img);
end;
else
cntalert := cntalert + 1;
end if;
-- Update log lines every 4 seconds for the watchdog
if cntrefresh = refresh_count'Last then
cntrefresh := refresh_count'First;
for b in builders'First .. num_builders loop
if builder_states (b) /= shutdown and then
builder_states (b) /= idle
then
CYC.set_log_lines (b);
end if;
end loop;
else
cntrefresh := cntrefresh + 1;
end if;
end if;
-- Generate latest history file every 3 seconds.
-- With a poll period of 6 seconds, we need twice that frequency to avoid aliasing
-- Note that in text mode, the logs are updated every 4 seconds, so in this mode
-- the log lines will often be identical for a cycle.
if cntwww = www_count'Last then
cntwww := www_count'First;
write_history_json;
write_summary_json (active => True,
states => builder_states,
num_builders => num_builders,
num_history_files => history.segment);
else
cntwww := cntwww + 1;
end if;
else
cntcycle := cntcycle + 1;
end if;
delay 0.10;
end loop;
if PM.configuration.avec_ncurses and then curses_support
then
DPY.terminate_monitor;
end if;
write_history_json;
write_summary_json (active => False,
states => builder_states,
num_builders => num_builders,
num_history_files => history.segment);
run_hook (run_end, "PORTS_BUILT=" & JT.int2str (bld_counter (success)) &
" PORTS_FAILED=" & JT.int2str (bld_counter (failure)) &
" PORTS_IGNORED=" & JT.int2str (bld_counter (ignored)) &
" PORTS_SKIPPED=" & JT.int2str (bld_counter (skipped)));
end parallel_bulk_run;
--------------------
-- lock_package --
--------------------
procedure lock_package (id : port_id) is
begin
if id /= port_match_failed then
all_ports (id).work_locked := True;
end if;
end lock_package;
----------------------------
-- cascade_failed_build --
----------------------------
procedure cascade_failed_build (id : port_id; numskipped : out Natural;
logs : dim_handlers)
is
purged : PortScan.port_id;
culprit : constant String := port_name (id);
begin
numskipped := 0;
loop
purged := skip_next_reverse_dependency (id);
exit when purged = port_match_failed;
if skip_verified (purged) then
numskipped := numskipped + 1;
TIO.Put_Line (logs (total), " Skipped: " &
port_name (purged));
TIO.Put_Line (logs (skipped),
port_name (purged) & " by " & culprit);
DPY.insert_history (assemble_HR (1, purged, DPY.action_skipped));
record_history_skipped (elapsed => CYC.elapsed_now,
origin => port_name (purged),
reason => culprit);
run_package_hook (pkg_skipped, purged);
end if;
end loop;
unlist_port (id);
end cascade_failed_build;
--------------------------------
-- cascade_successful_build --
--------------------------------
procedure cascade_successful_build (id : port_id)
is
procedure cycle (cursor : block_crate.Cursor);
procedure cycle (cursor : block_crate.Cursor)
is
target : constant port_index := block_crate.Element (cursor);
begin
if all_ports (target).blocked_by.Contains (Key => id) then
all_ports (target).blocked_by.Delete (Key => id);
else
raise seek_failure
with port_name (target) & " was expected to be blocked by " &
port_name (id);
end if;
end cycle;
begin
all_ports (id).blocks.Iterate (cycle'Access);
delete_rank (id);
end cascade_successful_build;
--------------------------
-- top_buildable_port --
--------------------------
function top_buildable_port return port_id
is
list_len : constant Integer := Integer (rank_queue.Length);
cursor : ranking_crate.Cursor;
QR : queue_record;
result : port_id := port_match_failed;
begin
if list_len = 0 then
return result;
end if;
cursor := rank_queue.First;
for k in 1 .. list_len loop
QR := ranking_crate.Element (Position => cursor);
if not all_ports (QR.ap_index).work_locked and then
all_ports (QR.ap_index).blocked_by.Is_Empty
then
result := QR.ap_index;
exit;
end if;
cursor := ranking_crate.Next (Position => cursor);
end loop;
if SIG.graceful_shutdown_requested then
return port_match_failed;
end if;
return result;
end top_buildable_port;
----------------------------
-- shutdown_recommended --
----------------------------
function shutdown_recommended (active_builders : Positive) return Boolean
is
list_len : constant Natural := Integer (rank_queue.Length);
list_max : constant Positive := 2 * active_builders;
num_wait : Natural := 0;
cursor : ranking_crate.Cursor;
QR : queue_record;
begin
if list_len = 0 or else list_len >= list_max then
return False;
end if;
cursor := rank_queue.First;
for k in 1 .. list_len loop
QR := ranking_crate.Element (Position => cursor);
if not all_ports (QR.ap_index).work_locked then
num_wait := num_wait + 1;
if num_wait >= active_builders then
return False;
end if;
end if;
cursor := ranking_crate.Next (Position => cursor);
end loop;
return True;
end shutdown_recommended;
--------------------
-- nothing_left --
--------------------
function nothing_left (num_builders : builders) return Boolean
is
list_len : constant Integer := Integer (rank_queue.Length);
begin
return list_len = 0;
end nothing_left;
------------------
-- rank_arrow --
------------------
function rank_arrow (id : port_id) return ranking_crate.Cursor
is
rscore : constant port_index := all_ports (id).reverse_score;
seek_target : constant queue_record := (ap_index => id,
reverse_score => rscore);
begin
return rank_queue.Find (seek_target);
end rank_arrow;
-------------------
-- delete_rank --
-------------------
procedure delete_rank (id : port_id)
is
rank_cursor : ranking_crate.Cursor := rank_arrow (id);
use type ranking_crate.Cursor;
begin
if rank_cursor /= ranking_crate.No_Element then
rank_queue.Delete (Position => rank_cursor);
end if;
end delete_rank;
--------------------
-- still_ranked --
--------------------
function still_ranked (id : port_id) return Boolean
is
rank_cursor : ranking_crate.Cursor := rank_arrow (id);
use type ranking_crate.Cursor;
begin
return rank_cursor /= ranking_crate.No_Element;
end still_ranked;
------------------------
-- integrity_intact --
------------------------
function integrity_intact return Boolean
is
procedure check_dep (cursor : block_crate.Cursor);
procedure check_rank (cursor : ranking_crate.Cursor);
intact : Boolean := True;
procedure check_dep (cursor : block_crate.Cursor)
is
did : constant port_index := block_crate.Element (cursor);
begin
if not still_ranked (did) then
intact := False;
end if;
end check_dep;
procedure check_rank (cursor : ranking_crate.Cursor)
is
QR : constant queue_record := ranking_crate.Element (cursor);
begin
if intact then
all_ports (QR.ap_index).blocked_by.Iterate (check_dep'Access);
end if;
end check_rank;
begin
rank_queue.Iterate (check_rank'Access);
return intact;
end integrity_intact;
---------------------
-- skip_verified --
---------------------
function skip_verified (id : port_id) return Boolean is
begin
if id = port_match_failed then
return False;
end if;
return not all_ports (id).unlist_failed;
end skip_verified;
--------------------
-- queue_length --
--------------------
function queue_length return Integer is
begin
return Integer (rank_queue.Length);
end queue_length;
-------------------
-- unlist_port --
-------------------
procedure unlist_port (id : port_id) is
begin
if id = port_match_failed then
return;
end if;
if still_ranked (id) then
delete_rank (id);
else
-- don't raise exception. Since we don't prune all_reverse as
-- we go, there's no guarantee the reverse dependency hasn't already
-- been removed (e.g. when it is a common reverse dep)
all_ports (id).unlist_failed := True;
end if;
end unlist_port;
------------------------------------
-- skip_next_reverse_dependency --
------------------------------------
function skip_next_reverse_dependency (pinnacle : port_id) return port_id
is
rev_cursor : block_crate.Cursor;
next_dep : port_index;
begin
if all_ports (pinnacle).all_reverse.Is_Empty then
return port_match_failed;
end if;
rev_cursor := all_ports (pinnacle).all_reverse.First;
next_dep := block_crate.Element (rev_cursor);
unlist_port (id => next_dep);
all_ports (pinnacle).all_reverse.Delete (rev_cursor);
return next_dep;
end skip_next_reverse_dependency;
---------------------
-- ignore_reason --
---------------------
function ignore_reason (id : port_id) return String is
begin
if id = port_match_failed or else
id > last_port
then
return "Invalid port ID";
end if;
return JT.USS (all_ports (id).ignore_reason);
end ignore_reason;
-------------------------
-- next_ignored_port --
-------------------------
function next_ignored_port return port_id
is
list_len : constant Integer := Integer (rank_queue.Length);
cursor : ranking_crate.Cursor;
QR : queue_record;
result : port_id := port_match_failed;
begin
if list_len = 0 then
return result;
end if;
cursor := rank_queue.First;
for k in 1 .. list_len loop
QR := ranking_crate.Element (Position => cursor);
if all_ports (QR.ap_index).ignored then
result := QR.ap_index;
DPY.insert_history (assemble_HR (1, QR.ap_index,
DPY.action_ignored));
run_package_hook (pkg_ignored, QR.ap_index);
exit;
end if;
cursor := ranking_crate.Next (Position => cursor);
end loop;
return result;
end next_ignored_port;
-----------------
-- port_name --
-----------------
function port_name (id : port_id) return String is
begin
if id = port_match_failed or else
id > last_port
then
return "Invalid port ID";
end if;
return get_catport (all_ports (id));
end port_name;
-----------------------
-- get_swap_status --
-----------------------
function get_swap_status return Float
is
command : String := REP.Platform.swapinfo_command;
comres : JT.Text;
topline : JT.Text;
crlen1 : Natural;
crlen2 : Natural;
blocks_total : Natural := 0;
blocks_used : Natural := 0;
begin
comres := CYC.generic_system_command (command);
-- Throw first line away, e.g "Device 1K-blocks Used Avail ..."
-- Distinguishes platforms though:
-- Net/Free/Dragon start with "Device"
-- Linux starts with "NAME"
-- Solaris starts with "swapfile"
-- columns differ by NFD/Linux/Solaris, the parsing of the
-- last two not yet supported
JT.nextline (lineblock => comres, firstline => topline);
crlen1 := JT.SU.Length (comres);
loop
JT.nextline (lineblock => comres, firstline => topline);
crlen2 := JT.SU.Length (comres);
exit when crlen1 = crlen2;
crlen1 := crlen2;
declare
subs : GSS.Slice_Set;
opts_found : GSS.Slice_Number;
use type GSS.Slice_Number;
begin
GSS.Create (S => subs,
From => JT.USS (topline),
Separators => " ",
Mode => GSS.Multiple);
opts_found := GSS.Slice_Count (S => subs);
if opts_found >= 3 then
blocks_total := blocks_total +
Natural'Value (GSS.Slice (subs, 2));
blocks_used := blocks_used +
Natural'Value (GSS.Slice (subs, 3));
end if;
end;
end loop;
if blocks_total = 0 then
return 200.0; -- Signal to set swap display to "N/A"
else
return 100.0 * Float (blocks_used) / Float (blocks_total);
end if;
exception
when others => return 0.0;
end get_swap_status;
-------------------------
-- hourly_build_rate --
-------------------------
function hourly_build_rate return Natural
is
pkg_that_count : constant Natural := bld_counter (success) +
bld_counter (failure);
begin
return CYC.get_packages_per_hour (pkg_that_count, start_time);
end hourly_build_rate;
--------------------
-- impulse_rate --
--------------------
function impulse_rate return Natural
is
pkg_that_count : constant Natural := bld_counter (success) +
bld_counter (failure);
pkg_diff : Natural;
result : Natural;
begin
if impulse_counter = impulse_range'Last then
impulse_counter := impulse_range'First;
else
impulse_counter := impulse_counter + 1;
end if;
if impulse_data (impulse_counter).virgin then
impulse_data (impulse_counter).hack := CAL.Clock;
impulse_data (impulse_counter).packages := pkg_that_count;
impulse_data (impulse_counter).virgin := False;
return CYC.get_packages_per_hour (pkg_that_count, start_time);
end if;
pkg_diff := pkg_that_count - impulse_data (impulse_counter).packages;
result := CYC.get_packages_per_hour
(packages_done => pkg_diff,
from_when => impulse_data (impulse_counter).hack);
impulse_data (impulse_counter).hack := CAL.Clock;
impulse_data (impulse_counter).packages := pkg_that_count;
return result;
exception
when others => return 0;
end impulse_rate;
-------------------
-- assemble_HR --
-------------------
function assemble_HR (slave : builders; pid : port_id;
action : DPY.history_action)
return DPY.history_rec
is
HR : DPY.history_rec;
HOLast : constant Natural := DPY.history_origin'Last;
catport : String := port_name (pid);
hyphens : constant DPY.history_elapsed := "--:--:--";
begin
HR.id := slave;
HR.slavid := JT.zeropad (Integer (slave), 2);
HR.established := True;
HR.action := action;
HR.origin := (others => ' ');
HR.run_elapsed := CYC.elapsed_now;
if action = DPY.action_shutdown then
HR.pkg_elapsed := hyphens;
else
if action = DPY.action_skipped or else
action = DPY.action_ignored
then
HR.pkg_elapsed := hyphens;
else
HR.pkg_elapsed := CYC.elapsed_build (slave);
end if;
if catport'Last > HOLast then
HR.origin (1 .. HOLast - 1) := catport (1 .. HOLast - 1);
HR.origin (HOLast) := LAT.Asterisk;
else
HR.origin (1 .. catport'Last) := catport;
end if;
end if;
return HR;
end assemble_HR;
------------------------
-- initialize_hooks --
------------------------
procedure initialize_hooks is
begin
for hook in hook_type'Range loop
declare
script : constant String := JT.USS (hook_location (hook));
begin
active_hook (hook) := AD.Exists (script) and then
REP.Platform.file_is_executable (script);
end;
end loop;
end initialize_hooks;
----------------------
-- run_start_hook --
----------------------
procedure run_start_hook is
begin
run_hook (run_start, "PORTS_QUEUED=" & JT.int2str (queue_length) & " ");
end run_start_hook;
----------------
-- run_hook --
----------------
procedure run_hook (hook : hook_type; envvar_list : String)
is
function nvpair (name : String; value : JT.Text) return String;
function nvpair (name : String; value : JT.Text) return String is
begin
return name & LAT.Equals_Sign & LAT.Quotation &
JT.USS (value) & LAT.Quotation & LAT.Space;
end nvpair;
common_env : constant String :=
nvpair ("PROFILE", PM.configuration.profile) &
nvpair ("DIR_PACKAGES", PM.configuration.dir_packages) &
nvpair ("DIR_REPOSITORY", PM.configuration.dir_repository) &
nvpair ("DIR_PORTS", PM.configuration.dir_portsdir) &
nvpair ("DIR_OPTIONS", PM.configuration.dir_options) &
nvpair ("DIR_DISTFILES", PM.configuration.dir_distfiles) &
nvpair ("DIR_LOGS", PM.configuration.dir_logs) &
nvpair ("DIR_BUILDBASE", PM.configuration.dir_buildbase);
-- The follow command works on every platform
command : constant String := "/usr/bin/env -i " & common_env &
envvar_list & " " & JT.USS (hook_location (hook));
begin
if not active_hook (hook) then
return;
end if;
if Unix.external_command (command) then
null;
end if;
end run_hook;
------------------------
-- run_package_hook --
------------------------
procedure run_package_hook (hook : hook_type; id : port_id)
is
tail : String := " ORIGIN=" & port_name (id) & " PKGNAME=" & package_name (id) & " ";
begin
case hook is
when pkg_success => run_hook (hook, "RESULT=success" & tail);
when pkg_failure => run_hook (hook, "RESULT=failure" & tail);
when pkg_ignored => run_hook (hook, "RESULT=ignored" & tail);
when pkg_skipped => run_hook (hook, "RESULT=skipped" & tail);
when others => null;
end case;
end run_package_hook;
----------------------------
-- run_hook_after_build --
----------------------------
procedure run_hook_after_build (built : Boolean; id : port_id) is
begin
if built then
run_package_hook (pkg_success, id);
else
run_package_hook (pkg_failure, id);
end if;
end run_hook_after_build;
--------------------
-- package_name --
--------------------
function package_name (id : port_id) return String is
begin
if id = port_match_failed or else
id > last_port
then
return "Invalid port ID";
end if;
declare
fullname : constant String := JT.USS (all_ports (id).package_name);
begin
return fullname (1 .. fullname'Length - 4);
end;
end package_name;
-----------------------------
-- initialize_web_report --
-----------------------------
procedure initialize_web_report (num_builders : builders) is
idle_slaves : constant dim_builder_state := (others => idle);
reportdir : constant String := JT.USS (PM.configuration.dir_logs) & "/Report";
sharedir : constant String := host_localbase & "/share/synth";
begin
AD.Create_Path (reportdir);
AD.Copy_File (sharedir & "/synth.png", reportdir & "/synth.png");
AD.Copy_File (sharedir & "/favicon.png", reportdir & "/favicon.png");
AD.Copy_File (sharedir & "/progress.js", reportdir & "/progress.js");
AD.Copy_File (sharedir & "/progress.css", reportdir & "/progress.css");
AD.Copy_File (sharedir & "/progress.html", reportdir & "/index.html");
write_summary_json (active => True,
states => idle_slaves,
num_builders => num_builders,
num_history_files => 0);
end initialize_web_report;
-----------------------------------------
-- delete_existing_web_history_files --
-----------------------------------------
procedure delete_existing_web_history_files
is
search : AD.Search_Type;
dirent : AD.Directory_Entry_Type;
pattern : constant String := "*_history.json";
filter : constant AD.Filter_Type := (AD.Ordinary_File => True, others => False);
reportdir : constant String := JT.USS (PM.configuration.dir_logs) & "/Report";
begin
if not AD.Exists (reportdir) then
return;
end if;
AD.Start_Search (Search => search,
Directory => reportdir,
Pattern => pattern,
Filter => filter);
while AD.More_Entries (search) loop
AD.Get_Next_Entry (search, dirent);
AD.Delete_File (reportdir & "/" & AD.Simple_Name (dirent));
end loop;
exception
when AD.Name_Error => null;
end delete_existing_web_history_files;
-----------------------
-- nv (2 versions) --
-----------------------
function nv (name, value : String) return String is
begin
return ASCII.Quotation & name & ASCII.Quotation & ASCII.Colon &
ASCII.Quotation & value & ASCII.Quotation;
end nv;
function nv (name : String; value : Integer) return String is
begin
return ASCII.Quotation & name & ASCII.Quotation & ASCII.Colon & JT.int2str (value);
end nv;
--------------------------
-- write_summary_json --
--------------------------
procedure write_summary_json
(active : Boolean;
states : dim_builder_state;
num_builders : builders;
num_history_files : Natural)
is
function TF (value : Boolean) return Natural;
function TF (value : Boolean) return Natural is
begin
if value then
return 1;
else
return 0;
end if;
end TF;
jsonfile : TIO.File_Type;
filename : constant String := JT.USS (PM.configuration.dir_logs) & "/Report/summary.json";
leftover : constant Integer := bld_counter (total) - bld_counter (success) -
bld_counter (failure) - bld_counter (ignored) - bld_counter (skipped);
slave : DPY.builder_rec;
begin
TIO.Create (File => jsonfile,
Mode => TIO.Out_File,
Name => filename);
TIO.Put (jsonfile, "{" & ASCII.LF &
" " & nv ("profile", JT.USS (PM.configuration.profile)) & ASCII.LF);
TIO.Put
(jsonfile,
" ," & nv ("kickoff", timestamp (start_time, True)) & ASCII.LF &
" ," & nv ("kfiles", num_history_files) & ASCII.LF &
" ," & nv ("active", TF (active)) & ASCII.LF &
" ," & ASCII.Quotation & "stats" & ASCII.Quotation & ASCII.Colon & "{" & ASCII.LF);
TIO.Put
(jsonfile,
" " & nv ("queued", bld_counter (total)) & ASCII.LF &
" ," & nv ("built", bld_counter (success)) & ASCII.LF &
" ," & nv ("failed", bld_counter (failure)) & ASCII.LF &
" ," & nv ("ignored", bld_counter (ignored)) & ASCII.LF &
" ," & nv ("skipped", bld_counter (skipped)) & ASCII.LF &
" ," & nv ("remains", leftover) & ASCII.LF &
" ," & nv ("elapsed", CYC.elapsed_now) & ASCII.LF &
" ," & nv ("pkghour", hourly_build_rate) & ASCII.LF &
" ," & nv ("impulse", impulse_rate) & ASCII.LF &
" ," & nv ("swapinfo", DPY.fmtpc (get_swap_status, True)) & ASCII.LF &
" ," & nv ("load", DPY.fmtpc (REP.Platform.get_instant_load, False)) & ASCII.LF &
" }" & ASCII.LF &
" ," & ASCII.Quotation & "builders" & ASCII.Quotation & ASCII.Colon & "[" & ASCII.LF);
for b in builders'First .. num_builders loop
case software_framework is
when ports_collection =>
if states (b) = shutdown then
slave := FPC.builder_status (b, True, False);
elsif states (b) = idle then
slave := FPC.builder_status (b, False, True);
else
slave := FPC.builder_status (b);
end if;
when pkgsrc =>
if states (b) = shutdown then
slave := NPS.builder_status (b, True, False);
elsif states (b) = idle then
slave := NPS.builder_status (b, False, True);
else
slave := NPS.builder_status (b);
end if;
end case;
if b = builders'First then
TIO.Put (jsonfile, " {" & ASCII.LF);
else
TIO.Put (jsonfile, " ,{" & ASCII.LF);
end if;
TIO.Put
(jsonfile,
" " & nv ("ID", slave.slavid) & ASCII.LF &
" ," & nv ("elapsed", JT.trim (slave.Elapsed)) & ASCII.LF &
" ," & nv ("phase", JT.trim (slave.phase)) & ASCII.LF &
" ," & nv ("origin", JT.trim (slave.origin)) & ASCII.LF &
" ," & nv ("lines", JT.trim (slave.LLines)) & ASCII.LF &
" }" & ASCII.LF);
end loop;
TIO.Put (jsonfile, " ]" & ASCII.LF & "}" & ASCII.LF);
TIO.Close (jsonfile);
exception
when others =>
if TIO.Is_Open (jsonfile) then
TIO.Close (jsonfile);
end if;
end write_summary_json;
----------------------------
-- write_history_json --
----------------------------
procedure write_history_json
is
jsonfile : TIO.File_Type;
filename : constant String := JT.USS (PM.configuration.dir_logs) &
"/Report/" & JT.zeropad (history.segment, 2) & "_history.json";
begin
if history.segment_count = 0 then
return;
end if;
if history.last_written = history.last_index then
return;
end if;
TIO.Create (File => jsonfile,
Mode => TIO.Out_File,
Name => filename);
TIO.Put (jsonfile, history.content (1 .. history.last_index));
TIO.Put (jsonfile, "]");
TIO.Close (jsonfile);
history.last_written := history.last_index;
exception
when others =>
if TIO.Is_Open (jsonfile) then
TIO.Close (jsonfile);
end if;
end write_history_json;
----------------------------
-- assimulate_substring --
----------------------------
procedure assimulate_substring
(history : in out progress_history;
substring : String)
is
first : constant Positive := history.last_index + 1;
last : constant Positive := history.last_index + substring'Length;
begin
-- silently fail (this shouldn't be practically possible)
if last < kfile_content'Last then
history.content (first .. last) := substring;
end if;
history.last_index := last;
end assimulate_substring;
----------------------------
-- record_history_built --
----------------------------
procedure handle_first_history_entry is
begin
if history.segment_count = 1 then
assimulate_substring (history, "[" & ASCII.LF & " {" & ASCII.LF);
else
assimulate_substring (history, " ,{" & ASCII.LF);
end if;
end handle_first_history_entry;
----------------------------
-- record_history_built --
----------------------------
procedure record_history_built
(elapsed : String;
slave_id : builders;
origin : String;
duration : String)
is
ID : constant String := JT.zeropad (Integer (slave_id), 2);
begin
history.log_entry := history.log_entry + 1;
history.segment_count := history.segment_count + 1;
handle_first_history_entry;
assimulate_substring (history, " " & nv ("entry", history.log_entry) & ASCII.LF);
assimulate_substring (history, " ," & nv ("elapsed", elapsed) & ASCII.LF);
assimulate_substring (history, " ," & nv ("ID", ID) & ASCII.LF);
assimulate_substring (history, " ," & nv ("result", "built") & ASCII.LF);
assimulate_substring (history, " ," & nv ("origin", origin) & ASCII.LF);
assimulate_substring (history, " ," & nv ("info", "") & ASCII.LF);
assimulate_substring (history, " ," & nv ("duration", duration) & ASCII.LF);
assimulate_substring (history, " }" & ASCII.LF);
check_history_segment_capacity;
end record_history_built;
-----------------------------
-- record_history_failed --
-----------------------------
procedure record_history_failed
(elapsed : String;
slave_id : builders;
origin : String;
duration : String;
die_phase : String;
skips : Natural)
is
info : constant String := die_phase & ":" & JT.int2str (skips);
ID : constant String := JT.zeropad (Integer (slave_id), 2);
begin
history.log_entry := history.log_entry + 1;
history.segment_count := history.segment_count + 1;
handle_first_history_entry;
assimulate_substring (history, " " & nv ("entry", history.log_entry) & ASCII.LF);
assimulate_substring (history, " ," & nv ("elapsed", elapsed) & ASCII.LF);
assimulate_substring (history, " ," & nv ("ID", ID) & ASCII.LF);
assimulate_substring (history, " ," & nv ("result", "failed") & ASCII.LF);
assimulate_substring (history, " ," & nv ("origin", origin) & ASCII.LF);
assimulate_substring (history, " ," & nv ("info", info) & ASCII.LF);
assimulate_substring (history, " ," & nv ("duration", duration) & ASCII.LF);
assimulate_substring (history, " }" & ASCII.LF);
check_history_segment_capacity;
end record_history_failed;
------------------------------
-- record_history_ignored --
------------------------------
procedure record_history_ignored
(elapsed : String;
origin : String;
reason : String;
skips : Natural)
is
cleantxt : constant String := JT.strip_control (reason);
info : constant String :=
JT.replace_char
(JT.replace_char (cleantxt, ASCII.Quotation, " "), ASCII.Back_Slash, "\")
& ":|:" & JT.int2str (skips);
begin
history.log_entry := history.log_entry + 1;
history.segment_count := history.segment_count + 1;
handle_first_history_entry;
assimulate_substring (history, " " & nv ("entry", history.log_entry) & ASCII.LF);
assimulate_substring (history, " ," & nv ("elapsed", elapsed) & ASCII.LF);
assimulate_substring (history, " ," & nv ("ID", "--") & ASCII.LF);
assimulate_substring (history, " ," & nv ("result", "ignored") & ASCII.LF);
assimulate_substring (history, " ," & nv ("origin", origin) & ASCII.LF);
assimulate_substring (history, " ," & nv ("info", info) & ASCII.LF);
assimulate_substring (history, " ," & nv ("duration", "--:--:--") & ASCII.LF);
assimulate_substring (history, " }" & ASCII.LF);
check_history_segment_capacity;
end record_history_ignored;
------------------------------
-- record_history_skipped --
------------------------------
procedure record_history_skipped
(elapsed : String;
origin : String;
reason : String)
is
begin
history.log_entry := history.log_entry + 1;
history.segment_count := history.segment_count + 1;
handle_first_history_entry;
assimulate_substring (history, " " & nv ("entry", history.log_entry) & ASCII.LF);
assimulate_substring (history, " ," & nv ("elapsed", elapsed) & ASCII.LF);
assimulate_substring (history, " ," & nv ("ID", "--") & ASCII.LF);
assimulate_substring (history, " ," & nv ("result", "skipped") & ASCII.LF);
assimulate_substring (history, " ," & nv ("origin", origin) & ASCII.LF);
assimulate_substring (history, " ," & nv ("info", reason) & ASCII.LF);
assimulate_substring (history, " ," & nv ("duration", "--:--:--") & ASCII.LF);
assimulate_substring (history, " }" & ASCII.LF);
check_history_segment_capacity;
end record_history_skipped;
--------------------------------------
-- check_history_segment_capacity --
--------------------------------------
procedure check_history_segment_capacity is
begin
if history.segment_count = 1 then
history.segment := history.segment + 1;
return;
end if;
if history.segment_count < kfile_units_limit then
return;
end if;
write_history_json;
history.last_index := 0;
history.last_written := 0;
history.segment_count := 0;
end check_history_segment_capacity;
end PortScan.Ops;
|
charlie5/aIDE | Ada | 3,541 | adb | with
AdaM.Factory;
package body AdaM.record_Component
is
-- Storage Pool
--
record_Version : constant := 1;
pool_Size : constant := 5_000;
package Pool is new AdaM.Factory.Pools (".adam-store",
"record_Components",
pool_Size,
record_Version,
record_Component.item,
record_Component.view);
-- Forge
--
procedure define (Self : in out Item)
is
begin
Self.Definition := component_Definition.new_Definition (is_subtype_Indication => True);
end define;
procedure destruct (Self : in out Item)
is
use component_Definition;
begin
free (Self.Definition);
end destruct;
function new_Component (Name : in String) return View
is
new_View : constant record_Component.view := Pool.new_Item;
begin
define (record_Component.item (new_View.all));
new_View.Name_is (+Name);
return new_View;
end new_Component;
procedure free (Self : in out record_Component.view)
is
begin
destruct (record_Component.item (Self.all));
Pool.free (Self);
end free;
-- Attributes
--
overriding
function Id (Self : access Item) return AdaM.Id
is
begin
return Pool.to_Id (Self);
end Id;
overriding
function Name (Self : in Item) return Identifier
is
begin
return +Self.Name;
end Name;
procedure Name_is (Self : out Item; Now : in Identifier)
is
begin
Self.Name := +(String (Now));
end Name_is;
function is_Aliased (Self : in Item) return Boolean
is
begin
return Self.Definition.is_Aliased;
end is_Aliased;
-- procedure Definition_is (Self : in out Item; Now : in AdaM.component_Definition.view)
-- is
-- begin
-- Self.Definition := Now;
-- end Definition_is;
function Definition (Self : in Item) return AdaM.component_Definition.view
is
begin
return Self.Definition;
end Definition;
-- procedure Type_is (Self : in out Item; Now : in AdaM.a_Type.view)
-- is
-- begin
-- Self.my_Type := Now;
-- end Type_is;
--
--
-- function my_Type (Self : in Item) return AdaM.a_Type.view
-- is
-- begin
-- return Self.my_Type;
-- end my_Type;
--
--
-- function my_Type (Self : access Item) return access AdaM.a_Type.view
-- is
-- begin
-- return Self.my_Type'Access;
-- end my_Type;
procedure Default_is (Self : in out Item; Now : in String)
is
begin
Self.Initialiser := +Now;
end Default_is;
function Default (Self : in Item) return String
is
begin
return +Self.Initialiser;
end Default;
overriding
function to_Source (Self : in Item) return text_Vectors.Vector
is
the_Source : text_Vectors.Vector;
begin
return the_Source;
end to_Source;
-- Streams
--
procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : in View)
renames Pool.View_write;
procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : out View)
renames Pool.View_read;
end AdaM.record_Component;
|
AdaCore/langkit | Ada | 1,479 | adb | with Ada.Text_IO; use Ada.Text_IO;
with System.Assertions;
with Langkit_Support.Vectors;
procedure Main is
package Int_Vectors is new Langkit_Support.Vectors (Integer);
procedure Put (V : Int_Vectors.Vector);
function Create (N : Natural) return Int_Vectors.Vector;
---------
-- Put --
---------
procedure Put (V : Int_Vectors.Vector) is
begin
Put ('[');
for I in V.First_Index .. V.Last_Index loop
if I > V.First_Index then
Put (", ");
end if;
Put (Integer'Image (V.Get (I)));
end loop;
Put (']');
New_Line;
end Put;
------------
-- Create --
------------
function Create (N : Natural) return Int_Vectors.Vector is
begin
return Result : Int_Vectors.Vector do
for I in 1 .. N loop
Result.Append (I);
end loop;
end return;
end Create;
V : Int_Vectors.Vector;
begin
Put ("Empty vector: ");
V := Create (0);
begin
V.Cut (5);
raise Program_Error;
exception
when System.Assertions.Assert_Failure =>
Put_Line ("Out of bound access");
end;
V.Destroy;
Put ("Out-of-bounds: ");
V := Create (3);
begin
V.Cut (5);
raise Program_Error;
exception
when System.Assertions.Assert_Failure =>
Put_Line ("Out of bound access");
end;
V.Destroy;
Put ("In-bounds: ");
V := Create (5);
V.Cut (3);
Put (V);
V.Destroy;
end Main;
|
onox/json-ada | Ada | 1,910 | ads | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with JSON.Types;
with JSON.Streams;
generic
with package Types is new JSON.Types (<>);
package JSON.Tokenizers with SPARK_Mode => On is
pragma Preelaborate;
type Token_Kind is
(Begin_Array_Token,
Begin_Object_Token,
End_Array_Token,
End_Object_Token,
Name_Separator_Token,
Value_Separator_Token,
String_Token,
Integer_Token,
Float_Token,
Boolean_Token,
Null_Token,
EOF_Token,
Invalid_Token);
type Token (Kind : Token_Kind := Invalid_Token) is record
case Kind is
when String_Token =>
String_Offset, String_Length : Streams.AS.Stream_Element_Offset;
when Integer_Token =>
Integer_Value : Types.Integer_Type;
when Float_Token =>
Float_Value : Types.Float_Type;
when Boolean_Token =>
Boolean_Value : Boolean;
when others =>
null;
end case;
end record;
procedure Read_Token
(Stream : in out Streams.Stream;
Next_Token : out Token;
Expect_EOF : Boolean := False)
with Post => Next_Token.Kind /= Invalid_Token and Expect_EOF = (Next_Token.Kind = EOF_Token);
Tokenizer_Error : exception;
end JSON.Tokenizers;
|
reznikmm/matreshka | Ada | 4,663 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Dr3d.Vertical_Segments_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Dr3d_Vertical_Segments_Attribute_Node is
begin
return Self : Dr3d_Vertical_Segments_Attribute_Node do
Matreshka.ODF_Dr3d.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Dr3d_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Dr3d_Vertical_Segments_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Vertical_Segments_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Dr3d_URI,
Matreshka.ODF_String_Constants.Vertical_Segments_Attribute,
Dr3d_Vertical_Segments_Attribute_Node'Tag);
end Matreshka.ODF_Dr3d.Vertical_Segments_Attributes;
|
fractal-mind/Amass | Ada | 1,220 | ads | -- Copyright 2022 Jeff Foley. All rights reserved.
-- Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
local json = require("json")
name = "SOCRadar"
type = "api"
function start()
set_rate_limit(1)
end
function check()
local c
local cfg = datasrc_config()
if cfg ~= nil then
c = cfg.credentials
end
if (c ~= nil and c.key ~= nil and c.key ~= "") then
return true
end
return false
end
function vertical(ctx, domain)
local c
local cfg = datasrc_config()
if cfg ~= nil then
c = cfg.credentials
end
if (c == nil or c.key == nil or c.key == "") then
return
end
local resp, err = request(ctx, {['url']=build_url(domain, c.key)})
if (err ~= nil and err ~= "") then
log(ctx, "vertical request to service failed: " .. err)
return
end
local j = json.decode(resp)
if (j == nil or j.is_success ~= true) then
return
end
for _, sub in pairs(j.data.subdomains) do
new_name(ctx, sub)
end
end
function build_url(domain, key)
return "https://platform.socradar.com/api/threat/analysis?key=" .. key .. "&entity=" .. domain
end
|
reznikmm/matreshka | Ada | 5,245 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
-- An interaction constraint is a Boolean expression that guards an operand
-- in a combined fragment.
------------------------------------------------------------------------------
with AMF.UML.Constraints;
limited with AMF.UML.Value_Specifications;
package AMF.UML.Interaction_Constraints is
pragma Preelaborate;
type UML_Interaction_Constraint is limited interface
and AMF.UML.Constraints.UML_Constraint;
type UML_Interaction_Constraint_Access is
access all UML_Interaction_Constraint'Class;
for UML_Interaction_Constraint_Access'Storage_Size use 0;
not overriding function Get_Maxint
(Self : not null access constant UML_Interaction_Constraint)
return AMF.UML.Value_Specifications.UML_Value_Specification_Access is abstract;
-- Getter of InteractionConstraint::maxint.
--
-- The maximum number of iterations of a loop
not overriding procedure Set_Maxint
(Self : not null access UML_Interaction_Constraint;
To : AMF.UML.Value_Specifications.UML_Value_Specification_Access) is abstract;
-- Setter of InteractionConstraint::maxint.
--
-- The maximum number of iterations of a loop
not overriding function Get_Minint
(Self : not null access constant UML_Interaction_Constraint)
return AMF.UML.Value_Specifications.UML_Value_Specification_Access is abstract;
-- Getter of InteractionConstraint::minint.
--
-- The minimum number of iterations of a loop
not overriding procedure Set_Minint
(Self : not null access UML_Interaction_Constraint;
To : AMF.UML.Value_Specifications.UML_Value_Specification_Access) is abstract;
-- Setter of InteractionConstraint::minint.
--
-- The minimum number of iterations of a loop
end AMF.UML.Interaction_Constraints;
|
MinimSecure/unum-sdk | Ada | 932 | adb | -- Copyright 2015-2019 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
package body Pck is
function Ident (R : Record_Type) return Record_Type is
begin
return R;
end Ident;
procedure Do_Nothing (A : System.Address) is
begin
null;
end Do_Nothing;
end Pck;
|
aeszter/lox-spark | Ada | 3,237 | adb | package body Ast_Printers is
function Print (The_Expr : Expr'Class) return String is
V : Ast_Printer;
begin
Accept_Visitor (The_Expr, V);
return Print (V);
end Print;
function Print (V : Ast_Printer) return String is
begin
return To_String (V.Image);
end Print;
function Print (The_Expr : Binary) return String is
begin
return "(" & To_String (The_Expr.Get_operator.Lexeme) & " "
& Print (Retrieve (The_Expr.Get_left)) & " "
& Print (Retrieve (The_Expr.Get_right)) & ")";
end Print;
function Print (The_Expr : Grouping) return String is
begin
return "(group " & Print (Retrieve (The_Expr.Get_expression)) & ")";
end Print;
function Print (The_Expr : Float_Literal) return String is
begin
return Float'Image (The_Expr.Get_value);
end Print;
function Print (The_Expr : Num_Literal) return String is
begin
return Integer'Image (The_Expr.Get_value);
end Print;
function Print (The_Expr : Str_Literal) return String is
begin
return L_Strings.To_String (The_Expr.Get_value);
end Print;
function Print (The_Expr : Unary) return String is
begin
return "(" & To_String (The_Expr.Get_operator.Lexeme) & " " & Print (Retrieve (The_Expr.Get_right)) & ")";
end Print;
generic
type Expr_Type (<>) is abstract new Expr with private;
with function Print (The_Expr : Expr_Type) return String is <>;
procedure Visit_Expr (V : in out Ast_Printer; The_Expr : Expr_Type);
procedure Visit_Expr (V : in out Ast_Printer; The_Expr : Expr_Type) is
function Local_Print (E : Expr_Type) return String
renames Print; -- resolve ambiguity
Image : constant String := Local_Print (The_Expr);
begin
V.Image := To_Bounded_String (Image);
end Visit_Expr;
procedure Do_Visit_Binary_Expr is new Visit_Expr (Binary);
overriding
procedure visit_Binary_Expr (Self : in out Ast_Printer; The_Expr : Binary)
renames Do_Visit_Binary_Expr;
procedure Do_Visit_Grouping_Expr is new Visit_Expr (Grouping);
overriding
procedure visit_Grouping_Expr (Self : in out Ast_Printer; The_Expr : Grouping)
renames Do_Visit_Grouping_Expr;
procedure Do_Visit_Float_Literal_Expr is new Visit_Expr (Float_Literal);
overriding
procedure visit_Float_Literal_Expr (Self : in out Ast_Printer; The_Expr : Float_Literal)
renames Do_Visit_Float_Literal_Expr;
procedure Do_Visit_Num_Literal_Expr is new Visit_Expr (Num_Literal);
overriding
procedure visit_Num_Literal_Expr (Self : in out Ast_Printer; The_Expr : Num_Literal)
renames Do_Visit_Num_Literal_Expr;
procedure Do_Visit_str_literal_Expr is new Visit_Expr (Str_Literal);
overriding
procedure visit_Str_Literal_Expr (Self : in out Ast_Printer; The_Expr : Str_Literal)
renames Do_Visit_str_literal_Expr;
procedure Do_Visit_unary_Expr is new Visit_Expr (Unary);
overriding
procedure visit_Unary_Expr (Self : in out Ast_Printer; The_Expr : Unary)
renames Do_Visit_unary_Expr;
end Ast_Printers;
|
AdaCore/libadalang | Ada | 2,474 | adb | -- Check that ``Libadalang.Config_Pragmas.Set_Mapping`` rejects invalid inputs
-- as expected.
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Langkit_Support.Errors; use Langkit_Support.Errors;
with Libadalang.Analysis; use Libadalang.Analysis;
with Libadalang.Config_Pragmas; use Libadalang.Config_Pragmas;
procedure Invalid is
Ctx : constant Analysis_Context := Create_Context;
Ctx_2 : constant Analysis_Context := Create_Context;
procedure Check_Error
(Label : String;
Context : Analysis_Context;
Mapping : Config_Pragmas_Mapping);
-- Run ``Set_Mapping (Context, Mapping)`` and print if it raises an
-- exception.
-----------------
-- Check_Error --
-----------------
procedure Check_Error
(Label : String;
Context : Analysis_Context;
Mapping : Config_Pragmas_Mapping) is
begin
Put_Line ("== " & Label & "==");
New_Line;
begin
Set_Mapping (Context, Mapping);
Put_Line ("No exception...");
exception
when Exc : Precondition_Failure =>
Put_Line (Exception_Name (Exc) & ": " & Exception_Message (Exc));
end;
New_Line;
end Check_Error;
Mapping : Config_Pragmas_Mapping;
Key : constant Analysis_Unit := Ctx.Get_From_File ("key");
Value : constant Analysis_Unit := Ctx.Get_From_File ("value");
begin
Mapping.Local_Pragmas.Include (Key, Value);
Check_Error ("no context", No_Analysis_Context, Mapping);
declare
M : Config_Pragmas_Mapping := Mapping;
begin
M.Local_Pragmas.Include (Ctx_2.Get_From_File ("key2"), Value);
Check_Error ("foreign key unit", Ctx, M);
end;
declare
M : Config_Pragmas_Mapping := Mapping;
begin
M.Local_Pragmas.Include (Key, Ctx_2.Get_From_File ("value2"));
Check_Error ("foreign value unit", Ctx, M);
end;
declare
M : Config_Pragmas_Mapping := Mapping;
begin
M.Global_Pragmas := Ctx_2.Get_From_File ("glob");
Check_Error ("foreign global", Ctx, M);
end;
declare
M : Config_Pragmas_Mapping := Mapping;
begin
M.Local_Pragmas.Include (No_Analysis_Unit, Value);
Check_Error ("null key unit", Ctx, M);
end;
declare
M : Config_Pragmas_Mapping := Mapping;
begin
M.Local_Pragmas.Include (Key, No_Analysis_Unit);
Check_Error ("null value unit", Ctx, M);
end;
Put_Line ("Done.");
end Invalid;
|
onox/orka | Ada | 2,625 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2022 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with AUnit.Assertions;
with AUnit.Test_Caller;
with AUnit.Test_Fixtures;
with Orka.SIMD.SSE2.Integers.Shift;
package body Test_SIMD_SSE2_Shift is
use Orka;
use Orka.SIMD.SSE2.Integers;
use Orka.SIMD.SSE2.Integers.Shift;
use AUnit.Assertions;
type Test is new AUnit.Test_Fixtures.Test_Fixture with null record;
procedure Test_Shift_Left_Zeros (Object : in out Test) is
Values : constant m128i := (0, 1, 2**16, 2**30);
-- x86 is little endian, so 'left' element is on the right side
Expected : constant m128i := (0, 0, 1, 2**16);
Result : constant m128i := Shift_Elements_Left_Zeros (Values);
begin
for I in Index_4D loop
Assert (Expected (I) = Result (I), "Unexpected Integer at " & I'Image);
end loop;
end Test_Shift_Left_Zeros;
procedure Test_Shift_Right_Zeros (Object : in out Test) is
Values : constant m128i := (0, 1, 2**16, 2**30);
-- x86 is little endian, so 'left' element is on the right side
Expected : constant m128i := (1, 2**16, 2**30, 0);
Result : constant m128i := Shift_Elements_Right_Zeros (Values);
begin
for I in Index_4D loop
Assert (Expected (I) = Result (I), "Unexpected Integer at " & I'Image);
end loop;
end Test_Shift_Right_Zeros;
----------------------------------------------------------------------------
package Caller is new AUnit.Test_Caller (Test);
Test_Suite : aliased AUnit.Test_Suites.Test_Suite;
function Suite return AUnit.Test_Suites.Access_Test_Suite is
Name : constant String := "(SIMD - SSE2 - Integers - Shift) ";
begin
Test_Suite.Add_Test (Caller.Create
(Name & "Test function Shift_Elements_Left_Zeros", Test_Shift_Left_Zeros'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test function Shift_Elements_Right_Zeros", Test_Shift_Right_Zeros'Access));
return Test_Suite'Access;
end Suite;
end Test_SIMD_SSE2_Shift;
|
tum-ei-rcs/StratoX | Ada | 3,738 | ads | with HAL; use HAL;
with HAL.Framebuffer; use HAL.Framebuffer;
with HAL.Bitmap;
private with STM32.Device;
private with STM32.DMA2D_Bitmap;
private with STM32.LTDC;
private with OTM8009A;
private with HAL.DSI;
package Framebuffer_OTM8009A is
LCD_Natural_Width : constant := 800;
LCD_Natural_Height : constant := 480;
type Frame_Buffer is limited
new HAL.Framebuffer.Frame_Buffer_Display with private;
overriding function Get_Max_Layers
(Display : Frame_Buffer) return Positive;
overriding function Is_Supported
(Display : Frame_Buffer;
Mode : HAL.Framebuffer.FB_Color_Mode) return Boolean;
procedure Initialize
(Display : in out Frame_Buffer;
Orientation : HAL.Framebuffer.Display_Orientation := Default;
Mode : HAL.Framebuffer.Wait_Mode := Interrupt);
overriding function Initialized
(Display : Frame_Buffer) return Boolean;
overriding procedure Set_Orientation
(Display : in out Frame_Buffer;
Orientation : HAL.Framebuffer.Display_Orientation);
overriding procedure Set_Mode
(Display : in out Frame_Buffer;
Mode : HAL.Framebuffer.Wait_Mode);
overriding function Get_Width
(Display : Frame_Buffer) return Positive;
overriding function Get_Height
(Display : Frame_Buffer) return Positive;
overriding function Is_Swapped
(Display : Frame_Buffer) return Boolean;
overriding procedure Set_Background
(Display : Frame_Buffer; R, G, B : Byte);
overriding procedure Initialize_Layer
(Display : in out Frame_Buffer;
Layer : Positive;
Mode : HAL.Framebuffer.FB_Color_Mode;
X : Natural := 0;
Y : Natural := 0;
Width : Positive := Positive'Last;
Height : Positive := Positive'Last);
-- All layers are double buffered, so an explicit call to Update_Layer
-- needs to be performed to actually display the current buffer attached
-- to the layer.
-- Alloc is called to create the actual buffer.
overriding function Initialized
(Display : Frame_Buffer;
Layer : Positive) return Boolean;
overriding procedure Update_Layer
(Display : in out Frame_Buffer;
Layer : Positive;
Copy_Back : Boolean := False);
-- Updates the layer so that the hidden buffer is displayed.
-- If Copy_Back is set, then the newly displayed buffer will be copied back
-- the the hidden buffer
overriding procedure Update_Layers
(Display : in out Frame_Buffer);
-- Updates all initialized layers at once with their respective hidden
-- buffer
overriding function Get_Color_Mode
(Display : Frame_Buffer;
Layer : Positive) return HAL.Framebuffer.FB_Color_Mode;
overriding function Get_Hidden_Buffer
(Display : Frame_Buffer;
Layer : Positive) return HAL.Bitmap.Bitmap_Buffer'Class;
-- Retrieves the current hidden buffer for the layer.
overriding function Get_Pixel_Size
(Display : Frame_Buffer;
Layer : Positive) return Positive;
private
type FB_Array is array (STM32.LTDC.LCD_Layer) of
STM32.DMA2D_Bitmap.DMA2D_Bitmap_Buffer;
LCD_Channel : constant HAL.DSI.DSI_Virtual_Channel_ID := 0;
-- Only one display on this board, constant to 0
type Frame_Buffer is limited new HAL.Framebuffer.Frame_Buffer_Display with
record
Device : OTM8009A.OTM8009A_Device
(DSI_Host => STM32.Device.DSIHOST'Access,
Channel_Id => LCD_Channel);
Swapped : Boolean;
Buffers : FB_Array := (others => STM32.DMA2D_Bitmap.Null_Buffer);
end record;
type Frame_Buffer_Ref is access all Frame_Buffer;
end Framebuffer_OTM8009A;
|
timboudreau/netbeans-contrib | Ada | 1,346 | adb | --
-- 3.3.1 Object Declarations
--
-- object_declaration ::=
-- defining_identifier_list : [aliased] [constant] subtype_indication [:= expression];
-- | defining_identifier_list : [aliased] [constant] array_type_definition [:= expression];
-- | single_task_declaration
-- | single_protected_declaration
--
-- defining_identifier_list ::=
-- defining_identifier {, defining_identifier}
--
-- NOTE: This module is not compilation is used only for testing purposes
--
procedure Object_Declaration is
-- Example of a multiple object declaration:
-- the multiple object declaration
John, Paul : Person_Name := new Person(Sex => M); -- see 3.10.1
-- is equivalent to the two single object declarations in the order given
John2 : Person_Name := new Person(Sex => M);
Paul2 : Person_Name := new Person(Sex => M);
-- Examples of variable declarations:
Count, Sum : Integer;
Size : Integer range 0 .. 10_000 := 0;
Sorted : Boolean := False;
Color_Table : array(1 .. Max) of Color;
Option : Bit_Vector(1 .. 10) := (others => True);
Hello : constant String := "Hi, world.";
-- Examples of constant declarations:
Limit : constant Integer := 10_000;
Low_Limit : constant Integer := Limit/10;
Tolerance : constant Real := Dispersion(1.15);
begin
null;
end Object_Declaration; |
reznikmm/matreshka | Ada | 4,041 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Draw_Caption_Point_X_Attributes;
package Matreshka.ODF_Draw.Caption_Point_X_Attributes is
type Draw_Caption_Point_X_Attribute_Node is
new Matreshka.ODF_Draw.Abstract_Draw_Attribute_Node
and ODF.DOM.Draw_Caption_Point_X_Attributes.ODF_Draw_Caption_Point_X_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Draw_Caption_Point_X_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Draw_Caption_Point_X_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Draw.Caption_Point_X_Attributes;
|
godunko/adagl | Ada | 5,062 | adb | ------------------------------------------------------------------------------
-- --
-- Ada binding for OpenGL/WebGL --
-- --
-- Examples Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2018, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with League.Strings;
with WebAPI.HTML.Globals;
with WebAPI.HTML.Canvas_Elements;
with OpenGL.Contexts;
with OpenGL.Textures;
with Pyramid.Programs;
procedure Pyramid.Driver is
use type OpenGL.GLfloat;
Points : constant Pyramid.Programs.Vertex_Data_Array
:= (((0.0, 0.5, 0.0), (0.5, 1.0)),
((0.5, -0.5, 0.0), (1.0, 0.0)),
((-0.5, -0.5, 0.0), (0.0, 0.0)));
-- Img : constant array (1 .. 9, 1 .. 3) of OpenGL.GLubyte :=
-- ((255, 0, 0), (127, 0, 0), (0, 0, 127),
-- (127, 255, 0), (0, 127, 0), (0, 0, 127),
-- (32, 0, 255), (0, 0, 127), (0,0, 127));
Unit : constant OpenGL.Texture_Unit := 0;
Context : OpenGL.Contexts.OpenGL_Context;
Buffer :
Pyramid.Programs.Vertex_Data_Buffers.OpenGL_Buffer (OpenGL.Vertex);
Program : Pyramid.Programs.Pyramid_Program;
Texture : OpenGL.Textures.OpenGL_Texture (OpenGL.Texture_2D);
begin
Context.Create
(WebAPI.HTML.Canvas_Elements.HTML_Canvas_Element_Access
(WebAPI.HTML.Globals.Window.Get_Document.Get_Element_By_Id
(League.Strings.To_Universal_String ("canvas"))));
Context.Make_Current;
Context.Functions.Enable (OpenGL.GL_DEPTH_TEST);
Buffer.Create;
Buffer.Bind;
Buffer.Allocate (Points);
Texture.Create;
Texture.Bind (Unit);
-- Texture.Set_Image_2D
-- (0, OpenGL.GL_RGB, 3, 3, OpenGL.GL_UNSIGNED_BYTE, Img'Address);
Texture.Set_Parameter (OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
Texture.Set_Parameter (OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
Program.Initialize;
Program.Bind;
Program.Set_Vertex_Data_Buffer (Buffer);
Program.Set_Texture_Unit (Unit);
declare
use type OpenGL.GLbitfield;
Clear_Flag : OpenGL.Clear_Buffer_Mask :=
OpenGL.GL_DEPTH_BUFFER_BIT + OpenGL.GL_COLOR_BUFFER_BIT;
begin
Context.Functions.Clear (Clear_Flag);
Context.Functions.Draw_Arrays (OpenGL.GL_TRIANGLES, 0, Points'Length);
end;
end Pyramid.Driver;
|
AdamSzerszen/Concurrency_v.2.0 | Ada | 282 | adb | with Infrastructure; use Infrastructure;
procedure Main is
test_steering: Steering;
begin
test_steering.SetNumber(5);
test_steering.CheckStatus;
test_steering.Incoming(12);
test_steering.CheckStatus;
test_steering.Leaving;
test_steering.CheckStatus;
end Main;
|
reznikmm/matreshka | Ada | 4,041 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Presentation_Pages_Attributes;
package Matreshka.ODF_Presentation.Pages_Attributes is
type Presentation_Pages_Attribute_Node is
new Matreshka.ODF_Presentation.Abstract_Presentation_Attribute_Node
and ODF.DOM.Presentation_Pages_Attributes.ODF_Presentation_Pages_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Presentation_Pages_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Presentation_Pages_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Presentation.Pages_Attributes;
|
reznikmm/matreshka | Ada | 4,783 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Visitors;
with ODF.DOM.Text_Sender_Firstname_Elements;
package Matreshka.ODF_Text.Sender_Firstname_Elements is
type Text_Sender_Firstname_Element_Node is
new Matreshka.ODF_Text.Abstract_Text_Element_Node
and ODF.DOM.Text_Sender_Firstname_Elements.ODF_Text_Sender_Firstname
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Text_Sender_Firstname_Element_Node;
overriding function Get_Local_Name
(Self : not null access constant Text_Sender_Firstname_Element_Node)
return League.Strings.Universal_String;
overriding procedure Enter_Node
(Self : not null access Text_Sender_Firstname_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Leave_Node
(Self : not null access Text_Sender_Firstname_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Visit_Node
(Self : not null access Text_Sender_Firstname_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
end Matreshka.ODF_Text.Sender_Firstname_Elements;
|
reznikmm/matreshka | Ada | 8,183 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
package AMF.UML is
pragma Preelaborate;
type UML_Aggregation_Kind is
(None,
Shared,
Composite);
type UML_Call_Concurrency_Kind is
(Sequential,
Guarded,
Concurrent);
type UML_Connector_Kind is
(Assembly,
Delegation);
type UML_Expansion_Kind is
(Parallel,
Iterative,
Stream);
type UML_Interaction_Operator_Kind is
(Alt_Operator,
Opt_Operator,
Break_Operator,
Par_Operator,
Loop_Operator,
Critical_Operator,
Neg_Operator,
Assert_Operator,
Strict_Operator,
Seq_Operator,
Ignore_Operator,
Consider_Operator);
type UML_Message_Kind is
(Complete,
Lost,
Found,
Unknown);
type UML_Message_Sort is
(Synch_Call,
Asynch_Call,
Asynch_Signal,
Create_Message,
Delete_Message,
Reply);
type UML_Object_Node_Ordering_Kind is
(Unordered,
Ordered,
LIFO,
FIFO);
type UML_Parameter_Direction_Kind is
(In_Parameter,
In_Out_Parameter,
Out_Parameter,
Return_Parameter);
type UML_Parameter_Effect_Kind is
(Create,
Read,
Update,
Delete);
type UML_Pseudostate_Kind is
(Initial_Pseudostate,
Deep_History_Pseudostate,
Shallow_History_Pseudostate,
Join_Pseudostate,
Fork_Pseudostate,
Junction_Pseudostate,
Choice_Pseudostate,
Entry_Point_Pseudostate,
Exit_Point_Pseudostate,
Terminate_Pseudostate);
type UML_Transition_Kind is
(External,
Internal,
Local);
type UML_Visibility_Kind is
(Public_Visibility,
Private_Visibility,
Protected_Visibility,
Package_Visibility);
type Optional_UML_Aggregation_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Aggregation_Kind;
end case;
end record;
type Optional_UML_Call_Concurrency_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Call_Concurrency_Kind;
end case;
end record;
type Optional_UML_Connector_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Connector_Kind;
end case;
end record;
type Optional_UML_Expansion_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Expansion_Kind;
end case;
end record;
type Optional_UML_Interaction_Operator_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Interaction_Operator_Kind;
end case;
end record;
type Optional_UML_Message_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Message_Kind;
end case;
end record;
type Optional_UML_Message_Sort (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Message_Sort;
end case;
end record;
type Optional_UML_Object_Node_Ordering_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Object_Node_Ordering_Kind;
end case;
end record;
type Optional_UML_Parameter_Direction_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Parameter_Direction_Kind;
end case;
end record;
type Optional_UML_Parameter_Effect_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Parameter_Effect_Kind;
end case;
end record;
type Optional_UML_Pseudostate_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Pseudostate_Kind;
end case;
end record;
type Optional_UML_Transition_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Transition_Kind;
end case;
end record;
type Optional_UML_Visibility_Kind (Is_Empty : Boolean := True) is record
case Is_Empty is
when True =>
null;
when False =>
Value : UML_Visibility_Kind;
end case;
end record;
end AMF.UML;
|
zhmu/ananas | Ada | 172 | adb | -- { dg-do compile }
with Pointer_Discr1_Pkg1;
with Pointer_Discr1_Pkg3;
procedure Pointer_Discr1 is
begin
Pointer_Discr1_Pkg3.Map(Pointer_Discr1_Pkg1.Window(1));
end;
|
AdaCore/libadalang | Ada | 129 | adb | package body Foo is
protected body T is
procedure Test is
begin
null;
end Test;
end T;
end Foo;
|
NCommander/dnscatcher | Ada | 4,078 | ads | -- Copyright 2019 Michael Casadevall <[email protected]>
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to
-- deal in the Software without restriction, including without limitation the
-- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-- sell copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-- DEALINGS IN THE SOFTWARE.
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with GNAT.Sockets; use GNAT.Sockets;
with DNSCatcher.Utils.Logger; use DNSCatcher.Utils.Logger;
-- @summary
-- Configuration information used by the DNSCatcher library
--
-- @description
-- The DNSCatcher library (and daemons) require configuration to know external
-- resources such as validation resolvers, database storage information, and
-- logger information.
--
-- This information can be stored as a configuration file, loaded from the
-- database (to be implemented), or programmatically stored. It is intended
-- for configuration information to be dynamically updatable (either through
-- runtime commands or sending SIGHUP to the Catcher daemon). As such
-- configuration information will be migrated to being a protected object
-- with standard setters and getters to prevent race conditions.
--
package DNSCatcher.Config is
-- Configuration record information
--
-- @field Local_Listen_Port
-- Port currently used to determine where DNS requests are listened for when
-- accepting legacy DNS traffic. Defaults to 53.
--
-- @field Upstream_DNS_Server
-- Currently used to denote servers requests are forwarded to. At the moment
-- only one server is supported at a time
--
-- @field Upstream_DNS_Server_Port Port to communicate with the server with.
-- Defaults to 53.
--
-- @field Logger_Config
-- Global configuration of the Logger object
type Configuration is limited record
Local_Listen_Port : Port_Type;
Upstream_DNS_Server : Unbounded_String;
Upstream_DNS_Server_Port : Port_Type;
Logger_Config : Logger_Configuration;
end record;
--type Configuration_Ptr is access Configuration;
-- Functions
-- Initializes the Configuration parser by loading methods to handle data
-- values and storage. Must be called before calling Parse_Config_File
procedure Initialize_Config_Parse;
-- Initializes a configuration object and returns it with default values set
-- ready for further config
procedure Initialize (Config : in out Configuration);
-- Handles parsing the configuration file
--
-- It is the caller's responsibility to deallocate the pointer after all
-- DNSCatcher services have shutdown.
--
-- @value Config
-- Configuration object
--
-- @value Config_File_Path
-- Path to the configuration file
--
-- @exception Malformed_Line
-- Raised when a line is malformed and can't be properly parsed
--
-- @exception Missing_Mandatory_Config_Option Raised when a mandatory option
-- in the config file is not present
--
procedure Read_Cfg_File
(Config : in out Configuration;
Config_File_Path : String);
-- Defined Exceptions
Malformed_Line : exception;
Missing_Mandatory_Config_Option : exception;
end DNSCatcher.Config;
|
ekoeppen/MSP430_Generic_Ada_Drivers | Ada | 452 | ads | with MSPGD.GPIO.Pin;
with MSPGD.GPIO.Polled;
with MSPGD.Clock.Source;
with MSPGD.UART.Peripheral;
with MSPGD.SPI.Peripheral;
package HAL is
pragma Preelaborate;
generic package Pin renames MSPGD.GPIO.Pin;
generic package Pin_IRQ renames MSPGD.GPIO.Polled;
generic package USART renames MSPGD.UART.Peripheral;
generic package SPI renames MSPGD.SPI.Peripheral;
generic package Clock renames MSPGD.Clock.Source;
end HAL;
|
onox/json-ada | Ada | 3,655 | ads | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with AUnit.Test_Suites;
with AUnit.Test_Fixtures;
package Test_Tokenizers is
function Suite return AUnit.Test_Suites.Access_Test_Suite;
private
type Test is new AUnit.Test_Fixtures.Test_Fixture with null record;
-- Keyword
procedure Test_Null_Token (Object : in out Test);
procedure Test_True_Token (Object : in out Test);
procedure Test_False_Token (Object : in out Test);
-- String
procedure Test_Empty_String_Token (Object : in out Test);
procedure Test_Non_Empty_String_Token (Object : in out Test);
procedure Test_Number_String_Token (Object : in out Test);
procedure Test_Escaped_Character_String_Token (Object : in out Test);
procedure Test_Escaped_Quotation_Solidus_String_Token (Object : in out Test);
-- Integer/float number
procedure Test_Zero_Number_Token (Object : in out Test);
procedure Test_Integer_Number_Token (Object : in out Test);
procedure Test_Float_Number_Token (Object : in out Test);
procedure Test_Negative_Float_Number_Token (Object : in out Test);
procedure Test_Integer_Exponent_Number_Token (Object : in out Test);
procedure Test_Float_Exponent_Number_Token (Object : in out Test);
procedure Test_Float_Negative_Exponent_Number_Token (Object : in out Test);
-- Array
procedure Test_Empty_Array_Tokens (Object : in out Test);
procedure Test_One_Element_Array_Tokens (Object : in out Test);
procedure Test_Two_Elements_Array_Tokens (Object : in out Test);
-- Object
procedure Test_Empty_Object_Tokens (Object : in out Test);
procedure Test_One_Pair_Object_Tokens (Object : in out Test);
procedure Test_Two_Pairs_Object_Tokens (Object : in out Test);
-- Exceptions
procedure Test_Control_Character_String_Exception (Object : in out Test);
procedure Test_Unexpected_Escaped_Character_String_Exception (Object : in out Test);
procedure Test_Minus_Number_EOF_Exception (Object : in out Test);
procedure Test_Minus_Number_Exception (Object : in out Test);
procedure Test_End_Dot_Number_Exception (Object : in out Test);
procedure Test_End_Exponent_Number_Exception (Object : in out Test);
procedure Test_End_Dot_Exponent_Number_Exception (Object : in out Test);
procedure Test_End_Exponent_Minus_Number_Exception (Object : in out Test);
procedure Test_End_Exponent_One_Digit_Exception (Object : in out Test);
procedure Test_End_Exponent_Minus_One_Digit_Exception (Object : in out Test);
procedure Test_Prefixed_Plus_Number_Exception (Object : in out Test);
procedure Test_Leading_Zeroes_Integer_Number_Exception (Object : in out Test);
procedure Test_Leading_Zeroes_Float_Number_Exception (Object : in out Test);
procedure Test_Incomplete_True_Text_Exception (Object : in out Test);
procedure Test_Incomplete_False_Text_Exception (Object : in out Test);
procedure Test_Incomplete_Null_Text_Exception (Object : in out Test);
procedure Test_Unknown_Keyword_Text_Exception (Object : in out Test);
end Test_Tokenizers;
|
zenharris/ada-bbs | Ada | 9,983 | adb | with Terminal_Interface.Curses; use Terminal_Interface.Curses;
with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
--with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
--with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO;
-- with Ada.Containers.Doubly_Linked_Lists;
with Ada.Text_IO;
with Ada.Directories;
use Ada.Text_IO;
use Ada.Directories;
with Ada.Containers.Doubly_Linked_Lists;
with Ada.Containers; use Ada.Containers;
with Text_File_Scroller;
with Process_Menu;
with Texaco;
with Message.Reader; use Message.Reader;
with Pong_Bot;
with Serpent;
with Formatter;
with Dbase.Scroller; -- comment out for No Gnatcoll compile
with Dbase.Login;
with Templates;
procedure Main is
c : Key_Code;
Lines : Line_Position;
Columns : Column_Position;
package SU renames Ada.Strings.Unbounded;
package SUIO renames Ada.Text_IO.Unbounded_IO;
-- task Display_Current_Time is
-- entry Start;
-- end Display_Current_Time;
-- task body Display_Current_Time is
-- Next : Time;
-- D : Duration := 1.0;
-- Now : Time := Clock;
-- win1 : Window;
-- Col : Column_Position;
-- Lin : Line_Position;
-- begin
-- accept Start;
-- win1 := Sub_Window(Win => Standard_Window,
-- Number_Of_Lines => 1,
-- Number_Of_Columns => 32,
-- First_Line_Position => 1,
-- First_Column_Position => 48);
-- -- Box(win1);
-- Refresh(Win => win1);
-- loop
-- Now := Clock;
--
-- Next := Now + D;
-- Get_Cursor_Position(Line => Lin,Column => Col);
-- Add (Win => win1,Line => 0,Column => 0,Str => " Sys Time " & Image (Now));
-- Refresh(Win => win1);
-- Move_Cursor(Line => Lin,Column => Col);
-- Refresh;
-- delay until Next;
-- end loop;
-- end Display_Current_Time;
procedure Serpent_Scoreboard;
function test_func return Boolean is
begin
return True;
end test_func;
procedure logout is
begin
-- Abort Display_Current_Time;
End_Windows;
Curses_Free_All;
raise PROGRAM_ERROR with "Aborted because User Logout. Bye";
end logout;
procedure Run_Fkey1 is
begin
Text_File_Scroller("main.adb");
end;
function Run_Pong_Bot return Boolean is
begin
Pong_Bot.Irc_Client;
return True;
end;
procedure Run_Line_Editor is
Edline : Unbounded_String := To_Unbounded_String("");
c : Key_Code;
begin
Texaco.Password_Editor(Standard_Window,
StartLine => Lines-3,
StartColumn => 0,
Edline => Edline,
MaxLength => 15);
Add(Standard_Window,Column => 0,Line => 10,Str => To_String(Edline));
Refresh;
c := Get_Keystroke;
end;
function Run_Message return Boolean is
begin
Message.Reader.Read_Messages;
-- c := Get_Keystroke;
return True;
end Run_Message;
procedure Run_Serpent is
begin
Serpent;
Serpent_Scoreboard;
end;
procedure Read_Score_File (FileName : in String;
Nick : out Unbounded_String;
Score : out Unbounded_String;
Date : out Unbounded_String) is
HeaderType, HeaderText, scratch : Unbounded_String;
File : File_Type;
begin
Open (File => File,
Mode => In_File,
Name => Filename);
scratch := SUIO.Get_Line(File);
while scratch /= "" loop
HeaderType := To_Unbounded_String(SU.Slice(scratch,1,SU.Index(scratch,":")-1));
HeaderText := To_Unbounded_String(SU.Slice(scratch,SU.Index(scratch,":")+2,SU.Length(scratch)));
if HeaderType = "Nick" then
Nick := HeaderText;
elsif HeaderType = "Score" then
Score := HeaderText;
elsif HeaderType = "Date" then
Date := HeaderText;
end if;
scratch := SUIO.Get_Line(File);
end loop;
Close (File);
exception
when End_Error =>
Close (File);
null;
end Read_Score_File;
procedure Serpent_Scoreboard is
use Message.Reader.Directory_List;
Curr_Dir : string := Current_Directory;
Dbuff : Message.Reader.Directory_List.List;
Dir : Directory_Entry_Type;
Dir_Search : Search_Type;
Nick,Score,Date : Unbounded_String;
I, J, SortCurs : Cursor;
swapped : Boolean;
Linenum : Line_Position := 1;
Display_Window : Window;
Width,Columns : Column_Position := 46;
Length,Lines : Line_Position := 20;
c : Key_Code := 0;
begin
Get_Size(Number_Of_Lines => Lines,Number_Of_Columns => Columns);
Display_Window := Sub_Window(Win => Standard_Window,
Number_Of_Lines => Length,
Number_Of_Columns => Width,
First_Line_Position => (Lines - Length) / 2,
First_Column_Position => (Columns - Width) / 2);
Clear(Display_Window);
Box(Display_Window);
Refresh(Display_Window);
Start_Search(Search => Dir_Search,
Directory => Curr_Dir&"/serpent",
Pattern => "*.score");
if More_Entries(Dir_Search) then
loop
exit when not More_Entries(Dir_Search);
Get_Next_Entry(Dir_Search, Dir);
Read_Score_File(Full_Name(Dir),Nick,Score,Date);
Dbuff.Append( (To_Unbounded_String(Full_Name(Dir)),
Message.Reader.CharPad(Nick,15) &
Message.Reader.CharPad(Score,5) & Date ) );
end loop;
End_Search(Dir_Search);
loop
SortCurs := Dbuff.First;
swapped := False;
while SortCurs /= Dbuff.Last loop
I := SortCurs;
Directory_List.Next(SortCurs);
J := SortCurs;
if Element(J).FileName > Element(I).FileName then
Swap(Dbuff,I,J);
swapped := True;
end if;
end loop;
exit when not swapped;
end loop;
SortCurs := Dbuff.First;
while SortCurs /= Dbuff.Last loop
Add (Display_Window,Line => Linenum,Column => 2,Str => To_String(Element(SortCurs).Prompt));
Linenum := Linenum + 1;
Directory_List.Next(SortCurs);
if Linenum = Length -2 then
Add(Display_Window,Linenum,2,Str => "Any Key More Esc exit");
Refresh(Display_Window);
c := Texaco.GetKey;
exit when (c in Real_Key_Code'Range) and then (Character'val(c) = ESC);
Clear(Display_Window);
Box(Display_Window);
Linenum := 1;
end if;
end loop;
Add (Display_Window,Line => Linenum,Column => 2,Str => To_String(Element(SortCurs).Prompt));
Refresh(Display_Window);
end if;
if c = 0 or else Character'Val(c) /= ESC then
c := Texaco.GetKey;
end if;
Clear(Display_Window);
Refresh(Display_Window);
Delete (Win => Display_Window);
end Serpent_Scoreboard;
Menu1 : Process_Menu.Menu_Type :=
((new String'("Message Forum"),Message.Reader.Read_Messages'Unrestricted_Access),
(new String'("Drack Space"),Dbase.Scroller.Run'Unrestricted_Access), -- Comment Out
(new String'("Drack Space Login"),Dbase.Login.Login_User'Unrestricted_Access),
(new String'("Create DS User"),Dbase.Login.Create_User'Unrestricted_Access),
(new String'("IRC Chat"),Pong_Bot.Irc_Client'Unrestricted_Access),
(new String'("Serpent Game"),Run_Serpent'Unrestricted_Access),
(new String'("Serpent Scores"),Serpent_Scoreboard'Unrestricted_Access),
-- (new String'("Templates"),Templates.Display_Page'Unrestricted_Access),
(new String'("Log Out"),logout'Unrestricted_Access));
Visibility : Cursor_Visibility := Invisible;
begin
-- Dbase.Scroller.test;
-- raise PROGRAM_ERROR with "Aborted because User Logout. Bye";
Init_Screen;
Set_Echo_Mode (False);
Set_Raw_Mode;
-- Set_Meta_Mode;
Set_KeyPad_Mode;
-- Set_Cursor_Visibility(Visibility);
Nap_Milli_Seconds(200);
Clear;
Box;
Refresh;
-- ;
Move_Cursor (Line => 1, Column => 10);
Add (Str => " This Is a Test ");
Refresh;
loop
Get_Size(Number_Of_Lines => Lines,Number_Of_Columns => Columns);
Clear;
Box;
Add (Line => Lines - 2,Column => 1, Str => " Func 1 | Func 2 | Func 3 | Func 4 |");
Refresh;
c := Texaco.GetKey; -- Get_Keystroke;
if c in Special_Key_Code'Range then
case c is
when Key_F1 =>
Process_Menu.Open_Menu (Function_Number => 1,Menu_Array => Menu1 );
when Key_F2 =>
Process_Menu.Open_Menu (Function_Number => 2,Menu_Array => Menu1);
when Key_F3 =>
Process_Menu.Open_Menu (Function_Number => 3,Menu_Array => Menu1);
when Key_F4 =>
Process_Menu.Open_Menu (Function_Number => 4,Menu_Array => Menu1);
when Key_F10 =>
Redraw(Win => Standard_Window,Begin_Line => 0,Line_Count => Integer(Lines));
when Key_End =>
exit;
when others => null;
end case;
end if;
end loop;
-- Abort Display_Current_Time;
End_Windows;
Curses_Free_All;
end Main;
|
AdaCore/libadalang | Ada | 47,289 | adb | ------------------------------------------------------------------------------
-- G P S --
-- --
-- Copyright (C) 2000-2017, AdaCore --
-- --
-- This 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. This software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details. You should have received a copy of the GNU --
-- General Public License distributed with this software; see file --
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
-- of the license. --
------------------------------------------------------------------------------
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Unchecked_Conversion;
pragma Warnings (Off);
with GNAT.TTY; use GNAT.TTY;
with GNAT.Expect.TTY; use GNAT.Expect.TTY;
pragma Warnings (On);
with GNAT.Strings;
with GNATCOLL.Utils; use GNATCOLL.Utils;
with GNATCOLL.VFS; use GNATCOLL.VFS;
with GNATCOLL.VFS_Utils; use GNATCOLL.VFS_Utils;
with System; use System;
with Glib; use Glib;
with Glib.Main; use Glib.Main;
with Glib.Object; use Glib.Object;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Window; use Gtk.Window;
with Gtk; use Gtk;
with Gtkada.Dialogs; use Gtkada.Dialogs;
with Gtkada.MDI; use Gtkada.MDI;
with Commands; use Commands;
with Config; use Config;
with Debugger.Base_Gdb.Gdb_CLI; use Debugger.Base_Gdb.Gdb_CLI;
with Debugger.Base_Gdb.Gdb_MI; use Debugger.Base_Gdb.Gdb_MI;
with Default_Preferences; use Default_Preferences;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with GPS.Intl; use GPS.Intl;
with GPS.Kernel.Hooks; use GPS.Kernel.Hooks;
with GPS.Kernel.Modules; use GPS.Kernel.Modules;
with GPS.Kernel.Modules.UI; use GPS.Kernel.Modules.UI;
with GPS.Kernel.Preferences; use GPS.Kernel.Preferences;
with GPS.Kernel.Project; use GPS.Kernel.Project;
with GPS.Main_Window; use GPS.Main_Window;
with GVD.Code_Editors; use GVD.Code_Editors;
with GVD.Consoles; use GVD.Consoles;
with GVD.Preferences; use GVD.Preferences;
with GVD.Types; use GVD.Types;
with GVD_Module; use GVD_Module;
with Language_Handlers; use Language_Handlers;
with Process_Proxies; use Process_Proxies;
with Projects; use Projects;
with Remote; use Remote;
with Toolchains_Old; use Toolchains_Old;
with GNATCOLL.Traces; use GNATCOLL.Traces;
package body GVD.Process is
Me : constant Trace_Handle := Create ("GVD.Process");
type GPS_Proxy is new Process_Proxy with record
Process : Visual_Debugger;
end record;
-- GPS specific proxy, used to redefine Set_Command_In_Process
overriding procedure Set_Command_In_Process
(Proxy : access GPS_Proxy; In_Process : Boolean := True);
-- Set the appropriate debugger menu items to the corresponding state
pragma Warnings (Off);
-- This UC is safe aliasing-wise, so kill warning
function To_Main_Debug_Window is new
Ada.Unchecked_Conversion (System.Address, GPS_Window);
pragma Warnings (On);
-----------------------
-- Local Subprograms --
-----------------------
procedure First_Text_Output_Filter
(Descriptor : GNAT.Expect.Process_Descriptor'Class;
Str : String;
Window : System.Address);
-- Standard handler to add gdb's output to the debugger window.
-- Simply strip CR characters if needed and then call Text_Output_Filter
procedure Text_Output_Filter
(Descriptor : GNAT.Expect.Process_Descriptor'Class;
Str : String;
Window : System.Address);
-- Real handler called by First_Text_Output_Filter
type On_Before_Exit is new Return_Boolean_Hooks_Function with record
Process : access Visual_Debugger_Record'Class;
end record;
overriding function Execute
(Self : On_Before_Exit;
Kernel : not null access Kernel_Handle_Record'Class) return Boolean;
-- Called before exiting
procedure Initialize
(Process : access Visual_Debugger_Record'Class;
Window : access GPS.Main_Window.GPS_Window_Record'Class);
-- Internal initialize procedure
procedure On_Console_Destroy
(Process : access GObject_Record'Class;
Kernel : Kernel_Handle);
-- Called when the debugger console is destroyed, which also terminates the
-- debugger itself
type String_Access_Access is access all GNAT.Strings.String_Access;
procedure Process_User_Command
(Debugger : not null access Visual_Debugger_Record'Class;
Command : String;
Output_Command : Boolean := False;
Mode : Command_Type;
Output : String_Access_Access);
-- Wrapper implementing common code for Process_User_Command routines
----------------
-- Get_Kernel --
----------------
function Get_Kernel
(Process : access Visual_Debugger_Record'Class)
return GPS.Kernel.Kernel_Handle is
begin
return Process.Kernel;
end Get_Kernel;
----------------------------
-- Set_Command_In_Process --
----------------------------
overriding procedure Set_Command_In_Process
(Proxy : access GPS_Proxy;
In_Process : Boolean := True) is
begin
Set_Command_In_Process (Process_Proxy (Proxy.all)'Access, In_Process);
Proxy.Process.Kernel.Refresh_Context;
if In_Process then
Debugger_State_Changed_Hook.Run
(Proxy.Process.Kernel, Proxy.Process, Debug_Busy);
else
Debugger_State_Changed_Hook.Run
(Proxy.Process.Kernel, Proxy.Process, Debug_Available);
end if;
Update_Menus_And_Buttons (Get_Kernel (Proxy.Process));
end Set_Command_In_Process;
-----------------------
-- Add_Regexp_Filter --
-----------------------
procedure Add_Regexp_Filter
(Process : access Visual_Debugger_Record'Class;
Filter : Regexp_Filter_Function;
Regexp : Pattern_Matcher) is
begin
Process.Filters :=
new Regexp_Filter_List_Elem'
(Filter => Filter,
Regexp => new Pattern_Matcher'(Regexp),
Next => Process.Filters);
end Add_Regexp_Filter;
-------------
-- Convert --
-------------
function Convert
(Kernel : access GPS.Kernel.Kernel_Handle_Record'Class;
Descriptor : GNAT.Expect.Process_Descriptor'Class)
return Visual_Debugger
is
procedure Callback
(Object : not null access Base_Visual_Debugger'Class);
Result : Visual_Debugger;
--------------
-- Callback --
--------------
procedure Callback
(Object : not null access Base_Visual_Debugger'Class)
is
Process : constant Visual_Debugger := Visual_Debugger (Object);
begin
if Process.Debugger /= null then
-- Note: The process might have been already killed when this
-- function is called.
if Get_Descriptor
(Get_Process (Process.Debugger)).all = Descriptor
then
Result := Process;
end if;
end if;
end Callback;
begin
For_Each_Debugger (Kernel, Callback'Access);
return Result;
exception
when Constraint_Error =>
return null;
end Convert;
-------------
-- Convert --
-------------
function Convert
(Debugger : access Debugger_Root'Class)
return Visual_Debugger is
begin
return Convert
(Get_Kernel (Debugger), Get_Descriptor (Get_Process (Debugger)).all);
end Convert;
------------------------
-- Command_In_Process --
------------------------
overriding function Command_In_Process
(Self : not null access Visual_Debugger_Record) return Boolean is
begin
return Self.Debugger /= null
and then Get_Process (Self.Debugger) /= null
and then Command_In_Process (Get_Process (Self.Debugger));
end Command_In_Process;
-----------------
-- Get_Command --
-----------------
function Get_Command
(Process : access Visual_Debugger_Record'Class) return String is
begin
if Process.Current_Command = null then
return "";
else
return Process.Current_Command.all;
end if;
end Get_Command;
---------------------------
-- Is_Execution_Command --
---------------------------
function Is_Execution_Command
(Process : access Visual_Debugger_Record'Class) return Boolean is
begin
if Process.Current_Command = null then
return False;
else
return Command_Kind
(Process.Debugger, Process.Current_Command.all) = Execution_Command;
end if;
end Is_Execution_Command;
-----------------
-- Output_Text --
-----------------
procedure Output_Text
(Process : not null access Visual_Debugger_Record'Class;
Str : String;
Is_Command : Boolean := False;
Set_Position : Boolean := False)
is
pragma Unreferenced (Set_Position);
Matched : GNAT.Regpat.Match_Array (0 .. 0);
Start : Positive := Str'First;
begin
if Process.Debugger_Text /= null then
if Is_Command then
Display_In_Debugger_Console
(Process, Str, Highlight => True, Add_To_History => True);
else
while Start <= Str'Last loop
Match (Highlighting_Pattern (Process.Debugger),
Str (Start .. Str'Last),
Matched);
if Matched (0) /= No_Match then
if Matched (0).First - 1 >= Start then
Display_In_Debugger_Console
(Process, Str (Start .. Matched (0).First - 1));
end if;
Display_In_Debugger_Console
(Process, Str (Matched (0).First .. Matched (0).Last),
Highlight => True);
Start := Matched (0).Last + 1;
else
Display_In_Debugger_Console
(Process, Str (Start .. Str'Last));
Start := Str'Last + 1;
end if;
end loop;
end if;
Highlight_Child
(Find_MDI_Child (Get_MDI (Process.Kernel), Process.Debugger_Text));
end if;
end Output_Text;
------------------------
-- Final_Post_Process --
------------------------
procedure Final_Post_Process
(Process : not null access Visual_Debugger_Record'Class;
Mode : GVD.Types.Command_Type;
Always_Emit_Hooks : Boolean;
Category : Command_Category;
Breakpoints_Might_Have_Changed : Boolean)
is
File : Unbounded_String;
Line : Natural := 0;
Addr : Address_Type;
begin
if Process.Post_Processing or else Process.Current_Output = null then
return;
end if;
Process.Post_Processing := True;
if Process.Debugger.Get_Process.Get_Parse_File_Name then
Process.Debugger.Found_File_Name
(Process.Current_Output
(Process.Current_Output'First .. Process.Current_Output_Pos - 1),
File, Line, Addr);
if Addr /= Invalid_Address then
Process.Pc := Addr;
end if;
end if;
-- Do we have a file name or line number indication?
-- This runs the Debugger_Location_Changed_Hook hook
if Length (File) /= 0 and then Line /= 0 then
Set_Current_File_And_Line
(Kernel => Process.Kernel,
Process => Process,
File => To_File (Process.Kernel, To_String (File)),
Line => Line);
end if;
Process.Post_Processing := False;
Free (Process.Current_Output);
-- Preserve the focus in the console for interactive execution
if Process.Is_From_Dbg_Console then
if Process.Debugger_Text /= null then
Set_Focus_Child
(Find_MDI_Child
(Get_MDI (Process.Kernel), Process.Debugger_Text));
end if;
Process.Is_From_Dbg_Console := False;
end if;
if Always_Emit_Hooks or else Mode /= Internal then
if Breakpoints_Might_Have_Changed
or else Process.Breakpoints.Has_Temporary_Breakpoint
then
Refresh_Breakpoints_List (Process.Kernel, Process);
end if;
case Category is
when Load_Command =>
Debugger_Executable_Changed_Hook.Run (Process.Kernel, Process);
when Context_Command =>
Debugger_Context_Changed_Hook.Run (Process.Kernel, Process);
when Execution_Command =>
Debugger_Process_Stopped_Hook.Run (Process.Kernel, Process);
when Misc_Command =>
null;
end case;
end if;
end Final_Post_Process;
------------------------------
-- First_Text_Output_Filter --
------------------------------
procedure First_Text_Output_Filter
(Descriptor : GNAT.Expect.Process_Descriptor'Class;
Str : String;
Window : System.Address) is
begin
-- Strip CRs in remote mode, as we can't know in advance if the debug
-- server outputs CR/LF or just LF, and the consequences or removing
-- CRs in the latter case are better than not removing them in the
-- first case
if Need_To_Strip_CR or else not Is_Local (Debug_Server) then
Text_Output_Filter (Descriptor, Strip_CR (Str), Window);
else
Text_Output_Filter (Descriptor, Str, Window);
end if;
end First_Text_Output_Filter;
------------------------
-- Text_Output_Filter --
------------------------
procedure Text_Output_Filter
(Descriptor : GNAT.Expect.Process_Descriptor'Class;
Str : String;
Window : System.Address)
is
Process : constant Visual_Debugger :=
Convert
(To_Main_Debug_Window (Window).Kernel, Descriptor);
Tmp_Str : GNAT.Strings.String_Access;
Current_Filter : Regexp_Filter_List;
Matched : Match_Array (0 .. Max_Paren_Count);
Last_Match : Natural := 0;
Offset : Natural := 0;
-- Offset from the start of the buffer to start the matching
New_Offset : Natural := 0;
Min_Size : Natural;
New_Size : Natural;
Str_Match : Boolean;
Result : Unbounded_String;
Mode : GVD.Types.Command_Type;
begin
-- Replace current output
if Process.Current_Output = null then
Process.Current_Output := new String (1 .. 1024);
Process.Current_Output_Pos := 1;
Process.Last_Match := 0;
end if;
Min_Size := Process.Current_Output_Pos + Str'Length;
if Process.Current_Output'Last < Min_Size then
New_Size := Process.Current_Output'Length * 2;
while New_Size < Min_Size loop
New_Size := New_Size * 2;
end loop;
Tmp_Str := new String (1 .. New_Size);
Tmp_Str (1 .. Process.Current_Output_Pos - 1) :=
Process.Current_Output (1 .. Process.Current_Output_Pos - 1);
Free (Process.Current_Output);
Process.Current_Output := Tmp_Str;
end if;
Process.Current_Output
(Process.Current_Output_Pos ..
Process.Current_Output_Pos + Str'Length - 1) := Str;
Process.Current_Output_Pos := Process.Current_Output_Pos + Str'Length;
-- Process the filters. Each filter is tested until there is no more
-- match at which point we move to the next one.
Current_Filter := Process.Filters;
Last_Match := Process.Last_Match;
while Current_Filter /= null loop
New_Offset := Offset;
Match
(Current_Filter.Regexp.all,
Process.Current_Output
(Process.Last_Match + 1 + Offset ..
Process.Current_Output_Pos - 1),
Matched);
Str_Match := False;
if Matched (0) = No_Match then
-- Try with just the input (Str)
Str_Match := True;
Match
(Current_Filter.Regexp.all,
Process.Current_Output
(Process.Current_Output_Pos - Str'Length + Offset ..
Process.Current_Output_Pos - 1),
Matched);
if Matched (0) /= No_Match then
-- Match found, record offset for next one. We cannot change
-- Offset here as we need it later when calling the filters.
New_Offset := Matched (0).Last + 1 -
(Process.Current_Output_Pos - Str'Length);
end if;
else
-- Match found (see comment above)
New_Offset := Matched (0).Last + 1 - (Process.Last_Match + 1);
end if;
if Matched (0) = No_Match then
-- No more match for this filter, move to next one
Current_Filter := Current_Filter.Next;
-- Reset New_Offset (and Offset in the next iteration) to the
-- start of the buffer.
New_Offset := 0;
else
if Matched (0).Last > Last_Match then
Last_Match := Matched (0).Last;
end if;
if Str_Match then
Current_Filter.Filter
(Process,
Process.Current_Output
(Process.Current_Output_Pos - Str'Length + Offset ..
Process.Current_Output_Pos - 1),
Matched);
else
Current_Filter.Filter
(Process,
Process.Current_Output
(Process.Last_Match + 1 + Offset ..
Process.Current_Output_Pos - 1),
Matched);
end if;
end if;
-- Now we can set the offset for next iteration
Offset := New_Offset;
end loop;
if Last_Match /= 0 then
Process.Last_Match := Last_Match;
end if;
-- Do not show the output if we have an internal or hidden command
Mode := Get_Command_Mode (Get_Process (Process.Debugger));
case Mode is
when User | GVD.Types.Visible =>
Filter_Output (Process.Debugger, Mode, Str, Result);
if Length (Result) > 0 then
Output_Text (Process, To_String (Result), Set_Position => True);
end if;
when Hidden | Internal =>
null;
end case;
end Text_Output_Filter;
----------------
-- Initialize --
----------------
procedure Initialize
(Process : access Visual_Debugger_Record'Class;
Window : access GPS.Main_Window.GPS_Window_Record'Class) is
begin
Initialize (Process);
Ref (Process);
Process.Kernel := Window.Kernel;
Set_Current_Debugger (Window.Kernel, Process);
Add_Debugger (Window.Kernel, Process);
end Initialize;
------------------------
-- On_Console_Destroy --
------------------------
procedure On_Console_Destroy
(Process : access GObject_Record'Class;
Kernel : Kernel_Handle)
is
pragma Unreferenced (Kernel);
Proc : constant Visual_Debugger := Visual_Debugger (Process);
begin
Proc.Debugger_Text := null;
Close_Debugger (Proc);
end On_Console_Destroy;
--------------------
-- Close_Debugger --
--------------------
procedure Close_Debugger (Process : access Visual_Debugger_Record) is
Kernel : constant Kernel_Handle := Process.Kernel;
Count : Natural;
begin
if Process.Exiting then
return;
end if;
GNATCOLL.Traces.Trace (Me, "Closing Debugger");
Process.Exiting := True;
Count := Count_Running_Debuggers (Kernel);
-- Load the default perspective before closing the debugger. This is
-- necessary because the position of views is memorized at this time:
-- if views are closed before the perspective change, their position
-- is lost.
if Count = 1 then
Load_Perspective (Kernel, "Default");
end if;
-- Let all views know that they should close
Debugger_State_Changed_Hook.Run (Process.Kernel, Process, Debug_None);
Debugger_Terminated_Hook.Run (Process.Kernel, Process);
Unhighlight_Current_Line (Process.Kernel);
Unregister_Dialog (Process);
Free (Process.Command_History);
-- Close the underlying debugger
if Process.Debugger /= null
and then Get_Process (Process.Debugger) /= null
then
Close (Process.Debugger);
end if;
Process.Debugger := null;
if Process.Timeout_Id /= 0 then
Glib.Main.Remove (Process.Timeout_Id);
Process.Timeout_Id := 0;
end if;
Remove_Debugger (Kernel, Process);
Unref (Process);
if Count = 1 then
Debug_Terminate (Kernel);
end if;
end Close_Debugger;
--------------------------
-- Process_User_Command --
--------------------------
procedure Process_User_Command
(Debugger : not null access Visual_Debugger_Record'Class;
Command : String;
Output_Command : Boolean := False;
Mode : Command_Type;
Output : String_Access_Access)
is
Lowered_Command : constant String := To_Lower (Command);
Busy : Boolean;
begin
if Output /= null then
Output.all := null;
end if;
if Debugger.Debugger = null then
return;
end if;
Busy := Debugger.Debugger.Get_Process.Command_In_Process;
if Output /= null and then Busy then
GNATCOLL.Traces.Trace
(Me, "Process_User_Command: Debugger is already busy");
return;
end if;
if Output_Command then
Debugger.Output_Text (Command & ASCII.LF, Is_Command => True);
end if;
-- Command has been converted to lower-cases, but the new version
-- should be used only to compare with our standard list of commands.
-- We should pass the original string to the debugger, in case we are
-- in a case-sensitive language.
if Is_Quit_Command (Debugger.Debugger, Lowered_Command) then
if Busy
and then not Separate_Execution_Window (Debugger.Debugger)
then
-- If the debugger does not have a separate execution window,
-- send the command right away.
Debugger.Debugger.Send
(Command, Wait_For_Prompt => False, Mode => Mode);
else
Close_Debugger (Debugger);
end if;
return;
end if;
-- Regular debugger command, send it.
-- If a dialog is currently displayed, do not wait for the debugger
-- prompt, since the prompt won't be displayed before the user
-- answers the question...
if Output = null
and then (Debugger.Debugger.Continuation_Line
or else Debugger.Registered_Dialog /= null)
then
-- For interactive command, we always send them immediately to
-- the debugger, since this might be an answer to a gdb question
-- ("restart process (y/n) ?")
Debugger.Debugger.Send
(Command,
Wait_For_Prompt => False,
Mode => Mode,
Force_Send => Debugger.Is_From_Dbg_Console);
elsif Output = null then
-- Force_Send is always false so that commands are queued. We
-- are not in a secondary prompt anyway (which should be when
-- we have a Registered_Dialog).
Debugger.Debugger.Send (Command, Mode => Mode, Force_Send => False);
else
Output.all := new String'
(Debugger.Debugger.Send_And_Get_Clean_Output
(Command, Mode => Mode));
if Output_Command
and then Debugger.Debugger /= null
then
Debugger.Debugger.Display_Prompt;
end if;
end if;
end Process_User_Command;
--------------------------
-- Process_User_Command --
--------------------------
procedure Process_User_Command
(Debugger : not null access Visual_Debugger_Record'Class;
Command : String;
Output_Command : Boolean := False;
Mode : Command_Type := GVD.Types.Visible) is
begin
Process_User_Command (Debugger, Command, Output_Command, Mode, null);
end Process_User_Command;
--------------------------
-- Process_User_Command --
--------------------------
function Process_User_Command
(Debugger : not null access Visual_Debugger_Record'Class;
Command : String;
Output_Command : Boolean := False;
Mode : GVD.Types.Invisible_Command := GVD.Types.Hidden)
return String
is
Result : aliased GNAT.Strings.String_Access;
begin
Process_User_Command
(Debugger, Command, Output_Command, Mode, Result'Unchecked_Access);
if Result = null then
return "";
else
declare
S : constant String := Result.all;
begin
GNAT.Strings.Free (Result);
return S;
end;
end if;
end Process_User_Command;
---------------------
-- Register_Dialog --
---------------------
procedure Register_Dialog
(Process : access Visual_Debugger_Record;
Dialog : access GPS_Dialog_Record'Class) is
begin
if Process.Registered_Dialog /= null then
-- Typically happens when the filter used to create a dialog
-- is called several times for the same dialog.
Destroy (Process.Registered_Dialog);
end if;
Process.Registered_Dialog := Dialog;
end Register_Dialog;
-----------------------
-- Unregister_Dialog --
-----------------------
procedure Unregister_Dialog
(Process : access Visual_Debugger_Record) is
begin
if Process.Registered_Dialog /= null then
Destroy (Process.Registered_Dialog);
Process.Registered_Dialog := null;
end if;
end Unregister_Dialog;
-------------
-- Get_Num --
-------------
overriding function Get_Num
(Self : not null access Visual_Debugger_Record) return Gint is
begin
return Gint (Self.Debugger_Num);
end Get_Num;
-----------------
-- Get_Console --
-----------------
function Get_Console
(Process : access Visual_Debugger_Record'Class)
return Gtk.Widget.Gtk_Widget is
begin
return Gtk_Widget (Process.Debugger_Text);
end Get_Console;
-------------
-- Execute --
-------------
overriding function Execute
(Self : On_Before_Exit;
Kernel : not null access Kernel_Handle_Record'Class) return Boolean is
begin
if Save_Desktop_On_Exit.Get_Pref then
Save_Desktop (Kernel, "Default");
end if;
-- Close the debugger immediately when receiving the "before exit"
-- action hook. This is needed so that the perspective can be saved
-- and the default perspective can be reset before the main window
-- is actually destroyed.
Close_Debugger (Self.Process);
return True;
end Execute;
-----------
-- Spawn --
-----------
function Spawn
(Kernel : access GPS.Kernel.Kernel_Handle_Record'Class;
Kind : GVD.Types.Debugger_Type;
File : GNATCOLL.VFS.Virtual_File;
Project : Project_Type;
Args : String;
Remote_Target : String := "";
Remote_Protocol : String := "";
Load_Executable : Boolean := False) return Visual_Debugger
is
Top : constant GPS_Window :=
GPS_Window (Get_Main_Window (Kernel));
Process : Visual_Debugger;
Program_Args : GNAT.Strings.String_Access;
Blank_Pos : Natural;
Proxy : Process_Proxy_Access;
Exit_H : access On_Before_Exit;
function Get_Main return Virtual_File;
-- Return the file to debug
--------------
-- Get_Main --
--------------
function Get_Main return Virtual_File is
type Extension_Array is array (Positive range <>) of
Filesystem_String (1 .. 4);
Extensions : constant Extension_Array := (".exe", ".out", ".vxe");
Tmp : Virtual_File;
End_Of_Exec : Natural;
Exec : Virtual_File;
begin
if File /= GNATCOLL.VFS.No_File then
Exec := File;
elsif Args /= "" then
Blank_Pos := Ada.Strings.Fixed.Index (Args, " ");
if Blank_Pos = 0 then
End_Of_Exec := Args'Last;
else
End_Of_Exec := Blank_Pos - 1;
Free (Program_Args);
Program_Args := new String'(Args (Blank_Pos + 1 .. Args'Last));
end if;
-- The code below assumes that the name of the executable is in
-- Args (Args'First .. End_Of_Exec).
declare
Exec_Name : constant Filesystem_String :=
+Args (Args'First .. End_Of_Exec);
begin
-- First check whether Exec_Name is an absolute path
Exec := Create (Full_Filename => Exec_Name);
if not Exec.Is_Absolute_Path then
-- If the Exec name is not an absolute path, check
-- whether it corresponds to a file found from the
-- current directory.
Exec := Create
(Full_Filename =>
Normalize_Pathname (Exec_Name, Get_Current_Dir));
if not Exec.Is_Regular_File then
-- If the Exec is not an absolute path and it is not
-- found from the current directory, try to locate it
-- on path.
Exec := Locate_Compiler_Executable (Exec_Name);
if Exec = No_File then
Exec := Create_From_Base (Exec_Name);
end if;
end if;
end if;
end;
end if;
-- Check for a missing extension in module, and add it if needed
-- Extensions currently checked in order: .exe, .out, .vxe
if Exec = GNATCOLL.VFS.No_File or else Exec.Is_Regular_File then
return Exec;
else
for J in Extensions'Range loop
Tmp := Create
(Full_Filename => Exec.Full_Name.all & Extensions (J));
if Tmp.Is_Regular_File then
Exec := Tmp;
exit;
end if;
end loop;
end if;
return Exec;
end Get_Main;
Target : constant String := Kernel.Get_Target;
Default_Gdb : constant String :=
(if Target = "" then "gdb" else Target & "-gdb");
Args2 : GNAT.OS_Lib.Argument_List_Access :=
GNAT.OS_Lib.Argument_String_To_List
(Project.Attribute_Value
(Debugger_Command_Attribute,
Default => Default_Gdb));
Actual_Remote_Target : constant String :=
(if Remote_Target /= ""
then Remote_Target
else Project.Attribute_Value (Program_Host_Attribute));
Actual_Remote_Protocol : constant String :=
(if Remote_Protocol /= ""
then Remote_Protocol
else Project.Attribute_Value (Protocol_Attribute));
Executable : GNATCOLL.VFS.Virtual_File;
begin
Process := new Visual_Debugger_Record;
GVD.Process.Initialize (Process, Top);
Program_Args := new String'("");
Executable := Get_Main;
Proxy := new GPS_Proxy;
GPS_Proxy (Proxy.all).Process := Process;
Process.Descriptor.Debugger := Kind;
Process.Descriptor.Program := Executable;
Process.Descriptor.Debugger_Name := new String'(Args2 (1).all);
case Kind is
when GVD.Types.Gdb =>
Process.Debugger := new Gdb_Debugger;
when GVD.Types.Gdb_MI =>
Process.Debugger := new Gdb_MI_Debugger;
end case;
-- Spawn the debugger
Process.Debugger.Spawn
(Kernel => Kernel,
Executable => Executable,
Debugger_Args => Args2 (2 .. Args2'Last),
Executable_Args => Program_Args.all,
Proxy => Proxy,
Remote_Target => Actual_Remote_Target,
Remote_Protocol => Actual_Remote_Protocol,
Debugger_Name => Process.Descriptor.Debugger_Name.all);
GNAT.OS_Lib.Free (Args2);
-- Switch to the "Debug" perspective if available
Load_Perspective (Kernel, "Debug");
-- Destroying the console should kill the debugger
-- ??? Signal should be handled in GVD.Console directly
Attach_To_Debugger_Console
(Process, Process.Kernel, Create_If_Necessary => True);
if Process.Debugger_Text /= null then
Kernel_Callback.Object_Connect
(Process.Debugger_Text, Signal_Destroy,
On_Console_Destroy'Access,
After => True,
User_Data => null,
Slot_Object => Process);
end if;
-- Set the output filter, so that we output everything in the Gtk_Text
-- window.
Add_Filter
(Get_Descriptor (Get_Process (Process.Debugger)).all,
First_Text_Output_Filter'Access, Output, Top.all'Address);
-- Initialize the debugger, and possibly get the name of the initial
-- file.
Initialize (Process.Debugger);
-- If we have a debuggee console in the desktop, always use it.
-- Otherwise, we only create one when the user has asked for it.
Attach_To_Debuggee_Console
(Process,
Process.Kernel,
Create_If_Necessary =>
Execution_Window.Get_Pref
and then Is_Local (Debug_Server)
and then Support_TTY (Process.Debugger)
and then GNAT.TTY.TTY_Supported);
Raise_Child (Find_MDI_Child (Get_MDI (Kernel), Process.Debugger_Text));
-- When True, Load the executable on the target, if any
if Load_Executable then
Process.Debugger.Load_Executable
(Executable => Executable.To_Remote (Get_Nickname (Debug_Server)),
Mode => Visible);
end if;
-- Force the creation of the project if needed
Load_Project_From_Executable (Kernel, Process);
Exit_H := new On_Before_Exit;
Exit_H.Process := Process;
Before_Exit_Action_Hook.Add (Exit_H, Watch => Process);
Debugger_State_Changed_Hook.Run
(Process.Kernel, Process, Debug_Available);
Debugger_Started_Hook.Run (Process.Kernel, Process);
return Process;
exception
when Process_Died =>
GNATCOLL.Traces.Trace (Me, "could not launch the debugger");
declare
Dummy : constant Message_Dialog_Buttons :=
Message_Dialog
(Expect_Out (Get_Process (Process.Debugger)) & ASCII.LF &
(-"Could not launch the debugger"),
Error, Button_OK, Button_OK,
Parent => Gtk_Window (Top));
begin
Process.Exiting := True;
Close_Debugger (Process);
Process.Exiting := False;
return null;
end;
when Spawn_Error =>
-- Do not display a dialog here since the Spawn procedure displays
-- a dialog before raising Spawn_Error.
-- This will close the debugger and switch back to the default
-- perspective. However, some windows haven't had a size allocation
-- yet, so this might corrupt the desktop.
Close_Debugger (Process);
return null;
when E : others =>
GNATCOLL.Traces.Trace (Me, E);
return Process;
end Spawn;
----------------------------------
-- Load_Project_From_Executable --
----------------------------------
procedure Load_Project_From_Executable
(Kernel : access Kernel_Handle_Record'Class;
Debugger : access Visual_Debugger_Record'Class)
is
Project : Project_Type := Get_Project (Kernel);
Exec : Virtual_File;
begin
-- Do nothing unless the current project was already generated from an
-- executable.
if Get_Registry (Kernel).Tree.Status /= From_Executable then
return;
end if;
Exec := Get_Executable (Debugger.Debugger);
if Exec /= No_File and then not Is_Regular_File (Exec) then
declare
Buttons : Message_Dialog_Buttons;
pragma Unreferenced (Buttons);
begin
if Active (Testsuite_Handle) then
GNATCOLL.Traces.Trace
(Testsuite_Handle, "executable passed to --debug not found");
else
Buttons := Message_Dialog
(Msg =>
-("The executable specified with" &
" --debug does not exist on disk"),
Dialog_Type => Error,
Buttons => Button_OK,
Title => -"Executable not found",
Parent => Get_Main_Window (Kernel));
end if;
end;
end if;
declare
List : String_List_Access := Project.Attribute_Value (Main_Attribute);
begin
if List /= null then
for L in List'Range loop
if Equal (+List (L).all, Full_Name (Exec)) then
Free (List);
return;
end if;
end loop;
Free (List);
end if;
end;
-- No handling of desktop is done here, we want to leave all windows
-- as-is.
declare
Debugger_Name : constant String :=
Project.Attribute_Value
(Debugger_Command_Attribute, Default => "");
Target : constant String :=
Project.Attribute_Value
(Program_Host_Attribute, Default => "");
Protocol : constant String :=
Project.Attribute_Value
(Protocol_Attribute, Default => "");
begin
Get_Registry (Kernel).Tree.Unload;
-- Create an empty project, and we'll add properties to it
if Exec /= GNATCOLL.VFS.No_File then
Get_Registry (Kernel).Tree.Load_Empty_Project
(Get_Registry (Kernel).Environment,
Name => "debugger_" & (+Base_Name (Exec)),
Recompute_View => False);
else
Get_Registry (Kernel).Tree.Load_Empty_Project
(Get_Registry (Kernel).Environment,
Name => "debugger_no_file",
Recompute_View => False);
end if;
Project := Get_Registry (Kernel).Tree.Root_Project;
if Debugger_Name /= "" then
Project.Set_Attribute
(Attribute => Debugger_Command_Attribute,
Value => Debugger_Name);
end if;
if Target /= "" then
Project.Set_Attribute
(Attribute => Program_Host_Attribute,
Value => Target);
end if;
if Protocol /= "" then
Project.Set_Attribute
(Attribute => Protocol_Attribute,
Value => Protocol);
end if;
end;
declare
List : GNAT.Strings.String_List :=
Source_Files_List (Debugger.Debugger);
Bases : GNAT.OS_Lib.Argument_List (List'Range);
Bases_Index : Natural := Bases'First;
Dirs : GNAT.OS_Lib.Argument_List (List'Range);
Dirs_Index : Natural := Dirs'First;
Main : GNAT.OS_Lib.Argument_List (1 .. 1);
Langs : GNAT.OS_Lib.Argument_List (List'Range);
Lang_Index : Natural := Langs'First;
begin
-- Source_Files, Source_Dirs & Languages
for L in List'Range loop
declare
Remote_File : constant Virtual_File :=
Create_From_Base
(+List (L).all,
Dir_Name (Exec),
Get_Nickname (Debug_Server));
Local_File : constant Virtual_File := To_Local (Remote_File);
Dir : constant Virtual_File := Local_File.Dir;
Base : constant Filesystem_String :=
Base_Name (Local_File);
Lang : constant String :=
Get_Language_From_File
(Get_Language_Handler (Kernel),
Local_File);
Found : Boolean;
begin
Found := False;
if Is_Directory (Dir) then
for D in Dirs'First .. Dirs_Index - 1 loop
if Equal (+Dirs (D).all, Dir.Full_Name) then
Found := True;
exit;
end if;
end loop;
if not Found then
Dirs (Dirs_Index) := new String'(+Dir.Full_Name);
Dirs_Index := Dirs_Index + 1;
end if;
Found := False;
for J in Bases'First .. Bases_Index - 1 loop
if Equal (+Bases (J).all, Base) then
Found := True;
exit;
end if;
end loop;
if not Found then
Bases (Bases_Index) :=
new String'(Base_Name (List (L).all));
Bases_Index := Bases_Index + 1;
end if;
Found := False;
if Lang /= "" then
for La in Langs'First .. Lang_Index - 1 loop
if Langs (La).all = Lang then
Found := True;
exit;
end if;
end loop;
if not Found then
Langs (Lang_Index) := new String'(Lang);
Lang_Index := Lang_Index + 1;
end if;
end if;
end if;
end;
end loop;
GNATCOLL.Traces.Trace (Me, "Setting Source_Dirs:");
for D in Dirs'First .. Dirs_Index - 1 loop
GNATCOLL.Traces.Trace (Me, " " & Dirs (D).all);
end loop;
Project.Set_Attribute
(Attribute => Source_Dirs_Attribute,
Values => Dirs (Dirs'First .. Dirs_Index - 1));
Free (Dirs);
GNATCOLL.Traces.Trace (Me, "Setting Source_Files:");
for B in Bases'First .. Bases_Index - 1 loop
GNATCOLL.Traces.Trace (Me, " " & Bases (B).all);
end loop;
Project.Set_Attribute
(Attribute => Source_Files_Attribute,
Values => Bases (Bases'First .. Bases_Index - 1));
Free (Bases);
GNATCOLL.Traces.Trace (Me, "Setting Languages:");
for L in Langs'First .. Lang_Index - 1 loop
GNATCOLL.Traces.Trace (Me, " " & Langs (L).all);
end loop;
if Lang_Index = Langs'First then
Project.Set_Attribute
(Scenario => All_Scenarios,
Attribute => Languages_Attribute,
Values =>
(new String'("ada"), new String'("c"), new String'("c++")));
else
Project.Set_Attribute
(Attribute => Languages_Attribute,
Values => Langs (Langs'First .. Lang_Index - 1));
end if;
Free (Langs);
-- Object_Dir, Exec_Dir, Main
if Exec /= GNATCOLL.VFS.No_File then
Project.Set_Attribute
(Attribute => Obj_Dir_Attribute,
Value => +Dir_Name (Exec));
Project.Set_Attribute
(Attribute => Exec_Dir_Attribute,
Value => +Dir_Name (Exec));
Main (Main'First) := new String'(+Full_Name (Exec));
Project.Set_Attribute
(Attribute => Main_Attribute,
Values => Main);
Free (Main);
end if;
Free (List);
end;
-- Is the information for this executable already cached? If yes,
-- we simply reuse it to avoid the need to interact with the debugger.
Project.Set_Modified (False);
Get_Registry (Kernel).Tree.Set_Status (From_Executable);
Project_Changed_Hook.Run (Kernel);
Recompute_View (Kernel);
end Load_Project_From_Executable;
-----------------
-- Dbg_Command --
-----------------
package body Dbg_Command is
overriding function Execute
(Command : access Debugger_Command;
Context : Interactive_Command_Context) return Command_Return_Type
is
Kernel : constant Kernel_Handle := Get_Kernel (Context.Context);
Process : Visual_Debugger;
begin
Process := Visual_Debugger (Get_Current_Debugger (Kernel));
if Process = null or else Process.Debugger = null then
return Commands.Failure;
end if;
if Debugger_Console_Has_Focus (Process) then
Process.Is_From_Dbg_Console := True;
end if;
return Debugger_Command_Access (Command).Execute_Dbg (Process);
end Execute;
end Dbg_Command;
end GVD.Process;
|
stcarrez/ada-util | Ada | 851 | adb | with Ada.Text_IO;
with Util.Serialize.IO.XML;
with Util.Streams.Texts;
procedure Serialize_Xml is
procedure Write (Stream : in out Util.Serialize.IO.Output_Stream'Class);
procedure Write (Stream : in out Util.Serialize.IO.Output_Stream'Class) is
begin
Stream.Start_Document;
Stream.Start_Entity ("person");
Stream.Write_Entity ("name", "Harry Potter");
Stream.Write_Entity ("gender", "male");
Stream.Write_Entity ("age", 17);
Stream.End_Entity ("person");
Stream.End_Document;
end Write;
Output : aliased Util.Streams.Texts.Print_Stream;
Stream : Util.Serialize.IO.XML.Output_Stream;
begin
Output.Initialize (Size => 10000);
Stream.Initialize (Output => Output'Unchecked_Access);
Write (Stream);
Ada.Text_IO.Put_Line (Util.Streams.Texts.To_String (Output));
end Serialize_Xml;
|
likai3g/afmt | Ada | 156 | ads | with Ada.Containers;
with Fmt.Generic_Signed_Int_Argument;
package Fmt.Count_Argument is
new Fmt.Generic_Signed_Int_Argument(Ada.Containers.Count_Type);
|
zhmu/ananas | Ada | 2,394 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . W I D E _ T E X T _ I O . F I X E D _ I O --
-- --
-- S p e c --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. In accordance with the copyright of that document, you can freely --
-- copy and modify this specification, provided that if you redistribute a --
-- modified version, any changes that you have made are clearly indicated. --
-- --
------------------------------------------------------------------------------
-- In Ada 95, the package Ada.Wide_Text_IO.Fixed_IO is a subpackage of
-- Wide_Text_IO. In GNAT we make it a child package to avoid loading
-- the necessary code if Fixed_IO is not instantiated. See the routine
-- Rtsfind.Check_Text_IO_Special_Unit for a description of how we patch up
-- the difference in semantics so that it is invisible to the Ada programmer.
private generic
type Num is delta <>;
package Ada.Wide_Text_IO.Fixed_IO is
Default_Fore : Field := Num'Fore;
Default_Aft : Field := Num'Aft;
Default_Exp : Field := 0;
procedure Get
(File : File_Type;
Item : out Num;
Width : Field := 0);
procedure Get
(Item : out Num;
Width : Field := 0);
procedure Put
(File : File_Type;
Item : Num;
Fore : Field := Default_Fore;
Aft : Field := Default_Aft;
Exp : Field := Default_Exp);
procedure Put
(Item : Num;
Fore : Field := Default_Fore;
Aft : Field := Default_Aft;
Exp : Field := Default_Exp);
procedure Get
(From : Wide_String;
Item : out Num;
Last : out Positive);
procedure Put
(To : out Wide_String;
Item : Num;
Aft : Field := Default_Aft;
Exp : Field := Default_Exp);
end Ada.Wide_Text_IO.Fixed_IO;
|
kishanbhashyam/Amass | Ada | 2,662 | ads | -- Copyright 2017-2021 Jeff Foley. All rights reserved.
-- Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
name = "Brute Forcing"
type = "brute"
probes = {"www", "online", "webserver", "ns", "ns1", "mail", "smtp", "webmail", "shop", "dev",
"prod", "test", "vpn", "ftp", "ssh", "secure", "whm", "admin", "webdisk", "mobile",
"remote", "server", "cpanel", "cloud", "autodiscover", "api", "m", "blog"}
function start()
set_rate_limit(1)
end
function vertical(ctx, domain)
local cfg = config(ctx)
if cfg.mode == "passive" then
return
end
if cfg['brute_forcing'].active then
make_names(ctx, domain)
end
end
function resolved(ctx, name, domain, records)
local nparts = split(name, ".")
local dparts = split(domain, ".")
-- Do not process resolved root domain names
if #nparts == #dparts then
return
end
-- Do not generate names from CNAMEs or names without A/AAAA records
if (#records == 0 or (has_cname(records) or not has_addr(records))) then
return
end
local cfg = config(ctx)
if cfg.mode == "passive" then
return
end
local bf = cfg['brute_forcing']
if (bf.active and bf.recursive and (bf['min_for_recursive'] == 0)) then
make_names(ctx, name)
end
end
function subdomain(ctx, name, domain, times)
local cfg = config(ctx)
if cfg.mode == "passive" then
return
end
local bf = cfg['brute_forcing']
if (bf.active and bf.recursive and (bf['min_for_recursive'] == times)) then
make_names(ctx, name)
end
end
function make_names(ctx, base)
local wordlist = brute_wordlist(ctx)
for i, word in pairs(wordlist) do
new_name(ctx, word .. "." .. base)
if i % 1000 == 0 then
check_rate_limit()
end
end
end
function has_cname(records)
if #records == 0 then
return false
end
for _, rec in pairs(records) do
if rec.rrtype == 5 then
return true
end
end
return false
end
function has_addr(records)
if #records == 0 then
return false
end
for _, rec in pairs(records) do
if (rec.rrtype == 1 or rec.rrtype == 28) then
return true
end
end
return false
end
function split(str, delim)
local result = {}
local pattern = "[^%" .. delim .. "]+"
local matches = find(str, pattern)
if (matches == nil or #matches == 0) then
return result
end
for _, match in pairs(matches) do
table.insert(result, match)
end
return result
end
|
reznikmm/matreshka | Ada | 6,720 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Anim.Set_Elements is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Anim_Set_Element_Node is
begin
return Self : Anim_Set_Element_Node do
Matreshka.ODF_Anim.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Anim_Prefix);
end return;
end Create;
----------------
-- Enter_Node --
----------------
overriding procedure Enter_Node
(Self : not null access Anim_Set_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Enter_Anim_Set
(ODF.DOM.Anim_Set_Elements.ODF_Anim_Set_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Enter_Node (Visitor, Control);
end if;
end Enter_Node;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Anim_Set_Element_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Set_Element;
end Get_Local_Name;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Anim_Set_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Leave_Anim_Set
(ODF.DOM.Anim_Set_Elements.ODF_Anim_Set_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Leave_Node (Visitor, Control);
end if;
end Leave_Node;
----------------
-- Visit_Node --
----------------
overriding procedure Visit_Node
(Self : not null access Anim_Set_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then
ODF.DOM.Iterators.Abstract_ODF_Iterator'Class
(Iterator).Visit_Anim_Set
(Visitor,
ODF.DOM.Anim_Set_Elements.ODF_Anim_Set_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Visit_Node (Iterator, Visitor, Control);
end if;
end Visit_Node;
begin
Matreshka.DOM_Documents.Register_Element
(Matreshka.ODF_String_Constants.Anim_URI,
Matreshka.ODF_String_Constants.Set_Element,
Anim_Set_Element_Node'Tag);
end Matreshka.ODF_Anim.Set_Elements;
|
zhmu/ananas | Ada | 1,194 | adb | -- PR ada/48844
-- Reported by Georg Bauhaus <[email protected]> */
-- { dg-do compile }
procedure Discr30 is
generic
type Source is private;
type Target is private;
function Conversion (S : Source) return Target;
function Conversion (S : Source) return Target is
type Source_Wrapper is tagged record
S : Source;
end record;
type Target_Wrapper is tagged record
T : Target;
end record;
type Selector is (Source_Field, Target_Field);
type Magic (Sel : Selector := Target_Field) is record
case Sel is
when Source_Field => S : Source_Wrapper;
when Target_Field => T : Target_Wrapper;
end case;
end record;
M : Magic;
function Convert (T : Target_Wrapper) return Target is
begin
M := (Sel => Source_Field, S => (S => S));
return T.T;
end Convert;
begin
return Convert (M.T);
end Conversion;
type Integer_Access is access all Integer;
I : aliased Integer;
I_Access : Integer_Access := I'Access;
function Convert is new Conversion (Integer_Access, Integer);
begin
I := Convert (I_Access);
end;
|
zhmu/ananas | Ada | 7,401 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T . B Y T E _ O R D E R _ M A R K --
-- --
-- B o d y --
-- --
-- Copyright (C) 2006-2022, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package body GNAT.Byte_Order_Mark is
--------------
-- Read_BOM --
--------------
procedure Read_BOM
(Str : String;
Len : out Natural;
BOM : out BOM_Kind;
XML_Support : Boolean := False)
is
begin
-- Note: the order of these tests is important, because in some cases
-- one sequence is a prefix of a longer sequence, and we must test for
-- the longer sequence first
-- UTF-32 (big-endian)
if Str'Length >= 4
and then Str (Str'First) = Character'Val (16#00#)
and then Str (Str'First + 1) = Character'Val (16#00#)
and then Str (Str'First + 2) = Character'Val (16#FE#)
and then Str (Str'First + 3) = Character'Val (16#FF#)
then
Len := 4;
BOM := UTF32_BE;
-- UTF-32 (little-endian)
elsif Str'Length >= 4
and then Str (Str'First) = Character'Val (16#FF#)
and then Str (Str'First + 1) = Character'Val (16#FE#)
and then Str (Str'First + 2) = Character'Val (16#00#)
and then Str (Str'First + 3) = Character'Val (16#00#)
then
Len := 4;
BOM := UTF32_LE;
-- UTF-16 (big-endian)
elsif Str'Length >= 2
and then Str (Str'First) = Character'Val (16#FE#)
and then Str (Str'First + 1) = Character'Val (16#FF#)
then
Len := 2;
BOM := UTF16_BE;
-- UTF-16 (little-endian)
elsif Str'Length >= 2
and then Str (Str'First) = Character'Val (16#FF#)
and then Str (Str'First + 1) = Character'Val (16#FE#)
then
Len := 2;
BOM := UTF16_LE;
-- UTF-8 (endian-independent)
elsif Str'Length >= 3
and then Str (Str'First) = Character'Val (16#EF#)
and then Str (Str'First + 1) = Character'Val (16#BB#)
and then Str (Str'First + 2) = Character'Val (16#BF#)
then
Len := 3;
BOM := UTF8_All;
-- UCS-4 (big-endian) XML only
elsif XML_Support
and then Str'Length >= 4
and then Str (Str'First) = Character'Val (16#00#)
and then Str (Str'First + 1) = Character'Val (16#00#)
and then Str (Str'First + 2) = Character'Val (16#00#)
and then Str (Str'First + 3) = Character'Val (16#3C#)
then
Len := 0;
BOM := UCS4_BE;
-- UCS-4 (little-endian) XML case
elsif XML_Support
and then Str'Length >= 4
and then Str (Str'First) = Character'Val (16#3C#)
and then Str (Str'First + 1) = Character'Val (16#00#)
and then Str (Str'First + 2) = Character'Val (16#00#)
and then Str (Str'First + 3) = Character'Val (16#00#)
then
Len := 0;
BOM := UCS4_LE;
-- UCS-4 (unusual byte order 2143) XML case
elsif XML_Support
and then Str'Length >= 4
and then Str (Str'First) = Character'Val (16#00#)
and then Str (Str'First + 1) = Character'Val (16#00#)
and then Str (Str'First + 2) = Character'Val (16#3C#)
and then Str (Str'First + 3) = Character'Val (16#00#)
then
Len := 0;
BOM := UCS4_2143;
-- UCS-4 (unusual byte order 3412) XML case
elsif XML_Support
and then Str'Length >= 4
and then Str (Str'First) = Character'Val (16#00#)
and then Str (Str'First + 1) = Character'Val (16#3C#)
and then Str (Str'First + 2) = Character'Val (16#00#)
and then Str (Str'First + 3) = Character'Val (16#00#)
then
Len := 0;
BOM := UCS4_3412;
-- UTF-16 (big-endian) XML case
elsif XML_Support
and then Str'Length >= 4
and then Str (Str'First) = Character'Val (16#00#)
and then Str (Str'First + 1) = Character'Val (16#3C#)
and then Str (Str'First + 2) = Character'Val (16#00#)
and then Str (Str'First + 3) = Character'Val (16#3F#)
then
Len := 0;
BOM := UTF16_BE;
-- UTF-32 (little-endian) XML case
elsif XML_Support
and then Str'Length >= 4
and then Str (Str'First) = Character'Val (16#3C#)
and then Str (Str'First + 1) = Character'Val (16#00#)
and then Str (Str'First + 2) = Character'Val (16#3F#)
and then Str (Str'First + 3) = Character'Val (16#00#)
then
Len := 0;
BOM := UTF16_LE;
-- Unrecognized special encodings XML only
elsif XML_Support
and then Str'Length >= 4
and then Str (Str'First) = Character'Val (16#3C#)
and then Str (Str'First + 1) = Character'Val (16#3F#)
and then Str (Str'First + 2) = Character'Val (16#78#)
and then Str (Str'First + 3) = Character'Val (16#6D#)
then
-- UTF-8, ASCII, some part of ISO8859, Shift-JIS, EUC,...
Len := 0;
BOM := Unknown;
-- No BOM recognized
else
Len := 0;
BOM := Unknown;
end if;
end Read_BOM;
end GNAT.Byte_Order_Mark;
|
tum-ei-rcs/StratoX | Ada | 2,365 | ads | ------------------------------------------------------------------------------
-- --
-- SPARK LIBRARY COMPONENTS --
-- --
-- S P A R K . F L O A T _ A R I T H M E T I C _ L E M M A S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2017, AdaCore --
-- --
-- SPARK 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. SPARK is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
------------------------------------------------------------------------------
pragma SPARK_Mode;
with SPARK.Floating_Point_Arithmetic_Lemmas;
pragma Elaborate_All (SPARK.Floating_Point_Arithmetic_Lemmas);
package SPARK.Float_Arithmetic_Lemmas is new
SPARK.Floating_Point_Arithmetic_Lemmas (Float, 2.0**63);
|
reznikmm/matreshka | Ada | 6,070 | adb | with GNAT.CRC32;
with Matreshka.Filters.Deflate.Pack;
package body Zip.Archives is
------------
-- Append --
------------
not overriding procedure Append
(Self : in out Output;
Path : League.Strings.Universal_String;
Data : League.Stream_Element_Vectors.Stream_Element_Vector;
Modified : League.Calendars.Date_Time;
Method : Zip.Compression_Method := Zip.Deflate)
is
function Get_CRC32 return GNAT.CRC32.CRC32;
function Complress
return League.Stream_Element_Vectors.Stream_Element_Vector;
---------------
-- Complress --
---------------
function Complress
return League.Stream_Element_Vectors.Stream_Element_Vector
is
Result : League.Stream_Element_Vectors.Stream_Element_Vector;
Filter : Matreshka.Filters.Deflate.Pack.Filter;
begin
Filter.Read (Data, Result);
Filter.Flush (Result);
return Result;
end Complress;
---------------
-- Get_CRC32 --
---------------
function Get_CRC32 return GNAT.CRC32.CRC32 is
Result : GNAT.CRC32.CRC32;
begin
GNAT.CRC32.Initialize (Result);
GNAT.CRC32.Update (Result, Data.To_Stream_Element_Array);
return GNAT.CRC32.CRC32 (GNAT.CRC32.Get_Value (Result));
end Get_CRC32;
New_Entry : Zip.Metadata.File_Record :=
(File_Name => Path,
Method => Method,
Last_Modified => Modified,
CRC32 => Get_CRC32,
Compressed_Size => 0,
Uncompressed_Size => Data.Length,
Has_Data_Descriptor => False,
Local_Header_Offset => Self.Stream.Offset);
Value : League.Stream_Element_Vectors.Stream_Element_Vector;
begin
if Method = Zip.Deflate and not Data.Is_Empty then
Value := Complress;
else
Value := Data;
end if;
New_Entry.Compressed_Size := Value.Length;
Self.Directory.Files.Append (New_Entry);
Zip.Metadata.Write_Local_File_Header (Self.Stream'Access, New_Entry);
Self.Stream.Write (Value.To_Stream_Element_Array);
end Append;
-----------
-- Close --
-----------
not overriding procedure Close (Self : in out Input) is
begin
Zip.IO.Close (Self.File);
end Close;
-----------
-- Close --
-----------
not overriding procedure Close (Self : in out Output) is
begin
Zip.Metadata.Write
(Self.Stream'Access,
Zip.Zip_File_Offset (Self.Stream.Offset),
Self.Directory);
Ada.Streams.Stream_IO.Close (Self.File);
end Close;
----------
-- Copy --
----------
not overriding procedure Copy
(To : in out Output'Class;
From : in out Input;
Index : Positive)
is
use type Ada.Streams.Stream_Element_Offset;
use type League.Strings.Universal_String;
Header : Zip.Metadata.File_Record;
Offset : Zip.Zip_File_Offset := 0;
begin
if Index not in 1 .. From.Directory.Files.Last_Index then
raise Constraint_Error;
end if;
Offset := Zip_File_Offset
(From.Directory.Files (Index).Local_Header_Offset);
-- Copy local file header
From.File.Set_Position (Offset);
Zip.Metadata.Read_Local_File_Header (From.File'Access, Header);
pragma Assert
(Header.File_Name = From.Directory.Files (Index).File_Name);
Header := From.Directory.Files (Index);
Header.Has_Data_Descriptor := False;
Header.Local_Header_Offset := To.Stream.Offset;
To.Directory.Files.Append (Header);
Zip.Metadata.Write_Local_File_Header (To.Stream'Access, Header);
-- Copy file's data
while Header.Compressed_Size > 0 loop
declare
Chunk_Size : constant := 1024;
Chunk : constant Ada.Streams.Stream_Element_Offset :=
Ada.Streams.Stream_Element_Offset'Min
(Chunk_Size, Header.Compressed_Size);
Length : constant Ada.Streams.Stream_Element_Offset :=
Ada.Streams.Stream_Element_Offset (Chunk);
Buffer : Ada.Streams.Stream_Element_Array (1 .. Length);
begin
Zip.IO.Read (From.File, Buffer);
To.Stream.Write (Buffer);
Header.Compressed_Size := Header.Compressed_Size - Chunk;
end;
end loop;
end Copy;
------------
-- Create --
------------
not overriding procedure Create
(Self : out Output;
Path : League.Strings.Universal_String)
is
begin
Ada.Streams.Stream_IO.Create (Self.File, Name => Path.To_UTF_8_String);
Self.Stream.Parent := Ada.Streams.Stream_IO.Stream (Self.File);
end Create;
-----------------
-- Entry_Count --
-----------------
not overriding function Entry_Count (Self : Input) return Natural is
begin
return Positive (Self.Directory.Files.Length);
end Entry_Count;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
Matreshka.Filters.Deflate.Pack.Initialize;
end Initialize;
----------
-- Open --
----------
not overriding procedure Open
(Self : out Input;
Path : League.Strings.Universal_String)
is
begin
Zip.IO.Open (Self.File, Path.To_UTF_8_String);
Self.Directory := Zip.Metadata.Read (Self.File'Access);
end Open;
----------
-- Path --
----------
not overriding function Path
(Self : Input;
Index : Positive) return League.Strings.Universal_String is
begin
return Self.Directory.Files.Element (Index).File_Name;
end Path;
-----------
-- Write --
-----------
overriding procedure Write
(Stream : in out Counting_Stream;
Item : Ada.Streams.Stream_Element_Array)
is
use type Ada.Streams.Stream_Element_Offset;
begin
Stream.Offset := Stream.Offset + Item'Length;
Stream.Parent.Write (Item);
end Write;
end Zip.Archives;
|
pvrego/adaino | Ada | 1,382 | adb | with System.Machine_Code;
with AVR.USART;
with AVR.TWI;
with AVR.TIMERS.CLOCK;
-- =============================================================================
-- Package body AVR.INTERRUPTS
-- =============================================================================
package body AVR.INTERRUPTS is
procedure Enable is
begin
System.Machine_Code.Asm ("sei", Volatile => True);
end Enable;
procedure Disable is
begin
System.Machine_Code.Asm ("cli", Volatile => True);
end Disable;
procedure Handle_Interrupt_USART0_RX is
begin
AVR.USART.Handle_ISR_RXC (AVR.USART.USART0);
end Handle_Interrupt_USART0_RX;
#if MCU="ATMEGA2560" then
procedure Handle_Interrupt_USART1_RX is
begin
AVR.USART.Handle_ISR_RXC (AVR.USART.USART1);
end Handle_Interrupt_USART1_RX;
procedure Handle_Interrupt_USART2_RX is
begin
AVR.USART.Handle_ISR_RXC (AVR.USART.USART2);
end Handle_Interrupt_USART2_RX;
procedure Handle_Interrupt_USART3_RX is
begin
AVR.USART.Handle_ISR_RXC (AVR.USART.USART3);
end Handle_Interrupt_USART3_RX;
#end if;
procedure Handle_Interrupt_TWI is
begin
AVR.TWI.Handle_Interrupts;
end Handle_Interrupt_TWI;
procedure Handle_Interrupt_TIMER4_OVF is
begin
AVR.TIMERS.CLOCK.Schedule_Update_Clock;
end Handle_Interrupt_TIMER4_OVF;
end AVR.INTERRUPTS;
|
stcarrez/dynamo | Ada | 28,486 | adb | -----------------------------------------------------------------------
-- gen-artifacts-distribs -- Artifact for distributions
-- Copyright (C) 2012, 2013, 2015, 2020, 2021, 2022 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Directories;
with Ada.Exceptions;
with Util.Files;
with Util.Strings;
with Util.Log.Loggers;
with Gen.Utils;
with Gen.Artifacts.Distribs.Copies;
with Gen.Artifacts.Distribs.Exec;
with Gen.Artifacts.Distribs.Concat;
with Gen.Artifacts.Distribs.Libs;
with Gen.Artifacts.Distribs.Bundles;
with Gen.Artifacts.Distribs.Merges;
-- The <b>Gen.Artifacts.Distribs</b> package is an artifact for the generation of
-- application distributions.
--
-- 1/ A package.xml file describes a set of distribution rules which indicate
-- how
package body Gen.Artifacts.Distribs is
use Util.Log;
Log : constant Loggers.Logger := Loggers.Create ("Gen.Artifacts.Distribs");
-- ------------------------------
-- Create a distribution rule identified by <b>Kind</b>.
-- The distribution rule is configured according to the DOM tree whose node is <b>Node</b>.
-- ------------------------------
function Create_Rule (Kind : in String;
Node : in DOM.Core.Node) return Distrib_Rule_Access is
begin
Log.Debug ("Creating distribution rule {0}", Kind);
if Kind = "copy" or else Kind = "" then
return Gen.Artifacts.Distribs.Copies.Create_Rule (Node, False);
elsif Kind = "copy-first" then
return Gen.Artifacts.Distribs.Copies.Create_Rule (Node, True);
elsif Kind = "exec" then
return Gen.Artifacts.Distribs.Exec.Create_Rule (Node, False);
elsif Kind = "copy-exec" then
return Gen.Artifacts.Distribs.Exec.Create_Rule (Node, True);
elsif Kind = "concat" then
return Gen.Artifacts.Distribs.Concat.Create_Rule (Node);
elsif Kind = "bundle" then
return Gen.Artifacts.Distribs.Bundles.Create_Rule (Node);
elsif Kind = "merge" then
return Gen.Artifacts.Distribs.Merges.Create_Rule (Node);
elsif Kind = "libs" then
return Gen.Artifacts.Distribs.Libs.Create_Rule (Node);
else
return null;
end if;
end Create_Rule;
-- ------------------------------
-- After the configuration file is read, processes the node whose root
-- is passed in <b>Node</b> and initializes the <b>Model</b> with the information.
-- ------------------------------
overriding
procedure Initialize (Handler : in out Artifact;
Path : in String;
Node : in DOM.Core.Node;
Model : in out Gen.Model.Packages.Model_Definition'Class;
Context : in out Generator'Class) is
procedure Register_Rule (O : in out Gen.Model.Packages.Model_Definition;
Node : in DOM.Core.Node);
procedure Register_Mappings (Model : in out Gen.Model.Packages.Model_Definition;
Node : in DOM.Core.Node);
procedure Register_Install (Model : in out Gen.Model.Packages.Model_Definition;
Node : in DOM.Core.Node);
-- ------------------------------
-- Register a new type mapping.
-- ------------------------------
procedure Register_Rule (O : in out Gen.Model.Packages.Model_Definition;
Node : in DOM.Core.Node) is
pragma Unreferenced (O);
-- Collect the include definitions for the distribution rule.
procedure Collect_Includes (Rule : in out Distrib_Rule_Access;
Node : in DOM.Core.Node);
-- Collect the exclude definitions for the distribution rule.
procedure Collect_Excludes (Rule : in out Distrib_Rule_Access;
Node : in DOM.Core.Node);
-- Collect the fileset definitions for the distribution rule.
procedure Collect_Filesets (Rule : in out Distrib_Rule_Access;
Node : in DOM.Core.Node);
Dir : constant String := To_String (Gen.Utils.Get_Attribute (Node, "dir"));
Mode : constant String := To_String (Gen.Utils.Get_Attribute (Node, "mode"));
Level : constant String := To_String (Gen.Utils.Get_Attribute (Node, "log"));
Rule : Distrib_Rule_Access := Create_Rule (Kind => Mode, Node => Node);
Match : Match_Rule;
-- ------------------------------
-- Collect the include definitions for the distribution rule.
-- ------------------------------
procedure Collect_Includes (Rule : in out Distrib_Rule_Access;
Node : in DOM.Core.Node) is
Name : constant String := To_String (Gen.Utils.Get_Attribute (Node, "name"));
begin
if Name = "" then
Context.Error ("Invalid include name {0}", Name);
return;
end if;
Match.Match := To_UString (Name);
Rule.Matches.Append (Match);
end Collect_Includes;
-- ------------------------------
-- Collect the exclude definitions for the distribution rule.
-- ------------------------------
procedure Collect_Excludes (Rule : in out Distrib_Rule_Access;
Node : in DOM.Core.Node) is
Name : constant String := To_String (Gen.Utils.Get_Attribute (Node, "name"));
begin
if Name = "" then
Context.Error ("Invalid exclude name {0}", Name);
return;
end if;
Match.Match := To_UString (Name);
Rule.Excludes.Append (Match);
end Collect_Excludes;
procedure Iterate is
new Gen.Utils.Iterate_Nodes (T => Distrib_Rule_Access,
Process => Collect_Includes);
procedure Iterate_Excludes is
new Gen.Utils.Iterate_Nodes (T => Distrib_Rule_Access,
Process => Collect_Excludes);
-- ------------------------------
-- Collect the include definitions for the distribution rule.
-- ------------------------------
procedure Collect_Filesets (Rule : in out Distrib_Rule_Access;
Node : in DOM.Core.Node) is
Dir : constant String := To_String (Gen.Utils.Get_Attribute (Node, "dir"));
begin
if Dir = "" then
Context.Error ("Invalid fileset directory {0}", Dir);
return;
end if;
Match.Base_Dir := To_UString (Dir);
Iterate (Rule, Node, "include");
Iterate_Excludes (Rule, Node, "exclude", False);
end Collect_Filesets;
procedure Iterate_Filesets is
new Gen.Utils.Iterate_Nodes (T => Distrib_Rule_Access,
Process => Collect_Filesets);
begin
Log.Debug ("Install {0}", Dir);
if Rule /= null then
Rule.Dir := To_UString (Dir);
if Level = "info" then
Rule.Level := Util.Log.INFO_LEVEL;
elsif Level = "debug" then
Rule.Level := Util.Log.DEBUG_LEVEL;
else
Rule.Level := Util.Log.WARN_LEVEL;
end if;
Handler.Rules.Append (Rule);
Iterate (Rule, Node, "include", False);
Iterate_Excludes (Rule, Node, "exclude", False);
Iterate_Filesets (Rule, Node, "fileset");
end if;
end Register_Rule;
-- ------------------------------
-- Register the installation rules.
-- ------------------------------
procedure Register_Install (Model : in out Gen.Model.Packages.Model_Definition;
Node : in DOM.Core.Node) is
procedure Iterate is
new Gen.Utils.Iterate_Nodes (T => Gen.Model.Packages.Model_Definition,
Process => Register_Rule);
begin
Iterate (Model, Node, "install");
end Register_Install;
-- ------------------------------
-- Register a model mapping
-- ------------------------------
procedure Register_Mappings (Model : in out Gen.Model.Packages.Model_Definition;
Node : in DOM.Core.Node) is
procedure Iterate is
new Gen.Utils.Iterate_Nodes (T => Gen.Model.Packages.Model_Definition,
Process => Register_Install);
begin
Iterate (Model, Node, "dist");
end Register_Mappings;
procedure Iterate is new Gen.Utils.Iterate_Nodes (T => Gen.Model.Packages.Model_Definition,
Process => Register_Mappings);
begin
Log.Debug ("Initializing distrib artifact for the configuration");
Gen.Artifacts.Artifact (Handler).Initialize (Path, Node, Model, Context);
Iterate (Gen.Model.Packages.Model_Definition (Model), Node, "package");
end Initialize;
-- ------------------------------
-- Prepare the model after all the configuration files have been read and before
-- actually invoking the generation.
-- ------------------------------
overriding
procedure Prepare (Handler : in out Artifact;
Model : in out Gen.Model.Packages.Model_Definition'Class;
Project : in out Gen.Model.Projects.Project_Definition'Class;
Context : in out Generator'Class) is
pragma Unreferenced (Model, Project);
procedure Scan_Rule (Pos : in Distrib_Rule_Vectors.Cursor);
procedure Scan_Directory (Dir : in String);
procedure Execute_Rule (Pos : in Distrib_Rule_Vectors.Cursor);
-- ------------------------------
-- Process the rule by scanning the directory tree and detecting files that are concerned.
-- ------------------------------
procedure Scan_Rule (Pos : in Distrib_Rule_Vectors.Cursor) is
Rule : constant Distrib_Rule_Access := Distrib_Rule_Vectors.Element (Pos);
Iter : Directory_List_Vector.Cursor := Handler.Trees.First;
begin
Log.Debug ("Scanning rule");
while Directory_List_Vector.Has_Element (Iter) loop
Rule.Scan (Directory_List_Vector.Element (Iter).all);
Directory_List_Vector.Next (Iter);
end loop;
end Scan_Rule;
-- ------------------------------
-- Execute the rules.
-- ------------------------------
procedure Execute_Rule (Pos : in Distrib_Rule_Vectors.Cursor) is
Rule : constant Distrib_Rule_Access := Distrib_Rule_Vectors.Element (Pos);
Path : constant String := Context.Get_Result_Directory;
begin
Log.Debug ("Process rule");
Rule.Execute (Path, Context);
end Execute_Rule;
-- ------------------------------
-- Scan the directory collecting the files that must be taken into account and
-- processed by the distribution rules.
-- ------------------------------
procedure Scan_Directory (Dir : in String) is
Tree : constant Directory_List_Access :=
new Directory_List '(Length => 1, Name => ".", Rel_Pos => Dir'Length + 2,
Path_Length => Dir'Length, Path => Dir, others => <>);
begin
Log.Info ("Scanning directory: {0}", Dir);
Handler.Trees.Append (Tree);
Scan (Dir, ".", Tree);
end Scan_Directory;
begin
-- Scan each directory used by the dynamo project.
Context.Scan_Directories (Scan_Directory'Access);
-- Apply the rules on the directory tree.
Handler.Rules.Iterate (Process => Scan_Rule'Access);
-- Apply the rules on the directory tree.
Handler.Rules.Iterate (Process => Execute_Rule'Access);
end Prepare;
-- ------------------------------
-- Get the relative path of the directory.
-- ------------------------------
function Get_Relative_Path (Dir : in Directory_List) return String is
begin
return Dir.Path (Dir.Rel_Pos .. Dir.Path'Last);
end Get_Relative_Path;
-- ------------------------------
-- Get the first source path from the list.
-- ------------------------------
function Get_Source_Path (From : in File_Vector;
Use_First_File : in Boolean := False) return String is
use type Ada.Containers.Count_Type;
begin
if From.Length = 0 then
return "";
elsif Use_First_File then
declare
File : constant File_Record := From.Element (1);
begin
return Util.Files.Compose (File.Dir.Path, File.Name);
end;
else
declare
File : constant File_Record := From.Element (From.Last_Index);
begin
return Util.Files.Compose (File.Dir.Path, File.Name);
end;
end if;
end Get_Source_Path;
-- ------------------------------
-- Build a regular expression pattern from a pattern string.
-- ------------------------------
function Make_Regexp (Pattern : in String) return String is
Result : String (1 .. Pattern'Length * 2 + 2);
Pos : Natural := 1;
begin
Result (1) := '^';
for I in Pattern'Range loop
if Pattern (I) = '*' then
Pos := Pos + 1;
Result (Pos) := '.';
elsif Pattern (I) in '.' | '$' | '^' then
Pos := Pos + 1;
Result (Pos) := '\';
end if;
Pos := Pos + 1;
Result (Pos) := Pattern (I);
end loop;
Pos := Pos + 1;
Result (Pos) := '$';
return Result (1 .. Pos);
end Make_Regexp;
-- ------------------------------
-- Build a regular expression pattern from a pattern string.
-- ------------------------------
function Make_Regexp (Pattern : in String) return GNAT.Regpat.Pattern_Matcher is
Expr : constant String := Make_Regexp (Pattern);
begin
return GNAT.Regpat.Compile (Expr);
end Make_Regexp;
-- ------------------------------
-- Scan the directory whose root path is <b>Path</b> and with the relative path
-- <b>Rel_Path</b> and build in <b>Dir</b> the list of files and directories.
-- ------------------------------
procedure Scan (Path : in String;
Rel_Path : in String;
Dir : in Directory_List_Access) is
use Ada.Directories;
Full_Path : constant String := Util.Files.Compose (Path, Rel_Path);
Filter : constant Filter_Type := (Ordinary_File => True,
Directory => True,
others => False);
Ent : Ada.Directories.Directory_Entry_Type;
Search : Search_Type;
begin
Log.Debug ("Scanning {0}", Full_Path);
Start_Search (Search, Directory => Full_Path,
Pattern => "*", Filter => Filter);
while More_Entries (Search) loop
Get_Next_Entry (Search, Ent);
declare
Name : constant String := Simple_Name (Ent);
File_Path : constant String := Util.Files.Compose (Rel_Path, Name);
Full_Path : constant String := Ada.Directories.Full_Name (Ent);
begin
Log.Debug ("Collect {0}", File_Path);
if Gen.Utils.Is_File_Ignored (Name) then
Log.Debug ("Ignoring {0}", Name);
-- If this is a directory, recursively scan it and collect its files.
elsif Ada.Directories.Kind (Full_Path) = Ada.Directories.Directory then
declare
Sub_Dir : constant Directory_List_Access
:= new Directory_List '(Length => Name'Length,
Path_Length => Full_Path'Length,
Rel_Pos => Full_Path'Length - File_Path'Length,
Name => Name,
Path => Full_Path,
others => <>);
begin
Dir.Directories.Append (Sub_Dir);
Scan (Path, File_Path, Sub_Dir);
end;
else
Dir.Files.Append (File_Record '(Length => Name'Length,
Name => Name,
Dir => Dir));
end if;
end;
end loop;
end Scan;
procedure Execute (Rule : in out Distrib_Rule;
Path : in String;
Context : in out Generator'Class) is
use Ada.Containers;
procedure Process (Key : in String;
Files : in out File_Vector);
procedure Process (Key : in String;
Files : in out File_Vector) is
Name : constant String := Util.Files.Compose (Path, Key);
begin
Distrib_Rule'Class (Rule).Install (Name, Files, Context);
exception
when Ex : others =>
Context.Error ("Install of {0} failed: {1}",
Name, Ada.Exceptions.Exception_Message (Ex));
end Process;
Iter : File_Tree.Cursor := Rule.Files.First;
Count : constant Count_Type := Rule.Files.Length;
Name : constant String := Distrib_Rule'Class (Rule).Get_Install_Name;
begin
if Count = 0 then
return;
elsif Count = 1 then
Log.Info ("Installing 1 file with {0}", Name);
else
Log.Info ("Installing{0} files with {1}", Count_Type'Image (Count), Name);
end if;
while File_Tree.Has_Element (Iter) loop
Rule.Files.Update_Element (Iter, Process'Access);
File_Tree.Next (Iter);
end loop;
end Execute;
-- ------------------------------
-- Strip the base part of the path
-- ------------------------------
function Get_Strip_Path (Base : in String;
Path : in String) return String is
begin
if Base /= "." and then Path (Path'First) = '/'
and then Path (Path'First + 1 .. Path'First + Base'Length) = Base
then
return Path (Path'First + Base'Length + 1 .. Path'Last);
else
return Path;
end if;
end Get_Strip_Path;
-- ------------------------------
-- Get the target path associate with the given source file for the distribution rule.
-- ------------------------------
function Get_Target_Path (Rule : in Distrib_Rule;
Base : in String;
File : in File_Record) return String is
Rel_Path : constant String := Get_Relative_Path (File.Dir.all);
Path : constant String := Get_Strip_Path (Base, Rel_Path);
begin
return Util.Files.Compose (To_String (Rule.Dir),
Util.Files.Compose (Path, File.Name));
end Get_Target_Path;
-- ------------------------------
-- Get the source path of the file.
-- ------------------------------
function Get_Source_Path (Rule : in Distrib_Rule;
File : in File_Record) return String is
pragma Unreferenced (Rule);
begin
return Util.Files.Compose (File.Dir.Path, File.Name);
end Get_Source_Path;
-- ------------------------------
-- Add the file to be processed by the distribution rule. The file has a relative
-- path represented by <b>Path</b>. The path is relative from the base directory
-- specified in <b>Base_Dir</b>.
-- ------------------------------
procedure Add_Source_File (Rule : in out Distrib_Rule;
Path : in String;
File : in File_Record) is
procedure Add_File (Key : in String;
Info : in out File_Vector);
procedure Add_File (Key : in String;
Info : in out File_Vector) is
pragma Unreferenced (Key);
begin
Info.Append (File);
end Add_File;
Target_Path : constant String := Distrib_Rule'Class (Rule).Get_Target_Path (Path, File);
Pos : constant File_Tree.Cursor := Rule.Files.Find (Target_Path);
begin
Log.Debug ("Adding {0} - {1}", Path, Target_Path);
if File_Tree.Has_Element (Pos) then
Rule.Files.Update_Element (Pos, Add_File'Access);
else
declare
Info : File_Vector;
begin
Info.Append (File);
Rule.Files.Insert (Target_Path, Info);
end;
end if;
end Add_Source_File;
-- ------------------------------
-- Remove the file to be processed by the distribution rule. This is the opposite of
-- <tt>Add_Source_File</tt> and used for the <exclude name="xxx"/> rules.
-- ------------------------------
procedure Remove_Source_File (Rule : in out Distrib_Rule;
Path : in String;
File : in File_Record) is
procedure Remove_File (Key : in String;
Info : in out File_Vector);
Target_Path : constant String := Distrib_Rule'Class (Rule).Get_Target_Path (Path, File);
Need_Remove : Boolean := False;
procedure Remove_File (Key : in String;
Info : in out File_Vector) is
pragma Unreferenced (Key);
Pos : File_Cursor := Info.Find (File);
begin
if File_Record_Vectors.Has_Element (Pos) then
Log.Debug ("Excluding {0} - {1}", Path, Target_Path);
Info.Delete (Pos);
Need_Remove := Info.Is_Empty;
end if;
end Remove_File;
Pos : File_Tree.Cursor := Rule.Files.Find (Target_Path);
begin
if File_Tree.Has_Element (Pos) then
Rule.Files.Update_Element (Pos, Remove_File'Access);
if Need_Remove then
Rule.Files.Delete (Pos);
end if;
end if;
end Remove_Source_File;
-- ------------------------------
-- Scan the directory tree whose root is defined by <b>Dir</b> and find the files
-- that match the current rule.
-- ------------------------------
procedure Scan (Rule : in out Distrib_Rule;
Dir : in Directory_List) is
procedure Scan_Pattern (Pos : in Match_Rule_Vector.Cursor);
Exclude : Boolean;
procedure Scan_Pattern (Pos : in Match_Rule_Vector.Cursor) is
Match : constant Match_Rule := Match_Rule_Vector.Element (Pos);
Base : constant String := To_String (Match.Base_Dir);
Pattern : constant String := To_String (Match.Match);
begin
Log.Debug ("Scan pattern base {0} - pat {1}", Base, Pattern);
if Base = "" then
Rule.Scan (Dir, ".", Pattern, Exclude);
return;
end if;
declare
Iter : Directory_List_Vector.Cursor := Dir.Directories.First;
D : Directory_List_Access;
P : Natural := Base'First;
N : Natural;
begin
while P < Base'Last loop
N := Util.Strings.Index (Base, '/', P);
if N = 0 then
N := Base'Last;
else
N := N - 1;
end if;
while Directory_List_Vector.Has_Element (Iter) loop
D := Directory_List_Vector.Element (Iter);
if D.Name = Base (P .. N) then
if N = Base'Last then
Log.Debug ("Scanning from sub directory at {0}", Base);
Rule.Scan (D.all, Base, Pattern, Exclude);
return;
end if;
Iter := D.Directories.First;
exit;
end if;
Directory_List_Vector.Next (Iter);
end loop;
P := N + 2;
end loop;
end;
end Scan_Pattern;
begin
Exclude := False;
Rule.Matches.Iterate (Scan_Pattern'Access);
Exclude := True;
Rule.Excludes.Iterate (Scan_Pattern'Access);
end Scan;
procedure Scan (Rule : in out Distrib_Rule;
Dir : in Directory_List;
Base_Dir : in String;
Pattern : in String;
Exclude : in Boolean) is
procedure Collect_Subdirs (Name_Pattern : in String);
procedure Collect_Files (Name_Pattern : in String);
-- **/*.xhtml
-- bin/**
-- bin/**/test.bin
N : constant Natural := Util.Strings.Index (Pattern, '/');
Pos : Natural := Pattern'First;
procedure Collect_Files (Name_Pattern : in String) is
use GNAT.Regpat;
procedure Collect_File (File : in File_Record);
Matcher : constant Pattern_Matcher := Make_Regexp (Name_Pattern);
procedure Collect_File (File : in File_Record) is
begin
Log.Debug ("Check {0} - {1}", Base_Dir, File.Name);
if Match (Matcher, File.Name) then
if Exclude then
Rule.Remove_Source_File (Base_Dir, File);
else
Rule.Add_Source_File (Base_Dir, File);
end if;
end if;
end Collect_File;
Iter : File_Record_Vectors.Cursor := Dir.Files.First;
begin
while File_Record_Vectors.Has_Element (Iter) loop
File_Record_Vectors.Query_Element (Iter, Collect_File'Access);
File_Record_Vectors.Next (Iter);
end loop;
end Collect_Files;
procedure Collect_Subdirs (Name_Pattern : in String) is
procedure Collect_Dir (Sub_Dir : in Directory_List_Access);
procedure Collect_Dir (Sub_Dir : in Directory_List_Access) is
begin
if Name_Pattern = Sub_Dir.Name or else Name_Pattern = "*" then
Rule.Scan (Sub_Dir.all, Base_Dir,
Pattern (Pos .. Pattern'Last), Exclude);
end if;
end Collect_Dir;
Iter : Directory_List_Vector.Cursor := Dir.Directories.First;
begin
while Directory_List_Vector.Has_Element (Iter) loop
Directory_List_Vector.Query_Element (Iter, Collect_Dir'Access);
Directory_List_Vector.Next (Iter);
end loop;
end Collect_Subdirs;
Next : Natural;
begin
Log.Debug ("Scan {0}/{1} for pattern {2}", Base_Dir, Dir.Name, Pattern);
if N > 0 then
if Pattern = "**" then
Collect_Subdirs (Name_Pattern => "**");
Collect_Files (Name_Pattern => "*");
return;
elsif Pattern (Pattern'First .. N) = "*/" then
Pos := N + 1;
Collect_Subdirs (Name_Pattern => "*");
elsif Pattern (Pattern'First .. N) = "**/" then
Collect_Subdirs (Name_Pattern => "*");
else
Pos := N + 1;
Collect_Subdirs (Name_Pattern => Pattern (Pattern'First .. N - 1));
return;
end if;
Next := Util.Strings.Index (Pattern, '/', N + 1);
if Next = 0 then
Collect_Files (Name_Pattern => Pattern (N + 1 .. Pattern'Last));
end if;
end if;
if N = 0 then
-- No more directory
Collect_Files (Name_Pattern => Pattern);
end if;
end Scan;
end Gen.Artifacts.Distribs;
|
onox/orka | Ada | 9,923 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with AUnit.Assertions;
with AUnit.Test_Caller;
with Orka.Scenes.Singles.Trees;
with Orka.Transforms.Singles.Matrices;
package body Test_Scene_Trees is
use Orka.Scenes.Singles.Trees;
use AUnit.Assertions;
package Caller is new AUnit.Test_Caller (Test);
Test_Suite : aliased AUnit.Test_Suites.Test_Suite;
function Suite return AUnit.Test_Suites.Access_Test_Suite is
Name : constant String := "(Scene trees) ";
begin
Test_Suite.Add_Test (Caller.Create
(Name & "Test Create_Tree function", Test_Create_Tree'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test Add_Node procedure (leaf node)", Test_Add_Leaf_Node'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test Add_Node procedure (non-leaf node)", Test_Add_Non_Leaf_Node'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test To_Cursor function (root node)", Test_To_Cursor_Root_Node'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test To_Cursor function (leaf node)", Test_To_Cursor_Leaf_Node'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test To_Cursor function (non-leaf node)", Test_To_Cursor_Non_Leaf_Node'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Raise Unknown_Node_Error in To_Cursor", Test_To_Cursor_Exception'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test Remove_Node procedure (leaf node)", Test_Remove_Leaf_Node'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test Remove_Node procedure (subtree)", Test_Remove_Subtree'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Raise Root_Removal_Error in Remove_Node", Test_Remove_Root_Exception'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test Set_Local_Transform procedure", Test_Set_Local_Transform'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test Update_Tree procedure", Test_Update_Tree'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test World_Transform function", Test_World_Transform'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test Depth function", Test_Depth'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test Width function", Test_Width'Access));
Test_Suite.Add_Test (Caller.Create
(Name & "Test Visibility function", Test_Visibility'Access));
return Test_Suite'Access;
end Suite;
procedure Test_Create_Tree (Object : in out Test) is
T : constant Tree := Create_Tree ("root");
pragma Unreferenced (T);
begin
null;
end Test_Create_Tree;
procedure Test_Add_Leaf_Node (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
T.Add_Node ("N1", "root");
T.Add_Node ("N2", "N1");
end Test_Add_Leaf_Node;
procedure Test_Add_Non_Leaf_Node (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
T.Add_Node ("N1", "root");
T.Add_Node ("N2", "N1");
-- Add nodes to non-leaf nodes
T.Add_Node ("N3", "N1");
T.Add_Node ("N4", "root");
end Test_Add_Non_Leaf_Node;
procedure Test_To_Cursor_Root_Node (Object : in out Test) is
T : constant Tree := Create_Tree ("root");
C : constant Cursor := T.To_Cursor ("root");
pragma Unreferenced (C);
begin
null;
end Test_To_Cursor_Root_Node;
procedure Test_To_Cursor_Leaf_Node (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
T.Add_Node ("N1", "root");
declare
C : constant Cursor := T.To_Cursor ("N1");
pragma Unreferenced (C);
begin
null;
end;
end Test_To_Cursor_Leaf_Node;
procedure Test_To_Cursor_Non_Leaf_Node (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
T.Add_Node ("N1", "root");
T.Add_Node ("N2", "N1");
declare
C : constant Cursor := T.To_Cursor ("N1");
pragma Unreferenced (C);
begin
null;
end;
end Test_To_Cursor_Non_Leaf_Node;
procedure Test_To_Cursor_Exception (Object : in out Test) is
T : constant Tree := Create_Tree ("root");
begin
declare
C : constant Cursor := T.To_Cursor ("N1");
pragma Unreferenced (C);
begin
Assert (False, "Expected Unknown_Node_Error exception");
end;
exception
when Unknown_Node_Error =>
null;
end Test_To_Cursor_Exception;
procedure Test_Remove_Leaf_Node (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
T.Add_Node ("N1", "root");
T.Remove_Node ("N1");
begin
declare
C : constant Cursor := T.To_Cursor ("N1");
pragma Unreferenced (C);
begin
Assert (False, "Expected Unknown_Node_Error exception");
end;
exception
when Unknown_Node_Error =>
null;
end;
end Test_Remove_Leaf_Node;
procedure Test_Remove_Subtree (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
T.Add_Node ("N1", "root");
T.Add_Node ("N2", "N1");
T.Remove_Node ("N1");
-- Test N1 has been removed
begin
declare
C : constant Cursor := T.To_Cursor ("N1");
pragma Unreferenced (C);
begin
Assert (False, "Expected Unknown_Node_Error exception");
end;
exception
when Unknown_Node_Error =>
null;
end;
-- Test N2 has been removed
begin
declare
C : constant Cursor := T.To_Cursor ("N2");
pragma Unreferenced (C);
begin
Assert (False, "Expected Unknown_Node_Error exception");
end;
exception
when Unknown_Node_Error =>
null;
end;
end Test_Remove_Subtree;
procedure Test_Remove_Root_Exception (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
T.Remove_Node ("root");
Assert (False, "Excepted Root_Removal_Error exception");
exception
when Root_Removal_Error =>
null;
end Test_Remove_Root_Exception;
procedure Test_Set_Local_Transform (Object : in out Test) is
T : Tree := Create_Tree ("root");
C : constant Cursor := T.To_Cursor ("root");
package Transforms renames Orka.Transforms.Singles.Matrices;
Offset : constant Transforms.Vector4 := (1.0, 2.0, 3.0, 1.0);
begin
T.Set_Local_Transform (C, Transforms.T (Offset));
end Test_Set_Local_Transform;
procedure Test_Update_Tree (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
-- Depth 1
T.Update_Tree;
-- Depth 2
T.Add_Node ("N1", "root");
T.Update_Tree;
-- Depth 3
T.Add_Node ("N2", "N1");
T.Update_Tree;
end Test_Update_Tree;
procedure Test_World_Transform (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
T.Add_Node ("N1", "root");
declare
C1 : constant Cursor := T.To_Cursor ("root");
C2 : constant Cursor := T.To_Cursor ("N1");
use type Orka.Transforms.Singles.Matrices.Matrix4;
use type Orka.Transforms.Singles.Matrices.Vector4;
package Transforms renames Orka.Transforms.Singles.Matrices;
Offset : constant Transforms.Vector4 := (1.0, 2.0, 3.0, 1.0);
begin
Assert
(T.World_Transform (C2) = Transforms.Identity_Matrix, "Unexpected World_Transform");
-- Update local transform of root node
T.Set_Local_Transform (C1, Transforms.T (Offset));
T.Update_Tree;
-- Check world transform of node N1
Assert (T.World_Transform (C2) (Orka.W) = Offset, "Unexpected World_Transform");
end;
end Test_World_Transform;
procedure Test_Depth (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
Assert (T.Depth = 1, "Unexpected Depth");
T.Add_Node ("N1", "root");
Assert (T.Depth = 2, "Unexpected Depth");
T.Add_Node ("N2", "N1");
Assert (T.Depth = 3, "Unexpected Depth");
T.Remove_Node ("N1");
Assert (T.Depth = 1, "Unexpected Depth");
end Test_Depth;
procedure Test_Width (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
T.Add_Node ("N1", "root");
T.Add_Node ("N2", "root");
T.Add_Node ("N3", "N1");
Assert (T.Width (1) = 1, "Unexpected Width");
Assert (T.Width (2) = 2, "Unexpected Width");
Assert (T.Width (3) = 1, "Unexpected Width");
end Test_Width;
procedure Test_Visibility (Object : in out Test) is
T : Tree := Create_Tree ("root");
begin
T.Add_Node ("N1", "root");
declare
C1 : constant Cursor := T.To_Cursor ("root");
C2 : constant Cursor := T.To_Cursor ("N1");
begin
Assert (T.Visibility (C2), "Unexpected Visibility");
-- Update local visibility of root node
T.Set_Visibility (C1, False);
T.Update_Tree;
-- Check visibility of node N1
Assert (not T.Visibility (C2), "Unexpected Visibility");
end;
end Test_Visibility;
end Test_Scene_Trees;
|
reznikmm/matreshka | Ada | 4,647 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Draw.Caption_Point_X_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Draw_Caption_Point_X_Attribute_Node is
begin
return Self : Draw_Caption_Point_X_Attribute_Node do
Matreshka.ODF_Draw.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Draw_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Draw_Caption_Point_X_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Caption_Point_X_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Draw_URI,
Matreshka.ODF_String_Constants.Caption_Point_X_Attribute,
Draw_Caption_Point_X_Attribute_Node'Tag);
end Matreshka.ODF_Draw.Caption_Point_X_Attributes;
|
AdaCore/Ada_Drivers_Library | Ada | 2,491 | ads | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2020, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with HAL;
package RISCV.Types is
XLEN : constant := 32;
subtype Unsigned_XLEN is HAL.UInt32;
end RISCV.Types;
|
AdaCore/libadalang | Ada | 45,524 | adb | procedure Test is
X : String :=
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" &
"x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x" & "x";
begin
end Test;
|
optikos/ada-lsp | Ada | 2,841 | ads | -- Copyright (c) 2017 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with League.JSON.Streams;
with League.JSON.Values;
with League.String_Vectors;
with League.Strings;
with LSP.Generic_Optional;
package LSP.Types is
pragma Preelaborate;
subtype LSP_Any is League.JSON.Values.JSON_Value;
subtype LSP_Number is Natural;
subtype LSP_String is League.Strings.Universal_String;
subtype LSP_String_Vector is League.String_Vectors.Universal_String_Vector;
type LSP_Number_Or_String (Is_Number : Boolean := False) is record
case Is_Number is
when True =>
Number : LSP_Number;
when False =>
String : LSP_String;
end case;
end record;
function Assigned (Id : LSP_Number_Or_String) return Boolean;
-- Check if Id has an empty value
type Line_Number is new Natural;
type UTF_16_Index is new Natural;
type Version_Id is new Natural;
type Trace_Kinds is (Unspecified, Off, Messages, Verbose);
package Optional_Numbers is new LSP.Generic_Optional (LSP_Number);
type Optional_Number is new Optional_Numbers.Optional_Type;
package Optional_Booleans is new LSP.Generic_Optional (Boolean);
type Optional_Boolean is new Optional_Booleans.Optional_Type;
package Optional_Strings is new LSP.Generic_Optional (LSP_String);
type Optional_String is new Optional_Strings.Optional_Type;
Optional_False : constant Optional_Boolean := (True, False);
Optional_True : constant Optional_Boolean := (True, True);
subtype MessageActionItem_Vector is
League.String_Vectors.Universal_String_Vector;
type Registration_Option_Kinds is
(Absent,
Text_Document_Registration_Option,
Text_Document_Change_Registration_Option,
Text_Document_Save_Registration_Option,
Completion_Registration_Option,
Signature_Help_Registration_Option,
Code_Lens_Registration_Option,
Document_Link_Registration_Option,
Document_On_Type_Formatting_Registration_Option,
Execute_Command_Registration_Option);
procedure Read_String
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : out LSP.Types.LSP_String);
procedure Read_Optional_String
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : out LSP.Types.Optional_String);
procedure Read_Number_Or_String
(Stream : in out League.JSON.Streams.JSON_Stream'Class;
Key : League.Strings.Universal_String;
Item : out LSP.Types.LSP_Number_Or_String);
end LSP.Types;
|
optikos/ada-lsp | Ada | 1,800 | ads | -- Copyright (c) 2017 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with LSP.Message_Handlers;
with LSP.Messages;
with LSP.Servers;
with Ada_LSP.Contexts;
package Ada_LSP.Handlers is
type Message_Handler
(Server : access LSP.Servers.Server;
Context : access Ada_LSP.Contexts.Context) is
limited new LSP.Message_Handlers.Request_Handler
and LSP.Message_Handlers.Notification_Handler with private;
private
type Message_Handler
(Server : access LSP.Servers.Server;
Context : access Ada_LSP.Contexts.Context)
is limited new LSP.Message_Handlers.Request_Handler
and LSP.Message_Handlers.Notification_Handler with record
null;
end record;
overriding procedure Exit_Notification
(Self : access Message_Handler);
overriding procedure Initialize_Request
(Self : access Message_Handler;
Value : LSP.Messages.InitializeParams;
Response : in out LSP.Messages.Initialize_Response);
overriding procedure Text_Document_Did_Change
(Self : access Message_Handler;
Value : LSP.Messages.DidChangeTextDocumentParams);
overriding procedure Text_Document_Did_Open
(Self : access Message_Handler;
Value : LSP.Messages.DidOpenTextDocumentParams);
overriding procedure Text_Document_Symbol_Request
(Self : access Message_Handler;
Value : LSP.Messages.DocumentSymbolParams;
Response : in out LSP.Messages.Symbol_Response);
overriding procedure Text_Document_Completion_Request
(Self : access Message_Handler;
Value : LSP.Messages.TextDocumentPositionParams;
Response : in out LSP.Messages.Completion_Response);
end Ada_LSP.Handlers;
|
gitter-badger/libAnne | Ada | 1,190 | ads | with Generics.Mathematics.Percents.IO;
use Generics.Mathematics.Percents.IO;
package Mathematics.Percents.IO is
--@Description Provides input/output operations for Mathematics.Percents
--@Version 1.0
function Image is new Percent_Image(Short_Short_Percent);
function Wide_Image is new Percent_Wide_Image(Short_Short_Percent);
function Wide_Wide_Image is new Percent_Wide_Wide_Image(Short_Short_Percent);
function Image is new Percent_Image(Short_Percent);
function Wide_Image is new Percent_Wide_Image(Short_Percent);
function Wide_Wide_Image is new Percent_Wide_Wide_Image(Short_Percent);
function Image is new Percent_Image(Percent);
function Wide_Image is new Percent_Wide_Image(Percent);
function Wide_Wide_Image is new Percent_Wide_Wide_Image(Percent);
function Image is new Percent_Image(Long_Percent);
function Wide_Image is new Percent_Wide_Image(Long_Percent);
function Wide_Wide_Image is new Percent_Wide_Wide_Image(Long_Percent);
function Image is new Percent_Image(Long_Long_Percent);
function Wide_Image is new Percent_Wide_Image(Long_Long_Percent);
function Wide_Wide_Image is new Percent_Wide_Wide_Image(Long_Long_Percent);
end Mathematics.Percents.IO;
|
merced317/scirun4plus | Ada | 13,177 | adb | ----------------------------------------------------------------
-- ZLib for Ada thick binding. --
-- --
-- Copyright (C) 2002-2003 Dmitriy Anisimkov --
-- --
-- Open source license information is in the zlib.ads file. --
----------------------------------------------------------------
-- $Id: test.adb,v 1.1 2008/12/19 14:44:49 dkf Exp $
-- The program has a few aims.
-- 1. Test ZLib.Ada95 thick binding functionality.
-- 2. Show the example of use main functionality of the ZLib.Ada95 binding.
-- 3. Build this program automatically compile all ZLib.Ada95 packages under
-- GNAT Ada95 compiler.
with ZLib.Streams;
with Ada.Streams.Stream_IO;
with Ada.Numerics.Discrete_Random;
with Ada.Text_IO;
with Ada.Calendar;
procedure Test is
use Ada.Streams;
use Stream_IO;
------------------------------------
-- Test configuration parameters --
------------------------------------
File_Size : Count := 100_000;
Continuous : constant Boolean := False;
Header : constant ZLib.Header_Type := ZLib.Default;
-- ZLib.None;
-- ZLib.Auto;
-- ZLib.GZip;
-- Do not use Header other then Default in ZLib versions 1.1.4
-- and older.
Strategy : constant ZLib.Strategy_Type := ZLib.Default_Strategy;
Init_Random : constant := 10;
-- End --
In_File_Name : constant String := "testzlib.in";
-- Name of the input file
Z_File_Name : constant String := "testzlib.zlb";
-- Name of the compressed file.
Out_File_Name : constant String := "testzlib.out";
-- Name of the decompressed file.
File_In : File_Type;
File_Out : File_Type;
File_Back : File_Type;
File_Z : ZLib.Streams.Stream_Type;
Filter : ZLib.Filter_Type;
Time_Stamp : Ada.Calendar.Time;
procedure Generate_File;
-- Generate file of spetsified size with some random data.
-- The random data is repeatable, for the good compression.
procedure Compare_Streams
(Left, Right : in out Root_Stream_Type'Class);
-- The procedure compearing data in 2 streams.
-- It is for compare data before and after compression/decompression.
procedure Compare_Files (Left, Right : String);
-- Compare files. Based on the Compare_Streams.
procedure Copy_Streams
(Source, Target : in out Root_Stream_Type'Class;
Buffer_Size : in Stream_Element_Offset := 1024);
-- Copying data from one stream to another. It is for test stream
-- interface of the library.
procedure Data_In
(Item : out Stream_Element_Array;
Last : out Stream_Element_Offset);
-- this procedure is for generic instantiation of
-- ZLib.Generic_Translate.
-- reading data from the File_In.
procedure Data_Out (Item : in Stream_Element_Array);
-- this procedure is for generic instantiation of
-- ZLib.Generic_Translate.
-- writing data to the File_Out.
procedure Stamp;
-- Store the timestamp to the local variable.
procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count);
-- Print the time statistic with the message.
procedure Translate is new ZLib.Generic_Translate
(Data_In => Data_In,
Data_Out => Data_Out);
-- This procedure is moving data from File_In to File_Out
-- with compression or decompression, depend on initialization of
-- Filter parameter.
-------------------
-- Compare_Files --
-------------------
procedure Compare_Files (Left, Right : String) is
Left_File, Right_File : File_Type;
begin
Open (Left_File, In_File, Left);
Open (Right_File, In_File, Right);
Compare_Streams (Stream (Left_File).all, Stream (Right_File).all);
Close (Left_File);
Close (Right_File);
end Compare_Files;
---------------------
-- Compare_Streams --
---------------------
procedure Compare_Streams
(Left, Right : in out Ada.Streams.Root_Stream_Type'Class)
is
Left_Buffer, Right_Buffer : Stream_Element_Array (0 .. 16#FFF#);
Left_Last, Right_Last : Stream_Element_Offset;
begin
loop
Read (Left, Left_Buffer, Left_Last);
Read (Right, Right_Buffer, Right_Last);
if Left_Last /= Right_Last then
Ada.Text_IO.Put_Line ("Compare error :"
& Stream_Element_Offset'Image (Left_Last)
& " /= "
& Stream_Element_Offset'Image (Right_Last));
raise Constraint_Error;
elsif Left_Buffer (0 .. Left_Last)
/= Right_Buffer (0 .. Right_Last)
then
Ada.Text_IO.Put_Line ("ERROR: IN and OUT files is not equal.");
raise Constraint_Error;
end if;
exit when Left_Last < Left_Buffer'Last;
end loop;
end Compare_Streams;
------------------
-- Copy_Streams --
------------------
procedure Copy_Streams
(Source, Target : in out Ada.Streams.Root_Stream_Type'Class;
Buffer_Size : in Stream_Element_Offset := 1024)
is
Buffer : Stream_Element_Array (1 .. Buffer_Size);
Last : Stream_Element_Offset;
begin
loop
Read (Source, Buffer, Last);
Write (Target, Buffer (1 .. Last));
exit when Last < Buffer'Last;
end loop;
end Copy_Streams;
-------------
-- Data_In --
-------------
procedure Data_In
(Item : out Stream_Element_Array;
Last : out Stream_Element_Offset) is
begin
Read (File_In, Item, Last);
end Data_In;
--------------
-- Data_Out --
--------------
procedure Data_Out (Item : in Stream_Element_Array) is
begin
Write (File_Out, Item);
end Data_Out;
-------------------
-- Generate_File --
-------------------
procedure Generate_File is
subtype Visible_Symbols is Stream_Element range 16#20# .. 16#7E#;
package Random_Elements is
new Ada.Numerics.Discrete_Random (Visible_Symbols);
Gen : Random_Elements.Generator;
Buffer : Stream_Element_Array := (1 .. 77 => 16#20#) & 10;
Buffer_Count : constant Count := File_Size / Buffer'Length;
-- Number of same buffers in the packet.
Density : constant Count := 30; -- from 0 to Buffer'Length - 2;
procedure Fill_Buffer (J, D : in Count);
-- Change the part of the buffer.
-----------------
-- Fill_Buffer --
-----------------
procedure Fill_Buffer (J, D : in Count) is
begin
for K in 0 .. D loop
Buffer
(Stream_Element_Offset ((J + K) mod (Buffer'Length - 1) + 1))
:= Random_Elements.Random (Gen);
end loop;
end Fill_Buffer;
begin
Random_Elements.Reset (Gen, Init_Random);
Create (File_In, Out_File, In_File_Name);
Fill_Buffer (1, Buffer'Length - 2);
for J in 1 .. Buffer_Count loop
Write (File_In, Buffer);
Fill_Buffer (J, Density);
end loop;
-- fill remain size.
Write
(File_In,
Buffer
(1 .. Stream_Element_Offset
(File_Size - Buffer'Length * Buffer_Count)));
Flush (File_In);
Close (File_In);
end Generate_File;
---------------------
-- Print_Statistic --
---------------------
procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count) is
use Ada.Calendar;
use Ada.Text_IO;
package Count_IO is new Integer_IO (ZLib.Count);
Curr_Dur : Duration := Clock - Time_Stamp;
begin
Put (Msg);
Set_Col (20);
Ada.Text_IO.Put ("size =");
Count_IO.Put
(Data_Size,
Width => Stream_IO.Count'Image (File_Size)'Length);
Put_Line (" duration =" & Duration'Image (Curr_Dur));
end Print_Statistic;
-----------
-- Stamp --
-----------
procedure Stamp is
begin
Time_Stamp := Ada.Calendar.Clock;
end Stamp;
begin
Ada.Text_IO.Put_Line ("ZLib " & ZLib.Version);
loop
Generate_File;
for Level in ZLib.Compression_Level'Range loop
Ada.Text_IO.Put_Line ("Level ="
& ZLib.Compression_Level'Image (Level));
-- Test generic interface.
Open (File_In, In_File, In_File_Name);
Create (File_Out, Out_File, Z_File_Name);
Stamp;
-- Deflate using generic instantiation.
ZLib.Deflate_Init
(Filter => Filter,
Level => Level,
Strategy => Strategy,
Header => Header);
Translate (Filter);
Print_Statistic ("Generic compress", ZLib.Total_Out (Filter));
ZLib.Close (Filter);
Close (File_In);
Close (File_Out);
Open (File_In, In_File, Z_File_Name);
Create (File_Out, Out_File, Out_File_Name);
Stamp;
-- Inflate using generic instantiation.
ZLib.Inflate_Init (Filter, Header => Header);
Translate (Filter);
Print_Statistic ("Generic decompress", ZLib.Total_Out (Filter));
ZLib.Close (Filter);
Close (File_In);
Close (File_Out);
Compare_Files (In_File_Name, Out_File_Name);
-- Test stream interface.
-- Compress to the back stream.
Open (File_In, In_File, In_File_Name);
Create (File_Back, Out_File, Z_File_Name);
Stamp;
ZLib.Streams.Create
(Stream => File_Z,
Mode => ZLib.Streams.Out_Stream,
Back => ZLib.Streams.Stream_Access
(Stream (File_Back)),
Back_Compressed => True,
Level => Level,
Strategy => Strategy,
Header => Header);
Copy_Streams
(Source => Stream (File_In).all,
Target => File_Z);
-- Flushing internal buffers to the back stream.
ZLib.Streams.Flush (File_Z, ZLib.Finish);
Print_Statistic ("Write compress",
ZLib.Streams.Write_Total_Out (File_Z));
ZLib.Streams.Close (File_Z);
Close (File_In);
Close (File_Back);
-- Compare reading from original file and from
-- decompression stream.
Open (File_In, In_File, In_File_Name);
Open (File_Back, In_File, Z_File_Name);
ZLib.Streams.Create
(Stream => File_Z,
Mode => ZLib.Streams.In_Stream,
Back => ZLib.Streams.Stream_Access
(Stream (File_Back)),
Back_Compressed => True,
Header => Header);
Stamp;
Compare_Streams (Stream (File_In).all, File_Z);
Print_Statistic ("Read decompress",
ZLib.Streams.Read_Total_Out (File_Z));
ZLib.Streams.Close (File_Z);
Close (File_In);
Close (File_Back);
-- Compress by reading from compression stream.
Open (File_Back, In_File, In_File_Name);
Create (File_Out, Out_File, Z_File_Name);
ZLib.Streams.Create
(Stream => File_Z,
Mode => ZLib.Streams.In_Stream,
Back => ZLib.Streams.Stream_Access
(Stream (File_Back)),
Back_Compressed => False,
Level => Level,
Strategy => Strategy,
Header => Header);
Stamp;
Copy_Streams
(Source => File_Z,
Target => Stream (File_Out).all);
Print_Statistic ("Read compress",
ZLib.Streams.Read_Total_Out (File_Z));
ZLib.Streams.Close (File_Z);
Close (File_Out);
Close (File_Back);
-- Decompress to decompression stream.
Open (File_In, In_File, Z_File_Name);
Create (File_Back, Out_File, Out_File_Name);
ZLib.Streams.Create
(Stream => File_Z,
Mode => ZLib.Streams.Out_Stream,
Back => ZLib.Streams.Stream_Access
(Stream (File_Back)),
Back_Compressed => False,
Header => Header);
Stamp;
Copy_Streams
(Source => Stream (File_In).all,
Target => File_Z);
Print_Statistic ("Write decompress",
ZLib.Streams.Write_Total_Out (File_Z));
ZLib.Streams.Close (File_Z);
Close (File_In);
Close (File_Back);
Compare_Files (In_File_Name, Out_File_Name);
end loop;
Ada.Text_IO.Put_Line (Count'Image (File_Size) & " Ok.");
exit when not Continuous;
File_Size := File_Size + 1;
end loop;
end Test;
|
reznikmm/matreshka | Ada | 3,981 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Db_Media_Type_Attributes;
package Matreshka.ODF_Db.Media_Type_Attributes is
type Db_Media_Type_Attribute_Node is
new Matreshka.ODF_Db.Abstract_Db_Attribute_Node
and ODF.DOM.Db_Media_Type_Attributes.ODF_Db_Media_Type_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Db_Media_Type_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Db_Media_Type_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Db.Media_Type_Attributes;
|
AdaCore/libadalang | Ada | 2,503 | adb | procedure Test is
package Pkg is
type T is tagged null record;
procedure Foo (X : T) is null;
procedure Foo (X : T; Y : Integer) is null;
function Foo return T is (null record);
end Pkg;
package Derived is
type U is new Pkg.T with null record;
overriding procedure Foo (X : U) is null;
type R is new Pkg.T with null record;
overriding procedure Foo (X : R) is null;
end Derived;
package Derived_2 is
type V is new Derived.U with null record;
overriding procedure Foo (X : V) is null;
overriding procedure Foo (X : V; Y : Integer) is null;
overriding function Foo return V is (null record);
end Derived_2;
package Interfaces is
type I is interface;
type J is interface;
procedure Foo (X : I) is abstract;
procedure Foo (X : J) is abstract;
end Interfaces;
package Interfaces_2 is
type K is interface and Interfaces.I and Interfaces.J;
overriding procedure Foo (X : K) is null;
end Interfaces_2;
package Derived_4 is
type D is new Derived_2.V and Interfaces_2.K with null record;
overriding procedure Foo (X : D) is null;
end Derived_4;
package T925_013_Base is
type T is tagged null record;
function Foo (X : T) return T'Class is (X);
end T925_013_Base;
package T925_013_Derived is
type U is new T925_013_Base.T with null record;
overriding function Foo (X : U) return T925_013_Base.T'Class is (X);
end T925_013_Derived;
package T925_015 is
type T is tagged null record;
function Foo (X : T) return T;
private
function Foo (X : T) return T is (X);
end T925_015;
package TB14_004 is
type T is tagged null record;
procedure Foo (X : T) is null;
private
type U;
end TB14_004;
package body TB14_004 is
type U is new T with null record;
overriding procedure Foo (X : U) is null;
end TB14_004;
package TC17_033 is
type A is abstract tagged
null record;
type B is abstract new A with
null record;
procedure Foo (Arg : B) is abstract;
type C is new A with private;
private
type C is new B with
null record;
overriding
procedure Foo (Arg : C);
end TC17_033;
procedure U812_023 is
type U is new Pkg.T with null record;
overriding procedure Foo (X : U) is null;
begin
null;
end U812_023;
begin
null;
end Test;
|
AdaCore/gpr | Ada | 1,310 | adb | --
-- Copyright (C) 2020-2022, AdaCore
-- SPDX-License-Identifier: Apache-2.0
--
package body Gpr_Parser_Support.Symbols.Precomputed is
-------------------------
-- Create_Symbol_Table --
-------------------------
function Create_Symbol_Table return Precomputed_Symbol_Table is
begin
return Result : constant Precomputed_Symbol_Table
:= new Precomputed_Symbol_Table_Record do
for I in Precomputed_Symbol_Index'Range loop
Result.Precomputed (I) := Find
(Symbol_Table (Result), Precomputed_Symbol (I));
end loop;
end return;
end Create_Symbol_Table;
------------------------
-- Precomputed_Symbol --
------------------------
function Precomputed_Symbol
(ST : Precomputed_Symbol_Table;
Index : Precomputed_Symbol_Index) return Symbol_Type
is
begin
return Get_Symbol (Symbol_Table (ST), Precomputed_Symbol (ST, Index));
end Precomputed_Symbol;
------------------------
-- Precomputed_Symbol --
------------------------
function Precomputed_Symbol
(ST : Precomputed_Symbol_Table;
Index : Precomputed_Symbol_Index) return Thin_Symbol
is
begin
return ST.Precomputed (Index);
end Precomputed_Symbol;
end Gpr_Parser_Support.Symbols.Precomputed;
|
reznikmm/matreshka | Ada | 6,822 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Office.Styles_Elements is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Office_Styles_Element_Node is
begin
return Self : Office_Styles_Element_Node do
Matreshka.ODF_Office.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Office_Prefix);
end return;
end Create;
----------------
-- Enter_Node --
----------------
overriding procedure Enter_Node
(Self : not null access Office_Styles_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Enter_Office_Styles
(ODF.DOM.Office_Styles_Elements.ODF_Office_Styles_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Enter_Node (Visitor, Control);
end if;
end Enter_Node;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Office_Styles_Element_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Styles_Element;
end Get_Local_Name;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Office_Styles_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Leave_Office_Styles
(ODF.DOM.Office_Styles_Elements.ODF_Office_Styles_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Leave_Node (Visitor, Control);
end if;
end Leave_Node;
----------------
-- Visit_Node --
----------------
overriding procedure Visit_Node
(Self : not null access Office_Styles_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then
ODF.DOM.Iterators.Abstract_ODF_Iterator'Class
(Iterator).Visit_Office_Styles
(Visitor,
ODF.DOM.Office_Styles_Elements.ODF_Office_Styles_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Visit_Node (Iterator, Visitor, Control);
end if;
end Visit_Node;
begin
Matreshka.DOM_Documents.Register_Element
(Matreshka.ODF_String_Constants.Office_URI,
Matreshka.ODF_String_Constants.Styles_Element,
Office_Styles_Element_Node'Tag);
end Matreshka.ODF_Office.Styles_Elements;
|
reznikmm/matreshka | Ada | 3,709 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Elements;
package ODF.DOM.Style_Background_Image_Elements is
pragma Preelaborate;
type ODF_Style_Background_Image is limited interface
and XML.DOM.Elements.DOM_Element;
type ODF_Style_Background_Image_Access is
access all ODF_Style_Background_Image'Class
with Storage_Size => 0;
end ODF.DOM.Style_Background_Image_Elements;
|
AdaCore/libadalang | Ada | 140 | ads | package Pkg is
type T is null record;
generic
package Nested is
procedure Proc;
end Nested;
procedure Stub;
end Pkg;
|
AdaCore/gpr | Ada | 13,660 | adb | --
-- Copyright (C) 2020-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
--
with Ada.Unchecked_Conversion;
with Interfaces.C.Strings;
with GPR2.View_Ids;
with GPR2.Context;
with System.Storage_Elements;
package body GPR2.C.JSON is
use type GNATCOLL.JSON.JSON_Value;
use type GNATCOLL.JSON.JSON_Value_Type;
function Convert is new Ada.Unchecked_Conversion
(Interfaces.C.Strings.chars_ptr, C_Answer);
function Get_Address
(Obj : JSON_Value; Key : String) return System.Address;
function Has_Non_Null_Field
(Obj : JSON_Value; Key : String) return Boolean
is
(GNATCOLL.JSON.Has_Field (Val => Obj, Field => Key) and then
GNATCOLL.JSON.Get (Val => Obj, Field => Key) /= GNATCOLL.JSON.JSON_Null);
-- Return True if Obj contains a non null field named Key
----------
-- Bind --
----------
function Bind
(Request : C_Request;
Answer : out C_Answer;
Handler : Bind_Handler) return C_Status
is
Answer_Obj : constant JSON_Value := Initialize_Answer;
Request_Obj : JSON.JSON_Value;
Result_Obj : JSON_Value;
Can_Decode : Boolean := True;
begin
Result_Obj := Get_Result (Answer_Obj);
-- Until this stage an error can only occur if there is a lack of
-- memory in which case nothing can really be done.
begin
Request_Obj := Decode (Request);
exception
when E : others =>
-- Error detected during parsing of the request JSON
Set_Status (Answer_Obj, Invalid_Request, E);
Can_Decode := False;
end;
if Can_Decode then
begin
Handler (Request => Request_Obj, Result => Result_Obj);
exception
when E : others =>
Set_Status (Answer_Obj, Call_Error, E);
end;
end if;
-- Unless there is a bug in the GNATCOLL.JSON library, all relevant
-- errors have been caught. No exception is expected from here.
Answer := Encode (Answer_Obj);
return Get_Status (Answer_Obj);
end Bind;
------------
-- Decode --
------------
function Decode (Request : C_Request) return JSON_Value is
begin
return GNATCOLL.JSON.Read (Value (Request));
end Decode;
------------
-- Encode --
------------
function Encode (Answer : JSON.JSON_Value) return C_Answer is
use Interfaces.C.Strings;
Result : constant chars_ptr :=
New_String (GNATCOLL.JSON.Write (Answer));
begin
return Convert (Result);
end Encode;
---------
-- Get --
---------
function Get (Obj : JSON_Value; Key : String) return JSON_Value is
begin
return GNATCOLL.JSON.Get (Obj, Key);
end Get;
-----------------
-- Get_Address --
-----------------
function Get_Address
(Obj : JSON_Value; Key : String) return System.Address
is
use System.Storage_Elements;
Str : constant String := GNATCOLL.JSON.Get (Obj, Key);
Addr_Int : constant Integer_Address := Integer_Address'Value (Str);
begin
return To_Address (Addr_Int);
end Get_Address;
----------------------
-- Get_GPR_Tree --
----------------------
function Get_GPR_Tree
(Obj : JSON_Value; Key : String) return GPR_Tree_Access
is
function Convert is new Ada.Unchecked_Conversion
(System.Address, GPR_Tree_Access);
begin
return Convert (Get_Address (Obj, Key));
end Get_GPR_Tree;
----------------------
-- Get_Level_Format --
----------------------
function Get_Level_Format
(Obj : JSON_Value;
Key : String;
Default : GPR2.Message.Level_Format)
return GPR2.Message.Level_Format is
begin
if not Has_Non_Null_Field (Obj => Obj, Key => Key) then
return Default;
else
declare
Value : constant String := To_String (Get (Obj, Key));
begin
if Value = "short" then
return GPR2.Message.Short;
elsif Value = "none" then
return GPR2.Message.None;
else
return GPR2.Message.Long;
end if;
end;
end if;
end Get_Level_Format;
----------------------
-- Get_Level_Output --
----------------------
function Get_Level_Output
(Obj : JSON_Value;
Default : GPR2.Message.Level_Output)
return GPR2.Message.Level_Output
is
Level_Output : GPR2.Message.Level_Output;
begin
Level_Output (GPR2.Message.Information) :=
Get_Level_Format
(Obj, "information_level_output",
Default (GPR2.Message.Information));
Level_Output (GPR2.Message.Warning) :=
Get_Level_Format
(Obj, "warning_level_output", Default (GPR2.Message.Warning));
Level_Output (GPR2.Message.Error) :=
Get_Level_Format
(Obj, "error_level_output", Default (GPR2.Message.Error));
return Level_Output;
end Get_Level_Output;
------------------------
-- Get_Name_Value_Map --
------------------------
function Get_Name_Value_Map
(Obj : JSON_Value; Key : String) return GPR2.Containers.Name_Value_Map
is
Result : GPR2.Containers.Name_Value_Map;
procedure CB
(Name : GNATCOLL.JSON.UTF8_String;
Value : GNATCOLL.JSON.JSON_Value);
--------
-- CB --
--------
procedure CB
(Name : GNATCOLL.JSON.UTF8_String;
Value : GNATCOLL.JSON.JSON_Value) is
begin
Result.Insert (Optional_Name_Type (Name), Value.Get);
end CB;
begin
if Has_Non_Null_Field (Obj => Obj, Key => Key) then
GNATCOLL.JSON.Map_JSON_Object
(Val => GNATCOLL.JSON.Get (Obj, Key),
CB => CB'Unrestricted_Access);
end if;
return Result;
end Get_Name_Value_Map;
----------------
-- Get_Result --
----------------
function Get_Result (Obj : JSON_Value) return JSON_Value is
begin
return GNATCOLL.JSON.Get (Obj, "result");
end Get_Result;
----------------
-- Get_Status --
----------------
function Get_Status (Obj : JSON_Value) return C_Status is
I : constant Integer := GNATCOLL.JSON.Get (Obj, "status");
begin
return C_Status (I);
end Get_Status;
-----------------------
-- Initialize_Answer --
-----------------------
function Initialize_Answer return JSON_Value is
Answer : constant JSON_Value := GNATCOLL.JSON.Create_Object;
begin
GNATCOLL.JSON.Set_Field (Answer, "result", GNATCOLL.JSON.Create_Object);
Set_Status (Answer, 0);
return Answer;
end Initialize_Answer;
---------
-- Set --
---------
procedure Set (Obj : JSON_Value; Key : String; Value : JSON_Value) is
begin
GNATCOLL.JSON.Set_Field (Obj, Key, Value);
end Set;
----------------
-- Set_Status --
----------------
procedure Set_Status
(Obj : JSON_Value;
Value : C_Status) is
begin
GNATCOLL.JSON.Set_Field (Obj, "status", Integer (Value));
GNATCOLL.JSON.Set_Field (Obj, "error_msg", "");
GNATCOLL.JSON.Set_Field (Obj, "error_name", "");
end Set_Status;
procedure Set_Status
(Obj : JSON_Value;
Value : C_Status;
E : Ada.Exceptions.Exception_Occurrence) is
begin
GNATCOLL.JSON.Set_Field (Obj, "status", Integer (Value));
GNATCOLL.JSON.Set_Field
(Obj, "error_msg", Ada.Exceptions.Exception_Message (E));
GNATCOLL.JSON.Set_Field
(Obj, "error_name", Ada.Exceptions.Exception_Name (E));
end Set_Status;
----------------
-- To_Boolean --
----------------
function To_Boolean (Obj : JSON_Value; Default : Boolean) return Boolean is
begin
if GNATCOLL.JSON."="(Obj, GNATCOLL.JSON.JSON_Null) then
return Default;
else
return GNATCOLL.JSON.Get (Val => Obj);
end if;
end To_Boolean;
----------------
-- To_Context --
----------------
function To_Context (Obj : JSON_Value) return GPR_Context
is
Result : GPR_Context;
procedure CB
(Name : GNATCOLL.JSON.UTF8_String;
Value : GNATCOLL.JSON.JSON_Value);
--------
-- CB --
--------
procedure CB
(Name : GNATCOLL.JSON.UTF8_String;
Value : GNATCOLL.JSON.JSON_Value) is
begin
Result.Insert
(Optional_Name_Type (Name), Value_Type (To_String (Value)));
end CB;
begin
if GNATCOLL.JSON.Kind (Obj) = GNATCOLL.JSON.JSON_Object_Type then
GNATCOLL.JSON.Map_JSON_Object
(Val => Obj,
CB => CB'Unrestricted_Access);
elsif GNATCOLL.JSON.Kind (Obj) /= GNATCOLL.JSON.JSON_Null_Type then
raise GPR2_C_Exception with "expected context json value";
end if;
return Result;
end To_Context;
-----------------
-- To_Filename --
-----------------
function To_Filename
(Obj : JSON_Value) return GPR2.Filename_Type
is
begin
return GPR2.Filename_Type (To_String (Obj));
end To_Filename;
---------------------
-- To_GPR_View --
---------------------
function To_GPR_View
(Tree : GPR_Tree; Obj : JSON_Value) return GPR_View
is
Id : GPR2.View_Ids.View_Id;
begin
Id := GPR2.View_Ids.Import (Value_Type (To_Name (Obj)));
return Tree.Instance_Of (Instance_Id => Id);
end To_GPR_View;
-----------------------
-- To_Lang_Value_Map --
-----------------------
function To_Lang_Value_Map
(Obj : JSON_Value) return GPR2.Containers.Lang_Value_Map
is
Result : GPR2.Containers.Lang_Value_Map;
procedure CB
(Name : GNATCOLL.JSON.UTF8_String;
Value : GNATCOLL.JSON.JSON_Value);
--------
-- CB --
--------
procedure CB
(Name : GNATCOLL.JSON.UTF8_String;
Value : GNATCOLL.JSON.JSON_Value) is
begin
Result.Insert (GPR2."+" (GPR2.Optional_Name_Type (Name)), Value.Get);
end CB;
begin
if GNATCOLL.JSON.Kind (Obj) = GNATCOLL.JSON.JSON_Object_Type then
GNATCOLL.JSON.Map_JSON_Object
(Val => Obj,
CB => CB'Unrestricted_Access);
elsif GNATCOLL.JSON.Kind (Obj) /= GNATCOLL.JSON.JSON_Null_Type then
raise GPR2_C_Exception with "lang_value_map expected";
end if;
return Result;
end To_Lang_Value_Map;
-----------------
-- To_Language --
-----------------
function To_Language
(Obj : JSON_Value) return GPR2.Language_Id
is
begin
return GPR2."+" (To_Name (Obj));
end To_Language;
-----------------------
-- To_Name_Value_Map --
-----------------------
function To_Name_Value_Map
(Obj : JSON_Value) return GPR2.Containers.Name_Value_Map
is
Result : GPR2.Containers.Name_Value_Map;
procedure CB
(Name : GNATCOLL.JSON.UTF8_String;
Value : GNATCOLL.JSON.JSON_Value);
--------
-- CB --
--------
procedure CB
(Name : GNATCOLL.JSON.UTF8_String;
Value : GNATCOLL.JSON.JSON_Value) is
begin
Result.Insert (GPR2.Optional_Name_Type (Name), Value.Get);
end CB;
begin
GNATCOLL.JSON.Map_JSON_Object
(Val => Obj,
CB => CB'Unrestricted_Access);
return Result;
end To_Name_Value_Map;
------------------
-- To_Path_Name --
------------------
function To_Path_Name (Obj : JSON_Value) return GPR2.Path_Name.Object is
begin
return GPR2.Path_Name.Create_File (Name => To_Filename (Obj));
end To_Path_Name;
----------------------
-- To_Path_Name_Set --
----------------------
function To_Path_Name_Set
(Obj : JSON_Value) return GPR2.Path_Name.Set.Object
is
Result : GPR2.Path_Name.Set.Object;
begin
if GNATCOLL.JSON.Kind (Obj) = GNATCOLL.JSON.JSON_Array_Type then
declare
Arr : constant JSON_Array := GNATCOLL.JSON.Get (Obj);
begin
for Value of Arr loop
Result.Append
(GPR2.Path_Name.Create_File (Name => To_Filename (Value)));
end loop;
end;
elsif GNATCOLL.JSON.Kind (Obj) /= GNATCOLL.JSON.JSON_Null_Type then
raise GPR2_C_Exception with "path_name list expected";
end if;
return Result;
end To_Path_Name_Set;
---------------
-- To_String --
---------------
function To_String (Obj : JSON_Value) return String
is
begin
if GNATCOLL.JSON.Kind (Obj) = GNATCOLL.JSON.JSON_String_Type then
return GNATCOLL.JSON.Get (Obj);
else
raise GPR2_C_Exception with "expected string type (got " &
GNATCOLL.JSON.JSON_Value_Type'Image (GNATCOLL.JSON.Kind (Obj)) & ")";
end if;
end To_String;
function To_String (Obj : JSON_Value; Default : String) return String is
begin
if GNATCOLL.JSON.Kind (Obj) = GNATCOLL.JSON.JSON_Null_Type then
return Default;
else
return To_String (Obj);
end if;
end To_String;
function To_Unit_Index
(Obj : JSON_Value; Default : Unit_Index) return Unit_Index
is
begin
if GNATCOLL.JSON.Kind (Obj) = GNATCOLL.JSON.JSON_Int_Type then
declare
Obj_Int : constant Integer := GNATCOLL.JSON.Get (Obj);
begin
return Unit_Index (Obj_Int);
end;
elsif GNATCOLL.JSON.Kind (Obj) = GNATCOLL.JSON.JSON_Null_Type then
return Default;
else
raise GPR2_C_Exception with "expected unit_index";
end if;
end To_Unit_Index;
end GPR2.C.JSON;
|
kjseefried/coreland-cgbc | Ada | 993 | adb | with Ada.Strings;
with CGBC.Bounded_Strings;
with Test;
procedure T_Bstr_Element_01 is
package BS renames CGBC.Bounded_Strings;
TC : Test.Context_t;
S1 : BS.Bounded_String (8);
Error : Boolean;
E : Character;
begin
Test.Initialize
(Test_Context => TC,
Program => "t_bstr_element_01",
Test_DB => "TEST_DB",
Test_Results => "TEST_RESULTS");
BS.Append (S1, "ABCD");
pragma Assert (BS.Length (S1) = 4);
Test.Check (TC, 251, BS.Element (S1, 1) = 'A', "BS.Element (S1, 1) = 'A'");
Test.Check (TC, 252, BS.Element (S1, 2) = 'B', "BS.Element (S1, 2) = 'B'");
Test.Check (TC, 253, BS.Element (S1, 3) = 'C', "BS.Element (S1, 3) = 'C'");
Test.Check (TC, 254, BS.Element (S1, 4) = 'D', "BS.Element (S1, 4) = 'D'");
Error := False;
begin
E := BS.Element (S1, 5);
pragma Assert (not E'Valid);
exception
when Ada.Strings.Index_Error => Error := True;
end;
Test.Check (TC, 255, Error, "Error");
end T_Bstr_Element_01;
|
reznikmm/matreshka | Ada | 3,684 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Draw_Code_Attributes is
pragma Preelaborate;
type ODF_Draw_Code_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Draw_Code_Attribute_Access is
access all ODF_Draw_Code_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Draw_Code_Attributes;
|
reznikmm/matreshka | Ada | 12,302 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Internals.OCL_Elements;
with AMF.OCL.Tuple_Literal_Parts;
with AMF.UML.Comments.Collections;
with AMF.UML.Dependencies.Collections;
with AMF.UML.Elements.Collections;
with AMF.UML.Named_Elements;
with AMF.UML.Namespaces.Collections;
with AMF.UML.Packages.Collections;
with AMF.UML.Properties;
with AMF.UML.String_Expressions;
with AMF.UML.Types;
with AMF.Visitors;
package AMF.Internals.OCL_Tuple_Literal_Parts is
type OCL_Tuple_Literal_Part_Proxy is
limited new AMF.Internals.OCL_Elements.OCL_Element_Proxy
and AMF.OCL.Tuple_Literal_Parts.OCL_Tuple_Literal_Part with null record;
overriding function Get_Attribute
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Properties.UML_Property_Access;
-- Getter of TupleLiteralPart::attribute.
--
overriding procedure Set_Attribute
(Self : not null access OCL_Tuple_Literal_Part_Proxy;
To : AMF.UML.Properties.UML_Property_Access);
-- Setter of TupleLiteralPart::attribute.
--
overriding function Get_Type
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Types.UML_Type_Access;
-- Getter of TypedElement::type.
--
-- The type of the TypedElement.
-- This information is derived from the return result for this Operation.
overriding procedure Set_Type
(Self : not null access OCL_Tuple_Literal_Part_Proxy;
To : AMF.UML.Types.UML_Type_Access);
-- Setter of TypedElement::type.
--
-- The type of the TypedElement.
-- This information is derived from the return result for this Operation.
overriding function Get_Client_Dependency
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Dependencies.Collections.Set_Of_UML_Dependency;
-- Getter of NamedElement::clientDependency.
--
-- Indicates the dependencies that reference the client.
overriding function Get_Name
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.Optional_String;
-- Getter of NamedElement::name.
--
-- The name of the NamedElement.
overriding procedure Set_Name
(Self : not null access OCL_Tuple_Literal_Part_Proxy;
To : AMF.Optional_String);
-- Setter of NamedElement::name.
--
-- The name of the NamedElement.
overriding function Get_Name_Expression
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.String_Expressions.UML_String_Expression_Access;
-- Getter of NamedElement::nameExpression.
--
-- The string expression used to define the name of this named element.
overriding procedure Set_Name_Expression
(Self : not null access OCL_Tuple_Literal_Part_Proxy;
To : AMF.UML.String_Expressions.UML_String_Expression_Access);
-- Setter of NamedElement::nameExpression.
--
-- The string expression used to define the name of this named element.
overriding function Get_Namespace
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access;
-- Getter of NamedElement::namespace.
--
-- Specifies the namespace that owns the NamedElement.
overriding function Get_Qualified_Name
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.Optional_String;
-- Getter of NamedElement::qualifiedName.
--
-- A name which allows the NamedElement to be identified within a
-- hierarchy of nested Namespaces. It is constructed from the names of the
-- containing namespaces starting at the root of the hierarchy and ending
-- with the name of the NamedElement itself.
overriding function Get_Visibility
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Optional_UML_Visibility_Kind;
-- Getter of NamedElement::visibility.
--
-- Determines where the NamedElement appears within different Namespaces
-- within the overall model, and its accessibility.
overriding procedure Set_Visibility
(Self : not null access OCL_Tuple_Literal_Part_Proxy;
To : AMF.UML.Optional_UML_Visibility_Kind);
-- Setter of NamedElement::visibility.
--
-- Determines where the NamedElement appears within different Namespaces
-- within the overall model, and its accessibility.
overriding function Get_Owned_Comment
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Comments.Collections.Set_Of_UML_Comment;
-- Getter of Element::ownedComment.
--
-- The Comments owned by this element.
overriding function Get_Owned_Element
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Elements.Collections.Set_Of_UML_Element;
-- Getter of Element::ownedElement.
--
-- The Elements owned by this element.
overriding function Get_Owner
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Elements.UML_Element_Access;
-- Getter of Element::owner.
--
-- The Element that owns this element.
overriding function All_Namespaces
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Namespaces.Collections.Ordered_Set_Of_UML_Namespace;
-- Operation NamedElement::allNamespaces.
--
-- The query allNamespaces() gives the sequence of namespaces in which the
-- NamedElement is nested, working outwards.
overriding function All_Owning_Packages
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Packages.Collections.Set_Of_UML_Package;
-- Operation NamedElement::allOwningPackages.
--
-- The query allOwningPackages() returns all the directly or indirectly
-- owning packages.
overriding function Is_Distinguishable_From
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy;
N : AMF.UML.Named_Elements.UML_Named_Element_Access;
Ns : AMF.UML.Namespaces.UML_Namespace_Access)
return Boolean;
-- Operation NamedElement::isDistinguishableFrom.
--
-- The query isDistinguishableFrom() determines whether two NamedElements
-- may logically co-exist within a Namespace. By default, two named
-- elements are distinguishable if (a) they have unrelated types or (b)
-- they have related types but different names.
overriding function Namespace
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access;
-- Operation NamedElement::namespace.
--
-- Missing derivation for NamedElement::/namespace : Namespace
overriding function Qualified_Name
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return League.Strings.Universal_String;
-- Operation NamedElement::qualifiedName.
--
-- When there is a name, and all of the containing namespaces have a name,
-- the qualified name is constructed from the names of the containing
-- namespaces.
overriding function Separator
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return League.Strings.Universal_String;
-- Operation NamedElement::separator.
--
-- The query separator() gives the string that is used to separate names
-- when constructing a qualified name.
overriding function All_Owned_Elements
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return AMF.UML.Elements.Collections.Set_Of_UML_Element;
-- Operation Element::allOwnedElements.
--
-- The query allOwnedElements() gives all of the direct and indirect owned
-- elements of an element.
overriding function Must_Be_Owned
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy)
return Boolean;
-- Operation Element::mustBeOwned.
--
-- The query mustBeOwned() indicates whether elements of this type must
-- have an owner. Subclasses of Element that do not require an owner must
-- override this operation.
overriding procedure Enter_Element
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
overriding procedure Leave_Element
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
overriding procedure Visit_Element
(Self : not null access constant OCL_Tuple_Literal_Part_Proxy;
Iterator : in out AMF.Visitors.Abstract_Iterator'Class;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
end AMF.Internals.OCL_Tuple_Literal_Parts;
|
jhumphry/auto_counters | Ada | 6,235 | ads | -- protected_refcounted_flyweights.ads
-- A package for ensuring resources are not duplicated in a manner similar
-- to the C++ Boost flyweight classes. This package provides a task-safe
-- implementation that uses reference counting to release resources when the
-- last reference is released
-- Copyright (c) 2016-2021, James Humphry
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.
pragma Profile (No_Implementation_Extensions);
with Ada.Containers;
with Flyweights.Refcounted_Lists;
with Flyweights.Protected_Hashtables;
with Flyweights.Refcounted_Ptrs;
generic
type Element(<>) is limited private;
type Element_Access is access Element;
with function Hash (E : Element) return Ada.Containers.Hash_Type;
Capacity : Ada.Containers.Hash_Type := 256;
with function "=" (Left, Right : in Element) return Boolean is <>;
package Protected_Refcounted_Flyweights is
package Lists is
new Flyweights.Refcounted_Lists(Element => Element,
Element_Access => Element_Access,
"=" => "=");
package Hashtables is
new Flyweights.Protected_Hashtables(Element => Element,
Element_Access => Element_Access,
Hash => Hash,
Lists_Spec => Lists.Lists_Spec,
Capacity => Capacity);
package Ptrs is
new Flyweights.Refcounted_Ptrs(Element => Element,
Element_Access => Element_Access,
Flyweight_Hashtables => Hashtables.Hashtables_Spec);
subtype Flyweight is Hashtables.Flyweight;
-- This Flyweight type is an implementation of the flyweight pattern, which
-- helps prevent the resource usage caused by the storage of duplicate
-- values. Reference counting is used to release resources when they are
-- no longer required. This implementation is protected so it is safe to
-- use even if multiple tasks could attempt to add or remove resources
-- simultaneously.
subtype E_Ref is Ptrs.E_Ref;
-- This is a generic generalised reference type which is used to make
-- Element_Ptr easier to use and which should not be stored or reused.
subtype Element_Ptr is Ptrs.Refcounted_Element_Ptr;
-- The Element_Ptr type points to a resource inside a Flyweight. It is
-- reference-counted (shared with Element_Ref) so that when the last
-- Element_Ptr or Element_Ref pointing to a resource is destroyed, the
-- resource will be deallocated as well. The 'Get' function returns an
-- access value to the resource.
subtype Element_Ref is Ptrs.Refcounted_Element_Ref;
-- The Element_Ref type points to a resource inside a Flyweight. It is
-- reference-counted (shared with Element_Ptr) so that when the last
-- Element_Ptr or Element_Ref pointing to a resource is destroyed, the
-- resource will be deallocated as well. The Element_Ref type can be
-- implicitly derefenced to return the resource.
function P (P : Ptrs.Refcounted_Element_Ptr) return E_Ref
renames Ptrs.P;
-- P returns an E_Ref which is a generalised reference to the stored value.
-- This is an alternative to calling the Get function and dereferencing the
-- access value returned with '.all'.
function Get (P : Ptrs.Refcounted_Element_Ptr) return Element_Access
renames Ptrs.Get;
-- Get returns an access value that points to a resource inside a
-- Flyweight.
function Get (P : Ptrs.Refcounted_Element_Ref) return Element_Access
renames Ptrs.Get;
-- Get returns an access value that points to a resource inside a
-- Flyweight.
function Make_Ref (P : Ptrs.Refcounted_Element_Ptr'Class)
return Ptrs.Refcounted_Element_Ref
renames Ptrs.Make_Ref;
-- Make_Ref converts a Refcounted_Element_Ptr into a Refcounted_Element_Ref.
function Insert_Ptr (F : aliased in out Hashtables.Flyweight;
E : in out Element_Access)
return Ptrs.Refcounted_Element_Ptr
renames Ptrs.Insert_Ptr;
-- Insert_Ptr looks to see if the Element pointed to by E already exists
-- inside the Flyweight F. If so, the Element pointed to by E is deallocated
-- and E is set to the existing copy. Otherwise, F stores E for future use. A
-- Refcounted_Element_Ptr is returned.
function Make_Ptr (R : Ptrs.Refcounted_Element_Ref'Class)
return Ptrs.Refcounted_Element_Ptr
renames Ptrs.Make_Ptr;
-- Make_Ref converts a Refcounted_Element_Ref into a Refcounted_Element_Ptr.
function Insert_Ref (F : aliased in out Hashtables.Flyweight;
E : in out Element_Access)
return Ptrs.Refcounted_Element_Ref
renames Ptrs.Insert_Ref;
-- Insert_Ref looks to see if the Element pointed to by E already exists
-- inside the Flyweight F. If so, the Element pointed to by E is deallocated
-- and E is set to the existing copy. Otherwise, F stores E for future use. A
-- Refcounted_Element_Ref is returned.
-- Note - ideally Insert_Ptr and Insert_Ref could both be overloadings of
-- Insert. However this seems to cause problems for GNAT GPL 2015 so for now
-- the type is suffixed to the name.
end Protected_Refcounted_Flyweights;
|
reznikmm/matreshka | Ada | 3,600 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Elements.Generic_Hash;
function AMF.UML.Use_Cases.Hash is
new AMF.Elements.Generic_Hash (UML_Use_Case, UML_Use_Case_Access);
|
reznikmm/matreshka | Ada | 4,617 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Office.Dde_Topic_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Office_Dde_Topic_Attribute_Node is
begin
return Self : Office_Dde_Topic_Attribute_Node do
Matreshka.ODF_Office.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Office_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Office_Dde_Topic_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Dde_Topic_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Office_URI,
Matreshka.ODF_String_Constants.Dde_Topic_Attribute,
Office_Dde_Topic_Attribute_Node'Tag);
end Matreshka.ODF_Office.Dde_Topic_Attributes;
|
burratoo/Acton | Ada | 13,218 | ads | ------------------------------------------------------------------------------------------
-- --
-- OAK PROCESSOR SUPPORT PACKAGE --
-- FREESCALE MPC5544 --
-- --
-- MPC5554.EMIOS --
-- --
-- Copyright (C) 2010-2021, Patrick Bernardi --
-- --
------------------------------------------------------------------------------------------
with System.Storage_Elements; use System.Storage_Elements;
package MPC5554.eMIOS with Preelaborate is
-- Disable forced biased representation warning.
pragma Warnings (".B");
----------------------------------------------------------------------------
-- Memory Addresses
----------------------------------------------------------------------------
EMIOS_Base_Address : constant Integer_Address := 16#C3FA_0000#;
GFR_Offset_Address : constant Integer_Address := 16#0004#;
Unified_Channel_Offset_Address : constant Integer_Address := 16#0020#;
----------------------------------------------------------------------------
-- Hardware Features
----------------------------------------------------------------------------
type EMIOS_ID_Type is range 0 .. 23;
Unified_Channel_Type_Size : constant Integer := 256;
Channel_Register_Size : constant Integer := 24;
----------------------------------------------------------------------------
-- eMIOS Types
---------------------------------------------------------------------------
-- Common Types
-- eMIOS Module Configuration Register
type MDIS_Type is (Enable, Disable);
type ETB_Type is (Unified_Channel_23, STAC);
type SRV_Type is (eTPUA_TCR1, eTPUB_TCR1, eTPUA_TCR2, eTPUB_TCR2);
type GPRE_Type is range 1 .. 256;
type Module_Configuration_Type is record
Module_Disable : MDIS_Type;
Freeze : Enable_Type;
Global_Time_Base_Enable : Enable_Type;
External_Time_Base : ETB_Type;
Global_Prescale_Enable : Enable_Type;
Server_Time_Slot : SRV_Type;
Global_Prescaler : GPRE_Type;
end record;
-- eMIOS Channel Data Register
type Channel_Register_Type is range 0 .. 16#FF_FFFF#;
for Channel_Register_Type'Size use Channel_Register_Size;
type ODISSL_Type is range 0 .. 3;
type Divide_Ratio is range 1 .. 4;
type DMA_Select_Type is (Interrupt, DMA);
type IF_Type is (Bypass, Two, Four, Eight, Sixteen);
type FCL_Type is (Prescaled, Main);
type BSL_Type is (A, BCD, Internal);
type Mode_Type is (
GPIO_Input,
GPIO_Output,
Single_Action_Input_Capture,
Single_Action_Output_Compare,
Input_Pulse_Width_Measurement,
Input_Period_Measurement,
Doblue_Action_Output_Compare_Second_Match,
Double_Action_Output_Compare_Both_Match,
Pulse_Edge_Accumulation_Continuous,
Pulse_Edge_Accumlation_Single,
Pulse_Edge_Counting_Continuous,
Pulse_Edge_Counting_Single,
Quadrature_Decode_1,
Quadrature_Decode_2,
Windowed_Programmable_Time_Accumulation,
Modulus_Counter_Up_Internal,
Modulus_Counter_Up_External,
Modulus_Counter_Up_Down_No_Change_Internal,
Modulus_Counter_Up_Down_No_Change_External,
Modulus_Counter_Up_Down_Change_Internal,
Modulus_Counter_Up_Down_Change_External,
Output_Pulse_Width_and_Frequency_Modulation_1,
Output_Pulse_Width_and_Frequency_Modulation_2,
Output_Pulse_Width_and_Frequency_Modulation_3,
Output_Pulse_Width_and_Frequency_Modulation_4,
Centre_Aligned_PWM_1,
Centre_Aligned_PWM_2,
Centre_Aligned_PWM_3,
Centre_Aligned_PWM_4,
Output_PWM_1,
Output_PWM_2,
Output_PWM_3,
Output_PWM_4,
Modulus_Up_Counter_Buffered_Internal,
Modulus_Up_Counter_Buffered_External,
Modulus_Up_Down_Counter_Buffered_1,
Modulus_Up_Down_Counter_Buffered_2,
Modulus_Up_Down_Counter_Buffered_3,
Modulus_Up_Down_Counter_Buffered_4,
Output_Pulse_Width_and_Frequency_Modulation_Buffered_1,
Output_Pulse_Width_and_Frequency_Modulation_Buffered_2,
Centre_Aligned_PWM_Buffered_1,
Centre_Aligned_PWM_Buffered_2,
Centre_Aligned_PWM_Buffered_3,
Centre_Aligned_PWM_Buffered_4,
Output_PWM_Buffered_1,
Output_PWM_Buffered_2);
type CCR_Type is record
Freeze : Enable_Type;
Output_Disable : Enable_Type;
Output_Disable_Select : ODISSL_Type;
Prescaler : Divide_Ratio;
Prescaler_Enable : Enable_Type;
DMA_Select : DMA_Select_Type;
Input_Filter : IF_Type;
Filter_Clock_Select : FCL_Type;
FLAG_Enable : Enable_Type;
Force_Match_A : Enable_Type;
Force_Match_B : Enable_Type;
Bus_Select : BSL_Type;
Edge_Select : Boolean; -- See page 17-17 of the MPC5554
-- reference manual for more info
Edge_Polarity : Boolean; -- See page 17-18
Mode : Mode_Type;
end record;
type CSR_Type is record
Overrun : Occurred_Type;
Overlow : Occurred_Type;
Unified_State_Input_Pin : Pin_State_Type;
Unified_State_Output_Pin : Pin_State_Type;
Flag : Occurred_Type;
end record;
pragma Warnings (Off, "*bits of*unused");
type Unified_Channel_Type is record
Channel_A_Data_Register : Channel_Register_Type;
Channel_B_Data_Register : Channel_Register_Type;
Channel_Counter_Register : Channel_Register_Type;
Channel_Control_Register : CCR_Type;
Channel_Status_Register : CSR_Type;
end record with Size => Unified_Channel_Type_Size;
pragma Warnings (On, "*bits of*unused");
----------------------------------------------------------------------------
-- Hardware Respresentations
----------------------------------------------------------------------------
for MDIS_Type use (Enable => 0, Disable => 1);
for ETB_Type use (Unified_Channel_23 => 0, STAC => 1);
for SRV_Type use
(eTPUA_TCR1 => 2#0000#,
eTPUB_TCR1 => 2#0001#,
eTPUA_TCR2 => 2#0010#,
eTPUB_TCR2 => 2#0011#);
for Module_Configuration_Type use record
Module_Disable at 0 range 1 .. 1;
Freeze at 0 range 2 .. 2;
Global_Time_Base_Enable at 0 range 3 .. 3;
External_Time_Base at 0 range 4 .. 4;
Global_Prescale_Enable at 0 range 5 .. 5;
Server_Time_Slot at 0 range 12 .. 15;
Global_Prescaler at 0 range 16 .. 23;
end record;
for DMA_Select_Type use (Interrupt => 0, DMA => 1);
for IF_Type use
(Bypass => 2#0000#,
Two => 2#0001#,
Four => 2#0010#,
Eight => 2#0100#,
Sixteen => 2#1000#);
for FCL_Type use (Prescaled => 0, Main => 1);
for BSL_Type use (A => 2#00#, BCD => 2#01#, Internal => 2#11#);
for Mode_Type use
(GPIO_Input => 2#0000000#,
GPIO_Output => 2#0000001#,
Single_Action_Input_Capture => 2#0000010#,
Single_Action_Output_Compare => 2#0000011#,
Input_Pulse_Width_Measurement => 2#0000100#,
Input_Period_Measurement => 2#0000101#,
Doblue_Action_Output_Compare_Second_Match => 2#0000110#,
Double_Action_Output_Compare_Both_Match => 2#0000111#,
Pulse_Edge_Accumulation_Continuous => 2#0001000#,
Pulse_Edge_Accumlation_Single => 2#0001001#,
Pulse_Edge_Counting_Continuous => 2#0001010#,
Pulse_Edge_Counting_Single => 2#0001011#,
Quadrature_Decode_1 => 2#0001100#,
Quadrature_Decode_2 => 2#0001101#,
Windowed_Programmable_Time_Accumulation => 2#0001110#,
Modulus_Counter_Up_Internal => 2#0010000#,
Modulus_Counter_Up_External => 2#0010001#,
Modulus_Counter_Up_Down_No_Change_Internal => 2#0010100#,
Modulus_Counter_Up_Down_No_Change_External => 2#0010101#,
Modulus_Counter_Up_Down_Change_Internal => 2#0010110#,
Modulus_Counter_Up_Down_Change_External => 2#0010111#,
Output_Pulse_Width_and_Frequency_Modulation_1 => 2#0011000#,
Output_Pulse_Width_and_Frequency_Modulation_2 => 2#0011001#,
Output_Pulse_Width_and_Frequency_Modulation_3 => 2#0011010#,
Output_Pulse_Width_and_Frequency_Modulation_4 => 2#0011011#,
Centre_Aligned_PWM_1 => 2#0011100#,
Centre_Aligned_PWM_2 => 2#0011101#,
Centre_Aligned_PWM_3 => 2#0011110#,
Centre_Aligned_PWM_4 => 2#0011111#,
Output_PWM_1 => 2#0100000#,
Output_PWM_2 => 2#0100001#,
Output_PWM_3 => 2#0100010#,
Output_PWM_4 => 2#0100011#,
Modulus_Up_Counter_Buffered_Internal => 2#1010000#,
Modulus_Up_Counter_Buffered_External => 2#1010001#,
Modulus_Up_Down_Counter_Buffered_1 => 2#1010100#,
Modulus_Up_Down_Counter_Buffered_2 => 2#1010101#,
Modulus_Up_Down_Counter_Buffered_3 => 2#1010110#,
Modulus_Up_Down_Counter_Buffered_4 => 2#1010111#,
Output_Pulse_Width_and_Frequency_Modulation_Buffered_1 => 2#1011000#,
Output_Pulse_Width_and_Frequency_Modulation_Buffered_2 => 2#1011010#,
Centre_Aligned_PWM_Buffered_1 => 2#1011100#,
Centre_Aligned_PWM_Buffered_2 => 2#1011101#,
Centre_Aligned_PWM_Buffered_3 => 2#1011110#,
Centre_Aligned_PWM_Buffered_4 => 2#1011111#,
Output_PWM_Buffered_1 => 2#1100000#,
Output_PWM_Buffered_2 => 2#1100010#);
for CCR_Type use record
Freeze at 0 range 0 .. 0;
Output_Disable at 0 range 1 .. 1;
Output_Disable_Select at 0 range 2 .. 3;
Prescaler at 0 range 4 .. 5;
Prescaler_Enable at 0 range 6 .. 6;
DMA_Select at 0 range 7 .. 7;
Input_Filter at 0 range 9 .. 12;
Filter_Clock_Select at 0 range 13 .. 13;
FLAG_Enable at 0 range 14 .. 14;
Force_Match_A at 0 range 18 .. 18;
Force_Match_B at 0 range 19 .. 19;
Bus_Select at 0 range 21 .. 22;
Edge_Select at 0 range 23 .. 23;
Edge_Polarity at 0 range 24 .. 24;
Mode at 0 range 25 .. 31;
end record;
for CSR_Type use record
Overrun at 0 range 0 .. 0;
Overlow at 0 range 16 .. 16;
Unified_State_Input_Pin at 0 range 29 .. 29;
Unified_State_Output_Pin at 0 range 30 .. 30;
Flag at 0 range 31 .. 31;
end record;
for Unified_Channel_Type use record
Channel_A_Data_Register at 0 range 8 .. 31;
Channel_B_Data_Register at 4 range 8 .. 31;
Channel_Counter_Register at 8 range 8 .. 31;
Channel_Control_Register at 12 range 0 .. 31;
Channel_Status_Register at 16 range 0 .. 31;
end record;
----------------------------------------------------------------------------
-- eMIOS Registers
----------------------------------------------------------------------------
pragma Warnings (Off, "*alignment*");
Module_Configuration_Register : Module_Configuration_Type;
for Module_Configuration_Register'Address use
System'To_Address (EMIOS_Base_Address);
Unified_Channel_Register_Array :
array (EMIOS_ID_Type) of aliased Unified_Channel_Type;
for Unified_Channel_Register_Array'Address use
System'To_Address (EMIOS_Base_Address + Unified_Channel_Offset_Address);
type Unified_Channel_Pointer is access all Unified_Channel_Type;
end MPC5554.eMIOS;
|
reznikmm/matreshka | Ada | 3,916 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.ODF_Attributes.Style.Font_Size_Complex;
package ODF.DOM.Attributes.Style.Font_Size_Complex.Internals is
function Create
(Node : Matreshka.ODF_Attributes.Style.Font_Size_Complex.Style_Font_Size_Complex_Access)
return ODF.DOM.Attributes.Style.Font_Size_Complex.ODF_Style_Font_Size_Complex;
function Wrap
(Node : Matreshka.ODF_Attributes.Style.Font_Size_Complex.Style_Font_Size_Complex_Access)
return ODF.DOM.Attributes.Style.Font_Size_Complex.ODF_Style_Font_Size_Complex;
end ODF.DOM.Attributes.Style.Font_Size_Complex.Internals;
|
reznikmm/matreshka | Ada | 3,836 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.ODF_Elements.Style.Page_Layout;
package ODF.DOM.Elements.Style.Page_Layout.Internals is
function Create
(Node : Matreshka.ODF_Elements.Style.Page_Layout.Style_Page_Layout_Access)
return ODF.DOM.Elements.Style.Page_Layout.ODF_Style_Page_Layout;
function Wrap
(Node : Matreshka.ODF_Elements.Style.Page_Layout.Style_Page_Layout_Access)
return ODF.DOM.Elements.Style.Page_Layout.ODF_Style_Page_Layout;
end ODF.DOM.Elements.Style.Page_Layout.Internals;
|
onox/orka | Ada | 2,008 | ads | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
package Orka.SIMD.SSE.Singles.Math is
pragma Pure;
function Min (Left, Right : m128) return m128
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_minps";
-- Compare each 32-bit float in Left and Right and take the minimum values.
--
-- Result (I) := Float'Min (Left (I), Right (I)) for I in 1 ..4
function Max (Left, Right : m128) return m128
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_maxps";
-- Compare each 32-bit float in Left and Right and take the maximum values.
--
-- Result (I) := Float'Max (Left (I), Right (I)) for I in 1 ..4
function Reciprocal (Elements : m128) return m128
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_rcpps";
-- Return the reciprocal (1/X) of each element
function Reciprocal_Sqrt (Elements : m128) return m128
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_rsqrtps";
-- Return the reciprocal of the square root (1/Sqrt(X)) of each element
function Sqrt (Elements : m128) return m128
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_sqrtps";
-- Return the square root (Sqrt(X)) of each element
function Cross_Product (Left, Right : m128) return m128
with Inline_Always;
end Orka.SIMD.SSE.Singles.Math;
|
leo-brewin/Regge | Ada | 3,054 | adb | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Command_Line; use Ada.Command_Line;
package body regge.io is
package Real_IO is new Ada.Text_IO.Float_IO (Real); use Real_IO;
package Integer_IO is new Ada.Text_IO.Integer_IO (Integer); use Integer_IO;
function str (source : in Integer;
width : in Integer := 0) return string is
result : string(1..width);
wide_result : string(1..Integer'width);
begin
if width = 0 then
Put(wide_result,source);
return trim(wide_result,left); -- flush left, returns a string just large enough to contain the integer
else
Put(result,source);
return result;
end if;
end str;
function str (source : in Real;
width : in Integer := 10) return string is
result : string(1..width);
begin
-- 4932 = largest exponent for 18 dec. digits
-- so may need up to 4 digits in the exponent + 1 for the sign = 5
if source = 0.0 then
Put (result,source,width-7,3);
elsif abs (source) < 1.0 then
if abs (source) >= 1.0e-99 then
Put (result,source,width-7,3);
elsif abs (source) >= 1.0e-999 then
Put (result,source,width-8,4);
else
Put (result,source,width-9,5);
end if;
else
if abs (source) < 1.0e100 then
Put (result,source,width-7,3);
elsif abs (source) < 1.0e1000 then
Put (result,source,width-8,4);
else
Put (result,source,width-9,5);
end if;
end if;
return result;
end str;
function read_command_arg (the_arg : Integer) return Integer is
last : Integer;
the_arg_value : Integer;
begin
get (Ada.Command_Line.Argument (the_arg),the_arg_value,last);
return the_arg;
end read_command_arg;
procedure read_lattice
is
txt : File_Type;
tmp : Integer;
bone : Integer;
begin
Open (txt,In_file,"data/lattice/simp12.txt");
Get (txt,n_simp2); skip_line (txt);
for a in 1..n_simp2 loop
Get (txt,bone); skip_line (txt);
Get (txt,n_loop02(bone)); skip_line (txt);
Get (txt,n_simp12(bone)); skip_line (txt);
for b in 1..n_simp12(bone) loop
Get (txt,tmp);
Get (txt,simp12(bone)(tmp));
end loop;
end loop;
Close (txt);
Open (txt,In_file,"data/lsq/data-0"&str(num,1)&".txt");
Get (txt,n_simp1);
skip_line (txt); -- skip trailing text on first line
skip_line (txt); -- skip second line
for i in 1 .. n_simp1 loop
Get (txt, simp01(i)(1));
Get (txt, simp01(i)(2));
Get (txt, lsq(i));
end loop;
Close (txt);
end read_lattice;
end regge.io;
|
AdaCore/training_material | Ada | 365 | adb | package body Alarm is
function Get_Temperature return Integer is
begin
return Temperature;
end Get_Temperature;
function Get_Status return Alarm_Status is
begin
return Status;
end Get_Status;
procedure Set_Status is
begin
if Get_Temperature > 100 then
Status := On;
end if;
end Set_Status;
end Alarm;
|
yannickmoy/atomic | Ada | 11,933 | ads | generic
type T is mod <>;
package Atomic.Generic16
with Preelaborate, Spark_Mode => On
is
-- Based on GCC atomic built-ins. See:
-- https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
--
-- The specification is exactly the same for all sizes of data (8, 16, 32,
-- 64).
type Instance is limited private;
-- This type is limited and private, it can only be manipulated using the
-- primitives below.
function Init (Val : T) return Instance
with Post => Value (Init'Result) = Val;
-- Can be used to initialize an atomic instance:
--
-- A : Atomic.Unsigned_8.Instance := Atomic.Unsigned_8.Init (0);
function Value (This : Instance) return T
with Ghost;
-- Ghost function to get the value of an instance without needing it
-- aliased. This function can be used in contracts for instance.
-- This doesn't use the atomic built-ins.
function Load (This : aliased Instance;
Order : Mem_Order := Seq_Cst)
return T
with Pre => Order in Relaxed | Consume | Acquire | Seq_Cst,
Post => Load'Result = Value (This);
procedure Store (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
with Pre => Order in Relaxed | Release | Seq_Cst,
Post => Value (This) = Val;
procedure Exchange (This : aliased in out Instance;
Val : T;
Old : out T;
Order : Mem_Order := Seq_Cst)
with Pre => Order in Relaxed | Acquire | Release | Acq_Rel | Seq_Cst,
Post => Old = Value (This)'Old and then Value (This) = Val;
procedure Compare_Exchange (This : aliased in out Instance;
Expected : T;
Desired : T;
Weak : Boolean;
Success : out Boolean;
Success_Order : Mem_Order := Seq_Cst;
Failure_Order : Mem_Order := Seq_Cst)
with Pre => Failure_Order in Relaxed | Consume | Acquire | Seq_Cst
and then
not Stronger (Failure_Order, Success_Order),
Post => Success = (Value (This)'Old = Expected)
and then
(if Success then Value (This) = Desired);
procedure Add (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
with Post => Value (This) = Value (This)'Old + Val;
procedure Sub (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
with Post => Value (This) = Value (This)'Old - Val;
procedure Op_And (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
with Post => Value (This) = (Value (This)'Old and Val);
procedure Op_XOR (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
with Post => Value (This) = (Value (This)'Old xor Val);
procedure Op_OR (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
with Post => Value (This) = (Value (This)'Old or Val);
procedure NAND (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
with Post => Value (This) = not (Value (This)'Old and Val);
procedure Add_Fetch (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = (Value (This)'Old + Val)
and then Value (This) = Result;
procedure Sub_Fetch (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = (Value (This)'Old - Val)
and then Value (This) = Result;
procedure And_Fetch (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = (Value (This)'Old and Val)
and then Value (This) = Result;
procedure XOR_Fetch (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = (Value (This)'Old xor Val)
and then Value (This) = Result;
procedure OR_Fetch (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = (Value (This)'Old or Val)
and then Value (This) = Result;
procedure NAND_Fetch (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = not (Value (This)'Old and Val)
and then Value (This) = Result;
procedure Fetch_Add (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = Value (This)'Old
and Value (This) = (Value (This)'Old + Val);
procedure Fetch_Sub (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = Value (This)'Old
and Value (This) = (Value (This)'Old - Val);
procedure Fetch_And (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = Value (This)'Old
and Value (This) = (Value (This)'Old and Val);
procedure Fetch_XOR (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = Value (This)'Old
and Value (This) = (Value (This)'Old xor Val);
procedure Fetch_OR (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = Value (This)'Old
and Value (This) = (Value (This)'Old or Val);
procedure Fetch_NAND (This : aliased in out Instance;
Val : T;
Result : out T;
Order : Mem_Order := Seq_Cst)
with Post => Result = Value (This)'Old
and Value (This) = not (Value (This)'Old and Val);
-- NOT SPARK compatible --
function Exchange (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off,
Post => Exchange'Result = Value (This)'Old
and then Value (This) = Val;
function Compare_Exchange (This : aliased in out Instance;
Expected : T;
Desired : T;
Weak : Boolean;
Success_Order : Mem_Order := Seq_Cst;
Failure_Order : Mem_Order := Seq_Cst)
return Boolean
with SPARK_Mode => Off,
Post =>
Compare_Exchange'Result = (Value (This)'Old = Expected)
and then
(if Compare_Exchange'Result then Value (This) = Desired);
function Add_Fetch (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off,
Post => Add_Fetch'Result = (Value (This)'Old + Val)
and then Value (This) = Add_Fetch'Result;
function Sub_Fetch (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off,
Post => Sub_Fetch'Result = (Value (This)'Old - Val)
and then Value (This) = Sub_Fetch'Result;
function And_Fetch (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off,
Post => And_Fetch'Result = (Value (This)'Old and Val)
and then Value (This) = And_Fetch'Result;
function XOR_Fetch (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off,
Post => XOR_Fetch'Result = (Value (This)'Old xor Val)
and then Value (This) = XOR_Fetch'Result;
function OR_Fetch (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off,
Post => OR_Fetch'Result = (Value (This)'Old or Val)
and then Value (This) = OR_Fetch'Result;
function NAND_Fetch (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off,
Post => NAND_Fetch'Result = not (Value (This)'Old and Val)
and then Value (This) = NAND_Fetch'Result;
function Fetch_Add (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off;
function Fetch_Sub (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off;
function Fetch_And (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off;
function Fetch_XOR (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off;
function Fetch_OR (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off;
function Fetch_NAND (This : aliased in out Instance;
Val : T;
Order : Mem_Order := Seq_Cst)
return T
with SPARK_Mode => Off;
private
type Instance is new T;
----------
-- Init --
----------
function Init (Val : T) return Instance
is (Instance (Val));
-----------
-- Value --
-----------
function Value (This : Instance) return T
is (T (This));
pragma Inline (Init);
pragma Inline (Load);
pragma Inline (Store);
pragma Inline (Exchange);
pragma Inline (Compare_Exchange);
pragma Inline (Add);
pragma Inline (Sub);
pragma Inline (Add_Fetch);
pragma Inline (Sub_Fetch);
pragma Inline (Fetch_Add);
pragma Inline (Fetch_Sub);
pragma Inline (Op_And);
pragma Inline (Op_XOR);
pragma Inline (Op_OR);
pragma Inline (NAND);
pragma Inline (And_Fetch);
pragma Inline (XOR_Fetch);
pragma Inline (OR_Fetch);
pragma Inline (NAND_Fetch);
pragma Inline (Fetch_And);
pragma Inline (Fetch_XOR);
pragma Inline (Fetch_OR);
pragma Inline (Fetch_NAND);
end Atomic.Generic16;
|
zhmu/ananas | Ada | 508 | adb | -- { dg-do compile }
-- { dg-options "-O" }
with Ada.Text_IO;
procedure Opt69 is
procedure Inner
(A : String := (1 .. 15 => ASCII.NUL);
B : String := (1 .. 5 => ASCII.NUL);
C : String := (1 .. 5 => ASCII.NUL))
is
Aa : String (1 .. 15);
Bb : String (1 .. 5);
Cc : String (1 .. 5);
begin
Aa := A;
Bb := B;
Cc := C;
Ada.Text_IO.Put_Line (Aa);
Ada.Text_IO.Put_Line (Bb);
Ada.Text_IO.Put_Line (Cc);
end;
begin
Inner;
end;
|
tum-ei-rcs/StratoX | Ada | 1,080 | ads |
with stm32.gpio;
with Bit_Types; use Bit_Types;
package HAL.GPIO
with SPARK_Mode
is
pragma Preelaborate;
type GPIO_Port_Type is (A, B, C, D, E, F);
subtype GPIO_Pin_Type is Integer range 1 .. 16;
type GPIO_Point_Type is record
Port : GPIO_Port_Type;
Pin : GPIO_Pin_Type;
end record;
type GPIO_Signal_Type is (LOW, HIGH);
-- precondition: only write if direction is output (ghost code)
procedure write (Point : GPIO_Point_Type; Signal : GPIO_Signal_Type);
-- with pre => stm32.gpio.GPIOA_Periph.MODER.Arr(Point.Pin) = stm32.gpio.Mode_OUT;
function read (Point : GPIO_Point_Type) return GPIO_Signal_Type;
-- function map(Point : GPIO_Point_Type) return stm32.gpio.GPIO_Peripheral
-- is ( case Point.Port is
-- when A => stm32.gpio.GPIOA_Periph,
-- when B => stm32.gpio.GPIOB_Periph,
-- when C => stm32.gpio.GPIOC_Periph,
-- when D => stm32.gpio.GPIOD_Periph,
-- when E => stm32.gpio.GPIOE_Periph,
-- when F => stm32.gpio.GPIOF_Periph );
end HAL.GPIO;
|
ekoeppen/STM32_Generic_Ada_Drivers | Ada | 209 | ads | with STM32_SVD.GPIO;
package STM32GD.GPIO.Port is
pragma Preelaborate;
function GPIO_Port_Representation (Port : STM32_SVD.GPIO.GPIO_Peripheral) return UInt4
with Inline;
end STM32GD.GPIO.Port;
|
reznikmm/matreshka | Ada | 3,624 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Elements.Generic_Hash;
function AMF.UML.Information_Items.Hash is
new AMF.Elements.Generic_Hash (UML_Information_Item, UML_Information_Item_Access);
|
charlie5/lace | Ada | 5,403 | adb | with
openGL.Shader,
openGL.Program,
openGL.Buffer.general,
openGL.Tasks,
openGL.Attribute,
openGL.Errors,
GL.lean,
GL.Pointers,
Interfaces.C.Strings,
System.storage_Elements;
package body openGL.Geometry.colored
is
use GL.lean, GL.Pointers;
use Interfaces;
-----------
-- Globals
--
vertex_Shader : aliased Shader.item;
fragment_Shader : aliased Shader.item;
the_Program : openGL.Program.view;
Name_1 : constant String := "Site";
Name_2 : constant String := "Color";
Attribute_1_Name : aliased C.char_array := C.to_C (Name_1);
Attribute_2_Name : aliased C.char_array := C.to_C (Name_2);
Attribute_1_Name_ptr : aliased constant C.strings.chars_ptr := C.strings.to_chars_ptr (Attribute_1_Name'Access);
Attribute_2_Name_ptr : aliased constant C.strings.chars_ptr := C.strings.to_chars_ptr (Attribute_2_Name'Access);
---------
-- Forge
--
function new_Geometry return Geometry.colored.view
is
use System.storage_Elements;
use type openGL.Program.view;
Self : constant Geometry.colored.view := new Geometry.colored.item;
begin
Tasks.check;
if the_Program = null
then -- Define the shaders and program.
declare
use openGL.Attribute.Forge;
sample_Vertex : Vertex;
Attribute_1 : Attribute.view;
Attribute_2 : Attribute.view;
begin
vertex_Shader .define (Shader.Vertex, "assets/opengl/shader/colored.vert");
fragment_Shader.define (Shader.Fragment, "assets/opengl/shader/colored.frag");
the_Program := new openGL.Program.item;
the_Program.define (vertex_Shader 'Access,
fragment_Shader'Access);
Attribute_1 := new_Attribute (Name => Name_1,
gl_Location => the_Program.attribute_Location (Name_1),
Size => 3,
data_Kind => Attribute.GL_FLOAT,
Stride => colored.Vertex'Size / 8,
Offset => 0,
Normalized => False);
Attribute_2 := new_Attribute (Name => Name_2,
gl_Location => the_Program.attribute_Location (Name_2),
Size => 4,
data_Kind => Attribute.GL_UNSIGNED_BYTE,
Stride => colored.Vertex'Size / 8,
Offset => sample_Vertex.Color.primary.Red'Address
- sample_Vertex.Site (1) 'Address,
Normalized => True);
the_Program.add (Attribute_1);
the_Program.add (Attribute_2);
glBindAttribLocation (Program => the_Program.gl_Program,
Index => the_Program.Attribute (named => Name_1).gl_Location,
Name => +Attribute_1_Name_ptr);
Errors.log;
glBindAttribLocation (Program => the_Program.gl_Program,
Index => the_Program.Attribute (named => Name_2).gl_Location,
Name => +Attribute_2_Name_ptr);
Errors.log;
end;
end if;
Self.Program_is (the_Program);
return Self;
end new_Geometry;
------------
-- Vertices
--
function is_Transparent (Self : in Vertex_array) return Boolean
is
function get_Color (Index : in Index_t) return rgba_Color
is (Self (Index).Color);
function my_Transparency is new get_Transparency (any_Index_t => Index_t,
get_Color => get_Color);
begin
return my_Transparency (Count => Self'Length);
end is_Transparent;
--------------
-- Attributes
--
package openGL_Buffer_of_geometry_Vertices is new Buffer.general (base_Object => Buffer.array_Object,
Index => Index_t,
Element => Vertex,
Element_Array => Vertex_array);
procedure Vertices_are (Self : in out Item; Now : in Vertex_array)
is
use openGL.Buffer,
openGL_Buffer_of_geometry_Vertices.Forge;
begin
free (Self.Vertices);
Self.Vertices := new openGL_Buffer_of_geometry_Vertices.Object' (to_Buffer (Now,
usage => Buffer.static_Draw));
Self.is_Transparent := is_Transparent (Now);
-- Set the bounds.
--
declare
function get_Site (Index : in Index_t) return Vector_3
is (Now (Index).Site);
function bounding_Box is new get_Bounds (Index_t, get_Site);
begin
Self.Bounds_are (bounding_Box (Count => Now'Length));
end;
end Vertices_are;
end openGL.Geometry.colored;
|
sungyeon/drake | Ada | 446 | ads | pragma License (Unrestricted);
-- runtime unit
package System.Formatting.Address is
pragma Pure;
subtype Address_String is String (1 .. (Standard'Address_Size + 3) / 4);
procedure Image (
Value : System.Address;
Item : out Address_String;
Set : Type_Set := Upper_Case);
procedure Value (
Item : Address_String;
Result : out System.Address;
Error : out Boolean);
end System.Formatting.Address;
|
reznikmm/matreshka | Ada | 4,317 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Nodes;
with XML.DOM.Elements.Internals;
package body ODF.DOM.Elements.Text.Notes_Configuration.Internals is
------------
-- Create --
------------
function Create
(Node : Matreshka.ODF_Elements.Text.Notes_Configuration.Text_Notes_Configuration_Access)
return ODF.DOM.Elements.Text.Notes_Configuration.ODF_Text_Notes_Configuration is
begin
return
(XML.DOM.Elements.Internals.Create
(Matreshka.DOM_Nodes.Element_Access (Node)) with null record);
end Create;
----------
-- Wrap --
----------
function Wrap
(Node : Matreshka.ODF_Elements.Text.Notes_Configuration.Text_Notes_Configuration_Access)
return ODF.DOM.Elements.Text.Notes_Configuration.ODF_Text_Notes_Configuration is
begin
return
(XML.DOM.Elements.Internals.Wrap
(Matreshka.DOM_Nodes.Element_Access (Node)) with null record);
end Wrap;
end ODF.DOM.Elements.Text.Notes_Configuration.Internals;
|
reznikmm/matreshka | Ada | 4,371 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
-- A separated portion of a UMLCompartmentableShape.
------------------------------------------------------------------------------
with AMF.UMLDI.UML_Diagram_Elements;
limited with AMF.UMLDI.UML_Diagram_Elements.Collections;
package AMF.UMLDI.UML_Compartments is
pragma Preelaborate;
type UMLDI_UML_Compartment is limited interface
and AMF.UMLDI.UML_Diagram_Elements.UMLDI_UML_Diagram_Element;
type UMLDI_UML_Compartment_Access is
access all UMLDI_UML_Compartment'Class;
for UMLDI_UML_Compartment_Access'Storage_Size use 0;
not overriding function Get_Element_In_Compartment
(Self : not null access constant UMLDI_UML_Compartment)
return AMF.UMLDI.UML_Diagram_Elements.Collections.Ordered_Set_Of_UMLDI_UML_Diagram_Element is abstract;
-- Getter of UMLCompartment::elementInCompartment.
--
-- Contents of the compartment.
end AMF.UMLDI.UML_Compartments;
|
zhmu/ananas | Ada | 6,227 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . C A L E N D A R . C O N V E R S I O N S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2008-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package provides various routines for conversion between Ada and Unix
-- time models - Time, Duration, struct tm and struct timespec.
with Interfaces.C;
package Ada.Calendar.Conversions is
function To_Ada_Time (Unix_Time : Interfaces.C.long) return Time;
-- Convert a time value represented as number of seconds since the
-- Unix Epoch to a time value relative to an Ada implementation-defined
-- Epoch. The units of the result are nanoseconds on all targets. Raises
-- Time_Error if the result cannot fit into a Time value.
function To_Ada_Time
(tm_year : Interfaces.C.int;
tm_mon : Interfaces.C.int;
tm_day : Interfaces.C.int;
tm_hour : Interfaces.C.int;
tm_min : Interfaces.C.int;
tm_sec : Interfaces.C.int;
tm_isdst : Interfaces.C.int) return Time;
-- Convert a time value expressed in Unix-like fields of struct tm into
-- a Time value relative to the Ada Epoch. The ranges of the formals are
-- as follows:
-- tm_year -- years since 1900
-- tm_mon -- months since January [0 .. 11]
-- tm_day -- day of the month [1 .. 31]
-- tm_hour -- hours since midnight [0 .. 24]
-- tm_min -- minutes after the hour [0 .. 59]
-- tm_sec -- seconds after the minute [0 .. 60]
-- tm_isdst -- Daylight Savings Time flag [-1 .. 1]
-- The returned value is in UTC and may or may not contain leap seconds
-- depending on whether binder flag "-y" was used. Raises Time_Error if
-- the input values are out of the defined ranges or if tm_sec equals 60
-- and the instance in time is not a leap second occurrence.
function To_Duration
(tv_sec : Interfaces.C.long;
tv_nsec : Interfaces.C.long) return Duration;
-- Convert an elapsed time value expressed in Unix-like fields of struct
-- timespec into a Duration value. The expected ranges are:
-- tv_sec - seconds
-- tv_nsec - nanoseconds
procedure To_Struct_Timespec
(D : Duration;
tv_sec : out Interfaces.C.long;
tv_nsec : out Interfaces.C.long);
-- Convert a Duration value into the constituents of struct timespec.
-- Formal tv_sec denotes seconds and tv_nsecs denotes nanoseconds.
procedure To_Struct_Tm
(T : Time;
tm_year : out Interfaces.C.int;
tm_mon : out Interfaces.C.int;
tm_day : out Interfaces.C.int;
tm_hour : out Interfaces.C.int;
tm_min : out Interfaces.C.int;
tm_sec : out Interfaces.C.int);
-- Convert a Time value set in the Ada Epoch into the constituents of
-- struct tm. The ranges of the out formals are as follows:
-- tm_year -- years since 1900
-- tm_mon -- months since January [0 .. 11]
-- tm_day -- day of the month [1 .. 31]
-- tm_hour -- hours since midnight [0 .. 24]
-- tm_min -- minutes after the hour [0 .. 59]
-- tm_sec -- seconds after the minute [0 .. 60]
-- tm_isdst -- Daylight Savings Time flag [-1 .. 1]
-- The input date is considered to be in UTC
function To_Unix_Time (Ada_Time : Time) return Interfaces.C.long;
-- Convert a time value represented as number of time units since the Ada
-- implementation-defined Epoch to a value relative to the Unix Epoch. The
-- units of the result are seconds. Raises Time_Error if the result cannot
-- fit into a Time value.
function To_Unix_Nano_Time
(Ada_Time : Time) return Interfaces.C.long_long;
-- Convert a time value represented as number of time units since the Ada
-- implementation-defined Epoch to a value relative to the Unix Epoch. The
-- units of the result are nanoseconds. Raises Time_Error if the result
-- cannot fit into a Time value.
end Ada.Calendar.Conversions;
|
damaki/SPARKNaCl | Ada | 347 | adb | separate (SPARKNaCl)
procedure Sanitize_U64 (R : out U64) is
begin
R := 0;
pragma Inspection_Point (R); -- See RM H3.2 (9)
-- Add target-dependent code here to
-- 1. flush and invalidate data cache,
-- 2. wait until writes have committed (e.g. a memory-fence instruction)
-- 3. whatever else is required.
end Sanitize_U64;
|
zhmu/ananas | Ada | 2,456 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- O S I N T - M --
-- --
-- B o d y --
-- --
-- Copyright (C) 2001-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package body Osint.M is
-----------------------
-- More_Source_Files --
-----------------------
function More_Source_Files return Boolean renames More_Files;
----------------------
-- Next_Main_Source --
----------------------
function Next_Main_Source return File_Name_Type renames Next_Main_File;
----------------------
-- Object_File_Name --
----------------------
function Object_File_Name (N : File_Name_Type) return File_Name_Type
renames Osint.Object_File_Name;
begin
Set_Program (Make);
end Osint.M;
|
AdaCore/training_material | Ada | 805 | adb | with Movie_Servers;
with Drawable_Chars;
with Drawable_Chars.Latin_1;
with Drawable_Chars.Circles;
procedure Mini_Cinema is
type Charsets_List_T is
array (Positive range <>) of Drawable_Chars.Sorted_Charset_T;
Charsets : constant Charsets_List_T :=
(Drawable_Chars.Circles.By_White, Drawable_Chars.Circles.By_Black,
Drawable_Chars.Latin_1.By_White, Drawable_Chars.Latin_1.By_Black);
-- TODO
Play_Settings : Movie_Servers.Play_Settings_Access_T := null;
Display_Server : Movie_Servers.Movie_Server_Task_T (Play_Settings);
begin
Play_Settings.Set_FPS (4);
Play_Settings.Set_Charset (Charsets (Charsets'First));
Display_Server.Play_Loop (Dir => "resources/movies/rotating_triangle");
-- TODO
-- Add commands for changing the server settings
end Mini_Cinema;
|
reznikmm/matreshka | Ada | 5,339 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- Testsuite Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Ada.Characters.Wide_Wide_Latin_1;
with League.Holders.JSON_Arrays;
with League.JSON.Arrays;
with League.Strings;
with XML.SAX.HTML5_Writers;
with XML.SAX.Simple_Readers;
with XML.SAX.String_Input_Sources;
with XML.SAX.String_Output_Destinations;
with XML.Templates.Processors;
procedure Test_350 is
use type League.Strings.Universal_String;
Source : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String
("<html xmlns='http://www.w3.org/1999/xhtml'"
& " xmlns:mtl='http://forge.ada-ru.org/matreshka/template'>"
& "<body>"
& "<ul>"
& "<mtl:for expression='item of items'>"
& "<li>${item}</li>"
& "</mtl:for>"
& "</ul>"
& "</body>"
& "</html>");
Expected : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String
("<!DOCTYPE html>"
& Ada.Characters.Wide_Wide_Latin_1.LF
& "<ul></ul>");
Input : aliased XML.SAX.String_Input_Sources.String_Input_Source;
Reader : XML.SAX.Simple_Readers.Simple_Reader;
Processor : aliased XML.Templates.Processors.Template_Processor;
Writer : aliased XML.SAX.HTML5_Writers.HTML5_Writer;
Output : aliased
XML.SAX.String_Output_Destinations.String_Output_Destination;
begin
Reader.Set_Content_Handler (Processor'Unchecked_Access);
Reader.Set_Lexical_Handler (Processor'Unchecked_Access);
Processor.Set_Content_Handler (Writer'Unchecked_Access);
Processor.Set_Lexical_Handler (Writer'Unchecked_Access);
Writer.Set_Output_Destination (Output'Unchecked_Access);
Processor.Set_Parameter
(League.Strings.To_Universal_String ("items"),
League.Holders.JSON_Arrays.To_Holder
(League.JSON.Arrays.Empty_JSON_Array));
Input.Set_String (Source);
Reader.Parse (Input'Unchecked_Access);
if Output.Get_Text /= Expected then
raise Program_Error;
end if;
end Test_350;
|
reznikmm/matreshka | Ada | 5,097 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Generic_Collections;
package AMF.CMOF.Typed_Elements.Collections is
pragma Preelaborate;
package CMOF_Typed_Element_Collections is
new AMF.Generic_Collections
(CMOF_Typed_Element,
CMOF_Typed_Element_Access);
type Set_Of_CMOF_Typed_Element is
new CMOF_Typed_Element_Collections.Set with null record;
Empty_Set_Of_CMOF_Typed_Element : constant Set_Of_CMOF_Typed_Element;
type Ordered_Set_Of_CMOF_Typed_Element is
new CMOF_Typed_Element_Collections.Ordered_Set with null record;
Empty_Ordered_Set_Of_CMOF_Typed_Element : constant Ordered_Set_Of_CMOF_Typed_Element;
type Bag_Of_CMOF_Typed_Element is
new CMOF_Typed_Element_Collections.Bag with null record;
Empty_Bag_Of_CMOF_Typed_Element : constant Bag_Of_CMOF_Typed_Element;
type Sequence_Of_CMOF_Typed_Element is
new CMOF_Typed_Element_Collections.Sequence with null record;
Empty_Sequence_Of_CMOF_Typed_Element : constant Sequence_Of_CMOF_Typed_Element;
private
Empty_Set_Of_CMOF_Typed_Element : constant Set_Of_CMOF_Typed_Element
:= (CMOF_Typed_Element_Collections.Set with null record);
Empty_Ordered_Set_Of_CMOF_Typed_Element : constant Ordered_Set_Of_CMOF_Typed_Element
:= (CMOF_Typed_Element_Collections.Ordered_Set with null record);
Empty_Bag_Of_CMOF_Typed_Element : constant Bag_Of_CMOF_Typed_Element
:= (CMOF_Typed_Element_Collections.Bag with null record);
Empty_Sequence_Of_CMOF_Typed_Element : constant Sequence_Of_CMOF_Typed_Element
:= (CMOF_Typed_Element_Collections.Sequence with null record);
end AMF.CMOF.Typed_Elements.Collections;
|
stcarrez/ada-util | Ada | 511 | adb | with Ada.Command_Line;
with Ada.Text_IO;
with Ada.Directories;
with Util.Files;
procedure Realpath is
Count : constant Natural := Ada.Command_Line.Argument_Count;
begin
for I in 1 .. Count loop
declare
Path : constant String := Ada.Command_Line.Argument (I);
begin
Ada.Text_IO.Put_Line (Util.Files.Realpath (Path));
exception
when Ada.Directories.Use_Error =>
Ada.Text_IO.Put_Line ("Invalid path: " & Path);
end;
end loop;
end Realpath;
|
tum-ei-rcs/StratoX | Ada | 416 | adb |
-- todo: initialize in several functions: initGPIO, initI2C, use HAL
with HIL.GPIO;
with HIL.Clock;
with HIL.SPI;
with HIL.UART;
package body CPU is
-- configures hardware registers
procedure initialize is
begin
-- Configure GPIO
HIL.Clock.configure;
HIL.GPIO.configure;
HIL.UART.configure;
HIL.SPI.configure;
-- HIL.I2C.initialize;
end initialize;
end CPU;
|
apple-oss-distributions/old_ncurses | Ada | 3,833 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding --
-- --
-- Terminal_Interface.Curses.Text_IO.Complex_IO --
-- --
-- B O D Y --
-- --
------------------------------------------------------------------------------
-- Copyright (c) 1998 Free Software Foundation, Inc. --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, distribute with modifications, sublicense, and/or sell --
-- copies of the Software, and to permit persons to whom the Software is --
-- furnished to do so, subject to the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
-- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Juergen Pfeifer <[email protected]> 1996
-- Version Control:
-- $Revision: 1.1.1.1 $
-- Binding Version 01.00
------------------------------------------------------------------------------
with Terminal_Interface.Curses.Text_IO.Float_IO;
package body Terminal_Interface.Curses.Text_IO.Complex_IO is
package FIO is new
Terminal_Interface.Curses.Text_IO.Float_IO (Complex_Types.Real'Base);
procedure Put
(Win : in Window;
Item : in Complex;
Fore : in Field := Default_Fore;
Aft : in Field := Default_Aft;
Exp : in Field := Default_Exp)
is
begin
Put (Win, '(');
FIO.Put (Win, Item.Re, Fore, Aft, Exp);
Put (Win, ',');
FIO.Put (Win, Item.Im, Fore, Aft, Exp);
Put (Win, ')');
end Put;
procedure Put
(Item : in Complex;
Fore : in Field := Default_Fore;
Aft : in Field := Default_Aft;
Exp : in Field := Default_Exp)
is
begin
Put (Get_Window, Item, Fore, Aft, Exp);
end Put;
end Terminal_Interface.Curses.Text_IO.Complex_IO;
|
DavJo-dotdotdot/Ada_Drivers_Library | Ada | 3,204 | adb | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2021, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with MicroBit.Console; use MicroBit.Console;
with MicroBit.Display;
with MicroBit.Display.Symbols;
with MicroBit.Buttons; use MicroBit.Buttons;
use MicroBit;
--this demo shows howto use the 2 buttons and the touch logo. Note that the logo is a little sensitive/erratic, sometimes touching back side for ground seems to be needed.
procedure Main is
begin
loop
if MicroBit.Buttons.State (Button_A) = Pressed then
MicroBit.Display.Display ('A');
Put_Line ("Pressed A");
elsif MicroBit.Buttons.State (Button_B) = Pressed then
MicroBit.Display.Display ('B');
Put_Line ("Pressed B");
elsif MicroBit.Buttons.State (Logo) = Pressed then
Display.Symbols.Heart;
Put_Line ("Pressed L");
else
MicroBit.Display.Clear;
end if;
end loop;
end Main;
|
reznikmm/matreshka | Ada | 4,133 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
generic
type Element_Type is private;
package League.Holders.Generic_Holders is
pragma Preelaborate;
Value_Tag : constant Tag;
function Element (Self : Holder) return Element_Type;
-- Returns internal value.
procedure Replace_Element (Self : in out Holder; To : Element_Type);
-- Set value. Tag of the value must be set before this call.
function To_Holder (Item : Element_Type) return Holder;
-- Creates new Value from specified value.
private
type Element_Container is new Abstract_Container with record
Value : Element_Type;
end record;
overriding function Constructor
(Is_Empty : not null access Boolean) return Element_Container;
Value_Tag : constant Tag := Tag (Element_Container'Tag);
end League.Holders.Generic_Holders;
|
kimtg/euler-ada | Ada | 293 | adb | with ada.text_io;
use ada.text_io;
procedure euler9 is
c : integer;
begin
for a in 1 .. 999 loop
for b in a + 1 .. 999 loop
c := 1000 - a - b;
if c > 0 and then a * a + b * b = c * c then
put_line(integer'image(a * b * c));
end if;
end loop;
end loop;
end;
|
sungyeon/drake | Ada | 1,815 | ads | pragma License (Unrestricted);
-- extended unit specialized for POSIX (Darwin, FreeBSD, or Linux)
package Ada.Text_IO.Terminal.Colors.Names is
-- Constants for system-specific system colors.
Black : constant Color; -- (R => 0.0, G => 0.0, B => 0.0)
Dark_Red : constant Color; -- (R => 0.75, G => 0.0, B => 0.0)
Dark_Green : constant Color; -- (R => 0.0, G => 0.75, B => 0.0)
Dark_Yellow : constant Color; -- (R => 0.75, G => 0.75, B => 0.0)
Dark_Blue : constant Color; -- (R => 0.0, G => 0.0, B => 0.75)
Dark_Magenta : constant Color; -- (R => 0.75, G => 0.0, B => 0.75)
Dark_Cyan : constant Color; -- (R => 0.0, G => 0.75, B => 0.75)
Gray : constant Color; -- (R => 0.75, G => 0.75, B => 0.75)
Dark_Gray : constant Color; -- (R => 0.5, G => 0.5, B => 0.5)
Red : constant Color; -- (R => 1.0, G => 0.5, B => 0.5)
Green : constant Color; -- (R => 0.5, G => 1.0, B => 0.5)
Yellow : constant Color; -- (R => 1.0, G => 1.0, B => 0.5)
Blue : constant Color; -- (R => 0.5, G => 0.5, B => 1.0)
Magenta : constant Color; -- (R => 1.0, G => 0.5, B => 1.0)
Cyan : constant Color; -- (R => 0.5, G => 1.0, B => 1.0)
White : constant Color; -- (R => 1.0, G => 1.0, B => 1.0)
private
Black : constant Color := 0;
Dark_Red : constant Color := 1;
Dark_Green : constant Color := 2;
Dark_Yellow : constant Color := 3;
Dark_Blue : constant Color := 4;
Dark_Magenta : constant Color := 5;
Dark_Cyan : constant Color := 6;
Gray : constant Color := 7;
Dark_Gray : constant Color := 8;
Red : constant Color := 9;
Green : constant Color := 10;
Yellow : constant Color := 11;
Blue : constant Color := 12;
Magenta : constant Color := 13;
Cyan : constant Color := 14;
White : constant Color := 15;
end Ada.Text_IO.Terminal.Colors.Names;
|
stcarrez/babel | Ada | 1,056 | adb | -----------------------------------------------------------------------
-- babel_harness -- Unit test program for babel
-- Copyright (C) 2015 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Babel.Testsuite;
with Util.Tests;
procedure Babel_Harness is
procedure Harness is new Util.Tests.Harness (Babel.Testsuite.Suite);
begin
Harness ("babel-tests.xml");
end Babel_Harness;
|
reznikmm/matreshka | Ada | 3,734 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Db_Is_Autoincrement_Attributes is
pragma Preelaborate;
type ODF_Db_Is_Autoincrement_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Db_Is_Autoincrement_Attribute_Access is
access all ODF_Db_Is_Autoincrement_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Db_Is_Autoincrement_Attributes;
|
reznikmm/matreshka | Ada | 5,097 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Generic_Collections;
package AMF.UML.Package_Imports.Collections is
pragma Preelaborate;
package UML_Package_Import_Collections is
new AMF.Generic_Collections
(UML_Package_Import,
UML_Package_Import_Access);
type Set_Of_UML_Package_Import is
new UML_Package_Import_Collections.Set with null record;
Empty_Set_Of_UML_Package_Import : constant Set_Of_UML_Package_Import;
type Ordered_Set_Of_UML_Package_Import is
new UML_Package_Import_Collections.Ordered_Set with null record;
Empty_Ordered_Set_Of_UML_Package_Import : constant Ordered_Set_Of_UML_Package_Import;
type Bag_Of_UML_Package_Import is
new UML_Package_Import_Collections.Bag with null record;
Empty_Bag_Of_UML_Package_Import : constant Bag_Of_UML_Package_Import;
type Sequence_Of_UML_Package_Import is
new UML_Package_Import_Collections.Sequence with null record;
Empty_Sequence_Of_UML_Package_Import : constant Sequence_Of_UML_Package_Import;
private
Empty_Set_Of_UML_Package_Import : constant Set_Of_UML_Package_Import
:= (UML_Package_Import_Collections.Set with null record);
Empty_Ordered_Set_Of_UML_Package_Import : constant Ordered_Set_Of_UML_Package_Import
:= (UML_Package_Import_Collections.Ordered_Set with null record);
Empty_Bag_Of_UML_Package_Import : constant Bag_Of_UML_Package_Import
:= (UML_Package_Import_Collections.Bag with null record);
Empty_Sequence_Of_UML_Package_Import : constant Sequence_Of_UML_Package_Import
:= (UML_Package_Import_Collections.Sequence with null record);
end AMF.UML.Package_Imports.Collections;
|
Rodeo-McCabe/orka | Ada | 2,981 | ads | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
private with GL.Low_Level;
package GL.Barriers is
pragma Preelaborate;
type Memory_Barrier_Bits (By_Region : Boolean) is record
Uniform : Boolean := False;
Texture_Fetch : Boolean := False;
Shader_Image_Access : Boolean := False;
Framebuffer : Boolean := False;
Atomic_Counter : Boolean := False;
Shader_Storage : Boolean := False;
case By_Region is
when False =>
Vertex_Attrib_Array : Boolean := False;
Element_Array : Boolean := False;
Command : Boolean := False;
Pixel_Buffer : Boolean := False;
Texture_Update : Boolean := False;
Buffer_Update : Boolean := False;
Transform_Feedback : Boolean := False;
Client_Mapped_Buffer : Boolean := False;
Query_Buffer : Boolean := False;
when others =>
null;
end case;
end record;
procedure Texture_Barrier;
procedure Memory_Barrier (Bits : Memory_Barrier_Bits)
with Pre => not Bits.By_Region;
-- Order memory transactions issued before this call relative
-- to those issues after this call
procedure Memory_Barrier_By_Region (Bits : Memory_Barrier_Bits)
with Pre => Bits.By_Region;
-- Order memory transactions caused by fragment shaders
private
for Memory_Barrier_Bits use record
Vertex_Attrib_Array at 0 range 0 .. 0;
Element_Array at 0 range 1 .. 1;
Uniform at 0 range 2 .. 2;
Texture_Fetch at 0 range 3 .. 3;
Shader_Image_Access at 0 range 5 .. 5;
Command at 0 range 6 .. 6;
Pixel_Buffer at 0 range 7 .. 7;
Texture_Update at 0 range 8 .. 8;
Buffer_Update at 0 range 9 .. 9;
Framebuffer at 0 range 10 .. 10;
Transform_Feedback at 0 range 11 .. 11;
Atomic_Counter at 0 range 12 .. 12;
Shader_Storage at 0 range 13 .. 13;
Client_Mapped_Buffer at 0 range 14 .. 14;
Query_Buffer at 0 range 15 .. 15;
-- Discriminant
By_Region at 2 range 0 .. 0;
end record;
for Memory_Barrier_Bits'Size use Low_Level.Bitfield'Size;
end GL.Barriers;
|
godunko/adawebui | Ada | 3,464 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2017-2020, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision: 5724 $ $Date: 2017-01-25 16:25:24 +0300 (Wed, 25 Jan 2017) $
------------------------------------------------------------------------------
package Web.UI.Slots is
pragma Preelaborate;
end Web.UI.Slots;
|
faelys/natools | Ada | 10,940 | adb | ------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
package body Natools.Reference_Tests.Pools is
use type Ref_Pools.Pool_Size;
procedure Check_Counts
(Test : in out NT.Test;
Pool : in Ref_Pools.Pool;
Active, Initialized, Total : in Ref_Pools.Pool_Size);
procedure Check_Order
(Test : in out NT.Test;
Pool : in out Ref_Pools.Pool);
------------------------------
-- Local Helper Subprograms --
------------------------------
procedure Check_Counts
(Test : in out NT.Test;
Pool : in Ref_Pools.Pool;
Active, Initialized, Total : in Ref_Pools.Pool_Size)
is
S : Ref_Pools.Pool_Size;
begin
S := Pool.Active_Size;
if S /= Active then
Test.Fail
("Pool.Active_Size is"
& Ref_Pools.Pool_Size'Image (S)
& ", expected "
& Ref_Pools.Pool_Size'Image (Active));
end if;
S := Pool.Initialized_Size;
if S /= Initialized then
Test.Fail
("Pool.Initialized_Size is"
& Ref_Pools.Pool_Size'Image (S)
& ", expected "
& Ref_Pools.Pool_Size'Image (Initialized));
end if;
S := Pool.Capacity;
if S /= Total then
Test.Fail
("Pool.Initialized_Size is"
& Ref_Pools.Pool_Size'Image (S)
& ", expected "
& Ref_Pools.Pool_Size'Image (Total));
end if;
end Check_Counts;
procedure Check_Order
(Test : in out NT.Test;
Pool : in out Ref_Pools.Pool)
is
procedure Process (Ref : in Refs.Reference);
Rank, Last : Natural := 0;
procedure Process (Ref : in Refs.Reference) is
begin
Rank := Rank + 1;
if Ref.Is_Empty then
Test.Fail ("Unexpected empty reference at rank"
& Natural'Image (Rank));
return;
end if;
declare
Accessor : constant Refs.Accessor := Ref.Query;
begin
if Accessor.Data.Instance_Number = 0 then
Test.Fail ("Unexpected null instance number at rank"
& Natural'Image (Rank));
elsif Last = 0 then
Last := Accessor.Data.Instance_Number;
elsif Accessor.Data.Instance_Number /= Last + 1 then
Test.Fail ("At rank"
& Natural'Image (Rank)
& ", reference to instance"
& Natural'Image (Accessor.Data.Instance_Number)
& " following reference to instance"
& Natural'Image (Last));
Last := 0;
else
Last := Accessor.Data.Instance_Number;
end if;
end;
end Process;
begin
Pool.Unchecked_Iterate (Process'Access);
end Check_Order;
------------------------
-- Peudo_Process Task --
------------------------
task body Pseudo_Process is
Time : Duration;
Ref : Refs.Reference;
begin
select
accept Start (Target : in Refs.Reference; Amount : in Duration) do
Time := Amount;
Ref := Target;
end Start;
or terminate;
end select;
delay Time;
Ref.Reset;
end Pseudo_Process;
procedure Bounded_Start
(Process : in out Pseudo_Process;
Pool : in out Ref_Pools.Pool;
Amount : in Duration;
Test : in out NT.Test;
Expected_Instance : in Natural)
is
Ref : Refs.Reference;
begin
Pool.Get (Factory'Access, Ref);
if Ref.Query.Data.Instance_Number /= Expected_Instance then
Test.Fail ("Got reference to instance"
& Natural'Image (Ref.Query.Data.Instance_Number)
& ", expected"
& Natural'Image (Expected_Instance));
end if;
Process.Start (Ref, Amount);
end Bounded_Start;
procedure Unbounded_Start
(Process : in out Pseudo_Process;
Pool : in out Ref_Pools.Pool;
Amount : in Duration;
Test : in out NT.Test;
Expected_Instance : in Natural)
is
Ref : Refs.Reference;
begin
Pool.Create (Factory'Access, Ref);
if Ref.Query.Data.Instance_Number /= Expected_Instance then
Test.Fail ("Got reference to instance"
& Natural'Image (Ref.Query.Data.Instance_Number)
& ", expected"
& Natural'Image (Expected_Instance));
end if;
Process.Start (Ref, Amount);
end Unbounded_Start;
-------------------------
-- Complete Test Suite --
-------------------------
procedure All_Tests (Report : in out NT.Reporter'Class) is
begin
Bounded_Pool (Report);
Static_Pool (Report);
Unbounded_Pool (Report);
end All_Tests;
-----------------------
-- Inidividual Tests --
-----------------------
procedure Bounded_Pool (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Bounded pool typical usage");
begin
declare
Test_Length : constant Duration := 0.5;
Ref_Pool : Ref_Pools.Pool;
Workers : array (1 .. 4) of Pseudo_Process;
begin
-- Timeline (in Test_Length/10): <-------->
-- Task using reference 1: 1111111111
-- Task using reference 2: 2222 44
-- Task using reference 3: 3333
Check_Counts (Test, Ref_Pool, 0, 0, 0);
Ref_Pool.Preallocate (3);
Check_Counts (Test, Ref_Pool, 0, 0, 3);
Bounded_Start (Workers (1), Ref_Pool, Test_Length, Test, 1);
Check_Counts (Test, Ref_Pool, 1, 1, 3);
delay Test_Length * 0.2;
Bounded_Start (Workers (2), Ref_Pool, Test_Length * 0.4, Test, 2);
Check_Counts (Test, Ref_Pool, 2, 2, 3);
delay Test_Length * 0.2;
Bounded_Start (Workers (3), Ref_Pool, Test_Length * 0.4, Test, 3);
Check_Counts (Test, Ref_Pool, 3, 3, 3);
delay Test_Length * 0.1;
begin
Bounded_Start (Workers (4), Ref_Pool, Test_Length * 0.2, Test, 0);
Test.Fail ("Expected exception after filling bounded pool");
exception
when Constraint_Error =>
null;
when Error : others =>
Test.Info ("At Get on full bounded pool,");
Test.Report_Exception (Error, NT.Fail);
end;
delay Test_Length * 0.2;
Check_Counts (Test, Ref_Pool, 2, 3, 3);
Bounded_Start (Workers (4), Ref_Pool, Test_Length * 0.2, Test, 2);
Check_Counts (Test, Ref_Pool, 3, 3, 3);
Check_Order (Test, Ref_Pool);
end;
exception
when Error : others => Test.Report_Exception (Error);
end Bounded_Pool;
procedure Static_Pool (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Static pool typical usage");
begin
declare
Size : constant Ref_Pools.Pool_Size := 10;
Ref_Pool : Ref_Pools.Pool;
Ref : array (Ref_Pools.Pool_Size range 1 .. Size) of Refs.Reference;
begin
Check_Counts (Test, Ref_Pool, 0, 0, 0);
Ref_Pool.Preallocate (Size, Factory'Access);
Check_Counts (Test, Ref_Pool, 0, Size, Size);
for I in Ref'Range loop
Ref_Pool.Get (Ref (I));
Check_Counts (Test, Ref_Pool, I, Size, Size);
end loop;
Ref (2).Reset;
Check_Counts (Test, Ref_Pool, Size - 1, Size, Size);
Ref_Pool.Get (Ref (2));
Check_Counts (Test, Ref_Pool, Size, Size, Size);
declare
Extra_Ref : Refs.Reference;
begin
Ref_Pool.Get (Extra_Ref);
Test.Fail ("Expected exception at Get on full pool");
exception
when Constraint_Error =>
null;
when Error : others =>
Test.Info ("At Get on full pool,");
Test.Report_Exception (Error, NT.Fail);
end;
Check_Order (Test, Ref_Pool);
end;
exception
when Error : others => Test.Report_Exception (Error);
end Static_Pool;
procedure Unbounded_Pool (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Unbounded pool typical usage");
begin
declare
Test_Length : constant Duration := 0.5;
Ref_Pool : Ref_Pools.Pool;
Workers : array (1 .. 5) of Pseudo_Process;
begin
Check_Counts (Test, Ref_Pool, 0, 0, 0);
Ref_Pool.Preallocate (1);
Check_Counts (Test, Ref_Pool, 0, 0, 1);
-- Timeline (in Test_Length/10): <-------->
-- Task using reference 1: 11111 444
-- Task using reference 2: 22222 55
-- Task using reference 3: 33333
Unbounded_Start (Workers (1), Ref_Pool, Test_Length * 0.5, Test, 1);
Check_Counts (Test, Ref_Pool, 1, 1, 1);
delay Test_Length * 0.2;
Unbounded_Start (Workers (2), Ref_Pool, Test_Length * 0.5, Test, 2);
Check_Counts (Test, Ref_Pool, 2, 2, 2);
delay Test_Length * 0.2;
Unbounded_Start (Workers (3), Ref_Pool, Test_Length * 0.5, Test, 3);
Check_Counts (Test, Ref_Pool, 3, 3, 3);
delay Test_Length * 0.2;
Check_Counts (Test, Ref_Pool, 2, 3, 3);
Unbounded_Start (Workers (4), Ref_Pool, Test_Length * 0.3, Test, 1);
Check_Counts (Test, Ref_Pool, 3, 3, 3);
delay Test_Length * 0.1;
Check_Counts (Test, Ref_Pool, 2, 3, 3);
Ref_Pool.Purge;
Check_Counts (Test, Ref_Pool, 2, 2, 2);
Unbounded_Start (Workers (5), Ref_Pool, Test_Length * 0.2, Test, 3);
end;
exception
when Error : others => Test.Report_Exception (Error);
end Unbounded_Pool;
end Natools.Reference_Tests.Pools;
|
Rodeo-McCabe/orka | Ada | 5,889 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2017 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with Ada.Numerics.Generic_Elementary_Functions;
package body Orka.Transforms.SIMD_Quaternions is
package EF is new Ada.Numerics.Generic_Elementary_Functions (Vectors.Element_Type);
function Vector_Part (Elements : Quaternion) return Vector4 is
begin
return Result : Vector4 := Vector4 (Elements) do
Result (W) := 0.0;
end return;
end Vector_Part;
function "*" (Left, Right : Quaternion) return Quaternion is
use Vectors;
Lv : constant Vector4 := Vector_Part (Left);
Rv : constant Vector4 := Vector_Part (Right);
Ls : constant Vectors.Element_Type := Left (W);
Rs : constant Vectors.Element_Type := Right (W);
V : constant Vector4 := Ls * Rv + Rs * Lv + Vectors.Cross (Lv, Rv);
S : constant Element_Type := Ls * Rs - Vectors.Dot (Lv, Rv);
begin
return Result : Quaternion := Quaternion (V) do
Result (W) := S;
end return;
end "*";
function Conjugate (Elements : Quaternion) return Quaternion is
Element_W : constant Vectors.Element_Type := Elements (W);
use Vectors;
begin
return Result : Quaternion := Quaternion (-Vector4 (Elements)) do
Result (W) := Element_W;
end return;
end Conjugate;
function Norm (Elements : Quaternion) return Vectors.Element_Type is
(Vectors.Magnitude (Vector4 (Elements)));
function Normalize (Elements : Quaternion) return Quaternion is
(Quaternion (Vectors.Normalize (Vector4 (Elements))));
function Normalized (Elements : Quaternion) return Boolean is
(Vectors.Normalized (Vector4 (Elements)));
function To_Axis_Angle (Elements : Quaternion) return Axis_Angle is
use type Vectors.Element_Type;
Angle : constant Vectors.Element_Type := EF.Arccos (Elements (W)) * 2.0;
SA : constant Vectors.Element_Type := EF.Sin (Angle / 2.0);
begin
if SA /= 0.0 then
declare
use Vectors;
Axis : Vector4 := Vector4 (Elements) * (1.0 / SA);
begin
Axis (W) := 0.0;
return (Axis => Axis, Angle => Angle);
end;
else
-- Singularity occurs when angle is 0. Return an arbitrary axis
return (Axis => (1.0, 0.0, 0.0, 0.0), Angle => 0.0);
end if;
end To_Axis_Angle;
function R
(Axis : Vector4;
Angle : Vectors.Element_Type) return Quaternion
is
use type Vectors.Element_Type;
CA : constant Vectors.Element_Type := EF.Cos (Angle / 2.0);
SA : constant Vectors.Element_Type := EF.Sin (Angle / 2.0);
use Vectors;
begin
return Result : Quaternion := Quaternion (Axis * SA) do
Result (W) := CA;
end return;
end R;
function R (Left, Right : Vector4) return Quaternion is
use type Vectors.Element_Type;
S : constant Vector4 := Vectors.Normalize (Left);
T : constant Vector4 := Vectors.Normalize (Right);
E : constant Vectors.Element_Type := Vectors.Dot (S, T);
SRE : constant Vectors.Element_Type := EF.Sqrt (2.0 * (1.0 + E));
use Vectors;
begin
-- Division by zero if Left and Right are in opposite direction.
-- Use rotation axis perpendicular to s and angle of 180 degrees
if SRE /= 0.0 then
-- Equation 4.53 from chapter 4.3 Quaternions from Real-Time Rendering
-- (third edition, 2008)
declare
Result : Quaternion := Quaternion ((1.0 / SRE) * Vectors.Cross (S, T));
begin
Result (W) := SRE / 2.0;
return Normalize (Result);
end;
else
if abs S (Z) < abs S (X) then
return R ((S (Y), -S (X), 0.0, 0.0), Ada.Numerics.Pi);
else
return R ((0.0, -S (Z), S (Y), 0.0), Ada.Numerics.Pi);
end if;
end if;
end R;
function Difference (Left, Right : Quaternion) return Quaternion is
begin
return Right * Conjugate (Left);
end Difference;
procedure Rotate_At_Origin
(Vector : in out Vector4;
Elements : Quaternion)
is
Result : Vectors.Vector_Type;
begin
Result := Vectors.Vector_Type (Elements * Quaternion (Vector) * Conjugate (Elements));
Vector := Result;
end Rotate_At_Origin;
function Lerp
(Left, Right : Quaternion;
Time : Vectors.Element_Type) return Quaternion
is
use type Vectors.Element_Type;
use Vectors;
begin
return Normalize (Quaternion ((1.0 - Time) * Vector4 (Left) + Time * Vector4 (Right)));
end Lerp;
function Slerp
(Left, Right : Quaternion;
Time : Vectors.Element_Type) return Quaternion
is
use type Vectors.Element_Type;
Cos_Angle : constant Vectors.Element_Type := Vectors.Dot (Vector4 (Left), Vector4 (Right));
Angle : constant Vectors.Element_Type := EF.Arccos (Cos_Angle);
SA : constant Vectors.Element_Type := EF.Sin (Angle);
SL : constant Vectors.Element_Type := EF.Sin ((1.0 - Time) * Angle);
SR : constant Vectors.Element_Type := EF.Sin (Time * Angle);
use Vectors;
begin
return Quaternion ((SL / SA) * Vector4 (Left) + (SR / SA) * Vector4 (Right));
end Slerp;
end Orka.Transforms.SIMD_Quaternions;
|
zhmu/ananas | Ada | 197,258 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- G N A T . S P I T B O L . P A T T E R N S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1998-2022, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- Note: the data structures and general approach used in this implementation
-- are derived from the original MINIMAL sources for SPITBOL. The code is not
-- a direct translation, but the approach is followed closely. In particular,
-- we use the one stack approach developed in the SPITBOL implementation.
with Ada.Strings.Unbounded.Aux; use Ada.Strings.Unbounded.Aux;
with GNAT.Debug_Utilities; use GNAT.Debug_Utilities;
with System; use System;
with Ada.Unchecked_Conversion;
with Ada.Unchecked_Deallocation;
package body GNAT.Spitbol.Patterns is
------------------------
-- Internal Debugging --
------------------------
Internal_Debug : constant Boolean := False;
-- Set this flag to True to activate some built-in debugging traceback
-- These are all lines output with PutD and Put_LineD.
procedure New_LineD;
pragma Inline (New_LineD);
-- Output new blank line with New_Line if Internal_Debug is True
procedure PutD (Str : String);
pragma Inline (PutD);
-- Output string with Put if Internal_Debug is True
procedure Put_LineD (Str : String);
pragma Inline (Put_LineD);
-- Output string with Put_Line if Internal_Debug is True
-----------------------------
-- Local Type Declarations --
-----------------------------
subtype String_Ptr is Ada.Strings.Unbounded.String_Access;
subtype File_Ptr is Ada.Text_IO.File_Access;
function To_Address is new Ada.Unchecked_Conversion (PE_Ptr, Address);
-- Used only for debugging output purposes
subtype AFC is Ada.Finalization.Controlled;
N : constant PE_Ptr := null;
-- Shorthand used to initialize Copy fields to null
type Natural_Ptr is access all Natural;
type Pattern_Ptr is access all Pattern;
--------------------------------------------------
-- Description of Algorithm and Data Structures --
--------------------------------------------------
-- A pattern structure is represented as a linked graph of nodes
-- with the following structure:
-- +------------------------------------+
-- I Pcode I
-- +------------------------------------+
-- I Index I
-- +------------------------------------+
-- I Pthen I
-- +------------------------------------+
-- I parameter(s) I
-- +------------------------------------+
-- Pcode is a code value indicating the type of the pattern node. This
-- code is used both as the discriminant value for the record, and as
-- the case index in the main match routine that branches to the proper
-- match code for the given element.
-- Index is a serial index number. The use of these serial index
-- numbers is described in a separate section.
-- Pthen is a pointer to the successor node, i.e the node to be matched
-- if the attempt to match the node succeeds. If this is the last node
-- of the pattern to be matched, then Pthen points to a dummy node
-- of kind PC_EOP (end of pattern), which initializes pattern exit.
-- The parameter or parameters are present for certain node types,
-- and the type varies with the pattern code.
type Pattern_Code is (
PC_Arb_Y,
PC_Assign,
PC_Bal,
PC_BreakX_X,
PC_Cancel,
PC_EOP,
PC_Fail,
PC_Fence,
PC_Fence_X,
PC_Fence_Y,
PC_R_Enter,
PC_R_Remove,
PC_R_Restore,
PC_Rest,
PC_Succeed,
PC_Unanchored,
PC_Alt,
PC_Arb_X,
PC_Arbno_S,
PC_Arbno_X,
PC_Rpat,
PC_Pred_Func,
PC_Assign_Imm,
PC_Assign_OnM,
PC_Any_VP,
PC_Break_VP,
PC_BreakX_VP,
PC_NotAny_VP,
PC_NSpan_VP,
PC_Span_VP,
PC_String_VP,
PC_Write_Imm,
PC_Write_OnM,
PC_Null,
PC_String,
PC_String_2,
PC_String_3,
PC_String_4,
PC_String_5,
PC_String_6,
PC_Setcur,
PC_Any_CH,
PC_Break_CH,
PC_BreakX_CH,
PC_Char,
PC_NotAny_CH,
PC_NSpan_CH,
PC_Span_CH,
PC_Any_CS,
PC_Break_CS,
PC_BreakX_CS,
PC_NotAny_CS,
PC_NSpan_CS,
PC_Span_CS,
PC_Arbno_Y,
PC_Len_Nat,
PC_Pos_Nat,
PC_RPos_Nat,
PC_RTab_Nat,
PC_Tab_Nat,
PC_Pos_NF,
PC_Len_NF,
PC_RPos_NF,
PC_RTab_NF,
PC_Tab_NF,
PC_Pos_NP,
PC_Len_NP,
PC_RPos_NP,
PC_RTab_NP,
PC_Tab_NP,
PC_Any_VF,
PC_Break_VF,
PC_BreakX_VF,
PC_NotAny_VF,
PC_NSpan_VF,
PC_Span_VF,
PC_String_VF);
type IndexT is range 0 .. +(2 **15 - 1);
type PE (Pcode : Pattern_Code) is record
Index : IndexT;
-- Serial index number of pattern element within pattern
Pthen : PE_Ptr;
-- Successor element, to be matched after this one
case Pcode is
when PC_Arb_Y
| PC_Assign
| PC_Bal
| PC_BreakX_X
| PC_Cancel
| PC_EOP
| PC_Fail
| PC_Fence
| PC_Fence_X
| PC_Fence_Y
| PC_Null
| PC_R_Enter
| PC_R_Remove
| PC_R_Restore
| PC_Rest
| PC_Succeed
| PC_Unanchored
=>
null;
when PC_Alt
| PC_Arb_X
| PC_Arbno_S
| PC_Arbno_X
=>
Alt : PE_Ptr;
when PC_Rpat =>
PP : Pattern_Ptr;
when PC_Pred_Func =>
BF : Boolean_Func;
when PC_Assign_Imm
| PC_Assign_OnM
| PC_Any_VP
| PC_Break_VP
| PC_BreakX_VP
| PC_NotAny_VP
| PC_NSpan_VP
| PC_Span_VP
| PC_String_VP
=>
VP : VString_Ptr;
when PC_Write_Imm
| PC_Write_OnM
=>
FP : File_Ptr;
when PC_String =>
Str : String_Ptr;
when PC_String_2 =>
Str2 : String (1 .. 2);
when PC_String_3 =>
Str3 : String (1 .. 3);
when PC_String_4 =>
Str4 : String (1 .. 4);
when PC_String_5 =>
Str5 : String (1 .. 5);
when PC_String_6 =>
Str6 : String (1 .. 6);
when PC_Setcur =>
Var : Natural_Ptr;
when PC_Any_CH
| PC_Break_CH
| PC_BreakX_CH
| PC_Char
| PC_NotAny_CH
| PC_NSpan_CH
| PC_Span_CH
=>
Char : Character;
when PC_Any_CS
| PC_Break_CS
| PC_BreakX_CS
| PC_NotAny_CS
| PC_NSpan_CS
| PC_Span_CS
=>
CS : Character_Set;
when PC_Arbno_Y
| PC_Len_Nat
| PC_Pos_Nat
| PC_RPos_Nat
| PC_RTab_Nat
| PC_Tab_Nat
=>
Nat : Natural;
when PC_Pos_NF
| PC_Len_NF
| PC_RPos_NF
| PC_RTab_NF
| PC_Tab_NF
=>
NF : Natural_Func;
when PC_Pos_NP
| PC_Len_NP
| PC_RPos_NP
| PC_RTab_NP
| PC_Tab_NP
=>
NP : Natural_Ptr;
when PC_Any_VF
| PC_Break_VF
| PC_BreakX_VF
| PC_NotAny_VF
| PC_NSpan_VF
| PC_Span_VF
| PC_String_VF
=>
VF : VString_Func;
end case;
end record;
subtype PC_Has_Alt is Pattern_Code range PC_Alt .. PC_Arbno_X;
-- Range of pattern codes that has an Alt field. This is used in the
-- recursive traversals, since these links must be followed.
EOP_Element : aliased constant PE := (PC_EOP, 0, N);
-- This is the end of pattern element, and is thus the representation of
-- a null pattern. It has a zero index element since it is never placed
-- inside a pattern. Furthermore it does not need a successor, since it
-- marks the end of the pattern, so that no more successors are needed.
EOP : constant PE_Ptr := EOP_Element'Unrestricted_Access;
-- This is the end of pattern pointer, that is used in the Pthen pointer
-- of other nodes to signal end of pattern.
-- The following array is used to determine if a pattern used as an
-- argument for Arbno is eligible for treatment using the simple Arbno
-- structure (i.e. it is a pattern that is guaranteed to match at least
-- one character on success, and not to make any entries on the stack.
OK_For_Simple_Arbno : constant array (Pattern_Code) of Boolean :=
[PC_Any_CS |
PC_Any_CH |
PC_Any_VF |
PC_Any_VP |
PC_Char |
PC_Len_Nat |
PC_NotAny_CS |
PC_NotAny_CH |
PC_NotAny_VF |
PC_NotAny_VP |
PC_Span_CS |
PC_Span_CH |
PC_Span_VF |
PC_Span_VP |
PC_String |
PC_String_2 |
PC_String_3 |
PC_String_4 |
PC_String_5 |
PC_String_6 => True,
others => False];
-------------------------------
-- The Pattern History Stack --
-------------------------------
-- The pattern history stack is used for controlling backtracking when
-- a match fails. The idea is to stack entries that give a cursor value
-- to be restored, and a node to be reestablished as the current node to
-- attempt an appropriate rematch operation. The processing for a pattern
-- element that has rematch alternatives pushes an appropriate entry or
-- entry on to the stack, and the proceeds. If a match fails at any point,
-- the top element of the stack is popped off, resetting the cursor and
-- the match continues by accessing the node stored with this entry.
type Stack_Entry is record
Cursor : Integer;
-- Saved cursor value that is restored when this entry is popped
-- from the stack if a match attempt fails. Occasionally, this
-- field is used to store a history stack pointer instead of a
-- cursor. Such cases are noted in the documentation and the value
-- stored is negative since stack pointer values are always negative.
Node : PE_Ptr;
-- This pattern element reference is reestablished as the current
-- Node to be matched (which will attempt an appropriate rematch).
end record;
subtype Stack_Range is Integer range -Stack_Size .. -1;
type Stack_Type is array (Stack_Range) of Stack_Entry;
-- The type used for a history stack. The actual instance of the stack
-- is declared as a local variable in the Match routine, to properly
-- handle recursive calls to Match. All stack pointer values are negative
-- to distinguish them from normal cursor values.
-- Note: the pattern matching stack is used only to handle backtracking.
-- If no backtracking occurs, its entries are never accessed, and never
-- popped off, and in particular it is normal for a successful match
-- to terminate with entries on the stack that are simply discarded.
-- Note: in subsequent diagrams of the stack, we always place element
-- zero (the deepest element) at the top of the page, then build the
-- stack down on the page with the most recent (top of stack) element
-- being the bottom-most entry on the page.
-- Stack checking is handled by labeling every pattern with the maximum
-- number of stack entries that are required, so a single check at the
-- start of matching the pattern suffices. There are two exceptions.
-- First, the count does not include entries for recursive pattern
-- references. Such recursions must therefore perform a specific
-- stack check with respect to the number of stack entries required
-- by the recursive pattern that is accessed and the amount of stack
-- that remains unused.
-- Second, the count includes only one iteration of an Arbno pattern,
-- so a specific check must be made on subsequent iterations that there
-- is still enough stack space left. The Arbno node has a field that
-- records the number of stack entries required by its argument for
-- this purpose.
---------------------------------------------------
-- Use of Serial Index Field in Pattern Elements --
---------------------------------------------------
-- The serial index numbers for the pattern elements are assigned as
-- a pattern is constructed from its constituent elements. Note that there
-- is never any sharing of pattern elements between patterns (copies are
-- always made), so the serial index numbers are unique to a particular
-- pattern as referenced from the P field of a value of type Pattern.
-- The index numbers meet three separate invariants, which are used for
-- various purposes as described in this section.
-- First, the numbers uniquely identify the pattern elements within a
-- pattern. If Num is the number of elements in a given pattern, then
-- the serial index numbers for the elements of this pattern will range
-- from 1 .. Num, so that each element has a separate value.
-- The purpose of this assignment is to provide a convenient auxiliary
-- data structure mechanism during operations which must traverse a
-- pattern (e.g. copy and finalization processing). Once constructed
-- patterns are strictly read only. This is necessary to allow sharing
-- of patterns between tasks. This means that we cannot go marking the
-- pattern (e.g. with a visited bit). Instead we construct a separate
-- vector that contains the necessary information indexed by the Index
-- values in the pattern elements. For this purpose the only requirement
-- is that they be uniquely assigned.
-- Second, the pattern element referenced directly, i.e. the leading
-- pattern element, is always the maximum numbered element and therefore
-- indicates the total number of elements in the pattern. More precisely,
-- the element referenced by the P field of a pattern value, or the
-- element returned by any of the internal pattern construction routines
-- in the body (that return a value of type PE_Ptr) always is this
-- maximum element,
-- The purpose of this requirement is to allow an immediate determination
-- of the number of pattern elements within a pattern. This is used to
-- properly size the vectors used to contain auxiliary information for
-- traversal as described above.
-- Third, as compound pattern structures are constructed, the way in which
-- constituent parts of the pattern are constructed is stylized. This is
-- an automatic consequence of the way that these compound structures
-- are constructed, and basically what we are doing is simply documenting
-- and specifying the natural result of the pattern construction. The
-- section describing compound pattern structures gives details of the
-- numbering of each compound pattern structure.
-- The purpose of specifying the stylized numbering structures for the
-- compound patterns is to help simplify the processing in the Image
-- function, since it eases the task of retrieving the original recursive
-- structure of the pattern from the flat graph structure of elements.
-- This use in the Image function is the only point at which the code
-- makes use of the stylized structures.
type Ref_Array is array (IndexT range <>) of PE_Ptr;
-- This type is used to build an array whose N'th entry references the
-- element in a pattern whose Index value is N. See Build_Ref_Array.
procedure Build_Ref_Array (E : PE_Ptr; RA : out Ref_Array);
-- Given a pattern element which is the leading element of a pattern
-- structure, and a Ref_Array with bounds 1 .. E.Index, fills in the
-- Ref_Array so that its N'th entry references the element of the
-- referenced pattern whose Index value is N.
-------------------------------
-- Recursive Pattern Matches --
-------------------------------
-- The pattern primitive (+P) where P is a Pattern_Ptr or Pattern_Func
-- causes a recursive pattern match. This cannot be handled by an actual
-- recursive call to the outer level Match routine, since this would not
-- allow for possible backtracking into the region matched by the inner
-- pattern. Indeed this is the classical clash between recursion and
-- backtracking, and a simple recursive stack structure does not suffice.
-- This section describes how this recursion and the possible associated
-- backtracking is handled. We still use a single stack, but we establish
-- the concept of nested regions on this stack, each of which has a stack
-- base value pointing to the deepest stack entry of the region. The base
-- value for the outer level is zero.
-- When a recursive match is established, two special stack entries are
-- made. The first entry is used to save the original node that starts
-- the recursive match. This is saved so that the successor field of
-- this node is accessible at the end of the match, but it is never
-- popped and executed.
-- The second entry corresponds to a standard new region action. A
-- PC_R_Remove node is stacked, whose cursor field is used to store
-- the outer stack base, and the stack base is reset to point to
-- this PC_R_Remove node. Then the recursive pattern is matched and
-- it can make history stack entries in the normal matter, so now
-- the stack looks like:
-- (stack entries made by outer level)
-- (Special entry, node is (+P) successor
-- cursor entry is not used)
-- (PC_R_Remove entry, "cursor" value is (negative) <-- Stack base
-- saved base value for the enclosing region)
-- (stack entries made by inner level)
-- If a subsequent failure occurs and pops the PC_R_Remove node, it
-- removes itself and the special entry immediately underneath it,
-- restores the stack base value for the enclosing region, and then
-- again signals failure to look for alternatives that were stacked
-- before the recursion was initiated.
-- Now we need to consider what happens if the inner pattern succeeds, as
-- signalled by accessing the special PC_EOP pattern primitive. First we
-- recognize the nested case by looking at the Base value. If this Base
-- value is Stack'First, then the entire match has succeeded, but if the
-- base value is greater than Stack'First, then we have successfully
-- matched an inner pattern, and processing continues at the outer level.
-- There are two cases. The simple case is when the inner pattern has made
-- no stack entries, as recognized by the fact that the current stack
-- pointer is equal to the current base value. In this case it is fine to
-- remove all trace of the recursion by restoring the outer base value and
-- using the special entry to find the appropriate successor node.
-- The more complex case arises when the inner match does make stack
-- entries. In this case, the PC_EOP processing stacks a special entry
-- whose cursor value saves the saved inner base value (the one that
-- references the corresponding PC_R_Remove value), and whose node
-- pointer references a PC_R_Restore node, so the stack looks like:
-- (stack entries made by outer level)
-- (Special entry, node is (+P) successor,
-- cursor entry is not used)
-- (PC_R_Remove entry, "cursor" value is (negative)
-- saved base value for the enclosing region)
-- (stack entries made by inner level)
-- (PC_Region_Replace entry, "cursor" value is (negative)
-- stack pointer value referencing the PC_R_Remove entry).
-- If the entire match succeeds, then these stack entries are, as usual,
-- ignored and abandoned. If on the other hand a subsequent failure
-- causes the PC_Region_Replace entry to be popped, it restores the
-- inner base value from its saved "cursor" value and then fails again.
-- Note that it is OK that the cursor is temporarily clobbered by this
-- pop, since the second failure will reestablish a proper cursor value.
---------------------------------
-- Compound Pattern Structures --
---------------------------------
-- This section discusses the compound structures used to represent
-- constructed patterns. It shows the graph structures of pattern
-- elements that are constructed, and in the case of patterns that
-- provide backtracking possibilities, describes how the history
-- stack is used to control the backtracking. Finally, it notes the
-- way in which the Index numbers are assigned to the structure.
-- In all diagrams, solid lines (built with minus signs or vertical
-- bars, represent successor pointers (Pthen fields) with > or V used
-- to indicate the direction of the pointer. The initial node of the
-- structure is in the upper left of the diagram. A dotted line is an
-- alternative pointer from the element above it to the element below
-- it. See individual sections for details on how alternatives are used.
-------------------
-- Concatenation --
-------------------
-- In the pattern structures listed in this section, a line that looks
-- like ----> with nothing to the right indicates an end of pattern
-- (EOP) pointer that represents the end of the match.
-- When a pattern concatenation (L & R) occurs, the resulting structure
-- is obtained by finding all such EOP pointers in L, and replacing
-- them to point to R. This is the most important flattening that
-- occurs in constructing a pattern, and it means that the pattern
-- matching circuitry does not have to keep track of the structure
-- of a pattern with respect to concatenation, since the appropriate
-- successor is always at hand.
-- Concatenation itself generates no additional possibilities for
-- backtracking, but the constituent patterns of the concatenated
-- structure will make stack entries as usual. The maximum amount
-- of stack required by the structure is thus simply the sum of the
-- maximums required by L and R.
-- The index numbering of a concatenation structure works by leaving
-- the numbering of the right hand pattern, R, unchanged and adjusting
-- the numbers in the left hand pattern, L up by the count of elements
-- in R. This ensures that the maximum numbered element is the leading
-- element as required (given that it was the leading element in L).
-----------------
-- Alternation --
-----------------
-- A pattern (L or R) constructs the structure:
-- +---+ +---+
-- | A |---->| L |---->
-- +---+ +---+
-- .
-- .
-- +---+
-- | R |---->
-- +---+
-- The A element here is a PC_Alt node, and the dotted line represents
-- the contents of the Alt field. When the PC_Alt element is matched,
-- it stacks a pointer to the leading element of R on the history stack
-- so that on subsequent failure, a match of R is attempted.
-- The A node is the highest numbered element in the pattern. The
-- original index numbers of R are unchanged, but the index numbers
-- of the L pattern are adjusted up by the count of elements in R.
-- Note that the difference between the index of the L leading element
-- the index of the R leading element (after building the alt structure)
-- indicates the number of nodes in L, and this is true even after the
-- structure is incorporated into some larger structure. For example,
-- if the A node has index 16, and L has index 15 and R has index
-- 5, then we know that L has 10 (15-5) elements in it.
-- Suppose that we now concatenate this structure to another pattern
-- with 9 elements in it. We will now have the A node with an index
-- of 25, L with an index of 24 and R with an index of 14. We still
-- know that L has 10 (24-14) elements in it, numbered 15-24, and
-- consequently the successor of the alternation structure has an
-- index with a value less than 15. This is used in Image to figure
-- out the original recursive structure of a pattern.
-- To clarify the interaction of the alternation and concatenation
-- structures, here is a more complex example of the structure built
-- for the pattern:
-- (V or W or X) (Y or Z)
-- where A,B,C,D,E are all single element patterns:
-- +---+ +---+ +---+ +---+
-- I A I---->I V I---+-->I A I---->I Y I---->
-- +---+ +---+ I +---+ +---+
-- . I .
-- . I .
-- +---+ +---+ I +---+
-- I A I---->I W I-->I I Z I---->
-- +---+ +---+ I +---+
-- . I
-- . I
-- +---+ I
-- I X I------------>+
-- +---+
-- The numbering of the nodes would be as follows:
-- +---+ +---+ +---+ +---+
-- I 8 I---->I 7 I---+-->I 3 I---->I 2 I---->
-- +---+ +---+ I +---+ +---+
-- . I .
-- . I .
-- +---+ +---+ I +---+
-- I 6 I---->I 5 I-->I I 1 I---->
-- +---+ +---+ I +---+
-- . I
-- . I
-- +---+ I
-- I 4 I------------>+
-- +---+
-- Note: The above structure actually corresponds to
-- (A or (B or C)) (D or E)
-- rather than
-- ((A or B) or C) (D or E)
-- which is the more natural interpretation, but in fact alternation
-- is associative, and the construction of an alternative changes the
-- left grouped pattern to the right grouped pattern in any case, so
-- that the Image function produces a more natural looking output.
---------
-- Arb --
---------
-- An Arb pattern builds the structure
-- +---+
-- | X |---->
-- +---+
-- .
-- .
-- +---+
-- | Y |---->
-- +---+
-- The X node is a PC_Arb_X node, which matches null, and stacks a
-- pointer to Y node, which is the PC_Arb_Y node that matches one
-- extra character and restacks itself.
-- The PC_Arb_X node is numbered 2, and the PC_Arb_Y node is 1
-------------------------
-- Arbno (simple case) --
-------------------------
-- The simple form of Arbno can be used where the pattern always
-- matches at least one character if it succeeds, and it is known
-- not to make any history stack entries. In this case, Arbno (P)
-- can construct the following structure:
-- +-------------+
-- | ^
-- V |
-- +---+ |
-- | S |----> |
-- +---+ |
-- . |
-- . |
-- +---+ |
-- | P |---------->+
-- +---+
-- The S (PC_Arbno_S) node matches null stacking a pointer to the
-- pattern P. If a subsequent failure causes P to be matched and
-- this match succeeds, then node A gets restacked to try another
-- instance if needed by a subsequent failure.
-- The node numbering of the constituent pattern P is not affected.
-- The S node has a node number of P.Index + 1.
--------------------------
-- Arbno (complex case) --
--------------------------
-- A call to Arbno (P), where P can match null (or at least is not
-- known to require a non-null string) and/or P requires pattern stack
-- entries, constructs the following structure:
-- +--------------------------+
-- | ^
-- V |
-- +---+ |
-- | X |----> |
-- +---+ |
-- . |
-- . |
-- +---+ +---+ +---+ |
-- | E |---->| P |---->| Y |--->+
-- +---+ +---+ +---+
-- The node X (PC_Arbno_X) matches null, stacking a pointer to the
-- E-P-X structure used to match one Arbno instance.
-- Here E is the PC_R_Enter node which matches null and creates two
-- stack entries. The first is a special entry whose node field is
-- not used at all, and whose cursor field has the initial cursor.
-- The second entry corresponds to a standard new region action. A
-- PC_R_Remove node is stacked, whose cursor field is used to store
-- the outer stack base, and the stack base is reset to point to
-- this PC_R_Remove node. Then the pattern P is matched, and it can
-- make history stack entries in the normal manner, so now the stack
-- looks like:
-- (stack entries made before assign pattern)
-- (Special entry, node field not used,
-- used only to save initial cursor)
-- (PC_R_Remove entry, "cursor" value is (negative) <-- Stack Base
-- saved base value for the enclosing region)
-- (stack entries made by matching P)
-- If the match of P fails, then the PC_R_Remove entry is popped and
-- it removes both itself and the special entry underneath it,
-- restores the outer stack base, and signals failure.
-- If the match of P succeeds, then node Y, the PC_Arbno_Y node, pops
-- the inner region. There are two possibilities. If matching P left
-- no stack entries, then all traces of the inner region can be removed.
-- If there are stack entries, then we push an PC_Region_Replace stack
-- entry whose "cursor" value is the inner stack base value, and then
-- restore the outer stack base value, so the stack looks like:
-- (stack entries made before assign pattern)
-- (Special entry, node field not used,
-- used only to save initial cursor)
-- (PC_R_Remove entry, "cursor" value is (negative)
-- saved base value for the enclosing region)
-- (stack entries made by matching P)
-- (PC_Region_Replace entry, "cursor" value is (negative)
-- stack pointer value referencing the PC_R_Remove entry).
-- Now that we have matched another instance of the Arbno pattern,
-- we need to move to the successor. There are two cases. If the
-- Arbno pattern matched null, then there is no point in seeking
-- alternatives, since we would just match a whole bunch of nulls.
-- In this case we look through the alternative node, and move
-- directly to its successor (i.e. the successor of the Arbno
-- pattern). If on the other hand a non-null string was matched,
-- we simply follow the successor to the alternative node, which
-- sets up for another possible match of the Arbno pattern.
-- As noted in the section on stack checking, the stack count (and
-- hence the stack check) for a pattern includes only one iteration
-- of the Arbno pattern. To make sure that multiple iterations do not
-- overflow the stack, the Arbno node saves the stack count required
-- by a single iteration, and the Concat function increments this to
-- include stack entries required by any successor. The PC_Arbno_Y
-- node uses this count to ensure that sufficient stack remains
-- before proceeding after matching each new instance.
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the Y node is numbered N + 1,
-- the E node is N + 2, and the X node is N + 3.
----------------------
-- Assign Immediate --
----------------------
-- Immediate assignment (P * V) constructs the following structure
-- +---+ +---+ +---+
-- | E |---->| P |---->| A |---->
-- +---+ +---+ +---+
-- Here E is the PC_R_Enter node which matches null and creates two
-- stack entries. The first is a special entry whose node field is
-- not used at all, and whose cursor field has the initial cursor.
-- The second entry corresponds to a standard new region action. A
-- PC_R_Remove node is stacked, whose cursor field is used to store
-- the outer stack base, and the stack base is reset to point to
-- this PC_R_Remove node. Then the pattern P is matched, and it can
-- make history stack entries in the normal manner, so now the stack
-- looks like:
-- (stack entries made before assign pattern)
-- (Special entry, node field not used,
-- used only to save initial cursor)
-- (PC_R_Remove entry, "cursor" value is (negative) <-- Stack Base
-- saved base value for the enclosing region)
-- (stack entries made by matching P)
-- If the match of P fails, then the PC_R_Remove entry is popped
-- and it removes both itself and the special entry underneath it,
-- restores the outer stack base, and signals failure.
-- If the match of P succeeds, then node A, which is the actual
-- PC_Assign_Imm node, executes the assignment (using the stack
-- base to locate the entry with the saved starting cursor value),
-- and the pops the inner region. There are two possibilities, if
-- matching P left no stack entries, then all traces of the inner
-- region can be removed. If there are stack entries, then we push
-- an PC_Region_Replace stack entry whose "cursor" value is the
-- inner stack base value, and then restore the outer stack base
-- value, so the stack looks like:
-- (stack entries made before assign pattern)
-- (Special entry, node field not used,
-- used only to save initial cursor)
-- (PC_R_Remove entry, "cursor" value is (negative)
-- saved base value for the enclosing region)
-- (stack entries made by matching P)
-- (PC_Region_Replace entry, "cursor" value is the (negative)
-- stack pointer value referencing the PC_R_Remove entry).
-- If a subsequent failure occurs, the PC_Region_Replace node restores
-- the inner stack base value and signals failure to explore rematches
-- of the pattern P.
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the A node is numbered N + 1,
-- and the E node is N + 2.
---------------------
-- Assign On Match --
---------------------
-- The assign on match (**) pattern is quite similar to the assign
-- immediate pattern, except that the actual assignment has to be
-- delayed. The following structure is constructed:
-- +---+ +---+ +---+
-- | E |---->| P |---->| A |---->
-- +---+ +---+ +---+
-- The operation of this pattern is identical to that described above
-- for deferred assignment, up to the point where P has been matched.
-- The A node, which is the PC_Assign_OnM node first pushes a
-- PC_Assign node onto the history stack. This node saves the ending
-- cursor and acts as a flag for the final assignment, as further
-- described below.
-- It then stores a pointer to itself in the special entry node field.
-- This was otherwise unused, and is now used to retrieve the address
-- of the variable to be assigned at the end of the pattern.
-- After that the inner region is terminated in the usual manner,
-- by stacking a PC_R_Restore entry as described for the assign
-- immediate case. Note that the optimization of completely
-- removing the inner region does not happen in this case, since
-- we have at least one stack entry (the PC_Assign one we just made).
-- The stack now looks like:
-- (stack entries made before assign pattern)
-- (Special entry, node points to copy of
-- the PC_Assign_OnM node, and the
-- cursor field saves the initial cursor).
-- (PC_R_Remove entry, "cursor" value is (negative)
-- saved base value for the enclosing region)
-- (stack entries made by matching P)
-- (PC_Assign entry, saves final cursor)
-- (PC_Region_Replace entry, "cursor" value is (negative)
-- stack pointer value referencing the PC_R_Remove entry).
-- If a subsequent failure causes the PC_Assign node to execute it
-- simply removes itself and propagates the failure.
-- If the match succeeds, then the history stack is scanned for
-- PC_Assign nodes, and the assignments are executed (examination
-- of the above diagram will show that all the necessary data is
-- at hand for the assignment).
-- To optimize the common case where no assign-on-match operations
-- are present, a global flag Assign_OnM is maintained which is
-- initialize to False, and gets set True as part of the execution
-- of the PC_Assign_OnM node. The scan of the history stack for
-- PC_Assign entries is done only if this flag is set.
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the A node is numbered N + 1,
-- and the E node is N + 2.
---------
-- Bal --
---------
-- Bal builds a single node:
-- +---+
-- | B |---->
-- +---+
-- The node B is the PC_Bal node which matches a parentheses balanced
-- string, starting at the current cursor position. It then updates
-- the cursor past this matched string, and stacks a pointer to itself
-- with this updated cursor value on the history stack, to extend the
-- matched string on a subsequent failure.
-- Since this is a single node it is numbered 1 (the reason we include
-- it in the compound patterns section is that it backtracks).
------------
-- BreakX --
------------
-- BreakX builds the structure
-- +---+ +---+
-- | B |---->| A |---->
-- +---+ +---+
-- ^ .
-- | .
-- | +---+
-- +<------| X |
-- +---+
-- Here the B node is the BreakX_xx node that performs a normal Break
-- function. The A node is an alternative (PC_Alt) node that matches
-- null, but stacks a pointer to node X (the PC_BreakX_X node) which
-- extends the match one character (to eat up the previously detected
-- break character), and then rematches the break.
-- The B node is numbered 3, the alternative node is 1, and the X
-- node is 2.
-----------
-- Fence --
-----------
-- Fence builds a single node:
-- +---+
-- | F |---->
-- +---+
-- The element F, PC_Fence, matches null, and stacks a pointer to a
-- PC_Cancel element which will abort the match on a subsequent failure.
-- Since this is a single element it is numbered 1 (the reason we
-- include it in the compound patterns section is that it backtracks).
--------------------
-- Fence Function --
--------------------
-- A call to the Fence function builds the structure:
-- +---+ +---+ +---+
-- | E |---->| P |---->| X |---->
-- +---+ +---+ +---+
-- Here E is the PC_R_Enter node which matches null and creates two
-- stack entries. The first is a special entry which is not used at
-- all in the fence case (it is present merely for uniformity with
-- other cases of region enter operations).
-- The second entry corresponds to a standard new region action. A
-- PC_R_Remove node is stacked, whose cursor field is used to store
-- the outer stack base, and the stack base is reset to point to
-- this PC_R_Remove node. Then the pattern P is matched, and it can
-- make history stack entries in the normal manner, so now the stack
-- looks like:
-- (stack entries made before fence pattern)
-- (Special entry, not used at all)
-- (PC_R_Remove entry, "cursor" value is (negative) <-- Stack Base
-- saved base value for the enclosing region)
-- (stack entries made by matching P)
-- If the match of P fails, then the PC_R_Remove entry is popped
-- and it removes both itself and the special entry underneath it,
-- restores the outer stack base, and signals failure.
-- If the match of P succeeds, then node X, the PC_Fence_X node, gets
-- control. One might be tempted to think that at this point, the
-- history stack entries made by matching P can just be removed since
-- they certainly are not going to be used for rematching (that is
-- whole point of Fence after all). However, this is wrong, because
-- it would result in the loss of possible assign-on-match entries
-- for deferred pattern assignments.
-- Instead what we do is to make a special entry whose node references
-- PC_Fence_Y, and whose cursor saves the inner stack base value, i.e.
-- the pointer to the PC_R_Remove entry. Then the outer stack base
-- pointer is restored, so the stack looks like:
-- (stack entries made before assign pattern)
-- (Special entry, not used at all)
-- (PC_R_Remove entry, "cursor" value is (negative)
-- saved base value for the enclosing region)
-- (stack entries made by matching P)
-- (PC_Fence_Y entry, "cursor" value is (negative) stack
-- pointer value referencing the PC_R_Remove entry).
-- If a subsequent failure occurs, then the PC_Fence_Y entry removes
-- the entire inner region, including all entries made by matching P,
-- and alternatives prior to the Fence pattern are sought.
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the X node is numbered N + 1,
-- and the E node is N + 2.
-------------
-- Succeed --
-------------
-- Succeed builds a single node:
-- +---+
-- | S |---->
-- +---+
-- The node S is the PC_Succeed node which matches null, and stacks
-- a pointer to itself on the history stack, so that a subsequent
-- failure repeats the same match.
-- Since this is a single node it is numbered 1 (the reason we include
-- it in the compound patterns section is that it backtracks).
---------------------
-- Write Immediate --
---------------------
-- The structure built for a write immediate operation (P * F, where
-- F is a file access value) is:
-- +---+ +---+ +---+
-- | E |---->| P |---->| W |---->
-- +---+ +---+ +---+
-- Here E is the PC_R_Enter node and W is the PC_Write_Imm node. The
-- handling is identical to that described above for Assign Immediate,
-- except that at the point where a successful match occurs, the matched
-- substring is written to the referenced file.
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the W node is numbered N + 1,
-- and the E node is N + 2.
--------------------
-- Write On Match --
--------------------
-- The structure built for a write on match operation (P ** F, where
-- F is a file access value) is:
-- +---+ +---+ +---+
-- | E |---->| P |---->| W |---->
-- +---+ +---+ +---+
-- Here E is the PC_R_Enter node and W is the PC_Write_OnM node. The
-- handling is identical to that described above for Assign On Match,
-- except that at the point where a successful match has completed,
-- the matched substring is written to the referenced file.
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the W node is numbered N + 1,
-- and the E node is N + 2.
-----------------------
-- Constant Patterns --
-----------------------
-- The following pattern elements are referenced only from the pattern
-- history stack. In each case the processing for the pattern element
-- results in pattern match abort, or further failure, so there is no
-- need for a successor and no need for a node number
CP_Assign : aliased PE := (PC_Assign, 0, N);
CP_Cancel : aliased PE := (PC_Cancel, 0, N);
CP_Fence_Y : aliased PE := (PC_Fence_Y, 0, N);
CP_R_Remove : aliased PE := (PC_R_Remove, 0, N);
CP_R_Restore : aliased PE := (PC_R_Restore, 0, N);
-----------------------
-- Local Subprograms --
-----------------------
function Alternate (L, R : PE_Ptr) return PE_Ptr;
function "or" (L, R : PE_Ptr) return PE_Ptr renames Alternate;
-- Build pattern structure corresponding to the alternation of L, R.
-- (i.e. try to match L, and if that fails, try to match R).
function Arbno_Simple (P : PE_Ptr) return PE_Ptr;
-- Build simple Arbno pattern, P is a pattern that is guaranteed to
-- match at least one character if it succeeds and to require no
-- stack entries under all circumstances. The result returned is
-- a simple Arbno structure as previously described.
function Bracket (E, P, A : PE_Ptr) return PE_Ptr;
-- Given two single node pattern elements E and A, and a (possible
-- complex) pattern P, construct the concatenation E-->P-->A and
-- return a pointer to E. The concatenation does not affect the
-- node numbering in P. A has a number one higher than the maximum
-- number in P, and E has a number two higher than the maximum
-- number in P (see for example the Assign_Immediate structure to
-- understand a typical use of this function).
function BreakX_Make (B : PE_Ptr) return Pattern;
-- Given a pattern element for a Break pattern, returns the
-- corresponding BreakX compound pattern structure.
function Concat (L, R : PE_Ptr; Incr : Natural) return PE_Ptr;
-- Creates a pattern element that represents a concatenation of the
-- two given pattern elements (i.e. the pattern L followed by R).
-- The result returned is always the same as L, but the pattern
-- referenced by L is modified to have R as a successor. This
-- procedure does not copy L or R, so if a copy is required, it
-- is the responsibility of the caller. The Incr parameter is an
-- amount to be added to the Nat field of any P_Arbno_Y node that is
-- in the left operand, it represents the additional stack space
-- required by the right operand.
function C_To_PE (C : PChar) return PE_Ptr;
-- Given a character, constructs a pattern element that matches
-- the single character.
function Copy (P : PE_Ptr) return PE_Ptr;
-- Creates a copy of the pattern element referenced by the given
-- pattern element reference. This is a deep copy, which means that
-- it follows the Next and Alt pointers.
function Image (P : PE_Ptr) return String;
-- Returns the image of the address of the referenced pattern element.
-- This is equivalent to Image (To_Address (P));
function Is_In (C : Character; Str : String) return Boolean;
pragma Inline (Is_In);
-- Determines if the character C is in string Str
procedure Logic_Error;
-- Called to raise Program_Error with an appropriate message if an
-- internal logic error is detected.
function Str_BF (A : Boolean_Func) return String;
function Str_FP (A : File_Ptr) return String;
function Str_NF (A : Natural_Func) return String;
function Str_NP (A : Natural_Ptr) return String;
function Str_PP (A : Pattern_Ptr) return String;
function Str_VF (A : VString_Func) return String;
function Str_VP (A : VString_Ptr) return String;
-- These are debugging routines, which return a representation of the
-- given access value (they are called only by Image and Dump)
procedure Set_Successor (Pat : PE_Ptr; Succ : PE_Ptr);
-- Adjusts all EOP pointers in Pat to point to Succ. No other changes
-- are made. In particular, Succ is unchanged, and no index numbers
-- are modified. Note that Pat may not be equal to EOP on entry.
function S_To_PE (Str : PString) return PE_Ptr;
-- Given a string, constructs a pattern element that matches the string
procedure Uninitialized_Pattern;
pragma No_Return (Uninitialized_Pattern);
-- Called to raise Program_Error with an appropriate error message if
-- an uninitialized pattern is used in any pattern construction or
-- pattern matching operation.
procedure XMatch
(Subject : String;
Pat_P : PE_Ptr;
Pat_S : Natural;
Start : out Natural;
Stop : out Natural);
-- This is the common pattern match routine. It is passed a string and
-- a pattern, and it indicates success or failure, and on success the
-- section of the string matched. It does not perform any assignments
-- to the subject string, so pattern replacement is for the caller.
--
-- Subject The subject string. The lower bound is always one. In the
-- Match procedures, it is fine to use strings whose lower bound
-- is not one, but we perform a one time conversion before the
-- call to XMatch, so that XMatch does not have to be bothered
-- with strange lower bounds.
--
-- Pat_P Points to initial pattern element of pattern to be matched
--
-- Pat_S Maximum required stack entries for pattern to be matched
--
-- Start If match is successful, starting index of matched section.
-- This value is always non-zero. A value of zero is used to
-- indicate a failed match.
--
-- Stop If match is successful, ending index of matched section.
-- This can be zero if we match the null string at the start,
-- in which case Start is set to zero, and Stop to one. If the
-- Match fails, then the contents of Stop is undefined.
procedure XMatchD
(Subject : String;
Pat_P : PE_Ptr;
Pat_S : Natural;
Start : out Natural;
Stop : out Natural);
-- Identical in all respects to XMatch, except that trace information is
-- output on Standard_Output during execution of the match. This is the
-- version that is called if the original Match call has Debug => True.
---------
-- "&" --
---------
function "&" (L : PString; R : Pattern) return Pattern is
begin
return (AFC with R.Stk, Concat (S_To_PE (L), Copy (R.P), R.Stk));
end "&";
function "&" (L : Pattern; R : PString) return Pattern is
begin
return (AFC with L.Stk, Concat (Copy (L.P), S_To_PE (R), 0));
end "&";
function "&" (L : PChar; R : Pattern) return Pattern is
begin
return (AFC with R.Stk, Concat (C_To_PE (L), Copy (R.P), R.Stk));
end "&";
function "&" (L : Pattern; R : PChar) return Pattern is
begin
return (AFC with L.Stk, Concat (Copy (L.P), C_To_PE (R), 0));
end "&";
function "&" (L : Pattern; R : Pattern) return Pattern is
begin
return (AFC with L.Stk + R.Stk, Concat (Copy (L.P), Copy (R.P), R.Stk));
end "&";
---------
-- "*" --
---------
-- Assign immediate
-- +---+ +---+ +---+
-- | E |---->| P |---->| A |---->
-- +---+ +---+ +---+
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the A node is numbered N + 1,
-- and the E node is N + 2.
function "*" (P : Pattern; Var : VString_Var) return Pattern is
Pat : constant PE_Ptr := Copy (P.P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
A : constant PE_Ptr :=
new PE'(PC_Assign_Imm, 0, EOP, Var'Unrestricted_Access);
begin
return (AFC with P.Stk + 3, Bracket (E, Pat, A));
end "*";
function "*" (P : PString; Var : VString_Var) return Pattern is
Pat : constant PE_Ptr := S_To_PE (P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
A : constant PE_Ptr :=
new PE'(PC_Assign_Imm, 0, EOP, Var'Unrestricted_Access);
begin
return (AFC with 3, Bracket (E, Pat, A));
end "*";
function "*" (P : PChar; Var : VString_Var) return Pattern is
Pat : constant PE_Ptr := C_To_PE (P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
A : constant PE_Ptr :=
new PE'(PC_Assign_Imm, 0, EOP, Var'Unrestricted_Access);
begin
return (AFC with 3, Bracket (E, Pat, A));
end "*";
-- Write immediate
-- +---+ +---+ +---+
-- | E |---->| P |---->| W |---->
-- +---+ +---+ +---+
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the W node is numbered N + 1,
-- and the E node is N + 2.
function "*" (P : Pattern; Fil : File_Access) return Pattern is
Pat : constant PE_Ptr := Copy (P.P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
W : constant PE_Ptr := new PE'(PC_Write_Imm, 0, EOP, Fil);
begin
return (AFC with 3, Bracket (E, Pat, W));
end "*";
function "*" (P : PString; Fil : File_Access) return Pattern is
Pat : constant PE_Ptr := S_To_PE (P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
W : constant PE_Ptr := new PE'(PC_Write_Imm, 0, EOP, Fil);
begin
return (AFC with 3, Bracket (E, Pat, W));
end "*";
function "*" (P : PChar; Fil : File_Access) return Pattern is
Pat : constant PE_Ptr := C_To_PE (P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
W : constant PE_Ptr := new PE'(PC_Write_Imm, 0, EOP, Fil);
begin
return (AFC with 3, Bracket (E, Pat, W));
end "*";
----------
-- "**" --
----------
-- Assign on match
-- +---+ +---+ +---+
-- | E |---->| P |---->| A |---->
-- +---+ +---+ +---+
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the A node is numbered N + 1,
-- and the E node is N + 2.
function "**" (P : Pattern; Var : VString_Var) return Pattern is
Pat : constant PE_Ptr := Copy (P.P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
A : constant PE_Ptr :=
new PE'(PC_Assign_OnM, 0, EOP, Var'Unrestricted_Access);
begin
return (AFC with P.Stk + 3, Bracket (E, Pat, A));
end "**";
function "**" (P : PString; Var : VString_Var) return Pattern is
Pat : constant PE_Ptr := S_To_PE (P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
A : constant PE_Ptr :=
new PE'(PC_Assign_OnM, 0, EOP, Var'Unrestricted_Access);
begin
return (AFC with 3, Bracket (E, Pat, A));
end "**";
function "**" (P : PChar; Var : VString_Var) return Pattern is
Pat : constant PE_Ptr := C_To_PE (P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
A : constant PE_Ptr :=
new PE'(PC_Assign_OnM, 0, EOP, Var'Unrestricted_Access);
begin
return (AFC with 3, Bracket (E, Pat, A));
end "**";
-- Write on match
-- +---+ +---+ +---+
-- | E |---->| P |---->| W |---->
-- +---+ +---+ +---+
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the W node is numbered N + 1,
-- and the E node is N + 2.
function "**" (P : Pattern; Fil : File_Access) return Pattern is
Pat : constant PE_Ptr := Copy (P.P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
W : constant PE_Ptr := new PE'(PC_Write_OnM, 0, EOP, Fil);
begin
return (AFC with P.Stk + 3, Bracket (E, Pat, W));
end "**";
function "**" (P : PString; Fil : File_Access) return Pattern is
Pat : constant PE_Ptr := S_To_PE (P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
W : constant PE_Ptr := new PE'(PC_Write_OnM, 0, EOP, Fil);
begin
return (AFC with 3, Bracket (E, Pat, W));
end "**";
function "**" (P : PChar; Fil : File_Access) return Pattern is
Pat : constant PE_Ptr := C_To_PE (P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
W : constant PE_Ptr := new PE'(PC_Write_OnM, 0, EOP, Fil);
begin
return (AFC with 3, Bracket (E, Pat, W));
end "**";
---------
-- "+" --
---------
function "+" (Str : VString_Var) return Pattern is
begin
return
(AFC with 0,
new PE'(PC_String_VP, 1, EOP, Str'Unrestricted_Access));
end "+";
function "+" (Str : VString_Func) return Pattern is
begin
return (AFC with 0, new PE'(PC_String_VF, 1, EOP, Str));
end "+";
function "+" (P : Pattern_Var) return Pattern is
begin
return
(AFC with 3,
new PE'(PC_Rpat, 1, EOP, P'Unrestricted_Access));
end "+";
function "+" (P : Boolean_Func) return Pattern is
begin
return (AFC with 3, new PE'(PC_Pred_Func, 1, EOP, P));
end "+";
----------
-- "or" --
----------
function "or" (L : PString; R : Pattern) return Pattern is
begin
return (AFC with R.Stk + 1, S_To_PE (L) or Copy (R.P));
end "or";
function "or" (L : Pattern; R : PString) return Pattern is
begin
return (AFC with L.Stk + 1, Copy (L.P) or S_To_PE (R));
end "or";
function "or" (L : PString; R : PString) return Pattern is
begin
return (AFC with 1, S_To_PE (L) or S_To_PE (R));
end "or";
function "or" (L : Pattern; R : Pattern) return Pattern is
begin
return (AFC with
Natural'Max (L.Stk, R.Stk) + 1, Copy (L.P) or Copy (R.P));
end "or";
function "or" (L : PChar; R : Pattern) return Pattern is
begin
return (AFC with 1, C_To_PE (L) or Copy (R.P));
end "or";
function "or" (L : Pattern; R : PChar) return Pattern is
begin
return (AFC with 1, Copy (L.P) or C_To_PE (R));
end "or";
function "or" (L : PChar; R : PChar) return Pattern is
begin
return (AFC with 1, C_To_PE (L) or C_To_PE (R));
end "or";
function "or" (L : PString; R : PChar) return Pattern is
begin
return (AFC with 1, S_To_PE (L) or C_To_PE (R));
end "or";
function "or" (L : PChar; R : PString) return Pattern is
begin
return (AFC with 1, C_To_PE (L) or S_To_PE (R));
end "or";
------------
-- Adjust --
------------
-- No two patterns share the same pattern elements, so the adjust
-- procedure for a Pattern assignment must do a deep copy of the
-- pattern element structure.
procedure Adjust (Object : in out Pattern) is
begin
Object.P := Copy (Object.P);
end Adjust;
---------------
-- Alternate --
---------------
function Alternate (L, R : PE_Ptr) return PE_Ptr is
begin
-- If the left pattern is null, then we just add the alternation
-- node with an index one greater than the right hand pattern.
if L = EOP then
return new PE'(PC_Alt, R.Index + 1, EOP, R);
-- If the left pattern is non-null, then build a reference vector
-- for its elements, and adjust their index values to accommodate
-- the right hand elements. Then add the alternation node.
else
declare
Refs : Ref_Array (1 .. L.Index);
begin
Build_Ref_Array (L, Refs);
for J in Refs'Range loop
Refs (J).Index := Refs (J).Index + R.Index;
end loop;
end;
return new PE'(PC_Alt, L.Index + 1, L, R);
end if;
end Alternate;
---------
-- Any --
---------
function Any (Str : String) return Pattern is
begin
return (AFC with 0, new PE'(PC_Any_CS, 1, EOP, To_Set (Str)));
end Any;
function Any (Str : VString) return Pattern is
begin
return Any (S (Str));
end Any;
function Any (Str : Character) return Pattern is
begin
return (AFC with 0, new PE'(PC_Any_CH, 1, EOP, Str));
end Any;
function Any (Str : Character_Set) return Pattern is
begin
return (AFC with 0, new PE'(PC_Any_CS, 1, EOP, Str));
end Any;
function Any (Str : not null access VString) return Pattern is
begin
return (AFC with 0, new PE'(PC_Any_VP, 1, EOP, VString_Ptr (Str)));
end Any;
function Any (Str : VString_Func) return Pattern is
begin
return (AFC with 0, new PE'(PC_Any_VF, 1, EOP, Str));
end Any;
---------
-- Arb --
---------
-- +---+
-- | X |---->
-- +---+
-- .
-- .
-- +---+
-- | Y |---->
-- +---+
-- The PC_Arb_X element is numbered 2, and the PC_Arb_Y element is 1
function Arb return Pattern is
Y : constant PE_Ptr := new PE'(PC_Arb_Y, 1, EOP);
X : constant PE_Ptr := new PE'(PC_Arb_X, 2, EOP, Y);
begin
return (AFC with 1, X);
end Arb;
-----------
-- Arbno --
-----------
function Arbno (P : PString) return Pattern is
begin
if P'Length = 0 then
return (AFC with 0, EOP);
else
return (AFC with 0, Arbno_Simple (S_To_PE (P)));
end if;
end Arbno;
function Arbno (P : PChar) return Pattern is
begin
return (AFC with 0, Arbno_Simple (C_To_PE (P)));
end Arbno;
function Arbno (P : Pattern) return Pattern is
Pat : constant PE_Ptr := Copy (P.P);
begin
if P.Stk = 0
and then OK_For_Simple_Arbno (Pat.Pcode)
then
return (AFC with 0, Arbno_Simple (Pat));
end if;
-- This is the complex case, either the pattern makes stack entries
-- or it is possible for the pattern to match the null string (more
-- accurately, we don't know that this is not the case).
-- +--------------------------+
-- | ^
-- V |
-- +---+ |
-- | X |----> |
-- +---+ |
-- . |
-- . |
-- +---+ +---+ +---+ |
-- | E |---->| P |---->| Y |--->+
-- +---+ +---+ +---+
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the Y node is numbered N + 1,
-- the E node is N + 2, and the X node is N + 3.
declare
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
X : constant PE_Ptr := new PE'(PC_Arbno_X, 0, EOP, E);
Y : constant PE_Ptr := new PE'(PC_Arbno_Y, 0, X, P.Stk + 3);
EPY : constant PE_Ptr := Bracket (E, Pat, Y);
begin
X.Alt := EPY;
X.Index := EPY.Index + 1;
return (AFC with P.Stk + 3, X);
end;
end Arbno;
------------------
-- Arbno_Simple --
------------------
-- +-------------+
-- | ^
-- V |
-- +---+ |
-- | S |----> |
-- +---+ |
-- . |
-- . |
-- +---+ |
-- | P |---------->+
-- +---+
-- The node numbering of the constituent pattern P is not affected.
-- The S node has a node number of P.Index + 1.
-- Note that we know that P cannot be EOP, because a null pattern
-- does not meet the requirements for simple Arbno.
function Arbno_Simple (P : PE_Ptr) return PE_Ptr is
S : constant PE_Ptr := new PE'(PC_Arbno_S, P.Index + 1, EOP, P);
begin
Set_Successor (P, S);
return S;
end Arbno_Simple;
---------
-- Bal --
---------
function Bal return Pattern is
begin
return (AFC with 1, new PE'(PC_Bal, 1, EOP));
end Bal;
-------------
-- Bracket --
-------------
function Bracket (E, P, A : PE_Ptr) return PE_Ptr is
begin
if P = EOP then
E.Pthen := A;
E.Index := 2;
A.Index := 1;
else
E.Pthen := P;
Set_Successor (P, A);
E.Index := P.Index + 2;
A.Index := P.Index + 1;
end if;
return E;
end Bracket;
-----------
-- Break --
-----------
function Break (Str : String) return Pattern is
begin
return (AFC with 0, new PE'(PC_Break_CS, 1, EOP, To_Set (Str)));
end Break;
function Break (Str : VString) return Pattern is
begin
return Break (S (Str));
end Break;
function Break (Str : Character) return Pattern is
begin
return (AFC with 0, new PE'(PC_Break_CH, 1, EOP, Str));
end Break;
function Break (Str : Character_Set) return Pattern is
begin
return (AFC with 0, new PE'(PC_Break_CS, 1, EOP, Str));
end Break;
function Break (Str : not null access VString) return Pattern is
begin
return (AFC with 0,
new PE'(PC_Break_VP, 1, EOP, Str.all'Unchecked_Access));
end Break;
function Break (Str : VString_Func) return Pattern is
begin
return (AFC with 0, new PE'(PC_Break_VF, 1, EOP, Str));
end Break;
------------
-- BreakX --
------------
function BreakX (Str : String) return Pattern is
begin
return BreakX_Make (new PE'(PC_BreakX_CS, 3, N, To_Set (Str)));
end BreakX;
function BreakX (Str : VString) return Pattern is
begin
return BreakX (S (Str));
end BreakX;
function BreakX (Str : Character) return Pattern is
begin
return BreakX_Make (new PE'(PC_BreakX_CH, 3, N, Str));
end BreakX;
function BreakX (Str : Character_Set) return Pattern is
begin
return BreakX_Make (new PE'(PC_BreakX_CS, 3, N, Str));
end BreakX;
function BreakX (Str : not null access VString) return Pattern is
begin
return BreakX_Make (new PE'(PC_BreakX_VP, 3, N, VString_Ptr (Str)));
end BreakX;
function BreakX (Str : VString_Func) return Pattern is
begin
return BreakX_Make (new PE'(PC_BreakX_VF, 3, N, Str));
end BreakX;
-----------------
-- BreakX_Make --
-----------------
-- +---+ +---+
-- | B |---->| A |---->
-- +---+ +---+
-- ^ .
-- | .
-- | +---+
-- +<------| X |
-- +---+
-- The B node is numbered 3, the alternative node is 1, and the X
-- node is 2.
function BreakX_Make (B : PE_Ptr) return Pattern is
X : constant PE_Ptr := new PE'(PC_BreakX_X, 2, B);
A : constant PE_Ptr := new PE'(PC_Alt, 1, EOP, X);
begin
B.Pthen := A;
return (AFC with 2, B);
end BreakX_Make;
---------------------
-- Build_Ref_Array --
---------------------
procedure Build_Ref_Array (E : PE_Ptr; RA : out Ref_Array) is
procedure Record_PE (E : PE_Ptr);
-- Record given pattern element if not already recorded in RA,
-- and also record any referenced pattern elements recursively.
---------------
-- Record_PE --
---------------
procedure Record_PE (E : PE_Ptr) is
begin
PutD (" Record_PE called with PE_Ptr = " & Image (E));
if E = EOP or else RA (E.Index) /= null then
Put_LineD (", nothing to do");
return;
else
Put_LineD (", recording" & IndexT'Image (E.Index));
RA (E.Index) := E;
Record_PE (E.Pthen);
if E.Pcode in PC_Has_Alt then
Record_PE (E.Alt);
end if;
end if;
end Record_PE;
-- Start of processing for Build_Ref_Array
begin
New_LineD;
Put_LineD ("Entering Build_Ref_Array");
Record_PE (E);
New_LineD;
end Build_Ref_Array;
-------------
-- C_To_PE --
-------------
function C_To_PE (C : PChar) return PE_Ptr is
begin
return new PE'(PC_Char, 1, EOP, C);
end C_To_PE;
------------
-- Cancel --
------------
function Cancel return Pattern is
begin
return (AFC with 0, new PE'(PC_Cancel, 1, EOP));
end Cancel;
------------
-- Concat --
------------
-- Concat needs to traverse the left operand performing the following
-- set of fixups:
-- a) Any successor pointers (Pthen fields) that are set to EOP are
-- reset to point to the second operand.
-- b) Any PC_Arbno_Y node has its stack count field incremented
-- by the parameter Incr provided for this purpose.
-- d) Num fields of all pattern elements in the left operand are
-- adjusted to include the elements of the right operand.
-- Note: we do not use Set_Successor in the processing for Concat, since
-- there is no point in doing two traversals, we may as well do everything
-- at the same time.
function Concat (L, R : PE_Ptr; Incr : Natural) return PE_Ptr is
begin
if L = EOP then
return R;
elsif R = EOP then
return L;
else
declare
Refs : Ref_Array (1 .. L.Index);
-- We build a reference array for L whose N'th element points to
-- the pattern element of L whose original Index value is N.
P : PE_Ptr;
begin
Build_Ref_Array (L, Refs);
for J in Refs'Range loop
P := Refs (J);
P.Index := P.Index + R.Index;
if P.Pcode = PC_Arbno_Y then
P.Nat := P.Nat + Incr;
end if;
if P.Pthen = EOP then
P.Pthen := R;
end if;
if P.Pcode in PC_Has_Alt and then P.Alt = EOP then
P.Alt := R;
end if;
end loop;
end;
return L;
end if;
end Concat;
----------
-- Copy --
----------
function Copy (P : PE_Ptr) return PE_Ptr is
begin
if P = null then
Uninitialized_Pattern;
else
declare
Refs : Ref_Array (1 .. P.Index);
-- References to elements in P, indexed by Index field
Copy : Ref_Array (1 .. P.Index);
-- Holds copies of elements of P, indexed by Index field
E : PE_Ptr;
begin
Build_Ref_Array (P, Refs);
-- Now copy all nodes
for J in Refs'Range loop
Copy (J) := new PE'(Refs (J).all);
end loop;
-- Adjust all internal references
for J in Copy'Range loop
E := Copy (J);
-- Adjust successor pointer to point to copy
if E.Pthen /= EOP then
E.Pthen := Copy (E.Pthen.Index);
end if;
-- Adjust Alt pointer if there is one to point to copy
if E.Pcode in PC_Has_Alt and then E.Alt /= EOP then
E.Alt := Copy (E.Alt.Index);
end if;
-- Copy referenced string
if E.Pcode = PC_String then
E.Str := new String'(E.Str.all);
end if;
end loop;
return Copy (P.Index);
end;
end if;
end Copy;
----------
-- Dump --
----------
procedure Dump (P : Pattern) is
procedure Write_Node_Id (E : PE_Ptr; Cols : Natural);
-- Writes out a string identifying the given pattern element. Cols is
-- the column indentation level.
-------------------
-- Write_Node_Id --
-------------------
procedure Write_Node_Id (E : PE_Ptr; Cols : Natural) is
begin
if E = EOP then
Put ("EOP");
for J in 4 .. Cols loop
Put (' ');
end loop;
else
declare
Str : String (1 .. Cols);
N : Natural := Natural (E.Index);
begin
Put ("#");
for J in reverse Str'Range loop
Str (J) := Character'Val (48 + N mod 10);
N := N / 10;
end loop;
Put (Str);
end;
end if;
end Write_Node_Id;
-- Local variables
Cols : Natural := 2;
-- Number of columns used for pattern numbers, minimum is 2
E : PE_Ptr;
subtype Count is Ada.Text_IO.Count;
Scol : Count;
-- Used to keep track of column in dump output
-- Start of processing for Dump
begin
New_Line;
Put
("Pattern Dump Output (pattern at "
& Image (P'Address)
& ", S = "
& Natural'Image (P.Stk) & ')');
New_Line;
Scol := Col;
while Col < Scol loop
Put ('-');
end loop;
New_Line;
-- If uninitialized pattern, dump line and we are done
if P.P = null then
Put_Line ("Uninitialized pattern value");
return;
end if;
-- If null pattern, just dump it and we are all done
if P.P = EOP then
Put_Line ("EOP (null pattern)");
return;
end if;
declare
Refs : Ref_Array (1 .. P.P.Index);
-- We build a reference array whose N'th element points to the
-- pattern element whose Index value is N.
begin
Build_Ref_Array (P.P, Refs);
-- Set number of columns required for node numbers
while 10 ** Cols - 1 < Integer (P.P.Index) loop
Cols := Cols + 1;
end loop;
-- Now dump the nodes in reverse sequence. We output them in reverse
-- sequence since this corresponds to the natural order used to
-- construct the patterns.
for J in reverse Refs'Range loop
E := Refs (J);
Write_Node_Id (E, Cols);
Set_Col (Count (Cols) + 4);
Put (Image (E));
Put (" ");
Put (Pattern_Code'Image (E.Pcode));
Put (" ");
Set_Col (21 + Count (Cols) + Address_Image_Length);
Write_Node_Id (E.Pthen, Cols);
Set_Col (24 + 2 * Count (Cols) + Address_Image_Length);
case E.Pcode is
when PC_Alt
| PC_Arb_X
| PC_Arbno_S
| PC_Arbno_X
=>
Write_Node_Id (E.Alt, Cols);
when PC_Rpat =>
Put (Str_PP (E.PP));
when PC_Pred_Func =>
Put (Str_BF (E.BF));
when PC_Assign_Imm
| PC_Assign_OnM
| PC_Any_VP
| PC_Break_VP
| PC_BreakX_VP
| PC_NotAny_VP
| PC_NSpan_VP
| PC_Span_VP
| PC_String_VP
=>
Put (Str_VP (E.VP));
when PC_Write_Imm
| PC_Write_OnM
=>
Put (Str_FP (E.FP));
when PC_String =>
Put (Image (E.Str.all));
when PC_String_2 =>
Put (Image (E.Str2));
when PC_String_3 =>
Put (Image (E.Str3));
when PC_String_4 =>
Put (Image (E.Str4));
when PC_String_5 =>
Put (Image (E.Str5));
when PC_String_6 =>
Put (Image (E.Str6));
when PC_Setcur =>
Put (Str_NP (E.Var));
when PC_Any_CH
| PC_Break_CH
| PC_BreakX_CH
| PC_Char
| PC_NotAny_CH
| PC_NSpan_CH
| PC_Span_CH
=>
Put (''' & E.Char & ''');
when PC_Any_CS
| PC_Break_CS
| PC_BreakX_CS
| PC_NotAny_CS
| PC_NSpan_CS
| PC_Span_CS
=>
Put ('"' & To_Sequence (E.CS) & '"');
when PC_Arbno_Y
| PC_Len_Nat
| PC_Pos_Nat
| PC_RPos_Nat
| PC_RTab_Nat
| PC_Tab_Nat
=>
Put (S (E.Nat));
when PC_Pos_NF
| PC_Len_NF
| PC_RPos_NF
| PC_RTab_NF
| PC_Tab_NF
=>
Put (Str_NF (E.NF));
when PC_Pos_NP
| PC_Len_NP
| PC_RPos_NP
| PC_RTab_NP
| PC_Tab_NP
=>
Put (Str_NP (E.NP));
when PC_Any_VF
| PC_Break_VF
| PC_BreakX_VF
| PC_NotAny_VF
| PC_NSpan_VF
| PC_Span_VF
| PC_String_VF
=>
Put (Str_VF (E.VF));
when others =>
null;
end case;
New_Line;
end loop;
New_Line;
end;
end Dump;
----------
-- Fail --
----------
function Fail return Pattern is
begin
return (AFC with 0, new PE'(PC_Fail, 1, EOP));
end Fail;
-----------
-- Fence --
-----------
-- Simple case
function Fence return Pattern is
begin
return (AFC with 1, new PE'(PC_Fence, 1, EOP));
end Fence;
-- Function case
-- +---+ +---+ +---+
-- | E |---->| P |---->| X |---->
-- +---+ +---+ +---+
-- The node numbering of the constituent pattern P is not affected.
-- Where N is the number of nodes in P, the X node is numbered N + 1,
-- and the E node is N + 2.
function Fence (P : Pattern) return Pattern is
Pat : constant PE_Ptr := Copy (P.P);
E : constant PE_Ptr := new PE'(PC_R_Enter, 0, EOP);
X : constant PE_Ptr := new PE'(PC_Fence_X, 0, EOP);
begin
return (AFC with P.Stk + 1, Bracket (E, Pat, X));
end Fence;
--------------
-- Finalize --
--------------
procedure Finalize (Object : in out Pattern) is
procedure Free is new Ada.Unchecked_Deallocation (PE, PE_Ptr);
procedure Free is new Ada.Unchecked_Deallocation (String, String_Ptr);
begin
-- Nothing to do if already freed
if Object.P = null then
return;
-- Otherwise we must free all elements
else
declare
Refs : Ref_Array (1 .. Object.P.Index);
-- References to elements in pattern to be finalized
begin
Build_Ref_Array (Object.P, Refs);
for J in Refs'Range loop
if Refs (J).Pcode = PC_String then
Free (Refs (J).Str);
end if;
Free (Refs (J));
end loop;
Object.P := null;
end;
end if;
end Finalize;
-----------
-- Image --
-----------
function Image (P : PE_Ptr) return String is
begin
return Image (To_Address (P));
end Image;
function Image (P : Pattern) return String is
begin
return S (Image (P));
end Image;
function Image (P : Pattern) return VString is
Kill_Ampersand : Boolean := False;
-- Set True to delete next & to be output to Result
Result : VString := Nul;
-- The result is accumulated here, using Append
Refs : Ref_Array (1 .. P.P.Index);
-- We build a reference array whose N'th element points to the
-- pattern element whose Index value is N.
procedure Delete_Ampersand;
-- Deletes the ampersand at the end of Result
procedure Image_Seq (E : PE_Ptr; Succ : PE_Ptr; Paren : Boolean);
-- E refers to a pattern structure whose successor is given by Succ.
-- This procedure appends to Result a representation of this pattern.
-- The Paren parameter indicates whether parentheses are required if
-- the output is more than one element.
procedure Image_One (E : in out PE_Ptr);
-- E refers to a pattern structure. This procedure appends to Result
-- a representation of the single simple or compound pattern structure
-- at the start of E and updates E to point to its successor.
----------------------
-- Delete_Ampersand --
----------------------
procedure Delete_Ampersand is
L : constant Natural := Length (Result);
begin
if L > 2 then
Delete (Result, L - 1, L);
end if;
end Delete_Ampersand;
---------------
-- Image_One --
---------------
procedure Image_One (E : in out PE_Ptr) is
ER : PE_Ptr := E.Pthen;
-- Successor set as result in E unless reset
begin
case E.Pcode is
when PC_Cancel =>
Append (Result, "Cancel");
when PC_Alt => Alt : declare
Elmts_In_L : constant IndexT := E.Pthen.Index - E.Alt.Index;
-- Number of elements in left pattern of alternation
Lowest_In_L : constant IndexT := E.Index - Elmts_In_L;
-- Number of lowest index in elements of left pattern
E1 : PE_Ptr;
begin
-- The successor of the alternation node must have a lower
-- index than any node that is in the left pattern or a
-- higher index than the alternation node itself.
while ER /= EOP
and then ER.Index >= Lowest_In_L
and then ER.Index < E.Index
loop
ER := ER.Pthen;
end loop;
Append (Result, '(');
E1 := E;
loop
Image_Seq (E1.Pthen, ER, False);
Append (Result, " or ");
E1 := E1.Alt;
exit when E1.Pcode /= PC_Alt;
end loop;
Image_Seq (E1, ER, False);
Append (Result, ')');
end Alt;
when PC_Any_CS =>
Append (Result, "Any (" & Image (To_Sequence (E.CS)) & ')');
when PC_Any_VF =>
Append (Result, "Any (" & Str_VF (E.VF) & ')');
when PC_Any_VP =>
Append (Result, "Any (" & Str_VP (E.VP) & ')');
when PC_Arb_X =>
Append (Result, "Arb");
when PC_Arbno_S =>
Append (Result, "Arbno (");
Image_Seq (E.Alt, E, False);
Append (Result, ')');
when PC_Arbno_X =>
Append (Result, "Arbno (");
Image_Seq (E.Alt.Pthen, Refs (E.Index - 2), False);
Append (Result, ')');
when PC_Assign_Imm =>
Delete_Ampersand;
Append (Result, "* " & Str_VP (Refs (E.Index).VP));
when PC_Assign_OnM =>
Delete_Ampersand;
Append (Result, "** " & Str_VP (Refs (E.Index).VP));
when PC_Any_CH =>
Append (Result, "Any ('" & E.Char & "')");
when PC_Bal =>
Append (Result, "Bal");
when PC_Break_CH =>
Append (Result, "Break ('" & E.Char & "')");
when PC_Break_CS =>
Append (Result, "Break (" & Image (To_Sequence (E.CS)) & ')');
when PC_Break_VF =>
Append (Result, "Break (" & Str_VF (E.VF) & ')');
when PC_Break_VP =>
Append (Result, "Break (" & Str_VP (E.VP) & ')');
when PC_BreakX_CH =>
Append (Result, "BreakX ('" & E.Char & "')");
ER := ER.Pthen;
when PC_BreakX_CS =>
Append (Result, "BreakX (" & Image (To_Sequence (E.CS)) & ')');
ER := ER.Pthen;
when PC_BreakX_VF =>
Append (Result, "BreakX (" & Str_VF (E.VF) & ')');
ER := ER.Pthen;
when PC_BreakX_VP =>
Append (Result, "BreakX (" & Str_VP (E.VP) & ')');
ER := ER.Pthen;
when PC_Char =>
Append (Result, ''' & E.Char & ''');
when PC_Fail =>
Append (Result, "Fail");
when PC_Fence =>
Append (Result, "Fence");
when PC_Fence_X =>
Append (Result, "Fence (");
Image_Seq (E.Pthen, Refs (E.Index - 1), False);
Append (Result, ")");
ER := Refs (E.Index - 1).Pthen;
when PC_Len_Nat =>
Append (Result, "Len (" & E.Nat & ')');
when PC_Len_NF =>
Append (Result, "Len (" & Str_NF (E.NF) & ')');
when PC_Len_NP =>
Append (Result, "Len (" & Str_NP (E.NP) & ')');
when PC_NotAny_CH =>
Append (Result, "NotAny ('" & E.Char & "')");
when PC_NotAny_CS =>
Append (Result, "NotAny (" & Image (To_Sequence (E.CS)) & ')');
when PC_NotAny_VF =>
Append (Result, "NotAny (" & Str_VF (E.VF) & ')');
when PC_NotAny_VP =>
Append (Result, "NotAny (" & Str_VP (E.VP) & ')');
when PC_NSpan_CH =>
Append (Result, "NSpan ('" & E.Char & "')");
when PC_NSpan_CS =>
Append (Result, "NSpan (" & Image (To_Sequence (E.CS)) & ')');
when PC_NSpan_VF =>
Append (Result, "NSpan (" & Str_VF (E.VF) & ')');
when PC_NSpan_VP =>
Append (Result, "NSpan (" & Str_VP (E.VP) & ')');
when PC_Null =>
Append (Result, """""");
when PC_Pos_Nat =>
Append (Result, "Pos (" & E.Nat & ')');
when PC_Pos_NF =>
Append (Result, "Pos (" & Str_NF (E.NF) & ')');
when PC_Pos_NP =>
Append (Result, "Pos (" & Str_NP (E.NP) & ')');
when PC_R_Enter =>
Kill_Ampersand := True;
when PC_Rest =>
Append (Result, "Rest");
when PC_Rpat =>
Append (Result, "(+ " & Str_PP (E.PP) & ')');
when PC_Pred_Func =>
Append (Result, "(+ " & Str_BF (E.BF) & ')');
when PC_RPos_Nat =>
Append (Result, "RPos (" & E.Nat & ')');
when PC_RPos_NF =>
Append (Result, "RPos (" & Str_NF (E.NF) & ')');
when PC_RPos_NP =>
Append (Result, "RPos (" & Str_NP (E.NP) & ')');
when PC_RTab_Nat =>
Append (Result, "RTab (" & E.Nat & ')');
when PC_RTab_NF =>
Append (Result, "RTab (" & Str_NF (E.NF) & ')');
when PC_RTab_NP =>
Append (Result, "RTab (" & Str_NP (E.NP) & ')');
when PC_Setcur =>
Append (Result, "Setcur (" & Str_NP (E.Var) & ')');
when PC_Span_CH =>
Append (Result, "Span ('" & E.Char & "')");
when PC_Span_CS =>
Append (Result, "Span (" & Image (To_Sequence (E.CS)) & ')');
when PC_Span_VF =>
Append (Result, "Span (" & Str_VF (E.VF) & ')');
when PC_Span_VP =>
Append (Result, "Span (" & Str_VP (E.VP) & ')');
when PC_String =>
Append (Result, Image (E.Str.all));
when PC_String_2 =>
Append (Result, Image (E.Str2));
when PC_String_3 =>
Append (Result, Image (E.Str3));
when PC_String_4 =>
Append (Result, Image (E.Str4));
when PC_String_5 =>
Append (Result, Image (E.Str5));
when PC_String_6 =>
Append (Result, Image (E.Str6));
when PC_String_VF =>
Append (Result, "(+" & Str_VF (E.VF) & ')');
when PC_String_VP =>
Append (Result, "(+" & Str_VP (E.VP) & ')');
when PC_Succeed =>
Append (Result, "Succeed");
when PC_Tab_Nat =>
Append (Result, "Tab (" & E.Nat & ')');
when PC_Tab_NF =>
Append (Result, "Tab (" & Str_NF (E.NF) & ')');
when PC_Tab_NP =>
Append (Result, "Tab (" & Str_NP (E.NP) & ')');
when PC_Write_Imm =>
Append (Result, '(');
Image_Seq (E, Refs (E.Index - 1), True);
Append (Result, " * " & Str_FP (Refs (E.Index - 1).FP));
ER := Refs (E.Index - 1).Pthen;
when PC_Write_OnM =>
Append (Result, '(');
Image_Seq (E.Pthen, Refs (E.Index - 1), True);
Append (Result, " ** " & Str_FP (Refs (E.Index - 1).FP));
ER := Refs (E.Index - 1).Pthen;
-- Other pattern codes should not appear as leading elements
when PC_Arb_Y
| PC_Arbno_Y
| PC_Assign
| PC_BreakX_X
| PC_EOP
| PC_Fence_Y
| PC_R_Remove
| PC_R_Restore
| PC_Unanchored
=>
Append (Result, "???");
end case;
E := ER;
end Image_One;
---------------
-- Image_Seq --
---------------
procedure Image_Seq (E : PE_Ptr; Succ : PE_Ptr; Paren : Boolean) is
Indx : constant Natural := Length (Result);
E1 : PE_Ptr := E;
Mult : Boolean := False;
begin
-- The image of EOP is "" (the null string)
if E = EOP then
Append (Result, """""");
-- Else generate appropriate concatenation sequence
else
loop
Image_One (E1);
exit when E1 = Succ;
exit when E1 = EOP;
Mult := True;
if Kill_Ampersand then
Kill_Ampersand := False;
else
Append (Result, " & ");
end if;
end loop;
end if;
if Mult and Paren then
Insert (Result, Indx + 1, "(");
Append (Result, ")");
end if;
end Image_Seq;
-- Start of processing for Image
begin
Build_Ref_Array (P.P, Refs);
Image_Seq (P.P, EOP, False);
return Result;
end Image;
-----------
-- Is_In --
-----------
function Is_In (C : Character; Str : String) return Boolean is
begin
for J in Str'Range loop
if Str (J) = C then
return True;
end if;
end loop;
return False;
end Is_In;
---------
-- Len --
---------
function Len (Count : Natural) return Pattern is
begin
-- Note, the following is not just an optimization, it is needed
-- to ensure that Arbno (Len (0)) does not generate an infinite
-- matching loop (since PC_Len_Nat is OK_For_Simple_Arbno).
if Count = 0 then
return (AFC with 0, new PE'(PC_Null, 1, EOP));
else
return (AFC with 0, new PE'(PC_Len_Nat, 1, EOP, Count));
end if;
end Len;
function Len (Count : Natural_Func) return Pattern is
begin
return (AFC with 0, new PE'(PC_Len_NF, 1, EOP, Count));
end Len;
function Len (Count : not null access Natural) return Pattern is
begin
return (AFC with 0, new PE'(PC_Len_NP, 1, EOP, Natural_Ptr (Count)));
end Len;
-----------------
-- Logic_Error --
-----------------
procedure Logic_Error is
begin
raise Program_Error with
"Internal logic error in GNAT.Spitbol.Patterns";
end Logic_Error;
-----------
-- Match --
-----------
function Match
(Subject : VString;
Pat : Pattern) return Boolean
is
S : Big_String_Access;
L : Natural;
Start : Natural;
Stop : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
else
XMatch (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
end if;
return Start /= 0;
end Match;
function Match
(Subject : String;
Pat : Pattern) return Boolean
is
Start, Stop : Natural;
subtype String1 is String (1 .. Subject'Length);
begin
if Debug_Mode then
XMatchD (String1 (Subject), Pat.P, Pat.Stk, Start, Stop);
else
XMatch (String1 (Subject), Pat.P, Pat.Stk, Start, Stop);
end if;
return Start /= 0;
end Match;
function Match
(Subject : VString_Var;
Pat : Pattern;
Replace : VString) return Boolean
is
Start : Natural;
Stop : Natural;
S : Big_String_Access;
L : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
else
XMatch (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
end if;
if Start = 0 then
return False;
else
Get_String (Replace, S, L);
Replace_Slice
(Subject'Unrestricted_Access.all, Start, Stop, S (1 .. L));
return True;
end if;
end Match;
function Match
(Subject : VString_Var;
Pat : Pattern;
Replace : String) return Boolean
is
Start : Natural;
Stop : Natural;
S : Big_String_Access;
L : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
else
XMatch (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
end if;
if Start = 0 then
return False;
else
Replace_Slice
(Subject'Unrestricted_Access.all, Start, Stop, Replace);
return True;
end if;
end Match;
procedure Match
(Subject : VString;
Pat : Pattern)
is
S : Big_String_Access;
L : Natural;
Start : Natural;
Stop : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
else
XMatch (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
end if;
end Match;
procedure Match
(Subject : String;
Pat : Pattern)
is
Start, Stop : Natural;
subtype String1 is String (1 .. Subject'Length);
begin
if Debug_Mode then
XMatchD (String1 (Subject), Pat.P, Pat.Stk, Start, Stop);
else
XMatch (String1 (Subject), Pat.P, Pat.Stk, Start, Stop);
end if;
end Match;
procedure Match
(Subject : in out VString;
Pat : Pattern;
Replace : VString)
is
Start : Natural;
Stop : Natural;
S : Big_String_Access;
L : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
else
XMatch (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
end if;
if Start /= 0 then
Get_String (Replace, S, L);
Replace_Slice (Subject, Start, Stop, S (1 .. L));
end if;
end Match;
procedure Match
(Subject : in out VString;
Pat : Pattern;
Replace : String)
is
Start : Natural;
Stop : Natural;
S : Big_String_Access;
L : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
else
XMatch (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
end if;
if Start /= 0 then
Replace_Slice (Subject, Start, Stop, Replace);
end if;
end Match;
function Match
(Subject : VString;
Pat : PString) return Boolean
is
Pat_Len : constant Natural := Pat'Length;
S : Big_String_Access;
L : Natural;
begin
Get_String (Subject, S, L);
if Anchored_Mode then
if Pat_Len > L then
return False;
else
return Pat = S (1 .. Pat_Len);
end if;
else
for J in 1 .. L - Pat_Len + 1 loop
if Pat = S (J .. J + (Pat_Len - 1)) then
return True;
end if;
end loop;
return False;
end if;
end Match;
function Match
(Subject : String;
Pat : PString) return Boolean
is
Pat_Len : constant Natural := Pat'Length;
Sub_Len : constant Natural := Subject'Length;
SFirst : constant Natural := Subject'First;
begin
if Anchored_Mode then
if Pat_Len > Sub_Len then
return False;
else
return Pat = Subject (SFirst .. SFirst + Pat_Len - 1);
end if;
else
for J in SFirst .. SFirst + Sub_Len - Pat_Len loop
if Pat = Subject (J .. J + (Pat_Len - 1)) then
return True;
end if;
end loop;
return False;
end if;
end Match;
function Match
(Subject : VString_Var;
Pat : PString;
Replace : VString) return Boolean
is
Start : Natural;
Stop : Natural;
S : Big_String_Access;
L : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), S_To_PE (Pat), 0, Start, Stop);
else
XMatch (S (1 .. L), S_To_PE (Pat), 0, Start, Stop);
end if;
if Start = 0 then
return False;
else
Get_String (Replace, S, L);
Replace_Slice
(Subject'Unrestricted_Access.all, Start, Stop, S (1 .. L));
return True;
end if;
end Match;
function Match
(Subject : VString_Var;
Pat : PString;
Replace : String) return Boolean
is
Start : Natural;
Stop : Natural;
S : Big_String_Access;
L : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), S_To_PE (Pat), 0, Start, Stop);
else
XMatch (S (1 .. L), S_To_PE (Pat), 0, Start, Stop);
end if;
if Start = 0 then
return False;
else
Replace_Slice
(Subject'Unrestricted_Access.all, Start, Stop, Replace);
return True;
end if;
end Match;
procedure Match
(Subject : VString;
Pat : PString)
is
S : Big_String_Access;
L : Natural;
Start : Natural;
Stop : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), S_To_PE (Pat), 0, Start, Stop);
else
XMatch (S (1 .. L), S_To_PE (Pat), 0, Start, Stop);
end if;
end Match;
procedure Match
(Subject : String;
Pat : PString)
is
Start, Stop : Natural;
subtype String1 is String (1 .. Subject'Length);
begin
if Debug_Mode then
XMatchD (String1 (Subject), S_To_PE (Pat), 0, Start, Stop);
else
XMatch (String1 (Subject), S_To_PE (Pat), 0, Start, Stop);
end if;
end Match;
procedure Match
(Subject : in out VString;
Pat : PString;
Replace : VString)
is
Start : Natural;
Stop : Natural;
S : Big_String_Access;
L : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), S_To_PE (Pat), 0, Start, Stop);
else
XMatch (S (1 .. L), S_To_PE (Pat), 0, Start, Stop);
end if;
if Start /= 0 then
Get_String (Replace, S, L);
Replace_Slice (Subject, Start, Stop, S (1 .. L));
end if;
end Match;
procedure Match
(Subject : in out VString;
Pat : PString;
Replace : String)
is
Start : Natural;
Stop : Natural;
S : Big_String_Access;
L : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), S_To_PE (Pat), 0, Start, Stop);
else
XMatch (S (1 .. L), S_To_PE (Pat), 0, Start, Stop);
end if;
if Start /= 0 then
Replace_Slice (Subject, Start, Stop, Replace);
end if;
end Match;
function Match
(Subject : VString_Var;
Pat : Pattern;
Result : Match_Result_Var) return Boolean
is
Start : Natural;
Stop : Natural;
S : Big_String_Access;
L : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
else
XMatch (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
end if;
if Start = 0 then
Result'Unrestricted_Access.all.Var := null;
return False;
else
Result'Unrestricted_Access.all.Var := Subject'Unrestricted_Access;
Result'Unrestricted_Access.all.Start := Start;
Result'Unrestricted_Access.all.Stop := Stop;
return True;
end if;
end Match;
procedure Match
(Subject : in out VString;
Pat : Pattern;
Result : out Match_Result)
is
Start : Natural;
Stop : Natural;
S : Big_String_Access;
L : Natural;
begin
Get_String (Subject, S, L);
if Debug_Mode then
XMatchD (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
else
XMatch (S (1 .. L), Pat.P, Pat.Stk, Start, Stop);
end if;
if Start = 0 then
Result.Var := null;
else
Result.Var := Subject'Unrestricted_Access;
Result.Start := Start;
Result.Stop := Stop;
end if;
end Match;
---------------
-- New_LineD --
---------------
procedure New_LineD is
begin
if Internal_Debug then
New_Line;
end if;
end New_LineD;
------------
-- NotAny --
------------
function NotAny (Str : String) return Pattern is
begin
return (AFC with 0, new PE'(PC_NotAny_CS, 1, EOP, To_Set (Str)));
end NotAny;
function NotAny (Str : VString) return Pattern is
begin
return NotAny (S (Str));
end NotAny;
function NotAny (Str : Character) return Pattern is
begin
return (AFC with 0, new PE'(PC_NotAny_CH, 1, EOP, Str));
end NotAny;
function NotAny (Str : Character_Set) return Pattern is
begin
return (AFC with 0, new PE'(PC_NotAny_CS, 1, EOP, Str));
end NotAny;
function NotAny (Str : not null access VString) return Pattern is
begin
return (AFC with 0, new PE'(PC_NotAny_VP, 1, EOP, VString_Ptr (Str)));
end NotAny;
function NotAny (Str : VString_Func) return Pattern is
begin
return (AFC with 0, new PE'(PC_NotAny_VF, 1, EOP, Str));
end NotAny;
-----------
-- NSpan --
-----------
function NSpan (Str : String) return Pattern is
begin
return (AFC with 0, new PE'(PC_NSpan_CS, 1, EOP, To_Set (Str)));
end NSpan;
function NSpan (Str : VString) return Pattern is
begin
return NSpan (S (Str));
end NSpan;
function NSpan (Str : Character) return Pattern is
begin
return (AFC with 0, new PE'(PC_NSpan_CH, 1, EOP, Str));
end NSpan;
function NSpan (Str : Character_Set) return Pattern is
begin
return (AFC with 0, new PE'(PC_NSpan_CS, 1, EOP, Str));
end NSpan;
function NSpan (Str : not null access VString) return Pattern is
begin
return (AFC with 0, new PE'(PC_NSpan_VP, 1, EOP, VString_Ptr (Str)));
end NSpan;
function NSpan (Str : VString_Func) return Pattern is
begin
return (AFC with 0, new PE'(PC_NSpan_VF, 1, EOP, Str));
end NSpan;
---------
-- Pos --
---------
function Pos (Count : Natural) return Pattern is
begin
return (AFC with 0, new PE'(PC_Pos_Nat, 1, EOP, Count));
end Pos;
function Pos (Count : Natural_Func) return Pattern is
begin
return (AFC with 0, new PE'(PC_Pos_NF, 1, EOP, Count));
end Pos;
function Pos (Count : not null access Natural) return Pattern is
begin
return (AFC with 0, new PE'(PC_Pos_NP, 1, EOP, Natural_Ptr (Count)));
end Pos;
----------
-- PutD --
----------
procedure PutD (Str : String) is
begin
if Internal_Debug then
Put (Str);
end if;
end PutD;
---------------
-- Put_LineD --
---------------
procedure Put_LineD (Str : String) is
begin
if Internal_Debug then
Put_Line (Str);
end if;
end Put_LineD;
-------------
-- Replace --
-------------
procedure Replace
(Result : in out Match_Result;
Replace : VString)
is
S : Big_String_Access;
L : Natural;
begin
Get_String (Replace, S, L);
if Result.Var /= null then
Replace_Slice (Result.Var.all, Result.Start, Result.Stop, S (1 .. L));
Result.Var := null;
end if;
end Replace;
----------
-- Rest --
----------
function Rest return Pattern is
begin
return (AFC with 0, new PE'(PC_Rest, 1, EOP));
end Rest;
----------
-- Rpos --
----------
function Rpos (Count : Natural) return Pattern is
begin
return (AFC with 0, new PE'(PC_RPos_Nat, 1, EOP, Count));
end Rpos;
function Rpos (Count : Natural_Func) return Pattern is
begin
return (AFC with 0, new PE'(PC_RPos_NF, 1, EOP, Count));
end Rpos;
function Rpos (Count : not null access Natural) return Pattern is
begin
return (AFC with 0, new PE'(PC_RPos_NP, 1, EOP, Natural_Ptr (Count)));
end Rpos;
----------
-- Rtab --
----------
function Rtab (Count : Natural) return Pattern is
begin
return (AFC with 0, new PE'(PC_RTab_Nat, 1, EOP, Count));
end Rtab;
function Rtab (Count : Natural_Func) return Pattern is
begin
return (AFC with 0, new PE'(PC_RTab_NF, 1, EOP, Count));
end Rtab;
function Rtab (Count : not null access Natural) return Pattern is
begin
return (AFC with 0, new PE'(PC_RTab_NP, 1, EOP, Natural_Ptr (Count)));
end Rtab;
-------------
-- S_To_PE --
-------------
function S_To_PE (Str : PString) return PE_Ptr is
Len : constant Natural := Str'Length;
begin
case Len is
when 0 =>
return new PE'(PC_Null, 1, EOP);
when 1 =>
return new PE'(PC_Char, 1, EOP, Str (Str'First));
when 2 =>
return new PE'(PC_String_2, 1, EOP, Str);
when 3 =>
return new PE'(PC_String_3, 1, EOP, Str);
when 4 =>
return new PE'(PC_String_4, 1, EOP, Str);
when 5 =>
return new PE'(PC_String_5, 1, EOP, Str);
when 6 =>
return new PE'(PC_String_6, 1, EOP, Str);
when others =>
return new PE'(PC_String, 1, EOP, new String'(Str));
end case;
end S_To_PE;
-------------------
-- Set_Successor --
-------------------
-- Note: this procedure is not used by the normal concatenation circuit,
-- since other fixups are required on the left operand in this case, and
-- they might as well be done all together.
procedure Set_Successor (Pat : PE_Ptr; Succ : PE_Ptr) is
begin
if Pat = null then
Uninitialized_Pattern;
elsif Pat = EOP then
Logic_Error;
else
declare
Refs : Ref_Array (1 .. Pat.Index);
-- We build a reference array for L whose N'th element points to
-- the pattern element of L whose original Index value is N.
P : PE_Ptr;
begin
Build_Ref_Array (Pat, Refs);
for J in Refs'Range loop
P := Refs (J);
if P.Pthen = EOP then
P.Pthen := Succ;
end if;
if P.Pcode in PC_Has_Alt and then P.Alt = EOP then
P.Alt := Succ;
end if;
end loop;
end;
end if;
end Set_Successor;
------------
-- Setcur --
------------
function Setcur (Var : not null access Natural) return Pattern is
begin
return (AFC with 0, new PE'(PC_Setcur, 1, EOP, Natural_Ptr (Var)));
end Setcur;
----------
-- Span --
----------
function Span (Str : String) return Pattern is
begin
return (AFC with 0, new PE'(PC_Span_CS, 1, EOP, To_Set (Str)));
end Span;
function Span (Str : VString) return Pattern is
begin
return Span (S (Str));
end Span;
function Span (Str : Character) return Pattern is
begin
return (AFC with 0, new PE'(PC_Span_CH, 1, EOP, Str));
end Span;
function Span (Str : Character_Set) return Pattern is
begin
return (AFC with 0, new PE'(PC_Span_CS, 1, EOP, Str));
end Span;
function Span (Str : not null access VString) return Pattern is
begin
return (AFC with 0, new PE'(PC_Span_VP, 1, EOP, VString_Ptr (Str)));
end Span;
function Span (Str : VString_Func) return Pattern is
begin
return (AFC with 0, new PE'(PC_Span_VF, 1, EOP, Str));
end Span;
------------
-- Str_BF --
------------
function Str_BF (A : Boolean_Func) return String is
function To_A is new Ada.Unchecked_Conversion (Boolean_Func, Address);
begin
return "BF(" & Image (To_A (A)) & ')';
end Str_BF;
------------
-- Str_FP --
------------
function Str_FP (A : File_Ptr) return String is
begin
return "FP(" & Image (A.all'Address) & ')';
end Str_FP;
------------
-- Str_NF --
------------
function Str_NF (A : Natural_Func) return String is
function To_A is new Ada.Unchecked_Conversion (Natural_Func, Address);
begin
return "NF(" & Image (To_A (A)) & ')';
end Str_NF;
------------
-- Str_NP --
------------
function Str_NP (A : Natural_Ptr) return String is
begin
return "NP(" & Image (A.all'Address) & ')';
end Str_NP;
------------
-- Str_PP --
------------
function Str_PP (A : Pattern_Ptr) return String is
begin
return "PP(" & Image (A.all'Address) & ')';
end Str_PP;
------------
-- Str_VF --
------------
function Str_VF (A : VString_Func) return String is
function To_A is new Ada.Unchecked_Conversion (VString_Func, Address);
begin
return "VF(" & Image (To_A (A)) & ')';
end Str_VF;
------------
-- Str_VP --
------------
function Str_VP (A : VString_Ptr) return String is
begin
return "VP(" & Image (A.all'Address) & ')';
end Str_VP;
-------------
-- Succeed --
-------------
function Succeed return Pattern is
begin
return (AFC with 1, new PE'(PC_Succeed, 1, EOP));
end Succeed;
---------
-- Tab --
---------
function Tab (Count : Natural) return Pattern is
begin
return (AFC with 0, new PE'(PC_Tab_Nat, 1, EOP, Count));
end Tab;
function Tab (Count : Natural_Func) return Pattern is
begin
return (AFC with 0, new PE'(PC_Tab_NF, 1, EOP, Count));
end Tab;
function Tab (Count : not null access Natural) return Pattern is
begin
return (AFC with 0, new PE'(PC_Tab_NP, 1, EOP, Natural_Ptr (Count)));
end Tab;
---------------------------
-- Uninitialized_Pattern --
---------------------------
procedure Uninitialized_Pattern is
begin
raise Program_Error with
"uninitialized value of type GNAT.Spitbol.Patterns.Pattern";
end Uninitialized_Pattern;
------------
-- XMatch --
------------
procedure XMatch
(Subject : String;
Pat_P : PE_Ptr;
Pat_S : Natural;
Start : out Natural;
Stop : out Natural)
is
Node : PE_Ptr;
-- Pointer to current pattern node. Initialized from Pat_P, and then
-- updated as the match proceeds through its constituent elements.
Length : constant Natural := Subject'Length;
-- Length of string (= Subject'Last, since Subject'First is always 1)
Cursor : Integer := 0;
-- If the value is non-negative, then this value is the index showing
-- the current position of the match in the subject string. The next
-- character to be matched is at Subject (Cursor + 1). Note that since
-- our view of the subject string in XMatch always has a lower bound
-- of one, regardless of original bounds, that this definition exactly
-- corresponds to the cursor value as referenced by functions like Pos.
--
-- If the value is negative, then this is a saved stack pointer,
-- typically a base pointer of an inner or outer region. Cursor
-- temporarily holds such a value when it is popped from the stack
-- by Fail. In all cases, Cursor is reset to a proper non-negative
-- cursor value before the match proceeds (e.g. by propagating the
-- failure and popping a "real" cursor value from the stack.
PE_Unanchored : aliased PE := (PC_Unanchored, 0, Pat_P);
-- Dummy pattern element used in the unanchored case
Stack : Stack_Type;
-- The pattern matching failure stack for this call to Match
Stack_Ptr : Stack_Range;
-- Current stack pointer. This points to the top element of the stack
-- that is currently in use. At the outer level this is the special
-- entry placed on the stack according to the anchor mode.
Stack_Init : constant Stack_Range := Stack'First + 1;
-- This is the initial value of the Stack_Ptr and Stack_Base. The
-- initial (Stack'First) element of the stack is not used so that
-- when we pop the last element off, Stack_Ptr is still in range.
Stack_Base : Stack_Range;
-- This value is the stack base value, i.e. the stack pointer for the
-- first history stack entry in the current stack region. See separate
-- section on handling of recursive pattern matches.
Assign_OnM : Boolean := False;
-- Set True if assign-on-match or write-on-match operations may be
-- present in the history stack, which must then be scanned on a
-- successful match.
procedure Pop_Region;
pragma Inline (Pop_Region);
-- Used at the end of processing of an inner region. If the inner
-- region left no stack entries, then all trace of it is removed.
-- Otherwise a PC_Restore_Region entry is pushed to ensure proper
-- handling of alternatives in the inner region.
procedure Push (Node : PE_Ptr);
pragma Inline (Push);
-- Make entry in pattern matching stack with current cursor value
procedure Push_Region;
pragma Inline (Push_Region);
-- This procedure makes a new region on the history stack. The
-- caller first establishes the special entry on the stack, but
-- does not push the stack pointer. Then this call stacks a
-- PC_Remove_Region node, on top of this entry, using the cursor
-- field of the PC_Remove_Region entry to save the outer level
-- stack base value, and resets the stack base to point to this
-- PC_Remove_Region node.
----------------
-- Pop_Region --
----------------
procedure Pop_Region is
begin
-- If nothing was pushed in the inner region, we can just get
-- rid of it entirely, leaving no traces that it was ever there
if Stack_Ptr = Stack_Base then
Stack_Ptr := Stack_Base - 2;
Stack_Base := Stack (Stack_Ptr + 2).Cursor;
-- If stuff was pushed in the inner region, then we have to
-- push a PC_R_Restore node so that we properly handle possible
-- rematches within the region.
else
Stack_Ptr := Stack_Ptr + 1;
Stack (Stack_Ptr).Cursor := Stack_Base;
Stack (Stack_Ptr).Node := CP_R_Restore'Access;
Stack_Base := Stack (Stack_Base).Cursor;
end if;
end Pop_Region;
----------
-- Push --
----------
procedure Push (Node : PE_Ptr) is
begin
Stack_Ptr := Stack_Ptr + 1;
Stack (Stack_Ptr).Cursor := Cursor;
Stack (Stack_Ptr).Node := Node;
end Push;
-----------------
-- Push_Region --
-----------------
procedure Push_Region is
begin
Stack_Ptr := Stack_Ptr + 2;
Stack (Stack_Ptr).Cursor := Stack_Base;
Stack (Stack_Ptr).Node := CP_R_Remove'Access;
Stack_Base := Stack_Ptr;
end Push_Region;
-- Start of processing for XMatch
begin
if Pat_P = null then
Uninitialized_Pattern;
end if;
-- Check we have enough stack for this pattern. This check deals with
-- every possibility except a match of a recursive pattern, where we
-- make a check at each recursion level.
if Pat_S >= Stack_Size - 1 then
raise Pattern_Stack_Overflow;
end if;
-- In anchored mode, the bottom entry on the stack is an abort entry
if Anchored_Mode then
Stack (Stack_Init).Node := CP_Cancel'Access;
Stack (Stack_Init).Cursor := 0;
-- In unanchored more, the bottom entry on the stack references
-- the special pattern element PE_Unanchored, whose Pthen field
-- points to the initial pattern element. The cursor value in this
-- entry is the number of anchor moves so far.
else
Stack (Stack_Init).Node := PE_Unanchored'Unchecked_Access;
Stack (Stack_Init).Cursor := 0;
end if;
Stack_Ptr := Stack_Init;
Stack_Base := Stack_Ptr;
Cursor := 0;
Node := Pat_P;
goto Match;
-----------------------------------------
-- Main Pattern Matching State Control --
-----------------------------------------
-- This is a state machine which uses gotos to change state. The
-- initial state is Match, to initiate the matching of the first
-- element, so the goto Match above starts the match. In the
-- following descriptions, we indicate the global values that
-- are relevant for the state transition.
-- Come here if entire match fails
<<Match_Fail>>
Start := 0;
Stop := 0;
return;
-- Come here if entire match succeeds
-- Cursor current position in subject string
<<Match_Succeed>>
Start := Stack (Stack_Init).Cursor + 1;
Stop := Cursor;
-- Scan history stack for deferred assignments or writes
if Assign_OnM then
for S in Stack_Init .. Stack_Ptr loop
if Stack (S).Node = CP_Assign'Access then
declare
Inner_Base : constant Stack_Range :=
Stack (S + 1).Cursor;
Special_Entry : constant Stack_Range :=
Inner_Base - 1;
Node_OnM : constant PE_Ptr :=
Stack (Special_Entry).Node;
Start : constant Natural :=
Stack (Special_Entry).Cursor + 1;
Stop : constant Natural := Stack (S).Cursor;
begin
if Node_OnM.Pcode = PC_Assign_OnM then
Set_Unbounded_String
(Node_OnM.VP.all, Subject (Start .. Stop));
elsif Node_OnM.Pcode = PC_Write_OnM then
Put_Line (Node_OnM.FP.all, Subject (Start .. Stop));
else
Logic_Error;
end if;
end;
end if;
end loop;
end if;
return;
-- Come here if attempt to match current element fails
-- Stack_Base current stack base
-- Stack_Ptr current stack pointer
<<Fail>>
Cursor := Stack (Stack_Ptr).Cursor;
Node := Stack (Stack_Ptr).Node;
Stack_Ptr := Stack_Ptr - 1;
goto Match;
-- Come here if attempt to match current element succeeds
-- Cursor current position in subject string
-- Node pointer to node successfully matched
-- Stack_Base current stack base
-- Stack_Ptr current stack pointer
<<Succeed>>
Node := Node.Pthen;
-- Come here to match the next pattern element
-- Cursor current position in subject string
-- Node pointer to node to be matched
-- Stack_Base current stack base
-- Stack_Ptr current stack pointer
<<Match>>
--------------------------------------------------
-- Main Pattern Match Element Matching Routines --
--------------------------------------------------
-- Here is the case statement that processes the current node. The
-- processing for each element does one of five things:
-- goto Succeed to move to the successor
-- goto Match_Succeed if the entire match succeeds
-- goto Match_Fail if the entire match fails
-- goto Fail to signal failure of current match
-- Processing is NOT allowed to fall through
case Node.Pcode is
-- Cancel
when PC_Cancel =>
goto Match_Fail;
-- Alternation
when PC_Alt =>
Push (Node.Alt);
Node := Node.Pthen;
goto Match;
-- Any (one character case)
when PC_Any_CH =>
if Cursor < Length
and then Subject (Cursor + 1) = Node.Char
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
-- Any (character set case)
when PC_Any_CS =>
if Cursor < Length
and then Is_In (Subject (Cursor + 1), Node.CS)
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
-- Any (string function case)
when PC_Any_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
if Cursor < Length
and then Is_In (Subject (Cursor + 1), S (1 .. L))
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
end;
-- Any (string pointer case)
when PC_Any_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
if Cursor < Length
and then Is_In (Subject (Cursor + 1), S (1 .. L))
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
end;
-- Arb (initial match)
when PC_Arb_X =>
Push (Node.Alt);
Node := Node.Pthen;
goto Match;
-- Arb (extension)
when PC_Arb_Y =>
if Cursor < Length then
Cursor := Cursor + 1;
Push (Node);
goto Succeed;
else
goto Fail;
end if;
-- Arbno_S (simple Arbno initialize). This is the node that
-- initiates the match of a simple Arbno structure.
when PC_Arbno_S =>
Push (Node.Alt);
Node := Node.Pthen;
goto Match;
-- Arbno_X (Arbno initialize). This is the node that initiates
-- the match of a complex Arbno structure.
when PC_Arbno_X =>
Push (Node.Alt);
Node := Node.Pthen;
goto Match;
-- Arbno_Y (Arbno rematch). This is the node that is executed
-- following successful matching of one instance of a complex
-- Arbno pattern.
when PC_Arbno_Y => declare
Null_Match : constant Boolean :=
Cursor = Stack (Stack_Base - 1).Cursor;
begin
Pop_Region;
-- If arbno extension matched null, then immediately fail
if Null_Match then
goto Fail;
end if;
-- Here we must do a stack check to make sure enough stack
-- is left. This check will happen once for each instance of
-- the Arbno pattern that is matched. The Nat field of a
-- PC_Arbno pattern contains the maximum stack entries needed
-- for the Arbno with one instance and the successor pattern
if Stack_Ptr + Node.Nat >= Stack'Last then
raise Pattern_Stack_Overflow;
end if;
goto Succeed;
end;
-- Assign. If this node is executed, it means the assign-on-match
-- or write-on-match operation will not happen after all, so we
-- is propagate the failure, removing the PC_Assign node.
when PC_Assign =>
goto Fail;
-- Assign immediate. This node performs the actual assignment
when PC_Assign_Imm =>
Set_Unbounded_String
(Node.VP.all,
Subject (Stack (Stack_Base - 1).Cursor + 1 .. Cursor));
Pop_Region;
goto Succeed;
-- Assign on match. This node sets up for the eventual assignment
when PC_Assign_OnM =>
Stack (Stack_Base - 1).Node := Node;
Push (CP_Assign'Access);
Pop_Region;
Assign_OnM := True;
goto Succeed;
-- Bal
when PC_Bal =>
if Cursor >= Length or else Subject (Cursor + 1) = ')' then
goto Fail;
elsif Subject (Cursor + 1) = '(' then
declare
Paren_Count : Natural := 1;
begin
loop
Cursor := Cursor + 1;
if Cursor >= Length then
goto Fail;
elsif Subject (Cursor + 1) = '(' then
Paren_Count := Paren_Count + 1;
elsif Subject (Cursor + 1) = ')' then
Paren_Count := Paren_Count - 1;
exit when Paren_Count = 0;
end if;
end loop;
end;
end if;
Cursor := Cursor + 1;
Push (Node);
goto Succeed;
-- Break (one character case)
when PC_Break_CH =>
while Cursor < Length loop
if Subject (Cursor + 1) = Node.Char then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
-- Break (character set case)
when PC_Break_CS =>
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), Node.CS) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
-- Break (string function case)
when PC_Break_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), S (1 .. L)) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
end;
-- Break (string pointer case)
when PC_Break_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), S (1 .. L)) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
end;
-- BreakX (one character case)
when PC_BreakX_CH =>
while Cursor < Length loop
if Subject (Cursor + 1) = Node.Char then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
-- BreakX (character set case)
when PC_BreakX_CS =>
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), Node.CS) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
-- BreakX (string function case)
when PC_BreakX_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), S (1 .. L)) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
end;
-- BreakX (string pointer case)
when PC_BreakX_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), S (1 .. L)) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
end;
-- BreakX_X (BreakX extension). See section on "Compound Pattern
-- Structures". This node is the alternative that is stacked to
-- skip past the break character and extend the break.
when PC_BreakX_X =>
Cursor := Cursor + 1;
goto Succeed;
-- Character (one character string)
when PC_Char =>
if Cursor < Length
and then Subject (Cursor + 1) = Node.Char
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
-- End of Pattern
when PC_EOP =>
if Stack_Base = Stack_Init then
goto Match_Succeed;
-- End of recursive inner match. See separate section on
-- handing of recursive pattern matches for details.
else
Node := Stack (Stack_Base - 1).Node;
Pop_Region;
goto Match;
end if;
-- Fail
when PC_Fail =>
goto Fail;
-- Fence (built in pattern)
when PC_Fence =>
Push (CP_Cancel'Access);
goto Succeed;
-- Fence function node X. This is the node that gets control
-- after a successful match of the fenced pattern.
when PC_Fence_X =>
Stack_Ptr := Stack_Ptr + 1;
Stack (Stack_Ptr).Cursor := Stack_Base;
Stack (Stack_Ptr).Node := CP_Fence_Y'Access;
Stack_Base := Stack (Stack_Base).Cursor;
goto Succeed;
-- Fence function node Y. This is the node that gets control on
-- a failure that occurs after the fenced pattern has matched.
-- Note: the Cursor at this stage is actually the inner stack
-- base value. We don't reset this, but we do use it to strip
-- off all the entries made by the fenced pattern.
when PC_Fence_Y =>
Stack_Ptr := Cursor - 2;
goto Fail;
-- Len (integer case)
when PC_Len_Nat =>
if Cursor + Node.Nat > Length then
goto Fail;
else
Cursor := Cursor + Node.Nat;
goto Succeed;
end if;
-- Len (Integer function case)
when PC_Len_NF => declare
N : constant Natural := Node.NF.all;
begin
if Cursor + N > Length then
goto Fail;
else
Cursor := Cursor + N;
goto Succeed;
end if;
end;
-- Len (integer pointer case)
when PC_Len_NP =>
if Cursor + Node.NP.all > Length then
goto Fail;
else
Cursor := Cursor + Node.NP.all;
goto Succeed;
end if;
-- NotAny (one character case)
when PC_NotAny_CH =>
if Cursor < Length
and then Subject (Cursor + 1) /= Node.Char
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
-- NotAny (character set case)
when PC_NotAny_CS =>
if Cursor < Length
and then not Is_In (Subject (Cursor + 1), Node.CS)
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
-- NotAny (string function case)
when PC_NotAny_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
if Cursor < Length
and then
not Is_In (Subject (Cursor + 1), S (1 .. L))
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
end;
-- NotAny (string pointer case)
when PC_NotAny_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
if Cursor < Length
and then
not Is_In (Subject (Cursor + 1), S (1 .. L))
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
end;
-- NSpan (one character case)
when PC_NSpan_CH =>
while Cursor < Length
and then Subject (Cursor + 1) = Node.Char
loop
Cursor := Cursor + 1;
end loop;
goto Succeed;
-- NSpan (character set case)
when PC_NSpan_CS =>
while Cursor < Length
and then Is_In (Subject (Cursor + 1), Node.CS)
loop
Cursor := Cursor + 1;
end loop;
goto Succeed;
-- NSpan (string function case)
when PC_NSpan_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
while Cursor < Length
and then Is_In (Subject (Cursor + 1), S (1 .. L))
loop
Cursor := Cursor + 1;
end loop;
goto Succeed;
end;
-- NSpan (string pointer case)
when PC_NSpan_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
while Cursor < Length
and then Is_In (Subject (Cursor + 1), S (1 .. L))
loop
Cursor := Cursor + 1;
end loop;
goto Succeed;
end;
-- Null string
when PC_Null =>
goto Succeed;
-- Pos (integer case)
when PC_Pos_Nat =>
if Cursor = Node.Nat then
goto Succeed;
else
goto Fail;
end if;
-- Pos (Integer function case)
when PC_Pos_NF => declare
N : constant Natural := Node.NF.all;
begin
if Cursor = N then
goto Succeed;
else
goto Fail;
end if;
end;
-- Pos (integer pointer case)
when PC_Pos_NP =>
if Cursor = Node.NP.all then
goto Succeed;
else
goto Fail;
end if;
-- Predicate function
when PC_Pred_Func =>
if Node.BF.all then
goto Succeed;
else
goto Fail;
end if;
-- Region Enter. Initiate new pattern history stack region
when PC_R_Enter =>
Stack (Stack_Ptr + 1).Cursor := Cursor;
Push_Region;
goto Succeed;
-- Region Remove node. This is the node stacked by an R_Enter.
-- It removes the special format stack entry right underneath, and
-- then restores the outer level stack base and signals failure.
-- Note: the cursor value at this stage is actually the (negative)
-- stack base value for the outer level.
when PC_R_Remove =>
Stack_Base := Cursor;
Stack_Ptr := Stack_Ptr - 1;
goto Fail;
-- Region restore node. This is the node stacked at the end of an
-- inner level match. Its function is to restore the inner level
-- region, so that alternatives in this region can be sought.
-- Note: the Cursor at this stage is actually the negative of the
-- inner stack base value, which we use to restore the inner region.
when PC_R_Restore =>
Stack_Base := Cursor;
goto Fail;
-- Rest
when PC_Rest =>
Cursor := Length;
goto Succeed;
-- Initiate recursive match (pattern pointer case)
when PC_Rpat =>
Stack (Stack_Ptr + 1).Node := Node.Pthen;
Push_Region;
if Stack_Ptr + Node.PP.all.Stk >= Stack_Size then
raise Pattern_Stack_Overflow;
else
Node := Node.PP.all.P;
goto Match;
end if;
-- RPos (integer case)
when PC_RPos_Nat =>
if Cursor = (Length - Node.Nat) then
goto Succeed;
else
goto Fail;
end if;
-- RPos (integer function case)
when PC_RPos_NF => declare
N : constant Natural := Node.NF.all;
begin
if Length - Cursor = N then
goto Succeed;
else
goto Fail;
end if;
end;
-- RPos (integer pointer case)
when PC_RPos_NP =>
if Cursor = (Length - Node.NP.all) then
goto Succeed;
else
goto Fail;
end if;
-- RTab (integer case)
when PC_RTab_Nat =>
if Cursor <= (Length - Node.Nat) then
Cursor := Length - Node.Nat;
goto Succeed;
else
goto Fail;
end if;
-- RTab (integer function case)
when PC_RTab_NF => declare
N : constant Natural := Node.NF.all;
begin
if Length - Cursor >= N then
Cursor := Length - N;
goto Succeed;
else
goto Fail;
end if;
end;
-- RTab (integer pointer case)
when PC_RTab_NP =>
if Cursor <= (Length - Node.NP.all) then
Cursor := Length - Node.NP.all;
goto Succeed;
else
goto Fail;
end if;
-- Cursor assignment
when PC_Setcur =>
Node.Var.all := Cursor;
goto Succeed;
-- Span (one character case)
when PC_Span_CH => declare
P : Natural;
begin
P := Cursor;
while P < Length
and then Subject (P + 1) = Node.Char
loop
P := P + 1;
end loop;
if P /= Cursor then
Cursor := P;
goto Succeed;
else
goto Fail;
end if;
end;
-- Span (character set case)
when PC_Span_CS => declare
P : Natural;
begin
P := Cursor;
while P < Length
and then Is_In (Subject (P + 1), Node.CS)
loop
P := P + 1;
end loop;
if P /= Cursor then
Cursor := P;
goto Succeed;
else
goto Fail;
end if;
end;
-- Span (string function case)
when PC_Span_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
P : Natural;
begin
Get_String (U, S, L);
P := Cursor;
while P < Length
and then Is_In (Subject (P + 1), S (1 .. L))
loop
P := P + 1;
end loop;
if P /= Cursor then
Cursor := P;
goto Succeed;
else
goto Fail;
end if;
end;
-- Span (string pointer case)
when PC_Span_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
P : Natural;
begin
Get_String (U, S, L);
P := Cursor;
while P < Length
and then Is_In (Subject (P + 1), S (1 .. L))
loop
P := P + 1;
end loop;
if P /= Cursor then
Cursor := P;
goto Succeed;
else
goto Fail;
end if;
end;
-- String (two character case)
when PC_String_2 =>
if (Length - Cursor) >= 2
and then Subject (Cursor + 1 .. Cursor + 2) = Node.Str2
then
Cursor := Cursor + 2;
goto Succeed;
else
goto Fail;
end if;
-- String (three character case)
when PC_String_3 =>
if (Length - Cursor) >= 3
and then Subject (Cursor + 1 .. Cursor + 3) = Node.Str3
then
Cursor := Cursor + 3;
goto Succeed;
else
goto Fail;
end if;
-- String (four character case)
when PC_String_4 =>
if (Length - Cursor) >= 4
and then Subject (Cursor + 1 .. Cursor + 4) = Node.Str4
then
Cursor := Cursor + 4;
goto Succeed;
else
goto Fail;
end if;
-- String (five character case)
when PC_String_5 =>
if (Length - Cursor) >= 5
and then Subject (Cursor + 1 .. Cursor + 5) = Node.Str5
then
Cursor := Cursor + 5;
goto Succeed;
else
goto Fail;
end if;
-- String (six character case)
when PC_String_6 =>
if (Length - Cursor) >= 6
and then Subject (Cursor + 1 .. Cursor + 6) = Node.Str6
then
Cursor := Cursor + 6;
goto Succeed;
else
goto Fail;
end if;
-- String (case of more than six characters)
when PC_String => declare
Len : constant Natural := Node.Str'Length;
begin
if (Length - Cursor) >= Len
and then Node.Str.all = Subject (Cursor + 1 .. Cursor + Len)
then
Cursor := Cursor + Len;
goto Succeed;
else
goto Fail;
end if;
end;
-- String (function case)
when PC_String_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
if (Length - Cursor) >= L
and then S (1 .. L) = Subject (Cursor + 1 .. Cursor + L)
then
Cursor := Cursor + L;
goto Succeed;
else
goto Fail;
end if;
end;
-- String (pointer case)
when PC_String_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
if (Length - Cursor) >= L
and then S (1 .. L) = Subject (Cursor + 1 .. Cursor + L)
then
Cursor := Cursor + L;
goto Succeed;
else
goto Fail;
end if;
end;
-- Succeed
when PC_Succeed =>
Push (Node);
goto Succeed;
-- Tab (integer case)
when PC_Tab_Nat =>
if Cursor <= Node.Nat then
Cursor := Node.Nat;
goto Succeed;
else
goto Fail;
end if;
-- Tab (integer function case)
when PC_Tab_NF => declare
N : constant Natural := Node.NF.all;
begin
if Cursor <= N then
Cursor := N;
goto Succeed;
else
goto Fail;
end if;
end;
-- Tab (integer pointer case)
when PC_Tab_NP =>
if Cursor <= Node.NP.all then
Cursor := Node.NP.all;
goto Succeed;
else
goto Fail;
end if;
-- Unanchored movement
when PC_Unanchored =>
-- All done if we tried every position
if Cursor > Length then
goto Match_Fail;
-- Otherwise extend the anchor point, and restack ourself
else
Cursor := Cursor + 1;
Push (Node);
goto Succeed;
end if;
-- Write immediate. This node performs the actual write
when PC_Write_Imm =>
Put_Line
(Node.FP.all,
Subject (Stack (Stack_Base - 1).Cursor + 1 .. Cursor));
Pop_Region;
goto Succeed;
-- Write on match. This node sets up for the eventual write
when PC_Write_OnM =>
Stack (Stack_Base - 1).Node := Node;
Push (CP_Assign'Access);
Pop_Region;
Assign_OnM := True;
goto Succeed;
end case;
-- We are NOT allowed to fall though this case statement, since every
-- match routine must end by executing a goto to the appropriate point
-- in the finite state machine model.
pragma Warnings (Off);
Logic_Error;
pragma Warnings (On);
end XMatch;
-------------
-- XMatchD --
-------------
-- Maintenance note: There is a LOT of code duplication between XMatch
-- and XMatchD. This is quite intentional, the point is to avoid any
-- unnecessary debugging overhead in the XMatch case, but this does mean
-- that any changes to XMatchD must be mirrored in XMatch. In case of
-- any major changes, the proper approach is to delete XMatch, make the
-- changes to XMatchD, and then make a copy of XMatchD, removing all
-- calls to Dout, and all Put and Put_Line operations. This copy becomes
-- the new XMatch.
procedure XMatchD
(Subject : String;
Pat_P : PE_Ptr;
Pat_S : Natural;
Start : out Natural;
Stop : out Natural)
is
Node : PE_Ptr;
-- Pointer to current pattern node. Initialized from Pat_P, and then
-- updated as the match proceeds through its constituent elements.
Length : constant Natural := Subject'Length;
-- Length of string (= Subject'Last, since Subject'First is always 1)
Cursor : Integer := 0;
-- If the value is non-negative, then this value is the index showing
-- the current position of the match in the subject string. The next
-- character to be matched is at Subject (Cursor + 1). Note that since
-- our view of the subject string in XMatch always has a lower bound
-- of one, regardless of original bounds, that this definition exactly
-- corresponds to the cursor value as referenced by functions like Pos.
--
-- If the value is negative, then this is a saved stack pointer,
-- typically a base pointer of an inner or outer region. Cursor
-- temporarily holds such a value when it is popped from the stack
-- by Fail. In all cases, Cursor is reset to a proper non-negative
-- cursor value before the match proceeds (e.g. by propagating the
-- failure and popping a "real" cursor value from the stack.
PE_Unanchored : aliased PE := (PC_Unanchored, 0, Pat_P);
-- Dummy pattern element used in the unanchored case
Region_Level : Natural := 0;
-- Keeps track of recursive region level. This is used only for
-- debugging, it is the number of saved history stack base values.
Stack : Stack_Type;
-- The pattern matching failure stack for this call to Match
Stack_Ptr : Stack_Range;
-- Current stack pointer. This points to the top element of the stack
-- that is currently in use. At the outer level this is the special
-- entry placed on the stack according to the anchor mode.
Stack_Init : constant Stack_Range := Stack'First + 1;
-- This is the initial value of the Stack_Ptr and Stack_Base. The
-- initial (Stack'First) element of the stack is not used so that
-- when we pop the last element off, Stack_Ptr is still in range.
Stack_Base : Stack_Range;
-- This value is the stack base value, i.e. the stack pointer for the
-- first history stack entry in the current stack region. See separate
-- section on handling of recursive pattern matches.
Assign_OnM : Boolean := False;
-- Set True if assign-on-match or write-on-match operations may be
-- present in the history stack, which must then be scanned on a
-- successful match.
procedure Dout (Str : String);
-- Output string to standard error with bars indicating region level
procedure Dout (Str : String; A : Character);
-- Calls Dout with the string S ('A')
procedure Dout (Str : String; A : Character_Set);
-- Calls Dout with the string S ("A")
procedure Dout (Str : String; A : Natural);
-- Calls Dout with the string S (A)
procedure Dout (Str : String; A : String);
-- Calls Dout with the string S ("A")
function Img (P : PE_Ptr) return String;
-- Returns a string of the form #nnn where nnn is P.Index
procedure Pop_Region;
pragma Inline (Pop_Region);
-- Used at the end of processing of an inner region. If the inner
-- region left no stack entries, then all trace of it is removed.
-- Otherwise a PC_Restore_Region entry is pushed to ensure proper
-- handling of alternatives in the inner region.
procedure Push (Node : PE_Ptr);
pragma Inline (Push);
-- Make entry in pattern matching stack with current cursor value
procedure Push_Region;
pragma Inline (Push_Region);
-- This procedure makes a new region on the history stack. The
-- caller first establishes the special entry on the stack, but
-- does not push the stack pointer. Then this call stacks a
-- PC_Remove_Region node, on top of this entry, using the cursor
-- field of the PC_Remove_Region entry to save the outer level
-- stack base value, and resets the stack base to point to this
-- PC_Remove_Region node.
----------
-- Dout --
----------
procedure Dout (Str : String) is
begin
for J in 1 .. Region_Level loop
Put ("| ");
end loop;
Put_Line (Str);
end Dout;
procedure Dout (Str : String; A : Character) is
begin
Dout (Str & " ('" & A & "')");
end Dout;
procedure Dout (Str : String; A : Character_Set) is
begin
Dout (Str & " (" & Image (To_Sequence (A)) & ')');
end Dout;
procedure Dout (Str : String; A : Natural) is
begin
Dout (Str & " (" & A & ')');
end Dout;
procedure Dout (Str : String; A : String) is
begin
Dout (Str & " (" & Image (A) & ')');
end Dout;
---------
-- Img --
---------
function Img (P : PE_Ptr) return String is
begin
return "#" & Integer (P.Index) & " ";
end Img;
----------------
-- Pop_Region --
----------------
procedure Pop_Region is
begin
Region_Level := Region_Level - 1;
-- If nothing was pushed in the inner region, we can just get
-- rid of it entirely, leaving no traces that it was ever there
if Stack_Ptr = Stack_Base then
Stack_Ptr := Stack_Base - 2;
Stack_Base := Stack (Stack_Ptr + 2).Cursor;
-- If stuff was pushed in the inner region, then we have to
-- push a PC_R_Restore node so that we properly handle possible
-- rematches within the region.
else
Stack_Ptr := Stack_Ptr + 1;
Stack (Stack_Ptr).Cursor := Stack_Base;
Stack (Stack_Ptr).Node := CP_R_Restore'Access;
Stack_Base := Stack (Stack_Base).Cursor;
end if;
end Pop_Region;
----------
-- Push --
----------
procedure Push (Node : PE_Ptr) is
begin
Stack_Ptr := Stack_Ptr + 1;
Stack (Stack_Ptr).Cursor := Cursor;
Stack (Stack_Ptr).Node := Node;
end Push;
-----------------
-- Push_Region --
-----------------
procedure Push_Region is
begin
Region_Level := Region_Level + 1;
Stack_Ptr := Stack_Ptr + 2;
Stack (Stack_Ptr).Cursor := Stack_Base;
Stack (Stack_Ptr).Node := CP_R_Remove'Access;
Stack_Base := Stack_Ptr;
end Push_Region;
-- Start of processing for XMatchD
begin
New_Line;
Put_Line ("Initiating pattern match, subject = " & Image (Subject));
Put ("--------------------------------------");
for J in 1 .. Length loop
Put ('-');
end loop;
New_Line;
Put_Line ("subject length = " & Length);
if Pat_P = null then
Uninitialized_Pattern;
end if;
-- Check we have enough stack for this pattern. This check deals with
-- every possibility except a match of a recursive pattern, where we
-- make a check at each recursion level.
if Pat_S >= Stack_Size - 1 then
raise Pattern_Stack_Overflow;
end if;
-- In anchored mode, the bottom entry on the stack is an abort entry
if Anchored_Mode then
Stack (Stack_Init).Node := CP_Cancel'Access;
Stack (Stack_Init).Cursor := 0;
-- In unanchored more, the bottom entry on the stack references
-- the special pattern element PE_Unanchored, whose Pthen field
-- points to the initial pattern element. The cursor value in this
-- entry is the number of anchor moves so far.
else
Stack (Stack_Init).Node := PE_Unanchored'Unchecked_Access;
Stack (Stack_Init).Cursor := 0;
end if;
Stack_Ptr := Stack_Init;
Stack_Base := Stack_Ptr;
Cursor := 0;
Node := Pat_P;
goto Match;
-----------------------------------------
-- Main Pattern Matching State Control --
-----------------------------------------
-- This is a state machine which uses gotos to change state. The
-- initial state is Match, to initiate the matching of the first
-- element, so the goto Match above starts the match. In the
-- following descriptions, we indicate the global values that
-- are relevant for the state transition.
-- Come here if entire match fails
<<Match_Fail>>
Dout ("match fails");
New_Line;
Start := 0;
Stop := 0;
return;
-- Come here if entire match succeeds
-- Cursor current position in subject string
<<Match_Succeed>>
Dout ("match succeeds");
Start := Stack (Stack_Init).Cursor + 1;
Stop := Cursor;
Dout ("first matched character index = " & Start);
Dout ("last matched character index = " & Stop);
Dout ("matched substring = " & Image (Subject (Start .. Stop)));
-- Scan history stack for deferred assignments or writes
if Assign_OnM then
for S in Stack'First .. Stack_Ptr loop
if Stack (S).Node = CP_Assign'Access then
declare
Inner_Base : constant Stack_Range :=
Stack (S + 1).Cursor;
Special_Entry : constant Stack_Range :=
Inner_Base - 1;
Node_OnM : constant PE_Ptr :=
Stack (Special_Entry).Node;
Start : constant Natural :=
Stack (Special_Entry).Cursor + 1;
Stop : constant Natural := Stack (S).Cursor;
begin
if Node_OnM.Pcode = PC_Assign_OnM then
Set_Unbounded_String
(Node_OnM.VP.all, Subject (Start .. Stop));
Dout
(Img (Stack (S).Node) &
"deferred assignment of " &
Image (Subject (Start .. Stop)));
elsif Node_OnM.Pcode = PC_Write_OnM then
Put_Line (Node_OnM.FP.all, Subject (Start .. Stop));
Dout
(Img (Stack (S).Node) &
"deferred write of " &
Image (Subject (Start .. Stop)));
else
Logic_Error;
end if;
end;
end if;
end loop;
end if;
New_Line;
return;
-- Come here if attempt to match current element fails
-- Stack_Base current stack base
-- Stack_Ptr current stack pointer
<<Fail>>
Cursor := Stack (Stack_Ptr).Cursor;
Node := Stack (Stack_Ptr).Node;
Stack_Ptr := Stack_Ptr - 1;
if Cursor >= 0 then
Dout ("failure, cursor reset to " & Cursor);
end if;
goto Match;
-- Come here if attempt to match current element succeeds
-- Cursor current position in subject string
-- Node pointer to node successfully matched
-- Stack_Base current stack base
-- Stack_Ptr current stack pointer
<<Succeed>>
Dout ("success, cursor = " & Cursor);
Node := Node.Pthen;
-- Come here to match the next pattern element
-- Cursor current position in subject string
-- Node pointer to node to be matched
-- Stack_Base current stack base
-- Stack_Ptr current stack pointer
<<Match>>
--------------------------------------------------
-- Main Pattern Match Element Matching Routines --
--------------------------------------------------
-- Here is the case statement that processes the current node. The
-- processing for each element does one of five things:
-- goto Succeed to move to the successor
-- goto Match_Succeed if the entire match succeeds
-- goto Match_Fail if the entire match fails
-- goto Fail to signal failure of current match
-- Processing is NOT allowed to fall through
case Node.Pcode is
-- Cancel
when PC_Cancel =>
Dout (Img (Node) & "matching Cancel");
goto Match_Fail;
-- Alternation
when PC_Alt =>
Dout (Img (Node) & "setting up alternative " & Img (Node.Alt));
Push (Node.Alt);
Node := Node.Pthen;
goto Match;
-- Any (one character case)
when PC_Any_CH =>
Dout (Img (Node) & "matching Any", Node.Char);
if Cursor < Length
and then Subject (Cursor + 1) = Node.Char
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
-- Any (character set case)
when PC_Any_CS =>
Dout (Img (Node) & "matching Any", Node.CS);
if Cursor < Length
and then Is_In (Subject (Cursor + 1), Node.CS)
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
-- Any (string function case)
when PC_Any_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching Any", S (1 .. L));
if Cursor < Length
and then Is_In (Subject (Cursor + 1), S (1 .. L))
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
end;
-- Any (string pointer case)
when PC_Any_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching Any", S (1 .. L));
if Cursor < Length
and then Is_In (Subject (Cursor + 1), S (1 .. L))
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
end;
-- Arb (initial match)
when PC_Arb_X =>
Dout (Img (Node) & "matching Arb");
Push (Node.Alt);
Node := Node.Pthen;
goto Match;
-- Arb (extension)
when PC_Arb_Y =>
Dout (Img (Node) & "extending Arb");
if Cursor < Length then
Cursor := Cursor + 1;
Push (Node);
goto Succeed;
else
goto Fail;
end if;
-- Arbno_S (simple Arbno initialize). This is the node that
-- initiates the match of a simple Arbno structure.
when PC_Arbno_S =>
Dout (Img (Node) &
"setting up Arbno alternative " & Img (Node.Alt));
Push (Node.Alt);
Node := Node.Pthen;
goto Match;
-- Arbno_X (Arbno initialize). This is the node that initiates
-- the match of a complex Arbno structure.
when PC_Arbno_X =>
Dout (Img (Node) &
"setting up Arbno alternative " & Img (Node.Alt));
Push (Node.Alt);
Node := Node.Pthen;
goto Match;
-- Arbno_Y (Arbno rematch). This is the node that is executed
-- following successful matching of one instance of a complex
-- Arbno pattern.
when PC_Arbno_Y => declare
Null_Match : constant Boolean :=
Cursor = Stack (Stack_Base - 1).Cursor;
begin
Dout (Img (Node) & "extending Arbno");
Pop_Region;
-- If arbno extension matched null, then immediately fail
if Null_Match then
Dout ("Arbno extension matched null, so fails");
goto Fail;
end if;
-- Here we must do a stack check to make sure enough stack
-- is left. This check will happen once for each instance of
-- the Arbno pattern that is matched. The Nat field of a
-- PC_Arbno pattern contains the maximum stack entries needed
-- for the Arbno with one instance and the successor pattern
if Stack_Ptr + Node.Nat >= Stack'Last then
raise Pattern_Stack_Overflow;
end if;
goto Succeed;
end;
-- Assign. If this node is executed, it means the assign-on-match
-- or write-on-match operation will not happen after all, so we
-- is propagate the failure, removing the PC_Assign node.
when PC_Assign =>
Dout (Img (Node) & "deferred assign/write cancelled");
goto Fail;
-- Assign immediate. This node performs the actual assignment
when PC_Assign_Imm =>
Dout
(Img (Node) & "executing immediate assignment of " &
Image (Subject (Stack (Stack_Base - 1).Cursor + 1 .. Cursor)));
Set_Unbounded_String
(Node.VP.all,
Subject (Stack (Stack_Base - 1).Cursor + 1 .. Cursor));
Pop_Region;
goto Succeed;
-- Assign on match. This node sets up for the eventual assignment
when PC_Assign_OnM =>
Dout (Img (Node) & "registering deferred assignment");
Stack (Stack_Base - 1).Node := Node;
Push (CP_Assign'Access);
Pop_Region;
Assign_OnM := True;
goto Succeed;
-- Bal
when PC_Bal =>
Dout (Img (Node) & "matching or extending Bal");
if Cursor >= Length or else Subject (Cursor + 1) = ')' then
goto Fail;
elsif Subject (Cursor + 1) = '(' then
declare
Paren_Count : Natural := 1;
begin
loop
Cursor := Cursor + 1;
if Cursor >= Length then
goto Fail;
elsif Subject (Cursor + 1) = '(' then
Paren_Count := Paren_Count + 1;
elsif Subject (Cursor + 1) = ')' then
Paren_Count := Paren_Count - 1;
exit when Paren_Count = 0;
end if;
end loop;
end;
end if;
Cursor := Cursor + 1;
Push (Node);
goto Succeed;
-- Break (one character case)
when PC_Break_CH =>
Dout (Img (Node) & "matching Break", Node.Char);
while Cursor < Length loop
if Subject (Cursor + 1) = Node.Char then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
-- Break (character set case)
when PC_Break_CS =>
Dout (Img (Node) & "matching Break", Node.CS);
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), Node.CS) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
-- Break (string function case)
when PC_Break_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching Break", S (1 .. L));
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), S (1 .. L)) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
end;
-- Break (string pointer case)
when PC_Break_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching Break", S (1 .. L));
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), S (1 .. L)) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
end;
-- BreakX (one character case)
when PC_BreakX_CH =>
Dout (Img (Node) & "matching BreakX", Node.Char);
while Cursor < Length loop
if Subject (Cursor + 1) = Node.Char then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
-- BreakX (character set case)
when PC_BreakX_CS =>
Dout (Img (Node) & "matching BreakX", Node.CS);
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), Node.CS) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
-- BreakX (string function case)
when PC_BreakX_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching BreakX", S (1 .. L));
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), S (1 .. L)) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
end;
-- BreakX (string pointer case)
when PC_BreakX_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching BreakX", S (1 .. L));
while Cursor < Length loop
if Is_In (Subject (Cursor + 1), S (1 .. L)) then
goto Succeed;
else
Cursor := Cursor + 1;
end if;
end loop;
goto Fail;
end;
-- BreakX_X (BreakX extension). See section on "Compound Pattern
-- Structures". This node is the alternative that is stacked
-- to skip past the break character and extend the break.
when PC_BreakX_X =>
Dout (Img (Node) & "extending BreakX");
Cursor := Cursor + 1;
goto Succeed;
-- Character (one character string)
when PC_Char =>
Dout (Img (Node) & "matching '" & Node.Char & ''');
if Cursor < Length
and then Subject (Cursor + 1) = Node.Char
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
-- End of Pattern
when PC_EOP =>
if Stack_Base = Stack_Init then
Dout ("end of pattern");
goto Match_Succeed;
-- End of recursive inner match. See separate section on
-- handing of recursive pattern matches for details.
else
Dout ("terminating recursive match");
Node := Stack (Stack_Base - 1).Node;
Pop_Region;
goto Match;
end if;
-- Fail
when PC_Fail =>
Dout (Img (Node) & "matching Fail");
goto Fail;
-- Fence (built in pattern)
when PC_Fence =>
Dout (Img (Node) & "matching Fence");
Push (CP_Cancel'Access);
goto Succeed;
-- Fence function node X. This is the node that gets control
-- after a successful match of the fenced pattern.
when PC_Fence_X =>
Dout (Img (Node) & "matching Fence function");
Stack_Ptr := Stack_Ptr + 1;
Stack (Stack_Ptr).Cursor := Stack_Base;
Stack (Stack_Ptr).Node := CP_Fence_Y'Access;
Stack_Base := Stack (Stack_Base).Cursor;
Region_Level := Region_Level - 1;
goto Succeed;
-- Fence function node Y. This is the node that gets control on
-- a failure that occurs after the fenced pattern has matched.
-- Note: the Cursor at this stage is actually the inner stack
-- base value. We don't reset this, but we do use it to strip
-- off all the entries made by the fenced pattern.
when PC_Fence_Y =>
Dout (Img (Node) & "pattern matched by Fence caused failure");
Stack_Ptr := Cursor - 2;
goto Fail;
-- Len (integer case)
when PC_Len_Nat =>
Dout (Img (Node) & "matching Len", Node.Nat);
if Cursor + Node.Nat > Length then
goto Fail;
else
Cursor := Cursor + Node.Nat;
goto Succeed;
end if;
-- Len (Integer function case)
when PC_Len_NF => declare
N : constant Natural := Node.NF.all;
begin
Dout (Img (Node) & "matching Len", N);
if Cursor + N > Length then
goto Fail;
else
Cursor := Cursor + N;
goto Succeed;
end if;
end;
-- Len (integer pointer case)
when PC_Len_NP =>
Dout (Img (Node) & "matching Len", Node.NP.all);
if Cursor + Node.NP.all > Length then
goto Fail;
else
Cursor := Cursor + Node.NP.all;
goto Succeed;
end if;
-- NotAny (one character case)
when PC_NotAny_CH =>
Dout (Img (Node) & "matching NotAny", Node.Char);
if Cursor < Length
and then Subject (Cursor + 1) /= Node.Char
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
-- NotAny (character set case)
when PC_NotAny_CS =>
Dout (Img (Node) & "matching NotAny", Node.CS);
if Cursor < Length
and then not Is_In (Subject (Cursor + 1), Node.CS)
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
-- NotAny (string function case)
when PC_NotAny_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching NotAny", S (1 .. L));
if Cursor < Length
and then
not Is_In (Subject (Cursor + 1), S (1 .. L))
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
end;
-- NotAny (string pointer case)
when PC_NotAny_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching NotAny", S (1 .. L));
if Cursor < Length
and then
not Is_In (Subject (Cursor + 1), S (1 .. L))
then
Cursor := Cursor + 1;
goto Succeed;
else
goto Fail;
end if;
end;
-- NSpan (one character case)
when PC_NSpan_CH =>
Dout (Img (Node) & "matching NSpan", Node.Char);
while Cursor < Length
and then Subject (Cursor + 1) = Node.Char
loop
Cursor := Cursor + 1;
end loop;
goto Succeed;
-- NSpan (character set case)
when PC_NSpan_CS =>
Dout (Img (Node) & "matching NSpan", Node.CS);
while Cursor < Length
and then Is_In (Subject (Cursor + 1), Node.CS)
loop
Cursor := Cursor + 1;
end loop;
goto Succeed;
-- NSpan (string function case)
when PC_NSpan_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching NSpan", S (1 .. L));
while Cursor < Length
and then Is_In (Subject (Cursor + 1), S (1 .. L))
loop
Cursor := Cursor + 1;
end loop;
goto Succeed;
end;
-- NSpan (string pointer case)
when PC_NSpan_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching NSpan", S (1 .. L));
while Cursor < Length
and then Is_In (Subject (Cursor + 1), S (1 .. L))
loop
Cursor := Cursor + 1;
end loop;
goto Succeed;
end;
when PC_Null =>
Dout (Img (Node) & "matching null");
goto Succeed;
-- Pos (integer case)
when PC_Pos_Nat =>
Dout (Img (Node) & "matching Pos", Node.Nat);
if Cursor = Node.Nat then
goto Succeed;
else
goto Fail;
end if;
-- Pos (Integer function case)
when PC_Pos_NF => declare
N : constant Natural := Node.NF.all;
begin
Dout (Img (Node) & "matching Pos", N);
if Cursor = N then
goto Succeed;
else
goto Fail;
end if;
end;
-- Pos (integer pointer case)
when PC_Pos_NP =>
Dout (Img (Node) & "matching Pos", Node.NP.all);
if Cursor = Node.NP.all then
goto Succeed;
else
goto Fail;
end if;
-- Predicate function
when PC_Pred_Func =>
Dout (Img (Node) & "matching predicate function");
if Node.BF.all then
goto Succeed;
else
goto Fail;
end if;
-- Region Enter. Initiate new pattern history stack region
when PC_R_Enter =>
Dout (Img (Node) & "starting match of nested pattern");
Stack (Stack_Ptr + 1).Cursor := Cursor;
Push_Region;
goto Succeed;
-- Region Remove node. This is the node stacked by an R_Enter.
-- It removes the special format stack entry right underneath, and
-- then restores the outer level stack base and signals failure.
-- Note: the cursor value at this stage is actually the (negative)
-- stack base value for the outer level.
when PC_R_Remove =>
Dout ("failure, match of nested pattern terminated");
Stack_Base := Cursor;
Region_Level := Region_Level - 1;
Stack_Ptr := Stack_Ptr - 1;
goto Fail;
-- Region restore node. This is the node stacked at the end of an
-- inner level match. Its function is to restore the inner level
-- region, so that alternatives in this region can be sought.
-- Note: the Cursor at this stage is actually the negative of the
-- inner stack base value, which we use to restore the inner region.
when PC_R_Restore =>
Dout ("failure, search for alternatives in nested pattern");
Region_Level := Region_Level + 1;
Stack_Base := Cursor;
goto Fail;
-- Rest
when PC_Rest =>
Dout (Img (Node) & "matching Rest");
Cursor := Length;
goto Succeed;
-- Initiate recursive match (pattern pointer case)
when PC_Rpat =>
Stack (Stack_Ptr + 1).Node := Node.Pthen;
Push_Region;
Dout (Img (Node) & "initiating recursive match");
if Stack_Ptr + Node.PP.all.Stk >= Stack_Size then
raise Pattern_Stack_Overflow;
else
Node := Node.PP.all.P;
goto Match;
end if;
-- RPos (integer case)
when PC_RPos_Nat =>
Dout (Img (Node) & "matching RPos", Node.Nat);
if Cursor = (Length - Node.Nat) then
goto Succeed;
else
goto Fail;
end if;
-- RPos (integer function case)
when PC_RPos_NF => declare
N : constant Natural := Node.NF.all;
begin
Dout (Img (Node) & "matching RPos", N);
if Length - Cursor = N then
goto Succeed;
else
goto Fail;
end if;
end;
-- RPos (integer pointer case)
when PC_RPos_NP =>
Dout (Img (Node) & "matching RPos", Node.NP.all);
if Cursor = (Length - Node.NP.all) then
goto Succeed;
else
goto Fail;
end if;
-- RTab (integer case)
when PC_RTab_Nat =>
Dout (Img (Node) & "matching RTab", Node.Nat);
if Cursor <= (Length - Node.Nat) then
Cursor := Length - Node.Nat;
goto Succeed;
else
goto Fail;
end if;
-- RTab (integer function case)
when PC_RTab_NF => declare
N : constant Natural := Node.NF.all;
begin
Dout (Img (Node) & "matching RPos", N);
if Length - Cursor >= N then
Cursor := Length - N;
goto Succeed;
else
goto Fail;
end if;
end;
-- RTab (integer pointer case)
when PC_RTab_NP =>
Dout (Img (Node) & "matching RPos", Node.NP.all);
if Cursor <= (Length - Node.NP.all) then
Cursor := Length - Node.NP.all;
goto Succeed;
else
goto Fail;
end if;
-- Cursor assignment
when PC_Setcur =>
Dout (Img (Node) & "matching Setcur");
Node.Var.all := Cursor;
goto Succeed;
-- Span (one character case)
when PC_Span_CH => declare
P : Natural := Cursor;
begin
Dout (Img (Node) & "matching Span", Node.Char);
while P < Length
and then Subject (P + 1) = Node.Char
loop
P := P + 1;
end loop;
if P /= Cursor then
Cursor := P;
goto Succeed;
else
goto Fail;
end if;
end;
-- Span (character set case)
when PC_Span_CS => declare
P : Natural := Cursor;
begin
Dout (Img (Node) & "matching Span", Node.CS);
while P < Length
and then Is_In (Subject (P + 1), Node.CS)
loop
P := P + 1;
end loop;
if P /= Cursor then
Cursor := P;
goto Succeed;
else
goto Fail;
end if;
end;
-- Span (string function case)
when PC_Span_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
P : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching Span", S (1 .. L));
P := Cursor;
while P < Length
and then Is_In (Subject (P + 1), S (1 .. L))
loop
P := P + 1;
end loop;
if P /= Cursor then
Cursor := P;
goto Succeed;
else
goto Fail;
end if;
end;
-- Span (string pointer case)
when PC_Span_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
P : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching Span", S (1 .. L));
P := Cursor;
while P < Length
and then Is_In (Subject (P + 1), S (1 .. L))
loop
P := P + 1;
end loop;
if P /= Cursor then
Cursor := P;
goto Succeed;
else
goto Fail;
end if;
end;
-- String (two character case)
when PC_String_2 =>
Dout (Img (Node) & "matching " & Image (Node.Str2));
if (Length - Cursor) >= 2
and then Subject (Cursor + 1 .. Cursor + 2) = Node.Str2
then
Cursor := Cursor + 2;
goto Succeed;
else
goto Fail;
end if;
-- String (three character case)
when PC_String_3 =>
Dout (Img (Node) & "matching " & Image (Node.Str3));
if (Length - Cursor) >= 3
and then Subject (Cursor + 1 .. Cursor + 3) = Node.Str3
then
Cursor := Cursor + 3;
goto Succeed;
else
goto Fail;
end if;
-- String (four character case)
when PC_String_4 =>
Dout (Img (Node) & "matching " & Image (Node.Str4));
if (Length - Cursor) >= 4
and then Subject (Cursor + 1 .. Cursor + 4) = Node.Str4
then
Cursor := Cursor + 4;
goto Succeed;
else
goto Fail;
end if;
-- String (five character case)
when PC_String_5 =>
Dout (Img (Node) & "matching " & Image (Node.Str5));
if (Length - Cursor) >= 5
and then Subject (Cursor + 1 .. Cursor + 5) = Node.Str5
then
Cursor := Cursor + 5;
goto Succeed;
else
goto Fail;
end if;
-- String (six character case)
when PC_String_6 =>
Dout (Img (Node) & "matching " & Image (Node.Str6));
if (Length - Cursor) >= 6
and then Subject (Cursor + 1 .. Cursor + 6) = Node.Str6
then
Cursor := Cursor + 6;
goto Succeed;
else
goto Fail;
end if;
-- String (case of more than six characters)
when PC_String => declare
Len : constant Natural := Node.Str'Length;
begin
Dout (Img (Node) & "matching " & Image (Node.Str.all));
if (Length - Cursor) >= Len
and then Node.Str.all = Subject (Cursor + 1 .. Cursor + Len)
then
Cursor := Cursor + Len;
goto Succeed;
else
goto Fail;
end if;
end;
-- String (function case)
when PC_String_VF => declare
U : constant VString := Node.VF.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching " & Image (S (1 .. L)));
if (Length - Cursor) >= L
and then S (1 .. L) = Subject (Cursor + 1 .. Cursor + L)
then
Cursor := Cursor + L;
goto Succeed;
else
goto Fail;
end if;
end;
-- String (vstring pointer case)
when PC_String_VP => declare
U : constant VString := Node.VP.all;
S : Big_String_Access;
L : Natural;
begin
Get_String (U, S, L);
Dout (Img (Node) & "matching " & Image (S (1 .. L)));
if (Length - Cursor) >= L
and then S (1 .. L) = Subject (Cursor + 1 .. Cursor + L)
then
Cursor := Cursor + L;
goto Succeed;
else
goto Fail;
end if;
end;
-- Succeed
when PC_Succeed =>
Dout (Img (Node) & "matching Succeed");
Push (Node);
goto Succeed;
-- Tab (integer case)
when PC_Tab_Nat =>
Dout (Img (Node) & "matching Tab", Node.Nat);
if Cursor <= Node.Nat then
Cursor := Node.Nat;
goto Succeed;
else
goto Fail;
end if;
-- Tab (integer function case)
when PC_Tab_NF => declare
N : constant Natural := Node.NF.all;
begin
Dout (Img (Node) & "matching Tab ", N);
if Cursor <= N then
Cursor := N;
goto Succeed;
else
goto Fail;
end if;
end;
-- Tab (integer pointer case)
when PC_Tab_NP =>
Dout (Img (Node) & "matching Tab ", Node.NP.all);
if Cursor <= Node.NP.all then
Cursor := Node.NP.all;
goto Succeed;
else
goto Fail;
end if;
-- Unanchored movement
when PC_Unanchored =>
Dout ("attempting to move anchor point");
-- All done if we tried every position
if Cursor > Length then
goto Match_Fail;
-- Otherwise extend the anchor point, and restack ourself
else
Cursor := Cursor + 1;
Push (Node);
goto Succeed;
end if;
-- Write immediate. This node performs the actual write
when PC_Write_Imm =>
Dout (Img (Node) & "executing immediate write of " &
Subject (Stack (Stack_Base - 1).Cursor + 1 .. Cursor));
Put_Line
(Node.FP.all,
Subject (Stack (Stack_Base - 1).Cursor + 1 .. Cursor));
Pop_Region;
goto Succeed;
-- Write on match. This node sets up for the eventual write
when PC_Write_OnM =>
Dout (Img (Node) & "registering deferred write");
Stack (Stack_Base - 1).Node := Node;
Push (CP_Assign'Access);
Pop_Region;
Assign_OnM := True;
goto Succeed;
end case;
-- We are NOT allowed to fall though this case statement, since every
-- match routine must end by executing a goto to the appropriate point
-- in the finite state machine model.
pragma Warnings (Off);
Logic_Error;
pragma Warnings (On);
end XMatchD;
end GNAT.Spitbol.Patterns;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.