content
stringlengths 23
1.05M
|
|---|
------------------------------------------------------------------------------
-- G P S --
-- --
-- Copyright (C) 2004-2016, AdaCore --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. This software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details. You should have received a copy of the GNU --
-- General Public License distributed with this software; see file --
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
-- of the license. --
------------------------------------------------------------------------------
-- Case support for case insensitive languages. This package has
-- services to change the casing of a word (identifier or keyword) and
-- to handle a set of casing exceptions.
with Basic_Types; use Basic_Types;
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Wide_Wide_Hash;
package Case_Handling is
type Casing_Policy is (Disabled, End_Of_Line, End_Of_Word, On_The_Fly);
for Casing_Policy'Size use Integer'Size;
pragma Convention (C, Casing_Policy);
-- The list of supported casing policies.
-- - Disable means that no auto-casing will be applied to the buffer
-- - End_Of_Line casing done when pressing return
-- - On_The_Fly casing is done when inserting a word separator
type Casing_Type is (Unchanged, Upper, Lower, Mixed, Smart_Mixed);
for Casing_Type'Size use Integer'Size;
pragma Convention (C, Casing_Type);
-- Casing used for identifiers and reserved words.
-- Only relevant for case insensitive languages.
-- - Mixed: Set first character of each word and characters after an
-- underscore to upper-case, all other characters are set to lower-case.
-- - Smart_Mixed: As Mixed but never force an upper-case to lower-case.
function Mixed_Case
(S : UTF8_String; Smart : Boolean := False) return UTF8_String;
-- Return S with a casing matching Ada style: upper case after an
-- underscore or a dot.
-- If smart is set, do not change upper-case letters in S
---------------------
-- Case Exceptions --
---------------------
type Casing_Exceptions is private;
-- This is the case exceptions handler, a set of exceptions to the
-- standard casing rule can be recorded into this object.
No_Casing_Exception : aliased constant Casing_Exceptions;
function Set_Case
(C : Casing_Exceptions;
Word : UTF8_String;
Casing : Casing_Type) return UTF8_String;
-- Change the case of Str as specified by Casing. This routine also
-- checks for case exceptions.
procedure Add_Exception
(C : in out Casing_Exceptions;
Word : String;
Read_Only : Boolean);
-- Add a case exception into the container. Read_Only must be set for
-- case exception that can't be removed interactively.
procedure Add_Substring_Exception
(C : in out Casing_Exceptions;
Substring : String;
Read_Only : Boolean);
-- Add a substring case exception into the container. Read_Only must be set
-- for case exception that can't be removed interactively.
procedure Remove_Exception (C : in out Casing_Exceptions; Word : String);
-- Remove a case exception from the container
procedure Remove_Substring_Exception
(C : in out Casing_Exceptions;
Substring : String);
-- Remove a substring case exception from the container
procedure Destroy (C : in out Casing_Exceptions);
-- Destroy the case exceptions handler, release all memory associated
-- with this object.
private
type W_Node (Size : Natural) is record
Read_Only : Boolean;
-- Set to True if this case exception is read only (can't be removed).
-- Such case exception comes from a global .xml files.
Word : Wide_Wide_String (1 .. Size);
end record;
package Casing_Exception_Table is new Ada.Containers.Indefinite_Hashed_Maps
(Key_Type => Wide_Wide_String,
Element_Type => W_Node,
Hash => Ada.Strings.Wide_Wide_Hash,
Equivalent_Keys => "=");
use Casing_Exception_Table;
type Exceptions_Table is access Map;
-- Exception Word handler, each exception is inserted into this hash
-- table. The key is the word in lower-case, the associated
-- value is the word with the right casing.
type Casing_Exceptions is record
E : Exceptions_Table := new Map;
S : Exceptions_Table := new Map;
end record;
No_Casing_Exception : aliased constant Casing_Exceptions :=
(E => null, S => null);
end Case_Handling;
|
------------------------------------------------------------------------------
-- Copyright (c) 2015, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
with Natools.Web.Escapes;
package body Natools.Web.Filters.Text_Blocks is
Begin_Paragraph : constant Ada.Streams.Stream_Element_Array
:= (1 => Character'Pos ('<'),
2 => Character'Pos ('p'),
3 => Character'Pos ('>'));
End_Paragraph : constant Ada.Streams.Stream_Element_Array
:= (1 => Character'Pos ('<'),
2 => Character'Pos ('/'),
3 => Character'Pos ('p'),
4 => Character'Pos ('>'));
function Newline (Encoding : Newline_Encoding)
return Ada.Streams.Stream_Element_Array;
-- Return the newline representation assicated with Encoding
------------------------------
-- Local Helper Subprograms --
------------------------------
function Newline (Encoding : Newline_Encoding)
return Ada.Streams.Stream_Element_Array is
begin
case Encoding is
when CR => return (1 => 13);
when LF => return (1 => 10);
when CR_LF => return (1 => 13, 2 => 10);
end case;
end Newline;
----------------------
-- Public Interface --
----------------------
overriding procedure Apply
(Object : in Filter;
Output : in out Ada.Streams.Root_Stream_Type'Class;
Data : in Ada.Streams.Stream_Element_Array)
is
use type Ada.Streams.Stream_Element_Offset;
type Automaton_State is
(CR_Read, LF_Read, Newline_Read, Between_Paragraphs, In_Text);
State : Automaton_State := Between_Paragraphs;
Index : Ada.Streams.Stream_Element_Offset := Data'First;
begin
while Index in Data'Range loop
case Data (Index) is
when 13 =>
case State is
when CR_Read | Newline_Read =>
Output.Write (End_Paragraph);
Output.Write (Newline (Object.Encoding));
State := Between_Paragraphs;
when LF_Read =>
State := Newline_Read;
when Between_Paragraphs =>
null;
when In_Text =>
State := CR_Read;
end case;
Index := Index + 1;
when 10 =>
case State is
when LF_Read | Newline_Read =>
Output.Write (End_Paragraph);
State := Between_Paragraphs;
when CR_Read =>
State := Newline_Read;
when Between_Paragraphs =>
null;
when In_Text =>
State := LF_Read;
end case;
Index := Index + 1;
when others =>
case State is
when CR_Read | LF_Read | Newline_Read =>
Output.Write (Newline (Object.Encoding));
when Between_Paragraphs =>
Output.Write (Begin_Paragraph);
when In_Text =>
null;
end case;
State := In_Text;
declare
Next : Ada.Streams.Stream_Element_Offset := Index + 1;
begin
while Next in Data'Range
and then Data (Next) not in 10 | 13
loop
Next := Next + 1;
end loop;
Escapes.Write
(Output, Data (Index .. Next - 1), Escapes.HTML_Body);
Index := Next;
end;
end case;
end loop;
case State is
when Between_Paragraphs =>
null;
when CR_Read | LF_Read | Newline_Read | In_Text =>
Output.Write (End_Paragraph);
Output.Write (Newline (Object.Encoding));
end case;
end Apply;
function Create
(Arguments : in out S_Expressions.Lockable.Descriptor'Class)
return Filters.Filter'Class
is
use type S_Expressions.Events.Event;
Result : Filter;
begin
if Arguments.Current_Event = S_Expressions.Events.Add_Atom then
begin
Result.Encoding := Newline_Encoding'Value
(S_Expressions.To_String (Arguments.Current_Atom));
exception
when Constraint_Error => null;
end;
end if;
return Result;
end Create;
not overriding procedure Set_Newline_Encoding
(Object : in out Filter;
Encoding : in Newline_Encoding) is
begin
Object.Encoding := Encoding;
end Set_Newline_Encoding;
end Natools.Web.Filters.Text_Blocks;
|
procedure ess is
x : float := 3.4;
y : float;
begin
y := float'large; -- this line is ok
y := x'large;
end ess;
|
with DOM.Core;
with Route_Aggregator; use Route_Aggregator;
with Route_Aggregator_Communication; use Route_Aggregator_Communication;
with Route_Aggregator_Common; use Route_Aggregator_Common;
with Ada.Containers.Ordered_Maps;
with Ada.Containers.Ordered_Sets;
with AVTAS.LMCP.Types;
with AFRL.CMASI.EntityState; use AFRL.CMASI.EntityState;
with Afrl.Cmasi.EntityConfiguration; use Afrl.Cmasi.EntityConfiguration;
with Uxas.Messages.Lmcptask.UniqueAutomationRequest; use Uxas.Messages.Lmcptask.UniqueAutomationRequest;
with UxAS.Messages.Lmcptask.TaskPlanOptions; use UxAS.Messages.Lmcptask.TaskPlanOptions;
package UxAS.Comms.LMCP_Net_Client.Service.Route_Aggregation is
type Route_Aggregator_Service is new Service_Base with private;
Type_Name : constant String := "RouteAggregatorService";
Directory_Name : constant String := "";
-- static const std::vector<std::string>
-- s_registryServiceTypeNames()
function Registry_Service_Type_Names return Service_Type_Names_List;
-- static ServiceBase*
-- create()
function Create return Any_Service;
private
type Route_Aggregator_Service is new Service_Base with record
-- the following types are defined in SPARK code
Mailbox : Route_Aggregator_Mailbox;
State : Route_Aggregator_State;
Config : Route_Aggregator_Configuration_Data;
end record;
overriding
procedure Configure
(This : in out Route_Aggregator_Service;
XML_Node : DOM.Core.Element;
Result : out Boolean);
overriding
procedure Initialize
(This : in out Route_Aggregator_Service;
Result : out Boolean);
overriding
procedure Process_Received_LMCP_Message
(This : in out Route_Aggregator_Service;
Received_Message : not null Any_LMCP_Message;
Should_Terminate : out Boolean);
end UxAS.Comms.LMCP_Net_Client.Service.Route_Aggregation;
|
----------------------------------------------------------------------------
--
-- Ada client for BaseX
--
----------------------------------------------------------------------------
with Ada.Strings.Unbounded;
with Ada.Containers.Indefinite_Vectors;
with GNAT.Sockets;
package AdaBaseXClient is
package String_Vectors is new Ada.Containers.Indefinite_Vectors
(Natural, String);
use String_Vectors;
--
-- BaseX exception
--
BaseXException : exception;
--
-- For Query Command Protocol
--
type Query is tagged private;
--
-- Inserts a document in the database at the specified path
--
function Add (Path : String; Input : String) return String;
--
-- Authenticate for this session
--
function Authenticate (Username : String; Password : String) return Boolean;
--
-- Bind procedure for Query class
--
procedure Bind
(Self : Query; Name : String; Value : String; Stype : String);
--
-- Close a connection to the host
--
procedure Close;
--
-- Close procedure for Query class
--
procedure Close (Self : out Query);
--
-- Open a connection to the host
--
function Connect (Server : String; Port : Natural) return Boolean;
--
-- Create a new database, inserts initial content
--
function Create (Name : String; Input : String) return String;
--
-- Create a new Query instance
--
function CreateQuery (Qstring : String) return Query;
--
-- Execute BaseX command
--
function Execute (command : String) return String;
--
-- Execute function for Query class
--
function Execute (Self : Query) return String;
--
-- Return process information
--
function Info return String;
--
-- Initialize procedure for Query class
--
procedure Initialize (Self : out Query; MyId : String);
--
-- Replaces content at the specified path by the given document
--
function Replace (Path : String; Input : String) return String;
--
-- Results function for Query class
-- Returns all resulting items as strings
--
function Results (Self : Query) return String_Vectors.Vector;
--
-- Stores a binary resource in the opened database
--
function Store (Path : String; Input : String) return String;
private
--
-- Socket variable
--
Socket : GNAT.Sockets.Socket_Type;
Channel : GNAT.Sockets.Stream_Access;
type Query is tagged record
Id : Ada.Strings.Unbounded.Unbounded_String;
end record;
--
-- Read data from server
--
function Read return String;
--
-- Read string from server
--
function ReadString return String;
--
-- Send data to server
--
procedure Send (Command : String);
--
-- Send Command to server
--
procedure SendCmd (Code : Natural; Arg : String; Input : String);
--
-- Read status single byte from socket.
-- Server replies with \00 (success) or \01 (error).
--
function Status return Boolean;
end AdaBaseXClient;
|
with OpenAL.Thin;
with Interfaces.C;
with Interfaces.C.Strings;
package body OpenAL.Global is
package C renames Interfaces.C;
package C_Strings renames Interfaces.C.Strings;
function Get_String (Parameter : Types.Enumeration_t) return C_Strings.chars_ptr;
pragma Import (C, Get_String, "alGetString");
type Map_From_Distance_Model_t is array (Distance_Model_t) of Types.Enumeration_t;
Map_From_Distance_Model : constant Map_From_Distance_Model_t :=
(None => Thin.AL_NONE,
Inverse_Distance => Thin.AL_INVERSE_DISTANCE,
Inverse_Distance_Clamped => Thin.AL_INVERSE_DISTANCE_CLAMPED,
Linear_Distance => Thin.AL_LINEAR_DISTANCE,
Linear_Distance_Clamped => Thin.AL_LINEAR_DISTANCE_CLAMPED,
Exponent_Distance => Thin.AL_EXPONENT_DISTANCE,
Exponent_Distance_Clamped => Thin.AL_EXPONENT_DISTANCE_CLAMPED,
Unknown_Distance_Model => 0);
function Extensions return String is
begin
return C_Strings.Value (Get_String (Thin.AL_EXTENSIONS));
end Extensions;
--
-- Get_*
--
function Get_Distance_Model return Distance_Model_t is
Value : Types.Integer_t;
Return_Value : Distance_Model_t;
begin
Value := Thin.Get_Integer (Thin.AL_DISTANCE_MODEL);
case Value is
when Thin.AL_NONE => Return_Value := None;
when Thin.AL_INVERSE_DISTANCE => Return_Value := Inverse_Distance;
when Thin.AL_INVERSE_DISTANCE_CLAMPED => Return_Value := Inverse_Distance_Clamped;
when Thin.AL_LINEAR_DISTANCE => Return_Value := Linear_Distance;
when Thin.AL_LINEAR_DISTANCE_CLAMPED => Return_Value := Linear_Distance_Clamped;
when Thin.AL_EXPONENT_DISTANCE => Return_Value := Exponent_Distance;
when Thin.AL_EXPONENT_DISTANCE_CLAMPED => Return_Value := Exponent_Distance_Clamped;
when others => Return_Value := Unknown_Distance_Model;
end case;
return Return_Value;
end Get_Distance_Model;
function Get_Doppler_Factor return Types.Natural_Float_t is
begin
return Thin.Get_Float (Thin.AL_DOPPLER_FACTOR);
end Get_Doppler_Factor;
function Get_Speed_Of_Sound return Types.Positive_Float_t is
begin
return Thin.Get_Float (Thin.AL_SPEED_OF_SOUND);
end Get_Speed_Of_Sound;
--
-- Is_Extension_Present
--
function Is_Extension_Present (Name : in String) return Boolean is
C_Name : aliased C.char_array := C.To_C (Name);
begin
return Boolean (Thin.Is_Extension_Present (C_Name (C_Name'First)'Address));
end Is_Extension_Present;
function Renderer return String is
begin
return C_Strings.Value (Get_String (Thin.AL_RENDERER));
end Renderer;
--
-- Set_*
--
procedure Set_Distance_Model (Model : in Valid_Distance_Model_t) is
begin
Thin.Distance_Model (Map_From_Distance_Model (Model));
end Set_Distance_Model;
procedure Set_Doppler_Factor (Factor : in Types.Natural_Float_t) is
begin
Thin.Doppler_Factor (Factor);
end Set_Doppler_Factor;
procedure Set_Speed_Of_Sound (Factor : in Types.Positive_Float_t) is
begin
Thin.Speed_Of_Sound (Factor);
end Set_Speed_Of_Sound;
function Vendor return String is
begin
return C_Strings.Value (Get_String (Thin.AL_VENDOR));
end Vendor;
function Version return String is
begin
return C_Strings.Value (Get_String (Thin.AL_VERSION));
end Version;
end OpenAL.Global;
|
package MatrixMult is
SIZE : constant Integer := 10;
type Matrix is array(1..SIZE,1..SIZE) of Integer;
procedure MatMult(A, B : Matrix; C : out Matrix);
end MatrixMult;
|
-----------------------------------------------------------------------
-- util-serialize-io-xml -- XML Serialization Driver
-- Copyright (C) 2011, 2012, 2013, 2016, 2017, 2020, 2021 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Characters.Conversions;
with Unicode;
with Unicode.CES.Utf8;
with Util.Log.Loggers;
with Util.Strings;
with Util.Dates.ISO8601;
with Util.Streams.Texts.TR;
with Util.Streams.Texts.WTR;
with Util.Beans.Objects.Maps;
package body Util.Serialize.IO.XML is
use Sax.Readers;
use Sax.Exceptions;
use Sax.Locators;
use Sax.Attributes;
use Unicode;
use Unicode.CES;
use Ada.Strings.Unbounded;
-- The logger
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Util.Serialize.IO.XML");
-- Return the location where the exception was raised.
function Get_Location (Except : Sax.Exceptions.Sax_Parse_Exception'Class)
return String is separate;
-- ------------------------------
-- Warning
-- ------------------------------
overriding
procedure Warning (Handler : in out Xhtml_Reader;
Except : Sax.Exceptions.Sax_Parse_Exception'Class) is
pragma Warnings (Off, Handler);
begin
Log.Warn ("{0}", Get_Message (Except));
end Warning;
-- ------------------------------
-- Error
-- ------------------------------
overriding
procedure Error (Handler : in out Xhtml_Reader;
Except : in Sax.Exceptions.Sax_Parse_Exception'Class) is
Msg : constant String := Get_Message (Except);
Pos : constant Natural := Util.Strings.Index (Msg, ' ');
begin
-- The SAX error message contains the line+file name. Remove it because this part
-- will be added by the <b>Error</b> procedure.
if Pos > Msg'First and then Msg (Pos - 1) = ':' then
Handler.Handler.Error (Msg (Pos + 1 .. Msg'Last));
else
Handler.Handler.Error (Msg);
end if;
end Error;
-- ------------------------------
-- Fatal_Error
-- ------------------------------
overriding
procedure Fatal_Error (Handler : in out Xhtml_Reader;
Except : in Sax.Exceptions.Sax_Parse_Exception'Class) is
begin
Handler.Error (Except);
end Fatal_Error;
-- ------------------------------
-- Set_Document_Locator
-- ------------------------------
overriding
procedure Set_Document_Locator (Handler : in out Xhtml_Reader;
Loc : in out Sax.Locators.Locator) is
begin
Handler.Handler.Locator := Loc;
end Set_Document_Locator;
-- ------------------------------
-- Start_Document
-- ------------------------------
overriding
procedure Start_Document (Handler : in out Xhtml_Reader) is
begin
null;
end Start_Document;
-- ------------------------------
-- End_Document
-- ------------------------------
overriding
procedure End_Document (Handler : in out Xhtml_Reader) is
begin
null;
end End_Document;
-- ------------------------------
-- Start_Prefix_Mapping
-- ------------------------------
overriding
procedure Start_Prefix_Mapping (Handler : in out Xhtml_Reader;
Prefix : in Unicode.CES.Byte_Sequence;
URI : in Unicode.CES.Byte_Sequence) is
begin
null;
end Start_Prefix_Mapping;
-- ------------------------------
-- End_Prefix_Mapping
-- ------------------------------
overriding
procedure End_Prefix_Mapping (Handler : in out Xhtml_Reader;
Prefix : in Unicode.CES.Byte_Sequence) is
begin
null;
end End_Prefix_Mapping;
-- ------------------------------
-- Start_Element
-- ------------------------------
overriding
procedure Start_Element (Handler : in out Xhtml_Reader;
Namespace_URI : in Unicode.CES.Byte_Sequence := "";
Local_Name : in Unicode.CES.Byte_Sequence := "";
Qname : in Unicode.CES.Byte_Sequence := "";
Atts : in Sax.Attributes.Attributes'Class) is
pragma Unreferenced (Namespace_URI, Qname);
Attr_Count : Natural;
begin
Log.Debug ("Start object {0}", Local_Name);
Handler.Sink.Start_Object (Local_Name, Handler.Handler.all);
Attr_Count := Get_Length (Atts);
for I in 0 .. Attr_Count - 1 loop
declare
Name : constant String := Get_Qname (Atts, I);
Value : constant String := Get_Value (Atts, I);
begin
Handler.Sink.Set_Member (Name => Name,
Value => Util.Beans.Objects.To_Object (Value),
Logger => Handler.Handler.all,
Attribute => True);
end;
end loop;
end Start_Element;
-- ------------------------------
-- End_Element
-- ------------------------------
overriding
procedure End_Element (Handler : in out Xhtml_Reader;
Namespace_URI : in Unicode.CES.Byte_Sequence := "";
Local_Name : in Unicode.CES.Byte_Sequence := "";
Qname : in Unicode.CES.Byte_Sequence := "") is
pragma Unreferenced (Namespace_URI, Qname);
Len : constant Natural := Length (Handler.Text);
begin
Handler.Sink.Finish_Object (Local_Name, Handler.Handler.all);
if Len > 0 then
-- Add debug message only when it is active (saves the To_String conversion).
if Log.Get_Level >= Util.Log.DEBUG_LEVEL then
Log.Debug ("Close object {0} -> {1}", Local_Name, To_String (Handler.Text));
end if;
Handler.Sink.Set_Member (Local_Name, Util.Beans.Objects.To_Object (Handler.Text),
Handler.Handler.all);
-- Clear the string using Delete so that the buffer is kept.
Ada.Strings.Unbounded.Delete (Source => Handler.Text, From => 1, Through => Len);
else
Log.Debug ("Close object {0}", Local_Name);
Handler.Sink.Set_Member (Local_Name, Util.Beans.Objects.To_Object (Handler.Text),
Handler.Handler.all);
end if;
end End_Element;
procedure Collect_Text (Handler : in out Xhtml_Reader;
Content : Unicode.CES.Byte_Sequence) is
begin
Append (Handler.Text, Content);
end Collect_Text;
-- ------------------------------
-- Characters
-- ------------------------------
overriding
procedure Characters (Handler : in out Xhtml_Reader;
Ch : in Unicode.CES.Byte_Sequence) is
begin
Collect_Text (Handler, Ch);
end Characters;
-- ------------------------------
-- Ignorable_Whitespace
-- ------------------------------
overriding
procedure Ignorable_Whitespace (Handler : in out Xhtml_Reader;
Ch : in Unicode.CES.Byte_Sequence) is
begin
if not Handler.Ignore_White_Spaces then
Collect_Text (Handler, Ch);
end if;
end Ignorable_Whitespace;
-- ------------------------------
-- Processing_Instruction
-- ------------------------------
overriding
procedure Processing_Instruction (Handler : in out Xhtml_Reader;
Target : in Unicode.CES.Byte_Sequence;
Data : in Unicode.CES.Byte_Sequence) is
pragma Unreferenced (Handler);
begin
Log.Error ("Processing instruction: {0}: {1}", Target, Data);
end Processing_Instruction;
-- ------------------------------
-- Skipped_Entity
-- ------------------------------
overriding
procedure Skipped_Entity (Handler : in out Xhtml_Reader;
Name : in Unicode.CES.Byte_Sequence) is
pragma Unmodified (Handler);
begin
null;
end Skipped_Entity;
-- ------------------------------
-- Start_Cdata
-- ------------------------------
overriding
procedure Start_Cdata (Handler : in out Xhtml_Reader) is
pragma Unmodified (Handler);
pragma Unreferenced (Handler);
begin
Log.Info ("Start CDATA");
end Start_Cdata;
-- ------------------------------
-- End_Cdata
-- ------------------------------
overriding
procedure End_Cdata (Handler : in out Xhtml_Reader) is
pragma Unmodified (Handler);
pragma Unreferenced (Handler);
begin
Log.Info ("End CDATA");
end End_Cdata;
-- ------------------------------
-- Resolve_Entity
-- ------------------------------
overriding
function Resolve_Entity (Handler : Xhtml_Reader;
Public_Id : Unicode.CES.Byte_Sequence;
System_Id : Unicode.CES.Byte_Sequence)
return Input_Sources.Input_Source_Access is
pragma Unreferenced (Handler);
begin
Log.Error ("Cannot resolve entity {0} - {1}", Public_Id, System_Id);
return null;
end Resolve_Entity;
overriding
procedure Start_DTD (Handler : in out Xhtml_Reader;
Name : Unicode.CES.Byte_Sequence;
Public_Id : Unicode.CES.Byte_Sequence := "";
System_Id : Unicode.CES.Byte_Sequence := "") is
begin
null;
end Start_DTD;
-- ------------------------------
-- Set the XHTML reader to ignore or not the white spaces.
-- When set to True, the ignorable white spaces will not be kept.
-- ------------------------------
procedure Set_Ignore_White_Spaces (Reader : in out Parser;
Value : in Boolean) is
begin
Reader.Ignore_White_Spaces := Value;
end Set_Ignore_White_Spaces;
-- ------------------------------
-- Set the XHTML reader to ignore empty lines.
-- ------------------------------
procedure Set_Ignore_Empty_Lines (Reader : in out Parser;
Value : in Boolean) is
begin
Reader.Ignore_Empty_Lines := Value;
end Set_Ignore_Empty_Lines;
-- ------------------------------
-- Get the current location (file and line) to report an error message.
-- ------------------------------
function Get_Location (Handler : in Parser) return String is
File : constant String := Util.Serialize.IO.Parser (Handler).Get_Location;
begin
if Handler.Locator = Sax.Locators.No_Locator then
return File;
else
return File & Sax.Locators.To_String (Handler.Locator);
end if;
end Get_Location;
-- ------------------------------
-- Parse an XML stream, and calls the appropriate SAX callbacks for each
-- event.
-- This is not re-entrant: you can not call Parse with the same Parser
-- argument in one of the SAX callbacks. This has undefined behavior.
-- ------------------------------
-- Parse the stream using the JSON parser.
procedure Parse (Handler : in out Parser;
Stream : in out Util.Streams.Buffered.Input_Buffer_Stream'Class;
Sink : in out Reader'Class) is
Buffer_Size : constant Positive := 256;
type String_Access is access all String (1 .. Buffer_Size);
type Stream_Input is new Input_Sources.Input_Source with record
Index : Natural;
Last : Natural;
Encoding : Unicode.CES.Encoding_Scheme;
Buffer : String_Access;
end record;
-- Return the next character in the string.
procedure Next_Char (From : in out Stream_Input;
C : out Unicode.Unicode_Char);
-- True if From is past the last character in the string.
function Eof (From : in Stream_Input) return Boolean;
procedure Fill (From : in out Stream_Input'Class);
procedure Fill (From : in out Stream_Input'Class) is
Last : Natural := From.Last;
begin
-- Move to the buffer start
if Last > From.Index and From.Index > From.Buffer'First then
From.Buffer (From.Buffer'First .. Last - 1 - From.Index + From.Buffer'First) :=
From.Buffer (From.Index .. Last - 1);
Last := Last - From.Index + From.Buffer'First;
From.Index := From.Buffer'First;
end if;
if From.Index > From.Last then
From.Index := From.Buffer'First;
end if;
begin
while not Stream.Is_Eof loop
Stream.Read (From.Buffer (Last));
Last := Last + 1;
exit when Last > From.Buffer'Last;
end loop;
exception
when others =>
null;
end;
From.Last := Last;
end Fill;
-- Return the next character in the string.
procedure Next_Char (From : in out Stream_Input;
C : out Unicode.Unicode_Char) is
begin
if From.Index + 6 >= From.Last then
Fill (From);
end if;
From.Encoding.Read (From.Buffer.all, From.Index, C);
end Next_Char;
-- True if From is past the last character in the string.
function Eof (From : in Stream_Input) return Boolean is
begin
if From.Index < From.Last then
return False;
end if;
return Stream.Is_Eof;
end Eof;
Input : Stream_Input;
Xml_Parser : Xhtml_Reader;
Buf : aliased String (1 .. Buffer_Size);
begin
Input.Buffer := Buf'Access;
Input.Index := Buf'First + 1;
Input.Last := Buf'First;
Input.Set_Encoding (Unicode.CES.Utf8.Utf8_Encoding);
Input.Encoding := Unicode.CES.Utf8.Utf8_Encoding;
Xml_Parser.Handler := Handler'Unchecked_Access;
Xml_Parser.Ignore_White_Spaces := Handler.Ignore_White_Spaces;
Xml_Parser.Ignore_Empty_Lines := Handler.Ignore_Empty_Lines;
Xml_Parser.Sink := Sink'Unchecked_Access;
Sax.Readers.Reader (Xml_Parser).Parse (Input);
Handler.Locator := Sax.Locators.No_Locator;
-- Ignore the Program_Error exception that SAX could raise if we know that the
-- error was reported.
exception
when Program_Error =>
Handler.Locator := Sax.Locators.No_Locator;
if not Handler.Has_Error then
raise;
end if;
when others =>
Handler.Locator := Sax.Locators.No_Locator;
raise;
end Parse;
-- Close the current XML entity if an entity was started
procedure Close_Current (Stream : in out Output_Stream'Class;
Indent : in Boolean);
-- ------------------------------
-- Close the current XML entity if an entity was started
-- ------------------------------
procedure Close_Current (Stream : in out Output_Stream'Class;
Indent : in Boolean) is
begin
if Stream.Close_Start then
Stream.Write ('>');
Stream.Close_Start := False;
end if;
if Indent then
if Stream.Indent /= 0 then
Stream.Write (ASCII.LF);
end if;
for I in 1 .. Stream.Level loop
Stream.Write (' ');
end loop;
end if;
end Close_Current;
-- -----------------------
-- Set the target output stream.
-- -----------------------
procedure Initialize (Stream : in out Output_Stream;
Output : in Util.Streams.Texts.Print_Stream_Access) is
begin
Stream.Stream := Output;
end Initialize;
-- -----------------------
-- Flush the buffer (if any) to the sink.
-- -----------------------
overriding
procedure Flush (Stream : in out Output_Stream) is
begin
Stream.Stream.Flush;
end Flush;
-- -----------------------
-- Close the sink.
-- -----------------------
overriding
procedure Close (Stream : in out Output_Stream) is
begin
Stream.Stream.Close;
end Close;
-- -----------------------
-- Write the buffer array to the output stream.
-- -----------------------
overriding
procedure Write (Stream : in out Output_Stream;
Buffer : in Ada.Streams.Stream_Element_Array) is
begin
Stream.Stream.Write (Buffer);
end Write;
-- ------------------------------
-- Write a character on the response stream and escape that character as necessary.
-- ------------------------------
procedure Write_Escape (Stream : in out Output_Stream'Class;
Char : in Wide_Wide_Character) is
type Unicode_Char is mod 2**32;
Code : constant Unicode_Char := Wide_Wide_Character'Pos (Char);
begin
-- If "?" or over, no escaping is needed (this covers
-- most of the Latin alphabet)
if Code >= 16#80# then
Stream.Write_Wide (Char);
elsif Code > 16#3F# or Code <= 16#20# then
Stream.Write (Character'Val (Code));
elsif Char = '<' then
Stream.Write ("<");
elsif Char = '>' then
Stream.Write (">");
elsif Char = '&' then
Stream.Write ("&");
else
Stream.Write (Character'Val (Code));
end if;
end Write_Escape;
-- ------------------------------
-- Write the value as a XML string. Special characters are escaped using the XML
-- escape rules.
-- ------------------------------
procedure Write_String (Stream : in out Output_Stream;
Value : in String) is
begin
Close_Current (Stream, False);
for I in Value'Range loop
Stream.Write_Escape (Ada.Characters.Conversions.To_Wide_Wide_Character (Value (I)));
end loop;
end Write_String;
-- ------------------------------
-- Write the value as a XML string. Special characters are escaped using the XML
-- escape rules.
-- ------------------------------
procedure Write_Wide_String (Stream : in out Output_Stream;
Value : in Wide_Wide_String) is
begin
Close_Current (Stream, False);
for I in Value'Range loop
Stream.Write_Escape (Value (I));
end loop;
end Write_Wide_String;
-- ------------------------------
-- Write the value as a XML string. Special characters are escaped using the XML
-- escape rules.
-- ------------------------------
procedure Write_String (Stream : in out Output_Stream;
Value : in Util.Beans.Objects.Object) is
use Util.Beans.Objects;
begin
Close_Current (Stream, False);
case Util.Beans.Objects.Get_Type (Value) is
when TYPE_NULL =>
null;
when TYPE_BOOLEAN =>
if Util.Beans.Objects.To_Boolean (Value) then
Stream.Write ("true");
else
Stream.Write ("false");
end if;
when TYPE_INTEGER =>
Stream.Stream.Write (Util.Beans.Objects.To_Long_Long_Integer (Value));
when others =>
Stream.Write_String (Util.Beans.Objects.To_String (Value));
end case;
end Write_String;
-- ------------------------------
-- Start a new XML object.
-- ------------------------------
procedure Start_Entity (Stream : in out Output_Stream;
Name : in String) is
begin
Close_Current (Stream, True);
Stream.Close_Start := True;
Stream.Is_Closed := False;
Stream.Write ('<');
Stream.Write (Name);
Stream.Level := Stream.Level + 1;
end Start_Entity;
-- ------------------------------
-- Terminates the current XML object.
-- ------------------------------
procedure End_Entity (Stream : in out Output_Stream;
Name : in String) is
begin
Stream.Level := Stream.Level - 1;
Close_Current (Stream, Stream.Is_Closed);
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
Stream.Is_Closed := True;
end End_Entity;
-- ------------------------------
-- Write the attribute name/value pair.
-- ------------------------------
overriding
procedure Write_Attribute (Stream : in out Output_Stream;
Name : in String;
Value : in String) is
begin
Stream.Write (' ');
Stream.Write (Name);
Stream.Write ("=""");
Util.Streams.Texts.TR.Escape_Xml (Content => Value, Into => Stream.Stream.all);
Stream.Write ('"');
end Write_Attribute;
overriding
procedure Write_Wide_Attribute (Stream : in out Output_Stream;
Name : in String;
Value : in Wide_Wide_String) is
begin
Stream.Write (' ');
Stream.Write (Name);
Stream.Write ("=""");
Util.Streams.Texts.WTR.Escape_Xml (Content => Value, Into => Stream.Stream.all);
Stream.Write ('"');
end Write_Wide_Attribute;
overriding
procedure Write_Attribute (Stream : in out Output_Stream;
Name : in String;
Value : in Integer) is
begin
Stream.Write (' ');
Stream.Write (Name);
Stream.Write ("=""");
Stream.Stream.Write (Value);
Stream.Write ('"');
end Write_Attribute;
overriding
procedure Write_Attribute (Stream : in out Output_Stream;
Name : in String;
Value : in Boolean) is
begin
Stream.Write (' ');
Stream.Write (Name);
if Value then
Stream.Write ("=""true""");
else
Stream.Write ("=""false""");
end if;
end Write_Attribute;
-- ------------------------------
-- Write a XML name/value attribute.
-- ------------------------------
procedure Write_Attribute (Stream : in out Output_Stream;
Name : in String;
Value : in Util.Beans.Objects.Object) is
use Util.Beans.Objects;
begin
Stream.Write (' ');
Stream.Write (Name);
Stream.Write ("=""");
case Util.Beans.Objects.Get_Type (Value) is
when TYPE_NULL =>
null;
when TYPE_BOOLEAN =>
if Util.Beans.Objects.To_Boolean (Value) then
Stream.Write ("true");
else
Stream.Write ("false");
end if;
when TYPE_INTEGER =>
Stream.Stream.Write (Util.Beans.Objects.To_Long_Long_Integer (Value));
when others =>
Stream.Write (Util.Beans.Objects.To_String (Value));
end case;
Stream.Write ('"');
end Write_Attribute;
-- ------------------------------
-- Write the attribute with a null value.
-- ------------------------------
overriding
procedure Write_Null_Attribute (Stream : in out Output_Stream;
Name : in String) is
begin
null;
end Write_Null_Attribute;
-- ------------------------------
-- Write the entity value.
-- ------------------------------
overriding
procedure Write_Entity (Stream : in out Output_Stream;
Name : in String;
Value : in String) is
begin
Close_Current (Stream, True);
Stream.Write ('<');
Stream.Write (Name);
Stream.Close_Start := True;
Stream.Write_String (Value);
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
Stream.Is_Closed := True;
end Write_Entity;
overriding
procedure Write_Wide_Entity (Stream : in out Output_Stream;
Name : in String;
Value : in Wide_Wide_String) is
begin
Close_Current (Stream, True);
Stream.Write ('<');
Stream.Write (Name);
Stream.Close_Start := True;
Stream.Write_Wide_String (Value);
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
Stream.Is_Closed := True;
end Write_Wide_Entity;
overriding
procedure Write_Entity (Stream : in out Output_Stream;
Name : in String;
Value : in Boolean) is
begin
Close_Current (Stream, True);
Stream.Write ('<');
Stream.Write (Name);
if Value then
Stream.Write (">true</");
else
Stream.Write (">false</");
end if;
Stream.Write (Name);
Stream.Write ('>');
Stream.Is_Closed := True;
end Write_Entity;
overriding
procedure Write_Entity (Stream : in out Output_Stream;
Name : in String;
Value : in Integer) is
begin
Close_Current (Stream, True);
Stream.Write ('<');
Stream.Write (Name);
Stream.Write ('>');
Stream.Stream.Write (Value);
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
Stream.Is_Closed := True;
end Write_Entity;
overriding
procedure Write_Entity (Stream : in out Output_Stream;
Name : in String;
Value : in Ada.Calendar.Time) is
begin
Stream.Write_Entity (Name, Util.Dates.ISO8601.Image (Value, Util.Dates.ISO8601.SUBSECOND));
end Write_Entity;
overriding
procedure Write_Long_Entity (Stream : in out Output_Stream;
Name : in String;
Value : in Long_Long_Integer) is
begin
Close_Current (Stream, True);
Stream.Write ('<');
Stream.Write (Name);
Stream.Write ('>');
Stream.Stream.Write (Value);
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
Stream.Is_Closed := True;
end Write_Long_Entity;
overriding
procedure Write_Enum_Entity (Stream : in out Output_Stream;
Name : in String;
Value : in String) is
begin
Stream.Write_Entity (Name, Value);
end Write_Enum_Entity;
-- ------------------------------
-- Write a XML name/value entity (see Write_Attribute).
-- ------------------------------
procedure Write_Entity (Stream : in out Output_Stream;
Name : in String;
Value : in Util.Beans.Objects.Object) is
use Util.Beans.Objects;
begin
case Util.Beans.Objects.Get_Type (Value) is
when TYPE_NULL =>
Close_Current (Stream, True);
Stream.Write ('<');
Stream.Write (Name);
Stream.Close_Start := True;
Stream.Write ("null");
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
Stream.Is_Closed := True;
when TYPE_BOOLEAN =>
Close_Current (Stream, True);
Stream.Write ('<');
Stream.Write (Name);
Stream.Close_Start := True;
if Util.Beans.Objects.To_Boolean (Value) then
Stream.Write ("true");
else
Stream.Write ("false");
end if;
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
Stream.Is_Closed := True;
when TYPE_INTEGER =>
Close_Current (Stream, True);
Stream.Write ('<');
Stream.Write (Name);
Stream.Close_Start := True;
Stream.Stream.Write (Util.Beans.Objects.To_Long_Long_Integer (Value));
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
Stream.Is_Closed := True;
when TYPE_BEAN | TYPE_ARRAY =>
if Is_Array (Value) then
declare
Count : constant Natural := Util.Beans.Objects.Get_Count (Value);
begin
Close_Current (Stream, False);
for I in 1 .. Count loop
Stream.Write_Entity (Name, Util.Beans.Objects.Get_Value (Value, I));
end loop;
end;
else
declare
procedure Process (Name : in String; Item : in Object);
procedure Process (Name : in String; Item : in Object) is
begin
Stream.Write_Entity (Name, Item);
end Process;
begin
Close_Current (Stream, True);
Stream.Write ('<');
Stream.Write (Name);
Stream.Close_Start := True;
Util.Beans.Objects.Maps.Iterate (Value, Process'Access);
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
Stream.Is_Closed := True;
end;
end if;
when others =>
Close_Current (Stream, True);
Stream.Write ('<');
Stream.Write (Name);
Stream.Close_Start := True;
Stream.Write_String (Util.Beans.Objects.To_String (Value));
Stream.Write ("</");
Stream.Write (Name);
Stream.Write ('>');
Stream.Is_Closed := True;
end case;
end Write_Entity;
-- ------------------------------
-- Write an entity with a null value.
-- ------------------------------
overriding
procedure Write_Null_Entity (Stream : in out Output_Stream;
Name : in String) is
begin
null;
end Write_Null_Entity;
-- ------------------------------
-- Starts a XML array.
-- ------------------------------
overriding
procedure Start_Array (Stream : in out Output_Stream;
Name : in String) is
pragma Unreferenced (Stream, Name);
begin
null;
end Start_Array;
-- ------------------------------
-- Terminates a XML array.
-- ------------------------------
overriding
procedure End_Array (Stream : in out Output_Stream;
Name : in String) is
begin
null;
end End_Array;
-- ------------------------------
-- Set the indentation level when writing XML entities.
-- ------------------------------
procedure Set_Indentation (Stream : in out Output_Stream;
Count : in Natural) is
begin
Stream.Indent := Count;
end Set_Indentation;
end Util.Serialize.IO.XML;
|
-- This package has been generated automatically by GNATtest.
-- Do not edit any part of it, see GNATtest documentation for more details.
-- begin read only
with Gnattest_Generated;
package Ships.Cargo.Test_Data.Tests is
type Test is new GNATtest_Generated.GNATtest_Standard.Ships.Cargo.Test_Data
.Test with
null record;
procedure Test_UpdateCargo_590faf_53988c(Gnattest_T: in out Test);
-- ships-cargo.ads:40:4:UpdateCargo:Test_UpdateCargo
procedure Test_FreeCargo_f63648_4f2f60(Gnattest_T: in out Test);
-- ships-cargo.ads:61:4:FreeCargo:Test_FreeCargo
procedure Test_GetItemAmount_57499f_15cacd(Gnattest_T: in out Test);
-- ships-cargo.ads:74:4:GetItemAmount:Test_GetItemAmount
procedure Test_GetItemsAmount_df8553_e4797c(Gnattest_T: in out Test);
-- ships-cargo.ads:87:4:GetItemsAmount:Test_GetItemsAmount
end Ships.Cargo.Test_Data.Tests;
-- end read only
|
with Ada.Text_IO; use Ada.Text_IO;
with Sf.Window.Window; use Sf, Sf.Window, Sf.Window.Window;
with Sf.Window.VideoMode; use Sf.Window.VideoMode;
with Sf.Window.Event; use Sf.Window.Event;
with Sf.Window.Keyboard; use Sf.Window.Keyboard;
with Sf.Window.Clipboard;
with Sf.Window.Cursor;
with Sf.System.Time; use Sf.System.Time;
with Sf.System.Sleep; use Sf.System.Sleep;
procedure Main is
Window : sfWindow_Ptr;
Mode : sfVideoMode := (640, 480, 32);
Event : aliased sfEvent;
CursorHand : sfCursor_Ptr := Cursor.createFromSystem(Cursor.sfCursorHand);
begin
Window := Create (Mode, "Window");
if Window = null then
Put_Line ("Failed to create window");
return;
end if;
setMouseCursor (Window, CursorHand);
SetFramerateLimit (Window, 32);
SetVerticalSyncEnabled (Window, sfTrue);
while IsOpen (Window) = sfTrue loop
while PollEvent (Window, Event'Access) = sfTrue loop
if Event.eventType = sfEvtClosed then
Close (Window);
Put_Line ("Attempting to close");
end if;
if Event.eventType = sfEvtKeyPressed then
if Event.key.code = sfKeyEscape then
Close (Window);
Put_Line ("Attempting to close");
elsif
Event.key.code = sfKeyC and
Event.key.control = sfTrue then
sf.Window.Clipboard.setString ("ASFML has copied to Clipboard");
setTitle (Window, "ASFML has copied to Clipboard");
elsif Event.key.code = sfKeyV and
Event.key.control = sfTrue then
Put_Line (sf.Window.Clipboard.getString);
setTitle (Window, "ASFML has pasted to standard output");
end if;
end if;
end loop;
Display (Window);
sfSleep (sfSeconds (0.001));
end loop;
Destroy (Window);
end Main;
|
-- ----------------------------------------------------------------- --
-- --
-- This 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 software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public --
-- License along with this library; if not, write to the --
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330, --
-- Boston, MA 02111-1307, USA. --
-- --
-- ----------------------------------------------------------------- --
-- ----------------------------------------------------------------- --
-- This is a translation, to the Ada programming language, of the --
-- original C test files written by Sam Lantinga - www.libsdl.org --
-- translation made by Antonio F. Vargas - www.adapower.net/~avargas --
-- ----------------------------------------------------------------- --
with Interfaces.C.Strings;
with Ada.Unchecked_Conversion;
with SDL.Timer;
with SDL.Types; use SDL.Types;
with Ada.Text_IO; use Ada.Text_IO;
package body TestSem_Sprogs is
package T renames SDL.Timer;
function To_int is
new Ada.Unchecked_Conversion (System.Address, C.int);
-- ======================================
function ThreadFunc (data : System.Address) return C.int
is
begin
while alive loop
M.SemWait (sem);
Put_Line ("Thread number " & C.int'Image (To_int (data)) &
" has got the semaphore (value = " &
Uint32'Image (M.SemValue (sem)) & ")!");
T.SDL_Delay (200);
M.SemPost (sem);
Put_Line ("Thread number " & C.int'Image (To_int (data)) &
" has released the semaphore (value = " &
Uint32'Image (M.SemValue (sem)) & ")!");
T.SDL_Delay (1); -- For the scheduler
end loop;
Put_Line ("Thread number " & C.int'Image (To_int (data)) & " exiting");
return 0;
end ThreadFunc;
-- ======================================
procedure killed (sig : C.int) is
begin
alive := False;
end killed;
-- ======================================
end TestSem_Sprogs;
|
-- AOC 2020, Day 7
package Day is
function valid_bag_colors return Natural;
function valid_test_bag_colors return Natural;
function nested_bags return Natural;
function nested_test_bags return Natural;
end Day;
|
with Ada.Text_IO;
with Ada.Integer_Text_IO;
package body Problem_38 is
package IO renames Ada.Text_IO;
package I_IO renames Ada.Integer_Text_IO;
procedure Solve is
subtype Digit is Integer range 1 .. 9;
type Seen_Array is Array(Digit) of Boolean;
seen : Seen_Array;
current_number : Integer;
function Check_2(num : Integer) return Boolean is
seen2 : Seen_Array := seen;
num_times_two : Integer := num*2;
good : Boolean := True;
begin
while num_times_two > 0 loop
declare
d : constant Integer := num_times_two mod 10;
begin
num_times_two := num_times_two / 10;
if d = 0 or else seen2(d) then
good := False;
exit;
end if;
seen2(d) := True;
end;
end loop;
return good;
end Check_2;
begin
for index in seen'Range loop
seen(index) := False;
end loop;
seen(9) := True;
-- If we do better than their sample, it has to come from a 4 digit
-- number. It has to start with a 9 and the most that the second digit can
-- be is a 4 because otherwise it would make the 18 that *2 makes into a
-- 19 which isn't kosher. We know that the first number we get to is the
-- best because the first thing we hit is the *1 which is just a copy of
-- our number.
for hundreds in reverse 2 .. 4 loop
seen(hundreds) := True;
current_number := 9000 + hundreds*100;
for tens in reverse 2 .. 7 loop
if not seen(tens) then
seen(tens) := True;
current_number := current_number + tens*10;
for ones in reverse 2 .. 7 loop
if not seen(ones) then
seen(ones) := True;
current_number := current_number + ones;
if Check_2(current_number) then
goto Have_Solution;
end if;
current_number := current_number - ones;
seen(ones) := False;
end if;
end loop;
current_number := current_number - tens*10;
seen(tens) := False;
end if;
end loop;
seen(hundreds) := False;
end loop;
<<Have_Solution>>
I_IO.Put(current_number);
IO.New_Line;
end Solve;
end Problem_38;
|
package Giza.Bitmap_Fonts.FreeMonoBoldOblique8pt7b is
Font : constant Giza.Font.Ref_Const;
private
FreeMonoBoldOblique8pt7bBitmaps : aliased constant Font_Bitmap := (
16#6D#, 16#BD#, 16#B0#, 16#D8#, 16#DE#, 16#E7#, 16#29#, 16#00#, 16#1A#,
16#16#, 16#36#, 16#7F#, 16#7F#, 16#2C#, 16#FE#, 16#FE#, 16#58#, 16#D8#,
16#D8#, 16#06#, 16#03#, 16#07#, 16#E6#, 16#23#, 16#01#, 16#F0#, 16#3C#,
16#86#, 16#63#, 16#3F#, 16#06#, 16#03#, 16#01#, 16#00#, 16#38#, 16#64#,
16#44#, 16#48#, 16#3E#, 16#70#, 16#9E#, 16#22#, 16#22#, 16#1C#, 16#0E#,
16#1E#, 16#30#, 16#30#, 16#78#, 16#FF#, 16#CE#, 16#FE#, 16#7E#, 16#FA#,
16#80#, 16#13#, 16#66#, 16#4C#, 16#CC#, 16#CC#, 16#E6#, 16#67#, 16#33#,
16#33#, 16#33#, 16#66#, 16#4C#, 16#18#, 16#23#, 16#7F#, 16#E7#, 16#9B#,
16#22#, 16#00#, 16#08#, 16#08#, 16#18#, 16#FF#, 16#FF#, 16#10#, 16#10#,
16#30#, 16#30#, 16#36#, 16#4C#, 16#80#, 16#FF#, 16#FF#, 16#F0#, 16#00#,
16#C0#, 16#60#, 16#10#, 16#0C#, 16#06#, 16#01#, 16#00#, 16#C0#, 16#60#,
16#30#, 16#0C#, 16#06#, 16#03#, 16#00#, 16#80#, 16#00#, 16#1E#, 16#3F#,
16#23#, 16#63#, 16#43#, 16#C2#, 16#C2#, 16#C6#, 16#C6#, 16#FC#, 16#78#,
16#0E#, 16#78#, 16#90#, 16#60#, 16#C1#, 16#02#, 16#0C#, 16#7E#, 16#FC#,
16#07#, 16#07#, 16#C6#, 16#62#, 16#30#, 16#38#, 16#38#, 16#38#, 16#78#,
16#70#, 16#7F#, 16#BF#, 16#80#, 16#1E#, 16#3F#, 16#03#, 16#03#, 16#1E#,
16#1C#, 16#06#, 16#06#, 16#0E#, 16#FC#, 16#F8#, 16#06#, 16#1C#, 16#59#,
16#24#, 16#5F#, 16#FF#, 16#9E#, 16#3C#, 16#7E#, 16#7E#, 16#60#, 16#7C#,
16#7E#, 16#C6#, 16#06#, 16#0E#, 16#FC#, 16#F8#, 16#07#, 16#8F#, 16#CE#,
16#0E#, 16#07#, 16#E7#, 16#FB#, 16#8D#, 16#86#, 16#C7#, 16#7F#, 16#1F#,
16#00#, 16#FE#, 16#FE#, 16#06#, 16#04#, 16#0C#, 16#08#, 16#18#, 16#30#,
16#30#, 16#60#, 16#1E#, 16#3F#, 16#63#, 16#63#, 16#66#, 16#3C#, 16#7C#,
16#C6#, 16#C6#, 16#FC#, 16#78#, 16#1E#, 16#3F#, 16#73#, 16#63#, 16#67#,
16#7F#, 16#3E#, 16#06#, 16#1C#, 16#F8#, 16#F0#, 16#6C#, 16#01#, 16#B0#,
16#18#, 16#C0#, 16#00#, 16#19#, 16#88#, 16#C4#, 16#00#, 16#03#, 16#0E#,
16#38#, 16#E0#, 16#78#, 16#1C#, 16#06#, 16#7F#, 16#BF#, 16#C0#, 16#1F#,
16#FF#, 16#F0#, 16#20#, 16#1C#, 16#03#, 16#80#, 16#F0#, 16#E3#, 16#C3#,
16#00#, 16#7B#, 16#F8#, 16#C3#, 16#3B#, 16#CC#, 16#00#, 16#C3#, 16#00#,
16#1E#, 16#3F#, 16#33#, 16#63#, 16#4E#, 16#DE#, 16#B6#, 16#B4#, 16#BC#,
16#DE#, 16#C0#, 16#F8#, 16#70#, 16#1F#, 16#07#, 16#C0#, 16#70#, 16#3C#,
16#19#, 16#86#, 16#63#, 16#F8#, 16#FE#, 16#F3#, 16#FC#, 16#F0#, 16#3F#,
16#8F#, 16#F1#, 16#8C#, 16#43#, 16#1F#, 16#8F#, 16#E3#, 16#0C#, 16#C3#,
16#7F#, 16#BF#, 16#C0#, 16#1F#, 16#CF#, 16#F7#, 16#19#, 16#86#, 16#C0#,
16#30#, 16#0C#, 16#03#, 16#8C#, 16#7F#, 16#0F#, 16#00#, 16#3F#, 16#0F#,
16#E1#, 16#1C#, 16#43#, 16#30#, 16#CC#, 16#32#, 16#1C#, 16#86#, 16#7F#,
16#3F#, 16#80#, 16#3F#, 16#CF#, 16#F1#, 16#0C#, 16#58#, 16#3E#, 16#0F#,
16#03#, 16#40#, 16#82#, 16#FF#, 16#BF#, 16#E0#, 16#3F#, 16#CF#, 16#F1#,
16#0C#, 16#48#, 16#3E#, 16#0F#, 16#82#, 16#40#, 16#80#, 16#FC#, 16#3E#,
16#00#, 16#0F#, 16#4F#, 16#F7#, 16#09#, 16#80#, 16#C0#, 16#31#, 16#EC#,
16#FB#, 16#04#, 16#FF#, 16#0F#, 16#80#, 16#3D#, 16#CF#, 16#71#, 16#08#,
16#42#, 16#3F#, 16#8F#, 16#E2#, 16#10#, 16#84#, 16#F7#, 16#BD#, 16#E0#,
16#3F#, 16#9F#, 16#83#, 16#01#, 16#00#, 16#80#, 16#C0#, 16#60#, 16#30#,
16#FE#, 16#7F#, 16#00#, 16#0F#, 16#E1#, 16#F8#, 16#04#, 16#00#, 16#80#,
16#30#, 16#06#, 16#10#, 16#C6#, 16#30#, 16#FE#, 16#0F#, 16#00#, 16#3C#,
16#E7#, 16#BC#, 16#46#, 16#0B#, 16#83#, 16#E0#, 16#7E#, 16#08#, 16#C1#,
16#18#, 16#F9#, 16#DE#, 16#38#, 16#3F#, 16#0F#, 16#80#, 16#80#, 16#60#,
16#18#, 16#06#, 16#01#, 16#0C#, 16#42#, 16#7F#, 16#BF#, 16#E0#, 16#38#,
16#73#, 16#8E#, 16#39#, 16#C3#, 16#9C#, 16#2F#, 16#C2#, 16#EC#, 16#6E#,
16#C6#, 16#08#, 16#F3#, 16#CF#, 16#3C#, 16#39#, 16#E7#, 16#3C#, 16#73#,
16#0E#, 16#63#, 16#EC#, 16#6D#, 16#09#, 16#A1#, 16#1C#, 16#7B#, 16#9E#,
16#30#, 16#1E#, 16#1F#, 16#9C#, 16#EC#, 16#3C#, 16#1E#, 16#0F#, 16#0D#,
16#CE#, 16#7E#, 16#1E#, 16#00#, 16#3F#, 16#8F#, 16#F1#, 16#8C#, 16#43#,
16#11#, 16#CF#, 16#E3#, 16#F0#, 16#C0#, 16#7C#, 16#3F#, 16#00#, 16#1E#,
16#1F#, 16#9C#, 16#EC#, 16#3C#, 16#1E#, 16#0F#, 16#0D#, 16#CE#, 16#7E#,
16#1E#, 16#1F#, 16#9F#, 16#C0#, 16#3F#, 16#87#, 16#F8#, 16#43#, 16#08#,
16#E3#, 16#F8#, 16#7E#, 16#08#, 16#C1#, 16#0C#, 16#F9#, 16#FE#, 16#1C#,
16#1D#, 16#9F#, 16#D8#, 16#CC#, 16#07#, 16#01#, 16#F1#, 16#19#, 16#8C#,
16#FC#, 16#5C#, 16#00#, 16#7F#, 16#BF#, 16#F2#, 16#79#, 16#21#, 16#80#,
16#C0#, 16#60#, 16#20#, 16#7C#, 16#7E#, 16#00#, 16#F3#, 16#FC#, 16#F6#,
16#19#, 16#04#, 16#43#, 16#30#, 16#CC#, 16#33#, 16#98#, 16#FE#, 16#1E#,
16#00#, 16#F3#, 16#FC#, 16#F4#, 16#11#, 16#8C#, 16#66#, 16#19#, 16#82#,
16#C0#, 16#A0#, 16#38#, 16#0C#, 16#00#, 16#F3#, 16#FC#, 16#F4#, 16#1B#,
16#34#, 16#DD#, 16#3F#, 16#CF#, 16#F3#, 16#B8#, 16#CE#, 16#31#, 16#80#,
16#39#, 16#E7#, 16#3C#, 16#66#, 16#07#, 16#80#, 16#E0#, 16#1C#, 16#07#,
16#C1#, 16#98#, 16#F3#, 16#9E#, 16#F0#, 16#73#, 16#F9#, 16#D8#, 16#C6#,
16#C3#, 16#C0#, 16#C0#, 16#40#, 16#20#, 16#FC#, 16#7E#, 16#00#, 16#3F#,
16#9F#, 16#88#, 16#C0#, 16#C0#, 16#C0#, 16#C0#, 16#C0#, 16#C6#, 16#FF#,
16#7F#, 16#00#, 16#3C#, 16#E2#, 16#18#, 16#61#, 16#84#, 16#10#, 16#C3#,
16#0E#, 16#38#, 16#C2#, 16#18#, 16#C6#, 16#10#, 16#C6#, 16#30#, 16#86#,
16#31#, 16#00#, 16#3C#, 16#E0#, 16#86#, 16#18#, 16#41#, 16#0C#, 16#30#,
16#CE#, 16#38#, 16#10#, 16#71#, 16#B6#, 16#68#, 16#40#, 16#7F#, 16#FF#,
16#F0#, 16#B4#, 16#1E#, 16#1F#, 16#8F#, 16#CF#, 16#EC#, 16#27#, 16#FD#,
16#FE#, 16#38#, 16#0E#, 16#01#, 16#00#, 16#5E#, 16#3F#, 16#CC#, 16#32#,
16#0C#, 16#87#, 16#FF#, 16#BF#, 16#C0#, 16#1E#, 16#BF#, 16#D8#, 16#58#,
16#0C#, 16#07#, 16#F1#, 16#F0#, 16#01#, 16#81#, 16#C0#, 16#63#, 16#F7#,
16#F7#, 16#0B#, 16#05#, 16#86#, 16#FF#, 16#BD#, 16#C0#, 16#1E#, 16#7F#,
16#61#, 16#FF#, 16#FF#, 16#FE#, 16#7C#, 16#07#, 16#C3#, 16#F0#, 16#80#,
16#FC#, 16#3F#, 16#06#, 16#01#, 16#00#, 16#40#, 16#7E#, 16#3F#, 16#80#,
16#1D#, 16#DF#, 16#FE#, 16#33#, 16#0C#, 16#C3#, 16#3F#, 16#87#, 16#A0#,
16#18#, 16#7C#, 16#1E#, 16#00#, 16#70#, 16#1C#, 16#03#, 16#00#, 16#BC#,
16#3F#, 16#98#, 16#66#, 16#11#, 16#84#, 16#E3#, 16#F8#, 16#F0#, 16#04#,
16#0C#, 16#00#, 16#3C#, 16#3C#, 16#0C#, 16#08#, 16#18#, 16#FF#, 16#FF#,
16#03#, 16#02#, 16#00#, 16#3F#, 16#3F#, 16#03#, 16#02#, 16#02#, 16#06#,
16#06#, 16#04#, 16#FC#, 16#F8#, 16#30#, 16#38#, 16#0C#, 16#06#, 16#F3#,
16#71#, 16#E0#, 16#E0#, 16#D8#, 16#EF#, 16#67#, 16#80#, 16#1E#, 16#1C#,
16#04#, 16#0C#, 16#0C#, 16#08#, 16#08#, 16#18#, 16#FF#, 16#FF#, 16#7E#,
16#CF#, 16#FC#, 16#99#, 16#B2#, 16#26#, 16#45#, 16#DD#, 16#FB#, 16#B8#,
16#7F#, 16#1F#, 16#E6#, 16#19#, 16#84#, 16#61#, 16#38#, 16#FE#, 16#3C#,
16#1E#, 16#3F#, 16#F8#, 16#78#, 16#3C#, 16#3F#, 16#F8#, 16#F0#, 16#3B#,
16#C7#, 16#FC#, 16#61#, 16#88#, 16#31#, 16#8E#, 16#7F#, 16#8D#, 16#E1#,
16#80#, 16#78#, 16#1F#, 16#00#, 16#3D#, 16#DF#, 16#FE#, 16#13#, 16#04#,
16#C3#, 16#3F#, 16#C7#, 16#A0#, 16#18#, 16#1F#, 16#07#, 16#C0#, 16#7B#,
16#BF#, 16#CE#, 16#06#, 16#03#, 16#07#, 16#F3#, 16#F0#, 16#3E#, 16#FD#,
16#89#, 16#FC#, 16#7F#, 16#FE#, 16#00#, 16#10#, 16#30#, 16#30#, 16#FE#,
16#FE#, 16#20#, 16#60#, 16#60#, 16#7F#, 16#3E#, 16#F7#, 16#FB#, 16#98#,
16#4C#, 16#66#, 16#33#, 16#F8#, 16#EC#, 16#F7#, 16#FD#, 16#E6#, 16#30#,
16#98#, 16#3C#, 16#0E#, 16#03#, 16#80#, 16#F1#, 16#FC#, 16#76#, 16#D9#,
16#F4#, 16#7F#, 16#1D#, 16#86#, 16#60#, 16#3D#, 16#CE#, 16#71#, 16#F0#,
16#38#, 16#1F#, 16#0C#, 16#EF#, 16#78#, 16#39#, 16#CE#, 16#73#, 16#18#,
16#4C#, 16#1E#, 16#07#, 16#01#, 16#80#, 16#60#, 16#F8#, 16#3E#, 16#00#,
16#3F#, 16#9F#, 16#C9#, 16#83#, 16#83#, 16#03#, 16#FB#, 16#FC#, 16#19#,
16#CC#, 16#62#, 16#73#, 16#8C#, 16#63#, 16#18#, 16#C0#, 16#13#, 16#32#,
16#26#, 16#66#, 16#4C#, 16#CC#, 16#18#, 16#61#, 16#86#, 16#18#, 16#71#,
16#C4#, 16#30#, 16#CE#, 16#38#, 16#70#, 16#F8#, 16#1F#, 16#0E#);
FreeMonoBoldOblique8pt7bGlyphs : aliased constant Glyph_Array := (
(0, 0, 0, 10, 0, 1), -- 0x20 ' '
(0, 3, 10, 10, 4, -9), -- 0x21 '!'
(4, 5, 5, 10, 4, -9), -- 0x22 '"'
(8, 8, 11, 10, 2, -9), -- 0x23 '#'
(19, 9, 13, 10, 1, -10), -- 0x24 '$'
(34, 8, 10, 10, 2, -9), -- 0x25 '%'
(44, 8, 9, 10, 2, -8), -- 0x26 '&'
(53, 2, 5, 10, 5, -9), -- 0x27 '''
(55, 4, 12, 10, 5, -9), -- 0x28 '('
(61, 4, 12, 10, 3, -9), -- 0x29 ')'
(67, 7, 7, 10, 3, -9), -- 0x2A '*'
(74, 8, 9, 10, 2, -8), -- 0x2B '+'
(83, 4, 5, 10, 2, -1), -- 0x2C ','
(86, 8, 2, 10, 2, -5), -- 0x2D '-'
(88, 2, 2, 10, 4, -1), -- 0x2E '.'
(89, 10, 13, 10, 1, -10), -- 0x2F '/'
(106, 8, 11, 10, 2, -10), -- 0x30 '0'
(117, 7, 10, 10, 1, -9), -- 0x31 '1'
(126, 9, 11, 10, 1, -10), -- 0x32 '2'
(139, 8, 11, 10, 3, -10), -- 0x33 '3'
(150, 7, 9, 10, 2, -8), -- 0x34 '4'
(158, 8, 10, 10, 3, -9), -- 0x35 '5'
(168, 9, 11, 10, 2, -10), -- 0x36 '6'
(181, 8, 10, 10, 3, -9), -- 0x37 '7'
(191, 8, 11, 10, 2, -10), -- 0x38 '8'
(202, 8, 11, 10, 2, -10), -- 0x39 '9'
(213, 3, 7, 10, 4, -6), -- 0x3A ':'
(216, 5, 10, 10, 1, -6), -- 0x3B ';'
(223, 8, 7, 10, 2, -7), -- 0x3C '<'
(230, 9, 5, 10, 1, -6), -- 0x3D '='
(236, 9, 7, 10, 1, -7), -- 0x3E '>'
(244, 6, 10, 10, 4, -9), -- 0x3F '?'
(252, 8, 13, 10, 2, -10), -- 0x40 '@'
(265, 10, 10, 10, 0, -9), -- 0x41 'A'
(278, 10, 10, 10, 0, -9), -- 0x42 'B'
(291, 10, 10, 10, 1, -9), -- 0x43 'C'
(304, 10, 10, 10, 0, -9), -- 0x44 'D'
(317, 10, 10, 10, 0, -9), -- 0x45 'E'
(330, 10, 10, 10, 0, -9), -- 0x46 'F'
(343, 10, 10, 10, 1, -9), -- 0x47 'G'
(356, 10, 10, 10, 0, -9), -- 0x48 'H'
(369, 9, 10, 10, 1, -9), -- 0x49 'I'
(381, 11, 10, 10, 0, -9), -- 0x4A 'J'
(395, 11, 10, 10, 0, -9), -- 0x4B 'K'
(409, 10, 10, 10, 0, -9), -- 0x4C 'L'
(422, 12, 10, 10, 0, -9), -- 0x4D 'M'
(437, 11, 10, 10, 0, -9), -- 0x4E 'N'
(451, 9, 10, 10, 1, -9), -- 0x4F 'O'
(463, 10, 10, 10, 0, -9), -- 0x50 'P'
(476, 9, 12, 10, 1, -9), -- 0x51 'Q'
(490, 11, 10, 10, 0, -9), -- 0x52 'R'
(504, 9, 10, 10, 2, -9), -- 0x53 'S'
(516, 9, 10, 10, 1, -9), -- 0x54 'T'
(528, 10, 10, 10, 1, -9), -- 0x55 'U'
(541, 10, 10, 10, 1, -9), -- 0x56 'V'
(554, 10, 10, 10, 1, -9), -- 0x57 'W'
(567, 11, 10, 10, 0, -9), -- 0x58 'X'
(581, 9, 10, 10, 1, -9), -- 0x59 'Y'
(593, 9, 10, 10, 1, -9), -- 0x5A 'Z'
(605, 6, 12, 10, 4, -9), -- 0x5B '['
(614, 5, 13, 10, 3, -10), -- 0x5C '\'
(623, 6, 12, 10, 2, -9), -- 0x5D ']'
(632, 7, 5, 10, 3, -9), -- 0x5E '^'
(637, 10, 2, 10, -1, 2), -- 0x5F '_'
(640, 2, 3, 10, 4, -10), -- 0x60 '`'
(641, 9, 7, 10, 1, -6), -- 0x61 'a'
(649, 10, 10, 10, 0, -9), -- 0x62 'b'
(662, 9, 7, 10, 1, -6), -- 0x63 'c'
(670, 9, 10, 10, 1, -9), -- 0x64 'd'
(682, 8, 7, 10, 1, -6), -- 0x65 'e'
(689, 10, 10, 10, 1, -9), -- 0x66 'f'
(702, 10, 10, 10, 1, -6), -- 0x67 'g'
(715, 10, 10, 10, 1, -9), -- 0x68 'h'
(728, 8, 10, 10, 1, -9), -- 0x69 'i'
(738, 8, 13, 10, 1, -9), -- 0x6A 'j'
(751, 9, 10, 10, 1, -9), -- 0x6B 'k'
(763, 8, 10, 10, 1, -9), -- 0x6C 'l'
(773, 11, 7, 10, 0, -6), -- 0x6D 'm'
(783, 10, 7, 10, 1, -6), -- 0x6E 'n'
(792, 9, 7, 10, 1, -6), -- 0x6F 'o'
(800, 11, 10, 10, -1, -6), -- 0x70 'p'
(814, 10, 10, 10, 1, -6), -- 0x71 'q'
(827, 9, 7, 10, 1, -6), -- 0x72 'r'
(835, 7, 7, 10, 2, -6), -- 0x73 's'
(842, 8, 10, 10, 1, -9), -- 0x74 't'
(852, 9, 7, 10, 1, -6), -- 0x75 'u'
(860, 10, 7, 10, 1, -6), -- 0x76 'v'
(869, 10, 7, 10, 1, -6), -- 0x77 'w'
(878, 10, 7, 10, 0, -6), -- 0x78 'x'
(887, 10, 10, 10, 0, -6), -- 0x79 'y'
(900, 9, 7, 10, 1, -6), -- 0x7A 'z'
(908, 5, 12, 10, 3, -9), -- 0x7B '{'
(916, 4, 12, 10, 4, -9), -- 0x7C '|'
(922, 6, 12, 10, 2, -9), -- 0x7D '}'
(931, 8, 4, 10, 2, -6)); -- 0x7E '~'
Font_D : aliased constant Bitmap_Font :=
(FreeMonoBoldOblique8pt7bBitmaps'Access,
FreeMonoBoldOblique8pt7bGlyphs'Access,
16);
Font : constant Giza.Font.Ref_Const := Font_D'Access;
end Giza.Bitmap_Fonts.FreeMonoBoldOblique8pt7b;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E L I S T S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package provides facilities for manipulating lists of nodes (see
-- package Atree for format and implementation of tree nodes). Separate list
-- elements are allocated to represent elements of these lists, so it is
-- possible for a given node to be on more than one element list at a time.
-- See also package Nlists, which provides another form that is threaded
-- through the nodes themselves (using the Link field), which is more time
-- and space efficient, but a node can be only one such list.
with Types; use Types;
with System;
package Elists is
-- An element list is represented by a header that is allocated in the
-- Elist header table. This header contains pointers to the first and
-- last elements in the list, or to No_Elmt if the list is empty.
-- The elements in the list each contain a pointer to the next element
-- and a pointer to the referenced node. Putting a node into an element
-- list causes no change at all to the node itself, so a node may be
-- included in multiple element lists, and the nodes thus included may
-- or may not be elements of node lists (see package Nlists).
procedure Initialize;
-- Initialize allocation of element list tables. Called at the start of
-- compiling each new main source file. Note that Initialize must not be
-- called if Tree_Read is used.
procedure Lock;
-- Lock tables used for element lists before calling backend
procedure Tree_Read;
-- Initializes internal tables from current tree file using the relevant
-- Table.Tree_Read routines. Note that Initialize should not be called if
-- Tree_Read is used. Tree_Read includes all necessary initialization.
procedure Tree_Write;
-- Writes out internal tables to current tree file using the relevant
-- Table.Tree_Write routines.
function Last_Elist_Id return Elist_Id;
-- Returns Id of last allocated element list header
function Elists_Address return System.Address;
-- Return address of Elists table (used in Back_End for Gigi call)
function Num_Elists return Nat;
-- Number of currently allocated element lists
function Last_Elmt_Id return Elmt_Id;
-- Returns Id of last allocated list element
function Elmts_Address return System.Address;
-- Return address of Elmts table (used in Back_End for Gigi call)
function Node (Elmt : Elmt_Id) return Node_Id;
pragma Inline (Node);
-- Returns the value of a given list element. Returns Empty if Elmt
-- is set to No_Elmt.
function New_Elmt_List return Elist_Id;
-- Creates a new empty element list. Typically this is used to initialize
-- a field in some other node which points to an element list where the
-- list is then subsequently filled in using Append calls.
function First_Elmt (List : Elist_Id) return Elmt_Id;
pragma Inline (First_Elmt);
-- Obtains the first element of the given element list or, if the
-- list has no items, then No_Elmt is returned.
function Last_Elmt (List : Elist_Id) return Elmt_Id;
pragma Inline (Last_Elmt);
-- Obtains the last element of the given element list or, if the
-- list has no items, then No_Elmt is returned.
function Next_Elmt (Elmt : Elmt_Id) return Elmt_Id;
pragma Inline (Next_Elmt);
-- This function returns the next element on an element list. The argument
-- must be a list element other than No_Elmt. Returns No_Elmt if the given
-- element is the last element of the list.
procedure Next_Elmt (Elmt : in out Elmt_Id);
pragma Inline (Next_Elmt);
-- Next_Elmt (Elmt) is equivalent to Elmt := Next_Elmt (Elmt)
function Is_Empty_Elmt_List (List : Elist_Id) return Boolean;
pragma Inline (Is_Empty_Elmt_List);
-- This function determines if a given tree id references an element list
-- that contains no items.
procedure Append_Elmt (Node : Node_Id; To : Elist_Id);
-- Appends Node at the end of To, allocating a new element
procedure Prepend_Elmt (Node : Node_Id; To : Elist_Id);
-- Appends Node at the beginning of To, allocating a new element
procedure Insert_Elmt_After (Node : Node_Id; Elmt : Elmt_Id);
-- Add a new element (Node) right after the pre-existing element Elmt
-- It is invalid to call this subprogram with Elmt = No_Elmt.
procedure Replace_Elmt (Elmt : Elmt_Id; New_Node : Node_Id);
pragma Inline (Replace_Elmt);
-- Causes the given element of the list to refer to New_Node, the node
-- which was previously referred to by Elmt is effectively removed from
-- the list and replaced by New_Node.
procedure Remove_Elmt (List : Elist_Id; Elmt : Elmt_Id);
-- Removes Elmt from the given list. The node itself is not affected,
-- but the space used by the list element may be (but is not required
-- to be) freed for reuse in a subsequent Append_Elmt call.
procedure Remove_Last_Elmt (List : Elist_Id);
-- Removes the last element of the given list. The node itself is not
-- affected, but the space used by the list element may be (but is not
-- required to be) freed for reuse in a subsequent Append_Elmt call.
function No (List : Elist_Id) return Boolean;
pragma Inline (No);
-- Tests given Id for equality with No_Elist. This allows notations like
-- "if No (Statements)" as opposed to "if Statements = No_Elist".
function Present (List : Elist_Id) return Boolean;
pragma Inline (Present);
-- Tests given Id for inequality with No_Elist. This allows notations like
-- "if Present (Statements)" as opposed to "if Statements /= No_Elist".
function No (Elmt : Elmt_Id) return Boolean;
pragma Inline (No);
-- Tests given Id for equality with No_Elmt. This allows notations like
-- "if No (Operation)" as opposed to "if Operation = No_Elmt".
function Present (Elmt : Elmt_Id) return Boolean;
pragma Inline (Present);
-- Tests given Id for inequality with No_Elmt. This allows notations like
-- "if Present (Operation)" as opposed to "if Operation /= No_Elmt".
end Elists;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Test is begin Put(F()); end;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- I N T E R F A C E S . P A C K E D _ D E C I M A L --
-- --
-- S p e c --
-- (Version for IBM Mainframe Packed Decimal Format) --
-- --
-- $Revision: 2 $ --
-- --
-- The GNAT library is free software; you can redistribute it and/or modify --
-- it under terms of the GNU Library General Public License as published by --
-- the Free Software Foundation; either version 2, or (at your option) any --
-- later version. The GNAT library is distributed in the hope that it will --
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty --
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- Library General Public License for more details. You should have --
-- received a copy of the GNU Library General Public License along with --
-- the GNAT library; see the file COPYING.LIB. If not, write to the Free --
-- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
-- --
------------------------------------------------------------------------------
-- This unit defines the packed decimal format used by GNAT in response to
-- a specication of Machine_Radix 10 for a decimal fixed-point type. The
-- format and operations are completely encapsulated in this unit, so all
-- that is necessary to compile using different packed decimal formats is
-- to replace this single unit.
-- Note that the compiler access the spec of this unit during compilation
-- to obtain the data length that needs allocating, so the correct version
-- of the spec must be available to the compiler, and must correspond to
-- the spec and body made available to the linker, and all units of a given
-- program must be compiled with the same version of the spec and body.
-- This consistency will be enforced automatically using the normal binder
-- consistency checking, since any unit declaring Machine_Radix 10 types or
-- containing operations on such data will implicitly with Packed_Decimal.
with System;
package Interfaces.Packed_Decimal is
------------------------
-- Format Description --
------------------------
-- IBM Mainframe packed decimal format uses a byte string of length one
-- to 10 bytes, with the most significant byte first. Each byte contains
-- two decimal digits (with the high order digit in the left nibble, and
-- the low order four bits contain the sign, using the following code:
-- 16#A# 2#1010# positive
-- 16#B# 2#1011# negative
-- 16#C# 2#1100# positive (preferred representation)
-- 16#D# 2#1101# negative (preferred representation)
-- 16#E# 2#1110# positive
-- 16#F# 2#1011# positive
-- In this package, all six sign representations are interpreted as
-- shown above when an operand is read, when an operand is written,
-- the preferred representations are always used. Constraint_Error
-- is raised if any other bit pattern is found in the sign nibble,
-- or if a digit nibble contains an invalid digit code.
-- Some examples follow:
-- 05 76 3C +5763
-- 00 01 1D -11
-- 00 04 4E +44 (non-standard sign)
-- 00 00 00 invalid (incorrect sign nibble)
-- 0A 01 1C invalid (bad digit)
------------------
-- Length Array --
------------------
-- The following array must be declared in exactly the form shown, since
-- the compiler accesses the associated tree to determine the size to be
-- allocated to a machine radix 10 type, depending on the number of digits.
subtype Byte_Length is Positive range 1 .. 10;
-- Range of possible byte lengths
Packed_Size : constant array (1 .. 18) of Byte_Length :=
(01 => 01, -- Length in bytes for digits 1
02 => 02, -- Length in bytes for digits 2
03 => 02, -- Length in bytes for digits 2
04 => 03, -- Length in bytes for digits 2
05 => 03, -- Length in bytes for digits 2
06 => 04, -- Length in bytes for digits 2
07 => 04, -- Length in bytes for digits 2
08 => 05, -- Length in bytes for digits 2
09 => 05, -- Length in bytes for digits 2
10 => 06, -- Length in bytes for digits 2
11 => 06, -- Length in bytes for digits 2
12 => 07, -- Length in bytes for digits 2
13 => 07, -- Length in bytes for digits 2
14 => 08, -- Length in bytes for digits 2
15 => 08, -- Length in bytes for digits 2
16 => 09, -- Length in bytes for digits 2
17 => 09, -- Length in bytes for digits 2
18 => 10); -- Length in bytes for digits 2
-------------------------
-- Conversion Routines --
-------------------------
subtype D32 is Positive range 1 .. 9;
-- Used to represent number of digits in a packed decimal value that
-- can be represented in a 32-bit binary signed integer form.
subtype D64 is Positive range 10 .. 18;
-- Used to represent number of digits in a packed decimal value that
-- requires a 64-bit signed binary integer for representing all values.
function Packed_To_Int32 (P : System.Address; D : D32) return Integer_32;
-- The argument P is the address of a packed decimal value and D is the
-- number of digits (in the range 1 .. 9, as implied by the subtype).
-- The returned result is the corresponding signed binary value. The
-- exception Constraint_Error is raised if the input is invalid.
function Packed_To_Int64 (P : System.Address; D : D64) return Integer_64;
-- The argument P is the address of a packed decimal value and D is the
-- number of digits (in the range 10 .. 18, as implied by the subtype).
-- The returned result is the corresponding signed binary value. The
-- exception Constraint_Error is raised if the input is invalid.
procedure Int32_To_Packed (V : Integer_32; P : System.Address; D : D32);
-- The argument V is a signed binary integer, which is converted to
-- packed decimal format and stored using P, the address of a packed
-- decimal item of D digits (D is in the range 1-9). Constraint_Error
-- is raised if V is out of range of this number of digits.
procedure Int64_To_Packed (V : Integer_64; P : System.Address; D : D64);
-- The argument V is a signed binary integer, which is converted to
-- packed decimal format and stored using P, the address of a packed
-- decimal item of D digits (D is in the range 10-18). Constraint_Error
-- is raised if V is out of range of this number of digits.
end Interfaces.Packed_Decimal;
|
-- This spec has been automatically generated from STM32WB55x.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.SYSCFG2 is
pragma Preelaborate;
---------------
-- Registers --
---------------
type IMR1_Register is record
-- unspecified
Reserved_0_12 : HAL.UInt13 := 16#0#;
TIM1IM : Boolean := False;
TIM16IM : Boolean := False;
TIM17IM : Boolean := False;
-- unspecified
Reserved_16_20 : HAL.UInt5 := 16#0#;
EXTI5IM : Boolean := False;
EXTI6IM : Boolean := False;
EXTI7IM : Boolean := False;
EXTI8IM : Boolean := False;
EXTI9IM : Boolean := False;
EXTI10IM : Boolean := False;
EXTI11IM : Boolean := False;
EXTI12IM : Boolean := False;
EXTI13IM : Boolean := False;
EXTI14IM : Boolean := False;
EXTI15IM : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for IMR1_Register use record
Reserved_0_12 at 0 range 0 .. 12;
TIM1IM at 0 range 13 .. 13;
TIM16IM at 0 range 14 .. 14;
TIM17IM at 0 range 15 .. 15;
Reserved_16_20 at 0 range 16 .. 20;
EXTI5IM at 0 range 21 .. 21;
EXTI6IM at 0 range 22 .. 22;
EXTI7IM at 0 range 23 .. 23;
EXTI8IM at 0 range 24 .. 24;
EXTI9IM at 0 range 25 .. 25;
EXTI10IM at 0 range 26 .. 26;
EXTI11IM at 0 range 27 .. 27;
EXTI12IM at 0 range 28 .. 28;
EXTI13IM at 0 range 29 .. 29;
EXTI14IM at 0 range 30 .. 30;
EXTI15IM at 0 range 31 .. 31;
end record;
type IMR2_Register is record
-- unspecified
Reserved_0_15 : HAL.UInt16 := 16#0#;
PVM1IM : Boolean := False;
-- unspecified
Reserved_17_17 : HAL.Bit := 16#0#;
PVM3IM : Boolean := False;
-- unspecified
Reserved_19_19 : HAL.Bit := 16#0#;
PVDIM : Boolean := False;
-- unspecified
Reserved_21_31 : HAL.UInt11 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for IMR2_Register use record
Reserved_0_15 at 0 range 0 .. 15;
PVM1IM at 0 range 16 .. 16;
Reserved_17_17 at 0 range 17 .. 17;
PVM3IM at 0 range 18 .. 18;
Reserved_19_19 at 0 range 19 .. 19;
PVDIM at 0 range 20 .. 20;
Reserved_21_31 at 0 range 21 .. 31;
end record;
type C2IMR1_Register is record
RTCSTAMPTAMPLSECSSIM : Boolean := False;
-- unspecified
Reserved_1_2 : HAL.UInt2 := 16#0#;
RTCWKUPIM : Boolean := False;
RTCALARMIM : Boolean := False;
RCCIM : Boolean := False;
FLASHIM : Boolean := False;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
PKAIM : Boolean := False;
RNGIM : Boolean := False;
AES1IM : Boolean := False;
COMPIM : Boolean := False;
ADCIM : Boolean := False;
-- unspecified
Reserved_13_15 : HAL.UInt3 := 16#0#;
EXTI0IM : Boolean := False;
EXTI1IM : Boolean := False;
EXTI2IM : Boolean := False;
EXTI3IM : Boolean := False;
EXTI4IM : Boolean := False;
EXTI5IM : Boolean := False;
EXTI6IM : Boolean := False;
EXTI7IM : Boolean := False;
EXTI8IM : Boolean := False;
EXTI9IM : Boolean := False;
EXTI10IM : Boolean := False;
EXTI11IM : Boolean := False;
EXTI12IM : Boolean := False;
EXTI13IM : Boolean := False;
EXTI14IM : Boolean := False;
EXTI15IM : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C2IMR1_Register use record
RTCSTAMPTAMPLSECSSIM at 0 range 0 .. 0;
Reserved_1_2 at 0 range 1 .. 2;
RTCWKUPIM at 0 range 3 .. 3;
RTCALARMIM at 0 range 4 .. 4;
RCCIM at 0 range 5 .. 5;
FLASHIM at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
PKAIM at 0 range 8 .. 8;
RNGIM at 0 range 9 .. 9;
AES1IM at 0 range 10 .. 10;
COMPIM at 0 range 11 .. 11;
ADCIM at 0 range 12 .. 12;
Reserved_13_15 at 0 range 13 .. 15;
EXTI0IM at 0 range 16 .. 16;
EXTI1IM at 0 range 17 .. 17;
EXTI2IM at 0 range 18 .. 18;
EXTI3IM at 0 range 19 .. 19;
EXTI4IM at 0 range 20 .. 20;
EXTI5IM at 0 range 21 .. 21;
EXTI6IM at 0 range 22 .. 22;
EXTI7IM at 0 range 23 .. 23;
EXTI8IM at 0 range 24 .. 24;
EXTI9IM at 0 range 25 .. 25;
EXTI10IM at 0 range 26 .. 26;
EXTI11IM at 0 range 27 .. 27;
EXTI12IM at 0 range 28 .. 28;
EXTI13IM at 0 range 29 .. 29;
EXTI14IM at 0 range 30 .. 30;
EXTI15IM at 0 range 31 .. 31;
end record;
type C2IMR2_Register is record
DMA1CH1IM : Boolean := False;
DMA1CH2IM : Boolean := False;
DMA1CH3IM : Boolean := False;
DMA1CH4IM : Boolean := False;
DMA1CH5IM : Boolean := False;
DMA1CH6IM : Boolean := False;
DMA1CH7IM : Boolean := False;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
DMA2CH1IM : Boolean := False;
DMA2CH2IM : Boolean := False;
DMA2CH3IM : Boolean := False;
DMA2CH4IM : Boolean := False;
DMA2CH5IM : Boolean := False;
DMA2CH6IM : Boolean := False;
DMA2CH7IM : Boolean := False;
DMAMUX1IM : Boolean := False;
PVM1IM : Boolean := False;
-- unspecified
Reserved_17_17 : HAL.Bit := 16#0#;
PVM3IM : Boolean := False;
-- unspecified
Reserved_19_19 : HAL.Bit := 16#0#;
PVDIM : Boolean := False;
TSCIM : Boolean := False;
LCDIM : Boolean := False;
-- unspecified
Reserved_23_31 : HAL.UInt9 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C2IMR2_Register use record
DMA1CH1IM at 0 range 0 .. 0;
DMA1CH2IM at 0 range 1 .. 1;
DMA1CH3IM at 0 range 2 .. 2;
DMA1CH4IM at 0 range 3 .. 3;
DMA1CH5IM at 0 range 4 .. 4;
DMA1CH6IM at 0 range 5 .. 5;
DMA1CH7IM at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
DMA2CH1IM at 0 range 8 .. 8;
DMA2CH2IM at 0 range 9 .. 9;
DMA2CH3IM at 0 range 10 .. 10;
DMA2CH4IM at 0 range 11 .. 11;
DMA2CH5IM at 0 range 12 .. 12;
DMA2CH6IM at 0 range 13 .. 13;
DMA2CH7IM at 0 range 14 .. 14;
DMAMUX1IM at 0 range 15 .. 15;
PVM1IM at 0 range 16 .. 16;
Reserved_17_17 at 0 range 17 .. 17;
PVM3IM at 0 range 18 .. 18;
Reserved_19_19 at 0 range 19 .. 19;
PVDIM at 0 range 20 .. 20;
TSCIM at 0 range 21 .. 21;
LCDIM at 0 range 22 .. 22;
Reserved_23_31 at 0 range 23 .. 31;
end record;
-- SIPCR_SAES array
type SIPCR_SAES_Field_Array is array (1 .. 2) of Boolean
with Component_Size => 1, Size => 2;
-- Type definition for SIPCR_SAES
type SIPCR_SAES_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- SAES as a value
Val : HAL.UInt2;
when True =>
-- SAES as an array
Arr : SIPCR_SAES_Field_Array;
end case;
end record
with Unchecked_Union, Size => 2;
for SIPCR_SAES_Field use record
Val at 0 range 0 .. 1;
Arr at 0 range 0 .. 1;
end record;
type SIPCR_Register is record
SAES : SIPCR_SAES_Field := (As_Array => False, Val => 16#0#);
SPKA : Boolean := False;
SRNG : Boolean := False;
-- unspecified
Reserved_4_31 : HAL.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SIPCR_Register use record
SAES at 0 range 0 .. 1;
SPKA at 0 range 2 .. 2;
SRNG at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
type SYSCFG2_Peripheral is record
IMR1 : aliased IMR1_Register;
IMR2 : aliased IMR2_Register;
C2IMR1 : aliased C2IMR1_Register;
C2IMR2 : aliased C2IMR2_Register;
SIPCR : aliased SIPCR_Register;
end record
with Volatile;
for SYSCFG2_Peripheral use record
IMR1 at 16#100# range 0 .. 31;
IMR2 at 16#104# range 0 .. 31;
C2IMR1 at 16#108# range 0 .. 31;
C2IMR2 at 16#10C# range 0 .. 31;
SIPCR at 16#110# range 0 .. 31;
end record;
SYSCFG2_Periph : aliased SYSCFG2_Peripheral
with Import, Address => System'To_Address (16#40010000#);
end STM32_SVD.SYSCFG2;
|
with Ahven; use Ahven;
with AdaPcre; use AdaPcre;
package body My_Tests is
procedure Initialize (T : in out Test) is
begin
Set_Name (T, "My tests");
Framework.Add_Test_Routine
(T, PCRE_MATCH'Access, "PCRE_MATCH");
Framework.Add_Test_Routine
(T, PCRE_MATCH2'Access, "PCRE_MATCH2");
end Initialize;
procedure Search_For_Pattern
(Compiled_Expression : AdaPcre.Pcre_Type;
Search_In : String;
Offset : Natural;
First, Last : out Positive;
Found : out Boolean)
is
Result : Match_Array (0 .. 2);
Retcode : Integer;
begin
Match
(Retcode,
Result,
Compiled_Expression,
Null_Extra,
Search_In,
Search_In'Length,
Offset);
if Retcode < 0 then
Found := False;
else
Found := True;
First := Search_In'First + Result (0);
Last := Search_In'First + Result (1) - 1;
end if;
end Search_For_Pattern;
procedure PCRE_MATCH is
Word_Pattern : constant String := "([A-z]+)";
Subject : constant String := ";-)I love PATTERN matching!";
Current_Offset : Natural := 0;
First, Last : Positive;
Found : Boolean;
Regexp : Pcre_Type;
Msg : Message;
Last_Msg, ErrPos : Natural := 0;
Count : Integer := 0;
begin
Compile (Regexp, Word_Pattern, Msg, Last_Msg, ErrPos);
loop
Search_For_Pattern
(Regexp,
Subject,
Current_Offset,
First,
Last,
Found);
exit when not Found;
Count := Count + 1;
Current_Offset := Last;
end loop;
Free (Regexp);
Assert (Condition => Count = 4,
Message => "Match 4 patterns");
end PCRE_MATCH;
procedure PCRE_MATCH2 is
Word_Pattern : constant String := "e";
Subject : constant String := "Eeeee: Weekly Challenge";
Current_Offset : Natural := 0;
First, Last : Positive;
Found : Boolean;
Extra : Extra_type;
Regexp : Pcre_Type;
Msg : Message;
Last_Msg, ErrPos : Natural := 0;
Count : Integer := 0;
begin
Compile (Regexp, Word_Pattern, Msg, Last_Msg, ErrPos);
Study (Extra, Regexp, Msg, Last_Msg);
loop
Search_For_Pattern
(Regexp,
Subject,
Current_Offset,
First,
Last,
Found);
exit when not Found;
Count := Count + 1;
Current_Offset := Last;
end loop;
Free (Regexp);
Assert (Condition => Count = 8,
Message => "Match 8 patterns");
end PCRE_MATCH2;
end My_Tests;
|
-------------------------------------------------------------------------------
-- Copyright (C) 2020-2030, per.s.sandberg@bahnhof.se --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files --
-- (the "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, sublicense, and / or sell copies of the Software, and to --
-- permit persons to whom the Software is furnished to do so, subject to --
-- the following conditions : --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, --
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL --
-- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR --
-- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, --
-- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR --
-- OTHER DEALINGS IN THE SOFTWARE. --
-------------------------------------------------------------------------------
with GNATCOLL.JSON;
with Ada.Strings.Unbounded;
package ZMQ.Examples.JSON_Data is
use Ada.Strings.Unbounded;
use GNATCOLL.JSON;
type Coordinate is record
X, Y, Z : Float;
end record;
type Data_Type is record
Sensor_Name : Unbounded_String;
OK : Boolean := True;
Location : Coordinate := (-1.0, -2.0, -3.0);
Orientation : Coordinate := (-1.2, -2.3, -3.4);
end record;
function Create (Val : Coordinate) return JSON_Value;
function Create (Val : Data_Type) return JSON_Value;
procedure Set_Field
(Val : JSON_Value;
Field_Name : UTF8_String;
Field : Coordinate);
procedure Set_Field
(Val : JSON_Value;
Field_Name : UTF8_String;
Field : Data_Type);
procedure Cb_Coordinate
(User_Object : in out Coordinate;
Name : UTF8_String;
Value : JSON_Value);
procedure Cb_Data_Type
(User_Object : in out Data_Type;
Name : UTF8_String;
Value : JSON_Value);
procedure Read (Src : JSON_Value; Into : in out Data_Type);
procedure Read is new Gen_Map_JSON_Object (Data_Type);
procedure Read is new Gen_Map_JSON_Object (Coordinate);
end ZMQ.Examples.JSON_Data;
|
with Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
with STB.Image;
with System; use System;
with System.Storage_Elements; use System.Storage_Elements;
with Interfaces.C; use Interfaces.C;
with Interfaces; use Interfaces;
with GNAT.OS_Lib;
with QOI; use QOI;
with Reference_QOI;
with AAA.Strings;
procedure Tests is
type Storage_Array_Access is access all Storage_Array;
type Input_Data is record
Data : Storage_Array_Access;
Desc : QOI.QOI_Desc;
end record;
procedure Write_To_File (Filename : String;
D : Storage_Array;
Size : Storage_Count);
function Load_PNG (Filename : String) return Input_Data;
function Load_QOI (Filename : String) return Input_Data;
function Img (I : Input_Data) return String
is ("Width:" & I.Desc.Width'Img &
" Height:" & I.Desc.Height'Img &
" Channels:" & I.Desc.Channels'Img &
" Data (" & I.Data'First'Img & " .." &
I.Data'Last'Img
& ")");
-------------------
-- Write_To_File --
-------------------
procedure Write_To_File (Filename : String;
D : Storage_Array;
Size : Storage_Count)
is
use GNAT.OS_Lib;
FD : File_Descriptor;
Ret : Integer;
begin
FD := GNAT.OS_Lib.Create_File (Filename, Binary);
if FD = Invalid_FD then
Ada.Text_IO.Put_Line (GNAT.OS_Lib.Errno_Message);
GNAT.OS_Lib.OS_Exit (1);
end if;
Ret := Write (FD, D'Address, Integer (Size));
if Ret /= Integer (Size) then
Ada.Text_IO.Put_Line (GNAT.OS_Lib.Errno_Message);
GNAT.OS_Lib.OS_Exit (1);
end if;
Close (FD);
end Write_To_File;
--------------
-- Load_PNG --
--------------
function Load_PNG (Filename : String) return Input_Data is
W, H, Channels_In_File : Interfaces.C.int;
Pixels : constant System.Address := STB.Image.Load
(Filename, W, H, Channels_In_File, 0);
Len : constant Storage_Count := Storage_Count (W * H * Channels_In_File);
From_File : aliased Storage_Array (1 .. Len)
with Address => Pixels;
Data : constant Storage_Array_Access := new Storage_Array (1 .. Len);
Result : Input_Data;
begin
Data.all := From_File;
Result.Desc := (Width => Storage_Count (W),
Height => Storage_Count (H),
Channels => Storage_Count (Channels_In_File),
Colorspace => QOI.SRGB);
Result.Data := Data;
return Result;
end Load_PNG;
--------------
-- Load_QOI --
--------------
function Load_QOI (Filename : String) return Input_Data is
use GNAT.OS_Lib;
FD : File_Descriptor;
Ret : Integer;
Result : Input_Data;
begin
FD := GNAT.OS_Lib.Open_Read (Filename, Binary);
if FD = Invalid_FD then
Ada.Text_IO.Put_Line (Standard_Error, GNAT.OS_Lib.Errno_Message);
GNAT.OS_Lib.OS_Exit (1);
end if;
declare
Len : constant Storage_Count := Storage_Count (File_Length (FD));
In_Data : constant Storage_Array_Access :=
new Storage_Array (1 .. Len);
begin
Ret := Read (FD, In_Data.all'Address, In_Data.all'Length);
if Ret /= In_Data'Length then
Ada.Text_IO.Put_Line (GNAT.OS_Lib.Errno_Message);
GNAT.OS_Lib.OS_Exit (1);
end if;
Close (FD);
QOI.Get_Desc (In_Data.all, Result.Desc);
declare
Out_Len : constant Storage_Count :=
Result.Desc.Width * Result.Desc.Height * Result.Desc.Channels;
Out_Data : constant Storage_Array_Access :=
new Storage_Array (1 .. Out_Len);
Output_Size : Storage_Count;
begin
QOI.Decode (Data => In_Data.all,
Desc => Result.Desc,
Output => Out_Data.all,
Output_Size => Output_Size);
Result.Data := Out_Data;
if Reference_QOI.Check_Decode
(In_Data.all,
Result.Desc,
Out_Data.all (Out_Data'First .. Out_Data'First + Output_Size - 1))
then
Put_Line ("Compare with reference decoder: OK");
else
Put_Line ("Compare with reference decoder: FAIL");
GNAT.OS_Lib.OS_Exit (1);
end if;
return Result;
end;
end;
end Load_QOI;
Input : Input_Data;
begin
if Ada.Command_Line.Argument_Count /= 2 then
Put_Line (Standard_Error, "Usage: tests <infile> <outfile>");
GNAT.OS_Lib.OS_Exit (1);
end if;
if AAA.Strings.Has_Suffix (Ada.Command_Line.Argument (1), ".png") then
Put_Line ("Load PNG: " & Ada.Command_Line.Argument (1));
Input := Load_PNG (Ada.Command_Line.Argument (1));
elsif AAA.Strings.Has_Suffix (Ada.Command_Line.Argument (1), ".qoi") then
Put_Line ("Load QOI: " & Ada.Command_Line.Argument (1));
Input := Load_QOI (Ada.Command_Line.Argument (1));
else
Put_Line (Standard_Error, "Invalid input file extension: '" &
Ada.Command_Line.Argument (1) & "'");
GNAT.OS_Lib.OS_Exit (1);
end if;
Put_Line ("Loaded -> " & Img (Input));
if AAA.Strings.Has_Suffix (Ada.Command_Line.Argument (2), ".png") then
declare
Result : Interfaces.C.int;
begin
Result := STB.Image.Write_PNG (Ada.Command_Line.Argument (2),
int (Input.Desc.Width),
int (Input.Desc.Height),
int (Input.Desc.Channels),
Input.Data.all'Address,
0);
if Result = 0 then
Put_Line (Standard_Error, "PNG write error: '" &
Ada.Command_Line.Argument (2) & "'");
GNAT.OS_Lib.OS_Exit (1);
end if;
end;
elsif AAA.Strings.Has_Suffix (Ada.Command_Line.Argument (2), ".qoi") then
declare
Output : Storage_Array (1 .. QOI.Encode_Worst_Case (Input.Desc));
Output_Size : Storage_Count;
begin
QOI.Encode (Input.Data.all,
Input.Desc,
Output,
Output_Size);
if Output_Size /= 0 then
Put_Line ("Encode: OK");
if Reference_QOI.Check_Encode
(Input.Data.all,
Input.Desc,
Output (Output'First .. Output'First + Output_Size - 1))
then
Put_Line ("Compare with reference encoder: OK");
else
Put_Line ("Compare with reference encoder: FAIL");
GNAT.OS_Lib.OS_Exit (1);
end if;
Write_To_File (Ada.Command_Line.Argument (2), Output, Output_Size);
else
Ada.Text_IO.Put_Line ("Encode failed");
GNAT.OS_Lib.OS_Exit (1);
end if;
end;
else
Put_Line (Standard_Error, "Invalid output file extension: '" &
Ada.Command_Line.Argument (2) & "'");
GNAT.OS_Lib.OS_Exit (1);
end if;
end Tests;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with Display;
with Port_Specification;
private with Ada.Calendar;
package PortScan.Buildcycle is
package PSP renames Port_Specification;
cycle_cmd_error : exception;
procedure initialize (test_mode : Boolean);
function build_package (id : builders;
sequence_id : port_id;
specification : PSP.Portspecs;
interactive : Boolean := False;
interphase : String := "") return Boolean;
-- Compile status of builder for the curses display
function builder_status (id : builders;
shutdown : Boolean := False;
idle : Boolean := False)
return Display.builder_rec;
function last_build_phase (id : builders) return String;
function assemble_history_record (slave : builders;
pid : port_id;
action : Display.history_action) return Display.history_rec;
-- exposed for WWW report
function load_core (instant_load : Boolean) return Float;
-- records the current length of the build log.
procedure set_log_lines (id : builders);
-- Returns the formatted time difference between start and stop of package build
function elapsed_build (id : builders) return String;
-- Run make -C /port/ makesum (used by developer to generate distinfo)
procedure run_makesum (id : builders; ssl_variant : String);
-- Exposed for Pilot to determine validity of test build request
function valid_test_phase (afterphase : String) return Boolean;
-- Exposed for Pilot to regenerate patches (Names and content are maintained)
procedure run_patch_regen (id : builders; sourceloc : String; ssl_variant : String);
private
package CAL renames Ada.Calendar;
type phases is (blr_depends, fetch, extract, patch, configure, build, stage,
test, check_plist, pkg_package, install, deinstall);
type trackrec is
record
seq_id : port_id;
head_time : CAL.Time;
tail_time : CAL.Time;
log_handle : aliased TIO.File_Type;
dynlink : string_crate.Vector;
runpaths : string_crate.Vector;
checkpaths : string_crate.Vector;
goodpaths : string_crate.Vector;
rpath_fatal : Boolean;
check_strip : Boolean;
disable_dog : Boolean;
loglines : Natural := 0;
end record;
type dim_trackers is array (builders) of trackrec;
type dim_phase_trackers is array (builders) of phases;
type execution_limit is range 1 .. 720;
phase_trackers : dim_phase_trackers;
trackers : dim_trackers;
testing : Boolean;
uname_mrv : HT.Text;
customenv : HT.Text;
selftest : constant String := "SELFTEST";
chroot_make_program : constant String := "/usr/bin/make -m /xports/Mk";
-- If the afterphase string matches a legal phase name then that phase
-- is returned, otherwise the value of blr_depends is returned. Allowed
-- phases are: extract/patch/configure/build/stage/test/install/deinstall.
-- blr_depends is considered a negative response
-- stage includes check-plist
function valid_test_phase (afterphase : String) return phases;
function exec_phase (id : builders; phase : phases;
time_limit : execution_limit;
environ : String;
phaseenv : String := "";
depends_phase : Boolean := False;
skip_header : Boolean := False;
skip_footer : Boolean := False)
return Boolean;
procedure mark_file_system (id : builders; action : String; environ : String);
procedure interact_with_builder (id : builders; ssl_variant : String);
procedure set_uname_mrv;
procedure obtain_custom_environment;
function phase2str (phase : phases) return String;
function max_time_without_output (phase : phases) return execution_limit;
function timeout_multiplier_x10 return Positive;
function get_environment (id : builders; environ : String) return String;
function get_port_variables (id : builders; environ : String) return String;
function generic_system_command (command : String) return String;
function get_root (id : builders) return String;
function passed_runpath_check (id : builders) return Boolean;
function format_loglines (numlines : Natural) return String;
function watchdog_message (minutes : execution_limit) return String;
function get_port_prefix (id : builders; environ : String) return String;
function pkg_install_subroutine (id : builders; root, env_vars, line : String) return Boolean;
function environment_override (toolchain : Boolean;
ssl_variant : String;
enable_tty : Boolean := False) return String;
function exec_phase_generic
(id : builders;
phase : phases;
environ : String) return Boolean;
function exec_phase_build
(id : builders;
environ : String) return Boolean;
function exec_phase_install
(id : builders;
pkgversion : String;
environ : String) return Boolean;
function exec_phase_deinstall
(id : builders;
pkgversion : String;
environ : String) return Boolean;
function deinstall_all_packages
(id : builders;
environ : String) return Boolean;
function install_run_depends
(specification : PSP.Portspecs;
id : builders;
environ : String) return Boolean;
function generic_execute
(id : builders;
command : String;
dogbite : out Boolean;
time_limit : execution_limit) return Boolean;
function exec_phase_depends
(specification : PSP.Portspecs;
phase_name : String;
id : builders;
environ : String) return Boolean;
function dynamically_linked
(base : String;
filename : String;
strip_check : Boolean;
unstripped : out Boolean) return Boolean;
function log_linked_libraries
(id : builders;
pkgversion : String;
environ : String) return Boolean;
procedure stack_linked_libraries
(id : builders;
base : String;
filename : String;
environ : String);
function detect_leftovers_and_MIA
(id : builders;
action : String;
description : String;
environ : String) return Boolean;
end PortScan.Buildcycle;
|
-- Chip Richards, NiEstu, Phoenix AZ, Spring 2010
-- Lumen would not be possible without the support and contributions of a cast
-- of thousands, including and primarily Rod Kay.
-- This code is covered by the ISC License:
--
-- Copyright © 2010, NiEstu
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- The software is provided "as is" and the author disclaims all warranties
-- with regard to this software including all implied warranties of
-- merchantability and fitness. In no event shall the author be liable for any
-- special, direct, indirect, or consequential damages or any damages
-- whatsoever resulting from loss of use, data or profits, whether in an
-- action of contract, negligence or other tortious action, arising out of or
-- in connection with the use or performance of this software.
with System;
package X11 is
-- Xlib stuff needed by more than one of the routines below
type Data_Format_Type is (Invalid, Bits_8, Bits_16, Bits_32);
for Data_Format_Type use
(Invalid => 0,
Bits_8 => 8,
Bits_16 => 16,
Bits_32 => 32);
type Atom is new Long_Integer;
-- Values used to compute record rep clause values that are portable
-- between 32- and 64-bit systems
Is_32 : constant := Boolean'Pos (System.Word_Size = 32);
Is_64 : constant := 1 - Is_32;
Word_Bytes : constant := Integer'Size / System.Storage_Unit;
Word_Bits : constant := Integer'Size - 1;
Long_Bytes : constant := Long_Integer'Size / System.Storage_Unit;
Long_Bits : constant := Long_Integer'Size - 1;
-- Xlib types needed only by Create
subtype Dimension is Short_Integer;
subtype Pixel is Long_Integer;
subtype Position is Short_Integer;
-- Used to simulate "out" param for C function
type Int_Ptr is access all Integer;
-- Actually an array, but only ever one element
type FB_Config_Ptr is access all System.Address;
-- OpenGL context ("visual") attribute specifiers
type X11Context_Attribute_Name is
(
Attr_None,
Attr_Use_GL, -- unused
Attr_Buffer_Size, -- color index buffer size, ignored if TrueColor
Attr_Level, -- buffer level for over/underlays
Attr_RGBA, -- set by Depth => TrueColor
Attr_Doublebuffer, -- set by Animate => True
Attr_Stereo, -- wow, you have stereo visuals?
Attr_Aux_Buffers, -- number of auxiliary buffers
Attr_Red_Size, -- bit depth, red
Attr_Green_Size, -- bit depth, green
Attr_Blue_Size, -- bit depth, blue
Attr_Alpha_Size, -- bit depth, alpha
Attr_Depth_Size, -- depth buffer size
Attr_Stencil_Size, -- stencil buffer size
Attr_Accum_Red_Size, -- accumulation buffer bit depth, red
Attr_Accum_Green_Size, -- accumulation buffer bit depth, green
Attr_Accum_Blue_Size, -- accumulation buffer bit depth, blue
Attr_Accum_Alpha_Size -- accumulation buffer bit depth, alpha
);
type X11Context_Attribute (Name : X11Context_Attribute_Name := Attr_None) is
record
case Name is
when Attr_None | Attr_Use_GL | Attr_RGBA |
Attr_Doublebuffer | Attr_Stereo =>
null; -- present or not, no value
when Attr_Level =>
Level : Integer := 0;
when Attr_Buffer_Size | Attr_Aux_Buffers | Attr_Depth_Size |
Attr_Stencil_Size | Attr_Red_Size | Attr_Green_Size |
Attr_Blue_Size | Attr_Alpha_Size | Attr_Accum_Red_Size |
Attr_Accum_Green_Size | Attr_Accum_Blue_Size |
Attr_Accum_Alpha_Size =>
Size : Natural := 0;
end case;
end record;
type X11Context_Attributes is array (Positive range <>) of
X11Context_Attribute;
Max_GLX_Attributes : constant := 2 +
(X11Context_Attribute_Name'Pos (X11Context_Attribute_Name'Last) + 1) * 2;
type GLX_Attribute_List is array (1 .. Max_GLX_Attributes) of Integer;
type GLX_Attribute_List_Ptr is new System.Address;
------------------------------------------------------------------------
type Display_Pointer is new System.Address;
-- The maximum length of an event data record
type Padding is array (1 .. 23) of Long_Integer;
type Screen_Depth is new Natural;
type Screen_Number is new Natural;
type Visual_ID is new Long_Integer;
type Window_ID is new Long_Integer;
type Alloc_Mode is (Alloc_None, Alloc_All);
type Atom_Array is array (Positive range <>) of Atom;
type Colormap_ID is new Long_Integer;
type X_Window_Attributes_Mask is mod 2 ** Integer'Size;
type Window_Class is (Copy_From_Parent, Input_Output, Input_Only);
type X_Event_Mask is mod 2 ** Long_Integer'Size;
-- An extremely abbreviated version of the XSetWindowAttributes
-- structure, containing only the fields we care about.
--
-- NOTE: offset multiplier values differ between 32-bit and 64-bit
-- systems since on 32-bit systems long size equals int size and the
-- record has no padding. The byte and bit widths come from Internal.
Start_32 : constant := 10;
Start_64 : constant := 9;
Start : constant := (Is_32 * Start_32) + (Is_64 * Start_64);
------------------------------------------------------------------------
Null_Display_Pointer : constant Display_Pointer :=
Display_Pointer (System.Null_Address);
type X_Set_Window_Attributes is record
Event_Mask : X_Event_Mask := 0;
Colormap : Colormap_ID := 0;
end record;
for X_Set_Window_Attributes use record
Event_Mask at (Start + 0) * Long_Bytes range 0 .. Long_Bits;
Colormap at (Start + 3) * Long_Bytes range 0 .. Long_Bits;
end record;
-- The GL rendering context type
type GLX_Context is new System.Address;
type X_Visual_Info is record
Visual : System.Address;
Visual_Ident : Visual_ID;
Screen : Screen_Number;
Depth : Screen_Depth;
Class : Integer;
Red_Mask : Long_Integer;
Green_Mask : Long_Integer;
Blue_Mask : Long_Integer;
Colormap_Size : Natural;
Bits_Per_RGB : Natural;
end record;
type X_Visual_Info_Pointer is access all X_Visual_Info;
type X_Class_Hint is record
Instance_Name : System.Address;
Class_Name : System.Address;
end record;
type X_Text_Property is record
Value : System.Address;
Encoding : Atom;
Format : Data_Format_Type;
NItems : Long_Integer;
end record;
---------------------------------------------------------------------------
-- X modifier mask and its values
type Modifier_Mask is mod 2 ** Integer'Size;
-- Xlib constants needed only by Create
Configure_Event_Mask : constant X_Window_Attributes_Mask :=
2#00_1000_0000_0000#; -- 11th bit
Configure_Colormap : constant X_Window_Attributes_Mask :=
2#10_0000_0000_0000#; -- 13th bit
-- Atom names
WM_Del : String := "WM_DELETE_WINDOW" & ASCII.NUL;
Null_Context : constant GLX_Context := GLX_Context (System.Null_Address);
-- X event type codes
-- we don't actually use this, just there to define bounds
X_Error : constant := 0;
X_Key_Press : constant := 2;
X_Key_Release : constant := 3;
X_Button_Press : constant := 4;
X_Button_Release : constant := 5;
X_Motion_Notify : constant := 6;
X_Enter_Notify : constant := 7;
X_Leave_Notify : constant := 8;
X_Focus_In : constant := 9;
X_Focus_Out : constant := 10;
X_Expose : constant := 12;
X_Unmap_Notify : constant := 18;
X_Map_Notify : constant := 19;
X_Configure_Notify : constant := 22;
X_Client_Message : constant := 33;
-- we don't actually use this, just there to define bounds
X_Generic_Event : constant := 35;
X_First_Event : constant := X_Error;
X_Last_Event : constant := X_Generic_Event + 1;
-- Our "delete window" atom value
Delete_Window_Atom : Atom;
------------------------------------------------------------------------
Shift_Mask : constant Modifier_Mask := 2#0000_0000_0000_0001#;
Lock_Mask : constant Modifier_Mask := 2#0000_0000_0000_0010#;
Control_Mask : constant Modifier_Mask := 2#0000_0000_0000_0100#;
Mod_1_Mask : constant Modifier_Mask := 2#0000_0000_0000_1000#;
Mod_2_Mask : constant Modifier_Mask := 2#0000_0000_0001_0000#;
Mod_3_Mask : constant Modifier_Mask := 2#0000_0000_0010_0000#;
Mod_4_Mask : constant Modifier_Mask := 2#0000_0000_0100_0000#;
Mod_5_Mask : constant Modifier_Mask := 2#0000_0000_1000_0000#;
Button_1_Mask : constant Modifier_Mask := 2#0000_0001_0000_0000#;
Button_2_Mask : constant Modifier_Mask := 2#0000_0010_0000_0000#;
Button_3_Mask : constant Modifier_Mask := 2#0000_0100_0000_0000#;
Button_4_Mask : constant Modifier_Mask := 2#0000_1000_0000_0000#;
Button_5_Mask : constant Modifier_Mask := 2#0001_0000_0000_0000#;
type X_Event_Code is new Integer range X_First_Event .. X_Last_Event;
Bytes : constant := Word_Bytes;
Bits : constant := Word_Bits;
Atom_Bits : constant := Atom'Size - 1;
Base_1_32 : constant := 8;
Base_2_32 : constant := 5;
Base_3_32 : constant := 6;
Base_4_32 : constant := 7;
Base_1_64 : constant := 16;
Base_2_64 : constant := 10;
Base_3_64 : constant := 12;
Base_4_64 : constant := 14;
Base_1 : constant := (Base_1_32 * Is_32) + (Base_1_64 * Is_64);
Base_2 : constant := (Base_2_32 * Is_32) + (Base_2_64 * Is_64);
Base_3 : constant := (Base_3_32 * Is_32) + (Base_3_64 * Is_64);
Base_4 : constant := (Base_4_32 * Is_32) + (Base_4_64 * Is_64);
type X_Event_Data (X_Event_Type : X_Event_Code := X_Error) is record
case X_Event_Type is
when X_Key_Press | X_Key_Release =>
Key_X : Natural;
Key_Y : Natural;
Key_Root_X : Natural;
Key_Root_Y : Natural;
Key_State : Modifier_Mask;
Key_Code : Natural;
when X_Button_Press | X_Button_Release =>
Btn_X : Natural;
Btn_Y : Natural;
Btn_Root_X : Natural;
Btn_Root_Y : Natural;
Btn_State : Modifier_Mask;
Btn_Code : Natural;
when X_Motion_Notify =>
Mov_X : Natural;
Mov_Y : Natural;
Mov_Root_X : Natural;
Mov_Root_Y : Natural;
Mov_State : Modifier_Mask;
when X_Enter_Notify | X_Leave_Notify =>
Xng_X : Natural;
Xng_Y : Natural;
Xng_Root_X : Natural;
Xng_Root_Y : Natural;
when X_Expose =>
Xps_X : Natural;
Xps_Y : Natural;
Xps_Width : Natural;
Xps_Height : Natural;
Xps_Count : Natural;
when X_Configure_Notify =>
Cfg_X : Natural;
Cfg_Y : Natural;
Cfg_Width : Natural;
Cfg_Height : Natural;
when X_Client_Message =>
Msg_Value : Atom;
when others =>
Pad : Padding;
end case;
end record;
for X_Event_Data use record
X_Event_Type at 0 * Bytes range 0 .. Bits;
Key_X at (Base_1 + 0) * Bytes range 0 .. Bits;
Key_Y at (Base_1 + 1) * Bytes range 0 .. Bits;
Key_Root_X at (Base_1 + 2) * Bytes range 0 .. Bits;
Key_Root_Y at (Base_1 + 3) * Bytes range 0 .. Bits;
Key_State at (Base_1 + 4) * Bytes range 0 .. Bits;
Key_Code at (Base_1 + 5) * Bytes range 0 .. Bits;
Btn_X at (Base_1 + 0) * Bytes range 0 .. Bits;
Btn_Y at (Base_1 + 1) * Bytes range 0 .. Bits;
Btn_Root_X at (Base_1 + 2) * Bytes range 0 .. Bits;
Btn_Root_Y at (Base_1 + 3) * Bytes range 0 .. Bits;
Btn_State at (Base_1 + 4) * Bytes range 0 .. Bits;
Btn_Code at (Base_1 + 5) * Bytes range 0 .. Bits;
Mov_X at (Base_1 + 0) * Bytes range 0 .. Bits;
Mov_Y at (Base_1 + 1) * Bytes range 0 .. Bits;
Mov_Root_X at (Base_1 + 2) * Bytes range 0 .. Bits;
Mov_Root_Y at (Base_1 + 3) * Bytes range 0 .. Bits;
Mov_State at (Base_1 + 4) * Bytes range 0 .. Bits;
Xng_X at (Base_1 + 0) * Bytes range 0 .. Bits;
Xng_Y at (Base_1 + 1) * Bytes range 0 .. Bits;
Xng_Root_X at (Base_1 + 2) * Bytes range 0 .. Bits;
Xng_Root_Y at (Base_1 + 3) * Bytes range 0 .. Bits;
Xps_X at (Base_2 + 0) * Bytes range 0 .. Bits;
Xps_Y at (Base_2 + 1) * Bytes range 0 .. Bits;
Xps_Width at (Base_2 + 2) * Bytes range 0 .. Bits;
Xps_Height at (Base_2 + 3) * Bytes range 0 .. Bits;
Xps_Count at (Base_2 + 4) * Bytes range 0 .. Bits;
Cfg_X at (Base_3 + 0) * Bytes range 0 .. Bits;
Cfg_Y at (Base_3 + 1) * Bytes range 0 .. Bits;
Cfg_Width at (Base_3 + 2) * Bytes range 0 .. Bits;
Cfg_Height at (Base_3 + 3) * Bytes range 0 .. Bits;
Msg_Value at (Base_4 + 0) * Bytes range 0 .. Atom_Bits;
end record;
------------------------------------------------------------------------
GL_TRUE : constant Character := Character'Val (1);
-----------------------------
-- Imported Xlib functions --
-----------------------------
function GLX_Create_Context (Display : in Display_Pointer;
Visual : in X_Visual_Info_Pointer;
Share_List : in GLX_Context;
Direct : in Character)
return GLX_Context
with Import => True, Convention => StdCall,
External_Name => "glXCreateContext";
function GLX_Make_Current (Display : in Display_Pointer;
Drawable : in Window_ID;
Context : in GLX_Context)
return Character
with Import => True, Convention => StdCall,
External_Name => "glXMakeCurrent";
function GLX_Make_Context_Current (Display : in Display_Pointer;
Draw : in Window_ID;
Read : in Window_ID;
Context : in GLX_Context)
return Character
with Import => True, Convention => StdCall,
External_Name => "glXMakeContextCurrent";
function X_Intern_Atom (Display : in Display_Pointer;
Name : in System.Address;
Only_If_Exists : in Natural)
return Atom
with Import => True, Convention => StdCall, External_Name => "XInternAtom";
procedure X_Set_Class_Hint (Display : in Display_Pointer;
Window : in Window_ID;
Hint : in X_Class_Hint)
with Import => True, Convention => StdCall,
External_Name => "XSetClassHint";
procedure X_Set_Icon_Name (Display : in Display_Pointer;
Window : in Window_ID;
Name : in System.Address)
with Import => True, Convention => StdCall,
External_Name => "XSetIconName";
procedure X_Set_WM_Icon_Name (Display : in Display_Pointer;
Window : in Window_ID;
Text_Prop : in System.Address)
with Import => True, Convention => StdCall,
External_Name => "XSetWMIconName";
procedure X_Set_WM_Name (Display : in Display_Pointer;
Window : in Window_ID;
Text_Prop : in System.Address)
with Import => True, Convention => StdCall,
External_Name => "XSetWMName";
function GLX_Choose_Visual (Display : in Display_Pointer;
Screen : in Screen_Number;
Attribute_List : in GLX_Attribute_List_Ptr)
return X_Visual_Info_Pointer
with Import => True, Convention => StdCall,
External_Name => "glXChooseVisual";
function GLX_Choose_FB_Config (Display : in Display_Pointer;
Screen : in Screen_Number;
Attribute_List : in GLX_Attribute_List_Ptr;
Num_Found : in Int_Ptr)
return FB_Config_Ptr
with Import => True, Convention => StdCall,
External_Name => "glXChooseFBConfig";
function GLX_Get_Visual_From_FB_Config (Display : in Display_Pointer;
Config : in System.Address)
return X_Visual_Info_Pointer
with Import => True, Convention => StdCall,
External_Name => "glXGetVisualFromFBConfig";
procedure X_Next_Event (Display : in Display_Pointer;
Event : in System.Address)
with Import => True, Convention => StdCall, External_Name => "XNextEvent";
procedure GLX_Destroy_Context (Display : in Display_Pointer;
Context : in GLX_Context)
with Import => True, Convention => StdCall,
External_Name => "glXDestroyContext";
function X_Create_Colormap (Display : in Display_Pointer;
Window : in Window_ID;
Visual : in System.Address;
Alloc : in Alloc_Mode)
return Colormap_ID
with Import => True, Convention => StdCall,
External_Name => "XCreateColormap";
function X_Create_Window (Display : in Display_Pointer;
Parent : in Window_ID;
X : in Position;
Y : in Position;
Width : in Dimension;
Height : in Dimension;
Border_Width : in Natural;
Depth : in Screen_Depth;
Class : in Window_Class;
Visual : in System.Address;
Valuemask : in X_Window_Attributes_Mask;
Attributes : in System.Address)
return Window_ID
with Import => True, Convention => StdCall,
External_Name => "XCreateWindow";
function X_Default_Screen (Display : in Display_Pointer)
return Screen_Number
with Import => True, Convention => StdCall,
External_Name => "XDefaultScreen";
procedure X_Map_Window (Display : in Display_Pointer;
Window : in Window_ID)
with Import => True, Convention => StdCall,
External_Name => "XMapWindow";
function X_Open_Display
(Display_Name : in System.Address := System.Null_Address)
return Display_Pointer
with Import => True, Convention => StdCall,
External_Name => "XOpenDisplay";
function X_Root_Window (Display : in Display_Pointer;
Screen_Num : in Screen_Number)
return Window_ID
with Import => True, Convention => StdCall, External_Name => "XRootWindow";
procedure X_Set_WM_Protocols (Display : in Display_Pointer;
Window : in Window_ID;
Protocols : in System.Address;
Count : in Integer)
with Import => True, Convention => StdCall,
External_Name => "XSetWMProtocols";
function X_Lookup_String (Event : in System.Address;
Buffer : in System.Address;
Limit : in Natural;
Keysym : in System.Address;
Compose : in System.Address)
return Natural
with Import => True, Convention => StdCall,
External_Name => "XLookupString";
function X_Pending (Display : in Display_Pointer)
return Natural
with Import => True, Convention => StdCall, External_Name => "XPending";
procedure X_Resize_Window (Display : in Display_Pointer;
Window : in Window_ID;
Width : in Positive;
Height : in Positive)
with Import => True, Convention => StdCall,
External_Name => "XResizeWindow";
procedure X_Warp_Pointer (Display : in Display_Pointer;
Source_W : in Window_ID;
Dest_W : in Window_ID;
Source_X : in Integer;
Source_Y : in Integer;
Source_Width : in Natural;
Source_Height : in Natural;
Dest_X : in Integer;
Dest_Y : in Integer)
with Import => True, Convention => StdCall,
External_Name => "XWarpPointer";
procedure X_Move_Window (Display : in Display_Pointer;
Window : in Window_ID;
X : in Natural;
Y : in Natural)
with Import => True, Convention => StdCall,
External_Name => "XMoveWindow";
procedure X_Query_Pointer (Display : in Display_Pointer;
Window : in Window_ID;
Root : in System.Address;
Child : in System.Address;
Root_X : in System.Address;
Root_Y : in System.Address;
Win_X : in System.Address;
Win_Y : in System.Address;
Mask : in System.Address)
with Import => True, Convention => StdCall,
External_Name => "XQueryPointer";
procedure X_Raise_Window (Display : in Display_Pointer;
Window : in Window_ID)
with Import => True, Convention => StdCall,
External_Name => "XRaiseWindow";
procedure X_Lower_Window (Display : in Display_Pointer;
Window : in Window_ID)
with Import => True, Convention => StdCall,
External_Name => "XLowerWindow";
---------------------------------------------------------------------------
end X11;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
private with Ada.Calendar;
package PortScan.Scan is
missing_index : exception;
bad_index_data : exception;
bsheet_parsing : exception;
populate_error : exception;
-- Scan the entire conspiracy and unkindness directories in order with a single,
-- non-recursive pass using up to 32 parallel scanners. Return True on success
function scan_entire_ports_tree (sysrootver : sysroot_characteristics) return Boolean;
-- Scan entire conspiracy and unkindness directories using parallel scanners in order
-- to compile a complete unique set of distribution files. Used for distfile purging.
-- Return True on success.
function gather_distfile_set (sysrootver : sysroot_characteristics) return Boolean;
-- Starting with a single port, recurse to determine a limited but complete
-- dependency tree. Repeated calls will augment already existing data.
-- Return True on success
function scan_single_port
(namebase : String;
variant : String;
always_build : Boolean;
sysrootver : sysroot_characteristics;
fatal : out Boolean) return Boolean;
-- This procedure causes the reverse dependencies to be calculated, and
-- then the extended (recursive) reverse dependencies. The former is
-- used progressively to determine when a port is free to build and the
-- latter sets the build priority.
procedure set_build_priority;
-- Iterate through portlist and scan each individual port recursively.
-- May be interrupted with a a singal. Returns False if any port fails scan or if
-- the process was interrupted by a signal.
function scan_provided_list_of_ports
(always_build : Boolean;
sysrootver : sysroot_characteristics) return Boolean;
-- Linearly scan through entire conspiracy directory and generate a new index
procedure generate_conspiracy_index (sysrootver : sysroot_characteristics);
-- Using parallel scanners, go through entire source directory and generate
-- all possible buildsheets. Stop on first error.
procedure generate_all_buildsheets (ravensource : String);
-- List every port to be built and the final tally.
procedure display_results_of_dry_run;
-- Scan distfiles directory, then purge all obsolete distfiles.
procedure purge_obsolete_distfiles;
-- Scan directory that contains the packages (*.tzst) and stores the
-- file names in the container. Returns False if no packages are found.
function scan_repository (repository : String) return Boolean;
-- Scans conspiracy + unkindness and generates a website at the given directory
-- Generate a web page for every single active port
-- Obsolete web pages are not removed, but no links will reference them
function generate_entire_website
(www_site : String;
sysrootver : sysroot_characteristics) return Boolean;
-- Regenerate buildsheets for unkindness as necessary, and return True if index needs
-- to be regenerated
function unkindness_index_required return Boolean;
-- Linearly scan through generated unkindness directory and generate a new index
-- Returns false if exception hit
function generate_unkindness_index (sysrootver : sysroot_characteristics) return Boolean;
-- Walk through log directory and gather list of existing build logs
procedure gather_list_of_build_logs;
-- Calculate all possible build log names and remove from the actual list
-- of build logs if found. Use either conspiracy_variants or unkindness_variants
-- based on value of main_tree boolean.
procedure eliminate_current_logs (main_tree : Boolean);
-- Removes the logs represented by the contents of log_list container
procedure remove_obsolete_logs;
private
package CAL renames Ada.Calendar;
type dependency_type is (build, buildrun, runtime, extra_runtime);
subtype LR_set is dependency_type range buildrun .. extra_runtime;
type verdiff is (newbuild, rebuild, change);
subtype AF is Integer range 0 .. 15;
type disktype is mod 2**64;
conspindex : constant String := "/Mk/Misc/conspiracy_variants";
port_dates : constant String := "/Mk/Misc/port_dates";
unkinindex : constant String := "/unkindness_variants";
type port_dates_record is
record
creation : CAL.Time;
lastmod : CAL.Time;
end record;
package dates_crate is new CON.Hashed_Maps
(Key_Type => HT.Text,
Element_Type => port_dates_record,
Hash => port_hash,
Equivalent_Keys => HT.equivalent);
type catalog_record is
record
lastmod64 : disktype;
origin : HT.Text;
end record;
function "<" (L, R : catalog_record) return Boolean;
package catalog_crate is new CON.Ordered_Sets
(Element_Type => catalog_record);
-- subroutines for populate_port_data
procedure prescan_ports_tree
(conspiracy : String;
unkindness : String;
sysrootver : sysroot_characteristics);
procedure prescan_conspiracy_index_for_distfiles
(conspiracy : String;
unkindness : String;
sysrootver : sysroot_characteristics);
procedure prescan_unkindness
(unkindness : String;
compiled_BS : String);
procedure populate_port_data
(conspiracy : String;
compiled_BS : String;
target : port_index;
always_build : Boolean;
sysrootver : sysroot_characteristics);
procedure parallel_deep_scan
(conspiracy : String;
compiled_BS : String;
sysrootver : sysroot_characteristics;
success : out Boolean;
show_progress : Boolean);
procedure populate_set_depends
(target : port_index;
tuple : String;
dtype : dependency_type);
procedure populate_option
(target : port_index;
option_name : String;
setting : Boolean);
procedure skeleton_compiler_data
(conspiracy : String;
compiled_BS : String;
target : port_index;
sysrootver : sysroot_characteristics);
procedure iterate_reverse_deps;
procedure iterate_drill_down;
procedure drill_down (next_target : port_index; circular_flag : in out Boolean);
-- some helper routines
function get_max_lots return scanners;
function convert_tuple_to_portkey (tuple : String) return String;
function extract_subpackage (tuple : String) return String;
function tohex (value : AF) return Character;
function display_kmg (number : disktype) return String;
-- Given a port ID, search for existing package in the packages directory
-- If the exact package exists, return " (rebuild <version>)"
-- If no package exists, return " (new)"
-- If previous package exists, return " (<oldversion> => <version>)"
function version_difference (id : port_id; kind : out verdiff) return String;
-- Don't bother with parallel scan on unkindness, just get the distfiles now.
procedure linear_scan_unkindness_for_distfiles (compiled_BS : String);
-- Split conspiracy up equally between available scanners looking for distfiles
procedure parallel_distfile_scan
(conspiracy : String;
sysrootver : sysroot_characteristics;
success : out Boolean;
show_progress : Boolean);
-- Set the portlist as if the user provided a list of every port via command line
procedure set_portlist_to_everything;
-- create a block of upstream ports. Each line is semi-colon delimited.
-- The first field is namebase-variant
-- The second field is the relative link
-- The third field is the tagline
function blocked_text_block (port : port_index) return String;
-- create an index block of all ravenports, sorted by last-modified order
function catalog_row_block
(crate : dates_crate.Map;
catcrate : catalog_crate.Set) return String;
-- Loop to generate all webpages (includes custom ports)
procedure serially_generate_web_pages
(www_site : String;
sysrootver : sysroot_characteristics;
success : out Boolean);
-- Single web page generator (called by parent loop)
-- Returns true if web page generation was successful
function generate_single_page
(port : port_index;
workzone : String;
www_site : String;
conspiracy : String;
unkindness : String;
cdatetime : CAL.Time;
mdatetime : CAL.Time;
sysrootver : sysroot_characteristics)
return Boolean;
-- Generates searchable catalog index
-- Returns true if web page generation was successful
function generate_catalog_index
(www_site : String;
crate : dates_crate.Map;
catcrate : catalog_crate.Set) return Boolean;
-- Extract dependencies, store them
-- Web site generation requires two complete passes
procedure store_port_dependencies
(port : port_index;
conspiracy : String;
unkindness : String;
sysrootver : sysroot_characteristics);
-- Slurp creation and last-modification timestamp of each port
procedure scan_port_dates
(conspiracy : String;
crate : in out dates_crate.Map;
catcrate : in out catalog_crate.Set);
-- Slurp last-modification timestamps of each buildsheet in unkindness
procedure scan_unkindness_buildsheets
(comp_unkind : String;
crate : in out dates_crate.Map);
-- Generate missing or obsolete buildsheets and remove from crate's checklist crate
-- Returns true if index needs to be regenerated
function generate_buildsheets
(comp_unkind : String;
crate : in out dates_crate.Map) return Boolean;
-- Returns true if unkindness source files are newer than existing buildsheet
function unkindness_source_newer
(BS_modtime : Ada.Calendar.Time;
bucket_name : String) return Boolean;
-- Given the directory of the unkindness port files, generate a buildsheet at the
-- given filename. However, if BROKEN[ALL] is set, don't generate and return True;
function generate_unkindness_buildsheet
(unkindness_srcdir : String;
new_buildsheet : String) return Boolean;
end PortScan.Scan;
|
with Ada.Real_Time; use Ada.Real_Time;
-- with STM32.RCC;
with STM_Board; use STM_Board;
procedure Test_LED_RT is
-- This demonstration program only initializes the GPIOs and flash a LED
-- with Ada.Real_Time. There is no initialization for PWM, ADC and timer.
begin
-- STM32.RCC.PWR_Overdrive_Enable;
-- Initialize GPIO ports
Initialize_GPIO;
-- Enter steady state
loop
Set_Toggle (Yellow_LED);
delay until Clock + Milliseconds (100); -- arbitrary
end loop;
end Test_LED_RT;
|
-- ////////////////////////////////////////////////////////////
-- //
-- // SFML - Simple and Fast Multimedia Library
-- // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
-- //
-- // This software is provided 'as-is', without any express or implied
-- // warranty.
-- // In no event will the authors be held liable for any damages arising from
-- // the use of this software.
-- //
-- // Permission is granted to anyone to use this software for any purpose,
-- // including commercial applications, and to alter it and redistribute it
-- // freely,
-- // subject to the following restrictions:
-- //
-- // 1. The origin of this software must not be misrepresented;
-- // you must not claim that you wrote the original software.
-- // If you use this software in a product, an acknowledgment
-- // in the product documentation would be appreciated but is not required.
-- //
-- // 2. Altered source versions must be plainly marked as such,
-- // and must not be misrepresented as being the original software.
-- //
-- // 3. This notice may not be removed or altered from any source
-- // distribution.
-- //
-- ////////////////////////////////////////////////////////////
-- ////////////////////////////////////////////////////////////
-- // Headers
-- ////////////////////////////////////////////////////////////
with Sf.Config;
with Sf.Audio.SoundStatus;
with Sf.Audio.Types;
package Sf.Audio.Music is
use Sf.Config;
use Sf.Audio.SoundStatus;
use Sf.Audio.Types;
-- ////////////////////////////////////////////////////////////
-- /// Create a new music and load it from a file
-- ///
-- /// \param Filename : Path of the music file to open
-- ///
-- /// \return A new sfMusic object (NULL if failed)
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_CreateFromFile (Filename : String) return sfMusic_Ptr;
-- ////////////////////////////////////////////////////////////
-- /// Create a new music and load it from a file in memory
-- ///
-- /// \param Data : Pointer to the file data in memory
-- /// \param SizeInBytes : Size of the data to load, in bytes
-- ///
-- /// \return A new sfMusic object (NULL if failed)
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_CreateFromMemory (Data : sfInt8_Ptr; SizeInBytes : sfSize_t) return sfMusic_Ptr;
-- ////////////////////////////////////////////////////////////
-- /// Destroy an existing music
-- ///
-- /// \param Music : Music to delete
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_Destroy (Music : sfMusic_Ptr);
-- ////////////////////////////////////////////////////////////
-- /// Set a music loop state
-- ///
-- /// \param Music : Music to set the loop state
-- /// \param Loop : sfTrue to play in loop, sfFalse to play once
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_SetLoop (Music : sfMusic_Ptr; Enable : sfBool);
-- ////////////////////////////////////////////////////////////
-- /// Tell whether or not a music is looping
-- ///
-- /// \param Music : Music to get the loop state from
-- ///
-- /// \return sfTrue if the music is looping, sfFalse otherwise
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_GetLoop (Music : sfMusic_Ptr) return sfBool;
-- ////////////////////////////////////////////////////////////
-- /// Get a music duration
-- ///
-- /// \param Music : Music to get the duration from
-- ///
-- /// \return Music duration, in seconds
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_GetDuration (Music : sfMusic_Ptr) return Float;
-- ////////////////////////////////////////////////////////////
-- /// Start playing a music
-- ///
-- /// \param Music : Music to play
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_Play (Music : sfMusic_Ptr);
-- ////////////////////////////////////////////////////////////
-- /// Pause a music
-- ///
-- /// \param Music : Music to pause
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_Pause (Music : sfMusic_Ptr);
-- ////////////////////////////////////////////////////////////
-- /// Stop playing a music
-- ///
-- /// \param Music : Music to stop
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_Stop (Music : sfMusic_Ptr);
-- ////////////////////////////////////////////////////////////
-- /// Return the number of channels of a music (1 = mono, 2 = stereo)
-- ///
-- /// \param Music : Music to get the channels count from
-- ///
-- /// \return Number of channels
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_GetChannelsCount (Music : sfMusic_Ptr) return sfUint32;
-- ////////////////////////////////////////////////////////////
-- /// Get the stream sample rate of a music
-- ///
-- /// \param Music : Music to get the sample rate from
-- ///
-- /// \return Stream frequency (number of samples per second)
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_GetSampleRate (Music : sfMusic_Ptr) return sfUint32;
-- ////////////////////////////////////////////////////////////
-- /// Get the status of a music (stopped, paused, playing)
-- ///
-- /// \param Music : Music to get the status from
-- ///
-- /// \return Current status of the sound
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_GetStatus (Music : sfMusic_Ptr) return sfSoundStatus;
-- ////////////////////////////////////////////////////////////
-- /// Get the current playing position of a music
-- ///
-- /// \param Music : Music to get the position from
-- ///
-- /// \return Current playing position, expressed in seconds
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_GetPlayingOffset (Music : sfMusic_Ptr) return Float;
-- ////////////////////////////////////////////////////////////
-- /// Set the pitch of a music
-- ///
-- /// \param Music : Music to modify
-- /// \param Pitch : New pitch
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_SetPitch (Music : sfMusic_Ptr; Pitch : Float);
-- ////////////////////////////////////////////////////////////
-- /// Set the volume of a music
-- ///
-- /// \param Music : Music to modify
-- /// \param Volume : Volume (in range [0, 100])
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_SetVolume (Music : sfMusic_Ptr; Volume : Float);
-- ////////////////////////////////////////////////////////////
-- /// Set the position of a music
-- ///
-- /// \param Music : Music to modify
-- /// \param X : X position of the sound in the world
-- /// \param Y : Y position of the sound in the world
-- /// \param Z : Z position of the sound in the world
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_SetPosition (Music : sfMusic_Ptr; X, Y, Z : Float);
-- ////////////////////////////////////////////////////////////
-- /// Make the music's position relative to the listener's
-- /// position, or absolute.
-- /// The default value is false (absolute)
-- ///
-- /// \param Music : Music to modify
-- /// \param Relative : True to set the position relative, false to set it absolute
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_SetRelativeToListener (Music : sfMusic_Ptr; Relative : sfBool);
-- ////////////////////////////////////////////////////////////
-- /// Set the minimum distance - closer than this distance,
-- /// the listener will hear the music at its maximum volume.
-- /// The default minimum distance is 1.0
-- ///
-- /// \param Music : Music to modify
-- /// \param MinDistance : New minimum distance for the music
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_SetMinDistance (Music : sfMusic_Ptr; MinDistance : Float);
-- ////////////////////////////////////////////////////////////
-- /// Set the attenuation factor - the higher the attenuation, the
-- /// more the sound will be attenuated with distance from listener.
-- /// The default attenuation factor 1.0
-- ///
-- /// \param Sound : Sound to modify
-- /// \param Attenuation : New attenuation factor for the sound
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_SetAttenuation (Music : sfMusic_Ptr; Attenuation : Float);
-- ////////////////////////////////////////////////////////////
-- /// Get the pitch of a music
-- ///
-- /// \param Music : Music to get the pitch from
-- ///
-- /// \return Pitch value
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_GetPitch (Music : sfMusic_Ptr) return Float;
-- ////////////////////////////////////////////////////////////
-- /// Get the volume of a music
-- ///
-- /// \param Music : Music to get the volume from
-- ///
-- /// \return Volume value (in range [1, 100])
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_GetVolume (Music : sfMusic_Ptr) return Float;
-- ////////////////////////////////////////////////////////////
-- /// Get the position of a music
-- ///
-- /// \param Music : Music to get the position from
-- /// \param X : X position of the sound in the world
-- /// \param Y : Y position of the sound in the world
-- /// \param Z : Z position of the sound in the world
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfMusic_GetPosition (Music : sfMusic_Ptr; X, Y, Z : access Float);
-- ////////////////////////////////////////////////////////////
-- /// Tell if the music's position is relative to the listener's
-- /// position, or if it's absolute
-- ///
-- /// \param Music : Music to check
-- ///
-- /// \return sfTrue if the position is relative, sfFalse if it's absolute
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_IsRelativeToListener (Music : sfMusic_Ptr) return sfBool;
-- ////////////////////////////////////////////////////////////
-- /// Get the minimum distance of a music
-- ///
-- /// \param Music : Music to get the minimum distance from
-- ///
-- /// \return Minimum distance for the music
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_GetMinDistance (Music : sfMusic_Ptr) return Float;
-- ////////////////////////////////////////////////////////////
-- /// Get the attenuation factor of a music
-- ///
-- /// \param Music : Music to get the attenuation factor from
-- ///
-- /// \return Attenuation factor for the a music
-- ///
-- ////////////////////////////////////////////////////////////
function sfMusic_GetAttenuation (Music : sfMusic_Ptr) return Float;
private
pragma Import (C, sfMusic_CreateFromMemory, "sfMusic_CreateFromMemory");
pragma Import (C, sfMusic_Destroy, "sfMusic_Destroy");
pragma Import (C, sfMusic_SetLoop, "sfMusic_SetLoop");
pragma Import (C, sfMusic_GetLoop, "sfMusic_GetLoop");
pragma Import (C, sfMusic_GetDuration, "sfMusic_GetDuration");
pragma Import (C, sfMusic_Play, "sfMusic_Play");
pragma Import (C, sfMusic_Pause, "sfMusic_Pause");
pragma Import (C, sfMusic_Stop, "sfMusic_Stop");
pragma Import (C, sfMusic_GetChannelsCount, "sfMusic_GetChannelsCount");
pragma Import (C, sfMusic_GetSampleRate, "sfMusic_GetSampleRate");
pragma Import (C, sfMusic_GetStatus, "sfMusic_GetStatus");
pragma Import (C, sfMusic_GetPlayingOffset, "sfMusic_GetPlayingOffset");
pragma Import (C, sfMusic_SetPitch, "sfMusic_SetPitch");
pragma Import (C, sfMusic_SetVolume, "sfMusic_SetVolume");
pragma Import (C, sfMusic_SetPosition, "sfMusic_SetPosition");
pragma Import (C, sfMusic_SetRelativeToListener, "sfMusic_SetRelativeToListener");
pragma Import (C, sfMusic_SetMinDistance, "sfMusic_SetMinDistance");
pragma Import (C, sfMusic_SetAttenuation, "sfMusic_SetAttenuation");
pragma Import (C, sfMusic_GetPitch, "sfMusic_GetPitch");
pragma Import (C, sfMusic_GetVolume, "sfMusic_GetVolume");
pragma Import (C, sfMusic_GetPosition, "sfMusic_GetPosition");
pragma Import (C, sfMusic_IsRelativeToListener, "sfMusic_IsRelativeToListener");
pragma Import (C, sfMusic_GetMinDistance, "sfMusic_GetMinDistance");
pragma Import (C, sfMusic_GetAttenuation, "sfMusic_GetAttenuation");
end Sf.Audio.Music;
|
with Ada.Containers; use Ada.Containers;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with AUnit.Assertions; use AUnit.Assertions;
with Langkit_Support.Text; use Langkit_Support.Text;
with Libadalang.Analysis; use Libadalang.Analysis;
with Libadalang.Common; use Libadalang.Common;
with Missing.AUnit.Assertions; use Missing.AUnit.Assertions;
with Rejuvenation; use Rejuvenation;
with Rejuvenation.Match_Patterns; use Rejuvenation.Match_Patterns;
with Rejuvenation.Patterns; use Rejuvenation.Patterns;
with Rejuvenation.Simple_Factory; use Rejuvenation.Simple_Factory;
with Rejuvenation.Utils; use Rejuvenation.Utils;
with String_Vectors; use String_Vectors;
with Make_Ada; use Make_Ada;
package body Test_Match_Patterns_Placeholders is
procedure Assert is new Generic_Assert (Count_Type);
procedure Assert is new Generic_Assert (Ada_Node_Kind_Type);
procedure Test_Placeholder_Slice (T : in out Test_Case'Class);
procedure Test_Placeholder_Slice (T : in out Test_Case'Class) is
pragma Unreferenced (T);
VarName : constant String := "My_Var";
Instance : constant Analysis_Unit :=
Analyze_Fragment (VarName, Expr_Rule);
procedure TestCase_Single (InsertKey, RetrieveKey : String);
procedure TestCase_Single (InsertKey, RetrieveKey : String) is
Pattern : constant Analysis_Unit :=
Analyze_Fragment (InsertKey, Expr_Rule);
MP : Match_Pattern;
Actual : constant Boolean :=
Match_Full (MP, Pattern.Root, Instance.Root);
begin
Assert (Condition => Actual, Message => "Match expected");
Assert
(Actual => MP.Get_Single_As_Raw_Signature (RetrieveKey),
Expected => VarName, Message => "Value of Placeholder differ");
end TestCase_Single;
Key : constant String := "$S_Var";
Twice : constant String := 2 * Key;
KeySlice1 : constant String :=
Twice (Twice'First .. Twice'First + Key'Length - 1);
KeySlice2 : constant String :=
Twice (Twice'First + Key'Length .. Twice'Last);
begin
Assert
(Condition => KeySlice1 = KeySlice2,
Message => "KeySlices unexpectedly differ");
Assert
(Condition => KeySlice1'First /= KeySlice2'First,
Message =>
"First index of Keyslices unexpectedly does not differ " &
KeySlice2'First'Image);
TestCase_Single (KeySlice1, KeySlice2);
TestCase_Single (KeySlice2, KeySlice1);
end Test_Placeholder_Slice;
procedure Test_Match_Single_Kind (T : in out Test_Case'Class);
procedure Test_Match_Single_Kind (T : in out Test_Case'Class) is
pragma Unreferenced (T);
procedure Test_Match_Single_Kind (Prefix : Vector);
procedure Test_Match_Single_Kind (Prefix : Vector) is
Placeholder_Name : constant String := "$S_Name";
Pattern_Str : constant String :=
Make_Object_Declaration_Subtype_Indication
(Defining_Identifier_List => Prefix & Placeholder_Name);
Pattern : constant Analysis_Unit :=
Analyze_Fragment (Pattern_Str, Basic_Decl_Rule);
Instance_Str : constant String :=
Make_Object_Declaration_Subtype_Indication
(Defining_Identifier_List => Prefix & "X");
Instance : constant Analysis_Unit :=
Analyze_Fragment (Instance_Str, Basic_Decl_Rule);
MP : Match_Pattern;
Actual : constant Boolean :=
Match_Full (MP, Pattern.Root, Instance.Root);
begin
Assert
(Condition => Actual, Message => "Instance doesn't match pattern.");
declare
Nodes : constant Node_List.Vector :=
MP.Get_Placeholder_As_Nodes (Placeholder_Name);
begin
Assert
(Actual => Nodes.Length, Expected => 1,
Message => "Nodes Length differ.");
for Node of Nodes loop
Assert
(Actual => Node.Kind, Expected => Ada_Defining_Name,
Message => "Node kind differ for " & Raw_Signature (Node));
end loop;
end;
end Test_Match_Single_Kind;
begin
Test_Match_Single_Kind (Empty_Vector);
Test_Match_Single_Kind (To_Vector ("Prefix", 1));
end Test_Match_Single_Kind;
procedure Test_Match_Multiple_Kind (T : in out Test_Case'Class);
procedure Test_Match_Multiple_Kind (T : in out Test_Case'Class) is
pragma Unreferenced (T);
procedure Test_Match_Multiple_Kind (Prefix : Vector);
procedure Test_Match_Multiple_Kind (Prefix : Vector) is
Placeholder_Name : constant String := "$M_Name";
Pattern_Str : constant String :=
Make_Object_Declaration_Subtype_Indication
(Defining_Identifier_List => Prefix & Placeholder_Name);
Pattern : constant Analysis_Unit :=
Analyze_Fragment (Pattern_Str, Basic_Decl_Rule);
type VectorArray is array (Natural range <>) of Vector;
All_Defining_Name_Lists : constant VectorArray :=
(Empty_Vector, To_Vector ("X", 1), "A" & "B",
To_Vector ("a", 1) & "b" & "c" & "d" & "e" & "f");
Defining_Name_Lists : constant VectorArray :=
All_Defining_Name_Lists
(All_Defining_Name_Lists'First +
(if Prefix.Is_Empty then 1 else 0) ..
All_Defining_Name_Lists'Last);
begin
for Defining_Name_List of Defining_Name_Lists loop
declare
Instance_Str : constant String :=
Make_Object_Declaration_Subtype_Indication
(Defining_Identifier_List => Prefix & Defining_Name_List);
Instance : constant Analysis_Unit :=
Analyze_Fragment (Instance_Str, Basic_Decl_Rule);
MP : Match_Pattern;
Actual : constant Boolean :=
Match_Full (MP, Pattern.Root, Instance.Root);
begin
Assert
(Condition => Actual,
Message => "Instance doesn't match pattern.");
declare
Nodes : constant Node_List.Vector :=
MP.Get_Placeholder_As_Nodes (Placeholder_Name);
begin
Assert
(Actual => Nodes.Length,
Expected => Defining_Name_List.Length,
Message => "Nodes Length differ");
for Node of Nodes loop
Assert
(Actual => Node.Kind, Expected => Ada_Defining_Name,
Message =>
"Node kind differ for " & Raw_Signature (Node));
end loop;
end;
end;
end loop;
end Test_Match_Multiple_Kind;
begin
Test_Match_Multiple_Kind (Empty_Vector);
Test_Match_Multiple_Kind (To_Vector ("Prefix", 1));
end Test_Match_Multiple_Kind;
procedure Test_Placeholder_In_CaseStmtAlternativeList
(T : in out Test_Case'Class);
procedure Test_Placeholder_In_CaseStmtAlternativeList
(T : in out Test_Case'Class)
is
pragma Unreferenced (T);
Find_Pattern : constant Pattern :=
Make_Pattern
("case $S_Expr is " & "when '*'| $M_Values => $M_Stmts_True;" &
"when others => $M_Stmts_False;" & "end case;",
Case_Stmt_Rule);
Unit : constant Analysis_Unit :=
Analyze_Fragment
("case c is " & "when '*' | '?' | '+' => in_call;" &
"when others => out_call;" & "end case;",
Case_Stmt_Rule);
Expected : constant String := "'?' | '+'";
MP : Match_Pattern;
Actual : constant Boolean :=
Match_Full (MP, Find_Pattern.As_Ada_Node, Unit.Root);
begin
Assert
(Condition => Actual,
Message =>
"Instance doesn't match pattern unexpectedly." & ASCII.CR &
ASCII.LF & "Instance = " & Image (Unit.Text) & ASCII.CR & ASCII.LF &
"Pattern = " & Find_Pattern.Get_String & ASCII.CR & ASCII.LF);
Assert
(Expected => Expected,
Actual => MP.Get_Placeholder_As_Raw_Signature ("$M_Values"),
Message => "Placeholder raw signature is not as expected");
end Test_Placeholder_In_CaseStmtAlternativeList;
-- Test plumbing
overriding function Name
(T : Match_Patterns_Placeholders_Test_Case) return AUnit.Message_String
is
pragma Unreferenced (T);
begin
return AUnit.Format ("Match Pattern Placeholders");
end Name;
overriding procedure Register_Tests
(T : in out Match_Patterns_Placeholders_Test_Case)
is
begin
Registration.Register_Routine
(T, Test_Placeholder_Slice'Access, "Placeholder slice");
Registration.Register_Routine
(T, Test_Match_Single_Kind'Access, "Match Single kind");
Registration.Register_Routine
(T, Test_Match_Multiple_Kind'Access, "Match Multiple kind");
Registration.Register_Routine
(T, Test_Placeholder_In_CaseStmtAlternativeList'Access,
"Placeholder Case Stmt Alternative List");
end Register_Tests;
end Test_Match_Patterns_Placeholders;
|
with Ada.Text_IO;
use Ada.Text_IO;
procedure Luhn is
function Luhn_Test (Number: String) return Boolean is
Sum : Natural := 0;
Odd : Boolean := True;
Digit: Natural range 0 .. 9;
begin
for p in reverse Number'Range loop
Digit := Integer'Value (Number (p..p));
if Odd then
Sum := Sum + Digit;
else
Sum := Sum + (Digit*2 mod 10) + (Digit / 5);
end if;
Odd := not Odd;
end loop;
return (Sum mod 10) = 0;
end Luhn_Test;
begin
Put_Line (Boolean'Image (Luhn_Test ("49927398716")));
Put_Line (Boolean'Image (Luhn_Test ("49927398717")));
Put_Line (Boolean'Image (Luhn_Test ("1234567812345678")));
Put_Line (Boolean'Image (Luhn_Test ("1234567812345670")));
end Luhn;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2019, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with HAL;
with System;
package SAM.DMAC is
type Descriptor_Section;
type Descriptor_Section_Access is access all Descriptor_Section;
-- See definition below
procedure Enable (Descriptors : not null Descriptor_Section_Access;
Write_Back : not null Descriptor_Section_Access);
procedure Disable;
type Channel_Id is range 0 .. 31;
type Priority_Level is range 0 .. 3;
-- Priority level used for the DMA channel, where a high level has priority
-- over a low level.
type Trigger_Source is new HAL.UInt7;
-- See child package SAM.DMAC.Sources
type Trigger_Action is (Block, Burst, Transaction);
-- Trigger action used for a transfer
type FIFO_Threshold_Kind is (BEAT_1, BEAT_2, BEAT_4, BEAT_8);
-- Threshold from which the DMA starts to write to the destination. These
-- bits have no effect in the case of single beat transfers.
type Burst_Length is range 1 .. 16;
-- Channel actions --
procedure Configure (Id : Channel_Id;
Trig_Src : Trigger_Source;
Trig_Action : Trigger_Action;
Priority : Priority_Level;
Burst_Len : Burst_Length;
Threshold : FIFO_Threshold_Kind;
Run_In_Standby : Boolean);
procedure Enable (Id : Channel_Id);
procedure Suspend (Id : Channel_Id);
procedure Resume (Id : Channel_Id);
procedure Software_Trigger (Id : Channel_Id);
-- Channel Status --
function Pending (Id : Channel_Id) return Boolean;
function Busy (Id : Channel_Id) return Boolean;
function Fetch_Error (Id : Channel_Id) return Boolean;
function CRC_Error (Id : Channel_Id) return Boolean;
-- Channel Interrupts --
type Interrupt_Kind is (Suspend, Transfer_Complete, Transfer_Error);
procedure Enable (Id : Channel_Id; Int : Interrupt_Kind);
procedure Disable (Id : Channel_Id; Int : Interrupt_Kind);
procedure Clear (Id : Channel_Id; Int : Interrupt_Kind);
function Set (Id : Channel_Id; Int : Interrupt_Kind) return Boolean;
-- Transfer Descriptor --
type Transfer_Descriptor is private;
-- Transfer_Descriptor is declared private because setting its values is not
-- trivial (address increments in particular). Use Configure_Descriptor ()
-- and Set_Data_Transfer () to write a Transfer_Descriptor;
type Transfer_Descriptor_Access is access all Transfer_Descriptor;
type Event_Output_Kind is
(Disable, -- Event generation disabled
Block, -- Event strobe when block transfer complete
Beat) -- Event strobe when beat transfer complete
with Size => 2;
type Block_Action_Kind is
(No_Action,
-- Channel will be disabled if it is the last block transfer in the
-- transaction.
Interrupt,
-- Channel will be disabled if it is the last block transfer in the
-- transaction and block interrupt.
Suspend,
-- Channel suspend operation is completed
Both
-- Both channel suspend operation and block interrupt
)
with Size => 2;
type Beat_Size_Kind is (B_8bit, B_16bit, B_32bit)
with Size => 2;
type Step_Selection_Kind is (Destination, Source)
with Size => 1;
type Step_Size_Kind is (X1, X2, X4, X8, X16, X32, X64, X128)
with Size => 3;
type Descriptor_Section is array (Channel_Id) of Transfer_Descriptor;
procedure Configure_Descriptor
(Desc : in out Transfer_Descriptor;
Valid : Boolean;
Event_Output : Event_Output_Kind;
Block_Action : Block_Action_Kind;
Beat_Size : Beat_Size_Kind;
Src_Addr_Inc : Boolean;
Dst_Addr_Inc : Boolean;
Step_Selection : Step_Selection_Kind;
Step_Size : Step_Size_Kind;
Next_Descriptor : Transfer_Descriptor_Access := null);
procedure Set_Data_Transfer
(Desc : in out Transfer_Descriptor;
Block_Transfer_Count : HAL.UInt16;
Src_Addr : System.Address;
Dst_Addr : System.Address);
private
pragma Inline (Configure_Descriptor);
pragma Inline (Set_Data_Transfer);
pragma Inline (Enable);
for Trigger_Action use (Block => 0,
Burst => 2,
Transaction => 3);
for FIFO_Threshold_Kind use (BEAT_1 => 0,
BEAT_2 => 2,
BEAT_4 => 3,
BEAT_8 => 4);
for Event_Output_Kind use
(Disable => 0,
Block => 1,
Beat => 3);
for Block_Action_Kind use
(No_Action => 0,
Interrupt => 1,
Suspend => 2,
Both => 3);
for Beat_Size_Kind use
(B_8bit => 0,
B_16bit => 1,
B_32bit => 2);
for Step_Selection_Kind use
(Destination => 0,
Source => 1);
for Step_Size_Kind use
(X1 => 0,
X2 => 1,
X4 => 2,
X8 => 3,
X16 => 4,
X32 => 5,
X64 => 6,
X128 => 7);
type Transfer_Descriptor is record
Valid : Boolean := False;
Event_Output : Event_Output_Kind;
Block_Action : Block_Action_Kind;
Set_To_Zero : HAL.UInt3 := 0;
Beat_Size : Beat_Size_Kind;
Src_Addr_Inc : Boolean;
Dst_Addr_Inc : Boolean;
Step_Selection : Step_Selection_Kind;
Step_Size : Step_Size_Kind;
Block_Transfer_Count : HAL.UInt16;
Src_Addr : System.Address;
Dst_Addr : System.Address;
Next_Descriptor : Transfer_Descriptor_Access := null;
end record
with Volatile, Size => 128, Alignment => 8;
for Transfer_Descriptor use record
Valid at 16#0# range 0 .. 0;
Event_Output at 16#0# range 1 .. 2;
Block_Action at 16#0# range 3 .. 4;
Set_To_Zero at 16#0# range 5 .. 7;
Beat_Size at 16#0# range 8 .. 9;
Src_Addr_Inc at 16#0# range 10 .. 10;
Dst_Addr_Inc at 16#0# range 11 .. 11;
Step_Selection at 16#0# range 12 .. 12;
Step_Size at 16#0# range 13 .. 15;
Block_Transfer_Count at 16#2# range 0 .. 15;
Src_Addr at 16#4# range 0 .. 31;
Dst_Addr at 16#8# range 0 .. 31;
Next_Descriptor at 16#C# range 0 .. 31;
end record;
for Descriptor_Section'Alignment use 128;
for Descriptor_Section'Size use 32 * 128;
end SAM.DMAC;
|
-- Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
--
-- SPDX-License-Identifier: BSD-3-Clause
-- This spec has been automatically generated from rp2040.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package RP_SVD.UART0 is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype UARTDR_DATA_Field is HAL.UInt8;
-- Data Register, UARTDR
type UARTDR_Register is record
-- Receive (read) data character. Transmit (write) data character.
DATA : UARTDR_DATA_Field := 16#0#;
-- Read-only. Framing error. When set to 1, it indicates that the
-- received character did not have a valid stop bit (a valid stop bit is
-- 1). In FIFO mode, this error is associated with the character at the
-- top of the FIFO.
FE : Boolean := False;
-- Read-only. Parity error. When set to 1, it indicates that the parity
-- of the received data character does not match the parity that the EPS
-- and SPS bits in the Line Control Register, UARTLCR_H. In FIFO mode,
-- this error is associated with the character at the top of the FIFO.
PE : Boolean := False;
-- Read-only. Break error. This bit is set to 1 if a break condition was
-- detected, indicating that the received data input was held LOW for
-- longer than a full-word transmission time (defined as start, data,
-- parity and stop bits). In FIFO mode, this error is associated with
-- the character at the top of the FIFO. When a break occurs, only one 0
-- character is loaded into the FIFO. The next character is only enabled
-- after the receive data input goes to a 1 (marking state), and the
-- next valid start bit is received.
BE : Boolean := False;
-- Read-only. Overrun error. This bit is set to 1 if data is received
-- and the receive FIFO is already full. This is cleared to 0 once there
-- is an empty space in the FIFO and a new character can be written to
-- it.
OE : Boolean := False;
-- unspecified
Reserved_12_31 : HAL.UInt20 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTDR_Register use record
DATA at 0 range 0 .. 7;
FE at 0 range 8 .. 8;
PE at 0 range 9 .. 9;
BE at 0 range 10 .. 10;
OE at 0 range 11 .. 11;
Reserved_12_31 at 0 range 12 .. 31;
end record;
-- Receive Status Register/Error Clear Register, UARTRSR/UARTECR
type UARTRSR_Register is record
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. Framing error. When set to 1, it indicates that the
-- received character did not have a valid stop bit (a valid stop bit is
-- 1). This bit is cleared to 0 by a write to UARTECR. In FIFO mode,
-- this error is associated with the character at the top of the FIFO.
FE : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. Parity error. When set to 1, it indicates that the
-- parity of the received data character does not match the parity that
-- the EPS and SPS bits in the Line Control Register, UARTLCR_H. This
-- bit is cleared to 0 by a write to UARTECR. In FIFO mode, this error
-- is associated with the character at the top of the FIFO.
PE : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. Break error. This bit is set to 1 if a break condition
-- was detected, indicating that the received data input was held LOW
-- for longer than a full-word transmission time (defined as start,
-- data, parity, and stop bits). This bit is cleared to 0 after a write
-- to UARTECR. In FIFO mode, this error is associated with the character
-- at the top of the FIFO. When a break occurs, only one 0 character is
-- loaded into the FIFO. The next character is only enabled after the
-- receive data input goes to a 1 (marking state) and the next valid
-- start bit is received.
BE : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. Overrun error. This bit is set to 1 if data is received
-- and the FIFO is already full. This bit is cleared to 0 by a write to
-- UARTECR. The FIFO contents remain valid because no more data is
-- written when the FIFO is full, only the contents of the shift
-- register are overwritten. The CPU must now read the data, to empty
-- the FIFO.
OE : Boolean := False;
-- unspecified
Reserved_4_31 : HAL.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTRSR_Register use record
FE at 0 range 0 .. 0;
PE at 0 range 1 .. 1;
BE at 0 range 2 .. 2;
OE at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-- Flag Register, UARTFR
type UARTFR_Register is record
-- Read-only. Clear to send. This bit is the complement of the UART
-- clear to send, nUARTCTS, modem status input. That is, the bit is 1
-- when nUARTCTS is LOW.
CTS : Boolean;
-- Read-only. Data set ready. This bit is the complement of the UART
-- data set ready, nUARTDSR, modem status input. That is, the bit is 1
-- when nUARTDSR is LOW.
DSR : Boolean;
-- Read-only. Data carrier detect. This bit is the complement of the
-- UART data carrier detect, nUARTDCD, modem status input. That is, the
-- bit is 1 when nUARTDCD is LOW.
DCD : Boolean;
-- Read-only. UART busy. If this bit is set to 1, the UART is busy
-- transmitting data. This bit remains set until the complete byte,
-- including all the stop bits, has been sent from the shift register.
-- This bit is set as soon as the transmit FIFO becomes non-empty,
-- regardless of whether the UART is enabled or not.
BUSY : Boolean;
-- Read-only. Receive FIFO empty. The meaning of this bit depends on the
-- state of the FEN bit in the UARTLCR_H Register. If the FIFO is
-- disabled, this bit is set when the receive holding register is empty.
-- If the FIFO is enabled, the RXFE bit is set when the receive FIFO is
-- empty.
RXFE : Boolean;
-- Read-only. Transmit FIFO full. The meaning of this bit depends on the
-- state of the FEN bit in the UARTLCR_H Register. If the FIFO is
-- disabled, this bit is set when the transmit holding register is full.
-- If the FIFO is enabled, the TXFF bit is set when the transmit FIFO is
-- full.
TXFF : Boolean;
-- Read-only. Receive FIFO full. The meaning of this bit depends on the
-- state of the FEN bit in the UARTLCR_H Register. If the FIFO is
-- disabled, this bit is set when the receive holding register is full.
-- If the FIFO is enabled, the RXFF bit is set when the receive FIFO is
-- full.
RXFF : Boolean;
-- Read-only. Transmit FIFO empty. The meaning of this bit depends on
-- the state of the FEN bit in the Line Control Register, UARTLCR_H. If
-- the FIFO is disabled, this bit is set when the transmit holding
-- register is empty. If the FIFO is enabled, the TXFE bit is set when
-- the transmit FIFO is empty. This bit does not indicate if there is
-- data in the transmit shift register.
TXFE : Boolean;
-- Read-only. Ring indicator. This bit is the complement of the UART
-- ring indicator, nUARTRI, modem status input. That is, the bit is 1
-- when nUARTRI is LOW.
RI : Boolean;
-- unspecified
Reserved_9_31 : HAL.UInt23;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTFR_Register use record
CTS at 0 range 0 .. 0;
DSR at 0 range 1 .. 1;
DCD at 0 range 2 .. 2;
BUSY at 0 range 3 .. 3;
RXFE at 0 range 4 .. 4;
TXFF at 0 range 5 .. 5;
RXFF at 0 range 6 .. 6;
TXFE at 0 range 7 .. 7;
RI at 0 range 8 .. 8;
Reserved_9_31 at 0 range 9 .. 31;
end record;
subtype UARTILPR_ILPDVSR_Field is HAL.UInt8;
-- IrDA Low-Power Counter Register, UARTILPR
type UARTILPR_Register is record
-- 8-bit low-power divisor value. These bits are cleared to 0 at reset.
ILPDVSR : UARTILPR_ILPDVSR_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTILPR_Register use record
ILPDVSR at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype UARTIBRD_BAUD_DIVINT_Field is HAL.UInt16;
-- Integer Baud Rate Register, UARTIBRD
type UARTIBRD_Register is record
-- The integer baud rate divisor. These bits are cleared to 0 on reset.
BAUD_DIVINT : UARTIBRD_BAUD_DIVINT_Field := 16#0#;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTIBRD_Register use record
BAUD_DIVINT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype UARTFBRD_BAUD_DIVFRAC_Field is HAL.UInt6;
-- Fractional Baud Rate Register, UARTFBRD
type UARTFBRD_Register is record
-- The fractional baud rate divisor. These bits are cleared to 0 on
-- reset.
BAUD_DIVFRAC : UARTFBRD_BAUD_DIVFRAC_Field := 16#0#;
-- unspecified
Reserved_6_31 : HAL.UInt26 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTFBRD_Register use record
BAUD_DIVFRAC at 0 range 0 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
subtype UARTLCR_H_WLEN_Field is HAL.UInt2;
-- Line Control Register, UARTLCR_H
type UARTLCR_H_Register is record
-- Send break. If this bit is set to 1, a low-level is continually
-- output on the UARTTXD output, after completing transmission of the
-- current character. For the proper execution of the break command, the
-- software must set this bit for at least two complete frames. For
-- normal use, this bit must be cleared to 0.
BRK : Boolean := False;
-- Parity enable: 0 = parity is disabled and no parity bit added to the
-- data frame 1 = parity checking and generation is enabled.
PEN : Boolean := False;
-- Even parity select. Controls the type of parity the UART uses during
-- transmission and reception: 0 = odd parity. The UART generates or
-- checks for an odd number of 1s in the data and parity bits. 1 = even
-- parity. The UART generates or checks for an even number of 1s in the
-- data and parity bits. This bit has no effect when the PEN bit
-- disables parity checking and generation.
EPS : Boolean := False;
-- Two stop bits select. If this bit is set to 1, two stop bits are
-- transmitted at the end of the frame. The receive logic does not check
-- for two stop bits being received.
STP2 : Boolean := False;
-- Enable FIFOs: 0 = FIFOs are disabled (character mode) that is, the
-- FIFOs become 1-byte-deep holding registers 1 = transmit and receive
-- FIFO buffers are enabled (FIFO mode).
FEN : Boolean := False;
-- Word length. These bits indicate the number of data bits transmitted
-- or received in a frame as follows: b11 = 8 bits b10 = 7 bits b01 = 6
-- bits b00 = 5 bits.
WLEN : UARTLCR_H_WLEN_Field := 16#0#;
-- Stick parity select. 0 = stick parity is disabled 1 = either: * if
-- the EPS bit is 0 then the parity bit is transmitted and checked as a
-- 1 * if the EPS bit is 1 then the parity bit is transmitted and
-- checked as a 0. This bit has no effect when the PEN bit disables
-- parity checking and generation.
SPS : Boolean := False;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTLCR_H_Register use record
BRK at 0 range 0 .. 0;
PEN at 0 range 1 .. 1;
EPS at 0 range 2 .. 2;
STP2 at 0 range 3 .. 3;
FEN at 0 range 4 .. 4;
WLEN at 0 range 5 .. 6;
SPS at 0 range 7 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-- UARTCR_OUT array
type UARTCR_OUT_Field_Array is array (1 .. 2) of Boolean
with Component_Size => 1, Size => 2;
-- Type definition for UARTCR_OUT
type UARTCR_OUT_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- OUT as a value
Val : HAL.UInt2;
when True =>
-- OUT as an array
Arr : UARTCR_OUT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 2;
for UARTCR_OUT_Field use record
Val at 0 range 0 .. 1;
Arr at 0 range 0 .. 1;
end record;
-- Control Register, UARTCR
type UARTCR_Register is record
-- UART enable: 0 = UART is disabled. If the UART is disabled in the
-- middle of transmission or reception, it completes the current
-- character before stopping. 1 = the UART is enabled. Data transmission
-- and reception occurs for either UART signals or SIR signals depending
-- on the setting of the SIREN bit.
UARTEN : Boolean := False;
-- SIR enable: 0 = IrDA SIR ENDEC is disabled. nSIROUT remains LOW (no
-- light pulse generated), and signal transitions on SIRIN have no
-- effect. 1 = IrDA SIR ENDEC is enabled. Data is transmitted and
-- received on nSIROUT and SIRIN. UARTTXD remains HIGH, in the marking
-- state. Signal transitions on UARTRXD or modem status inputs have no
-- effect. This bit has no effect if the UARTEN bit disables the UART.
SIREN : Boolean := False;
-- SIR low-power IrDA mode. This bit selects the IrDA encoding mode. If
-- this bit is cleared to 0, low-level bits are transmitted as an active
-- high pulse with a width of 3 / 16th of the bit period. If this bit is
-- set to 1, low-level bits are transmitted with a pulse width that is 3
-- times the period of the IrLPBaud16 input signal, regardless of the
-- selected bit rate. Setting this bit uses less power, but might reduce
-- transmission distances.
SIRLP : Boolean := False;
-- unspecified
Reserved_3_6 : HAL.UInt4 := 16#0#;
-- Loopback enable. If this bit is set to 1 and the SIREN bit is set to
-- 1 and the SIRTEST bit in the Test Control Register, UARTTCR is set to
-- 1, then the nSIROUT path is inverted, and fed through to the SIRIN
-- path. The SIRTEST bit in the test register must be set to 1 to
-- override the normal half-duplex SIR operation. This must be the
-- requirement for accessing the test registers during normal operation,
-- and SIRTEST must be cleared to 0 when loopback testing is finished.
-- This feature reduces the amount of external coupling required during
-- system test. If this bit is set to 1, and the SIRTEST bit is set to
-- 0, the UARTTXD path is fed through to the UARTRXD path. In either SIR
-- mode or UART mode, when this bit is set, the modem outputs are also
-- fed through to the modem inputs. This bit is cleared to 0 on reset,
-- to disable loopback.
LBE : Boolean := False;
-- Transmit enable. If this bit is set to 1, the transmit section of the
-- UART is enabled. Data transmission occurs for either UART signals, or
-- SIR signals depending on the setting of the SIREN bit. When the UART
-- is disabled in the middle of transmission, it completes the current
-- character before stopping.
TXE : Boolean := True;
-- Receive enable. If this bit is set to 1, the receive section of the
-- UART is enabled. Data reception occurs for either UART signals or SIR
-- signals depending on the setting of the SIREN bit. When the UART is
-- disabled in the middle of reception, it completes the current
-- character before stopping.
RXE : Boolean := True;
-- Data transmit ready. This bit is the complement of the UART data
-- transmit ready, nUARTDTR, modem status output. That is, when the bit
-- is programmed to a 1 then nUARTDTR is LOW.
DTR : Boolean := False;
-- Request to send. This bit is the complement of the UART request to
-- send, nUARTRTS, modem status output. That is, when the bit is
-- programmed to a 1 then nUARTRTS is LOW.
RTS : Boolean := False;
-- This bit is the complement of the UART Out1 (nUARTOut1) modem status
-- output. That is, when the bit is programmed to a 1 the output is 0.
-- For DTE this can be used as Data Carrier Detect (DCD).
OUT_k : UARTCR_OUT_Field := (As_Array => False, Val => 16#0#);
-- RTS hardware flow control enable. If this bit is set to 1, RTS
-- hardware flow control is enabled. Data is only requested when there
-- is space in the receive FIFO for it to be received.
RTSEN : Boolean := False;
-- CTS hardware flow control enable. If this bit is set to 1, CTS
-- hardware flow control is enabled. Data is only transmitted when the
-- nUARTCTS signal is asserted.
CTSEN : Boolean := False;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTCR_Register use record
UARTEN at 0 range 0 .. 0;
SIREN at 0 range 1 .. 1;
SIRLP at 0 range 2 .. 2;
Reserved_3_6 at 0 range 3 .. 6;
LBE at 0 range 7 .. 7;
TXE at 0 range 8 .. 8;
RXE at 0 range 9 .. 9;
DTR at 0 range 10 .. 10;
RTS at 0 range 11 .. 11;
OUT_k at 0 range 12 .. 13;
RTSEN at 0 range 14 .. 14;
CTSEN at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype UARTIFLS_TXIFLSEL_Field is HAL.UInt3;
subtype UARTIFLS_RXIFLSEL_Field is HAL.UInt3;
-- Interrupt FIFO Level Select Register, UARTIFLS
type UARTIFLS_Register is record
-- Transmit interrupt FIFO level select. The trigger points for the
-- transmit interrupt are as follows: b000 = Transmit FIFO becomes <= 1
-- / 8 full b001 = Transmit FIFO becomes <= 1 / 4 full b010 = Transmit
-- FIFO becomes <= 1 / 2 full b011 = Transmit FIFO becomes <= 3 / 4 full
-- b100 = Transmit FIFO becomes <= 7 / 8 full b101-b111 = reserved.
TXIFLSEL : UARTIFLS_TXIFLSEL_Field := 16#2#;
-- Receive interrupt FIFO level select. The trigger points for the
-- receive interrupt are as follows: b000 = Receive FIFO becomes >= 1 /
-- 8 full b001 = Receive FIFO becomes >= 1 / 4 full b010 = Receive FIFO
-- becomes >= 1 / 2 full b011 = Receive FIFO becomes >= 3 / 4 full b100
-- = Receive FIFO becomes >= 7 / 8 full b101-b111 = reserved.
RXIFLSEL : UARTIFLS_RXIFLSEL_Field := 16#2#;
-- unspecified
Reserved_6_31 : HAL.UInt26 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTIFLS_Register use record
TXIFLSEL at 0 range 0 .. 2;
RXIFLSEL at 0 range 3 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
-- Interrupt Mask Set/Clear Register, UARTIMSC
type UARTIMSC_Register is record
-- nUARTRI modem interrupt mask. A read returns the current mask for the
-- UARTRIINTR interrupt. On a write of 1, the mask of the UARTRIINTR
-- interrupt is set. A write of 0 clears the mask.
RIMIM : Boolean := False;
-- nUARTCTS modem interrupt mask. A read returns the current mask for
-- the UARTCTSINTR interrupt. On a write of 1, the mask of the
-- UARTCTSINTR interrupt is set. A write of 0 clears the mask.
CTSMIM : Boolean := False;
-- nUARTDCD modem interrupt mask. A read returns the current mask for
-- the UARTDCDINTR interrupt. On a write of 1, the mask of the
-- UARTDCDINTR interrupt is set. A write of 0 clears the mask.
DCDMIM : Boolean := False;
-- nUARTDSR modem interrupt mask. A read returns the current mask for
-- the UARTDSRINTR interrupt. On a write of 1, the mask of the
-- UARTDSRINTR interrupt is set. A write of 0 clears the mask.
DSRMIM : Boolean := False;
-- Receive interrupt mask. A read returns the current mask for the
-- UARTRXINTR interrupt. On a write of 1, the mask of the UARTRXINTR
-- interrupt is set. A write of 0 clears the mask.
RXIM : Boolean := False;
-- Transmit interrupt mask. A read returns the current mask for the
-- UARTTXINTR interrupt. On a write of 1, the mask of the UARTTXINTR
-- interrupt is set. A write of 0 clears the mask.
TXIM : Boolean := False;
-- Receive timeout interrupt mask. A read returns the current mask for
-- the UARTRTINTR interrupt. On a write of 1, the mask of the UARTRTINTR
-- interrupt is set. A write of 0 clears the mask.
RTIM : Boolean := False;
-- Framing error interrupt mask. A read returns the current mask for the
-- UARTFEINTR interrupt. On a write of 1, the mask of the UARTFEINTR
-- interrupt is set. A write of 0 clears the mask.
FEIM : Boolean := False;
-- Parity error interrupt mask. A read returns the current mask for the
-- UARTPEINTR interrupt. On a write of 1, the mask of the UARTPEINTR
-- interrupt is set. A write of 0 clears the mask.
PEIM : Boolean := False;
-- Break error interrupt mask. A read returns the current mask for the
-- UARTBEINTR interrupt. On a write of 1, the mask of the UARTBEINTR
-- interrupt is set. A write of 0 clears the mask.
BEIM : Boolean := False;
-- Overrun error interrupt mask. A read returns the current mask for the
-- UARTOEINTR interrupt. On a write of 1, the mask of the UARTOEINTR
-- interrupt is set. A write of 0 clears the mask.
OEIM : Boolean := False;
-- unspecified
Reserved_11_31 : HAL.UInt21 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTIMSC_Register use record
RIMIM at 0 range 0 .. 0;
CTSMIM at 0 range 1 .. 1;
DCDMIM at 0 range 2 .. 2;
DSRMIM at 0 range 3 .. 3;
RXIM at 0 range 4 .. 4;
TXIM at 0 range 5 .. 5;
RTIM at 0 range 6 .. 6;
FEIM at 0 range 7 .. 7;
PEIM at 0 range 8 .. 8;
BEIM at 0 range 9 .. 9;
OEIM at 0 range 10 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
-- Raw Interrupt Status Register, UARTRIS
type UARTRIS_Register is record
-- Read-only. nUARTRI modem interrupt status. Returns the raw interrupt
-- state of the UARTRIINTR interrupt.
RIRMIS : Boolean;
-- Read-only. nUARTCTS modem interrupt status. Returns the raw interrupt
-- state of the UARTCTSINTR interrupt.
CTSRMIS : Boolean;
-- Read-only. nUARTDCD modem interrupt status. Returns the raw interrupt
-- state of the UARTDCDINTR interrupt.
DCDRMIS : Boolean;
-- Read-only. nUARTDSR modem interrupt status. Returns the raw interrupt
-- state of the UARTDSRINTR interrupt.
DSRRMIS : Boolean;
-- Read-only. Receive interrupt status. Returns the raw interrupt state
-- of the UARTRXINTR interrupt.
RXRIS : Boolean;
-- Read-only. Transmit interrupt status. Returns the raw interrupt state
-- of the UARTTXINTR interrupt.
TXRIS : Boolean;
-- Read-only. Receive timeout interrupt status. Returns the raw
-- interrupt state of the UARTRTINTR interrupt. a
RTRIS : Boolean;
-- Read-only. Framing error interrupt status. Returns the raw interrupt
-- state of the UARTFEINTR interrupt.
FERIS : Boolean;
-- Read-only. Parity error interrupt status. Returns the raw interrupt
-- state of the UARTPEINTR interrupt.
PERIS : Boolean;
-- Read-only. Break error interrupt status. Returns the raw interrupt
-- state of the UARTBEINTR interrupt.
BERIS : Boolean;
-- Read-only. Overrun error interrupt status. Returns the raw interrupt
-- state of the UARTOEINTR interrupt.
OERIS : Boolean;
-- unspecified
Reserved_11_31 : HAL.UInt21;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTRIS_Register use record
RIRMIS at 0 range 0 .. 0;
CTSRMIS at 0 range 1 .. 1;
DCDRMIS at 0 range 2 .. 2;
DSRRMIS at 0 range 3 .. 3;
RXRIS at 0 range 4 .. 4;
TXRIS at 0 range 5 .. 5;
RTRIS at 0 range 6 .. 6;
FERIS at 0 range 7 .. 7;
PERIS at 0 range 8 .. 8;
BERIS at 0 range 9 .. 9;
OERIS at 0 range 10 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
-- Masked Interrupt Status Register, UARTMIS
type UARTMIS_Register is record
-- Read-only. nUARTRI modem masked interrupt status. Returns the masked
-- interrupt state of the UARTRIINTR interrupt.
RIMMIS : Boolean;
-- Read-only. nUARTCTS modem masked interrupt status. Returns the masked
-- interrupt state of the UARTCTSINTR interrupt.
CTSMMIS : Boolean;
-- Read-only. nUARTDCD modem masked interrupt status. Returns the masked
-- interrupt state of the UARTDCDINTR interrupt.
DCDMMIS : Boolean;
-- Read-only. nUARTDSR modem masked interrupt status. Returns the masked
-- interrupt state of the UARTDSRINTR interrupt.
DSRMMIS : Boolean;
-- Read-only. Receive masked interrupt status. Returns the masked
-- interrupt state of the UARTRXINTR interrupt.
RXMIS : Boolean;
-- Read-only. Transmit masked interrupt status. Returns the masked
-- interrupt state of the UARTTXINTR interrupt.
TXMIS : Boolean;
-- Read-only. Receive timeout masked interrupt status. Returns the
-- masked interrupt state of the UARTRTINTR interrupt.
RTMIS : Boolean;
-- Read-only. Framing error masked interrupt status. Returns the masked
-- interrupt state of the UARTFEINTR interrupt.
FEMIS : Boolean;
-- Read-only. Parity error masked interrupt status. Returns the masked
-- interrupt state of the UARTPEINTR interrupt.
PEMIS : Boolean;
-- Read-only. Break error masked interrupt status. Returns the masked
-- interrupt state of the UARTBEINTR interrupt.
BEMIS : Boolean;
-- Read-only. Overrun error masked interrupt status. Returns the masked
-- interrupt state of the UARTOEINTR interrupt.
OEMIS : Boolean;
-- unspecified
Reserved_11_31 : HAL.UInt21;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTMIS_Register use record
RIMMIS at 0 range 0 .. 0;
CTSMMIS at 0 range 1 .. 1;
DCDMMIS at 0 range 2 .. 2;
DSRMMIS at 0 range 3 .. 3;
RXMIS at 0 range 4 .. 4;
TXMIS at 0 range 5 .. 5;
RTMIS at 0 range 6 .. 6;
FEMIS at 0 range 7 .. 7;
PEMIS at 0 range 8 .. 8;
BEMIS at 0 range 9 .. 9;
OEMIS at 0 range 10 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
-- Interrupt Clear Register, UARTICR
type UARTICR_Register is record
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. nUARTRI modem interrupt clear. Clears the UARTRIINTR
-- interrupt.
RIMIC : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. nUARTCTS modem interrupt clear. Clears the UARTCTSINTR
-- interrupt.
CTSMIC : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. nUARTDCD modem interrupt clear. Clears the UARTDCDINTR
-- interrupt.
DCDMIC : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. nUARTDSR modem interrupt clear. Clears the UARTDSRINTR
-- interrupt.
DSRMIC : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. Receive interrupt clear. Clears the UARTRXINTR
-- interrupt.
RXIC : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. Transmit interrupt clear. Clears the UARTTXINTR
-- interrupt.
TXIC : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. Receive timeout interrupt clear. Clears the UARTRTINTR
-- interrupt.
RTIC : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. Framing error interrupt clear. Clears the UARTFEINTR
-- interrupt.
FEIC : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. Parity error interrupt clear. Clears the UARTPEINTR
-- interrupt.
PEIC : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. Break error interrupt clear. Clears the UARTBEINTR
-- interrupt.
BEIC : Boolean := False;
-- Write data bit of one shall clear (set to zero) the corresponding bit
-- in the field. Overrun error interrupt clear. Clears the UARTOEINTR
-- interrupt.
OEIC : Boolean := False;
-- unspecified
Reserved_11_31 : HAL.UInt21 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTICR_Register use record
RIMIC at 0 range 0 .. 0;
CTSMIC at 0 range 1 .. 1;
DCDMIC at 0 range 2 .. 2;
DSRMIC at 0 range 3 .. 3;
RXIC at 0 range 4 .. 4;
TXIC at 0 range 5 .. 5;
RTIC at 0 range 6 .. 6;
FEIC at 0 range 7 .. 7;
PEIC at 0 range 8 .. 8;
BEIC at 0 range 9 .. 9;
OEIC at 0 range 10 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
-- DMA Control Register, UARTDMACR
type UARTDMACR_Register is record
-- Receive DMA enable. If this bit is set to 1, DMA for the receive FIFO
-- is enabled.
RXDMAE : Boolean := False;
-- Transmit DMA enable. If this bit is set to 1, DMA for the transmit
-- FIFO is enabled.
TXDMAE : Boolean := False;
-- DMA on error. If this bit is set to 1, the DMA receive request
-- outputs, UARTRXDMASREQ or UARTRXDMABREQ, are disabled when the UART
-- error interrupt is asserted.
DMAONERR : Boolean := False;
-- unspecified
Reserved_3_31 : HAL.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTDMACR_Register use record
RXDMAE at 0 range 0 .. 0;
TXDMAE at 0 range 1 .. 1;
DMAONERR at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
subtype UARTPERIPHID0_PARTNUMBER0_Field is HAL.UInt8;
-- UARTPeriphID0 Register
type UARTPERIPHID0_Register is record
-- Read-only. These bits read back as 0x11
PARTNUMBER0 : UARTPERIPHID0_PARTNUMBER0_Field;
-- unspecified
Reserved_8_31 : HAL.UInt24;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTPERIPHID0_Register use record
PARTNUMBER0 at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype UARTPERIPHID1_PARTNUMBER1_Field is HAL.UInt4;
subtype UARTPERIPHID1_DESIGNER0_Field is HAL.UInt4;
-- UARTPeriphID1 Register
type UARTPERIPHID1_Register is record
-- Read-only. These bits read back as 0x0
PARTNUMBER1 : UARTPERIPHID1_PARTNUMBER1_Field;
-- Read-only. These bits read back as 0x1
DESIGNER0 : UARTPERIPHID1_DESIGNER0_Field;
-- unspecified
Reserved_8_31 : HAL.UInt24;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTPERIPHID1_Register use record
PARTNUMBER1 at 0 range 0 .. 3;
DESIGNER0 at 0 range 4 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype UARTPERIPHID2_DESIGNER1_Field is HAL.UInt4;
subtype UARTPERIPHID2_REVISION_Field is HAL.UInt4;
-- UARTPeriphID2 Register
type UARTPERIPHID2_Register is record
-- Read-only. These bits read back as 0x4
DESIGNER1 : UARTPERIPHID2_DESIGNER1_Field;
-- Read-only. This field depends on the revision of the UART: r1p0 0x0
-- r1p1 0x1 r1p3 0x2 r1p4 0x2 r1p5 0x3
REVISION : UARTPERIPHID2_REVISION_Field;
-- unspecified
Reserved_8_31 : HAL.UInt24;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTPERIPHID2_Register use record
DESIGNER1 at 0 range 0 .. 3;
REVISION at 0 range 4 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype UARTPERIPHID3_CONFIGURATION_Field is HAL.UInt8;
-- UARTPeriphID3 Register
type UARTPERIPHID3_Register is record
-- Read-only. These bits read back as 0x00
CONFIGURATION : UARTPERIPHID3_CONFIGURATION_Field;
-- unspecified
Reserved_8_31 : HAL.UInt24;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTPERIPHID3_Register use record
CONFIGURATION at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype UARTPCELLID0_UARTPCELLID0_Field is HAL.UInt8;
-- UARTPCellID0 Register
type UARTPCELLID0_Register is record
-- Read-only. These bits read back as 0x0D
UARTPCELLID0 : UARTPCELLID0_UARTPCELLID0_Field;
-- unspecified
Reserved_8_31 : HAL.UInt24;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTPCELLID0_Register use record
UARTPCELLID0 at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype UARTPCELLID1_UARTPCELLID1_Field is HAL.UInt8;
-- UARTPCellID1 Register
type UARTPCELLID1_Register is record
-- Read-only. These bits read back as 0xF0
UARTPCELLID1 : UARTPCELLID1_UARTPCELLID1_Field;
-- unspecified
Reserved_8_31 : HAL.UInt24;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTPCELLID1_Register use record
UARTPCELLID1 at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype UARTPCELLID2_UARTPCELLID2_Field is HAL.UInt8;
-- UARTPCellID2 Register
type UARTPCELLID2_Register is record
-- Read-only. These bits read back as 0x05
UARTPCELLID2 : UARTPCELLID2_UARTPCELLID2_Field;
-- unspecified
Reserved_8_31 : HAL.UInt24;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTPCELLID2_Register use record
UARTPCELLID2 at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype UARTPCELLID3_UARTPCELLID3_Field is HAL.UInt8;
-- UARTPCellID3 Register
type UARTPCELLID3_Register is record
-- Read-only. These bits read back as 0xB1
UARTPCELLID3 : UARTPCELLID3_UARTPCELLID3_Field;
-- unspecified
Reserved_8_31 : HAL.UInt24;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for UARTPCELLID3_Register use record
UARTPCELLID3 at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
type UART0_Peripheral is record
-- Data Register, UARTDR
UARTDR : aliased UARTDR_Register;
-- Receive Status Register/Error Clear Register, UARTRSR/UARTECR
UARTRSR : aliased UARTRSR_Register;
-- Flag Register, UARTFR
UARTFR : aliased UARTFR_Register;
-- IrDA Low-Power Counter Register, UARTILPR
UARTILPR : aliased UARTILPR_Register;
-- Integer Baud Rate Register, UARTIBRD
UARTIBRD : aliased UARTIBRD_Register;
-- Fractional Baud Rate Register, UARTFBRD
UARTFBRD : aliased UARTFBRD_Register;
-- Line Control Register, UARTLCR_H
UARTLCR_H : aliased UARTLCR_H_Register;
-- Control Register, UARTCR
UARTCR : aliased UARTCR_Register;
-- Interrupt FIFO Level Select Register, UARTIFLS
UARTIFLS : aliased UARTIFLS_Register;
-- Interrupt Mask Set/Clear Register, UARTIMSC
UARTIMSC : aliased UARTIMSC_Register;
-- Raw Interrupt Status Register, UARTRIS
UARTRIS : aliased UARTRIS_Register;
-- Masked Interrupt Status Register, UARTMIS
UARTMIS : aliased UARTMIS_Register;
-- Interrupt Clear Register, UARTICR
UARTICR : aliased UARTICR_Register;
-- DMA Control Register, UARTDMACR
UARTDMACR : aliased UARTDMACR_Register;
-- UARTPeriphID0 Register
UARTPERIPHID0 : aliased UARTPERIPHID0_Register;
-- UARTPeriphID1 Register
UARTPERIPHID1 : aliased UARTPERIPHID1_Register;
-- UARTPeriphID2 Register
UARTPERIPHID2 : aliased UARTPERIPHID2_Register;
-- UARTPeriphID3 Register
UARTPERIPHID3 : aliased UARTPERIPHID3_Register;
-- UARTPCellID0 Register
UARTPCELLID0 : aliased UARTPCELLID0_Register;
-- UARTPCellID1 Register
UARTPCELLID1 : aliased UARTPCELLID1_Register;
-- UARTPCellID2 Register
UARTPCELLID2 : aliased UARTPCELLID2_Register;
-- UARTPCellID3 Register
UARTPCELLID3 : aliased UARTPCELLID3_Register;
end record
with Volatile;
for UART0_Peripheral use record
UARTDR at 16#0# range 0 .. 31;
UARTRSR at 16#4# range 0 .. 31;
UARTFR at 16#18# range 0 .. 31;
UARTILPR at 16#20# range 0 .. 31;
UARTIBRD at 16#24# range 0 .. 31;
UARTFBRD at 16#28# range 0 .. 31;
UARTLCR_H at 16#2C# range 0 .. 31;
UARTCR at 16#30# range 0 .. 31;
UARTIFLS at 16#34# range 0 .. 31;
UARTIMSC at 16#38# range 0 .. 31;
UARTRIS at 16#3C# range 0 .. 31;
UARTMIS at 16#40# range 0 .. 31;
UARTICR at 16#44# range 0 .. 31;
UARTDMACR at 16#48# range 0 .. 31;
UARTPERIPHID0 at 16#FE0# range 0 .. 31;
UARTPERIPHID1 at 16#FE4# range 0 .. 31;
UARTPERIPHID2 at 16#FE8# range 0 .. 31;
UARTPERIPHID3 at 16#FEC# range 0 .. 31;
UARTPCELLID0 at 16#FF0# range 0 .. 31;
UARTPCELLID1 at 16#FF4# range 0 .. 31;
UARTPCELLID2 at 16#FF8# range 0 .. 31;
UARTPCELLID3 at 16#FFC# range 0 .. 31;
end record;
UART0_Periph : aliased UART0_Peripheral
with Import, Address => UART0_Base;
end RP_SVD.UART0;
|
with Ada.Real_Time; use Ada.Real_Time;
with STM32GD.Board; use STM32GD.Board;
with STM32GD.SysTick; use STM32GD.SysTick;
with Drivers.Text_IO;
with Peripherals;
procedure Main is
Temperature : Peripherals.Si7006.Temperature_Type;
Humidity : Peripherals.Si7006.Humidity_Type;
Next_Release : Time := Clock;
Period : constant Time_Span := Milliseconds (500);
package Text_IO is new Drivers.Text_IO (USART => STM32GD.Board.USART);
use Text_IO;
begin
Init;
Peripherals.Init;
SysTick_Periph.RVR.RELOAD := 16#10000#;
SysTick_Periph.CSR.ENABLE := 1;
Put_Line ("Starting");
Put ("Reload: "); Put (Integer'Image (Integer (SysTick_Periph.RVR.RELOAD))); New_Line;
loop
Temperature := Peripherals.Si7006.Temperature_x100;
Humidity := Peripherals.Si7006.Humidity;
Put ("Ticks: "); Put (Integer'Image (Integer (SysTick_Periph.CVR.CURRENT))); New_Line;
Put ("Temperature: "); Put (Integer'Image (Integer (Temperature))); New_Line;
Put ("Humidity: "); Put (Integer'Image (Humidity)); New_Line;
Next_Release := Next_Release + Period;
delay until Next_Release;
end loop;
end Main;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . W C H _ C N V --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
pragma Compiler_Unit_Warning;
with Interfaces; use Interfaces;
with System.WCh_Con; use System.WCh_Con;
with System.WCh_JIS; use System.WCh_JIS;
package body System.WCh_Cnv is
-----------------------------
-- Char_Sequence_To_UTF_32 --
-----------------------------
function Char_Sequence_To_UTF_32
(C : Character;
EM : System.WCh_Con.WC_Encoding_Method) return UTF_32_Code
is
B1 : Unsigned_32;
C1 : Character;
U : Unsigned_32;
W : Unsigned_32;
procedure Get_Hex (N : Character);
-- If N is a hex character, then set B1 to 16 * B1 + character N.
-- Raise Constraint_Error if character N is not a hex character.
procedure Get_UTF_Byte;
pragma Inline (Get_UTF_Byte);
-- Used to interpret a 2#10xxxxxx# continuation byte in UTF-8 mode.
-- Reads a byte, and raises CE if the first two bits are not 10.
-- Otherwise shifts W 6 bits left and or's in the 6 xxxxxx bits.
-------------
-- Get_Hex --
-------------
procedure Get_Hex (N : Character) is
B2 : constant Unsigned_32 := Character'Pos (N);
begin
if B2 in Character'Pos ('0') .. Character'Pos ('9') then
B1 := B1 * 16 + B2 - Character'Pos ('0');
elsif B2 in Character'Pos ('A') .. Character'Pos ('F') then
B1 := B1 * 16 + B2 - (Character'Pos ('A') - 10);
elsif B2 in Character'Pos ('a') .. Character'Pos ('f') then
B1 := B1 * 16 + B2 - (Character'Pos ('a') - 10);
else
raise Constraint_Error;
end if;
end Get_Hex;
------------------
-- Get_UTF_Byte --
------------------
procedure Get_UTF_Byte is
begin
U := Unsigned_32 (Character'Pos (In_Char));
if (U and 2#11000000#) /= 2#10_000000# then
raise Constraint_Error;
end if;
W := Shift_Left (W, 6) or (U and 2#00111111#);
end Get_UTF_Byte;
-- Start of processing for Char_Sequence_To_UTF_32
begin
case EM is
when WCEM_Hex =>
if C /= ASCII.ESC then
return Character'Pos (C);
else
B1 := 0;
Get_Hex (In_Char);
Get_Hex (In_Char);
Get_Hex (In_Char);
Get_Hex (In_Char);
return UTF_32_Code (B1);
end if;
when WCEM_Upper =>
if C > ASCII.DEL then
return 256 * Character'Pos (C) + Character'Pos (In_Char);
else
return Character'Pos (C);
end if;
when WCEM_Shift_JIS =>
if C > ASCII.DEL then
return Wide_Character'Pos (Shift_JIS_To_JIS (C, In_Char));
else
return Character'Pos (C);
end if;
when WCEM_EUC =>
if C > ASCII.DEL then
return Wide_Character'Pos (EUC_To_JIS (C, In_Char));
else
return Character'Pos (C);
end if;
when WCEM_UTF8 =>
-- Note: for details of UTF8 encoding see RFC 3629
U := Unsigned_32 (Character'Pos (C));
-- 16#00_0000#-16#00_007F#: 0xxxxxxx
if (U and 2#10000000#) = 2#00000000# then
return Character'Pos (C);
-- 16#00_0080#-16#00_07FF#: 110xxxxx 10xxxxxx
elsif (U and 2#11100000#) = 2#110_00000# then
W := U and 2#00011111#;
Get_UTF_Byte;
return UTF_32_Code (W);
-- 16#00_0800#-16#00_ffff#: 1110xxxx 10xxxxxx 10xxxxxx
elsif (U and 2#11110000#) = 2#1110_0000# then
W := U and 2#00001111#;
Get_UTF_Byte;
Get_UTF_Byte;
return UTF_32_Code (W);
-- 16#01_0000#-16#10_FFFF#: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
elsif (U and 2#11111000#) = 2#11110_000# then
W := U and 2#00000111#;
for K in 1 .. 3 loop
Get_UTF_Byte;
end loop;
return UTF_32_Code (W);
-- 16#0020_0000#-16#03FF_FFFF#: 111110xx 10xxxxxx 10xxxxxx
-- 10xxxxxx 10xxxxxx
elsif (U and 2#11111100#) = 2#111110_00# then
W := U and 2#00000011#;
for K in 1 .. 4 loop
Get_UTF_Byte;
end loop;
return UTF_32_Code (W);
-- 16#0400_0000#-16#7FFF_FFFF#: 1111110x 10xxxxxx 10xxxxxx
-- 10xxxxxx 10xxxxxx 10xxxxxx
elsif (U and 2#11111110#) = 2#1111110_0# then
W := U and 2#00000001#;
for K in 1 .. 5 loop
Get_UTF_Byte;
end loop;
return UTF_32_Code (W);
else
raise Constraint_Error;
end if;
when WCEM_Brackets =>
if C /= '[' then
return Character'Pos (C);
end if;
if In_Char /= '"' then
raise Constraint_Error;
end if;
B1 := 0;
Get_Hex (In_Char);
Get_Hex (In_Char);
C1 := In_Char;
if C1 /= '"' then
Get_Hex (C1);
Get_Hex (In_Char);
C1 := In_Char;
if C1 /= '"' then
Get_Hex (C1);
Get_Hex (In_Char);
C1 := In_Char;
if C1 /= '"' then
Get_Hex (C1);
Get_Hex (In_Char);
if B1 > Unsigned_32 (UTF_32_Code'Last) then
raise Constraint_Error;
end if;
if In_Char /= '"' then
raise Constraint_Error;
end if;
end if;
end if;
end if;
if In_Char /= ']' then
raise Constraint_Error;
end if;
return UTF_32_Code (B1);
end case;
end Char_Sequence_To_UTF_32;
--------------------------------
-- Char_Sequence_To_Wide_Char --
--------------------------------
function Char_Sequence_To_Wide_Char
(C : Character;
EM : System.WCh_Con.WC_Encoding_Method) return Wide_Character
is
function Char_Sequence_To_UTF is new Char_Sequence_To_UTF_32 (In_Char);
U : constant UTF_32_Code := Char_Sequence_To_UTF (C, EM);
begin
if U > 16#FFFF# then
raise Constraint_Error;
else
return Wide_Character'Val (U);
end if;
end Char_Sequence_To_Wide_Char;
-----------------------------
-- UTF_32_To_Char_Sequence --
-----------------------------
procedure UTF_32_To_Char_Sequence
(Val : UTF_32_Code;
EM : System.WCh_Con.WC_Encoding_Method)
is
Hexc : constant array (UTF_32_Code range 0 .. 15) of Character :=
"0123456789ABCDEF";
C1, C2 : Character;
U : Unsigned_32;
begin
-- Raise CE for invalid UTF_32_Code
if not Val'Valid then
raise Constraint_Error;
end if;
-- Processing depends on encoding mode
case EM is
when WCEM_Hex =>
if Val < 256 then
Out_Char (Character'Val (Val));
elsif Val <= 16#FFFF# then
Out_Char (ASCII.ESC);
Out_Char (Hexc (Val / (16**3)));
Out_Char (Hexc ((Val / (16**2)) mod 16));
Out_Char (Hexc ((Val / 16) mod 16));
Out_Char (Hexc (Val mod 16));
else
raise Constraint_Error;
end if;
when WCEM_Upper =>
if Val < 128 then
Out_Char (Character'Val (Val));
elsif Val < 16#8000# or else Val > 16#FFFF# then
raise Constraint_Error;
else
Out_Char (Character'Val (Val / 256));
Out_Char (Character'Val (Val mod 256));
end if;
when WCEM_Shift_JIS =>
if Val < 128 then
Out_Char (Character'Val (Val));
elsif Val <= 16#FFFF# then
JIS_To_Shift_JIS (Wide_Character'Val (Val), C1, C2);
Out_Char (C1);
Out_Char (C2);
else
raise Constraint_Error;
end if;
when WCEM_EUC =>
if Val < 128 then
Out_Char (Character'Val (Val));
elsif Val <= 16#FFFF# then
JIS_To_EUC (Wide_Character'Val (Val), C1, C2);
Out_Char (C1);
Out_Char (C2);
else
raise Constraint_Error;
end if;
when WCEM_UTF8 =>
-- Note: for details of UTF8 encoding see RFC 3629
U := Unsigned_32 (Val);
-- 16#00_0000#-16#00_007F#: 0xxxxxxx
if U <= 16#00_007F# then
Out_Char (Character'Val (U));
-- 16#00_0080#-16#00_07FF#: 110xxxxx 10xxxxxx
elsif U <= 16#00_07FF# then
Out_Char (Character'Val (2#11000000# or Shift_Right (U, 6)));
Out_Char (Character'Val (2#10000000# or (U and 2#00111111#)));
-- 16#00_0800#-16#00_FFFF#: 1110xxxx 10xxxxxx 10xxxxxx
elsif U <= 16#00_FFFF# then
Out_Char (Character'Val (2#11100000# or Shift_Right (U, 12)));
Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 6)
and 2#00111111#)));
Out_Char (Character'Val (2#10000000# or (U and 2#00111111#)));
-- 16#01_0000#-16#10_FFFF#: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
elsif U <= 16#10_FFFF# then
Out_Char (Character'Val (2#11110000# or Shift_Right (U, 18)));
Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 12)
and 2#00111111#)));
Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 6)
and 2#00111111#)));
Out_Char (Character'Val (2#10000000# or (U and 2#00111111#)));
-- 16#0020_0000#-16#03FF_FFFF#: 111110xx 10xxxxxx 10xxxxxx
-- 10xxxxxx 10xxxxxx
elsif U <= 16#03FF_FFFF# then
Out_Char (Character'Val (2#11111000# or Shift_Right (U, 24)));
Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 18)
and 2#00111111#)));
Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 12)
and 2#00111111#)));
Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 6)
and 2#00111111#)));
Out_Char (Character'Val (2#10000000# or (U and 2#00111111#)));
-- 16#0400_0000#-16#7FFF_FFFF#: 1111110x 10xxxxxx 10xxxxxx
-- 10xxxxxx 10xxxxxx 10xxxxxx
elsif U <= 16#7FFF_FFFF# then
Out_Char (Character'Val (2#11111100# or Shift_Right (U, 30)));
Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 24)
and 2#00111111#)));
Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 18)
and 2#00111111#)));
Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 12)
and 2#00111111#)));
Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 6)
and 2#00111111#)));
Out_Char (Character'Val (2#10000000# or (U and 2#00111111#)));
else
raise Constraint_Error;
end if;
when WCEM_Brackets =>
-- Values in the range 0-255 are directly output. Note that there
-- is an issue with [ (16#5B#) since this will cause confusion
-- if the resulting string is interpreted using brackets encoding.
-- One possibility would be to always output [ as ["5B"] but in
-- practice this is undesirable, since for example normal use of
-- Wide_Text_IO for output (much more common than input), really
-- does want to be able to say something like
-- Put_Line ("Start of output [first run]");
-- and have it come out as intended, rather than contaminated by
-- a ["5B"] sequence in place of the left bracket.
if Val < 256 then
Out_Char (Character'Val (Val));
-- Otherwise use brackets notation for vales greater than 255
else
Out_Char ('[');
Out_Char ('"');
if Val > 16#FFFF# then
if Val > 16#00FF_FFFF# then
Out_Char (Hexc (Val / 16 ** 7));
Out_Char (Hexc ((Val / 16 ** 6) mod 16));
end if;
Out_Char (Hexc ((Val / 16 ** 5) mod 16));
Out_Char (Hexc ((Val / 16 ** 4) mod 16));
end if;
Out_Char (Hexc ((Val / 16 ** 3) mod 16));
Out_Char (Hexc ((Val / 16 ** 2) mod 16));
Out_Char (Hexc ((Val / 16) mod 16));
Out_Char (Hexc (Val mod 16));
Out_Char ('"');
Out_Char (']');
end if;
end case;
end UTF_32_To_Char_Sequence;
--------------------------------
-- Wide_Char_To_Char_Sequence --
--------------------------------
procedure Wide_Char_To_Char_Sequence
(WC : Wide_Character;
EM : System.WCh_Con.WC_Encoding_Method)
is
procedure UTF_To_Char_Sequence is new UTF_32_To_Char_Sequence (Out_Char);
begin
UTF_To_Char_Sequence (Wide_Character'Pos (WC), EM);
end Wide_Char_To_Char_Sequence;
end System.WCh_Cnv;
|
package body address is
function valid_value_for_pos_addr (value : word) return boolean is
begin
return even(value) and value /= 16#ffff#;
end valid_value_for_pos_addr;
procedure valid_addr_assert (addr : word) is
begin
if not valid_value_for_pos_addr(addr) then
raise error_address_odd;
end if;
end valid_addr_assert;
function create (value : word) return pos_addr_t is
begin
valid_addr_assert(value);
return (addr => value);
end create;
procedure set (pos_addr : in out pos_addr_t; value : word) is
begin
valid_addr_assert(value);
pos_addr.addr := value;
end set;
function get (pos_addr : pos_addr_t) return word is
begin
return pos_addr.addr;
end get;
procedure inc (pos_addr : in out pos_addr_t) is
begin
incd(pos_addr.addr);
valid_addr_assert(pos_addr.addr);
end inc;
procedure dec (pos_addr : in out pos_addr_t) is
begin
decd(pos_addr.addr);
valid_addr_assert(pos_addr.addr);
end dec;
function inc (pos_addr : pos_addr_t) return pos_addr_t is
begin
valid_addr_assert(incd(pos_addr.addr));
return (addr => incd(pos_addr.addr));
end inc;
function "<" (a, b : pos_addr_t) return boolean is
begin
return a.addr < b.addr;
end "<";
function "<=" (a, b : pos_addr_t) return boolean is
begin
return a.addr <= b.addr;
end "<=";
function ">" (a, b : pos_addr_t) return boolean is
begin
return a.addr > b.addr;
end ">";
function ">=" (a, b : pos_addr_t) return boolean is
begin
return a.addr >= b.addr;
end ">=";
function "-" (a, b : pos_addr_t) return pos_addr_t is
begin
return (addr => a.addr - b.addr);
end "-";
function "+" (a, b : pos_addr_t) return pos_addr_t is
begin
return (addr => a.addr + b.addr);
end "+";
function "*" (a, b : pos_addr_t) return pos_addr_t is
begin
return (addr => a.addr * b.addr);
end "*";
function "/" (a, b : pos_addr_t) return pos_addr_t is
begin
return (addr => a.addr / b.addr);
end "/";
function "+" (a: pos_addr_t; b : natural) return pos_addr_t is
begin
return (addr => a.addr + word(b));
end "+";
function "+" (a: pos_addr_t; b : word) return pos_addr_t is
begin
return (addr => a.addr + b);
end "+";
end address;
|
package Uninit_Array_Pkg Is
type Rec is record
B1, B2, B3, B4: Boolean;
end record;
type Arr is array (Boolean) of Rec;
function F (R : Rec) return Integer;
end Uninit_Array_Pkg;
|
with Interfaces.C;
with SDL.Types; use SDL.Types;
package Picture_xbm is
picture_width : constant := 32;
picture_height : constant := 32;
type picture_bits_Array is
array (Natural range <>) of aliased Uint8;
picture_bits : picture_bits_Array :=
(
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#18#, 16#80#, 16#01#, 16#18#, 16#64#, 16#6f#, 16#f6#, 16#26#,
16#0a#, 16#00#, 16#00#, 16#50#, 16#f2#, 16#ff#, 16#ff#, 16#4f#,
16#14#, 16#04#, 16#00#, 16#28#, 16#14#, 16#0e#, 16#00#, 16#28#,
16#10#, 16#32#, 16#00#, 16#08#, 16#94#, 16#03#, 16#00#, 16#08#,
16#f4#, 16#04#, 16#00#, 16#08#, 16#b0#, 16#08#, 16#00#, 16#08#,
16#34#, 16#01#, 16#00#, 16#28#, 16#34#, 16#01#, 16#00#, 16#28#,
16#12#, 16#00#, 16#40#, 16#48#, 16#12#, 16#20#, 16#a6#, 16#48#,
16#14#, 16#50#, 16#11#, 16#29#, 16#14#, 16#50#, 16#48#, 16#2a#,
16#10#, 16#27#, 16#ac#, 16#0e#, 16#d4#, 16#71#, 16#e8#, 16#0a#,
16#74#, 16#20#, 16#a8#, 16#0a#, 16#14#, 16#20#, 16#00#, 16#08#,
16#10#, 16#50#, 16#00#, 16#08#, 16#14#, 16#00#, 16#00#, 16#28#,
16#14#, 16#00#, 16#00#, 16#28#, 16#f2#, 16#ff#, 16#ff#, 16#4f#,
16#0a#, 16#00#, 16#00#, 16#50#, 16#64#, 16#6f#, 16#f6#, 16#26#,
16#18#, 16#80#, 16#01#, 16#18#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#
);
end Picture_xbm;
|
with USB;
with USB.LibUSB1;
with Interfaces.C;
with Ada.Text_IO;
use Ada.Text_IO;
procedure InitExit is
Ctx: aliased USB.LibUSB1.Context_Access;
R: USB.LibUSB1.Status;
begin
R := USB.LibUSB1.Init_Lib(Ctx'Access);
Put(USB.LibUSB1.Status'Image(R));
Put_Line("");
USB.LibUSB1.Exit_Lib(Ctx);
end;
|
with STM32_SVD; use STM32_SVD;
with STM32_SVD.RCC; use STM32_SVD.RCC;
with STM32_SVD.NVIC;
with STM32_SVD.GPIO; use STM32_SVD.GPIO;
with STM32GD.Startup;
with STM32GD.Vectors;
package body STM32GD.Board is
procedure Enable_Peripherals is
begin
STM32_SVD.RCC.RCC_Periph.AHBENR.IOPAEN := 1;
STM32_SVD.RCC.RCC_Periph.AHBENR.IOPBEN := 1;
STM32_SVD.RCC.RCC_Periph.APB2ENR.USART1EN := 1;
STM32_SVD.RCC.RCC_Periph.APB2ENR.SPI1EN := 1;
STM32_SVD.RCC.RCC_Periph.APB2ENR.ADCEN := 1;
STM32_SVD.RCC.RCC_Periph.APB1ENR.I2C1EN := 1;
BUTTON.Init;
LED.Init;
LED2.Init;
LED3.Init;
TX.Init;
RX.Init;
RFM69_RESET.Init;
SCL.Init;
SDA.Init;
CSN.Init;
CSN.Set;
SCLK.Init;
MISO.Init;
MOSI.Init;
IRQ.Init;
USART.Init;
SPI.Init;
I2C.Init;
end Enable_Peripherals;
procedure Disable_Peripherals is
begin
RCC_Periph.AHBENR.IOPAEN := 1;
RCC_Periph.AHBENR.IOPBEN := 1;
RCC_Periph.AHBENR.IOPCEN := 1;
RCC_Periph.AHBENR.IOPDEN := 1;
RCC_Periph.AHBENR.IOPFEN := 1;
GPIOA_Periph.MODER.Val := 16#FFFF_FFFF#;
GPIOB_Periph.MODER.Val := 16#FFFF_FFFF#;
GPIOC_Periph.MODER.Val := 16#FFFF_FFFF#;
GPIOD_Periph.MODER.Val := 16#FFFF_FFFF#;
GPIOF_Periph.MODER.Val := 16#FFFF_FFFF#;
MOSI.Set_Mode (STM32GD.GPIO.Mode_In);
MOSI.Set_Pull_Resistor (STM32GD.GPIO.Pull_Down);
MISO.Set_Mode (STM32GD.GPIO.Mode_In);
MISO.Set_Pull_Resistor (STM32GD.GPIO.Pull_Down);
SCLK.Set_Mode (STM32GD.GPIO.Mode_In);
SCLK.Set_Pull_Resistor (STM32GD.GPIO.Pull_Up);
CSN.Set_Mode (STM32GD.GPIO.Mode_In);
CSN.Set_Pull_Resistor (STM32GD.GPIO.Pull_Up);
RCC_Periph.AHBENR.IOPAEN := 0;
RCC_Periph.AHBENR.IOPBEN := 0;
RCC_Periph.AHBENR.IOPCEN := 0;
RCC_Periph.AHBENR.IOPDEN := 0;
RCC_Periph.AHBENR.IOPFEN := 0;
RCC_Periph.APB2ENR.USART1EN := 0;
RCC_Periph.APB2ENR.SPI1EN := 0;
RCC_Periph.APB1ENR.I2C1EN := 0;
RCC_Periph.AHBENR.DMAEN := 0;
RCC_Periph.APB2ENR.ADCEN := 0;
end Disable_Peripherals;
procedure Init is
begin
CLOCKS.Init;
RTC.Init;
Enable_Peripherals;
STM32GD.Clear_Event;
end Init;
end STM32GD.Board;
|
pragma License (Unrestricted);
-- extended unit specialized for Darwin
private with System.Storage_Map;
package System.Program is
-- Probing information of the program itself.
pragma Preelaborate;
-- the executable file
function Full_Name return String;
function Load_Address return Address;
pragma Inline (Load_Address); -- renamed
private
function Load_Address return Address
renames Storage_Map.Load_Address;
end System.Program;
|
with Lv.Style;
package Lv.Objx.Arc is
subtype Instance is Obj_T;
type Style_T is (Style_Main);
-- Create a arc objects
-- @param par pointer to an object, it will be the parent of the new arc
-- @param copy pointer to a arc object, if not NULL then the new object will be copied from it
-- @return pointer to the created arc
function Create (Parent : Obj_T; Copy : Instance) return Instance;
----------------------
-- Setter functions --
----------------------
-- Set the start and end angles of an arc. 0 deg: bottom, 90 deg: right etc.
-- @param arc pointer to an arc object
-- @param start the start angle [0..360]
-- @param end the end angle [0..360]
procedure Set_Angles (Self : Instance; Start : Uint16_T; End_P : Uint16_T);
-- Set a style of a arc.
-- @param arc pointer to arc object
-- @param type which style should be set
-- @param style pointer to a style
procedure Set_Style
(Self : Instance;
Type_P : Style_T;
Style : access Lv.Style.Style);
----------------------
-- Getter functions --
----------------------
-- Get the start angle of an arc.
-- @param arc pointer to an arc object
-- @return the start angle [0..360]
function Angle_Start (Self : Instance) return Uint16_T;
-- Get the end angle of an arc.
-- @param arc pointer to an arc object
-- @return the end angle [0..360]
function Angle_End (Self : Instance) return Uint16_T;
-- Get style of a arc.
-- @param arc pointer to arc object
-- @param type which style should be get
-- @return style pointer to the style
function Style
(Self : Instance;
Arg2 : Style_T) return access Lv.Style.Style;
-------------
-- Imports --
-------------
pragma Import (C, Create, "lv_arc_create");
pragma Import (C, Set_Angles, "lv_arc_set_angles");
pragma Import (C, Set_Style, "lv_arc_set_style");
pragma Import (C, Angle_Start, "lv_arc_get_angle_start");
pragma Import (C, Angle_End, "lv_arc_get_angle_end");
pragma Import (C, Style, "lv_arc_get_style");
for Style_T'Size use 8;
for Style_T use (Style_Main => 0);
end Lv.Objx.Arc;
|
-- This spec has been automatically generated from STM32F103.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with System;
package STM32_SVD.RTC is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype CRH_SECIE_Field is STM32_SVD.Bit;
subtype CRH_ALRIE_Field is STM32_SVD.Bit;
subtype CRH_OWIE_Field is STM32_SVD.Bit;
-- RTC Control Register High
type CRH_Register is record
-- Second interrupt Enable
SECIE : CRH_SECIE_Field := 16#0#;
-- Alarm interrupt Enable
ALRIE : CRH_ALRIE_Field := 16#0#;
-- Overflow interrupt Enable
OWIE : CRH_OWIE_Field := 16#0#;
-- unspecified
Reserved_3_31 : STM32_SVD.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CRH_Register use record
SECIE at 0 range 0 .. 0;
ALRIE at 0 range 1 .. 1;
OWIE at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
subtype CRL_SECF_Field is STM32_SVD.Bit;
subtype CRL_ALRF_Field is STM32_SVD.Bit;
subtype CRL_OWF_Field is STM32_SVD.Bit;
subtype CRL_RSF_Field is STM32_SVD.Bit;
subtype CRL_CNF_Field is STM32_SVD.Bit;
subtype CRL_RTOFF_Field is STM32_SVD.Bit;
-- RTC Control Register Low
type CRL_Register is record
-- Second Flag
SECF : CRL_SECF_Field := 16#0#;
-- Alarm Flag
ALRF : CRL_ALRF_Field := 16#0#;
-- Overflow Flag
OWF : CRL_OWF_Field := 16#0#;
-- Registers Synchronized Flag
RSF : CRL_RSF_Field := 16#0#;
-- Configuration Flag
CNF : CRL_CNF_Field := 16#0#;
-- Read-only. RTC operation OFF
RTOFF : CRL_RTOFF_Field := 16#1#;
-- unspecified
Reserved_6_31 : STM32_SVD.UInt26 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CRL_Register use record
SECF at 0 range 0 .. 0;
ALRF at 0 range 1 .. 1;
OWF at 0 range 2 .. 2;
RSF at 0 range 3 .. 3;
CNF at 0 range 4 .. 4;
RTOFF at 0 range 5 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
subtype PRLH_PRLH_Field is STM32_SVD.UInt4;
-- RTC Prescaler Load Register High
type PRLH_Register is record
-- Write-only. RTC Prescaler Load Register High
PRLH : PRLH_PRLH_Field := 16#0#;
-- unspecified
Reserved_4_31 : STM32_SVD.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for PRLH_Register use record
PRLH at 0 range 0 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
subtype PRLL_PRLL_Field is STM32_SVD.UInt16;
-- RTC Prescaler Load Register Low
type PRLL_Register is record
-- Write-only. RTC Prescaler Divider Register Low
PRLL : PRLL_PRLL_Field := 16#8000#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for PRLL_Register use record
PRLL at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DIVH_DIVH_Field is STM32_SVD.UInt4;
-- RTC Prescaler Divider Register High
type DIVH_Register is record
-- Read-only. RTC prescaler divider register high
DIVH : DIVH_DIVH_Field;
-- unspecified
Reserved_4_31 : STM32_SVD.UInt28;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DIVH_Register use record
DIVH at 0 range 0 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
subtype DIVL_DIVL_Field is STM32_SVD.UInt16;
-- RTC Prescaler Divider Register Low
type DIVL_Register is record
-- Read-only. RTC prescaler divider register Low
DIVL : DIVL_DIVL_Field;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DIVL_Register use record
DIVL at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype CNTH_CNTH_Field is STM32_SVD.UInt16;
-- RTC Counter Register High
type CNTH_Register is record
-- RTC counter register high
CNTH : CNTH_CNTH_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CNTH_Register use record
CNTH at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype CNTL_CNTL_Field is STM32_SVD.UInt16;
-- RTC Counter Register Low
type CNTL_Register is record
-- RTC counter register Low
CNTL : CNTL_CNTL_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CNTL_Register use record
CNTL at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype ALRH_ALRH_Field is STM32_SVD.UInt16;
-- RTC Alarm Register High
type ALRH_Register is record
-- Write-only. RTC alarm register high
ALRH : ALRH_ALRH_Field := 16#FFFF#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for ALRH_Register use record
ALRH at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype ALRL_ALRL_Field is STM32_SVD.UInt16;
-- RTC Alarm Register Low
type ALRL_Register is record
-- Write-only. RTC alarm register low
ALRL : ALRL_ALRL_Field := 16#FFFF#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for ALRL_Register use record
ALRL at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Real time clock
type RTC_Peripheral is record
-- RTC Control Register High
CRH : aliased CRH_Register;
-- RTC Control Register Low
CRL : aliased CRL_Register;
-- RTC Prescaler Load Register High
PRLH : aliased PRLH_Register;
-- RTC Prescaler Load Register Low
PRLL : aliased PRLL_Register;
-- RTC Prescaler Divider Register High
DIVH : aliased DIVH_Register;
-- RTC Prescaler Divider Register Low
DIVL : aliased DIVL_Register;
-- RTC Counter Register High
CNTH : aliased CNTH_Register;
-- RTC Counter Register Low
CNTL : aliased CNTL_Register;
-- RTC Alarm Register High
ALRH : aliased ALRH_Register;
-- RTC Alarm Register Low
ALRL : aliased ALRL_Register;
end record
with Volatile;
for RTC_Peripheral use record
CRH at 16#0# range 0 .. 31;
CRL at 16#4# range 0 .. 31;
PRLH at 16#8# range 0 .. 31;
PRLL at 16#C# range 0 .. 31;
DIVH at 16#10# range 0 .. 31;
DIVL at 16#14# range 0 .. 31;
CNTH at 16#18# range 0 .. 31;
CNTL at 16#1C# range 0 .. 31;
ALRH at 16#20# range 0 .. 31;
ALRL at 16#24# range 0 .. 31;
end record;
-- Real time clock
RTC_Periph : aliased RTC_Peripheral
with Import, Address => System'To_Address (16#40002800#);
end STM32_SVD.RTC;
|
-- Copyright (c) 2021 Devin Hill
-- zlib License -- see LICENSE for details.
package body GBA.DMA is
procedure Setup_DMA_Transfer
( Channel : Channel_ID;
Source, Dest : Address;
Info : Transfer_Info ) is
Selected_Channel : Channel_Info renames Channel_Array_View (Channel);
begin
Selected_Channel.Source := Source;
Selected_Channel.Dest := Dest;
Selected_Channel.DMA_Info := (Info with delta Enabled => True);
end;
procedure Stop_Ongoing_Transfer (Channel : Channel_ID) is
Selected_Channel : Channel_Info renames Channel_Array_View (Channel);
begin
Selected_Channel.DMA_Info.Enabled := False;
end;
function Is_Transfer_Ongoing (Channel : Channel_ID) return Boolean is
Selected_Channel : Channel_Info renames Channel_Array_View (Channel);
begin
return Selected_Channel.DMA_Info.Enabled;
end;
end GBA.DMA;
|
------------------------------------------------------------------------------
-- Copyright (C) 2020 by Heisenbug Ltd. (gh+spat@heisenbug.eu)
--
-- This work is free. You can redistribute it and/or modify it under the
-- terms of the Do What The Fuck You Want To Public License, Version 2,
-- as published by Sam Hocevar. See the LICENSE file for more details.
------------------------------------------------------------------------------
pragma License (Unrestricted);
package body SPAT.String_Vectors is
---------------------------------------------------------------------------
-- Max_Length
---------------------------------------------------------------------------
not overriding
function Max_Length (Source : in List) return Ada.Text_IO.Count is
Result : Ada.Text_IO.Count := 0;
begin
for S of Source loop
Result :=
Ada.Text_IO.Count'Max (Result,
Ada.Text_IO.Count (Length (Source => S)));
end loop;
return Result;
end Max_Length;
end SPAT.String_Vectors;
|
-----------------------------------------------------------------------
-- ADO Databases -- Database Objects
-- Copyright (C) 2012 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Directories;
with Ada.Streams.Stream_IO;
with Util.Streams.Files;
package body ADO is
use Util.Refs;
use Ada.Streams;
-- ------------------------------
-- Create a blob with an allocated buffer of <b>Size</b> bytes.
-- ------------------------------
function Create_Blob (Size : in Natural) return Blob_Ref is
B : constant Blob_Access := new Blob '(Ref_Entity with
Len => Stream_Element_Offset (Size),
others => <>);
begin
return Blob_References.Create (B);
end Create_Blob;
-- ------------------------------
-- Create a blob initialized with the given data buffer.
-- ------------------------------
function Create_Blob (Data : in Ada.Streams.Stream_Element_Array) return Blob_Ref is
B : constant Blob_Access := new Blob '(Ref_Entity with
Len => Data'Length,
Data => Data);
begin
return Blob_References.Create (B);
end Create_Blob;
-- ------------------------------
-- Create a blob initialized with the content from the file whose path is <b>Path</b>.
-- Raises an IO exception if the file does not exist.
-- ------------------------------
function Create_Blob (Path : in String) return Blob_Ref is
Size : constant Stream_Element_Offset := Stream_Element_Offset (Ada.Directories.Size (Path));
File : Util.Streams.Files.File_Stream;
Last : Stream_Element_Offset;
begin
File.Open (Name => Path, Mode => Ada.Streams.Stream_IO.In_File);
declare
B : constant Blob_Access := new Blob '(Ref_Entity with
Len => Size,
others => <>);
begin
File.Read (Into => B.Data, Last => Last);
File.Close;
return Blob_References.Create (B);
end;
end Create_Blob;
Null_Blob_Instance : Blob_Ref;
-- ------------------------------
-- Return a null blob.
-- ------------------------------
function Null_Blob return Blob_Ref is
begin
return Null_Blob_Instance;
end Null_Blob;
end ADO;
|
-- @summary
-- Convert to string and concatenate float-derived types.
--
-- @description
-- See its usage to get the idea. However, I don't think this
-- should be a "top" package. I would like it could be seen
-- only in Measure_Units, because Measure_Units uses it to
-- provide some functions to its clients.
--
-- Could this be a good idea as a general purpose utility?
--
package Converters is
generic
type A_Type is new Float;
function To_String (V : A_Type) return String;
generic
type A_Type is new Float;
with function String_Conv (C : A_Type) return String;
function Concat (L : String; R : A_Type) return String;
end Converters;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 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.
package body Orka.Rendering.Buffers.MDI is
procedure Append
(Object : in out Batch;
Instances : Natural;
Vertices : Natural;
Indices : Natural;
Append_Vertices : not null access procedure (Offset, Count : Natural);
Append_Indices : not null access procedure (Offset, Count : Natural))
is
Index_Count : constant Natural := Indices;
Vertex_Count : constant Natural := Vertices;
Commands : Indirect.Elements_Indirect_Command_Array (1 .. 1);
begin
Commands (1) :=
(Count => UInt (Index_Count),
Instances => UInt (Instances),
First_Index => UInt (Object.Index_Offset),
Base_Vertex => UInt (Object.Vertex_Offset),
Base_Instance => UInt (Object.Instance_Index));
Append_Vertices (Offset => Object.Vertex_Offset, Count => Vertex_Count);
Append_Indices (Offset => Object.Index_Offset, Count => Index_Count);
-- Upload command to command buffer
Object.Commands.Write_Data (Commands, Offset => Object.Draw_Index);
Object.Index_Offset := Object.Index_Offset + Index_Count;
Object.Vertex_Offset := Object.Vertex_Offset + Vertex_Count;
Object.Draw_Index := Object.Draw_Index + 1;
Object.Instance_Index := Object.Instance_Index + Instances;
end Append;
function Create_Batch
(Vertex_Kind : Types.Numeric_Type;
Index_Kind : Types.Index_Type;
Parts, Vertex_Data, Indices : Positive) return Batch
is
use all type Mapped.Unsynchronized.Unsynchronized_Mapped_Buffer;
begin
return Result : Batch (Vertex_Kind, Index_Kind) do
Result.Commands := Create_Buffer
(Types.Elements_Command_Type, Parts, Mapped.Write);
Result.Data := Create_Buffer
(Vertex_Kind, Vertex_Data, Mapped.Write);
-- Indices
Result.Indices := Create_Buffer (Index_Kind, Indices, Mapped.Write);
Result.Data.Map;
Result.Indices.Map;
Result.Commands.Map;
end return;
end Create_Batch;
procedure Finish_Batch (Object : in out Batch) is
begin
Object.Data.Unmap;
Object.Indices.Unmap;
Object.Commands.Unmap;
end Finish_Batch;
-----------------------------------------------------------------------------
Interleaved_Half_Type_Elements : constant := 8;
function Create_Batch (Parts, Vertices, Indices : Positive) return Batch is
(Create_Batch (Types.Half_Type, Types.UInt_Type,
Parts, Vertices * Interleaved_Half_Type_Elements, Indices));
procedure Append
(Object : in out Batch;
Positions : not null Indirect.Half_Array_Access;
Normals : not null Indirect.Half_Array_Access;
UVs : not null Indirect.Half_Array_Access;
Indices : not null Indirect.UInt_Array_Access)
is
Vertex_Count : constant Natural := Positions'Length / 3;
Index_Count : constant Natural := Indices'Length;
pragma Assert (Positions'Length = Normals'Length);
pragma Assert (Vertex_Count = UVs'Length / 2);
procedure Write_Vertices (Vertex_Offset, Vertex_Count : Natural) is
begin
-- Iterate over the vertices to interleave all the data into one buffer
for I in 1 .. Size (Vertex_Count) loop
declare
Offset : constant Natural := (Vertex_Offset + Natural (I) - 1)
* Interleaved_Half_Type_Elements;
begin
Object.Data.Write_Data (Positions.all (I * 3 - 2 .. I * 3), Offset => Offset + 0);
Object.Data.Write_Data (Normals.all (I * 3 - 2 .. I * 3), Offset => Offset + 3);
Object.Data.Write_Data (UVs.all (I * 2 - 1 .. I * 2), Offset => Offset + 6);
end;
end loop;
end Write_Vertices;
procedure Write_Indices (Index_Offset, Index_Count : Natural) is
begin
Object.Indices.Write_Data (Indices.all, Offset => Index_Offset);
end Write_Indices;
begin
Object.Append (0, Vertex_Count, Index_Count, Write_Vertices'Access, Write_Indices'Access);
end Append;
end Orka.Rendering.Buffers.MDI;
|
with Ada.Text_IO; use Ada.Text_IO;
with Libadalang.Analysis; use Libadalang.Analysis;
with Libadalang.Common; use Libadalang.Common;
with Rejuvenation; use Rejuvenation;
with Rejuvenation.Factory; use Rejuvenation.Factory;
with Rejuvenation.Finder; use Rejuvenation.Finder;
package body Examples.Ast is
procedure Demo_Syntactic_F_Fields (Unit : Analysis_Unit);
procedure Demo_Semantic_P_Properties (Unit : Analysis_Unit);
procedure Demo (Project_Name : String; File_Name : String) is
Context : constant Project_Context := Open_Project (Project_Name);
Unit : constant Analysis_Unit := Open_File (File_Name, Context);
begin
Put_Line ("=== Examples of AST accessors =======");
New_Line;
Put_Line ("--- Example of syntactic F fields -------");
New_Line;
Demo_Syntactic_F_Fields (Unit);
New_Line;
Put_Line ("--- Example of semantic P properties -------");
New_Line;
Demo_Semantic_P_Properties (Unit);
New_Line;
end Demo;
procedure Demo_Syntactic_F_Fields (Unit : Analysis_Unit) is
-- Hint: <CTRL>-<SPACE> helps to find the right F_ fields
CU : constant Compilation_Unit := Unit.Root.As_Compilation_Unit;
LI : constant Library_Item := CU.F_Body.As_Library_Item;
Subp : constant Subp_Body := LI.F_Item.As_Subp_Body;
DP : constant Declarative_Part := Subp.F_Decls;
Decls : constant Ada_Node_List := DP.F_Decls;
begin
Put_Line ("Declarations:");
for Decl of Decls loop
New_Line;
Decl.Print; -- Show the node's internal structure
end loop;
end Demo_Syntactic_F_Fields;
procedure Demo_Semantic_P_Properties (Unit : Analysis_Unit) is
-- Hint: <CTRL>-<SPACE> helps to find the
-- right F_ and P_ fields/properties
begin
for Node of Find (Unit.Root, Ada_Call_Expr) loop
declare
Call : constant Call_Expr := Node.As_Call_Expr;
Call_Name : constant Libadalang.Analysis.Name := Call.F_Name;
begin
Put_Line
("Call: " & Call.Image & " from " & Call.Unit.Get_Filename);
declare
Called_Decl : constant Basic_Decl :=
Call_Name.P_Referenced_Decl;
begin
if Called_Decl.Is_Null then
Put_Line (" --> Resolution unknown");
else
Put_Line
(" --> Declaration: " & Called_Decl.Image & " from " &
Called_Decl.Unit.Get_Filename);
end if;
end;
exception
when Libadalang.Common.Property_Error =>
Put_Line (" --> Resolution failed");
end;
end loop;
end Demo_Semantic_P_Properties;
end Examples.Ast;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- SYSTEM.MACHINE_STATE_OPERATIONS --
-- --
-- S p e c --
-- --
-- Copyright (C) 1999-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. --
-- --
------------------------------------------------------------------------------
pragma Polling (Off);
-- We must turn polling off for this unit, because otherwise we get
-- elaboration circularities with System.Exception_Tables.
with System.Storage_Elements;
package System.Machine_State_Operations is
subtype Code_Loc is System.Address;
-- Code location used in building exception tables and for call
-- addresses when propagating an exception (also traceback table)
-- Values of this type are created by using Label'Address or
-- extracted from machine states using Get_Code_Loc.
type Machine_State is new System.Address;
-- The table based exception handling approach (see a-except.adb) isolates
-- the target dependent aspects using an abstract data type interface
-- to the type Machine_State, which is represented as a System.Address
-- value (presumably implemented as a pointer to an appropriate record
-- structure).
function Machine_State_Length return System.Storage_Elements.Storage_Offset;
-- Function to determine the length of the Storage_Array needed to hold
-- a machine state. The machine state will always be maximally aligned.
-- The value returned is a constant that will be used to allocate space
-- for a machine state value.
function Allocate_Machine_State return Machine_State;
-- Allocate the required space for a Machine_State
procedure Free_Machine_State (M : in out Machine_State);
-- Free the dynamic memory taken by Machine_State
-- The initial value of type Machine_State is created by the low level
-- routine that actually raises an exception using the special builtin
-- _builtin_machine_state. This value will typically encode the value
-- of the program counter, and relevant registers. The following
-- operations are defined on Machine_State values:
function Get_Code_Loc (M : Machine_State) return Code_Loc;
-- This function extracts the program counter value from a machine
-- state, which the caller uses for searching the exception tables,
-- and also for recording entries in the traceback table. The call
-- returns a value of Null_Loc if the machine state represents the
-- outer level, or some other frame for which no information can be
-- provided.
procedure Pop_Frame (M : Machine_State);
-- This procedure pops the machine state M so that it represents the
-- call point, as though the current subprogram had returned. It
-- changes only the value referenced by M, and does not affect
-- the current stack environment.
function Fetch_Code (Loc : Code_Loc) return Code_Loc;
-- Some architectures (notably VMS) use a descriptor to describe
-- a subprogram address. This function computes the actual starting
-- address of the code from Loc.
-- Do not add pragma Inline, see 9116-002.
-- ??? This function will go away when 'Code_Address is fixed on VMS.
procedure Set_Machine_State (M : Machine_State);
-- This routine sets M from the current machine state. It is called
-- when an exception is initially signalled to initialize the state.
end System.Machine_State_Operations;
|
package Bug_Elaboration_Code is
pragma Elaborate_Body;
I : Integer;
J : Integer;
end Bug_Elaboration_Code;
|
--****p* Fakedsp/Data_Streams
-- DESCRIPTION
-- Since the virtual card is not... a real one (really?) the samples
-- read by the ADC need to come from some external source and also
-- the samples sento to the virtual DAC need to be written somewehere.
--
-- The most obvious choice for said external source/destinations are
-- files. However, there are many possible format available such as
-- WAV, octave, pure text, and so on... Moreover, the file could be a
-- file on disk or, in a Linux environment, the standard input/output or
-- a network connection or...
--
-- In order to not commit ourselves to a specific choice and allowing
-- for future expansions, the library introduces two abstract
-- interfaces that describe the minimum required to a data source/destination
-- and that can be specialized to specific formats. Currenty the library
-- provides implementations for WAV format and a text-based format
-- compatible with the octave text format.
--
-- The two interfaces defined in this package are:
-- * Data_Source are used to read data from (surprised?).
-- * Data_Destination used to write data (surprised again, I guess)
--
-- Both Data_Source and Data_Destination have a sampling frequency
-- and one or more channels. They can I/O both values of type
-- Sample_Type (closer to what actually happen with a real ADC/DAC)
-- or of type Float. We decided of allowing saving Float values
-- since in some case we could want to post-process the output produced
-- by the processing without the additional noise due to the quantization
-- done in order to send data to the DAC.
--
-- NOTE
-- Currently most of the code is designed to work with a single channel
-- only. Maybe this will change in the future.
--***
package Fakedsp.Data_Streams is
type Channel_Index is range 1 .. 1024;
--****I* Data_Streams/Data_Source
-- SOURCE
type Data_Source is limited interface;
type Data_Source_Access is access all Data_Source'Class;
-- DESCRIPTION
-- Abstract interface representing the generic data source.
-- A concrete implementation of this interface needs to define:
-- * procedure Read to get the next sample
-- * function Sampling_Frequency that returns the
-- sampling frequency of the source
-- * function Max_Channel returning the number of the
-- last channel
-- * procedure Close that... close the source.
--***
--****m* Data_Source/Read
-- SOURCE
procedure Read
(Src : in out Data_Source;
Sample : out Sample_Type;
End_Of_Stream : out Boolean;
Channel : in Channel_Index := Channel_Index'First)
is abstract
with Pre'Class => Channel <= Src.Max_Channel;
procedure Read
(Src : in out Data_Source;
Sample : out Float;
End_Of_Stream : out Boolean;
Channel : in Channel_Index := Channel_Index'First)
is abstract
with Pre'Class => Channel <= Src.Max_Channel;
-- DESCRIPTION
-- Read one sample from a channel of the specified source. If
-- the source ran out of data, End_Of_Stream is set to True, otherwise
-- is set to False.
--***
--****m* Data_Source/Sampling_Frequency
-- SOURCE
function Sampling_Frequency (Src : Data_Source) return Frequency_Hz is abstract;
-- DESCRIPTION
-- Return the sampling frequency of the source
--***
--****m* Data_Source/Max_Channel
-- SOURCE
function Max_Channel (Src : Data_Source) return Channel_Index is abstract;
-- DESCRIPTION
-- Return the number of the last channel of the source
--***
--****m* Data_Source/Close
-- SOURCE
procedure Close (Src : in out Data_Source) is abstract;
-- DESCRIPTION
-- Close the source, doing all the necessary housekeeping (if required)
--***
--****I* Data_Streams/Data_Destination
-- SOURCE
type Data_Destination is limited interface;
type Data_destination_Access is access all Data_Destination'Class;
-- DESCRIPTION
-- Abstract interface representing the generic data destination.
-- A concrete implementation of this interface needs to define:
-- * procedure Write to output the next sample
-- * function Max_Channel returning the number of the
-- last channel
-- * procedure Close that... close the destination.
--***
--****m* Data_Destination/Write
-- SOURCE
procedure Write (Dst : Data_Destination;
Sample : Sample_Type;
Channel : Channel_Index := Channel_Index'First)
is abstract
with Pre'Class => Channel <= Dst.Max_Channel;
procedure Write (Dst : Data_Destination;
Sample : Float;
Channel : Channel_Index := Channel_Index'First)
is abstract
with Pre'Class => Channel <= Dst.Max_Channel;
-- DESCRIPTION
-- Output a sample to the destination
--***
--****m* Data_Destination/Max_Channel
-- SOURCE
function Max_Channel (Src : Data_Destination) return Channel_Index is abstract;
-- DESCRIPTION
-- Return the number of the last channel of the source
--***
--****m* Data_Destination/Close
-- SOURCE
procedure Close (Src : in out Data_Destination) is abstract;
-- DESCRIPTION
-- Close the destination, doing all the necessary housekeeping
--***
end Fakedsp.Data_Streams;
|
pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with System;
with Interfaces.C.Strings;
private package CUPS.cups_language_h is
-- * "$Id: language.h 10996 2013-05-29 11:51:34Z msweet $"
-- *
-- * Multi-language support for CUPS.
-- *
-- * Copyright 2007-2011 by Apple Inc.
-- * Copyright 1997-2006 by Easy Software Products.
-- *
-- * These coded instructions, statements, and computer programs are the
-- * property of Apple Inc. and are protected by Federal copyright
-- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
-- * which should have been included with this file. If this file is
-- * file is missing or damaged, see the license at "http://www.cups.org/".
-- *
-- * This file is subject to the Apple OS-Developed Software exception.
--
-- * Include necessary headers...
--
-- * Types...
--
--*** Language Encodings ***
subtype cups_encoding_e is unsigned;
CUPS_AUTO_ENCODING : constant cups_encoding_e := -1;
CUPS_US_ASCII : constant cups_encoding_e := 0;
CUPS_ISO8859_1 : constant cups_encoding_e := 1;
CUPS_ISO8859_2 : constant cups_encoding_e := 2;
CUPS_ISO8859_3 : constant cups_encoding_e := 3;
CUPS_ISO8859_4 : constant cups_encoding_e := 4;
CUPS_ISO8859_5 : constant cups_encoding_e := 5;
CUPS_ISO8859_6 : constant cups_encoding_e := 6;
CUPS_ISO8859_7 : constant cups_encoding_e := 7;
CUPS_ISO8859_8 : constant cups_encoding_e := 8;
CUPS_ISO8859_9 : constant cups_encoding_e := 9;
CUPS_ISO8859_10 : constant cups_encoding_e := 10;
CUPS_UTF8 : constant cups_encoding_e := 11;
CUPS_ISO8859_13 : constant cups_encoding_e := 12;
CUPS_ISO8859_14 : constant cups_encoding_e := 13;
CUPS_ISO8859_15 : constant cups_encoding_e := 14;
CUPS_WINDOWS_874 : constant cups_encoding_e := 15;
CUPS_WINDOWS_1250 : constant cups_encoding_e := 16;
CUPS_WINDOWS_1251 : constant cups_encoding_e := 17;
CUPS_WINDOWS_1252 : constant cups_encoding_e := 18;
CUPS_WINDOWS_1253 : constant cups_encoding_e := 19;
CUPS_WINDOWS_1254 : constant cups_encoding_e := 20;
CUPS_WINDOWS_1255 : constant cups_encoding_e := 21;
CUPS_WINDOWS_1256 : constant cups_encoding_e := 22;
CUPS_WINDOWS_1257 : constant cups_encoding_e := 23;
CUPS_WINDOWS_1258 : constant cups_encoding_e := 24;
CUPS_KOI8_R : constant cups_encoding_e := 25;
CUPS_KOI8_U : constant cups_encoding_e := 26;
CUPS_ISO8859_11 : constant cups_encoding_e := 27;
CUPS_ISO8859_16 : constant cups_encoding_e := 28;
CUPS_MAC_ROMAN : constant cups_encoding_e := 29;
CUPS_ENCODING_SBCS_END : constant cups_encoding_e := 63;
CUPS_WINDOWS_932 : constant cups_encoding_e := 64;
CUPS_WINDOWS_936 : constant cups_encoding_e := 65;
CUPS_WINDOWS_949 : constant cups_encoding_e := 66;
CUPS_WINDOWS_950 : constant cups_encoding_e := 67;
CUPS_WINDOWS_1361 : constant cups_encoding_e := 68;
CUPS_ENCODING_DBCS_END : constant cups_encoding_e := 127;
CUPS_EUC_CN : constant cups_encoding_e := 128;
CUPS_EUC_JP : constant cups_encoding_e := 129;
CUPS_EUC_KR : constant cups_encoding_e := 130;
CUPS_EUC_TW : constant cups_encoding_e := 131;
CUPS_JIS_X0213 : constant cups_encoding_e := 132;
CUPS_ENCODING_VBCS_END : constant cups_encoding_e := 191; -- cups/language.h:37
-- Auto-detect the encoding @private@
-- US ASCII
-- ISO-8859-1
-- ISO-8859-2
-- ISO-8859-3
-- ISO-8859-4
-- ISO-8859-5
-- ISO-8859-6
-- ISO-8859-7
-- ISO-8859-8
-- ISO-8859-9
-- ISO-8859-10
-- UTF-8
-- ISO-8859-13
-- ISO-8859-14
-- ISO-8859-15
-- CP-874
-- CP-1250
-- CP-1251
-- CP-1252
-- CP-1253
-- CP-1254
-- CP-1255
-- CP-1256
-- CP-1257
-- CP-1258
-- KOI-8-R
-- KOI-8-U
-- ISO-8859-11
-- ISO-8859-16
-- MacRoman
-- End of single-byte encodings @private@
-- Japanese JIS X0208-1990
-- Simplified Chinese GB 2312-80
-- Korean KS C5601-1992
-- Traditional Chinese Big Five
-- Korean Johab
-- End of double-byte encodings @private@
-- EUC Simplified Chinese
-- EUC Japanese
-- EUC Korean
-- EUC Traditional Chinese
-- JIS X0213 aka Shift JIS
-- End of variable-length encodings @private@
subtype cups_encoding_t is cups_encoding_e;
--*** Language Cache Structure ***
-- Next language in cache
subtype cups_lang_s_language_array is Interfaces.C.char_array (0 .. 15);
type cups_lang_s is record
next : access cups_lang_s; -- cups/language.h:89
used : aliased int; -- cups/language.h:90
encoding : aliased cups_encoding_t; -- cups/language.h:91
language : aliased cups_lang_s_language_array; -- cups/language.h:92
strings : System.Address; -- cups/language.h:93
end record;
pragma Convention (C_Pass_By_Copy, cups_lang_s); -- cups/language.h:87
-- Number of times this entry has been used.
-- Text encoding
-- Language/locale name
-- Message strings @private@
subtype cups_lang_t is cups_lang_s;
-- * Prototypes...
--
-- * "$Id: language.h 10996 2013-05-29 11:51:34Z msweet $"
-- *
-- * Multi-language support for CUPS.
-- *
-- * Copyright 2007-2011 by Apple Inc.
-- * Copyright 1997-2006 by Easy Software Products.
-- *
-- * These coded instructions, statements, and computer programs are the
-- * property of Apple Inc. and are protected by Federal copyright
-- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
-- * which should have been included with this file. If this file is
-- * file is missing or damaged, see the license at "http://www.cups.org/".
-- *
-- * This file is subject to the Apple OS-Developed Software exception.
--
-- * "$Id: language.h 10996 2013-05-29 11:51:34Z msweet $"
-- *
-- * Multi-language support for CUPS.
-- *
-- * Copyright 2007-2011 by Apple Inc.
-- * Copyright 1997-2006 by Easy Software Products.
-- *
-- * These coded instructions, statements, and computer programs are the
-- * property of Apple Inc. and are protected by Federal copyright
-- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
-- * which should have been included with this file. If this file is
-- * file is missing or damaged, see the license at "http://www.cups.org/".
-- *
-- * This file is subject to the Apple OS-Developed Software exception.
--
-- * Include necessary headers...
--
-- * Types...
--
--*** Language Encodings ***
-- Auto-detect the encoding @private@
-- US ASCII
-- ISO-8859-1
-- ISO-8859-2
-- ISO-8859-3
-- ISO-8859-4
-- ISO-8859-5
-- ISO-8859-6
-- ISO-8859-7
-- ISO-8859-8
-- ISO-8859-9
-- ISO-8859-10
-- UTF-8
-- ISO-8859-13
-- ISO-8859-14
-- ISO-8859-15
-- CP-874
-- CP-1250
-- CP-1251
-- CP-1252
-- CP-1253
-- CP-1254
-- CP-1255
-- CP-1256
-- CP-1257
-- CP-1258
-- KOI-8-R
-- KOI-8-U
-- ISO-8859-11
-- ISO-8859-16
-- MacRoman
-- End of single-byte encodings @private@
-- Japanese JIS X0208-1990
-- Simplified Chinese GB 2312-80
-- Korean KS C5601-1992
-- Traditional Chinese Big Five
-- Korean Johab
-- End of double-byte encodings @private@
-- EUC Simplified Chinese
-- EUC Japanese
-- EUC Korean
-- EUC Traditional Chinese
-- JIS X0213 aka Shift JIS
-- End of variable-length encodings @private@
--*** Language Cache Structure ***
-- Next language in cache
-- Number of times this entry has been used.
-- Text encoding
-- Language/locale name
-- Message strings @private@
-- * Prototypes...
--
function cupsLangDefault return access cups_lang_t; -- cups/language.h:101
pragma Import (C, cupsLangDefault, "cupsLangDefault");
function cupsLangEncoding (lang : access cups_lang_t) return Interfaces.C.Strings.chars_ptr; -- cups/language.h:102
pragma Import (C, cupsLangEncoding, "cupsLangEncoding");
procedure cupsLangFlush; -- cups/language.h:103
pragma Import (C, cupsLangFlush, "cupsLangFlush");
procedure cupsLangFree (lang : access cups_lang_t); -- cups/language.h:104
pragma Import (C, cupsLangFree, "cupsLangFree");
function cupsLangGet (language : Interfaces.C.Strings.chars_ptr) return access cups_lang_t; -- cups/language.h:105
pragma Import (C, cupsLangGet, "cupsLangGet");
-- * End of "$Id: language.h 10996 2013-05-29 11:51:34Z msweet $".
--
end CUPS.cups_language_h;
|
-- Copyright (c) 1990 Regents of the University of California.
-- All rights reserved.
--
-- This software was developed by John Self of the Arcadia project
-- at the University of California, Irvine.
--
-- Redistribution and use in source and binary forms are permitted
-- provided that the above copyright notice and this paragraph are
-- duplicated in all such forms and that any documentation,
-- advertising materials, and other materials related to such
-- distribution and use acknowledge that the software was developed
-- by the University of California, Irvine. The name of the
-- University may not be used to endorse or promote products derived
-- from this software without specific prior written permission.
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
-- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-- WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-- TITLE miscellaneous definitions
-- AUTHOR: John Self (UCI)
-- DESCRIPTION contains all global variables used in aflex.
-- also some subprograms which are commonly used.
-- NOTES The real purpose of this file is to contain all miscellaneous
-- items (functions, MACROS, variables definitions) which were at the
-- top level of flex.
-- $Header: /co/ua/self/arcadia/aflex/ada/src/RCS/misc_defsB.a,v 1.5 90/01/12 15:20:21 self Exp Locker: self $
package body misc_defs is
-- returns true if an nfa state has an epsilon out-transition slot
-- that can be used. This definition is currently not used.
function FREE_EPSILON(STATE : in INTEGER) return BOOLEAN is
begin
return ((TRANSCHAR(STATE) = SYM_EPSILON) and (TRANS2(STATE) = NO_TRANSITION)
and (FINALST(STATE) /= STATE));
end FREE_EPSILON;
-- returns true if an nfa state has an epsilon out-transition character
-- and both slots are free
function SUPER_FREE_EPSILON(STATE : in INTEGER) return BOOLEAN is
begin
return ((TRANSCHAR(STATE) = SYM_EPSILON) and (TRANS1(STATE) = NO_TRANSITION)
);
end SUPER_FREE_EPSILON;
function ALLOCATE_INTEGER_ARRAY(SIZE : in INTEGER) return INT_PTR is
begin
return new UNBOUNDED_INT_ARRAY(0 .. SIZE);
end ALLOCATE_INTEGER_ARRAY;
procedure REALLOCATE_INTEGER_ARRAY(ARR : in out INT_PTR;
SIZE : in INTEGER) is
NEW_ARR : INT_PTR;
begin
NEW_ARR := ALLOCATE_INTEGER_ARRAY(SIZE);
NEW_ARR(0 .. ARR'LAST) := ARR(0 .. ARR'LAST);
ARR := NEW_ARR;
end REALLOCATE_INTEGER_ARRAY;
procedure REALLOCATE_STATE_ENUM_ARRAY(ARR : in out STATE_ENUM_PTR;
SIZE : in INTEGER) is
NEW_ARR : STATE_ENUM_PTR;
begin
NEW_ARR := ALLOCATE_STATE_ENUM_ARRAY(SIZE);
NEW_ARR(0 .. ARR'LAST) := ARR(0 .. ARR'LAST);
ARR := NEW_ARR;
end REALLOCATE_STATE_ENUM_ARRAY;
procedure REALLOCATE_RULE_ENUM_ARRAY(ARR : in out RULE_ENUM_PTR;
SIZE : in INTEGER) is
NEW_ARR : RULE_ENUM_PTR;
begin
NEW_ARR := ALLOCATE_RULE_ENUM_ARRAY(SIZE);
NEW_ARR(0 .. ARR'LAST) := ARR(0 .. ARR'LAST);
ARR := NEW_ARR;
end REALLOCATE_RULE_ENUM_ARRAY;
function ALLOCATE_INT_PTR_ARRAY(SIZE : in INTEGER) return INT_STAR_PTR is
begin
return new UNBOUNDED_INT_STAR_ARRAY(0 .. SIZE);
end ALLOCATE_INT_PTR_ARRAY;
function ALLOCATE_RULE_ENUM_ARRAY(SIZE : in INTEGER) return RULE_ENUM_PTR is
begin
return new UNBOUNDED_RULE_ENUM_ARRAY(0 .. SIZE);
end ALLOCATE_RULE_ENUM_ARRAY;
function ALLOCATE_STATE_ENUM_ARRAY(SIZE : in INTEGER) return STATE_ENUM_PTR
is
begin
return new UNBOUNDED_STATE_ENUM_ARRAY(0 .. SIZE);
end ALLOCATE_STATE_ENUM_ARRAY;
function ALLOCATE_BOOLEAN_ARRAY(SIZE : in INTEGER) return BOOLEAN_PTR is
begin
return new BOOLEAN_ARRAY(0 .. SIZE);
end ALLOCATE_BOOLEAN_ARRAY;
function ALLOCATE_VSTRING_ARRAY(SIZE : in INTEGER) return VSTRING_PTR is
begin
return new UNBOUNDED_VSTRING_ARRAY(0 .. SIZE);
end ALLOCATE_VSTRING_ARRAY;
function ALLOCATE_DFAACC_UNION(SIZE : in INTEGER) return DFAACC_PTR is
begin
return new UNBOUNDED_DFAACC_ARRAY(0 .. SIZE);
end ALLOCATE_DFAACC_UNION;
procedure REALLOCATE_INT_PTR_ARRAY(ARR : in out INT_STAR_PTR;
SIZE : in INTEGER) is
NEW_ARR : INT_STAR_PTR;
begin
NEW_ARR := ALLOCATE_INT_PTR_ARRAY(SIZE);
NEW_ARR(0 .. ARR'LAST) := ARR(0 .. ARR'LAST);
ARR := NEW_ARR;
end REALLOCATE_INT_PTR_ARRAY;
procedure REALLOCATE_CHARACTER_ARRAY(ARR : in out CHAR_PTR;
SIZE : in INTEGER) is
NEW_ARR : CHAR_PTR;
begin
NEW_ARR := ALLOCATE_CHARACTER_ARRAY(SIZE);
NEW_ARR(0 .. ARR'LAST) := ARR(0 .. ARR'LAST);
ARR := NEW_ARR;
end REALLOCATE_CHARACTER_ARRAY;
procedure REALLOCATE_VSTRING_ARRAY(ARR : in out VSTRING_PTR;
SIZE : in INTEGER) is
NEW_ARR : VSTRING_PTR;
begin
NEW_ARR := ALLOCATE_VSTRING_ARRAY(SIZE);
NEW_ARR(0 .. ARR'LAST) := ARR(0 .. ARR'LAST);
ARR := NEW_ARR;
end REALLOCATE_VSTRING_ARRAY;
function ALLOCATE_CHARACTER_ARRAY(SIZE : in INTEGER) return CHAR_PTR is
begin
return new CHAR_ARRAY(0 .. SIZE);
end ALLOCATE_CHARACTER_ARRAY;
procedure REALLOCATE_DFAACC_UNION(ARR : in out DFAACC_PTR;
SIZE : in INTEGER) is
NEW_ARR : DFAACC_PTR;
begin
NEW_ARR := ALLOCATE_DFAACC_UNION(SIZE);
NEW_ARR(0 .. ARR'LAST) := ARR(0 .. ARR'LAST);
ARR := NEW_ARR;
end REALLOCATE_DFAACC_UNION;
procedure REALLOCATE_BOOLEAN_ARRAY(ARR : in out BOOLEAN_PTR;
SIZE : in INTEGER) is
NEW_ARR : BOOLEAN_PTR;
begin
NEW_ARR := ALLOCATE_BOOLEAN_ARRAY(SIZE);
NEW_ARR(0 .. ARR'LAST) := ARR(0 .. ARR'LAST);
ARR := NEW_ARR;
end REALLOCATE_BOOLEAN_ARRAY;
function MAX(X, Y : in INTEGER) return INTEGER is
begin
if (X > Y) then
return X;
else
return Y;
end if;
end MAX;
function MIN(X, Y : in INTEGER) return INTEGER is
begin
if (X < Y) then
return X;
else
return Y;
end if;
end MIN;
end misc_defs;
|
------------------------------------------------------------------------------
-- 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 Asis.Gela.Lists; use Asis.Gela.Lists;
with Asis.Gela.Compilations;
package Asis.Gela.Elements.Helpers is
-----------------------
-- Fake_Element_Node --
-----------------------
type Fake_Element_Node is abstract
new Element_Node with private;
type Fake_Element_Ptr is
access all Fake_Element_Node;
for Fake_Element_Ptr'Storage_Pool use Lists.Pool;
function Start_Position
(Element : Fake_Element_Node) return Asis.Text_Position;
procedure Set_Start_Position
(Element : in out Fake_Element_Node;
Value : in Asis.Text_Position);
----------------
-- Token_Node --
----------------
type Token_Node is
new Fake_Element_Node with private;
type Token_Ptr is
access all Token_Node;
for Token_Ptr'Storage_Pool use Lists.Pool;
function New_Token_Node
(The_Context : ASIS.Context)
return Token_Ptr;
function End_Position
(Element : Token_Node) return Asis.Text_Position;
procedure Set_End_Position
(Element : in out Token_Node;
Value : in Asis.Text_Position);
function Raw_Image
(Element : Token_Node) return Gela_String;
procedure Set_Raw_Image
(Element : in out Token_Node;
Value : in Gela_String);
function Clone
(Element : Token_Node;
Parent : Asis.Element)
return Asis.Element;
----------------------------
-- Private_Indicator_Node --
----------------------------
type Private_Indicator_Node is
new Fake_Element_Node with private;
type Private_Indicator_Ptr is
access all Private_Indicator_Node;
for Private_Indicator_Ptr'Storage_Pool use Lists.Pool;
function New_Private_Indicator_Node
(The_Context : ASIS.Context)
return Private_Indicator_Ptr;
function Next_Element
(Element : Private_Indicator_Node) return Asis.Element;
procedure Set_Next_Element
(Element : in out Private_Indicator_Node;
Value : in Asis.Element);
function End_Position
(Element : Private_Indicator_Node) return Asis.Text_Position;
procedure Set_End_Position
(Element : in out Private_Indicator_Node;
Value : in Asis.Text_Position);
function Clone
(Element : Private_Indicator_Node;
Parent : Asis.Element)
return Asis.Element;
-----------------------------
-- Handled_Statements_Node --
-----------------------------
type Handled_Statements_Node is
new Fake_Element_Node with private;
type Handled_Statements_Ptr is
access all Handled_Statements_Node;
for Handled_Statements_Ptr'Storage_Pool use Lists.Pool;
function New_Handled_Statements_Node
(The_Context : ASIS.Context)
return Handled_Statements_Ptr;
function Statements
(Element : Handled_Statements_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
procedure Set_Statements
(Element : in out Handled_Statements_Node;
Value : in Asis.Element);
function Statements_List
(Element : Handled_Statements_Node) return Asis.Element;
function Exception_Handlers
(Element : Handled_Statements_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
procedure Set_Exception_Handlers
(Element : in out Handled_Statements_Node;
Value : in Asis.Element);
function Exception_Handlers_List
(Element : Handled_Statements_Node) return Asis.Element;
function Get_Identifier
(Element : Handled_Statements_Node) return Asis.Element;
procedure Set_Identifier
(Element : in out Handled_Statements_Node;
Value : in Asis.Element);
function End_Position
(Element : Handled_Statements_Node) return Asis.Text_Position;
procedure Set_End_Position
(Element : in out Handled_Statements_Node;
Value : in Asis.Text_Position);
function Clone
(Element : Handled_Statements_Node;
Parent : Asis.Element)
return Asis.Element;
---------------------------
-- Function_Profile_Node --
---------------------------
type Function_Profile_Node is
new Fake_Element_Node with private;
type Function_Profile_Ptr is
access all Function_Profile_Node;
for Function_Profile_Ptr'Storage_Pool use Lists.Pool;
function New_Function_Profile_Node
(The_Context : ASIS.Context)
return Function_Profile_Ptr;
function Parameter_Profile
(Element : Function_Profile_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
procedure Set_Parameter_Profile
(Element : in out Function_Profile_Node;
Value : in Asis.Element);
function Parameter_Profile_List
(Element : Function_Profile_Node) return Asis.Element;
function Result_Profile
(Element : Function_Profile_Node) return Asis.Expression;
procedure Set_Result_Profile
(Element : in out Function_Profile_Node;
Value : in Asis.Expression);
function End_Position
(Element : Function_Profile_Node) return Asis.Text_Position;
procedure Set_End_Position
(Element : in out Function_Profile_Node;
Value : in Asis.Text_Position);
function Clone
(Element : Function_Profile_Node;
Parent : Asis.Element)
return Asis.Element;
----------------------------------
-- Procedure_Specification_Node --
----------------------------------
type Procedure_Specification_Node is
new Fake_Element_Node with private;
type Procedure_Specification_Ptr is
access all Procedure_Specification_Node;
for Procedure_Specification_Ptr'Storage_Pool use Lists.Pool;
function New_Procedure_Specification_Node
(The_Context : ASIS.Context)
return Procedure_Specification_Ptr;
function Names
(Element : Procedure_Specification_Node) return Asis.Element;
procedure Set_Names
(Element : in out Procedure_Specification_Node;
Value : in Asis.Element);
function Profile
(Element : Procedure_Specification_Node) return Asis.Element;
procedure Set_Profile
(Element : in out Procedure_Specification_Node;
Value : in Asis.Element);
function End_Position
(Element : Procedure_Specification_Node) return Asis.Text_Position;
procedure Set_End_Position
(Element : in out Procedure_Specification_Node;
Value : in Asis.Text_Position);
function Clone
(Element : Procedure_Specification_Node;
Parent : Asis.Element)
return Asis.Element;
---------------------------------
-- Function_Specification_Node --
---------------------------------
type Function_Specification_Node is
new Procedure_Specification_Node with private;
type Function_Specification_Ptr is
access all Function_Specification_Node;
for Function_Specification_Ptr'Storage_Pool use Lists.Pool;
function New_Function_Specification_Node
(The_Context : ASIS.Context)
return Function_Specification_Ptr;
function Clone
(Element : Function_Specification_Node;
Parent : Asis.Element)
return Asis.Element;
--------------------------------
-- Package_Specification_Node --
--------------------------------
type Package_Specification_Node is
new Fake_Element_Node with private;
type Package_Specification_Ptr is
access all Package_Specification_Node;
for Package_Specification_Ptr'Storage_Pool use Lists.Pool;
function New_Package_Specification_Node
(The_Context : ASIS.Context)
return Package_Specification_Ptr;
function Names
(Element : Package_Specification_Node) return Asis.Element;
procedure Set_Names
(Element : in out Package_Specification_Node;
Value : in Asis.Element);
function Visible_Part_Declarative_Items
(Element : Package_Specification_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
procedure Set_Visible_Part_Declarative_Items
(Element : in out Package_Specification_Node;
Value : in Asis.Element);
function Visible_Part_Declarative_Items_List
(Element : Package_Specification_Node) return Asis.Element;
function Private_Part_Declarative_Items
(Element : Package_Specification_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
procedure Set_Private_Part_Declarative_Items
(Element : in out Package_Specification_Node;
Value : in Asis.Element);
function Private_Part_Declarative_Items_List
(Element : Package_Specification_Node) return Asis.Element;
function Compound_Name
(Element : Package_Specification_Node) return Asis.Element;
procedure Set_Compound_Name
(Element : in out Package_Specification_Node;
Value : in Asis.Element);
function End_Position
(Element : Package_Specification_Node) return Asis.Text_Position;
procedure Set_End_Position
(Element : in out Package_Specification_Node;
Value : in Asis.Text_Position);
function Clone
(Element : Package_Specification_Node;
Parent : Asis.Element)
return Asis.Element;
private
type Fake_Element_Node is abstract
new Element_Node with
record
Start_Position : aliased Asis.Text_Position;
end record;
type Token_Node is
new Fake_Element_Node with
record
End_Position : aliased Asis.Text_Position;
Raw_Image : aliased Gela_String;
end record;
type Private_Indicator_Node is
new Fake_Element_Node with
record
Next_Element : aliased Asis.Element;
End_Position : aliased Asis.Text_Position;
end record;
type Handled_Statements_Node is
new Fake_Element_Node with
record
Statements : aliased Primary_Statement_Lists.List;
Exception_Handlers : aliased Primary_Handler_Lists.List;
Identifier : aliased Asis.Element;
End_Position : aliased Asis.Text_Position;
end record;
type Function_Profile_Node is
new Fake_Element_Node with
record
Parameter_Profile : aliased Primary_Parameter_Lists.List;
Result_Profile : aliased Asis.Expression;
End_Position : aliased Asis.Text_Position;
end record;
type Procedure_Specification_Node is
new Fake_Element_Node with
record
Names : aliased Asis.Element;
Profile : aliased Asis.Element;
End_Position : aliased Asis.Text_Position;
end record;
type Function_Specification_Node is
new Procedure_Specification_Node with
record
null;
end record;
type Package_Specification_Node is
new Fake_Element_Node with
record
Names : aliased Asis.Element;
Visible_Part_Declarative_Items : aliased Primary_Declaration_Lists.List;
Private_Part_Declarative_Items : aliased Primary_Declaration_Lists.List;
Compound_Name : aliased Asis.Element;
End_Position : aliased Asis.Text_Position;
end record;
end Asis.Gela.Elements.Helpers;
|
with Ada.Real_Time;
with ACO.States;
with ACO.Messages;
with ACO.OD;
private with ACO.Utils.Generic_Alarms;
private with ACO.Configuration;
package ACO.Slave_Monitors is
type Slave_Monitor (Od : not null access ACO.OD.Object_Dictionary'Class) is
tagged limited private;
type Slave_Monitor_Ref is access all Slave_Monitor'Class;
function Is_Monitored
(This : Slave_Monitor;
Node_Id : ACO.Messages.Slave_Node_Nr)
return Boolean;
function Get_State
(This : Slave_Monitor;
Node_Id : ACO.Messages.Slave_Node_Nr)
return ACO.States.State
with Pre => This.Is_Monitored (Node_Id);
procedure Restart
(This : in out Slave_Monitor;
T_Now : in Ada.Real_Time.Time);
procedure Start
(This : in out Slave_Monitor;
Node_Id : in ACO.Messages.Slave_Node_Nr;
Slave_State : in ACO.States.State;
T_Now : in Ada.Real_Time.Time)
with Pre => not This.Is_Monitored (Node_Id);
procedure Update_State
(This : in out Slave_Monitor;
Node_Id : in ACO.Messages.Slave_Node_Nr;
Slave_State : in ACO.States.State;
T_Now : in Ada.Real_Time.Time)
with Pre => This.Is_Monitored (Node_Id);
procedure Update_Alarms
(This : in out Slave_Monitor;
T_Now : in Ada.Real_Time.Time);
private
package Alarms is new ACO.Utils.Generic_Alarms
(Maximum_Nof_Alarms => ACO.Configuration.Max_Nof_Heartbeat_Slaves);
type Slave_Alarm
(Ref : access Slave_Monitor := null)
is new Alarms.Alarm_Type with record
Node_Id : ACO.Messages.Node_Nr;
Slave_State : ACO.States.State_Transition;
end record;
overriding
procedure Signal
(This : access Slave_Alarm;
T_Now : in Ada.Real_Time.Time);
type Slaves_Array is array (Positive range <>) of aliased Slave_Alarm;
type Slave_Monitor (Od : not null access ACO.OD.Object_Dictionary'Class) is
tagged limited
record
Manager : Alarms.Alarm_Manager;
Slaves : Slaves_Array (1 .. ACO.Configuration.Max_Nof_Heartbeat_Slaves) :=
(others => (Slave_Monitor'Access,
ACO.Messages.Not_A_Slave,
(ACO.States.Unknown_State, ACO.States.Unknown_State)));
end record;
end ACO.Slave_Monitors;
|
with System;
package Self is
type Lim is limited private;
type Lim_Ref is access all Lim;
function G (X : Integer) return lim;
procedure Change (X : in out Lim; Incr : Integer);
function Get (X : Lim) return Integer;
private
type Lim is limited record
Comp : Integer;
Self_Default : Lim_Ref := Lim'Unchecked_Access;
Self_Unrestricted_Default : Lim_Ref := Lim'Unrestricted_Access;
Self_Anon_Default : access Lim := Lim'Unchecked_Access;
Self_Anon_Unrestricted_Default : access Lim := Lim'Unrestricted_Access;
end record;
end Self;
|
with
chat.Client.local,
lace.Event.utility,
ada.Characters.latin_1,
ada.command_Line,
ada.Text_IO,
ada.Exceptions;
procedure launch_simple_chat_Client
--
-- Starts a chat client.
--
is
use ada.Text_IO;
begin
-- Usage
--
if ada.command_Line.argument_Count /= 1
then
put_Line ("Usage: $ ./launch_simple_chat_Client <nickname>");
return;
end if;
declare
use chat.Client.local;
client_Name : constant String := ada.command_Line.Argument (1);
the_Client : chat.Client.local.item := to_Client (client_Name);
begin
the_Client.start;
end;
exception
when E : others =>
lace.Event.utility.close;
new_Line;
put_Line ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
put_Line ("Unhandled exception, aborting. Please report the following to developer.");
put_Line ("________________________________________________________________________");
put_Line (ada.Exceptions.exception_Information (E));
put (ada.Characters.latin_1.ESC & "[1A"); -- Move cursor up.
put_Line ("________________________________________________________________________");
new_Line;
end launch_simple_chat_Client;
|
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;
with PW;
use PW;
procedure Main is
EQ : EntryQueue;
DC : DistributorCollection;
begin
Initialize(DC);
Data.SendDC(DC);
Data.SendQueue(EQ);
end Main;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . S T R I N G S . U T F _ E N C O D I N G --
-- --
-- B o d y --
-- --
-- Copyright (C) 2010, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package body Ada.Strings.UTF_Encoding is
use Interfaces;
--------------
-- Encoding --
--------------
function Encoding
(Item : UTF_String;
Default : Encoding_Scheme := UTF_8) return Encoding_Scheme
is
begin
if Item'Length >= 2 then
if Item (Item'First .. Item'First + 1) = BOM_16BE then
return UTF_16BE;
elsif Item (Item'First .. Item'First + 1) = BOM_16LE then
return UTF_16LE;
elsif Item'Length >= 3
and then Item (Item'First .. Item'First + 2) = BOM_8
then
return UTF_8;
end if;
end if;
return Default;
end Encoding;
-----------------
-- From_UTF_16 --
-----------------
function From_UTF_16
(Item : UTF_16_Wide_String;
Output_Scheme : UTF_XE_Encoding;
Output_BOM : Boolean := False) return UTF_String
is
BSpace : constant Natural := 2 * Boolean'Pos (Output_BOM);
Result : UTF_String (1 .. 2 * Item'Length + BSpace);
Len : Natural;
C : Unsigned_16;
Iptr : Natural;
begin
if Output_BOM then
Result (1 .. 2) :=
(if Output_Scheme = UTF_16BE then BOM_16BE else BOM_16LE);
Len := 2;
else
Len := 0;
end if;
-- Skip input BOM
Iptr := Item'First;
if Iptr <= Item'Last and then Item (Iptr) = BOM_16 (1) then
Iptr := Iptr + 1;
end if;
-- UTF-16BE case
if Output_Scheme = UTF_16BE then
while Iptr <= Item'Last loop
C := To_Unsigned_16 (Item (Iptr));
Result (Len + 1) := Character'Val (Shift_Right (C, 8));
Result (Len + 2) := Character'Val (C and 16#00_FF#);
Len := Len + 2;
Iptr := Iptr + 1;
end loop;
-- UTF-16LE case
else
while Iptr <= Item'Last loop
C := To_Unsigned_16 (Item (Iptr));
Result (Len + 1) := Character'Val (C and 16#00_FF#);
Result (Len + 2) := Character'Val (Shift_Right (C, 8));
Len := Len + 2;
Iptr := Iptr + 1;
end loop;
end if;
return Result (1 .. Len);
end From_UTF_16;
--------------------------
-- Raise_Encoding_Error --
--------------------------
procedure Raise_Encoding_Error (Index : Natural) is
Val : constant String := Index'Img;
begin
raise Encoding_Error with
"bad input at Item (" & Val (Val'First + 1 .. Val'Last) & ')';
end Raise_Encoding_Error;
---------------
-- To_UTF_16 --
---------------
function To_UTF_16
(Item : UTF_String;
Input_Scheme : UTF_XE_Encoding;
Output_BOM : Boolean := False) return UTF_16_Wide_String
is
Result : UTF_16_Wide_String (1 .. Item'Length / 2 + 1);
Len : Natural;
Iptr : Natural;
begin
if Item'Length mod 2 /= 0 then
raise Encoding_Error with "UTF-16BE/LE string has odd length";
end if;
-- Deal with input BOM, skip if OK, error if bad BOM
Iptr := Item'First;
if Item'Length >= 2 then
if Item (Iptr .. Iptr + 1) = BOM_16BE then
if Input_Scheme = UTF_16BE then
Iptr := Iptr + 2;
else
Raise_Encoding_Error (Iptr);
end if;
elsif Item (Iptr .. Iptr + 1) = BOM_16LE then
if Input_Scheme = UTF_16LE then
Iptr := Iptr + 2;
else
Raise_Encoding_Error (Iptr);
end if;
elsif Item'Length >= 3 and then Item (Iptr .. Iptr + 2) = BOM_8 then
Raise_Encoding_Error (Iptr);
end if;
end if;
-- Output BOM if specified
if Output_BOM then
Result (1) := BOM_16 (1);
Len := 1;
else
Len := 0;
end if;
-- UTF-16BE case
if Input_Scheme = UTF_16BE then
while Iptr < Item'Last loop
Len := Len + 1;
Result (Len) :=
Wide_Character'Val
(Character'Pos (Item (Iptr)) * 256 +
Character'Pos (Item (Iptr + 1)));
Iptr := Iptr + 2;
end loop;
-- UTF-16LE case
else
while Iptr < Item'Last loop
Len := Len + 1;
Result (Len) :=
Wide_Character'Val
(Character'Pos (Item (Iptr)) +
Character'Pos (Item (Iptr + 1)) * 256);
Iptr := Iptr + 2;
end loop;
end if;
return Result (1 .. Len);
end To_UTF_16;
end Ada.Strings.UTF_Encoding;
|
-- Ada regular expression library
-- (c) Kristian Klomsten Skordal 2020 <kristian.skordal@wafflemail.net>
-- Report bugs and issues on <https://github.com/skordal/ada-regex>
package Regex.Utilities is
pragma Pure;
end Regex.Utilities;
|
-- { dg-do compile }
with Interfaces.C; use Interfaces.C;
procedure Object_Overflow1 is
procedure Proc (x : Boolean) is begin null; end;
type Arr is array(ptrdiff_t) of Boolean;
Obj : Arr; -- { dg-warning "Storage_Error" }
begin
Obj(1) := True;
Proc (Obj(1));
end;
|
-- C97201X.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 NO RENDEZVOUS CAN EVER OCCUR IF BOTH PARTNERS REFUSE TO
-- WAIT (THAT IS, IF THE ENTRY CALL IS ISSUED BY A
-- "CONDITIONAL_ENTRY_CALL" AND THUS FOLLOWS A NO-WAIT POLICY
-- (DEMANDING UNCONDITIONALLY THAT "YOU DO IT N O W , OR ELSE"),
-- WHILE THE CALLEE IS ALSO COMMITTED TO A NO-WAIT POLICY,
-- BY VIRTUE OF A SELECTIVE_WAIT STATEMENT OF THE THIRD KIND
-- (WITH AN "ELSE" PART) IN WHICH THE CORRESPONDING ACCEPT_STATEMENT
-- IS EMBEDDED).
-- ("CLOSE ENCOUNTERS OF THE THIRD KIND" -- ARE THEY POSSIBLE?)
-- THE SEMANTICS OF THIS ENTRY CALL REQUIRES THAT THE CALLING TASK
-- N O T ENTER ITSELF ON ANY QUEUE BUT RATHER ATTEMPT AN IMMEDIATE
-- RENDEZVOUS WHICH IS TO TAKE PLACE IF AND ONLY IF THE CALLED TASK
-- HAS REACHED A POINT WHERE IT IS READY TO ACCEPT THE CALL (I.E.
-- IT IS EITHER WAITING AT AN ACCEPT STATEMENT FOR THE CORRESPONDING
-- ENTRY OR IT IS WAITING AT A SELECTIVE_WAIT STATEMENT WITH AN OPEN
-- ALTERNATIVE STARTING WITH SUCH AN ACCEPT STATEMENT). IT ALSO
-- REQUIRES THAT THE ENTRY CALL BE CANCELLED IF THE CALLED TASK
-- IS NOT AT SUCH A POINT. ON THE OTHER HAND, THE SEMANTICS OF THE
-- SELECTIVE_WAIT STATEMENT WITH AN 'ELSE' PART SPECIFIES THAT
-- THE 'ELSE' PART MUST BE SELECTED IF NO 'ACCEPT' ALTERNATIVE
-- CAN BE IMMEDIATELY SELECTED, AND THAT SUCH AN ALTERNATIVE
-- IS DEEMED TO BE IMMEDIATELY SELECTABLE ("SELECTION OF ONE SUCH
-- ALTERNATIVE OCCURS IMMEDIATELY"), AND A CORRESPONDING RENDEZVOUS
-- POSSIBLE, IF AND ONLY IF THERE IS A CORRESPONDING ENTRY CALL
-- W A I T I N G TO BE ACCCEPTED. A "CONDITIONAL ENTRY CALL"
-- NEVER WAITS, AND IS NEVER ENTERED IN WAIT QUEUES; IT TAKES
-- THE 'ELSE' PART INSTEAD.
-- NOTE: IF THIS TEST PROGRAM HANGS UP, THE COMPILER WILL BE DEEMED
-- TO HAVE FAILED.
-- RM 3/19/82
WITH REPORT; USE REPORT;
PROCEDURE C97201X IS
RENDEZVOUS_OCCURRED : BOOLEAN := FALSE ;
CALLER_TAKES_WRONG_BRANCH : BOOLEAN := TRUE ;
SERVER_TAKES_WRONG_BRANCH : BOOLEAN := TRUE ;
QUEUE_NOT_EMPTY : BOOLEAN := FALSE ;
BEGIN
TEST ("C97201X", "CHECK THAT NO RENDEZVOUS CAN EVER OCCUR IF" &
" BOTH PARTNERS REFUSE TO WAIT" );
DECLARE
TASK T IS
ENTRY SYNCHRONIZE ;
ENTRY DO_IT_NOW_ORELSE( DID_YOU_DO_IT : IN OUT BOOLEAN);
ENTRY KEEP_ALIVE ;
END T ;
TASK BODY T IS
BEGIN
ACCEPT SYNCHRONIZE ;
IF DO_IT_NOW_ORELSE'COUNT /= 0 THEN
QUEUE_NOT_EMPTY := TRUE ;
END IF;
SELECT
ACCEPT DO_IT_NOW_ORELSE
( DID_YOU_DO_IT : IN OUT BOOLEAN )
DO
DID_YOU_DO_IT := TRUE ;
END ;
ELSE -- (I.E. TASK ADOPTS NO-WAIT POLICY)
-- 'ELSE' BRANCH MUST THEREFORE BE CHOSEN
SERVER_TAKES_WRONG_BRANCH := FALSE ;
END SELECT;
IF DO_IT_NOW_ORELSE'COUNT /= 0 THEN
QUEUE_NOT_EMPTY := TRUE ;
END IF;
ACCEPT KEEP_ALIVE ; -- TO PREVENT THIS SERVER TASK FROM
-- TERMINATING IF IT GETS TO
-- THE NO-WAIT MEETING-PLACE
-- AHEAD OF THE CALLER (WHICH
-- WOULD LEAD TO A SUBSEQUENT
-- TASKING_ERROR AT THE TIME OF
-- THE NO-WAIT CALL).
END T ;
BEGIN
T.SYNCHRONIZE ; -- TO MINIMIZE THE N E E D TO WAIT
SELECT
T.DO_IT_NOW_ORELSE ( RENDEZVOUS_OCCURRED );
ELSE -- (I.E. CALLER TOO ADOPTS A NO-WAIT POLICY)
-- MUST THEREFORE CHOOSE THIS BRANCH
CALLER_TAKES_WRONG_BRANCH := FALSE ;
END SELECT;
T.KEEP_ALIVE ; -- THIS ALSO UPDATES THE NONLOCALS
END; -- END OF BLOCK CONTAINING THE NO-WAIT ENTRY CALL
IF RENDEZVOUS_OCCURRED
THEN
FAILED( "RENDEZVOUS OCCURRED" );
END IF;
IF CALLER_TAKES_WRONG_BRANCH OR
SERVER_TAKES_WRONG_BRANCH
THEN
FAILED( "WRONG BRANCH TAKEN" );
END IF;
IF QUEUE_NOT_EMPTY
THEN
FAILED( "ENTRY QUEUE NOT EMPTY" );
END IF;
RESULT;
END C97201X ;
|
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;
with Unchecked_Deallocation;
package body lists is
procedure Free is new Unchecked_Deallocation(Element,P_List);
function Create_List(Elements: Tab_Of_List_Type) return List is
L :List := (First_Element => null);
begin
for i in Elements'Range loop --add every number of the array into the list
L.Append(Elements(i));
end loop;
return L;
end Create_List;
procedure Append(Self: in out List; Data: T_Data) is
aux: P_List := Self.First_Element;
begin
if aux = null then --return a new list if its empty
Self.First_Element := new Element'(info => Data,
suiv => null);
else --go to the last element (next element = null) and add a new wlement with the new data
while aux.all.suiv /= null loop
aux := aux.all.suiv;
end loop;
aux.all.suiv := new Element'(info => Data,
suiv => null);
end if;
end Append;
function Length(Self:in List) return Natural is
len: Natural := 0;
aux: P_List := Self.First_Element;
begin
if aux /= null then
len := len + 1;
while aux.all.suiv /= null loop
aux:= aux.all.suiv;
len := len + 1;
end loop;
end if;
return len;
end Length;
function get(Self:in List; Index: Integer) return T_Data is
begin
return Self.get_pointer(Index => Index).all.info;
end get;
function Image(Self: in out List) return String is
aux: P_List := Self.First_Element;
img: Unbounded_String;
index : Integer := 1;
begin
img := To_Unbounded_String("[");
if aux /= null then
while aux.all.suiv /= null loop
img := img & To_Unbounded_String(Data_Image(aux.all.info) & ", ");
aux := aux.all.suiv;
end loop;
img := img & To_Unbounded_String(Data_Image(aux.all.info));
end if;
img := img & "]";
return To_String(img);
end Image;
procedure Set(Self:in out List; Index :Integer; New_Value: T_Data) is
begin
Self.get_pointer(Index => Index).all.info := New_Value;
end Set;
procedure Remove_Element(Self: in out List; Element: T_Data) is
pre, aux, rec: P_List;
begin
if Self.First_Element = null then
raise Element_not_in_the_list;
elsif Self.First_Element.all.info = Element then
rec:= Self.First_Element;
Self.First_Element := Self.First_Element.all.suiv;
Free(rec);
else
pre:= Self.First_Element;
aux:=Self.First_Element.all.suiv;
while aux /= null and then aux.all.info /= Element loop
pre:= aux;
aux:= aux.all.suiv;
end loop;
if aux /= null then
rec := aux;
pre.all.suiv:= aux.all.suiv;
Free(rec);
end if;
end if;
end Remove_Element;
procedure Remove_Nth_Element(Self: in out List; Index: Integer) is
aux : P_List := Self.First_Element;
rec : P_List := null;
begin
if aux = null or Index > Self.Length then --the list is null
raise Get_Index_Value_Outside_the_list;
elsif Index = 1 then --its the firs element on the list
Delete_Object(aux.all.info);
Self.First_Element := aux.all.suiv;
Free(aux);
elsif Index = Self.Length then --its the last element on the list
aux := Self.get_pointer(Index => Index - 1);
Delete_Object(aux.all.suiv.all.info);
Free(aux.all.suiv);
aux.all.suiv := null;
else -- its one element of the list, not ht efirst not the last
aux := Self.get_pointer(Index - 1);
rec := aux.all.suiv;
aux.all.suiv := rec.all.suiv;
Delete_Object(rec.all.info);
Free(rec);
end if;
end Remove_Nth_Element;
function get_pointer(Self: in List; Index: Integer) return P_List is
aux : P_List := Self.First_Element;
begin
if Index > Self.Length then
raise Get_Index_Value_Outside_the_list;
elsif Index < 0 then
raise Get_Index_value_negative_not_implemented_yet;
end if;
for i in 2..Index loop
aux:= aux.all.suiv;
end loop;
return aux;
end get_pointer;
procedure Empty(Self: in out List) is
--empties all the list and frees the memory mostly used to instance in a list which contains lists
rec : P_List := null;
aux : P_List := Self.First_Element;
begin
for i in 1..Self.Length loop
rec := aux;
aux := aux.all.suiv;
Delete_Object(rec.all.info);
Free (rec);
end loop;
end Empty;
function "+"(L,R : List) return List is
--appends the second list to the first and returns the whole list
res: List := (First_Element => null);
aux: P_List := L.First_Element;
begin
for i in 1..L.Length loop
res.Append(L.get(i));
end loop;
for i in 1..R.Length loop
res.Append(R.get(i));
end loop;
return res;
end "+";
function "="(L,R: List) return Boolean is
res: Boolean := False;
auxL:P_List := L.First_Element;
auxR: P_List := R.First_Element;
begin
if L.Length = R.Length then
res := True;
while res and auxL /= null loop
res := auxL.all.info = auxR.all.info;
auxL := auxL.all.suiv;
auxR := auxR.all.suiv;
end loop;
end if;
return res;
end "=";
function Index(Self: in List; Element : T_Data) return Integer is
aux: P_List := Self.First_Element;
Index : Integer := 1;
begin
while aux /= null and then aux.all.info /= Element loop
aux := aux.all.suiv;
index := Index + 1;
end loop;
if aux = null then
raise Element_not_in_the_list;
end if;
return Index;
end Index;
end lists;
|
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; use Ada;
with Ada.Command_Line.Environment;
procedure Startxterminal 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;
-- package OS renames gnat.os_lib;
-- 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_Session_Management_Callbacks : Boolean := False;
Xterm_Loginshell : Boolean := False;
-- Xterm_Font : String := "adobe-source code pro*";
-- Xterm_Font : String := "gnu-unifont*";
Xterm_Font : String := "gnu-unifont*";
Xterm_Font_Size : String := "9";
Xterm_Lineshistory : String := "4000";
Xterm_Cursorcolor : String := "yellow";
Xterm_Geometry : String := "200x50+-128+-128";
-- Xterm_Geometry : String := "260x70+-128+-128";
Xterm_Border : String := "256";
Launch_Num_Of_Arguments : Integer := 15;
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 .. Launch_Num_Of_Arguments);
Launch_Arguments : GNAT.OS_Lib.Argument_List :=
(new String'("-bg"),
new String'(Xterm_Background),
new String'("-fg"),
new String'(Xterm_Foreground),
(if Xterm_Scrollbar then new String'("-sb") else new String'("+sb")),
(if Xterm_Session_Management_Callbacks then new String'("-sm")
else new String'("+sm")),
(if Xterm_Loginshell then new String'("-ls") else new String'("+ls")),
new String'("-fs"),
new String'(Xterm_Font_Size),
new String'("-fn"),
new String'
("-gnu-unifont-medium-r-normal-sans-16-160-75-75-c-80-iso10646-1"),
-- new String'("-fa"),
-- new String'(Xterm_Font),
new String'("-sl"),
new String'(Xterm_Lineshistory),
new String'("-cr"),
new String'(Xterm_Cursorcolor),
new String'("-geometry"),
new String'(Xterm_Geometry),
new String'("-b"),
new String'(Xterm_Border),
new String'("-xrm"),
new String'("*overrideRedirect: True"));
-- (1 ..
-- (if Argument_Count = 0 then Launch_Num_Of_Arguments
-- else Launch_Num_Of_Arguments + 2));
-- The arguments to give the executable
Launch_Status : Boolean;
-- The return status of the command + arguments
function Command_Arguments return GNAT.OS_Lib.Argument_List is
Empty_Words : GNAT.OS_Lib.Argument_List (1 .. 0) := (others => null);
Command_Words : GNAT.OS_Lib.Argument_List (1 .. 2) := (others => null);
function More (X : Integer := 0; S : String := "") return String is
Arg_Ind : Integer := X + 1;
Sp : String := (if S'Length = 0 then "" else " ");
begin
null;
if Argument_Count > Arg_Ind
then
return S & More (Arg_Ind, S & Sp & Argument (Arg_Ind));
else
return S & Sp & Argument (Arg_Ind);
end if;
end More;
begin
null;
if Argument_Count > 0
then
Command_Words (1) := new String'("-e");
Command_Words (2) := new String'(More);
return Command_Words;
else
return Empty_Words;
end if;
end Command_Arguments;
procedure Launch
(Command : String;
Arguments : GNAT.OS_Lib.Argument_List)
is
Launch_Arguments : GNAT.OS_Lib.Argument_List := Arguments;
begin
Spawn (Command, Launch_Arguments, Launch_Status);
for I in Launch_Arguments'Range
loop
Free (Launch_Arguments (I));
end loop;
end Launch;
begin
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);
-- Launch_Arguments (14) := new String'("-geometry");
-- Launch_Arguments (15) := new String'(Xterm_Geometry);
--
-- 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
Launch (Launch_Name, Launch_Arguments & Command_Arguments);
-- 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 Startxterminal;
|
-- Copyright 2016-2021 Bartek thindil Jasicki
--
-- This file is part of Steam Sky.
--
-- Steam Sky is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- Steam Sky is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with Steam Sky. If not, see <http://www.gnu.org/licenses/>.
with Ada.Containers.Vectors; use Ada.Containers;
with Ada.Containers.Indefinite_Vectors;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Hash;
with Ada.Containers.Hashed_Maps;
with DOM.Readers; use DOM.Readers;
with Crew; use Crew;
with Game; use Game;
with Items; use Items;
with Mobs; use Mobs;
-- ****h* Ships/Ships
-- FUNCTION
-- Provides code for manipulate ships
-- SOURCE
package Ships is
-- ****
-- ****t* Ships/Ships.Ship_Speed
-- FUNCTION
-- Ship speed states
-- SOURCE
type Ship_Speed is
(DOCKED, FULL_STOP, QUARTER_SPEED, HALF_SPEED, FULL_SPEED) with
Default_Value => FULL_SPEED;
-- ****
-- ****d* Ships/Ships.Default_Ship_Speed
-- FUNCTION
-- Default speed setting for ships
-- SOURCE
Default_Ship_Speed: constant Ship_Speed := FULL_SPEED;
-- ****
-- ****t* Ships/Ships.Ship_Combat_Ai
-- FUNCTION
-- NPC ships combat AI types
-- SOURCE
type Ship_Combat_Ai is (NONE, BERSERKER, ATTACKER, COWARD, DISARMER) with
Default_Value => NONE;
-- ****
-- ****d* Ships/Ships.Default_Combat_Ai
-- FUNCTION
-- Default value for NPC's ships combat behavior
-- SOURCE
Default_Combat_Ai: constant Ship_Combat_Ai := NONE;
-- ****
-- ****t* Ships/Ships.Ship_Upgrade
-- FUNCTION
-- Player ship types of module upgrades
-- SOURCE
type Ship_Upgrade is (NONE, DURABILITY, MAX_VALUE, VALUE) with
Default_Value => NONE;
-- ****
-- ****d* Ships/Ships.Default_Ship_Upgrade
-- FUNCTION
-- Default ship upgrade (no upgrade)
-- SOURCE
Default_Ship_Upgrade: constant Ship_Upgrade := NONE;
-- ****
-- ****t* Ships/Ships.Data_Array
-- FUNCTION
-- Used to store ship modules data
-- SOURCE
type Data_Array is array(1 .. 3) of Integer with
Default_Component_Value => 0;
-- ****
-- ****d* Ships/Ships.Empty_Data_Array
-- FUNCTION
-- Empty modules data
-- SOURCE
Empty_Data_Array: constant Data_Array := (others => 0);
-- ****
-- ****t* Ships/Ships.Module_Type_2
-- FUNCTION
-- Types of ships modules
-- SOURCE
type Module_Type_2 is
(WORKSHOP, ANY, MEDICAL_ROOM, TRAINING_ROOM, ENGINE, CABIN, COCKPIT,
TURRET, GUN, CARGO_ROOM, HULL, ARMOR, BATTERING_RAM, HARPOON_GUN) with
Default_Value => ANY;
-- ****
-- ****d* Ships/Ships.Default_Module_Type
-- FUNCTION
-- Default type of ships modules
-- SOURCE
Default_Module_Type: constant Module_Type_2 := ANY;
-- ****
-- ****s* Ships/Ships.Module_Data
-- FUNCTION
-- Data structure for ship modules, medical room, cockpit, armor and cargo
-- bays don't have any special fields
-- PARAMETERS
-- Name - Name of module
-- Proto_Index - Index of module prototype
-- Weight - Weight of module
-- Durability - 0 = destroyed
-- Max_Durability - Base durability
-- Owner - Crew member indexes for owners of module
-- Upgrade_Progress - Progress of module upgrade
-- Upgrade_Action - Type of module upgrade
-- Fuel_Usage - Amount of fuel used for each move on map
-- Power - Power of engine used for counting ship speed
-- Disabled - Did engine is disabled or not
-- Cleanliness - Cleanliness of selected cabin
-- Quality - Quality of selected cabin
-- Gun_Index - Index of installed gun
-- Damage - Damage bonus for selected gun
-- Ammo_Index - Cargo index of ammunition used by selected gun
-- Installed_Modules - Amount of installed modules on ship
-- Max_Modules - Amount of maximum installed modules for this hull
-- Crafting_Index - Index of crafting recipe or item which is
-- deconstructed or studies
-- Crafting_Time - Time needed to finish crating order
-- Crafting_Amount - How many times repeat crafting order
-- Trained_Skill - Index of skill set to training
-- Damage2 - Damage done by battering ram
-- Cooling_Down - If true, battering ram can't attack
-- Duration - Duration bonus for selected harpoon gun
-- Harpoon_Index - Cargo index of ammunition used by selected harpoon
-- gun
-- Data - Various data for module (depends on module)
-- SOURCE
type Module_Data(M_Type: Module_Type_2 := Default_Module_Type) is record
Name: Unbounded_String;
Proto_Index: Unbounded_String;
Weight: Natural := 0;
Durability: Integer := 0;
Max_Durability: Natural := 0;
Owner: Natural_Container.Vector;
Upgrade_Progress: Integer := 0;
Upgrade_Action: Ship_Upgrade;
case M_Type is
when ENGINE =>
Fuel_Usage: Positive := 1;
Power: Positive := 1;
Disabled: Boolean;
when CABIN =>
Cleanliness: Natural := 0;
Quality: Natural := 0;
when TURRET =>
Gun_Index: Natural := 0;
when GUN =>
Damage: Positive := 1;
Ammo_Index: Inventory_Container.Extended_Index;
when HULL =>
Installed_Modules: Natural := 0;
Max_Modules: Positive := 1;
when WORKSHOP =>
Crafting_Index: Unbounded_String;
Crafting_Time: Natural := 0;
Crafting_Amount: Natural := 0;
when MEDICAL_ROOM | COCKPIT | ARMOR | CARGO_ROOM =>
null;
when TRAINING_ROOM =>
Trained_Skill: SkillsData_Container.Extended_Index;
when BATTERING_RAM =>
Damage2: Positive := 1;
Cooling_Down: Boolean;
when HARPOON_GUN =>
Duration: Positive := 1;
Harpoon_Index: Inventory_Container.Extended_Index;
when ANY =>
Data: Data_Array;
end case;
end record;
-- ****
-- ****d* Ships/Ships.Default_Module
-- FUNCTION
-- Default empty module without type
-- SOURCE
Default_Module: constant Module_Data := (others => <>);
-- ****
-- ****t* Ships/Ships.Modules_Container
-- FUNCTION
-- Used to store modules data in ships
-- SOURCE
package Modules_Container is new Vectors
(Index_Type => Positive, Element_Type => Module_Data);
-- ****
-- ****t* Ships/Ships.Crew_Container
-- FUNCTION
-- Used to store crew data in ships
-- SOURCE
package Crew_Container is new Indefinite_Vectors
(Index_Type => Positive, Element_Type => Member_Data);
-- ****
-- ****s* Ships/Ships.Ship_Record
-- FUNCTION
-- Data structure for ships
-- PARAMETERS
-- Name - Ship name
-- Sky_X - X coordinate on sky map
-- SKy_Y - Y coordinate on sky map
-- Speed - Speed of ship
-- Modules - List of ship modules
-- Cargo - List of ship cargo
-- Crew - List of ship crew
-- Upgrade_Module - Number of module to upgrade
-- Destination_X - Destination X coordinate
-- Destination_Y - Destination Y coordinate
-- Repair_Module - Number of module to repair as first
-- Description - Description of ship
-- Home_Base - Index of home base of ship
-- SOURCE
type Ship_Record is record
Name: Unbounded_String;
Sky_X: Map_X_Range;
Sky_Y: Map_Y_Range;
Speed: Ship_Speed;
Modules: Modules_Container.Vector;
Cargo: Inventory_Container.Vector;
Crew: Crew_Container.Vector;
Upgrade_Module: Modules_Container.Extended_Index;
Destination_X: Natural range 0 .. Map_X_Range'Last;
Destination_Y: Natural range 0 .. Map_Y_Range'Last;
Repair_Module: Modules_Container.Extended_Index;
Description: Unbounded_String;
Home_Base: Extended_Base_Range;
end record;
-- ****
-- ****d* Ships/Ships.Empty_Ship
-- FUNCTION
-- Empty record for ship data
-- SOURCE
Empty_Ship: constant Ship_Record := (others => <>);
-- ****
-- ****s* Ships/Ships.Proto_Member_Data
-- FUNCTION
-- Data structure for proto crew info
-- PARAMETERS
-- Proto_Index - Index of proto mob which will be used as crew member
-- Min_Amount - Mininum amount of that mob in crew
-- Max_Amount - Maximum amount of that mob in crew. If 0 then MinAmount
-- will be amount
-- SOURCE
type Proto_Member_Data is record
Proto_Index: Unbounded_String;
Min_Amount: Positive := 1;
Max_Amount: Natural := 0;
end record;
-- ****
-- ****d* Ships/Ships.Empty_Proto_Member
-- FUNCTION
-- Empty record for proto crew info
-- SOURCE
Empty_Proto_Member: constant Proto_Member_Data := (others => <>);
-- ****
-- ****t* Ships/Ships.Proto_Crew_Container
-- FUNCTION
-- Used to store crew info in ships prototypes
-- SOURCE
package Proto_Crew_Container is new Vectors
(Index_Type => Positive, Element_Type => Proto_Member_Data);
-- ****
-- ****s* Ships/Ships.Proto_Ship_Data
-- FUNCTION
-- Data structure for ship prototypes
-- PARAMETERS
-- Name - Prototype name
-- Modules - List of ship modules
-- Accuracy - Bonus to hit for ship
-- Combat_Ai - Behaviour of ship in combat
-- Evasion - Bonus to evade attacks
-- Loot - Amount of loot(moneys) gained for destroying ship
-- Perception - Bonus to spot player ship first
-- Cargo - List of ship cargo
-- Combat_Value - Combat value of ship (used to generate enemies)
-- Crew - List of mobs used as ship crew
-- Description - Description of ship
-- Owner - Index of faction to which ship belong
-- Known_Recipes - List of known recipes
-- SOURCE
type Proto_Ship_Data is record
Name: Unbounded_String;
Modules: UnboundedString_Container.Vector;
Accuracy: Natural_Array(1 .. 2);
Combat_Ai: Ship_Combat_Ai;
Evasion: Natural_Array(1 .. 2);
Loot: Natural_Array(1 .. 2);
Perception: Natural_Array(1 .. 2);
Cargo: MobInventory_Container.Vector;
Combat_Value: Positive := 1;
Crew: Proto_Crew_Container.Vector;
Description: Unbounded_String;
Owner: Unbounded_String;
Known_Recipes: UnboundedString_Container.Vector;
end record;
-- ****
-- ****d* Ships/Ships.Empty_Proto_Ship
-- FUNCTION
-- Empty record for ships prototypes
-- SOURCE
Empty_Proto_Ship: constant Proto_Ship_Data := (others => <>);
-- ****
-- ****t* Ships/Ships.Proto_Ships_Container
-- FUNCTION
-- Used to store prototype ships data
-- SOURCE
package Proto_Ships_Container is new Hashed_Maps
(Key_Type => Unbounded_String, Element_Type => Proto_Ship_Data,
Hash => Ada.Strings.Unbounded.Hash, Equivalent_Keys => "=");
-- ****
-- ****v* Ships/Ships.Proto_Ships_List
-- FUNCTION
-- List of all prototypes of ships
-- SOURCE
Proto_Ships_List: Proto_Ships_Container.Map;
-- ****
-- ****v* Ships/Ships.Player_Ship
-- FUNCTION
-- The player ship
-- SOURCE
Player_Ship: Ship_Record;
-- ****
-- ****v* Ships/Ships.Ship_Syllables_Start
-- FUNCTION
-- List of first syllables for generating ships names
-- SOURCE
Ship_Syllables_Start: UnboundedString_Container.Vector;
-- ****
-- ****v* Ships/Ships.Ship_Syllables_Middle
-- FUNCTION
-- List of middle syllables for generating ships names
-- SOURCE
Ship_Syllables_Middle: UnboundedString_Container.Vector;
-- ****
-- ****v* Ships/Ships.Ship_Syllables_End
-- FUNCTION
-- List of last syllables for generating ships names
-- SOURCE
Ship_Syllables_End: UnboundedString_Container.Vector;
-- ****
-- ****e* Ships/Ships.Ships_Invalid_Data
-- FUNCTION
-- Raised when invalid data in ships file
-- SOURCE
Ships_Invalid_Data: exception;
-- ****
-- ****f* Ships/Ships.CreateShip
-- FUNCTION
-- Create new ship
-- PARAMETERS
-- Proto_Index - Index of prototype ship which will be used to create
-- the new ship
-- Name - Name of the new ship. If empty, then the default name
-- of the prototype ship will be used
-- X - X coordinate of newly created ship on map
-- Y - Y coordinate of newly created ship on map
-- Speed - Starting speed of newly created ship
-- Random_Upgrades - If true, newly created ship will be have
-- random upgrades to own modules. Default is true.
-- RESULT
-- Newly created ship
-- SOURCE
function Create_Ship
(Proto_Index, Name: Unbounded_String; X: Map_X_Range; Y: Map_Y_Range;
Speed: Ship_Speed; Random_Upgrades: Boolean := True)
return Ship_Record with
Pre => Proto_Ships_List.Contains(Key => Proto_Index),
Test_Case => (Name => "Test_CreateShip", Mode => Nominal);
-- ****
-- ****f* Ships/Ships.Load_Ships
-- FUNCTION
-- Load ships from files
-- PARAMETERS
-- Reader - XML Reader from which ships data will be read
-- SOURCE
procedure Load_Ships(Reader: Tree_Reader);
-- ****
-- ****f* Ships/Ships.Count_Ship_Weight
-- FUNCTION
-- Count weight of ship (with modules and cargo)
-- PARAMETERS
-- Ship - Ship which weight will be counted
-- RESULT
-- Ship weight in kilograms
-- SOURCE
function Count_Ship_Weight(Ship: Ship_Record) return Positive with
Test_Case => (Name => "Test_CountShipWeight", Mode => Robustness);
-- ****
-- ****f* Ships/Ships.Generate_Ship_Name
-- FUNCTION
-- Generate random name for ship
-- PARAMETERS
-- Owner - Index of faction to which ship belongs
-- RESULT
-- Random name for a ship
-- SOURCE
function Generate_Ship_Name
(Owner: Unbounded_String) return Unbounded_String with
Pre => Owner /= Null_Unbounded_String,
Test_Case => (Name => "Test_GenerateShipName", Mode => Nominal);
-- ****
-- ****f* Ships/Ships.Count_Combat_Value
-- FUNCTION
-- Count combat value of player ship
-- RESULT
-- Numeric level of combat value of player ship
-- SOURCE
function Count_Combat_Value return Natural with
Test_Case => (Name => "Test_CountCombatValue", Mode => Robustness);
-- ****
-- ****f* Ships/Ships.Get_Cabin_Quality
-- FUNCTION
-- Get description of quality of selected cabin in player ship
-- PARAMETERS
-- Quality - Numeric value of cabin quality
-- RESULT
-- Description of cabin quality
-- SOURCE
function Get_Cabin_Quality(Quality: Natural) return String with
Post => Get_Cabin_Quality'Result'Length > 0,
Test_Case => (Name => "Test_GetCabinQuality", Mode => Nominal);
-- ****
-- ****f* Ships/Ships.Damage_Module
-- FUNCTION
-- Damage the selected module
-- PARAMETERS
-- Ship - Ship in which the module will be damaged
-- Module_Index - Index of the module to damage
-- Damage - Amount of damage which the module will take
-- Death_Reason - If module has owner, reason of owner's death
-- if module will be destroyed
-- SOURCE
procedure Damage_Module
(Ship: in out Ship_Record; Module_Index: Modules_Container.Extended_Index;
Damage: Positive; Death_Reason: String) with
Pre => Module_Index in
Ship.Modules.First_Index .. Ship.Modules.Last_Index and
Death_Reason'Length > 0,
Test_Case => (Name => "Test_DamageModule", Mode => Nominal);
-- ****
end Ships;
|
-- { dg-do compile }
with Prot2_Pkg1;
with Prot2_Pkg2;
package body Prot2 is
type A is array (1 .. Prot2_Pkg1.Num) of Integer;
type E is (One, Two);
type Rec (D : E := One) is record
case D is
when One => L : A;
when Two => null;
end case;
end record;
package My_Pkg2 is new Prot2_Pkg2 (Rec);
procedure Dummy is begin null; end;
end Prot2;
|
with Ada.Streams;
package Real_Cst is
procedure Write (Stream : access Ada.Streams.Root_Stream_Type'Class);
end;
|
procedure x is
id, id1, id2: Integer;
function Minimo (a, b: Integer) return Integer is
begin
if a < b then return a;
else return b;
end if;
end Minimo;
procedure x3 is
begin
put("Hola Mundo");
end x3;
begin
put(Minimo(1,2));
end x;
|
with System.Storage_Elements;
package body Interfaces.C.Pointers is
use type System.Storage_Elements.Storage_Offset;
-- no System.Address_To_Access_Conversions for modifying to Pure
function To_Pointer (Value : System.Address) return access Element
with Import, Convention => Intrinsic;
function To_Address (Value : access constant Element) return System.Address
with Import, Convention => Intrinsic;
-- implementation
function Value (
Ref : access constant Element;
Terminator : Element := Default_Terminator)
return Element_Array
is
pragma Check (Dynamic_Predicate,
Check => Ref /= null or else raise Dereference_Error); -- CXB3014
Length : constant ptrdiff_t :=
Virtual_Length (Ref, Terminator) + 1; -- including nul
begin
return Value (Ref, Length);
end Value;
function Value (
Ref : access constant Element;
Length : ptrdiff_t)
return Element_Array
is
pragma Check (Dynamic_Predicate,
Check => Ref /= null or else raise Dereference_Error); -- CXB3014
First : Index;
Last : Index'Base;
begin
if Index'First = Index'Base'First and then Length = 0 then
First := Index'Succ (Index'First);
Last := Index'First;
else
First := Index'First;
Last := Index'Base'Val (Index'Pos (Index'First) + Length - 1);
end if;
declare
Source : Element_Array (First .. Last);
for Source'Address use To_Address (Ref);
begin
return Source;
end;
end Value;
function "+" (
Left : Pointer;
Right : ptrdiff_t)
return not null Pointer
is
pragma Check (Dynamic_Predicate,
Check => Left /= null or else raise Pointer_Error); -- CXB3015
begin
return To_Pointer (
To_Address (Left)
+ System.Storage_Elements.Storage_Offset (Right)
* (Element_Array'Component_Size / Standard'Storage_Unit));
end "+";
function "+" (
Left : ptrdiff_t;
Right : not null Pointer)
return not null Pointer is
begin
return Right + Left;
end "+";
function "-" (
Left : Pointer;
Right : ptrdiff_t)
return not null Pointer
is
pragma Check (Dynamic_Predicate,
Check => Left /= null or else raise Pointer_Error); -- CXB3015
begin
return To_Pointer (
To_Address (Left)
- System.Storage_Elements.Storage_Offset (Right)
* (Element_Array'Component_Size / Standard'Storage_Unit));
end "-";
function "-" (
Left : not null Pointer;
Right : not null access constant Element)
return ptrdiff_t is
begin
return Constant_Pointer (Left) - Right;
end "-";
procedure Increment (Ref : in out not null Pointer) is
begin
Ref := Ref + 1;
end Increment;
procedure Decrement (Ref : in out Pointer) is
begin
Ref := Ref - 1;
end Decrement;
function "+" (Left : not null Constant_Pointer; Right : ptrdiff_t)
return not null Constant_Pointer is
begin
return To_Pointer (
To_Address (Left)
+ System.Storage_Elements.Storage_Offset (Right)
* (Element_Array'Component_Size / Standard'Storage_Unit));
end "+";
function "+" (Left : ptrdiff_t; Right : not null Constant_Pointer)
return not null Constant_Pointer is
begin
return Right + Left;
end "+";
function "-" (Left : not null Constant_Pointer; Right : ptrdiff_t)
return not null Constant_Pointer is
begin
return To_Pointer (
To_Address (Left)
- System.Storage_Elements.Storage_Offset (Right)
* (Element_Array'Component_Size / Standard'Storage_Unit));
end "-";
function "-" (
Left : not null Constant_Pointer;
Right : not null access constant Element)
return ptrdiff_t is
begin
return ptrdiff_t (
(To_Address (Left) - To_Address (Right))
/ (Element_Array'Component_Size / Standard'Storage_Unit));
end "-";
procedure Increment (Ref : in out not null Constant_Pointer) is
begin
Ref := Ref + 1;
end Increment;
procedure Decrement (Ref : in out not null Constant_Pointer) is
begin
Ref := Ref - 1;
end Decrement;
function Virtual_Length (
Ref : access constant Element;
Terminator : Element := Default_Terminator)
return ptrdiff_t
is
pragma Check (Dynamic_Predicate,
Check => Ref /= null or else raise Dereference_Error); -- CXB3016
Result : ptrdiff_t := 0;
begin
while Constant_Pointer'(Ref + Result).all /= Terminator loop
Result := Result + 1;
end loop;
return Result;
end Virtual_Length;
function Virtual_Length (
Ref : not null access constant Element;
Limit : ptrdiff_t;
Terminator : Element := Default_Terminator)
return ptrdiff_t
is
Result : ptrdiff_t := 0;
begin
while Result < Limit
and then Constant_Pointer'(Ref + Result).all /= Terminator
loop
Result := Result + 1;
end loop;
return Result;
end Virtual_Length;
procedure Copy_Terminated_Array (
Source : access constant Element;
Target : access Element;
Limit : ptrdiff_t := ptrdiff_t'Last;
Terminator : Element := Default_Terminator)
is
pragma Check (Dynamic_Predicate,
Check => Source /= null or else raise Dereference_Error); -- CXB3016
pragma Check (Dynamic_Predicate,
Check => Target /= null or else raise Dereference_Error); -- CXB3016
Length : ptrdiff_t;
begin
if Limit < ptrdiff_t'Last then
Length := Virtual_Length (Source, Limit, Terminator);
if Length < Limit then
Length := Length + 1; -- including nul
end if;
else -- unlimited
Length := Virtual_Length (Source, Terminator) + 1; -- including nul
end if;
Copy_Array (Source, Target, Length);
end Copy_Terminated_Array;
procedure Copy_Array (
Source : access constant Element;
Target : access Element;
Length : ptrdiff_t)
is
pragma Check (Dynamic_Predicate,
Check => Source /= null or else raise Dereference_Error); -- CXB3016
pragma Check (Dynamic_Predicate,
Check => Target /= null or else raise Dereference_Error); -- CXB3016
begin
if Length > 0 then
declare
subtype R is
Index range
Index'First ..
Index'Val (Index'Pos (Index'First) + Length - 1);
Source_Array : Element_Array (R);
for Source_Array'Address use To_Address (Source);
Target_Array : Element_Array (R);
for Target_Array'Address use To_Address (Target);
begin
Target_Array := Source_Array;
end;
end if;
end Copy_Array;
end Interfaces.C.Pointers;
|
package Statically_Matching is
type T1(b: boolean) is tagged null record;
type T2 is new T1(b => false) with private;
private
F: constant boolean := false;
type T2 is new T1(b => F) with null record; -- OK
end Statically_Matching;
|
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Lire_Entier is
-- Lire un entier au clavier.
-- Paramètres :
-- Nombre : l'entier à lire
-- Nécessite : ---
-- Assure : -- Nombre est l'entier lu
procedure Lire (Nombre: out Integer) is
Char: Character;
EOL: Boolean;
begin
Nombre := 0;
loop
Look_Ahead(Char, EOL);
exit when EOL or else (Char < '0' or Char > '9');
Get(Char);
Nombre := Nombre * 10 + (Character'Pos(Char) - Character'Pos('0'));
end loop;
end Lire;
Un_Entier: Integer; -- lu au clavier
Suivant: Character; -- lu au clavier
begin
-- Demander un entier
Put ("Un entier : ");
-- Appeler le sous-programme Lire
Lire(Un_Entier);
-- Afficher l'entier lu
Put ("L'entier lu est : ");
Put (Un_Entier, 1);
New_Line;
-- Afficher le caractère suivant
Get (Suivant);
Put ("Le caractère suivant est : ");
Put (Suivant);
New_Line;
end Lire_Entier;
|
--------------------------------------------------------------------------------
-- MIT License
--
-- Copyright (c) 2020 Zane Myers
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
--------------------------------------------------------------------------------
with Vulkan.Math.Integers;
with Vulkan.Math.Common;
with Vulkan.Math.GenFType;
with Ada.Unchecked_Conversion;
use Vulkan.Math.Integers;
use Vulkan.Math.Common;
use Vulkan.Math.GenFType;
package body Vulkan.Math.Packing is
-- A short value.
type Half_Float_Unused_Bits is mod 2 ** 16;
-- A sign bit.
type Sign_Bit is mod 2 ** 1;
-- Single float exponent MSB bits
type Single_Float_Exponent_Msb is mod 2 ** 3;
-- Single float exponent LSB bits
type Single_Float_Exponent_Lsb is mod 2 ** 5;
-- Single float mantissa MSB bits
type Single_Float_Mantissa_Msb is mod 2 ** 10;
-- Single float mantissa LSB bits
type Single_Float_Mantissa_Lsb is mod 2 ** 13;
-- The layout of a single-precision floating point number.
type Single_Float_Bits is record
sign : Sign_Bit;
exponent_msb : Single_Float_Exponent_Msb;
exponent_lsb : Single_Float_Exponent_Lsb;
mantissa_msb : Single_Float_Mantissa_Msb;
mantissa_lsb : Single_Float_Mantissa_Lsb;
end record;
-- The bit positions to use for each field of the record.
for Single_Float_Bits use record
sign at 0 range 31 .. 31;
exponent_msb at 0 range 28 .. 30;
exponent_lsb at 0 range 23 .. 27;
mantissa_msb at 0 range 13 .. 22;
mantissa_lsb at 0 range 0 .. 12;
end record;
-- The size of a single precision float.
for Single_Float_Bits'Size use 32;
-- The layout of a half-precision floating point number.
type Vkm_Half_Float_Bits is record
unused : Half_Float_Unused_Bits;
sign : Sign_Bit;
exponent : Single_Float_Exponent_Lsb;
mantissa : Single_Float_Mantissa_Msb;
end record;
-- The bit positions to use for each field of the record.
for Vkm_Half_Float_Bits use record
unused at 0 range 16 .. 31;
sign at 0 range 15 .. 15;
exponent at 0 range 10 .. 14;
mantissa at 0 range 0 .. 9;
end record;
-- The size of a half-precision float.
for Vkm_Half_Float_Bits'Size use 32;
-- The layout of a packed double-precision floating point number.
type Vkm_Double_Float_Bits is record
msb : Vkm_Uint;
lsb : Vkm_Uint;
end record;
-- The bit positions to use for each field of the record.
for Vkm_Double_Float_Bits use record
msb at 0 range 32 .. 63;
lsb at 0 range 0 .. 31;
end record;
-- The size of a double-precision float.
for Vkm_Double_Float_Bits'Size use 64;
----------------------------------------------------------------------------
-- Unchecked Conversion Operations
----------------------------------------------------------------------------
-- Unchecked conversion from 32-bit float to Single Float Bits.
function Convert_Vkm_Float_To_Single_Float_Bits is new
Ada.Unchecked_Conversion(Source => Vkm_Float, Target => Single_Float_Bits);
-- Unchecked conversion to 32-bit float from Single Float Bits.
function Convert_Single_Float_Bits_To_Vkm_Float is new
Ada.Unchecked_Conversion(Source => Single_Float_Bits, Target => Vkm_Float);
-- Unchecked conversion from Half_Float_Bits to unsigned integer.
function Convert_Vkm_Half_Float_Bits_To_Vkm_Uint is new
Ada.Unchecked_Conversion(Source => Vkm_Half_Float_Bits, Target => Vkm_Uint);
-- Unchecked conversion from unsigned integer to Vkm_Half_Float_Bits.
function Convert_Vkm_Uint_To_Half_Float_Bits is new
Ada.Unchecked_Conversion(Source => Vkm_Uint, Target => Vkm_Half_Float_Bits);
-- Unchecked conversion from Vkm_Double_Float_Bits to Vkm_Double.
function Convert_Vkm_Double_Float_Bits_To_Vkm_Double is new
Ada.Unchecked_Conversion(Source => Vkm_Double_Float_Bits, Target => Vkm_Double);
-- Unchecked conversion from Vkm_Double_Float_Bits to Vkm_Double.
function Convert_Vkm_Double_To_Vkm_Double_Float_Bits is new
Ada.Unchecked_Conversion(Source => Vkm_Double, Target => Vkm_Double_Float_Bits);
----------------------------------------------------------------------------
-- Local Operation Declarations
----------------------------------------------------------------------------
-- @summary
-- Convert a single-precision floating point number to a half-precision
-- floating point number.
--
-- @description
-- Convert a single-precision floating point number to a half-precision
-- floating point number.
--
-- @param value
-- The Vkm_Float to convert to bits for a half-precision floating point number.
--
-- @return
-- The bits for a half-precision floating point number.
----------------------------------------------------------------------------
function Convert_Single_To_Half(
value : in Vkm_Float) return Vkm_Uint;
----------------------------------------------------------------------------
-- @summary
-- Convert a half-precision floating point number to a single-precision
-- floating point number.
--
-- @description
-- Convert a half-precision floating point number to a single-precision
-- floating point number.
--
-- @param value
-- The bits for a half-precision floating point number to convert to a
-- single-precision floating point number.
--
-- @return
-- The bits for a half-precision floating point number.
----------------------------------------------------------------------------
function Convert_Half_To_Single(
value : in Vkm_Uint) return Vkm_Float;
----------------------------------------------------------------------------
-- Operations
----------------------------------------------------------------------------
function Pack_Unsigned_Normalized_2x16(
vector : in Vkm_Vec2) return Vkm_Uint is
converted : constant Vkm_Vec2 := Round(Clamp(vector, 0.0, 1.0) * 65535.0);
packed : Vkm_Uint := 0;
begin
packed := Bitfield_Insert(packed, To_Vkm_Uint(converted.x), 0, 16);
packed := Bitfield_Insert(packed, To_Vkm_Uint(converted.y), 16, 16);
return packed;
end Pack_Unsigned_Normalized_2x16;
----------------------------------------------------------------------------
function Pack_Signed_Normalized_2x16(
vector : in Vkm_Vec2) return Vkm_Uint is
converted : constant Vkm_Vec2 := Round(Clamp(vector, -1.0, 1.0) * 32767.0);
packed : Vkm_Int := 0;
begin
packed := Bitfield_Insert(packed, To_Vkm_Int(converted.x), 0, 16);
packed := Bitfield_Insert(packed, To_Vkm_Int(converted.y), 16, 16);
return To_Vkm_Uint(packed);
end Pack_Signed_Normalized_2x16;
----------------------------------------------------------------------------
function Pack_Unsigned_Normalized_4x8(
vector : in Vkm_Vec4) return Vkm_Uint is
converted : constant Vkm_Vec4 := Round(Clamp(vector, 0.0, 1.0) * 255.0);
packed : Vkm_Uint := 0;
begin
packed := Bitfield_Insert(packed, To_Vkm_Uint(converted.x), 0, 8);
packed := Bitfield_Insert(packed, To_Vkm_Uint(converted.y), 8, 8);
packed := Bitfield_Insert(packed, To_Vkm_Uint(converted.z), 16, 8);
packed := Bitfield_Insert(packed, To_Vkm_Uint(converted.w), 24, 8);
return packed;
end Pack_Unsigned_Normalized_4x8;
----------------------------------------------------------------------------
function Pack_Signed_Normalized_4x8(
vector : in Vkm_Vec4) return Vkm_Uint is
converted : constant Vkm_Vec4 := Round(Clamp(vector, -1.0, 1.0) * 127.0);
packed : Vkm_Int := 0;
begin
packed := Bitfield_Insert(packed, To_Vkm_Int(converted.x), 0, 8);
packed := Bitfield_Insert(packed, To_Vkm_Int(converted.y), 8, 8);
packed := Bitfield_Insert(packed, To_Vkm_Int(converted.z), 16, 8);
packed := Bitfield_Insert(packed, To_Vkm_Int(converted.w), 24, 8);
return To_Vkm_Uint(packed);
end Pack_Signed_Normalized_4x8;
----------------------------------------------------------------------------
function Unpack_Unsigned_Normalized_2x16(
packed : in Vkm_Uint) return Vkm_Vec2 is
unpacked : Vkm_Vec2 := Make_Vec2;
begin
unpacked.x(To_Vkm_Float(Bitfield_Extract(packed, 0, 16)));
unpacked.y(To_Vkm_Float(Bitfield_Extract(packed, 16, 16)));
return unpacked / 65535.0;
end Unpack_Unsigned_Normalized_2x16;
----------------------------------------------------------------------------
function Unpack_Signed_Normalized_2x16(
packed : in Vkm_Uint) return Vkm_Vec2 is
unpacked : Vkm_Vec2 := Make_Vec2;
begin
unpacked.x(To_Vkm_Float(Bitfield_Extract(To_Vkm_Int(packed), 0, 16)));
unpacked.y(To_Vkm_Float(Bitfield_Extract(To_Vkm_Int(packed), 16, 16)));
return Clamp(unpacked / 32767.0, -1.0, 1.0);
end Unpack_Signed_Normalized_2x16;
----------------------------------------------------------------------------
function Unpack_Unsigned_Normalized_4x8(
packed : in Vkm_Uint) return Vkm_Vec4 is
unpacked : Vkm_Vec4 := Make_Vec4;
begin
unpacked.x(To_Vkm_Float(Bitfield_Extract(packed, 0, 8)));
unpacked.y(To_Vkm_Float(Bitfield_Extract(packed, 8, 8)));
unpacked.z(To_Vkm_Float(Bitfield_Extract(packed, 16, 8)));
unpacked.w(To_Vkm_Float(Bitfield_Extract(packed, 24, 8)));
return unpacked / 255.0;
end Unpack_Unsigned_Normalized_4x8;
----------------------------------------------------------------------------
function Unpack_Signed_Normalized_4x8(
packed : in Vkm_Uint) return Vkm_Vec4 is
unpacked : Vkm_Vec4 := Make_Vec4;
begin
unpacked.x(To_Vkm_Float(Bitfield_Extract(To_Vkm_Int(packed), 0, 8)))
.y(To_Vkm_Float(Bitfield_Extract(To_Vkm_Int(packed), 8, 8)))
.z(To_Vkm_Float(Bitfield_Extract(To_Vkm_Int(packed), 16, 8)))
.w(To_Vkm_Float(Bitfield_Extract(To_Vkm_Int(packed), 24, 8)));
return Clamp( unpacked / 127.0, -1.0, 1.0);
end Unpack_Signed_Normalized_4x8;
----------------------------------------------------------------------------
function Pack_Half_2x16(
vector : in Vkm_Vec2) return Vkm_Uint is
packed : Vkm_Uint := 0;
begin
packed := Bitfield_Insert(packed, Convert_Single_To_Half(vector.x), 0, 16);
packed := Bitfield_Insert(packed, Convert_Single_To_Half(vector.y), 16, 16);
return packed;
end Pack_Half_2x16;
----------------------------------------------------------------------------
function Unpack_Half_2x16(
packed : in Vkm_Uint) return Vkm_Vec2 is
unpacked : Vkm_Vec2 := Make_Vec2;
begin
unpacked.x(Convert_Half_To_Single(Bitfield_Extract(packed, 0, 16)))
.y(Convert_Half_To_Single(Bitfield_Extract(packed, 16, 16)));
return unpacked;
end Unpack_Half_2x16;
----------------------------------------------------------------------------
function Pack_Double_2x32(
vector : in Vkm_Uvec2) return Vkm_Double is
double_float_bits : constant Vkm_Double_Float_Bits :=
(lsb => vector.x,
msb => vector.y);
begin
return Convert_Vkm_Double_Float_Bits_To_Vkm_Double(double_float_bits);
end Pack_Double_2x32;
----------------------------------------------------------------------------
function Unpack_Double_2x32(
packed : in Vkm_Double) return Vkm_Uvec2 is
double_float_bits : constant Vkm_Double_Float_Bits :=
Convert_Vkm_Double_To_Vkm_Double_Float_Bits(packed);
unpacked : Vkm_Uvec2 := Make_Uvec2;
begin
unpacked.x(double_float_bits.lsb)
.y(double_float_bits.msb);
return unpacked;
end Unpack_Double_2x32;
----------------------------------------------------------------------------
-- Local Operation Definitions
----------------------------------------------------------------------------
function Convert_Single_To_Half(
value : in Vkm_Float) return Vkm_Uint is
float_bits : constant Single_Float_Bits :=
Convert_Vkm_Float_To_Single_Float_Bits(value);
half_float_bits : constant Vkm_Half_Float_Bits :=
(unused => 0,
sign => float_bits.sign,
exponent => float_bits.exponent_lsb,
mantissa => float_bits.mantissa_msb);
begin
return Convert_Vkm_Half_Float_Bits_To_Vkm_Uint(half_float_bits);
end Convert_Single_To_Half;
----------------------------------------------------------------------------
function Convert_Half_To_Single(
value : in Vkm_Uint) return Vkm_Float is
half_float_bits : constant Vkm_Half_Float_Bits :=
Convert_Vkm_Uint_To_Half_Float_Bits(value);
float_bits : constant Single_Float_Bits :=
(sign => half_float_bits.sign,
exponent_msb => 0,
exponent_lsb => half_float_bits.exponent,
mantissa_msb => half_float_bits.mantissa,
mantissa_lsb => 0);
begin
return Convert_Single_Float_Bits_To_Vkm_Float(float_bits);
end Convert_Half_To_Single;
end Vulkan.Math.Packing;
|
-- { dg-do compile }
-- { dg-options "-O" }
package body Opt55 is
function Cond (B : Boolean; If_True, If_False : Date) return Date is
begin
if B then
return If_True;
else
return If_False;
end if;
end;
function F (C : Rec2; B : Boolean) return Date is
begin
return Cond (B, C.D1, C.D2);
end;
end Opt55;
|
------------------------------------------------------------------------------
-- --
-- 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 HAL; use HAL;
with System; use System;
pragma Warnings (Off, "* is an internal GNAT unit");
with System.BB.Parameters;
pragma Warnings (On, "* is an internal GNAT unit");
with STM32_SVD.RCC; use STM32_SVD.RCC;
package body STM32.Device is
------------------
-- Enable_Clock --
------------------
Secure_Code : UInt32;
pragma Import (C, Secure_Code, "secure_code");
RCC : aliased RCC_Peripheral
with Import, Address => S_NS_Periph (RCC_Base);
procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)
is
begin
RCC_Periph.APB1ENR1.DAC1EN := True;
end Enable_Clock;
procedure Reset (This : aliased in out Digital_To_Analog_Converter)
is
begin
RCC_Periph.APB1RSTR1.DAC1RST := True;
RCC_Periph.APB1RSTR1.DAC1RST := False;
end Reset;
procedure Enable_Clock (This : aliased in out GPIO_Port) is
begin
if This'Address = S_NS_Periph (GPIOA_Base) then
RCC.AHB2ENR.GPIOAEN := True;
elsif This'Address = S_NS_Periph (GPIOB_Base) then
RCC.AHB2ENR.GPIOBEN := True;
elsif This'Address = S_NS_Periph (GPIOC_Base) then
RCC.AHB2ENR.GPIOCEN := True;
elsif This'Address = S_NS_Periph (GPIOD_Base) then
RCC.AHB2ENR.GPIODEN := True;
elsif This'Address = S_NS_Periph (GPIOE_Base) then
RCC.AHB2ENR.GPIOEEN := True;
elsif This'Address = S_NS_Periph (GPIOF_Base) then
RCC.AHB2ENR.GPIOFEN := True;
elsif This'Address = S_NS_Periph (GPIOG_Base) then
RCC.AHB2ENR.GPIOGEN := True;
elsif This'Address = S_NS_Periph (GPIOH_Base) then
RCC.AHB2ENR.GPIOHEN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
procedure Disable_Clock (This : aliased in out GPIO_Port) is
begin
if This'Address = S_NS_Periph (GPIOA_Base) then
RCC.AHB2ENR.GPIOAEN := False;
elsif This'Address = S_NS_Periph (GPIOB_Base) then
RCC.AHB2ENR.GPIOBEN := False;
elsif This'Address = S_NS_Periph (GPIOC_Base) then
RCC.AHB2ENR.GPIOCEN := False;
elsif This'Address = S_NS_Periph (GPIOD_Base) then
RCC.AHB2ENR.GPIODEN := False;
elsif This'Address = S_NS_Periph (GPIOE_Base) then
RCC.AHB2ENR.GPIOEEN := False;
elsif This'Address = S_NS_Periph (GPIOF_Base) then
RCC.AHB2ENR.GPIOFEN := False;
elsif This'Address = S_NS_Periph (GPIOG_Base) then
RCC.AHB2ENR.GPIOGEN := False;
elsif This'Address = S_NS_Periph (GPIOH_Base) then
RCC.AHB2ENR.GPIOHEN := False;
else
raise Unknown_Device;
end if;
end Disable_Clock;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (Point : GPIO_Point)
is
begin
Enable_Clock (Point.Periph.all);
end Enable_Clock;
procedure Disable_Clock (Point : GPIO_Point)
is
begin
Disable_Clock (Point.Periph.all);
end Disable_Clock;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (Points : GPIO_Points)
is
begin
for Point of Points loop
Enable_Clock (Point.Periph.all);
end loop;
end Enable_Clock;
procedure Disable_Clock (Points : GPIO_Points)
is
begin
for Point of Points loop
Disable_Clock (Point.Periph.all);
end loop;
end Disable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : aliased in out GPIO_Port) is
begin
if This'Address = S_NS_Periph (GPIOA_Base) then
RCC.AHB2RSTR.GPIOARST := True;
RCC.AHB2RSTR.GPIOARST := False;
elsif This'Address = S_NS_Periph (GPIOB_Base) then
RCC.AHB2RSTR.GPIOBRST := True;
RCC.AHB2RSTR.GPIOBRST := False;
elsif This'Address = S_NS_Periph (GPIOC_Base) then
RCC.AHB2RSTR.GPIOCRST := True;
RCC.AHB2RSTR.GPIOCRST := False;
elsif This'Address = S_NS_Periph (GPIOD_Base) then
RCC.AHB2RSTR.GPIODRST := True;
RCC.AHB2RSTR.GPIODRST := False;
elsif This'Address = S_NS_Periph (GPIOE_Base) then
RCC.AHB2RSTR.GPIOERST := True;
RCC.AHB2RSTR.GPIOERST := False;
else
raise Unknown_Device;
end if;
end Reset;
-----------
-- Reset --
-----------
procedure Reset (Point : GPIO_Point) is
begin
Reset (Point.Periph.all);
end Reset;
-----------
-- Reset --
-----------
procedure Reset (Points : GPIO_Points)
is
Do_Reset : Boolean;
begin
for J in Points'Range loop
Do_Reset := True;
for K in Points'First .. J - 1 loop
if Points (K).Periph = Points (J).Periph then
Do_Reset := False;
exit;
end if;
end loop;
if Do_Reset then
Reset (Points (J).Periph.all);
end if;
end loop;
end Reset;
------------------------------
-- GPIO_Port_Representation --
------------------------------
function GPIO_Port_Representation (Port : GPIO_Port) return UInt4 is
begin
-- TODO: rather ugly to have this board-specific range here
if Port'Address = S_NS_Periph (GPIOA_Base) then
return 0;
elsif Port'Address = S_NS_Periph (GPIOB_Base) then
return 1;
elsif Port'Address = S_NS_Periph (GPIOC_Base) then
return 2;
elsif Port'Address = S_NS_Periph (GPIOD_Base) then
return 3;
elsif Port'Address = S_NS_Periph (GPIOE_Base) then
return 4;
else
raise Program_Error;
end if;
end GPIO_Port_Representation;
----------------
-- As_Port_Id --
----------------
function As_Port_Id (Port : I2C_Port) return I2C_Port_Id is
begin
if Port.Periph.all'Address = S_NS_Periph (I2C1_Base) then
return I2C_Id_1;
elsif Port.Periph.all'Address = S_NS_Periph (I2C2_Base) then
return I2C_Id_2;
elsif Port.Periph.all'Address = S_NS_Periph (I2C3_Base) then
return I2C_Id_3;
else
raise Unknown_Device;
end if;
end As_Port_Id;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : I2C_Port) is
begin
Enable_Clock (As_Port_Id (This));
end Enable_Clock;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : I2C_Port_Id) is
begin
case This is
when I2C_Id_1 =>
RCC_Periph.APB1ENR1.I2C1EN := True;
when I2C_Id_2 =>
RCC_Periph.APB1ENR1.I2C2EN := True;
when I2C_Id_3 =>
RCC_Periph.APB1ENR1.I2C3EN := True;
end case;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : I2C_Port) is
begin
Reset (As_Port_Id (This));
end Reset;
-----------
-- Reset --
-----------
procedure Reset (This : I2C_Port_Id) is
begin
case This is
when I2C_Id_1 =>
RCC_Periph.APB1RSTR1.I2C1RST := True;
RCC_Periph.APB1RSTR1.I2C1RST := False;
when I2C_Id_2 =>
RCC_Periph.APB1RSTR1.I2C2RST := True;
RCC_Periph.APB1RSTR1.I2C2RST := False;
when I2C_Id_3 =>
RCC_Periph.APB1RSTR1.I2C3RST := True;
RCC_Periph.APB1RSTR1.I2C3RST := False;
end case;
end Reset;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : SPI_Port) is
begin
if This.Periph.all'Address = S_NS_Periph (SPI1_Base) then
RCC.APB2ENR.SPI1EN := True;
elsif This.Periph.all'Address = S_NS_Periph (SPI2_Base) then
RCC.APB1ENR1.SPI2EN := True;
elsif This.Periph.all'Address = S_NS_Periph (SPI3_Base) then
RCC.APB1ENR1.SPI3EN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : in out SPI_Port) is
begin
if This.Periph.all'Address = S_NS_Periph (SPI1_Base) then
RCC.APB2RSTR.SPI1RST := True;
RCC.APB2RSTR.SPI1RST := False;
elsif This.Periph.all'Address = S_NS_Periph (SPI2_Base) then
RCC.APB1RSTR1.SPI2RST := True;
RCC.APB1RSTR1.SPI2RST := False;
elsif This.Periph.all'Address = S_NS_Periph (SPI3_Base) then
RCC.APB1RSTR1.SPI3RST := True;
RCC.APB1RSTR1.SPI3RST := False;
else
raise Unknown_Device;
end if;
end Reset;
function S_NS_Periph (Addr : System.Address) return System.Address
is
X : UInt32;
LAddr : System.Address;
for X'Address use LAddr'Address;
begin
LAddr := Addr;
if Secure_Code > 0 then
X := X + 16#1000_0000#;
end if;
return LAddr;
end S_NS_Periph;
end STM32.Device;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . B I T _ O P S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1996-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; use System;
with System.Pure_Exceptions; use System.Pure_Exceptions;
with System.Unsigned_Types; use System.Unsigned_Types;
with Unchecked_Conversion;
package body System.Bit_Ops is
subtype Bits_Array is System.Unsigned_Types.Packed_Bytes1 (Positive);
-- Dummy array type used to interpret the address values. We use the
-- unaligned version always, since this will handle both the aligned and
-- unaligned cases, and we always do these operations by bytes anyway.
-- Note: we use a ones origin array here so that the computations of the
-- length in bytes work correctly (give a non-negative value) for the
-- case of zero length bit strings). Note that we never allocate any
-- objects of this type (we can't because they would be absurdly big).
type Bits is access Bits_Array;
-- This is the actual type into which address values are converted
function To_Bits is new Unchecked_Conversion (Address, Bits);
LE : constant := Standard'Default_Bit_Order;
-- Static constant set to 0 for big-endian, 1 for little-endian
-- The following is an array of masks used to mask the final byte, either
-- at the high end (big-endian case) or the low end (little-endian case).
Masks : constant array (1 .. 7) of Packed_Byte := (
(1 - LE) * 2#1000_0000# + LE * 2#0000_0001#,
(1 - LE) * 2#1100_0000# + LE * 2#0000_0011#,
(1 - LE) * 2#1110_0000# + LE * 2#0000_0111#,
(1 - LE) * 2#1111_0000# + LE * 2#0000_1111#,
(1 - LE) * 2#1111_1000# + LE * 2#0001_1111#,
(1 - LE) * 2#1111_1100# + LE * 2#0011_1111#,
(1 - LE) * 2#1111_1110# + LE * 2#0111_1111#);
-----------------------
-- Local Subprograms --
-----------------------
procedure Raise_Error;
-- Raise Constraint_Error, complaining about unequal lengths
-------------
-- Bit_And --
-------------
procedure Bit_And
(Left : Address;
Llen : Natural;
Right : Address;
Rlen : Natural;
Result : Address)
is
LeftB : constant Bits := To_Bits (Left);
RightB : constant Bits := To_Bits (Right);
ResultB : constant Bits := To_Bits (Result);
begin
if Llen /= Rlen then
Raise_Error;
end if;
for J in 1 .. (Rlen + 7) / 8 loop
ResultB (J) := LeftB (J) and RightB (J);
end loop;
end Bit_And;
------------
-- Bit_Eq --
------------
function Bit_Eq
(Left : Address;
Llen : Natural;
Right : Address;
Rlen : Natural) return Boolean
is
LeftB : constant Bits := To_Bits (Left);
RightB : constant Bits := To_Bits (Right);
begin
if Llen /= Rlen then
return False;
else
declare
BLen : constant Natural := Llen / 8;
Bitc : constant Natural := Llen mod 8;
begin
if LeftB (1 .. BLen) /= RightB (1 .. BLen) then
return False;
elsif Bitc /= 0 then
return
((LeftB (BLen + 1) xor RightB (BLen + 1))
and Masks (Bitc)) = 0;
else -- Bitc = 0
return True;
end if;
end;
end if;
end Bit_Eq;
-------------
-- Bit_Not --
-------------
procedure Bit_Not
(Opnd : System.Address;
Len : Natural;
Result : System.Address)
is
OpndB : constant Bits := To_Bits (Opnd);
ResultB : constant Bits := To_Bits (Result);
begin
for J in 1 .. (Len + 7) / 8 loop
ResultB (J) := not OpndB (J);
end loop;
end Bit_Not;
------------
-- Bit_Or --
------------
procedure Bit_Or
(Left : Address;
Llen : Natural;
Right : Address;
Rlen : Natural;
Result : Address)
is
LeftB : constant Bits := To_Bits (Left);
RightB : constant Bits := To_Bits (Right);
ResultB : constant Bits := To_Bits (Result);
begin
if Llen /= Rlen then
Raise_Error;
end if;
for J in 1 .. (Rlen + 7) / 8 loop
ResultB (J) := LeftB (J) or RightB (J);
end loop;
end Bit_Or;
-------------
-- Bit_Xor --
-------------
procedure Bit_Xor
(Left : Address;
Llen : Natural;
Right : Address;
Rlen : Natural;
Result : Address)
is
LeftB : constant Bits := To_Bits (Left);
RightB : constant Bits := To_Bits (Right);
ResultB : constant Bits := To_Bits (Result);
begin
if Llen /= Rlen then
Raise_Error;
end if;
for J in 1 .. (Rlen + 7) / 8 loop
ResultB (J) := LeftB (J) xor RightB (J);
end loop;
end Bit_Xor;
-----------------
-- Raise_Error --
-----------------
procedure Raise_Error is
begin
Raise_Exception (CE, "unequal lengths in logical operation");
end Raise_Error;
end System.Bit_Ops;
|
with Memory.Register; use Memory.Register;
with Memory.Transform.Offset; use Memory.Transform.Offset;
with Memory.Join; use Memory.Join;
package body Test.Register is
procedure Test_Insert is
ram : constant Monitor_Pointer := Create_Monitor(10);
offset : Offset_Pointer := Create_Offset;
bank : constant Offset_Pointer := Create_Offset;
join : constant Join_Pointer := Create_Join(offset, 0);
begin
Set_Value(offset.all, 4);
Set_Value(bank.all, 4);
Set_Memory(offset.all, ram);
Set_Memory(bank.all, join);
Set_Bank(offset.all, bank);
Check(Get_Path_Length(ram.all) = 0);
Check(Get_Path_Length(bank.all) = 64);
Check(Get_Path_Length(offset.all) = 96);
Check(Get_Time(offset.all) = 0);
Check(Get_Writes(offset.all) = 0);
Check(Get_Cost(offset.all) = 0);
Read(offset.all, 0, 1);
Check(ram.reads = 1);
Check(Get_Time(offset.all) = 11);
Check(Get_Time(ram.all) = 11);
Write(offset.all, 0, 1);
Check(Get_Time(offset.all) = 22);
Check(Get_Writes(offset.all) = 1);
Insert_Registers(offset);
Check(Get_Path_Length(ram.all) = 0);
Check(Get_Path_Length(bank.all) = 64);
Check(Get_Path_Length(offset.all) = 32);
Check(Get_Max_Length(offset) = 64);
Reset(offset.all, 0);
Check(Get_Time(offset.all) = 0);
Read(offset.all, 0, 1);
Check(Get_Time(offset.all) = 12);
Check(Get_Time(ram.all) = 11);
Write(offset.all, 0, 1);
Check(Get_Time(offset.all) = 24);
Check(Get_Writes(offset.all) = 1);
offset := Offset_Pointer(Remove_Registers(Memory_Pointer(offset)));
Reset(offset.all, 0);
Check(Get_Time(offset.all) = 0);
Read(offset.all, 0, 1);
Check(Get_Time(offset.all) = 11);
Check(Get_Time(ram.all) = 11);
Write(offset.all, 0, 1);
Check(Get_Time(offset.all) = 22);
Check(Get_Writes(offset.all) = 1);
Destroy(Memory_Pointer(offset));
end Test_Insert;
procedure Run_Tests is
begin
Test_Insert;
end Run_Tests;
end Test.Register;
|
pragma License (Unrestricted);
package System.Interrupt_Management.Operations is
procedure Set_Interrupt_Mask (Mask : access Interrupt_Mask);
procedure Set_Interrupt_Mask (
Mask : access Interrupt_Mask;
OMask : access Interrupt_Mask);
procedure Get_Interrupt_Mask (Mask : access Interrupt_Mask);
procedure Fill_Interrupt_Mask (Mask : access Interrupt_Mask);
procedure Add_To_Interrupt_Mask (
Mask : access Interrupt_Mask;
Interrupt : Interrupt_ID);
procedure Copy_Interrupt_Mask (
X : out Interrupt_Mask;
Y : Interrupt_Mask);
end System.Interrupt_Management.Operations;
|
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Command_Line;
procedure Floyd_Triangle is
Rows: constant Positive := Integer'Value(Ada.Command_Line.Argument(1));
Current: Positive := 1;
Width: array(1 .. Rows) of Positive;
begin
-- compute the width for the different columns
for I in Width'Range loop
Width(I) := Integer'Image(I + (Rows * (Rows-1))/2)'Length;
end loop;
-- output the triangle
for Line in 1 .. Rows loop
for Column in 1 .. Line loop
Ada.Integer_Text_IO.Put(Current, Width => Width(Column));
Current := Current + 1;
end loop;
Ada.Text_IO.New_Line;
end loop;
end Floyd_Triangle;
|
with Ada.Finalization;
with System.Initialization;
with System.Storage_Elements;
procedure init is
use type System.Address;
begin
-- controlled type
declare
type Phase_Type is (Uninitialized, Initialized, Finalized);
Phase : Phase_Type := Uninitialized;
The_Address : System.Address;
Adjust_Count : Natural := 0;
In_Another : Boolean := False; -- handling Another_Object
type Dummy is new Ada.Finalization.Controlled with null record;
overriding procedure Initialize (Object : in out Dummy);
overriding procedure Adjust (Object : in out Dummy);
overriding procedure Finalize (Object : in out Dummy);
overriding procedure Initialize (Object : in out Dummy) is
begin
pragma Assert (Object'Address = The_Address);
pragma Assert (Phase = Uninitialized);
Phase := Initialized;
end Initialize;
overriding procedure Adjust (Object : in out Dummy) is
begin
pragma Assert (Object'Address = The_Address);
pragma Assert (Phase = Finalized);
Phase := Initialized;
Adjust_Count := Adjust_Count + 1;
end Adjust;
overriding procedure Finalize (Object : in out Dummy) is
begin
if not In_Another then
pragma Assert (Object'Address = The_Address);
pragma Assert (Phase = Initialized);
Phase := Finalized;
end if;
end Finalize;
Another_Object : Dummy := (Ada.Finalization.Controlled with null record);
Alignment_Of_Dummy : constant :=
System.Storage_Elements.Integer_Address'Alignment;
-- Dummy'Alignment; -- is not static.
package I is new System.Initialization (Dummy);
type Object_Storage is new I.Object_Storage;
for Object_Storage'Alignment use Alignment_Of_Dummy;
Storage : aliased Object_Storage;
P : access Dummy;
begin
pragma Assert (Object_Storage'Size = Dummy'Size);
pragma Assert (Object_Storage'Alignment = Dummy'Alignment);
The_Address := Storage'Address;
P := New_Object (Storage'Access);
pragma Assert (Phase = Initialized);
pragma Assert (Adjust_Count = 0);
P.all := Another_Object;
pragma Assert (Phase = Initialized);
pragma Assert (Adjust_Count = 1);
Dispose_Object (Storage'Access);
pragma Assert (Phase = Finalized);
In_Another := True; -- for finalizing Anotehr_Object
end;
-- default value
declare
type T is record
F : Integer := 123;
end record;
Alignment_Of_T : constant := Integer'Alignment;
package J is new System.Initialization (T);
type Object_Storage is new J.Object_Storage;
for Object_Storage'Alignment use Alignment_Of_T;
Storage : aliased Object_Storage;
P : access T;
begin
pragma Assert (Object_Storage'Size = T'Size);
pragma Assert (Object_Storage'Alignment = T'Alignment);
P := New_Object (Storage'Access);
pragma Assert (P.all = (F => 123));
P := New_Object (Storage'Access, (F => 456));
pragma Assert (P.all = (F => 456));
end;
pragma Debug (Ada.Debug.Put ("OK"));
end init;
|
with Last_Chance_Handler; pragma Unreferenced (Last_Chance_Handler);
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Text_IO; use Ada.Text_IO;
with STM32GD.Board; use STM32GD.Board;
with STM32GD.GPIO; use STM32GD.GPIO;
with STM32GD.GPIO.Pin;
with STM32GD.EXTI;
with STM32_SVD.AFIO;
with STM32_SVD.NVIC;
with STM32_SVD.RCC;
with Peripherals; use Peripherals;
procedure Main is
Next_Release : Time := Clock;
Period : constant Time_Span := Milliseconds (1000); -- arbitrary
begin
Init;
STM32_SVD.NVIC.NVIC_Periph.ISER0 := 2#00000000_10011000_00000000_00000000#;
Put_Line ("Init");
USB_Re_Enumerate;
USB.Init;
LED2.Set;
Put_Line ("Starting");
loop
LED2.Toggle;
Next_Release := Next_Release + Period;
delay until Next_Release;
end loop;
end Main;
|
-- Motherlode
-- Copyright (c) 2020 Fabien Chouteau
with PyGamer; use PyGamer;
with HAL; use HAL;
with Sound;
with PyGamer.Controls;
with PyGamer.Time;
with Parameters;
with World; use World;
with Player;
with Cargo_Menu;
with Equipment_Menu;
with Render;
package body Motherload is
-----------------
-- Draw_Screen --
-----------------
procedure Draw_Screen (FB : in out HAL.UInt16_Array) is
begin
Render.Draw_World (FB);
end Draw_Screen;
---------
-- Run --
---------
procedure Run is
Period : constant Time.Time_Ms := Parameters.Frame_Period;
Next_Release : Time.Time_Ms;
begin
Next_Release := Time.Clock;
Sound.Stop_Music;
Generate_Ground;
Player.Spawn;
loop
Controls.Scan;
if Controls.Pressed (Controls.Up) then
Player.Move_Up;
elsif Controls.Pressed (Controls.Down) then
Player.Move_Down;
end if;
if Controls.Pressed (Controls.Left) then
Player.Move_Left;
elsif Controls.Pressed (Controls.Right) then
Player.Move_Right;
end if;
if Controls.Pressed (Controls.A) then
Player.Drill;
end if;
if Controls.Falling (Controls.Sel) then
Cargo_Menu.Run;
Next_Release := Time.Clock;
end if;
-- Fuel pump
if Player.Position.Y in 16 * 2 .. 16 * 3
and then
Player.Position.X in 16 * 25 .. 16 * 26
then
Equipment_Menu.Run;
Next_Release := Time.Clock;
Player.Move ((Parameters.Spawn_X, Parameters.Spawn_Y));
end if;
if Render.Flip then
Render.Refresh_Screen (Render.FB1'Access);
Draw_Screen (Render.FB2);
else
Render.Refresh_Screen (Render.FB2'Access);
Draw_Screen (Render.FB1);
end if;
Render.Flip := not Render.Flip;
Player.Update;
Sound.Tick;
Time.Delay_Until (Next_Release);
Next_Release := Next_Release + Period;
end loop;
end Run;
end Motherload;
|
-- REST API Validation
-- API to validate
-- ------------ EDIT NOTE ------------
-- This file was generated with openapi-generator. You can modify it to implement
-- the server. After you modify this file, you should add the following line
-- to the .openapi-generator-ignore file:
--
-- src/testapi.ads
--
-- Then, you can drop this edit note comment.
-- ------------ EDIT NOTE ------------
package TestAPI is
end TestAPI;
|
generic
Fraction : Float;
-- How large a fraction of the execution time should be allocated
-- to creating backups.
with procedure Save_State;
-- Should save the relevant state.
package JSA.Intermediate_Backups is
procedure Begin_Loop
with Pre => not In_Loop;
-- To be called before entering a loop performing
-- heavy/long-running calculations.
--
-- Sets up timers and counters.
procedure End_Of_Iteration
with Pre => In_Loop;
-- To be called at the end of a loop performing heavy/long-running
-- calculations.
--
-- Will call Save_State if it is considered timely.
procedure End_Loop
with Pre => In_Loop;
-- To be called immediately after the end of a loop performing
-- heavy/long-running calculations.
--
-- Will call Save_State if the last execution of End_Of_Iteration
-- didn't.
function In_Loop return Boolean;
end JSA.Intermediate_Backups;
|
pragma Task_Dispatching_Policy(FIFO_Within_Priorities);
with Ada.Text_IO;use Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Dispatching; use Ada.Dispatching;
with System; use System;
procedure fixed_priority is
pragma Priority(System.Priority'Last);
protected release_manager is
procedure release(num : in Integer);
entry t1_release;
entry t2_release;
entry t3_release;
private
t1 : Boolean;
t2 : Boolean;
t3 : Boolean;
min_int : Time_Span := Milliseconds(3000);
last_release : Time;
end release_manager;
protected body release_manager is
procedure release(num : in Integer ) is
begin
if num = 3 then
t1 := True;
t3 := True;
else
t1 := True;
t2 := True;
end if;
end release;
entry t1_release when t1 is
begin
t1 := False;
end t1_release;
entry t2_release when t2 is
begin
t2 := False;
end t2_release;
entry t3_release when t3 is
begin
t3 := False;
end t3_release;
end release_manager;
task type tsk1 is
pragma Priority(System.Priority'Last - 1);
end tsk1;
task type tsk2 is
pragma Priority(System.Priority'Last - 2);
end tsk2;
task type tsk3 is
pragma Priority(System.Priority'Last - 2);
end tsk3;
task type server is
pragma Priority(System.Priority'Last);
end server;
task body tsk1 is
begin
loop
release_manager.t1_release;
Put_Line("tsk1 released");
end loop;
end tsk1;
task body tsk2 is
begin
loop
release_manager.t2_release;
Put_Line("tsk2 released");
end loop;
end tsk2;
task body tsk3 is
begin
loop
release_manager.t3_release;
Put_Line("tsk3 released");
end loop;
end tsk3;
task body server is
current : Time := Clock;
interval: Time_Span := Milliseconds(300);
begin
loop
release_manager.release(3);
delay until current + interval;
current := Clock;
release_manager.release(2);
delay until current + interval;
current := Clock;
end loop;
end server;
tk1 : tsk1;
tk2 : tsk2;
tk3 : tsk3;
ss : server;
begin
Put_Line("This is an example of rate monotonic fixed priority scheduling");
end fixed_priority;
|
with Ada.Containers.Indefinite_Vectors;
with System;
package OpenAL.List is
package String_Vectors is new Ada.Containers.Indefinite_Vectors
(Index_Type => Positive,
Element_Type => String);
subtype String_Vector_t is String_Vectors.Vector;
procedure Address_To_Vector
(Address : in System.Address;
List : out String_Vector_t);
end OpenAL.List;
|
with Ada.Integer_Text_IO, Ada.Float_Text_IO;
package body S_Expr.Parser is
function Parse(Input: String) return List_Of_Data is
procedure First_Token(S: String;
Start_Of_Token, End_Of_Token: out Positive) is
begin
Start_Of_Token := S'First;
while Start_Of_Token <= S'Last and then S(Start_Of_Token) = ' ' loop
Start_Of_Token := Start_Of_Token + 1; -- skip spaces
end loop;
if Start_Of_Token > S'Last then
End_Of_Token := Start_Of_Token - 1;
-- S(Start_Of_Token .. End_Of_Token) is the empty string
elsif (S(Start_Of_Token) = '(') or (S(Start_Of_Token) = ')') then
End_OF_Token := Start_Of_Token; -- the bracket is the token
elsif S(Start_Of_Token) = '"' then -- " -- begin quoted string
End_Of_Token := Start_Of_Token + 1;
while S(End_Of_Token) /= '"' loop -- " -- search for closing bracket
End_Of_Token := End_Of_Token + 1;
end loop; -- raises Constraint_Error if closing bracket not found
else -- Token is some kind of string
End_Of_Token := Start_Of_Token;
while End_Of_Token < S'Last and then
((S(End_Of_Token+1) /= ' ') and (S(End_Of_Token+1) /= '(') and
(S(End_Of_Token+1) /= ')') and (S(End_Of_Token+1) /= '"')) loop -- "
End_Of_Token := End_Of_Token + 1;
end loop;
end if;
end First_Token;
procedure To_Int(Token: String; I: out Integer; Found: out Boolean) is
Last: Positive;
begin
Ada.Integer_Text_IO.Get(Token, I, Last);
Found := Last = Token'Last;
exception
when others => Found := False;
end To_Int;
procedure To_Flt(Token: String; F: out Float; Found: out Boolean) is
Last: Positive;
begin
Ada.Float_Text_IO.Get(Token, F, Last);
Found := Last = Token'Last;
exception
when others => Found := False;
end To_Flt;
function Quoted_String(Token: String) return Boolean is
begin
return
Token'Length >= 2 and then Token(Token'First)='"' -- "
and then Token(Token'Last) ='"'; -- "
end Quoted_String;
Start, Stop: Positive;
procedure Recursive_Parse(This: in out List_Of_Data) is
Found: Boolean;
Flt: Flt_Data;
Int: Int_Data;
Str: Str_Data;
Lst: List_Of_Data;
begin
while Input(Start .. Stop) /= "" loop
if Input(Start .. Stop) = ")" then
return;
elsif Input(Start .. Stop) = "(" then
First_Token(Input(Stop+1 .. Input'Last), Start, Stop);
Recursive_Parse(Lst);
This.Values.Append(Lst);
else
To_Int(Input(Start .. Stop), Int.Value, Found);
if Found then
This.Values.Append(Int);
else
To_Flt(Input(Start .. Stop), Flt.Value, Found);
if Found then
This.Values.Append(Flt);
else
if Quoted_String(Input(Start .. Stop)) then
Str.Value := -Input(Start+1 .. Stop-1);
Str.Quoted := True;
else
Str.Value := -Input(Start .. Stop);
Str.Quoted := False;
end if;
This.Values.Append(Str);
end if;
end if;
end if;
First_Token(Input(Stop+1 .. Input'Last), Start, Stop);
end loop;
end Recursive_Parse;
L: List_Of_Data;
begin
First_Token(Input, Start, Stop);
Recursive_Parse(L);
return L;
end Parse;
end S_Expr.Parser;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with Glfw.API;
with Glfw.Enums;
package body Glfw.Events.Keys is
function Name (Query : Key) return String is
begin
case Query is
when 32 .. 256 => return (1 => Character'Val (Query));
when Esc => return "Esc";
when F1 => return "F1";
when F2 => return "F2";
when F3 => return "F3";
when F4 => return "F4";
when F5 => return "F5";
when F6 => return "F6";
when F7 => return "F7";
when F8 => return "F8";
when F9 => return "F9";
when F10 => return "F10";
when F11 => return "F11";
when F12 => return "F12";
when F13 => return "F13";
when F14 => return "F14";
when F15 => return "F15";
when F16 => return "F16";
when F17 => return "F17";
when F18 => return "F18";
when F19 => return "F19";
when F20 => return "F20";
when F21 => return "F21";
when F22 => return "F22";
when F23 => return "F23";
when F24 => return "F24";
when F25 => return "F25";
when Up => return "Up";
when Down => return "Down";
when Left => return "Left";
when Right => return "Right";
when L_Shift => return "Left Shift";
when R_Shift => return "Right Shift";
when L_Ctrl => return "Left Ctrl";
when R_Ctrl => return "Right Ctrl";
when L_Alt => return "Left Alt";
when R_Alt => return "Right Alt";
when Tab => return "Tab";
when Enter => return "Enter";
when Backspace => return "Backspace";
when Insert => return "Insert";
when Del => return "Delete";
when Page_Up => return "Page Up";
when Page_Down => return "Page Down";
when Home => return "Home";
when End_Key => return "End";
when KP_0 => return "0 (Numpad)";
when KP_1 => return "1 (Numpad)";
when KP_2 => return "2 (Numpad)";
when KP_3 => return "3 (Numpad)";
when KP_4 => return "4 (Numpad)";
when KP_5 => return "5 (Numpad)";
when KP_6 => return "6 (Numpad)";
when KP_7 => return "7 (Numpad)";
when KP_8 => return "8 (Numpad)";
when KP_9 => return "9 (Numpad)";
when KP_Divide => return "/ (Numpad)";
when KP_Multiply => return "* (Numpad)";
when KP_Substract => return "- (Numpad)";
when KP_Add => return "+ (Numpad)";
when KP_Decimal => return ". (Numpad)";
when KP_Equal => return "= (Numpad)";
when KP_Enter => return "Enter (Numpad)";
when KP_Num_Lock => return "Numlock";
when Caps_Lock => return "Caps Lock";
when Scroll_Lock => return "Scroll Lock";
when Pause => return "Pause";
when L_Super => return "Left Super";
when R_Super => return "Right Super";
when Menu => return "Menu";
end case;
end Name;
function Pressed (Query : Key) return Boolean is
begin
return API.Get_Key (Query) = Press;
end Pressed;
procedure Raw_Key_Callback (Subject : Key; Action : Button_State);
procedure Raw_Character_Callback (Unicode_Char : Unicode_Character;
Action : Glfw.Events.Button_State);
pragma Convention (C, Raw_Key_Callback);
pragma Convention (C, Raw_Character_Callback);
User_Key_Callback : Key_Callback := null;
User_Character_Callback : Character_Callback := null;
procedure Raw_Key_Callback (Subject : Key; Action : Button_State) is
begin
if User_Key_Callback /= null then
User_Key_Callback (Subject, Action);
end if;
end Raw_Key_Callback;
procedure Raw_Character_Callback (Unicode_Char : Unicode_Character;
Action : Glfw.Events.Button_State) is
begin
if User_Character_Callback /= null then
User_Character_Callback (Unicode_Char, Action);
end if;
end Raw_Character_Callback;
procedure Set_Key_Callback (Callback : Key_Callback) is
begin
User_Key_Callback := Callback;
if Callback /= null then
API.Set_Key_Callback (Raw_Key_Callback'Access);
else
API.Set_Key_Callback (null);
end if;
end Set_Key_Callback;
procedure Set_Character_Callback (Callback : Character_Callback) is
begin
User_Character_Callback := Callback;
if Callback /= null then
API.Set_Char_Callback (Raw_Character_Callback'Access);
else
API.Set_Char_Callback (null);
end if;
end Set_Character_Callback;
procedure Toggle_Key_Repeat (Enable : Boolean) is
begin
if Enable then
API.Enable (Enums.Key_Repeat);
else
API.Disable (Enums.Key_Repeat);
end if;
end Toggle_Key_Repeat;
procedure Toggle_Sticky_Keys (Enable : Boolean) is
begin
if Enable then
API.Enable (Enums.Sticky_Keys);
else
API.Disable (Enums.Sticky_Keys);
end if;
end Toggle_Sticky_Keys;
procedure Toggle_System_Keys (Enable : Boolean) is
begin
if Enable then
API.Enable (Enums.System_Keys);
else
API.Disable (Enums.System_Keys);
end if;
end Toggle_System_Keys;
end Glfw.Events.Keys;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E X P _ U T I L --
-- --
-- B o d y --
-- --
-- $Revision$
-- --
-- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Checks; use Checks;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Exp_Ch7; use Exp_Ch7;
with Exp_Ch11; use Exp_Ch11;
with Hostparm; use Hostparm;
with Inline; use Inline;
with Itypes; use Itypes;
with Lib; use Lib;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Restrict; use Restrict;
with Sem; use Sem;
with Sem_Ch8; use Sem_Ch8;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Stand; use Stand;
with Stringt; use Stringt;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uintp; use Uintp;
with Validsw; use Validsw;
package body Exp_Util is
-----------------------
-- Local Subprograms --
-----------------------
function Build_Task_Array_Image
(Loc : Source_Ptr;
Id_Ref : Node_Id;
A_Type : Entity_Id;
Dyn : Boolean := False)
return Node_Id;
-- Build function to generate the image string for a task that is an
-- array component, concatenating the images of each index. To avoid
-- storage leaks, the string is built with successive slice assignments.
-- The flag Dyn indicates whether this is called for the initialization
-- procedure of an array of tasks, or for the name of a dynamically
-- created task that is assigned to an indexed component.
function Build_Task_Image_Function
(Loc : Source_Ptr;
Decls : List_Id;
Stats : List_Id;
Res : Entity_Id)
return Node_Id;
-- Common processing for Task_Array_Image and Task_Record_Image.
-- Build function body that computes image.
procedure Build_Task_Image_Prefix
(Loc : Source_Ptr;
Len : out Entity_Id;
Res : out Entity_Id;
Pos : out Entity_Id;
Prefix : Entity_Id;
Sum : Node_Id;
Decls : in out List_Id;
Stats : in out List_Id);
-- Common processing for Task_Array_Image and Task_Record_Image.
-- Create local variables and assign prefix of name to result string.
function Build_Task_Record_Image
(Loc : Source_Ptr;
Id_Ref : Node_Id;
A_Type : Entity_Id;
Dyn : Boolean := False)
return Node_Id;
-- Build function to generate the image string for a task that is a
-- record component. Concatenate name of variable with that of selector.
-- The flag Dyn indicates whether this is called for the initialization
-- procedure of record with task components, or for a dynamically
-- created task that is assigned to a selected component.
function Make_CW_Equivalent_Type
(T : Entity_Id;
E : Node_Id)
return Entity_Id;
-- T is a class-wide type entity, E is the initial expression node that
-- constrains T in case such as: " X: T := E" or "new T'(E)"
-- This function returns the entity of the Equivalent type and inserts
-- on the fly the necessary declaration such as:
-- type anon is record
-- _parent : Root_Type (T); constrained with E discriminants (if any)
-- Extension : String (1 .. expr to match size of E);
-- end record;
--
-- This record is compatible with any object of the class of T thanks
-- to the first field and has the same size as E thanks to the second.
function Make_Literal_Range
(Loc : Source_Ptr;
Literal_Typ : Entity_Id)
return Node_Id;
-- Produce a Range node whose bounds are:
-- Low_Bound (Literal_Type) ..
-- Low_Bound (Literal_Type) + Length (Literal_Typ) - 1
-- this is used for expanding declarations like X : String := "sdfgdfg";
function New_Class_Wide_Subtype
(CW_Typ : Entity_Id;
N : Node_Id)
return Entity_Id;
-- Create an implicit subtype of CW_Typ attached to node N.
----------------------
-- Adjust_Condition --
----------------------
procedure Adjust_Condition (N : Node_Id) is
begin
if No (N) then
return;
end if;
declare
Loc : constant Source_Ptr := Sloc (N);
T : constant Entity_Id := Etype (N);
Ti : Entity_Id;
begin
-- For now, we simply ignore a call where the argument has no
-- type (probably case of unanalyzed condition), or has a type
-- that is not Boolean. This is because this is a pretty marginal
-- piece of functionality, and violations of these rules are
-- likely to be truly marginal (how much code uses Fortran Logical
-- as the barrier to a protected entry?) and we do not want to
-- blow up existing programs. We can change this to an assertion
-- after 3.12a is released ???
if No (T) or else not Is_Boolean_Type (T) then
return;
end if;
-- Apply validity checking if needed
if Validity_Checks_On and Validity_Check_Tests then
Ensure_Valid (N);
end if;
-- Immediate return if standard boolean, the most common case,
-- where nothing needs to be done.
if Base_Type (T) = Standard_Boolean then
return;
end if;
-- Case of zero/non-zero semantics or non-standard enumeration
-- representation. In each case, we rewrite the node as:
-- ityp!(N) /= False'Enum_Rep
-- where ityp is an integer type with large enough size to hold
-- any value of type T.
if Nonzero_Is_True (T) or else Has_Non_Standard_Rep (T) then
if Esize (T) <= Esize (Standard_Integer) then
Ti := Standard_Integer;
else
Ti := Standard_Long_Long_Integer;
end if;
Rewrite (N,
Make_Op_Ne (Loc,
Left_Opnd => Unchecked_Convert_To (Ti, N),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Enum_Rep,
Prefix =>
New_Occurrence_Of (First_Literal (T), Loc))));
Analyze_And_Resolve (N, Standard_Boolean);
else
Rewrite (N, Convert_To (Standard_Boolean, N));
Analyze_And_Resolve (N, Standard_Boolean);
end if;
end;
end Adjust_Condition;
------------------------
-- Adjust_Result_Type --
------------------------
procedure Adjust_Result_Type (N : Node_Id; T : Entity_Id) is
begin
-- Ignore call if current type is not Standard.Boolean
if Etype (N) /= Standard_Boolean then
return;
end if;
-- If result is already of correct type, nothing to do. Note that
-- this will get the most common case where everything has a type
-- of Standard.Boolean.
if Base_Type (T) = Standard_Boolean then
return;
else
declare
KP : constant Node_Kind := Nkind (Parent (N));
begin
-- If result is to be used as a Condition in the syntax, no need
-- to convert it back, since if it was changed to Standard.Boolean
-- using Adjust_Condition, that is just fine for this usage.
if KP in N_Raise_xxx_Error or else KP in N_Has_Condition then
return;
-- If result is an operand of another logical operation, no need
-- to reset its type, since Standard.Boolean is just fine, and
-- such operations always do Adjust_Condition on their operands.
elsif KP in N_Op_Boolean
or else KP = N_And_Then
or else KP = N_Or_Else
or else KP = N_Op_Not
then
return;
-- Otherwise we perform a conversion from the current type,
-- which must be Standard.Boolean, to the desired type.
else
Set_Analyzed (N);
Rewrite (N, Convert_To (T, N));
Analyze_And_Resolve (N, T);
end if;
end;
end if;
end Adjust_Result_Type;
--------------------------
-- Append_Freeze_Action --
--------------------------
procedure Append_Freeze_Action (T : Entity_Id; N : Node_Id) is
Fnode : Node_Id := Freeze_Node (T);
begin
Ensure_Freeze_Node (T);
Fnode := Freeze_Node (T);
if not Present (Actions (Fnode)) then
Set_Actions (Fnode, New_List);
end if;
Append (N, Actions (Fnode));
end Append_Freeze_Action;
---------------------------
-- Append_Freeze_Actions --
---------------------------
procedure Append_Freeze_Actions (T : Entity_Id; L : List_Id) is
Fnode : constant Node_Id := Freeze_Node (T);
begin
if No (L) then
return;
else
if No (Actions (Fnode)) then
Set_Actions (Fnode, L);
else
Append_List (L, Actions (Fnode));
end if;
end if;
end Append_Freeze_Actions;
------------------------
-- Build_Runtime_Call --
------------------------
function Build_Runtime_Call (Loc : Source_Ptr; RE : RE_Id) return Node_Id is
begin
return
Make_Procedure_Call_Statement (Loc,
Name => New_Reference_To (RTE (RE), Loc));
end Build_Runtime_Call;
-----------------------------
-- Build_Task_Array_Image --
-----------------------------
-- This function generates the body for a function that constructs the
-- image string for a task that is an array component. The function is
-- local to the init_proc for the array type, and is called for each one
-- of the components. The constructed image has the form of an indexed
-- component, whose prefix is the outer variable of the array type.
-- The n-dimensional array type has known indices Index, Index2...
-- Id_Ref is an indexed component form created by the enclosing init_proc.
-- Its successive indices are Val1, Val2,.. which are the loop variables
-- in the loops that call the individual task init_proc on each component.
-- The generated function has the following structure:
-- function F return Task_Image_Type is
-- Pref : string := Task_Id.all;
-- T1 : String := Index1'Image (Val1);
-- ...
-- Tn : String := indexn'image (Valn);
-- Len : Integer := T1'Length + ... + Tn'Length + n + 1;
-- -- Len includes commas and the end parentheses.
-- Res : String (1..Len);
-- Pos : Integer := Pref'Length;
--
-- begin
-- Res (1 .. Pos) := Pref;
-- Pos := Pos + 1;
-- Res (Pos) := '(';
-- Pos := Pos + 1;
-- Res (Pos .. Pos + T1'Length - 1) := T1;
-- Pos := Pos + T1'Length;
-- Res (Pos) := '.';
-- Pos := Pos + 1;
-- ...
-- Res (Pos .. Pos + Tn'Length - 1) := Tn;
-- Res (Len) := ')';
--
-- return new String (Res);
-- end F;
--
-- Needless to say, multidimensional arrays of tasks are rare enough
-- that the bulkiness of this code is not really a concern.
function Build_Task_Array_Image
(Loc : Source_Ptr;
Id_Ref : Node_Id;
A_Type : Entity_Id;
Dyn : Boolean := False)
return Node_Id
is
Dims : constant Nat := Number_Dimensions (A_Type);
-- Number of dimensions for array of tasks.
Temps : array (1 .. Dims) of Entity_Id;
-- Array of temporaries to hold string for each index.
Indx : Node_Id;
-- Index expression
Len : Entity_Id;
-- Total length of generated name
Pos : Entity_Id;
-- Running index for substring assignments
Pref : Entity_Id;
-- Name of enclosing variable, prefix of resulting name
P_Nam : Node_Id;
-- string expression for Pref.
Res : Entity_Id;
-- String to hold result
Val : Node_Id;
-- Value of successive indices
Sum : Node_Id;
-- Expression to compute total size of string
T : Entity_Id;
-- Entity for name at one index position
Decls : List_Id := New_List;
Stats : List_Id := New_List;
begin
Pref := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
-- For a dynamic task, the name comes from the target variable.
-- For a static one it is a formal of the enclosing init_proc.
if Dyn then
Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
P_Nam :=
Make_String_Literal (Loc, Strval => String_From_Name_Buffer);
else
P_Nam :=
Make_Explicit_Dereference (Loc,
Prefix => Make_Identifier (Loc, Name_uTask_Id));
end if;
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Pref,
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
Expression => P_Nam));
Indx := First_Index (A_Type);
Val := First (Expressions (Id_Ref));
for J in 1 .. Dims loop
T := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
Temps (J) := T;
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => T,
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Image,
Prefix =>
New_Occurrence_Of (Etype (Indx), Loc),
Expressions => New_List (
New_Copy_Tree (Val)))));
Next_Index (Indx);
Next (Val);
end loop;
Sum := Make_Integer_Literal (Loc, Dims + 1);
Sum :=
Make_Op_Add (Loc,
Left_Opnd => Sum,
Right_Opnd =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Length,
Prefix =>
New_Occurrence_Of (Pref, Loc),
Expressions => New_List (Make_Integer_Literal (Loc, 1))));
for J in 1 .. Dims loop
Sum :=
Make_Op_Add (Loc,
Left_Opnd => Sum,
Right_Opnd =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Length,
Prefix =>
New_Occurrence_Of (Temps (J), Loc),
Expressions => New_List (Make_Integer_Literal (Loc, 1))));
end loop;
Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
Set_Character_Literal_Name (Char_Code (Character'Pos ('(')));
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => Make_Indexed_Component (Loc,
Prefix => New_Occurrence_Of (Res, Loc),
Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
Expression =>
Make_Character_Literal (Loc,
Chars => Name_Find,
Char_Literal_Value =>
Char_Code (Character'Pos ('(')))));
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Pos, Loc),
Expression =>
Make_Op_Add (Loc,
Left_Opnd => New_Occurrence_Of (Pos, Loc),
Right_Opnd => Make_Integer_Literal (Loc, 1))));
for J in 1 .. Dims loop
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => Make_Slice (Loc,
Prefix => New_Occurrence_Of (Res, Loc),
Discrete_Range =>
Make_Range (Loc,
Low_Bound => New_Occurrence_Of (Pos, Loc),
High_Bound => Make_Op_Subtract (Loc,
Left_Opnd =>
Make_Op_Add (Loc,
Left_Opnd => New_Occurrence_Of (Pos, Loc),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Length,
Prefix =>
New_Occurrence_Of (Temps (J), Loc),
Expressions =>
New_List (Make_Integer_Literal (Loc, 1)))),
Right_Opnd => Make_Integer_Literal (Loc, 1)))),
Expression => New_Occurrence_Of (Temps (J), Loc)));
if J < Dims then
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Pos, Loc),
Expression =>
Make_Op_Add (Loc,
Left_Opnd => New_Occurrence_Of (Pos, Loc),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Length,
Prefix => New_Occurrence_Of (Temps (J), Loc),
Expressions =>
New_List (Make_Integer_Literal (Loc, 1))))));
Set_Character_Literal_Name (Char_Code (Character'Pos (',')));
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => Make_Indexed_Component (Loc,
Prefix => New_Occurrence_Of (Res, Loc),
Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
Expression =>
Make_Character_Literal (Loc,
Chars => Name_Find,
Char_Literal_Value =>
Char_Code (Character'Pos (',')))));
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Pos, Loc),
Expression =>
Make_Op_Add (Loc,
Left_Opnd => New_Occurrence_Of (Pos, Loc),
Right_Opnd => Make_Integer_Literal (Loc, 1))));
end if;
end loop;
Set_Character_Literal_Name (Char_Code (Character'Pos (')')));
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => Make_Indexed_Component (Loc,
Prefix => New_Occurrence_Of (Res, Loc),
Expressions => New_List (New_Occurrence_Of (Len, Loc))),
Expression =>
Make_Character_Literal (Loc,
Chars => Name_Find,
Char_Literal_Value =>
Char_Code (Character'Pos (')')))));
return Build_Task_Image_Function (Loc, Decls, Stats, Res);
end Build_Task_Array_Image;
----------------------------
-- Build_Task_Image_Decls --
----------------------------
function Build_Task_Image_Decls
(Loc : Source_Ptr;
Id_Ref : Node_Id;
A_Type : Entity_Id)
return List_Id
is
T_Id : Entity_Id := Empty;
Decl : Node_Id;
Decls : List_Id := New_List;
Expr : Node_Id := Empty;
Fun : Node_Id := Empty;
Is_Dyn : constant Boolean :=
Nkind (Parent (Id_Ref)) = N_Assignment_Statement
and then Nkind (Expression (Parent (Id_Ref))) = N_Allocator;
begin
-- If Discard_Names is in effect, generate a dummy declaration only.
if Global_Discard_Names then
T_Id :=
Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
return
New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => T_Id,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Task_Image_Type), Loc)));
else
if Nkind (Id_Ref) = N_Identifier
or else Nkind (Id_Ref) = N_Defining_Identifier
then
-- For a simple variable, the image of the task is the name
-- of the variable.
T_Id :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (Id_Ref), 'I'));
Get_Name_String (Chars (Id_Ref));
Expr :=
Make_Allocator (Loc,
Expression =>
Make_Qualified_Expression (Loc,
Subtype_Mark =>
New_Occurrence_Of (Standard_String, Loc),
Expression =>
Make_String_Literal
(Loc, Strval => String_From_Name_Buffer)));
elsif Nkind (Id_Ref) = N_Selected_Component then
T_Id :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (Selector_Name (Id_Ref)), 'I'));
Fun := Build_Task_Record_Image (Loc, Id_Ref, A_Type, Is_Dyn);
elsif Nkind (Id_Ref) = N_Indexed_Component then
T_Id :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (A_Type), 'I'));
Fun := Build_Task_Array_Image (Loc, Id_Ref, A_Type, Is_Dyn);
end if;
end if;
if Present (Fun) then
Append (Fun, Decls);
Expr :=
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Defining_Entity (Fun), Loc));
end if;
Decl := Make_Object_Declaration (Loc,
Defining_Identifier => T_Id,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Task_Image_Type), Loc),
Expression => Expr);
Append (Decl, Decls);
return Decls;
end Build_Task_Image_Decls;
-------------------------------
-- Build_Task_Image_Function --
-------------------------------
function Build_Task_Image_Function
(Loc : Source_Ptr;
Decls : List_Id;
Stats : List_Id;
Res : Entity_Id)
return Node_Id
is
Spec : Node_Id;
begin
Append_To (Stats,
Make_Return_Statement (Loc,
Expression =>
Make_Allocator (Loc,
Expression =>
Make_Qualified_Expression (Loc,
Subtype_Mark =>
New_Occurrence_Of (Standard_String, Loc),
Expression => New_Occurrence_Of (Res, Loc)))));
Spec := Make_Function_Specification (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc, New_Internal_Name ('F')),
Subtype_Mark => New_Occurrence_Of (RTE (RE_Task_Image_Type), Loc));
return Make_Subprogram_Body (Loc,
Specification => Spec,
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stats));
end Build_Task_Image_Function;
-----------------------------
-- Build_Task_Image_Prefix --
-----------------------------
procedure Build_Task_Image_Prefix
(Loc : Source_Ptr;
Len : out Entity_Id;
Res : out Entity_Id;
Pos : out Entity_Id;
Prefix : Entity_Id;
Sum : Node_Id;
Decls : in out List_Id;
Stats : in out List_Id)
is
begin
Len := Make_Defining_Identifier (Loc, New_Internal_Name ('L'));
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Len,
Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
Expression => Sum));
Res := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Res,
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints =>
New_List (
Make_Range (Loc,
Low_Bound => Make_Integer_Literal (Loc, 1),
High_Bound => New_Occurrence_Of (Len, Loc)))))));
Pos := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Pos,
Object_Definition => New_Occurrence_Of (Standard_Integer, Loc)));
-- Pos := Prefix'Length;
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Pos, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Length,
Prefix => New_Occurrence_Of (Prefix, Loc),
Expressions =>
New_List (Make_Integer_Literal (Loc, 1)))));
-- Res (1 .. Pos) := Prefix;
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => Make_Slice (Loc,
Prefix => New_Occurrence_Of (Res, Loc),
Discrete_Range =>
Make_Range (Loc,
Low_Bound => Make_Integer_Literal (Loc, 1),
High_Bound => New_Occurrence_Of (Pos, Loc))),
Expression => New_Occurrence_Of (Prefix, Loc)));
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Pos, Loc),
Expression =>
Make_Op_Add (Loc,
Left_Opnd => New_Occurrence_Of (Pos, Loc),
Right_Opnd => Make_Integer_Literal (Loc, 1))));
end Build_Task_Image_Prefix;
-----------------------------
-- Build_Task_Record_Image --
-----------------------------
function Build_Task_Record_Image
(Loc : Source_Ptr;
Id_Ref : Node_Id;
A_Type : Entity_Id;
Dyn : Boolean := False)
return Node_Id
is
Len : Entity_Id;
-- Total length of generated name
Pos : Entity_Id;
-- Index into result
Res : Entity_Id;
-- String to hold result
Pref : Entity_Id;
-- Name of enclosing variable, prefix of resulting name
P_Nam : Node_Id;
-- string expression for Pref.
Sum : Node_Id;
-- Expression to compute total size of string.
Sel : Entity_Id;
-- Entity for selector name
Decls : List_Id := New_List;
Stats : List_Id := New_List;
begin
Pref := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
-- For a dynamic task, the name comes from the target variable.
-- For a static one it is a formal of the enclosing init_proc.
if Dyn then
Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
P_Nam :=
Make_String_Literal (Loc, Strval => String_From_Name_Buffer);
else
P_Nam :=
Make_Explicit_Dereference (Loc,
Prefix => Make_Identifier (Loc, Name_uTask_Id));
end if;
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Pref,
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
Expression => P_Nam));
Sel := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
Get_Name_String (Chars (Selector_Name (Id_Ref)));
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Sel,
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
Expression =>
Make_String_Literal (Loc, Strval => String_From_Name_Buffer)));
Sum := Make_Integer_Literal (Loc, Nat (Name_Len + 1));
Sum :=
Make_Op_Add (Loc,
Left_Opnd => Sum,
Right_Opnd =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Length,
Prefix =>
New_Occurrence_Of (Pref, Loc),
Expressions => New_List (Make_Integer_Literal (Loc, 1))));
Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
Set_Character_Literal_Name (Char_Code (Character'Pos ('.')));
-- Res (Pos) := '.';
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => Make_Indexed_Component (Loc,
Prefix => New_Occurrence_Of (Res, Loc),
Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
Expression =>
Make_Character_Literal (Loc,
Chars => Name_Find,
Char_Literal_Value =>
Char_Code (Character'Pos ('.')))));
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Pos, Loc),
Expression =>
Make_Op_Add (Loc,
Left_Opnd => New_Occurrence_Of (Pos, Loc),
Right_Opnd => Make_Integer_Literal (Loc, 1))));
-- Res (Pos .. Len) := Selector;
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => Make_Slice (Loc,
Prefix => New_Occurrence_Of (Res, Loc),
Discrete_Range =>
Make_Range (Loc,
Low_Bound => New_Occurrence_Of (Pos, Loc),
High_Bound => New_Occurrence_Of (Len, Loc))),
Expression => New_Occurrence_Of (Sel, Loc)));
return Build_Task_Image_Function (Loc, Decls, Stats, Res);
end Build_Task_Record_Image;
-------------------------------
-- Convert_To_Actual_Subtype --
-------------------------------
procedure Convert_To_Actual_Subtype (Exp : Entity_Id) is
Act_ST : Entity_Id;
begin
Act_ST := Get_Actual_Subtype (Exp);
if Act_ST = Etype (Exp) then
return;
else
Rewrite (Exp,
Convert_To (Act_ST, Relocate_Node (Exp)));
Analyze_And_Resolve (Exp, Act_ST);
end if;
end Convert_To_Actual_Subtype;
-----------------------------------
-- Current_Sem_Unit_Declarations --
-----------------------------------
function Current_Sem_Unit_Declarations return List_Id is
U : Node_Id := Unit (Cunit (Current_Sem_Unit));
Decls : List_Id;
begin
-- If the current unit is a package body, locate the visible
-- declarations of the package spec.
if Nkind (U) = N_Package_Body then
U := Unit (Library_Unit (Cunit (Current_Sem_Unit)));
end if;
if Nkind (U) = N_Package_Declaration then
U := Specification (U);
Decls := Visible_Declarations (U);
if No (Decls) then
Decls := New_List;
Set_Visible_Declarations (U, Decls);
end if;
else
Decls := Declarations (U);
if No (Decls) then
Decls := New_List;
Set_Declarations (U, Decls);
end if;
end if;
return Decls;
end Current_Sem_Unit_Declarations;
-----------------------
-- Duplicate_Subexpr --
-----------------------
function Duplicate_Subexpr
(Exp : Node_Id;
Name_Req : Boolean := False)
return Node_Id
is
begin
Remove_Side_Effects (Exp, Name_Req);
return New_Copy_Tree (Exp);
end Duplicate_Subexpr;
--------------------
-- Ensure_Defined --
--------------------
procedure Ensure_Defined (Typ : Entity_Id; N : Node_Id) is
IR : Node_Id;
P : Node_Id;
begin
if Is_Itype (Typ) then
IR := Make_Itype_Reference (Sloc (N));
Set_Itype (IR, Typ);
if not In_Open_Scopes (Scope (Typ))
and then Is_Subprogram (Current_Scope)
and then Scope (Current_Scope) /= Standard_Standard
then
-- Insert node in front of subprogram, to avoid scope anomalies
-- in gigi.
P := Parent (N);
while Present (P)
and then Nkind (P) /= N_Subprogram_Body
loop
P := Parent (P);
end loop;
if Present (P) then
Insert_Action (P, IR);
else
Insert_Action (N, IR);
end if;
else
Insert_Action (N, IR);
end if;
end if;
end Ensure_Defined;
---------------------
-- Evolve_And_Then --
---------------------
procedure Evolve_And_Then (Cond : in out Node_Id; Cond1 : Node_Id) is
begin
if No (Cond) then
Cond := Cond1;
else
Cond :=
Make_And_Then (Sloc (Cond1),
Left_Opnd => Cond,
Right_Opnd => Cond1);
end if;
end Evolve_And_Then;
--------------------
-- Evolve_Or_Else --
--------------------
procedure Evolve_Or_Else (Cond : in out Node_Id; Cond1 : Node_Id) is
begin
if No (Cond) then
Cond := Cond1;
else
Cond :=
Make_Or_Else (Sloc (Cond1),
Left_Opnd => Cond,
Right_Opnd => Cond1);
end if;
end Evolve_Or_Else;
------------------------------
-- Expand_Subtype_From_Expr --
------------------------------
-- This function is applicable for both static and dynamic allocation of
-- objects which are constrained by an initial expression. Basically it
-- transforms an unconstrained subtype indication into a constrained one.
-- The expression may also be transformed in certain cases in order to
-- avoid multiple evaulation. In the static allocation case, the general
-- scheme is :
-- Val : T := Expr;
-- is transformed into
-- Val : Constrained_Subtype_of_T := Maybe_Modified_Expr;
--
-- Here are the main cases :
--
-- <if Expr is a Slice>
-- Val : T ([Index_Subtype (Expr)]) := Expr;
--
-- <elsif Expr is a String Literal>
-- Val : T (T'First .. T'First + Length (string literal) - 1) := Expr;
--
-- <elsif Expr is Constrained>
-- subtype T is Type_Of_Expr
-- Val : T := Expr;
--
-- <elsif Expr is an entity_name>
-- Val : T (constraints taken from Expr) := Expr;
--
-- <else>
-- type Axxx is access all T;
-- Rval : Axxx := Expr'ref;
-- Val : T (constraints taken from Rval) := Rval.all;
-- ??? note: when the Expression is allocated in the secondary stack
-- we could use it directly instead of copying it by declaring
-- Val : T (...) renames Rval.all
procedure Expand_Subtype_From_Expr
(N : Node_Id;
Unc_Type : Entity_Id;
Subtype_Indic : Node_Id;
Exp : Node_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Exp_Typ : constant Entity_Id := Etype (Exp);
T : Entity_Id;
begin
-- In general we cannot build the subtype if expansion is disabled,
-- because internal entities may not have been defined. However, to
-- avoid some cascaded errors, we try to continue when the expression
-- is an array (or string), because it is safe to compute the bounds.
-- It is in fact required to do so even in a generic context, because
-- there may be constants that depend on bounds of string literal.
if not Expander_Active
and then (No (Etype (Exp))
or else Base_Type (Etype (Exp)) /= Standard_String)
then
return;
end if;
if Nkind (Exp) = N_Slice then
declare
Slice_Type : constant Entity_Id := Etype (First_Index (Exp_Typ));
begin
Rewrite (Subtype_Indic,
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Reference_To (Unc_Type, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List
(New_Reference_To (Slice_Type, Loc)))));
-- This subtype indication may be used later for contraint checks
-- we better make sure that if a variable was used as a bound of
-- of the original slice, its value is frozen.
Force_Evaluation (Low_Bound (Scalar_Range (Slice_Type)));
Force_Evaluation (High_Bound (Scalar_Range (Slice_Type)));
end;
elsif Ekind (Exp_Typ) = E_String_Literal_Subtype then
Rewrite (Subtype_Indic,
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Reference_To (Unc_Type, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (
Make_Literal_Range (Loc,
Literal_Typ => Exp_Typ)))));
elsif Is_Constrained (Exp_Typ)
and then not Is_Class_Wide_Type (Unc_Type)
then
if Is_Itype (Exp_Typ) then
-- No need to generate a new one.
T := Exp_Typ;
else
T :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('T'));
Insert_Action (N,
Make_Subtype_Declaration (Loc,
Defining_Identifier => T,
Subtype_Indication => New_Reference_To (Exp_Typ, Loc)));
-- This type is marked as an itype even though it has an
-- explicit declaration because otherwise it can be marked
-- with Is_Generic_Actual_Type and generate spurious errors.
-- (see sem_ch8.Analyze_Package_Renaming and sem_type.covers)
Set_Is_Itype (T);
Set_Associated_Node_For_Itype (T, Exp);
end if;
Rewrite (Subtype_Indic, New_Reference_To (T, Loc));
-- nothing needs to be done for private types with unknown discriminants
-- if the underlying type is not an unconstrained composite type.
elsif Is_Private_Type (Unc_Type)
and then Has_Unknown_Discriminants (Unc_Type)
and then (not Is_Composite_Type (Underlying_Type (Unc_Type))
or else Is_Constrained (Underlying_Type (Unc_Type)))
then
null;
else
Remove_Side_Effects (Exp);
Rewrite (Subtype_Indic,
Make_Subtype_From_Expr (Exp, Unc_Type));
end if;
end Expand_Subtype_From_Expr;
------------------
-- Find_Prim_Op --
------------------
function Find_Prim_Op (T : Entity_Id; Name : Name_Id) return Entity_Id is
Prim : Elmt_Id;
Typ : Entity_Id := T;
begin
if Is_Class_Wide_Type (Typ) then
Typ := Root_Type (Typ);
end if;
Typ := Underlying_Type (Typ);
Prim := First_Elmt (Primitive_Operations (Typ));
while Chars (Node (Prim)) /= Name loop
Next_Elmt (Prim);
pragma Assert (Present (Prim));
end loop;
return Node (Prim);
end Find_Prim_Op;
----------------------
-- Force_Evaluation --
----------------------
procedure Force_Evaluation (Exp : Node_Id; Name_Req : Boolean := False) is
begin
Remove_Side_Effects (Exp, Name_Req, Variable_Ref => True);
end Force_Evaluation;
------------------------
-- Generate_Poll_Call --
------------------------
procedure Generate_Poll_Call (N : Node_Id) is
begin
-- No poll call if polling not active
if not Polling_Required then
return;
-- Otherwise generate require poll call
else
Insert_Before_And_Analyze (N,
Make_Procedure_Call_Statement (Sloc (N),
Name => New_Occurrence_Of (RTE (RE_Poll), Sloc (N))));
end if;
end Generate_Poll_Call;
--------------------
-- Homonym_Number --
--------------------
function Homonym_Number (Subp : Entity_Id) return Nat is
Count : Nat;
Hom : Entity_Id;
begin
Count := 1;
Hom := Homonym (Subp);
while Present (Hom) loop
if Scope (Hom) = Scope (Subp) then
Count := Count + 1;
end if;
Hom := Homonym (Hom);
end loop;
return Count;
end Homonym_Number;
------------------------------
-- In_Unconditional_Context --
------------------------------
function In_Unconditional_Context (Node : Node_Id) return Boolean is
P : Node_Id;
begin
P := Node;
while Present (P) loop
case Nkind (P) is
when N_Subprogram_Body =>
return True;
when N_If_Statement =>
return False;
when N_Loop_Statement =>
return False;
when N_Case_Statement =>
return False;
when others =>
P := Parent (P);
end case;
end loop;
return False;
end In_Unconditional_Context;
-------------------
-- Insert_Action --
-------------------
procedure Insert_Action (Assoc_Node : Node_Id; Ins_Action : Node_Id) is
begin
if Present (Ins_Action) then
Insert_Actions (Assoc_Node, New_List (Ins_Action));
end if;
end Insert_Action;
-- Version with check(s) suppressed
procedure Insert_Action
(Assoc_Node : Node_Id; Ins_Action : Node_Id; Suppress : Check_Id)
is
begin
Insert_Actions (Assoc_Node, New_List (Ins_Action), Suppress);
end Insert_Action;
--------------------
-- Insert_Actions --
--------------------
procedure Insert_Actions (Assoc_Node : Node_Id; Ins_Actions : List_Id) is
N : Node_Id;
P : Node_Id;
Wrapped_Node : Node_Id := Empty;
begin
if No (Ins_Actions) or else Is_Empty_List (Ins_Actions) then
return;
end if;
-- Ignore insert of actions from inside default expression in the
-- special preliminary analyze mode. Any insertions at this point
-- have no relevance, since we are only doing the analyze to freeze
-- the types of any static expressions. See section "Handling of
-- Default Expressions" in the spec of package Sem for further details.
if In_Default_Expression then
return;
end if;
-- If the action derives from stuff inside a record, then the actions
-- are attached to the current scope, to be inserted and analyzed on
-- exit from the scope. The reason for this is that we may also
-- be generating freeze actions at the same time, and they must
-- eventually be elaborated in the correct order.
if Is_Record_Type (Current_Scope)
and then not Is_Frozen (Current_Scope)
then
if No (Scope_Stack.Table
(Scope_Stack.Last).Pending_Freeze_Actions)
then
Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions :=
Ins_Actions;
else
Append_List
(Ins_Actions,
Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions);
end if;
return;
end if;
-- We now intend to climb up the tree to find the right point to
-- insert the actions. We start at Assoc_Node, unless this node is
-- a subexpression in which case we start with its parent. We do this
-- for two reasons. First it speeds things up. Second, if Assoc_Node
-- is itself one of the special nodes like N_And_Then, then we assume
-- that an initial request to insert actions for such a node does not
-- expect the actions to get deposited in the node for later handling
-- when the node is expanded, since clearly the node is being dealt
-- with by the caller. Note that in the subexpression case, N is
-- always the child we came from.
-- N_Raise_xxx_Error is an annoying special case, it is a statement
-- if it has type Standard_Void_Type, and a subexpression otherwise.
-- otherwise. Procedure attribute references are also statements.
if Nkind (Assoc_Node) in N_Subexpr
and then (Nkind (Assoc_Node) in N_Raise_xxx_Error
or else Etype (Assoc_Node) /= Standard_Void_Type)
and then (Nkind (Assoc_Node) /= N_Attribute_Reference
or else
not Is_Procedure_Attribute_Name
(Attribute_Name (Assoc_Node)))
then
P := Assoc_Node; -- ????? does not agree with above!
N := Parent (Assoc_Node);
-- Non-subexpression case. Note that N is initially Empty in this
-- case (N is only guaranteed Non-Empty in the subexpr case).
else
P := Assoc_Node;
N := Empty;
end if;
-- Capture root of the transient scope
if Scope_Is_Transient then
Wrapped_Node := Node_To_Be_Wrapped;
end if;
loop
pragma Assert (Present (P));
case Nkind (P) is
-- Case of right operand of AND THEN or OR ELSE. Put the actions
-- in the Actions field of the right operand. They will be moved
-- out further when the AND THEN or OR ELSE operator is expanded.
-- Nothing special needs to be done for the left operand since
-- in that case the actions are executed unconditionally.
when N_And_Then | N_Or_Else =>
if N = Right_Opnd (P) then
if Present (Actions (P)) then
Insert_List_After_And_Analyze
(Last (Actions (P)), Ins_Actions);
else
Set_Actions (P, Ins_Actions);
Analyze_List (Actions (P));
end if;
return;
end if;
-- Then or Else operand of conditional expression. Add actions to
-- Then_Actions or Else_Actions field as appropriate. The actions
-- will be moved further out when the conditional is expanded.
when N_Conditional_Expression =>
declare
ThenX : constant Node_Id := Next (First (Expressions (P)));
ElseX : constant Node_Id := Next (ThenX);
begin
-- Actions belong to the then expression, temporarily
-- place them as Then_Actions of the conditional expr.
-- They will be moved to the proper place later when
-- the conditional expression is expanded.
if N = ThenX then
if Present (Then_Actions (P)) then
Insert_List_After_And_Analyze
(Last (Then_Actions (P)), Ins_Actions);
else
Set_Then_Actions (P, Ins_Actions);
Analyze_List (Then_Actions (P));
end if;
return;
-- Actions belong to the else expression, temporarily
-- place them as Else_Actions of the conditional expr.
-- They will be moved to the proper place later when
-- the conditional expression is expanded.
elsif N = ElseX then
if Present (Else_Actions (P)) then
Insert_List_After_And_Analyze
(Last (Else_Actions (P)), Ins_Actions);
else
Set_Else_Actions (P, Ins_Actions);
Analyze_List (Else_Actions (P));
end if;
return;
-- Actions belong to the condition. In this case they are
-- unconditionally executed, and so we can continue the
-- search for the proper insert point.
else
null;
end if;
end;
-- Case of appearing in the condition of a while expression or
-- elsif. We insert the actions into the Condition_Actions field.
-- They will be moved further out when the while loop or elsif
-- is analyzed.
when N_Iteration_Scheme |
N_Elsif_Part
=>
if N = Condition (P) then
if Present (Condition_Actions (P)) then
Insert_List_After_And_Analyze
(Last (Condition_Actions (P)), Ins_Actions);
else
Set_Condition_Actions (P, Ins_Actions);
-- Set the parent of the insert actions explicitly.
-- This is not a syntactic field, but we need the
-- parent field set, in particular so that freeze
-- can understand that it is dealing with condition
-- actions, and properly insert the freezing actions.
Set_Parent (Ins_Actions, P);
Analyze_List (Condition_Actions (P));
end if;
return;
end if;
-- Statements, declarations, pragmas, representation clauses.
when
-- Statements
N_Procedure_Call_Statement |
N_Statement_Other_Than_Procedure_Call |
-- Pragmas
N_Pragma |
-- Representation_Clause
N_At_Clause |
N_Attribute_Definition_Clause |
N_Enumeration_Representation_Clause |
N_Record_Representation_Clause |
-- Declarations
N_Abstract_Subprogram_Declaration |
N_Entry_Body |
N_Exception_Declaration |
N_Exception_Renaming_Declaration |
N_Formal_Object_Declaration |
N_Formal_Subprogram_Declaration |
N_Formal_Type_Declaration |
N_Full_Type_Declaration |
N_Function_Instantiation |
N_Generic_Function_Renaming_Declaration |
N_Generic_Package_Declaration |
N_Generic_Package_Renaming_Declaration |
N_Generic_Procedure_Renaming_Declaration |
N_Generic_Subprogram_Declaration |
N_Implicit_Label_Declaration |
N_Incomplete_Type_Declaration |
N_Number_Declaration |
N_Object_Declaration |
N_Object_Renaming_Declaration |
N_Package_Body |
N_Package_Body_Stub |
N_Package_Declaration |
N_Package_Instantiation |
N_Package_Renaming_Declaration |
N_Private_Extension_Declaration |
N_Private_Type_Declaration |
N_Procedure_Instantiation |
N_Protected_Body_Stub |
N_Protected_Type_Declaration |
N_Single_Task_Declaration |
N_Subprogram_Body |
N_Subprogram_Body_Stub |
N_Subprogram_Declaration |
N_Subprogram_Renaming_Declaration |
N_Subtype_Declaration |
N_Task_Body |
N_Task_Body_Stub |
N_Task_Type_Declaration |
-- Freeze entity behaves like a declaration or statement
N_Freeze_Entity
=>
-- Do not insert here if the item is not a list member (this
-- happens for example with a triggering statement, and the
-- proper approach is to insert before the entire select).
if not Is_List_Member (P) then
null;
-- Do not insert if parent of P is an N_Component_Association
-- node (i.e. we are in the context of an N_Aggregate node.
-- In this case we want to insert before the entire aggregate.
elsif Nkind (Parent (P)) = N_Component_Association then
null;
-- Do not insert if the parent of P is either an N_Variant
-- node or an N_Record_Definition node, meaning in either
-- case that P is a member of a component list, and that
-- therefore the actions should be inserted outside the
-- complete record declaration.
elsif Nkind (Parent (P)) = N_Variant
or else Nkind (Parent (P)) = N_Record_Definition
then
null;
-- Do not insert freeze nodes within the loop generated for
-- an aggregate, because they may be elaborated too late for
-- subsequent use in the back end: within a package spec the
-- loop is part of the elaboration procedure and is only
-- elaborated during the second pass.
-- If the loop comes from source, or the entity is local to
-- the loop itself it must remain within.
elsif Nkind (Parent (P)) = N_Loop_Statement
and then not Comes_From_Source (Parent (P))
and then Nkind (First (Ins_Actions)) = N_Freeze_Entity
and then
Scope (Entity (First (Ins_Actions))) /= Current_Scope
then
null;
-- Otherwise we can go ahead and do the insertion
elsif P = Wrapped_Node then
Store_Before_Actions_In_Scope (Ins_Actions);
return;
else
Insert_List_Before_And_Analyze (P, Ins_Actions);
return;
end if;
-- A special case, N_Raise_xxx_Error can act either as a
-- statement or a subexpression. We tell the difference
-- by looking at the Etype. It is set to Standard_Void_Type
-- in the statement case.
when
N_Raise_xxx_Error =>
if Etype (P) = Standard_Void_Type then
if P = Wrapped_Node then
Store_Before_Actions_In_Scope (Ins_Actions);
else
Insert_List_Before_And_Analyze (P, Ins_Actions);
end if;
return;
-- In the subexpression case, keep climbing
else
null;
end if;
-- If a component association appears within a loop created for
-- an array aggregate, attach the actions to the association so
-- they can be subsequently inserted within the loop. For other
-- component associations insert outside of the aggregate.
-- The list of loop_actions can in turn generate additional ones,
-- that are inserted before the associated node. If the associated
-- node is outside the aggregate, the new actions are collected
-- at the end of the loop actions, to respect the order in which
-- they are to be elaborated.
when
N_Component_Association =>
if Nkind (Parent (P)) = N_Aggregate
and then Present (Aggregate_Bounds (Parent (P)))
and then Nkind (First (Choices (P))) = N_Others_Choice
and then Nkind (First (Ins_Actions)) /= N_Freeze_Entity
then
if No (Loop_Actions (P)) then
Set_Loop_Actions (P, Ins_Actions);
Analyze_List (Ins_Actions);
else
declare
Decl : Node_Id := Assoc_Node;
begin
-- Check whether these actions were generated
-- by a declaration that is part of the loop_
-- actions for the component_association.
while Present (Decl) loop
exit when Parent (Decl) = P
and then Is_List_Member (Decl)
and then
List_Containing (Decl) = Loop_Actions (P);
Decl := Parent (Decl);
end loop;
if Present (Decl) then
Insert_List_Before_And_Analyze
(Decl, Ins_Actions);
else
Insert_List_After_And_Analyze
(Last (Loop_Actions (P)), Ins_Actions);
end if;
end;
end if;
return;
else
null;
end if;
-- Another special case, an attribute denoting a procedure call
when
N_Attribute_Reference =>
if Is_Procedure_Attribute_Name (Attribute_Name (P)) then
if P = Wrapped_Node then
Store_Before_Actions_In_Scope (Ins_Actions);
else
Insert_List_Before_And_Analyze (P, Ins_Actions);
end if;
return;
-- In the subexpression case, keep climbing
else
null;
end if;
-- For all other node types, keep climbing tree
when
N_Abortable_Part |
N_Accept_Alternative |
N_Access_Definition |
N_Access_Function_Definition |
N_Access_Procedure_Definition |
N_Access_To_Object_Definition |
N_Aggregate |
N_Allocator |
N_Case_Statement_Alternative |
N_Character_Literal |
N_Compilation_Unit |
N_Compilation_Unit_Aux |
N_Component_Clause |
N_Component_Declaration |
N_Component_List |
N_Constrained_Array_Definition |
N_Decimal_Fixed_Point_Definition |
N_Defining_Character_Literal |
N_Defining_Identifier |
N_Defining_Operator_Symbol |
N_Defining_Program_Unit_Name |
N_Delay_Alternative |
N_Delta_Constraint |
N_Derived_Type_Definition |
N_Designator |
N_Digits_Constraint |
N_Discriminant_Association |
N_Discriminant_Specification |
N_Empty |
N_Entry_Body_Formal_Part |
N_Entry_Call_Alternative |
N_Entry_Declaration |
N_Entry_Index_Specification |
N_Enumeration_Type_Definition |
N_Error |
N_Exception_Handler |
N_Expanded_Name |
N_Explicit_Dereference |
N_Extension_Aggregate |
N_Floating_Point_Definition |
N_Formal_Decimal_Fixed_Point_Definition |
N_Formal_Derived_Type_Definition |
N_Formal_Discrete_Type_Definition |
N_Formal_Floating_Point_Definition |
N_Formal_Modular_Type_Definition |
N_Formal_Ordinary_Fixed_Point_Definition |
N_Formal_Package_Declaration |
N_Formal_Private_Type_Definition |
N_Formal_Signed_Integer_Type_Definition |
N_Function_Call |
N_Function_Specification |
N_Generic_Association |
N_Handled_Sequence_Of_Statements |
N_Identifier |
N_In |
N_Index_Or_Discriminant_Constraint |
N_Indexed_Component |
N_Integer_Literal |
N_Itype_Reference |
N_Label |
N_Loop_Parameter_Specification |
N_Mod_Clause |
N_Modular_Type_Definition |
N_Not_In |
N_Null |
N_Op_Abs |
N_Op_Add |
N_Op_And |
N_Op_Concat |
N_Op_Divide |
N_Op_Eq |
N_Op_Expon |
N_Op_Ge |
N_Op_Gt |
N_Op_Le |
N_Op_Lt |
N_Op_Minus |
N_Op_Mod |
N_Op_Multiply |
N_Op_Ne |
N_Op_Not |
N_Op_Or |
N_Op_Plus |
N_Op_Rem |
N_Op_Rotate_Left |
N_Op_Rotate_Right |
N_Op_Shift_Left |
N_Op_Shift_Right |
N_Op_Shift_Right_Arithmetic |
N_Op_Subtract |
N_Op_Xor |
N_Operator_Symbol |
N_Ordinary_Fixed_Point_Definition |
N_Others_Choice |
N_Package_Specification |
N_Parameter_Association |
N_Parameter_Specification |
N_Pragma_Argument_Association |
N_Procedure_Specification |
N_Protected_Body |
N_Protected_Definition |
N_Qualified_Expression |
N_Range |
N_Range_Constraint |
N_Real_Literal |
N_Real_Range_Specification |
N_Record_Definition |
N_Reference |
N_Selected_Component |
N_Signed_Integer_Type_Definition |
N_Single_Protected_Declaration |
N_Slice |
N_String_Literal |
N_Subprogram_Info |
N_Subtype_Indication |
N_Subunit |
N_Task_Definition |
N_Terminate_Alternative |
N_Triggering_Alternative |
N_Type_Conversion |
N_Unchecked_Expression |
N_Unchecked_Type_Conversion |
N_Unconstrained_Array_Definition |
N_Unused_At_End |
N_Unused_At_Start |
N_Use_Package_Clause |
N_Use_Type_Clause |
N_Variant |
N_Variant_Part |
N_Validate_Unchecked_Conversion |
N_With_Clause |
N_With_Type_Clause
=>
null;
end case;
-- Make sure that inserted actions stay in the transient scope
if P = Wrapped_Node then
Store_Before_Actions_In_Scope (Ins_Actions);
return;
end if;
-- If we fall through above tests, keep climbing tree
N := P;
if Nkind (Parent (N)) = N_Subunit then
-- This is the proper body corresponding to a stub. Insertion
-- must be done at the point of the stub, which is in the decla-
-- tive part of the parent unit.
P := Corresponding_Stub (Parent (N));
else
P := Parent (N);
end if;
end loop;
end Insert_Actions;
-- Version with check(s) suppressed
procedure Insert_Actions
(Assoc_Node : Node_Id; Ins_Actions : List_Id; Suppress : Check_Id)
is
begin
if Suppress = All_Checks then
declare
Svg : constant Suppress_Record := Scope_Suppress;
begin
Scope_Suppress := (others => True);
Insert_Actions (Assoc_Node, Ins_Actions);
Scope_Suppress := Svg;
end;
else
declare
Svg : constant Boolean := Get_Scope_Suppress (Suppress);
begin
Set_Scope_Suppress (Suppress, True);
Insert_Actions (Assoc_Node, Ins_Actions);
Set_Scope_Suppress (Suppress, Svg);
end;
end if;
end Insert_Actions;
--------------------------
-- Insert_Actions_After --
--------------------------
procedure Insert_Actions_After
(Assoc_Node : Node_Id;
Ins_Actions : List_Id)
is
begin
if Scope_Is_Transient
and then Assoc_Node = Node_To_Be_Wrapped
then
Store_After_Actions_In_Scope (Ins_Actions);
else
Insert_List_After_And_Analyze (Assoc_Node, Ins_Actions);
end if;
end Insert_Actions_After;
---------------------------------
-- Insert_Library_Level_Action --
---------------------------------
procedure Insert_Library_Level_Action (N : Node_Id) is
Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
begin
New_Scope (Cunit_Entity (Main_Unit));
if No (Actions (Aux)) then
Set_Actions (Aux, New_List (N));
else
Append (N, Actions (Aux));
end if;
Analyze (N);
Pop_Scope;
end Insert_Library_Level_Action;
----------------------------------
-- Insert_Library_Level_Actions --
----------------------------------
procedure Insert_Library_Level_Actions (L : List_Id) is
Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
begin
if Is_Non_Empty_List (L) then
New_Scope (Cunit_Entity (Main_Unit));
if No (Actions (Aux)) then
Set_Actions (Aux, L);
Analyze_List (L);
else
Insert_List_After_And_Analyze (Last (Actions (Aux)), L);
end if;
Pop_Scope;
end if;
end Insert_Library_Level_Actions;
----------------------
-- Inside_Init_Proc --
----------------------
function Inside_Init_Proc return Boolean is
S : Entity_Id;
begin
S := Current_Scope;
while S /= Standard_Standard loop
if Chars (S) = Name_uInit_Proc then
return True;
else
S := Scope (S);
end if;
end loop;
return False;
end Inside_Init_Proc;
--------------------------------
-- Is_Ref_To_Bit_Packed_Array --
--------------------------------
function Is_Ref_To_Bit_Packed_Array (P : Node_Id) return Boolean is
Result : Boolean;
Expr : Node_Id;
begin
if Nkind (P) = N_Indexed_Component
or else
Nkind (P) = N_Selected_Component
then
if Is_Bit_Packed_Array (Etype (Prefix (P))) then
Result := True;
else
Result := Is_Ref_To_Bit_Packed_Array (Prefix (P));
end if;
if Result and then Nkind (P) = N_Indexed_Component then
Expr := First (Expressions (P));
while Present (Expr) loop
Force_Evaluation (Expr);
Next (Expr);
end loop;
end if;
return Result;
else
return False;
end if;
end Is_Ref_To_Bit_Packed_Array;
--------------------------------
-- Is_Ref_To_Bit_Packed_Slce --
--------------------------------
function Is_Ref_To_Bit_Packed_Slice (P : Node_Id) return Boolean is
begin
if Nkind (P) = N_Slice
and then Is_Bit_Packed_Array (Etype (Prefix (P)))
then
return True;
elsif Nkind (P) = N_Indexed_Component
or else
Nkind (P) = N_Selected_Component
then
return Is_Ref_To_Bit_Packed_Slice (Prefix (P));
else
return False;
end if;
end Is_Ref_To_Bit_Packed_Slice;
-----------------------
-- Is_Renamed_Object --
-----------------------
function Is_Renamed_Object (N : Node_Id) return Boolean is
Pnod : constant Node_Id := Parent (N);
Kind : constant Node_Kind := Nkind (Pnod);
begin
if Kind = N_Object_Renaming_Declaration then
return True;
elsif Kind = N_Indexed_Component
or else Kind = N_Selected_Component
then
return Is_Renamed_Object (Pnod);
else
return False;
end if;
end Is_Renamed_Object;
----------------------------
-- Is_Untagged_Derivation --
----------------------------
function Is_Untagged_Derivation (T : Entity_Id) return Boolean is
begin
return (not Is_Tagged_Type (T) and then Is_Derived_Type (T))
or else
(Is_Private_Type (T) and then Present (Full_View (T))
and then not Is_Tagged_Type (Full_View (T))
and then Is_Derived_Type (Full_View (T))
and then Etype (Full_View (T)) /= T);
end Is_Untagged_Derivation;
--------------------
-- Kill_Dead_Code --
--------------------
procedure Kill_Dead_Code (N : Node_Id) is
begin
if Present (N) then
Remove_Handler_Entries (N);
Remove_Warning_Messages (N);
-- Recurse into block statements to process declarations/statements
if Nkind (N) = N_Block_Statement then
Kill_Dead_Code (Declarations (N));
Kill_Dead_Code (Statements (Handled_Statement_Sequence (N)));
-- Recurse into composite statement to kill individual statements,
-- in particular instantiations.
elsif Nkind (N) = N_If_Statement then
Kill_Dead_Code (Then_Statements (N));
Kill_Dead_Code (Elsif_Parts (N));
Kill_Dead_Code (Else_Statements (N));
elsif Nkind (N) = N_Loop_Statement then
Kill_Dead_Code (Statements (N));
elsif Nkind (N) = N_Case_Statement then
declare
Alt : Node_Id := First (Alternatives (N));
begin
while Present (Alt) loop
Kill_Dead_Code (Statements (Alt));
Next (Alt);
end loop;
end;
-- Deal with dead instances caused by deleting instantiations
elsif Nkind (N) in N_Generic_Instantiation then
Remove_Dead_Instance (N);
end if;
Delete_Tree (N);
end if;
end Kill_Dead_Code;
-- Case where argument is a list of nodes to be killed
procedure Kill_Dead_Code (L : List_Id) is
N : Node_Id;
begin
if Is_Non_Empty_List (L) then
loop
N := Remove_Head (L);
exit when No (N);
Kill_Dead_Code (N);
end loop;
end if;
end Kill_Dead_Code;
------------------------
-- Known_Non_Negative --
------------------------
function Known_Non_Negative (Opnd : Node_Id) return Boolean is
begin
if Is_OK_Static_Expression (Opnd)
and then Expr_Value (Opnd) >= 0
then
return True;
else
declare
Lo : constant Node_Id := Type_Low_Bound (Etype (Opnd));
begin
return
Is_OK_Static_Expression (Lo) and then Expr_Value (Lo) >= 0;
end;
end if;
end Known_Non_Negative;
-----------------------------
-- Make_CW_Equivalent_Type --
-----------------------------
-- Create a record type used as an equivalent of any member
-- of the class which takes its size from exp.
-- Generate the following code:
-- type Equiv_T is record
-- _parent : T (List of discriminant constaints taken from Exp);
-- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'size) / Storage_Unit);
-- end Equiv_T;
function Make_CW_Equivalent_Type
(T : Entity_Id;
E : Node_Id)
return Entity_Id
is
Loc : constant Source_Ptr := Sloc (E);
Root_Typ : constant Entity_Id := Root_Type (T);
Equiv_Type : Entity_Id;
Range_Type : Entity_Id;
Str_Type : Entity_Id;
List_Def : List_Id := Empty_List;
Constr_Root : Entity_Id;
Sizexpr : Node_Id;
begin
if not Has_Discriminants (Root_Typ) then
Constr_Root := Root_Typ;
else
Constr_Root :=
Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
-- subtype cstr__n is T (List of discr constraints taken from Exp)
Append_To (List_Def,
Make_Subtype_Declaration (Loc,
Defining_Identifier => Constr_Root,
Subtype_Indication =>
Make_Subtype_From_Expr (E, Root_Typ)));
end if;
-- subtype rg__xx is Storage_Offset range
-- (Expr'size - typ'size) / Storage_Unit
Range_Type := Make_Defining_Identifier (Loc, New_Internal_Name ('G'));
Sizexpr :=
Make_Op_Subtract (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => OK_Convert_To (T, Duplicate_Subexpr (E)),
Attribute_Name => Name_Size),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Constr_Root, Loc),
Attribute_Name => Name_Size));
Set_Paren_Count (Sizexpr, 1);
Append_To (List_Def,
Make_Subtype_Declaration (Loc,
Defining_Identifier => Range_Type,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Reference_To (RTE (RE_Storage_Offset), Loc),
Constraint => Make_Range_Constraint (Loc,
Range_Expression =>
Make_Range (Loc,
Low_Bound => Make_Integer_Literal (Loc, 1),
High_Bound =>
Make_Op_Divide (Loc,
Left_Opnd => Sizexpr,
Right_Opnd => Make_Integer_Literal (Loc,
Intval => System_Storage_Unit)))))));
-- subtype str__nn is Storage_Array (rg__x);
Str_Type := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
Append_To (List_Def,
Make_Subtype_Declaration (Loc,
Defining_Identifier => Str_Type,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Reference_To (RTE (RE_Storage_Array), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints =>
New_List (New_Reference_To (Range_Type, Loc))))));
-- type Equiv_T is record
-- _parent : Tnn;
-- E : Str_Type;
-- end Equiv_T;
Equiv_Type := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
-- Avoid the generation of an init procedure
Set_Is_Frozen (Equiv_Type);
Set_Ekind (Equiv_Type, E_Record_Type);
Set_Parent_Subtype (Equiv_Type, Constr_Root);
Append_To (List_Def,
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Equiv_Type,
Type_Definition =>
Make_Record_Definition (Loc,
Component_List => Make_Component_List (Loc,
Component_Items => New_List (
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uParent),
Subtype_Indication => New_Reference_To (Constr_Root, Loc)),
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('C')),
Subtype_Indication => New_Reference_To (Str_Type, Loc))),
Variant_Part => Empty))));
Insert_Actions (E, List_Def);
return Equiv_Type;
end Make_CW_Equivalent_Type;
------------------------
-- Make_Literal_Range --
------------------------
function Make_Literal_Range
(Loc : Source_Ptr;
Literal_Typ : Entity_Id)
return Node_Id
is
Lo : Node_Id :=
New_Copy_Tree (String_Literal_Low_Bound (Literal_Typ));
begin
Set_Analyzed (Lo, False);
return
Make_Range (Loc,
Low_Bound => Lo,
High_Bound =>
Make_Op_Subtract (Loc,
Left_Opnd =>
Make_Op_Add (Loc,
Left_Opnd => New_Copy_Tree (Lo),
Right_Opnd =>
Make_Integer_Literal (Loc,
String_Literal_Length (Literal_Typ))),
Right_Opnd => Make_Integer_Literal (Loc, 1)));
end Make_Literal_Range;
----------------------------
-- Make_Subtype_From_Expr --
----------------------------
-- 1. If Expr is an uncontrained array expression, creates
-- Unc_Type(Expr'first(1)..Expr'Last(1),..., Expr'first(n)..Expr'last(n))
-- 2. If Expr is a unconstrained discriminated type expression, creates
-- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
-- 3. If Expr is class-wide, creates an implicit class wide subtype
function Make_Subtype_From_Expr
(E : Node_Id;
Unc_Typ : Entity_Id)
return Node_Id
is
Loc : constant Source_Ptr := Sloc (E);
List_Constr : List_Id := New_List;
D : Entity_Id;
Full_Subtyp : Entity_Id;
Priv_Subtyp : Entity_Id;
Utyp : Entity_Id;
Full_Exp : Node_Id;
begin
if Is_Private_Type (Unc_Typ)
and then Has_Unknown_Discriminants (Unc_Typ)
then
-- Prepare the subtype completion
Utyp := Underlying_Type (Unc_Typ);
Full_Subtyp := Make_Defining_Identifier (Loc,
New_Internal_Name ('C'));
Full_Exp := Unchecked_Convert_To (Utyp, Duplicate_Subexpr (E));
Set_Parent (Full_Exp, Parent (E));
Priv_Subtyp :=
Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
Insert_Action (E,
Make_Subtype_Declaration (Loc,
Defining_Identifier => Full_Subtyp,
Subtype_Indication => Make_Subtype_From_Expr (Full_Exp, Utyp)));
-- Define the dummy private subtype
Set_Ekind (Priv_Subtyp, Subtype_Kind (Ekind (Unc_Typ)));
Set_Etype (Priv_Subtyp, Unc_Typ);
Set_Scope (Priv_Subtyp, Full_Subtyp);
Set_Is_Constrained (Priv_Subtyp);
Set_Is_Tagged_Type (Priv_Subtyp, Is_Tagged_Type (Unc_Typ));
Set_Is_Itype (Priv_Subtyp);
Set_Associated_Node_For_Itype (Priv_Subtyp, E);
if Is_Tagged_Type (Priv_Subtyp) then
Set_Class_Wide_Type
(Base_Type (Priv_Subtyp), Class_Wide_Type (Unc_Typ));
Set_Primitive_Operations (Priv_Subtyp,
Primitive_Operations (Unc_Typ));
end if;
Set_Full_View (Priv_Subtyp, Full_Subtyp);
return New_Reference_To (Priv_Subtyp, Loc);
elsif Is_Array_Type (Unc_Typ) then
for J in 1 .. Number_Dimensions (Unc_Typ) loop
Append_To (List_Constr,
Make_Range (Loc,
Low_Bound =>
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (E),
Attribute_Name => Name_First,
Expressions => New_List (
Make_Integer_Literal (Loc, J))),
High_Bound =>
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (E),
Attribute_Name => Name_Last,
Expressions => New_List (
Make_Integer_Literal (Loc, J)))));
end loop;
elsif Is_Class_Wide_Type (Unc_Typ) then
declare
CW_Subtype : Entity_Id;
EQ_Typ : Entity_Id := Empty;
begin
-- A class-wide equivalent type is not needed when Java_VM
-- because the JVM back end handles the class-wide object
-- initialization itself (and doesn't need or want the
-- additional intermediate type to handle the assignment).
if Expander_Active and then not Java_VM then
EQ_Typ := Make_CW_Equivalent_Type (Unc_Typ, E);
end if;
CW_Subtype := New_Class_Wide_Subtype (Unc_Typ, E);
Set_Equivalent_Type (CW_Subtype, EQ_Typ);
Set_Cloned_Subtype (CW_Subtype, Base_Type (Unc_Typ));
return New_Occurrence_Of (CW_Subtype, Loc);
end;
else
D := First_Discriminant (Unc_Typ);
while (Present (D)) loop
Append_To (List_Constr,
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (E),
Selector_Name => New_Reference_To (D, Loc)));
Next_Discriminant (D);
end loop;
end if;
return
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Reference_To (Unc_Typ, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => List_Constr));
end Make_Subtype_From_Expr;
-----------------------------
-- May_Generate_Large_Temp --
-----------------------------
-- At the current time, the only types that we return False for (i.e.
-- where we decide we know they cannot generate large temps) are ones
-- where we know the size is 128 bits or less at compile time, and we
-- are still not doing a thorough job on arrays and records ???
function May_Generate_Large_Temp (Typ : Entity_Id) return Boolean is
begin
if not Stack_Checking_Enabled then
return False;
elsif not Size_Known_At_Compile_Time (Typ) then
return False;
elsif Esize (Typ) /= 0 and then Esize (Typ) <= 256 then
return False;
elsif Is_Array_Type (Typ)
and then Present (Packed_Array_Type (Typ))
then
return May_Generate_Large_Temp (Packed_Array_Type (Typ));
-- We could do more here to find other small types ???
else
return True;
end if;
end May_Generate_Large_Temp;
----------------------------
-- New_Class_Wide_Subtype --
----------------------------
function New_Class_Wide_Subtype
(CW_Typ : Entity_Id;
N : Node_Id)
return Entity_Id
is
Res : Entity_Id := Create_Itype (E_Void, N);
Res_Name : constant Name_Id := Chars (Res);
Res_Scope : Entity_Id := Scope (Res);
begin
Copy_Node (CW_Typ, Res);
Set_Sloc (Res, Sloc (N));
Set_Is_Itype (Res);
Set_Associated_Node_For_Itype (Res, N);
Set_Is_Public (Res, False); -- By default, may be changed below.
Set_Public_Status (Res);
Set_Chars (Res, Res_Name);
Set_Scope (Res, Res_Scope);
Set_Ekind (Res, E_Class_Wide_Subtype);
Set_Next_Entity (Res, Empty);
Set_Etype (Res, Base_Type (CW_Typ));
Set_Freeze_Node (Res, Empty);
return (Res);
end New_Class_Wide_Subtype;
-------------------------
-- Remove_Side_Effects --
-------------------------
procedure Remove_Side_Effects
(Exp : Node_Id;
Name_Req : Boolean := False;
Variable_Ref : Boolean := False)
is
Loc : constant Source_Ptr := Sloc (Exp);
Exp_Type : constant Entity_Id := Etype (Exp);
Svg_Suppress : constant Suppress_Record := Scope_Suppress;
Def_Id : Entity_Id;
Ref_Type : Entity_Id;
Res : Node_Id;
Ptr_Typ_Decl : Node_Id;
New_Exp : Node_Id;
E : Node_Id;
function Side_Effect_Free (N : Node_Id) return Boolean;
-- Determines if the tree N represents an expession that is known
-- not to have side effects, and for which no processing is required.
function Side_Effect_Free (L : List_Id) return Boolean;
-- Determines if all elements of the list L are side effect free
function Mutable_Dereference (N : Node_Id) return Boolean;
-- If a selected component involves an implicit dereference and
-- the type of the prefix is not an_access_to_constant, the node
-- must be evaluated because it may be affected by a subsequent
-- assignment.
-------------------------
-- Mutable_Dereference --
-------------------------
function Mutable_Dereference (N : Node_Id) return Boolean is
begin
return Nkind (N) = N_Selected_Component
and then Is_Access_Type (Etype (Prefix (N)))
and then not Is_Access_Constant (Etype (Prefix (N)))
and then Variable_Ref;
end Mutable_Dereference;
----------------------
-- Side_Effect_Free --
----------------------
function Side_Effect_Free (N : Node_Id) return Boolean is
K : constant Node_Kind := Nkind (N);
begin
-- Note on checks that could raise Constraint_Error. Strictly, if
-- we take advantage of 11.6, these checks do not count as side
-- effects. However, we would just as soon consider that they are
-- side effects, since the backend CSE does not work very well on
-- expressions which can raise Constraint_Error. On the other
-- hand, if we do not consider them to be side effect free, then
-- we get some awkward expansions in -gnato mode, resulting in
-- code insertions at a point where we do not have a clear model
-- for performing the insertions. See 4908-002/comment for details.
-- An attribute reference is side effect free if its expressions
-- are side effect free and its prefix is (could be a dereference
-- or an indexed retrieval for example).
if K = N_Attribute_Reference then
return Side_Effect_Free (Expressions (N))
and then (Is_Entity_Name (Prefix (N))
or else Side_Effect_Free (Prefix (N)));
-- An entity is side effect free unless it is a function call, or
-- a reference to a volatile variable and Name_Req is False. If
-- Name_Req is True then we can't help returning a name which
-- effectively allows multiple references in any case.
elsif Is_Entity_Name (N)
and then Ekind (Entity (N)) /= E_Function
and then (not Is_Volatile (Entity (N)) or else Name_Req)
then
-- If the entity is a constant, it is definitely side effect
-- free. Note that the test of Is_Variable (N) below might
-- be expected to catch this case, but it does not, because
-- this test goes to the original tree, and we may have
-- already rewritten a variable node with a constant as
-- a result of an earlier Force_Evaluation call.
if Ekind (Entity (N)) = E_Constant then
return True;
-- If the Variable_Ref flag is set, any variable reference is
-- is considered a side-effect
elsif Variable_Ref then
return not Is_Variable (N);
else
return True;
end if;
-- A value known at compile time is always side effect free
elsif Compile_Time_Known_Value (N) then
return True;
-- Literals are always side-effect free
elsif (K = N_Integer_Literal
or else K = N_Real_Literal
or else K = N_Character_Literal
or else K = N_String_Literal
or else K = N_Null)
and then not Raises_Constraint_Error (N)
then
return True;
-- A type conversion or qualification is side effect free if the
-- expression to be converted is side effect free.
elsif K = N_Type_Conversion or else K = N_Qualified_Expression then
return Side_Effect_Free (Expression (N));
-- An unchecked type conversion is never side effect free since we
-- need to check whether it is safe.
-- effect free if its argument is side effect free.
elsif K = N_Unchecked_Type_Conversion then
if Safe_Unchecked_Type_Conversion (N) then
return Side_Effect_Free (Expression (N));
else
return False;
end if;
-- A unary operator is side effect free if the operand
-- is side effect free.
elsif K in N_Unary_Op then
return Side_Effect_Free (Right_Opnd (N));
-- A binary operator is side effect free if and both operands
-- are side effect free.
elsif K in N_Binary_Op then
return Side_Effect_Free (Left_Opnd (N))
and then Side_Effect_Free (Right_Opnd (N));
-- An explicit dereference or selected component is side effect
-- free if its prefix is side effect free.
elsif K = N_Explicit_Dereference
or else K = N_Selected_Component
then
return Side_Effect_Free (Prefix (N))
and then not Mutable_Dereference (Prefix (N));
-- An indexed component can be copied if the prefix is copyable
-- and all the indexing expressions are copyable and there is
-- no access check and no range checks.
elsif K = N_Indexed_Component then
return Side_Effect_Free (Prefix (N))
and then Side_Effect_Free (Expressions (N));
elsif K = N_Unchecked_Expression then
return Side_Effect_Free (Expression (N));
-- A call to _rep_to_pos is side effect free, since we generate
-- this pure function call ourselves. Moreover it is critically
-- important to make this exception, since otherwise we can
-- have discriminants in array components which don't look
-- side effect free in the case of an array whose index type
-- is an enumeration type with an enumeration rep clause.
elsif K = N_Function_Call
and then Nkind (Name (N)) = N_Identifier
and then Chars (Name (N)) = Name_uRep_To_Pos
then
return True;
-- We consider that anything else has side effects. This is a bit
-- crude, but we are pretty close for most common cases, and we
-- are certainly correct (i.e. we never return True when the
-- answer should be False).
else
return False;
end if;
end Side_Effect_Free;
function Side_Effect_Free (L : List_Id) return Boolean is
N : Node_Id;
begin
if L = No_List or else L = Error_List then
return True;
else
N := First (L);
while Present (N) loop
if not Side_Effect_Free (N) then
return False;
else
Next (N);
end if;
end loop;
return True;
end if;
end Side_Effect_Free;
-- Start of processing for Remove_Side_Effects
begin
-- If we are side effect free already or expansion is disabled,
-- there is nothing to do.
if Side_Effect_Free (Exp) or else not Expander_Active then
return;
end if;
-- All the must not have any checks
Scope_Suppress := (others => True);
-- If the expression has the form v.all then we can just capture
-- the pointer, and then do an explicit dereference on the result.
if Nkind (Exp) = N_Explicit_Dereference then
Def_Id :=
Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
Res :=
Make_Explicit_Dereference (Loc, New_Reference_To (Def_Id, Loc));
Insert_Action (Exp,
Make_Object_Declaration (Loc,
Defining_Identifier => Def_Id,
Object_Definition =>
New_Reference_To (Etype (Prefix (Exp)), Loc),
Constant_Present => True,
Expression => Relocate_Node (Prefix (Exp))));
-- If this is a type conversion, leave the type conversion and remove
-- the side effects in the expression. This is important in several
-- circumstances: for change of representations, and also when this
-- is a view conversion to a smaller object, where gigi can end up
-- its own temporary of the wrong size.
-- ??? this transformation is inhibited for elementary types that are
-- not involved in a change of representation because it causes
-- regressions that are not fully understood yet.
elsif Nkind (Exp) = N_Type_Conversion
and then (not Is_Elementary_Type (Underlying_Type (Exp_Type))
or else Nkind (Parent (Exp)) = N_Assignment_Statement)
then
Remove_Side_Effects (Expression (Exp), Variable_Ref);
Scope_Suppress := Svg_Suppress;
return;
-- For expressions that denote objects, we can use a renaming scheme.
-- We skip using this if we have a volatile variable and we do not
-- have Nam_Req set true (see comments above for Side_Effect_Free).
-- We also skip this scheme for class-wide expressions in order to
-- avoid recursive expension (see Expand_N_Object_Renaming_Declaration)
-- If the object is a function call, we need to create a temporary and
-- not a renaming.
elsif Is_Object_Reference (Exp)
and then Nkind (Exp) /= N_Function_Call
and then not Variable_Ref
and then (Name_Req
or else not Is_Entity_Name (Exp)
or else not Is_Volatile (Entity (Exp)))
and then not Is_Class_Wide_Type (Exp_Type)
then
Def_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
if Nkind (Exp) = N_Selected_Component
and then Nkind (Prefix (Exp)) = N_Function_Call
and then Is_Array_Type (Etype (Exp))
then
-- Avoid generating a variable-sized temporary, by generating
-- the renaming declaration just for the function call. The
-- transformation could be refined to apply only when the array
-- component is constrained by a discriminant???
Res :=
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Def_Id, Loc),
Selector_Name => Selector_Name (Exp));
Insert_Action (Exp,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Def_Id,
Subtype_Mark =>
New_Reference_To (Base_Type (Etype (Prefix (Exp))), Loc),
Name => Relocate_Node (Prefix (Exp))));
else
Res := New_Reference_To (Def_Id, Loc);
Insert_Action (Exp,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Def_Id,
Subtype_Mark => New_Reference_To (Exp_Type, Loc),
Name => Relocate_Node (Exp)));
end if;
-- If it is a scalar type, just make a copy.
elsif Is_Elementary_Type (Exp_Type) then
Def_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
Set_Etype (Def_Id, Exp_Type);
Res := New_Reference_To (Def_Id, Loc);
E :=
Make_Object_Declaration (Loc,
Defining_Identifier => Def_Id,
Object_Definition => New_Reference_To (Exp_Type, Loc),
Constant_Present => True,
Expression => Relocate_Node (Exp));
Set_Assignment_OK (E);
Insert_Action (Exp, E);
-- If this is an unchecked conversion that Gigi can't handle, make
-- a copy or a use a renaming to capture the value.
elsif (Nkind (Exp) = N_Unchecked_Type_Conversion
and then not Safe_Unchecked_Type_Conversion (Exp))
then
if Controlled_Type (Etype (Exp)) then
-- Use a renaming to capture the expression, rather than create
-- a controlled temporary.
Def_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
Res := New_Reference_To (Def_Id, Loc);
Insert_Action (Exp,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Def_Id,
Subtype_Mark => New_Reference_To (Exp_Type, Loc),
Name => Relocate_Node (Exp)));
else
Def_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
Set_Etype (Def_Id, Exp_Type);
Res := New_Reference_To (Def_Id, Loc);
E :=
Make_Object_Declaration (Loc,
Defining_Identifier => Def_Id,
Object_Definition => New_Reference_To (Exp_Type, Loc),
Constant_Present => True,
Expression => Relocate_Node (Exp));
Set_Assignment_OK (E);
Insert_Action (Exp, E);
end if;
-- Otherwise we generate a reference to the value
else
Ref_Type := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
Ptr_Typ_Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Ref_Type,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
All_Present => True,
Subtype_Indication =>
New_Reference_To (Exp_Type, Loc)));
E := Exp;
Insert_Action (Exp, Ptr_Typ_Decl);
Def_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
Set_Etype (Def_Id, Exp_Type);
Res :=
Make_Explicit_Dereference (Loc,
Prefix => New_Reference_To (Def_Id, Loc));
if Nkind (E) = N_Explicit_Dereference then
New_Exp := Relocate_Node (Prefix (E));
else
E := Relocate_Node (E);
New_Exp := Make_Reference (Loc, E);
end if;
if Nkind (E) = N_Aggregate and then Expansion_Delayed (E) then
Set_Expansion_Delayed (E, False);
Set_Analyzed (E, False);
end if;
Insert_Action (Exp,
Make_Object_Declaration (Loc,
Defining_Identifier => Def_Id,
Object_Definition => New_Reference_To (Ref_Type, Loc),
Expression => New_Exp));
end if;
-- Preserve the Assignment_OK flag in all copies, since at least
-- one copy may be used in a context where this flag must be set
-- (otherwise why would the flag be set in the first place).
Set_Assignment_OK (Res, Assignment_OK (Exp));
-- Finally rewrite the original expression and we are done
Rewrite (Exp, Res);
Analyze_And_Resolve (Exp, Exp_Type);
Scope_Suppress := Svg_Suppress;
end Remove_Side_Effects;
------------------------------------
-- Safe_Unchecked_Type_Conversion --
------------------------------------
-- Note: this function knows quite a bit about the exact requirements
-- of Gigi with respect to unchecked type conversions, and its code
-- must be coordinated with any changes in Gigi in this area.
-- The above requirements should be documented in Sinfo ???
function Safe_Unchecked_Type_Conversion (Exp : Node_Id) return Boolean is
Otyp : Entity_Id;
Ityp : Entity_Id;
Oalign : Uint;
Ialign : Uint;
Pexp : constant Node_Id := Parent (Exp);
begin
-- If the expression is the RHS of an assignment or object declaration
-- we are always OK because there will always be a target.
-- Object renaming declarations, (generated for view conversions of
-- actuals in inlined calls), like object declarations, provide an
-- explicit type, and are safe as well.
if (Nkind (Pexp) = N_Assignment_Statement
and then Expression (Pexp) = Exp)
or else Nkind (Pexp) = N_Object_Declaration
or else Nkind (Pexp) = N_Object_Renaming_Declaration
then
return True;
-- If the expression is the prefix of an N_Selected_Component
-- we should also be OK because GCC knows to look inside the
-- conversion except if the type is discriminated. We assume
-- that we are OK anyway if the type is not set yet or if it is
-- controlled since we can't afford to introduce a temporary in
-- this case.
elsif Nkind (Pexp) = N_Selected_Component
and then Prefix (Pexp) = Exp
then
if No (Etype (Pexp)) then
return True;
else
return
not Has_Discriminants (Etype (Pexp))
or else Is_Constrained (Etype (Pexp));
end if;
end if;
-- Set the output type, this comes from Etype if it is set, otherwise
-- we take it from the subtype mark, which we assume was already
-- fully analyzed.
if Present (Etype (Exp)) then
Otyp := Etype (Exp);
else
Otyp := Entity (Subtype_Mark (Exp));
end if;
-- The input type always comes from the expression, and we assume
-- this is indeed always analyzed, so we can simply get the Etype.
Ityp := Etype (Expression (Exp));
-- Initialize alignments to unknown so far
Oalign := No_Uint;
Ialign := No_Uint;
-- Replace a concurrent type by its corresponding record type
-- and each type by its underlying type and do the tests on those.
-- The original type may be a private type whose completion is a
-- concurrent type, so find the underlying type first.
if Present (Underlying_Type (Otyp)) then
Otyp := Underlying_Type (Otyp);
end if;
if Present (Underlying_Type (Ityp)) then
Ityp := Underlying_Type (Ityp);
end if;
if Is_Concurrent_Type (Otyp) then
Otyp := Corresponding_Record_Type (Otyp);
end if;
if Is_Concurrent_Type (Ityp) then
Ityp := Corresponding_Record_Type (Ityp);
end if;
-- If the base types are the same, we know there is no problem since
-- this conversion will be a noop.
if Implementation_Base_Type (Otyp) = Implementation_Base_Type (Ityp) then
return True;
-- If the size of output type is known at compile time, there is
-- never a problem. Note that unconstrained records are considered
-- to be of known size, but we can't consider them that way here,
-- because we are talking about the actual size of the object.
-- We also make sure that in addition to the size being known, we do
-- not have a case which might generate an embarrassingly large temp
-- in stack checking mode.
elsif Size_Known_At_Compile_Time (Otyp)
and then not May_Generate_Large_Temp (Otyp)
and then not (Is_Record_Type (Otyp) and then not Is_Constrained (Otyp))
then
return True;
-- If either type is tagged, then we know the alignment is OK so
-- Gigi will be able to use pointer punning.
elsif Is_Tagged_Type (Otyp) or else Is_Tagged_Type (Ityp) then
return True;
-- If either type is a limited record type, we cannot do a copy, so
-- say safe since there's nothing else we can do.
elsif Is_Limited_Record (Otyp) or else Is_Limited_Record (Ityp) then
return True;
-- Conversions to and from packed array types are always ignored and
-- hence are safe.
elsif Is_Packed_Array_Type (Otyp)
or else Is_Packed_Array_Type (Ityp)
then
return True;
end if;
-- The only other cases known to be safe is if the input type's
-- alignment is known to be at least the maximum alignment for the
-- target or if both alignments are known and the output type's
-- alignment is no stricter than the input's. We can use the alignment
-- of the component type of an array if a type is an unpacked
-- array type.
if Present (Alignment_Clause (Otyp)) then
Oalign := Expr_Value (Expression (Alignment_Clause (Otyp)));
elsif Is_Array_Type (Otyp)
and then Present (Alignment_Clause (Component_Type (Otyp)))
then
Oalign := Expr_Value (Expression (Alignment_Clause
(Component_Type (Otyp))));
end if;
if Present (Alignment_Clause (Ityp)) then
Ialign := Expr_Value (Expression (Alignment_Clause (Ityp)));
elsif Is_Array_Type (Ityp)
and then Present (Alignment_Clause (Component_Type (Ityp)))
then
Ialign := Expr_Value (Expression (Alignment_Clause
(Component_Type (Ityp))));
end if;
if Ialign /= No_Uint and then Ialign > Maximum_Alignment then
return True;
elsif Ialign /= No_Uint and then Oalign /= No_Uint
and then Ialign <= Oalign
then
return True;
-- Otherwise, Gigi cannot handle this and we must make a temporary.
else
return False;
end if;
end Safe_Unchecked_Type_Conversion;
--------------------------
-- Set_Elaboration_Flag --
--------------------------
procedure Set_Elaboration_Flag (N : Node_Id; Spec_Id : Entity_Id) is
Loc : constant Source_Ptr := Sloc (N);
Asn : Node_Id;
begin
if Present (Elaboration_Entity (Spec_Id)) then
-- Nothing to do if at the compilation unit level, because in this
-- case the flag is set by the binder generated elaboration routine.
if Nkind (Parent (N)) = N_Compilation_Unit then
null;
-- Here we do need to generate an assignment statement
else
Check_Restriction (No_Elaboration_Code, N);
Asn :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Elaboration_Entity (Spec_Id), Loc),
Expression => New_Occurrence_Of (Standard_True, Loc));
if Nkind (Parent (N)) = N_Subunit then
Insert_After (Corresponding_Stub (Parent (N)), Asn);
else
Insert_After (N, Asn);
end if;
Analyze (Asn);
end if;
end if;
end Set_Elaboration_Flag;
----------------------------
-- Wrap_Cleanup_Procedure --
----------------------------
procedure Wrap_Cleanup_Procedure (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Stseq : constant Node_Id := Handled_Statement_Sequence (N);
Stmts : constant List_Id := Statements (Stseq);
begin
if Abort_Allowed then
Prepend_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
Append_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer));
end if;
end Wrap_Cleanup_Procedure;
end Exp_Util;
|
-- ----------------------------------------------------------------- --
-- AdaSDL --
-- Binding to Simple Direct Media Layer --
-- Copyright (C) 2001 A.M.F.Vargas --
-- Antonio M. F. Vargas --
-- Ponta Delgada - Azores - Portugal --
-- http://www.adapower.net/~avargas --
-- E-mail: avargas@adapower.net --
-- ----------------------------------------------------------------- --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public --
-- License as published by the Free Software Foundation; either --
-- version 2 of the License, or (at your option) any later version. --
-- --
-- This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public --
-- License along with this library; if not, write to the --
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330, --
-- Boston, MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from --
-- this unit, or you link this unit with other files to produce an --
-- executable, this unit does not by itself cause the resulting --
-- executable to be covered by the GNU General Public License. This --
-- exception does not however invalidate any other reasons why the --
-- executable file might be covered by the GNU Public License. --
-- ----------------------------------------------------------------- --
with System;
with Interfaces.C;
package Lib_C is
package C renames Interfaces.C;
function memset (
BLOCK : System.Address;
Ch : C.int;
SIZE : C.size_t)
return System.Address;
procedure memset (
BLOCK : System.Address;
Ch : C.int;
SIZE : C.size_t);
pragma Import (C, memset);
procedure Mem_Set (
BLOCK : System.Address;
Ch : C.int;
SIZE : C.size_t);
pragma Import (C, Mem_Set, "memset");
-- function malloc (SIZE : C.size_t)
-- return System.Address;
-- pragma Import (C, malloc);
-- This procedure is necessary to deallocate
-- valid data created inside de SDL C library.
procedure free (PTR : System.Address);
pragma Import (C, free);
type sighandler_t is access procedure (signum : C.int);
pragma Convention (C, sighandler_t);
function signal (
signum : C.int; -- Ex: System.OS_Interface.SIGKILL
handler : sighandler_t)
return sighandler_t;
pragma Import (C, signal);
procedure Set_Signal (
signum : C.int; -- Ex: System.OS_Interface.SIGKILL
handler : sighandler_t);
pragma Import (C, Set_Signal, "signal");
function Raise_Signal (sig : C.int) return C.int;
pragma Import (C, Raise_Signal, "raise");
procedure Raise_The_Signal (sig : C.int);
pragma Import (C, Raise_The_Signal, "raise");
end Lib_C;
|
with System.Runtime_Context;
package body System.Storage_Pools.Overlaps is
pragma Suppress (All_Checks);
-- implementation
procedure Set_Address (Storage_Address : Address) is
TLS : constant not null Runtime_Context.Task_Local_Storage_Access :=
Runtime_Context.Get_Task_Local_Storage;
begin
TLS.Overlaid_Allocation := Storage_Address;
end Set_Address;
overriding procedure Allocate (
Pool : in out Overlay_Pool;
Storage_Address : out Address;
Size_In_Storage_Elements : Storage_Elements.Storage_Count;
Alignment : Storage_Elements.Storage_Count)
is
pragma Unreferenced (Pool);
pragma Unreferenced (Size_In_Storage_Elements);
pragma Unreferenced (Alignment);
TLS : constant not null Runtime_Context.Task_Local_Storage_Access :=
Runtime_Context.Get_Task_Local_Storage;
begin
Storage_Address := TLS.Overlaid_Allocation;
TLS.Overlaid_Allocation := Null_Address;
end Allocate;
overriding procedure Deallocate (
Pool : in out Overlay_Pool;
Storage_Address : Address;
Size_In_Storage_Elements : Storage_Elements.Storage_Count;
Alignment : Storage_Elements.Storage_Count)
is
pragma Unreferenced (Pool);
pragma Unreferenced (Size_In_Storage_Elements);
pragma Unreferenced (Alignment);
TLS : constant not null Runtime_Context.Task_Local_Storage_Access :=
Runtime_Context.Get_Task_Local_Storage;
begin
pragma Assert (Storage_Address = TLS.Overlaid_Allocation);
TLS.Overlaid_Allocation := Null_Address;
end Deallocate;
end System.Storage_Pools.Overlaps;
|
package freetype_c.FT_Vector
is
type Item is
record
X : aliased FT_Pos;
Y : aliased FT_Pos;
end record;
type Item_array is array (C.Size_t range <>) of aliased FT_Vector.Item;
type Pointer is access all FT_Vector.Item;
type Pointer_array is array (C.Size_t range <>) of aliased FT_Vector.Pointer;
type pointer_Pointer is access all freetype_c.FT_Vector.Pointer;
end freetype_c.FT_Vector;
|
pragma License (Unrestricted);
-- runtime unit for ZCX
with C.unwind;
package System.Unwind.Searching is
pragma Preelaborate;
function Unwind_RaiseException (
exc : access C.unwind.struct_Unwind_Exception)
return C.unwind.Unwind_Reason_Code
renames C.unwind.Unwind_RaiseException;
function Unwind_ForcedUnwind (
exc : access C.unwind.struct_Unwind_Exception;
stop : C.unwind.Unwind_Stop_Fn;
stop_argument : C.void_ptr)
return C.unwind.Unwind_Reason_Code
renames C.unwind.Unwind_ForcedUnwind;
-- (a-exexpr-gcc.adb)
Others_Value : aliased constant C.char := 'O'
with Export, Convention => C, External_Name => "__gnat_others_value";
All_Others_Value : aliased constant C.char := 'A'
with Export, Convention => C, External_Name => "__gnat_all_others_value";
-- personality function (raise-gcc.c)
function Personality (
ABI_Version : C.signed_int;
Phases : C.unwind.Unwind_Action;
Exception_Class : C.unwind.Unwind_Exception_Class;
Exception_Object : access C.unwind.struct_Unwind_Exception;
Context : access C.unwind.struct_Unwind_Context)
return C.unwind.Unwind_Reason_Code
with Export, Convention => C, External_Name => "__gnat_personality_v0";
pragma Compile_Time_Error (
Personality'Access = C.unwind.Unwind_Personality_Fn'(null),
"this expression is always false, for type check purpose");
end System.Unwind.Searching;
|
with Ada.Streams;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Wide_Wide_Text_IO; use Ada.Wide_Wide_Text_IO;
with DOM.Core.Documents; use DOM.Core.Documents;
with DOM.Core; use DOM.Core;
with DOM.Core.Elements; use DOM.Core.Elements;
with DOM.Core.Nodes; use DOM.Core.Nodes;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
with Ada.Characters.Conversions;
with Ada.Directories;
with DOM.Readers;
with Globals;
with Version;
package Xmlhelpers is
procedure Add_Node (
Node_Name,
Node_Value : String;
Parent_Node : DOM.Core.Element; Feed : Node);
procedure Add_Link (
Parent_Node : DOM.Core.Element;
Url, Relationship : String; Feed : Node);
procedure Add_Generator (
Parent_Node : DOM.Core.Element; Feed : Node);
procedure Add_Author (Parent_Node : DOM.Core.Element;
Name, Email : String; Feed : Node);
end Xmlhelpers;
|
package SubmarineSubSystem with SPARK_Mode is
type Operational is (On, Off); -- Can Submarine Operate?
type DoSomething is (Fire, CantFire); -- Test for actions can only be done once,
-- Nuclear Submarine is operational.
--Door Duntionality types
type AirDoorOne is (Closed, Open); -- Airlock door One closed or open
type AirDoorTwo is (Closed, Open); -- Airlock door Two Closed or open
type DoorOneLock is (Locked, Unlocked); -- Airlock door One Locked or Unlocked
type DoorTwoLock is (Locked, Unlocked); -- Airlock door Two Locked or Unlocked
-- Depth Sensor types
type DepthDive is (Dive, Surface);
type DepthStage is (Nominal, Warning, Danger);
type DepthLevel is new Integer range 0..10;
-- Oxyegen System types
type OxygenState is (High, Low);
type OxygenWarning is (Oxygen_Fine, Oxygen_Warning);
type OxygenTank is new Integer range 0..100;
-- Reactor System types
type ReactorTemp is (Fine, Overheating);
-- Submarine variables
type Submarine is record
GoodToGo : Operational;
OpTest : DoSomething;
ClosingOne : AirDoorOne;
ClosingTwo : AirDoorTwo;
LockingOne : DoorOneLock;
LockingTwo : DoorTwoLock;
DDive : DepthDive;
DStage : DepthStage;
DLevel : DepthLevel;
OState : OxygenState;
OWarning : OxygenWarning;
OTank : OxygenTank;
RTemp : ReactorTemp;
end record;
-- Record of NuclearSubmarine
NuclearSubmarine : Submarine := (GoodToGo => Off, ClosingOne => Open,
ClosingTwo => Closed, LockingOne => Unlocked,
LockingTwo => Unlocked, OpTest => CantFire,
DDive => Surface, DStage => Nominal, DLevel => 0,
OState => High, OWarning => Oxygen_Fine, OTank => 100,
RTemp => Fine);
-- Try to Start Submarine
procedure StartSubmarine with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.GoodToGo = Off and then
NuclearSubmarine.ClosingOne = Closed
and then NuclearSubmarine.LockingOne = Locked and then
NuclearSubmarine.ClosingTwo = Closed
and then NuclearSubmarine.LockingTwo = Locked,
Post => NuclearSubmarine.GoodToGo = On;
-- Can only do if Submarine is operational, TEST!
procedure SubmarineAction with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.GoodToGo = On and then
NuclearSubmarine.ClosingOne = Closed
and then NuclearSubmarine.LockingOne = Locked and then
NuclearSubmarine.ClosingTwo = Closed
and then NuclearSubmarine.LockingTwo = Locked,
Post => NuclearSubmarine.OpTest = Fire;
-----------------------------------------------------------------------------------------------
-----------------------------------DOOR FUNCTIONALITY------------------------------------------
-----------------------------------------------------------------------------------------------
-- Airlock Door One can only open if Airlock Door Two is Closed. And Vide Versa
-- These Checks are made in procedures: D1Close, D2Close, D1Open and D2 Open
-- Airlock Door One Close
procedure D1Close with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.ClosingOne = Open and then
NuclearSubmarine.ClosingTwo = Closed,
Post => NuclearSubmarine.ClosingOne = Closed;
-- Airlock Door Two Close
procedure D2Close with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.ClosingTwo = Open and then
NuclearSubmarine.ClosingOne = Closed,
Post => NuclearSubmarine.ClosingTwo = Closed;
--Airlock Door One Lock
procedure D1Lock with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.ClosingOne = Closed and then
NuclearSubmarine.LockingOne = Unlocked,
Post => NuclearSubmarine.LockingOne = Locked;
-- Airlock Door Two Lock
procedure D2Lock with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.ClosingTwo = Closed and then
NuclearSubmarine.LockingTwo = Unlocked,
Post => NuclearSubmarine.LockingTwo = Locked;
--Airlock Door One Open
procedure D1Open with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.LockingOne = Unlocked and then
NuclearSubmarine.ClosingOne = Closed and then
NuclearSubmarine.ClosingTwo = Closed,
Post => NuclearSubmarine.ClosingOne = Open;
-- Airlock Door Two Open
procedure D2Open with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.LockingTwo = Unlocked and then
NuclearSubmarine.ClosingTwo = Closed and then
NuclearSubmarine.ClosingOne = Closed,
Post => NuclearSubmarine.ClosingTwo = Open;
--Airlock Door One Unlock
procedure D1Unlock with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.ClosingOne = Closed and then
NuclearSubmarine.LockingOne = Locked,
Post => NuclearSubmarine.ClosingOne = Closed and then
NuclearSubmarine.LockingOne = Unlocked;
-- Airlock Door Two Unlock
procedure D2Unlock with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.ClosingTwo = Closed and then
NuclearSubmarine.LockingTwo = Locked,
Post => NuclearSubmarine.ClosingTwo = Closed and then
NuclearSubmarine.LockingTwo = Unlocked;
-----------------------------------------------------------------------------------------------
-----------------------------------END OF DOOR FUNCTIONALITY-----------------------------------
-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
-----------------------------------DEPTH SENSOR FUNCTIONALITY----------------------------------
-----------------------------------------------------------------------------------------------
-- Gauges Depth Meter to see if Submarine is Nominal, Warning or Danger stage
procedure DepthMeterCheck with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.GoodToGo = On and then
NuclearSubmarine.OpTest = Fire,
Post => NuclearSubmarine.GoodToGo = On and then
NuclearSubmarine.OpTest = Fire;
-- Changes the depth of the Submarine. Cannnot go above 9.
procedure ChangeDepth with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.GoodToGo = On and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.DDive = Dive and then
NuclearSubmarine.DLevel < 8,
Post => NuclearSubmarine.GoodToGo = On and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.DDive = Dive and then
NuclearSubmarine.DLevel /= 0;
-- Checks if Submarine can Dive
procedure DiveOrNot with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.GoodToGo = On and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.DDive = Surface and then
NuclearSubmarine.RTemp = Fine,
Post => NuclearSubmarine.DDive = Dive;
-- Allows submarine to resurface
procedure Resurface with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.GoodToGo = On and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.DDive = Dive,
Post=> NuclearSubmarine.DDive = Surface and then
NuclearSubmarine.OTank = 100;
-----------------------------------------------------------------------------------------------
--------------------------- END OF DEPTH SENSOR FUNCTIONALITY----------------------------------
-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
----------------------------------- OXYGEN FUNCTIONALITY --------------------------------------
-----------------------------------------------------------------------------------------------
-- Checks the integer value in OTank
procedure OxygenReserveCheck with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.GoodToGo = On and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.OTank <= 0,
Post => NuclearSubmarine.GoodToGo = On and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.OTank <= 0;
--This procedure will consume 10 oxygen out of OTank
procedure ConsumeOxygen with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.GoodToGo = On and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.DDive = Dive and then
NuclearSubmarine.OTank >= 10,
Post => NuclearSubmarine.GoodToGo = On and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.DDive = Dive and then
NuclearSubmarine.OTank >= 0;
-----------------------------------------------------------------------------------------------
------------------------------- END OF OXYGEN FUNCTIONALITY ---------------------------------
-----------------------------------------------------------------------------------------------
-- Post condition MIGHT fail here. Look at Comments from in submarinesubsystem.adb
-- Code line 242 to 247 for clarification.
-- This procedure will still pass "Bronze" level of Proofing
procedure ReactorOverheatRoutine with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.GoodToGo = on and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.RTemp = Fine and then
NuclearSubmarine.DDive = Dive,
Post => NuclearSubmarine.GoodToGo = on and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.RTemp = Fine and then
NuclearSubmarine.RTemp = Overheating;
procedure CoolReactor with
Global => (In_Out => NuclearSubmarine),
Pre => NuclearSubmarine.GoodToGo = on and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.DDive = Surface and then
NuclearSubmarine.RTemp = Overheating,
Post => NuclearSubmarine.GoodToGo = on and then
NuclearSubmarine.OpTest = Fire and then
NuclearSubmarine.DDive = Surface and then
NuclearSubmarine.RTemp = Fine;
-----------------------------------------------------------------------------------------------
------------------------------- END OF REACTOR FUNCTIONALITY ---------------------------------
-----------------------------------------------------------------------------------------------
end SubmarineSubSystem;
|
-----------------------------------------------------------------------
-- Util-strings -- Various String Utility
-- Copyright (C) 2001, 2002, 2003, 2009, 2010, 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.Strings;
with Ada.Strings.Unbounded;
with Ada.Containers;
with Ada.Containers.Hashed_Maps;
with Ada.Containers.Hashed_Sets;
with Util.Concurrent.Counters;
package Util.Strings is
pragma Preelaborate;
-- Constant string access
type Name_Access is access constant String;
-- Compute the hash value of the string.
function Hash (Key : Name_Access) return Ada.Containers.Hash_Type;
-- Returns true if left and right strings are equivalent.
function Equivalent_Keys (Left, Right : Name_Access) return Boolean;
-- Search for the first occurrence of the character in the string
-- after the from index. This implementation is 3-times faster than
-- the Ada.Strings.Fixed version.
-- Returns the index of the first occurrence or 0.
function Index (Source : in String;
Char : in Character;
From : in Natural := 0) return Natural;
-- Search for the first occurrence of the character in the string
-- before the from index and going backward.
-- This implementation is 3-times faster than the Ada.Strings.Fixed version.
-- Returns the index of the first occurrence or 0.
function Rindex (Source : in String;
Ch : in Character;
From : in Natural := 0) return Natural;
-- Search for the first occurrence of the pattern in the string.
function Index (Source : in String;
Pattern : in String;
From : in Positive;
Going : in Ada.Strings.Direction := Ada.Strings.Forward) return Natural;
-- Returns Integer'Image (Value) with the possible space stripped.
function Image (Value : in Integer) return String;
-- Returns Integer'Image (Value) with the possible space stripped.
function Image (Value : in Long_Long_Integer) return String;
package String_Access_Map is new Ada.Containers.Hashed_Maps
(Key_Type => Name_Access,
Element_Type => Name_Access,
Hash => Hash,
Equivalent_Keys => Equivalent_Keys);
package String_Set is new Ada.Containers.Hashed_Sets
(Element_Type => Name_Access,
Hash => Hash,
Equivalent_Elements => Equivalent_Keys);
-- String reference
type String_Ref is private;
-- Create a string reference from a string.
function To_String_Ref (S : in String) return String_Ref;
-- Create a string reference from an unbounded string.
function To_String_Ref (S : in Ada.Strings.Unbounded.Unbounded_String) return String_Ref;
-- Get the string
function To_String (S : in String_Ref) return String;
-- Get the string as an unbounded string
function To_Unbounded_String (S : in String_Ref) return Ada.Strings.Unbounded.Unbounded_String;
-- Compute the hash value of the string reference.
function Hash (Key : in String_Ref) return Ada.Containers.Hash_Type;
-- Returns true if left and right string references are equivalent.
function Equivalent_Keys (Left, Right : in String_Ref) return Boolean;
function "=" (Left, Right : in String_Ref) return Boolean renames Equivalent_Keys;
function "=" (Left : in String_Ref;
Right : in String) return Boolean;
function "=" (Left : in String_Ref;
Right : in Ada.Strings.Unbounded.Unbounded_String) return Boolean;
-- Returns the string length.
function Length (S : in String_Ref) return Natural;
private
pragma Inline (To_String_Ref);
pragma Inline (To_String);
type String_Record (Len : Natural) is limited record
Counter : Util.Concurrent.Counters.Counter;
Str : String (1 .. Len);
end record;
type String_Record_Access is access all String_Record;
type String_Ref is new Ada.Finalization.Controlled with record
Str : String_Record_Access := null;
end record;
pragma Finalize_Storage_Only (String_Ref);
-- Increment the reference counter.
overriding
procedure Adjust (Object : in out String_Ref);
-- Decrement the reference counter and free the allocated string.
overriding
procedure Finalize (Object : in out String_Ref);
end Util.Strings;
|
-- Abstract:
--
-- Bounded stack implementation, with full Spark verification,
-- optimized for speed.
--
-- Copyright (C) 1998-2000, 2002-2003, 2009, 2015, 2017 - 2019 Free Software Foundation, Inc.
--
-- SAL is free software; you can redistribute it and/or modify it
-- under terms of the GNU General Public License as published by the
-- Free Software Foundation; either version 3, or (at your option)
-- any later version. SAL 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 SAL; see file COPYING. If not, write to the Free Software
-- Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-- USA.
--
-- As a special exception under Section 7 of GPL version 3, you are granted
-- additional permissions described in the GCC Runtime Library Exception,
-- version 3.1, as published by the Free Software Foundation.
pragma License (Modified_GPL);
generic
type Element_Type is private;
package SAL.Gen_Bounded_Definite_Stacks
with Spark_Mode
is
pragma Pure;
-- pragma Suppress (All_Checks); -- Users must check Is_Full before Push, Is_Empty before Pop etc.
package Sgbds renames SAL.Gen_Bounded_Definite_Stacks;
subtype Size_Type is Base_Peek_Type range 0 .. Base_Peek_Type'Last / 2;
-- The upper limit is needed to avoid overflow in Peek.
-- Zero included for Depth result.
type Stack (Size : Size_Type) is tagged private;
-- Tagged to allow Object.Method notation.
-- No Empty_Stack constant, to avoid requiring a Default_Element.
procedure Clear (Stack : in out Sgbds.Stack)
with Post'Class => Depth (Stack) = 0;
-- Empty Stack of all items.
function Depth (Stack : in Sgbds.Stack) return Size_Type;
-- Returns current count of items in Stack
function Is_Empty (Stack : in Sgbds.Stack) return Boolean
with Post'Class => Is_Empty'Result = (Depth (Stack) = 0);
-- Returns true iff no items are in Stack.
function Is_Full (Stack : in Sgbds.Stack) return Boolean
with Post'Class => Is_Full'Result = (Depth (Stack) = Stack.Size);
-- Returns true iff Stack is full.
function Peek (Stack : in Sgbds.Stack; Index : in Peek_Type := 1) return Element_Type
with Pre'Class => Depth (Stack) in 1 .. Stack.Size and Index in 1 .. Depth (Stack);
-- Return the Index'th item from the top of Stack; the Item is _not_ removed.
-- Top item has index 1.
procedure Pop (Stack : in out Sgbds.Stack; Count : in Base_Peek_Type := 1) with
Pre'Class => Depth (Stack) in 1 .. Stack.Size and Count in 0 .. Depth (Stack),
Post'Class => Depth (Stack) = Depth (Stack)'Old - Count and then
(for all I in 1 .. Depth (Stack) => Peek (Stack'Old, I + Count) = Peek (Stack, I));
-- Remove Count Items from the top of Stack, discard them.
procedure Pop (Stack : in out Sgbds.Stack; Item : out Element_Type) with
Pre'Class => Depth (Stack) in 1 .. Stack.Size,
Post'Class =>
Depth (Stack) = Depth (Stack)'Old - 1 and then
(Item = Peek (Stack'Old) and
(for all I in 1 .. Depth (Stack) => Peek (Stack'Old, I + 1) = Peek (Stack, I)));
-- Remove one item from the top of Stack, return in Item.
function Pop (Stack : in out Sgbds.Stack) return Element_Type with
Spark_Mode => Off;
-- Remove one item from the top of Stack, and return it.
procedure Push (Stack : in out Sgbds.Stack; Item : in Element_Type) with
Pre'Class => Depth (Stack) in 0 .. Stack.Size - 1,
Post'Class =>
Depth (Stack) = Depth (Stack)'Old + 1 and then
(Item = Peek (Stack) and
(for all I in 1 .. Depth (Stack'Old) => Peek (Stack'Old, I) = Peek (Stack, I + 1)));
-- Add Item to the top of Stack.
private
type Element_Array is array (Size_Type range <>) of aliased Element_Type;
type Stack (Size : Size_Type) is tagged record
Top : Base_Peek_Type := Invalid_Peek_Index; -- empty
Data : Element_Array (1 .. Size);
-- Top of stack is at Data (Top).
-- Data (1 .. Top) has been set at some point.
end record with
Dynamic_Predicate => Top in 0 .. Size;
end SAL.Gen_Bounded_Definite_Stacks;
|
with AUnit.Assertions; use AUnit.Assertions;
with Ada.Containers.Vectors;
with Ada.Text_IO;
with NNClassifier;
with NeuralNet;
with DataBatch;
with MathUtils;
use MathUtils.Float_Vec;
use Ada.Containers;
package body NNClassifierTests is
procedure Register_Tests (T: in out TestCase) is
use AUnit.Test_Cases.Registration;
begin
Register_Routine (T, testLogisticRegression'Access, "logistic regression");
end Register_Tests;
function Name(T: TestCase) return Test_String is
begin
return Format("NN Classifier Tests");
end Name;
procedure testLogisticRegression(T : in out Test_Cases.Test_Case'Class) is
config: NeuralNet.Config(1);
dnn: NNClassifier.DNN(config.size + 1);
batch: DataBatch.Batch;
labels: NNClassifier.LabelVector;
trainSetSize: constant Positive := 1000;
input: MathUtils.Vector;
prediction: MathUtils.Vector;
begin
config.inputSize := 4;
config.act := NeuralNet.LOGISTIC;
config.lr := 0.9;
config.sizes := (1 => 16);
dnn := NNClassifier.create(config => config,
numberOfClasses => 2);
for i in 1 .. trainSetSize loop
batch.append((MathUtils.rand01 + 0.5) & 0.0 & 0.0 & (MathUtils.rand01 + 0.5));
labels.Append(0);
batch.append((MathUtils.rand01 + 0.5) & (MathUtils.rand01 + 0.5) & 0.0 & 0.0);
labels.Append(1);
end loop;
dnn.train(batch, labels);
input := 0.5 & 0.0 & 0.0 & 0.5;
prediction := dnn.classify(input);
Assert(prediction(1) > prediction(2), "");
input := 0.5 & 0.5 & 0.0 & 0.0;
prediction := dnn.classify(input);
Assert(prediction(2) > prediction(1), "");
end testLogisticRegression;
end NNClassifierTests;
|
-- Mojang API
-- No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
--
-- OpenAPI spec version: 2020_06_05
--
--
-- NOTE: This package is auto generated by the swagger code generator 3.3.4.
-- https://openapi-generator.tech
-- Do not edit the class manually.
with Swagger.Streams;
with Ada.Containers.Vectors;
package com.github.asyncmc.mojang.status.ada.server.model.Models is
type ApiStatus_Type is
record
end record;
package ApiStatus_Type_Vectors is
new Ada.Containers.Vectors (Index_Type => Positive,
Element_Type => ApiStatus_Type);
procedure Serialize (Into : in out Swagger.Streams.Output_Stream'Class;
Name : in String;
Value : in ApiStatus_Type);
procedure Serialize (Into : in out Swagger.Streams.Output_Stream'Class;
Name : in String;
Value : in ApiStatus_Type_Vectors.Vector);
procedure Deserialize (From : in Swagger.Value_Type;
Name : in String;
Value : out ApiStatus_Type);
procedure Deserialize (From : in Swagger.Value_Type;
Name : in String;
Value : out ApiStatus_Type_Vectors.Vector);
end com.github.asyncmc.mojang.status.ada.server.model.Models;
|
with GESTE;
with GESTE.Text;
with Ada.Text_IO;
with Console_Char_Screen;
with GESTE_Fonts.FreeMono6pt7b;
procedure Simple_Text is
package Font_A renames GESTE_Fonts.FreeMono6pt7b;
package Console_Screen is new Console_Char_Screen
(Width => 42,
Height => 35,
Buffer_Size => 256,
Init_Char => ' ');
Text_A : aliased GESTE.Text.Instance
(Font_A.Font, 6, 3, '#', ' ');
begin
Text_A.Move ((0, 0));
GESTE.Add (Text_A'Unrestricted_Access, 0);
Text_A.Cursor (1, 1);
-- Check that out of bounds Set_Cursor has no effect
Text_A.Cursor (100, 1);
Text_A.Cursor (1, 100);
Text_A.Cursor (100, 100);
Text_A.Put ("AbCdEf");
-- Check LF in the middle of a string
Text_A.Put ("{!@&^" & ASCII.LF & "123");
-- Check overflow of the last line (7 will be printed at (1, 1)
Text_A.Put ("4567");
if Text_A.Char (1, 1) /= '7' then
Ada.Text_IO.Put_Line ("unexpected character at (1, 1)");
end if;
-- Invert some characters
Text_A.Invert (1, 1);
Text_A.Invert (3, 1);
Text_A.Invert (5, 1);
Text_A.Invert (2, 2);
Text_A.Invert (4, 2);
-- Change color of the second line
for A in 1 .. 5 loop
Text_A.Set_Colors (A, 2, '/', ' ');
end loop;
-- Out of bounds access
if Text_A.Char (10, 10) /= ASCII.NUL then
Ada.Text_IO.Put_Line ("NUL expected for out of bounds position");
end if;
GESTE.Render_Window
(Window => Console_Screen.Screen_Rect,
Background => ' ',
Buffer => Console_Screen.Buffer,
Push_Pixels => Console_Screen.Push_Pixels'Unrestricted_Access,
Set_Drawing_Area => Console_Screen.Set_Drawing_Area'Unrestricted_Access);
Console_Screen.Print;
Ada.Text_IO.New_Line;
Text_A.Invert_All;
Text_A.Set_Colors_All ('-', ' ');
GESTE.Render_Window
(Window => Console_Screen.Screen_Rect,
Background => ' ',
Buffer => Console_Screen.Buffer,
Push_Pixels => Console_Screen.Push_Pixels'Unrestricted_Access,
Set_Drawing_Area => Console_Screen.Set_Drawing_Area'Unrestricted_Access);
Console_Screen.Print;
Ada.Text_IO.New_Line;
end Simple_Text;
|
with AUnit;
with AUnit.Test_Fixtures;
with Brackelib.Queues;
package Queues_Tests is
package State_Queues is new Brackelib.Queues (Integer);
use State_Queues;
type Test is new AUnit.Test_Fixtures.Test_Fixture with null record;
procedure Set_Up (T : in out Test);
procedure Test_Enqueue (T : in out Test);
procedure Test_Dequeue (T : in out Test);
procedure Test_Clear (T : in out Test);
procedure Test_Empty (T : in out Test);
end Queues_Tests;
|
pragma Style_Checks (Off);
-- This spec has been automatically generated from ATSAMD51G19A.svd
pragma Restrictions (No_Elaboration_Code);
with HAL;
with System;
package SAM_SVD.ADC is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- Dual Mode Trigger Selection
type CTRLA_DUALSELSelect is
(-- Start event or software trigger will start a conversion on both ADCs
BOTH,
-- START event or software trigger will alternatingly start a conversion on
-- ADC0 and ADC1
INTERLEAVE)
with Size => 2;
for CTRLA_DUALSELSelect use
(BOTH => 0,
INTERLEAVE => 1);
-- Prescaler Configuration
type CTRLA_PRESCALERSelect is
(-- Peripheral clock divided by 2
DIV2,
-- Peripheral clock divided by 4
DIV4,
-- Peripheral clock divided by 8
DIV8,
-- Peripheral clock divided by 16
DIV16,
-- Peripheral clock divided by 32
DIV32,
-- Peripheral clock divided by 64
DIV64,
-- Peripheral clock divided by 128
DIV128,
-- Peripheral clock divided by 256
DIV256)
with Size => 3;
for CTRLA_PRESCALERSelect use
(DIV2 => 0,
DIV4 => 1,
DIV8 => 2,
DIV16 => 3,
DIV32 => 4,
DIV64 => 5,
DIV128 => 6,
DIV256 => 7);
-- Control A
type ADC_CTRLA_Register is record
-- Software Reset
SWRST : Boolean := False;
-- Enable
ENABLE : Boolean := False;
-- unspecified
Reserved_2_2 : HAL.Bit := 16#0#;
-- Dual Mode Trigger Selection
DUALSEL : CTRLA_DUALSELSelect := SAM_SVD.ADC.BOTH;
-- Slave Enable
SLAVEEN : Boolean := False;
-- Run in Standby
RUNSTDBY : Boolean := False;
-- On Demand Control
ONDEMAND : Boolean := False;
-- Prescaler Configuration
PRESCALER : CTRLA_PRESCALERSelect := SAM_SVD.ADC.DIV2;
-- unspecified
Reserved_11_14 : HAL.UInt4 := 16#0#;
-- Rail to Rail Operation Enable
R2R : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 16,
Bit_Order => System.Low_Order_First;
for ADC_CTRLA_Register use record
SWRST at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
Reserved_2_2 at 0 range 2 .. 2;
DUALSEL at 0 range 3 .. 4;
SLAVEEN at 0 range 5 .. 5;
RUNSTDBY at 0 range 6 .. 6;
ONDEMAND at 0 range 7 .. 7;
PRESCALER at 0 range 8 .. 10;
Reserved_11_14 at 0 range 11 .. 14;
R2R at 0 range 15 .. 15;
end record;
-- Event Control
type ADC_EVCTRL_Register is record
-- Flush Event Input Enable
FLUSHEI : Boolean := False;
-- Start Conversion Event Input Enable
STARTEI : Boolean := False;
-- Flush Event Invert Enable
FLUSHINV : Boolean := False;
-- Start Conversion Event Invert Enable
STARTINV : Boolean := False;
-- Result Ready Event Out
RESRDYEO : Boolean := False;
-- Window Monitor Event Out
WINMONEO : Boolean := False;
-- unspecified
Reserved_6_7 : HAL.UInt2 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for ADC_EVCTRL_Register use record
FLUSHEI at 0 range 0 .. 0;
STARTEI at 0 range 1 .. 1;
FLUSHINV at 0 range 2 .. 2;
STARTINV at 0 range 3 .. 3;
RESRDYEO at 0 range 4 .. 4;
WINMONEO at 0 range 5 .. 5;
Reserved_6_7 at 0 range 6 .. 7;
end record;
-- Debug Control
type ADC_DBGCTRL_Register is record
-- Debug Run
DBGRUN : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for ADC_DBGCTRL_Register use record
DBGRUN at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Positive Mux Input Selection
type INPUTCTRL_MUXPOSSelect is
(-- ADC AIN0 Pin
AIN0,
-- ADC AIN1 Pin
AIN1,
-- ADC AIN2 Pin
AIN2,
-- ADC AIN3 Pin
AIN3,
-- ADC AIN4 Pin
AIN4,
-- ADC AIN5 Pin
AIN5,
-- ADC AIN6 Pin
AIN6,
-- ADC AIN7 Pin
AIN7,
-- ADC AIN8 Pin
AIN8,
-- ADC AIN9 Pin
AIN9,
-- ADC AIN10 Pin
AIN10,
-- ADC AIN11 Pin
AIN11,
-- ADC AIN12 Pin
AIN12,
-- ADC AIN13 Pin
AIN13,
-- ADC AIN14 Pin
AIN14,
-- ADC AIN15 Pin
AIN15,
-- ADC AIN16 Pin
AIN16,
-- ADC AIN17 Pin
AIN17,
-- ADC AIN18 Pin
AIN18,
-- ADC AIN19 Pin
AIN19,
-- ADC AIN20 Pin
AIN20,
-- ADC AIN21 Pin
AIN21,
-- ADC AIN22 Pin
AIN22,
-- ADC AIN23 Pin
AIN23,
-- 1/4 Scaled Core Supply
SCALEDCOREVCC,
-- 1/4 Scaled VBAT Supply
SCALEDVBAT,
-- 1/4 Scaled I/O Supply
SCALEDIOVCC,
-- Bandgap Voltage
BANDGAP,
-- Temperature Sensor
PTAT,
-- Temperature Sensor
CTAT,
-- DAC Output
DAC,
-- PTC output (only on ADC0)
PTC)
with Size => 5;
for INPUTCTRL_MUXPOSSelect use
(AIN0 => 0,
AIN1 => 1,
AIN2 => 2,
AIN3 => 3,
AIN4 => 4,
AIN5 => 5,
AIN6 => 6,
AIN7 => 7,
AIN8 => 8,
AIN9 => 9,
AIN10 => 10,
AIN11 => 11,
AIN12 => 12,
AIN13 => 13,
AIN14 => 14,
AIN15 => 15,
AIN16 => 16,
AIN17 => 17,
AIN18 => 18,
AIN19 => 19,
AIN20 => 20,
AIN21 => 21,
AIN22 => 22,
AIN23 => 23,
SCALEDCOREVCC => 24,
SCALEDVBAT => 25,
SCALEDIOVCC => 26,
BANDGAP => 27,
PTAT => 28,
CTAT => 29,
DAC => 30,
PTC => 31);
-- Negative Mux Input Selection
type INPUTCTRL_MUXNEGSelect is
(-- ADC AIN0 Pin
AIN0,
-- ADC AIN1 Pin
AIN1,
-- ADC AIN2 Pin
AIN2,
-- ADC AIN3 Pin
AIN3,
-- ADC AIN4 Pin
AIN4,
-- ADC AIN5 Pin
AIN5,
-- ADC AIN6 Pin
AIN6,
-- ADC AIN7 Pin
AIN7,
-- Internal Ground
GND)
with Size => 5;
for INPUTCTRL_MUXNEGSelect use
(AIN0 => 0,
AIN1 => 1,
AIN2 => 2,
AIN3 => 3,
AIN4 => 4,
AIN5 => 5,
AIN6 => 6,
AIN7 => 7,
GND => 24);
-- Input Control
type ADC_INPUTCTRL_Register is record
-- Positive Mux Input Selection
MUXPOS : INPUTCTRL_MUXPOSSelect := SAM_SVD.ADC.AIN0;
-- unspecified
Reserved_5_6 : HAL.UInt2 := 16#0#;
-- Differential Mode
DIFFMODE : Boolean := False;
-- Negative Mux Input Selection
MUXNEG : INPUTCTRL_MUXNEGSelect := SAM_SVD.ADC.AIN0;
-- unspecified
Reserved_13_14 : HAL.UInt2 := 16#0#;
-- Stop DMA Sequencing
DSEQSTOP : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 16,
Bit_Order => System.Low_Order_First;
for ADC_INPUTCTRL_Register use record
MUXPOS at 0 range 0 .. 4;
Reserved_5_6 at 0 range 5 .. 6;
DIFFMODE at 0 range 7 .. 7;
MUXNEG at 0 range 8 .. 12;
Reserved_13_14 at 0 range 13 .. 14;
DSEQSTOP at 0 range 15 .. 15;
end record;
-- Conversion Result Resolution
type CTRLB_RESSELSelect is
(-- 12-bit result
Val_12BIT,
-- For averaging mode output
Val_16BIT,
-- 10-bit result
Val_10BIT,
-- 8-bit result
Val_8BIT)
with Size => 2;
for CTRLB_RESSELSelect use
(Val_12BIT => 0,
Val_16BIT => 1,
Val_10BIT => 2,
Val_8BIT => 3);
-- Window Monitor Mode
type CTRLB_WINMODESelect is
(-- No window mode (default)
DISABLE,
-- RESULT > WINLT
MODE1,
-- RESULT < WINUT
MODE2,
-- WINLT < RESULT < WINUT
MODE3,
-- !(WINLT < RESULT < WINUT)
MODE4)
with Size => 3;
for CTRLB_WINMODESelect use
(DISABLE => 0,
MODE1 => 1,
MODE2 => 2,
MODE3 => 3,
MODE4 => 4);
-- Control B
type ADC_CTRLB_Register is record
-- Left-Adjusted Result
LEFTADJ : Boolean := False;
-- Free Running Mode
FREERUN : Boolean := False;
-- Digital Correction Logic Enable
CORREN : Boolean := False;
-- Conversion Result Resolution
RESSEL : CTRLB_RESSELSelect := SAM_SVD.ADC.Val_12BIT;
-- unspecified
Reserved_5_7 : HAL.UInt3 := 16#0#;
-- Window Monitor Mode
WINMODE : CTRLB_WINMODESelect := SAM_SVD.ADC.DISABLE;
-- Window Single Sample
WINSS : Boolean := False;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 16,
Bit_Order => System.Low_Order_First;
for ADC_CTRLB_Register use record
LEFTADJ at 0 range 0 .. 0;
FREERUN at 0 range 1 .. 1;
CORREN at 0 range 2 .. 2;
RESSEL at 0 range 3 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
WINMODE at 0 range 8 .. 10;
WINSS at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
end record;
-- Reference Selection
type REFCTRL_REFSELSelect is
(-- Internal Bandgap Reference
INTREF,
-- 1/2 VDDANA
INTVCC0,
-- VDDANA
INTVCC1,
-- External Reference
AREFA,
-- External Reference
AREFB,
-- External Reference (only on ADC1)
AREFC)
with Size => 4;
for REFCTRL_REFSELSelect use
(INTREF => 0,
INTVCC0 => 2,
INTVCC1 => 3,
AREFA => 4,
AREFB => 5,
AREFC => 6);
-- Reference Control
type ADC_REFCTRL_Register is record
-- Reference Selection
REFSEL : REFCTRL_REFSELSelect := SAM_SVD.ADC.INTREF;
-- unspecified
Reserved_4_6 : HAL.UInt3 := 16#0#;
-- Reference Buffer Offset Compensation Enable
REFCOMP : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for ADC_REFCTRL_Register use record
REFSEL at 0 range 0 .. 3;
Reserved_4_6 at 0 range 4 .. 6;
REFCOMP at 0 range 7 .. 7;
end record;
-- Number of Samples to be Collected
type AVGCTRL_SAMPLENUMSelect is
(-- 1 sample
Val_1,
-- 2 samples
Val_2,
-- 4 samples
Val_4,
-- 8 samples
Val_8,
-- 16 samples
Val_16,
-- 32 samples
Val_32,
-- 64 samples
Val_64,
-- 128 samples
Val_128,
-- 256 samples
Val_256,
-- 512 samples
Val_512,
-- 1024 samples
Val_1024)
with Size => 4;
for AVGCTRL_SAMPLENUMSelect use
(Val_1 => 0,
Val_2 => 1,
Val_4 => 2,
Val_8 => 3,
Val_16 => 4,
Val_32 => 5,
Val_64 => 6,
Val_128 => 7,
Val_256 => 8,
Val_512 => 9,
Val_1024 => 10);
subtype ADC_AVGCTRL_ADJRES_Field is HAL.UInt3;
-- Average Control
type ADC_AVGCTRL_Register is record
-- Number of Samples to be Collected
SAMPLENUM : AVGCTRL_SAMPLENUMSelect := SAM_SVD.ADC.Val_1;
-- Adjusting Result / Division Coefficient
ADJRES : ADC_AVGCTRL_ADJRES_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for ADC_AVGCTRL_Register use record
SAMPLENUM at 0 range 0 .. 3;
ADJRES at 0 range 4 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
end record;
subtype ADC_SAMPCTRL_SAMPLEN_Field is HAL.UInt6;
-- Sample Time Control
type ADC_SAMPCTRL_Register is record
-- Sampling Time Length
SAMPLEN : ADC_SAMPCTRL_SAMPLEN_Field := 16#0#;
-- unspecified
Reserved_6_6 : HAL.Bit := 16#0#;
-- Comparator Offset Compensation Enable
OFFCOMP : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for ADC_SAMPCTRL_Register use record
SAMPLEN at 0 range 0 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
OFFCOMP at 0 range 7 .. 7;
end record;
subtype ADC_GAINCORR_GAINCORR_Field is HAL.UInt12;
-- Gain Correction
type ADC_GAINCORR_Register is record
-- Gain Correction Value
GAINCORR : ADC_GAINCORR_GAINCORR_Field := 16#0#;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 16,
Bit_Order => System.Low_Order_First;
for ADC_GAINCORR_Register use record
GAINCORR at 0 range 0 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
end record;
subtype ADC_OFFSETCORR_OFFSETCORR_Field is HAL.UInt12;
-- Offset Correction
type ADC_OFFSETCORR_Register is record
-- Offset Correction Value
OFFSETCORR : ADC_OFFSETCORR_OFFSETCORR_Field := 16#0#;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 16,
Bit_Order => System.Low_Order_First;
for ADC_OFFSETCORR_Register use record
OFFSETCORR at 0 range 0 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
end record;
-- Software Trigger
type ADC_SWTRIG_Register is record
-- ADC Conversion Flush
FLUSH : Boolean := False;
-- Start ADC Conversion
START : Boolean := False;
-- unspecified
Reserved_2_7 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for ADC_SWTRIG_Register use record
FLUSH at 0 range 0 .. 0;
START at 0 range 1 .. 1;
Reserved_2_7 at 0 range 2 .. 7;
end record;
-- Interrupt Enable Clear
type ADC_INTENCLR_Register is record
-- Result Ready Interrupt Disable
RESRDY : Boolean := False;
-- Overrun Interrupt Disable
OVERRUN : Boolean := False;
-- Window Monitor Interrupt Disable
WINMON : Boolean := False;
-- unspecified
Reserved_3_7 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for ADC_INTENCLR_Register use record
RESRDY at 0 range 0 .. 0;
OVERRUN at 0 range 1 .. 1;
WINMON at 0 range 2 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
end record;
-- Interrupt Enable Set
type ADC_INTENSET_Register is record
-- Result Ready Interrupt Enable
RESRDY : Boolean := False;
-- Overrun Interrupt Enable
OVERRUN : Boolean := False;
-- Window Monitor Interrupt Enable
WINMON : Boolean := False;
-- unspecified
Reserved_3_7 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for ADC_INTENSET_Register use record
RESRDY at 0 range 0 .. 0;
OVERRUN at 0 range 1 .. 1;
WINMON at 0 range 2 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
end record;
-- Interrupt Flag Status and Clear
type ADC_INTFLAG_Register is record
-- Result Ready Interrupt Flag
RESRDY : Boolean := False;
-- Overrun Interrupt Flag
OVERRUN : Boolean := False;
-- Window Monitor Interrupt Flag
WINMON : Boolean := False;
-- unspecified
Reserved_3_7 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for ADC_INTFLAG_Register use record
RESRDY at 0 range 0 .. 0;
OVERRUN at 0 range 1 .. 1;
WINMON at 0 range 2 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
end record;
subtype ADC_STATUS_WCC_Field is HAL.UInt6;
-- Status
type ADC_STATUS_Register is record
-- Read-only. ADC Busy Status
ADCBUSY : Boolean;
-- unspecified
Reserved_1_1 : HAL.Bit;
-- Read-only. Window Comparator Counter
WCC : ADC_STATUS_WCC_Field;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for ADC_STATUS_Register use record
ADCBUSY at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
WCC at 0 range 2 .. 7;
end record;
-- Synchronization Busy
type ADC_SYNCBUSY_Register is record
-- Read-only. SWRST Synchronization Busy
SWRST : Boolean;
-- Read-only. ENABLE Synchronization Busy
ENABLE : Boolean;
-- Read-only. Input Control Synchronization Busy
INPUTCTRL : Boolean;
-- Read-only. Control B Synchronization Busy
CTRLB : Boolean;
-- Read-only. Reference Control Synchronization Busy
REFCTRL : Boolean;
-- Read-only. Average Control Synchronization Busy
AVGCTRL : Boolean;
-- Read-only. Sampling Time Control Synchronization Busy
SAMPCTRL : Boolean;
-- Read-only. Window Monitor Lower Threshold Synchronization Busy
WINLT : Boolean;
-- Read-only. Window Monitor Upper Threshold Synchronization Busy
WINUT : Boolean;
-- Read-only. Gain Correction Synchronization Busy
GAINCORR : Boolean;
-- Read-only. Offset Correction Synchronization Busy
OFFSETCORR : Boolean;
-- Read-only. Software Trigger Synchronization Busy
SWTRIG : Boolean;
-- unspecified
Reserved_12_31 : HAL.UInt20;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_SYNCBUSY_Register use record
SWRST at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
INPUTCTRL at 0 range 2 .. 2;
CTRLB at 0 range 3 .. 3;
REFCTRL at 0 range 4 .. 4;
AVGCTRL at 0 range 5 .. 5;
SAMPCTRL at 0 range 6 .. 6;
WINLT at 0 range 7 .. 7;
WINUT at 0 range 8 .. 8;
GAINCORR at 0 range 9 .. 9;
OFFSETCORR at 0 range 10 .. 10;
SWTRIG at 0 range 11 .. 11;
Reserved_12_31 at 0 range 12 .. 31;
end record;
-- DMA Sequential Control
type ADC_DSEQCTRL_Register is record
-- Input Control
INPUTCTRL : Boolean := False;
-- Control B
CTRLB : Boolean := False;
-- Reference Control
REFCTRL : Boolean := False;
-- Average Control
AVGCTRL : Boolean := False;
-- Sampling Time Control
SAMPCTRL : Boolean := False;
-- Window Monitor Lower Threshold
WINLT : Boolean := False;
-- Window Monitor Upper Threshold
WINUT : Boolean := False;
-- Gain Correction
GAINCORR : Boolean := False;
-- Offset Correction
OFFSETCORR : Boolean := False;
-- unspecified
Reserved_9_30 : HAL.UInt22 := 16#0#;
-- ADC Auto-Start Conversion
AUTOSTART : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_DSEQCTRL_Register use record
INPUTCTRL at 0 range 0 .. 0;
CTRLB at 0 range 1 .. 1;
REFCTRL at 0 range 2 .. 2;
AVGCTRL at 0 range 3 .. 3;
SAMPCTRL at 0 range 4 .. 4;
WINLT at 0 range 5 .. 5;
WINUT at 0 range 6 .. 6;
GAINCORR at 0 range 7 .. 7;
OFFSETCORR at 0 range 8 .. 8;
Reserved_9_30 at 0 range 9 .. 30;
AUTOSTART at 0 range 31 .. 31;
end record;
-- DMA Sequencial Status
type ADC_DSEQSTAT_Register is record
-- Read-only. Input Control
INPUTCTRL : Boolean;
-- Read-only. Control B
CTRLB : Boolean;
-- Read-only. Reference Control
REFCTRL : Boolean;
-- Read-only. Average Control
AVGCTRL : Boolean;
-- Read-only. Sampling Time Control
SAMPCTRL : Boolean;
-- Read-only. Window Monitor Lower Threshold
WINLT : Boolean;
-- Read-only. Window Monitor Upper Threshold
WINUT : Boolean;
-- Read-only. Gain Correction
GAINCORR : Boolean;
-- Read-only. Offset Correction
OFFSETCORR : Boolean;
-- unspecified
Reserved_9_30 : HAL.UInt22;
-- Read-only. DMA Sequencing Busy
BUSY : Boolean;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_DSEQSTAT_Register use record
INPUTCTRL at 0 range 0 .. 0;
CTRLB at 0 range 1 .. 1;
REFCTRL at 0 range 2 .. 2;
AVGCTRL at 0 range 3 .. 3;
SAMPCTRL at 0 range 4 .. 4;
WINLT at 0 range 5 .. 5;
WINUT at 0 range 6 .. 6;
GAINCORR at 0 range 7 .. 7;
OFFSETCORR at 0 range 8 .. 8;
Reserved_9_30 at 0 range 9 .. 30;
BUSY at 0 range 31 .. 31;
end record;
subtype ADC_CALIB_BIASCOMP_Field is HAL.UInt3;
subtype ADC_CALIB_BIASR2R_Field is HAL.UInt3;
subtype ADC_CALIB_BIASREFBUF_Field is HAL.UInt3;
-- Calibration
type ADC_CALIB_Register is record
-- Bias Comparator Scaling
BIASCOMP : ADC_CALIB_BIASCOMP_Field := 16#0#;
-- unspecified
Reserved_3_3 : HAL.Bit := 16#0#;
-- Bias R2R Ampli scaling
BIASR2R : ADC_CALIB_BIASR2R_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Bias Reference Buffer Scaling
BIASREFBUF : ADC_CALIB_BIASREFBUF_Field := 16#0#;
-- unspecified
Reserved_11_15 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 16,
Bit_Order => System.Low_Order_First;
for ADC_CALIB_Register use record
BIASCOMP at 0 range 0 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
BIASR2R at 0 range 4 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
BIASREFBUF at 0 range 8 .. 10;
Reserved_11_15 at 0 range 11 .. 15;
end record;
-----------------
-- Peripherals --
-----------------
-- Analog Digital Converter
type ADC_Peripheral is record
-- Control A
CTRLA : aliased ADC_CTRLA_Register;
-- Event Control
EVCTRL : aliased ADC_EVCTRL_Register;
-- Debug Control
DBGCTRL : aliased ADC_DBGCTRL_Register;
-- Input Control
INPUTCTRL : aliased ADC_INPUTCTRL_Register;
-- Control B
CTRLB : aliased ADC_CTRLB_Register;
-- Reference Control
REFCTRL : aliased ADC_REFCTRL_Register;
-- Average Control
AVGCTRL : aliased ADC_AVGCTRL_Register;
-- Sample Time Control
SAMPCTRL : aliased ADC_SAMPCTRL_Register;
-- Window Monitor Lower Threshold
WINLT : aliased HAL.UInt16;
-- Window Monitor Upper Threshold
WINUT : aliased HAL.UInt16;
-- Gain Correction
GAINCORR : aliased ADC_GAINCORR_Register;
-- Offset Correction
OFFSETCORR : aliased ADC_OFFSETCORR_Register;
-- Software Trigger
SWTRIG : aliased ADC_SWTRIG_Register;
-- Interrupt Enable Clear
INTENCLR : aliased ADC_INTENCLR_Register;
-- Interrupt Enable Set
INTENSET : aliased ADC_INTENSET_Register;
-- Interrupt Flag Status and Clear
INTFLAG : aliased ADC_INTFLAG_Register;
-- Status
STATUS : aliased ADC_STATUS_Register;
-- Synchronization Busy
SYNCBUSY : aliased ADC_SYNCBUSY_Register;
-- DMA Sequencial Data
DSEQDATA : aliased HAL.UInt32;
-- DMA Sequential Control
DSEQCTRL : aliased ADC_DSEQCTRL_Register;
-- DMA Sequencial Status
DSEQSTAT : aliased ADC_DSEQSTAT_Register;
-- Result Conversion Value
RESULT : aliased HAL.UInt16;
-- Last Sample Result
RESS : aliased HAL.UInt16;
-- Calibration
CALIB : aliased ADC_CALIB_Register;
end record
with Volatile;
for ADC_Peripheral use record
CTRLA at 16#0# range 0 .. 15;
EVCTRL at 16#2# range 0 .. 7;
DBGCTRL at 16#3# range 0 .. 7;
INPUTCTRL at 16#4# range 0 .. 15;
CTRLB at 16#6# range 0 .. 15;
REFCTRL at 16#8# range 0 .. 7;
AVGCTRL at 16#A# range 0 .. 7;
SAMPCTRL at 16#B# range 0 .. 7;
WINLT at 16#C# range 0 .. 15;
WINUT at 16#E# range 0 .. 15;
GAINCORR at 16#10# range 0 .. 15;
OFFSETCORR at 16#12# range 0 .. 15;
SWTRIG at 16#14# range 0 .. 7;
INTENCLR at 16#2C# range 0 .. 7;
INTENSET at 16#2D# range 0 .. 7;
INTFLAG at 16#2E# range 0 .. 7;
STATUS at 16#2F# range 0 .. 7;
SYNCBUSY at 16#30# range 0 .. 31;
DSEQDATA at 16#34# range 0 .. 31;
DSEQCTRL at 16#38# range 0 .. 31;
DSEQSTAT at 16#3C# range 0 .. 31;
RESULT at 16#40# range 0 .. 15;
RESS at 16#44# range 0 .. 15;
CALIB at 16#48# range 0 .. 15;
end record;
-- Analog Digital Converter
ADC0_Periph : aliased ADC_Peripheral
with Import, Address => ADC0_Base;
-- Analog Digital Converter
ADC1_Periph : aliased ADC_Peripheral
with Import, Address => ADC1_Base;
end SAM_SVD.ADC;
|
-- This spec has been automatically generated from FE310.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package FE310_SVD.CLINT is
pragma Preelaborate;
---------------
-- Registers --
---------------
-----------------
-- Peripherals --
-----------------
-- Core Local Interruptor.
type CLINT_Peripheral is record
-- Machine Software Interrupt Pending Register.
MSIP : aliased HAL.UInt32;
-- Machine Timer Compare Register Low.
MTIMECMP_LO : aliased HAL.UInt32;
-- Machine Timer Compare Register High.
MTIMECMP_HI : aliased HAL.UInt32;
-- Machine Timer Register Low.
MTIME_LO : aliased HAL.UInt32;
-- Machine Timer Register High.
MTIME_HI : aliased HAL.UInt32;
end record
with Volatile;
for CLINT_Peripheral use record
MSIP at 16#0# range 0 .. 31;
MTIMECMP_LO at 16#4000# range 0 .. 31;
MTIMECMP_HI at 16#4004# range 0 .. 31;
MTIME_LO at 16#BFF8# range 0 .. 31;
MTIME_HI at 16#BFFC# range 0 .. 31;
end record;
-- Core Local Interruptor.
CLINT_Periph : aliased CLINT_Peripheral
with Import, Address => System'To_Address (16#2000000#);
end FE310_SVD.CLINT;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.