content
stringlengths 23
1.05M
|
|---|
-- { dg-do run }
-- { dg-options "-gnatws" }
procedure Alignment13 is
type Rec is record
I1 : aliased Short_Integer;
I2 : Integer;
end record;
for Rec use record
I1 at 0 range 0 .. 15;
end record;
R : Rec;
begin
if R.I2'Bit_Position /= 32 then
raise Program_Error;
end if;
end;
|
package GESTE_Fonts.FreeMonoOblique5pt7b is
Font : constant Bitmap_Font_Ref;
private
FreeMonoOblique5pt7bBitmaps : aliased constant Font_Bitmap := (
16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#04#, 16#08#, 16#10#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#8A#, 16#14#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#0F#, 16#18#, 16#78#, 16#60#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#89#, 16#1C#, 16#48#, 16#F0#,
16#00#, 16#00#, 16#00#, 16#01#, 16#05#, 16#0C#, 16#02#, 16#38#, 16#50#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#08#, 16#10#, 16#68#, 16#A0#,
16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#04#, 16#08#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#82#, 16#08#, 16#10#, 16#20#,
16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#04#, 16#08#, 16#10#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0D#, 16#0C#, 16#08#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#3E#, 16#10#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3E#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#82#, 16#08#, 16#10#, 16#40#,
16#00#, 16#00#, 16#00#, 16#01#, 16#84#, 16#89#, 16#12#, 16#28#, 16#50#,
16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#0C#, 16#08#, 16#10#, 16#40#,
16#00#, 16#00#, 16#00#, 16#01#, 16#84#, 16#81#, 16#04#, 16#30#, 16#80#,
16#00#, 16#00#, 16#00#, 16#01#, 16#80#, 16#81#, 16#0C#, 16#08#, 16#10#,
16#00#, 16#00#, 16#00#, 16#00#, 16#83#, 16#06#, 16#14#, 16#48#, 16#F0#,
16#00#, 16#00#, 16#00#, 16#01#, 16#C4#, 16#08#, 16#1C#, 16#08#, 16#10#,
16#00#, 16#00#, 16#00#, 16#00#, 16#C2#, 16#08#, 16#1C#, 16#24#, 16#50#,
16#00#, 16#00#, 16#00#, 16#03#, 16#C4#, 16#82#, 16#04#, 16#10#, 16#20#,
16#00#, 16#00#, 16#00#, 16#01#, 16#84#, 16#89#, 16#0C#, 16#68#, 16#90#,
16#00#, 16#00#, 16#00#, 16#01#, 16#84#, 16#89#, 16#12#, 16#1C#, 16#10#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#08#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#08#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#0C#, 16#20#, 16#20#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3E#, 16#7C#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#08#, 16#0C#, 16#08#, 16#60#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#81#, 16#0C#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#01#, 16#84#, 16#93#, 16#2C#, 16#68#, 16#B0#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#06#, 16#14#, 16#28#, 16#F0#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#89#, 16#1C#, 16#44#, 16#88#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#09#, 16#20#, 16#40#, 16#80#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#11#, 16#22#, 16#44#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#88#, 16#18#, 16#40#, 16#80#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#88#, 16#18#, 16#40#, 16#80#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#09#, 16#20#, 16#4C#, 16#88#,
16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#89#, 16#1E#, 16#48#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#84#, 16#08#, 16#10#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#C1#, 16#04#, 16#08#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#CA#, 16#28#, 16#68#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#08#, 16#10#, 16#20#, 16#88#,
16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#C9#, 16#36#, 16#75#, 16#08#,
16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#D9#, 16#2A#, 16#54#, 16#B0#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#09#, 16#22#, 16#44#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#09#, 16#22#, 16#38#, 16#80#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#09#, 16#22#, 16#44#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#09#, 16#22#, 16#38#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#09#, 16#18#, 16#08#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#84#, 16#08#, 16#10#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#D1#, 16#22#, 16#44#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#D1#, 16#24#, 16#28#, 16#60#,
16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#D1#, 16#2A#, 16#74#, 16#F0#,
16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#C9#, 16#0C#, 16#30#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#C9#, 16#14#, 16#10#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#8A#, 16#08#, 16#20#, 16#80#,
16#00#, 16#00#, 16#00#, 16#00#, 16#C2#, 16#04#, 16#08#, 16#10#, 16#20#,
16#00#, 16#00#, 16#00#, 16#01#, 16#02#, 16#04#, 16#08#, 16#10#, 16#20#,
16#00#, 16#00#, 16#00#, 16#01#, 16#02#, 16#04#, 16#08#, 16#10#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#87#, 16#09#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1C#, 16#38#, 16#90#,
16#00#, 16#00#, 16#00#, 16#06#, 16#08#, 16#10#, 16#1C#, 16#44#, 16#88#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1C#, 16#44#, 16#80#,
16#00#, 16#00#, 16#00#, 16#00#, 16#40#, 16#81#, 16#1E#, 16#48#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1C#, 16#7C#, 16#80#,
16#00#, 16#00#, 16#00#, 16#00#, 16#E2#, 16#04#, 16#1E#, 16#20#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1E#, 16#48#, 16#90#,
16#00#, 16#00#, 16#00#, 16#02#, 16#04#, 16#10#, 16#3C#, 16#48#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#18#, 16#10#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#00#, 16#1C#, 16#08#, 16#10#,
16#00#, 16#00#, 16#00#, 16#02#, 16#04#, 16#08#, 16#26#, 16#30#, 16#A0#,
16#00#, 16#00#, 16#00#, 16#01#, 16#02#, 16#04#, 16#08#, 16#10#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3E#, 16#55#, 16#48#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1C#, 16#48#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1C#, 16#44#, 16#88#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3C#, 16#44#, 16#88#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1F#, 16#44#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#16#, 16#30#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1E#, 16#40#, 16#F0#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#08#, 16#3C#, 16#20#, 16#80#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#26#, 16#48#, 16#90#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#37#, 16#48#, 16#50#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#33#, 16#54#, 16#F0#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#16#, 16#28#, 16#70#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#32#, 16#48#, 16#50#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1E#, 16#10#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#82#, 16#04#, 16#08#, 16#30#, 16#20#,
16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#04#, 16#08#, 16#10#, 16#20#,
16#00#, 16#00#, 16#00#, 16#01#, 16#02#, 16#04#, 16#08#, 16#08#, 16#20#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#12#, 16#18#, 16#00#);
Font_D : aliased constant Bitmap_Font :=
(
Bytes_Per_Glyph => 9,
Glyph_Width => 7,
Glyph_Height => 10,
Data => FreeMonoOblique5pt7bBitmaps'Access);
Font : constant Bitmap_Font_Ref := Font_D'Access;
end GESTE_Fonts.FreeMonoOblique5pt7b;
|
with Memory;
package Intcode.Op is
type Code is (
Add,
Mul,
Get,
Put,
Jnz,
Jz,
Lt,
Eq,
Mrb,
Halt
);
type Parameter_Mode is (Position, Immediate, Relative);
type Parameter_List is array (Positive range <>) of Parameter_Mode;
type Schema(Num_Params: Natural) is record
Instruction: Code;
Params: Parameter_List(1 .. Num_Params);
end record;
function Decode(V: Memory.Value) return Schema;
end Intcode.Op;
|
--------------------------------------------------------------------------------------------------------------------
-- Copyright (c) 2013-2020, Luke A. Guest
--
-- This software is provided 'as-is', without any express or implied
-- warranty. In no event will the authors be held liable for any damages
-- arising from the use of this software.
--
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely, subject to the following restrictions:
--
-- 1. The origin of this software must not be misrepresented; you must not
-- claim that you wrote the original software. If you use this software
-- in a product, an acknowledgment in the product documentation would be
-- appreciated but is not required.
--
-- 2. Altered source versions must be plainly marked as such, and must not be
-- misrepresented as being the original software.
--
-- 3. This notice may not be removed or altered from any source
-- distribution.
--------------------------------------------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
with Interfaces;
with Interfaces.C;
with Interfaces.C.Strings;
with SDL.Error;
-- with SDL.Video.Surfaces.Makers;
-- with SDL.Log;
package body SDL.Video.Windows is
package C renames Interfaces.C;
use type Interfaces.Unsigned_32;
use type C.int;
use type SDL.C_Pointers.Windows_Pointer;
use type System.Address;
function Undefined_Window_Position
(Display : Natural := 0) return SDL.Natural_Coordinate
is
Mask : constant Interfaces.Unsigned_32 := 16#1FFF_0000#;
begin
return C.int (Interfaces.Unsigned_32 (Display) or Mask);
end Undefined_Window_Position;
function Centered_Window_Position
(Display : Natural := 0) return SDL.Natural_Coordinate
is
Mask : constant Interfaces.Unsigned_32 := 16#2FFF_0000#;
begin
return C.int (Interfaces.Unsigned_32 (Display) or Mask);
end Centered_Window_Position;
procedure Increment_Windows is
begin
Total_Windows_Created := Total_Windows_Created + 1;
end Increment_Windows;
procedure Decrement_Windows is
begin
Total_Windows_Created := Total_Windows_Created - 1;
end Decrement_Windows;
overriding
procedure Finalize (Self : in out Window) is
procedure SDL_Destroy (W : in SDL.C_Pointers.Windows_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_DestroyWindow";
begin
-- SDL.Log.Put_Debug ("Windows.Finalize: " & (if Self.Internal = null then "null" else "not null") &
-- " " & (if Self.Owns = True then "owns" else "Doesn't own"));
-- Make sure we don't delete this twice!
if Self.Internal /= null and then Self.Owns then
-- SDL.Log.Put_Debug ("Windows.Finalize: Deleting");
SDL_Destroy (Self.Internal);
Self.Internal := null;
Decrement_Windows;
end if;
end Finalize;
function Get_Brightness (Self : in Window) return Brightness is
function SDL_Get_Brightness (W : in SDL.C_Pointers.Windows_Pointer) return C.C_float with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowBrightness";
begin
return Brightness (SDL_Get_Brightness (Self.Internal));
end Get_Brightness;
procedure Set_Brightness (Self : in out Window; How_Bright : in Brightness) is
function SDL_Set_Brightness (W : in SDL.C_Pointers.Windows_Pointer; B : in C.C_float) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowBrightness";
Result : C.int := SDL_Set_Brightness (Self.Internal, C.C_float (How_Bright));
begin
if Result /= Success then
raise Window_Error with SDL.Error.Get;
end if;
end Set_Brightness;
-- TODO: Try to see if we can just see User_Data_Access as the return type from the C function.
function To_Data_Access is new Ada.Unchecked_Conversion (Source => System.Address, Target => User_Data_Access);
function To_Address is new Ada.Unchecked_Conversion (Source => User_Data_Access, Target => System.Address);
-- TODO: Make this and Set_Data generic.
function Get_Data (Self : in Window; Name : in String) return User_Data_Access is
function SDL_Get_Window_Data (W : in SDL.C_Pointers.Windows_Pointer;
Name : in C.Strings.chars_ptr) return System.Address with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowData";
C_Name_Str : C.Strings.chars_ptr := C.Strings.New_String (Name);
Item : User_Data_Access := To_Data_Access (SDL_Get_Window_Data (Self.Internal, C_Name_Str));
begin
C.Strings.Free (C_Name_Str);
return Item;
end Get_Data;
function Set_Data (Self : in out Window; Name : in String; Item : in User_Data_Access) return User_Data_Access is
function SDL_Set_Window_Data (W : in SDL.C_Pointers.Windows_Pointer;
Name : in C.Strings.chars_ptr;
User_Data : in System.Address) return System.Address with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowData";
C_Name_Str : C.Strings.chars_ptr := C.Strings.New_String (Name);
Previous_Data : User_Data_Access := To_Data_Access (SDL_Set_Window_Data (Self.Internal,
C_Name_Str,
To_Address (Item)));
begin
C.Strings.Free (C_Name_Str);
return Previous_Data;
end Set_Data;
function Display_Index (Self : in Window) return SDL.Video.Displays.Display_Indices is
function SDL_Get_Window_Display_Index (W : in SDL.C_Pointers.Windows_Pointer) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowDisplayIndex";
Total : C.int := SDL_Get_Window_Display_Index (Self.Internal);
begin
if Total < 0 then
raise Window_Error with SDL.Error.Get;
end if;
return SDL.Video.Displays.Display_Indices (Total + 1);
end Display_Index;
procedure Get_Display_Mode (Self : in Window; Mode : out SDL.Video.Displays.Mode) is
function SDL_Get_Window_Display_Mode (W : in SDL.C_Pointers.Windows_Pointer;
M : out SDL.Video.Displays.Mode) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowDisplayMode";
Result : C.int := SDL_Get_Window_Display_Mode (Self.Internal, Mode);
begin
if Result /= Success then
raise Window_Error with SDL.Error.Get;
end if;
end Get_Display_Mode;
procedure Set_Display_Mode (Self : in out Window; Mode : in SDL.Video.Displays.Mode) is
function SDL_Set_Window_Display_Mode (W : in SDL.C_Pointers.Windows_Pointer;
M : in SDL.Video.Displays.Mode) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowDisplayMode";
Result : C.int := SDL_Set_Window_Display_Mode (Self.Internal, Mode);
begin
if Result /= Success then
raise Window_Error with SDL.Error.Get;
end if;
end Set_Display_Mode;
function Get_Flags (Self : in Window) return Window_Flags is
function SDL_Get_Window_Flags (W : in SDL.C_Pointers.Windows_Pointer) return Window_Flags with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowFlags";
begin
return SDL_Get_Window_Flags (Self.Internal);
end Get_Flags;
function From_ID (Window_ID : in ID) return Window is
function SDL_Get_Window_From_ID (W : in ID) return SDL.C_Pointers.Windows_Pointer with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowFromID";
begin
return W : constant Window :=
(Ada.Finalization.Limited_Controlled with Internal => SDL_Get_Window_From_ID (Window_ID), Owns => False)
do
null;
end return;
end From_ID;
procedure Get_Gamma_Ramp (Self : in Window; Red, Green, Blue : out SDL.Video.Pixel_Formats.Gamma_Ramp) is
function SDL_Get_Window_Gamma_Ramp (W : in SDL.C_Pointers.Windows_Pointer;
R, G, B : out SDL.Video.Pixel_Formats.Gamma_Ramp) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowGammaRamp";
Result : C.int := SDL_Get_Window_Gamma_Ramp (Self.Internal, Red, Green, Blue);
begin
if Result /= Success then
raise Window_Error with SDL.Error.Get;
end if;
end Get_Gamma_Ramp;
procedure Set_Gamma_Ramp (Self : in out Window; Red, Green, Blue : in SDL.Video.Pixel_Formats.Gamma_Ramp) is
function SDL_Set_Window_Gamma_Ramp (W : in SDL.C_Pointers.Windows_Pointer;
R, G, B : in SDL.Video.Pixel_Formats.Gamma_Ramp) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowGammaRamp";
Result : C.int := SDL_Set_Window_Gamma_Ramp (Self.Internal, Red, Green, Blue);
begin
if Result /= Success then
raise Window_Error with SDL.Error.Get;
end if;
end Set_Gamma_Ramp;
function Is_Grabbed (Self : in Window) return Boolean is
function SDL_Get_Window_Grab (W : in SDL.C_Pointers.Windows_Pointer) return SDL_Bool with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowGrab";
begin
return (SDL_Get_Window_Grab (Self.Internal) = SDL_True);
end Is_Grabbed;
procedure Set_Grabbed (Self : in out Window; Grabbed : in Boolean := True) is
procedure SDL_Set_Window_Grab (W : in SDL.C_Pointers.Windows_Pointer; G : in SDL_Bool) with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowGrab";
begin
SDL_Set_Window_Grab (Self.Internal, (if Grabbed = True then SDL_True else SDL_False));
end Set_Grabbed;
function Get_ID (Self : in Window) return ID is
function SDL_Get_Window_ID (W : in SDL.C_Pointers.Windows_Pointer) return ID with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowID";
begin
return SDL_Get_Window_ID (Self.Internal);
end Get_ID;
function Get_Maximum_Size (Self : in Window) return SDL.Sizes is
procedure SDL_Get_Window_Maximum_Size (Win : in SDL.C_Pointers.Windows_Pointer;
W, H : out SDL.Dimension) with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowMaximumSize";
W, H : C.int := 0;
begin
SDL_Get_Window_Maximum_Size (Self.Internal, W, H);
return SDL.Sizes'(Width => W, Height => H);
end Get_Maximum_Size;
procedure Set_Maximum_Size (Self : in out Window; Size : in SDL.Sizes) is
procedure SDL_Get_Window_Maximum_Size (Win : in SDL.C_Pointers.Windows_Pointer; W, H : in C.int) with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowMaximumSize";
begin
SDL_Get_Window_Maximum_Size (Self.Internal, C.int (Size.Width), C.int (Size.Height));
end Set_Maximum_Size;
function Get_Minimum_Size (Self : in Window) return SDL.Sizes is
procedure SDL_Get_Window_Minimum_Size (Win : in SDL.C_Pointers.Windows_Pointer;
W, H : out SDL.Dimension) with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowMinimumSize";
W, H : C.int := 0;
begin
SDL_Get_Window_Minimum_Size (Self.Internal, W, H);
return SDL.Sizes'(Width => W, Height => H);
end Get_Minimum_Size;
procedure Set_Minimum_Size (Self : in out Window; Size : in SDL.Sizes) is
procedure SDL_Get_Window_Minimum_Size (Win : in SDL.C_Pointers.Windows_Pointer; W, H : in C.int) with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowMinimumSize";
begin
SDL_Get_Window_Minimum_Size (Self.Internal, C.int (Size.Width), C.int (Size.Height));
end Set_Minimum_Size;
function Pixel_Format (Self : in Window) return SDL.Video.Pixel_Formats.Pixel_Format is
function SDL_Get_Window_Pixel_Format (W : in SDL.C_Pointers.Windows_Pointer)
return SDL.Video.Pixel_Formats.Pixel_Format with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowPixelFormat";
begin
return SDL_Get_Window_Pixel_Format (Self.Internal);
end Pixel_Format;
function Get_Position (Self : in Window) return SDL.Natural_Coordinates is
procedure SDL_Get_Window_Position (W : in SDL.C_Pointers.Windows_Pointer; X, Y : out C.int) with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowPosition";
Position : SDL.Natural_Coordinates := SDL.Zero_Coordinate;
begin
SDL_Get_Window_Position (Self.Internal, Position.X, Position.Y);
return Position;
end Get_Position;
procedure Set_Position (Self : in out Window; Position : SDL.Natural_Coordinates) is
procedure SDL_Set_Window_Position (W : in SDL.C_Pointers.Windows_Pointer; X, Y : in C.int) with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowPosition";
begin
SDL_Set_Window_Position (Self.Internal, Position.X, Position.Y);
end Set_Position;
function Get_Size (Self : in Window) return SDL.Sizes is
procedure SDL_Get_Window_Size (Win : in SDL.C_Pointers.Windows_Pointer; W, H : out SDL.Dimension) with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowSize";
W, H : C.int := 0;
begin
SDL_Get_Window_Size (Self.Internal, W, H);
return SDL.Sizes'(Width => W, Height => H);
end Get_Size;
procedure Set_Size (Self : in out Window; Size : in SDL.Sizes) is
procedure SDL_Get_Window_Size (Win : in SDL.C_Pointers.Windows_Pointer; W, H : in C.int) with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowSize";
begin
SDL_Get_Window_Size (Self.Internal, C.int (Size.Width), C.int (Size.Height));
end Set_Size;
function Get_Surface (Self : in Window) return SDL.Video.Surfaces.Surface is
function SDL_Get_Window_Surface (W : in SDL.C_Pointers.Windows_Pointer)
return SDL.Video.Surfaces.Internal_Surface_Pointer with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowSurface";
use type SDL.Video.Surfaces.Internal_Surface_Pointer;
S : SDL.Video.Surfaces.Internal_Surface_Pointer := SDL_Get_Window_Surface (Self.Internal);
function Make_Surface_From_Pointer (S : in SDL.Video.Surfaces.Internal_Surface_Pointer)
return SDL.Video.Surfaces.Surface with
Convention => Ada,
Import => True;
begin
if S = null then
raise Window_Error with SDL.Error.Get;
end if;
return Make_Surface_From_Pointer (S);
end Get_Surface;
function Get_Title (Self : in Window) return Ada.Strings.UTF_Encoding.UTF_8_String is
function SDL_Get_Window_Title (W : in SDL.C_Pointers.Windows_Pointer) return C.Strings.chars_ptr with
Import => True,
Convention => C,
External_Name => "SDL_GetWindowTitle";
begin
return C.Strings.Value (SDL_Get_Window_Title (Self.Internal));
end Get_Title;
procedure Set_Title (Self : in Window; Title : in Ada.Strings.UTF_Encoding.UTF_8_String) is
procedure SDL_Set_Window_Title (W : in SDL.C_Pointers.Windows_Pointer; C_Str : in C.char_array) with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowTitle";
begin
SDL_Set_Window_Title (Self.Internal, C.To_C (Title));
end Set_Title;
procedure Hide (Self : in Window) is
procedure SDL_Hide_Window (W : in SDL.C_Pointers.Windows_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_HideWindow";
begin
SDL_Hide_Window (Self.Internal);
end Hide;
procedure Show (Self : in Window) is
procedure SDL_Show_Window (W : in SDL.C_Pointers.Windows_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_ShowWindow";
begin
SDL_Show_Window (Self.Internal);
end Show;
procedure Maximise (Self : in Window) is
procedure SDL_Maximise_Window (W : in SDL.C_Pointers.Windows_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_MaximizeWindow";
begin
SDL_Maximise_Window (Self.Internal);
end Maximise;
procedure Minimise (Self : in Window) is
procedure SDL_Minimise_Window (W : in SDL.C_Pointers.Windows_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_MinimizeWindow";
begin
SDL_Minimise_Window (Self.Internal);
end Minimise;
procedure Raise_And_Focus (Self : in Window) is
procedure SDL_Raise_Window (W : in SDL.C_Pointers.Windows_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_RaiseWindow";
begin
SDL_Raise_Window (Self.Internal);
end Raise_And_Focus;
procedure Restore (Self : in Window) is
procedure SDL_Restore_Window (W : in SDL.C_Pointers.Windows_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_RestoreWindow";
begin
SDL_Restore_Window (Self.Internal);
end Restore;
procedure Set_Mode (Self : in out Window; Flags : in Full_Screen_Flags) is
function SDL_Window_Full_Screen (W : in SDL.C_Pointers.Windows_Pointer;
F : in Full_Screen_Flags) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowFullscreen";
Result : C.int := SDL_Window_Full_Screen (Self.Internal, Flags);
begin
if Result /= Success then
raise Window_Error with SDL.Error.Get;
end if;
end Set_Mode;
procedure Set_Icon (Self : in out Window; Icon : in SDL.Video.Surfaces.Surface) is
procedure SDL_Set_Window_Icon (W : in SDL.C_Pointers.Windows_Pointer;
S : SDL.Video.Surfaces.Internal_Surface_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_SetWindowIcon";
function Get_Internal_Surface (Self : in SDL.Video.Surfaces.Surface)
return SDL.Video.Surfaces.Internal_Surface_Pointer with
Import => True,
Convention => Ada;
begin
SDL_Set_Window_Icon (Self.Internal, Get_Internal_Surface (Icon));
end Set_Icon;
procedure Update_Surface (Self : in Window) is
function SDL_Update_Window_Surface (W : in SDL.C_Pointers.Windows_Pointer) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_UpdateWindowSurface";
Result : C.int := SDL_Update_Window_Surface (Self.Internal);
begin
if Result /= Success then
raise Window_Error with SDL.Error.Get;
end if;
end Update_Surface;
procedure Update_Surface_Rectangle (Self : in Window; Rectangle : in SDL.Video.Rectangles.Rectangle) is
function SDL_Update_Window_Surface_Rects (W : in SDL.C_Pointers.Windows_Pointer;
R : in SDL.Video.Rectangles.Rectangle;
L : in C.int) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_UpdateWindowSurfaceRects";
Result : C.int := SDL_Update_Window_Surface_Rects (Self.Internal, Rectangle, 1);
begin
if Result /= Success then
raise Window_Error with SDL.Error.Get;
end if;
end Update_Surface_Rectangle;
procedure Update_Surface_Rectangles (Self : in Window; Rectangles : SDL.Video.Rectangles.Rectangle_Arrays) is
function SDL_Update_Window_Surface_Rects (W : in SDL.C_Pointers.Windows_Pointer;
R : in SDL.Video.Rectangles.Rectangle_Arrays;
L : in C.int) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_UpdateWindowSurfaceRects";
Result : C.int := SDL_Update_Window_Surface_Rects (Self.Internal, Rectangles, Rectangles'Length);
begin
if Result /= Success then
raise Window_Error with SDL.Error.Get;
end if;
end Update_Surface_Rectangles;
function Exist return Boolean is
begin
return Total_Windows_Created /= Natural'First;
end Exist;
function Get_Internal_Window (Self : in Window) return SDL.C_Pointers.Windows_Pointer is
begin
return Self.Internal;
end Get_Internal_Window;
end SDL.Video.Windows;
|
with Ada.Text_IO,Ada.Numerics.Discrete_Random,Ada.Calendar;
use Ada.Text_IO;
procedure Market is
subtype Index is Positive range 1..10;
package randomPos is new Ada.Numerics.Discrete_Random(Index);
infected_count : Natural := 0;
type Position is record
x: Natural;
y: Natural;
end record;
type Direction is (left,right,up,down);
package randomDir is new Ada.Numerics.Discrete_Random(Direction);
protected Generator is
procedure Init;
function GetRandPos return Position;
function GetRandDir return Direction;
private
k:randomPos.Generator;
l:randomDir.Generator;
end Generator;
protected body Generator is
procedure Init is
begin
randomPos.Reset(k);
randomDir.Reset(l);
end Init;
function GetRandPos return Position is
x:Index;
y:Index;
begin
x:=randomPos.Random(k);
y:=randomPos.Random(k);
return (x,y);
end GetRandPos;
function GetRandDir return Direction is
begin
return randomDir.Random(l);
end GetRandDir;
end Generator;
protected Monitor is
procedure Print(s:String);
end Monitor;
protected body Monitor is
procedure Print(s:String) is
begin
Put_Line(s);
end Print;
end Monitor;
type Barr is array (Natural range <>,Natural range <>) of Boolean;
protected Area is
procedure Init;
function inArea(pos:Position) return Boolean;
procedure infectCell(pos:Position);
function isInfected(pos:Position) return Boolean;
function getInfectedPerc return Natural;
private
a : Barr(1..10,1..10);
end Area;
protected body Area is
procedure Init is
begin
for i in 1..10 loop
for j in 1..10 loop
a(i,j):=False; --no covid at first
end loop;
end loop;
end Init;
procedure infectCell(pos:Position) is
begin
a(pos.x,pos.y):=True;
end infectCell;
function isInfected(pos:Position) return Boolean is
begin
return a(pos.x,pos.y);
end isInfected;
function inArea(pos:Position) return Boolean is
begin
if (pos.x>=1 and then pos.x<=10 and then
pos.y>=1 and then pos.y<=10)
then
return True;
else
return False;
end if;
end inArea;
function getInfectedPerc return Natural is
cnt : Natural:=0;
begin
for i in 1..10 loop
for j in 1..10 loop
if a(i,j) then
cnt:=cnt+1;
end if;
end loop;
end loop;
return cnt;
end getInfectedPerc;
end Area;
type Pstr is access String;
task type Customer(name : Pstr ; is_infected : Boolean);
task Organizer is
entry Create;
end Organizer;
task body Customer is
pos:Position:=Generator.GetRandPos;
movement:Natural:=0;
is_sick : Boolean := is_infected;
procedure move is
tmp:Position;
dir:Direction;
begin
loop
tmp:=pos;
dir:=Generator.GetRandDir;
case dir is
when left => tmp.x:=pos.x-1;
when right => tmp.x:=pos.x+1;
when up => tmp.y:=pos.y-1;
when down => tmp.y:=pos.y+1;
end case;
exit when Area.inArea(tmp);
end loop;
pos:=tmp;
end move;
begin
while movement<4 loop
--if not Organizer'Callable then
-- exit;
--end if;
--Monitor.Print("Current position : " & pos.x'Image & " , "& pos.y'Image);
if is_sick then
Area.infectCell(pos);
--Monitor.Print("One more cell infected");
end if;
if Area.isInfected(pos) then
is_sick := True;
end if;
movement:=movement+1;
delay 0.5;
move;
end loop;
if is_sick then
Monitor.Print(name.all &" named customer has infected");
infected_count := infected_count + 1;
end if;
if Organizer'Callable then
Monitor.Print( name.all &" named customer finished"); -- this means 4 movements so 2 mins done
Organizer.Create;
end if;
end Customer;
type CustomerPtr is access Customer;
task body Organizer is
start : Ada.Calendar.Time;
a,b,c,d,e,tmp: CustomerPtr;
total_customers : Natural := 5;
begin
Generator.Init;
Area.Init;
a:=new Customer(new String'("c1"),True);
b:=new Customer(new String'("c2"),True);
c:=new Customer(new String'("c3"),True);
d:=new Customer(new String'("c4"),True);
e:=new Customer(new String'("c5"),True);
start:=Ada.Calendar.Clock;
loop
if Ada.Calendar."-"( Ada.Calendar.Clock, start ) >=60.0 then
exit;
end if;
select
accept Create do
tmp:=new Customer(new String'("cus "& total_customers'Image),False);
Monitor.Print("Created new customer");
total_customers := total_customers + 1;
end Create;
end select;
end loop;
Monitor.Print("Percentage of territory is infected : " & Area.getInfectedPerc'Image);
--Monitor.Print("Infected customers : " & infected_count'Image);
--Monitor.Print("Total customers : " & total_customers'Image);
Monitor.Print("Out of "& total_customers'Image &" customers, "& infected_count'Image & " got infected.");
--exit;
end Organizer;
begin
-- Insert code here.
null;
end Market;
|
with System; use System;
with STM32.Device; use STM32.Device;
with STM32.GPIO; use STM32.GPIO;
with STM32.EXTI; use STM32.EXTI;
with STM32.Timers; use STM32.Timers;
with STM32.ADC; use STM32.ADC;
with Ada.Interrupts.Names; use Ada.Interrupts.Names;
with Ada.Real_Time; use Ada.Real_Time;
package STM_Board is
---------------
-- Constants --
---------------
subtype Frequency_Hz is Float;
---------------------
-- PWM Full-bridge --
---------------------
PWM_Timer : Timer renames Timer_1;
-- Timer for reading sine table values.
PWM_Interrupt : Ada.Interrupts.Interrupt_ID renames TIM1_UP_Interrupt;
PWM_ISR_Priority : constant Interrupt_Priority := Interrupt_Priority'Last - 3;
PWM_A_Channel : Timer_Channel renames Channel_1;
PWM_A_H_Pin : GPIO_Point renames PA8;
PWM_A_L_Pin : GPIO_Point renames PA7;
PWM_A_GPIO_AF : STM32.GPIO_Alternate_Function renames GPIO_AF_TIM1_1;
PWM_B_Channel : Timer_Channel renames Channel_3; -- because Channel 2 has two LEDs
PWM_B_H_Pin : GPIO_Point renames PA10;
PWM_B_L_Pin : GPIO_Point renames PB1;
PWM_B_GPIO_AF : STM32.GPIO_Alternate_Function renames GPIO_AF_TIM1_1;
PWM_Gate_Power : GPIO_Point renames PA11;
-- Output for the FET/IGBT gate drivers.
------------------------------
-- Voltage and Current ADCs --
------------------------------
Sensor_ADC : constant access Analog_To_Digital_Converter := ADC_1'Access;
Sensor_Trigger_Event : External_Events_Regular_Group := Timer6_TRGO_Event;
Sensor_Interrupt : Ada.Interrupts.Interrupt_ID renames ADC1_2_Interrupt;
Sensor_ISR_Priority : constant Interrupt_Priority := Interrupt_Priority'Last - 2;
ADC_Battery_V_Point : constant ADC_Point := (Sensor_ADC, Channel => 10);
ADC_Battery_V_Pin : GPIO_Point renames PC0;
ADC_Battery_I_Point : constant ADC_Point := (Sensor_ADC, Channel => 11);
ADC_Battery_I_Pin : GPIO_Point renames PC1;
ADC_Output_V_Point : constant ADC_Point := (Sensor_ADC, Channel => 12);
ADC_Output_V_Pin : GPIO_Point renames PC2;
---------------
-- ADC Timer --
---------------
-- To syncronize A/D conversion and timers, the ADCs could be triggered
-- by any of TIM1, TIM2, TIM3, TIM6, TIM7, TIM15, TIM16 or TIM17 timer.
Sensor_Timer : Timer renames Timer_6;
-------------------
-- General Timer --
-------------------
General_Timer : Timer renames Timer_3;
General_Timer_Interrupt : Ada.Interrupts.Interrupt_ID renames TIM3_Interrupt;
General_Timer_ISR_Priority : constant Interrupt_Priority := Interrupt_Priority'Last - 2;
-- Channel for reading analog inputs (5 kHz, 200 us)
Sensor_Timer_Channel : Timer_Channel renames Channel_4;
Sensor_Timer_AF : STM32.GPIO_Alternate_Function renames GPIO_AF_TIM3_2;
Sensor_Timer_Point : GPIO_Point renames PC9;
-- Point not used because this timer only start an interrupt.
-------------------------
-- Other GPIO Channels --
-------------------------
AC_Frequency_Pin : GPIO_Point renames PA0;
-- Input for AC frequency select jumper.
Button : GPIO_Point renames PC13;
-- B1 user button input
Button_EXTI_Line : External_Line_Number renames EXTI_Line_13;
Button_Interrupt : Ada.Interrupts.Interrupt_ID renames EXTI15_10_Interrupt;
Button_ISR_Priority : constant Interrupt_Priority := Interrupt_Priority'Last;
Green_LED : GPIO_Point renames PB0; -- LD1
-- Output for OK indication in the nucleo board.
Yellow_LED : GPIO_Point renames PE1; -- LD2
-- Output for OK indication in the nucleo board.
Red_LED : GPIO_Point renames PB14; -- LD3
-- Output for problem indication in the nucleo board.
LCH_LED : GPIO_Point renames Red_LED;
-- Last chance handler led.
All_LEDs : GPIO_Points := Green_LED & Yellow_LED & Red_LED;
Buzzer : GPIO_Point renames PB2;
-- Output for buzzer alarm.
------------------------------
-- Procedures and functions --
------------------------------
procedure Initialize_GPIO;
-- Initialize GPIO inputs and outputs.
function Read_Input (This : GPIO_Point) return Boolean
with
Pre => Is_Initialized;
-- Read the specified input.
procedure Turn_On (This : in out GPIO_Point)
with
Pre => Is_Initialized and (This /= PWM_Gate_Power);
-- Turns ON the specified output.
procedure Turn_Off (This : in out GPIO_Point)
with
Pre => Is_Initialized and (This /= PWM_Gate_Power);
-- Turns OFF the specified output.
procedure Set_Toggle (This : in out GPIO_Point)
with
Pre => Is_Initialized and (This /= PWM_Gate_Power);
-- Toggle the specified output.
procedure All_LEDs_Off
with
Pre => Is_Initialized;
-- Turns OFF all LEDs.
procedure All_LEDs_On
with
Pre => Is_Initialized;
-- Turns ON all LEDs.
procedure Toggle_LEDs (These : in out GPIO_Points)
with
Pre => Is_Initialized;
-- Toggle the specified LEDs.
function Is_Initialized return Boolean;
-- Returns True if the board specifics are initialized.
private
Initialized : Boolean := False;
Debounce_Time : constant Time_Span := Milliseconds (300);
protected Button_Handler is
pragma Interrupt_Priority (Button_ISR_Priority);
private
Last_Time : Time := Clock;
procedure Button_ISR_Handler with
Attach_Handler => Button_Interrupt;
end Button_Handler;
end STM_Board;
|
package Error_Handling is
procedure Make_Safe;
-- The inverter is forced into a safe state.
end Error_Handling;
|
with Ada.Text_IO;
use Ada.Text_IO;
procedure RADWIMPS is
package Rad_Package is
type Rad is tagged null record;
procedure se(Self: in Rad);
function t_hen(Self: in Rad) return Rad;
end Rad_Package;
package body Rad_Package is
procedure se(Self: in Rad) is
begin
put_line("世");
end se;
function t_hen(Self: in Rad) return Rad is
begin
put("前");
return Self;
end t_hen;
end Rad_Package;
use Rad_Package;
RADWIMPS: Rad;
begin
RADWIMPS.t_hen.t_hen.t_hen.se;
end RADWIMPS;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2016, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with Interfaces;
package Bitmap is
pragma Pure;
type Bit is mod 2**1
with Size => 1;
type UInt8 is new Interfaces.Unsigned_8;
type UInt16 is new Interfaces.Unsigned_16;
type UInt24 is new Interfaces.Unsigned_24;
type UInt32 is new Interfaces.Unsigned_32;
type UInt65 is new Interfaces.Unsigned_32;
type UInt8_Array is array (Natural range <>) of UInt8;
type UInt16_Array is array (Natural range <>) of UInt16;
type UInt24_Array is array (Natural range <>) of UInt24;
type UInt32_Array is array (Natural range <>) of UInt32;
type Orientation_Mode is
(Default,
Portrait,
Landscape);
subtype Actual_Orientation is Orientation_Mode range Portrait .. Landscape;
type Bitmap_Color_Mode is
(ARGB_8888,
RGB_888,
RGB_565,
ARGB_1555,
ARGB_4444,
L_8,
AL_44,
AL_88,
L_4,
A_8,
A_4,
M_1 -- Monochrome
) with Size => 4;
function Bits_Per_Pixel (Mode : Bitmap_Color_Mode) return Positive is
(case Mode is
when ARGB_8888 => 32,
when RGB_888 => 24,
when RGB_565 | ARGB_1555 | ARGB_4444 | AL_88 => 16,
when L_8 | AL_44 | A_8 => 8,
when L_4 | A_4 => 4,
when M_1 => 1);
type Point is record
X : Natural;
Y : Natural;
end record;
function "+" (P1, P2 : Point) return Point
is ((P1.X + P2.X, P1.Y + P2.Y));
function "-" (P1, P2 : Point) return Point
is ((P1.X - P2.X, P1.Y - P2.Y));
type Rect is record
Position : Point;
Width : Natural;
Height : Natural;
end record;
type Bitmap_Color is record
Alpha : UInt8;
Red : UInt8;
Green : UInt8;
Blue : UInt8;
end record with Size => 32;
for Bitmap_Color use record
Blue at 0 range 0 .. 7;
Green at 1 range 0 .. 7;
Red at 2 range 0 .. 7;
Alpha at 3 range 0 .. 7;
end record;
Transparent : constant Bitmap_Color := (000, 000, 000, 000);
Dark_Red : constant Bitmap_Color := (255, 139, 000, 000);
Brown : constant Bitmap_Color := (255, 165, 042, 042);
Firebrick : constant Bitmap_Color := (255, 178, 034, 034);
Crimson : constant Bitmap_Color := (255, 220, 020, 060);
Red : constant Bitmap_Color := (255, 255, 000, 000);
Tomato : constant Bitmap_Color := (255, 255, 099, 071);
Coral : constant Bitmap_Color := (255, 255, 127, 080);
Indian_Red : constant Bitmap_Color := (255, 205, 092, 092);
Light_Coral : constant Bitmap_Color := (255, 240, 128, 128);
Dark_Salmon : constant Bitmap_Color := (255, 233, 150, 122);
Salmon : constant Bitmap_Color := (255, 250, 128, 114);
Light_Salmon : constant Bitmap_Color := (255, 255, 160, 122);
Dark_Orange : constant Bitmap_Color := (255, 255, 140, 000);
Orange : constant Bitmap_Color := (255, 255, 165, 000);
Light_Orange : constant Bitmap_Color := (255, 255, 069, 000);
Gold : constant Bitmap_Color := (255, 255, 215, 000);
Dark_Golden_Rod : constant Bitmap_Color := (255, 184, 134, 011);
Golden_Rod : constant Bitmap_Color := (255, 218, 165, 032);
Pale_Golden_Rod : constant Bitmap_Color := (255, 238, 232, 170);
Dark_Khaki : constant Bitmap_Color := (255, 189, 183, 107);
Khaki : constant Bitmap_Color := (255, 240, 230, 140);
Olive : constant Bitmap_Color := (255, 128, 128, 000);
Yellow : constant Bitmap_Color := (255, 255, 255, 000);
Yellow_Green : constant Bitmap_Color := (255, 154, 205, 050);
Dark_Olive_Green : constant Bitmap_Color := (255, 085, 107, 047);
Olive_Drab : constant Bitmap_Color := (255, 107, 142, 035);
Lawn_Green : constant Bitmap_Color := (255, 124, 252, 000);
Chart_Reuse : constant Bitmap_Color := (255, 127, 255, 000);
Green_Yellow : constant Bitmap_Color := (255, 173, 255, 047);
Dark_Green : constant Bitmap_Color := (255, 000, 100, 000);
Green : constant Bitmap_Color := (255, 000, 255, 000);
Maroon : constant Bitmap_Color := (255, 128, 000, 000);
Forest_Green : constant Bitmap_Color := (255, 034, 139, 034);
Lime : constant Bitmap_Color := (255, 000, 255, 000);
Lime_Green : constant Bitmap_Color := (255, 050, 205, 050);
Light_Green : constant Bitmap_Color := (255, 144, 238, 144);
Pale_Green : constant Bitmap_Color := (255, 152, 251, 152);
Dark_Sea_Green : constant Bitmap_Color := (255, 143, 188, 143);
Medium_Spring_Green : constant Bitmap_Color := (255, 000, 250, 154);
Spring_Green : constant Bitmap_Color := (255, 000, 255, 127);
Sea_Green : constant Bitmap_Color := (255, 046, 139, 087);
Medium_Aqua_Marine : constant Bitmap_Color := (255, 102, 205, 170);
Medium_Sea_Green : constant Bitmap_Color := (255, 060, 179, 113);
Light_Sea_Green : constant Bitmap_Color := (255, 032, 178, 170);
Dark_Slate_Gray : constant Bitmap_Color := (255, 047, 079, 079);
Teal : constant Bitmap_Color := (255, 000, 128, 128);
Dark_Cyan : constant Bitmap_Color := (255, 000, 139, 139);
Aqua : constant Bitmap_Color := (255, 000, 255, 255);
Cyan : constant Bitmap_Color := (255, 000, 255, 255);
Light_Cyan : constant Bitmap_Color := (255, 224, 255, 255);
Dark_Turquoise : constant Bitmap_Color := (255, 000, 206, 209);
Turquoise : constant Bitmap_Color := (255, 064, 224, 208);
Medium_Turquoise : constant Bitmap_Color := (255, 072, 209, 204);
Pale_Turquoise : constant Bitmap_Color := (255, 175, 238, 238);
Aqua_Marine : constant Bitmap_Color := (255, 127, 255, 212);
Powder_Blue : constant Bitmap_Color := (255, 176, 224, 230);
Cadet_Blue : constant Bitmap_Color := (255, 095, 158, 160);
Steel_Blue : constant Bitmap_Color := (255, 070, 130, 180);
Corn_Flower_Blue : constant Bitmap_Color := (255, 100, 149, 237);
Deep_Sky_Blue : constant Bitmap_Color := (255, 000, 191, 255);
Dodger_Blue : constant Bitmap_Color := (255, 030, 144, 255);
Light_Blue : constant Bitmap_Color := (255, 173, 216, 230);
Sky_Blue : constant Bitmap_Color := (255, 135, 206, 235);
Light_Sky_Blue : constant Bitmap_Color := (255, 135, 206, 250);
Midnight_Blue : constant Bitmap_Color := (255, 025, 025, 112);
Navy : constant Bitmap_Color := (255, 000, 000, 128);
Dark_Blue : constant Bitmap_Color := (255, 000, 000, 139);
Medium_Blue : constant Bitmap_Color := (255, 000, 000, 205);
Blue : constant Bitmap_Color := (255, 000, 000, 255);
Royal_Blue : constant Bitmap_Color := (255, 065, 105, 225);
Blue_Violet : constant Bitmap_Color := (255, 138, 043, 226);
Indigo : constant Bitmap_Color := (255, 075, 000, 130);
Dark_Slate_Blue : constant Bitmap_Color := (255, 072, 061, 139);
Slate_Blue : constant Bitmap_Color := (255, 106, 090, 205);
Medium_Slate_Blue : constant Bitmap_Color := (255, 123, 104, 238);
Medium_Purple : constant Bitmap_Color := (255, 147, 112, 219);
Dark_Magenta : constant Bitmap_Color := (255, 139, 000, 139);
Dark_Violet : constant Bitmap_Color := (255, 148, 000, 211);
Dark_Orchid : constant Bitmap_Color := (255, 153, 050, 204);
Medium_Orchid : constant Bitmap_Color := (255, 186, 085, 211);
Purple : constant Bitmap_Color := (255, 128, 000, 128);
Thistle : constant Bitmap_Color := (255, 216, 191, 216);
Plum : constant Bitmap_Color := (255, 221, 160, 221);
Violet : constant Bitmap_Color := (255, 238, 130, 238);
Magenta : constant Bitmap_Color := (255, 255, 000, 255);
Orchid : constant Bitmap_Color := (255, 218, 112, 214);
Medium_Violet_Red : constant Bitmap_Color := (255, 199, 021, 133);
Pale_Violet_Red : constant Bitmap_Color := (255, 219, 112, 147);
Deep_Pink : constant Bitmap_Color := (255, 255, 020, 147);
Hot_Pink : constant Bitmap_Color := (255, 255, 105, 180);
Light_Pink : constant Bitmap_Color := (255, 255, 182, 193);
Pink : constant Bitmap_Color := (255, 255, 192, 203);
Antique_White : constant Bitmap_Color := (255, 250, 235, 215);
Beige : constant Bitmap_Color := (255, 245, 245, 220);
Bisque : constant Bitmap_Color := (255, 255, 228, 196);
Blanched_Almond : constant Bitmap_Color := (255, 255, 235, 205);
Wheat : constant Bitmap_Color := (255, 245, 222, 179);
Corn_Silk : constant Bitmap_Color := (255, 255, 248, 220);
Lemon_Chiffon : constant Bitmap_Color := (255, 255, 250, 205);
Light_Yellow : constant Bitmap_Color := (255, 255, 255, 224);
Saddle_Brown : constant Bitmap_Color := (255, 139, 069, 019);
Sienna : constant Bitmap_Color := (255, 160, 082, 045);
Chocolate : constant Bitmap_Color := (255, 210, 105, 030);
Peru : constant Bitmap_Color := (255, 205, 133, 063);
Sandy_Brown : constant Bitmap_Color := (255, 244, 164, 096);
Burly_Wood : constant Bitmap_Color := (255, 222, 184, 135);
Tan : constant Bitmap_Color := (255, 210, 180, 140);
Rosy_Brown : constant Bitmap_Color := (255, 188, 143, 143);
Moccasin : constant Bitmap_Color := (255, 255, 228, 181);
Navajo_White : constant Bitmap_Color := (255, 255, 222, 173);
Peach_Puff : constant Bitmap_Color := (255, 255, 218, 185);
Misty_Rose : constant Bitmap_Color := (255, 255, 228, 225);
Lavender_Blush : constant Bitmap_Color := (255, 255, 240, 245);
Linen : constant Bitmap_Color := (255, 250, 240, 230);
Old_Lace : constant Bitmap_Color := (255, 253, 245, 230);
Papaya_Whip : constant Bitmap_Color := (255, 255, 239, 213);
Sea_Shell : constant Bitmap_Color := (255, 255, 245, 238);
Mint_Cream : constant Bitmap_Color := (255, 245, 255, 250);
Slate_Gray : constant Bitmap_Color := (255, 112, 128, 144);
Light_Slate_Gray : constant Bitmap_Color := (255, 119, 136, 153);
Light_Steel_Blue : constant Bitmap_Color := (255, 176, 196, 222);
Lavender : constant Bitmap_Color := (255, 230, 230, 250);
Floral_White : constant Bitmap_Color := (255, 255, 250, 240);
Alice_Blue : constant Bitmap_Color := (255, 240, 248, 255);
Ghost_White : constant Bitmap_Color := (255, 248, 248, 255);
Honeydew : constant Bitmap_Color := (255, 240, 255, 240);
Ivory : constant Bitmap_Color := (255, 255, 255, 240);
Azure : constant Bitmap_Color := (255, 240, 255, 255);
Snow : constant Bitmap_Color := (255, 255, 250, 250);
Black : constant Bitmap_Color := (255, 000, 000, 000);
Dim_Grey : constant Bitmap_Color := (255, 105, 105, 105);
Grey : constant Bitmap_Color := (255, 128, 128, 128);
Gray : constant Bitmap_Color := (255, 190, 190, 190);
Dark_Grey : constant Bitmap_Color := (255, 169, 169, 169);
Silver : constant Bitmap_Color := (255, 192, 192, 192);
Light_Grey : constant Bitmap_Color := (255, 211, 211, 211);
Gainsboro : constant Bitmap_Color := (255, 220, 220, 220);
White_Smoke : constant Bitmap_Color := (255, 245, 245, 245);
White : constant Bitmap_Color := (255, 255, 255, 255);
end Bitmap;
|
procedure Call_Foo is
begin
Foo;
exception
when Foo_Error =>
... -- do something
when others =>
... -- this catches all other exceptions
end Call_Foo;
|
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
-- Afficher une valeur approchée de la racine carréé d'un nombre réel
procedure Racine_Carree_Rang is
A: Float; -- le nombre dont on veut calculer la racine carrée
Rang: Integer; -- le rang souhaité
Racine: Float; -- valeur approchée de la racine carrée de A
begin
-- Demander la valeur (sans contrôle)
Get (A);
-- Déterminer la valeur approchée de la racine carrée
-- Demander le rang (sans contrôle)
Get (Rang);
-- Calculer le terme de rang Rang de la suite
Racine := A;
for I in 1 .. Rang loop
exit when Racine = 0.0;
Racine := (Racine + A/Racine)/2.0;
end loop;
-- Afficher la valeur approchée de la racine carrée
Put (Racine, Exp => 0, Aft => 4);
New_Line;
end Racine_Carree_Rang;
|
-- Copyright (c) 2021 Devin Hill
-- zlib License -- see LICENSE for details.
with GBA.Memory;
use GBA.Memory;
with GBA.Numerics;
use GBA.Numerics;
with GBA.Display.Tiles;
use GBA.Display.Tiles;
with GBA.Display.Palettes;
use GBA.Display.Palettes;
package GBA.Display.Objects is
type OBJ_ID is range 0 .. 127;
type OBJ_Y_Coordinate is mod 2**8;
type OBJ_X_Coordinate is mod 2**9;
type OBJ_Kind is
( Regular
, Affine
)
with Size => 1;
for OBJ_Kind use
( Regular => 0
, Affine => 1
);
type OBJ_Mode is
( Normal
, Transparent
, Window
)
with Size => 2;
for OBJ_Mode use
( Normal => 0
, Transparent => 1
, Window => 2
);
type OBJ_Shape is
( Square
, Wide
, Tall
)
with Size => 2;
for OBJ_Shape use
( Square => 0
, Wide => 1
, Tall => 2
);
type OBJ_Scale is range 0 .. 3
with Size => 2;
type OBJ_Size is
( Size_8x8
, Size_16x16
, Size_32x32
, Size_64x64
, Size_16x8
, Size_32x8
, Size_32x16
, Size_64x32
, Size_8x16
, Size_8x32
, Size_16x32
, Size_32x64
) with Size => 4;
for OBJ_Size use
( Size_8x8 => 2#0000#
, Size_16x16 => 2#0001#
, Size_32x32 => 2#0010#
, Size_64x64 => 2#0011#
, Size_16x8 => 2#0100#
, Size_32x8 => 2#0101#
, Size_32x16 => 2#0110#
, Size_64x32 => 2#0111#
, Size_8x16 => 2#1000#
, Size_8x32 => 2#1001#
, Size_16x32 => 2#1010#
, Size_32x64 => 2#1011#
);
function As_Size (Shape : OBJ_Shape; Scale : OBJ_Scale) return OBJ_Size
with Inline_Always;
procedure As_Shape_And_Scale (Size : OBJ_Size; Shape : out OBJ_Shape; Scale : out OBJ_Scale)
with Inline_Always;
type OBJ_Affine_Transform_Index is range 0 .. 31
with Size => 5;
function Affine_Transform_Address (Ix : OBJ_Affine_Transform_Index) return Address
with Pure_Function, Inline_Always;
type OBJ_Attributes (Kind : OBJ_Kind := Regular) is
record
Y : OBJ_Y_Coordinate;
X : OBJ_X_Coordinate;
Mode : OBJ_Mode;
Enable_Mosaic : Boolean;
Color_Mode : Palette_Mode;
Shape : OBJ_Shape;
Scale : OBJ_Scale;
Tile_Index : OBJ_Tile_Index;
Priority : Display_Priority;
Palette_Index : Palette_Index_16; -- Unused if Color_Mode is 256
case Kind is
when Regular =>
Disabled : Boolean;
Flip_Horizontal : Boolean;
Flip_Vertical : Boolean;
when Affine =>
Double_Size : Boolean;
Transform_Index : OBJ_Affine_Transform_Index;
end case;
end record
with Size => 48;
for OBJ_Attributes use
record
Y at 0 range 0 .. 7;
Kind at 0 range 8 .. 8;
Disabled at 0 range 9 .. 9;
Double_Size at 0 range 9 .. 9;
Mode at 0 range 10 .. 11;
Enable_Mosaic at 0 range 12 .. 12;
Color_Mode at 0 range 13 .. 13;
Shape at 0 range 14 .. 15;
X at 2 range 0 .. 8;
Transform_Index at 2 range 9 .. 13;
Flip_Horizontal at 2 range 12 .. 12;
Flip_Vertical at 2 range 13 .. 13;
Scale at 2 range 14 .. 15;
Tile_Index at 4 range 0 .. 9;
Priority at 4 range 10 .. 11;
Palette_Index at 4 range 12 .. 15;
end record;
type Volatile_OBJ_Attributes is new OBJ_Attributes
with Volatile;
type OAM_Attributes_Ptr is access all Volatile_OBJ_Attributes
with Storage_Size => 0, Volatile;
function Attributes_Of_Object (ID : OBJ_ID) return OAM_Attributes_Ptr
with Pure_Function, Inline_Always;
function Attributes_Of_Object (ID : OBJ_ID) return OBJ_Attributes
with Inline_Always;
procedure Set_Object_Attributes (ID : OBJ_ID; Attributes : OBJ_Attributes)
with Inline;
type OAM_Entry is limited
record
Attributes : aliased Volatile_OBJ_Attributes;
Transform_Parameter : aliased Affine_Transform_Parameter;
end record
with Size => 64, Volatile;
for OAM_Entry use
record
Attributes at 0 range 0 .. 47;
Transform_Parameter at 6 range 0 .. 15;
end record;
Object_Attribute_Memory : array (0 .. 127) of OAM_Entry
with Import, Volatile_Components, Address => OAM_Address'First;
end GBA.Display.Objects;
|
with
Interfaces.C,
System;
use type
System.Address,
Interfaces.C.unsigned;
package body FLTK.Widgets.Groups.Windows.Single.Menu is
procedure menu_window_set_draw_hook
(W, D : in System.Address);
pragma Import (C, menu_window_set_draw_hook, "menu_window_set_draw_hook");
pragma Inline (menu_window_set_draw_hook);
procedure menu_window_set_handle_hook
(W, H : in System.Address);
pragma Import (C, menu_window_set_handle_hook, "menu_window_set_handle_hook");
pragma Inline (menu_window_set_handle_hook);
function new_fl_menu_window
(X, Y, W, H : in Interfaces.C.int;
Label : in Interfaces.C.char_array)
return System.Address;
pragma Import (C, new_fl_menu_window, "new_fl_menu_window");
pragma Inline (new_fl_menu_window);
function new_fl_menu_window2
(W, H : in Interfaces.C.int;
Text : in Interfaces.C.char_array)
return System.Address;
pragma Import (C, new_fl_menu_window2, "new_fl_menu_window2");
pragma Inline (new_fl_menu_window2);
procedure free_fl_menu_window
(M : in System.Address);
pragma Import (C, free_fl_menu_window, "free_fl_menu_window");
pragma Inline (free_fl_menu_window);
procedure fl_menu_window_show
(M : in System.Address);
pragma Import (C, fl_menu_window_show, "fl_menu_window_show");
pragma Inline (fl_menu_window_show);
procedure fl_menu_window_hide
(M : in System.Address);
pragma Import (C, fl_menu_window_hide, "fl_menu_window_hide");
pragma Inline (fl_menu_window_hide);
procedure fl_menu_window_flush
(M : in System.Address);
pragma Import (C, fl_menu_window_flush, "fl_menu_window_flush");
pragma Inline (fl_menu_window_flush);
procedure fl_menu_window_set_overlay
(M : in System.Address);
pragma Import (C, fl_menu_window_set_overlay, "fl_menu_window_set_overlay");
pragma Inline (fl_menu_window_set_overlay);
procedure fl_menu_window_clear_overlay
(M : in System.Address);
pragma Import (C, fl_menu_window_clear_overlay, "fl_menu_window_clear_overlay");
pragma Inline (fl_menu_window_clear_overlay);
function fl_menu_window_overlay
(M : in System.Address)
return Interfaces.C.unsigned;
pragma Import (C, fl_menu_window_overlay, "fl_menu_window_overlay");
pragma Inline (fl_menu_window_overlay);
procedure fl_menu_window_draw
(W : in System.Address);
pragma Import (C, fl_menu_window_draw, "fl_menu_window_draw");
pragma Inline (fl_menu_window_draw);
function fl_menu_window_handle
(W : in System.Address;
E : in Interfaces.C.int)
return Interfaces.C.int;
pragma Import (C, fl_menu_window_handle, "fl_menu_window_handle");
pragma Inline (fl_menu_window_handle);
procedure Finalize
(This : in out Menu_Window) is
begin
if This.Void_Ptr /= System.Null_Address and then
This in Menu_Window'Class
then
This.Clear;
free_fl_menu_window (This.Void_Ptr);
This.Void_Ptr := System.Null_Address;
end if;
Finalize (Single_Window (This));
end Finalize;
package body Forge is
function Create
(X, Y, W, H : in Integer;
Text : in String)
return Menu_Window is
begin
return This : Menu_Window do
This.Void_Ptr := new_fl_menu_window
(Interfaces.C.int (X),
Interfaces.C.int (Y),
Interfaces.C.int (W),
Interfaces.C.int (H),
Interfaces.C.To_C (Text));
fl_group_end (This.Void_Ptr);
fl_widget_set_user_data
(This.Void_Ptr,
Widget_Convert.To_Address (This'Unchecked_Access));
menu_window_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
menu_window_set_handle_hook (This.Void_Ptr, Handle_Hook'Address);
end return;
end Create;
function Create
(W, H : in Integer;
Text : in String)
return Menu_Window is
begin
return This : Menu_Window do
This.Void_Ptr := new_fl_menu_window2
(Interfaces.C.int (W),
Interfaces.C.int (H),
Interfaces.C.To_C (Text));
fl_group_end (This.Void_Ptr);
fl_widget_set_user_data
(This.Void_Ptr,
Widget_Convert.To_Address (This'Unchecked_Access));
menu_window_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
menu_window_set_handle_hook (This.Void_Ptr, Handle_Hook'Address);
end return;
end Create;
end Forge;
procedure Show
(This : in out Menu_Window) is
begin
fl_menu_window_show (This.Void_Ptr);
end Show;
procedure Hide
(This : in out Menu_Window) is
begin
fl_menu_window_hide (This.Void_Ptr);
end Hide;
procedure Flush
(This : in out Menu_Window) is
begin
fl_menu_window_flush (This.Void_Ptr);
end Flush;
function Is_Overlay
(This : in Menu_Window)
return Boolean is
begin
return fl_menu_window_overlay (This.Void_Ptr) /= 0;
end Is_Overlay;
procedure Set_Overlay
(This : in out Menu_Window;
Value : in Boolean) is
begin
if Value then
fl_menu_window_set_overlay (This.Void_Ptr);
else
fl_menu_window_clear_overlay (This.Void_Ptr);
end if;
end Set_Overlay;
procedure Draw
(This : in out Menu_Window) is
begin
fl_menu_window_draw (This.Void_Ptr);
end Draw;
function Handle
(This : in out Menu_Window;
Event : in Event_Kind)
return Event_Outcome is
begin
return Event_Outcome'Val
(fl_menu_window_handle (This.Void_Ptr, Event_Kind'Pos (Event)));
end Handle;
end FLTK.Widgets.Groups.Windows.Single.Menu;
|
-- File: adaid-generate.adb
-- Description: UUID Generation
-- Author: Anthony Arnold
-- License: Simplified BSD License (see LICENSE)
with SHA.Process_Data; -- For From_Name
with Ada.Numerics.Discrete_Random; -- For RNG
with Ada.Streams.Stream_IO; -- For reading from /dev/random
use Ada.Streams.Stream_IO;
package body AdaID.Generate is
-- For RNG
package RNG is new Ada.Numerics.Discrete_Random (Result_Subtype =>
Unsigned_32);
generator : RNG.Generator;
generator_is_set : Boolean := False;
procedure Seed_RNG is
seed : Integer;
file : File_Type;
begin
-- Set up the generator first time
if not generator_is_set then
begin
Open (File => file,
Mode => In_File,
Name => "/dev/urandom");
Integer'Read (Stream (file), seed);
Close (file);
RNG.Reset (generator, seed);
exception
when others =>
RNG.Reset (generator); -- Fallback to time-based
end;
generator_is_set := True;
end if;
end Seed_RNG;
-- Reset a UUID to Nil
procedure Nil (id : in out UUID) is
begin
Initialize (id);
end Nil;
-- Generate a random UUID
procedure Random (id : in out UUID) is
rand : Unsigned_32;
x : Integer := 0;
begin
-- Ensure RNG is seeded
Seed_RNG;
-- Get a random number
rand := RNG.Random (generator);
for i in ByteArray'Range loop
if x = 4 then
x := 0;
rand := RNG.Random (generator);
end if;
id.data (i) := Byte (shift_right (rand, x * 8) and 16#FF#);
x := x + 1;
end loop;
-- Set the variant
id.data (8) := (id.data (8) and 16#BF#) or 16#80#;
-- Set the version to random-number-based
id.data (6) := (id.data (6) and 16#4F#) or 16#40#;
end Random;
-- Generate a UUID based on a name
procedure From_Name
(namespace : in UUID;
name : in String;
id : in out UUID)
is
use SHA.Process_Data;
c : Context;
d : SHA.Digest;
begin
Initialize (c);
-- Start SHA1 hashing with namespace uuid
for i in namespace.data'Range loop
Add (SHA.Process_Data.Byte (namespace.data (i)), c);
end loop;
-- Continuing hashing the actual name
for i in name'Range loop
Add (SHA.Process_Data.Byte (Character'Pos (name (i))), c);
end loop;
-- Get the digest
Finalize (d, c);
-- Now make the UUID from the hash
for i in 0 .. 3 loop
id.data (i * 4 + 0) := Byte (shift_right (d (i), 24) and 16#FF#);
id.data (i * 4 + 1) := Byte (shift_right (d (i), 16) and 16#FF#);
id.data (i * 4 + 2) := Byte (shift_right (d (i), 8) and 16#FF#);
id.data (i * 4 + 3) := Byte (shift_right (d (i), 0) and 16#FF#);
end loop;
-- set variant
id.data (8) := (id.data (8) and 16#BF#) or 16#80#;
-- set version
id.data (6) := (id.data (6) and 16#5F#) or 16#50#;
end From_Name;
-- Generate a UUID from a string.
-- This is not so much generation, but reconstruction
procedure From_String (str : in String; id : in out UUID) is
delim : constant Character := '-';
open : constant Character := '{';
close : constant Character := '}';
-- expect dashes if str is 36 or 38 in length
dashed : constant Boolean := str'Length = 36 or else str'Length = 38;
-- check to see if braces surround the string
braced : constant Boolean := str (str'First) = open and then
str (str'Last) = close;
-- track where to read from/write to
idx : Integer := 0;
start, rel : Integer;
begin
-- Check that length is valid
if not dashed and then str'Length /= 32 and then str'Length /= 34 then
raise Invalid_String;
end if;
-- Check that brace are valid
start := str'First;
if not braced and then
(str (str'First) = open or else str (str'Last) = close)
then
raise Invalid_String; -- only one brace present
elsif braced then
start := str'First + 1;
end if;
idx := start;
-- Grab each pair and stuff into byte
for i in ByteArray'Range loop
rel := idx - start;
if dashed and then
(rel = 8 or else rel = 13 or else rel = 18 or else rel = 23)
then
if str (idx) /= delim then
raise Invalid_String; -- expected '-'
end if;
idx := idx + 1;
end if;
-- Convert to byte
id.data (i) := Byte'Value ("16#" & str (idx .. idx + 1) & "#");
idx := idx + 2;
end loop;
end From_String;
end AdaID.Generate;
|
------------------------------------------------------------------------------
-- G E L A A S I S --
-- ASIS implementation for Gela project, a portable Ada compiler --
-- http://gela.ada-ru.org --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license at the end of this file --
------------------------------------------------------------------------------
-- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $
-- Purpose:
-- Implement Asis.Text.
-- Not implemented yet (except Element_Span)
with Gela.Decoders;
with Gela.Source_Buffers;
use Gela;
with Asis.Errors;
with Asis.Elements;
with Asis.Exceptions;
with Asis.Gela.Lines;
with Asis.Implementation;
with Asis.Gela.Text_Utils;
with Asis.Compilation_Units;
package body Asis.Text is
LF : constant Wide_Character := Wide_Character'Val (10);
Max_Line_Size : constant := 1024;
-------------------
-- Comment_Image --
-------------------
function Comment_Image (The_Line : in Line) return Program_Text is
use Asis.Gela.Text_Utils;
Line : Asis.Gela.Lines.Line;
Decoder : Decoder_Access;
Source : Source_Buffer_Access;
begin
if Is_Nil (The_Line) then
Implementation.Set_Status (
Status => Asis.Errors.Value_Error,
Diagnosis => "Line is nil");
raise Asis.Exceptions.ASIS_Inappropriate_Line;
end if;
Line := Get_Line (The_Line.Unit, The_Line.Index);
Decoder := Gela.Text_Utils.Decoder (The_Line.Unit);
Source := Source_Buffer (The_Line.Unit);
declare
Text : Wide_String (1 .. Max_Line_Size);
Last : Natural;
begin
Decoders.Decode
(Object => Decoder.all,
From => Line.From,
To => Line.Comment,
Result => Text,
Last => Last);
Text (1 .. Last) := (others => ' ');
Decoders.Decode
(Object => Decoder.all,
From => Line.Comment,
To => Line.To,
Result => Text (Last + 1 .. Text'Last),
Last => Last);
if The_Line.From > 1 then
Text (1 .. The_Line.From - 1) := (others => ' ');
end if;
if The_Line.To < Last then
Last := The_Line.To;
end if;
return Text (1 .. Last);
end;
end Comment_Image;
----------------------
-- Compilation_Span --
----------------------
function Compilation_Span
(Element : in Asis.Element)
return Span
is
use Asis.Gela.Text_Utils;
Unit : constant Asis.Compilation_Unit :=
Asis.Elements.Enclosing_Compilation_Unit (Element);
begin
return (1, 1, Compilation_Line_Count (Unit), Max_Line_Size);
end Compilation_Span;
---------------------------
-- Compilation_Unit_Span --
---------------------------
function Compilation_Unit_Span
(Element : in Asis.Element)
return Span
is
begin
if not Assigned (Element) then
return Nil_Span;
else
declare
Unit : constant Asis.Compilation_Unit :=
Asis.Elements.Enclosing_Compilation_Unit (Element);
Start : constant Text_Position := Start_Position (Unit.all);
Stop : constant Text_Position := End_Position (Unit.all);
begin
if Start.Line = 0 or Start.Column = 0 then
return Nil_Span;
end if;
return (First_Line => Line_Number_Positive (Start.Line),
First_Column => Character_Position_Positive (Start.Column),
Last_Line => Line_Number (Stop.Line),
Last_Column => Character_Position (Stop.Column));
end;
end if;
end Compilation_Unit_Span;
-----------------
-- Debug_Image --
-----------------
function Debug_Image (The_Line : in Line) return Wide_String is
begin
if Is_Nil (The_Line) then
return "[nil_line]";
else
declare
Unit : constant Wide_String :=
Compilation_Units.Text_Name (The_Line.Unit);
Image : constant Wide_String :=
Line_Number'Wide_Image (The_Line.Index);
begin
return Unit & "[" & Image (2 .. Image'Last) & "]";
end;
end if;
end Debug_Image;
---------------------
-- Delimiter_Image --
---------------------
function Delimiter_Image return Wide_String is
begin
return (1 => LF);
end Delimiter_Image;
-------------------
-- Element_Image --
-------------------
function Element_Image (Element : in Asis.Element) return Program_Text is
function Image (List : Line_List;
Prefix : Program_Text := "") return Program_Text
is
Result : Program_Text (1 .. 4096);
Last : Natural := 0;
Index : Line_Number_Positive := List'First;
begin
while Index <= List'Last loop
declare
Text : constant Program_Text := Line_Image (List (Index));
begin
if Text'Length < Result'Length - Last then
Result (Last + 1 .. Last + Text'Length) := Text;
Last := Last + Text'Length;
if Index < List'Last then
Result (Last + 1) := LF;
Last := Last + 1;
end if;
elsif Index < List'Last then
return Image (List (Index + 1 .. List'Last),
Prefix & Result (1 .. Last) & Text & LF);
else
return Prefix & Result (1 .. Last) & Text;
end if;
Index := Index + 1;
end;
end loop;
return Prefix & Result (1 .. Last);
end Image;
begin
return Image (Lines (Element));
end Element_Image;
------------------
-- Element_Span --
------------------
function Element_Span
(Element : in Asis.Element)
return Span
is
begin
if not Assigned (Element) then
return Nil_Span;
else
declare
Start : constant Text_Position := Start_Position (Element.all);
Stop : constant Text_Position := End_Position (Element.all);
begin
if Start.Line = 0 or Start.Column = 0 then
return Nil_Span;
end if;
return (First_Line => Line_Number_Positive (Start.Line),
First_Column => Character_Position_Positive (Start.Column),
Last_Line => Line_Number (Stop.Line),
Last_Column => Character_Position (Stop.Column));
end;
end if;
end Element_Span;
-----------------------
-- First_Line_Number --
-----------------------
function First_Line_Number
(Element : in Asis.Element)
return Line_Number
is
S : constant Span := Element_Span (Element);
begin
return S.First_Line;
end First_Line_Number;
--------------
-- Is_Equal --
--------------
function Is_Equal
(Left : in Line;
Right : in Line)
return Boolean
is
begin
return Is_Identical (Left, Right);
end Is_Equal;
------------------
-- Is_Identical --
------------------
function Is_Identical
(Left : in Line;
Right : in Line)
return Boolean
is
begin
return Asis.Compilation_Units.Is_Identical (Left.Unit, Right.Unit) and
Left.From = Right.From and
Left.To = Right.To and
Left.Index = Right.Index;
end Is_Identical;
------------
-- Is_Nil --
------------
function Is_Nil
(Right : in Line)
return Boolean
is
begin
return Asis.Compilation_Units.Is_Nil (Right.Unit);
end Is_Nil;
------------
-- Is_Nil --
------------
function Is_Nil
(Right : in Line_List)
return Boolean
is
begin
return Right'Length = 0;
end Is_Nil;
------------
-- Is_Nil --
------------
function Is_Nil
(Right : in Span)
return Boolean
is
begin
return Right = Nil_Span;
end Is_Nil;
-----------------------
-- Is_Text_Available --
-----------------------
function Is_Text_Available (Element : in Asis.Element) return Boolean is
use Asis.Elements;
begin
if Is_Nil (Element) or
Is_Part_Of_Implicit (Element) or
Is_Part_Of_Instance (Element)
then
return False;
else
return True;
end if;
end Is_Text_Available;
----------------------
-- Last_Line_Number --
----------------------
function Last_Line_Number
(Element : in Asis.Element)
return Line_Number
is
S : constant Span := Element_Span (Element);
begin
return S.Last_Line;
end Last_Line_Number;
------------
-- Length --
------------
function Length (The_Line : in Line) return Character_Position is
begin
return Line_Image (The_Line)'Length;
end Length;
----------------
-- Line_Image --
----------------
function Line_Image (The_Line : in Line) return Program_Text is
use Asis.Gela.Text_Utils;
Line : Asis.Gela.Lines.Line;
Decoder : Decoder_Access;
Source : Source_Buffer_Access;
begin
if Is_Nil (The_Line) then
Implementation.Set_Status (
Status => Asis.Errors.Value_Error,
Diagnosis => "Line is nil");
raise Asis.Exceptions.ASIS_Inappropriate_Line;
end if;
Line := Get_Line (The_Line.Unit, The_Line.Index);
Decoder := Gela.Text_Utils.Decoder (The_Line.Unit);
Source := Source_Buffer (The_Line.Unit);
declare
Text : Wide_String (1 .. Max_Line_Size);
Last : Natural;
begin
Decoders.Decode
(Object => Decoder.all,
From => Line.From,
To => Line.To,
Result => Text,
Last => Last);
if The_Line.From > 1 then
Text (1 .. The_Line.From - 1) := (others => ' ');
end if;
if The_Line.To < Last then
Last := The_Line.To;
end if;
return Text (1 .. Last);
end;
end Line_Image;
-----------
-- Lines --
-----------
function Lines (Element : in Asis.Element) return Line_List is
The_Span : constant Span := Element_Span (Element);
begin
if Asis.Elements.Is_Nil (Element) then
return Nil_Line_List;
else
return Lines (Element, The_Span);
end if;
end Lines;
-----------
-- Lines --
-----------
function Lines
(Element : in Asis.Element;
The_Span : in Span)
return Line_List
is
Unit : constant Asis.Compilation_Unit :=
Asis.Elements.Enclosing_Compilation_Unit (Element);
Result : Line_List (The_Span.First_Line .. The_Span.Last_Line);
begin
if Is_Nil (The_Span) then
Implementation.Set_Status (
Status => Asis.Errors.Value_Error,
Diagnosis => "Span is nil");
raise Asis.Exceptions.ASIS_Inappropriate_Line;
end if;
for J in Result'Range loop
Result (J).Unit := Unit;
Result (J).Index := J;
end loop;
Result (Result'First).From := Positive (The_Span.First_Column);
Result (Result'Last).To := Natural (The_Span.Last_Column);
return Result;
end Lines;
-----------
-- Lines --
-----------
function Lines
(Element : in Asis.Element;
First_Line : in Line_Number_Positive;
Last_Line : in Line_Number)
return Line_List
is
Unit : constant Asis.Compilation_Unit :=
Asis.Elements.Enclosing_Compilation_Unit (Element);
Result : Line_List (First_Line .. Last_Line);
begin
if First_Line > Last_Line then
Implementation.Set_Status (
Status => Asis.Errors.Value_Error,
Diagnosis => "Span is nil");
raise Asis.Exceptions.ASIS_Inappropriate_Line;
end if;
for J in Result'Range loop
Result (J).Unit := Unit;
Result (J).Index := J;
end loop;
return Result;
end Lines;
-----------------------
-- Non_Comment_Image --
-----------------------
function Non_Comment_Image (The_Line : in Line) return Program_Text is
use Asis.Gela.Text_Utils;
Line : Asis.Gela.Lines.Line;
Decoder : Decoder_Access;
Source : Source_Buffer_Access;
begin
if Is_Nil (The_Line) then
Implementation.Set_Status (
Status => Asis.Errors.Value_Error,
Diagnosis => "Line is nil");
raise Asis.Exceptions.ASIS_Inappropriate_Line;
end if;
Line := Get_Line (The_Line.Unit, The_Line.Index);
Decoder := Gela.Text_Utils.Decoder (The_Line.Unit);
Source := Source_Buffer (The_Line.Unit);
declare
Text : Wide_String (1 .. Max_Line_Size);
Last : Natural;
begin
Decoders.Decode
(Object => Decoder.all,
From => Line.From,
To => Line.Comment,
Result => Text,
Last => Last);
if The_Line.From > 1 then
Text (1 .. The_Line.From - 1) := (others => ' ');
end if;
if The_Line.To < Last then
Last := The_Line.To;
end if;
return Text (1 .. Last);
end;
end Non_Comment_Image;
end Asis.Text;
------------------------------------------------------------------------------
-- Copyright (c) 2006-2013, Maxim Reznik
-- 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 Maxim Reznik, 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 OWNER OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
|
-- This package has been generated automatically by GNATtest.
-- You are allowed to add your code to the bodies of test routines.
-- Such changes will be kept during further regeneration of this file.
-- All code placed outside of test routine bodies will be lost. The
-- code intended to set up and tear down the test environment should be
-- placed into Ships.Repairs.Test_Data.
with AUnit.Assertions; use AUnit.Assertions;
with System.Assertions;
-- begin read only
-- id:2.2/00/
--
-- This section can be used to add with clauses if necessary.
--
-- end read only
with Config; use Config;
with Ships.Crew; use Ships.Crew;
-- begin read only
-- end read only
package body Ships.Repairs.Test_Data.Tests is
-- begin read only
-- id:2.2/01/
--
-- This section can be used to add global variables and other elements.
--
-- end read only
-- begin read only
-- end read only
-- begin read only
procedure Wrap_Test_RepairShip_41c4af_831bda(Minutes: Positive) is
begin
GNATtest_Generated.GNATtest_Standard.Ships.Repairs.RepairShip(Minutes);
end Wrap_Test_RepairShip_41c4af_831bda;
-- end read only
-- begin read only
procedure Test_RepairShip_test_repairship(Gnattest_T: in out Test);
procedure Test_RepairShip_41c4af_831bda(Gnattest_T: in out Test) renames
Test_RepairShip_test_repairship;
-- id:2.2/41c4af333c446830/RepairShip/1/0/test_repairship/
procedure Test_RepairShip_test_repairship(Gnattest_T: in out Test) is
procedure RepairShip(Minutes: Positive) renames
Wrap_Test_RepairShip_41c4af_831bda;
-- end read only
pragma Unreferenced(Gnattest_T);
Durability: constant Positive := Player_Ship.Modules(1).Durability;
begin
Player_Ship.Cargo.Swap(5, 12);
Player_Ship.Cargo(10).Amount := 1;
Player_Ship.Modules(1).Durability := Durability - 1;
GiveOrders(Player_Ship, 4, Repair, 0, False);
RepairShip(15);
Assert
(Player_Ship.Modules(1).Durability = Durability,
"Failed to repair ship.");
New_Game_Settings.Player_Faction := To_Unbounded_String("POLEIS");
New_Game_Settings.Player_Career := To_Unbounded_String("general");
New_Game_Settings.Starting_Base := To_Unbounded_String("1");
New_Game;
-- begin read only
end Test_RepairShip_test_repairship;
-- end read only
-- begin read only
-- id:2.2/02/
--
-- This section can be used to add elaboration code for the global state.
--
begin
-- end read only
null;
-- begin read only
-- end read only
end Ships.Repairs.Test_Data.Tests;
|
-- SPDX-FileCopyrightText: 2020 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
----------------------------------------------------------------
with League.Regexps;
package body Markdown.Inline_Parsers.Autolinks is
function "+" (Text : Wide_Wide_String)
return League.Regexps.Regexp_Pattern
is (League.Regexps.Compile (League.Strings.To_Universal_String (Text)));
Absolute_URI : constant Wide_Wide_String :=
"[a-zA-Z][a-zA-Z0-9\+\.\-]+\:[^\ \t\n\v\f\r\<\>]*";
EMail : constant Wide_Wide_String :=
"[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^_\`\{\|\}\~\-]+" &
"\@[a-zA-Z0-9]" &
"([a-zA-Z0-9\-]{0,39}[a-zA-Z0-9])?" & -- s/39/61/
"(\.[a-zA-Z0-9]([a-zA-Z0-9\-]{0,39}[a-zA-Z0-9])?)*"; -- s/39/61/
Autolink_Pattern : constant Wide_Wide_String :=
"\<(" & Absolute_URI & "|(" & EMail & "))\>";
-- 1 2
Autolink : constant League.Regexps.Regexp_Pattern := +Autolink_Pattern;
----------
-- Find --
----------
procedure Find
(Text : Plain_Texts.Plain_Text;
Cursor : Position;
State : in out Optional_Inline_State)
is
Line : League.Strings.Universal_String := Text.Line (Cursor);
Offset : Natural := Cursor.Column - 1; -- Dropped characters count
Index : Positive := Cursor.Line;
begin
loop
declare
Match : constant League.Regexps.Regexp_Match :=
Autolink.Find_Match (Line);
begin
if not Match.Is_Matched then
exit when Index = Text.Last.Line;
Index := Index + 1;
Offset := 0;
Line := Text.Line (Index);
else
declare
Result : Optional_Inline_State (True);
URL : League.Strings.Universal_String :=
Match.Capture (1);
begin
if Match.First_Index (2) <= Match.Last_Index (2) then
URL.Prepend ("mailto:");
end if;
Result.Span.From := (Index, Match.First_Index + Offset);
Result.Span.To := (Index, Match.Last_Index + Offset);
Result.Value.Plain_Text.Append (Match.Capture (1));
Result.Value.Annotation.Append
((Kind => Markdown.Inline_Parsers.Link,
From => 1,
To => Result.Value.Plain_Text.Length,
Title => <>,
Destination => URL));
State := Result;
return;
end;
end if;
end;
end loop;
State := (Is_Set => False);
end Find;
end Markdown.Inline_Parsers.Autolinks;
|
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Maps; use Ada.Strings.Maps;
with Ada.Characters.Handling; use Ada.Characters.Handling;
procedure pangram is
function ispangram(txt: String) return Boolean is
(Is_Subset(To_Set(Span => ('a','z')), To_Set(To_Lower(txt))));
begin
put_line(Boolean'Image(ispangram("This is a test")));
put_line(Boolean'Image(ispangram("The quick brown fox jumps over the lazy dog")));
put_line(Boolean'Image(ispangram("NOPQRSTUVWXYZ abcdefghijklm")));
put_line(Boolean'Image(ispangram("abcdefghijklopqrstuvwxyz"))); --Missing m, n
end pangram;
|
------------------------------------------------------------------------------
-- --
-- GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . T A S K I N G . U T I L I T I E S --
-- --
-- S p e c --
-- --
-- $Revision: 2 $ --
-- --
-- Copyright (c) 1991,1992,1993,1994, FSU, All Rights Reserved --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU Library General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. GNARL is distributed in the hope that it will be use- --
-- ful, but but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Gen- --
-- eral Library Public License for more details. You should have received --
-- a copy of the GNU Library General Public License along with GNARL; see --
-- file COPYING.LIB. If not, write to the Free Software Foundation, 675 --
-- Mass Ave, Cambridge, MA 02139, USA. --
-- --
------------------------------------------------------------------------------
-- This package provides RTS Internal Declarations.
-- These declarations are not part of the GNARLI
with Unchecked_Conversion;
with System.Compiler_Exceptions;
-- Used for, Exception_ID
-- *** tbd added following line to get adadb access to system.task_primitives
with system.task_primitives;
package System.Tasking.Utilities is
-- Entry queue related types
type Server_Kind is (Task_Server, PO_Server);
type Server_Record (Kind : Server_Kind := Task_Server) is record
case Kind is
when Task_Server =>
Called_Task : Task_ID;
Acceptor_Prev_Call : Entry_Call_Link;
Acceptor_Prev_Priority : Rendezvous_Priority;
-- For a task servicing a task entry call,
-- information about the most recent prior call being serviced.
-- Not used for protected entry calls;
-- this function should be performed by GNULLI ceiling locking.
when PO_Server =>
Called_PO : Protection_Access;
end case;
end record;
-- Protected Objects related definitions
Null_PO : constant Protection_Access := null;
-- ATCB type definitions
type Ada_Task_Control_Block (Entry_Num : Task_Entry_Index);
type ATCB_Ptr is access Ada_Task_Control_Block;
All_Tasks_List : ATCB_Ptr;
All_Tasks_L : System.Task_Primitives.Lock;
-- All_Tasks_L should not be locked by a task that holds any other
-- locks; in other words, All_Tasks_L should be the outermost lock.
-- Currently, only ATCB locks are locked at the same time as All_Tasks_L.
function ID_To_ATCB is new
Unchecked_Conversion (Task_ID, ATCB_Ptr);
function ATCB_To_ID is new
Unchecked_Conversion (ATCB_Ptr, Task_ID);
function ATCB_To_Address is new
Unchecked_Conversion (ATCB_Ptr, System.Address);
type Task_Stage is (
Created,
-- Task has been created but has not begun activation.
Can_Activate,
-- Task has begin activation.
Active,
-- Task has completed activation and is executing the task body.
Await_Dependents,
-- Task is trying to complete a task master other than itself,
-- and is waiting for the tasks dependent on that master to become
-- passive (be complete, terminated, or be waiting on a terminate
-- alternative).
Passive,
-- The task is passive.
Completing,
-- The task is committed to becoming complete, but has not yet
-- satisfied all of the conditions for completion. This
-- acts as a claim to completion; once Stage is set to this value,
-- no other task can continue with completion.
Complete,
-- The task is complete. The task and all of its dependents are
-- passive; some dependents may still be waiting on terminate
-- alternatives.
Terminated);
-- The task is terminated. All dependents waiting on terminate
-- alternatives have been awakened and have terminated themselves.
type Accepting_State is (
Not_Accepting, -- task is not ready to accept any entry call
Trivial_Accept, -- "accept E;"
Simple_Accept, -- "accept E do ... end E;"
Select_Wait); -- most general case
type Entry_Call_Array is array (ATC_Level_Index) of
aliased Entry_Call_Record;
type Entry_Queue_Array is array (Task_Entry_Index range <>) of Entry_Queue;
-- Notes on protection (synchronization) of TRTS data structures.
-- Any field of the TCB can be written by the activator of a task when the
-- task is created, since no other task can access the new task's
-- state until creation is complete.
-- The protection for each field is described in a comment starting with
-- "Protection:".
-- When a lock is used to protect an ATCB field, this lock is simply named.
-- Some protection is described in terms of tasks related to the
-- ATCB being protected. These are:
-- Self: The task which is controlled by this ATCB.
-- Acceptor: A task accepting a call from Self.
-- Caller: A task calling an entry of Self.
-- Parent: The task executing the master on which Self depends.
-- Dependent: A task dependent on Self.
-- Activator: The task that created Self and initiated its activation.
-- Created: A task created and activated by Self.
type Ada_Task_Control_Block (Entry_Num : Task_Entry_Index) is record
LL_TCB : aliased System.Task_Primitives.Task_Control_Block;
-- Control block used by the underlying low-level tasking service
-- (GNULLI).
-- Protection: This is used only by the GNULLI implementation, which
-- takes care of all of its synchronization.
Task_Entry_Point : Task_Procedure_Access;
-- Information needed to call the procedure containing the code for
-- the body of this task.
-- Protection: Part of the synchronization between Self and
-- Activator. Activator writes it, once, before Self starts
-- executing. Self reads it, once, as part of its execution.
Task_Arg : System.Address;
-- The argument to to task procedure. Currently unused; this will
-- provide a handle for discriminant information.
-- Protection: Part of the synchronization between Self and
-- Activator. Activator writes it, once, before Self starts
-- executing. Thereafter, Self only reads it.
Stack_Size : Size_Type;
-- Requested stack size.
-- Protection: Only used by Self.
Current_Priority : System.Priority;
-- Active priority, except that the effects of protected object
-- priority ceilings are not reflected. This only reflects explicit
-- priority changes and priority inherited through task activation
-- and rendezvous.
-- Ada 95 notes: In Ada 95, this field will be transferred to the
-- Priority field of an Entry_Calls component when an entry call
-- is initiated. The Priority of the Entry_Calls component will not
-- change for the duration of the call. The accepting task can
-- use it to boost its own priority without fear of its changing in
-- the meantime.
-- This can safely be used in the priority ordering
-- of entry queues. Once a call is queued, its priority does not
-- change.
-- Since an entry call cannot be made while executing
-- a protected action, the priority of a task will never reflect a
-- priority ceiling change at the point of an entry call.
-- Protection: Only written by Self, and only accessed when Acceptor
-- accepts an entry or when Created activates, at which points Self is
-- suspended.
Base_Priority : System.Priority;
-- Base priority, not changed during entry calls, only changed
-- via dynamic priorities package.
-- Protection: Only written by Self, accessed by anyone.
New_Base_Priority : System.Priority;
-- New value for Base_Priority (for dynamic priorities package).
-- Protection: Self.L.
L : System.Task_Primitives.Lock;
-- General purpose lock; protects most fields in the ATCB.
Compiler_Data : System.Address;
-- Untyped task-specific data needed by the compiler to store
-- per-task structures.
-- Protection: Only accessed by Self.
-- the following declarations are for Rendezvous
Cond : System.Task_Primitives.Condition_Variable;
-- Used by Self to wait for a condition to become true.
-- It is invariant in the GNARL that a task waits only on its
-- own condition variable.
-- Protection: Condition variables are always associated with a lock.
-- The runtime places no restrictions on which lock is used, except
-- that it must protection the condition upon which the task is waiting.
All_Tasks_Link : ATCB_Ptr;
-- Used to link this task to the list of all tasks in the system.
-- Protection: All_Tasks.L.
Activation_Link : ATCB_Ptr;
-- Used to link this task to a list of tasks to be activated.
-- Protection: Only used by Activator.
Open_Accepts : Accept_List_Access;
-- This points to the Open_Accepts array of accept alternatives passed
-- to the RTS by the compiler-generated code to Selective_Wait.
-- Protection: Self.L.
Exception_To_Raise : System.Compiler_Exceptions.Exception_ID;
Exception_Address : System.Address;
-- An exception which should be raised by this task when it regains
-- control, and the address at which it should be raised.
-- Protection: Read only by Self, under circumstances where it will
-- be notified by the writer when it is safe to read it:
-- 1. Written by Acceptor, when Self is suspended.
-- 2. Written by Notify_Exception, executed by Self through a
-- synchronous signal handler, which redirects control to a
-- routine to read it and raise the exception.
Chosen_Index : Select_Index;
-- The index in Open_Accepts of the entry call accepted by a selective
-- wait executed by this task.
-- Protection: Written by both Self and Caller. Usually protected
-- by Self.L. However, once the selection is known to have been
-- written it can be accessed without protection. This happens
-- after Self has updated it itself using information from a suspended
-- Caller, or after Caller has updated it and awakened Self.
Call : Entry_Call_Link;
-- The entry call that has been accepted by this task.
-- Protection: Self.L. Self will modify this field
-- when Self.Accepting is False, and will not need the mutex to do so.
-- Once a task sets Stage=Completing, no other task can access this
-- field.
-- The following fields are used to manage the task's life cycle.
Activator : ATCB_Ptr;
-- The task that created this task, either by declaring it as a task
-- object or by executing a task allocator.
-- Protection: Set by Activator before Self is activated, and
-- read after Self is activated.
Parent : ATCB_Ptr;
Master_of_Task : Master_ID;
-- The task executing the master of this task, and the ID of this task's
-- master (unique only among masters currently active within Parent).
-- Protection: Set by Activator before Self is activated, and
-- read after Self is activated.
Master_Within : Master_ID;
-- The ID of the master currently executing within this task; that is,
-- the most deeply nested currently active master.
-- Protection: Only written by Self, and only read by Self or by
-- dependents when Self is attempting to exit a master. Since Self
-- will not write this field until the master is complete, the
-- synchronization should be adequate to prevent races.
Activation_Count : Integer;
-- This is the number of tasks that this task is activating, i.e. the
-- children that have started activation but have not completed it.
-- Protection: Self.L and Created.L. Both mutexes must be locked,
-- since Self.Activation_Count and Created.Stage must be synchronized.
Awake_Count : Integer;
-- Number of tasks dependent on this task (including this task) that are
-- still "awake": not terminated and not waiting on a terminate
-- alternative.
-- Protection: Self.L. Parent.L must also be locked when this is
-- updated, so that it can be synchronized with
-- Parent.Awaited_Dependent_Count, except under special circumstances
-- where we know that the two can be out of sync without allowing the
-- parent to terminate before its dependents.
Awaited_Dependent_Count : Integer;
-- This is the awake count of a master being completed by this task.
-- Protection: Self.L. Dependent.L must also be locked so that
-- this field and Dependent.Awake_Count can be synchronized, except
-- under special circumstances where we know that the two can be out
-- of sync without allowing the parent to terminate before its
-- dependents.
Terminating_Dependent_Count : Integer;
-- This is the count of tasks dependent on a master being completed by
-- this task which are waiting on a terminate alternative. Only valid
-- when there none of the dependents are awake.
-- Protection: Self.L.
Pending_Priority_Change : Boolean;
-- Flag to indicate pending priority change (for dynamic priorities
-- package). The base priority is updated on the next abortion
-- completion point (aka. synchronization point).
-- Protection: Self.L.
Pending_Action : Boolean;
-- Unified flag indicating pending action on abortion completion
-- point (aka. synchronization point). Currently set if:
-- . Pending_Priority_Change is set or
-- . Pending_ATC_Level is changed.
-- Protection: Self.L.
Pending_ATC_Level : ATC_Level_Base;
-- The ATC level to which this task is currently being aborted.
-- Protection: Self.L.
ATC_Nesting_Level : ATC_Level;
-- The dynamic level of ATC nesting (currently executing nested
-- asynchronous select statements) in this task.
-- Protection: This is only used by Self. However, decrementing it
-- in effect deallocates an Entry_Calls component, and care must be
-- taken that all references to that component are eliminated before
-- doing the decrement. This in turn will probably required locking
-- a protected object (for a protected entry call) or the Acceptor's
-- lock (for a task entry call). However, ATC_Nesting_Level itself can
-- be accessed without a lock.
Deferral_Level : Natural;
-- This is the number of times that Defer_Abortion has been called by
-- this task without a matching Undefer_Abortion call. Abortion is
-- only allowed when this zero.
-- Protection: Only updated by Self; access assumed to be atomic.
Elaborated : Access_Boolean;
-- Pointer to a flag indicating that this task's body has been
-- elaborated. The flag is created and managed by the
-- compiler-generated code.
-- Protection: The field itself is only accessed by Activator. The flag
-- that it points to is updated by Master and read by Activator; access
-- is assumed to be atomic.
Stage : Task_Stage;
-- The general stage of the task in it's life cycle.
-- Protection: Self.L.
-- beginning of flags
Cancel_Was_Successful : Boolean;
-- This indicates that the last attempt to cancel an entry call was
-- successful. It needs to be accurate between a call to
-- *Cancel_*_Entry_Call and the following call to Complete_*_Entry_Call.
-- These calls cannot be nested; that is, there can be no intervening
-- *Cancel_*_Entry_Call, so this single field is adequate.
-- Protection: Accessed only by Self.
Accepting : Accepting_State;
-- The ability of this task to accept an entry call.
-- Protection: Self.L.
Aborting : Boolean;
-- Self is in the process of aborting. While set, prevents multiple
-- abortion signals from being sent by different aborter while abortion
-- is acted upon. This is essential since an aborter which calls
-- Abort_To_Level could set the Pending_ATC_Level to yet a lower level
-- (than the current level), may be preempted and would send the
-- abortion signal when resuming execution. At this point, the abortee
-- may have completed abortion to the proper level such that the
-- signal (and resulting abortion exception) are not handled any more.
-- In other words, the flag prevents a race between multiple aborters
-- and the abortee.
-- Protection: Self.L.
Suspended_Abortably : Boolean;
-- Task is suspended with (low-level) abortion deferred, but is
-- abortable. This means that the task must be awakened to perform
-- its own abortion.
-- Protection: Self.L.
-- end of flags
Entry_Calls : Entry_Call_Array;
-- An array of entry calls.
-- Protection: The elements of this array are on entry call queues
-- associated with protected objects or task entries, and are protected
-- by the protected object lock or Acceptor.L, respectively.
Entry_Queues : Entry_Queue_Array (1 .. Entry_Num);
-- An array of task entry queues.
-- Protection: Self.L. Once a task has set Self.Stage to Completing, it
-- has exclusive access to this field.
Aborter_Link : ATCB_Ptr;
-- Link to the list of tasks which tries to abort this task but
-- blocked by another aborter who has already been aborting the task.
Terminate_Alternative : Boolean;
-- Task is accepting Select with Terminate Alternative.
end record;
-- The following record holds the information used to initialize a task
type ATCB_Init is record
Task_Entry_Point : Task_Procedure_Access;
Task_Arg : System.Address;
Stack_Size : Size_Type;
Activator : ATCB_Ptr;
Parent : ATCB_Ptr;
Master_of_Task : Master_ID;
Elaborated : Access_Boolean;
Entry_Num : Task_Entry_Index;
Priority : System.Priority;
end record;
procedure Vulnerable_Complete_Activation
(T : ATCB_Ptr;
Completed : Boolean);
-- Completes the activation by signaling its children.
-- Completed indicates a call when the task has completed.
-- Does not defer abortion (unlike Complete_Activation).
procedure Check_Exception;
-- Raises an exception pending on Self.
-- Used to delay exceptions until abortion is undeferred.
---------------------------------
-- Rendezvous related routines --
---------------------------------
procedure Close_Entries (Target : Task_ID);
-- Close entries, purge entry queues (called by Task_Stages.Complete)
-- T.Stage must be Completing before this is called.
procedure Complete_on_Sync_Point (T : Task_ID);
-- If a task is suspended on an accept, select, or entry call
-- (but not yet *in* rendezvous) then complete the task.
procedure Reset_Priority
(Acceptor_Prev_Priority : Rendezvous_Priority;
Acceptor : Task_ID);
pragma Inline (Reset_Priority);
-- Reset the priority of a task completing an accept statement to
-- the value it had before the call.
procedure Terminate_Alternative;
-- Called when terminate alternative is selected.
-- Waits for the parent to terminate the task
-- or a caller to select an accept alternative.
-- Assumes that abortion is deferred when called.
procedure Complete (Target : Task_ID);
-- Complete task and act on pending abortion.
---------------------------------
-- Task_Stage Related routines --
---------------------------------
procedure Make_Independent;
-- Remove a task from the master hierarchy. This includes setting the
-- master ID to zero (no master) and removing the task from the
-- All_Tasks_List (which is used to search for masters and dependents).
-- No master will wait on the termination of an independent task;
-- such tasks may still be running when the program terminates, at which
-- point they will be killed by the underlying operating system.
-- This is a dangerous operation, and should only be used on tasks
-- that require no finalization. Independent tasks are intended only
-- for internal use by the GNARL, to prevent such internal tasks from
-- preventing a user task from terminating.
------------------------------------
-- Task Abortion related routines --
------------------------------------
procedure Abort_To_Level (Target : Task_ID; L : ATC_Level);
-- Abort a task to a specified ATC level.
procedure Abort_Handler (Context : System.Task_Primitives.Pre_Call_State);
-- Handler to be installed at initialization; it is invoked by a task
-- when it is the target of an Abort_Task low-level operation.
procedure Abort_Dependents (Abortee : Task_ID);
-- Propagate the abortion of a parent into its children.
procedure Remove_From_All_Tasks_List
(Source : Utilities.ATCB_Ptr; Result : out Boolean);
-- Remove an entry from the All_Tasks_List.
end System.Tasking.Utilities;
|
--
-- Copyright (C) 2015-2016 secunet Security Networks AG
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
with HW.GFX.GMA.Registers;
with HW.Debug;
with GNAT.Source_Info;
package body HW.GFX.GMA.GMCH.HDMI
is
GMCH_HDMI_ENABLE : constant := 1 * 2 ** 31;
GMCH_HDMI_COLOR_FORMAT_8BPC : constant := 0 * 2 ** 26;
GMCH_HDMI_COLOR_FORMAT_12BPC : constant := 3 * 2 ** 26;
GMCH_HDMI_COLOR_FORMAT_MASK : constant := 7 * 2 ** 26;
GMCH_HDMI_SDVO_ENCODING_SDVO : constant := 0 * 2 ** 10;
GMCH_HDMI_SDVO_ENCODING_HDMI : constant := 2 * 2 ** 10;
GMCH_HDMI_SDVO_ENCODING_MASK : constant := 3 * 2 ** 10;
GMCH_HDMI_MODE_SELECT_HDMI : constant := 1 * 2 ** 9;
GMCH_HDMI_MODE_SELECT_DVI : constant := 0 * 2 ** 9;
GMCH_HDMI_VSYNC_ACTIVE_HIGH : constant := 1 * 2 ** 4;
GMCH_HDMI_HSYNC_ACTIVE_HIGH : constant := 1 * 2 ** 3;
GMCH_HDMI_PORT_DETECT : constant := 1 * 2 ** 2;
GMCH_HDMI_MASK : constant Word32 :=
GMCH_PORT_PIPE_SELECT_MASK or
GMCH_HDMI_ENABLE or
GMCH_HDMI_COLOR_FORMAT_MASK or
GMCH_HDMI_SDVO_ENCODING_MASK or
GMCH_HDMI_MODE_SELECT_HDMI or
GMCH_HDMI_HSYNC_ACTIVE_HIGH or
GMCH_HDMI_VSYNC_ACTIVE_HIGH;
type GMCH_HDMI_Array is array (GMCH_HDMI_Port) of Registers.Registers_Index;
GMCH_HDMI : constant GMCH_HDMI_Array := GMCH_HDMI_Array'
(DIGI_B => Registers.GMCH_HDMIB,
DIGI_C => Registers.GMCH_HDMIC);
----------------------------------------------------------------------------
procedure On (Port_Cfg : in Port_Config;
Pipe : in Pipe_Index)
is
Polarity : constant Word32 :=
(if Port_Cfg.Mode.H_Sync_Active_High then
GMCH_HDMI_HSYNC_ACTIVE_HIGH else 0) or
(if Port_Cfg.Mode.V_Sync_Active_High then
GMCH_HDMI_VSYNC_ACTIVE_HIGH else 0);
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
Registers.Unset_And_Set_Mask
(Register => GMCH_HDMI (Port_Cfg.Port),
Mask_Unset => GMCH_HDMI_MASK,
Mask_Set => GMCH_HDMI_ENABLE or
GMCH_PORT_PIPE_SELECT (Pipe) or
GMCH_HDMI_SDVO_ENCODING_HDMI or
GMCH_HDMI_MODE_SELECT_DVI or
Polarity);
end On;
----------------------------------------------------------------------------
procedure Off (Port : GMCH_HDMI_Port)
is
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
Registers.Unset_And_Set_Mask
(Register => GMCH_HDMI (Port),
Mask_Unset => GMCH_HDMI_MASK,
Mask_Set => GMCH_HDMI_HSYNC_ACTIVE_HIGH or
GMCH_HDMI_VSYNC_ACTIVE_HIGH);
end Off;
procedure All_Off
is
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
for Port in GMCH_HDMI_Port loop
Off (Port);
end loop;
end All_Off;
end HW.GFX.GMA.GMCH.HDMI;
|
with Ada.Text_IO;
package body Eval is
procedure Show (E : in Expr) is
begin
case E.Kind is
when Add =>
Ada.Text_IO.Put ("Add(");
when Sub =>
Ada.Text_IO.Put ("Sub(");
when Mul =>
Ada.Text_IO.Put ("Mul(");
when Div =>
Ada.Text_IO.Put ("Div(");
when Val =>
Ada.Text_IO.Put (Image (E.Val));
return;
end case;
Show (E.Left.all);
Ada.Text_IO.Put (", ");
Show (E.Right.all);
Ada.Text_IO.Put (")");
end Show;
function Eval (E : in Expr) return T is
begin
case E.Kind is
when Val =>
return E.Val;
when Add =>
return Eval (E.Left.all) + Eval (E.Right.all);
when Sub =>
return Eval (E.Left.all) - Eval (E.Right.all);
when Mul =>
return Eval (E.Left.all) * Eval (E.Right.all);
when Div =>
return Eval (E.Left.all) / Eval (E.Right.all);
end case;
end Eval;
end Eval;
|
--- { dg-do run }
with Atomic7_Pkg1; use Atomic7_Pkg1;
procedure Atomic7_2 is
begin
if I /= 1 then
raise Program_Error;
end if;
end;
|
------------------------------------------------------------------------
--
-- Copyright (c) 2018, Brendan T Malone All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
------------------------------------------------------------------------
------------------------------------------------------------------------
--
-- Ada support for leveled logs. Based on Google's glog
--
------------------------------------------------------------------------
with GNAT.Source_Info;
with Ada.Containers.Hashed_Maps;
with Ada.Strings.Unbounded.Hash;
package Alog is
package ASU renames Ada.Strings.Unbounded;
-- Four levels of loggging.
type Level is (
INFO,
WARN,
ERROR,
FATAL
);
-- Type representing where things are logged to.
type LogTo is (
NONE,
STDOUT,
FILE,
BOTH
);
---------------------------------------------------------------------
-- Logging
---------------------------------------------------------------------
-- Methods for each log message level.
procedure Info (Msg : String);
procedure Warn (Msg : String);
procedure Error (Msg : String);
procedure Fatal (Msg : String);
procedure Vlog (Lvl : Natural;
Msg : String;
Source : String := GNAT.Source_Info.Source_Location);
---------------------------------------------------------------------
-- Configuration
---------------------------------------------------------------------
-- Set where the logs saved. By default set to BOTH.
procedure Set_LogTo (Output : LogTo);
-- Helper method to you can pass a String representation of LogTo.
procedure Set_LogTo (Output : String);
-- Set what the threshold level of stdout will be.
procedure Set_Stdout_Threshold (Lvl : Level);
-- Helper method to you can pass a String representation of Level.
procedure Set_Stdout_Threshold (Lvl : String);
-- Set where the log files shoudl be saved.
procedure Set_File_Path (Path : String);
-- Set the Vlog Threshold.
procedure Set_Vlog_Threshold (Lvl : Natural);
-- blah
procedure Set_Vlog_Modules (Mods : String);
---------------------------------------------------------------------
-- Statistics
---------------------------------------------------------------------
-- Return the number of lines written to a specified log file.
function Lines (Lvl : Level) return Natural;
private
-- Record of statistics about the log levels.
type Level_Stats is record
Lines : Natural := 0;
end record;
-- Array of level stats for each log level.
type Log_Stats is array (Level) of Level_Stats;
Stats : Log_Stats;
function Program_Name (Cmd : String) return String;
function Program_Time (Time : String) return String;
function Format_Module (Source : String) return String;
procedure Vmodule_Setup (Mods : String);
Files_Created : Boolean := False;
Files_Location_Set : Boolean := False;
function Equivalent_Strings (Left, Right : ASU.Unbounded_String)
return Boolean;
package Module is new Ada.Containers.Hashed_Maps
(Key_Type => ASU.Unbounded_String,
Element_Type => Natural,
Hash => ASU.Hash,
Equivalent_Keys => Equivalent_Strings);
Modules_Map : Module.Map;
end Alog;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2020 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with Ada.Finalization;
package EGL.Objects is
pragma Preelaborate;
type EGL_Object is abstract new Ada.Finalization.Controlled with private;
overriding procedure Initialize (Object : in out EGL_Object);
overriding procedure Adjust (Object : in out EGL_Object);
overriding procedure Finalize (Object : in out EGL_Object);
function ID (Object : EGL_Object) return ID_Type;
function Is_Initialized (Object : EGL_Object) return Boolean;
procedure Post_Initialize (Object : in out EGL_Object) is null;
procedure Pre_Finalize (Object : in out EGL_Object) is null;
overriding
function "=" (Left, Right : EGL_Object) return Boolean;
private
type EGL_Object_Reference is record
ID : ID_Type;
Count : Natural with Atomic;
Active : Boolean with Atomic;
-- Currently only used for contexts to record whether context
-- is current on any task
end record;
type EGL_Object_Reference_Access is access all EGL_Object_Reference;
type EGL_Object is abstract new Ada.Finalization.Controlled with record
Reference : EGL_Object_Reference_Access;
end record;
end EGL.Objects;
|
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr>
-- MIT license. Please refer to the LICENSE file.
generic
with procedure Work (Obj : Test_Node_Interfa'Class;
Outcome : out Test_Outcome;
Kind : Run_Kind);
procedure Apsepp.Test_Node_Class.Generic_Case_And_Suite_Run_Body
(Obj : Test_Node_Interfa'Class;
Outcome : out Test_Outcome;
Kind : Run_Kind;
Cond : not null access function return Boolean);
|
pragma License (Unrestricted);
-- implementation unit
package System.Long_Long_Float_Types is
pragma Pure;
procedure Divide (
Left, Right : Long_Long_Float;
Quotient, Remainder : out Long_Long_Float);
end System.Long_Long_Float_Types;
|
type Banana is new Food with null record;
overriding procedure Eat (Object : in out Banana) is null;
package Banana_Box is new Food_Boxes (Banana);
type Tomato is new Food with null record;
overriding procedure Eat (Object : in out Tomato) is null;
package Tomato_Box is new Food_Boxes (Tomato);
-- We have declared Banana and Tomato as a Food.
|
package body AFRL.CMASI.AutomationResponse.SPARK_Boundary with SPARK_Mode => Off is
--------------------
-- Get_WaypointEntity_Set --
--------------------
function Get_WaypointEntity_Set
(Response : AutomationResponse) return Int64_Set
is
L : constant Vect_MissionCommand_Acc_Acc := Response.getMissionCommandList;
begin
return R : Int64_Set do
for E of L.all loop
Int64_Sets.Include (R, E.getVehicleID);
end loop;
end return;
end Get_WaypointEntity_Set;
end AFRL.CMASI.AutomationResponse.SPARK_Boundary;
|
With
NSO.JSON,
Ada.Containers.Ordered_Maps,
Ada.Calendar,
Gnoga.Gui.Base,
Gnoga.Gui.Element.Form,
Gnoga.Gui.Element.Common;
Limited with
Report_Form;
Package NSO.Types.Report_Objects.Observation_Report with Elaborate_Body is
Package Instrument_Mode_Pkg is new Ada.Containers.Indefinite_Ordered_Maps(
"<" => Ada.Strings.Less_Case_Insensitive,
"=" => String_Set."=",
Key_Type => String,
Element_Type => String_Set.Set
);
-------------------
-- REPORT DATA --
-------------------
Subtype Report_Data is Instrument_Mode_Pkg.Map;
-- record
-- Frequency : String_Vector.Vector:= String_Vector.Empty_Vector;
-- End record;
------------------
-- REPORT MAP --
------------------
Package Report_Map is new Ada.Containers.Indefinite_Ordered_Maps(
"=" => Instrument_Mode_Pkg."=",
"<" => Ada.Calendar."<",
Key_Type => Ada.Calendar.Time,
Element_Type => Report_Data
);
----------------------------------------
-- OBSERVATION REPORT GNOGA ELEMENT --
----------------------------------------
Type Observation_Report is new Abstract_Report with record
--Gnoga.Gui.Element.Common.DIV_Type with
Date : Gnoga.Gui.Element.Form.Date_Type;
Time : Gnoga.Gui.Element.Form.Time_Type;
end record;
overriding
procedure Create (Report : in out Observation_Report;
Parent : in out Gnoga.Gui.Base.Base_Type'Class;
Content : in String := "";
ID : in String := "" );
overriding
procedure Add_Self(
Self : in Observation_Report;
Form : in out Gnoga.Gui.Element.Form.Form_Type'Class
);
Function Report( Data : JSON.Instance'Class ) return Report_Map.Map;
Function Report( Object : Report_Map.Map ) return String;
Private
Overriding Function Get_Name( Self : Observation_Report ) return String;
End NSO.Types.Report_Objects.Observation_Report;
|
with Ada.Real_Time;
with ACO.Utils.Generic_Event;
with ACO.Messages;
with ACO.States;
with ACO.SDO_Sessions;
with ACO.OD_Types;
with ACO.Configuration;
package ACO.Events is
use ACO.Configuration;
type Handler_Event_Type is
(Tick,
Received_Message);
type Handler_Event_Data
(Event : Handler_Event_Type := Tick)
is record
case Event is
when Tick =>
Current_Time : Ada.Real_Time.Time;
when Received_Message =>
Msg : ACO.Messages.Message;
end case;
end record;
package HEP is new ACO.Utils.Generic_Event
(Item_Type => Handler_Event_Data,
Max_Nof_Subscribers => Max_Nof_Handler_Event_Subscribers,
Max_Nof_Queued_Events => Max_Nof_Event_Queue_Data_Items);
type Handler_Event_Listener
(Event : Handler_Event_Type)
is abstract new HEP.Subscriber with null record;
overriding
procedure Update
(This : access Handler_Event_Listener;
Data : in Handler_Event_Data);
procedure On_Event
(This : in out Handler_Event_Listener;
Data : in Handler_Event_Data) is abstract;
type Handler_Event_Manager is tagged limited record
Handler_Events : HEP.Event_Publisher;
end record;
type Event_Type is
(State_Transition,
Slave_State_Transition,
OD_Entry_Update,
Heartbeat_Received,
Heartbeat_Timed_Out,
SDO_Status_Update);
type Heartbeat_Data is record
Id : ACO.Messages.Node_Nr;
State : ACO.States.State;
end record;
type SDO_Status_Data is record
Endpoint_Id : ACO.SDO_Sessions.Endpoint_Nr;
Result : ACO.SDO_Sessions.SDO_Result;
end record;
type Slave_State_Data is record
State : ACO.States.State_Transition;
Node_Id : ACO.Messages.Node_Nr;
end record;
type Event_Data
(Event : Event_Type := State_Transition)
is record
case Event is
when State_Transition =>
State : ACO.States.State_Transition;
when Slave_State_Transition =>
Slave : Slave_State_Data;
when OD_Entry_Update =>
Index : ACO.OD_Types.Entry_Index;
when Heartbeat_Received =>
Received_Heartbeat : Heartbeat_Data;
when Heartbeat_Timed_Out =>
Node_Id : ACO.Messages.Node_Nr;
when SDO_Status_Update =>
SDO_Status : SDO_Status_Data;
end case;
end record;
package EP is new ACO.Utils.Generic_Event
(Item_Type => Event_Data,
Max_Nof_Subscribers => Max_Nof_Node_Event_Subscribers,
Max_Nof_Queued_Events => Max_Nof_Event_Queue_Data_Items);
type Event_Listener
(Event : Event_Type)
is abstract new EP.Subscriber with null record;
overriding
procedure Update
(This : access Event_Listener;
Data : in Event_Data);
procedure On_Event
(This : in out Event_Listener;
Data : in Event_Data) is abstract;
type Node_Event_Manager is tagged limited record
Node_Events : EP.Queued_Event_Publisher
(Priority_Ceiling => Event_Queue_Ceiling);
end record;
procedure Process
(This : in out Node_Event_Manager);
end ACO.Events;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- T R E E _ I O --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package contains the routines used to read and write the tree files
-- used by ASIS. Only the actual read and write routines are here. The open,
-- create and close routines are elsewhere (in Osint in the compiler, and in
-- the tree read driver for the tree read interface).
with Types; use Types;
with System; use System;
pragma Warnings (Off);
-- This package is used also by gnatcoll
with System.OS_Lib; use System.OS_Lib;
pragma Warnings (On);
package Tree_IO is
Tree_Format_Error : exception;
-- Raised if a format error is detected in the input file
ASIS_Version_Number : constant := 34;
-- ASIS Version. This is used to check for consistency between the compiler
-- used to generate trees and an ASIS application that is reading the
-- trees. It must be incremented whenever a change is made to the tree
-- format that would result in the compiler being incompatible with an
-- older version of ASIS.
--
-- 27 Changes in the tree structures for expression functions
-- 28 Changes in Snames
-- 29 Changes in Sem_Ch3 (tree copying in case of discriminant constraint
-- for concurrent types).
-- 30 Add Check_Float_Overflow boolean to tree file
-- 31 Remove read/write of Debug_Pragmas_Disabled/Debug_Pragmas_Enabled
-- 32 Change the way entities are changed through Next_Entity field in
-- the hierarchy of child units
-- 33 Add copying subtrees for rewriting infix calls of operator
-- functions for the corresponding original nodes.
-- 34 Add read/write of Address_Is_Private, Ignore_Rep_Clauses,
-- Ignore_Style_Check_Pragmas, Multiple_Unit_Index. Also this
-- is the version where rep clauses are removed by -gnatI.
procedure Tree_Read_Initialize (Desc : File_Descriptor);
-- Called to initialize reading of a tree file. This call must be made
-- before calls to Tree_Read_xx. No calls to Tree_Write_xx are permitted
-- after this call.
procedure Tree_Read_Data (Addr : Address; Length : Int);
-- Checks that the Length provided is the same as what has been provided
-- to the corresponding Tree_Write_Data from the current tree file,
-- Tree_Format_Error is raised if it is not the case. If Length is
-- correct and non zero, reads Length bytes of information into memory
-- starting at Addr from the current tree file.
procedure Tree_Read_Bool (B : out Boolean);
-- Reads a single boolean value. The boolean value must have been written
-- with a call to the Tree_Write_Bool procedure.
procedure Tree_Read_Char (C : out Character);
-- Reads a single character. The character must have been written with a
-- call to the Tree_Write_Char procedure.
procedure Tree_Read_Int (N : out Int);
-- Reads a single integer value. The integer must have been written with
-- a call to the Tree_Write_Int procedure.
procedure Tree_Read_Str (S : out String_Ptr);
-- Read string, allocate on heap, and return pointer to allocated string
-- which always has a lower bound of 1.
procedure Tree_Read_Terminate;
-- Called after reading all data, checks that the buffer pointers is at
-- the end of file, raising Tree_Format_Error if not.
procedure Tree_Write_Initialize (Desc : File_Descriptor);
-- Called to initialize writing of a tree file. This call must be made
-- before calls to Tree_Write_xx. No calls to Tree_Read_xx are permitted
-- after this call.
procedure Tree_Write_Data (Addr : Address; Length : Int);
-- Writes Length then, if Length is not null, Length bytes of data
-- starting at Addr to current tree file
procedure Tree_Write_Bool (B : Boolean);
-- Writes a single boolean value to the current tree file
procedure Tree_Write_Char (C : Character);
-- Writes a single character to the current tree file
procedure Tree_Write_Int (N : Int);
-- Writes a single integer value to the current tree file
procedure Tree_Write_Str (S : String_Ptr);
-- Write out string value referenced by S (low bound of S must be 1)
procedure Tree_Write_Terminate;
-- Terminates writing of the file (flushing the buffer), but does not
-- close the file (the caller is responsible for closing the file).
end Tree_IO;
|
package body Mergesort is
-----------
-- Merge --
-----------
function Merge(Left, Right : Collection_Type) return Collection_Type is
Result : Collection_Type(Left'First..Right'Last);
Left_Index : Index_Type := Left'First;
Right_Index : Index_Type := Right'First;
Result_Index : Index_Type := Result'First;
begin
while Left_Index <= Left'Last and Right_Index <= Right'Last loop
if Left(Left_Index) <= Right(Right_Index) then
Result(Result_Index) := Left(Left_Index);
Left_Index := Index_Type'Succ(Left_Index); -- increment Left_Index
else
Result(Result_Index) := Right(Right_Index);
Right_Index := Index_Type'Succ(Right_Index); -- increment Right_Index
end if;
Result_Index := Index_Type'Succ(Result_Index); -- increment Result_Index
end loop;
if Left_Index <= Left'Last then
Result(Result_Index..Result'Last) := Left(Left_Index..Left'Last);
end if;
if Right_Index <= Right'Last then
Result(Result_Index..Result'Last) := Right(Right_Index..Right'Last);
end if;
return Result;
end Merge;
----------
-- Sort --
----------
function Sort (Item : Collection_Type) return Collection_Type is
Result : Collection_Type(Item'range);
Middle : Index_Type;
begin
if Item'Length <= 1 then
return Item;
else
Middle := Index_Type'Val((Item'Length / 2) + Index_Type'Pos(Item'First));
declare
Left : Collection_Type(Item'First..Index_Type'Pred(Middle));
Right : Collection_Type(Middle..Item'Last);
begin
for I in Left'range loop
Left(I) := Item(I);
end loop;
for I in Right'range loop
Right(I) := Item(I);
end loop;
Left := Sort(Left);
Right := Sort(Right);
Result := Merge(Left, Right);
end;
return Result;
end if;
end Sort;
end Mergesort;
|
pragma Ada_2012;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with bits_struct_mutex_h;
with bits_thread_shared_types_h;
with bits_struct_rwlock_h;
package bits_pthreadtypes_h is
-- Declaration of common pthread types for all architectures.
-- Copyright (C) 2017-2021 Free Software Foundation, Inc.
-- This file is part of the GNU C Library.
-- The GNU C Library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
-- The GNU C Library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
-- You should have received a copy of the GNU Lesser General Public
-- License along with the GNU C Library; if not, see
-- <https://www.gnu.org/licenses/>.
-- For internal mutex and condition variable definitions.
-- Thread identifiers. The structure of the attribute type is not
-- exposed on purpose.
subtype pthread_t is unsigned_long; -- /usr/include/bits/pthreadtypes.h:27
-- Data structures for mutex handling. The structure of the attribute
-- type is not exposed on purpose.
-- skipped anonymous struct anon_8
subtype pthread_mutexattr_t_array1001 is Interfaces.C.char_array (0 .. 3);
type pthread_mutexattr_t (discr : unsigned := 0) is record
case discr is
when 0 =>
uu_size : aliased pthread_mutexattr_t_array1001; -- /usr/include/bits/pthreadtypes.h:34
when others =>
uu_align : aliased int; -- /usr/include/bits/pthreadtypes.h:35
end case;
end record
with Convention => C_Pass_By_Copy,
Unchecked_Union => True; -- /usr/include/bits/pthreadtypes.h:36
-- Data structure for condition variable handling. The structure of
-- the attribute type is not exposed on purpose.
-- skipped anonymous struct anon_9
subtype pthread_condattr_t_array1001 is Interfaces.C.char_array (0 .. 3);
type pthread_condattr_t (discr : unsigned := 0) is record
case discr is
when 0 =>
uu_size : aliased pthread_condattr_t_array1001; -- /usr/include/bits/pthreadtypes.h:43
when others =>
uu_align : aliased int; -- /usr/include/bits/pthreadtypes.h:44
end case;
end record
with Convention => C_Pass_By_Copy,
Unchecked_Union => True; -- /usr/include/bits/pthreadtypes.h:45
-- Keys for thread-specific data
subtype pthread_key_t is unsigned; -- /usr/include/bits/pthreadtypes.h:49
-- Once-only execution
subtype pthread_once_t is int; -- /usr/include/bits/pthreadtypes.h:53
subtype pthread_attr_t_array1009 is Interfaces.C.char_array (0 .. 55);
type pthread_attr_t (discr : unsigned := 0) is record
case discr is
when 0 =>
uu_size : aliased pthread_attr_t_array1009; -- /usr/include/bits/pthreadtypes.h:58
when others =>
uu_align : aliased long; -- /usr/include/bits/pthreadtypes.h:59
end case;
end record
with Convention => C_Pass_By_Copy,
Unchecked_Union => True; -- /usr/include/bits/pthreadtypes.h:56
-- skipped anonymous struct anon_10
subtype pthread_mutex_t_array1014 is Interfaces.C.char_array (0 .. 39);
type pthread_mutex_t (discr : unsigned := 0) is record
case discr is
when 0 =>
uu_data : aliased bits_struct_mutex_h.uu_pthread_mutex_s; -- /usr/include/bits/pthreadtypes.h:69
when 1 =>
uu_size : aliased pthread_mutex_t_array1014; -- /usr/include/bits/pthreadtypes.h:70
when others =>
uu_align : aliased long; -- /usr/include/bits/pthreadtypes.h:71
end case;
end record
with Convention => C_Pass_By_Copy,
Unchecked_Union => True; -- /usr/include/bits/pthreadtypes.h:72
-- skipped anonymous struct anon_11
subtype pthread_cond_t_array1018 is Interfaces.C.char_array (0 .. 47);
type pthread_cond_t (discr : unsigned := 0) is record
case discr is
when 0 =>
uu_data : aliased bits_thread_shared_types_h.uu_pthread_cond_s; -- /usr/include/bits/pthreadtypes.h:77
when 1 =>
uu_size : aliased pthread_cond_t_array1018; -- /usr/include/bits/pthreadtypes.h:78
when others =>
uu_align : aliased Long_Long_Integer; -- /usr/include/bits/pthreadtypes.h:79
end case;
end record
with Convention => C_Pass_By_Copy,
Unchecked_Union => True; -- /usr/include/bits/pthreadtypes.h:80
-- Data structure for reader-writer lock variable handling. The
-- structure of the attribute type is deliberately not exposed.
-- skipped anonymous struct anon_12
subtype pthread_rwlock_t_array1009 is Interfaces.C.char_array (0 .. 55);
type pthread_rwlock_t (discr : unsigned := 0) is record
case discr is
when 0 =>
uu_data : aliased bits_struct_rwlock_h.uu_pthread_rwlock_arch_t; -- /usr/include/bits/pthreadtypes.h:88
when 1 =>
uu_size : aliased pthread_rwlock_t_array1009; -- /usr/include/bits/pthreadtypes.h:89
when others =>
uu_align : aliased long; -- /usr/include/bits/pthreadtypes.h:90
end case;
end record
with Convention => C_Pass_By_Copy,
Unchecked_Union => True; -- /usr/include/bits/pthreadtypes.h:91
-- skipped anonymous struct anon_13
subtype pthread_rwlockattr_t_array1024 is Interfaces.C.char_array (0 .. 7);
type pthread_rwlockattr_t (discr : unsigned := 0) is record
case discr is
when 0 =>
uu_size : aliased pthread_rwlockattr_t_array1024; -- /usr/include/bits/pthreadtypes.h:95
when others =>
uu_align : aliased long; -- /usr/include/bits/pthreadtypes.h:96
end case;
end record
with Convention => C_Pass_By_Copy,
Unchecked_Union => True; -- /usr/include/bits/pthreadtypes.h:97
-- POSIX spinlock data type.
subtype pthread_spinlock_t is int; -- /usr/include/bits/pthreadtypes.h:103
-- POSIX barriers data type. The structure of the type is
-- deliberately not exposed.
-- skipped anonymous struct anon_14
subtype pthread_barrier_t_array1030 is Interfaces.C.char_array (0 .. 31);
type pthread_barrier_t (discr : unsigned := 0) is record
case discr is
when 0 =>
uu_size : aliased pthread_barrier_t_array1030; -- /usr/include/bits/pthreadtypes.h:110
when others =>
uu_align : aliased long; -- /usr/include/bits/pthreadtypes.h:111
end case;
end record
with Convention => C_Pass_By_Copy,
Unchecked_Union => True; -- /usr/include/bits/pthreadtypes.h:112
-- skipped anonymous struct anon_15
subtype pthread_barrierattr_t_array1001 is Interfaces.C.char_array (0 .. 3);
type pthread_barrierattr_t (discr : unsigned := 0) is record
case discr is
when 0 =>
uu_size : aliased pthread_barrierattr_t_array1001; -- /usr/include/bits/pthreadtypes.h:116
when others =>
uu_align : aliased int; -- /usr/include/bits/pthreadtypes.h:117
end case;
end record
with Convention => C_Pass_By_Copy,
Unchecked_Union => True; -- /usr/include/bits/pthreadtypes.h:118
end bits_pthreadtypes_h;
|
-- $Id: General.md,v 1.5 1994/06/13 09:41:43 grosch rel $
-- $Log: General.md,v $
-- Ich, Doktor Josef Grosch, Informatiker, Aug. 1994
-- General Subroutines: minimum, maximum, binary logarithm, and power of 2
package General is
type ForAlign is record char: Character; longreal: Long_Float; end record;
MaxAlign : constant Integer := ForAlign'size - Long_Float'size;
AlignMask : Integer := 0;
function Min (a, b: Integer) return Integer;
-- Returns the minimum of 'a' and 'b'.
function Max (a, b: Integer) return Integer;
-- Returns the maximum of 'a' and 'b'.
function Log2 (x: Integer) return Integer;
-- Returns the logarithm to the base 2 of 'x'.
function Exp2 (x: Integer) return Integer;
-- Returns 2 to the power of 'x'.
function AntiLog (x: Integer) return Integer;
-- Returns the number of the lowest bit set in 'x'.
function Exp10 (x: Integer) return Float;
-- Returns 10 to the power of 'x'.
end General;
|
with Get_Line;
with Solitaire_Operations.Text_Representation;
with Ada.Text_IO;
use Ada;
procedure Key_Decrypt is
Passphrase : constant String := Get_Line;
Crypto : constant String := Get_Line;
Deck : Solitaire_Operations.Deck_List;
Plain : String (Crypto'range);
begin -- Key_Decrypt
Solitaire_Operations.Key (Deck => Deck, Passphrase => Passphrase);
Solitaire_Operations.Decrypt (Deck => Deck, Plain => Plain, Crypto => Crypto);
Text_IO.Put_Line (Item => Plain);
exception -- Key_Decrypt
when Solitaire_Operations.Text_Representation.Card_Not_Found =>
Text_IO.Put_Line (Item => "Invalid deck");
end Key_Decrypt;
|
--------------------------------------------------------------------------------------------------------------------
-- Copyright (c) 2013-2020, Luke A. Guest
--
-- This software is provided 'as-is', without any express or implied
-- warranty. In no event will the authors be held liable for any damages
-- arising from the use of this software.
--
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely, subject to the following restrictions:
--
-- 1. The origin of this software must not be misrepresented; you must not
-- claim that you wrote the original software. If you use this software
-- in a product, an acknowledgment in the product documentation would be
-- appreciated but is not required.
--
-- 2. Altered source versions must be plainly marked as such, and must not be
-- misrepresented as being the original software.
--
-- 3. This notice may not be removed or altered from any source
-- distribution.
--------------------------------------------------------------------------------------------------------------------
with Interfaces.C;
with Interfaces.C.Strings;
with SDL.Error;
package body SDL.Video is
use type C.int;
function Is_Screen_Saver_Enabled return Boolean is
function SDL_Is_Screen_Saver_Enabled return C.int with
Import => True,
Convention => C,
External_Name => "SDL_IsScreenSaverEnabled";
begin
return (if SDL_Is_Screen_Saver_Enabled = 1 then True else False);
end Is_Screen_Saver_Enabled;
function Initialise (Name : in String) return Boolean is
function SDL_Video_Init (C_Name : in C.Strings.chars_ptr) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_VideoInit";
C_Str : C.Strings.chars_ptr := C.Strings.Null_Ptr;
Result : C.int;
begin
if Name /= "" then
C_Str := C.Strings.New_String (Name);
Result := SDL_Video_Init (C_Name => C_Str);
C.Strings.Free (C_Str);
else
Result := SDL_Video_Init (C_Name => C.Strings.Null_Ptr);
end if;
return (Result = Success);
end Initialise;
function Total_Drivers return Positive is
function SDL_Get_Num_Video_Drivers return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetNumVideoDrivers";
Num : constant C.int := SDL_Get_Num_Video_Drivers;
begin
if Num < 0 then
raise Video_Error with SDL.Error.Get;
end if;
return Positive (Num);
end Total_Drivers;
function Driver_Name (Index : in Positive) return String is
function SDL_Get_Video_Driver (I : in C.int) return C.Strings.chars_ptr with
Import => True,
Convention => C,
External_Name => "SDL_GetVideoDriver";
-- Index is zero based, so need to subtract 1 to correct it.
C_Str : C.Strings.chars_ptr := SDL_Get_Video_Driver (C.int (Index) - 1);
begin
return C.Strings.Value (C_Str);
end Driver_Name;
function Current_Driver_Name return String is
function SDL_Get_Current_Video_Driver return C.Strings.chars_ptr with
Import => True,
Convention => C,
External_Name => "SDL_GetCurrentVideoDriver";
C_Str : constant C.Strings.chars_ptr := SDL_Get_Current_Video_Driver;
use type C.Strings.chars_ptr;
begin
if C_Str = C.Strings.Null_Ptr then
raise Video_Error with SDL.Error.Get;
end if;
return C.Strings.Value (C_Str);
end Current_Driver_Name;
function Total_Displays return Positive is
function SDL_Get_Num_Video_Displays return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetNumVideoDisplays";
Num : constant C.int := SDL_Get_Num_Video_Displays;
begin
if Num <= 0 then
raise Video_Error with SDL.Error.Get;
end if;
return Positive (Num);
end Total_Displays;
end SDL.Video;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
package body GL.API.Mac_OS_X is
OpenGLFramework_Cached : CFBundleRef;
function OpenGLFramework return CFBundleRef is
use type System.Address;
begin
if OpenGLFramework_Cached = System.Null_Address then
declare
OpenGLFramework_ID : constant CFStringRef
:= CFStringCreateWithCString (System.Null_Address,
IFC.To_C ("com.apple.opengl"),
kCFStringEncodingASCII);
begin
OpenGLFramework_Cached
:= CFBundleGetBundleWithIdentifier (OpenGLFramework_ID);
end;
end if;
return OpenGLFramework_Cached;
end OpenGLFramework;
end GL.API.Mac_OS_X;
|
-----------------------------------------------------------------------
-- awa-mail-components-attachments -- Mail UI Attachments
-- Copyright (C) 2020 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings.Unbounded;
with Util.Beans.Objects;
package body AWA.Mail.Components.Attachments is
use Ada.Strings.Unbounded;
-- ------------------------------
-- Render the mail subject and initializes the message with its content.
-- ------------------------------
overriding
procedure Encode_Children (UI : in UIMailAttachment;
Context : in out ASF.Contexts.Faces.Faces_Context'Class) is
procedure Process (Content : in Unbounded_String);
Content_Type : Util.Beans.Objects.Object;
File_Name : Util.Beans.Objects.Object;
Value : Util.Beans.Objects.Object;
Msg : constant AWA.Mail.Clients.Mail_Message_Access := UI.Get_Message;
function Get_Content_Id return String is
(if not Util.Beans.Objects.Is_Empty (File_Name) then
Util.Beans.Objects.To_String (File_Name)
else
To_String (UI.Get_Client_Id));
function Get_Content_Type return String is
(if Util.Beans.Objects.Is_Empty (Content_Type) then
""
else
Util.Beans.Objects.To_String (Content_Type));
procedure Process (Content : in Unbounded_String) is
begin
Msg.Add_Attachment (Content, Get_Content_Id, Get_Content_Type);
end Process;
begin
Content_Type := UI.Get_Attribute (Name => "contentType", Context => Context);
File_Name := UI.Get_Attribute (Name => "fileName", Context => Context);
Value := UI.Get_Attribute (Name => "value", Context => Context);
if Util.Beans.Objects.Is_Empty (Value) then
UI.Wrap_Encode_Children (Context, Process'Access);
else
Msg.Add_File_Attachment (Util.Beans.Objects.To_String (Value),
Get_Content_Id,
Get_Content_Type);
end if;
end Encode_Children;
end AWA.Mail.Components.Attachments;
|
------------------------------------------------------------------------------
-- G E L A A S I S --
-- ASIS implementation for Gela project, a portable Ada compiler --
-- http://gela.ada-ru.org --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license at the end of this file --
------------------------------------------------------------------------------
-- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- 3 package Asis
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
with Gela.Source_Buffers; use Gela;
-------------------------------------------------------------------------------
package Asis is
pragma Preelaborate;
-------------------------------------------------------------------------------
-- Package Asis encapsulates implementation-specific declarations, which are
-- made available to ASIS and its client applications in an
-- implementation-independent manner.
--
-- Package ASIS is the root of the ASIS interface.
--
-------------------------------------------------------------------------------
-- Abstract
--
-- The Ada Semantic Interface Specification (ASIS) is an interface between an
-- Ada environment as defined by ISO/IEC 8652:1995 (the Ada Reference Manual)
-- and any tool requiring information from this environment. An Ada
-- environment includes valuable semantic and syntactic information. ASIS is
-- an open and published callable interface which gives CASE tool and
-- application developers access to this information. ASIS has been designed
-- to be independent of underlying Ada environment implementations, thus
-- supporting portability of software engineering tools while relieving tool
-- developers from having to understand the complexities of an Ada
-- environment's proprietary internal representation.
--
-------------------------------------------------------------------------------
-- Package ASIS Types:
--
-- The following types are made visible directly through package Asis:
-- type ASIS_Integer
-- type ASIS_Natural
-- type ASIS_Positive
-- type List_Index
-- type Context
-- type Element
-- type Element_List
-- Element subtypes
-- Element Kinds (set of enumeration types)
-- type Compilation_Unit
-- type Compilation_Unit_List
-- Unit Kinds (set of enumeration types)
-- type Traverse_Control
-- subtype Program_Text
--
-- The ASIS interface uses string parameters for many procedure and function
-- calls. Wide_String is used to convey ASIS environment information.
-- Program_Text, a subtype of Wide_String, is used to convey program text.
-- The Ada type String is not used in the ASIS interface. Neither the Ada
-- types Character nor Wide_Character are used in the ASIS interface.
--
-- Implementation_Defined types and values
--
-- A number of implementation-defined types and constants are used. To make
-- the ASIS specification compile, the following types and constants are
-- provided:
type Implementation_Defined_Integer_Type is range -(2**31-1) .. 2**31-1;
Implementation_Defined_Integer_Constant : constant := 2**31-1;
-- In addition, there are several implementation-defined private types.
-- For compilation convenience these types have been represented as
-- enumeration types with the single value of "Implementation_Defined".
-- An implementation may define reasonable types and constants.
-- Please refer to commentary where each is used.
--
-------------------------------------------------------------------------------
-- 3.1 type ASIS_Integer
-------------------------------------------------------------------------------
subtype ASIS_Integer is Implementation_Defined_Integer_Type;
-------------------------------------------------------------------------------
--
-- A numeric subtype that allows each ASIS implementation to place constraints
-- on the lower and upper bounds. Whenever possible, the range of this type
-- should meet or exceed -(2**31-1) .. 2**31-1.
--
-------------------------------------------------------------------------------
-- 3.2 type ASIS_Natural
-------------------------------------------------------------------------------
subtype ASIS_Natural is ASIS_Integer range 0 .. ASIS_Integer'Last;
-------------------------------------------------------------------------------
-- 3.3 type ASIS_Positive
-------------------------------------------------------------------------------
subtype ASIS_Positive is ASIS_Integer range 1 .. ASIS_Integer'Last;
-------------------------------------------------------------------------------
-- 3.4 type List_Index
-------------------------------------------------------------------------------
List_Index_Implementation_Upper :
constant ASIS_Positive := Implementation_Defined_Integer_Constant;
subtype List_Index is ASIS_Positive
range 1 .. List_Index_Implementation_Upper;
-------------------------------------------------------------------------------
-- List_Index is a numeric subtype used to establish the upper bound for list
-- size.
-------------------------------------------------------------------------------
-- 3.5 type Context
-------------------------------------------------------------------------------
-- The ASIS Context is a view of a particular implementation of an Ada
-- environment. ASIS requires an application to identify that view of
-- the Ada environment. An ASIS Context identifies an Ada environment
-- as defined by ISO/IEC 8652:1995. The Ada environment is well
-- defined for Ada implementations. ISO/IEC 8652:1995 provides for an
-- implementation-defined method to enter compilation units into the
-- Ada environment. Implementation permissions allow for illegal and
-- inconsistent units to be in the environment. The use of ASIS may
-- result in the exception ASIS_Failed being raised if the Ada
-- environment includes such units.
--
-- Defined by the implementation, an ASIS context is a way to identify
-- a set of Compilation Units to be processed by an ASIS application.
-- This may include things such as the pathname, search rules, etc.,
-- which are attributes of the Ada environment and consequently
-- becomes part of the ASIS Context only because it is a "view" of
-- the Ada environment.
--
-- Because the contents of the Ada environment are (Ada-)implementation
-- defined, the ASIS context may contain illegal compilation units.
-- An ASIS Context is a handle to a set of compilation units accessible
-- by an ASIS application. The set of compilation units available
-- from an ASIS context may be inconsistent, and may contain illegal
-- compilation units. The contents are selected from the Ada
-- environment as defined by the corresponding Ada Implementation.
-- ASIS should allow multiple open contexts.
--
-- In the Context abstraction, a logical handle is associated with Name and
-- Parameters values that are used by the implementation to identify and
-- connect to the information in the Ada environment.
--
-- An ASIS Context is associated with some set of Ada compilation units
-- maintained by an underlying Ada implementation or a stand-alone ASIS
-- implementation. After this association has been made, this set of units
-- is considered to be part of the compile-time Ada environment, which forms
-- the outermost context of any compilation, as specified in section 10.1.4 of
-- the Ada Reference Manual. This same environment context provides the
-- implicit outermost anonymous task during program execution.
--
-- Some implementations might not need explicit Name and/or Parameters values
-- to identify their Ada environment. Other implementations might choose to
-- implement the Ada environment as a single external file in which case the
-- name and parameters values might simply supply the Name, Form, and any
-- other values needed to open such a file.
--
-------------------------------------------------------------------------------
-- Context shall be an undiscriminated limited private.
-------------------------------------------------------------------------------
type Context is limited private;
Nil_Context : constant Context;
function "=" (Left : in Context;
Right : in Context)
return Boolean is abstract;
-------------------------------------------------------------------------------
--
-- |IR Implementation Requirement
-- |IR
-- |IR The concrete mechanism of this association is implementation-specific:
-- |IR
-- |IR Each ASIS implementation provides the means to construct an ASIS
-- |IR Context value that defines the environment declarative_part or
-- |IR "context" from which ASIS can obtain library units.
--
-------------------------------------------------------------------------------
-- 3.6 type Element
-------------------------------------------------------------------------------
-- The Ada lexical element abstraction (a private type).
--
-- The Element type is a distinct abstract type representing handles for the
-- lexical elements that form the text of compilation units. Elements deal
-- with the internal or "textual" view of compilation units.
--
-- Operations are provided that split a Compilation_Unit object into one
-- Element and two Element lists:
--
-- a) A context clause represented by an Element_List containing
-- with clauses, use clauses, and pragmas.
--
-- b) An Element associated with the declaration.
--
-- c) A list of pragmas, that are not part of the context clause but which
-- nonetheless affect the compilation of the unit.
--
-------------------------------------------------------------------------------
-- ASIS Elements are representations of the syntactic and semantic information
-- available from most Ada environments.
--
-- The ASIS Element type shall be an undiscriminated private type.
-------------------------------------------------------------------------------
type Element is private;
Nil_Element : constant Element;
function "=" (Left : in Element;
Right : in Element)
return Boolean is abstract;
-------------------------------------------------------------------------------
-- 3.7 type Element_List
-------------------------------------------------------------------------------
type Element_List is array (List_Index range <>) of Element;
Nil_Element_List : constant Element_List;
-------------------------------------------------------------------------------
-- 3.8 subtypes of Element and Element_List
-------------------------------------------------------------------------------
subtype Access_Type_Definition is Element;
subtype Association is Element;
subtype Association_List is Element_List;
subtype Case_Statement_Alternative is Element;
subtype Clause is Element;
subtype Component_Clause is Element;
subtype Component_Clause_List is Element_List;
subtype Component_Declaration is Element;
subtype Component_Definition is Element;
subtype Constraint is Element;
subtype Context_Clause is Element;
subtype Context_Clause_List is Element_List;
subtype Declaration is Element;
subtype Declaration_List is Element_List;
subtype Declarative_Item_List is Element_List;
subtype Definition is Element;
subtype Definition_List is Element_List;
subtype Discrete_Range is Element;
subtype Discrete_Range_List is Element_List;
subtype Discrete_Subtype_Definition is Element;
subtype Discriminant_Association is Element;
subtype Discriminant_Association_List is Element_List;
subtype Discriminant_Specification_List is Element_List;
subtype Defining_Name is Element;
subtype Defining_Name_List is Element_List;
subtype Exception_Handler is Element;
subtype Exception_Handler_List is Element_List;
subtype Expression is Element;
subtype Expression_List is Element_List;
subtype Formal_Type_Definition is Element;
subtype Generic_Formal_Parameter is Element;
subtype Generic_Formal_Parameter_List is Element_List;
subtype Identifier is Element;
subtype Identifier_List is Element_List;
subtype Name is Element;
subtype Name_List is Element_List;
subtype Parameter_Specification is Element;
subtype Parameter_Specification_List is Element_List;
subtype Path is Element;
subtype Path_List is Element_List;
subtype Pragma_Element is Element;
subtype Pragma_Element_List is Element_List;
subtype Range_Constraint is Element;
subtype Record_Component is Element;
subtype Record_Component_List is Element_List;
subtype Record_Definition is Element;
subtype Representation_Clause is Element;
subtype Representation_Clause_List is Element_List;
subtype Root_Type_Definition is Element;
subtype Select_Alternative is Element;
subtype Statement is Element;
subtype Statement_List is Element_List;
subtype Subtype_Indication is Element;
subtype Subtype_Mark is Element;
subtype Type_Definition is Element;
subtype Variant is Element;
subtype Variant_Component_List is Element_List;
subtype Variant_List is Element_List;
--
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- 3.9 Element Kinds
-------------------------------------------------------------------------------
-- Element Kinds are enumeration types describing various kinds of elements.
-- These element kinds are only used by package Asis.Elements.
-------------------------------------------------------------------------------
-- 3.9.1 type Element_Kinds
-------------------------------------------------------------------------------
-- Element_Kinds Hierarchy
--
-- ASIS offers hierarchical classification of elements. At the highest
-- level, the Element_Kinds type provides literals that define "kinds" or
-- classes listed below into which all non-nil elements are grouped. Elements
-- in each of the Element_Kinds classes, with the exception of
-- An_Exception_Handler, can be further classified by a subordinate kind at
-- the next level in the hierarchy. Several subordinate kinds also have
-- additional subordinate kinds.
--
-- For example, Element_Kinds'A_Declaration might be classified into
-- Declaration_Kinds'A_Parameter_Specification which might be further
-- classified into Mode_Kinds'An_In_Mode.
-- This fully identifies the syntax of an element such as:
--
-- (Who : in Person)
--
-- All Element_Kinds and subordinate kinds Queries are in Asis.Elements.
--
-- It is not necessary to strictly follow the hierarchy; any element can be
-- classified by any subordinate kind from any level. However, meaningful
-- results will only be obtained from subordinate kinds that are appropriate.
-- These are designated within the hierarchy shown below:
--
-- Element_Kinds -> Subordinate Kinds
-------------------------------------------------------------------------------
-- Key: Read "->" as "is further classified by its"
--
-- A_Pragma -> Pragma_Kinds
--
-- A_Defining_Name -> Defining_Name_Kinds
-- -> Operator_Kinds
--
-- A_Declaration -> Declaration_Kinds
-- -> Declaration_Origins
-- -> Mode_Kinds
-- -> Subprogram_Default_Kinds
--
-- A_Definition -> Definition_Kinds
-- -> Type_Kinds
-- -> Formal_Type_Kinds
-- -> Access_Type_Kinds
-- -> Root_Type_Kinds
-- -> Constraint_Kinds
-- -> Discrete_Range_Kinds
--
-- An_Expression -> Expression_Kinds
-- -> Operator_Kinds
-- -> Attribute_Kinds
--
-- An_Association -> Association_Kinds
--
-- A_Statement -> Statement_Kinds
--
-- A_Path -> Path_Kinds
--
-- A_Clause -> Clause_Kinds
-- -> Representation_Clause_Kinds
--
-- An_Exception_Handler
--
-------------------------------------------------------------------------------
-- Element_Kinds - general element classifications
-- Literals -- ASIS package with queries for these kinds
-------------------------------------------------------------------------------
type Element_Kinds is (
Not_An_Element, -- Nil_Element
A_Pragma, -- Asis.Elements
A_Defining_Name, -- Asis.Declarations
A_Declaration, -- Asis.Declarations
A_Definition, -- Asis.Definitions
An_Expression, -- Asis.Expressions
An_Association, -- Asis.Expressions
A_Statement, -- Asis.Statements
A_Path, -- Asis.Statements
A_Clause, -- Asis.Clauses
An_Exception_Handler); -- Asis.Statements
-------------------------------------------------------------------------------
-- 3.9.2 type Pragma_Kinds
-------------------------------------------------------------------------------
-- Pragma_Kinds - classifications for pragmas
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Pragma_Kinds is (
Not_A_Pragma, -- An unexpected element
An_All_Calls_Remote_Pragma, -- E.2.3(5)
An_Assert_Pragma, -- 11.4.2 (3)
An_Assertion_Policy_Pragma, -- 11.4.2 (6)
An_Asynchronous_Pragma, -- E.4.1(3)
An_Atomic_Pragma, -- C.6(3)
An_Atomic_Components_Pragma, -- C.6(5)
An_Attach_Handler_Pragma, -- C.3.1(4)
A_Controlled_Pragma, -- 13.11.3(3)
A_Convention_Pragma, -- B.1(7), M.1(5)
A_Detect_Blocking_Pragma, -- D.13 (4)
A_Discard_Names_Pragma, -- C.5(3)
An_Elaborate_Pragma, -- 10.2.1(20)
An_Elaborate_All_Pragma, -- 10.2.1(21)
An_Elaborate_Body_Pragma, -- 10.2.1(22)
An_Export_Pragma, -- B.1(5), M.1(5)
An_Import_Pragma, -- B.1(6), M.1(5)
An_Inline_Pragma, -- 6.3.2(3)
An_Inspection_Point_Pragma, -- H.3.2(3)
An_Interrupt_Handler_Pragma, -- C.3.1(2)
An_Interrupt_Priority_Pragma, -- D.1(5)
A_Linker_Options_Pragma, -- B.1(8)
A_List_Pragma, -- 2.8(21)
A_Locking_Policy_Pragma, -- D.3(3)
A_No_Return_Pragma, -- 6.5.1 (3)
A_Normalize_Scalars_Pragma, -- H.1(3)
An_Optimize_Pragma, -- 2.8(23)
A_Pack_Pragma, -- 13.2(3)
A_Page_Pragma, -- 2.8(22)
A_Partition_Elaboration_Policy_Pragma, -- H.6 (3)
A_Preelaborable_Initialization_Pragma, -- 7.6 (5)
A_Preelaborate_Pragma, -- 10.2.1(3)
A_Priority_Pragma, -- D.1(3)
A_Priority_Specific_Dispatching_Pragma, -- D.2.2 (2.2)
A_Profile_Pragma, -- D.13 (2)
A_Pure_Pragma, -- 10.2.1(14)
A_Queuing_Policy_Pragma, -- D.4(3)
A_Relative_Deadline_Pragma, -- D.2.6 (2.2)
A_Remote_Call_Interface_Pragma, -- E.2.3(3)
A_Remote_Types_Pragma, -- E.2.2(3)
A_Restrictions_Pragma, -- 13.12(3)
A_Reviewable_Pragma, -- H.3.1(3)
A_Shared_Passive_Pragma, -- E.2.1(3)
A_Storage_Size_Pragma, -- 13.3(63)
A_Suppress_Pragma, -- 11.5(4)
A_Task_Dispatching_Policy_Pragma, -- D.2.2(2)
An_Unchecked_Union_Pragma, -- B.3.3 (3)
An_Unsuppress_Pragma, -- 11.5 (4.1)
A_Volatile_Pragma, -- C.6(4)
A_Volatile_Components_Pragma, -- C.6(6)
An_Implementation_Defined_Pragma, -- 2.8(14)
An_Unknown_Pragma); -- Unknown to ASIS
-------------------------------------------------------------------------------
-- 3.9.3 type Defining_Name_Kinds
-------------------------------------------------------------------------------
-- Defining_Name_Kinds - names defined by declarations and specifications.
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Defining_Name_Kinds is (
Not_A_Defining_Name, -- An unexpected element
A_Defining_Identifier, -- 3.1(4)
A_Defining_Character_Literal, -- 3.5.1(4)
A_Defining_Enumeration_Literal, -- 3.5.1(3)
A_Defining_Operator_Symbol, -- 6.1(9)
A_Defining_Expanded_Name); -- 6.1(7)
-- program unit name defining_identifier
-------------------------------------------------------------------------------
-- 3.9.4 type Declaration_Kinds
-------------------------------------------------------------------------------
-- Declaration_Kinds - declarations and specifications having defining
-- name literals.
-- Literals -- Reference Manual -> Subordinate Kinds
-------------------------------------------------------------------------------
type Declaration_Kinds is (
Not_A_Declaration, -- An unexpected element
An_Ordinary_Type_Declaration, -- 3.2.1(3)
-- a full_type_declaration of the form:
-- type defining_identifier [known_discriminant_part]
-- is type_definition;
A_Task_Type_Declaration, -- 9.1(2)
A_Protected_Type_Declaration, -- 9.4(2)
An_Incomplete_Type_Declaration, -- 3.2.1(2),3.10(2)
A_Private_Type_Declaration, -- 3.2.1(2),7.3(2)
A_Private_Extension_Declaration, -- 3.2.1(2),7.3(3)
A_Subtype_Declaration, -- 3.2.2(2)
A_Variable_Declaration, -- 3.3.1(2)
A_Constant_Declaration, -- 3.3.1(4)
A_Deferred_Constant_Declaration, -- 3.3.1(6),7.4(2)
A_Single_Task_Declaration, -- 3.3.1(2),9.1(3)
A_Single_Protected_Declaration, -- 3.3.1(2),9.4(2)
An_Integer_Number_Declaration, -- 3.3.2(2)
A_Real_Number_Declaration, -- 3.5.6(2)
An_Enumeration_Literal_Specification, -- 3.5.1(3)
A_Discriminant_Specification, -- 3.7(5)
A_Component_Declaration, -- 3.8(6)
A_Return_Object_Specification, -- 6.5(2)
A_Loop_Parameter_Specification, -- 5.5(4)
A_Procedure_Declaration, -- 6.1(4)
A_Function_Declaration, -- 6.1(4)
A_Parameter_Specification, -- 6.1(15) -> Mode_Kinds
A_Procedure_Body_Declaration, -- 6.3(2)
A_Function_Body_Declaration, -- 6.3(2)
A_Package_Declaration, -- 7.1(2)
A_Package_Body_Declaration, -- 7.2(2)
An_Object_Renaming_Declaration, -- 8.5.1(2)
An_Exception_Renaming_Declaration, -- 8.5.2(2)
A_Package_Renaming_Declaration, -- 8.5.3(2)
A_Procedure_Renaming_Declaration, -- 8.5.4(2)
A_Function_Renaming_Declaration, -- 8.5.4(2)
A_Generic_Package_Renaming_Declaration, -- 8.5.5(2)
A_Generic_Procedure_Renaming_Declaration, -- 8.5.5(2)
A_Generic_Function_Renaming_Declaration, -- 8.5.5(2)
A_Task_Body_Declaration, -- 9.1(6)
A_Protected_Body_Declaration, -- 9.4(7)
An_Entry_Declaration, -- 9.5.2(2)
An_Entry_Body_Declaration, -- 9.5.2(5)
An_Entry_Index_Specification, -- 9.5.2(2)
A_Procedure_Body_Stub, -- 10.1.3(3)
A_Function_Body_Stub, -- 10.1.3(3)
A_Package_Body_Stub, -- 10.1.3(4)
A_Task_Body_Stub, -- 10.1.3(5)
A_Protected_Body_Stub, -- 10.1.3(6)
An_Exception_Declaration, -- 11.1(2)
A_Choice_Parameter_Specification, -- 11.2(4)
A_Generic_Procedure_Declaration, -- 12.1(2)
A_Generic_Function_Declaration, -- 12.1(2)
A_Generic_Package_Declaration, -- 12.1(2)
A_Package_Instantiation, -- 12.3(2)
A_Procedure_Instantiation, -- 12.3(2)
A_Function_Instantiation, -- 12.3(2)
A_Formal_Object_Declaration, -- 12.4(2) -> Mode_Kinds
A_Formal_Type_Declaration, -- 12.5(2)
A_Formal_Procedure_Declaration, -- 12.6(2)
-- -- -> Subprogram_Default_Kinds
A_Formal_Function_Declaration, -- 12.6(2)
-- -- -> Subprogram_Default_Kinds
A_Formal_Package_Declaration, -- 12.7(2)
A_Formal_Package_Declaration_With_Box); -- 12.7(3)
-- The following Declaration_Kinds subtypes are not used by ASIS but are
-- provided for the convenience of the ASIS implementor:
subtype A_Type_Declaration is Declaration_Kinds range
An_Ordinary_Type_Declaration .. A_Private_Extension_Declaration;
subtype A_Full_Type_Declaration is Declaration_Kinds range
An_Ordinary_Type_Declaration .. A_Protected_Type_Declaration;
subtype An_Object_Declaration is Declaration_Kinds range
A_Variable_Declaration .. A_Single_Protected_Declaration;
subtype A_Number_Declaration is Declaration_Kinds range
An_Integer_Number_Declaration .. A_Real_Number_Declaration;
subtype A_Renaming_Declaration is Declaration_Kinds range
An_Object_Renaming_Declaration ..
A_Generic_Function_Renaming_Declaration;
subtype A_Body_Stub is Declaration_Kinds range
A_Procedure_Body_Stub .. A_Protected_Body_Stub;
subtype A_Generic_Declaration is Declaration_Kinds range
A_Generic_Procedure_Declaration .. A_Generic_Package_Declaration;
subtype A_Generic_Instantiation is Declaration_Kinds range
A_Package_Instantiation .. A_Function_Instantiation;
subtype A_Formal_Declaration is Declaration_Kinds range
A_Formal_Object_Declaration ..
A_Formal_Package_Declaration_With_Box;
-------------------------------------------------------------------------------
-- 3.9.x type Overriding_Indicator_Kinds
-------------------------------------------------------------------------------
--
-- Type Overriding_Indicator_Kinds classifies declarations and specifications
-- having an overrriding indicator.
--
-------------------------------------------------------------------------------
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Overriding_Indicator_Kinds is (
Not_An_Overriding_Indicator,
No_Overriding_Indicator, -- 8.3.1 (2)
An_Indicator_of_Overriding, -- 8.3.1 (2)
An_Indicator_of_Not_Overriding); -- 8.3.1 (2)
-------------------------------------------------------------------------------
-- 3.9.5 type Trait_Kinds (Obsolescent) - see clause X
-------------------------------------------------------------------------------
--
-- Trait_Kinds provide a means of further classifying the syntactic structure
-- or "trait" of certain A_Declaration and A_Definition elements.
-- Trait_Kinds are determined only by the presence (or absence) of certain
-- syntactic constructs. The semantics of an element are not considered.
--
-- The syntax of interest here are the reserved words "abstract", "aliased",
-- "limited", "private", "reverse", whereever they appear, and the reserved
-- word "access" when it qualifies a definition defining an anonymous type
-- (an access_definition).
-- Trait_Kinds enumerates all combinations useful in this classification.
--
-- For example, A_Variable_Declaration element that is semantically a
-- limited type because its components are of a limited type is
-- An_Ordinary_Trait, not A_Limited_Trait, since the reserved word "limited"
-- does not appear in its declaration or definition.
--
-- The subordinate Trait_Kinds allow Declaration_Kinds and Definition_Kinds
-- to enumerate fewer higher level elements, and be less cluttered by all
-- possible permutations of syntactic possibilities. For example, in the case
-- of a record_type_definition, Definition_Kinds can provide just two literals
-- that differentiate between ordinary record types and tagged record types:
--
-- A_Record_Type_Definition, -- 3.8(2) -> Trait_Kinds
-- A_Tagged_Record_Type_Definition, -- 3.8(2) -> Trait_Kinds
--
-- The remaining classification can be accomplished, if desired, using
-- Trait_Kinds to determine if the definition is abstract, or limited,
-- or both. Without Trait_Kinds, Definition_Kinds needs six literals to
-- identify all the syntactic combinations for a record_type_definition.
--
-- Elements expected by the Trait_Kind query are any Declaration_Kinds or
-- Definition_Kinds for which Trait_Kinds is a subordinate kind: the literal
-- definition has "-> Trait_Kinds" following it. For example, the
-- definitions of:
--
-- A_Discriminant_Specification, -- 3.7(5) -> Trait_Kinds
-- A_Component_Declaration, -- 3.8(6)
--
-- indicate A_Discriminant_Specification is an expected kind while
-- A_Component_Declaration is unexpected.
--
-- All Declaration_Kinds and Definition_Kinds for which Trait_Kinds is not a
-- subordinate kind, and all other Element_Kinds, are unexpected and are
-- Not_A_Trait.
--
-- An_Ordinary_Trait is any expected element whose syntax does not explicitly
-- contain any of the reserved words listed above.
--
-------------------------------------------------------------------------------
-- Trait_Kinds
-- Literals
-------------------------------------------------------------------------------
type Trait_Kinds is (
Not_A_Trait, -- An unexpected element
An_Ordinary_Trait, -- The declaration or definition
-- does not have any of the
-- following traits
An_Aliased_Trait, -- "aliased" is present
An_Access_Definition_Trait, -- The definition defines an
-- anonymous access type
A_Reverse_Trait, -- "reverse" is present
A_Private_Trait, -- Only "private" is present
A_Limited_Trait, -- Only "limited" is present
A_Limited_Private_Trait, -- "limited" and "private" are
-- present
An_Abstract_Trait, -- Only "abstract" is present
An_Abstract_Private_Trait, -- "abstract" and "private" are
-- present
An_Abstract_Limited_Trait, -- "abstract" and "limited" are
-- present
An_Abstract_Limited_Private_Trait); -- "abstract", "limited", and
-- "private" are present
-------------------------------------------------------------------------------
-- 3.9.6 type Declaration_Origins
-------------------------------------------------------------------------------
-- Declaration_Origins
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Declaration_Origins is (
Not_A_Declaration_Origin, -- An unexpected element
An_Explicit_Declaration, -- 3.1(5) explicitly declared in
-- the text of a program, or within
-- an expanded generic template
An_Implicit_Predefined_Declaration, -- 3.1(5), 3.2.3(1), A.1(2)
An_Implicit_Inherited_Declaration); -- 3.1(5), 3.4(6-35)
-------------------------------------------------------------------------------
-- 3.9.7 type Mode_Kinds
-------------------------------------------------------------------------------
-- Mode_Kinds
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Mode_Kinds is ( -- 6.1
Not_A_Mode, -- An unexpected element
A_Default_In_Mode, -- procedure A(B : C);
An_In_Mode, -- procedure A(B : IN C);
An_Out_Mode, -- procedure A(B : OUT C);
An_In_Out_Mode); -- procedure A(B : IN OUT C);
-------------------------------------------------------------------------------
-- 3.9.8 type Subprogram_Default_Kinds
-------------------------------------------------------------------------------
-- Subprogram_Default_Kinds
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Subprogram_Default_Kinds is ( -- 12.6
Not_A_Default, -- An unexpected element
A_Name_Default, -- with subprogram_specification is default_name;
A_Box_Default, -- with subprogram_specification is <>;
A_Nil_Default); -- with subprogram_specification;
-------------------------------------------------------------------------------
-- 3.9.9 type Definition_Kinds
-------------------------------------------------------------------------------
-- Definition_Kinds
-- Literals -- Reference Manual -> Subordinate Kinds
-------------------------------------------------------------------------------
type Definition_Kinds is (
Not_A_Definition, -- An unexpected element
A_Type_Definition, -- 3.2.1(4)
A_Subtype_Indication, -- 3.2.2(3)
A_Constraint, -- 3.2.2(5) -> Constraint_Kinds
A_Component_Definition, -- 3.6(7)
A_Discrete_Subtype_Definition, -- 3.6(6) -> Discrete_Range_Kinds
A_Discrete_Range, -- 3.6.1(3) -> Discrete_Range_Kinds
An_Unknown_Discriminant_Part, -- 3.7(3)
A_Known_Discriminant_Part, -- 3.7(2)
A_Record_Definition, -- 3.8(3)
A_Null_Record_Definition, -- 3.8(3)
A_Null_Component, -- 3.8(4)
A_Variant_Part, -- 3.8.1(2)
A_Variant, -- 3.8.1(3)
An_Others_Choice, -- 3.8.1(5), 4.3.1(5), 4.3.3(5),11.2(5)
An_Access_Definition, -- 3.10(6)
An_Incomplete_Type_Definition, -- 3.10.1(1)
A_Tagged_Incomplete_Type_Definition, -- 3.10.1(2)
A_Private_Type_Definition, -- 7.3(2)
A_Tagged_Private_Type_Definition, -- 7.3(2)
A_Private_Extension_Definition, -- 7.3(3)
A_Task_Definition, -- 9.1(4)
A_Protected_Definition, -- 9.4(4)
A_Formal_Type_Definition); -- 12.5(3) -> Formal_Type_Kinds
-------------------------------------------------------------------------------
-- 3.9.10 type Type_Kinds
-------------------------------------------------------------------------------
-- Type_Kinds
-- Literals -- Reference Manual -> Subordinate Kinds
-------------------------------------------------------------------------------
type Type_Kinds is (
Not_A_Type_Definition, -- An unexpected element
A_Derived_Type_Definition, -- 3.4(2)
A_Derived_Record_Extension_Definition, -- 3.4(2)
An_Enumeration_Type_Definition, -- 3.5.1(2)
A_Signed_Integer_Type_Definition, -- 3.5.4(3)
A_Modular_Type_Definition, -- 3.5.4(4)
A_Root_Type_Definition, -- 3.5.4(14), 3.5.6(3)
-- -> Root_Type_Kinds
A_Floating_Point_Definition, -- 3.5.7(2)
An_Ordinary_Fixed_Point_Definition, -- 3.5.9(3)
A_Decimal_Fixed_Point_Definition, -- 3.5.9(6)
An_Unconstrained_Array_Definition, -- 3.6(2)
A_Constrained_Array_Definition, -- 3.6(2)
A_Record_Type_Definition, -- 3.8(2)
A_Tagged_Record_Type_Definition, -- 3.8(2)
An_Interface_Type_Definition, -- 3.9.4 (2) -> Interface_Kinds
An_Access_Type_Definition); -- 3.10(2) -> Access_Type_Kinds
-------------------------------------------------------------------------------
-- 3.9.11 type Formal_Type_Kinds
-------------------------------------------------------------------------------
-- Formal_Type_Kinds
-- Literals -- Reference Manual -> Subordinate Kinds
-------------------------------------------------------------------------------
type Formal_Type_Kinds is (
Not_A_Formal_Type_Definition, -- An unexpected element
A_Formal_Private_Type_Definition, -- 12.5.1(2)
A_Formal_Tagged_Private_Type_Definition, -- 12.5.1(2)
A_Formal_Derived_Type_Definition, -- 12.5.1(3)
A_Formal_Discrete_Type_Definition, -- 12.5.2(2)
A_Formal_Signed_Integer_Type_Definition, -- 12.5.2(3)
A_Formal_Modular_Type_Definition, -- 12.5.2(4)
A_Formal_Floating_Point_Definition, -- 12.5.2(5)
A_Formal_Ordinary_Fixed_Point_Definition, -- 12.5.2(6)
A_Formal_Decimal_Fixed_Point_Definition, -- 12.5.2(7)
A_Formal_Unconstrained_Array_Definition, -- 12.5.3(2), 3.6(3)
A_Formal_Constrained_Array_Definition, -- 12.5.3(2), 3.6(5)
A_Formal_Access_Type_Definition, -- 12.5.4(2)
-- -> Access_Type_Kinds
A_Formal_Interface_Type_Definition); -- 12.5.5 (2)
-- -> Interface_Kinds
-------------------------------------------------------------------------------
-- 3.9.12 type Access_Type_Kinds
-------------------------------------------------------------------------------
-- Access_Type_Kinds
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Access_Type_Kinds is ( -- 3.10
Not_An_Access_Type_Definition, -- An unexpected element
A_Pool_Specific_Access_To_Variable, -- access subtype_indication
An_Access_To_Variable, -- access all subtype_indication
An_Access_To_Constant, -- access constant subtype_indication
An_Access_To_Procedure, -- access procedure
An_Access_To_Protected_Procedure, -- access protected procedure
An_Access_To_Function, -- access function
An_Access_To_Protected_Function); -- access protected function
-- The following Access_Type_Kinds subtypes are not used by ASIS but are
-- provided for the convenience of the ASIS implementor:
subtype Access_To_Object_Definition is Access_Type_Kinds range
A_Pool_Specific_Access_To_Variable .. An_Access_To_Constant;
subtype Access_To_Subprogram_Definition is Access_Type_Kinds range
An_Access_To_Procedure .. An_Access_To_Protected_Function;
-------------------------------------------------------------------------------
-- 3.9.xx type Access_Definition_Kinds
-------------------------------------------------------------------------------
type Access_Definition_Kinds is ( -- 3.3.1(2) / 3.10(6)
Not_An_Access_Definition, -- An unexpected element
An_Anonymous_Access_To_Variable, -- 3.3.1(2) access
-- subtype_mark
An_Anonymous_Access_To_Constant, -- 3.3.1(2) / 3.10(6)
-- access constant
-- subtype_mark
An_Anonymous_Access_To_Procedure, -- 3.10(6) access procedure
An_Anonymous_Access_To_Protected_Procedure, -- 3.10(6) access protected
-- procedure
An_Anonymous_Access_To_Function, -- 3.10(6) access function
An_Anonymous_Access_To_Protected_Function); -- 3.10(6) access protected
-- function
subtype An_Anonymous_Access_to_Object_Definition is Access_Definition_Kinds
range An_Anonymous_Access_To_Variable .. An_Anonymous_Access_To_Constant;
subtype An_Anonymous_Access_to_Subprogram_Definition
is Access_Definition_Kinds
range An_Anonymous_Access_To_Procedure
.. An_Anonymous_Access_To_Protected_Function;
-------------------------------------------------------------------------------
-- 3.9.13 type Root_Type_Kinds
-------------------------------------------------------------------------------
-- Root_Type_Kinds
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Root_Type_Kinds is (
Not_A_Root_Type_Definition, -- An unexpected element
A_Root_Integer_Definition, -- 3.4.1(8)
A_Root_Real_Definition, -- 3.4.1(8)
A_Universal_Integer_Definition, -- 3.4.1(6)
A_Universal_Real_Definition, -- 3.4.1(6)
A_Universal_Fixed_Definition, -- 3.4.1(6)
A_Universal_Access_Definition); -- 3.4.1(6)
-------------------------------------------------------------------------------
-- 3.9.14 type Constraint_Kinds
-------------------------------------------------------------------------------
-- Constraint_Kinds
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Constraint_Kinds is (
Not_A_Constraint, -- An unexpected element
A_Range_Attribute_Reference, -- 3.5(2)
A_Simple_Expression_Range, -- 3.2.2, 3.5(3)
A_Digits_Constraint, -- 3.2.2, 3.5.9
A_Delta_Constraint, -- 3.2.2, J.3
An_Index_Constraint, -- 3.2.2, 3.6.1
A_Discriminant_Constraint); -- 3.2.2
-------------------------------------------------------------------------------
-- 3.9.15 type Discrete_Range_Kinds
-------------------------------------------------------------------------------
-- Discrete_Range_Kinds
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Discrete_Range_Kinds is (
Not_A_Discrete_Range, -- An unexpected element
A_Discrete_Subtype_Indication, -- 3.6.1(6), 3.2.2
A_Discrete_Range_Attribute_Reference, -- 3.6.1, 3.5
A_Discrete_Simple_Expression_Range); -- 3.6.1, 3.5
-------------------------------------------------------------------------------
-- 3.9.xx type Interface_Types
-------------------------------------------------------------------------------
type Interface_Kinds is ( -- 3.9.4 (2)
Not_An_Interface, -- An unexpected element
An_Ordinary_Interface, -- 3.9.4(2) interface ...
A_Limited_Interface, -- 3.9.4(2) limited interface ...
A_Task_Interface, -- 3.9.4(2) task interface ...
A_Protected_Interface, -- 3.9.4(2) protected interface ...
A_Synchronized_Interface); -- 3.9.4(2) synchronized interface ...
-------------------------------------------------------------------------------
-- 3.9.16 type Association_Kinds
-------------------------------------------------------------------------------
-- Association_Kinds
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Association_Kinds is (
Not_An_Association, -- An unexpected element
A_Pragma_Argument_Association, -- 2.8
A_Discriminant_Association, -- 3.7.1
A_Record_Component_Association, -- 4.3.1
An_Array_Component_Association, -- 4.3.3
A_Parameter_Association, -- 6.4
A_Generic_Association); -- 12.3
-------------------------------------------------------------------------------
-- 3.9.17 type Expression_Kinds
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Expression_Kinds - general expression classifications
-- Literals -- Reference Manual -> Subordinate Kinds
-------------------------------------------------------------------------------
type Expression_Kinds is (
Not_An_Expression, -- An unexpected element
A_Box_Expression, -- 4.3.1(4), 4.3.3(3,6)
An_Integer_Literal, -- 2.4
A_Real_Literal, -- 2.4.1
A_String_Literal, -- 2.6
An_Identifier, -- 4.1
An_Operator_Symbol, -- 4.1
A_Character_Literal, -- 4.1
An_Enumeration_Literal, -- 4.1
An_Explicit_Dereference, -- 4.1
A_Function_Call, -- 4.1
An_Indexed_Component, -- 4.1.1
A_Slice, -- 4.1.2
A_Selected_Component, -- 4.1.3
An_Attribute_Reference, -- 4.1.4 -> Attribute_Kinds
A_Record_Aggregate, -- 4.3
An_Extension_Aggregate, -- 4.3
A_Positional_Array_Aggregate, -- 4.3
A_Named_Array_Aggregate, -- 4.3
An_And_Then_Short_Circuit, -- 4.4
An_Or_Else_Short_Circuit, -- 4.4
An_In_Range_Membership_Test, -- 4.4
A_Not_In_Range_Membership_Test, -- 4.4
An_In_Type_Membership_Test, -- 4.4
A_Not_In_Type_Membership_Test, -- 4.4
A_Null_Literal, -- 4.4
A_Parenthesized_Expression, -- 4.4
A_Type_Conversion, -- 4.6
A_Qualified_Expression, -- 4.7
An_Allocation_From_Subtype, -- 4.8
An_Allocation_From_Qualified_Expression); -- 4.8
-------------------------------------------------------------------------------
-- 3.9.18 type Operator_Kinds
-------------------------------------------------------------------------------
-- Operator_Kinds - classification of the various Ada predefined operators
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Operator_Kinds is ( -- 4.5
Not_An_Operator, -- An unexpected element
An_And_Operator, -- and
An_Or_Operator, -- or
An_Xor_Operator, -- xor
An_Equal_Operator, -- =
A_Not_Equal_Operator, -- /=
A_Less_Than_Operator, -- <
A_Less_Than_Or_Equal_Operator, -- <=
A_Greater_Than_Operator, -- >
A_Greater_Than_Or_Equal_Operator, -- >=
A_Plus_Operator, -- +
A_Minus_Operator, -- -
A_Concatenate_Operator, -- &
A_Unary_Plus_Operator, -- +
A_Unary_Minus_Operator, -- -
A_Multiply_Operator, -- *
A_Divide_Operator, -- /
A_Mod_Operator, -- mod
A_Rem_Operator, -- rem
An_Exponentiate_Operator, -- **
An_Abs_Operator, -- abs
A_Not_Operator); -- not
-------------------------------------------------------------------------------
-- 3.9.19 type Attribute_Kinds
-------------------------------------------------------------------------------
-- Attribute_Kinds - classifications for all known Ada attributes
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Attribute_Kinds is (
Not_An_Attribute, -- An unexpected element
An_Access_Attribute, -- 3.10.2(24), 3.10.2(32), K(2), K(4)
An_Address_Attribute, -- 13.3(11), J.7.1(5), K(6)
An_Adjacent_Attribute, -- A.5.3(48), K(8)
An_Aft_Attribute, -- 3.5.10(5), K(12)
An_Alignment_Attribute, -- 13.3(23), K(14)
A_Base_Attribute, -- 3.5(15), K(17)
A_Bit_Order_Attribute, -- 13.5.3(4), K(19)
A_Body_Version_Attribute, -- E.3(4), K(21)
A_Callable_Attribute, -- 9.9(2), K(23)
A_Caller_Attribute, -- C.7.1(14), K(25)
A_Ceiling_Attribute, -- A.5.3(33), K(27)
A_Class_Attribute, -- 3.9(14), 7.3.1(9), K(31), K(34)
A_Component_Size_Attribute, -- 13.3(69), K(36)
A_Compose_Attribute, -- A.5.3(24), K(38)
A_Constrained_Attribute, -- 3.7.2(3), J.4(2), K(42)
A_Copy_Sign_Attribute, -- A.5.3(51), K(44)
A_Count_Attribute, -- 9.9(5), K(48)
A_Definite_Attribute, -- 12.5.1(23), K(50)
A_Delta_Attribute, -- 3.5.10(3), K(52)
A_Denorm_Attribute, -- A.5.3(9), K(54)
A_Digits_Attribute, -- 3.5.8(2), 3.5.10(7), K(56), K(58)
An_Exponent_Attribute, -- A.5.3(18), K(60)
An_External_Tag_Attribute, -- 13.3(75), K(64)
A_First_Attribute, -- 3.5(12), 3.6.2(3), K(68), K(70)
A_First_Bit_Attribute, -- 13.5.2(3), K(72)
A_Floor_Attribute, -- A.5.3(30), K(74)
A_Fore_Attribute, -- 3.5.10(4), K(78)
A_Fraction_Attribute, -- A.5.3(21), K(80)
An_Identity_Attribute, -- 11.4.1(9), C.7.1(12), K(84), K(86)
An_Image_Attribute, -- 3.5(35), K(88)
An_Input_Attribute, -- 13.13.2(22), 13.13.2(32), K(92), K(96)
A_Last_Attribute, -- 3.5(13), 3.6.2(5), K(102), K(104)
A_Last_Bit_Attribute, -- 13.5.2(4), K(106)
A_Leading_Part_Attribute, -- A.5.3(54), K(108)
A_Length_Attribute, -- 3.6.2(9), K(117)
A_Machine_Attribute, -- A.5.3(60), K(119)
A_Machine_Emax_Attribute, -- A.5.3(8), K(123)
A_Machine_Emin_Attribute, -- A.5.3(7), K(125)
A_Machine_Mantissa_Attribute, -- A.5.3(6), K(127)
A_Machine_Overflows_Attribute, -- A.5.3(12), A.5.4(4), K(129), K(131)
A_Machine_Radix_Attribute, -- A.5.3(2), A.5.4(2), K(133), K(135)
A_Machine_Rounding_Attribute, -- A.5.3 (41.1/2), K(135.1/2)
A_Machine_Rounds_Attribute, -- A.5.3(11), A.5.4(3), K(137), K(139)
A_Max_Attribute, -- 3.5(19), K(141)
A_Max_Size_In_Storage_Elements_Attribute, -- 13.11.1(3), K(145)
A_Min_Attribute, -- 3.5(16), K(147)
A_Mod_Attribute, -- 3.5.4 (16.3/2), K(150.1/2)
A_Model_Attribute, -- A.5.3(68), G.2.2(7), K(151)
A_Model_Emin_Attribute, -- A.5.3(65), G.2.2(4), K(155)
A_Model_Epsilon_Attribute, -- A.5.3(66), K(157)
A_Model_Mantissa_Attribute, -- A.5.3(64), G.2.2(3), K(159)
A_Model_Small_Attribute, -- A.5.3(67), K(161)
A_Modulus_Attribute, -- 3.5.4(17), K(163)
An_Output_Attribute, -- 13.13.2(19), 13.13.2(29), K(165), K(169)
A_Partition_ID_Attribute, -- E.1(9), K(173)
A_Pos_Attribute, -- 3.5.5(2), K(175)
A_Position_Attribute, -- 13.5.2(2), K(179)
A_Pred_Attribute, -- 3.5(25), K(181)
A_Priority_Attribute, -- D.2.6 (27/2), K(184.1/2)
A_Range_Attribute, -- 3.5(14), 3.6.2(7), K(187), K(189)
A_Read_Attribute, -- 13.13.2(6), 13.13.2(14), K(191), K(195)
A_Remainder_Attribute, -- A.5.3(45), K(199)
A_Round_Attribute, -- 3.5.10(12), K(203)
A_Rounding_Attribute, -- A.5.3(36), K(207)
A_Safe_First_Attribute, -- A.5.3(71), G.2.2(5), K(211)
A_Safe_Last_Attribute, -- A.5.3(72), G.2.2(6), K(213)
A_Scale_Attribute, -- 3.5.10(11), K(215)
A_Scaling_Attribute, -- A.5.3(27), K(217)
A_Signed_Zeros_Attribute, -- A.5.3(13), K(221)
A_Size_Attribute, -- 13.3(40), 13.3(45), K(223), K(228)
A_Small_Attribute, -- 3.5.10(2), K(230)
A_Storage_Pool_Attribute, -- 13.11(13), K(232)
A_Storage_Size_Attribute, -- 13.3(60), 13.11(14), J.9(2), K(234),
-- K(236)
A_Stream_Size_Attribute, -- 13.13.2 (1.2/2), K(237.1/2)
A_Succ_Attribute, -- 3.5(22), K(238)
A_Tag_Attribute, -- 3.9(16), 3.9(18), K(242), K(244)
A_Terminated_Attribute, -- 9.9(3), K(246)
A_Truncation_Attribute, -- A.5.3(42), K(248)
An_Unbiased_Rounding_Attribute, -- A.5.3(39), K(252)
An_Unchecked_Access_Attribute, -- 13.10(3), H.4(18), K(256)
A_Val_Attribute, -- 3.5.5(5), K(258)
A_Valid_Attribute, -- 13.9.2(3), H(6), K(262)
A_Value_Attribute, -- 3.5(52), K(264)
A_Version_Attribute, -- E.3(3), K(268)
A_Wide_Image_Attribute, -- 3.5(28), K(270)
A_Wide_Value_Attribute, -- 3.5(40), K(274)
A_Wide_Wide_Image_Attribute, -- 3.5 (27.1/2), K(277.1/2)
A_Wide_Wide_Value_Attribute, -- 3.5 (39.1/2), K(277.5/2)
A_Wide_Wide_Width_Attribute, -- 3.5 (37.1/2), K(277.9/2)
A_Wide_Width_Attribute, -- 3.5(38), K(278)
A_Width_Attribute, -- 3.5(39), K(280)
A_Write_Attribute, -- 13.13.2(3), 13.13.2(11), K(282), K(286)
An_Implementation_Defined_Attribute, -- Reference Manual, Annex M
An_Unknown_Attribute); -- Unknown to ASIS
-------------------------------------------------------------------------------
-- 3.9.20 type Statement_Kinds
-------------------------------------------------------------------------------
-- Statement_Kinds - classifications of Ada statements
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Statement_Kinds is (
Not_A_Statement, -- An unexpected element
A_Null_Statement, -- 5.1
An_Assignment_Statement, -- 5.2
An_If_Statement, -- 5.3
A_Case_Statement, -- 5.4
A_Loop_Statement, -- 5.5
A_While_Loop_Statement, -- 5.5
A_For_Loop_Statement, -- 5.5
A_Block_Statement, -- 5.6
An_Exit_Statement, -- 5.7
A_Goto_Statement, -- 5.8
A_Procedure_Call_Statement, -- 6.4
A_Simple_Return_Statement, -- 6.5
An_Extended_Return_Statement, -- 6.5
An_Accept_Statement, -- 9.5.2
An_Entry_Call_Statement, -- 9.5.3
A_Requeue_Statement, -- 9.5.4
A_Requeue_Statement_With_Abort, -- 9.5.4
A_Delay_Until_Statement, -- 9.6
A_Delay_Relative_Statement, -- 9.6
A_Terminate_Alternative_Statement, -- 9.7.1
A_Selective_Accept_Statement, -- 9.7.1
A_Timed_Entry_Call_Statement, -- 9.7.2
A_Conditional_Entry_Call_Statement, -- 9.7.3
An_Asynchronous_Select_Statement, -- 9.7.4
An_Abort_Statement, -- 9.8
A_Raise_Statement, -- 11.3
A_Code_Statement); -- 13.8
A_Return_Statement : Statement_Kinds renames A_Simple_Return_Statement;
-- For compatibility with a prior version of this Standard
-------------------------------------------------------------------------------
-- 3.9.21 type Path_Kinds
-------------------------------------------------------------------------------
--
-- A_Path elements represent execution path alternatives presented by the
-- if_statement, case_statement, and the four forms of select_statement.
-- Each statement path alternative encloses component elements that
-- represent a sequence_of_statements. Some forms of A_Path elements also
-- have as a component elements that represent a condition, an optional
-- guard, or a discrete_choice_list.
--
-- ASIS treats the select_alternative, entry_call_alternative, and
-- triggering_alternative, as the syntactic equivalent of a
-- sequence_of_statements.
-- Specifically, the terminate_alternative (terminate;)
-- is treated as the syntactical equivalent of a single statement and are
-- represented as Statement_Kinds'A_Terminate_Alternative_Statement.
-- This allows queries to directly provide the sequence_of_statements enclosed
-- by A_Path elements, avoiding the extra step of returning an element
-- representing such an alternative.
--
-- For example,
--
-- select -- A_Select_Path enclosing a sequence of two statements
--
-- accept Next_Work_Item(WI : in Work_Item) do
-- Current_Work_Item := WI;
-- end;
-- Process_Work_Item(Current_Work_Item);
--
-- or -- An_Or_Path enclosing a guard and
-- -- a sequence of two statements
--
-- when Done_Early =>
-- accept Shut_Down;
-- exit;
--
-- or -- An_Or_Path enclosing a sequence with only a single statement
--
-- terminate;
--
-- end select;
--
-------------------------------------------------------------------------------
-- Path_Kinds
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Path_Kinds is (
Not_A_Path, -- An unexpected element
An_If_Path, -- 5.3:
-- if condition then
-- sequence_of_statements
An_Elsif_Path, -- 5.3:
-- elsif condition then
-- sequence_of_statements
An_Else_Path, -- 5.3, 9.7.1, 9.7.3:
-- else sequence_of_statements
A_Case_Path, -- 5.4:
-- when discrete_choice_list =>
-- sequence_of_statements
A_Select_Path, -- 9.7.1:
-- select [guard] select_alternative
-- 9.7.2, 9.7.3:
-- select entry_call_alternative
-- 9.7.4:
-- select triggering_alternative
An_Or_Path, -- 9.7.1:
-- or [guard] select_alternative
-- 9.7.2:
-- or delay_alternative
A_Then_Abort_Path); -- 9.7.4
-- then abort sequence_of_statements
-------------------------------------------------------------------------------
-- 3.9.22 type Clause_Kinds
-------------------------------------------------------------------------------
-- Clause_Kinds
-- Literals -- Reference Manual -> Subordinate Kinds
-------------------------------------------------------------------------------
type Clause_Kinds is (
Not_A_Clause, -- An unexpected element
A_Use_Package_Clause, -- 8.4
A_Use_Type_Clause, -- 8.4
A_With_Clause, -- 10.1.2
A_Representation_Clause, -- 13.1 -> Representation_Clause_Kinds
A_Component_Clause); -- 13.5.1
-------------------------------------------------------------------------------
-- 3.9.23 type Representation_Clause_Kinds
-------------------------------------------------------------------------------
-- Representation_Clause_Kinds - varieties of representation clauses
-- Literals -- Reference Manual
-------------------------------------------------------------------------------
type Representation_Clause_Kinds is (
Not_A_Representation_Clause, -- An unexpected element
An_Attribute_Definition_Clause, -- 13.3
An_Enumeration_Representation_Clause, -- 13.4
A_Record_Representation_Clause, -- 13.5.1
An_At_Clause); -- J.7
-------------------------------------------------------------------------------
-- 3.10 type Compilation_Unit
-------------------------------------------------------------------------------
-- The Ada Compilation Unit abstraction:
--
-- The text of a program is submitted to the compiler in one or more
-- compilations. Each compilation is a succession of compilation units.
--
-- Compilation units are composed of three distinct parts:
--
-- a) A context clause.
--
-- b) The declaration of a library_item or unit.
--
-- c) Pragmas that apply to the compilation, of which the unit is a part.
--
-- The context clause contains zero or more with clauses, use clauses,
-- pragma elaborates, and possibly other pragmas.
--
-- ASIS treats Pragmas that appear immediately after the context clause and
-- before the subsequent declaration part as belonging to the context
-- clause part.
--
-- The declaration associated with a compilation unit is one of: a
-- package, a procedure, a function, a generic, or a subunit for normal units.
-- The associated declaration is a Nil_Element for An_Unknown_Unit and
-- Nonexistent units.
--
-- The abstract type Compilation_Unit is a handle for compilation units as a
-- whole. An object of the type Compilation_Unit deals with the external view
-- of compilation units such as their relationships with other units or their
-- compilation attributes.
--
-- Compilation_Unit shall be an undiscriminated private type.
-------------------------------------------------------------------------------
type Compilation_Unit is private;
Nil_Compilation_Unit : constant Compilation_Unit;
function "=" (Left : in Compilation_Unit;
Right : in Compilation_Unit)
return Boolean is abstract;
-------------------------------------------------------------------------------
-- 3.11 type Compilation_Unit_List
-------------------------------------------------------------------------------
type Compilation_Unit_List is
array (List_Index range <>) of Compilation_Unit;
Nil_Compilation_Unit_List : constant Compilation_Unit_List;
-------------------------------------------------------------------------------
-- 3.12 Unit Kinds
-------------------------------------------------------------------------------
-- Unit Kinds are enumeration types describing the various kinds of units.
-- These element kinds are only used by package Asis.Compilation_Units.
-------------------------------------------------------------------------------
-- 3.12.1 type Unit_Kinds
-------------------------------------------------------------------------------
-- Unit_Kinds - the varieties of compilation units of compilations,
-- including compilations having no compilation units but consisting of
-- configuration pragmas or comments.
-------------------------------------------------------------------------------
type Unit_Kinds is (
Not_A_Unit, -- A Nil_Compilation_Unit
A_Procedure,
A_Function,
A_Package,
A_Generic_Procedure,
A_Generic_Function,
A_Generic_Package,
A_Procedure_Instance,
A_Function_Instance,
A_Package_Instance,
A_Procedure_Renaming,
A_Function_Renaming,
A_Package_Renaming,
A_Generic_Procedure_Renaming,
A_Generic_Function_Renaming,
A_Generic_Package_Renaming,
A_Procedure_Body, -- A unit interpreted only as the completion
-- of a procedure, or a unit interpreted as
-- both the declaration and body of a library
-- procedure. Reference Manual 10.1.4(4)
A_Function_Body, -- A unit interpreted only as the completion
-- of a function, or a unit interpreted as
-- both the declaration and body of a library
-- function. Reference Manual 10.1.4(4)
A_Package_Body,
A_Procedure_Body_Subunit,
A_Function_Body_Subunit,
A_Package_Body_Subunit,
A_Task_Body_Subunit,
A_Protected_Body_Subunit,
A_Nonexistent_Declaration, -- A unit that does not exist but is:
-- 1) mentioned in a with clause of
-- another unit or,
-- 2) a required corresponding
-- library_unit_declaration
A_Nonexistent_Body, -- A unit that does not exist but is:
-- 1) known to be a corresponding
-- subunit or,
-- 2) a required corresponding
-- library_unit_body
A_Configuration_Compilation, -- Corresponds to the whole content of a
-- compilation with no compilation_unit,
-- but possibly containing comments,
-- configuration pragmas, or both.
-- A Context is not limited to the number
-- of units of A_Configuration_Compilation
-- kind. A unit of
-- A_Configuration_Compilation does not
-- have a name. This unit
-- represents configuration pragmas that
-- are "in effect". The only interface
-- that returns this unit kind is
-- Enclosing_Compilation_Unit when given
-- A_Pragma element obtained from
-- Configuration_Pragmas.
An_Unknown_Unit); -- An indeterminable or proprietary unit
subtype A_Subprogram_Declaration is Unit_Kinds range
A_Procedure ..
A_Function;
subtype A_Subprogram_Renaming is Unit_Kinds range
A_Procedure_Renaming ..
A_Function_Renaming;
subtype A_Generic_Unit_Declaration is Unit_Kinds range
A_Generic_Procedure ..
A_Generic_Package;
subtype A_Generic_Unit_Instance is Unit_Kinds range
A_Procedure_Instance ..
A_Package_Instance;
subtype A_Subprogram_Body is Unit_Kinds range
A_Procedure_Body ..
A_Function_Body;
subtype A_Library_Unit_Body is Unit_Kinds range
A_Procedure_Body ..
A_Package_Body;
subtype A_Generic_Renaming is Unit_Kinds range
A_Generic_Procedure_Renaming ..
A_Generic_Package_Renaming;
subtype A_Renaming is Unit_Kinds range
A_Procedure_Renaming ..
A_Generic_Package_Renaming;
subtype A_Subunit is Unit_Kinds range
A_Procedure_Body_Subunit ..
A_Protected_Body_Subunit;
-------------------------------------------------------------------------------
-- 3.12.2 type Unit_Classes
-------------------------------------------------------------------------------
-- Unit_Classes - classification of public, private, body, and subunit.
-------------------------------------------------------------------------------
type Unit_Classes is ( -- Reference Manual 10.1.1(12), 10.1.3
Not_A_Class, -- A nil, nonexistent, unknown,
-- or configuration compilation unit class.
A_Public_Declaration, -- library_unit_declaration or
-- library_unit_renaming_declaration.
A_Public_Body, -- library_unit_body interpreted only as a
-- completion. Its declaration is public.
A_Public_Declaration_And_Body,
-- subprogram_body interpreted as both a
-- declaration and body of a library
-- subprogram - Reference Manual 10.1.4(4).
A_Private_Declaration, -- private library_unit_declaration or
-- private library_unit_renaming_declaration.
A_Private_Body, -- library_unit_body interpreted only as a
-- completion. Its declaration is private.
A_Separate_Body); -- separate (parent_unit_name) proper_body.
-------------------------------------------------------------------------------
-- 3.12.3 type Unit_Origins
-------------------------------------------------------------------------------
-- Unit_Origins - classification of possible unit origination
-------------------------------------------------------------------------------
type Unit_Origins is (
Not_An_Origin, -- A nil or nonexistent unit origin
-- An_Unknown_Unit can be any origin
A_Predefined_Unit, -- Ada predefined language environment units
-- listed in Annex A(2). These include
-- Standard and the three root library
-- units: Ada, Interfaces, and System,
-- and their descendants. i.e., Ada.Text_Io,
-- Ada.Calendar, Interfaces.C, etc.
An_Implementation_Unit,
-- Implementation specific library units,
-- e.g., runtime support packages, utility
-- libraries, etc. It is not required
-- that any implementation supplied units
-- have this origin. This is a suggestion.
-- Implementations might provide, for
-- example, precompiled versions of public
-- domain software that could have
-- An_Application_Unit origin.
An_Application_Unit); -- Neither A_Predefined_Unit or
-- An_Implementation_Unit
-------------------------------------------------------------------------------
-- 3.12.4 type Relation_Kinds
-------------------------------------------------------------------------------
-- Relation_Kinds - classification of unit relationships
type Relation_Kinds is (
Ancestors,
Descendants,
-------------------------------------------------------------------------------
-- Definition: ANCESTORS of a unit; DESCENDANTS of a unit
--
-- Ancestors of a library unit are itself, its parent, its parent's
-- parent, and so on. (Standard is an ancestor of every library unit).
--
-- The Descendants relation is the inverse of the ancestor relation.
-- Reference Manual 10.1.1(11).
-------------------------------------------------------------------------------
Supporters,
-------------------------------------------------------------------------------
-- Definition: SUPPORTERS of a unit
--
-- Supporters of a compilation unit are units on which it semantically
-- depends. Reference Manual 10.1.1(26).
--
-- The Supporters relation is transitive; units that are supporters of library
-- units mentioned in a with clause of a compilation unit are also supporters
-- of that compilation unit.
--
-- A parent declaration is a Supporter of its descendant units.
--
-- Each library unit mentioned in the with clauses of a compilation unit
-- is a Supporter of that compilation unit and (recursively) any
-- completion, child units, or subunits that are included in the declarative
-- region of that compilation unit. Reference Manual 8.1(7-10).
--
-- A library_unit_body has as a Supporter, its corresponding
-- library_unit_declaration, if any.
--
-- The parent body of a subunit is a Supporter of the subunit.
--
-------------------------------------------------------------------------------
Dependents,
-------------------------------------------------------------------------------
-- Definition: DEPENDENTS of a unit
--
-- Dependents of a compilation unit are all the compilation units that
-- depend semantically on it.
--
-- The Dependents relation is transitive; Dependents of a unit include the
-- unit's Dependents, each dependent unit's Dependents, and so on. A unit
-- that is a dependent of a compilation unit also is a dependent
-- of the compilation unit's Supporters.
--
-- Child units are Dependents of their ancestor units.
--
-- A compilation unit that mentions other library units in its with
-- clauses is one of the Dependents of those library units.
--
-- A library_unit_body is a Dependent of its corresponding
-- library_unit_declaration, if any.
--
-- A subunit is a Dependent of its parent body.
--
-- A compilation unit that contains an attribute_reference of a type defined
-- in another compilation unit is a Dependent of the other unit.
--
-- For example:
--
-- If A withs B and B withs C
-- then A directly depends on A, B directly depends on C,
-- A indirectly depends on C, and
-- both A and B are dependents of C.
--
-- Dependencies between compilation units may also be introduced by
-- inline inclusions (Reference Manual 10.1.4(7)) and for certain other
-- compiler optimizations. These relations are intended to reflect all
-- of these considerations.
--
-------------------------------------------------------------------------------
Family,
-------------------------------------------------------------------------------
-- Definition: FAMILY of a unit
--
-- The family of a given unit is defined as the set of compilation
-- units that comprise the given unit's declaration, body, descendants,
-- and subunits (and subunits of subunits and descendants, etc.).
-------------------------------------------------------------------------------
Needed_Units);
-------------------------------------------------------------------------------
-- Definition: NEEDED UNITS of a unit; CLOSURE of a unit
--
-- The needed units of a given unit is defined as the set of all
-- the Ada units ultimately needed by that unit to form a partition.
-- Reference Manual 10.2(2-7).
--
-- The term closure is commonly used with similar meaning.
--
-- For example:
-- Assume the body of C has a subunit C.S and the declaration of C has
-- child units C.Y and C.Z.
--
-- If A withs B, B withs C, B withs C.Y, and C does not with a library
-- unit. Then the needed units of A are:
-- library unit declaration C
-- child library unit declaration C.Y
-- child library unit body C.Y, if any
-- library unit body C
-- subunit C.S
-- library unit declaration B
-- library unit body B, if any
-- library unit declaration A
-- library unit body A, if any
--
-- Child unit C.Z is only part of the Needed_Units if it is needed.
--
-------------------------------------------------------------------------------
-- 3.13 type Traverse_Control
-------------------------------------------------------------------------------
-- Traverse_Control - controls for the traversal generic provided in package
-- Asis.Iterator. It is defined in package Asis to facilitate automatic
-- translation to IDL (See Annex C for details).
-------------------------------------------------------------------------------
type Traverse_Control is (
Continue, -- Continues the normal depth-first traversal.
Abandon_Children, -- Prevents traversal of the current element's
-- children.
Abandon_Siblings, -- Prevents traversal of the current element's
-- children and remaining siblings.
Terminate_Immediately); -- Does exactly that.
-------------------------------------------------------------------------------
-- 3.14 type Program_Text
-------------------------------------------------------------------------------
subtype Program_Text is Wide_String;
-------------------------------------------------------------------------------
private
-- Private part of this
Unimplemented : exception;
Internal_Error : exception;
-------------------
-- Text_Position --
-------------------
type Text_Position is record
Line : Natural := 0;
Column : Natural := 0;
end record;
function "<" (Left, Right : Text_Position) return Boolean;
function To_Wide_String (Item : Text_Position) return Wide_String;
Nil_Text_Position : constant Text_Position := (0, 0);
type Gela_String is record
From, To : Source_Buffers.Cursor;
end record;
-----------------
-- Error_Level --
-----------------
type Error_Level is (Success, Warning, Error, Fatal);
type Element_Access is access all Asis.Element;
type Traverse_List_Item (Is_List : Boolean := False) is record
case Is_List is
when True =>
List : Asis.Element;
when False =>
Item : Element_Access;
end case;
end record;
type Traverse_List is array (Positive range <>) of Traverse_List_Item;
function Without_Pragmas (List : Element_List) return Element_List;
function Is_Equal (Left, Right : Element) return Boolean;
pragma Inline (Is_Equal);
procedure Raise_Inappropriate_Element (Raiser : Wide_String := "");
procedure Check_Context (The_Context : Asis.Context);
procedure Check_Nil_Element
(Element : Asis.Element;
Raiser : Wide_String := "");
procedure Check_Nil_Unit
(Unit : Asis.Compilation_Unit;
Raiser : Wide_String := "");
-------------
-- Context --
-------------
type Context_Node is abstract tagged limited null record;
type Context is access all Context_Node'Class;
procedure Associate
(The_Context : access Context_Node;
Name : in Wide_String;
Parameters : in Wide_String) is abstract;
procedure Open (The_Context : in out Context_Node) is abstract;
procedure Close (The_Context : in out Context_Node) is abstract;
procedure Dissociate (The_Context : in out Context_Node) is abstract;
function Is_Open (The_Context : Context_Node) return Boolean is abstract;
function Is_Equal
(Left : in Context_Node;
Right : in Context_Node)
return Boolean is abstract;
function Has_Associations (The_Context : Context_Node)
return Boolean is abstract;
function Context_Name (The_Context : Context_Node)
return Wide_String is abstract;
function Parameters (The_Context : Context_Node)
return Wide_String is abstract;
function Debug_Image (The_Context : Context_Node)
return Wide_String is abstract;
function Configuration_Pragmas
(The_Context : in Context_Node)
return Asis.Pragma_Element_List is abstract;
function Library_Unit_Declaration
(Name : in Wide_String;
The_Context : in Context_Node)
return Asis.Compilation_Unit is abstract;
function Compilation_Unit_Body
(Name : in Wide_String;
The_Context : in Context_Node)
return Asis.Compilation_Unit is abstract;
function Library_Unit_Declarations
(The_Context : in Context_Node)
return Asis.Compilation_Unit_List is abstract;
function Compilation_Unit_Bodies
(The_Context : in Context_Node)
return Asis.Compilation_Unit_List is abstract;
function Context_Compilation_Units
(The_Context : in Context_Node)
return Asis.Compilation_Unit_List is abstract;
function Corresponding_Children
(Library_Unit : in Asis.Compilation_Unit;
The_Context : in Context_Node)
return Asis.Compilation_Unit_List is abstract;
function Corresponding_Parent_Declaration
(Library_Unit : in Asis.Compilation_Unit;
The_Context : in Context_Node)
return Asis.Compilation_Unit is abstract;
function Corresponding_Declaration
(Library_Item : in Asis.Compilation_Unit;
The_Context : in Context_Node)
return Asis.Compilation_Unit is abstract;
function Corresponding_Body
(Library_Item : in Asis.Compilation_Unit;
The_Context : in Context_Node)
return Asis.Compilation_Unit is abstract;
function Subunits
(Parent_Body : in Asis.Compilation_Unit;
The_Context : in Context_Node)
return Asis.Compilation_Unit_List is abstract;
function Corresponding_Subunit_Parent_Body
(Subunit : in Asis.Compilation_Unit;
The_Context : in Context_Node)
return Asis.Compilation_Unit is abstract;
function Corresponding_Body
(Declaration : in Asis.Declaration;
The_Context : in Context_Node)
return Asis.Declaration is abstract;
function Corresponding_Body_Stub
(Subunit : in Asis.Declaration;
The_Context : in Context_Node)
return Asis.Declaration is abstract;
function Corresponding_Declaration
(Declaration : in Asis.Declaration;
The_Context : in Context_Node)
return Asis.Declaration is abstract;
function Corresponding_Subunit
(Body_Stub : in Asis.Declaration;
The_Context : in Context_Node)
return Asis.Declaration is abstract;
function Corresponding_Type_Declaration
(Declaration : in Asis.Declaration;
The_Context : in Context_Node)
return Asis.Declaration is abstract;
function Current_Unit
(The_Context : in Context_Node)
return Asis.Compilation_Unit is abstract;
function Current_File
(The_Context : in Context_Node)
return Wide_String is abstract;
function New_Compilation_Unit
(The_Context : access Context_Node)
return Asis.Compilation_Unit is abstract;
procedure Report_Error
(The_Context : in out Context_Node;
The_Unit : in Compilation_Unit;
Where : in Text_Position;
Text : in Wide_String;
Level : in Error_Level) is abstract;
function Check_Appropriate
(The_Context : in Context_Node)
return Boolean is abstract;
procedure Set_Check_Appropriate
(The_Context : in out Context_Node;
Value : in Boolean) is abstract;
Nil_Context : constant Context := null;
------------
-- Cloner --
------------
type Cloner is tagged limited null record;
function Clone
(Object : Cloner;
Item : Element;
Parent : Element) return Element;
subtype Cloner_Class is Cloner'Class;
function Deep_Copy
(Cloner : in Cloner_Class;
Source : in Element;
Parent : in Element) return Element;
function Copy
(Cloner : in Cloner_Class;
Source : in Element;
Parent : in Element) return Element;
------------------
-- Element_Node --
------------------
type Element_Node;
type Element is access all Element_Node'Class;
for Element'Storage_Size use 0;
type Element_Node_Ptr is access all Element_Node'Class;
for Element_Node_Ptr'Storage_Size use 0;
type Element_Node is abstract tagged limited record
Next : Element;
end record;
procedure Set_Next_Element
(Item : in out Element_Node;
Next : in Element);
function Children (Item : access Element_Node) return Traverse_List;
function Is_List (Item : Element_Node) return Boolean;
function Clone
(Item : Element_Node;
Parent : Element) return Element is abstract;
procedure Copy
(Source : in Element;
Target : access Element_Node;
Cloner : in Cloner_Class;
Parent : in Element);
function Aborted_Tasks
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Accept_Body_Exception_Handlers
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Accept_Body_Statements
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Accept_Entry_Direct_Name
(Element : Element_Node) return Asis.Name;
function Accept_Entry_Index
(Element : Element_Node) return Asis.Expression;
function Accept_Parameters
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Access_To_Function_Result_Subtype
(Element : Element_Node) return Asis.Definition;
function Get_Access_To_Object_Definition
(Element : Element_Node) return Asis.Subtype_Indication;
function Access_To_Subprogram_Parameter_Profile
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Access_Type_Kind
(Element : Element_Node) return Asis.Access_Type_Kinds;
function Actual_Parameter
(Element : Element_Node) return Asis.Expression;
function Allocator_Qualified_Expression
(Element : Element_Node) return Asis.Expression;
function Allocator_Subtype_Indication
(Element : Element_Node) return Asis.Subtype_Indication;
function Ancestor_Subtype_Indication
(Element : Element_Node) return Asis.Subtype_Indication;
function Anonymous_Access_To_Object_Subtype_Mark
(Element : Element_Node) return Asis.Name;
function Array_Component_Associations
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Array_Component_Choices
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Array_Component_Definition
(Element : Element_Node) return Asis.Component_Definition;
function Assignment_Expression
(Element : Element_Node) return Asis.Expression;
function Assignment_Variable_Name
(Element : Element_Node) return Asis.Expression;
function Attribute_Designator_Expressions
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Attribute_Designator_Identifier
(Element : Element_Node) return Asis.Expression;
function Attribute_Kind
(Element : Element_Node) return Asis.Attribute_Kinds;
function Block_Declarative_Items
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Block_Exception_Handlers
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Block_Statements
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Body_Declarative_Items
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Body_Exception_Handlers
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Body_Statements
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Call_Statement_Parameters
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Called_Name
(Element : Element_Node) return Asis.Expression;
function Case_Expression
(Element : Element_Node) return Asis.Expression;
function Case_Statement_Alternative_Choices
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Choice_Parameter_Specification
(Element : Element_Node) return Asis.Element;
function Clause_Names
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Component_Clause_Position
(Element : Element_Node) return Asis.Expression;
function Component_Clause_Range
(Element : Element_Node) return Asis.Discrete_Range;
function Component_Clauses
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Component_Expression
(Element : Element_Node) return Asis.Expression;
function Component_Subtype_Indication
(Element : Element_Node) return Asis.Subtype_Indication;
function Condition_Expression
(Element : Element_Node) return Asis.Expression;
function Converted_Or_Qualified_Expression
(Element : Element_Node) return Asis.Expression;
function Converted_Or_Qualified_Subtype_Mark
(Element : Element_Node) return Asis.Expression;
function Corresponding_Base_Entity
(Element : Element_Node) return Asis.Expression;
function Corresponding_Body
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Body_Stub
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Called_Entity
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Called_Function
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Constant_Declaration
(Element : Element_Node) return Asis.Element;
function Corresponding_Declaration
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Destination_Statement
(Element : Element_Node) return Asis.Statement;
function Corresponding_Entry
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Equality_Operator
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Expression_Type
(Element : Element_Node) return Asis.Element;
function Corresponding_First_Subtype
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Generic_Element
(Element : Element_Node) return Asis.Defining_Name;
function Corresponding_Last_Constraint
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Last_Subtype
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Loop_Exited
(Element : Element_Node) return Asis.Statement;
function Corresponding_Name_Declaration
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Name_Definition_List
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Corresponding_Parent_Subtype
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Pragmas
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Corresponding_Representation_Clauses
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Corresponding_Root_Type
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Subprogram_Derivation
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Subunit
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Type
(Element : Element_Node) return Asis.Type_Definition;
function Corresponding_Type_Declaration
(Element : Element_Node) return Asis.Declaration;
function Corresponding_Type_Operators
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Corresponding_Type_Structure
(Element : Element_Node) return Asis.Declaration;
function Declaration_Origin
(Element : Element_Node) return Asis.Declaration_Origins;
function Default_Kind
(Element : Element_Node) return Asis.Subprogram_Default_Kinds;
function Defining_Name_Image
(Element : Element_Node) return Wide_String;
function Defining_Prefix
(Element : Element_Node) return Asis.Name;
function Defining_Selector
(Element : Element_Node) return Asis.Defining_Name;
function Delay_Expression
(Element : Element_Node) return Asis.Expression;
function Delta_Expression
(Element : Element_Node) return Asis.Expression;
function Digits_Expression
(Element : Element_Node) return Asis.Expression;
function Discrete_Ranges
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Discrete_Subtype_Definitions
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Discriminant_Associations
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Discriminant_Direct_Name
(Element : Element_Node) return Asis.Name;
function Discriminant_Expression
(Element : Element_Node) return Asis.Expression;
function Discriminant_Part
(Element : Element_Node) return Asis.Definition;
function Discriminant_Selector_Name
(Element : Element_Node) return Asis.Expression;
function Discriminant_Selector_Names
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Discriminants
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Enclosing_Compilation_Unit
(Element : Element_Node) return Asis.Compilation_Unit;
function Enclosing_Element
(Element : Element_Node) return Asis.Element;
function End_Position
(Element : Element_Node) return Asis.Text_Position;
function Entry_Barrier
(Element : Element_Node) return Asis.Expression;
function Entry_Family_Definition
(Element : Element_Node) return Asis.Discrete_Subtype_Definition;
function Entry_Index_Specification
(Element : Element_Node) return Asis.Declaration;
function Enumeration_Literal_Declarations
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Exception_Choices
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Exception_Handlers
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Exit_Condition
(Element : Element_Node) return Asis.Expression;
function Exit_Loop_Name
(Element : Element_Node) return Asis.Expression;
function Expression_Parenthesized
(Element : Element_Node) return Asis.Expression;
function Extended_Return_Exception_Handlers
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Extended_Return_Statements
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Extension_Aggregate_Expression
(Element : Element_Node) return Asis.Expression;
function Formal_Parameter
(Element : Element_Node) return Asis.Identifier;
function Formal_Subprogram_Default
(Element : Element_Node) return Asis.Expression;
function Function_Call_Parameters
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Generic_Actual_Part
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Generic_Formal_Part
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Generic_Unit_Name
(Element : Element_Node) return Asis.Expression;
function Goto_Label
(Element : Element_Node) return Asis.Expression;
function Guard
(Element : Element_Node) return Asis.Expression;
function Handler_Statements
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Has_Abstract
(Element : Element_Node) return Boolean;
function Has_Limited
(Element : Element_Node) return Boolean;
function Has_Null_Exclusion
(Element : Element_Node) return Boolean;
function Has_Private
(Element : Element_Node) return Boolean;
function Has_Protected
(Element : Element_Node) return Boolean;
function Has_Synchronized
(Element : Element_Node) return Boolean;
function Has_Tagged
(Element : Element_Node) return Boolean;
function Has_Task
(Element : Element_Node) return Boolean;
function Hash
(Element : Element_Node) return Asis.ASIS_Integer;
function Implicit_Components
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Implicit_Inherited_Declarations
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Implicit_Inherited_Subprograms
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Index_Expressions
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Index_Subtype_Definitions
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Initialization_Expression
(Element : Element_Node) return Asis.Expression;
function Integer_Constraint
(Element : Element_Node) return Asis.Range_Constraint;
function Interface_Kind
(Element : Element_Node) return Asis.Interface_Kinds;
function Is_Call_On_Dispatching_Operation
(Element : Element_Node) return Boolean;
function Is_Declare_Block
(Element : Element_Node) return Boolean;
function Is_Defaulted_Association
(Element : Element_Node) return Boolean;
function Is_Dispatching_Call
(Element : Element_Node) return Boolean;
function Is_Dispatching_Operation
(Element : Element_Node) return Boolean;
function Is_Name_Repeated
(Element : Element_Node) return Boolean;
function Is_Normalized
(Element : Element_Node) return Boolean;
function Is_Null_Procedure
(Element : Element_Node) return Boolean;
function Is_Part_Of_Implicit
(Element : Element_Node) return Boolean;
function Is_Part_Of_Inherited
(Element : Element_Node) return Boolean;
function Is_Part_Of_Instance
(Element : Element_Node) return Boolean;
function Is_Prefix_Call
(Element : Element_Node) return Boolean;
function Is_Private_Present
(Element : Element_Node) return Boolean;
function Is_Task_Definition_Present
(Element : Element_Node) return Boolean;
function Label_Names
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Loop_Parameter_Specification
(Element : Element_Node) return Asis.Declaration;
function Loop_Statements
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Lower_Bound
(Element : Element_Node) return Asis.Expression;
function Membership_Test_Expression
(Element : Element_Node) return Asis.Expression;
function Membership_Test_Range
(Element : Element_Node) return Asis.Range_Constraint;
function Membership_Test_Subtype_Mark
(Element : Element_Node) return Asis.Expression;
function Mod_Clause_Expression
(Element : Element_Node) return Asis.Expression;
function Mod_Static_Expression
(Element : Element_Node) return Asis.Expression;
function Mode_Kind
(Element : Element_Node) return Asis.Mode_Kinds;
function Name_Image
(Element : Element_Node) return Wide_String;
function Names
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Next_Element
(Element : Element_Node) return Asis.Element;
function Normalized_Call_Statement_Parameters
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Normalized_Discriminant_Associations
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Normalized_Function_Call_Parameters
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Normalized_Generic_Actual_Part
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Normalized_Record_Component_Associations
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Object_Declaration_Subtype
(Element : Element_Node) return Asis.Definition;
function Operator_Kind
(Element : Element_Node) return Asis.Operator_Kinds;
function Overriding_Indicator_Kind
(Element : Element_Node) return Asis.Overriding_Indicator_Kinds;
function Parameter_Profile
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Parent_Subtype_Indication
(Element : Element_Node) return Asis.Subtype_Indication;
function Position_Number_Image
(Element : Element_Node) return Wide_String;
function Pragma_Argument_Associations
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Pragma_Kind
(Element : Element_Node) return Asis.Pragma_Kinds;
function Pragma_Name_Image
(Element : Element_Node) return Wide_String;
function Pragmas
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Prefix
(Element : Element_Node) return Asis.Expression;
function Private_Part_Declarative_Items
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Private_Part_Items
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Profile
(Element : Element_Node) return Asis.Element;
function Progenitor_List
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Protected_Operation_Items
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Qualified_Expression
(Element : Element_Node) return Asis.Expression;
function Raise_Statement_Message
(Element : Element_Node) return Asis.Expression;
function Raised_Exception
(Element : Element_Node) return Asis.Expression;
function Range_Attribute
(Element : Element_Node) return Asis.Expression;
function Raw_Image
(Element : Element_Node) return Gela_String;
function Real_Range_Constraint
(Element : Element_Node) return Asis.Range_Constraint;
function Record_Component_Associations
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Record_Component_Choice
(Element : Element_Node) return Asis.Defining_Name;
function Record_Component_Choices
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Record_Components
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Get_Record_Definition
(Element : Element_Node) return Asis.Definition;
function References
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Renamed_Entity
(Element : Element_Node) return Asis.Expression;
function Representation_Clause_Expression
(Element : Element_Node) return Asis.Expression;
function Representation_Clause_Name
(Element : Element_Node) return Asis.Name;
function Representation_Value_Image
(Element : Element_Node) return Wide_String;
function Requeue_Entry_Name
(Element : Element_Node) return Asis.Name;
function Result_Subtype
(Element : Element_Node) return Asis.Definition;
function Return_Expression
(Element : Element_Node) return Asis.Expression;
function Return_Object_Specification
(Element : Element_Node) return Asis.Declaration;
function Root_Type_Kind
(Element : Element_Node) return Asis.Root_Type_Kinds;
function Selector
(Element : Element_Node) return Asis.Expression;
function Sequence_Of_Statements
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Short_Circuit_Operation_Left_Expression
(Element : Element_Node) return Asis.Expression;
function Short_Circuit_Operation_Right_Expression
(Element : Element_Node) return Asis.Expression;
function Slice_Range
(Element : Element_Node) return Asis.Discrete_Range;
function Specification_Subtype_Definition
(Element : Element_Node) return Asis.Discrete_Subtype_Definition;
function Start_Position
(Element : Element_Node) return Asis.Text_Position;
function Statement_Identifier
(Element : Element_Node) return Asis.Defining_Name;
function Statement_Paths
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Subtype_Constraint
(Element : Element_Node) return Asis.Constraint;
function Get_Subtype_Mark
(Element : Element_Node) return Asis.Expression;
function Trait_Kind
(Element : Element_Node) return Asis.Trait_Kinds;
function Type_Declaration_View
(Element : Element_Node) return Asis.Definition;
function Upper_Bound
(Element : Element_Node) return Asis.Expression;
function Value_Image
(Element : Element_Node) return Wide_String;
function Variant_Choices
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Variants
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Visible_Part_Declarative_Items
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function Visible_Part_Items
(Element : Element_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
function While_Condition
(Element : Element_Node) return Asis.Expression;
function Access_Definition_Kind (Element : Element_Node)
return Asis.Access_Definition_Kinds;
function Association_Kind (Element : Element_Node)
return Asis.Association_Kinds;
function Clause_Kind (Element : Element_Node)
return Asis.Clause_Kinds;
function Constraint_Kind (Element : Element_Node)
return Asis.Constraint_Kinds;
function Declaration_Kind (Element : Element_Node)
return Asis.Declaration_Kinds;
function Defining_Name_Kind (Element : Element_Node)
return Asis.Defining_Name_Kinds;
function Definition_Kind (Element : Element_Node)
return Asis.Definition_Kinds;
function Discrete_Range_Kind (Element : Element_Node)
return Asis.Discrete_Range_Kinds;
function Element_Kind (Element : Element_Node)
return Asis.Element_Kinds;
function Expression_Kind (Element : Element_Node)
return Asis.Expression_Kinds;
function Formal_Type_Definition_Kind (Element : Element_Node)
return Asis.Formal_Type_Kinds;
function Path_Kind (Element : Element_Node)
return Asis.Path_Kinds;
function Representation_Clause_Kind (Element : Element_Node)
return Asis.Representation_Clause_Kinds;
function Statement_Kind (Element : Element_Node)
return Asis.Statement_Kinds;
function Type_Definition_Kind (Element : Element_Node)
return Asis.Type_Kinds;
Nil_Element : constant Element := null;
Nil_Element_List : constant Element_List (1 .. 0) :=
(1 .. 0 => null);
----------------------
-- Compilation_Unit --
----------------------
type Compilation_Unit_Node is abstract new Element_Node with null record;
type Compilation_Unit is access all Compilation_Unit_Node'Class;
for Compilation_Unit'Storage_Size use 0;
function Can_Be_Main_Program
(Element : Compilation_Unit_Node) return Boolean
is abstract;
function Compilation_Command_Line_Options
(Element : Compilation_Unit_Node) return Wide_String
is abstract;
function Compilation_Pragmas
(Element : Compilation_Unit_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List
is abstract;
function Context_Clause_Elements
(Element : Compilation_Unit_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List
is abstract;
function Corresponding_Body
(Element : Compilation_Unit_Node) return Asis.Compilation_Unit
is abstract;
function Corresponding_Children
(Element : Compilation_Unit_Node) return Asis.Compilation_Unit_List
is abstract;
function Corresponding_Declaration
(Element : Compilation_Unit_Node) return Asis.Compilation_Unit
is abstract;
function Corresponding_Parent_Declaration
(Element : Compilation_Unit_Node) return Asis.Compilation_Unit
is abstract;
function Corresponding_Subunit_Parent_Body
(Element : Compilation_Unit_Node) return Asis.Compilation_Unit
is abstract;
function Enclosing_Context
(Element : Compilation_Unit_Node) return Asis.Context
is abstract;
function End_Position
(Element : Compilation_Unit_Node) return Asis.Text_Position
is abstract;
function Hash
(Element : Compilation_Unit_Node) return Asis.ASIS_Integer
is abstract;
function Is_Body_Required
(Element : Compilation_Unit_Node) return Boolean
is abstract;
function Next_Element
(Element : Compilation_Unit_Node) return Asis.Element
is abstract;
function Object_Form
(Element : Compilation_Unit_Node) return Wide_String
is abstract;
function Object_Name
(Element : Compilation_Unit_Node) return Wide_String
is abstract;
function Separate_Name_Image
(Element : Compilation_Unit_Node) return Wide_String
is abstract;
function Start_Position
(Element : Compilation_Unit_Node) return Asis.Text_Position
is abstract;
function Subunits
(Element : Compilation_Unit_Node) return Asis.Compilation_Unit_List
is abstract;
function Text_Form
(Element : Compilation_Unit_Node) return Wide_String
is abstract;
function Text_Name
(Element : Compilation_Unit_Node) return Wide_String
is abstract;
function Unique_Name
(Element : Compilation_Unit_Node) return Wide_String
is abstract;
function Unit_Class
(Element : Compilation_Unit_Node) return Asis.Unit_Classes
is abstract;
function Unit_Declaration
(Element : Compilation_Unit_Node) return Asis.Element
is abstract;
function Unit_Full_Name
(Element : Compilation_Unit_Node) return Wide_String
is abstract;
function Unit_Kind
(Element : Compilation_Unit_Node) return Asis.Unit_Kinds
is abstract;
function Unit_Origin
(Element : Compilation_Unit_Node) return Asis.Unit_Origins
is abstract;
Nil_Compilation_Unit : constant Compilation_Unit := null;
Nil_Compilation_Unit_List : constant Compilation_Unit_List (1 .. 0) :=
(1 .. 0 => null);
function Assigned (Item : in Context) return Boolean;
function Assigned (Item : in Compilation_Unit) return Boolean;
function Assigned (Item : in Element) return Boolean;
pragma Inline (Assigned);
end Asis;
------------------------------------------------------------------------------
-- Copyright (c) 2006-2013, Maxim Reznik
-- 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 Maxim Reznik, 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 OWNER OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
|
with RTCH.Colours; use RTCH.Colours;
package RTCH.Visuals.Canvases with
Preelaborate is
-- type Pixel_Array is array (Positive range <>, Positive range <>) of Colour;
type Canvas is array (Positive range <>, Positive range <>) of Colour;
type Canvas_Access is access all Canvas;
function Make_Canvas (Width, Height : in Positive) return Canvas_Access;
function Get_Width (C : in Canvas) return Positive is (C'Length (1));
function Get_Height (C : in Canvas) return Positive is (C'Length (2));
procedure Set_Pixel (C : in out Canvas; X, Y : in Positive; Colour : in Colours.Colour);
function Get_Pixel (C : in Canvas; X, Y : in Positive) return Colour is (C (X, Y));
-- type Canvas (Width, Height : Positive) is record
-- Pixels : Pixel_Array (1 .. Width, 1 .. Height) := ((others => (others => Make_Colour (0.0, 0.0, 0.0))));
-- end record;
end RTCH.Visuals.Canvases;
|
package body agar.gui.text is
use type c.int;
package cbinds is
function render (text : cs.chars_ptr) return agar.gui.surface.surface_access_t;
pragma import (c, render, "agar_gui_text_render");
function render_ucs4 (text : access c.char32_t) return agar.gui.surface.surface_access_t;
pragma import (c, render_ucs4, "AG_TextRenderUCS4");
procedure size
(text : cs.chars_ptr;
width : access c.int;
height : access c.int);
pragma import (c, size, "AG_TextSize");
procedure size_ucs4
(text : access c.char32_t;
width : access c.int;
height : access c.int);
pragma import (c, size_ucs4, "AG_TextSizeUCS4");
procedure msg
(title : msg_title_t;
text : cs.chars_ptr);
pragma import (c, msg, "AG_TextMsgS");
procedure warning
(disable_key : cs.chars_ptr;
text : cs.chars_ptr);
pragma import (c, warning, "AG_TextWarningS");
procedure info
(disable_key : cs.chars_ptr;
text : cs.chars_ptr);
pragma import (c, info, "AG_TextInfoS");
procedure timed_message
(title : msg_title_t;
expire : agar.core.types.uint32_t;
text : cs.chars_ptr);
pragma import (c, timed_message, "AG_TextTmsgS");
procedure prompt_string
(prompt : cs.chars_ptr;
ok_func : access procedure (event : agar.core.event.event_access_t);
fmt : cs.chars_ptr;
text : cs.chars_ptr);
pragma import (c, prompt_string, "AG_TextPromptString");
procedure parse_font_spec (spec : cs.chars_ptr);
pragma import (c, parse_font_spec, "AG_TextParseFontSpec");
end cbinds;
function render (text : string) return agar.gui.surface.surface_access_t is
ca_text : aliased c.char_array := c.to_c (text);
begin
return cbinds.render (cs.to_chars_ptr (ca_text'unchecked_access));
end render;
-- this is probably as close to UCS4 as is possible here
function render_ucs4 (text : wide_wide_string) return agar.gui.surface.surface_access_t is
ca_text : aliased c.char32_array := c.to_c (text);
begin
return cbinds.render_ucs4 (ca_text (ca_text'first)'unchecked_access);
end render_ucs4;
procedure size
(text : string;
width : out positive;
height : out positive)
is
c_width : aliased c.int;
c_height : aliased c.int;
c_text : aliased c.char_array := c.to_c (text);
begin
cbinds.size
(text => cs.to_chars_ptr (c_text'unchecked_access),
height => c_height'unchecked_access,
width => c_width'unchecked_access);
width := positive (c_width);
height := positive (c_height);
end size;
procedure size_ucs4
(text : wide_wide_string;
width : out positive;
height : out positive)
is
c_width : aliased c.int;
c_height : aliased c.int;
c_text : aliased c.char32_array := c.to_c (text);
begin
cbinds.size_ucs4
(text => c_text (c_text'first)'unchecked_access,
height => c_height'unchecked_access,
width => c_width'unchecked_access);
width := positive (c_width);
height := positive (c_height);
end size_ucs4;
procedure msg
(title : msg_title_t;
text : string)
is
ca_text : aliased c.char_array := c.to_c (text);
begin
cbinds.msg
(title => title,
text => cs.to_chars_ptr (ca_text'unchecked_access));
end msg;
procedure warning
(disable_key : string;
text : string)
is
ca_disa : aliased c.char_array := c.to_c (disable_key);
ca_text : aliased c.char_array := c.to_c (text);
begin
cbinds.warning
(disable_key => cs.to_chars_ptr (ca_disa'unchecked_access),
text => cs.to_chars_ptr (ca_text'unchecked_access));
end warning;
procedure info
(disable_key : string;
text : string)
is
ca_disa : aliased c.char_array := c.to_c (disable_key);
ca_text : aliased c.char_array := c.to_c (text);
begin
cbinds.info
(disable_key => cs.to_chars_ptr (ca_disa'unchecked_access),
text => cs.to_chars_ptr (ca_text'unchecked_access));
end info;
procedure timed_message
(title : msg_title_t;
expire : agar.core.types.uint32_t;
text : string)
is
ca_text : aliased c.char_array := c.to_c (text);
begin
cbinds.timed_message
(title => title,
expire => expire,
text => cs.to_chars_ptr (ca_text'unchecked_access));
end timed_message;
procedure prompt_string
(prompt : string;
ok_func : access procedure (event : agar.core.event.event_access_t);
text : string)
is
ca_fmt : aliased c.char_array := c.to_c ("%s");
ca_prmp : aliased c.char_array := c.to_c (prompt);
ca_text : aliased c.char_array := c.to_c (text);
begin
cbinds.prompt_string
(prompt => cs.to_chars_ptr (ca_prmp'unchecked_access),
ok_func => ok_func,
fmt => cs.to_chars_ptr (ca_fmt'unchecked_access),
text => cs.to_chars_ptr (ca_text'unchecked_access));
end prompt_string;
procedure parse_font_spec (spec : string) is
ca_spec : aliased c.char_array := c.to_c (spec);
begin
cbinds.parse_font_spec (cs.to_chars_ptr (ca_spec'unchecked_access));
end parse_font_spec;
end agar.gui.text;
|
-----------------------------------------------------------------------
-- Security-oauth-clients-tests - Unit tests for OAuth
-- Copyright (C) 2013 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings.Fixed;
with Util.Test_Caller;
with Util.Measures;
with Util.Strings.Sets;
package body Security.OAuth.Clients.Tests is
package Caller is new Util.Test_Caller (Test, "Security.OAuth.Clients");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test Security.OAuth.Clients.Create_Nonce",
Test_Create_Nonce'Access);
Caller.Add_Test (Suite, "Test Security.OAuth.Clients.Get_State",
Test_Get_State'Access);
Caller.Add_Test (Suite, "Test Security.OAuth.Clients.Is_Valid_State",
Test_Is_Valid_State'Access);
Caller.Add_Test (Suite, "Test Security.OAuth.Clients.Get_Auth_Params",
Test_Get_Auth_Params'Access);
end Add_Tests;
-- ------------------------------
-- Test Create_Nonce operation.
-- ------------------------------
procedure Test_Create_Nonce (T : in out Test) is
Nonces : Util.Strings.Sets.Set;
begin
for I in 1 .. 1_000 loop
for I in 32 .. 734 loop
declare
S : constant String := Create_Nonce (I * 3);
begin
T.Assert (not Nonces.Contains (S), "Nonce was not unique: " & S);
Nonces.Include (S);
end;
end loop;
end loop;
declare
S : Util.Measures.Stamp;
begin
for I in 1 .. 1_000 loop
declare
Nonce : constant String := Create_Nonce (128);
pragma Unreferenced (Nonce);
begin
null;
end;
end loop;
Util.Measures.Report (S, "128 bits nonce generation", 1_000);
end;
end Test_Create_Nonce;
-- ------------------------------
-- Test the Get_State operation.
-- ------------------------------
procedure Test_Get_State (T : in out Test) is
App : Application;
Nonce : constant String := Create_Nonce (128);
begin
App.Set_Application_Identifier ("test");
Util.Tests.Assert_Equals (T, "test", App.Get_Application_Identifier, "Invalid application");
App.Set_Application_Secret ("my-secret");
App.Set_Application_Callback ("my-callback");
App.Set_Provider_URI ("http://my-provider");
declare
State : constant String := App.Get_State (Nonce);
begin
T.Assert (State'Length > 25, "State is too small: " & State);
T.Assert (Ada.Strings.Fixed.Index (State, Nonce) = 0,
"The state must not contain the nonce");
-- Calling Get_State with the same nonce should produce the same result.
Util.Tests.Assert_Equals (T, State, App.Get_State (Nonce), "Invalid state");
App.Set_Application_Secret ("second-secret");
declare
State2 : constant String := App.Get_State (Nonce);
begin
T.Assert (State /= State2,
"Changing the application key should produce a different state");
end;
-- Restore the secret and change the callback.
App.Set_Application_Secret ("my-secret");
App.Set_Application_Callback ("my-callback2");
declare
State2 : constant String := App.Get_State (Nonce);
begin
T.Assert (State /= State2,
"Changing the application callback should produce a different state");
end;
-- Restore the callback and change the client Id.
App.Set_Application_Callback ("my-callback");
App.Set_Application_Identifier ("test2");
declare
State2 : constant String := App.Get_State (Nonce);
begin
T.Assert (State /= State2,
"Changing the application identifier should produce a different state");
end;
end;
end Test_Get_State;
-- ------------------------------
-- Test the Is_Valid_State operation.
-- ------------------------------
procedure Test_Is_Valid_State (T : in out Test) is
App : Application;
begin
App.Set_Application_Identifier ("test");
Util.Tests.Assert_Equals (T, "test", App.Get_Application_Identifier, "Invalid application");
App.Set_Application_Secret ("my-secret");
App.Set_Application_Callback ("my-callback");
App.Set_Provider_URI ("http://my-provider");
for I in 1 .. 100 loop
declare
Nonce : constant String := Create_Nonce (128);
State : constant String := App.Get_State (Nonce);
begin
T.Assert (State'Length > 25, "State is too small: " & State);
T.Assert (App.Is_Valid_State (Nonce, State), "Invalid state: " & State);
T.Assert (not App.Is_Valid_State ("", State), "State was valid with invalid nonce");
T.Assert (not App.Is_Valid_State (State, State), "State must be invalid");
T.Assert (not App.Is_Valid_State (Nonce, State & "d"), "State must be invalid");
end;
end loop;
end Test_Is_Valid_State;
-- Test the Get_Auth_Params operation.
procedure Test_Get_Auth_Params (T : in out Test) is
App : Application;
begin
App.Set_Application_Identifier ("test");
Util.Tests.Assert_Equals (T, "test", App.Get_Application_Identifier, "Invalid application");
App.Set_Application_Secret ("my-secret");
App.Set_Application_Callback ("my-callback");
App.Set_Provider_URI ("http://my-provider");
declare
P : constant String := App.Get_Auth_Params ("the-state", "the-scope");
begin
Util.Tests.Assert_Equals (T, "client_id=test&redirect_uri=my-callback&"
& "scope=the-scope&state=the-state", P,
"Invalid auth params");
end;
end Test_Get_Auth_Params;
end Security.OAuth.Clients.Tests;
|
package Emulator_8080 is
type Byte_Type is mod 256;
for Byte_Type'Size use 8;
type Byte_Array_Type is array(Natural range <>) of Byte_Type;
end Emulator_8080;
|
-----------------------------------------------------------------------
-- util-beans-objects-record_tests -- Unit tests for objects.records package
-- Copyright (C) 2011, 2017 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Test_Caller;
with Util.Strings;
with Util.Beans.Basic;
with Util.Beans.Objects.Vectors;
with Util.Beans.Objects.Records;
package body Util.Beans.Objects.Record_Tests is
use Util.Tests;
package Caller is new Util.Test_Caller (Test, "Objects.Records");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test Util.Beans.Objects.Records",
Test_Record'Access);
Caller.Add_Test (Suite, "Test Util.Beans.Basic",
Test_Bean'Access);
end Add_Tests;
type Data is record
Name : Unbounded_String;
Value : Util.Beans.Objects.Object;
end record;
package Data_Bean is new Util.Beans.Objects.Records (Data);
use type Data_Bean.Element_Type_Access;
subtype Data_Access is Data_Bean.Element_Type_Access;
procedure Test_Record (T : in out Test) is
D : Data;
begin
D.Name := To_Unbounded_String ("testing");
D.Value := To_Object (Integer (23));
declare
V : Object := Data_Bean.To_Object (D);
P : constant Data_Access := Data_Bean.To_Element_Access (V);
V2 : constant Object := V;
begin
T.Assert (not Is_Empty (V), "Object with data record should not be empty");
T.Assert (not Is_Null (V), "Object with data record should not be null");
T.Assert (P /= null, "To_Element_Access returned null");
Assert_Equals (T, "testing", To_String (P.Name), "Data name is not the same");
Assert_Equals (T, 23, To_Integer (P.Value), "Data value is not the same");
V := Data_Bean.Create;
declare
D2 : constant Data_Access := Data_Bean.To_Element_Access (V);
begin
T.Assert (D2 /= null, "Null element");
D2.Name := To_Unbounded_String ("second test");
D2.Value := V2;
end;
V := Data_Bean.To_Object (D);
end;
end Test_Record;
type Bean_Type is new Util.Beans.Basic.Readonly_Bean with record
Name : Unbounded_String;
end record;
type Bean_Type_Access is access all Bean_Type'Class;
overriding
function Get_Value (Bean : in Bean_Type;
Name : in String) return Util.Beans.Objects.Object;
overriding
function Get_Value (Bean : in Bean_Type;
Name : in String) return Util.Beans.Objects.Object is
begin
if Name = "name" then
return Util.Beans.Objects.To_Object (Bean.Name);
elsif Name = "length" then
return Util.Beans.Objects.To_Object (Length (Bean.Name));
else
return Util.Beans.Objects.Null_Object;
end if;
end Get_Value;
procedure Test_Bean (T : in out Test) is
use Basic;
Static : aliased Bean_Type;
begin
Static.Name := To_Unbounded_String ("Static");
-- Allocate dynamically several Bean_Type objects and drop the list.
-- The memory held by internal proxy as well as the Bean_Type must be freed.
-- The static bean should never be freed!
for I in 1 .. 10 loop
declare
List : Util.Beans.Objects.Vectors.Vector;
Value : Util.Beans.Objects.Object;
Bean : Bean_Type_Access;
P : access Readonly_Bean'Class;
begin
for J in 1 .. 1_000 loop
if I = J then
Value := To_Object (Static'Unchecked_Access, Objects.STATIC);
List.Append (Value);
end if;
Bean := new Bean_Type;
Bean.Name := To_Unbounded_String ("B" & Util.Strings.Image (J));
Value := To_Object (Bean);
List.Append (Value);
end loop;
-- Verify each bean of the list
for J in 1 .. 1_000 + 1 loop
Value := List.Element (J);
-- Check some common status.
T.Assert (not Is_Null (Value), "The value should hold a bean");
T.Assert (Get_Type (Value) = TYPE_BEAN, "The value should hold a bean");
T.Assert (not Is_Empty (Value), "The value should not be empty");
-- Check the bean access.
P := To_Bean (Value);
T.Assert (P /= null, "To_Bean returned null");
Bean := Bean_Type'Class (P.all)'Unchecked_Access;
-- Check we have the good bean object.
if I = J then
Assert_Equals (T, "Static", To_String (Bean.Name),
"Bean at" & Integer'Image (J) & " is invalid");
elsif J > I then
Assert_Equals (T, "B" & Util.Strings.Image (J - 1), To_String (Bean.Name),
"Bean at" & Integer'Image (J) & " is invalid");
else
Assert_Equals (T, "B" & Util.Strings.Image (J), To_String (Bean.Name),
"Bean at" & Integer'Image (J) & " is invalid");
end if;
end loop;
end;
end loop;
end Test_Bean;
end Util.Beans.Objects.Record_Tests;
|
--//////////////////////////////////////////////////////////
-- //
-- // SFML - Simple and Fast Multimedia Library
-- // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
-- //
-- // This software is provided 'as-is', without any express or implied warranty.
-- // In no event will the authors be held liable for any damages arising from the use of this software.
-- //
-- // Permission is granted to anyone to use this software for any purpose,
-- // including commercial applications, and to alter it and redistribute it freely,
-- // subject to the following restrictions:
-- //
-- // 1. The origin of this software must not be misrepresented;
-- // you must not claim that you wrote the original software.
-- // If you use this software in a product, an acknowledgment
-- // in the product documentation would be appreciated but is not required.
-- //
-- // 2. Altered source versions must be plainly marked as such,
-- // and must not be misrepresented as being the original software.
-- //
-- // 3. This notice may not be removed or altered from any source distribution.
-- //
--//////////////////////////////////////////////////////////
--//////////////////////////////////////////////////////////
-- SFML - Simple and Fast Multimedia Library
-- Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
-- This software is provided 'as-is', without any express or implied warranty.
-- In no event will the authors be held liable for any damages arising from the use of this software.
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it freely,
-- subject to the following restrictions:
-- 1. The origin of this software must not be misrepresented;
-- you must not claim that you wrote the original software.
-- If you use this software in a product, an acknowledgment
-- in the product documentation would be appreciated but is not required.
-- 2. Altered source versions must be plainly marked as such,
-- and must not be misrepresented as being the original software.
-- 3. This notice may not be removed or altered from any source distribution.
--//////////////////////////////////////////////////////////
--//////////////////////////////////////////////////////////
with Interfaces.C;
with System;
with Ada.Strings.Unbounded;
--/ @image ASFML_Logo.svg
--/ @summary
--/ ASFML: Ada binding to the SFML library
--/
--/ @description
--/ Root package of all the packages provided by SFML. Direct children are the
--/ SFML modules: Audio, Graphics, Network, System and Window.
package Sf is
--//////////////////////////////////////////////////////////
-- // Define the CSFML version
--//////////////////////////////////////////////////////////
Version_Major : constant := 2;
Version_Minor : constant := 5;
Version_Patch : constant := 0;
--//////////////////////////////////////////////////////////
-- // Define a portable boolean type
--//////////////////////////////////////////////////////////
type sfBool is new Boolean;
for sfBool'Size use Interfaces.C.Int'Size;
for sfBool use (False => 0, True => 1);
sfFalse : sfBool renames False;
sfTrue : sfBool renames True;
--//////////////////////////////////////////////////////////
-- // Define portable types
--//////////////////////////////////////////////////////////
-- // 8 bits integer types
type sfInt8 is range -128 .. 127;
for sfInt8'SIZE use 8;
type sfInt8_Ptr is access all sfInt8;
pragma Convention (C, sfInt8);
pragma Convention (C, sfInt8_Ptr);
type sfUint8 is mod 256;
for sfUint8'SIZE use 8;
type sfUint8_Ptr is access all sfUint8;
pragma Convention (C, sfUint8);
pragma Convention (C, sfUint8_Ptr);
-- // 16 bits integer types
type sfInt16 is new Interfaces.Integer_16;
type sfInt16_Ptr is access all sfInt16;
pragma Convention (C, sfInt16);
pragma Convention (C, sfInt16_Ptr);
type sfUint16 is mod 2 ** sfInt16'SIZE;
type sfUint16_Ptr is access all sfUint16;
pragma Convention (C, sfUint16);
pragma Convention (C, sfUint16_Ptr);
-- // 32 bits integer types
type sfInt32 is new Integer;
type sfInt32_Ptr is access all sfInt32;
pragma Convention (C, sfInt32);
pragma Convention (C, sfInt32_Ptr);
type sfUint32 is mod 2 ** sfInt32'SIZE;
type sfUint32_Ptr is access all sfUint32;
pragma Convention (C, sfUint32);
pragma Convention (C, sfUint32_Ptr);
-- // 64 bits integer types
type sfInt64 is new Interfaces.Integer_64;
type sfInt64_Ptr is access all sfInt64;
pragma Convention (C, sfInt64);
pragma Convention (C, sfInt64_Ptr);
type sfUint64 is new Interfaces.Unsigned_64;
type sfUint64_Ptr is access all sfUint64;
pragma Convention (C, sfUint64_Ptr);
-- // size_t
type sfSize_t is mod 2 ** Standard'ADDRESS_SIZE;
type sfSize_t_Ptr is access all sfSize_t;
pragma Convention (C, sfSize_t);
pragma Convention (C, sfSize_t_Ptr);
type sfArrayOfStrings is array (sfSize_t range <>) of
Ada.Strings.Unbounded.Unbounded_String;
end Sf;
|
------------------------------------------------------------------------------
-- Copyright (c) 2006-2013, Maxim Reznik
-- 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 Maxim Reznik, 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 OWNER OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
package body Asis.Gela.Elements.Defs is
function Corresponding_Type_Operators
(Element : Type_Definition_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Secondary_Declaration_Lists.To_Element_List
(Element.Corresponding_Type_Operators, Include_Pragmas);
end Corresponding_Type_Operators;
procedure Add_To_Corresponding_Type_Operators
(Element : in out Type_Definition_Node;
Item : in Asis.Element) is
begin
Secondary_Declaration_Lists.Add (Element.Corresponding_Type_Operators, Item);
end Add_To_Corresponding_Type_Operators;
function Definition_Kind (Element : Type_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Type_Definition;
end;
function Get_Subtype_Mark
(Element : Subtype_Indication_Node) return Asis.Expression is
begin
return Element.Subtype_Mark;
end Get_Subtype_Mark;
procedure Set_Subtype_Mark
(Element : in out Subtype_Indication_Node;
Value : in Asis.Expression) is
begin
Element.Subtype_Mark := Value;
end Set_Subtype_Mark;
function Subtype_Constraint
(Element : Subtype_Indication_Node) return Asis.Constraint is
begin
return Element.Subtype_Constraint;
end Subtype_Constraint;
procedure Set_Subtype_Constraint
(Element : in out Subtype_Indication_Node;
Value : in Asis.Constraint) is
begin
Element.Subtype_Constraint := Value;
end Set_Subtype_Constraint;
function Has_Null_Exclusion
(Element : Subtype_Indication_Node) return Boolean is
begin
return Element.Has_Null_Exclusion;
end Has_Null_Exclusion;
procedure Set_Has_Null_Exclusion
(Element : in out Subtype_Indication_Node;
Value : in Boolean) is
begin
Element.Has_Null_Exclusion := Value;
end Set_Has_Null_Exclusion;
function New_Subtype_Indication_Node
(The_Context : ASIS.Context)
return Subtype_Indication_Ptr
is
Result : Subtype_Indication_Ptr :=
new Subtype_Indication_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Subtype_Indication_Node;
function Definition_Kind (Element : Subtype_Indication_Node)
return Asis.Definition_Kinds is
begin
return A_Subtype_Indication;
end;
function Children (Element : access Subtype_Indication_Node)
return Traverse_List is
begin
return ((False, Element.Subtype_Mark'Access),
(False, Element.Subtype_Constraint'Access));
end Children;
function Clone
(Element : Subtype_Indication_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Subtype_Indication_Ptr := new Subtype_Indication_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
Result.Has_Null_Exclusion := Element.Has_Null_Exclusion;
return Asis.Element (Result);
end Clone;
procedure Copy
(Source : in Asis.Element;
Target : access Subtype_Indication_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element)
is
begin
Target.Subtype_Mark :=
Copy (Cloner, Get_Subtype_Mark (Source.all), Asis.Element (Target));
Target.Subtype_Constraint :=
Copy (Cloner, Subtype_Constraint (Source.all), Asis.Element (Target));
end Copy;
function Definition_Kind (Element : Constraint_Node)
return Asis.Definition_Kinds is
begin
return A_Constraint;
end;
function Component_Subtype_Indication
(Element : Component_Definition_Node) return Asis.Subtype_Indication is
begin
return Element.Component_Subtype_Indication;
end Component_Subtype_Indication;
procedure Set_Component_Subtype_Indication
(Element : in out Component_Definition_Node;
Value : in Asis.Subtype_Indication) is
begin
Element.Component_Subtype_Indication := Value;
end Set_Component_Subtype_Indication;
function Trait_Kind
(Element : Component_Definition_Node) return Asis.Trait_Kinds is
begin
return Element.Trait_Kind;
end Trait_Kind;
procedure Set_Trait_Kind
(Element : in out Component_Definition_Node;
Value : in Asis.Trait_Kinds) is
begin
Element.Trait_Kind := Value;
end Set_Trait_Kind;
function New_Component_Definition_Node
(The_Context : ASIS.Context)
return Component_Definition_Ptr
is
Result : Component_Definition_Ptr :=
new Component_Definition_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Component_Definition_Node;
function Definition_Kind (Element : Component_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Component_Definition;
end;
function Children (Element : access Component_Definition_Node)
return Traverse_List is
begin
return (1 => (False, Element.Component_Subtype_Indication'Access));
end Children;
function Clone
(Element : Component_Definition_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Component_Definition_Ptr := new Component_Definition_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
Result.Trait_Kind := Element.Trait_Kind;
return Asis.Element (Result);
end Clone;
procedure Copy
(Source : in Asis.Element;
Target : access Component_Definition_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element)
is
begin
Target.Component_Subtype_Indication :=
Copy (Cloner, Component_Subtype_Indication (Source.all), Asis.Element (Target));
end Copy;
function Definition_Kind (Element : Discrete_Subtype_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Discrete_Subtype_Definition;
end;
function Definition_Kind (Element : Discrete_Range_Node)
return Asis.Definition_Kinds is
begin
return A_Discrete_Range;
end;
function New_Unknown_Discriminant_Part_Node
(The_Context : ASIS.Context)
return Unknown_Discriminant_Part_Ptr
is
Result : Unknown_Discriminant_Part_Ptr :=
new Unknown_Discriminant_Part_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Unknown_Discriminant_Part_Node;
function Definition_Kind (Element : Unknown_Discriminant_Part_Node)
return Asis.Definition_Kinds is
begin
return An_Unknown_Discriminant_Part;
end;
function Clone
(Element : Unknown_Discriminant_Part_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Unknown_Discriminant_Part_Ptr := new Unknown_Discriminant_Part_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
return Asis.Element (Result);
end Clone;
function Discriminants
(Element : Known_Discriminant_Part_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Primary_Declaration_Lists.To_Element_List
(Element.Discriminants, Include_Pragmas);
end Discriminants;
procedure Set_Discriminants
(Element : in out Known_Discriminant_Part_Node;
Value : in Asis.Element) is
begin
Element.Discriminants := Primary_Declaration_Lists.List (Value);
end Set_Discriminants;
function Discriminants_List
(Element : Known_Discriminant_Part_Node) return Asis.Element is
begin
return Asis.Element (Element.Discriminants);
end Discriminants_List;
function New_Known_Discriminant_Part_Node
(The_Context : ASIS.Context)
return Known_Discriminant_Part_Ptr
is
Result : Known_Discriminant_Part_Ptr :=
new Known_Discriminant_Part_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Known_Discriminant_Part_Node;
function Definition_Kind (Element : Known_Discriminant_Part_Node)
return Asis.Definition_Kinds is
begin
return A_Known_Discriminant_Part;
end;
function Children (Element : access Known_Discriminant_Part_Node)
return Traverse_List is
begin
return (1 => (True, Asis.Element (Element.Discriminants)));
end Children;
function Clone
(Element : Known_Discriminant_Part_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Known_Discriminant_Part_Ptr := new Known_Discriminant_Part_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
return Asis.Element (Result);
end Clone;
procedure Copy
(Source : in Asis.Element;
Target : access Known_Discriminant_Part_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element)
is
begin
Set_Discriminants
(Target.all,
Primary_Declaration_Lists.Deep_Copy
(Discriminants (Source.all), Cloner, Asis.Element (Target)));
end Copy;
function Record_Components
(Element : Record_Definition_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Primary_Declaration_Lists.To_Element_List
(Element.Record_Components, Include_Pragmas);
end Record_Components;
procedure Set_Record_Components
(Element : in out Record_Definition_Node;
Value : in Asis.Element) is
begin
Element.Record_Components := Primary_Declaration_Lists.List (Value);
end Set_Record_Components;
function Record_Components_List
(Element : Record_Definition_Node) return Asis.Element is
begin
return Asis.Element (Element.Record_Components);
end Record_Components_List;
function Implicit_Components
(Element : Record_Definition_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Secondary_Declaration_Lists.To_Element_List
(Element.Implicit_Components, Include_Pragmas);
end Implicit_Components;
procedure Add_To_Implicit_Components
(Element : in out Record_Definition_Node;
Item : in Asis.Element) is
begin
Secondary_Declaration_Lists.Add (Element.Implicit_Components, Item);
end Add_To_Implicit_Components;
function New_Record_Definition_Node
(The_Context : ASIS.Context)
return Record_Definition_Ptr
is
Result : Record_Definition_Ptr :=
new Record_Definition_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Record_Definition_Node;
function Definition_Kind (Element : Record_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Record_Definition;
end;
function Children (Element : access Record_Definition_Node)
return Traverse_List is
begin
return (1 => (True, Asis.Element (Element.Record_Components)));
end Children;
function Clone
(Element : Record_Definition_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Record_Definition_Ptr := new Record_Definition_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
null;
return Asis.Element (Result);
end Clone;
procedure Copy
(Source : in Asis.Element;
Target : access Record_Definition_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element)
is
begin
Set_Record_Components
(Target.all,
Primary_Declaration_Lists.Deep_Copy
(Record_Components (Source.all), Cloner, Asis.Element (Target)));
end Copy;
function New_Null_Record_Definition_Node
(The_Context : ASIS.Context)
return Null_Record_Definition_Ptr
is
Result : Null_Record_Definition_Ptr :=
new Null_Record_Definition_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Null_Record_Definition_Node;
function Definition_Kind (Element : Null_Record_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Null_Record_Definition;
end;
function Clone
(Element : Null_Record_Definition_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Null_Record_Definition_Ptr := new Null_Record_Definition_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
return Asis.Element (Result);
end Clone;
function Pragmas
(Element : Null_Component_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Primary_Pragma_Lists.To_Element_List
(Element.Pragmas, Include_Pragmas);
end Pragmas;
procedure Set_Pragmas
(Element : in out Null_Component_Node;
Value : in Asis.Element) is
begin
Element.Pragmas := Primary_Pragma_Lists.List (Value);
end Set_Pragmas;
function Pragmas_List
(Element : Null_Component_Node) return Asis.Element is
begin
return Asis.Element (Element.Pragmas);
end Pragmas_List;
function New_Null_Component_Node
(The_Context : ASIS.Context)
return Null_Component_Ptr
is
Result : Null_Component_Ptr :=
new Null_Component_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Null_Component_Node;
function Definition_Kind (Element : Null_Component_Node)
return Asis.Definition_Kinds is
begin
return A_Null_Component;
end;
function Clone
(Element : Null_Component_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Null_Component_Ptr := new Null_Component_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
return Asis.Element (Result);
end Clone;
function Discriminant_Direct_Name
(Element : Variant_Part_Node) return Asis.Name is
begin
return Element.Discriminant_Direct_Name;
end Discriminant_Direct_Name;
procedure Set_Discriminant_Direct_Name
(Element : in out Variant_Part_Node;
Value : in Asis.Name) is
begin
Element.Discriminant_Direct_Name := Value;
end Set_Discriminant_Direct_Name;
function Variants
(Element : Variant_Part_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Primary_Variant_Lists.To_Element_List
(Element.Variants, Include_Pragmas);
end Variants;
procedure Set_Variants
(Element : in out Variant_Part_Node;
Value : in Asis.Element) is
begin
Element.Variants := Primary_Variant_Lists.List (Value);
end Set_Variants;
function Variants_List
(Element : Variant_Part_Node) return Asis.Element is
begin
return Asis.Element (Element.Variants);
end Variants_List;
function Pragmas
(Element : Variant_Part_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Primary_Pragma_Lists.To_Element_List
(Element.Pragmas, Include_Pragmas);
end Pragmas;
procedure Set_Pragmas
(Element : in out Variant_Part_Node;
Value : in Asis.Element) is
begin
Element.Pragmas := Primary_Pragma_Lists.List (Value);
end Set_Pragmas;
function Pragmas_List
(Element : Variant_Part_Node) return Asis.Element is
begin
return Asis.Element (Element.Pragmas);
end Pragmas_List;
function End_Pragmas
(Element : Variant_Part_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Primary_Pragma_Lists.To_Element_List
(Element.End_Pragmas, Include_Pragmas);
end End_Pragmas;
procedure Set_End_Pragmas
(Element : in out Variant_Part_Node;
Value : in Asis.Element) is
begin
Element.End_Pragmas := Primary_Pragma_Lists.List (Value);
end Set_End_Pragmas;
function End_Pragmas_List
(Element : Variant_Part_Node) return Asis.Element is
begin
return Asis.Element (Element.End_Pragmas);
end End_Pragmas_List;
function New_Variant_Part_Node
(The_Context : ASIS.Context)
return Variant_Part_Ptr
is
Result : Variant_Part_Ptr :=
new Variant_Part_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Variant_Part_Node;
function Definition_Kind (Element : Variant_Part_Node)
return Asis.Definition_Kinds is
begin
return A_Variant_Part;
end;
function Children (Element : access Variant_Part_Node)
return Traverse_List is
begin
return ((False, Element.Discriminant_Direct_Name'Access),
(True, Asis.Element (Element.Pragmas)),
(True, Asis.Element (Element.Variants)));
end Children;
function Clone
(Element : Variant_Part_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Variant_Part_Ptr := new Variant_Part_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
return Asis.Element (Result);
end Clone;
procedure Copy
(Source : in Asis.Element;
Target : access Variant_Part_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element)
is
begin
Target.Discriminant_Direct_Name :=
Copy (Cloner, Discriminant_Direct_Name (Source.all), Asis.Element (Target));
Set_Pragmas
(Target.all,
Primary_Pragma_Lists.Deep_Copy
(Pragmas (Source.all), Cloner, Asis.Element (Target)));
Set_Variants
(Target.all,
Primary_Variant_Lists.Deep_Copy
(Variants (Source.all), Cloner, Asis.Element (Target)));
end Copy;
function Record_Components
(Element : Variant_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Primary_Declaration_Lists.To_Element_List
(Element.Record_Components, Include_Pragmas);
end Record_Components;
procedure Set_Record_Components
(Element : in out Variant_Node;
Value : in Asis.Element) is
begin
Element.Record_Components := Primary_Declaration_Lists.List (Value);
end Set_Record_Components;
function Record_Components_List
(Element : Variant_Node) return Asis.Element is
begin
return Asis.Element (Element.Record_Components);
end Record_Components_List;
function Implicit_Components
(Element : Variant_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Secondary_Declaration_Lists.To_Element_List
(Element.Implicit_Components, Include_Pragmas);
end Implicit_Components;
procedure Add_To_Implicit_Components
(Element : in out Variant_Node;
Item : in Asis.Element) is
begin
Secondary_Declaration_Lists.Add (Element.Implicit_Components, Item);
end Add_To_Implicit_Components;
function Variant_Choices
(Element : Variant_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Primary_Choise_Lists.To_Element_List
(Element.Variant_Choices, Include_Pragmas);
end Variant_Choices;
procedure Set_Variant_Choices
(Element : in out Variant_Node;
Value : in Asis.Element) is
begin
Element.Variant_Choices := Primary_Choise_Lists.List (Value);
end Set_Variant_Choices;
function Variant_Choices_List
(Element : Variant_Node) return Asis.Element is
begin
return Asis.Element (Element.Variant_Choices);
end Variant_Choices_List;
function New_Variant_Node
(The_Context : ASIS.Context)
return Variant_Ptr
is
Result : Variant_Ptr :=
new Variant_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Variant_Node;
function Definition_Kind (Element : Variant_Node)
return Asis.Definition_Kinds is
begin
return A_Variant;
end;
function Children (Element : access Variant_Node)
return Traverse_List is
begin
return ((True, Asis.Element (Element.Variant_Choices)),
(True, Asis.Element (Element.Record_Components)));
end Children;
function Clone
(Element : Variant_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Variant_Ptr := new Variant_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
null;
return Asis.Element (Result);
end Clone;
procedure Copy
(Source : in Asis.Element;
Target : access Variant_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element)
is
begin
Set_Variant_Choices
(Target.all,
Primary_Choise_Lists.Deep_Copy
(Variant_Choices (Source.all), Cloner, Asis.Element (Target)));
Set_Record_Components
(Target.all,
Primary_Declaration_Lists.Deep_Copy
(Record_Components (Source.all), Cloner, Asis.Element (Target)));
end Copy;
function New_Others_Choice_Node
(The_Context : ASIS.Context)
return Others_Choice_Ptr
is
Result : Others_Choice_Ptr :=
new Others_Choice_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Others_Choice_Node;
function Definition_Kind (Element : Others_Choice_Node)
return Asis.Definition_Kinds is
begin
return An_Others_Choice;
end;
function Clone
(Element : Others_Choice_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Others_Choice_Ptr := new Others_Choice_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
return Asis.Element (Result);
end Clone;
function Has_Null_Exclusion
(Element : Access_Definition_Node) return Boolean is
begin
return Element.Has_Null_Exclusion;
end Has_Null_Exclusion;
procedure Set_Has_Null_Exclusion
(Element : in out Access_Definition_Node;
Value : in Boolean) is
begin
Element.Has_Null_Exclusion := Value;
end Set_Has_Null_Exclusion;
function Definition_Kind (Element : Access_Definition_Node)
return Asis.Definition_Kinds is
begin
return An_Access_Definition;
end;
function New_Incomplete_Type_Definition_Node
(The_Context : ASIS.Context)
return Incomplete_Type_Definition_Ptr
is
Result : Incomplete_Type_Definition_Ptr :=
new Incomplete_Type_Definition_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Incomplete_Type_Definition_Node;
function Definition_Kind (Element : Incomplete_Type_Definition_Node)
return Asis.Definition_Kinds is
begin
return An_Incomplete_Type_Definition;
end;
function Clone
(Element : Incomplete_Type_Definition_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Incomplete_Type_Definition_Ptr := new Incomplete_Type_Definition_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
return Asis.Element (Result);
end Clone;
function Has_Tagged
(Element : Tagged_Incomplete_Type_Definition_Node) return Boolean is
begin
return Element.Has_Tagged;
end Has_Tagged;
procedure Set_Has_Tagged
(Element : in out Tagged_Incomplete_Type_Definition_Node;
Value : in Boolean) is
begin
Element.Has_Tagged := Value;
end Set_Has_Tagged;
function New_Tagged_Incomplete_Type_Definition_Node
(The_Context : ASIS.Context)
return Tagged_Incomplete_Type_Definition_Ptr
is
Result : Tagged_Incomplete_Type_Definition_Ptr :=
new Tagged_Incomplete_Type_Definition_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Tagged_Incomplete_Type_Definition_Node;
function Definition_Kind (Element : Tagged_Incomplete_Type_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Tagged_Incomplete_Type_Definition;
end;
function Clone
(Element : Tagged_Incomplete_Type_Definition_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Tagged_Incomplete_Type_Definition_Ptr := new Tagged_Incomplete_Type_Definition_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
Result.Has_Tagged := Element.Has_Tagged;
return Asis.Element (Result);
end Clone;
function Trait_Kind
(Element : Private_Type_Definition_Node) return Asis.Trait_Kinds is
begin
return Element.Trait_Kind;
end Trait_Kind;
procedure Set_Trait_Kind
(Element : in out Private_Type_Definition_Node;
Value : in Asis.Trait_Kinds) is
begin
Element.Trait_Kind := Value;
end Set_Trait_Kind;
function Corresponding_Type_Operators
(Element : Private_Type_Definition_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Secondary_Declaration_Lists.To_Element_List
(Element.Corresponding_Type_Operators, Include_Pragmas);
end Corresponding_Type_Operators;
procedure Add_To_Corresponding_Type_Operators
(Element : in out Private_Type_Definition_Node;
Item : in Asis.Element) is
begin
Secondary_Declaration_Lists.Add (Element.Corresponding_Type_Operators, Item);
end Add_To_Corresponding_Type_Operators;
function Has_Limited
(Element : Private_Type_Definition_Node) return Boolean is
begin
return Element.Has_Limited;
end Has_Limited;
procedure Set_Has_Limited
(Element : in out Private_Type_Definition_Node;
Value : in Boolean) is
begin
Element.Has_Limited := Value;
end Set_Has_Limited;
function Has_Private
(Element : Private_Type_Definition_Node) return Boolean is
begin
return Element.Has_Private;
end Has_Private;
procedure Set_Has_Private
(Element : in out Private_Type_Definition_Node;
Value : in Boolean) is
begin
Element.Has_Private := Value;
end Set_Has_Private;
function New_Private_Type_Definition_Node
(The_Context : ASIS.Context)
return Private_Type_Definition_Ptr
is
Result : Private_Type_Definition_Ptr :=
new Private_Type_Definition_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Private_Type_Definition_Node;
function Definition_Kind (Element : Private_Type_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Private_Type_Definition;
end;
function Clone
(Element : Private_Type_Definition_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Private_Type_Definition_Ptr := new Private_Type_Definition_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
Result.Trait_Kind := Element.Trait_Kind;
null;
Result.Has_Limited := Element.Has_Limited;
Result.Has_Private := Element.Has_Private;
return Asis.Element (Result);
end Clone;
function Has_Abstract
(Element : Tagged_Private_Type_Definition_Node) return Boolean is
begin
return Element.Has_Abstract;
end Has_Abstract;
procedure Set_Has_Abstract
(Element : in out Tagged_Private_Type_Definition_Node;
Value : in Boolean) is
begin
Element.Has_Abstract := Value;
end Set_Has_Abstract;
function Has_Tagged
(Element : Tagged_Private_Type_Definition_Node) return Boolean is
begin
return Element.Has_Tagged;
end Has_Tagged;
procedure Set_Has_Tagged
(Element : in out Tagged_Private_Type_Definition_Node;
Value : in Boolean) is
begin
Element.Has_Tagged := Value;
end Set_Has_Tagged;
function New_Tagged_Private_Type_Definition_Node
(The_Context : ASIS.Context)
return Tagged_Private_Type_Definition_Ptr
is
Result : Tagged_Private_Type_Definition_Ptr :=
new Tagged_Private_Type_Definition_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Tagged_Private_Type_Definition_Node;
function Definition_Kind (Element : Tagged_Private_Type_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Tagged_Private_Type_Definition;
end;
function Clone
(Element : Tagged_Private_Type_Definition_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Tagged_Private_Type_Definition_Ptr := new Tagged_Private_Type_Definition_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
Result.Trait_Kind := Element.Trait_Kind;
null;
Result.Has_Limited := Element.Has_Limited;
Result.Has_Private := Element.Has_Private;
Result.Has_Abstract := Element.Has_Abstract;
Result.Has_Tagged := Element.Has_Tagged;
return Asis.Element (Result);
end Clone;
function Ancestor_Subtype_Indication
(Element : Private_Extension_Definition_Node) return Asis.Subtype_Indication is
begin
return Element.Ancestor_Subtype_Indication;
end Ancestor_Subtype_Indication;
procedure Set_Ancestor_Subtype_Indication
(Element : in out Private_Extension_Definition_Node;
Value : in Asis.Subtype_Indication) is
begin
Element.Ancestor_Subtype_Indication := Value;
end Set_Ancestor_Subtype_Indication;
function Implicit_Inherited_Declarations
(Element : Private_Extension_Definition_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Secondary_Declaration_Lists.To_Element_List
(Element.Implicit_Inherited_Declarations, Include_Pragmas);
end Implicit_Inherited_Declarations;
procedure Add_To_Implicit_Inherited_Declarations
(Element : in out Private_Extension_Definition_Node;
Item : in Asis.Element) is
begin
Secondary_Declaration_Lists.Add (Element.Implicit_Inherited_Declarations, Item);
end Add_To_Implicit_Inherited_Declarations;
function Implicit_Inherited_Subprograms
(Element : Private_Extension_Definition_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Secondary_Declaration_Lists.To_Element_List
(Element.Implicit_Inherited_Subprograms, Include_Pragmas);
end Implicit_Inherited_Subprograms;
procedure Add_To_Implicit_Inherited_Subprograms
(Element : in out Private_Extension_Definition_Node;
Item : in Asis.Element) is
begin
Secondary_Declaration_Lists.Add (Element.Implicit_Inherited_Subprograms, Item);
end Add_To_Implicit_Inherited_Subprograms;
function Has_Synchronized
(Element : Private_Extension_Definition_Node) return Boolean is
begin
return Element.Has_Synchronized;
end Has_Synchronized;
procedure Set_Has_Synchronized
(Element : in out Private_Extension_Definition_Node;
Value : in Boolean) is
begin
Element.Has_Synchronized := Value;
end Set_Has_Synchronized;
function Has_Abstract
(Element : Private_Extension_Definition_Node) return Boolean is
begin
return Element.Has_Abstract;
end Has_Abstract;
procedure Set_Has_Abstract
(Element : in out Private_Extension_Definition_Node;
Value : in Boolean) is
begin
Element.Has_Abstract := Value;
end Set_Has_Abstract;
function New_Private_Extension_Definition_Node
(The_Context : ASIS.Context)
return Private_Extension_Definition_Ptr
is
Result : Private_Extension_Definition_Ptr :=
new Private_Extension_Definition_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Private_Extension_Definition_Node;
function Definition_Kind (Element : Private_Extension_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Private_Extension_Definition;
end;
function Children (Element : access Private_Extension_Definition_Node)
return Traverse_List is
begin
return (1 => (False, Element.Ancestor_Subtype_Indication'Access));
end Children;
function Clone
(Element : Private_Extension_Definition_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Private_Extension_Definition_Ptr := new Private_Extension_Definition_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
Result.Trait_Kind := Element.Trait_Kind;
null;
Result.Has_Limited := Element.Has_Limited;
Result.Has_Private := Element.Has_Private;
null;
null;
Result.Has_Synchronized := Element.Has_Synchronized;
Result.Has_Abstract := Element.Has_Abstract;
return Asis.Element (Result);
end Clone;
procedure Copy
(Source : in Asis.Element;
Target : access Private_Extension_Definition_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element)
is
begin
Target.Ancestor_Subtype_Indication :=
Copy (Cloner, Ancestor_Subtype_Indication (Source.all), Asis.Element (Target));
end Copy;
function Is_Private_Present
(Element : Protected_Definition_Node) return Boolean is
begin
return Element.Is_Private_Present;
end Is_Private_Present;
procedure Set_Is_Private_Present
(Element : in out Protected_Definition_Node;
Value : in Boolean) is
begin
Element.Is_Private_Present := Value;
end Set_Is_Private_Present;
function Visible_Part_Items
(Element : Protected_Definition_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Primary_Declaration_Lists.To_Element_List
(Element.Visible_Part_Items, Include_Pragmas);
end Visible_Part_Items;
procedure Set_Visible_Part_Items
(Element : in out Protected_Definition_Node;
Value : in Asis.Element) is
begin
Element.Visible_Part_Items := Primary_Declaration_Lists.List (Value);
end Set_Visible_Part_Items;
function Visible_Part_Items_List
(Element : Protected_Definition_Node) return Asis.Element is
begin
return Asis.Element (Element.Visible_Part_Items);
end Visible_Part_Items_List;
function Private_Part_Items
(Element : Protected_Definition_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Primary_Declaration_Lists.To_Element_List
(Element.Private_Part_Items, Include_Pragmas);
end Private_Part_Items;
procedure Set_Private_Part_Items
(Element : in out Protected_Definition_Node;
Value : in Asis.Element) is
begin
Element.Private_Part_Items := Primary_Declaration_Lists.List (Value);
end Set_Private_Part_Items;
function Private_Part_Items_List
(Element : Protected_Definition_Node) return Asis.Element is
begin
return Asis.Element (Element.Private_Part_Items);
end Private_Part_Items_List;
function Get_Identifier
(Element : Protected_Definition_Node) return Asis.Element is
begin
return Element.Identifier;
end Get_Identifier;
procedure Set_Identifier
(Element : in out Protected_Definition_Node;
Value : in Asis.Element) is
begin
Element.Identifier := Value;
end Set_Identifier;
function Corresponding_Type_Operators
(Element : Protected_Definition_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Secondary_Declaration_Lists.To_Element_List
(Element.Corresponding_Type_Operators, Include_Pragmas);
end Corresponding_Type_Operators;
procedure Add_To_Corresponding_Type_Operators
(Element : in out Protected_Definition_Node;
Item : in Asis.Element) is
begin
Secondary_Declaration_Lists.Add (Element.Corresponding_Type_Operators, Item);
end Add_To_Corresponding_Type_Operators;
function New_Protected_Definition_Node
(The_Context : ASIS.Context)
return Protected_Definition_Ptr
is
Result : Protected_Definition_Ptr :=
new Protected_Definition_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Protected_Definition_Node;
function Definition_Kind (Element : Protected_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Protected_Definition;
end;
function Children (Element : access Protected_Definition_Node)
return Traverse_List is
begin
return ((True, Asis.Element (Element.Visible_Part_Items)),
(True, Asis.Element (Element.Private_Part_Items)));
end Children;
function Clone
(Element : Protected_Definition_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Protected_Definition_Ptr := new Protected_Definition_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
Result.Is_Private_Present := Element.Is_Private_Present;
Result.Identifier := Element.Identifier;
null;
return Asis.Element (Result);
end Clone;
procedure Copy
(Source : in Asis.Element;
Target : access Protected_Definition_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element)
is
begin
Set_Visible_Part_Items
(Target.all,
Primary_Declaration_Lists.Deep_Copy
(Visible_Part_Items (Source.all), Cloner, Asis.Element (Target)));
Set_Private_Part_Items
(Target.all,
Primary_Declaration_Lists.Deep_Copy
(Private_Part_Items (Source.all), Cloner, Asis.Element (Target)));
end Copy;
function Is_Task_Definition_Present
(Element : Task_Definition_Node) return Boolean is
begin
return Element.Is_Task_Definition_Present;
end Is_Task_Definition_Present;
procedure Set_Is_Task_Definition_Present
(Element : in out Task_Definition_Node;
Value : in Boolean) is
begin
Element.Is_Task_Definition_Present := Value;
end Set_Is_Task_Definition_Present;
function New_Task_Definition_Node
(The_Context : ASIS.Context)
return Task_Definition_Ptr
is
Result : Task_Definition_Ptr :=
new Task_Definition_Node;
begin
Set_Enclosing_Compilation_Unit
(Result.all, Current_Unit (The_Context.all));
return Result;
end New_Task_Definition_Node;
function Definition_Kind (Element : Task_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Task_Definition;
end;
function Clone
(Element : Task_Definition_Node;
Parent : Asis.Element)
return Asis.Element
is
Result : constant Task_Definition_Ptr := new Task_Definition_Node;
begin
Result.Enclosing_Element := Parent;
Result.Is_Part_Of_Implicit := Element.Is_Part_Of_Implicit;
Result.Is_Part_Of_Inherited := Element.Is_Part_Of_Inherited;
Result.Is_Part_Of_Instance := Element.Is_Part_Of_Instance;
Result.Start_Position := Element.Start_Position;
Result.End_Position := Element.End_Position;
Result.Enclosing_Compilation_Unit :=
Enclosing_Compilation_Unit (Parent.all);
Result.Hash := Element.Hash;
Result.Is_Private_Present := Element.Is_Private_Present;
Result.Identifier := Element.Identifier;
null;
Result.Is_Task_Definition_Present := Element.Is_Task_Definition_Present;
return Asis.Element (Result);
end Clone;
procedure Copy
(Source : in Asis.Element;
Target : access Task_Definition_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element)
is
begin
Set_Visible_Part_Items
(Target.all,
Primary_Declaration_Lists.Deep_Copy
(Visible_Part_Items (Source.all), Cloner, Asis.Element (Target)));
Set_Private_Part_Items
(Target.all,
Primary_Declaration_Lists.Deep_Copy
(Private_Part_Items (Source.all), Cloner, Asis.Element (Target)));
end Copy;
function Corresponding_Type_Operators
(Element : Formal_Type_Definition_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List is
begin
return Secondary_Declaration_Lists.To_Element_List
(Element.Corresponding_Type_Operators, Include_Pragmas);
end Corresponding_Type_Operators;
procedure Add_To_Corresponding_Type_Operators
(Element : in out Formal_Type_Definition_Node;
Item : in Asis.Element) is
begin
Secondary_Declaration_Lists.Add (Element.Corresponding_Type_Operators, Item);
end Add_To_Corresponding_Type_Operators;
function Definition_Kind (Element : Formal_Type_Definition_Node)
return Asis.Definition_Kinds is
begin
return A_Formal_Type_Definition;
end;
end Asis.Gela.Elements.Defs;
|
with Primes_IDL_File.PrimeNumberRequest_DataWriter;
with Primes_IDL_File.PrimeNumberReply_DataReader;
with DDS.Request_Reply.Typed_Requester_Generic;
package Primes.PrimeNumberRequester is new DDS.Request_Reply.Typed_Requester_Generic
(Request_DataWriters => Primes_IDL_File.PrimeNumberRequest_DataWriter,
Reply_DataReaders => Primes_IDL_File.PrimeNumberReply_DataReader);
|
------------------------------------------------------------------------------
-- 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. --
------------------------------------------------------------------------------
with Ada.Characters.Latin_1;
with Natools.S_Expressions.Encodings;
with Natools.S_Expressions.Parsers;
with Natools.S_Expressions.Test_Tools;
package body Natools.S_Expressions.Printers.Pretty.Tests is
package Latin_1 renames Ada.Characters.Latin_1;
procedure Parse_Print_Test
(Test : in out NT.Test;
Param : in Parameters;
Expected : in Atom);
-- Parse Expected and feed it into a new pretty printer, checking
-- the result is identical to Expected.
------------------------------
-- Local Helper Subprograms --
------------------------------
procedure Parse_Print_Test
(Test : in out NT.Test;
Param : in Parameters;
Expected : in Atom) is
begin
declare
Input, Output : aliased Test_Tools.Memory_Stream;
Parser : Parsers.Stream_Parser (Input'Access);
Pretty_Printer : Stream_Printer (Output'Access);
begin
Input.Set_Data (Expected);
Output.Set_Expected (Expected);
Pretty_Printer.Set_Parameters (Param);
Parser.Next;
Transfer (Parser, Pretty_Printer);
Output.Check_Stream (Test);
end;
exception
when Error : others =>
Test.Report_Exception (Error);
end Parse_Print_Test;
-------------------------
-- Complete Test Suite --
-------------------------
procedure All_Tests (Report : in out NT.Reporter'Class) is
begin
Basic_Printing (Report);
Atom_Encodings (Report);
Separators (Report);
Atom_Width (Report);
Quoted_String_Escapes (Report);
Indentation (Report);
Newline_Formats (Report);
Token_Separation (Report);
Parameter_Mutators (Report);
Expression_Width (Report);
Tabulation_Width (Report);
end All_Tests;
-----------------------
-- Inidividual Tests --
-----------------------
procedure Atom_Encodings (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Atom encodings");
Param : Parameters := Canonical;
begin
Parse_Print_Test (Test, Param,
To_Atom ("17:verbatim" & Latin_1.NUL & "encoding"));
Param.Fallback := Hexadecimal;
Parse_Print_Test (Test, Param,
To_Atom ("#48657861646563696D616C03456E636F64696E670A#"));
Param.Hex_Casing := Encodings.Lower;
Parse_Print_Test (Test, Param,
To_Atom ("#4c6f7765722043617365204865786164"
& "6563696d616c03456e636f64696e670a#"));
Param.Fallback := Base64;
Parse_Print_Test (Test, Param,
To_Atom ("|QmFzZS02NAllbmNvZGluZwo=|"));
Param.Quoted := Single_Line;
Parse_Print_Test (Test, Param,
To_Atom ("""quoted\r\nstring\tencoding"""));
Param.Token := Standard_Token;
Parse_Print_Test (Test, Param,
To_Atom ("(standard token ""123""encoding)"));
Param.Token := Extended_Token;
Parse_Print_Test (Test, Param,
To_Atom ("(extended token 123 encoding)"));
exception
when Error : others => Test.Report_Exception (Error);
end Atom_Encodings;
procedure Atom_Width (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Atom width");
Param : Parameters
:= (Width => 10,
Newline_At => (others => (others => False)),
Space_At => (others => (others => False)),
Tab_Stop => 8,
Indentation => 3,
Indent => Spaces,
Quoted => No_Quoted,
Token => No_Token,
Hex_Casing => Encodings.Upper,
Quoted_Escape => Hex_Escape,
Char_Encoding => ASCII,
Fallback => Hexadecimal,
Newline => LF);
begin
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom ("(" & Latin_1.LF
& " #303132" & Latin_1.LF
& " 333435" & Latin_1.LF
& " 3637#)"));
Pr.Set_Parameters (Param);
Pr.Open_List;
Pr.Append_Atom (To_Atom ("01234567"));
Pr.Close_List;
Output.Check_Stream (Test);
end;
Param.Fallback := Base64;
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom ("(" & Latin_1.LF
& " | YWJj" & Latin_1.LF
& " REVG" & Latin_1.LF
& " Z2hp" & Latin_1.LF
& " SktM" & Latin_1.LF
& " |)"));
Pr.Set_Parameters (Param);
Pr.Open_List;
Pr.Append_Atom (To_Atom ("abcDEFghiJKL"));
Pr.Close_List;
Output.Check_Stream (Test);
end;
exception
when Error : others => Test.Report_Exception (Error);
end Atom_Width;
procedure Basic_Printing (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Basic printing");
begin
declare
Output : aliased Test_Tools.Memory_Stream;
P : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom ("(7:command(6:subarg)3:arg)3:end"));
P.Set_Parameters (Canonical);
P.Open_List;
P.Append_Atom (To_Atom ("command"));
P.Open_List;
P.Append_Atom (To_Atom ("subarg"));
P.Close_List;
P.Append_Atom (To_Atom ("arg"));
P.Close_List;
P.Append_Atom (To_Atom ("end"));
Output.Check_Stream (Test);
end;
exception
when Error : others => Test.Report_Exception (Error);
end Basic_Printing;
procedure Expression_Width (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("S-expression width");
Param : constant Parameters
:= (Width => 6,
Newline_At => (others => (others => True)),
Space_At => (others => (others => False)),
Tab_Stop => 8,
Indentation => 0,
Indent => Tabs_And_Spaces,
Quoted => Single_Line,
Token => No_Token,
Hex_Casing => Encodings.Upper,
Quoted_Escape => Hex_Escape,
Char_Encoding => UTF_8,
Fallback => Verbatim,
Newline => LF);
begin
declare
Output : aliased Test_Tools.Memory_Stream;
P, Q : Stream_Printer (Output'Access);
Template : constant Atom (1 .. 6) := To_Atom ("é-123");
begin
Output.Set_Expected (To_Atom
("""\xC3""" & Latin_1.LF
& """é""" & Latin_1.LF
& """é-""" & Latin_1.LF
& """é-1""" & Latin_1.LF
& """é-12""" & Latin_1.LF
& "6:é-123" & Latin_1.LF
& '"' & Character'Val (16#C3#) & '"' & Latin_1.LF
& """é""" & Latin_1.LF
& """é-""" & Latin_1.LF
& """é-1""" & Latin_1.LF
& "5:é-12" & Latin_1.LF
& "6:é-123"));
P.Set_Parameters (Param);
Q.Set_Parameters (Param);
Q.Set_Char_Encoding (Latin);
for I in Template'Range loop
P.Append_Atom (Template (Template'First .. I));
end loop;
P.Newline;
for I in Template'Range loop
Q.Append_Atom (Template (Template'First .. I));
end loop;
Output.Check_Stream (Test);
end;
exception
when Error : others => Test.Report_Exception (Error);
end Expression_Width;
procedure Indentation (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Indentation");
Param : Parameters
:= (Width => 16,
Newline_At => (others => (others => False)),
Space_At => (others => (others => False)),
Tab_Stop => 8,
Indentation => 3,
Indent => Tabs_And_Spaces,
Quoted => Single_Line,
Token => Standard_Token,
Hex_Casing => Encodings.Upper,
Quoted_Escape => Hex_Escape,
Char_Encoding => ASCII,
Fallback => Verbatim,
Newline => LF);
begin
Parse_Print_Test (Test, Param, To_Atom
("(first-level(" & Latin_1.LF
& " second-level" & Latin_1.LF
& " (third" & Latin_1.LF
& Latin_1.HT & " level" & Latin_1.LF
& Latin_1.HT & " ""Q#""))" & Latin_1.LF
& " end)"));
Param.Indent := Spaces;
Param.Token := Extended_Token;
Parse_Print_Test (Test, Param, To_Atom
("(first-level(" & Latin_1.LF
& " second-level" & Latin_1.LF
& " (third" & Latin_1.LF
& " level" & Latin_1.LF
& " ""Q)""))" & Latin_1.LF
& " end)"));
Param.Indent := Tabs;
Param.Indentation := 1;
Param.Tab_Stop := 5;
Parse_Print_Test (Test, Param, To_Atom
("(first-level(" & Latin_1.LF
& Latin_1.HT & Latin_1.HT & "second-level" & Latin_1.LF
& Latin_1.HT & Latin_1.HT & "(third" & Latin_1.LF
& Latin_1.HT & Latin_1.HT & Latin_1.HT & "level" & Latin_1.LF
& Latin_1.HT & Latin_1.HT & Latin_1.HT & "2:Q(" & Latin_1.LF
& Latin_1.HT & Latin_1.HT & "))end)"));
exception
when Error : others => Test.Report_Exception (Error);
end Indentation;
procedure Newline_Formats (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Newline formats");
procedure Print (Pr : in out Stream_Printer);
procedure Print (Pr : in out Stream_Printer) is
begin
Pr.Open_List;
Pr.Append_Atom (To_Atom ("begin"));
Pr.Append_Atom (To_Atom
("quoted" & Latin_1.CR & Latin_1.LF & Latin_1.CR & "str"));
Pr.Close_List;
end Print;
Param : Parameters
:= (Width => 7,
Newline_At => (others => (others => False)),
Space_At => (others => (others => False)),
Tab_Stop => 8, -- unused
Indentation => 1,
Indent => Spaces,
Quoted => When_Shorter,
Token => Standard_Token,
Hex_Casing => Encodings.Upper,
Quoted_Escape => Hex_Escape,
Char_Encoding => ASCII,
Fallback => Hexadecimal,
Newline => CR);
begin
Param.Newline_At (Atom_Data, Atom_Data) := True;
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Pr.Set_Parameters (Param);
Output.Set_Expected (To_Atom
("(begin" & Latin_1.CR
& " ""quot\" & Latin_1.CR
& "ed" & Latin_1.CR
& "\n" & Latin_1.CR
& "str"")"));
Print (Pr);
Output.Check_Stream (Test);
end;
Param.Newline := LF;
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Pr.Set_Parameters (Param);
Output.Set_Expected (To_Atom
("(begin" & Latin_1.LF
& " ""quot\" & Latin_1.LF
& "ed\r" & Latin_1.LF
& "\rstr"")"));
Print (Pr);
Output.Check_Stream (Test);
end;
Param.Newline := CR_LF;
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Pr.Set_Parameters (Param);
Output.Set_Expected (To_Atom
("(begin" & Latin_1.CR & Latin_1.LF
& " ""quot\" & Latin_1.CR & Latin_1.LF
& "ed" & Latin_1.CR & Latin_1.LF
& "\rstr"")"));
Print (Pr);
Output.Check_Stream (Test);
end;
Param.Newline := LF_CR;
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Pr.Set_Parameters (Param);
Output.Set_Expected (To_Atom
("(begin" & Latin_1.LF & Latin_1.CR
& " ""quot\" & Latin_1.LF & Latin_1.CR
& "ed\r" & Latin_1.LF & Latin_1.CR
& "str"")"));
Print (Pr);
Output.Check_Stream (Test);
end;
exception
when Error : others => Test.Report_Exception (Error);
end Newline_Formats;
procedure Parameter_Mutators (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Parameter mutators");
Initial : constant Parameters
:= (Width => 0,
Newline_At => (others => (others => False)),
Space_At => (others => (others => False)),
Tab_Stop => 8,
Indentation => 0,
Indent => Spaces,
Quoted => No_Quoted,
Token => No_Token,
Hex_Casing => Encodings.Upper,
Quoted_Escape => Octal_Escape,
Char_Encoding => ASCII,
Fallback => Verbatim,
Newline => LF);
Final : constant Parameters
:= (Width => 79,
Newline_At => (others => (others => True)),
Space_At => (others => (others => True)),
Tab_Stop => 4,
Indentation => 1,
Indent => Tabs,
Quoted => When_Shorter,
Token => Standard_Token,
Hex_Casing => Encodings.Lower,
Quoted_Escape => Hex_Escape,
Char_Encoding => UTF_8,
Fallback => Hexadecimal,
Newline => CR_LF);
begin
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Pr.Set_Parameters (Initial);
Pr.Set_Width (Final.Width);
Pr.Set_Newline_At (Final.Newline_At);
Pr.Set_Space_At (Final.Space_At);
Pr.Set_Tab_Stop (Final.Tab_Stop);
Pr.Set_Indentation (Final.Indentation);
Pr.Set_Indent (Final.Indent);
Pr.Set_Quoted (Final.Quoted);
Pr.Set_Token (Final.Token);
Pr.Set_Hex_Casing (Final.Hex_Casing);
Pr.Set_Quoted_Escape (Final.Quoted_Escape);
Pr.Set_Char_Encoding (Final.Char_Encoding);
Pr.Set_Fallback (Final.Fallback);
Pr.Set_Newline (Final.Newline);
if Pr.Get_Parameters /= Final then
Test.Fail;
end if;
end;
exception
when Error : others => Test.Report_Exception (Error);
end Parameter_Mutators;
procedure Quoted_String_Escapes (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Escapes in quoted string atoms");
Source : constant Atom (0 .. 123) := To_Atom
("Special: " -- indices 0 .. 17
& Latin_1.BS & Latin_1.HT & Latin_1.LF
& Latin_1.VT & Latin_1.FF & Latin_1.CR
& '\' & '"' & Latin_1.NUL
& "UTF-8 sequences: " -- indices 18 .. 62
& "é, −, 🁡, " -- U+00E9, U+2212, U+1F061
& Character'Val (16#F9#) & Character'Val (16#88#)
& Character'Val (16#B4#) & Character'Val (16#95#)
& Character'Val (16#A7#) -- U+1234567
& ", "
& Character'Val (16#FD#) & Character'Val (16#B6#)
& Character'Val (16#95#) & Character'Val (16#83#)
& Character'Val (16#88#) & Character'Val (16#90#) -- U+76543210
& "Invalid UTF-8 sequences: " -- indices 63 .. 117
& Character'Val (16#AA#) & ", "
& Character'Val (16#C3#) & ", "
& Character'Val (16#E2#) & Character'Val (16#88#) & ", "
& Character'Val (16#F0#) & Character'Val (16#9F#)
& Character'Val (16#81#) & ", "
& Character'Val (16#F9#) & Character'Val (16#88#)
& Character'Val (16#B4#) & Character'Val (16#95#) & ", "
& Character'Val (16#FD#) & Character'Val (16#B6#)
& Character'Val (16#95#) & Character'Val (16#83#)
& Character'Val (16#88#) & ", "
& Character'Val (16#FE#) & "."
& Latin_1.CR & Latin_1.LF -- indices 118 .. 119
& "<>" -- indices 120 .. 121
& Latin_1.CR & Latin_1.LF);
Param : Parameters
:= (Width => 0,
Newline_At => (others => (others => False)),
Space_At => (others => (others => False)),
Tab_Stop => 8,
Indentation => 3,
Indent => Spaces,
Quoted => When_Shorter,
Token => No_Token,
Hex_Casing => Encodings.Upper,
Quoted_Escape => Hex_Escape,
Char_Encoding => ASCII,
Fallback => Hexadecimal,
Newline => CR_LF);
begin
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
-- Check that the first quoted string encoding is exactly as long as
-- fallback (hexadecimal) encoding, by trying with one less char.
Output.Set_Expected
(Encodings.Hex_Atom_Begin
& Encodings.Encode_Hex
(Source (Source'First + 1 .. Source'Last), Param.Hex_Casing)
& Encodings.Hex_Atom_End);
Pr.Set_Parameters (Param);
Pr.Append_Atom (Source (Source'First + 1 .. Source'Last));
Output.Check_Stream (Test);
end;
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom
("""Special: \b\t\n\v\f\r\\\""\x00"
& "UTF-8 sequences: \xC3\xA9, \xE2\x88\x92, \xF0\x9F\x81\xA1, "
& "\xF9\x88\xB4\x95\xA7, \xFD\xB6\x95\x83\x88\x90"
& "Invalid UTF-8 sequences: "
& "\xAA, \xC3, \xE2\x88, \xF0\x9F\x81, \xF9\x88\xB4\x95, "
& "\xFD\xB6\x95\x83\x88, \xFE." & Latin_1.CR & Latin_1.LF
& "<>\r\n"""));
Pr.Set_Parameters (Param);
Pr.Append_Atom (Source);
Output.Check_Stream (Test);
end;
Param.Char_Encoding := Latin;
Param.Hex_Casing := Encodings.Lower;
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom
("""Special: \b\t\n\v\f\r\\\""\x00"
& "UTF-8 sequences: "
& Character'Val (16#C3#) & Character'Val (16#A9#)
& ", " & Character'Val (16#E2#) & "\x88\x92, "
& Character'Val (16#F0#) & "\x9f\x81"
& Character'Val (16#A1#) & ", "
& Character'Val (16#F9#) & "\x88"
& Character'Val (16#B4#) & "\x95"
& Character'Val (16#A7#) & ", "
& Character'Val (16#FD#) & Character'Val (16#B6#)
& "\x95\x83\x88\x90"
& "Invalid UTF-8 sequences: "
& Character'Val (16#AA#) & ", "
& Character'Val (16#C3#) & ", "
& Character'Val (16#E2#) & "\x88, "
& Character'Val (16#F0#) & "\x9f\x81, "
& Character'Val (16#F9#) & "\x88"
& Character'Val (16#B4#) & "\x95, "
& Character'Val (16#FD#) & Character'Val (16#B6#)
& "\x95\x83\x88, " & Character'Val (16#FE#) & '.'
& Latin_1.CR & Latin_1.LF
& "<>\r\n"""));
Pr.Set_Parameters (Param);
Pr.Append_Atom (Source);
Output.Check_Stream (Test);
end;
Param.Char_Encoding := UTF_8;
Param.Quoted_Escape := Octal_Escape;
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom ("""Special: \b\t\n\v\f\r\\\""\000")
& Source (18 .. 62)
& To_Atom ("Invalid UTF-8 sequences: "
& "\252, \303, \342\210, \360\237\201, "
& "\371\210\264\225, \375\266\225\203\210, \376."
& Latin_1.CR & Latin_1.LF
& "<>\r\n"""));
Pr.Set_Parameters (Param);
Pr.Append_Atom (Source);
Output.Check_Stream (Test);
end;
Param.Width := 31;
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom ("""Special: \b\t\n\v\f\r\\\""\000"
& '\' & Latin_1.CR & Latin_1.LF)
& Source (18 .. 62)
& To_Atom ('\' & Latin_1.CR & Latin_1.LF
& "Invalid UTF-8 sequences: \252,\" & Latin_1.CR & Latin_1.LF
& " \303, \342\210, \360\237\201,\" & Latin_1.CR & Latin_1.LF
& " \371\210\264\225, \375\266\" & Latin_1.CR & Latin_1.LF
& "\225\203\210, \376."
& Latin_1.CR & Latin_1.LF
& "<>\r\n"""));
Pr.Set_Parameters (Param);
Pr.Append_Atom (Source);
Output.Check_Stream (Test);
end;
exception
when Error : others => Test.Report_Exception (Error);
end Quoted_String_Escapes;
procedure Separators (Report : in out NT.Reporter'Class) is
procedure Test_Exp (Pr : in out Stream_Printer);
procedure Test_Exp (Pr : in out Stream_Printer) is
begin
Pr.Append_Atom (To_Atom ("begin"));
Pr.Open_List;
Pr.Open_List;
Pr.Close_List;
Pr.Open_List;
Pr.Append_Atom (To_Atom ("head"));
Pr.Append_Atom (To_Atom ("tail"));
Pr.Close_List;
Pr.Close_List;
Pr.Append_Atom (To_Atom ("end"));
end Test_Exp;
Test : NT.Test := Report.Item ("Separators");
Param : Parameters := Canonical;
begin
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom ("5:begin(()(4:head4:tail))3:end"));
Pr.Set_Parameters (Param);
Test_Exp (Pr);
Output.Check_Stream (Test);
end;
Param.Space_At := (others => (others => True));
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Output.Set_Expected
(To_Atom ("5:begin ( ( ) ( 4:head 4:tail ) ) 3:end"));
Pr.Set_Parameters (Param);
Test_Exp (Pr);
Output.Check_Stream (Test);
end;
Param.Newline_At := (others => (others => True));
Param.Newline := LF;
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom ("5:begin" & Latin_1.LF
& '(' & Latin_1.LF
& '(' & Latin_1.LF
& ')' & Latin_1.LF
& '(' & Latin_1.LF
& "4:head" & Latin_1.LF
& "4:tail" & Latin_1.LF
& ')' & Latin_1.LF
& ')' & Latin_1.LF
& "3:end"));
Pr.Set_Parameters (Param);
Test_Exp (Pr);
Output.Check_Stream (Test);
end;
exception
when Error : others => Test.Report_Exception (Error);
end Separators;
procedure Tabulation_Width (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Width of tabulations");
procedure Fill (P : in out Stream_Printer; Times : in Natural);
X : constant Atom := To_Atom ("x");
procedure Fill (P : in out Stream_Printer; Times : in Natural) is
begin
for I in 1 .. Times loop
P.Append_Atom (X);
end loop;
end Fill;
Tab : constant Character := Latin_1.HT;
NL : constant Character := Latin_1.LF;
Param : constant Parameters
:= (Width => 20,
Newline_At => (others => (others => False)),
Space_At =>
(Atom_Data => (Opening => True, others => False),
others => (others => False)),
Tab_Stop => 5,
Indentation => 3,
Indent => Tabs_And_Spaces,
Quoted => Single_Line,
Token => Standard_Token,
Hex_Casing => Encodings.Upper,
Quoted_Escape => Hex_Escape,
Char_Encoding => UTF_8,
Fallback => Verbatim,
Newline => LF);
begin
declare
Output : aliased Test_Tools.Memory_Stream;
P : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom -- 1234-6789-1234-6789-
("(first-level x x x x" & NL -- (first-level x x x x
& " x (second-level x" & NL -- ...x (second-level x
& Tab & " x x x x x x x" & NL -- >----.x x x x x x x
& Tab & " x x (third x x" & NL -- >----.x x (third x x
& Tab & " x (fourth x" & NL -- >----....x (fourth x
& Tab & Tab & " x x (x x" & NL -- >---->----..x x (x x
& Tab & Tab & Tab & "x)x x" & NL -- >---->---->----x)x x
& Tab & Tab & " x))x x x" & NL -- >---->----..x))x x x
& Tab & " x))")); -- >----.x))
P.Set_Parameters (Param);
P.Open_List;
P.Append_Atom (To_Atom ("first-level"));
Fill (P, 5);
P.Open_List;
P.Append_Atom (To_Atom ("second-level"));
Fill (P, 10);
P.Open_List;
P.Append_Atom (To_Atom ("third"));
Fill (P, 3);
P.Open_List;
P.Append_Atom (To_Atom ("fourth"));
Fill (P, 3);
P.Open_List;
Fill (P, 3);
P.Close_List;
Fill (P, 3);
P.Close_List;
P.Close_List;
Fill (P, 4);
P.Close_List;
P.Close_List;
Output.Check_Stream (Test);
end;
declare
Output : aliased Test_Tools.Memory_Stream;
P : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom -- 1234-6789-1234-6789-
("(first-level x x x x" & NL -- (first-level x x x x
& Tab & "x x x x x x x x" & NL -- >----x x x x x x x x
& Tab & "x x (second x x" & NL -- >----x x (second x x
& Tab & Tab & "x x x x x" & NL -- >---->----x x x x x
& Tab & Tab & "x x))")); -- >---->----x x))
P.Set_Parameters (Param);
P.Set_Indent (Tabs);
P.Set_Indentation (1);
P.Open_List;
P.Append_Atom (To_Atom ("first-level"));
Fill (P, 14);
P.Open_List;
P.Append_Atom (To_Atom ("second"));
Fill (P, 9);
P.Close_List;
P.Close_List;
Output.Check_Stream (Test);
end;
exception
when Error : others => Test.Report_Exception (Error);
end Tabulation_Width;
procedure Token_Separation (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Token separation");
Token : constant Atom := To_Atom ("token");
begin
declare
Output : aliased Test_Tools.Memory_Stream;
Pr : Stream_Printer (Output'Access);
begin
Output.Set_Expected (To_Atom
("(begin(token ""quoted\n""token token #4865780A#token "
& "|QmFzZS02NAo=|token)end)"));
Pr.Set_Parameters
((Width => 0,
Newline_At => (others => (others => False)),
Space_At => (others => (others => False)),
Tab_Stop => 8,
Indentation => 0,
Indent => Spaces,
Quoted => When_Shorter,
Token => Standard_Token,
Hex_Casing => Encodings.Upper,
Quoted_Escape => Hex_Escape,
Char_Encoding => ASCII,
Fallback => Hexadecimal,
Newline => LF));
Pr.Open_List;
Pr.Append_Atom (To_Atom ("begin"));
Pr.Open_List;
Pr.Append_Atom (Token);
Pr.Append_Atom (To_Atom ("quoted" & Latin_1.LF));
Pr.Append_Atom (Token);
Pr.Append_Atom (Token);
Pr.Set_Quoted (No_Quoted);
Pr.Append_Atom (To_Atom ("Hex" & Latin_1.LF));
Pr.Append_Atom (Token);
Pr.Set_Fallback (Base64);
Pr.Append_Atom (To_Atom ("Base-64" & Latin_1.LF));
Pr.Append_Atom (Token);
Pr.Close_List;
Pr.Append_Atom (To_Atom ("end"));
Pr.Close_List;
Output.Check_Stream (Test);
end;
exception
when Error : others => Test.Report_Exception (Error);
end Token_Separation;
end Natools.S_Expressions.Printers.Pretty.Tests;
|
with Logger;
with Units;
with Types; use Types;
with Bounded_Image; use Bounded_Image;
package body Profiler with SPARK_Mode is
procedure enableProfiling is
begin
G_state.isEnabled := True;
end enableProfiling;
procedure disableProfiling is
begin
G_state.isEnabled := False;
end disableProfiling;
procedure init(Self : in out Profile_Tag; name : String) is
now : constant Time := Clock;
maxlen : constant Integer := (if name'Length > Self.name'Length
then Self.name'Length else name'Length);
idx_s0 : constant Integer := Self.name'First;
idx_s1 : constant Integer := idx_s0 - 1 + maxlen;
idx_n0 : constant Integer := name'First;
idx_n1 : constant Integer := idx_n0 - 1 + maxlen;
begin
Self.name(idx_s0 .. idx_s1) := name (idx_n0 .. idx_n1);
Self.name_length := maxlen;
Self.stop_Time := now;
Self.start_Time := now;
end init;
procedure reset(Self : in out Profile_Tag) is
now : constant Time := Clock;
begin
Self.max_duration := Milliseconds( 0 );
Self.stop_Time := now;
Self.start_Time := now;
end reset;
procedure start(Self : in out Profile_Tag) is
begin
Self.start_Time := Clock;
end start;
procedure stop(Self : in out Profile_Tag) is
begin
if CFG_PROFILER_PROFILING then
Self.stop_Time := Clock;
if Self.stop_Time - Self.start_Time > Self.max_duration then
Self.max_duration := Self.stop_Time - Self.start_Time;
end if;
end if;
end stop;
procedure log(Self : in Profile_Tag) is
time_us_flt : constant Float := Float (Units.To_Time (Self.max_duration)) * 1.0e6;
time_us_int : Integer;
begin
if CFG_PROFILER_PROFILING and CFG_PROFILER_LOGGING then
time_us_int := Sat_Cast_Int (time_us_flt); -- rounding
Logger.log_console (Logger.INFO, Self.name & " Profile: " & Integer_Img (time_us_int) & " us" );
end if;
end log;
function get_Name(Self : in Profile_Tag) return String is
begin
return Self.name(1 .. Self.name_length);
end get_Name;
function get_Start(Self : in Profile_Tag) return Time is
begin
return Self.start_Time;
end get_Start;
function get_Stop(Self : in Profile_Tag) return Time is
begin
return Self.stop_Time;
end get_Stop;
-- elapsed time before stop or last measurement time after stop
function get_Elapsed(Self : in Profile_Tag) return Time_Span with SPARK_Mode => Off is
now : constant Time := Clock;
begin
return (if Self.stop_Time > Self.start_Time then
Self.stop_Time - Self.start_Time else
now - Self.start_Time
);
end get_Elapsed;
function get_Max(Self : in Profile_Tag) return Time_Span is
begin
return Self.max_duration;
end get_Max;
procedure Read_From_Memory(Self : in out Profile_Tag) is
pragma Unreferenced (Self);
begin
null;
end Read_From_Memory;
procedure Write_To_Memory(Self : in out Profile_Tag) is
pragma Unreferenced (Self);
begin
null;
end Write_To_Memory;
end Profiler;
|
with AUnit;
with AUnit.Simple_Test_Cases;
with kv.avm.Instructions;
with kv.avm.Registers;
with kv.avm.Processors;
with kv.avm.Instances;
with kv.avm.Actors;
with kv.avm.Messages;
with kv.avm.references; use kv.avm.references;
with kv.avm.Memories;
with kv.avm.Control;
package kv.avm.Test is
type Instruction_Test_Case is abstract new AUnit.Simple_Test_Cases.Test_Case with
record
p : aliased kv.avm.Processors.Processor_Type;
i : kv.avm.Instances.Instance_Access;
c : kv.avm.Instructions.Code_Access;
f : kv.avm.Instructions.Code_Access; -- FooBar code
a : kv.avm.Actors.Actor_Access;
m : kv.avm.Memories.Memory_Type;
s : kv.avm.Control.Status_Type;
x : kv.avm.Messages.Message_Type;
end record;
procedure Set_Up (T : in out Instruction_Test_Case);
procedure Tear_Down (T : in out Instruction_Test_Case);
procedure Mem_Set
(T : in out Instruction_Test_Case;
Ref : in reference_type;
Val : in kv.avm.Registers.Register_Type);
function Mem_Get
(T : in Instruction_Test_Case;
Ref : in reference_type) return kv.avm.Registers.Register_Type;
procedure Step(T : in out Instruction_Test_Case);
type Test_1 is new Instruction_Test_Case with null record;
function Name (T : Test_1) return AUnit.Message_String;
procedure Run_Test (T : in out Test_1);
type Test_2 is new Instruction_Test_Case with null record;
function Name (T : Test_2) return AUnit.Message_String;
procedure Run_Test (T : in out Test_2);
type Test_3 is new Instruction_Test_Case with null record;
function Name (T : Test_3) return AUnit.Message_String;
procedure Run_Test (T : in out Test_3);
type Test_4 is new Instruction_Test_Case with null record;
function Name (T : Test_4) return AUnit.Message_String;
procedure Run_Test (T : in out Test_4);
type Test_4b is new Instruction_Test_Case with null record;
function Name (T : Test_4b) return AUnit.Message_String;
procedure Run_Test (T : in out Test_4b);
type Test_5 is new Instruction_Test_Case with null record;
function Name (T : Test_5) return AUnit.Message_String;
procedure Run_Test (T : in out Test_5);
type Test_6 is new Instruction_Test_Case with null record;
function Name (T : Test_6) return AUnit.Message_String;
procedure Run_Test (T : in out Test_6);
type Test_6b is new Instruction_Test_Case with null record;
function Name (T : Test_6b) return AUnit.Message_String;
procedure Run_Test (T : in out Test_6b);
type Test_7 is new Instruction_Test_Case with null record;
function Name (T : Test_7) return AUnit.Message_String;
procedure Run_Test (T : in out Test_7);
type Test_8 is new Instruction_Test_Case with null record;
function Name (T : Test_8) return AUnit.Message_String;
procedure Run_Test (T : in out Test_8);
type Machine_Test_Case is abstract new AUnit.Simple_Test_Cases.Test_Case with
record
null;
end record;
procedure Set_Up (T : in out Machine_Test_Case);
procedure Tear_Down (T : in out Machine_Test_Case);
type Test_9 is new Machine_Test_Case with null record;
function Name (T : Test_9) return AUnit.Message_String;
procedure Run_Test (T : in out Test_9);
type Test_9b is new Machine_Test_Case with null record;
function Name (T : Test_9b) return AUnit.Message_String;
procedure Run_Test (T : in out Test_9b);
type Test_9c is new Machine_Test_Case with null record;
function Name (T : Test_9c) return AUnit.Message_String;
procedure Run_Test (T : in out Test_9c);
type Test_9d is new Instruction_Test_Case with null record;
function Name (T : Test_9d) return AUnit.Message_String;
procedure Run_Test (T : in out Test_9d);
type Test_10 is new Machine_Test_Case with null record;
function Name (T : Test_10) return AUnit.Message_String;
procedure Run_Test (T : in out Test_10);
type Test_11 is new Instruction_Test_Case with null record;
function Name (T : Test_11) return AUnit.Message_String;
procedure Run_Test (T : in out Test_11);
type Test_12 is new Instruction_Test_Case with null record;
function Name (T : Test_12) return AUnit.Message_String;
procedure Run_Test (T : in out Test_12);
type Test_13 is new Instruction_Test_Case with null record;
function Name (T : Test_13) return AUnit.Message_String;
procedure Run_Test (T : in out Test_13);
type Test_14 is new Instruction_Test_Case with null record;
function Name (T : Test_14) return AUnit.Message_String;
procedure Run_Test (T : in out Test_14);
type Test_15 is new Instruction_Test_Case with null record;
function Name (T : Test_15) return AUnit.Message_String;
procedure Run_Test (T : in out Test_15);
type Test_16 is new AUnit.Simple_Test_Cases.Test_Case with null record;
function Name (T : Test_16) return AUnit.Message_String;
procedure Run_Test (T : in out Test_16);
type Test_17 is new AUnit.Simple_Test_Cases.Test_Case with null record;
function Name (T : Test_17) return AUnit.Message_String;
procedure Run_Test (T : in out Test_17);
type Test_18 is new Instruction_Test_Case with null record;
function Name (T : Test_18) return AUnit.Message_String;
procedure Run_Test (T : in out Test_18);
type Test_19 is new Instruction_Test_Case with null record;
function Name (T : Test_19) return AUnit.Message_String;
procedure Run_Test (T : in out Test_19);
type Test_20 is new Instruction_Test_Case with null record;
function Name (T : Test_20) return AUnit.Message_String;
procedure Run_Test (T : in out Test_20);
type Test_21 is new Instruction_Test_Case with null record;
function Name (T : Test_21) return AUnit.Message_String;
procedure Run_Test (T : in out Test_21);
type Test_22 is new Instruction_Test_Case with null record;
function Name (T : Test_22) return AUnit.Message_String;
procedure Run_Test (T : in out Test_22);
type Test_23 is new Instruction_Test_Case with null record;
function Name (T : Test_23) return AUnit.Message_String;
procedure Run_Test (T : in out Test_23);
type Test_24 is new Instruction_Test_Case with null record;
function Name (T : Test_24) return AUnit.Message_String;
procedure Run_Test (T : in out Test_24);
type Test_25 is new Instruction_Test_Case with null record;
function Name (T : Test_25) return AUnit.Message_String;
procedure Run_Test (T : in out Test_25);
type Test_26 is new Instruction_Test_Case with null record;
function Name (T : Test_26) return AUnit.Message_String;
procedure Run_Test (T : in out Test_26);
end kv.avm.Test;
|
with Ada.Strings.Fixed;
with Ada.Strings.Maps;
with Text_IO;
use Text_IO;
package body split_string is
function collect1
(fs : String;
from_word_number : Natural;
ws : String := command_white_space1) return String
is
begin
if from_word_number <= number_of_words (fs, ws => ws) then
return word (fs, from_word_number, ws => ws) &
" " &
collect1 (fs, from_word_number + 1, ws);
else
return "";
end if;
end collect1;
function shrink1 (fs : String) return String is
fs1 : String := Ada.Strings.Fixed.Trim (fs, Ada.Strings.Both);
i1 : Integer := Ada.Strings.Fixed.Index (fs1, " ");
begin
while i1 > 0 loop
Ada.Strings.Fixed.Delete (fs1, i1, i1);
i1 := Ada.Strings.Fixed.Index (Ada.Strings.Fixed.Trim (fs1, Ada.Strings.Both), " ");
end loop;
return Ada.Strings.Fixed.Trim (fs1, Ada.Strings.Both);
end shrink1;
function expand1 (fs : String; singles : String) return String is
use Ada.Strings.Fixed;
singles1 : constant Ada.Strings.Maps.Character_Set := Ada.Strings.Maps.To_Set (singles);
fs1 : String := Ada.Strings.Fixed.Trim (shrink1 (fs), Ada.Strings.Both) & 10 * " ";
i1 : Integer := fs1'First;
i2 : Integer;
begin
loop
i2 := Ada.Strings.Fixed.Index (fs1 (i1 .. fs1'Last), singles1, Ada.Strings.Inside);
exit when i2 = 0;
if fs1 (i2 - 1) /= ' ' then
Insert (fs1, i2, " ", Drop => Ada.Strings.Right);
i1 := i2 + 1;
elsif fs1 (i2 + 1) /= ' ' then
Insert (fs1, i2 + 1, " ", Drop => Ada.Strings.Right);
i1 := i2 + 2;
else
i1 := i2 + 1;
end if;
end loop;
return Trim (fs1, Ada.Strings.Both);
end expand1;
function word
(fs : String;
word_number : Natural;
ws : String := command_white_space1) return String
is
use Ada.Strings.Maps;
i : Integer;
j : Integer := fs'First - 1;
space1 : constant Character_Set := To_Set (ws);
k1, k2 : Integer := 0;
no_matching_quotation : exception;
begin
if Ada.Strings.Fixed.Index (fs, Set => space1, Test => Ada.Strings.Outside) = 0 then
return "";
end if;
for n in 0 .. word_number - 1 loop
i := j + 1;
Ada.Strings.Fixed.Find_Token
(Source => fs (i .. fs'Last),
Set => space1,
Test => Ada.Strings.Outside,
First => i,
Last => j);
if j = 0 then
return "";
end if;
k1 := Ada.Strings.Fixed.Index (fs (i .. j), """");
if k1 > 0 then
k2 := Ada.Strings.Fixed.Index (fs (k1 + 1 .. fs'Last), """");
if k2 = 0 then
raise no_matching_quotation;
end if;
j := k2;
end if;
end loop;
return Ada.Strings.Fixed.Trim
(Source => fs (i .. j),
Left => To_Set (""""),
Right => To_Set (""""));
exception
when no_matching_quotation =>
Put ("** No matching quotation mark ** ");
New_Line;
return "";
end word;
function number_of_words
(fs : String;
ws : String := command_white_space1) return Natural
is
n : Natural := 0;
begin
while word (fs, n + 1, ws)'Length > 0 loop
n := n + 1;
end loop;
return n;
end number_of_words;
function first_word
(fs : String;
ws : String := command_white_space1) return String
is
begin
return word (fs, 1, ws);
end first_word;
function last_word
(fs : String;
ws : String := command_white_space1) return String
is
begin
return word (fs, number_of_words (fs, ws), ws);
end last_word;
function remove_comment1 (fs : String; cc : String := "#") return String is
use Ada.Strings.Fixed;
i0 : constant Natural := Index (fs, cc);
begin
return fs (fs'First .. (if i0 > 0 then i0 - 1 else fs'Last));
end remove_comment1;
end split_string;
|
with Sodium.Functions; use Sodium.Functions;
with Ada.Text_IO; use Ada.Text_IO;
procedure Demo_Ada
is
message : constant String := "From Russia with love.";
metadata : constant String := "22 chars";
begin
if not initialize_sodium_library then
Put_Line ("Initialization failed");
return;
end if;
declare
secret_key : AEAD_Key := Random_AEAD_Key;
msg_nonce : AEAD_Nonce := Random_AEAD_Nonce;
cipherlen : constant Positive := AEAD_Cipher_Length (message);
cipher_text : Encrypted_Data (1 .. cipherlen);
clear_text : String (1 .. message'Length);
begin
-- Match with C version for comparison's sake
secret_key (1 .. secret_key'Last) := (others => ASCII.NUL);
msg_nonce (1 .. msg_nonce'Last) := (others => ASCII.NUL);
Put_Line ("Secret Key (ChaCha20): " & As_Hexidecimal (secret_key));
Put_Line ("Nonce (ChaCha20): " & As_Hexidecimal (msg_nonce));
cipher_text := AEAD_Encrypt (data_to_encrypt => message,
additional_data => metadata,
secret_key => secret_key,
unique_nonce => msg_nonce);
Put_Line ("CipherText (ChaCha20): " & As_Hexidecimal (cipher_text));
begin
clear_text := AEAD_Decrypt (ciphertext => cipher_text,
additional_data => metadata,
secret_key => secret_key,
unique_nonce => msg_nonce);
Put_Line ("Back again : " & clear_text);
exception
when others => Put_Line ("Convert to clear text failed");
end;
end;
declare
secret_key : AEAD_Key := Random_AEAD_Key (AES256_GCM);
msg_nonce : AEAD_Nonce := Random_AEAD_Nonce (AES256_GCM);
clear_text : String (1 .. message'Length);
begin
Put_Line ("");
Put_Line ("Secret Key (AES256_GCM): " & As_Hexidecimal (secret_key));
Put_Line ("Nonce (AES256_GCM): " & As_Hexidecimal (msg_nonce));
declare
cipher_text : Encrypted_Data :=
AEAD_Encrypt (data_to_encrypt => message,
additional_data => metadata,
secret_key => secret_key,
unique_nonce => msg_nonce,
construction => AES256_GCM);
begin
Put_Line ("CipherText (AES256_GCM): " & As_Hexidecimal (cipher_text));
clear_text := AEAD_Decrypt (ciphertext => cipher_text,
additional_data => metadata,
secret_key => secret_key,
unique_nonce => msg_nonce,
construction => AES256_GCM);
Put_Line ("Back again : " & clear_text);
exception
when others => Put_Line ("Convert to clear text failed");
end;
end;
declare
secret_key : AEAD_Key := Random_AEAD_Key (ChaCha20_Poly1305_IETF);
msg_nonce : AEAD_Nonce := Random_AEAD_Nonce (ChaCha20_Poly1305_IETF);
cipherlen : constant Positive := AEAD_Cipher_Length (message, ChaCha20_Poly1305_IETF);
cipher_text : Encrypted_Data (1 .. cipherlen);
clear_text : String (1 .. message'Length);
begin
Put_Line ("");
if AES256_GCM_Available then
Put_Line ("Secret Key (CC20IETF): " & As_Hexidecimal (secret_key));
Put_Line ("Nonce (CC20IETF): " & As_Hexidecimal (msg_nonce));
cipher_text := AEAD_Encrypt (data_to_encrypt => message,
additional_data => metadata,
secret_key => secret_key,
unique_nonce => msg_nonce,
construction => ChaCha20_Poly1305_IETF);
Put_Line ("CipherText (CC20IETF): " & As_Hexidecimal (cipher_text));
begin
clear_text := AEAD_Decrypt (ciphertext => cipher_text,
additional_data => metadata,
secret_key => secret_key,
unique_nonce => msg_nonce,
construction => ChaCha20_Poly1305_IETF);
Put_Line ("Back again : " & clear_text);
exception
when others => Put_Line ("Convert to clear text failed");
end;
else
Put_Line ("This CPU cannot perform AES256, skipping test ...");
end if;
end;
end Demo_Ada;
|
-----------------------------------------------------------------------
-- hestia-display-main -- Main display view manager
-- Copyright (C) 2018 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with BMP_Fonts;
with UI.Texts;
with UI.Clocks;
with Hestia.Display.Instances;
with Hestia.Display.Scheduler;
package body Hestia.Display.Main is
procedure Draw_Zone_Button (Buffer : in out HAL.Bitmap.Bitmap_Buffer'Class;
Button : in UI.Buttons.Button_Type);
procedure Draw_Zone_Button (Buffer : in out HAL.Bitmap.Bitmap_Buffer'Class;
Button : in UI.Buttons.Button_Type) is
use type UI.Buttons.Button_State;
begin
if Button.State = UI.Buttons.B_PRESSED then
Buffer.Set_Source (Hot_Color);
UI.Texts.Background := Hot_Color;
else
Buffer.Set_Source (Cold_Color);
UI.Texts.Background := Cold_Color;
end if;
Buffer.Fill_Rect ((Position => Button.Pos,
Width => Button.Width,
Height => Button.Height));
UI.Texts.Current_Font := BMP_Fonts.Font16x24;
if Button.State = UI.Buttons.B_PRESSED then
UI.Texts.Draw_String (Buffer => Buffer,
Start => (Button.Pos.X, Button.Pos.Y - 12 + Button.Height / 2),
Width => Button.Width,
Msg => "ON",
Justify => UI.Texts.CENTER);
else
UI.Texts.Draw_String (Buffer => Buffer,
Start => (Button.Pos.X, Button.Pos.Y - 12 + Button.Height / 2),
Width => Button.Width,
Msg => "OFF",
Justify => UI.Texts.CENTER);
end if;
UI.Texts.Background := HAL.Bitmap.Black;
end Draw_Zone_Button;
-- ------------------------------
-- Draw the layout presentation frame.
-- ------------------------------
overriding
procedure On_Restore (Display : in out Display_Type;
Buffer : in out HAL.Bitmap.Bitmap_Buffer'Class) is
W : constant Natural := Buffer.Width;
H : constant Natural := Buffer.Height;
M : constant Natural := W / 2;
begin
-- Info button on top right.
Display.Info_Button.Pos := (W - 30, 0);
Display.Info_Button.Width := 30;
Display.Info_Button.Height := 30;
Display.Info_Button.Len := 3;
-- Zone buttons
Display.Zone1_Button.Pos := (1, 180 - 30);
Display.Zone1_Button.Width := 60;
Display.Zone1_Button.Height := 60;
Display.Zone2_Button.Pos := (W - 60, 180 - 30);
Display.Zone2_Button.Width := 60;
Display.Zone2_Button.Height := 60;
-- Scheduler buttons
Display.Sched1_Button.Pos := (M - 90 - 40, 180 - 40);
Display.Sched1_Button.Width := 80;
Display.Sched1_Button.Height := 80;
Display.Sched2_Button.Pos := (M + 90 - 40, 180 - 40);
Display.Sched2_Button.Width := 80;
Display.Sched2_Button.Height := 80;
Buffer.Set_Source (UI.Texts.Background);
Buffer.Fill;
Buffer.Set_Source (Line_Color);
Buffer.Fill_Rect ((Position => (0, 60),
Width => W,
Height => 3));
Buffer.Fill_Rect ((Position => (M, 60),
Width => 3,
Height => H - 60));
UI.Texts.Current_Font := BMP_Fonts.Font16x24;
UI.Texts.Draw_String (Buffer => Buffer,
Start => (0, W - 16),
Width => 16,
Msg => "I",
Justify => UI.Texts.LEFT);
UI.Texts.Draw_String (Buffer => Buffer,
Start => (0, 70),
Width => M - 1,
Msg => "Zone 1",
Justify => UI.Texts.CENTER);
UI.Texts.Draw_String (Buffer => Buffer,
Start => (M, 70),
Width => M - 1,
Msg => "Zone 2",
Justify => UI.Texts.CENTER);
UI.Clocks.Draw_Clock (Buffer, Center => (M - 90, 180), Width => 80);
UI.Clocks.Draw_Clock (Buffer, Center => (M + 90, 180), Width => 80);
end On_Restore;
-- ------------------------------
-- Handle touch events on the display.
-- ------------------------------
overriding
procedure On_Touch (Display : in out Display_Type;
Buffer : in out HAL.Bitmap.Bitmap_Buffer'Class;
States : in HAL.Touch_Panel.TP_State) is
use UI.Buttons;
X : constant Natural := States (States'First).X;
Y : constant Natural := States (States'First).Y;
begin
if UI.Buttons.Contains (Display.Info_Button, X, Y) then
UI.Displays.Push_Display (Instances.Info_Display'Access);
-- Toggle Zone1
elsif UI.Buttons.Contains (Display.Zone1_Button, X, Y) then
Display.Zone1_Button.State
:= (if Display.Zone1_Button.State = B_PRESSED then B_RELEASED else B_PRESSED);
Display.Refresh (Buffer, UI.Displays.REFRESH_BOTH);
-- Toggle Zone2
elsif UI.Buttons.Contains (Display.Zone2_Button, X, Y) then
Display.Zone2_Button.State
:= (if Display.Zone2_Button.State = B_PRESSED then B_RELEASED else B_PRESSED);
Display.Refresh (Buffer, UI.Displays.REFRESH_BOTH);
-- Schedule 1
elsif UI.Buttons.Contains (Display.Sched1_Button, X, Y) then
Instances.Scheduler_Display.Set_Zone (1);
UI.Displays.Push_Display (Instances.Scheduler_Display'Access);
-- Schedule 2
elsif UI.Buttons.Contains (Display.Sched2_Button, X, Y) then
Instances.Scheduler_Display.Set_Zone (2);
UI.Displays.Push_Display (Instances.Scheduler_Display'Access);
end if;
end On_Touch;
Cur_Hour : Natural := 0;
Cur_Min : Natural := 0;
Cur_Sec : Natural := 0;
-- ------------------------------
-- Refresh the current display.
-- ------------------------------
overriding
procedure On_Refresh (Display : in out Display_Type;
Buffer : in out HAL.Bitmap.Bitmap_Buffer'Class;
Deadline : out Ada.Real_Time.Time) is
W : constant Natural := Buffer.Width;
H : constant Natural := Buffer.Height;
M : constant Natural := W / 2;
begin
Draw_Zone_Button (Buffer, Display.Zone1_Button);
Draw_Zone_Button (Buffer, Display.Zone2_Button);
UI.Clocks.Draw_Clock (Buffer, Center => (M - 90, 180), Width => 80);
UI.Clocks.Draw_Clock_Tick (Buffer, (M - 90, 180), 80, Cur_Hour,
Cur_Min, Cur_Sec, UI.Clocks.HOUR_HAND);
UI.Clocks.Draw_Clock_Tick (Buffer, (M - 90, 180), 80, Cur_Hour,
Cur_Min, Cur_Sec, UI.Clocks.MINUTE_HAND);
Cur_Min := Cur_Min + 1;
if Cur_Min = 60 then
Cur_Min := 0;
Cur_Hour := (Cur_Hour + 1) mod 24;
end if;
Hestia.Display.Display_Time (Buffer, Deadline);
end On_Refresh;
end Hestia.Display.Main;
|
Pragma Ada_2012;
With
Ada.Unchecked_Conversion,
NSO.Types,
--NSO.Types.Report_Objects,
Gnoga.Server.Connection;
Package Body NSO.JSON.Gnoga_Object is
JS_Make_Path : Constant String :=
"let pathing = (str) => "&
" {return Array.from(str).reduceRight( (accumulator, current) =>"&
" {switch (current){"&
" case '[' : accumulator.push(''); break;"&
" case ']' : break;"&
" default: accumulator[accumulator.length-1] = current+accumulator[accumulator.length-1];"&
" };"&
" return accumulator; },['']).reverse();"&
" }; /*pathing*/";
JS_Get_Parameters : Constant String:=
"let collect = () => {"&
" let object = {};"&
" new URLSearchParams( new URL( document.location.href ).search ).forEach((value, key) => {"&
" /* Reflect.has in favor of: object.hasOwnProperty(key) */"&
" if(!Reflect.has(object, key)){"&
" object[key] = value;"&
" return;"&
" }"&
" if(!Array.isArray(object[key])){"&
" object[key] = [object[key]];"&
" }"&
" object[key].push(value);"&
" });"&
" return object;"&
"}; /* collect */";
JS_Build_Object : constant String:=
"let build_obj = (kvp) => {"&
" let object = {};"&
" Object.entries(kvp).forEach(([key, value]) => {"&
" let keyset = pathing( key ).reduce( (acc, cur, x, arr) =>"&
" {const exists = Reflect.has(acc,cur);"&
" const is_last = (x == arr.length-1);"&
" if (exists)"&
" {if (is_last) { acc[cur].push(value); } else {return acc[cur];}}"&
" else"&
" {if (is_last) { acc[cur] = []; acc[cur].push(value);} else { acc[cur]={}; }};"&
" return acc[cur];"&
" },object);"&
" });"&
" return object;"&
"}; /* build_obj */";
JS_Normalize_Object : Constant String:=
"let normalize = (o) => {"&
" let object = {};"&
" Object.entries(o).forEach(([key, value]) => {"&
" if (Array.isArray(value) && (value.length == 1)) { object[key] = value[0]; }"&
" else { object[key] = normalize(value);};"&
" },o);"&
" return object;"&
"}; /* Normalize */";
JS_Parameter_Object : Constant String :=
--"{"&
JS_Make_Path &
JS_Get_Parameters &
JS_Build_Object &
JS_Normalize_Object &
" JSON.stringify( normalize(build_obj(collect())) );"&
"";--"}";
Function Get_JSON(Object : Base_Type'Class) return JSON_Class is
(JSON_Class'Class'Input(
NSO.Types."+"(
Gnoga.Server.Connection.Execute_Script(
ID => Object.Connection_ID,
Script => "JSON.stringify( params )"
) -- Returns the String that is the JSON form-parameters.
) -- Uses the given String as a Stream.
) -- Reads the JSON from the given Stream.
); -- Returns the JSON.
Function Parameters (Object : Form_Object) return JSON_Class is
(JSON_Class'Class'Input(
NSO.Types."+"(
Gnoga.Server.Connection.Execute_Script(
ID => Object.Connection_ID,
Script =>
JS_Parameter_Object
-- "object = {};"&
-- "new URLSearchParams( new URL( document.location.href )"&
-- ".search ).forEach((value, key) => {"&
-- " /* Reflect.has in favor of: object.hasOwnProperty(key) */ "&
-- " if(!Reflect.has(object, key)){"&
-- " object[key] = value;"&
-- " return;"&
-- " }"&
-- " if(!Array.isArray(object[key])){"&
-- " object[key] = [object[key]];"&
-- " }"&
-- " object[key].push(value);"&
-- "});"&
-- "JSON.stringify( object );"
) -- Returns the String that is the JSON form-parameters.
) -- Uses the given String as a Stream.
) -- Reads the JSON from the given Stream.
); -- Returns the JSON.
-- Generic
-- Type Params(<>) is limited private;
-- Type Report(<>) is limited private;
-- Type View (<>) is limited private;
--
-- with Function Get(Object : Params) return Report is <>;
-- with Function Get(Object : Report) return View is <>;
Function Report_View (Object : Form_Object'Class) Return View is
-- Function Submission(Object : Form ) return Params renames Get;
-- Function Parameters(Object : Params) return Report renames Get;
-- Function Processing(Object : Report) return View renames Get;
Form_Data : Form renames Form( Object );
Begin
Return Result : Constant View :=
Processing( Parameters( Submission( Object => Form_Data ) ) );
End Report_View;
Function As_Form (Object : Base_Type'Class) return Form_Object is
Function Convert is new Ada.Unchecked_Conversion(
Source => Base_Type,
Target => Form_Object
);
Base : Base_Type renames Base_Type( Object );
Begin
-- Note: For completeness this should handle upwards-conversion, too.
-- TODO: Add a RENAMES view-conversion branch if the parameter descends from Form_Object.
Return Convert( Base );
End As_Form;
Package Body Generic_Reporter is
Function Generate_Report return View is
( Processing );
End Generic_Reporter;
End NSO.JSON.Gnoga_Object;
|
with Ada.Text_IO; use Ada.Text_IO;
package body Benchmark_Runner is
procedure Register_Benchmark(runner : in out Runner_Type;
benchmark : in Benchmark_Pointer) is
begin
runner.benchmarks.Append(benchmark);
end Register_Benchmark;
procedure Run(runner : in out Runner_Type;
mem : in Memory_Pointer) is
first : constant Natural := runner.benchmarks.First_Index;
last : constant Natural := runner.benchmarks.Last_Index;
bp : Benchmark_Pointer;
begin
for i in first .. last loop
bp := runner.benchmarks.Element(i);
Set_Memory(bp.all, mem);
end loop;
loop
for i in reverse first .. last loop
bp := runner.benchmarks.Element(i);
Reset(bp.all, i);
begin
Run(bp.all);
exception
when Prune_Error =>
null;
end;
Show_Stats(mem.all);
end loop;
exit when Done(mem.all);
end loop;
exception
when Invalid_Address =>
Put_Line("error: invalid address");
end Run;
procedure Finalize(runner : in out Runner_Type) is
first : constant Integer := runner.benchmarks.First_Index;
last : constant Integer := runner.benchmarks.Last_Index;
bp : Benchmark_Pointer;
begin
for i in first .. last loop
bp := runner.benchmarks.Element(i);
Destroy(bp);
end loop;
end Finalize;
end Benchmark_Runner;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Greet_5a is
begin
for I in 1 .. 5 loop
Put_Line ("Hello, World!" & Integer'Image (I)); -- Procedure call
-- ^ Procedure parameter
end loop;
end Greet_5a;
|
package collada.Library.geometries
--
-- Models a collada 'geometries' library, which is a collection of geometries.
--
is
------------
--- Vertices
--
type Vertices is
record
Id : Text;
Inputs : access library.Inputs;
end record;
--------------
--- Primitives
--
type int_array_List is array (Positive range <>) of access int_array;
type primitive_Kind is (Unknown,
Lines, line_Strips,
Polygons, polyList,
Triangles, triFans, triStrips);
type Primitive (Kind : primitive_Kind := Unknown) is
record
Count : Natural;
Material : Text;
Inputs : access library.Inputs;
P_List : access int_array_List;
case Kind is
when polyList =>
vCount : access int_Array;
when others =>
null;
end case;
end record;
type Primitives is array (Positive range <>) of Primitive;
function vertex_Offset_of (Self : in Primitive) return math.Index;
function normal_Offset_of (Self : in Primitive) return math.Index;
function coord_Offset_of (Self : in Primitive) return math.Index;
no_coord_Offset : exception;
--------
--- Mesh
--
type Mesh is
record
Sources : access library.Sources;
Vertices : geometries.Vertices;
Primitives : access geometries.Primitives;
end record;
function Source_of (Self : in Mesh;
source_Name : in String) return Source;
function Positions_of (Self : in Mesh) return access float_Array;
function Normals_of (Self : in Mesh;
for_Primitive : in Primitive) return access float_Array;
function Coords_of (Self : in Mesh;
for_Primitive : in Primitive) return access float_Array;
------------
--- Geometry
--
type Geometry is
record
Name : Text;
Id : Text;
Mesh : geometries.Mesh;
end record;
type Geometry_array is array (Positive range <>) of Geometry;
----------------
--- Library Item
--
type Item is
record
Contents : access Geometry_array;
end record;
end collada.Library.geometries;
|
with
openGL.Tasks,
openGL.Errors,
GL.lean,
GL.Pointers,
ada.Characters.latin_1,
ada.Strings.unbounded,
ada.Text_IO,
ada.IO_Exceptions,
interfaces.C.Strings;
package body openGL.Shader
is
use GL.lean,
Interfaces;
-----------
-- Utility
--
function read_text_File (Filename : in String) return C.char_array;
---------
-- Forge
--
procedure define (Self : in out Item; Kind : in shader.Kind;
source_Filename : in String)
is
use GL.Pointers,
C.Strings;
the_Source : aliased C.char_array := read_text_File (source_Filename);
the_Source_ptr : aliased
constant chars_ptr := to_chars_ptr (the_Source'unchecked_Access);
the_Source_Array : aliased chars_ptr_array := (1 => the_Source_ptr);
begin
Tasks.check;
Self.Kind := Kind;
if Kind = Vertex
then Self.gl_Shader := glCreateShader (GL_VERTEX_SHADER);
else Self.gl_Shader := glCreateShader (GL_FRAGMENT_SHADER);
end if;
Errors.log;
glShaderSource (Self.gl_Shader,
1,
to_GLchar_Pointer_access (the_Source_array'Access),
null);
Errors.log;
glCompileShader (Self.gl_Shader);
Errors.log;
declare
use type C.int;
Status : aliased gl.glInt;
begin
glGetShaderiv (self.gl_Shader,
GL_COMPILE_STATUS,
Status'unchecked_Access);
if Status = 0
then
declare
compile_Log : constant String := Self.shader_info_Log;
begin
Self.destroy;
raise Error with "'" & source_Filename & "' compilation failed ~ " & compile_Log;
end;
end if;
end;
end define;
procedure destroy (Self : in out Item)
is
begin
Tasks.check;
glDeleteShader (self.gl_Shader);
end destroy;
--------------
-- Attributes
--
function shader_info_Log (Self : in Item) return String
is
use C, GL;
info_log_Length : aliased glInt := 0;
chars_Written : aliased glSizei := 0;
begin
Tasks.check;
glGetShaderiv (Self.gl_Shader,
GL_INFO_LOG_LENGTH,
info_log_Length'unchecked_Access);
if info_log_Length = 0
then
return "";
end if;
declare
use gl.Pointers;
info_Log : aliased C.char_array := C.char_array' (1 .. C.size_t (info_log_Length) => <>);
info_Log_ptr : constant C.Strings.chars_Ptr := C.Strings.to_chars_ptr (info_Log'unchecked_Access);
begin
glGetShaderInfoLog (self.gl_Shader,
glSizei (info_log_Length),
chars_Written'unchecked_Access,
to_GLchar_access (info_Log_ptr));
return C.to_Ada (info_Log);
end;
end shader_info_Log;
----------
-- Privvy
--
function gl_Shader (Self : in Item) return a_gl_Shader
is
begin
return Self.gl_Shader;
end gl_Shader;
-----------
-- Utility
--
NL : constant String := "" & ada.characters.latin_1.LF;
function read_text_File (Filename : in String) return C.char_array
is
use ada.Text_IO,
ada.Strings.unbounded;
the_File : ada.Text_IO.File_type;
Pad : unbounded_String;
begin
open (the_File, in_File, Filename);
while not end_of_File (the_File)
loop
append (Pad, get_Line (the_File) & NL);
end loop;
close (the_File);
declare
use type Interfaces.C.size_t;
the_Data : C.char_array (1 .. C.size_t (Length (Pad)) + 1);
begin
for i in 1 .. the_Data'Last - 1
loop
the_Data (i) := C.char (Element (Pad, Integer (i)));
end loop;
the_Data (the_Data'Last) := C.char'Val (0);
return the_Data;
end;
exception
when ada.IO_Exceptions.name_Error =>
raise Error with "Unable to locate shader asset named '" & Filename & "'.";
end read_text_File;
end openGL.Shader;
|
with Ada.Text_IO;
procedure Sudoku is
type sudoku_ar_t is array ( integer range 0..80 ) of integer range 0..9;
FINISH_EXCEPTION : exception;
procedure prettyprint(sudoku_ar: sudoku_ar_t);
function checkValidity( val : integer; x : integer; y : integer; sudoku_ar: in sudoku_ar_t) return Boolean;
procedure placeNumber(pos: Integer; sudoku_ar: in out sudoku_ar_t);
procedure solve(sudoku_ar: in out sudoku_ar_t);
function checkValidity( val : integer; x : integer; y : integer; sudoku_ar: in sudoku_ar_t) return Boolean
is
begin
for i in 0..8 loop
if ( sudoku_ar( y * 9 + i ) = val or sudoku_ar( i * 9 + x ) = val ) then
return False;
end if;
end loop;
declare
startX : constant integer := ( x / 3 ) * 3;
startY : constant integer := ( y / 3 ) * 3;
begin
for i in startY..startY+2 loop
for j in startX..startX+2 loop
if ( sudoku_ar( i * 9 +j ) = val ) then
return False;
end if;
end loop;
end loop;
return True;
end;
end checkValidity;
procedure placeNumber(pos: Integer; sudoku_ar: in out sudoku_ar_t)
is
begin
if ( pos = 81 ) then
raise FINISH_EXCEPTION;
end if;
if ( sudoku_ar(pos) > 0 ) then
placeNumber(pos+1, sudoku_ar);
return;
end if;
for n in 1..9 loop
if( checkValidity( n, pos mod 9, pos / 9 , sudoku_ar ) ) then
sudoku_ar(pos) := n;
placeNumber(pos + 1, sudoku_ar );
sudoku_ar(pos) := 0;
end if;
end loop;
end placeNumber;
procedure solve(sudoku_ar: in out sudoku_ar_t)
is
begin
placeNumber( 0, sudoku_ar );
Ada.Text_IO.Put_Line("Unresolvable !");
exception
when FINISH_EXCEPTION =>
Ada.Text_IO.Put_Line("Finished !");
prettyprint(sudoku_ar);
end solve;
procedure prettyprint(sudoku_ar: sudoku_ar_t)
is
line_sep : constant String := "------+------+------";
begin
for i in sudoku_ar'Range loop
Ada.Text_IO.Put(sudoku_ar(i)'Image);
if (i+1) mod 3 = 0 and not((i+1) mod 9 = 0) then
Ada.Text_IO.Put("|");
end if;
if (i+1) mod 9 = 0 then
Ada.Text_IO.Put_Line("");
end if;
if (i+1) mod 27 = 0 then
Ada.Text_IO.Put_Line(line_sep);
end if;
end loop;
end prettyprint;
sudoku_ar : sudoku_ar_t :=
(
8,5,0,0,0,2,4,0,0,
7,2,0,0,0,0,0,0,9,
0,0,4,0,0,0,0,0,0,
0,0,0,1,0,7,0,0,2,
3,0,5,0,0,0,9,0,0,
0,4,0,0,0,0,0,0,0,
0,0,0,0,8,0,0,7,0,
0,1,7,0,0,0,0,0,0,
0,0,0,0,3,6,0,4,0
);
begin
solve( sudoku_ar );
end Sudoku;
|
-----------------------------------------------------------------------
-- wiki-attributes -- Wiki document attributes
-- Copyright (C) 2015, 2016, 2020 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Wiki.Strings;
private with Ada.Containers.Vectors;
private with Ada.Finalization;
private with Util.Refs;
-- == Attributes ==
-- The `Attributes` package defines a simple management of attributes for
-- the wiki document parser. Attribute lists are described by the `Attribute_List`
-- with some operations to append or query for an attribute. Attributes are used for
-- the Wiki document representation to describe the HTML attributes that were parsed and
-- several parameters that describe Wiki content (links, ...).
--
-- The Wiki filters and Wiki plugins have access to the attributes before they are added
-- to the Wiki document. They can check them or modify them according to their needs.
--
-- The Wiki renderers use the attributes to render the final HTML content.
package Wiki.Attributes is
pragma Preelaborate;
type Cursor is private;
-- Get the attribute name.
function Get_Name (Position : in Cursor) return String;
-- Get the attribute value.
function Get_Value (Position : in Cursor) return String;
-- Get the attribute wide value.
function Get_Wide_Value (Position : in Cursor) return Wiki.Strings.WString;
-- Returns True if the cursor has a valid attribute.
function Has_Element (Position : in Cursor) return Boolean;
-- Move the cursor to the next attribute.
procedure Next (Position : in out Cursor);
-- A list of attributes.
type Attribute_List is private;
-- Find the attribute with the given name.
function Find (List : in Attribute_List;
Name : in String) return Cursor;
-- Find the attribute with the given name and return its value.
function Get_Attribute (List : in Attribute_List;
Name : in String) return Wiki.Strings.WString;
-- Append the attribute to the attribute list.
procedure Append (List : in out Attribute_List;
Name : in Wiki.Strings.WString;
Value : in Wiki.Strings.WString);
-- Append the attribute to the attribute list.
procedure Append (List : in out Attribute_List;
Name : in String;
Value : in Wiki.Strings.WString);
-- Append the attribute to the attribute list.
procedure Append (List : in out Attribute_List;
Name : in String;
Value : in Wiki.Strings.UString);
-- Get the cursor to get access to the first attribute.
function First (List : in Attribute_List) return Cursor;
-- Get the number of attributes in the list.
function Length (List : in Attribute_List) return Natural;
-- Clear the list and remove all existing attributes.
procedure Clear (List : in out Attribute_List);
-- Iterate over the list attributes and call the <tt>Process</tt> procedure.
procedure Iterate (List : in Attribute_List;
Process : not null access procedure (Name : in String;
Value : in Wiki.Strings.WString));
private
type Attribute (Name_Length, Value_Length : Natural) is limited
new Util.Refs.Ref_Entity with record
Name : String (1 .. Name_Length);
Value : Wiki.Strings.WString (1 .. Value_Length);
end record;
type Attribute_Access is access all Attribute;
package Attribute_Refs is new Util.Refs.Indefinite_References (Attribute, Attribute_Access);
use Attribute_Refs;
subtype Attribute_Ref is Attribute_Refs.Ref;
package Attribute_Vectors is
new Ada.Containers.Vectors (Index_Type => Positive,
Element_Type => Attribute_Ref);
subtype Attribute_Vector is Attribute_Vectors.Vector;
type Cursor is record
Pos : Attribute_Vectors.Cursor;
end record;
type Attribute_List is new Ada.Finalization.Controlled with record
List : Attribute_Vector;
end record;
-- Finalize the attribute list releasing any storage.
overriding
procedure Finalize (List : in out Attribute_List);
end Wiki.Attributes;
|
-----------------------------------------------------------------------
-- awa-mail -- Mail module
-- Copyright (C) 2011, 2017, 2018, 2020 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
-- = Mail Module =
-- The `mail` module allows an application to format and send a mail
-- to users. This module does not define any web interface. It provides
-- a set of services and methods to send a mail when an event is
-- received. All this is done through configuration. The module
-- defines a set of specific ASF components to format and prepare the
-- email.
--
-- @include awa-mail-modules.ads
package AWA.Mail is
pragma Pure;
end AWA.Mail;
|
-- Copyright 2015 Steven Stewart-Gallus
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-- implied. See the License for the specific language governing
-- permissions and limitations under the License.
with Interfaces.C; use Interfaces.C;
with Libc.Stdint;
with Interfaces.C.Strings;
with Libc.Stddef;
with System;
limited with Libc.Stdio;
package XKB with
Spark_Mode => Off is
pragma Preelaborate;
pragma Link_With ("-lxkbcommon");
XKB_KEYCODE_INVALID : constant := 16#ffffffff#;
XKB_LAYOUT_INVALID : constant := 16#ffffffff#;
XKB_LEVEL_INVALID : constant := 16#ffffffff#;
XKB_MOD_INVALID : constant := 16#ffffffff#;
XKB_LED_INVALID : constant := 16#ffffffff#;
XKB_KEYCODE_MAX : constant := 16#ffffffff# - 1;
-- arg-macro: function xkb_keycode_is_legal_ext (key)
-- return key <= XKB_KEYCODE_MAX;
-- arg-macro: function xkb_keycode_is_legal_x11 (key)
-- return key >= 8 and then key <= 255;
type xkb_context is limited private;
type xkb_context_access is access all xkb_context;
type xkb_keymap is limited private;
type xkb_keymap_access is access all xkb_keymap;
type xkb_state is limited private;
type xkb_state_access is access all xkb_state;
subtype xkb_keycode_t is
Libc.Stdint.uint32_t; -- /usr/include/xkbcommon/xkbcommon.h:161
subtype xkb_keysym_t is
Libc.Stdint.uint32_t; -- /usr/include/xkbcommon/xkbcommon.h:191
subtype xkb_layout_index_t is
Libc.Stdint.uint32_t; -- /usr/include/xkbcommon/xkbcommon.h:211
subtype xkb_layout_mask_t is
Libc.Stdint.uint32_t; -- /usr/include/xkbcommon/xkbcommon.h:213
subtype xkb_level_index_t is
Libc.Stdint.uint32_t; -- /usr/include/xkbcommon/xkbcommon.h:227
subtype xkb_mod_index_t is
Libc.Stdint.uint32_t; -- /usr/include/xkbcommon/xkbcommon.h:252
subtype xkb_mod_mask_t is
Libc.Stdint.uint32_t; -- /usr/include/xkbcommon/xkbcommon.h:254
subtype xkb_led_index_t is
Libc.Stdint.uint32_t; -- /usr/include/xkbcommon/xkbcommon.h:281
subtype xkb_led_mask_t is
Libc.Stdint.uint32_t; -- /usr/include/xkbcommon/xkbcommon.h:283
type xkb_rule_names is record
rules : Interfaces.C.Strings
.chars_ptr; -- /usr/include/xkbcommon/xkbcommon.h:323
model : Interfaces.C.Strings
.chars_ptr; -- /usr/include/xkbcommon/xkbcommon.h:331
layout : Interfaces.C.Strings
.chars_ptr; -- /usr/include/xkbcommon/xkbcommon.h:340
variant : Interfaces.C.Strings
.chars_ptr; -- /usr/include/xkbcommon/xkbcommon.h:351
options : Interfaces.C.Strings
.chars_ptr; -- /usr/include/xkbcommon/xkbcommon.h:362
end record;
pragma Convention
(C_Pass_By_Copy,
xkb_rule_names); -- /usr/include/xkbcommon/xkbcommon.h:314
function xkb_keysym_get_name
(keysym : xkb_keysym_t;
buffer : Interfaces.C.Strings.chars_ptr;
size : Libc.Stddef.size_t)
return int; -- /usr/include/xkbcommon/xkbcommon.h:393
pragma Import (C, xkb_keysym_get_name, "xkb_keysym_get_name");
type xkb_keysym_flags is (XKB_KEYSYM_NO_FLAGS, XKB_KEYSYM_CASE_INSENSITIVE);
pragma Convention
(C,
xkb_keysym_flags); -- /usr/include/xkbcommon/xkbcommon.h:396
function xkb_keysym_from_name
(name : Interfaces.C.Strings.chars_ptr;
flags : xkb_keysym_flags)
return xkb_keysym_t; -- /usr/include/xkbcommon/xkbcommon.h:424
pragma Import (C, xkb_keysym_from_name, "xkb_keysym_from_name");
function xkb_keysym_to_utf8
(keysym : xkb_keysym_t;
buffer : Interfaces.C.Strings.chars_ptr;
size : Libc.Stddef.size_t)
return int; -- /usr/include/xkbcommon/xkbcommon.h:443
pragma Import (C, xkb_keysym_to_utf8, "xkb_keysym_to_utf8");
function xkb_keysym_to_utf32
(keysym : xkb_keysym_t)
return Libc.Stdint.uint32_t; -- /usr/include/xkbcommon/xkbcommon.h:458
pragma Import (C, xkb_keysym_to_utf32, "xkb_keysym_to_utf32");
type xkb_context_flags is
(XKB_CONTEXT_NO_FLAGS,
XKB_CONTEXT_NO_DEFAULT_INCLUDES,
XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
pragma Convention
(C,
xkb_context_flags); -- /usr/include/xkbcommon/xkbcommon.h:473
function xkb_context_new
(flags : xkb_context_flags)
return xkb_context_access; -- /usr/include/xkbcommon/xkbcommon.h:496
pragma Import (C, xkb_context_new, "xkb_context_new");
function xkb_context_ref
(context : xkb_context)
return xkb_context_access; -- /usr/include/xkbcommon/xkbcommon.h:506
pragma Import (C, xkb_context_ref, "xkb_context_ref");
procedure xkb_context_unref
(context : xkb_context); -- /usr/include/xkbcommon/xkbcommon.h:516
pragma Import (C, xkb_context_unref, "xkb_context_unref");
procedure xkb_context_set_user_data
(context : xkb_context_access;
user_data : System.Address); -- /usr/include/xkbcommon/xkbcommon.h:527
pragma Import (C, xkb_context_set_user_data, "xkb_context_set_user_data");
function xkb_context_get_user_data
(context : xkb_context)
return System.Address; -- /usr/include/xkbcommon/xkbcommon.h:541
pragma Import (C, xkb_context_get_user_data, "xkb_context_get_user_data");
function xkb_context_include_path_append
(context : xkb_context_access;
path : Interfaces.C.Strings.chars_ptr)
return int; -- /usr/include/xkbcommon/xkbcommon.h:565
pragma Import
(C,
xkb_context_include_path_append,
"xkb_context_include_path_append");
function xkb_context_include_path_append_default
(context : xkb_context)
return int; -- /usr/include/xkbcommon/xkbcommon.h:575
pragma Import
(C,
xkb_context_include_path_append_default,
"xkb_context_include_path_append_default");
function xkb_context_include_path_reset_defaults
(context : xkb_context)
return int; -- /usr/include/xkbcommon/xkbcommon.h:588
pragma Import
(C,
xkb_context_include_path_reset_defaults,
"xkb_context_include_path_reset_defaults");
procedure xkb_context_include_path_clear
(context : xkb_context); -- /usr/include/xkbcommon/xkbcommon.h:596
pragma Import
(C,
xkb_context_include_path_clear,
"xkb_context_include_path_clear");
function xkb_context_num_include_paths
(context : xkb_context)
return unsigned; -- /usr/include/xkbcommon/xkbcommon.h:604
pragma Import
(C,
xkb_context_num_include_paths,
"xkb_context_num_include_paths");
function xkb_context_include_path_get
(context : xkb_context_access;
index : unsigned)
return Interfaces.C.Strings
.chars_ptr; -- /usr/include/xkbcommon/xkbcommon.h:615
pragma Import
(C,
xkb_context_include_path_get,
"xkb_context_include_path_get");
subtype xkb_log_level is unsigned;
XKB_LOG_LEVEL_CRITICAL : constant xkb_log_level := 10;
XKB_LOG_LEVEL_ERROR : constant xkb_log_level := 20;
XKB_LOG_LEVEL_WARNING : constant xkb_log_level := 30;
XKB_LOG_LEVEL_INFO : constant xkb_log_level := 40;
XKB_LOG_LEVEL_DEBUG : constant xkb_log_level :=
50; -- /usr/include/xkbcommon/xkbcommon.h:627
procedure xkb_context_set_log_level
(context : xkb_context_access;
level : xkb_log_level); -- /usr/include/xkbcommon/xkbcommon.h:649
pragma Import (C, xkb_context_set_log_level, "xkb_context_set_log_level");
function xkb_context_get_log_level
(context : xkb_context)
return xkb_log_level; -- /usr/include/xkbcommon/xkbcommon.h:658
pragma Import (C, xkb_context_get_log_level, "xkb_context_get_log_level");
procedure xkb_context_set_log_verbosity
(context : xkb_context_access;
verbosity : int); -- /usr/include/xkbcommon/xkbcommon.h:680
pragma Import
(C,
xkb_context_set_log_verbosity,
"xkb_context_set_log_verbosity");
function xkb_context_get_log_verbosity
(context : xkb_context)
return int; -- /usr/include/xkbcommon/xkbcommon.h:688
pragma Import
(C,
xkb_context_get_log_verbosity,
"xkb_context_get_log_verbosity");
procedure xkb_context_set_log_fn
(context : xkb_context_access;
log_fn : access procedure
(arg1 : System.Address;
arg2 : xkb_log_level;
arg3 : Interfaces.C.Strings.chars_ptr;
arg4 : access System
.Address)); -- /usr/include/xkbcommon/xkbcommon.h:711
pragma Import (C, xkb_context_set_log_fn, "xkb_context_set_log_fn");
type xkb_keymap_compile_flags is (XKB_KEYMAP_COMPILE_NO_FLAGS);
pragma Convention
(C,
xkb_keymap_compile_flags); -- /usr/include/xkbcommon/xkbcommon.h:726
function xkb_keymap_new_from_names
(context : xkb_context_access;
names : access constant xkb_rule_names;
flags : xkb_keymap_compile_flags)
return xkb_keymap_access; -- /usr/include/xkbcommon/xkbcommon.h:748
pragma Import (C, xkb_keymap_new_from_names, "xkb_keymap_new_from_names");
subtype xkb_keymap_format is unsigned;
XKB_KEYMAP_FORMAT_TEXT_V1 : constant xkb_keymap_format :=
1; -- /usr/include/xkbcommon/xkbcommon.h:753
XKB_KEYMAP_USE_ORIGINAL_FORMAT : constant xkb_keymap_format :=
xkb_keymap_format'Last;
function xkb_keymap_new_from_file
(context : xkb_context_access;
the_file : access Libc.Stdio.FILE;
format : xkb_keymap_format;
flags : xkb_keymap_compile_flags)
return xkb_keymap_access; -- /usr/include/xkbcommon/xkbcommon.h:777
pragma Import (C, xkb_keymap_new_from_file, "xkb_keymap_new_from_file");
function xkb_keymap_new_from_string
(context : xkb_context_access;
string : Interfaces.C.Strings.chars_ptr;
format : xkb_keymap_format;
flags : xkb_keymap_compile_flags)
return xkb_keymap_access; -- /usr/include/xkbcommon/xkbcommon.h:791
pragma Import (C, xkb_keymap_new_from_string, "xkb_keymap_new_from_string");
function xkb_keymap_new_from_buffer
(context : xkb_context_access;
buffer : Interfaces.C.Strings.chars_ptr;
length : Libc.Stddef.size_t;
format : xkb_keymap_format;
flags : xkb_keymap_compile_flags)
return xkb_keymap_access; -- /usr/include/xkbcommon/xkbcommon.h:805
pragma Import (C, xkb_keymap_new_from_buffer, "xkb_keymap_new_from_buffer");
function xkb_keymap_ref
(keymap : xkb_keymap)
return xkb_keymap_access; -- /usr/include/xkbcommon/xkbcommon.h:817
pragma Import (C, xkb_keymap_ref, "xkb_keymap_ref");
procedure xkb_keymap_unref
(keymap : xkb_keymap); -- /usr/include/xkbcommon/xkbcommon.h:827
pragma Import (C, xkb_keymap_unref, "xkb_keymap_unref");
function xkb_keymap_get_as_string
(keymap : xkb_keymap_access;
format : xkb_keymap_format)
return Interfaces.C.Strings
.chars_ptr; -- /usr/include/xkbcommon/xkbcommon.h:854
pragma Import (C, xkb_keymap_get_as_string, "xkb_keymap_get_as_string");
function xkb_keymap_min_keycode
(keymap : xkb_keymap)
return xkb_keycode_t; -- /usr/include/xkbcommon/xkbcommon.h:873
pragma Import (C, xkb_keymap_min_keycode, "xkb_keymap_min_keycode");
function xkb_keymap_max_keycode
(keymap : xkb_keymap)
return xkb_keycode_t; -- /usr/include/xkbcommon/xkbcommon.h:882
pragma Import (C, xkb_keymap_max_keycode, "xkb_keymap_max_keycode");
type xkb_keymap_key_iter_t is access procedure
(arg1 : System.Address;
arg2 : xkb_keycode_t;
arg3 : System.Address);
pragma Convention
(C,
xkb_keymap_key_iter_t); -- /usr/include/xkbcommon/xkbcommon.h:891
procedure xkb_keymap_key_for_each
(keymap : xkb_keymap_access;
iter : xkb_keymap_key_iter_t;
data : System.Address); -- /usr/include/xkbcommon/xkbcommon.h:903
pragma Import (C, xkb_keymap_key_for_each, "xkb_keymap_key_for_each");
function xkb_keymap_num_mods
(keymap : xkb_keymap)
return xkb_mod_index_t; -- /usr/include/xkbcommon/xkbcommon.h:913
pragma Import (C, xkb_keymap_num_mods, "xkb_keymap_num_mods");
function xkb_keymap_mod_get_name
(keymap : xkb_keymap_access;
idx : xkb_mod_index_t)
return Interfaces.C.Strings
.chars_ptr; -- /usr/include/xkbcommon/xkbcommon.h:924
pragma Import (C, xkb_keymap_mod_get_name, "xkb_keymap_mod_get_name");
function xkb_keymap_mod_get_index
(keymap : xkb_keymap_access;
name : Interfaces.C.Strings.chars_ptr)
return xkb_mod_index_t; -- /usr/include/xkbcommon/xkbcommon.h:936
pragma Import (C, xkb_keymap_mod_get_index, "xkb_keymap_mod_get_index");
function xkb_keymap_num_layouts
(keymap : xkb_keymap)
return xkb_layout_index_t; -- /usr/include/xkbcommon/xkbcommon.h:945
pragma Import (C, xkb_keymap_num_layouts, "xkb_keymap_num_layouts");
function xkb_keymap_layout_get_name
(keymap : xkb_keymap_access;
idx : xkb_layout_index_t)
return Interfaces.C.Strings
.chars_ptr; -- /usr/include/xkbcommon/xkbcommon.h:957
pragma Import (C, xkb_keymap_layout_get_name, "xkb_keymap_layout_get_name");
function xkb_keymap_layout_get_index
(keymap : xkb_keymap_access;
name : Interfaces.C.Strings.chars_ptr)
return xkb_layout_index_t; -- /usr/include/xkbcommon/xkbcommon.h:969
pragma Import
(C,
xkb_keymap_layout_get_index,
"xkb_keymap_layout_get_index");
function xkb_keymap_num_layouts_for_key
(keymap : xkb_keymap_access;
key : xkb_keycode_t)
return xkb_layout_index_t; -- /usr/include/xkbcommon/xkbcommon.h:982
pragma Import
(C,
xkb_keymap_num_layouts_for_key,
"xkb_keymap_num_layouts_for_key");
function xkb_keymap_num_levels_for_key
(keymap : xkb_keymap_access;
key : xkb_keycode_t;
layout : xkb_layout_index_t)
return xkb_level_index_t; -- /usr/include/xkbcommon/xkbcommon.h:995
pragma Import
(C,
xkb_keymap_num_levels_for_key,
"xkb_keymap_num_levels_for_key");
function xkb_keymap_key_get_syms_by_level
(keymap : xkb_keymap_access;
key : xkb_keycode_t;
layout : xkb_layout_index_t;
level : xkb_level_index_t;
syms_out : System.Address)
return int; -- /usr/include/xkbcommon/xkbcommon.h:1027
pragma Import
(C,
xkb_keymap_key_get_syms_by_level,
"xkb_keymap_key_get_syms_by_level");
function xkb_keymap_num_leds
(keymap : xkb_keymap)
return xkb_led_index_t; -- /usr/include/xkbcommon/xkbcommon.h:1045
pragma Import (C, xkb_keymap_num_leds, "xkb_keymap_num_leds");
function xkb_keymap_led_get_name
(keymap : xkb_keymap_access;
idx : xkb_led_index_t)
return Interfaces.C.Strings
.chars_ptr; -- /usr/include/xkbcommon/xkbcommon.h:1055
pragma Import (C, xkb_keymap_led_get_name, "xkb_keymap_led_get_name");
function xkb_keymap_led_get_index
(keymap : xkb_keymap_access;
name : Interfaces.C.Strings.chars_ptr)
return xkb_led_index_t; -- /usr/include/xkbcommon/xkbcommon.h:1066
pragma Import (C, xkb_keymap_led_get_index, "xkb_keymap_led_get_index");
function xkb_keymap_key_repeats
(keymap : xkb_keymap_access;
key : xkb_keycode_t)
return int; -- /usr/include/xkbcommon/xkbcommon.h:1084
pragma Import (C, xkb_keymap_key_repeats, "xkb_keymap_key_repeats");
function xkb_state_new
(keymap : xkb_keymap)
return xkb_state_access; -- /usr/include/xkbcommon/xkbcommon.h:1105
pragma Import (C, xkb_state_new, "xkb_state_new");
function xkb_state_ref
(state : xkb_state)
return xkb_state_access; -- /usr/include/xkbcommon/xkbcommon.h:1115
pragma Import (C, xkb_state_ref, "xkb_state_ref");
procedure xkb_state_unref
(state : xkb_state); -- /usr/include/xkbcommon/xkbcommon.h:1125
pragma Import (C, xkb_state_unref, "xkb_state_unref");
function xkb_state_get_keymap
(state : xkb_state)
return xkb_keymap_access; -- /usr/include/xkbcommon/xkbcommon.h:1140
pragma Import (C, xkb_state_get_keymap, "xkb_state_get_keymap");
type xkb_key_direction is (XKB_KEY_UP, XKB_KEY_DOWN);
pragma Convention
(C,
xkb_key_direction); -- /usr/include/xkbcommon/xkbcommon.h:1143
subtype xkb_state_component is unsigned;
XKB_STATE_MODS_DEPRESSED : constant xkb_state_component := 1;
XKB_STATE_MODS_LATCHED : constant xkb_state_component := 2;
XKB_STATE_MODS_LOCKED : constant xkb_state_component := 4;
XKB_STATE_MODS_EFFECTIVE : constant xkb_state_component := 8;
XKB_STATE_LAYOUT_DEPRESSED : constant xkb_state_component := 16;
XKB_STATE_LAYOUT_LATCHED : constant xkb_state_component := 32;
XKB_STATE_LAYOUT_LOCKED : constant xkb_state_component := 64;
XKB_STATE_LAYOUT_EFFECTIVE : constant xkb_state_component := 128;
XKB_STATE_LEDS : constant xkb_state_component :=
256; -- /usr/include/xkbcommon/xkbcommon.h:1155
function xkb_state_update_key
(state : xkb_state_access;
key : xkb_keycode_t;
direction : xkb_key_direction)
return xkb_state_component; -- /usr/include/xkbcommon/xkbcommon.h:1214
pragma Import (C, xkb_state_update_key, "xkb_state_update_key");
function xkb_state_update_mask
(state : xkb_state_access;
depressed_mods : xkb_mod_mask_t;
latched_mods : xkb_mod_mask_t;
locked_mods : xkb_mod_mask_t;
depressed_layout : xkb_layout_index_t;
latched_layout : xkb_layout_index_t;
locked_layout : xkb_layout_index_t)
return xkb_state_component; -- /usr/include/xkbcommon/xkbcommon.h:1245
pragma Import (C, xkb_state_update_mask, "xkb_state_update_mask");
function xkb_state_key_get_syms
(state : xkb_state_access;
key : xkb_keycode_t;
syms_out : System.Address)
return int; -- /usr/include/xkbcommon/xkbcommon.h:1278
pragma Import (C, xkb_state_key_get_syms, "xkb_state_key_get_syms");
function xkb_state_key_get_utf8
(state : xkb_state_access;
key : xkb_keycode_t;
buffer : Interfaces.C.Strings.chars_ptr;
size : Libc.Stddef.size_t)
return int; -- /usr/include/xkbcommon/xkbcommon.h:1304
pragma Import (C, xkb_state_key_get_utf8, "xkb_state_key_get_utf8");
function xkb_state_key_get_utf32
(state : xkb_state_access;
key : xkb_keycode_t)
return Libc.Stdint.uint32_t; -- /usr/include/xkbcommon/xkbcommon.h:1317
pragma Import (C, xkb_state_key_get_utf32, "xkb_state_key_get_utf32");
function xkb_state_key_get_one_sym
(state : xkb_state_access;
key : xkb_keycode_t)
return xkb_keysym_t; -- /usr/include/xkbcommon/xkbcommon.h:1335
pragma Import (C, xkb_state_key_get_one_sym, "xkb_state_key_get_one_sym");
function xkb_state_key_get_layout
(state : xkb_state_access;
key : xkb_keycode_t)
return xkb_layout_index_t; -- /usr/include/xkbcommon/xkbcommon.h:1352
pragma Import (C, xkb_state_key_get_layout, "xkb_state_key_get_layout");
function xkb_state_key_get_level
(state : xkb_state_access;
key : xkb_keycode_t;
layout : xkb_layout_index_t)
return xkb_level_index_t; -- /usr/include/xkbcommon/xkbcommon.h:1377
pragma Import (C, xkb_state_key_get_level, "xkb_state_key_get_level");
subtype xkb_state_match is unsigned;
XKB_STATE_MATCH_ANY : constant xkb_state_match := 1;
XKB_STATE_MATCH_ALL : constant xkb_state_match := 2;
XKB_STATE_MATCH_NON_EXCLUSIVE : constant xkb_state_match :=
65536; -- /usr/include/xkbcommon/xkbcommon.h:1386
function xkb_state_serialize_mods
(state : xkb_state_access;
components : xkb_state_component)
return xkb_mod_mask_t; -- /usr/include/xkbcommon/xkbcommon.h:1415
pragma Import (C, xkb_state_serialize_mods, "xkb_state_serialize_mods");
function xkb_state_serialize_layout
(state : xkb_state_access;
components : xkb_state_component)
return xkb_layout_index_t; -- /usr/include/xkbcommon/xkbcommon.h:1437
pragma Import (C, xkb_state_serialize_layout, "xkb_state_serialize_layout");
function xkb_state_mod_name_is_active
(state : xkb_state_access;
name : Interfaces.C.Strings.chars_ptr;
c_type : xkb_state_component)
return int; -- /usr/include/xkbcommon/xkbcommon.h:1449
pragma Import
(C,
xkb_state_mod_name_is_active,
"xkb_state_mod_name_is_active");
function xkb_state_mod_names_are_active
(state : xkb_state_access;
c_type : xkb_state_component;
match : xkb_state_match -- , ...
) return int; -- /usr/include/xkbcommon/xkbcommon.h:1470
pragma Import
(C,
xkb_state_mod_names_are_active,
"xkb_state_mod_names_are_active");
function xkb_state_mod_index_is_active
(state : xkb_state_access;
idx : xkb_mod_index_t;
c_type : xkb_state_component)
return int; -- /usr/include/xkbcommon/xkbcommon.h:1484
pragma Import
(C,
xkb_state_mod_index_is_active,
"xkb_state_mod_index_is_active");
function xkb_state_mod_indices_are_active
(state : xkb_state_access;
c_type : xkb_state_component;
match : xkb_state_match -- , ...
) return int; -- /usr/include/xkbcommon/xkbcommon.h:1505
pragma Import
(C,
xkb_state_mod_indices_are_active,
"xkb_state_mod_indices_are_active");
function xkb_state_mod_index_is_consumed
(state : xkb_state_access;
key : xkb_keycode_t;
idx : xkb_mod_index_t)
return int; -- /usr/include/xkbcommon/xkbcommon.h:1574
pragma Import
(C,
xkb_state_mod_index_is_consumed,
"xkb_state_mod_index_is_consumed");
function xkb_state_mod_mask_remove_consumed
(state : xkb_state_access;
key : xkb_keycode_t;
mask : xkb_mod_mask_t)
return xkb_mod_mask_t; -- /usr/include/xkbcommon/xkbcommon.h:1587
pragma Import
(C,
xkb_state_mod_mask_remove_consumed,
"xkb_state_mod_mask_remove_consumed");
function xkb_state_key_get_consumed_mods
(state : xkb_state_access;
key : xkb_keycode_t)
return xkb_mod_mask_t; -- /usr/include/xkbcommon/xkbcommon.h:1599
pragma Import
(C,
xkb_state_key_get_consumed_mods,
"xkb_state_key_get_consumed_mods");
function xkb_state_layout_name_is_active
(state : xkb_state_access;
name : Interfaces.C.Strings.chars_ptr;
c_type : xkb_state_component)
return int; -- /usr/include/xkbcommon/xkbcommon.h:1614
pragma Import
(C,
xkb_state_layout_name_is_active,
"xkb_state_layout_name_is_active");
function xkb_state_layout_index_is_active
(state : xkb_state_access;
idx : xkb_layout_index_t;
c_type : xkb_state_component)
return int; -- /usr/include/xkbcommon/xkbcommon.h:1627
pragma Import
(C,
xkb_state_layout_index_is_active,
"xkb_state_layout_index_is_active");
function xkb_state_led_name_is_active
(state : xkb_state_access;
name : Interfaces.C.Strings.chars_ptr)
return int; -- /usr/include/xkbcommon/xkbcommon.h:1641
pragma Import
(C,
xkb_state_led_name_is_active,
"xkb_state_led_name_is_active");
function xkb_state_led_index_is_active
(state : xkb_state_access;
idx : xkb_led_index_t)
return int; -- /usr/include/xkbcommon/xkbcommon.h:1653
pragma Import
(C,
xkb_state_led_index_is_active,
"xkb_state_led_index_is_active");
private
type xkb_context is limited record
null;
end record;
type xkb_keymap is limited record
null;
end record;
type xkb_state is limited record
null;
end record;
end XKB;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . O B J E C T _ R E A D E R --
-- --
-- S p e c --
-- --
-- Copyright (C) 2009-2019, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package implements a simple, minimal overhead reader for object files
-- composed of sections of untyped heterogeneous binary data.
with Interfaces;
with System.Mmap;
package System.Object_Reader is
--------------
-- Limits --
--------------
BUFFER_SIZE : constant := 8 * 1024;
---------------------
-- Object sections --
----------------------
type Object_Section is private;
Null_Section : constant Object_Section;
--------------------
-- Object symbols --
--------------------
type Object_Symbol is private;
------------------------
-- Object format type --
------------------------
type Object_Format is
(ELF32,
-- Object format is 32-bit ELF
ELF64,
-- Object format is 64-bit ELF
PECOFF,
-- Object format is Microsoft PECOFF
PECOFF_PLUS,
-- Object format is Microsoft PECOFF+
XCOFF32);
-- Object format is AIX 32-bit XCOFF
-- PECOFF | PECOFF_PLUS appears so often as a case choice, would
-- seem a good idea to have a subtype name covering these two choices ???
------------------
-- Object files --
------------------
type Object_File (Format : Object_Format) is private;
type Object_File_Access is access Object_File;
------------------------------
-- Object architecture type --
------------------------------
type Object_Arch is
(Unknown,
-- The target architecture has not yet been determined
SPARC,
-- 32-bit SPARC
SPARC64,
-- 64-bit SPARC
i386,
-- Intel IA32
MIPS,
-- MIPS Technologies MIPS
x86_64,
-- x86-64 (64-bit AMD/Intel)
IA64,
-- Intel IA64
PPC,
-- 32-bit PowerPC
PPC64);
-- 64-bit PowerPC
------------------
-- Target types --
------------------
subtype Offset is Interfaces.Integer_64;
subtype uint8 is Interfaces.Unsigned_8;
subtype uint16 is Interfaces.Unsigned_16;
subtype uint32 is Interfaces.Unsigned_32;
subtype uint64 is Interfaces.Unsigned_64;
subtype int8 is Interfaces.Integer_8;
subtype int16 is Interfaces.Integer_16;
subtype int32 is Interfaces.Integer_32;
subtype int64 is Interfaces.Integer_64;
type Buffer is array (0 .. BUFFER_SIZE - 1) of uint8;
type String_Ptr_Len is record
Ptr : Mmap.Str_Access;
Len : Natural;
end record;
-- A string made from a pointer and a length. Not all strings for name
-- are C strings: COFF inlined symbol names have a max length of 8.
-------------------------------------------
-- Operations on buffers of untyped data --
-------------------------------------------
function To_String (Buf : Buffer) return String;
-- Construct string from C style null-terminated string stored in a buffer
function To_String_Ptr_Len
(Ptr : Mmap.Str_Access;
Max_Len : Natural := Natural'Last) return String_Ptr_Len;
-- Convert PTR to a String_Ptr_Len.
function Strlen (Buf : Buffer) return int32;
-- Return the length of a C style null-terminated string
-------------------------
-- Opening and closing --
-------------------------
function Open
(File_Name : String;
In_Exception : Boolean := False) return Object_File_Access;
-- Open the object file and initialize the reader. In_Exception is true
-- when the parsing is done as part of an exception handler decorator. In
-- this mode we do not want to raise an exception.
procedure Close (Obj : in out Object_File);
-- Close the object file
-----------------------
-- Sequential access --
-----------------------
type Mapped_Stream is private;
-- Provide an abstraction of a stream on a memory mapped file
function Create_Stream (Mf : System.Mmap.Mapped_File;
File_Offset : System.Mmap.File_Size;
File_Length : System.Mmap.File_Size)
return Mapped_Stream;
-- Create a stream from Mf
procedure Close (S : in out Mapped_Stream);
-- Close the stream (deallocate memory)
procedure Read_Raw
(S : in out Mapped_Stream;
Addr : Address;
Size : uint32);
pragma Inline (Read_Raw);
-- Read a number of fixed sized records
procedure Seek (S : in out Mapped_Stream; Off : Offset);
-- Seek to an absolute offset in bytes
procedure Tell (Obj : in out Mapped_Stream; Off : out Offset)
with Inline;
function Tell (Obj : Mapped_Stream) return Offset
with Inline;
-- Fetch the current offset
function Length (Obj : Mapped_Stream) return Offset
with Inline;
-- Length of the stream
function Read (S : in out Mapped_Stream) return Mmap.Str_Access;
-- Provide a pointer in memory at the current offset
function Read (S : in out Mapped_Stream) return String_Ptr_Len;
-- Provide a pointer in memory at the current offset
function Read (S : in out Mapped_Stream) return uint8;
function Read (S : in out Mapped_Stream) return uint16;
function Read (S : in out Mapped_Stream) return uint32;
function Read (S : in out Mapped_Stream) return uint64;
function Read (S : in out Mapped_Stream) return int8;
function Read (S : in out Mapped_Stream) return int16;
function Read (S : in out Mapped_Stream) return int32;
function Read (S : in out Mapped_Stream) return int64;
-- Read a scalar
function Read_Address
(Obj : Object_File; S : in out Mapped_Stream) return uint64;
-- Read either a 64 or 32 bit address from the file stream depending on the
-- address size of the target architecture and promote it to a 64 bit type.
function Read_LEB128 (S : in out Mapped_Stream) return uint32;
function Read_LEB128 (S : in out Mapped_Stream) return int32;
-- Read a value encoding in Little-Endian Base 128 format
procedure Read_C_String (S : in out Mapped_Stream; B : out Buffer);
function Read_C_String (S : in out Mapped_Stream) return Mmap.Str_Access;
-- Read a C style NULL terminated string
function Offset_To_String
(S : in out Mapped_Stream;
Off : Offset) return String;
-- Construct a string from a C style NULL terminated string located at an
-- offset into the object file.
------------------------
-- Object information --
------------------------
function Arch (Obj : Object_File) return Object_Arch;
-- Return the object architecture
function Format (Obj : Object_File) return Object_Format;
-- Return the object file format
function Get_Load_Address (Obj : Object_File) return uint64;
-- Return the load address defined in Obj. May raise Format_Error if not
-- implemented
function Num_Sections (Obj : Object_File) return uint32;
-- Return the number of sections composing the object file
function Get_Section
(Obj : in out Object_File;
Shnum : uint32) return Object_Section;
-- Return the Nth section (numbered from zero)
function Get_Section
(Obj : in out Object_File;
Sec_Name : String) return Object_Section;
-- Return a section by name
function Create_Stream
(Obj : Object_File;
Sec : Object_Section) return Mapped_Stream;
-- Create a stream for section Sec
procedure Get_Xcode_Bounds
(Obj : in out Object_File;
Low, High : out uint64);
-- Return the low and high addresses of the code for the object file. Can
-- be used to check if an address in within this object file. This
-- procedure is not efficient and the result should be saved to avoid
-- recomputation.
-------------------------
-- Section information --
-------------------------
function Name
(Obj : in out Object_File;
Sec : Object_Section) return String;
-- Return the name of a section as a string
function Size (Sec : Object_Section) return uint64;
-- Return the size of a section in bytes
function Num (Sec : Object_Section) return uint32;
-- Return the index of a section from zero
function Off (Sec : Object_Section) return Offset;
-- Return the byte offset of the section within the object
------------------------------
-- Symbol table information --
------------------------------
Null_Symbol : constant Object_Symbol;
-- An empty symbol table entry.
function First_Symbol (Obj : in out Object_File) return Object_Symbol;
-- Return the first element in the symbol table or Null_Symbol if the
-- symbol table is empty.
function Next_Symbol
(Obj : in out Object_File;
Prev : Object_Symbol) return Object_Symbol;
-- Return the element following Prev in the symbol table, or Null_Symbol if
-- Prev is the last symbol in the table.
function Read_Symbol
(Obj : in out Object_File;
Off : Offset) return Object_Symbol;
-- Read symbol at Off
function Name
(Obj : in out Object_File;
Sym : Object_Symbol) return String_Ptr_Len;
-- Return the name of the symbol
function Decoded_Ada_Name
(Obj : in out Object_File;
Sym : String_Ptr_Len) return String;
-- Return the decoded name of a symbol encoded as per exp_dbug.ads
function Strip_Leading_Char
(Obj : in out Object_File;
Sym : String_Ptr_Len) return Positive;
-- Return the index of the first character to decode the name. This can
-- strip one character for ABI with a prefix (like x86 for PECOFF).
function Value (Sym : Object_Symbol) return uint64;
-- Return the name of the symbol
function Size (Sym : Object_Symbol) return uint64;
-- Return the size of the symbol in bytes
function Spans (Sym : Object_Symbol; Addr : uint64) return Boolean;
-- Determine whether a particular address corresponds to the range
-- referenced by this symbol.
function Off (Sym : Object_Symbol) return Offset;
-- Return the offset of the symbol.
----------------
-- Exceptions --
----------------
IO_Error : exception;
-- Input/Output error reading file
Format_Error : exception;
-- Encountered a problem parsing the object
private
type Mapped_Stream is record
Region : System.Mmap.Mapped_Region;
Off : Offset;
Len : Offset;
end record;
subtype ELF is Object_Format range ELF32 .. ELF64;
subtype Any_PECOFF is Object_Format range PECOFF .. PECOFF_PLUS;
type Object_File (Format : Object_Format) is record
Mf : System.Mmap.Mapped_File :=
System.Mmap.Invalid_Mapped_File;
Arch : Object_Arch := Unknown;
Num_Sections : uint32 := 0;
-- Number of sections
Symtab_Last : Offset; -- Last offset of symbol table
In_Exception : Boolean := False;
-- True if the parsing is done as part of an exception handler
Sectab_Stream : Mapped_Stream;
-- Section table
Symtab_Stream : Mapped_Stream;
-- Symbol table
Symstr_Stream : Mapped_Stream;
-- Symbol strings
case Format is
when ELF =>
Secstr_Stream : Mapped_Stream;
-- Section strings
when Any_PECOFF =>
ImageBase : uint64; -- ImageBase value from header
-- Cache for latest result of Get_Section_Virtual_Address
GSVA_Sec : uint32 := uint32'Last;
GSVA_Addr : uint64;
when XCOFF32 =>
null;
end case;
end record;
subtype ELF_Object_File is Object_File; -- with
-- Predicate => ELF_Object_File.Format in ELF;
subtype PECOFF_Object_File is Object_File; -- with
-- Predicate => PECOFF_Object_File.Format in Any_PECOFF;
subtype XCOFF32_Object_File is Object_File; -- with
-- Predicate => XCOFF32_Object_File.Format in XCOFF32;
-- ???Above predicates cause the compiler to crash when instantiating
-- ELF64_Ops (see package body).
type Object_Section is record
Num : uint32 := 0;
-- Section index in the section table
Off : Offset := 0;
-- First byte of the section in the object file
Addr : uint64 := 0;
-- Load address of the section. Valid only when Flag_Alloc is true.
Size : uint64 := 0;
-- Length of the section in bytes
Flag_Xcode : Boolean := False;
-- True if the section is advertised to contain executable code
end record;
Null_Section : constant Object_Section := (0, 0, 0, 0, False);
type Object_Symbol is record
Off : Offset := 0; -- Offset of underlying symbol on disk
Next : Offset := 0; -- Offset of the following symbol
Value : uint64 := 0; -- Value associated with this symbol
Size : uint64 := 0; -- Size of the referenced entity
end record;
Null_Symbol : constant Object_Symbol := (0, 0, 0, 0);
end System.Object_Reader;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- M D L L --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package provides the core high level routines used by GNATDLL
-- to build Windows DLL.
with Ada.Text_IO;
with GNAT.Directory_Operations;
with MDLL.Utl;
with MDLL.Fil;
package body MDLL is
use Ada;
use GNAT;
-- Convention used for the library names on Windows:
-- DLL: <name>.dll
-- Import library: lib<name>.dll
function Get_Dll_Name (Lib_Filename : String) return String;
-- Returns <Lib_Filename> if it contains a file extension otherwise it
-- returns <Lib_Filename>.dll.
---------------------------
-- Build_Dynamic_Library --
---------------------------
procedure Build_Dynamic_Library
(Ofiles : Argument_List;
Afiles : Argument_List;
Options : Argument_List;
Bargs_Options : Argument_List;
Largs_Options : Argument_List;
Lib_Filename : String;
Def_Filename : String;
Lib_Address : String := "";
Build_Import : Boolean := False;
Relocatable : Boolean := False;
Map_File : Boolean := False)
is
use type OS_Lib.Argument_List;
Base_Filename : constant String := MDLL.Fil.Ext_To (Lib_Filename);
Def_File : aliased constant String := Def_Filename;
Jnk_File : aliased String := Base_Filename & ".jnk";
Bas_File : aliased constant String := Base_Filename & ".base";
Dll_File : aliased String := Get_Dll_Name (Lib_Filename);
Exp_File : aliased String := Base_Filename & ".exp";
Lib_File : aliased constant String := "lib" & Base_Filename & ".dll.a";
Bas_Opt : aliased String := "-Wl,--base-file," & Bas_File;
Lib_Opt : aliased String := "-mdll";
Out_Opt : aliased String := "-o";
Adr_Opt : aliased String := "-Wl,--image-base=" & Lib_Address;
Map_Opt : aliased String := "-Wl,-Map," & Lib_Filename & ".map";
L_Afiles : Argument_List := Afiles;
-- Local afiles list. This list can be reordered to ensure that the
-- binder ALI file is not the first entry in this list.
All_Options : constant Argument_List := Options & Largs_Options;
procedure Build_Reloc_DLL;
-- Build a relocatable DLL with only objects file specified. This uses
-- the well known five step build (see GNAT User's Guide).
procedure Ada_Build_Reloc_DLL;
-- Build a relocatable DLL with Ada code. This uses the well known five
-- step build (see GNAT User's Guide).
procedure Build_Non_Reloc_DLL;
-- Build a non relocatable DLL containing no Ada code
procedure Ada_Build_Non_Reloc_DLL;
-- Build a non relocatable DLL with Ada code
---------------------
-- Build_Reloc_DLL --
---------------------
procedure Build_Reloc_DLL is
Objects_Exp_File : constant OS_Lib.Argument_List :=
Exp_File'Unchecked_Access & Ofiles;
-- Objects plus the export table (.exp) file
Success : Boolean;
pragma Warnings (Off, Success);
begin
if not Quiet then
Text_IO.Put_Line ("building relocatable DLL...");
Text_IO.Put ("make " & Dll_File);
if Build_Import then
Text_IO.Put_Line (" and " & Lib_File);
else
Text_IO.New_Line;
end if;
end if;
-- 1) Build base file with objects files
Utl.Gcc (Output_File => Jnk_File,
Files => Ofiles,
Options => All_Options,
Base_File => Bas_File,
Build_Lib => True);
-- 2) Build exp from base file
Utl.Dlltool (Def_File, Dll_File, Lib_File,
Base_File => Bas_File,
Exp_Table => Exp_File,
Build_Import => False);
-- 3) Build base file with exp file and objects files
Utl.Gcc (Output_File => Jnk_File,
Files => Objects_Exp_File,
Options => All_Options,
Base_File => Bas_File,
Build_Lib => True);
-- 4) Build new exp from base file and the lib file (.a)
Utl.Dlltool (Def_File, Dll_File, Lib_File,
Base_File => Bas_File,
Exp_Table => Exp_File,
Build_Import => Build_Import);
-- 5) Build the dynamic library
declare
Params : constant OS_Lib.Argument_List :=
Map_Opt'Unchecked_Access &
Adr_Opt'Unchecked_Access & All_Options;
First_Param : Positive := Params'First + 1;
begin
if Map_File then
First_Param := Params'First;
end if;
Utl.Gcc
(Output_File => Dll_File,
Files => Objects_Exp_File,
Options => Params (First_Param .. Params'Last),
Build_Lib => True);
end;
OS_Lib.Delete_File (Exp_File, Success);
OS_Lib.Delete_File (Bas_File, Success);
OS_Lib.Delete_File (Jnk_File, Success);
exception
when others =>
OS_Lib.Delete_File (Exp_File, Success);
OS_Lib.Delete_File (Bas_File, Success);
OS_Lib.Delete_File (Jnk_File, Success);
raise;
end Build_Reloc_DLL;
-------------------------
-- Ada_Build_Reloc_DLL --
-------------------------
procedure Ada_Build_Reloc_DLL is
Success : Boolean;
pragma Warnings (Off, Success);
begin
if not Quiet then
Text_IO.Put_Line ("Building relocatable DLL...");
Text_IO.Put ("make " & Dll_File);
if Build_Import then
Text_IO.Put_Line (" and " & Lib_File);
else
Text_IO.New_Line;
end if;
end if;
-- 1) Build base file with objects files
Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
declare
Params : constant OS_Lib.Argument_List :=
Out_Opt'Unchecked_Access &
Jnk_File'Unchecked_Access &
Lib_Opt'Unchecked_Access &
Bas_Opt'Unchecked_Access &
Ofiles &
All_Options;
begin
Utl.Gnatlink (L_Afiles (L_Afiles'Last).all, Params);
end;
-- 2) Build exp from base file
Utl.Dlltool (Def_File, Dll_File, Lib_File,
Base_File => Bas_File,
Exp_Table => Exp_File,
Build_Import => False);
-- 3) Build base file with exp file and objects files
Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
declare
Params : constant OS_Lib.Argument_List :=
Out_Opt'Unchecked_Access &
Jnk_File'Unchecked_Access &
Lib_Opt'Unchecked_Access &
Bas_Opt'Unchecked_Access &
Exp_File'Unchecked_Access &
Ofiles &
All_Options;
begin
Utl.Gnatlink (L_Afiles (L_Afiles'Last).all, Params);
end;
-- 4) Build new exp from base file and the lib file (.a)
Utl.Dlltool (Def_File, Dll_File, Lib_File,
Base_File => Bas_File,
Exp_Table => Exp_File,
Build_Import => Build_Import);
-- 5) Build the dynamic library
Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
declare
Params : constant OS_Lib.Argument_List :=
Map_Opt'Unchecked_Access &
Out_Opt'Unchecked_Access &
Dll_File'Unchecked_Access &
Lib_Opt'Unchecked_Access &
Exp_File'Unchecked_Access &
Adr_Opt'Unchecked_Access &
Ofiles &
All_Options;
First_Param : Positive := Params'First + 1;
begin
if Map_File then
First_Param := Params'First;
end if;
Utl.Gnatlink
(L_Afiles (L_Afiles'Last).all,
Params (First_Param .. Params'Last));
end;
OS_Lib.Delete_File (Exp_File, Success);
OS_Lib.Delete_File (Bas_File, Success);
OS_Lib.Delete_File (Jnk_File, Success);
exception
when others =>
OS_Lib.Delete_File (Exp_File, Success);
OS_Lib.Delete_File (Bas_File, Success);
OS_Lib.Delete_File (Jnk_File, Success);
raise;
end Ada_Build_Reloc_DLL;
-------------------------
-- Build_Non_Reloc_DLL --
-------------------------
procedure Build_Non_Reloc_DLL is
Success : Boolean;
pragma Warnings (Off, Success);
begin
if not Quiet then
Text_IO.Put_Line ("building non relocatable DLL...");
Text_IO.Put ("make " & Dll_File &
" using address " & Lib_Address);
if Build_Import then
Text_IO.Put_Line (" and " & Lib_File);
else
Text_IO.New_Line;
end if;
end if;
-- Build exp table and the lib .a file
Utl.Dlltool (Def_File, Dll_File, Lib_File,
Exp_Table => Exp_File,
Build_Import => Build_Import);
-- Build the DLL
declare
Params : OS_Lib.Argument_List :=
Adr_Opt'Unchecked_Access & All_Options;
begin
if Map_File then
Params := Map_Opt'Unchecked_Access & Params;
end if;
Utl.Gcc (Output_File => Dll_File,
Files => Exp_File'Unchecked_Access & Ofiles,
Options => Params,
Build_Lib => True);
end;
OS_Lib.Delete_File (Exp_File, Success);
exception
when others =>
OS_Lib.Delete_File (Exp_File, Success);
raise;
end Build_Non_Reloc_DLL;
-----------------------------
-- Ada_Build_Non_Reloc_DLL --
-----------------------------
-- Build a non relocatable DLL with Ada code
procedure Ada_Build_Non_Reloc_DLL is
Success : Boolean;
pragma Warnings (Off, Success);
begin
if not Quiet then
Text_IO.Put_Line ("building non relocatable DLL...");
Text_IO.Put ("make " & Dll_File &
" using address " & Lib_Address);
if Build_Import then
Text_IO.Put_Line (" and " & Lib_File);
else
Text_IO.New_Line;
end if;
end if;
-- Build exp table and the lib .a file
Utl.Dlltool (Def_File, Dll_File, Lib_File,
Exp_Table => Exp_File,
Build_Import => Build_Import);
-- Build the DLL
Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
declare
Params : OS_Lib.Argument_List :=
Out_Opt'Unchecked_Access &
Dll_File'Unchecked_Access &
Lib_Opt'Unchecked_Access &
Exp_File'Unchecked_Access &
Adr_Opt'Unchecked_Access &
Ofiles &
All_Options;
begin
if Map_File then
Params := Map_Opt'Unchecked_Access & Params;
end if;
Utl.Gnatlink (L_Afiles (L_Afiles'Last).all, Params);
end;
OS_Lib.Delete_File (Exp_File, Success);
exception
when others =>
OS_Lib.Delete_File (Exp_File, Success);
raise;
end Ada_Build_Non_Reloc_DLL;
-- Start of processing for Build_Dynamic_Library
begin
-- On Windows the binder file must not be in the first position in the
-- list. This is due to the way DLL's are built on Windows. We swap the
-- first ali with the last one if it is the case.
if L_Afiles'Length > 1 then
declare
Filename : constant String :=
Directory_Operations.Base_Name
(L_Afiles (L_Afiles'First).all);
First : constant Positive := Filename'First;
begin
if Filename (First .. First + 1) = "b~" then
L_Afiles (L_Afiles'Last) := Afiles (Afiles'First);
L_Afiles (L_Afiles'First) := Afiles (Afiles'Last);
end if;
end;
end if;
case Relocatable is
when True =>
if L_Afiles'Length = 0 then
Build_Reloc_DLL;
else
Ada_Build_Reloc_DLL;
end if;
when False =>
if L_Afiles'Length = 0 then
Build_Non_Reloc_DLL;
else
Ada_Build_Non_Reloc_DLL;
end if;
end case;
end Build_Dynamic_Library;
--------------------------
-- Build_Import_Library --
--------------------------
procedure Build_Import_Library
(Lib_Filename : String;
Def_Filename : String)
is
procedure Build_Import_Library (Lib_Filename : String);
-- Build an import library. This is to build only a .a library to link
-- against a DLL.
--------------------------
-- Build_Import_Library --
--------------------------
procedure Build_Import_Library (Lib_Filename : String) is
function No_Lib_Prefix (Filename : String) return String;
-- Return Filename without the lib prefix if present
-------------------
-- No_Lib_Prefix --
-------------------
function No_Lib_Prefix (Filename : String) return String is
begin
if Filename (Filename'First .. Filename'First + 2) = "lib" then
return Filename (Filename'First + 3 .. Filename'Last);
else
return Filename;
end if;
end No_Lib_Prefix;
-- Local variables
Def_File : String renames Def_Filename;
Dll_File : constant String := Get_Dll_Name (Lib_Filename);
Base_Filename : constant String :=
MDLL.Fil.Ext_To (No_Lib_Prefix (Lib_Filename));
Lib_File : constant String := "lib" & Base_Filename & ".dll.a";
-- Start of processing for Build_Import_Library
begin
if not Quiet then
Text_IO.Put_Line ("Building import library...");
Text_IO.Put_Line
("make " & Lib_File & " to use dynamic library " & Dll_File);
end if;
Utl.Dlltool
(Def_File, Dll_File, Lib_File, Build_Import => True);
end Build_Import_Library;
-- Start of processing for Build_Import_Library
begin
Build_Import_Library (Lib_Filename);
end Build_Import_Library;
------------------
-- Get_Dll_Name --
------------------
function Get_Dll_Name (Lib_Filename : String) return String is
begin
if MDLL.Fil.Get_Ext (Lib_Filename) = "" then
return Lib_Filename & ".dll";
else
return Lib_Filename;
end if;
end Get_Dll_Name;
end MDLL;
|
package Natools.Smaz_Original_Hash is
pragma Pure;
function Hash (S : String) return Natural;
end Natools.Smaz_Original_Hash;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . S E C O N D A R Y _ S T A C K --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System.Soft_Links;
with System.Parameters;
with Unchecked_Conversion;
with Unchecked_Deallocation;
package body System.Secondary_Stack is
package SSL renames System.Soft_Links;
use type SSE.Storage_Offset;
use type System.Parameters.Size_Type;
SS_Ratio_Dynamic : constant Boolean :=
Parameters.Sec_Stack_Ratio = Parameters.Dynamic;
-- There are two entirely different implementations of the secondary
-- stack mechanism in this unit, and this Boolean is used to select
-- between them (at compile time, so the generated code will contain
-- only the code for the desired variant). If SS_Ratio_Dynamic is
-- True, then the secondary stack is dynamically allocated from the
-- heap in a linked list of chunks. If SS_Ration_Dynamic is False,
-- then the secondary stack is allocated statically by grabbing a
-- section of the primary stack and using it for this purpose.
type Memory is array (SS_Ptr range <>) of SSE.Storage_Element;
for Memory'Alignment use Standard'Maximum_Alignment;
-- This is the type used for actual allocation of secondary stack
-- areas. We require maximum alignment for all such allocations.
---------------------------------------------------------------
-- Data Structures for Dynamically Allocated Secondary Stack --
---------------------------------------------------------------
-- The following is a diagram of the data structures used for the
-- case of a dynamically allocated secondary stack, where the stack
-- is allocated as a linked list of chunks allocated from the heap.
-- +------------------+
-- | Next |
-- +------------------+
-- | | Last (200)
-- | |
-- | |
-- | |
-- | |
-- | |
-- | | First (101)
-- +------------------+
-- +----------> | | |
-- | +----------+-------+
-- | | |
-- | ^ V
-- | | |
-- | +-------+----------+
-- | | | |
-- | +------------------+
-- | | | Last (100)
-- | | C |
-- | | H |
-- +-----------------+ | +-------->| U |
-- | Current_Chunk -|--+ | | N |
-- +-----------------+ | | K |
-- | Top -|-----+ | | First (1)
-- +-----------------+ +------------------+
-- | Default_Size | | Prev |
-- +-----------------+ +------------------+
--
type Chunk_Id (First, Last : SS_Ptr);
type Chunk_Ptr is access all Chunk_Id;
type Chunk_Id (First, Last : SS_Ptr) is record
Prev, Next : Chunk_Ptr;
Mem : Memory (First .. Last);
end record;
type Stack_Id is record
Top : SS_Ptr;
Default_Size : SSE.Storage_Count;
Current_Chunk : Chunk_Ptr;
end record;
type Stack_Ptr is access Stack_Id;
-- Pointer to record used to represent a dynamically allocated secondary
-- stack descriptor for a secondary stack chunk.
procedure Free is new Unchecked_Deallocation (Chunk_Id, Chunk_Ptr);
-- Free a dynamically allocated chunk
function To_Stack_Ptr is new
Unchecked_Conversion (Address, Stack_Ptr);
function To_Addr is new
Unchecked_Conversion (Stack_Ptr, Address);
-- Convert to and from address stored in task data structures
--------------------------------------------------------------
-- Data Structures for Statically Allocated Secondary Stack --
--------------------------------------------------------------
-- For the static case, the secondary stack is a single contiguous
-- chunk of storage, carved out of the primary stack, and represented
-- by the following data strcuture
type Fixed_Stack_Id is record
Top : SS_Ptr;
-- Index of next available location in Mem. This is initialized to
-- 0, and then incremented on Allocate, and Decremented on Release.
Last : SS_Ptr;
-- Length of usable Mem array, which is thus the index past the
-- last available location in Mem. Mem (Last-1) can be used. This
-- is used to check that the stack does not overflow.
Max : SS_Ptr;
-- Maximum value of Top. Initialized to 0, and then may be incremented
-- on Allocate, but is never Decremented. The last used location will
-- be Mem (Max - 1), so Max is the maximum count of used stack space.
Mem : Memory (0 .. 0);
-- This is the area that is actually used for the secondary stack.
-- Note that the upper bound is a dummy value properly defined by
-- the value of Last. We never actually allocate objects of type
-- Fixed_Stack_Id, so the bounds declared here do not matter.
end record;
Dummy_Fixed_Stack : Fixed_Stack_Id;
pragma Warnings (Off, Dummy_Fixed_Stack);
-- Well it is not quite true that we never allocate an object of the
-- type. This dummy object is allocated for the purpose of getting the
-- offset of the Mem field via the 'Position attribute (such a nuisance
-- that we cannot apply this to a field of a type!)
type Fixed_Stack_Ptr is access Fixed_Stack_Id;
-- Pointer to record used to describe statically allocated sec stack
function To_Fixed_Stack_Ptr is new
Unchecked_Conversion (Address, Fixed_Stack_Ptr);
-- Convert from address stored in task data structures
--------------
-- Allocate --
--------------
procedure SS_Allocate
(Addr : out Address;
Storage_Size : SSE.Storage_Count)
is
Max_Align : constant SS_Ptr := SS_Ptr (Standard'Maximum_Alignment);
Max_Size : constant SS_Ptr :=
((SS_Ptr (Storage_Size) + Max_Align - 1) / Max_Align)
* Max_Align;
begin
-- Case of fixed allocation secondary stack
if not SS_Ratio_Dynamic then
declare
Fixed_Stack : constant Fixed_Stack_Ptr :=
To_Fixed_Stack_Ptr (SSL.Get_Sec_Stack_Addr.all);
begin
-- Check if max stack usage is increasing
if Fixed_Stack.Top + Max_Size > Fixed_Stack.Max then
-- If so, check if max size is exceeded
if Fixed_Stack.Top + Max_Size > Fixed_Stack.Last then
raise Storage_Error;
end if;
-- Record new max usage
Fixed_Stack.Max := Fixed_Stack.Top + Max_Size;
end if;
-- Set resulting address and update top of stack pointer
Addr := Fixed_Stack.Mem (Fixed_Stack.Top)'Address;
Fixed_Stack.Top := Fixed_Stack.Top + Max_Size;
end;
-- Case of dynamically allocated secondary stack
else
declare
Stack : constant Stack_Ptr :=
To_Stack_Ptr (SSL.Get_Sec_Stack_Addr.all);
Chunk : Chunk_Ptr;
To_Be_Released_Chunk : Chunk_Ptr;
begin
Chunk := Stack.Current_Chunk;
-- The Current_Chunk may not be the good one if a lot of release
-- operations have taken place. So go down the stack if necessary
while Chunk.First > Stack.Top loop
Chunk := Chunk.Prev;
end loop;
-- Find out if the available memory in the current chunk is
-- sufficient, if not, go to the next one and eventally create
-- the necessary room.
while Chunk.Last - Stack.Top + 1 < Max_Size loop
if Chunk.Next /= null then
-- Release unused non-first empty chunk
if Chunk.Prev /= null and then Chunk.First = Stack.Top then
To_Be_Released_Chunk := Chunk;
Chunk := Chunk.Prev;
Chunk.Next := To_Be_Released_Chunk.Next;
To_Be_Released_Chunk.Next.Prev := Chunk;
Free (To_Be_Released_Chunk);
end if;
-- Create new chunk of default size unless it is not
-- sufficient to satisfy the current request.
elsif SSE.Storage_Count (Max_Size) <= Stack.Default_Size then
Chunk.Next :=
new Chunk_Id
(First => Chunk.Last + 1,
Last => Chunk.Last + SS_Ptr (Stack.Default_Size));
Chunk.Next.Prev := Chunk;
-- Otherwise create new chunk of requested size
else
Chunk.Next :=
new Chunk_Id
(First => Chunk.Last + 1,
Last => Chunk.Last + Max_Size);
Chunk.Next.Prev := Chunk;
end if;
Chunk := Chunk.Next;
Stack.Top := Chunk.First;
end loop;
-- Resulting address is the address pointed by Stack.Top
Addr := Chunk.Mem (Stack.Top)'Address;
Stack.Top := Stack.Top + Max_Size;
Stack.Current_Chunk := Chunk;
end;
end if;
end SS_Allocate;
-------------
-- SS_Free --
-------------
procedure SS_Free (Stk : in out Address) is
begin
-- Case of statically allocated secondary stack, nothing to free
if not SS_Ratio_Dynamic then
return;
-- Case of dynamically allocated secondary stack
else
declare
Stack : Stack_Ptr := To_Stack_Ptr (Stk);
Chunk : Chunk_Ptr;
procedure Free is new Unchecked_Deallocation (Stack_Id, Stack_Ptr);
begin
Chunk := Stack.Current_Chunk;
while Chunk.Prev /= null loop
Chunk := Chunk.Prev;
end loop;
while Chunk.Next /= null loop
Chunk := Chunk.Next;
Free (Chunk.Prev);
end loop;
Free (Chunk);
Free (Stack);
Stk := Null_Address;
end;
end if;
end SS_Free;
----------------
-- SS_Get_Max --
----------------
function SS_Get_Max return Long_Long_Integer is
begin
if SS_Ratio_Dynamic then
return -1;
else
declare
Fixed_Stack : constant Fixed_Stack_Ptr :=
To_Fixed_Stack_Ptr (SSL.Get_Sec_Stack_Addr.all);
begin
return Long_Long_Integer (Fixed_Stack.Max);
end;
end if;
end SS_Get_Max;
-------------
-- SS_Info --
-------------
procedure SS_Info is
begin
Put_Line ("Secondary Stack information:");
-- Case of fixed secondary stack
if not SS_Ratio_Dynamic then
declare
Fixed_Stack : constant Fixed_Stack_Ptr :=
To_Fixed_Stack_Ptr (SSL.Get_Sec_Stack_Addr.all);
begin
Put_Line (
" Total size : "
& SS_Ptr'Image (Fixed_Stack.Last)
& " bytes");
Put_Line (
" Current allocated space : "
& SS_Ptr'Image (Fixed_Stack.Top - 1)
& " bytes");
end;
-- Case of dynamically allocated secondary stack
else
declare
Stack : constant Stack_Ptr :=
To_Stack_Ptr (SSL.Get_Sec_Stack_Addr.all);
Nb_Chunks : Integer := 1;
Chunk : Chunk_Ptr := Stack.Current_Chunk;
begin
while Chunk.Prev /= null loop
Chunk := Chunk.Prev;
end loop;
while Chunk.Next /= null loop
Nb_Chunks := Nb_Chunks + 1;
Chunk := Chunk.Next;
end loop;
-- Current Chunk information
Put_Line (
" Total size : "
& SS_Ptr'Image (Chunk.Last)
& " bytes");
Put_Line (
" Current allocated space : "
& SS_Ptr'Image (Stack.Top - 1)
& " bytes");
Put_Line (
" Number of Chunks : "
& Integer'Image (Nb_Chunks));
Put_Line (
" Default size of Chunks : "
& SSE.Storage_Count'Image (Stack.Default_Size));
end;
end if;
end SS_Info;
-------------
-- SS_Init --
-------------
procedure SS_Init
(Stk : in out Address;
Size : Natural := Default_Secondary_Stack_Size)
is
begin
-- Case of fixed size secondary stack
if not SS_Ratio_Dynamic then
declare
Fixed_Stack : constant Fixed_Stack_Ptr :=
To_Fixed_Stack_Ptr (Stk);
begin
Fixed_Stack.Top := 0;
Fixed_Stack.Max := 0;
if Size < Dummy_Fixed_Stack.Mem'Position then
Fixed_Stack.Last := 0;
else
Fixed_Stack.Last :=
SS_Ptr (Size) - Dummy_Fixed_Stack.Mem'Position;
end if;
end;
-- Case of dynamically allocated secondary stack
else
declare
Stack : Stack_Ptr;
begin
Stack := new Stack_Id;
Stack.Current_Chunk := new Chunk_Id (1, SS_Ptr (Size));
Stack.Top := 1;
Stack.Default_Size := SSE.Storage_Count (Size);
Stk := To_Addr (Stack);
end;
end if;
end SS_Init;
-------------
-- SS_Mark --
-------------
function SS_Mark return Mark_Id is
Sstk : constant System.Address := SSL.Get_Sec_Stack_Addr.all;
begin
if SS_Ratio_Dynamic then
return (Sstk => Sstk, Sptr => To_Stack_Ptr (Sstk).Top);
else
return (Sstk => Sstk, Sptr => To_Fixed_Stack_Ptr (Sstk).Top);
end if;
end SS_Mark;
----------------
-- SS_Release --
----------------
procedure SS_Release (M : Mark_Id) is
begin
if SS_Ratio_Dynamic then
To_Stack_Ptr (M.Sstk).Top := M.Sptr;
else
To_Fixed_Stack_Ptr (M.Sstk).Top := M.Sptr;
end if;
end SS_Release;
-------------------------
-- Package Elaboration --
-------------------------
-- Allocate a secondary stack for the main program to use
-- We make sure that the stack has maximum alignment. Some systems require
-- this (e.g. Sun), and in any case it is a good idea for efficiency.
Stack : aliased Stack_Id;
for Stack'Alignment use Standard'Maximum_Alignment;
Chunk : aliased Chunk_Id (1, SS_Ptr (Default_Secondary_Stack_Size));
for Chunk'Alignment use Standard'Maximum_Alignment;
Chunk_Address : Address;
begin
if SS_Ratio_Dynamic then
Stack.Top := 1;
Stack.Current_Chunk := Chunk'Access;
Stack.Default_Size := SSE.Storage_Offset (Default_Secondary_Stack_Size);
System.Soft_Links.Set_Sec_Stack_Addr_NT (Stack'Address);
else
Chunk_Address := Chunk'Address;
SS_Init (Chunk_Address, Default_Secondary_Stack_Size);
System.Soft_Links.Set_Sec_Stack_Addr_NT (Chunk_Address);
end if;
end System.Secondary_Stack;
|
-- Abstract :
--
-- See spec.
--
-- Copyright (C) 2002, 2003, 2008, 2009, 2012 - 2015, 2017 - 2020 Free Software Foundation, Inc.
--
-- This file is part of the WisiToken package.
--
-- The WisiToken package is free software; you can redistribute it
-- and/or modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; either version 3, or
-- (at your option) any later version. The WisiToken package 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 distributed with the WisiToken package;
-- see file GPL.txt. If not, write to the Free Software Foundation,
-- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
--
-- As a special exception, if other files instantiate generics from
-- this unit, or you link this unit with other files to produce an
-- executable, this unit does not by itself cause the resulting
-- executable to be covered by the GNU General Public License. This
-- exception does not however invalidate any other reasons why the
-- executable file might be covered by the GNU Public License.
pragma License (Modified_GPL);
with Ada.Text_IO;
with Ada.Strings.Unbounded;
package body WisiToken.Generate.LR1_Items is
use type Ada.Strings.Unbounded.Unbounded_String;
----------
-- body subprograms
function Get_Dot_IDs
(Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Set : in Item_Lists.List;
Descriptor : in WisiToken.Descriptor)
return Token_ID_Arrays.Vector
is
use Item_Lists;
IDs : Token_ID_Set (Descriptor.First_Terminal .. Descriptor.Last_Nonterminal) := (others => False);
begin
for Item of Set loop
declare
use Token_ID_Arrays;
Dot : constant Token_ID_Arrays.Cursor :=
WisiToken.Productions.Constant_Ref_RHS (Grammar, Item.Prod).Tokens.To_Cursor (Item.Dot);
begin
if Has_Element (Dot) then
if Element (Dot) /= Descriptor.EOI_ID then
IDs (Element (Dot)) := True;
end if;
end if;
end;
end loop;
return To_Array (IDs);
end Get_Dot_IDs;
function Merge
(Prod : in Production_ID;
Dot : in Token_ID_Arrays.Extended_Index;
Lookaheads : in Lookahead;
Existing_Set : in out Item_Set)
return Boolean
is
-- Merge item into Existing_Set. Return True if Existing_Set
-- is modified.
use Item_Lists;
Found : constant Item_Lists.Cursor := Find (Prod, Dot, Existing_Set);
Modified : Boolean := False;
begin
if not Has_Element (Found) then
Existing_Set.Set.Insert ((Prod, Dot, new Token_ID_Set'(Lookaheads)));
Modified := True;
else
Include (Variable_Ref (Found), Lookaheads, Modified);
end if;
return Modified;
end Merge;
----------
-- Public subprograms, declaration order
function To_Lookahead (Item : in Token_ID; Descriptor : in WisiToken.Descriptor) return Lookahead
is begin
return Result : Token_ID_Set := (Descriptor.First_Terminal .. Descriptor.Last_Lookahead => False) do
Result (Item) := True;
end return;
end To_Lookahead;
function Lookahead_Image (Item : in Lookahead; Descriptor : in WisiToken.Descriptor) return String
is
use Ada.Strings.Unbounded;
Result : Unbounded_String := Null_Unbounded_String;
begin
for I in Item'Range loop
if Item (I) then
if Length (Result) > 0 then
Result := Result & "/";
end if;
Result := Result & Image (I, Descriptor);
end if;
end loop;
return To_String (Result);
end Lookahead_Image;
function Item_Compare (Left, Right : in Item) return SAL.Compare_Result
is (if Left.Prod.LHS > Right.Prod.LHS then SAL.Greater
elsif Left.Prod.LHS < Right.Prod.LHS then SAL.Less
elsif Left.Prod.RHS > Right.Prod.RHS then SAL.Greater
elsif Left.Prod.RHS < Right.Prod.RHS then SAL.Less
elsif Left.Dot > Right.Dot then SAL.Greater
elsif Left.Dot < Right.Dot then SAL.Less
else SAL.Equal);
procedure Include
(Item : in out LR1_Items.Item;
Value : in Lookahead;
Added : out Boolean)
is begin
Added := False;
for I in Item.Lookaheads'Range loop
if Value (I) then
Added := Added or not Item.Lookaheads (I);
Item.Lookaheads (I) := True;
end if;
end loop;
end Include;
procedure Include
(Item : in out LR1_Items.Item;
Value : in Lookahead;
Descriptor : in WisiToken.Descriptor)
is
Added : Boolean;
pragma Unreferenced (Added);
begin
Include (Item, Value, Added, Descriptor);
end Include;
procedure Include
(Item : in out LR1_Items.Item;
Value : in Lookahead;
Added : out Boolean;
Descriptor : in WisiToken.Descriptor)
is begin
Added := False;
for I in Item.Lookaheads'Range loop
if I = Descriptor.Last_Lookahead then
null;
else
if Value (I) then
Added := Added or not Item.Lookaheads (I);
Item.Lookaheads (I) := True;
end if;
end if;
end loop;
end Include;
function Filter
(Set : in Item_Set;
Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Descriptor : in WisiToken.Descriptor;
Include : access function
(Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Descriptor : in WisiToken.Descriptor;
Item : in LR1_Items.Item)
return Boolean)
return Item_Set
is begin
return Result : Item_Set := (Set => <>, Goto_List => Set.Goto_List, Dot_IDs => Set.Dot_IDs, State => Set.State)
do
for Item of Set.Set loop
if Include (Grammar, Descriptor, Item) then
Result.Set.Insert (Item);
end if;
end loop;
end return;
end Filter;
function In_Kernel
(Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Descriptor : in WisiToken.Descriptor;
Item : in LR1_Items.Item)
return Boolean
is
use all type Ada.Containers.Count_Type;
use Token_ID_Arrays;
Prod : WisiToken.Productions.Instance renames Grammar (Item.Prod.LHS);
RHS : WisiToken.Productions.Right_Hand_Side renames Prod.RHSs (Item.Prod.RHS);
begin
return
RHS.Tokens.Length > 0 and
(Item.Dot = No_Index or else
((Prod.LHS = Descriptor.Accept_ID and
Item.Dot = RHS.Tokens.First_Index)
-- Start symbol production with dot before first token.
or
Item.Dot /= RHS.Tokens.First_Index));
end In_Kernel;
function Find
(Item : in LR1_Items.Item;
Set : in Item_Set)
return Item_Lists.Cursor
is begin
return Find (Item.Prod, Item.Dot, Set);
end Find;
function Find
(Prod : in Production_ID;
Dot : in Token_ID_Arrays.Extended_Index;
Set : in Item_Set)
return Item_Lists.Cursor
is begin
return Set.Set.Find ((Prod, Dot, null));
end Find;
function To_Item_Set_Tree_Key
(Item_Set : in LR1_Items.Item_Set;
Include_Lookaheads : in Boolean)
return Item_Set_Tree_Key
is
use Interfaces;
use Item_Lists;
Cur : Item_Lists.Cursor := Item_Set.Set.First;
begin
return Result : Item_Set_Tree_Key do
Result.Append (Integer_16 (Item_Set.Set.Length));
-- Int_Arrays."<" compares length, but only after everything else; we
-- want it to compare first, since it is most likely to be different.
loop
exit when not Has_Element (Cur);
declare
Item_1 : Item renames Item_Set.Set (Cur);
begin
Result.Append (Integer_16 (Item_1.Prod.LHS));
Result.Append (Integer_16 (Item_1.Prod.RHS));
Result.Append (Integer_16 (Item_1.Dot));
if Include_Lookaheads then
for ID in Item_1.Lookaheads'Range loop
if Item_1.Lookaheads (ID) then
Result.Append (Integer_16 (ID));
end if;
end loop;
end if;
end;
Next (Cur);
end loop;
end return;
end To_Item_Set_Tree_Key;
function Find
(New_Item_Set : in Item_Set;
Item_Set_Tree : in Item_Set_Trees.Tree;
Match_Lookaheads : in Boolean)
return Unknown_State_Index
is
use all type Item_Set_Trees.Cursor;
Tree_It : constant Item_Set_Trees.Iterator := Item_Set_Trees.Iterate (Item_Set_Tree);
Key : constant Item_Set_Tree_Key := To_Item_Set_Tree_Key
(New_Item_Set, Include_Lookaheads => Match_Lookaheads);
Found_Tree : constant Item_Set_Trees.Cursor := Tree_It.Find (Key);
begin
if Found_Tree = Item_Set_Trees.No_Element then
return Unknown_State;
else
return Item_Set_Tree (Found_Tree).State;
end if;
end Find;
procedure Add
(Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
New_Item_Set : in Item_Set;
Item_Set_Vector : in out Item_Set_List;
Item_Set_Tree : in out Item_Set_Trees.Tree;
Descriptor : in WisiToken.Descriptor;
Include_Lookaheads : in Boolean)
is
use Item_Set_Trees;
Key : constant Item_Set_Tree_Key := To_Item_Set_Tree_Key (New_Item_Set, Include_Lookaheads);
begin
Item_Set_Vector.Append (New_Item_Set);
Item_Set_Vector (Item_Set_Vector.Last_Index).Dot_IDs := Get_Dot_IDs (Grammar, New_Item_Set.Set, Descriptor);
Item_Set_Tree.Insert ((Key, New_Item_Set.State));
end Add;
function Is_In
(Item : in Goto_Item;
Goto_List : in Goto_Item_Lists.List)
return Boolean
is begin
for List_Item of Goto_List loop
if List_Item = Item then
return True;
end if;
end loop;
return False;
end Is_In;
function Goto_State
(From : in Item_Set;
Symbol : in Token_ID)
return Unknown_State_Index
is begin
for Item of From.Goto_List loop
if Item.Symbol = Symbol then
return Item.State;
end if;
end loop;
return Unknown_State;
end Goto_State;
function Closure
(Set : in Item_Set;
Has_Empty_Production : in Token_ID_Set;
First_Terminal_Sequence : in Token_Sequence_Arrays.Vector;
Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Descriptor : in WisiToken.Descriptor)
return Item_Set
is
use all type Item_Lists.Cursor;
use Token_ID_Arrays;
-- [dragon] algorithm 4.9 pg 231; figure 4.38 pg 232; procedure "closure"
--
-- Taken literally, the algorithm modifies its input; we make a
-- copy instead.
I : Item_Set := Set; -- The result.
Item_I : Item_Lists.Cursor := I.Set.First; -- iterator 'for each item in I'
Added_Item : Boolean := False; -- 'until no more items can be added'
begin
loop
declare
Item : LR1_Items.Item renames I.Set (Item_I);
Dot : constant Token_ID_Arrays.Cursor :=
WisiToken.Productions.Constant_Ref_RHS (Grammar, Item.Prod).Tokens.To_Cursor (Item.Dot);
begin
-- An item has the structure [A -> alpha Dot B Beta, a].
--
-- If B is a nonterminal, find its productions and place
-- them in the set with lookaheads from FIRST(Beta a).
if Has_Element (Dot) and then
Element (Dot) in Descriptor.First_Nonterminal .. Descriptor.Last_Nonterminal
then
declare
Prod : WisiToken.Productions.Instance renames Grammar (Element (Dot));
begin
For_Each_RHS :
for J in Prod.RHSs.First_Index .. Prod.RHSs.Last_Index loop
declare
RHS : WisiToken.Productions.Right_Hand_Side renames Prod.RHSs (J);
P_ID : constant Production_ID := (Prod.LHS, J);
Beta : Token_ID_Arrays.Cursor := Next (Dot); -- tokens after nonterminal, possibly null
begin
-- Compute FIRST (<tail of right hand side> a); loop
-- until find a terminal, a nonterminal that
-- cannot be empty, or end of production, adding
-- items on the way.
First_Tail :
loop
if not Has_Element (Beta) then
-- Use FIRST (a); a = Item.Lookaheads.
-- Lookaheads are all terminals, so
-- FIRST (a) = a.
Added_Item := Added_Item or
Merge (P_ID, To_Index (RHS.Tokens.First), Item.Lookaheads.all, I);
exit First_Tail;
elsif Element (Beta) in Descriptor.First_Terminal .. Descriptor.Last_Terminal then
-- FIRST (Beta) = Beta
Added_Item := Added_Item or Merge
(P_ID, To_Index (RHS.Tokens.First), To_Lookahead (Element (Beta), Descriptor), I);
exit First_Tail;
else
-- Beta is a nonterminal; use FIRST (Beta)
for Terminal of First_Terminal_Sequence (Element (Beta)) loop
Added_Item := Added_Item or
Merge (P_ID, To_Index (RHS.Tokens.First), To_Lookahead (Terminal, Descriptor), I);
end loop;
if Has_Empty_Production (Element (Beta)) then
-- Process the next token in the tail, or "a"
Beta := Next (Beta);
else
exit First_Tail;
end if;
end if;
end loop First_Tail;
end;
end loop For_Each_RHS;
end;
end if; -- Dot is at non-terminal
end;
if not Has_Element (Item_Lists.Next (Item_I)) then
exit when not Added_Item;
Item_I := I.Set.First;
Added_Item := False;
if Trace_Generate_Table > Extra then
Ada.Text_IO.Put_Line (" closure:");
Put (Grammar, Descriptor, I);
end if;
else
Item_I := Item_Lists.Next (Item_I);
end if;
end loop;
return I;
end Closure;
function Productions (Set : in Item_Set) return Production_ID_Arrays.Vector
is begin
return Result : Production_ID_Arrays.Vector do
for Item of Set.Set loop
Result.Append (Item.Prod);
end loop;
end return;
end Productions;
function Image
(Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Descriptor : in WisiToken.Descriptor;
Item : in LR1_Items.Item;
Show_Lookaheads : in Boolean)
return String
is
use Token_ID_Arrays;
Prod : WisiToken.Productions.Instance renames Grammar (Item.Prod.LHS);
RHS : WisiToken.Productions.Right_Hand_Side renames Prod.RHSs (Item.Prod.RHS);
Result : Ada.Strings.Unbounded.Unbounded_String :=
+Padded_Image (Item.Prod, Width => Prod_ID_Image_Width) & ":" & Image (Prod.LHS, Descriptor) & " <=";
I : Cursor := RHS.Tokens.First;
begin
while Has_Element (I) loop
if To_Index (I) = Item.Dot then
Result := Result & " ^ ";
else
Result := Result & " ";
end if;
Result := Result & Image (Element (I), Descriptor);
Next (I);
end loop;
if Item.Dot = No_Index then
Result := Result & " ^";
end if;
if Show_Lookaheads then
Result := Result & ", " & Lookahead_Image (Item.Lookaheads.all, Descriptor);
end if;
return Ada.Strings.Unbounded.To_String (Result);
end Image;
procedure Put
(Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Descriptor : in WisiToken.Descriptor;
Item : in LR1_Items.Item;
Show_Lookaheads : in Boolean := True)
is begin
Ada.Text_IO.Put (Image (Grammar, Descriptor, Item, Show_Lookaheads => Show_Lookaheads));
end Put;
procedure Put
(Descriptor : in WisiToken.Descriptor;
List : in Goto_Item_Lists.List)
is
use Ada.Text_IO;
begin
for Item of List loop
Put_Line
(" on " & Image (Item.Symbol, Descriptor) &
" => State" & Unknown_State_Index'Image (Item.State));
end loop;
end Put;
procedure Put
(Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Descriptor : in WisiToken.Descriptor;
Item : in Item_Lists.List;
Show_Lookaheads : in Boolean := True;
Kernel_Only : in Boolean := False)
is begin
for It of Item loop
if not Kernel_Only or else
In_Kernel (Grammar, Descriptor, It)
then
Ada.Text_IO.Put_Line
(" " & Image (Grammar, Descriptor, It, Show_Lookaheads => Show_Lookaheads));
end if;
end loop;
end Put;
procedure Put
(Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Descriptor : in WisiToken.Descriptor;
Item : in Item_Set;
Show_Lookaheads : in Boolean := True;
Kernel_Only : in Boolean := False;
Show_Goto_List : in Boolean := False)
is
use Ada.Text_IO;
begin
if Item.State /= Unknown_State then
Put_Line ("State" & Unknown_State_Index'Image (Item.State) & ":");
end if;
Put (Grammar, Descriptor, Item.Set, Show_Lookaheads, Kernel_Only);
if Show_Goto_List then
Put (Descriptor, Item.Goto_List);
end if;
end Put;
procedure Put
(Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Descriptor : in WisiToken.Descriptor;
Item : in Item_Set_List;
Show_Lookaheads : in Boolean := True)
is
use Ada.Text_IO;
begin
for Set of Item loop
Put (Grammar, Descriptor, Set, Show_Lookaheads);
Put_Line (" Goto:");
Put (Descriptor, Set.Goto_List);
end loop;
end Put;
end WisiToken.Generate.LR1_Items;
|
-- CC3123A.ADA
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
-- CHECK THAT DEFAULT EXPRESSIONS FOR GENERIC IN PARAMETERS ARE ONLY
-- EVALUATED IF THERE ARE NO ACTUAL PARAMETERS.
-- TBN 12/01/86
WITH REPORT; USE REPORT;
PROCEDURE CC3123A IS
BEGIN
TEST ("CC3123A", "CHECK THAT DEFAULT EXPRESSIONS FOR GENERIC IN " &
"PARAMETERS ARE ONLY EVALUATED IF THERE ARE " &
"NO ACTUAL PARAMETERS");
DECLARE
TYPE ENUM IS (I, II, III);
OBJ_INT : INTEGER := 1;
OBJ_ENUM : ENUM := I;
GENERIC
GEN_INT : IN INTEGER := IDENT_INT(2);
GEN_BOOL : IN BOOLEAN := IDENT_BOOL(FALSE);
GEN_ENUM : IN ENUM := II;
PACKAGE P IS
PAC_INT : INTEGER := GEN_INT;
PAC_BOOL : BOOLEAN := GEN_BOOL;
PAC_ENUM : ENUM := GEN_ENUM;
END P;
PACKAGE P1 IS NEW P;
PACKAGE P2 IS
NEW P (IDENT_INT(OBJ_INT), GEN_ENUM => OBJ_ENUM);
PACKAGE P3 IS NEW P (GEN_BOOL => IDENT_BOOL(TRUE));
BEGIN
IF P1.PAC_INT /= 2 OR P1.PAC_BOOL OR P1.PAC_ENUM /= II THEN
FAILED ("DEFAULT VALUES WERE NOT EVALUATED");
END IF;
IF P2.PAC_INT /= 1 OR P2.PAC_BOOL OR P2.PAC_ENUM /= I THEN
FAILED ("DEFAULT VALUES WERE NOT EVALUATED CORRECTLY " &
"- 1");
END IF;
IF P3.PAC_INT /= 2 OR NOT(P3.PAC_BOOL) OR
P3.PAC_ENUM /= II THEN
FAILED ("DEFAULT VALUES WERE NOT EVALUATED CORRECTLY " &
"- 2");
END IF;
END;
-------------------------------------------------------------------
DECLARE
OBJ_INT1 : INTEGER := 3;
FUNCTION FUNC (X : INTEGER) RETURN INTEGER;
GENERIC
GEN_INT1 : IN INTEGER := FUNC (1);
GEN_INT2 : IN INTEGER := FUNC (GEN_INT1 + 1);
PROCEDURE PROC;
PROCEDURE PROC IS
PROC_INT1 : INTEGER := GEN_INT1;
PROC_INT2 : INTEGER := GEN_INT2;
BEGIN
IF PROC_INT1 /= 3 THEN
FAILED ("DEFAULT VALUES WERE NOT EVALUATED " &
"CORRECTLY - 3");
END IF;
IF PROC_INT2 /= 4 THEN
FAILED ("DEFAULT VALUES WERE NOT EVALUATED " &
"CORRECTLY - 4");
END IF;
END PROC;
FUNCTION FUNC (X : INTEGER) RETURN INTEGER IS
BEGIN
IF X /= IDENT_INT(4) THEN
FAILED ("DEFAULT VALUES WERE NOT EVALUATED " &
"CORRECTLY - 5");
END IF;
RETURN IDENT_INT(X);
END FUNC;
PROCEDURE NEW_PROC IS NEW PROC (GEN_INT1 => OBJ_INT1);
BEGIN
NEW_PROC;
END;
-------------------------------------------------------------------
DECLARE
TYPE ARA_TYP IS ARRAY (1 .. 2) OF INTEGER;
TYPE REC IS
RECORD
ANS : BOOLEAN;
ARA : ARA_TYP;
END RECORD;
TYPE ARA_REC IS ARRAY (1 .. 5) OF REC;
FUNCTION F (X : INTEGER) RETURN INTEGER;
OBJ_REC : REC := (FALSE, (3, 4));
OBJ_ARA : ARA_REC := (1 .. 5 => (FALSE, (3, 4)));
GENERIC
GEN_OBJ1 : IN ARA_TYP := (F(1), 2);
GEN_OBJ2 : IN REC := (TRUE, GEN_OBJ1);
GEN_OBJ3 : IN ARA_REC := (1 .. F(5) => (TRUE, (1, 2)));
FUNCTION FUNC RETURN INTEGER;
FUNCTION FUNC RETURN INTEGER IS
BEGIN
RETURN IDENT_INT(1);
END FUNC;
FUNCTION F (X : INTEGER) RETURN INTEGER IS
BEGIN
FAILED ("DEFAULT VALUES WERE EVALUATED - 1");
RETURN IDENT_INT(X);
END F;
FUNCTION NEW_FUNC IS NEW FUNC ((3, 4), OBJ_REC, OBJ_ARA);
BEGIN
IF NOT EQUAL (NEW_FUNC, 1) THEN
FAILED ("INCORRECT RESULT FROM GENERIC FUNCTION - 1");
END IF;
END;
-------------------------------------------------------------------
DECLARE
SUBTYPE INT IS INTEGER RANGE 1 .. 5;
TYPE ARA_TYP IS ARRAY (1 .. 2) OF INTEGER;
TYPE COLOR IS (RED, WHITE);
TYPE CON_REC (D : INT) IS
RECORD
A : COLOR;
B : ARA_TYP;
END RECORD;
TYPE UNCON_OR_CON_REC (D : INT := 2) IS
RECORD
A : COLOR;
B : ARA_TYP;
END RECORD;
FUNCTION F (X : COLOR) RETURN COLOR;
OBJ_CON1 : CON_REC (1) := (1, WHITE, (3, 4));
OBJ_UNCON : UNCON_OR_CON_REC := (2, WHITE, (3, 4));
OBJ_CON2 : UNCON_OR_CON_REC (3) := (3, WHITE, (3, 4));
GENERIC
GEN_CON1 : IN CON_REC := (2, F(RED), (1, 2));
GEN_UNCON : IN UNCON_OR_CON_REC := (2, F(RED), (1, 2));
GEN_CON2 : IN UNCON_OR_CON_REC := GEN_UNCON;
FUNCTION FUNC RETURN INTEGER;
FUNCTION FUNC RETURN INTEGER IS
BEGIN
RETURN IDENT_INT(1);
END FUNC;
FUNCTION F (X : COLOR) RETURN COLOR IS
BEGIN
FAILED ("DEFAULT VALUES WERE EVALUATED - 2");
RETURN WHITE;
END F;
FUNCTION NEW_FUNC IS NEW FUNC (OBJ_CON1, OBJ_UNCON, OBJ_CON2);
BEGIN
IF NOT EQUAL (NEW_FUNC, 1) THEN
FAILED ("INCORRECT RESULT FROM GENERIC FUNCTION - 2");
END IF;
END;
RESULT;
END CC3123A;
|
package body File_IO with SPARK_Mode => Off is
use all type Ada.Text_IO.File_Type;
function Open_Status (File : File_Type) return Open_Result is
begin
if Is_Open (File.Value) then
return File_Open;
else
return File_Closed;
end if;
exception
when others =>
return Open_Error;
end Open_Status;
procedure Open_Input_File (Name : String;
File : in out File_Type;
Is_Success : out Boolean) is
begin
Open (File => File.Value,
Mode => Ada.Text_IO.In_File,
Name => Name);
Is_Success := True;
exception
when others =>
Is_Success := False;
end Open_Input_File;
procedure Close (File : in out File_Type;
Is_Success : out Boolean) is
begin
Close (File.Value);
Is_Success := True;
exception
when others =>
Is_Success := False;
end Close;
function End_Of_File (File : File_Type) return EOF_Result is
begin
if End_Of_Line (File.Value) then
return End_Reached;
else
return More_Data_Exists;
end if;
exception
when others =>
return EOF_Error;
end End_Of_File;
function Read_Line (File : File_Type) return Read_Result is
begin
declare
Line : constant String := Get_Line (File.Value);
begin
return (Is_Success => True, Last => Line'Last, Text => Line);
end;
exception
when others =>
return (Is_Success => False, Last => 0, Text => (others => ' '));
end Read_Line;
end File_IO;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../../License.txt
package body AdaBase.Statement.Base.SQLite is
-------------------
-- log_problem --
-------------------
procedure log_problem
(statement : SQLite_statement;
category : Log_Category;
message : String;
pull_codes : Boolean := False;
break : Boolean := False)
is
error_msg : CT.Text := CT.blank;
error_code : Driver_Codes := 0;
sqlstate : SQL_State := stateless;
begin
if pull_codes then
error_msg := CT.SUS (statement.last_driver_message);
error_code := statement.last_driver_code;
sqlstate := statement.last_sql_state;
end if;
logger_access.all.log_problem
(driver => statement.dialect,
category => category,
message => CT.SUS (message),
error_msg => error_msg,
error_code => error_code,
sqlstate => sqlstate,
break => break);
end log_problem;
--------------------
-- column_count --
--------------------
overriding
function column_count (Stmt : SQLite_statement) return Natural is
begin
return Stmt.num_columns;
end column_count;
-------------------
-- column_name --
-------------------
overriding
function column_name (Stmt : SQLite_statement; index : Positive)
return String
is
maxlen : constant Natural := Natural (Stmt.column_info.Length);
begin
if index > maxlen then
raise INVALID_COLUMN_INDEX with "Max index is" & maxlen'Img &
" but" & index'Img & " attempted";
end if;
return CT.USS (Stmt.column_info.Element (Index => index).field_name);
end column_name;
--------------------
-- column_table --
--------------------
overriding
function column_table (Stmt : SQLite_statement; index : Positive)
return String
is
maxlen : constant Natural := Natural (Stmt.column_info.Length);
begin
if index > maxlen then
raise INVALID_COLUMN_INDEX with "Max index is" & maxlen'Img &
" but" & index'Img & " attempted";
end if;
return CT.USS (Stmt.column_info.Element (Index => index).table);
end column_table;
------------------
-- initialize --
------------------
overriding
procedure initialize (Object : in out SQLite_statement)
is
use type ACS.SQLite_Connection_Access;
conn : ACS.SQLite_Connection_Access renames Object.sqlite_conn;
logcat : Log_Category;
begin
if conn = null then
return;
end if;
logger_access := Object.log_handler;
Object.dialect := driver_sqlite;
Object.connection := ACB.Base_Connection_Access (conn);
case Object.type_of_statement is
when direct_statement =>
Object.sql_final := new String'(CT.trim_sql
(Object.initial_sql.all));
logcat := statement_execution;
when prepared_statement =>
Object.sql_final := new String'(Object.transform_sql
(Object.initial_sql.all));
logcat := statement_preparation;
end case;
if conn.prepare_statement (stmt => Object.stmt_handle,
sql => Object.sql_final.all)
then
Object.successful_execution := True;
Object.log_nominal (category => logcat,
message => Object.sql_final.all);
else
Object.log_problem
(category => statement_preparation,
message => "Failed to parse SQL query: '" &
Object.sql_final.all & "'",
pull_codes => True);
return;
end if;
if Object.type_of_statement = prepared_statement then
-- Check that we have as many markers as expected
declare
params : Natural := conn.prep_markers_found (Object.stmt_handle);
errmsg : String := "marker mismatch," &
Object.realmccoy.Length'Img & " expected but" &
params'Img & " found by SQLite";
begin
if params /= Natural (Object.realmccoy.Length) then
Object.log_problem
(category => statement_preparation,
message => errmsg);
return;
end if;
end;
else
if not Object.private_execute then
Object.log_problem
(category => statement_preparation,
message => "Failed to execute a direct SQL query");
return;
end if;
end if;
Object.scan_column_information;
exception
when HELL : others =>
Object.log_problem
(category => statement_preparation,
message => ACS.EX.Exception_Message (HELL));
end initialize;
-------------------------------
-- scan_column_information --
-------------------------------
procedure scan_column_information (Stmt : out SQLite_statement)
is
function fn (raw : String) return CT.Text;
function sn (raw : String) return String;
function fn (raw : String) return CT.Text is
begin
case Stmt.con_case_mode is
when upper_case =>
return CT.SUS (ACH.To_Upper (raw));
when lower_case =>
return CT.SUS (ACH.To_Lower (raw));
when natural_case =>
return CT.SUS (raw);
end case;
end fn;
function sn (raw : String) return String is
begin
case Stmt.con_case_mode is
when upper_case =>
return ACH.To_Upper (raw);
when lower_case =>
return ACH.To_Lower (raw);
when natural_case =>
return raw;
end case;
end sn;
conn : ACS.SQLite_Connection_Access renames Stmt.sqlite_conn;
begin
Stmt.num_columns := conn.fields_in_result (Stmt.stmt_handle);
for index in Natural range 0 .. Stmt.num_columns - 1 loop
declare
info : column_info;
brec : bindrec;
name : String := conn.field_name (Stmt.stmt_handle, index);
tname : String := conn.field_true_name (Stmt.stmt_handle, index);
table : String := conn.field_table (Stmt.stmt_handle, index);
dbase : String := conn.field_database (Stmt.stmt_handle, index);
begin
brec.v00 := False; -- placeholder
info.field_name := fn (name);
info.table := fn (table);
conn.get_field_meta_data (stmt => Stmt.stmt_handle,
database => dbase,
table => table,
column => tname,
data_type => info.sqlite_type,
nullable => info.null_possible);
case info.sqlite_type is
when BND.SQLITE_INTEGER => info.field_type := ft_byte8;
when BND.SQLITE_TEXT => info.field_type := ft_utf8;
when BND.SQLITE_BLOB => info.field_type := ft_chain;
when BND.SQLITE_FLOAT => info.field_type := ft_real18;
when BND.SQLITE_NULL => info.field_type := ft_nbyte0;
end case;
Stmt.column_info.Append (New_Item => info);
-- The following pre-populates for bind support
Stmt.crate.Append (New_Item => brec);
Stmt.headings_map.Insert (Key => sn (name),
New_Item => Stmt.crate.Last_Index);
end;
end loop;
end scan_column_information;
--------------------------
-- column_native_type --
--------------------------
overriding
function column_native_type (Stmt : SQLite_statement; index : Positive)
return field_types
is
maxlen : constant Natural := Natural (Stmt.column_info.Length);
begin
if index > maxlen then
raise INVALID_COLUMN_INDEX with "Max index is" & maxlen'Img &
" but" & index'Img & " attempted";
end if;
return Stmt.column_info.Element (Index => index).field_type;
end column_native_type;
----------------------
-- last_insert_id --
----------------------
overriding
function last_insert_id (Stmt : SQLite_statement) return Trax_ID
is
conn : ACS.SQLite_Connection_Access renames Stmt.sqlite_conn;
begin
return conn.lastInsertID;
end last_insert_id;
----------------------
-- last_sql_state --
----------------------
overriding
function last_sql_state (Stmt : SQLite_statement) return SQL_State
is
conn : ACS.SQLite_Connection_Access renames Stmt.sqlite_conn;
begin
return conn.SqlState;
end last_sql_state;
------------------------
-- last_driver_code --
------------------------
overriding
function last_driver_code (Stmt : SQLite_statement) return Driver_Codes
is
conn : ACS.SQLite_Connection_Access renames Stmt.sqlite_conn;
begin
return conn.driverCode;
end last_driver_code;
---------------------------
-- last_driver_message --
---------------------------
overriding
function last_driver_message (Stmt : SQLite_statement) return String
is
conn : ACS.SQLite_Connection_Access renames Stmt.sqlite_conn;
begin
return conn.driverMessage;
end last_driver_message;
---------------------
-- rows_returned --
---------------------
overriding
function rows_returned (Stmt : SQLite_statement) return Affected_Rows is
begin
-- Not supported by SQLite
return 0;
end rows_returned;
--------------------
-- discard_rest --
--------------------
overriding
procedure discard_rest (Stmt : out SQLite_statement)
is
conn : ACS.SQLite_Connection_Access renames Stmt.sqlite_conn;
begin
Stmt.rows_leftover := (Stmt.step_result = data_pulled);
conn.reset_prep_stmt (stmt => Stmt.stmt_handle);
Stmt.step_result := unset;
end discard_rest;
-----------------------
-- private_execute --
-----------------------
function private_execute (Stmt : out SQLite_statement) return Boolean
is
conn : ACS.SQLite_Connection_Access renames Stmt.sqlite_conn;
begin
if conn.prep_fetch_next (Stmt.stmt_handle) then
Stmt.step_result := data_pulled;
else
Stmt.step_result := progam_complete;
Stmt.impacted := conn.rows_affected_by_execution;
end if;
return True;
exception
when ACS.STMT_FETCH_FAIL =>
Stmt.step_result := error_seen;
return False;
end private_execute;
------------------
-- execute #1 --
------------------
overriding
function execute (Stmt : out SQLite_statement) return Boolean
is
conn : ACS.SQLite_Connection_Access renames Stmt.sqlite_conn;
num_markers : constant Natural := Natural (Stmt.realmccoy.Length);
status_successful : Boolean := True;
begin
if Stmt.type_of_statement = direct_statement then
raise INVALID_FOR_DIRECT_QUERY
with "The execute command is for prepared statements only";
end if;
Stmt.successful_execution := False;
conn.reset_prep_stmt (Stmt.stmt_handle);
Stmt.reclaim_canvas;
Stmt.step_result := unset;
Stmt.rows_leftover := False;
if num_markers > 0 then
-- Check to make sure all prepared markers are bound
for sx in Natural range 1 .. num_markers loop
if not Stmt.realmccoy.Element (sx).bound then
raise STMT_PREPARATION
with "Prep Stmt column" & sx'Img & " unbound";
end if;
end loop;
-- Now bind the actual values to the markers
begin
for sx in Natural range 1 .. num_markers loop
Stmt.bind_canvas.Append (Stmt.construct_bind_slot (sx));
end loop;
Stmt.log_nominal (category => statement_execution,
message => "Exec with" & num_markers'Img &
" bound parameters");
exception
when CBS : others =>
Stmt.log_problem (category => statement_execution,
message => ACS.EX.Exception_Message (CBS));
return False;
end;
else
-- No binding required, just execute the prepared statement
Stmt.log_nominal (category => statement_execution,
message => "Exec without bound parameters");
end if;
begin
if conn.prep_fetch_next (Stmt.stmt_handle) then
Stmt.step_result := data_pulled;
else
Stmt.step_result := progam_complete;
Stmt.impacted := conn.rows_affected_by_execution;
end if;
Stmt.successful_execution := True;
exception
when ACS.STMT_FETCH_FAIL =>
Stmt.step_result := error_seen;
status_successful := False;
end;
return status_successful;
end execute;
------------------
-- execute #2 --
------------------
overriding
function execute (Stmt : out SQLite_statement; parameters : String;
delimiter : Character := '|') return Boolean
is
function parameters_given return Natural;
num_markers : constant Natural := Natural (Stmt.realmccoy.Length);
function parameters_given return Natural
is
result : Natural := 1;
begin
for x in parameters'Range loop
if parameters (x) = delimiter then
result := result + 1;
end if;
end loop;
return result;
end parameters_given;
begin
if Stmt.type_of_statement = direct_statement then
raise INVALID_FOR_DIRECT_QUERY
with "The execute command is for prepared statements only";
end if;
if num_markers /= parameters_given then
raise STMT_PREPARATION
with "Parameter number mismatch, " & num_markers'Img &
" expected, but" & parameters_given'Img & " provided.";
end if;
declare
index : Natural := 1;
arrow : Natural := parameters'First;
scans : Boolean := False;
start : Natural := 1;
stop : Natural := 0;
begin
for x in parameters'Range loop
if parameters (x) = delimiter then
if not scans then
Stmt.auto_assign (index, "");
else
Stmt.auto_assign (index, parameters (start .. stop));
scans := False;
end if;
index := index + 1;
else
stop := x;
if not scans then
start := x;
scans := True;
end if;
end if;
end loop;
if not scans then
Stmt.auto_assign (index, "");
else
Stmt.auto_assign (index, parameters (start .. stop));
end if;
end;
return Stmt.execute;
end execute;
------------------
-- fetch_next --
------------------
overriding
function fetch_next (Stmt : out SQLite_statement) return ARS.Datarow
is
conn : ACS.SQLite_Connection_Access renames Stmt.sqlite_conn;
begin
if Stmt.step_result /= data_pulled then
return ARS.Empty_Datarow;
end if;
declare
maxlen : constant Natural := Natural (Stmt.column_info.Length);
result : ARS.Datarow;
begin
for F in 1 .. maxlen loop
declare
colinfo : column_info renames Stmt.column_info.Element (F);
field : ARF.Std_Field;
dvariant : ARF.Variant;
scol : constant Natural := F - 1;
last_one : constant Boolean := (F = maxlen);
heading : constant String := CT.USS (colinfo.field_name);
isnull : constant Boolean :=
conn.field_is_null (Stmt.stmt_handle, scol);
begin
if isnull then
field := ARF.spawn_null_field (colinfo.field_type);
else
case colinfo.field_type is
when ft_nbyte0 =>
-- This should never occur though
dvariant := (datatype => ft_nbyte0, v00 => False);
when ft_byte8 =>
dvariant :=
(datatype => ft_byte8,
v10 => conn.retrieve_integer (Stmt.stmt_handle, scol));
when ft_real18 =>
dvariant :=
(datatype => ft_real18,
v12 => conn.retrieve_double (Stmt.stmt_handle, scol));
when ft_utf8 =>
declare
datatext : AR.Textual :=
conn.retrieve_text (Stmt.stmt_handle, scol);
begin
if seems_like_bit_string (datatext) then
dvariant := (datatype => ft_bits,
v20 => datatext);
else
dvariant := (datatype => ft_utf8,
v21 => datatext);
end if;
end;
when ft_chain => null;
when others => raise INVALID_FOR_RESULT_SET
with "Impossible field type (internal bug??)";
end case;
case colinfo.field_type is
when ft_chain =>
field := ARF.spawn_field
(binob => ARC.convert
(conn.retrieve_blob
(stmt => Stmt.stmt_handle,
index => scol,
maxsz => Stmt.con_max_blob)));
when ft_nbyte0 | ft_byte8 | ft_real18 | ft_utf8 =>
field := ARF.spawn_field (data => dvariant,
null_data => isnull);
when others => null;
end case;
end if;
result.push (heading => heading,
field => field,
last_field => last_one);
end;
end loop;
begin
if conn.prep_fetch_next (Stmt.stmt_handle) then
Stmt.step_result := data_pulled;
else
Stmt.step_result := progam_complete;
end if;
exception
when ACS.STMT_FETCH_FAIL =>
Stmt.step_result := error_seen;
end;
return result;
end;
end fetch_next;
------------------
-- fetch_bound --
------------------
overriding
function fetch_bound (Stmt : out SQLite_statement) return Boolean
is
conn : ACS.SQLite_Connection_Access renames Stmt.sqlite_conn;
begin
if Stmt.step_result /= data_pulled then
return False;
end if;
declare
maxlen : constant Natural := Stmt.num_columns;
begin
for F in 1 .. maxlen loop
declare
dossier : bindrec renames Stmt.crate.Element (F);
colinfo : column_info renames Stmt.column_info.Element (F);
Tout : constant field_types := dossier.output_type;
Tnative : constant field_types := colinfo.field_type;
dvariant : ARF.Variant;
scol : constant Natural := F - 1;
begin
if not dossier.bound then
goto continue;
end if;
case Tnative is
when ft_byte8 =>
dvariant :=
(datatype => ft_byte8,
v10 => conn.retrieve_integer (Stmt.stmt_handle, scol));
when ft_real18 =>
dvariant :=
(datatype => ft_real18,
v12 => conn.retrieve_double (Stmt.stmt_handle, scol));
when ft_utf8 =>
dvariant :=
(datatype => ft_utf8,
v21 => conn.retrieve_text (Stmt.stmt_handle, scol));
when ft_chain =>
declare
bin : String :=
conn.retrieve_blob
(stmt => Stmt.stmt_handle,
index => scol,
maxsz => Stmt.con_max_blob);
begin
dvariant := (datatype => ft_chain,
v17 => CT.SUS (bin));
end;
when others => raise INVALID_FOR_RESULT_SET
with "Impossible field type (internal bug??)";
end case;
if Tnative = ft_byte8 and then
(Tout = ft_nbyte0 or else
Tout = ft_nbyte1 or else
Tout = ft_nbyte2 or else
Tout = ft_nbyte3 or else
Tout = ft_nbyte4 or else
Tout = ft_nbyte8 or else
Tout = ft_byte1 or else
Tout = ft_byte2 or else
Tout = ft_byte3 or else
Tout = ft_byte4 or else
Tout = ft_byte8)
then
case Tout is
when ft_nbyte0 =>
dossier.a00.all := ARC.convert (dvariant.v10);
when ft_nbyte1 =>
dossier.a01.all := ARC.convert (dvariant.v10);
when ft_nbyte2 =>
dossier.a02.all := ARC.convert (dvariant.v10);
when ft_nbyte3 =>
dossier.a03.all := ARC.convert (dvariant.v10);
when ft_nbyte4 =>
dossier.a04.all := ARC.convert (dvariant.v10);
when ft_nbyte8 =>
dossier.a05.all := ARC.convert (dvariant.v10);
when ft_byte1 =>
dossier.a06.all := ARC.convert (dvariant.v10);
when ft_byte2 =>
dossier.a07.all := ARC.convert (dvariant.v10);
when ft_byte3 =>
dossier.a08.all := ARC.convert (dvariant.v10);
when ft_byte4 =>
dossier.a09.all := ARC.convert (dvariant.v10);
when ft_byte8 =>
dossier.a10.all := dvariant.v10;
when others => null;
end case;
elsif Tnative = ft_real18 and then
(Tout = ft_real9 or else
Tout = ft_real18)
then
if Tout = ft_real18 then
dossier.a12.all := dvariant.v12;
else
dossier.a11.all := ARC.convert (dvariant.v12);
end if;
elsif Tnative = ft_utf8 and then
(Tout = ft_textual or else
Tout = ft_widetext or else
Tout = ft_supertext or else
Tout = ft_timestamp or else
Tout = ft_enumtype or else
Tout = ft_settype or else
Tout = ft_utf8 or else
Tout = ft_bits)
then
declare
STU : String := ARC.convert (dvariant.v21);
STA : String := ARC.cvu2str (CT.USS (dvariant.v21));
begin
case Tout is
when ft_textual => dossier.a13.all := CT.SUS (STA);
when ft_widetext => dossier.a14.all := convert (STA);
when ft_supertext => dossier.a15.all := convert (STA);
when ft_timestamp => dossier.a16.all := ARC.convert (STU);
when ft_enumtype => dossier.a18.all := ARC.convert (STU);
when ft_utf8 => dossier.a21.all := STU;
when ft_settype =>
declare
FL : Natural := dossier.a19.all'Length;
items : constant Natural := CT.num_set_items (STU);
begin
if items > FL then
raise BINDING_SIZE_MISMATCH with
"native size : " & items'Img &
" greater than binding size : " & FL'Img;
end if;
dossier.a19.all := ARC.convert (STU, FL);
end;
when ft_bits =>
declare
FL : Natural := dossier.a20.all'Length;
DVLEN : Natural := STA'Length;
begin
if DVLEN > FL then
raise BINDING_SIZE_MISMATCH with "native size : " &
DVLEN'Img & " greater than binding size : " &
FL'Img;
end if;
dossier.a20.all := ARC.convert (STA, FL);
end;
when others => null;
end case;
end;
elsif Tnative = ft_chain and then Tout = ft_chain then
declare
ST : String := ARC.convert (dvariant.v17);
FL : Natural := dossier.a17.all'Length;
DVLEN : Natural := ST'Length;
begin
if DVLEN > FL then
raise BINDING_SIZE_MISMATCH with "native size : " &
DVLEN'Img & " greater than binding size : " & FL'Img;
end if;
dossier.a17.all := ARC.convert (ST, FL);
end;
else
raise BINDING_TYPE_MISMATCH with "native type " &
field_types'Image (Tnative) &
" is incompatible with binding type " &
field_types'Image (Tout);
end if;
end;
<<continue>>
end loop;
end;
begin
if conn.prep_fetch_next (Stmt.stmt_handle) then
Stmt.step_result := data_pulled;
else
Stmt.step_result := progam_complete;
end if;
exception
when ACS.STMT_FETCH_FAIL =>
Stmt.step_result := error_seen;
end;
return True;
end fetch_bound;
-----------------
-- fetch_all --
-----------------
overriding
function fetch_all (Stmt : out SQLite_statement) return ARS.Datarow_Set
is
subtype rack_range is Positive range 1 .. 20000;
dataset_size : Natural := 0;
arrow : rack_range := rack_range'First;
rack : ARS.Datarow_Set (rack_range);
nullset : constant ARS.Datarow_Set (1 .. 0) :=
(others => ARS.Empty_Datarow);
begin
if Stmt.step_result /= data_pulled then
return nullset;
end if;
-- With SQLite, we don't know many rows of data are fetched, ever.
-- For practical purposes, let's limit a result set to 20k rows
-- Rather than dynamically allocating rows and having to worry about
-- copying them to a fixed array, let's just allocate a 20k set and
-- return the part we need. That should be more efficient considering
-- trade-offs.
--
-- Note that this was originally intended to be a 100k row result set.
-- but gcc 5.3 is core dumping with "illegal" instruction if the
-- rack_range is >= 25000. Maybe a problem with containers? But it
-- happened with a 100k array of access to datarows too!
loop
rack (arrow) := Stmt.fetch_next;
exit when rack (arrow).data_exhausted;
dataset_size := dataset_size + 1;
if arrow = rack_range'Last then
Stmt.discard_rest;
exit;
end if;
arrow := arrow + 1;
end loop;
if dataset_size = 0 then
-- nothing was fetched
return nullset;
end if;
return rack (1 .. dataset_size);
end fetch_all;
--------------
-- Adjust --
--------------
overriding
procedure Adjust (Object : in out SQLite_statement) is
begin
-- The stmt object goes through this evolution:
-- A) created in private_prepare()
-- B) copied to new object in prepare(), A) destroyed
-- C) copied to new object in program, B) destroyed
-- We don't want to take any action until C) is destroyed, so add a
-- reference counter upon each assignment. When finalize sees a
-- value of "2", it knows it is the program-level statement and then
-- it can release memory releases, but not before!
Object.assign_counter := Object.assign_counter + 1;
-- Since the finalization is looking for a specific reference
-- counter, any further assignments would fail finalization, so
-- just prohibit them outright.
if Object.assign_counter > 2 then
raise STMT_PREPARATION
with "Statement objects cannot be re-assigned.";
end if;
end Adjust;
----------------
-- finalize --
----------------
overriding
procedure finalize (Object : in out SQLite_statement)
is
use type BND.sqlite3_stmt_Access;
begin
if Object.assign_counter /= 2 then
return;
end if;
if Object.stmt_handle /= null then
if not Object.sqlite_conn.prep_finalize (Object.stmt_handle) then
Object.log_problem
(category => statement_preparation,
message => "Deallocating statement resources",
pull_codes => True);
end if;
end if;
if Object.sql_final /= null then
free_sql (Object.sql_final);
end if;
Object.reclaim_canvas;
end finalize;
---------------------------
-- construct_bind_slot --
---------------------------
function construct_bind_slot (Stmt : SQLite_statement; marker : Positive)
return sqlite_canvas
is
zone : bindrec renames Stmt.realmccoy.Element (marker);
conn : ACS.SQLite_Connection_Access renames Stmt.sqlite_conn;
vartype : constant field_types := zone.output_type;
okay : Boolean := True;
product : sqlite_canvas;
BT : BND.ICS.chars_ptr renames product.buffer_text;
BB : BND.ICS.char_array_access renames product.buffer_binary;
use type AR.NByte0_Access;
use type AR.NByte1_Access;
use type AR.NByte2_Access;
use type AR.NByte3_Access;
use type AR.NByte4_Access;
use type AR.NByte8_Access;
use type AR.Byte1_Access;
use type AR.Byte2_Access;
use type AR.Byte3_Access;
use type AR.Byte4_Access;
use type AR.Byte8_Access;
use type AR.Real9_Access;
use type AR.Real18_Access;
use type AR.Str1_Access;
use type AR.Str2_Access;
use type AR.Str4_Access;
use type AR.Time_Access;
use type AR.Enum_Access;
use type AR.Chain_Access;
use type AR.Settype_Access;
use type AR.Bits_Access;
use type AR.S_UTF8_Access;
use type AR.Geometry_Access;
begin
if zone.null_data then
if not conn.marker_is_null (Stmt.stmt_handle, marker) then
raise STMT_EXECUTION
with "failed to bind NULL marker" & marker'Img;
end if;
else
case vartype is
when ft_nbyte0 | ft_nbyte1 | ft_nbyte2 | ft_nbyte3 | ft_nbyte4 |
ft_nbyte8 | ft_byte1 | ft_byte2 | ft_byte3 | ft_byte4 |
ft_byte8 =>
declare
hold : AR.Byte8;
begin
case vartype is
when ft_nbyte0 =>
if zone.a00 = null then
hold := ARC.convert (zone.v00);
else
hold := ARC.convert (zone.a00.all);
end if;
when ft_nbyte1 =>
if zone.a01 = null then
hold := ARC.convert (zone.v01);
else
hold := ARC.convert (zone.a01.all);
end if;
when ft_nbyte2 =>
if zone.a02 = null then
hold := ARC.convert (zone.v02);
else
hold := ARC.convert (zone.a02.all);
end if;
when ft_nbyte3 =>
if zone.a03 = null then
hold := ARC.convert (zone.v03);
else
hold := ARC.convert (zone.a03.all);
end if;
when ft_nbyte4 =>
if zone.a04 = null then
hold := ARC.convert (zone.v04);
else
hold := ARC.convert (zone.a04.all);
end if;
when ft_nbyte8 =>
if zone.a05 = null then
hold := ARC.convert (zone.v05);
else
hold := ARC.convert (zone.a05.all);
end if;
when ft_byte1 =>
if zone.a06 = null then
hold := ARC.convert (zone.v06);
else
hold := ARC.convert (zone.a06.all);
end if;
when ft_byte2 =>
if zone.a07 = null then
hold := ARC.convert (zone.v07);
else
hold := ARC.convert (zone.a07.all);
end if;
when ft_byte3 =>
if zone.a08 = null then
hold := ARC.convert (zone.v08);
else
hold := ARC.convert (zone.a08.all);
end if;
when ft_byte4 =>
if zone.a09 = null then
hold := ARC.convert (zone.v09);
else
hold := ARC.convert (zone.a09.all);
end if;
when ft_byte8 =>
if zone.a10 = null then
hold := zone.v10;
else
hold := zone.a10.all;
end if;
when others => hold := 0;
end case;
okay := conn.marker_is_integer (Stmt.stmt_handle,
marker, hold);
end;
when ft_real9 | ft_real18 =>
declare
hold : AR.Real18;
begin
if vartype = ft_real18 then
if zone.a12 = null then
hold := zone.v12;
else
hold := zone.a12.all;
end if;
else
if zone.a11 = null then
hold := ARC.convert (zone.v11);
else
hold := ARC.convert (zone.a11.all);
end if;
end if;
okay := conn.marker_is_double (Stmt.stmt_handle,
marker, hold);
end;
when ft_textual =>
if zone.a13 = null then
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.v13), BT);
else
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.a13.all), BT);
end if;
when ft_widetext =>
if zone.a14 = null then
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.v14), BT);
else
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.a14.all), BT);
end if;
when ft_supertext =>
if zone.a15 = null then
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.v15), BT);
else
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.a15.all), BT);
end if;
when ft_timestamp =>
if zone.a16 = null then
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.v16), BT);
else
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.a16.all), BT);
end if;
when ft_enumtype =>
if zone.a18 = null then
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.v18), BT);
else
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.a18.all), BT);
end if;
when ft_settype =>
if zone.a19 = null then
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.v19), BT);
else
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.a19.all), BT);
end if;
when ft_chain =>
if zone.a17 = null then
okay := conn.marker_is_blob (Stmt.stmt_handle, marker,
ARC.convert (zone.v17), BB);
else
okay := conn.marker_is_blob (Stmt.stmt_handle, marker,
ARC.convert (zone.a17.all), BB);
end if;
when ft_bits =>
if zone.a20 = null then
okay := conn.marker_is_blob (Stmt.stmt_handle, marker,
ARC.convert (zone.v20), BB);
else
okay := conn.marker_is_blob (Stmt.stmt_handle, marker,
ARC.convert (zone.a20.all), BB);
end if;
when ft_utf8 =>
if zone.a21 = null then
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
ARC.convert (zone.v21), BT);
else
okay := conn.marker_is_text (Stmt.stmt_handle, marker,
zone.a21.all, BT);
end if;
when ft_geometry =>
if zone.a22 = null then
okay := conn.marker_is_text
(Stmt.stmt_handle, marker, WKB.produce_WKT (zone.v22), BT);
else
okay := conn.marker_is_text
(Stmt.stmt_handle, marker,
Spatial_Data.Well_Known_Text (zone.a22.all), BT);
end if;
end case;
if not okay then
Stmt.log_problem (category => statement_execution,
message => "failed to bind " & vartype'Img &
" type to marker " & marker'Img,
pull_codes => True,
break => True);
end if;
end if;
return product;
end construct_bind_slot;
----------------------
-- reclaim_canvas --
----------------------
procedure reclaim_canvas (Stmt : out SQLite_statement)
is
use type BND.ICS.char_array_access;
use type BND.ICS.chars_ptr;
begin
for x in Positive range 1 .. Natural (Stmt.bind_canvas.Length) loop
declare
SC : sqlite_canvas renames Stmt.bind_canvas.Element (x);
BT : BND.ICS.chars_ptr := SC.buffer_text;
BB : BND.ICS.char_array_access := SC.buffer_binary;
begin
if BT /= BND.ICS.Null_Ptr then
BND.ICS.Free (BT);
end if;
if BB /= null then
free_binary (BB);
end if;
end;
end loop;
Stmt.bind_canvas.Clear;
end reclaim_canvas;
----------------------
-- fetch_next_set --
----------------------
overriding
procedure fetch_next_set (Stmt : out SQLite_statement;
data_present : out Boolean;
data_fetched : out Boolean)
is
pragma Unreferenced (Stmt);
-- Stored precedures are not supported on SQLite
-- There's nothting that would generate multiple result sets
-- with a single query.
begin
data_fetched := False;
data_present := False;
end fetch_next_set;
------------------
-- bit_string --
------------------
function seems_like_bit_string (candidate : CT.Text) return Boolean
is
canstr : String := CT.USS (candidate);
begin
if canstr'Length > 64 then
return False;
end if;
for x in canstr'Range loop
if canstr (x) /= '0' and then canstr (x) /= '1' then
return False;
end if;
end loop;
return True;
end seems_like_bit_string;
end AdaBase.Statement.Base.SQLite;
|
with Asis.Elements;
with Asis.Statements;
package body Asis_Adapter.Element.Paths is
------------
-- EXPORTED:
------------
procedure Do_Pre_Child_Processing
(Element : in Asis.Element; State : in out Class)
is
Parent_Name : constant String := Module_Name;
Module_Name : constant String := Parent_Name & ".Do_Pre_Child_Processing";
Result : a_nodes_h.Path_Struct :=
a_nodes_h.Support.Default_Path_Struct;
Path_Kind : constant Asis.Path_Kinds := Asis.Elements.Path_Kind (Element);
procedure Add_Case_Path_Alternative_Choices is
begin
Add_Element_List
(This => State,
Elements_In => Asis.Statements.Case_Path_Alternative_Choices (Element),
Dot_Label_Name => "Case_Path_Alternative_Choices",
List_Out => Result.Case_Path_Alternative_Choices,
Add_Edges => True);
end;
procedure Add_Condition_Expression is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Statements.Condition_Expression (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Condition_Expression", ID);
Result.Condition_Expression := ID;
end;
procedure Add_Guard is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Statements.Guard (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Guard", ID);
Result.Guard := ID;
end;
procedure Add_Sequence_Of_Statements is
begin
if Path_Kind in Asis.A_Statement_Path then
Add_Element_List
(This => State,
Elements_In => Asis.Statements.Sequence_Of_Statements (Element),
Dot_Label_Name => "Sequence_Of_Statements",
List_Out => Result.Sequence_Of_Statements,
Add_Edges => True);
else
-- Asis.Statements.Sequence_Of_Statements doesn't like paths outside
-- A_Statement_Path:
State.Add_Not_Implemented;
end if;
end;
procedure Add_Common_Items is
begin
State.Add_To_Dot_Label ("Path_Kind", Path_Kind'Image);
Result.Path_Kind := anhS.To_Path_Kinds (Path_Kind);
Add_Sequence_Of_Statements; -- Has Add_Not_Implemented
end Add_Common_Items;
use all type Asis.Path_Kinds;
begin
If Path_Kind /= Not_A_Path then
Add_Common_Items; -- Has Add_Not_Implemented
end if;
case Path_Kind is
when Not_A_Path =>
raise Program_Error with
Module_Name & " called with: " & Path_Kind'Image;
when An_If_Path =>
Add_Condition_Expression;
when An_Elsif_Path =>
Add_Condition_Expression;
when An_Else_Path =>
null; -- No more info
when A_Case_Path =>
Add_Case_Path_Alternative_Choices;
when A_Select_Path =>
Add_Guard;
when An_Or_Path =>
Add_Guard;
when A_Then_Abort_Path =>
null; -- No more info
when A_Case_Expression_Path => -- A2012
Add_Case_Path_Alternative_Choices;
when An_If_Expression_Path => -- A2012
Add_Condition_Expression;
when An_Elsif_Expression_Path => -- A2012
Add_Condition_Expression;
when An_Else_Expression_Path => -- A2012
null; -- No more info
end case;
State.A_Element.Element_Kind := a_nodes_h.A_Path;
State.A_Element.The_Union.Path := Result;
end Do_Pre_Child_Processing;
end Asis_Adapter.Element.Paths;
|
package types.c
with spark_mode => on
is
type t_retval is (SUCCESS, FAILURE) with size => 8;
for t_retval use (SUCCESS => 0, FAILURE => 1);
--
-- C string
--
type c_string is array (positive range <>) of aliased character;
for c_string'component_size use character'size;
-- C_string length (without nul character)
function len (s : c_string) return natural;
-- String conversion
procedure to_c
(dst : out c_string; src : in string);
procedure to_ada
(dst : out string; src : in c_string);
--
-- C buffer
--
subtype c_buffer is byte_array;
--
-- Boolean
--
type bool is new boolean with size => 8;
for bool use (true => 1, false => 0);
end types.c;
|
with Piles;
procedure Parenthesage is
-- L'indice dans la chaîne Meule de l'élément Aiguille.
-- Si l'Aiguille n'est pas dans la Meule, on retroune Meule'Last + 1.
Function Index (Meule : in String; Aiguille: Character) return Integer with
Post => Meule'First <= Index'Result and then Index'Result <= Meule'Last + 1
and then (Index'Result > Meule'Last or else Meule (Index'Result) = Aiguille)
is
Indice: Integer;
begin
Indice := Meule'First;
for C of Meule loop
exit when C = Aiguille;
Indice := Indice + 1;
end loop;
return Indice;
end Index;
-- Programme de test de Index.
procedure Tester_Index is
ABCDEF : constant String := "abcdef";
begin
pragma Assert (1 = Index (ABCDEF, 'a'));
pragma Assert (3 = Index (ABCDEF, 'c'));
pragma Assert (6 = Index (ABCDEF, 'f'));
pragma Assert (7 = Index (ABCDEF, 'z'));
pragma Assert (4 = Index (ABCDEF (1..3), 'z'));
pragma Assert (3 = Index (ABCDEF (3..5), 'c'));
pragma Assert (5 = Index (ABCDEF (3..5), 'e'));
pragma Assert (6 = Index (ABCDEF (3..5), 'a'));
pragma Assert (6 = Index (ABCDEF (3..5), 'g'));
end;
-- Vérifier les bon parenthésage d'une Chaîne (D). Le sous-programme
-- indique si le parenthésage est bon ou non (Correct : R) et dans le cas
-- où il n'est pas correct, l'indice (Indice_Erreur : R) du symbole qui
-- n'est pas appairé (symbole ouvrant ou fermant).
--
-- Exemples
-- "[({})]" -> Correct
-- "]" -> Non Correct et Indice_Erreur = 1
-- "((()" -> Non Correct et Indice_Erreur = 2
--
procedure Verifier_Parenthesage (Chaine: in String ; Correct : out Boolean ; Indice_Erreur : out Integer) is
COuvrants : Constant String := "([{";
CFermants : Constant String := ")]}";
package Pile_Ouvrants is
new Piles(Chaine'Last - Chaine'First + 1, Character);
use Pile_Ouvrants;
package Pile_Indices is
new Piles(Chaine'Last - Chaine'First + 1, Integer);
use Pile_Indices;
Ouvrants : Pile_Ouvrants.T_Pile;
Indices : Pile_Indices.T_Pile;
Depilement: Character;
begin
Initialiser (Ouvrants);
Initialiser (Indices);
for J in Chaine'First..Chaine'Last loop
begin
case Chaine(J) is
when '(' | '[' | '{' =>
Empiler(Ouvrants, Chaine(J));
Empiler(Indices, J);
raise Constraint_Error; -- continue
when ')' => Depilement := '(';
when ']' => Depilement := '[';
when '}' => Depilement := '{';
when others => raise Constraint_Error; -- continue
end case;
if Est_Vide(Ouvrants) or else Sommet(Ouvrants) /= Depilement then
Indice_Erreur := J;
Correct := False;
return;
else
Depiler(Ouvrants);
Depiler(Indices);
end if;
exception
when Constraint_Error => Null;
end;
end loop;
if not Est_Vide(Indices) then
Indice_Erreur := Sommet(Indices);
Correct := False;
else
Correct := True;
end if;
end Verifier_Parenthesage;
-- Programme de test de Verifier_Parenthesage
procedure Tester_Verifier_Parenthesage is
Exemple1 : constant String(1..2) := "{}";
Exemple2 : constant String(11..18) := "]{[(X)]}";
Indice : Integer; -- Résultat de ... XXX
Correct : Boolean;
begin
Verifier_Parenthesage ("(a < b)", Correct, Indice);
pragma Assert (Correct);
Verifier_Parenthesage ("([{a}])", Correct, Indice);
pragma Assert (Correct);
Verifier_Parenthesage ("(][{a}])", Correct, Indice);
pragma Assert (not Correct);
pragma Assert (Indice = 2);
Verifier_Parenthesage ("]([{a}])", Correct, Indice);
pragma Assert (not Correct);
pragma Assert (Indice = 1);
Verifier_Parenthesage ("([{}])}", Correct, Indice);
pragma Assert (not Correct);
pragma Assert (Indice = 7);
Verifier_Parenthesage ("([{", Correct, Indice);
pragma Assert (not Correct);
pragma Assert (Indice = 3);
Verifier_Parenthesage ("([{}]", Correct, Indice);
pragma Assert (not Correct);
pragma Assert (Indice = 1);
Verifier_Parenthesage ("", Correct, Indice);
pragma Assert (Correct);
Verifier_Parenthesage (Exemple1, Correct, Indice);
pragma Assert (Correct);
Verifier_Parenthesage (Exemple2, Correct, Indice);
pragma Assert (not Correct);
pragma Assert (Indice = 11);
Verifier_Parenthesage (Exemple2(12..18), Correct, Indice);
pragma Assert (Correct);
Verifier_Parenthesage (Exemple2(12..15), Correct, Indice);
pragma Assert (not Correct);
pragma Assert (Indice = 14);
end Tester_Verifier_Parenthesage;
begin
Tester_Index;
Tester_Verifier_Parenthesage;
end Parenthesage;
|
generic
type Component is private;
package G_Tables is
type Table (<>) is limited private;
function Create (L : Natural) return Table;
private
type Table is array (Positive range <>) of Component;
end G_Tables;
|
------------------------------------------------------------------------------
-- --
-- tiled-code-gen --
-- --
-- Copyright (C) 2021 Fabien Chouteau --
-- --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with Ada.Directories; use Ada.Directories;
with Ada.Text_IO; use Ada.Text_IO;
with TCG.Utils; use TCG.Utils;
with TCG.Tilesets;
with TCG.Palette;
use TCG;
package body TCG.Outputs.LibGBA is
use type Tilesets.Master_Tile_Id;
use type Palette.Color_Id;
procedure Generate_Charblock (Filepath : String;
Package_Name : String);
procedure Generate_Tileset_Collisions (Filepath : String;
Package_Name : String);
procedure Generate_Root_Package
(Filename : String;
Package_Name : String;
Format : Palette.Output_Color_Format);
------------------------
-- Generate_Charblock --
------------------------
procedure Generate_Charblock (Filepath : String;
Package_Name : String)
is
Output : Ada.Text_IO.File_Type;
procedure P (Str : String);
procedure PL (Str : String);
procedure NL;
procedure P (Str : String) is
begin
Put (Output, Str);
end P;
procedure PL (Str : String) is
begin
Put_Line (Output, Str);
end PL;
procedure NL is
begin
New_Line (Output);
end NL;
begin
pragma Style_Checks ("M200");
Create (Output, Out_File, Filepath);
PL ("with GBA.Graphics.Charblocks;");
PL ("pragma Style_Checks (Off);");
PL ("package " & Package_Name & " is");
NL;
PL (" Block : aliased constant GBA.Graphics.Charblocks.Charblock_Raw :=");
PL (" (");
for Id in Tilesets.First_Id .. Tilesets.Last_Id loop
for Y in 1 .. Tilesets.Tile_Height loop
P (" ");
for X in 1 .. Tilesets.Tile_Width loop
if Id /= Tilesets.No_Tile and then Id <= Tilesets.Last_Id then
P (Palette.Color_Id'Image ((Tilesets.Pix (Id, X, Y))));
else
P (" 0");
end if;
if X /= Tilesets.Tile_Width then
P (",");
end if;
end loop;
if Y /= Tilesets.Tile_Height then
PL (",");
else
P ("");
end if;
end loop;
if Id /= Tilesets.Last_Id then
PL (",");
else
PL (");");
end if;
end loop;
PL ("end " & Package_Name & ";");
Close (Output);
end Generate_Charblock;
---------------------------------
-- Generate_Tileset_Collisions --
---------------------------------
procedure Generate_Tileset_Collisions (Filepath : String;
Package_Name : String)
is
Output : Ada.Text_IO.File_Type;
procedure P (Str : String);
procedure PL (Str : String);
procedure NL;
procedure P (Str : String) is
begin
Put (Output, Str);
end P;
procedure PL (Str : String) is
begin
Put_Line (Output, Str);
end PL;
procedure NL is
begin
New_Line (Output);
end NL;
begin
Create (Output, Out_File, Filepath);
PL ("with GBA.Graphics.Charblocks;");
PL ("pragma Style_Checks (Off);");
PL ("package " & Package_Name & " is");
NL;
PL (" Block : aliased constant GBA.Graphics.Charblocks.Charblock_Raw :=");
PL (" (");
for Id in Tilesets.First_Id .. Tilesets.Last_Id loop
for Y in 1 .. Tilesets.Tile_Height loop
P (" ");
for X in 1 .. Tilesets.Tile_Width loop
P (if Id /= Tilesets.No_Tile
and then
Id <= Tilesets.Last_Id
and then
Tilesets.Collision (Id, X, Y)
then
"1"
else
"0");
if X /= Tilesets.Tile_Width then
P (",");
end if;
end loop;
if Y /= Tilesets.Tile_Height then
PL (",");
else
P ("");
end if;
end loop;
if Id /= Tilesets.Last_Id then
PL (",");
else
PL (");");
end if;
end loop;
PL ("end " & Package_Name & ";");
Close (Output);
end Generate_Tileset_Collisions;
---------------------------
-- Generate_Root_Package --
---------------------------
procedure Generate_Root_Package
(Filename : String;
Package_Name : String;
Format : Palette.Output_Color_Format)
is
Output : File_Type;
begin
Create (Output, Out_File, Filename);
Put_Line (Output, "with GBA.Graphics.Palettes;");
Put_Line (Output, "with GBA.Graphics.Charblocks;");
New_Line (Output);
Put_Line (Output, "pragma Style_Checks (Off);");
Put_Line (Output, "package " & Package_Name & " is");
New_Line (Output);
New_Line (Output);
Put_Line (Output,
" Palette : aliased GBA.Graphics.Palettes.Palette := (");
declare
use TCG.Palette;
First : constant Color_Id := Palette.First_Id;
Last : constant Color_Id := Palette.Last_Id;
-- The GBA palettes have fixed size 256 colors
Max : constant Color_Id := 255;
begin
if First /= 0 then
raise Program_Error with "expected Palette.First_Id = 0";
end if;
if Last > 255 then
raise Program_Error with "Palette size (" &
Palette.Number_Of_Colors'Img &
") above maximum allowed for LibGBA (256)";
end if;
for Id in First .. Max loop
if Id <= Last then
Put (Output, " " & Id'Img & " => " &
Palette.Image (Palette.Convert (Id), Format));
else
Put (Output, " " & Id'Img & " => 0");
end if;
if Id /= Max then
Put_Line (Output, ",");
end if;
end loop;
end;
Put_Line (Output, ");");
New_Line (Output);
Put_Line (Output, " type Object_Kind is (Rectangle_Obj, Point_Obj,");
Put_Line (Output, " Ellipse_Obj, Polygon_Obj, Tile_Obj, Text_Obj);");
New_Line (Output);
Put_Line (Output, " type String_Access is access all String;");
New_Line (Output);
Put_Line (Output, " type Object");
Put_Line (Output, " (Kind : Object_Kind := Rectangle_Obj)");
Put_Line (Output, " is record");
Put_Line (Output, " Name : String_Access;");
Put_Line (Output, " Id : Natural;");
Put_Line (Output, " X : Float;");
Put_Line (Output, " Y : Float;");
Put_Line (Output, " Width : Float;");
Put_Line (Output, " Height : Float;");
-- Put_Linr (Output, " Points : Polygon_Access;");
Put_Line (Output, " Str : String_Access;");
Put_Line (Output, " Flip_Vertical : Boolean;");
Put_Line (Output, " Flip_Horizontal: Boolean;");
Put_Line
(Output, " Tile_Id : GBA.Graphics.Charblocks.Tile_Id;");
Put_Line (Output, " end record;");
New_Line (Output);
Put_Line (Output, " type Object_Array is array (Natural range <>)");
Put_Line (Output, " of Object;");
New_Line (Output);
Put_Line (Output, "end " & Package_Name & ";");
Close (Output);
end Generate_Root_Package;
-----------------------
-- Gen_LibGBA_Source --
-----------------------
procedure Gen_LibGBA_Source
(Directory : String;
Root_Package_Name : String;
Map_List : TCG.Maps.List.List)
is
Format : constant Palette.Output_Color_Format := Palette.RGB555;
begin
if not TCG.Utils.Make_Dir (Directory) then
Ada.Text_IO.Put_Line
(Ada.Text_IO.Standard_Error,
"Cannot create directory for GESTE code: '" & Directory & "'");
return;
end if;
if Tilesets.Tile_Width /= Tilesets.Tile_Height then
raise Program_Error with "Tiles are not square";
end if;
if Tilesets.Tile_Width /= 8 then
raise Program_Error with "Only 8x8 tiles allowed for LibGBA";
end if;
if Tilesets.Number_Of_Tiles > 512 then
raise Program_Error
with "Number of tiles (" & Tilesets.Number_Of_Tiles'Img &
") above maximum allowed for LibGBA (512)";
end if;
declare
Package_Name : constant String := Root_Package_Name;
Filename : constant String :=
Compose (Directory, To_Ada_Filename (Package_Name));
begin
Generate_Root_Package (Filename, Package_Name, Format);
end;
declare
Package_Name : constant String := Root_Package_Name & ".Charblock";
Filename : constant String :=
Compose (Directory, To_Ada_Filename (Package_Name));
begin
Generate_Charblock (Filename, Package_Name);
end;
declare
Package_Name : constant String :=
Root_Package_Name & ".Collisions";
Filename : constant String :=
Compose (Directory, To_Ada_Filename (Package_Name));
begin
Generate_Tileset_Collisions (Filename, Package_Name);
end;
for Map of Map_List loop
declare
Package_Name : constant String :=
Root_Package_Name & "." & To_Ada_Identifier (Maps.Name (Map));
Filename : constant String :=
Compose (Directory, To_Ada_Filename (Package_Name));
begin
TCG.Maps.Generate_LibGBA_Source (Map, Package_Name, Filename);
end;
end loop;
end Gen_LibGBA_Source;
end TCG.Outputs.LibGBA;
|
--
-- This is free and unencumbered software released into the public domain.
--
-- Anyone is free to copy, modify, publish, use, compile, sell, or
-- distribute this software, either in source code form or as a compiled
-- binary, for any purpose, commercial or non-commercial, and by any
-- means.
--
-- In jurisdictions that recognize copyright laws, the author or authors
-- of this software dedicate any and all copyright interest in the
-- software to the public domain. We make this dedication for the benefit
-- of the public at large and to the detriment of our heirs and
-- successors. We intend this dedication to be an overt act of
-- relinquishment in perpetuity of all present and future rights to this
-- software under copyright law.
--
-- 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 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.
--
-- For more information, please refer to <http://unlicense.org>
--
package body BBS.units with SPARK_Mode => on is
--
-- Get elementary math functions for floating point numbers
--
-- package float_functions is new Ada.Numerics.Generic_Elementary_Functions(float);
-- function "**"(Left, Right : float) return float
-- renames float_functions."**";
--
-- Since the conversion and operation routines are so simple, most have been
-- converted to expression functions. Occasionally, one may be left here
-- due to dependencies with partial type declarations.
--
-- Unit conversion routines. Most of these are pretty simple. Add as needed.
-- The conversion factors come from a variety of sources and definitions.
--
-- -------------------------------------------------------------------------
-- *** Distance conversions ***
--
--
-- Length functions
--
function "/"(Left : len_m; Right : Duration) return vel_m_s is
begin
return vel_m_s(Float(Left) / Float(Right));
end;
-- -------------------------------------------------------------------------
-- *** Area conversions ***
--
-- -------------------------------------------------------------------------
-- *** Volume conversions ***
--
-- -------------------------------------------------------------------------
-- *** Mass conversions ***
--
-- -------------------------------------------------------------------------
-- *** Force conversions ***
--
-- none
--
-- Force functions
--
function "*"(Left : mass_kg; Right : accel_m_s2) return force_n is
begin
return force_n(Float(Left) * Float(Right));
end;
--
function "*"(Left : accel_m_s2; Right : mass_kg) return force_n is
begin
return force_n(Float(Left) * Float(Right));
end;
--
function "/"(Left : force_n; Right : accel_m_s2) return mass_kg is
begin
return mass_kg(Float(Left) / Float(Right));
end;
--
function "/"(Left : force_n; Right : mass_kg) return accel_m_s2 is
begin
return accel_m_s2(Float(Left) / Float(Right));
end;
-- -------------------------------------------------------------------------
-- *** Temperature conversions ***
--
-- -------------------------------------------------------------------------
-- *** Pressure conversions ***
--
--
-- Given local pressure and altimeter setting, determine the pressure
-- altitude. Given local pressure and altitude, determine the altimeter
-- setting.
--
-- function pressure_altitude(pressure : press_p; altm : press_p)
-- return len_m is
-- begin
-- return len_m(44330.0 * (1.0 - (float(pressure)/float(altm))**float(1.0/5.255)));
-- end;
--
-- function altimeter(pressure : press_p; altitude : len_m) return press_p is
-- begin
-- return press_p(float(pressure)/(1.0 - (float(altitude)/44330.0)**float(5.255)));
-- end;
-- -------------------------------------------------------------------------
-- *** Velocity conversions ***
--
--
-- Velocity functions
--
function "/"(Left : vel_m_s; Right : Duration) return accel_m_s2 is
begin
return accel_m_s2(Float(Left) / Float(Right));
end;
-- -------------------------------------------------------------------------
-- *** Acceleration conversions ***
--
-- -------------------------------------------------------------------------
-- *** Angle conversions ***
--
-- -------------------------------------------------------------------------
-- *** Rotation rate conversions ***
--
-- -------------------------------------------------------------------------
-- *** Functions for Ohms law ***
--
-- -------------------------------------------------------------------------
-- *** Frequency and time conversions ***
--
end;
|
-- AOC 2020, Day 5
with Ada.Containers.Vectors;
package Day is
type Row_Type is range 0..127;
type Seat_Type is range 0..7;
type Boarding_Pass is record
Row : Row_Type := 0;
Seat : Seat_Type := 0;
end record;
package Boarding_Pass_Vectors is new Ada.Containers.Vectors
(Index_Type => Natural,
Element_Type => Boarding_Pass);
function load_batch(filename : in String) return Boarding_Pass_Vectors.Vector;
function highest_id(passes : in Boarding_Pass_Vectors.Vector) return Natural;
function missing_id(passes : in Boarding_Pass_Vectors.Vector) return Natural;
end Day;
|
-- Generated from glu.h
-- Date: Wed Sep 22 12:47:09 1999
--
with Interfaces.C.Extensions;
with gl_h;
package glu_h is
-- $Id: glu_h.ads,v 1.1.1.1 2002/08/30 01:10:55 afvargas Exp $
--
-- Mesa 3-D graphics library
-- Version: 3.0
-- Copyright (C) 1995-1998 Brian Paul
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Library General Public
-- License as published by the Free Software Foundation; either
-- version 2 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Library General Public License for more details.
--
-- You should have received a copy of the GNU Library General Public
-- License along with this library; if not, write to the Free
-- Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--
--
-- $Log: glu_h.ads,v $
-- Revision 1.1.1.1 2002/08/30 01:10:55 afvargas
--
--
-- Revision 1.1.1.1 2001/04/11 01:22:08 afvargas
--
--
-- Revision 1.1 1999/09/24 08:37:15 briot
-- These two files provide a very basic binding to the openGL library (they
-- were generated from the Mesa files). These are mainly provided as examples,
-- not as a full binding
--
-- Revision 3.2 1998/07/26 01:36:27 brianp
-- changes for Windows compilation per Ted Jump
--
-- Revision 3.1 1998/06/23 00:33:08 brianp
-- added some WIN32 APIENTRY, CALLBACK stuff (Eric Lassauge)
--
-- Revision 3.0 1998/02/20 05:06:01 brianp
-- initial rev
--
-- to facilitate clean DLL building ...
-- tag specifying we're building for DLL runtime support
GLU_VERSION_1_1 : constant := 1;
GLU_TRUE : constant := 1;
GLU_FALSE : constant := 0;
type GLUenum is new Integer;
for GLUenum 'Size use 32;
GLU_SMOOTH : constant GLUenum := 100000;
GLU_FLAT : constant GLUenum := 100001;
GLU_NONE : constant GLUenum := 100002;
GLU_POINT : constant GLUenum := 100010;
GLU_LINE : constant GLUenum := 100011;
GLU_FILL : constant GLUenum := 100012;
GLU_SILHOUETTE : constant GLUenum := 100013;
GLU_OUTSIDE : constant GLUenum := 100020;
GLU_INSIDE : constant GLUenum := 100021;
GLU_BEGIN : constant GLUenum := 100100;
GLU_VERTEX : constant GLUenum := 100101;
GLU_END : constant GLUenum := 100102;
GLU_ERROR : constant GLUenum := 100103;
GLU_EDGE_FLAG : constant GLUenum := 100104;
GLU_CW : constant GLUenum := 100120;
GLU_CCW : constant GLUenum := 100121;
GLU_INTERIOR : constant GLUenum := 100122;
GLU_EXTERIOR : constant GLUenum := 100123;
GLU_UNKNOWN : constant GLUenum := 100124;
GLU_TESS_ERROR1 : constant GLUenum := 100151;
GLU_TESS_ERROR2 : constant GLUenum := 100152;
GLU_TESS_ERROR3 : constant GLUenum := 100153;
GLU_TESS_ERROR4 : constant GLUenum := 100154;
GLU_TESS_ERROR5 : constant GLUenum := 100155;
GLU_TESS_ERROR6 : constant GLUenum := 100156;
GLU_TESS_ERROR7 : constant GLUenum := 100157;
GLU_TESS_ERROR8 : constant GLUenum := 100158;
GLU_TESS_ERROR9 : constant GLUenum := 100159;
GLU_AUTO_LOAD_MATRIX : constant GLUenum := 100200;
GLU_CULLING : constant GLUenum := 100201;
GLU_PARAMETRIC_TOLERANCE : constant GLUenum := 100202;
GLU_SAMPLING_TOLERANCE : constant GLUenum := 100203;
GLU_DISPLAY_MODE : constant GLUenum := 100204;
GLU_SAMPLING_METHOD : constant GLUenum := 100205;
GLU_U_STEP : constant GLUenum := 100206;
GLU_V_STEP : constant GLUenum := 100207;
GLU_PATH_LENGTH : constant GLUenum := 100215;
GLU_PARAMETRIC_ERROR : constant GLUenum := 100216;
GLU_DOMAIN_DISTANCE : constant GLUenum := 100217;
GLU_MAP1_TRIM_2 : constant GLUenum := 100210;
GLU_MAP1_TRIM_3 : constant GLUenum := 100211;
GLU_OUTLINE_POLYGON : constant GLUenum := 100240;
GLU_OUTLINE_PATCH : constant GLUenum := 100241;
GLU_NURBS_ERROR1 : constant GLUenum := 100251;
GLU_NURBS_ERROR2 : constant GLUenum := 100252;
GLU_NURBS_ERROR3 : constant GLUenum := 100253;
GLU_NURBS_ERROR4 : constant GLUenum := 100254;
GLU_NURBS_ERROR5 : constant GLUenum := 100255;
GLU_NURBS_ERROR6 : constant GLUenum := 100256;
GLU_NURBS_ERROR7 : constant GLUenum := 100257;
GLU_NURBS_ERROR8 : constant GLUenum := 100258;
GLU_NURBS_ERROR9 : constant GLUenum := 100259;
GLU_NURBS_ERROR10 : constant GLUenum := 100260;
GLU_NURBS_ERROR11 : constant GLUenum := 100261;
GLU_NURBS_ERROR12 : constant GLUenum := 100262;
GLU_NURBS_ERROR13 : constant GLUenum := 100263;
GLU_NURBS_ERROR14 : constant GLUenum := 100264;
GLU_NURBS_ERROR15 : constant GLUenum := 100265;
GLU_NURBS_ERROR16 : constant GLUenum := 100266;
GLU_NURBS_ERROR17 : constant GLUenum := 100267;
GLU_NURBS_ERROR18 : constant GLUenum := 100268;
GLU_NURBS_ERROR19 : constant GLUenum := 100269;
GLU_NURBS_ERROR20 : constant GLUenum := 100270;
GLU_NURBS_ERROR21 : constant GLUenum := 100271;
GLU_NURBS_ERROR22 : constant GLUenum := 100272;
GLU_NURBS_ERROR23 : constant GLUenum := 100273;
GLU_NURBS_ERROR24 : constant GLUenum := 100274;
GLU_NURBS_ERROR25 : constant GLUenum := 100275;
GLU_NURBS_ERROR26 : constant GLUenum := 100276;
GLU_NURBS_ERROR27 : constant GLUenum := 100277;
GLU_NURBS_ERROR28 : constant GLUenum := 100278;
GLU_NURBS_ERROR29 : constant GLUenum := 100279;
GLU_NURBS_ERROR30 : constant GLUenum := 100280;
GLU_NURBS_ERROR31 : constant GLUenum := 100281;
GLU_NURBS_ERROR32 : constant GLUenum := 100282;
GLU_NURBS_ERROR33 : constant GLUenum := 100283;
GLU_NURBS_ERROR34 : constant GLUenum := 100284;
GLU_NURBS_ERROR35 : constant GLUenum := 100285;
GLU_NURBS_ERROR36 : constant GLUenum := 100286;
GLU_NURBS_ERROR37 : constant GLUenum := 100287;
GLU_INVALID_ENUM : constant GLUenum := 100900;
GLU_INVALID_VALUE : constant GLUenum := 100901;
GLU_OUT_OF_MEMORY : constant GLUenum := 100902;
GLU_INCOMPATIBLE_GL_VERSION : constant GLUenum := 100903;
GLU_VERSION : constant GLUenum := 100800;
GLU_EXTENSIONS : constant GLUenum := 100801;
-- Normal vectors
-- Quadric draw styles
-- Quadric orientation
-- Tesselator
-- Contour types
-- Tesselation errors
-- NURBS
-- Errors
-- New in GLU 1.1
--
-- These are the GLU 1.1 typedefs. GLU 1.2 has different ones!
--
type GLUquadricObj is new Interfaces.C.Extensions.opaque_structure_def;
type GLUquadricObj_Ptr is access GLUquadricObj;
type GLUtriangulatorObj is new Interfaces.C.Extensions.opaque_structure_def;
type GLUtriangulatorObj_Ptr is access GLUtriangulatorObj;
type GLUnurbsObj is new Interfaces.C.Extensions.opaque_structure_def;
type GLUnurbsObj_Ptr is access GLUnurbsObj;
--
-- Miscellaneous functions
--
procedure gluLookAt (eyex : Gl_H.GLdouble;
eyey : Gl_H.GLdouble;
eyez : Gl_H.GLdouble;
centerx : Gl_H.GLdouble;
centery : Gl_H.GLdouble;
centerz : Gl_H.GLdouble;
upx : Gl_H.GLdouble;
upy : Gl_H.GLdouble;
upz : Gl_H.GLdouble);
procedure gluOrtho2D (left : Gl_H.GLdouble;
right : Gl_H.GLdouble;
bottom : Gl_H.GLdouble;
top : Gl_H.GLdouble);
procedure gluPerspective (fovy : Gl_H.GLdouble;
aspect : Gl_H.GLdouble;
zNear : Gl_H.GLdouble;
zFar : Gl_H.GLdouble);
procedure gluPickMatrix (x : Gl_H.GLdouble;
y : Gl_H.GLdouble;
width : Gl_H.GLdouble;
height : Gl_H.GLdouble;
viewport : Gl_H.GLint_Vec_4);
function gluProject (objx : Gl_H.GLdouble;
objy : Gl_H.GLdouble;
objz : Gl_H.GLdouble;
modelMatrix : Gl_H.GLdouble_Vec_16;
projMatrix : Gl_H.GLdouble_Vec_16;
viewport : Gl_H.GLint_Vec_4;
winx : access Gl_H.GLdouble;
winy : access Gl_H.GLdouble;
winz : access Gl_H.GLdouble) return Gl_H.GLint;
function gluUnProject
(winx : Gl_H.GLdouble;
winy : Gl_H.GLdouble;
winz : Gl_H.GLdouble;
modelMatrix : Gl_H.GLdouble_Vec_16;
projMatrix : Gl_H.GLdouble_Vec_16;
viewport : Gl_H.GLint_Vec_4;
objx : access Gl_H.GLdouble;
objy : access Gl_H.GLdouble;
objz : access Gl_H.GLdouble) return Gl_H.GLint;
function gluErrorString (errorCode : Gl_H.GLenum) return Gl_H.GLubyte_Ptr;
--
-- Mipmapping and image scaling
--
function gluScaleImage
(format : Gl_H.GLenum;
widthin : Gl_H.GLint;
heightin : Gl_H.GLint;
typein : Gl_H.GLenum;
datain : Interfaces.C.Extensions.Void_Ptr;
widthout : Gl_H.GLint;
heightout : Gl_H.GLint;
typeout : Gl_H.GLenum;
dataout : Interfaces.C.Extensions.Void_Ptr) return Gl_H.GLint;
function gluBuild1DMipmaps
(target : Gl_H.GLenum;
components : Gl_H.GLint;
width : Gl_H.GLint;
format : Gl_H.GLenum;
type_Id : Gl_H.GLenum;
data : Interfaces.C.Extensions.Void_Ptr) return Gl_H.GLint;
function gluBuild2DMipmaps
(target : Gl_H.GLenum;
components : Gl_H.GLint;
width : Gl_H.GLint;
height : Gl_H.GLint;
format : Gl_H.GLenum;
type_Id : Gl_H.GLenum;
data : Interfaces.C.Extensions.Void_Ptr) return Gl_H.GLint;
--
-- Quadrics
--
function gluNewQuadric return GLUquadricObj_Ptr;
procedure gluDeleteQuadric (state : access GLUquadricObj);
procedure gluQuadricDrawStyle (quadObject : access GLUquadricObj;
drawStyle : Gl_H.GLenum);
procedure gluQuadricOrientation (quadObject : access GLUquadricObj;
orientation : Gl_H.GLenum);
procedure gluQuadricNormals (quadObject : access GLUquadricObj;
normals : Gl_H.GLenum);
procedure gluQuadricTexture (quadObject : access GLUquadricObj;
textureCoords : Gl_H.GLboolean);
type glu_h_proc_1 is access procedure;
procedure gluQuadricCallback (qobj : access GLUquadricObj;
which : Gl_H.GLenum;
fn : glu_h_proc_1);
procedure gluCylinder (qobj : access GLUquadricObj;
baseRadius : Gl_H.GLdouble;
topRadius : Gl_H.GLdouble;
height : Gl_H.GLdouble;
slices : Gl_H.GLint;
stacks : Gl_H.GLint);
procedure gluSphere (qobj : access GLUquadricObj;
radius : Gl_H.GLdouble;
slices : Gl_H.GLint;
stacks : Gl_H.GLint);
procedure gluDisk (qobj : access GLUquadricObj;
innerRadius : Gl_H.GLdouble;
outerRadius : Gl_H.GLdouble;
slices : Gl_H.GLint;
loops : Gl_H.GLint);
procedure gluPartialDisk (qobj : access GLUquadricObj;
innerRadius : Gl_H.GLdouble;
outerRadius : Gl_H.GLdouble;
slices : Gl_H.GLint;
loops : Gl_H.GLint;
startAngle : Gl_H.GLdouble;
sweepAngle : Gl_H.GLdouble);
--
-- Nurbs
--
function gluNewNurbsRenderer return GLUnurbsObj_Ptr;
procedure gluDeleteNurbsRenderer (nobj : access GLUnurbsObj);
procedure gluLoadSamplingMatrices (nobj : access GLUnurbsObj;
modelMatrix : Gl_H.GLfloat_Vec_16;
projMatrix : Gl_H.GLfloat_Vec_16;
viewport : Gl_H.GLint_Vec_4);
procedure gluNurbsProperty (nobj : access GLUnurbsObj;
property : Gl_H.GLenum;
value : Gl_H.GLfloat);
procedure gluGetNurbsProperty (nobj : access GLUnurbsObj;
property : Gl_H.GLenum;
value : access Gl_H.GLfloat);
procedure gluBeginCurve (nobj : access GLUnurbsObj);
procedure gluEndCurve (nobj : access GLUnurbsObj);
procedure gluNurbsCurve (nobj : access GLUnurbsObj;
nknots : Gl_H.GLint;
knot : access Gl_H.GLfloat;
stride : Gl_H.GLint;
ctlarray : access Gl_H.GLfloat;
order : Gl_H.GLint;
type_Id : Gl_H.GLenum);
procedure gluBeginSurface (nobj : access GLUnurbsObj);
procedure gluEndSurface (nobj : access GLUnurbsObj);
procedure gluNurbsSurface (nobj : access GLUnurbsObj;
sknot_count : Gl_H.GLint;
sknot : access Gl_H.GLfloat;
tknot_count : Gl_H.GLint;
tknot : access Gl_H.GLfloat;
s_stride : Gl_H.GLint;
t_stride : Gl_H.GLint;
ctlarray : access Gl_H.GLfloat;
sorder : Gl_H.GLint;
torder : Gl_H.GLint;
type_Id : Gl_H.GLenum);
procedure gluBeginTrim (nobj : access GLUnurbsObj);
procedure gluEndTrim (nobj : access GLUnurbsObj);
procedure gluPwlCurve (nobj : access GLUnurbsObj;
count : Gl_H.GLint;
array_Id : access Gl_H.GLfloat;
stride : Gl_H.GLint;
type_Id : Gl_H.GLenum);
type glu_h_proc_2 is access procedure;
procedure gluNurbsCallback (nobj : access GLUnurbsObj;
which : Gl_H.GLenum;
fn : glu_h_proc_2);
--
-- Polygon tesselation
--
function gluNewTess return GLUtriangulatorObj_Ptr;
type glu_h_proc_3 is access procedure;
procedure gluTessCallback (tobj : access GLUtriangulatorObj;
which : Gl_H.GLenum;
fn : glu_h_proc_3);
procedure gluDeleteTess (tobj : access GLUtriangulatorObj);
procedure gluBeginPolygon (tobj : access GLUtriangulatorObj);
procedure gluEndPolygon (tobj : access GLUtriangulatorObj);
procedure gluNextContour (tobj : access GLUtriangulatorObj;
type_Id : Gl_H.GLenum);
procedure gluTessVertex (tobj : access GLUtriangulatorObj;
v : Gl_H.GLdouble_Vec_3;
data : Interfaces.C.Extensions.Void_Ptr);
--
-- New functions in GLU 1.1
--
function gluGetString (name : Gl_H.GLenum) return Gl_H.GLubyte_Ptr;
private
pragma Import (C, gluLookAt, "gluLookAt");
pragma Import (C, gluOrtho2D, "gluOrtho2D");
pragma Import (C, gluPerspective, "gluPerspective");
pragma Import (C, gluPickMatrix, "gluPickMatrix");
pragma Import (C, gluProject, "gluProject");
pragma Import (C, gluUnProject, "gluUnProject");
pragma Import (C, gluErrorString, "gluErrorString");
pragma Import (C, gluScaleImage, "gluScaleImage");
pragma Import (C, gluBuild1DMipmaps, "gluBuild1DMipmaps");
pragma Import (C, gluBuild2DMipmaps, "gluBuild2DMipmaps");
pragma Import (C, gluNewQuadric, "gluNewQuadric");
pragma Import (C, gluDeleteQuadric, "gluDeleteQuadric");
pragma Import (C, gluQuadricDrawStyle, "gluQuadricDrawStyle");
pragma Import (C, gluQuadricOrientation, "gluQuadricOrientation");
pragma Import (C, gluQuadricNormals, "gluQuadricNormals");
pragma Import (C, gluQuadricTexture, "gluQuadricTexture");
pragma Import (C, gluQuadricCallback, "gluQuadricCallback");
pragma Import (C, gluCylinder, "gluCylinder");
pragma Import (C, gluSphere, "gluSphere");
pragma Import (C, gluDisk, "gluDisk");
pragma Import (C, gluPartialDisk, "gluPartialDisk");
pragma Import (C, gluNewNurbsRenderer, "gluNewNurbsRenderer");
pragma Import (C, gluDeleteNurbsRenderer, "gluDeleteNurbsRenderer");
pragma Import (C, gluLoadSamplingMatrices, "gluLoadSamplingMatrices");
pragma Import (C, gluNurbsProperty, "gluNurbsProperty");
pragma Import (C, gluGetNurbsProperty, "gluGetNurbsProperty");
pragma Import (C, gluBeginCurve, "gluBeginCurve");
pragma Import (C, gluEndCurve, "gluEndCurve");
pragma Import (C, gluNurbsCurve, "gluNurbsCurve");
pragma Import (C, gluBeginSurface, "gluBeginSurface");
pragma Import (C, gluEndSurface, "gluEndSurface");
pragma Import (C, gluNurbsSurface, "gluNurbsSurface");
pragma Import (C, gluBeginTrim, "gluBeginTrim");
pragma Import (C, gluEndTrim, "gluEndTrim");
pragma Import (C, gluPwlCurve, "gluPwlCurve");
pragma Import (C, gluNurbsCallback, "gluNurbsCallback");
pragma Import (C, gluNewTess, "gluNewTess");
pragma Import (C, gluTessCallback, "gluTessCallback");
pragma Import (C, gluDeleteTess, "gluDeleteTess");
pragma Import (C, gluBeginPolygon, "gluBeginPolygon");
pragma Import (C, gluEndPolygon, "gluEndPolygon");
pragma Import (C, gluNextContour, "gluNextContour");
pragma Import (C, gluTessVertex, "gluTessVertex");
pragma Import (C, gluGetString, "gluGetString");
end glu_h;
|
with TTS_Example_A;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Real_Time;
with Ada.Text_IO; use Ada.Text_IO;
with System;
procedure Main_A
with Priority => System.Priority'First
is
begin
TTS_Example_A.Main;
delay until Ada.Real_Time.Time_Last;
exception
when E : others =>
Put_Line (Exception_Message (E));
end Main_A;
|
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Command_Line; use Ada.Command_Line;
with GNAT.Command_Line; use GNAT.Command_Line;
with Ada.Environment_Variables;
with Ada.Directories; use Ada.Directories;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with Ada.Containers.Indefinite_Hashed_Maps; use Ada.Containers;
with Ada; use Ada;
with Ada.Command_Line.Environment;
procedure Xterm is
-- Ada_Launch is the default name, but is meant to be renamed
-- to the executable or app name that this executable launches
package Env renames Ada.Environment_Variables;
package Cl renames Ada.Command_Line;
package Clenv renames Ada.Command_Line.Environment;
package Files renames Ada.Directories;
-- Env, CL, and CLenv are just abbreviations for:
-- Environment_Variables, Command_Line, and Command_Line.Environment
-- xterm -bg black -fg white +sb +sm -fn 10x20 -sl 4000 -cr yellow
Launch_Name : String := Locate_Exec_On_Path ("/usr/bin/xterm").all;
Xterm_Background : String := "black";
Xterm_Foreground : String := "white";
Xterm_Scrollbar : Boolean := False;
Xterm_Sessionmanagementcallbacks : Boolean := False;
Xterm_Loginshell : Boolean := False;
Xterm_Font : String :=
"-gnu-unifont-medium-r-normal-sans-16-160-75-75-c-80-iso10646-1";
Xterm_Lineshistory : String := "4000";
Xterm_Cursorcolor : String := "yellow";
Launch_Num_Of_Arguments : Integer := 13;
Env_Display : String := Env.Value ("DISPLAY", ":0");
--Launch_Name : String := "/bin/" & Simple_Name (Command_Name);
-- The file name to execute/launch
Launch_Arguments : GNAT.OS_Lib
.Argument_List
(1 .. Argument_Count + Launch_Num_Of_Arguments);
-- The arguments to give the executable
Launch_Status : Boolean;
-- The return status of the command + arguments
begin
-- Env.Clear;
-- Env.Set ("DISPLAY", Env_Display);
Launch_Arguments (1) := new String'("-bg");
Launch_Arguments (2) := new String'(Xterm_Background);
Launch_Arguments (3) := new String'("-fg");
Launch_Arguments (4) := new String'(Xterm_Foreground);
if Xterm_Scrollbar then
Launch_Arguments (5) := new String'("-sb");
else
Launch_Arguments (5) := new String'("+sb");
end if;
if Xterm_Sessionmanagementcallbacks then
Launch_Arguments (6) := new String'("-sm");
else
Launch_Arguments (6) := new String'("+sm");
end if;
if Xterm_Loginshell then
Launch_Arguments (7) := new String'("-ls");
else
Launch_Arguments (7) := new String'("+ls");
end if;
Launch_Arguments (8) := new String'("-fn");
Launch_Arguments (9) := new String'(Xterm_Font);
Launch_Arguments (10) := new String'("-sl");
Launch_Arguments (11) := new String'(Xterm_Lineshistory);
Launch_Arguments (12) := new String'("-cr");
Launch_Arguments (13) := new String'(Xterm_Cursorcolor);
for N in 1 .. Argument_Count loop
Launch_Arguments (N + Launch_Num_Of_Arguments) :=
new String'(Argument (N));
end loop;
-- Simply copy/convey all arguments to the new command launch.
--Put_Line (Launch_Name);
-- DEBUG ACTION - remove this statement when the performance is sufficient.
if Files.Exists (Launch_Name) then
Spawn (Launch_Name, Launch_Arguments, Launch_Status);
-- Launch the new process with conveyed arguments and capture general
-- return status as Success or Failure. A number may be used in the future.
else
Launch_Status := False;
end if;
if not Launch_Status then
Set_Exit_Status (Failure);
else
Set_Exit_Status (Success);
end if;
--Give return status back to calling os/environment.
end Xterm;
|
with Employee_Data;
package Timecards is
type Hours_Worked_T is new Integer; -- better implementation
type Pay_T is new Integer; -- better implementation
type Timecard_T is limited private;
function Create
(Name : String;
Rate : Employee_Data.Hourly_Rate_T;
Hours : Hours_Worked_T)
return Timecard_T;
function Id
(Timecard : Timecard_T)
return Employee_Data.Id_T;
function Name
(Timecard : Timecard_T)
return String;
function Rate
(Timecard : Timecard_T)
return Employee_Data.Hourly_Rate_T;
function Pay
(Timecard : Timecard_T)
return Pay_T;
function Image
(Timecard : Timecard_T)
return String;
private
-- finish implementation
type Timecard_T is limited null record;
end Timecards;
|
with
AdaM.Factory,
AdaM.a_Package,
ada.Tags;
package body AdaM.a_Type
is
-- Forge
--
procedure destruct (Self : in out Item)
is
begin
raise Program_Error with "'adam.a_Type' subclasses must override the 'destruct' procedure";
end destruct;
-- Attributes
--
overriding
function Name (Self : in Item) return Identifier
is
begin
return +Self.Name;
end Name;
procedure Name_is (Self : in out Item; Now : in String)
is
begin
Self.Name := +Now;
end Name_is;
function full_Name (Self : in Item) return Identifier
is
use type Entity.view;
begin
if Self.parent_Entity = null
then
return "Standard." & (+Self.Name);
else
return a_Package.view (Self.parent_Entity).full_Name & "." & (+Self.Name);
end if;
end full_Name;
-- Streams
--
procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : in View)
is
use Ada.Tags;
begin
if Self = null
then
AdaM.Id'write (Stream, null_Id);
return;
end if;
AdaM.Id'write (Stream, Self.Id);
String 'output (Stream, external_Tag (Self.all'Tag));
end View_write;
procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : out View)
is
Id : AdaM.Id;
begin
AdaM.Id'read (Stream, Id);
if Id = null_Id
then
Self := null;
return;
end if;
declare
use Ada.Tags;
the_String : constant String := String'Input (Stream); -- Read tag as string from stream.
the_Tag : constant Tag := Descendant_Tag (the_String, Item'Tag); -- Convert to a tag.
begin
Self := View (AdaM.Factory.to_View (Id, the_Tag));
end;
end View_read;
end AdaM.a_Type;
|
-----------------------------------------------------------------------
-- babel-streams-cached -- Cached stream management
-- Copyright (C) 2014, 2015 Stephane.Carrez
-- Written by Stephane.Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
package body Babel.Streams.Cached is
package BAV renames Babel.Files.Buffers.Buffer_Access_Vectors;
-- ------------------------------
-- Load the file stream into the cache and use the buffer pool to obtain more buffers
-- for the cache.
-- ------------------------------
procedure Load (Stream : in out Stream_Type;
File : in out Babel.Streams.Stream_Type'Class;
Pool : in out Babel.Files.Buffers.Buffer_Pool) is
use type Babel.Files.Buffers.Buffer_Access;
Buffer : Babel.Files.Buffers.Buffer_Access;
begin
loop
File.Read (Buffer);
exit when Buffer = null;
Stream.Buffers.Append (Buffer);
Pool.Get_Buffer (Buffer);
File.Set_Buffer (Buffer);
end loop;
Stream.Current := Stream.Buffers.First;
end Load;
-- ------------------------------
-- Read the data stream as much as possible and return the result in a buffer.
-- The buffer is owned by the stream and need not be released. The same buffer may
-- or may not be returned by the next <tt>Read</tt> operation.
-- A null buffer is returned when the end of the data stream is reached.
-- ------------------------------
overriding
procedure Read (Stream : in out Stream_Type;
Buffer : out Babel.Files.Buffers.Buffer_Access) is
begin
if BAV.Has_Element (Stream.Current) then
Buffer := BAV.Element (Stream.Current);
BAV.Next (Stream.Current);
else
Buffer := null;
end if;
end Read;
-- ------------------------------
-- Write the buffer in the data stream.
-- ------------------------------
overriding
procedure Write (Stream : in out Stream_Type;
Buffer : in Babel.Files.Buffers.Buffer_Access) is
begin
null;
end Write;
-- ------------------------------
-- Prepare to read again the data stream from the beginning.
-- ------------------------------
overriding
procedure Rewind (Stream : in out Stream_Type) is
begin
Stream.Current := Stream.Buffers.First;
end Rewind;
-- ------------------------------
-- Release the buffers associated with the cache.
-- ------------------------------
overriding
procedure Finalize (Stream : in out Stream_Type) is
Buffer : Babel.Files.Buffers.Buffer_Access;
begin
while not Stream.Buffers.Is_Empty loop
Buffer := Stream.Buffers.Last_Element;
Babel.Files.Buffers.Release (Buffer);
Stream.Buffers.Delete_Last;
end loop;
Babel.Streams.Stream_Type (Stream).Finalize;
end Finalize;
end Babel.Streams.Cached;
|
private with Ada.Finalization;
with Ada.Strings.Unbounded;
private with Interfaces;
private with Interfaces.C;
private with Interfaces.C.Strings;
private with Interfaces.C.Pointers;
private with System;
package YAML is
type UTF8_String is new String;
type Document_Type is tagged limited private;
-- Holder for a YAML document
type Document_Handle (Document : access Document_Type) is
tagged private
with Implicit_Dereference => Document;
-- Reference-counting reference to a dynamically allocated document. Create
-- such references to new Documents using the Create function below.
function "=" (Left, Right : Document_Handle'Class) return Boolean is
(Left.Document = Right.Document);
No_Document_Handle : constant Document_Handle;
-- Special value to mean: no reference. Think of it as a null access.
function Create return Document_Handle;
-- Create a dynamically allocated document and return a handle to it
type Node_Kind is
(No_Node,
-- An empty node
Scalar_Node,
-- A scalar node
Sequence_Node,
-- A sequence node
Mapping_Node
-- A mapping node
) with
Convention => C;
-- Type of a node in a document
type Mark_Type is record
Line, Column : Positive;
end record;
-- Position in a YAML file
type Node_Ref is tagged private;
-- Reference to a node as part of a document. Such values must not outlive
-- the value for the document that owns them.
No_Node_Ref : constant Node_Ref;
function Root_Node (Document : Document_Type'Class) return Node_Ref;
-- Return the root node of a document, or No_Node_Ref for an empty
-- document.
function Start_Mark (Document : Document_Type'Class) return Mark_Type;
-- Return Document's starting position
function End_Mark (Document : Document_Type'Class) return Mark_Type;
-- Return Document's ending position
function Kind (Node : Node_Ref'Class) return Node_Kind;
-- Return the type of a node
function Start_Mark (Node : Node_Ref'Class) return Mark_Type;
-- Return Node's starting position
function End_Mark (Node : Node_Ref'Class) return Mark_Type;
-- Return Node's ending position
function Value (Node : Node_Ref'Class) return UTF8_String
with Pre => Kind (Node) = Scalar_Node;
function Length (Node : Node_Ref'Class) return Natural
with Pre => Kind (Node) in Sequence_Node | Mapping_Node;
-- Return the number of items in the Node sequence/mapping
function Item (Node : Node_Ref'Class; Index : Positive) return Node_Ref
with Pre => Kind (Node) = Sequence_Node
and then Index <= Length (Node);
-- Return the Index'th item in Node. Index is 1-based.
type Node_Pair is record
Key, Value : Node_Ref;
end record;
-- Key/value asssociation in a mapping node
function Item (Node : Node_Ref'Class; Index : Positive) return Node_Pair
with Pre => Kind (Node) = Mapping_Node
and then Index <= Length (Node);
-- Return the Index'th key/value association in Node. Index is 1-based.
function Item (Node : Node_Ref'Class; Key : UTF8_String) return Node_Ref
with Pre => Kind (Node) = Mapping_Node;
-- Look for Key in the Node mapping. If there is one, return the
-- corresponding Value. Return No_Node_Ref otherwise.
type Error_Kind is
(No_Error,
-- No error is produced
Memory_Error,
-- Cannot allocate or reallocate a block of memory
Reader_Error,
-- Cannot read or decode the input stream
Scanner_Error,
-- Cannot scan the input stream
Parser_Error,
-- Cannot parse the input stream
Composer_Error,
-- Cannot compose a YAML document
Writer_Error,
-- Cannot write to the output stream
Emitter_Error
-- Cannot emit a YAML stream
) with Convention => C;
-- Many bad things could happen with the parser and the emitter. Note: as
-- this Ada binding does not cover the emitter yet, some errors cannot
-- occur.
type Error_Type (Kind : Error_Kind := No_Error) is record
Problem : Ada.Strings.Unbounded.Unbounded_String;
-- Error description
case Kind is
when No_Error => null;
when Reader_Error =>
Problem_Offset : Natural;
-- The byte about which the problem occured
Problem_Value : Integer;
-- The problematic value (-1 is none)
when Scanner_Error | Parser_Error =>
Context : Ada.Strings.Unbounded.Unbounded_String;
-- Error context
Context_Mark : Mark_Type;
-- Context position
Problem_Mark : Mark_Type;
-- Problem position
when Composer_Error => null;
when Memory_Error | Writer_Error | Emitter_Error => null;
end case;
end record;
function Image (Error : Error_Type) return String;
-- Return a human-readable representation of Error
type Parser_Type is tagged limited private;
-- YAML document parser
function Has_Input (P : Parser_Type'Class) return Boolean;
-- Return whether a Set_Input_* procedure was called on P
type Encoding_Type is
(Any_Encoding,
-- Let the parser choose the encoding
UTF8_Encoding,
-- The default UTF-8 encoding
UTF16LE_Encoding,
-- The UTF-16-LE encoding with BOM
UTF16BE_Encoding
-- The UTF-16-BE encoding with BOM
) with
Convention => C;
-- Stream encoding
procedure Set_Input_String
(Parser : in out Parser_Type'Class;
Input : String;
Encoding : Encoding_Type)
with Pre => not Parser.Has_Input;
-- Set a string input. This maintains a copy of Input in Parser.
File_Error : exception;
-- Exception raised when file-related errors occurs. For instance: cannot
-- open a file, cannot read a file, etc.
procedure Set_Input_File
(Parser : in out Parser_Type'Class;
Filename : String;
Encoding : Encoding_Type)
with Pre => not Parser.Has_Input;
-- Set a file input. This opens Filename until the parser is destroyed or
-- until another Set_Input_* procedure is successfuly called. If an error
-- occurs while opening the file, raise a File_Error and leave the parser
-- unmodified.
procedure Discard_Input (Parser : in out Parser_Type'Class);
-- If Parser was assigned an input, discard it
procedure Load
(Parser : in out Parser_Type'Class;
Error : out Error_Type;
Document : in out Document_Type'Class)
with Pre => Parser.Has_Input;
-- Parse the input stream and produce the next YAML document.
--
-- Call this function subsequently to produce a sequence of documents
-- constituting the input stream. If the produced document has no root
-- node, it means that the document end has been reached.
--
-- If upon return Error.Kind is different than No_Error, Document must be
-- considered as garbage.
private
subtype C_Int is Interfaces.C.int;
subtype C_Index is C_Int range 0 .. C_Int'Last;
subtype C_Size_T is Interfaces.C.size_t;
subtype C_Ptr_Diff is Interfaces.C.ptrdiff_t;
type C_Char_Array is array (C_Index) of Interfaces.Unsigned_8;
type C_Char_Access is access all C_Char_Array;
type C_Node_T;
type C_Node_Access is access all C_Node_T;
type C_Scalar_Style_T is
(Any_Scalar_Style,
Plain_Scalar_Style,
Single_Quoted_Scalar_Style,
Double_Quoted_Scalar_Style,
Literal_Scalar_Style,
Folded_Scalar_Style) with
Convention => C;
-- Scalar styles
type C_Sequence_Style_T is
(Any_Sequence_Style,
Block_Sequence_Style,
Flow_Sequence_Style) with
Convention => C;
-- Sequence styles
type C_Mapping_Style_T is
(Any_Mapping_Style,
Block_Mapping_Style,
Flow_Mapping_Style) with
Convention => C;
-- Mapping styles
type C_Mark_T is record
Index, Line, Column : Interfaces.C.size_t;
end record with
Convention => C_Pass_By_Copy;
-- The pointer position
type C_Version_Directive_T is record
Major, Minor : C_Int;
-- Major and minor version numbers
end record with
Convention => C_Pass_By_Copy;
-- The version directive data
type C_Version_Directive_Access is access all C_Version_Directive_T;
type C_Tag_Directive_T is record
Handle : C_Char_Access;
-- The tag handle
Prefix : C_Char_Access;
-- The tag prefix
end record with
Convention => C_Pass_By_Copy;
-- The tag directive data
type C_Tag_Directive_Access is access C_Tag_Directive_T;
subtype C_Node_Item_T is C_Int;
type C_Node_Item_Array is array (C_Index range <>) of aliased C_Node_Item_T;
package C_Node_Item_Accesses is new Interfaces.C.Pointers
(Index => C_Index,
Element => C_Node_Item_T,
Element_Array => C_Node_Item_Array,
Default_Terminator => -1);
subtype C_Node_Item_Access is C_Node_Item_Accesses.Pointer;
type C_Node_Pair_T is record
Key, Value : C_Int;
end record with
Convention => C_Pass_By_Copy;
type C_Node_Pair_Array is array (C_Index range <>) of aliased C_Node_Pair_T;
package C_Node_Pair_Accesses is new Interfaces.C.Pointers
(Index => C_Index,
Element => C_Node_Pair_T,
Element_Array => C_Node_Pair_Array,
Default_Terminator => (-1, -1));
subtype C_Node_Pair_Access is C_Node_Pair_Accesses.Pointer;
----------------------------
-- Node structure binding --
----------------------------
type C_Scalar_Node_Data is record
Value : C_Char_Access;
-- The scalar value
Length : Interfaces.C.size_t;
-- The length of the scalar value
Style : C_Scalar_Style_T;
-- The scalar style
end record with
Convention => C_Pass_By_Copy;
type C_Sequence_Items is record
Seq_Start, Seq_End, Seq_Top : C_Node_Item_Access;
end record with
Convention => C_Pass_By_Copy;
type C_Sequence_Node_Data is record
Items : C_Sequence_Items;
-- The stack of sequence items
Style : C_Sequence_Style_T;
-- The sequence style
end record with
Convention => C_Pass_By_Copy;
type C_Mapping_Pairs is record
Map_Start, Map_End, Map_Top : C_Node_Pair_Access;
end record with
Convention => C_Pass_By_Copy;
type C_Mapping_Node_Data is record
Pairs : C_Mapping_Pairs;
-- The stack of mapping pairs
Style : C_Mapping_Style_T;
-- The mapping style
end record with
Convention => C_Pass_By_Copy;
type C_Node_Data (Dummy : Node_Kind := No_Node) is record
case Dummy is
when No_Node =>
null;
when Scalar_Node =>
Scalar : C_Scalar_Node_Data;
-- The scalar parameters (for Scalar_Node)
when Sequence_Node =>
Sequence : C_Sequence_Node_Data;
-- The sequence parameters (for Sequence_Node)
when Mapping_Node =>
Mapping : C_Mapping_Node_Data;
-- The mapping parameters (for Mapping_Node)
end case;
end record with
Convention => C_Pass_By_Copy,
Unchecked_Union;
type C_Node_T is record
Kind : Node_Kind;
-- The node type
Tag : C_Char_Access;
-- The node tag
Data : C_Node_Data;
-- The node data
Start_Mark, End_Mark : C_Mark_T;
end record with
Convention => C_Pass_By_Copy;
--------------------------------
-- Document structure binding --
--------------------------------
type C_Document_Nodes is record
Start_Node, End_Node, Top_Node : C_Node_T;
-- Begining, end and top of the stack
end record with
Convention => C_Pass_By_Copy;
type C_Tag_Directives is record
Start_Dir, End_Dir : C_Tag_Directive_Access;
-- Beginning and end of the tag directives list
end record with
Convention => C_Pass_By_Copy;
type C_Document_T is record
Nodes : C_Document_Nodes;
-- The document nodes
Version_Directives : C_Version_Directive_Access;
-- The version directive
Tag_Directives : C_Tag_Directives;
-- The list of tag directives
Start_Implicit, End_Implicit : C_Int;
-- Is the document start/end indicator explicit?
Start_Mark, End_Mark : C_Mark_T;
-- Beginning and end of the document
end record with
Convention => C_Pass_By_Copy;
-- The document structure
type C_Document_Access is access all C_Document_T;
-------------------------
-- High-level Wrappers --
-------------------------
type Document_Type is limited new Ada.Finalization.Limited_Controlled
with record
C_Doc : aliased C_Document_T;
-- Inlined C document structure. This is the reason Document_Type is
-- limited.
Ref_Count : Natural;
-- Reference counter for Document_Handle. The document must be deleted
-- when the count drops to 0.
To_Delete : Boolean;
-- Whether C_Doc has been initialized. In this case, it must be deleted
-- during finalization.
end record;
overriding procedure Initialize (Document : in out Document_Type);
overriding procedure Finalize (Document : in out Document_Type);
type Document_Access is access all Document_Type;
type Document_Handle (Document : access Document_Type) is new
Ada.Finalization.Controlled with null record;
overriding procedure Adjust (Handle : in out Document_Handle);
overriding procedure Finalize (Handle : in out Document_Handle);
procedure Inc_Ref (Handle : in out Document_Handle'Class);
procedure Dec_Ref (Handle : in out Document_Handle'Class);
No_Document_Handle : constant Document_Handle :=
(Ada.Finalization.Controlled with Document => null);
type Node_Ref is tagged record
Node : C_Node_Access;
-- The referenced node
Document : Document_Access;
-- The document it belongs to
end record;
No_Node_Ref : constant Node_Ref := (null, null);
type C_Parser_Access is new System.Address;
type String_Access is access String;
type C_Parser_Error_View is record
Error : Error_Kind;
Problem : Interfaces.C.Strings.chars_ptr;
Problem_Offset : C_Size_T;
Problem_Value : C_Int;
Problem_Mark : C_Mark_T;
Context : Interfaces.C.Strings.chars_ptr;
Context_Mark : C_Mark_T;
end record with
Convention => C_Pass_By_Copy;
-- Partial view on the yaml_parser_s C structure. Used to access error
-- flags.
type C_File_Ptr is new System.Address;
No_File_Ptr : constant C_File_Ptr := C_File_Ptr (System.Null_Address);
type Parser_Type is limited new Ada.Finalization.Limited_Controlled
with record
C_Parser : C_Parser_Access;
Input_Encoding : Encoding_Type;
Input_String : String_Access;
Input_File : C_File_Ptr;
end record;
overriding procedure Initialize (Parser : in out Parser_Type);
overriding procedure Finalize (Parser : in out Parser_Type);
end YAML;
|
------------------------------------------------------------------------------
-- --
-- Ada User Repository Annex (AURA) --
-- ANNEXI-STRAYLINE Reference Implementation --
-- --
-- Core --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2020-2021, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * Richard Wai (ANNEXI-STRAYLINE) --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- --
-- * Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A --
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with Ada.Assertions;
with Ada.Containers;
with Ada.Directories;
with Ada.Characters.Conversions;
with Ada.Streams.Stream_IO;
with Ada_Lexical_Parser;
with Unit_Names.Sets;
with Registrar.Registry;
with Registrar.Subsystems;
with Registrar.Library_Units;
with Registrar.Registration;
with Registrar.Source_Files.Allocation;
with Registrar.Executive.Library_Units_Request;
with Registrar.Executive.Library_Unit_Registration;
separate (Registrar.Executive.Unit_Entry)
procedure Execute (Order: in out Unit_Entry_Order) is
use Registrar.Library_Units;
use Registrar.Executive.Library_Units_Request;
use Registrar.Executive.Library_Unit_Registration;
use Registrar.Source_Files;
use type Ada.Containers.Count_Type;
function To_Wide_Wide_String (Item: in String) return Wide_Wide_String
renames Ada.Characters.Conversions.To_Wide_Wide_String;
New_Unit_Registration: Library_Unit_Registration_Order (AURA => Order.AURA);
New_Unit: Library_Unit renames New_Unit_Registration.Registrant;
Dependency_Request: Library_Units_Request_Order;
Dependencies : Library_Unit_Sets.Set
renames Dependency_Request.Requested_Units;
use type Unit_Names.Unit_Name;
procedure Assert (Check: in Boolean; Message: in String)
renames Ada.Assertions.Assert;
package Source_Pack is
use Registrar.Source_Files;
type Source_File_Type is (Ada_Spec, Ada_Body, Non_Ada);
subtype Ada_File_Type is Source_File_Type range Ada_Spec .. Ada_Body;
subtype Ada_File_Extension is String (1 .. 4);
Ada_File_Extensions: constant array (Ada_File_Type) of Ada_File_Extension
:= (Ada_Spec => ".ads", Ada_Body => ".adb");
Unit_Source_Type: Source_File_Type;
Source: Source_File_Access := Registrar.Source_Files.Allocation.Open
(UBS.To_String (Order.File_Full_Name));
Stream: aliased Source_Stream := Checkout_Read_Stream (Source);
procedure Discard_Source;
-- Closes Source and then Destroys it.
-- This nullfies Source and makes the Stream unusable
Can_Discard: Boolean := True;
-- Indicates that it is safe to call Discard_Source (which deallocates
-- the Source_File object pointed to by Source). If it is possible that
-- the New_Unit_Registration work order has been submitted,
-- Discard_Source becomes unsafe
end Source_Pack;
package Parse_Pack is
use Ada_Lexical_Parser;
function Content return Wide_Wide_String;
function Category return Lexical_Category;
-- Of the more recent element parsed
procedure Next_Element;
-- Parse the next non-comment element of the Source
procedure Skip_To_Semicolon;
-- Skip all elements until reaching a semi-colon
function File_And_Position return String;
-- Return a string in the format "path/to/file.ads: 12: 1"
procedure Abort_Parse;
-- Raise an Invalid_Unit exception with information identifiying
-- the location of the offending element in the source
end Parse_Pack;
package Process_Pack is
procedure Process_With;
-- All library units including implicitly with'ed parent units of a with
-- statement are included in the Dependencies set.
procedure Process_External_With;
-- All external unit file names of an External_With pragma are staged
-- in lieu of a verified subsystem name, to be included in the
-- Dependencies set during the Process_Declaration phase.
procedure Process_Declaration;
-- Identifies the unit name, or the parent unit name of a subunit,
-- and sets that as the Name of New_Unit
--
-- This also sets the Kind property of the New_Unit
procedure Filter_Standard_Library;
-- Removes from the Dependencies set all units that are part of the
-- standard Ada library (particularily Ada, Interfaces, and GNAT)
procedure Process_Parent_Dependencies;
-- Adds all implicit withs of parent units to the Dependencies set,
procedure Process_Staged_Externals;
-- Prepends New_Unit.Name.Subsystem, plus a '%' to the name of each unit
-- of the set of staged external with units, and then unions that set
-- with Dependencies
end Process_Pack;
package body Source_Pack is separate;
package body Parse_Pack is separate;
package body Process_Pack is separate;
begin
-- Attach trackers
New_Unit_Registration.Tracker := Registration.Entry_Progress'Access;
Dependency_Request.Tracker := Registration.Entry_Progress'Access;
pragma Assert (if Order.AURA then Order.AURA_Subsystem.AURA);
-- First try to classify the source type by file extension. If it does
-- not appear to be an Ada source, we don't even need to open the file,
-- or do any other special processing
declare
use UBS;
use Source_Pack;
File_Name: Unbounded_String renames Order.File_Full_Name;
Last_Dot_Index: Natural := Index (Source => File_Name,
Pattern => ".",
Going => Ada.Strings.Backward);
Extension: Unbounded_String;
begin
pragma Assert (Length (File_Name) > 0);
if Last_Dot_Index > 0 then
Extension := Unbounded_Slice (Source => File_Name,
Low => Last_Dot_Index,
High => Length (File_Name));
end if;
-- Propegate the reported subsystem
if New_Unit_Registration.AURA then
New_Unit_Registration.AURA_Subsystem := Order.AURA_Subsystem;
end if;
if Extension = Ada_File_Extensions (Ada_Spec) then
Unit_Source_Type := Ada_Spec;
elsif Extension = Ada_File_Extensions (Ada_Body) then
Unit_Source_Type := Ada_Body;
else
-- Not an Ada source. Generate external dependency name and enter
-- the unit, to allow it to be refrenced from Ada sources through
-- the AURA-specific pragma External_With
-- The source file itself takes place of the body, for later
-- hashing
-- If the file itself is part of the root project, we make it a
-- conceptual child of standard. Similarily, if we see an external
-- with in a non-AURA unit.
New_Unit.Name.Set_Name
((if Order.AURA then
Order.AURA_Subsystem.Name.To_String
else
"standard")
& '%'
& To_Wide_Wide_String
(Ada.Directories.Simple_Name(To_String (File_Name))));
-- Submit the registration order
New_Unit.State := Available;
New_Unit.Kind := External_Unit;
New_Unit.Body_File := Source;
New_Unit_Registration.Tracker.Increment_Total_Items;
Workers.Enqueue_Order (New_Unit_Registration);
-- We also need to register an empty forward dependency set. We can do
-- a regular Insert which should always work because external units
-- cannot have subunits
declare
Inserted: Boolean;
begin
Registry.Unit_Forward_Dependencies.Insert
(Key => New_Unit.Name,
New_Item => Unit_Names.Sets.Empty_Set,
Inserted => Inserted);
pragma Assert (Inserted);
end;
return;
end if;
end;
-- The New_Unit_Registration order is now filled-out except for the Name,
-- which will be parsed from the Ada source itself
declare
use Ada_Lexical_Parser;
use Parse_Pack;
use Process_Pack;
begin
-- Note that we should not ever reach the end of file before we've
-- finished our job here, so any exception that occurs due to reaching
-- the end of the file causes failure of the entry order as expected
-- Our job is to collect the dependencies (with and pragma
-- External_With), and then verify and register then name of the
-- unit itself. We check for syntax errors were possible, and if
-- anything is a miss, we abort the parse.
Next_Element;
loop
-- Everything we are processing starts with a reserved word
if Category /= Reserved_Word then
Abort_Parse;
end if;
if Content = "with" then
Process_With;
Next_Element;
elsif Content = "use" then
Skip_To_Semicolon;
Next_Element;
elsif Content = "pragma" then
Next_Element;
if Category = Identifier then
if Content = "external_with" then
Process_External_With;
else
-- Otherwise we ignore it
Skip_To_Semicolon;
end if;
Next_Element;
else
Abort_Parse;
end if;
elsif Content = "private" then
-- We expect either package or a with statement to follow
Next_Element;
if Category /= Reserved_Word then
Abort_Parse;
end if;
if Content = "with" then
Process_With;
Next_Element;
elsif Content = "package" then
Process_Declaration;
exit;
end if;
elsif Content = "limited" then
-- We expect only a with to follow
Next_Element;
if Category = Reserved_Word
and then Content = "with"
then
Process_With;
Next_Element;
else
Abort_Parse;
end if;
elsif Content = "generic" then
-- Skip the generic, arriving at either package. procedure,
-- or function
loop
Skip_To_Semicolon;
Next_Element;
exit when Category = Reserved_Word
and then Content in "package" | "function" | "procedure";
end loop;
elsif Content in
"separate" | "package" | "function" | "procedure"
then
Process_Declaration;
-- This completes the parsing pass
exit;
else
-- This is unexpected
Abort_Parse;
end if;
end loop;
-- With the declaration processed, we filter out standard library with's
-- and process the staged externals
Filter_Standard_Library;
Process_Parent_Dependencies;
Process_Staged_Externals;
end;
-- We now have collected all required dependencies. We can now submit the
-- Dependency_Request (if any), and also update the
-- Unit_Forward_Dependencies and Unit_Reverse_Dependencies maps
if not Dependencies.Is_Empty then
-- Get these sent off now since there will be no more changes to the
-- Dependencies set
Dependency_Request.Tracker.Increment_Total_Items;
Workers.Enqueue_Order (Dependency_Request);
end if;
-- Now lets also register the forward and unit dependencies
--
-- Interestingly enough, this will correctly associate dependencies of
-- immediate subunits to the parent unit, since New_Unit's name is set
-- according to the "parent" unit in the case of subunits. In other words,
-- if this unit is a subunit, the dependent units will be told that the
-- parent of this unit is depending on it - which is correct.
--
-- A later pass of Registrar.Dependency_Processing.Consolidate_Dependencies
-- will merge all subunit forward dependency maps to their library-unit
-- parent, and then build a reverse dependency map from the forward map
--
-- Every entered unit must have an entry, even if that entry is an empty
-- set.
--
-- Note that we do not add our subystem to the subsystem forward dependency
-- set here since that information is implicit in the unit dependencies.
-- Also it is more efficient to build that set during the
-- Consolidate_Dependencies processes.
declare
Forward_Dependencies: Unit_Names.Sets.Set;
procedure Include_Forward_Dependencies (Set: in out Unit_Names.Sets.Set)
is begin
Set.Union (Forward_Dependencies);
end Include_Forward_Dependencies;
begin
for Unit of Dependencies loop
Forward_Dependencies.Insert (Unit.Name);
end loop;
Registry.Unit_Forward_Dependencies.Insert_Or_Modify
(Key => New_Unit.Name,
New_Item => Forward_Dependencies,
Process_Existing => Include_Forward_Dependencies'Access);
end;
-- AURA Subsystems need special treatment, as does the AURA Subsystem
-- itself!
if New_Unit.Name.Subsystem_Name.To_String = "aura" then
-- AURA subsystems themselves should not have any units of the AURA
-- subsystem. This can often happen by accident when preparing a manifest
-- so we will both do a hard assertion, and give some kind of meaninful
-- message if this happens
Assert (Check => not Order.AURA,
Message => "Check manifest: AURA subsystems should not have "
& "units of the AURA subsystem.");
-- Units of the AURA subsystem shouldn't ever have dependencies (besides
-- the standard library) that are not also AURA subsystem units.
--
-- Also, any grandchildren of AURA shall be named "checkout". Recall that
-- AURA children are either Repository units ("repository_x") - which
-- cannot have children, or configuration units with the name of their
-- respective subsystem - who shall only have a checkout child.
--
-- The problem is when a user modifies a Configuration unit. We need
-- to at least provide some feedback if they try to get too fancy by
-- either with'ing non-standard library units, or trying to add a child
-- unit
Assert
(Check => New_Unit.Subunit_Bodies.Length = 0,
Message => "Units of the AURA subsystem may not have subunits.");
for Unit of Dependencies loop
Assert (Check => Unit.Name.Subsystem_Name.To_String = "aura",
Message => "Units of the AURA subsystem shall not have"
& "outside dependencies besides the standard "
& "library.");
end loop;
if New_Unit.Name.To_String /= "aura"
and then New_Unit.Name.Parent_Name.To_String /= "aura"
then
-- This is a (great-xx) grandchild of the AURA unit
Assert
(Check => New_Unit.Name.Parent_Name.Parent_Name.To_String = "aura",
Message => "The AURA subsystem heirarchy cannot be deeper "
& "than 3 levels");
-- This is a grandchild of the AURA unit
Assert
(Check => New_Unit.Name.Self_Direct_Name.To_String = "checkout",
Message => "AURA subsystem child packages cannot have "
& "children (or nested subunits) except for "
& "checkout package specs.");
end if;
elsif Order.AURA then
-- The provided subsystem and the unit's subsystem must match.
-- Each AURA Subsystem shall only contain that subsystem, and
-- the manifest (AURA.Subsystem) only
Assert
(Check =>
Order.AURA_Subsystem.Name
= Unit_Names.Unit_Name(New_Unit.Name.Subsystem_Name),
Message =>
"Subsystem of entered unit does not match that " &
"of the AURA subsystem to which is should belong");
-- Police configuration manifests and configuration units.
-- Configuration packages (spec and body) may not have any AURA
-- dependencies, or dependencies on their own subsystem. Ergo they can
-- only depend on the standard library, or possibly the compiler library
-- (e.g. GNAT).
--
-- Manifests also may not have any children
--
-- Note that the ultimate configuration unit is the manifest renamed
-- (in the physical sense, not the Ada sense) to be AURA.Subsystem, and
-- so implicitly with's the root AURA package. This also means that
-- any unit that is part of the AURA subsystem face the same
-- restrictions - which is checked above
declare
use Unit_Names;
Subsys_Name : constant Unit_Name
:= Unit_Name (New_Unit.Name.Subsystem_Name);
Check_Manifest: constant Unit_Name := Subsys_Name & ".AURA";
Check_Children: constant Unit_Name := Check_Manifest & ".";
Exclude_Parent: constant Library_Unit := (Name => Subsys_Name,
others => <>);
begin
if New_Unit.Name = Check_Manifest then
-- A properly formed manfiest will have one dependency, which
-- will be the implicit dependency on subsystem's root unit
Dependencies.Exclude (Exclude_Parent);
Assert
(Check => Dependencies.Is_Empty,
Message => "AURA Configuration Manifests must only depend on "
& "the Standard Library.");
Assert
(Check => New_Unit.Kind = Package_Unit,
Message => "AURA Configuration Manifest must be a package.");
Assert
(Check => New_Unit.Subunit_Bodies.Length = 0,
Message => "AURA Configuration Manifest may not have "
& "subunits.");
else
Ada.Assertions.Assert
(Check =>
not New_Unit.Name.Match_Initial (Check_Children.To_String),
Message =>
"AURA Configuration Manifests may not have children or "
& "subunits.");
end if;
end;
end if;
-- Assign the Source file to the appropriate location
declare
use Source_Pack;
begin
if New_Unit.Kind = Subunit then
-- Even though subunits are not actually library units, we still
-- need to keep the file handle around for hashing, and so we still
-- submit the registration. For first order subunits, these will
-- properly be attached to the parent library unit.
--
-- For second-order subunits (subunits of subunits), the dependency
-- on the parent is entered as appropriate, so changes in these
-- subunits will still trigger recompilation of the associated
-- library unit. See also the discussion in the reverse dependency
-- mapping part above
--
-- As a consequence, for second-order subunits, the "parent" subunit
-- will have a "library unit" registered but will have no spec or body
-- file. It's perhapse not great for it to be considered a "library
-- unit", but the mechanics work-out.
--
-- The compiler will ultimately reject any funny buisness where,
-- for example, there is an actual child package with the same name
-- as a subunit - which isn't allowed anyways. (RM 10.1.3-14)
pragma Assert (Unit_Source_Type = Ada_Body);
New_Unit.Subunit_Bodies.Append (Source);
else
case Unit_Source_Type is
when Ada_Spec =>
New_Unit.Spec_File := Source;
when Ada_Body =>
New_Unit.Body_File := Source;
when Non_Ada =>
-- This shouldn't get here..
raise Program_Error;
end case;
end if;
end;
Source_Pack.Can_Discard := False;
-- Finally, submit the new registration
New_Unit.State := Available;
New_Unit_Registration.Tracker.Increment_Total_Items;
Workers.Enqueue_Order (New_Unit_Registration);
exception
when others =>
if Source_Pack.Can_Discard then
Source_Pack.Discard_Source;
end if;
raise;
end Execute;
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . S T A N D --
-- --
-- S p e c --
-- --
-- $Revision: 15121 $
-- --
-- Copyright (c) 1999-2002, Free Software Foundation, Inc. --
-- --
-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIS-for-GNAT is distributed in the hope that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with ASIS-for-GNAT; see file --
-- COPYING. If not, write to the Free Software Foundation, 59 Temple Place --
-- - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by Ada Core Technologies Inc --
-- (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
-- This package provides routines for processing the code of the predefined
-- Standard package in ASIS queries. The problem with Standard is that the
-- tree for it does not created from the source, but it is created by the
-- front-end in some special way. As a result, some elements of the tree
-- structure and some semantic links are missed for Standard, and we have
-- to simulate these missed tree componennts for ASIS queries.
with Asis; use Asis;
with Types; use Types;
package A4G.Stand is
function Is_Standard_Char_Type (N : Node_Id) return Boolean;
-- Returns True N is N_Enumeration_Type_Definition node representing the
-- definition of Standard.Character or Standard.Wide_Character. Returns
-- False otherwise
function Standard_Char_Decls
(Type_Definition : Asis.Type_Definition;
Implicit : Boolean := False)
return Asis.Element_List;
-- Provided that Type_Definition is An_Enumeration_Type_Definition Element
-- representing the definition of a predefined character type or a type
-- derived from it, directly or indirectly, this function returns the
-- corresponding list of An_Enumeration_Literal_Specification Elements.
-- Elements in the result list are based on argument's node (they are
-- "artificial" Elements created for components of the predefined Standard
-- package or their derivations which are not presented in the tree.
function Stand_Char_Image (Code : Char_Code) return Wide_String;
-- Provided that N is a N_Character_Literal Node from Standard.ASCII
-- package, returns its string image
function Get_Numeric_Error_Renaming return Asis.Element;
-- Returns the artificial declaration for an obsolete renaming of
-- Numeric_Error in Standard. This function assumes that the current
-- context and current tree are properly set.
end A4G.Stand;
|
type Scheduler is task interface;
procedure Plan (Manager : in out Scheduler; Activity : in out Job) is abstract;
|
package Centro_Mensajeria is
procedure Inicializar(Nombre: String; Localidad: String);
procedure Localizar_Envios_Cercanos(Geo: GeoLoc.Geo; LCer: Lista_Envios.Lista);
function Localidad() return String;
procedure Anadir_Envio(Env: Envios.Envio);
end Centro_Mensajeria;
|
separate (Numerics.Sparse_Matrices)
function Direct_Sum (A, B : in Sparse_Matrix) return Sparse_Matrix is
C : Sparse_Matrix;
NRow : constant Pos := A.N_Row;
NP : constant Pos := A.P (A.N_Col + 1);
use Ada.Containers;
begin
pragma Assert (A.Format = CSC and B.Format = CSC);
C.Format := CSC;
C.N_Col := A.N_Col + B.N_Col;
C.N_Row := A.N_Row + B.N_Row;
C.X.Reserve_Capacity (A.X.Length + B.X.Length);
C.I.Reserve_Capacity (A.I.Length + B.I.Length);
C.P.Reserve_Capacity (A.P.Length + B.P.Length - 1);
-- left matrix
for J in 1 .. Pos (A.I.Length) loop
C.X.Append (A.X (J));
end loop;
for J in 1 .. Pos (A.I.Length) loop
C.I.Append (A.I (J));
end loop;
for J in 1 .. Pos (A.P.Length) loop
C.P.Append (A.P (J));
end loop;
-- right matrix
for J in 1 .. Pos (B.I.Length) loop
C.X.Append (B.X (J));
end loop;
for J in 1 .. Pos (B.I.Length) loop
C.I.Append (NRow + B.I (J));
end loop;
for J in 2 .. Pos (B.P.Length) loop
C.P.Append (NP + B.P (J) - 1);
end loop;
return C;
end Direct_Sum;
|
--
--
--
with Sessions;
with States;
with Configs;
package Debugs is
procedure JQ_Dump_Rules (Session : in Sessions.Session_Type;
Mode : in Integer);
procedure Put_States (Session : in Sessions.Session_Type;
Mode : in Integer);
procedure Put_State (State : in States.State_Access);
procedure Put_Configs (Session : in Sessions.Session_Type;
Config_List : in Configs.Config_Access);
procedure Put_Config (Session : in Sessions.Session_Type;
Config : in Configs.Config_Access);
procedure Debug (On : in Boolean;
Message : in String);
--
end Debugs;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- C S E T S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2009, 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. --
-- --
------------------------------------------------------------------------------
package Csets is
pragma Elaborate_Body;
-- This package contains character tables for the various character
-- sets that are supported for source representation. Character and
-- string literals are not affected, only identifiers. For each set,
-- the table in this package gives the mapping of letters to their
-- upper case equivalent. Each table thus provides the information
-- for building the table used to fold lower case to upper case, and
-- also the table of flags showing which characters are allowed in
-- identifiers.
type Translate_Table is array (Character) of Character;
-- Type used to describe translate tables
type Char_Array_Flags is array (Character) of Boolean;
-- Type used for character attribute arrays. Note that we deliberately
-- do NOT pack this table, since we don't want the extra overhead of
-- accessing a packed bit string.
----------------------------------------------
-- Character Tables For Current Compilation --
----------------------------------------------
procedure Initialize;
-- Routine to initialize following character tables, whose content depends
-- on the character code being used to represent the source program. In
-- particular, the use of the upper half of the 8-bit code set varies.
-- The character set in use is specified by the value stored in
-- Opt.Identifier_Character_Set, which has the following settings:
-- '1' Latin-1 (ISO-8859-1)
-- '2' Latin-2 (ISO-8859-2)
-- '3' Latin-3 (ISO-8859-3)
-- '4' Latin-4 (ISO-8859-4)
-- '5' Latin-5 (ISO-8859-5, Cyrillic)
-- 'p' IBM PC (code page 437)
-- '8' IBM PC (code page 850)
-- '9' Latin-9 (ISO-9959-9)
-- 'f' Full upper set (all distinct)
-- 'n' No upper characters (Ada/83 rules)
-- 'w' Latin-1 plus wide characters also allowed
function Is_Upper_Case_Letter (C : Character) return Boolean;
pragma Inline (Is_Upper_Case_Letter);
-- Determine if character is upper case letter
function Is_Lower_Case_Letter (C : Character) return Boolean;
pragma Inline (Is_Lower_Case_Letter);
-- Determine if character is lower case letter
Fold_Upper : Translate_Table;
-- Table to fold lower case identifier letters to upper case
Fold_Lower : Translate_Table;
-- Table to fold upper case identifier letters to lower case
Identifier_Char : Char_Array_Flags;
-- This table has True entries for all characters that can legally appear
-- in identifiers, including digits, the underline character, all letters
-- including upper and lower case and extended letters (as controlled by
-- the setting of Opt.Identifier_Character_Set, left bracket for brackets
-- notation wide characters and also ESC if wide characters are permitted
-- in identifiers using escape sequences starting with ESC.
end Csets;
|
--------------------------------------------------------------------------------
-- --
-- Copyright (C) 2004, RISC OS Ada Library (RASCAL) developers. --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU Lesser General Public --
-- License as published by the Free Software Foundation; either --
-- version 2.1 of the License, or (at your option) any later version. --
-- --
-- This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- Lesser General Public License for more details. --
-- --
-- You should have received a copy of the GNU Lesser General Public --
-- License along with this library; if not, write to the Free Software --
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
-- --
--------------------------------------------------------------------------------
-- $Author$
-- $Date$
-- $Revision$
with RASCAL.OS;
with RASCAL.Utility; use RASCAL.Utility;
with RASCAL.Memory; use RASCAL.Memory;
with Kernel; use Kernel;
with Interfaces.C; use Interfaces.C;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Reporter;
package body RASCAL.ToolboxMenu is
Toolbox_ObjectMiscOp : constant Interfaces.C.Unsigned :=16#44EC6#;
--
procedure Set_Available (Menu : in Object_ID;
Available : in String;
Items : in out Natural;
Event : in Integer := 16#828C3#;
Flags : in System.Unsigned_Types.Unsigned := 0) is
ID : Component_ID := 0;
Entries : Unbounded_String := U(Available);
Single : Unbounded_String;
Pos : Integer;
begin
if Items > 0 then
Remove_Entries (Menu,0,Items);
end if;
Pos := Index (Entries,",");
while Pos > 0 loop
Single := U(Slice (Entries,1,Pos-1));
Entries := U(Slice (Entries,Pos+1,Length(Entries)));
Add_Last_Entry (Menu,S(Single),ID,"",Event);
ID := ID + 1;
Pos := Index (Entries,",");
end loop;
Add_Last_Entry (Menu,S(Entries),ID,"",Event);
Items := Natural(ID+1);
end Set_Available;
--
procedure Add_Last_Entry (Menu : in Object_ID;
Name : in String;
Id : in Component_ID;
Help : in String := "";
Click_Event : in integer := 16#828C3#;
Click_Show : in Object_ID := Object_ID'Val(0);
Submenu_Event : in integer := 16#828C2#;
Submenu_Show : in Object_ID := Object_ID'Val(0);
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Line : Menu_Entry_Type;
Name_0 : String := Name & ASCII.NUL;
Help_0 : String := Help & ASCII.NUL;
begin
Line.Flags := 0;
Line.ComponentID := Id;
Line.Name := Name_0'Address;
Line.Max_Text := Name_0'Length;
Line.Click_Show := integer(Click_Show);
Line.Submenu_Show := integer(Submenu_Show);
Line.Submenu_Event := Submenu_Event;
Line.Click_Event := Click_Event;
Line.Help_Message := Help_0'Address;
Line.Max_Entry_Help := Help_0'Length;
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(integer(Menu));
Register.R(2) := 20; -- menu_add_entry
Register.R(3) := -2;
Register.R(4) := Adr_To_Int(Line'Address);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Add_Last_Entry: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Add_Last_Entry;
--
procedure Add_After_Entry (Menu : in Object_ID;
Name : in String;
Id : in Component_ID;
Next_ID : in Component_ID;
Help : in String := "";
Click_Event : in integer := 16#828C3#;
Click_Show : in Object_ID := Object_ID'Val(0);
Submenu_Event : in integer := 16#828C2#;
Submenu_Show : in Object_ID := Object_ID'Val(0);
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Line : Menu_Entry_Type;
Name_0 : String := Name & ASCII.NUL;
Help_0 : String := Help & ASCII.NUL;
begin
Line.Flags := 0;
Line.ComponentID := Id;
Line.Name := Name_0'Address;
Line.Max_Text := Name_0'Length;
Line.Click_Show := integer(Click_Show);
Line.Submenu_Show := integer(Submenu_Show);
Line.Submenu_Event := Submenu_Event;
Line.Click_Event := Click_Event;
Line.Help_Message := Help_0'Address;
Line.Max_Entry_Help := Help_0'Length;
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(integer(Menu));
Register.R(2) := 20; -- menu_add_entry
Register.R(3) := int(Next_ID);
Register.R(4) := Adr_To_Int(Line'Address);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Add_After_Entry: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Add_After_Entry;
--
function Get_Click_Event (Menu : in Object_ID;
Component : in Component_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return Toolbox_Event_Code_Type is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 15;
Register.R(3) := int(Component);
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Click_Event: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
return Toolbox_Event_Code_Type(Register.R(4));
end Get_Click_Event;
--
function Get_Click_Show (Menu : in Object_ID;
Component : in Component_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return Object_ID is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 13;
Register.R(3) := int(Component);
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Click_Show: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
return Object_ID(Register.R(0));
end Get_Click_Show;
--
function Get_Click_Show_Type (Menu : in Object_ID;
Component : in Component_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return Menu_Show_Type is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Flag : integer;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 13;
Register.R(3) := int(Component);
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Click_Show_Type: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
Flag := integer(Register.R(1));
if "And" (Flag,1) = 1 then
return Transient;
else
return Persistent;
end if;
end Get_Click_Show_Type;
--
function Get_Entry_Help (Menu : in Object_ID;
Component : in Component_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return string is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Buffer_Size : integer;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 19;
Register.R(3) := int(Component);
Register.R(4) := 0;
Register.R(5) := 0;
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Entry_Help: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
return "";
end if;
Buffer_Size := integer(Register.R(5)) + 1;
declare
Buffer : string(1..Buffer_Size);
begin
Register.R(0) := 0;
Register.R(1) := int(Menu);
Register.R(2) := 19;
Register.R(3) := int(Component);
Register.R(4) := Adr_To_Int(Buffer'Address);
Register.R(5) := int(Buffer_Size);
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Entry_Help: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
return "";
end if;
return MemoryToString(Buffer'Address);
end;
end Get_Entry_Help;
--
function Get_Entry_Sprite (Menu : in Object_ID;
Component : in Component_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return string is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Buffer_Size : integer;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 7;
Register.R(3) := int(Component);
Register.R(4) := 0;
Register.R(5) := 0;
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Entry_Sprite: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
return "";
end if;
Buffer_Size := integer(Register.R(5)) + 1;
declare
Buffer : string(1..Buffer_Size);
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 7;
Register.R(3) := int(Component);
Register.R(4) := Adr_To_Int(Buffer'Address);
Register.R(5) := int(Buffer_Size);
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Entry_Sprite: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
return "";
end if;
return MemoryToString(Buffer'Address);
end;
end Get_Entry_Sprite;
--
function Get_Entry_Text (Menu : in Object_ID;
Component : in Component_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return String is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Buffer_Size : Size_T;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 5;
Register.R(3) := int(Component);
Register.R(4) := 0;
Register.R(5) := 0;
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Entry_Text: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
Buffer_SIze := Size_T(Register.R(5));
declare
Buffer : Char_Array(1..Buffer_Size);
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 5;
Register.R(3) := int(Component);
Register.R(4) := Adr_To_Int(Buffer'Address);
Register.R(5) := int(Buffer_Size);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Entry_Text: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
return To_Ada(Buffer);
end;
end Get_Entry_Text;
--
function Get_Fade (Menu : in Object_ID;
Component : in Component_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return Menu_Fade_Type is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 3;
Register.R(3) := int(Component);
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Fade: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
if integer(Register.R(0)) /= 0 then
return Faded;
else
return Unfaded;
end if;
end Get_Fade;
--
function Get_Height (Menu : in Object_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return integer is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 22;
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Height: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
return integer(Register.R(0));
end Get_Height;
--
function Get_Help (Menu : in Object_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return string is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Buffer_Size : integer;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 17;
Register.R(3) := 0;
Register.R(4) := 0;
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Help: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
return "";
end if;
Buffer_Size := integer(Register.R(4)) + 1;
declare
Buffer : string(1..Buffer_Size);
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 17;
Register.R(3) := Adr_To_Int(Buffer'Address);
Register.R(4) := int(Buffer_Size);
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Add_Last_Entry: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
return "";
end if;
return MemoryToString(Buffer'Address);
end;
end Get_Help;
--
function Get_Sub_Menu_Event (Menu : in Object_ID;
Component : in Component_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return Toolbox_Event_Code_Type is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 11;
Register.R(3) := int(Component);
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Sub_Menu_Event: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
return Toolbox_Event_Code_Type(Register.R(0));
end Get_Sub_Menu_Event;
--
function Get_Sub_Menu_Show (Menu : in Object_ID;
Component : in Component_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return Object_ID is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 9;
Register.R(3) := int(Component);
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Sub_Menu_Show: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
return Object_ID(Register.R(0));
end Get_Sub_Menu_Show;
--
function Get_Tick (Menu : in Object_ID;
Component : in Component_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return Menu_Tick_Type is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 1;
Register.R(3) := int(Component);
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Tick: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
if integer(Register.R(0)) /= 0 then
return Ticked;
else
return UnTicked;
end if;
end Get_Tick;
--
function Get_Title (Menu : in Object_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return string is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Buffer_Size : integer;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 25;
Register.R(3) := 0;
Register.R(4) := 0;
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Title: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
return "";
end if;
Buffer_Size := integer(Register.R(4)) + 1;
declare
Buffer : string(1..Buffer_Size);
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 25;
Register.R(3) := Adr_To_Int(Buffer'Address);
Register.R(4) := int(Buffer_Size);
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Title: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
return "";
end if;
return MemoryToString(Buffer'Address);
end;
end Get_Title;
--
function Get_Width (Menu : in Object_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) return integer is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 23;
Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Get_Width: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
return integer(Register.R(0));
end Get_Width;
--
procedure Remove_Entry (Menu : in Object_ID;
ID : in integer;
Flags: in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(integer(Menu));
Register.R(2) := 21;
Register.R(3) := int(ID);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Remove_Entry: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Remove_Entry;
--
procedure Remove_Entries (Menu : in Object_ID;
Nr : in integer;
Start: in integer :=0;
Flags: in System.Unsigned_Types.Unsigned := 0) is
begin
for i in Start..(Start+Nr-1) loop
Remove_Entry(Menu,i);
end loop;
end Remove_Entries;
--
procedure Set_Click_Event (Menu : in Object_ID;
Component : in Component_ID;
Event : in Toolbox_Event_Code_Type;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 14;
Register.R(3) := int(Component);
Register.R(4) := int(Event);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Set_Click_Event: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Set_Click_Event;
--
procedure Set_Click_Show (Menu : in Object_ID;
Component : in Component_ID;
Object : in Object_ID;
Show : in Menu_Show_Type := Persistent;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 12;
Register.R(3) := int(Component);
Register.R(4) := int(Object);
Register.R(5) := int(Menu_Show_Type'Pos(Show));
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Set_Click_Show: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Set_Click_Show;
--
procedure Set_Entry_Help (Menu : in Object_ID;
Component : in Component_ID;
Help : in string;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Null_Help : String := Help & ASCII.NUL;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 18;
Register.R(3) := int(Component);
Register.R(4) := Adr_To_Int(Null_Help'Address);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Set_Entry_Help: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Set_Entry_Help;
--
procedure Set_Entry_Sprite (Menu : in Object_ID;
Component : in Component_ID;
Sprite : in string;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Null_Sprite : String := Sprite & ASCII.NUL;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 6;
Register.R(3) := int(Component);
Register.R(4) := Adr_To_Int(Null_Sprite'Address);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Set_Entry_Sprite: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Set_Entry_Sprite;
--
procedure Set_Entry_Text (Menu : in Object_ID;
Component : in Component_ID;
Text : in string;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Null_Text : String := Text & ASCII.NUL;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 4;
Register.R(3) := int(Component);
Register.R(4) := Adr_To_Int(Null_Text'Address);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Set_Entry_Text: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Set_Entry_Text;
--
procedure Set_Fade (Menu : in Object_ID;
Component : in Component_ID;
Fade : in Menu_Fade_Type;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 2;
Register.R(3) := int(Component);
Register.R(4) := int(Menu_Fade_Type'Pos(Fade));
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Set_Fade: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Set_Fade;
--
procedure Set_Help (Menu : in Object_ID;
Help : in string;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Null_Help : String := Help & ASCII.NUL;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 16;
Register.R(3) := Adr_To_Int(Null_Help'Address);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Set_Help: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Set_Help;
--
procedure Set_Sub_Menu_Event (Menu : in Object_ID;
Component : in Component_ID;
Event : in Toolbox_Event_Code_Type;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 10;
Register.R(3) := int(Component);
Register.R(4) := int(Event);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Set_Sub_Menu_Event: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Set_Sub_Menu_Event;
--
procedure Set_Sub_Menu_Show (Menu : in Object_ID;
Component : in Component_ID;
Object : in Object_ID;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 8;
Register.R(3) := int(Component);
Register.R(4) := int(Object);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Set_Sub_Menu_Show: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Set_Sub_Menu_Show;
--
procedure Set_Tick (Menu : in Object_ID;
Component : in Component_ID;
Tick : in Menu_Tick_Type;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 0;
Register.R(3) := int(Component);
Register.R(4) := int(Menu_Tick_Type'Pos(Tick));
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Set_Tick: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Set_Tick;
--
procedure Set_Title (Menu : in Object_ID;
Title : in string;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Null_Title : String := Title & ASCII.NUL;
begin
Register.R(0) := int(Unsigned_to_Int(Flags));
Register.R(1) := int(Menu);
Register.R(2) := 24;
Register.R(3) := Adr_To_Int(Null_Title'Address);
Error := Kernel.Swi (Toolbox_ObjectMiscOp, Register'Access, Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("ToolboxMenu.Set_Title: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Set_Title;
--
end RASCAL.ToolboxMenu;
|
pragma License (Unrestricted);
-- extended unit
with Ada.Strings.Functions.Maps;
package Ada.Strings.Unbounded_Strings.Functions.Maps is
new Generic_Maps (Strings.Functions.Maps);
pragma Preelaborate (Ada.Strings.Unbounded_Strings.Functions.Maps);
|
-- Description:
-- Main System File
-- the main loop (TM)
with Ada.Real_Time; use Ada.Real_Time;
with CPU;
with Units; use Units;
-- with Units.Navigation; use Units.Navigation;
with HIL;
with Interfaces; use Interfaces;
with MPU6000.Driver; use MPU6000.Driver;
with PX4IO.Driver;
with ublox8.Driver; use ublox8.Driver;
with NVRAM;
with Logger;
with Config.Software; use Config.Software;
with Bounded_Image; use Bounded_Image;
with Mission; use Mission;
-- with Console;
with Estimator;
with Controller;
with LED_Manager;
with Buzzer_Manager;
with Buildinfo;
with Profiler; use Profiler;
package body Main with SPARK_Mode => On is
type LED_Counter_Type is mod 1000/Config.Software.MAIN_TICK_RATE_MS/2;
G_led_counter : LED_Counter_Type := 0;
----------------
-- Initialize
----------------
procedure Initialize is
num_boots : HIL.Byte;
begin
CPU.initialize;
-- start logger first
declare
ret : Logger.Init_Error_Code;
begin
Logger.Init (ret);
pragma Unreferenced (ret);
end;
Logger.Set_Log_Level (CFG_LOGGER_LEVEL_UART);
-- wait to satisfy some (?) timing
declare
now : constant Time := Clock;
begin
delay until now + Milliseconds (50);
end;
if Config.Software.TEST_MODE_ACTIVE then
Logger.log_console (Logger.ERROR, "TEST-DUMMY MODE IS ACTIVE!");
end if;
-- start NVRAM (bootcounter...)
Logger.log_console (Logger.INFO, "Initializing NVRAM...");
NVRAM.Init;
-- from now on, log everything to SDcard
Logger.log_console (Logger.INFO, "Starting SDLog...");
Logger.Start_SDLog; -- should be called after NVRAM.Init
Buzzer_Manager.Initialize;
Estimator.initialize;
Controller.initialize;
-- wait a bit: UART doesn't seem to write earlier.
declare
now : constant Time := Clock;
begin
delay until now + Milliseconds (1000); -- reduced from 1500
end;
-- Dump general boot & crash info
declare
exception_line : HIL.Byte_Array_2 := (0,0);
exception_addr : Unsigned_32;
high_watermark_us : Unsigned_32;
begin
NVRAM.Load (NVRAM.VAR_BOOTCOUNTER, num_boots); -- is maintained by the NVRAM itself
declare
strboot : constant String := Unsigned8_Img (num_boots);
begin
Logger.log_console (Logger.INFO, ("Boot number: " & strboot));
Logger.log_console (Logger.INFO, "Build date: " & Buildinfo.Compilation_ISO_Date
& " " & Buildinfo.Compilation_Time);
end;
NVRAM.Load (NVRAM.VAR_EXCEPTION_LINE_L, exception_line(1));
NVRAM.Load (NVRAM.VAR_EXCEPTION_LINE_H, exception_line(2));
NVRAM.Load (NVRAM.VAR_EXCEPTION_ADDR_A, exception_addr);
-- write to SD card and console: last crash info
Logger.log (Logger.WARN, "Last Exception: line=" &
Integer_Img (Integer (HIL.toUnsigned_16 (exception_line))) &
" addr=" & Unsigned_Img (exception_addr));
NVRAM.Load (NVRAM.VAR_HIGHWATERMARK_A, high_watermark_us);
Logger.log (Logger.WARN, "High Watermark: " & Unsigned_Img (high_watermark_us));
end;
Mission.load_Mission;
end Initialize;
-----------------------
-- Perform_Self_Test
-----------------------
procedure Perform_Self_Test (passed : out Boolean) is
in_air_reset : constant Boolean := Mission.Is_Resumed;
begin
if in_air_reset then
passed := True;
Logger.log_console (Logger.INFO, "In-Air reset, no self-check");
return;
end if;
Logger.log_console (Logger.INFO, "Starting Self Test");
-- check NVRAM
NVRAM.Self_Check (passed);
if not passed then
Logger.log_console (Logger.ERROR, "NVRAM self-check failed");
return;
else
Logger.log_console (Logger.INFO, "NVRAM self-check passed");
end if;
-- check MPU6000
declare
Status : Boolean;
begin
MPU6000.Driver.Self_Test (Status);
passed := Status;
end;
if not passed then
Logger.log_console (Logger.ERROR, "MPU6000 self-check failed");
return;
else
Logger.log_console (Logger.INFO, "MPU6000 self-check passed");
end if;
-- check PX4IO
declare
Status : Boolean;
begin
PX4IO.Driver.Self_Check (Status);
passed := Status;
end;
if not passed then
Logger.log_console (Logger.ERROR, "PX4IO self-check failed; continuing anyway");
--return; -- this happens a lot
else
Logger.log_console (Logger.INFO, "PX4IO self-check passed");
end if;
-- check GPS
declare
Status : ublox8.Driver.Error_Type;
begin
ublox8.Driver.perform_Self_Check (Status);
passed := Status = ublox8.Driver.SUCCESS;
end;
if not passed then
Logger.log_console (Logger.ERROR, "Ublox8 self-check failed");
return;
else
Logger.log_console (Logger.INFO, "Ublox8 self-check passed");
end if;
end Perform_Self_Test;
--------------
-- Run_Loop
--------------
procedure Run_Loop is
msg : constant String := "Main";
time_next_loop : Time;
time_loop_start : Time;
Main_Profile : Profile_Tag;
--command : Console.User_Command_Type;
type skipper is mod 100; -- every 2 seconds one perf log
skip : skipper := 0;
watermark_high_us : Unsigned_32 := 0;
watermark_last_us : Unsigned_32 := 0;
m_state : Mission.Mission_State_Type;
begin
Main_Profile.init(name => "Main");
LED_Manager.LED_blink (LED_Manager.SLOW);
NVRAM.Load (NVRAM.VAR_HIGHWATERMARK_A, watermark_high_us);
Logger.log_console (Logger.INFO, msg);
-- arm PX4IO
Controller.activate;
time_next_loop := Clock;
loop
Main_Profile.start;
time_loop_start := Clock;
skip := skip + 1;
-- LED alive: toggle with main loop, which allows to see irregularities
G_led_counter := LED_Counter_Type'Succ( G_led_counter );
if G_led_counter < LED_Counter_Type'Last/2 then
LED_Manager.LED_switchOn;
else
LED_Manager.LED_switchOff;
end if;
-- do not use the buzzer here...just call tick. The only one who may buzzer is mission.adb
Buzzer_Manager.Tick;
-- Mission
m_state := Mission.get_state;
Mission.run_Mission; -- may switch to next one
-- -- Console
-- Console.read_Command( command );
--
-- case ( command ) is
-- when Console.TEST =>
-- perform_Self_Test (checks_passed);
-- if not checks_passed then
-- Logger.log_console (Logger.ERROR, "Self-checks failed");
-- else
-- Logger.log_console (Logger.INFO, "Self-checks passed");
-- end if;
--
-- when Console.STATUS =>
-- Estimator.log_Info;
-- Controller.log_Info;
-- PX4IO.Driver.read_Status;
--
-- Logger.log_console (Logger.INFO, "Profile: " & Integer_Img ( Integer(
-- Float( Units.To_Time(loop_duration_max) ) * 1000.0 ) ) & " ms" );
--
-- when Console.ARM => Controller.activate;
--
-- when Console.DISARM => Controller.deactivate;
--
-- when Console.PROFILE =>
-- Logger.log_console (Logger.INFO, "Profile: " & Integer_Img ( Integer(
-- Float( Units.To_Time(loop_duration_max) ) * 1000.0 ) ) & " ms" );
-- Main_Profile.log;
--
-- when others =>
-- null;
-- end case;
-- Maintain high watermark
Main_Profile.stop;
if m_state /= Mission.DETACHING and then m_state /= Mission.STARTING then
-- we measure the loop time, except in detach and start. Because there we screw with timing
declare
t_watermark_sec : constant Float := Float (To_Time (Main_Profile.get_Max));
t_watermark_usec : constant Float := t_watermark_sec * 1.0E6;
begin
if t_watermark_usec > 0.0 then
if Float (Unsigned_32'Last) > t_watermark_usec then
watermark_last_us := Unsigned_32 (t_watermark_usec);
else
watermark_last_us := Unsigned_32'Last;
end if;
if watermark_last_us > watermark_high_us then
watermark_high_us := watermark_last_us;
NVRAM.Store (NVRAM.VAR_HIGHWATERMARK_A, watermark_high_us);
end if;
if skip = 0 then
Main_Profile.reset;
Logger.log_console (Logger.DEBUG, "Main Time: cur=" & Unsigned_Img (watermark_last_us)
& ", high=" & Unsigned_Img (watermark_high_us));
end if;
end if;
end;
else
-- recover timing
Main_Profile.reset;
time_next_loop := time_loop_start;
end if;
-- wait remaining loop time
time_next_loop := time_next_loop + Milliseconds (MAIN_TICK_RATE_MS);
delay until time_next_loop;
end loop;
end Run_Loop;
end Main;
|
package Opt22_Pkg is
procedure Fail;
procedure Put (S : String);
end Opt22_Pkg;
|
with STM32.Device;
package body Digital is
-------------------
-- Configure_Pin --
-------------------
procedure Configure_Pin(Pin : GPIO_Point; Mode : Digital_Mode) is
IO_Mode : STM32.GPIO.Pin_IO_Modes;
begin
case Mode is
when Input =>
IO_Mode := Mode_In;
when Output =>
IO_Mode := Mode_Out;
end case;
declare
Configuration_Pin : GPIO_Port_Configuration(IO_Mode);
begin
STM32.Device.Enable_Clock(Pin);
STM32.GPIO.Configure_IO(This => Pin,
Config => Configuration_Pin);
end;
end Configure_Pin;
----------------
-- Set_Signal --
----------------
procedure Set_Signal(Pin : GPIO_Point; Mode : Signal_Mode) is
Actual_Pin: GPIO_Point:= Pin;
begin
STM32.GPIO.Set(Actual_Pin);
case Mode is
when HIGH =>
STM32.GPIO.Set(Actual_Pin);
when LOW =>
STM32.GPIO.Clear(Actual_Pin);
end case;
end Set_Signal;
-----------------
-- Read_Signal --
-----------------
function Read_Signal(Pin : GPIO_Point) return Signal_Mode is
Value : constant Boolean := Set(Pin);
begin
case Value is
when False =>
return LOW;
when True =>
return HIGH;
end case;
end Read_Signal;
end Digital;
|
package body impact.d3.Material
is
function to_Material (friction,
restitution : math.Real) return Item
is
Self : Item;
begin
Self.m_friction := friction;
Self.m_restitution := restitution;
return Self;
end to_Material;
end impact.d3.Material;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUNTIME COMPONENTS --
-- --
-- S Y S T E M . G E N E R I C _ C _ M A T H _ I N T E R F A C E --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2021, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- 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 is the Ada Cert Math specific version of s-gcmain.adb.
-- The separate version is necessary, because this system does not provide
-- an implementation of tanh, among other hyperbolic functions. The run time
-- currently has no code to implement this function, so the only short term
-- option was to remove the hyperbolic functions.
with Ada.Numerics; use Ada.Numerics;
package body System.Generic_C_Math_Interface is
subtype T is Float_Type'Base;
-- The implementations of these functions start with a summary
-- of the Ada requirements for the following:
-- * Principal branch of multivalued functions
-- * Conditions for raising exceptions
-- * Prescribed function results
-- * Tightly approximated function results (strict mode only)
-- Implementation choices are explained after the summary for each
-- elementary function. Exceptions are raised either by checking the
-- arguments or the C function result. Prescribed results are satisfied by
-- referring to corresponding requirements in C, standard implementation
-- practice or by explicit special-casing in the code below.
-- If one of the arguments of a function is a NaN, the function will return
-- a NaN value or raise Argument_Error. Generally, for functions that
-- require Argument_Error to be raised for some arguments will also
-- raise Argument_Error for NaN arguments.
-- Many comparisons for special cases are inverted using "not" in order
-- to make sure the condition is false for NaN values, using the principle
-- that any comparison involving a NaN argument evaluates to false.
-- Principal branch:
-- Describes function result for cases where the mathematical
-- function is multivalued.
-- Exceptions:
-- Describes in what situations exceptions such as
-- Argument_Error and Constraint_Error must be raised.
-- In addition to these required exceptions, Constraint_Error
-- may also be raised instead of yielding an infinity value
-- for types T where T'Machine_Overflows is True.
-- Prescribed results:
-- Describes identities that must be satisfied.
-- Tightly approximated results:
-- Describes arguments for which the function result must
-- be in the model interval of the mathematical result.
-- This is required for strict mode.
-- Special values:
-- These are implementation-defined results arguments with
-- special values such as infinities (represented by +Inf and -Inf)
-- not-a-number values (written as NaN). Where consistent with the
-- Ada standard, the implementation satisfies the identities given
-- in Chapter F.9 of the C standard.
----------
-- "**" --
----------
-- Principle branch:
-- The result is nonnegative.
-- Required exceptions:
-- Argument_Error is raised when Left < 0.0, Left is a NaN
-- or when Left = 0.0 and Right = 0.0.
-- Constraint_Error is raised when Left = 0.0, and Right < 0.0 or is a
-- NaN.
-- Prescribed results:
-- (1) Left ** 0.0 = 1.0
-- (2) Left ** 1.0 = Left
-- (3) 0.0 ** Right = 0.0
-- (4) 1.0 ** Right = 1.0
-- The prescribed result (1) is satisfied by C_Pow.
-- Result (2) is not, and therefore is special-cased.
-- For case (3) this implementation always returns +0.0,
-- while C_Pow would return -0.0 when Left = -0.0 and Right a positive
-- odd integer. This would seem inconsistent with the required principle
-- branch, although it is debatable whether -0.0 is negative.
-- For case (4), C_Pow would return NaN, so a special case is required.
function "**" (Left, Right : Float_Type'Base) return Float_Type'Base is
begin
-- The if statements are structured to ensure NaN parameters cause the
-- correct exception to be raised (since a NaN will always fail a
-- non-equal comparison test).
if not (Left > 0.0) then
if not (Left = 0.0) or else not (Right /= 0.0) then
raise Argument_Error;
elsif not (Right >= 0.0) then
raise Constraint_Error;
else
-- Left = 0.0 and Right > 0.0
return 0.0;
end if;
elsif Right = 1.0 then
return Left;
elsif Left = 1.0 then
return 1.0;
end if;
return C_Pow (Left, Right);
end "**";
------------
-- Arccos --
------------
-- (Natural cycle)
-- Principal branch:
-- The result is in the quadrant containing the point (X, 1.0).
-- This quadrant is I or II; thus, the Arccos function ranges
-- from 0.0 to approximately Pi.
-- Exceptions:
-- Argument_Error is raised when abs (X) > 1.0
-- Tightly approximated results:
-- Arccos (0.0) = Pi / 2.0;
-- Arccos (1.0) = 0.0;
-- Since C mandates a NaN result for abs (X) > 1.0 and testing
-- for a NaN only requires a single test without calling the "abs"
-- function, the result is checked rather than the argument.
function Arccos (X : Float_Type'Base) return Float_Type'Base is
R : T;
begin
R := C_Acos (X);
if R /= R then
raise Argument_Error;
else
return R;
end if;
end Arccos;
-- (Arbitrary cycle)
-- Principal branch:
-- The result is in the quadrant containing the point (X, 1.0).
-- This quadrant is I or II; thus, the Arccos function ranges
-- from 0.0 to approximately Cycle / 2.0.
-- Exceptions:
-- Argument_Error is raised when abs (X) > 1.0 or when Cycle <= 0.0
-- or when either parameter is a NaN
-- Prescribed results:
-- Arccos (1.0) = 0.0
-- Tightly approximated results:
-- Arccos (0.0) = Cycle / 4.0
-- Since C mandates a NaN result for abs (X) > 1.0 and testing for a NaN
-- only requires a single test without calling the "abs" function, the
-- result is checked rather than the argument. The tightly approximated
-- result may not be obtained by dividing the C_Acos result by Pi, since
-- these are transcedental numbers.
function Arccos (X, Cycle : Float_Type'Base) return Float_Type'Base is
begin
if not (Cycle > 0.0) then
raise Argument_Error;
elsif not (abs X < 1.0) then
if X = 1.0 then
return 0.0;
elsif X = -1.0 then
return Cycle / 2.0;
end if;
raise Argument_Error;
end if;
if X = 0.0 then
return Cycle / 4.0;
end if;
return C_Acos (X) / (Pi / 2.0) * (Cycle / 4.0);
end Arccos;
-------------
-- Arccosh --
-------------
-- Principal branch:
-- The result is positive
-- Exceptions:
-- Argument_Error is raised when X < 1.0
-- Prescribed results:
-- Arccosh (1.0) = 0.0;
-- General description
-- TODO
function Arccosh (X : Float_Type'Base) return Float_Type'Base is
begin
if X < 1.0 then
raise Argument_Error;
else
return C_Acosh (X);
end if;
end Arccosh;
------------
-- Arccot --
------------
-- Natural cycle
-- Principal branch:
-- The results are in the quadrant containing the point (X, Y).
-- This may be any quadrant (I through IV) when the parameter Y is
-- specified, but it is restricted to quadrants I and II when that
-- parameter is omitted. Thus the range when that parameter is
-- specified is approximately -Pi to Pi; when omitted the range is
-- 0.0 to Pi.
-- Exceptions:
-- Argument_Error is raised when parameters X and Y both have the
-- value zero
-- Prescribed results:
-- Arccot (X, 0.0) = 0.0 when X > 0.0
function Arccot
(X : Float_Type'Base;
Y : Float_Type'Base := 1.0) return Float_Type'Base
is
begin
if X = 0.0 and then Y = 0.0 then
raise Argument_Error;
else
-- Just reverse arguments
return Arctan (Y, X);
end if;
end Arccot;
-- Arbitrary cycle
function Arccot
(X : Float_Type'Base;
Y : Float_Type'Base := 1.0;
Cycle : Float_Type'Base) return Float_Type'Base
is
begin
if X = 0.0 and then Y = 0.0 then
raise Argument_Error;
else
-- Just reverse arguments
return Arctan (Y, X, Cycle);
end if;
end Arccot;
-------------
-- Arccoth --
-------------
-- Exceptions:
-- Argument_Error is raised if abs (X) < 1.0
-- Constraint_Error is raised if X = +-1.0
function Arccoth (X : Float_Type'Base) return Float_Type'Base is
begin
if abs X <= 1.0 then
if abs X = 1.0 then
raise Constraint_Error;
else
raise Argument_Error;
end if;
elsif abs X > 2.0 then
return C_Atanh (1.0 / X);
else
-- 1.0 < abs X <= 2.0. One of X + 1.0 and X - 1.0 is exact, the
-- other has error 0 or Epsilon.
return 0.5 * (C_Log (abs (X + 1.0)) - C_Log (abs (X - 1.0)));
end if;
end Arccoth;
------------
-- Arcsin --
------------
-- (Natural cycle)
-- Principal branch:
-- The result of the Arcsin function is in the quadrant containing the
-- the point (1.0, X). This quadrant is I or IV; thus, the range of the
-- function is approximately -Pi/2.0 to Pi/2.0.
-- Exceptions:
-- Argument_Error is raised when abs X > 1.0 or X is a NaN
-- Prescribed results:
-- Arcsin (0.0) = 0.0
-- Tightly approximated results:
-- Arcsin (1.0) = Pi / 2.0
-- Arcsin (-1.0) = -Pi / 2.0
-- The prescribed result is guaranteed by C, but the tightly approximated
-- results are not.
function Arcsin (X : Float_Type'Base) return Float_Type'Base is
Y : constant T := abs X;
begin
if not (Y < 1.0) then
if X = 1.0 then
return Pi / 2.0;
elsif X = -1.0 then
return -Pi / 2.0;
else
raise Argument_Error;
end if;
end if;
return C_Asin (X);
end Arcsin;
-- (Arbitrary cycle)
-- Principal branch:
-- The result of the Arcsin function is in the quadrant containing the
-- the point (1.0, X). This quadrant is I or IV; thus, the range of the
-- function is approximately -Cycle/4.0 to Cycle/4.0.
-- Exceptions:
-- Argument_Error is raised when abs X > 1.0 or X is a NaN
-- or when Cycle <= 0.0 or Cycle is a NaN
-- Prescribed results:
-- Arcsin (0.0) = 0.0
-- Tightly approximated results:
-- Arcsin (1.0) = Cycle / 4.0
-- Arcsin (-1.0) = -Cycle / 4.0
-- The prescribed result is guaranteed by C, but the tightly approximated
-- results are not.
function Arcsin (X, Cycle : Float_Type'Base) return Float_Type'Base is
Y : constant T := abs X;
begin
if not (Cycle > 0.0) then
raise Argument_Error;
elsif not (Y < 1.0) then
if X = 1.0 then
return Cycle / 4.0;
elsif X = -1.0 then
return -Cycle / 4.0;
else
raise Argument_Error;
end if;
end if;
return C_Asin (X) / (Pi / 2.0) * (Cycle / 4.0);
end Arcsin;
-------------
-- Arcsinh --
-------------
-- Prescribed results:
-- Arcsinh (0.0) = 0.0
-- TODO - general description
function Arcsinh (X : Float_Type'Base) return Float_Type'Base is
(C_Asinh (X));
------------
-- Arctan --
------------
-- (Natural cycle)
-- Principal branch:
-- The results are in the quadrant containing the point (X, Y).
-- This may be any quadrant (I through IV) when the parameter X is
-- specified, but it is restricted to quadrants I and IV when that
-- parameter is omitted. Thus the range when that parameter is
-- specified is approximately -Pi to Pi; when omitted the range is
-- -Pi/2.0 to Pi/2.0.
-- Exceptions:
-- Argument_Error is raised when both X and Y have the value zero.
-- Prescribed results:
-- Arctan ( X, 0.0) = 0.0, when X > 0.0
-- Tightly approximated results:
-- Arctan (0.0, Y) = Pi/2.0, when Y > 0.0
-- Arctan (0.0, Y) = -Pi/2.0, when Y < 0.0
-- Arctan ( X, +0.0) = +Pi, when X < 0.0
-- Arctan ( X, -0.0) = -Pi, when X < 0.0
-- The prescribed result and tightly approximated results are all
-- guaranteed by C.
function Arctan
(Y : Float_Type'Base;
X : Float_Type'Base := 1.0) return Float_Type'Base
is
begin
if not (X /= 0.0) and then not (Y /= 0.0) then
raise Argument_Error;
end if;
return C_Atan2 (Y, X);
end Arctan;
-- (Arbitrary cycle)
-- Principal branch:
-- The results are in the quadrant containing the point (X, Y).
-- This may be any quadrant (I through IV) when the parameter X is
-- specified, but it is restricted to quadrants I and IV when that
-- parameter is omitted. Thus the range when that parameter is
-- specified is approximately -Cycle/2.0 to Cycle/2.0; when omitted
-- the range is -Cycle/4.0 to Cycle/4.0.
-- Exceptions:
-- Argument_Error is raised when both X and Y have the value zero,
-- or when Cycle <= 0.0 or Cycle is a NaN.
-- Prescribed results:
-- Arctan ( X, 0.0, Cycle) = 0.0, when X > 0.0
-- Tightly approximated results:
-- Arctan (0.0, Y, Cycle) = Cycle/4.0, when Y > 0.0
-- Arctan (0.0, Y, Cycle) = -Cycle/4.0, when Y < 0.0
-- Arctan ( X, +0.0, Cycle) = Cycle/2.0, when X < 0.0
-- Arctan ( X, -0.0, Cycle) = -Cycle/2.0, when X < 0.0
-- The prescribed result and tightly approximated results are all
-- guaranteed by C.
function Arctan
(Y : Float_Type'Base;
X : Float_Type'Base := 1.0;
Cycle : Float_Type'Base) return Float_Type'Base
is
begin
if not (Cycle > 0.0) then
raise Argument_Error;
end if;
if X = 0.0 then
if Y = 0.0 then
raise Argument_Error;
elsif Y > 0.0 then
return Cycle / 4.0;
elsif Y < 0.0 then
return -Cycle / 4.0;
end if;
-- Y is a NaN
elsif Y = 0.0 then
-- X /= 0
if X > 0.0 then
return 0.0;
elsif X < 0.0 then
return T'Copy_Sign (Cycle / 2.0, Y);
end if;
-- X is a NaN
end if;
return C_Atan2 (Y, X) * Cycle / (2.0 * Pi);
end Arctan;
-------------
-- Arctanh --
-------------
-- Exceptions:
-- Argument_Error is raised when abs (X) > 1.0
-- Constraint_Error is raised when X = +-1.0
-- Prescribed results:
-- Arctanh (0.0) = 0.0
-- TODO - general description
function Arctanh (X : Float_Type'Base) return Float_Type'Base is
begin
if not (abs (X) < 1.0) then
if abs (X) = 1.0 then
raise Constraint_Error;
else
raise Argument_Error;
end if;
else
return C_Atanh (X);
end if;
end Arctanh;
---------
-- Cos --
---------
-- (Natural cycle)
-- Prescribed results:
-- Cos (0.0) = 1.0
-- Special values:
-- Cos (X), where X is positive or negative infinity returns NaN value
-- The C_Cos function satisfies all requirements
function Cos (X : Float_Type'Base) return Float_Type'Base is
begin
return C_Cos (X);
end Cos;
-- (Arbitrary cycle)
-- Exceptions:
-- Argument_Error is raised when Cycle <= 0
-- Prescribed results:
-- Cos (X) = 0.0, when X is K * Cycle / 4.0 with odd integer K
-- Cos (X) = 1.0, when X is K * Cycle, with integer K
-- Cos (X) = -1.0, with X is K * Cycle / 2.0, with odd integer K
-- Special values:
-- Cos (X), where X is positive or negative infinity returns a
-- NaN value.
function Cos (X, Cycle : Float_Type'Base) return Float_Type'Base is
begin
-- Just reuse the code for Sin. The potential small
-- loss of speed is negligible with proper (front-end) inlining.
return -Sin (abs X - Cycle * 0.25, Cycle);
end Cos;
----------
-- Cosh --
----------
-- Prescribed results:
-- Cosh (0.0) = 1.0
-- Tightly approximated results:
-- TODO
-- TODO - general description
function Cosh (X : Float_Type'Base) return Float_Type'Base is
(C_Cosh (X));
---------
-- Cot --
---------
-- (natural cycle)
-- Exceptions:
-- Constraint_Error is raised when X = 0.0
-- As there is no cotangent function defined for C99, it is implemented
-- here in terms of the regular tangent function.
function Cot (X : Float_Type'Base) return Float_Type'Base is
begin
if not (X /= 0.0) then
raise Constraint_Error;
else
return 1.0 / C_Tan (X);
end if;
end Cot;
-- (arbitrary cycle)
-- Exceptions:
-- Argument_Error is raised when Cycle <= 0
-- Constraint_Error is raised when X = K * Cycle / 2.0, with integer K
-- Prescribed results:
-- Cot (X) = 0.0, when X is K * Cycle / 4.0 with odd integer K
-- Special values:
-- Cot (X), where X is positive or negative infinity returns NaN value
function Cot (X, Cycle : Float_Type'Base) return Float_Type'Base is
T, TA : Float_Type'Base;
begin
if not (Cycle > 0.0) then
raise Argument_Error;
end if;
T := Float_Type'Base'Remainder (X, Cycle) / Cycle;
TA := abs T;
if not (T /= 0.0 and then TA /= 0.5) then
raise Constraint_Error;
end if;
if TA = 0.25 then
return 0.0;
end if;
return 1.0 / C_Tan (T * 2.0 * Pi);
end Cot;
----------
-- Coth --
----------
-- Exceptions:
-- Argument_Error is raised when X = 0.
-- Tightly approximated results:
-- TODO
-- TODO - general description
function Coth (X : Float_Type'Base) return Float_Type'Base is
begin
if not (X /= 0.0) then
raise Argument_Error;
else
return 1.0 / C_Tanh (X);
end if;
end Coth;
---------
-- Exp --
---------
-- Prescribed results:
-- Exp (0.0) = 1.0
-- Special values:
-- Exp (X) = +0.0, for X is negative infinity
-- Exp (X) = X, for X is positive infinity
-- and Float_Type'Machine_Overflows = False
-- The C_Exp function satisfies all Ada requirements
function Exp (X : Float_Type'Base) return Float_Type'Base is
begin
return C_Exp (X);
end Exp;
---------
-- Log --
---------
-- (natural base)
-- Exceptions:
-- Argument is raised when X < 0.0
-- Constraint_Error is raised when X = 0.0
-- Prescribed results:
-- Log (1.0) = 0.0;
-- Special values:
-- Log (X) = X, for X is positive infinity
-- Apart from exceptions, the C_Log function satisfies all constraints
function Log (X : Float_Type'Base) return Float_Type'Base is
begin
-- The if statements are structured to ensure NaN parameters cause the
-- correct exception to be raised (since a NaN will always fail a
-- non-equal comparison test).
if not (X > 0.0) then
if X = 0.0 then
raise Constraint_Error;
end if;
raise Argument_Error;
end if;
return C_Log (X);
end Log;
-- (arbitrary base)
-- Exceptions:
-- Argument is raised when X < 0.0, Base <= 0.0 or Base = 1.0
-- Constraint_Error is raised when X = 0.0
-- Prescribed results:
-- Log (1.0, Base) = 0.0
-- Special values:
-- Log (X, Base) = X, for X is positive infinity
-- Apart from exceptions, the C_Log function satisfies all constraints
function Log (X, Base : Float_Type'Base) return Float_Type'Base is
begin
-- Try to execute the common case of X > 0.0 and Base > 1.0 with
-- minimal checks.
-- Note, the if statements are structured to ensure NaN parameters cause
-- the correct exception to be raised (since a NaN will always fail a
-- non-equal comparison test).
if not (X > 0.0) or else not (Base > 1.0) then
if not (X >= 0.0) or else not (Base > 0.0)
or else Base = 1.0
then
raise Argument_Error;
end if;
if X = 0.0 then
raise Constraint_Error;
end if;
end if;
return C_Log (X) / C_Log (Base);
end Log;
---------
-- Sin --
---------
-- (Natural cycle)
-- Prescribed results:
-- Sin (+0.0) = +0.0
-- Sin (-0.0) = -0.0
-- Special values:
-- Sin (X), where X is positive or negative infinity returns a
-- NaN value.
-- The C_Sin function satisfies all requirements
function Sin (X : Float_Type'Base) return Float_Type'Base is
begin
return C_Sin (X);
end Sin;
-- (Arbitrary cycle)
-- Exceptions:
-- Argument_Error is raised when Cycle <= 0
-- Prescribed results:
-- Sin (-0.0) = -0.0
-- Sin (+0.0) = +0.0
-- Sin (X) = 1.0, when X is K * Cycle + Cycle / 4.0, with integer K
-- Sin (X) = -1.0, with X is K * Cycle - Cycle / 4.0, with integer K
-- Special values:
-- Sin (X), where X is positive or negative infinity returns NaN value
function Sin (X, Cycle : Float_Type'Base) return Float_Type'Base is
T : Float_Type'Base;
begin
if not (Cycle > 0.0) then
raise Argument_Error;
end if;
T := Float_Type'Base'Remainder (X, Cycle);
-- The following reduction reduces the argument to the interval
-- [-0.5 Cycle, 0.5 * Cycle]. The entire reduction is exact.
if T > 0.25 * Cycle then
T := 0.5 * Cycle - T;
elsif T < -0.25 * Cycle then
T := -T - 0.5 * Cycle;
end if;
return C_Sin (T / Cycle * 2.0 * Pi);
end Sin;
----------
-- Sinh --
----------
-- Prescribed results:
-- Sinh (0.0) = 0.0
-- TODO - general description
function Sinh (X : Float_Type'Base) return Float_Type'Base is
(C_Sinh (X));
----------
-- Sqrt --
----------
-- Principle branch:
-- The result is nonnegative.
-- Exceptions:
-- Argument_Error is raised when X < 0.0
-- Prescribed results:
-- Sqrt (-0.0) = -0.0
-- Sqrt (+0.0) = +0.0
-- Sqrt (1.0) = 1.0
-- Special values:
-- Sqrt (X) = X, for X is positive infinity
-- C_Sqrt satisfies all requirements
function Sqrt (X : Float_Type'Base) return Float_Type'Base is
begin
if not (X >= 0.0) then
raise Argument_Error;
end if;
return C_Sqrt (X);
end Sqrt;
---------
-- Tan --
---------
-- (natural cycle)
-- Prescribed results:
-- Tan (-0.0) = -0.0
-- Tan (+0.0) = +0.0
-- Special values:
-- Tan (X) returns a NaN value, when X is positive or negative infinity
-- The C_Tan function satisfies all requirements
function Tan (X : Float_Type'Base) return Float_Type'Base is
begin
return C_Tan (X);
end Tan;
-- (arbitrary cycle)
-- Exceptions:
-- Argument_Error is raised for Cycle <= 0.0
-- Prescribed results:
-- Tan (-0.0, Cycle) = -0.0
-- Tan (+0.0, Cycle) = +0.0
-- Tan (X, Cycle) = 0, for X a multiple of Cycle / 2.0
-- Special values:
-- Tan (X, Cycle) returns a NaN value, when X is positive or
-- negative infinity
function Tan (X, Cycle : Float_Type'Base) return Float_Type'Base is
T : Float_Type'Base;
TA : Float_Type'Base;
begin
if not (Cycle > 0.0) then
raise Argument_Error;
end if;
T := Float_Type'Base'Remainder (X, Cycle) / Cycle;
TA := abs T;
-- The TA = 0.75 case is not needed because the remainder function
-- is defined so that it never returns a value greater than Cycle/2,
-- the value of TA will always be less than or equal to 0.5. Therefore,
-- the condition TA = 0.75 can never be true.
if TA = 0.25 then
raise Constraint_Error;
end if;
if TA = 0.5 then
return 0.0;
end if;
return C_Tan (T * 2.0 * Pi);
end Tan;
----------
-- Tanh --
----------
-- Principal branch:
-- The absolute value of the result is smaller than 1.0
-- Prescribed results:
-- Tanh (0.0) = 0.0
-- TODO - general description
function Tanh (X : Float_Type'Base) return Float_Type'Base is
(C_Tanh (X));
end System.Generic_C_Math_Interface;
|
--
-- Copyright (C) 2019, AdaCore
--
-- Copyright (c) 2010 - 2018, Nordic Semiconductor ASA
--
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form, except as embedded into a Nordic
-- Semiconductor ASA integrated circuit in a product or a software update
-- for such product, 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 Nordic Semiconductor ASA nor the names of its
-- contributors may be used to endorse or promote products derived from
-- this software without specific prior written permission.
--
-- 4. This software, with or without modification, must only be used with a
-- Nordic Semiconductor ASA integrated circuit.
--
-- 5. Any software provided in binary form under this license must not be
-- reverse engineered, decompiled, modified and/or disassembled.
--
-- THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-- WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR
-- ASA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--
-- This spec has been automatically generated from nrf52840.svd
pragma Ada_2012;
pragma Style_Checks (Off);
with System;
package Interfaces.NRF52.CCM is
pragma Preelaborate;
pragma No_Elaboration_Code_All;
---------------
-- Registers --
---------------
subtype TASKS_KSGEN_TASKS_KSGEN_Field is Interfaces.NRF52.Bit;
-- Start generation of key-stream. This operation will stop by itself when
-- completed.
type TASKS_KSGEN_Register is record
-- Write-only.
TASKS_KSGEN : TASKS_KSGEN_TASKS_KSGEN_Field := 16#0#;
-- unspecified
Reserved_1_31 : Interfaces.NRF52.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for TASKS_KSGEN_Register use record
TASKS_KSGEN at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
subtype TASKS_CRYPT_TASKS_CRYPT_Field is Interfaces.NRF52.Bit;
-- Start encryption/decryption. This operation will stop by itself when
-- completed.
type TASKS_CRYPT_Register is record
-- Write-only.
TASKS_CRYPT : TASKS_CRYPT_TASKS_CRYPT_Field := 16#0#;
-- unspecified
Reserved_1_31 : Interfaces.NRF52.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for TASKS_CRYPT_Register use record
TASKS_CRYPT at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
subtype TASKS_STOP_TASKS_STOP_Field is Interfaces.NRF52.Bit;
-- Stop encryption/decryption
type TASKS_STOP_Register is record
-- Write-only.
TASKS_STOP : TASKS_STOP_TASKS_STOP_Field := 16#0#;
-- unspecified
Reserved_1_31 : Interfaces.NRF52.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for TASKS_STOP_Register use record
TASKS_STOP at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
subtype TASKS_RATEOVERRIDE_TASKS_RATEOVERRIDE_Field is Interfaces.NRF52.Bit;
-- Override DATARATE setting in MODE register with the contents of the
-- RATEOVERRIDE register for any ongoing encryption/decryption
type TASKS_RATEOVERRIDE_Register is record
-- Write-only.
TASKS_RATEOVERRIDE : TASKS_RATEOVERRIDE_TASKS_RATEOVERRIDE_Field :=
16#0#;
-- unspecified
Reserved_1_31 : Interfaces.NRF52.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for TASKS_RATEOVERRIDE_Register use record
TASKS_RATEOVERRIDE at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
subtype EVENTS_ENDKSGEN_EVENTS_ENDKSGEN_Field is Interfaces.NRF52.Bit;
-- Key-stream generation complete
type EVENTS_ENDKSGEN_Register is record
EVENTS_ENDKSGEN : EVENTS_ENDKSGEN_EVENTS_ENDKSGEN_Field := 16#0#;
-- unspecified
Reserved_1_31 : Interfaces.NRF52.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for EVENTS_ENDKSGEN_Register use record
EVENTS_ENDKSGEN at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
subtype EVENTS_ENDCRYPT_EVENTS_ENDCRYPT_Field is Interfaces.NRF52.Bit;
-- Encrypt/decrypt complete
type EVENTS_ENDCRYPT_Register is record
EVENTS_ENDCRYPT : EVENTS_ENDCRYPT_EVENTS_ENDCRYPT_Field := 16#0#;
-- unspecified
Reserved_1_31 : Interfaces.NRF52.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for EVENTS_ENDCRYPT_Register use record
EVENTS_ENDCRYPT at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
subtype EVENTS_ERROR_EVENTS_ERROR_Field is Interfaces.NRF52.Bit;
-- Deprecated register - CCM error event
type EVENTS_ERROR_Register is record
EVENTS_ERROR : EVENTS_ERROR_EVENTS_ERROR_Field := 16#0#;
-- unspecified
Reserved_1_31 : Interfaces.NRF52.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for EVENTS_ERROR_Register use record
EVENTS_ERROR at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
-- Shortcut between ENDKSGEN event and CRYPT task
type SHORTS_ENDKSGEN_CRYPT_Field is
(-- Disable shortcut
Disabled,
-- Enable shortcut
Enabled)
with Size => 1;
for SHORTS_ENDKSGEN_CRYPT_Field use
(Disabled => 0,
Enabled => 1);
-- Shortcut register
type SHORTS_Register is record
-- Shortcut between ENDKSGEN event and CRYPT task
ENDKSGEN_CRYPT : SHORTS_ENDKSGEN_CRYPT_Field :=
Interfaces.NRF52.CCM.Disabled;
-- unspecified
Reserved_1_31 : Interfaces.NRF52.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SHORTS_Register use record
ENDKSGEN_CRYPT at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
-- Write '1' to enable interrupt for ENDKSGEN event
type INTENSET_ENDKSGEN_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENSET_ENDKSGEN_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to enable interrupt for ENDKSGEN event
type INTENSET_ENDKSGEN_Field_1 is
(-- Reset value for the field
Intenset_Endksgen_Field_Reset,
-- Enable
Set)
with Size => 1;
for INTENSET_ENDKSGEN_Field_1 use
(Intenset_Endksgen_Field_Reset => 0,
Set => 1);
-- Write '1' to enable interrupt for ENDCRYPT event
type INTENSET_ENDCRYPT_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENSET_ENDCRYPT_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to enable interrupt for ENDCRYPT event
type INTENSET_ENDCRYPT_Field_1 is
(-- Reset value for the field
Intenset_Endcrypt_Field_Reset,
-- Enable
Set)
with Size => 1;
for INTENSET_ENDCRYPT_Field_1 use
(Intenset_Endcrypt_Field_Reset => 0,
Set => 1);
-- Write '1' to enable interrupt for ERROR event
type INTENSET_ERROR_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENSET_ERROR_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to enable interrupt for ERROR event
type INTENSET_ERROR_Field_1 is
(-- Reset value for the field
Intenset_Error_Field_Reset,
-- Enable
Set)
with Size => 1;
for INTENSET_ERROR_Field_1 use
(Intenset_Error_Field_Reset => 0,
Set => 1);
-- Enable interrupt
type INTENSET_Register is record
-- Write '1' to enable interrupt for ENDKSGEN event
ENDKSGEN : INTENSET_ENDKSGEN_Field_1 :=
Intenset_Endksgen_Field_Reset;
-- Write '1' to enable interrupt for ENDCRYPT event
ENDCRYPT : INTENSET_ENDCRYPT_Field_1 :=
Intenset_Endcrypt_Field_Reset;
-- Write '1' to enable interrupt for ERROR event
ERROR : INTENSET_ERROR_Field_1 := Intenset_Error_Field_Reset;
-- unspecified
Reserved_3_31 : Interfaces.NRF52.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for INTENSET_Register use record
ENDKSGEN at 0 range 0 .. 0;
ENDCRYPT at 0 range 1 .. 1;
ERROR at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
-- Write '1' to disable interrupt for ENDKSGEN event
type INTENCLR_ENDKSGEN_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENCLR_ENDKSGEN_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to disable interrupt for ENDKSGEN event
type INTENCLR_ENDKSGEN_Field_1 is
(-- Reset value for the field
Intenclr_Endksgen_Field_Reset,
-- Disable
Clear)
with Size => 1;
for INTENCLR_ENDKSGEN_Field_1 use
(Intenclr_Endksgen_Field_Reset => 0,
Clear => 1);
-- Write '1' to disable interrupt for ENDCRYPT event
type INTENCLR_ENDCRYPT_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENCLR_ENDCRYPT_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to disable interrupt for ENDCRYPT event
type INTENCLR_ENDCRYPT_Field_1 is
(-- Reset value for the field
Intenclr_Endcrypt_Field_Reset,
-- Disable
Clear)
with Size => 1;
for INTENCLR_ENDCRYPT_Field_1 use
(Intenclr_Endcrypt_Field_Reset => 0,
Clear => 1);
-- Write '1' to disable interrupt for ERROR event
type INTENCLR_ERROR_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENCLR_ERROR_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to disable interrupt for ERROR event
type INTENCLR_ERROR_Field_1 is
(-- Reset value for the field
Intenclr_Error_Field_Reset,
-- Disable
Clear)
with Size => 1;
for INTENCLR_ERROR_Field_1 use
(Intenclr_Error_Field_Reset => 0,
Clear => 1);
-- Disable interrupt
type INTENCLR_Register is record
-- Write '1' to disable interrupt for ENDKSGEN event
ENDKSGEN : INTENCLR_ENDKSGEN_Field_1 :=
Intenclr_Endksgen_Field_Reset;
-- Write '1' to disable interrupt for ENDCRYPT event
ENDCRYPT : INTENCLR_ENDCRYPT_Field_1 :=
Intenclr_Endcrypt_Field_Reset;
-- Write '1' to disable interrupt for ERROR event
ERROR : INTENCLR_ERROR_Field_1 := Intenclr_Error_Field_Reset;
-- unspecified
Reserved_3_31 : Interfaces.NRF52.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for INTENCLR_Register use record
ENDKSGEN at 0 range 0 .. 0;
ENDCRYPT at 0 range 1 .. 1;
ERROR at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
-- The result of the MIC check performed during the previous decryption
-- operation
type MICSTATUS_MICSTATUS_Field is
(-- MIC check failed
Checkfailed,
-- MIC check passed
Checkpassed)
with Size => 1;
for MICSTATUS_MICSTATUS_Field use
(Checkfailed => 0,
Checkpassed => 1);
-- MIC check result
type MICSTATUS_Register is record
-- Read-only. The result of the MIC check performed during the previous
-- decryption operation
MICSTATUS : MICSTATUS_MICSTATUS_Field;
-- unspecified
Reserved_1_31 : Interfaces.NRF52.UInt31;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MICSTATUS_Register use record
MICSTATUS at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
-- Enable or disable CCM
type ENABLE_ENABLE_Field is
(-- Disable
Disabled,
-- Enable
Enabled)
with Size => 2;
for ENABLE_ENABLE_Field use
(Disabled => 0,
Enabled => 2);
-- Enable
type ENABLE_Register is record
-- Enable or disable CCM
ENABLE : ENABLE_ENABLE_Field := Interfaces.NRF52.CCM.Disabled;
-- unspecified
Reserved_2_31 : Interfaces.NRF52.UInt30 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for ENABLE_Register use record
ENABLE at 0 range 0 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- The mode of operation to be used. The settings in this register apply
-- whenever either the KSGEN or CRYPT tasks are triggered.
type MODE_MODE_Field is
(-- AES CCM packet encryption mode
Encryption,
-- AES CCM packet decryption mode
Decryption)
with Size => 1;
for MODE_MODE_Field use
(Encryption => 0,
Decryption => 1);
-- Radio data rate that the CCM shall run synchronous with
type MODE_DATARATE_Field is
(-- 1 Mbps
Val_1Mbit,
-- 2 Mbps
Val_2Mbit,
-- 125 Kbps
Val_125Kbps,
-- 500 Kbps
Val_500Kbps)
with Size => 2;
for MODE_DATARATE_Field use
(Val_1Mbit => 0,
Val_2Mbit => 1,
Val_125Kbps => 2,
Val_500Kbps => 3);
-- Packet length configuration
type MODE_LENGTH_Field is
(-- Default length. Effective length of LENGTH field in encrypted/decrypted
-- packet is 5 bits. A key-stream for packet payloads up to 27 bytes will be
-- generated.
Default,
-- Extended length. Effective length of LENGTH field in encrypted/decrypted
-- packet is 8 bits. A key-stream for packet payloads up to MAXPACKETSIZE
-- bytes will be generated.
Extended)
with Size => 1;
for MODE_LENGTH_Field use
(Default => 0,
Extended => 1);
-- Operation mode
type MODE_Register is record
-- The mode of operation to be used. The settings in this register apply
-- whenever either the KSGEN or CRYPT tasks are triggered.
MODE : MODE_MODE_Field := Interfaces.NRF52.CCM.Decryption;
-- unspecified
Reserved_1_15 : Interfaces.NRF52.UInt15 := 16#0#;
-- Radio data rate that the CCM shall run synchronous with
DATARATE : MODE_DATARATE_Field := Interfaces.NRF52.CCM.Val_1Mbit;
-- unspecified
Reserved_18_23 : Interfaces.NRF52.UInt6 := 16#0#;
-- Packet length configuration
LENGTH : MODE_LENGTH_Field := Interfaces.NRF52.CCM.Default;
-- unspecified
Reserved_25_31 : Interfaces.NRF52.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MODE_Register use record
MODE at 0 range 0 .. 0;
Reserved_1_15 at 0 range 1 .. 15;
DATARATE at 0 range 16 .. 17;
Reserved_18_23 at 0 range 18 .. 23;
LENGTH at 0 range 24 .. 24;
Reserved_25_31 at 0 range 25 .. 31;
end record;
subtype MAXPACKETSIZE_MAXPACKETSIZE_Field is Interfaces.NRF52.Byte;
-- Length of key-stream generated when MODE.LENGTH = Extended.
type MAXPACKETSIZE_Register is record
-- Length of key-stream generated when MODE.LENGTH = Extended. This
-- value must be greater or equal to the subsequent packet payload to be
-- encrypted/decrypted.
MAXPACKETSIZE : MAXPACKETSIZE_MAXPACKETSIZE_Field := 16#FB#;
-- unspecified
Reserved_8_31 : Interfaces.NRF52.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MAXPACKETSIZE_Register use record
MAXPACKETSIZE at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-- Data rate override setting.
type RATEOVERRIDE_RATEOVERRIDE_Field is
(-- 1 Mbps
Val_1Mbit,
-- 2 Mbps
Val_2Mbit,
-- 125 Kbps
Val_125Kbps,
-- 500 Kbps
Val_500Kbps)
with Size => 2;
for RATEOVERRIDE_RATEOVERRIDE_Field use
(Val_1Mbit => 0,
Val_2Mbit => 1,
Val_125Kbps => 2,
Val_500Kbps => 3);
-- Data rate override setting.
type RATEOVERRIDE_Register is record
-- Data rate override setting.
RATEOVERRIDE : RATEOVERRIDE_RATEOVERRIDE_Field :=
Interfaces.NRF52.CCM.Val_1Mbit;
-- unspecified
Reserved_2_31 : Interfaces.NRF52.UInt30 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RATEOVERRIDE_Register use record
RATEOVERRIDE at 0 range 0 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- AES CCM Mode Encryption
type CCM_Peripheral is record
-- Start generation of key-stream. This operation will stop by itself
-- when completed.
TASKS_KSGEN : aliased TASKS_KSGEN_Register;
-- Start encryption/decryption. This operation will stop by itself when
-- completed.
TASKS_CRYPT : aliased TASKS_CRYPT_Register;
-- Stop encryption/decryption
TASKS_STOP : aliased TASKS_STOP_Register;
-- Override DATARATE setting in MODE register with the contents of the
-- RATEOVERRIDE register for any ongoing encryption/decryption
TASKS_RATEOVERRIDE : aliased TASKS_RATEOVERRIDE_Register;
-- Key-stream generation complete
EVENTS_ENDKSGEN : aliased EVENTS_ENDKSGEN_Register;
-- Encrypt/decrypt complete
EVENTS_ENDCRYPT : aliased EVENTS_ENDCRYPT_Register;
-- Deprecated register - CCM error event
EVENTS_ERROR : aliased EVENTS_ERROR_Register;
-- Shortcut register
SHORTS : aliased SHORTS_Register;
-- Enable interrupt
INTENSET : aliased INTENSET_Register;
-- Disable interrupt
INTENCLR : aliased INTENCLR_Register;
-- MIC check result
MICSTATUS : aliased MICSTATUS_Register;
-- Enable
ENABLE : aliased ENABLE_Register;
-- Operation mode
MODE : aliased MODE_Register;
-- Pointer to data structure holding AES key and NONCE vector
CNFPTR : aliased Interfaces.NRF52.UInt32;
-- Input pointer
INPTR : aliased Interfaces.NRF52.UInt32;
-- Output pointer
OUTPTR : aliased Interfaces.NRF52.UInt32;
-- Pointer to data area used for temporary storage
SCRATCHPTR : aliased Interfaces.NRF52.UInt32;
-- Length of key-stream generated when MODE.LENGTH = Extended.
MAXPACKETSIZE : aliased MAXPACKETSIZE_Register;
-- Data rate override setting.
RATEOVERRIDE : aliased RATEOVERRIDE_Register;
end record
with Volatile;
for CCM_Peripheral use record
TASKS_KSGEN at 16#0# range 0 .. 31;
TASKS_CRYPT at 16#4# range 0 .. 31;
TASKS_STOP at 16#8# range 0 .. 31;
TASKS_RATEOVERRIDE at 16#C# range 0 .. 31;
EVENTS_ENDKSGEN at 16#100# range 0 .. 31;
EVENTS_ENDCRYPT at 16#104# range 0 .. 31;
EVENTS_ERROR at 16#108# range 0 .. 31;
SHORTS at 16#200# range 0 .. 31;
INTENSET at 16#304# range 0 .. 31;
INTENCLR at 16#308# range 0 .. 31;
MICSTATUS at 16#400# range 0 .. 31;
ENABLE at 16#500# range 0 .. 31;
MODE at 16#504# range 0 .. 31;
CNFPTR at 16#508# range 0 .. 31;
INPTR at 16#50C# range 0 .. 31;
OUTPTR at 16#510# range 0 .. 31;
SCRATCHPTR at 16#514# range 0 .. 31;
MAXPACKETSIZE at 16#518# range 0 .. 31;
RATEOVERRIDE at 16#51C# range 0 .. 31;
end record;
-- AES CCM Mode Encryption
CCM_Periph : aliased CCM_Peripheral
with Import, Address => CCM_Base;
end Interfaces.NRF52.CCM;
|
-----------------------------------------------------------------------
-- babel-commands -- Commands for Babel
-- Copyright (C) 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Text_IO;
with Ada.Command_Line;
with GNAT.Command_Line;
with Util.Log.Loggers;
with Babel.Commands.Save;
package body Babel.Commands is
use Ada.Strings.Unbounded;
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Babel.Commands");
Commands : Command_Maps.Map;
-- ------------------------------
-- Write the command usage.
-- ------------------------------
procedure Usage (Cmd : in Command) is
begin
null;
end Usage;
-- ------------------------------
-- Print a message on the standard output.
-- ------------------------------
procedure Print (Cmd : in Command;
Message : in String) is
pragma Unreferenced (Cmd);
begin
Ada.Text_IO.Put_Line (Message);
end Print;
-- ------------------------------
-- Print dynamo usage
-- ------------------------------
procedure Usage is
use Ada.Text_IO;
begin
-- Put_Line (Gen.Configs.RELEASE);
New_Line;
Put ("Usage: ");
Put (Ada.Command_Line.Command_Name);
Put_Line (" [-v] [-o directory] [-t templates] {command} {arguments}");
Put_Line ("where:");
Put_Line (" -v Print the version, configuration and installation paths");
Put_Line (" -o directory Directory where the Ada mapping files are generated");
Put_Line (" -t templates Directory where the Ada templates are defined");
Put_Line (" -c dir Directory where the Ada templates "
& "and configurations are defined");
end Usage;
-- ------------------------------
-- Print dynamo short usage.
-- ------------------------------
procedure Short_Help_Usage is
use Ada.Text_IO;
begin
New_Line;
Put ("Type '");
Put (Ada.Command_Line.Command_Name);
Put_Line (" help' for the list of commands.");
end Short_Help_Usage;
-- ------------------------------
-- Execute the command with the arguments.
-- ------------------------------
procedure Execute (Cmd : in Help_Command) is
pragma Unreferenced (Cmd);
procedure Print (Position : in Command_Maps.Cursor);
use Ada.Text_IO;
use GNAT.Command_Line;
procedure Print (Position : in Command_Maps.Cursor) is
Name : constant Unbounded_String := Command_Maps.Key (Position);
begin
Put_Line (" " & To_String (Name));
end Print;
Name : constant String := Get_Argument;
begin
Log.Debug ("Execute command {0}", Name);
if Name'Length = 0 then
Usage;
New_Line;
Put ("Type '");
Put (Ada.Command_Line.Command_Name);
Put_Line (" help {command}' for help on a specific command.");
New_Line;
Put_Line ("Available subcommands:");
Commands.Iterate (Process => Print'Access);
else
declare
Target_Cmd : constant Command_Access := Find_Command (Name);
begin
if Target_Cmd = null then
Log.Error ("Unknown command {0}", Name);
else
Target_Cmd.Help;
end if;
end;
end if;
end Execute;
-- ------------------------------
-- Write the help associated with the command.
-- ------------------------------
procedure Help (Cmd : in Help_Command) is
begin
null;
end Help;
-- ------------------------------
-- Register the command under the given name.
-- ------------------------------
procedure Add_Command (Cmd : in Command_Access;
Name : in String) is
begin
Commands.Include (Key => To_Unbounded_String (Name), New_Item => Cmd);
end Add_Command;
-- ------------------------------
-- Find the command having the given name.
-- ------------------------------
function Find_Command (Name : in String) return Command_Access is
Pos : constant Command_Maps.Cursor := Commands.Find (To_Unbounded_String (Name));
begin
if Command_Maps.Has_Element (Pos) then
return Command_Maps.Element (Pos);
else
return null;
end if;
end Find_Command;
-- Save command.
Save_Cmd : aliased Babel.Commands.Save.Command;
-- Help command.
Help_Cmd : aliased Help_Command;
begin
Add_Command (Name => "help", Cmd => Help_Cmd'Access);
Add_Command (Name => "save", Cmd => Save_Cmd'Access);
end Babel.Commands;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.