CombinedText stringlengths 4 3.42M |
|---|
pragma Ada_2005;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Interfaces.C; use Interfaces.C;
with glib;
with glib.Values;
with System;
with System;
-- limited with GStreamer.GST_Low_Level.glib_2_0_glib_gpoll_h;
with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h;
package GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpoll_h is
-- unsupported macro: GST_POLL_FD_INIT { -1, -1 }
-- GStreamer
-- * Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
-- * Copyright (C) 2004 Wim Taymans <wim.taymans@gmail.com>
-- * Copyright (C) 2007 Peter Kjellerstedt <pkj@axis.com>
-- *
-- * gstpoll.h: File descriptor set
-- *
-- * This library is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU Library General Public
-- * License as published by the Free Software Foundation; either
-- * version 2 of the License, or (at your option) any later version.
-- *
-- * This library is distributed in the hope that it will be useful,
-- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- * Library General Public License for more details.
-- *
-- * You should have received a copy of the GNU Library General Public
-- * License along with this library; if not, write to the
-- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- * Boston, MA 02111-1307, USA.
--
--*
-- * GstPoll:
-- *
-- * A set of file/network descriptors.
--
-- skipped empty struct u_GstPoll
-- skipped empty struct GstPoll
--*
-- * GstPollFD:
-- * @fd: a file descriptor
-- *
-- * A file descriptor object.
--
type GstPollFD is record
fd : aliased int; -- gst/gstpoll.h:48
idx : aliased GLIB.gint; -- gst/gstpoll.h:51
end record;
pragma Convention (C_Pass_By_Copy, GstPollFD); -- gst/gstpoll.h:52
-- skipped anonymous struct anon_243
--< private >
--*
-- * GST_POLL_FD_INIT:
-- *
-- * A #GstPollFD must be initialized with this macro, before it can be
-- * used. This macro can used be to initialize a variable, but it cannot
-- * be assigned to a variable. In that case you have to use
-- * gst_poll_fd_init().
-- *
-- * Since: 0.10.18
--
function gst_poll_new (controllable : GLIB.gboolean) return System.Address; -- gst/gstpoll.h:66
pragma Import (C, gst_poll_new, "gst_poll_new");
function gst_poll_new_timer return System.Address; -- gst/gstpoll.h:67
pragma Import (C, gst_poll_new_timer, "gst_poll_new_timer");
procedure gst_poll_free (set : System.Address); -- gst/gstpoll.h:68
pragma Import (C, gst_poll_free, "gst_poll_free");
procedure gst_poll_get_read_gpollfd (set : System.Address; fd : access GStreamer.GST_Low_Level.glib_2_0_glib_gpoll_h.GPollFD); -- gst/gstpoll.h:70
pragma Import (C, gst_poll_get_read_gpollfd, "gst_poll_get_read_gpollfd");
procedure gst_poll_fd_init (fd : access GstPollFD); -- gst/gstpoll.h:72
pragma Import (C, gst_poll_fd_init, "gst_poll_fd_init");
function gst_poll_add_fd (set : System.Address; fd : access GstPollFD) return GLIB.gboolean; -- gst/gstpoll.h:74
pragma Import (C, gst_poll_add_fd, "gst_poll_add_fd");
function gst_poll_remove_fd (set : System.Address; fd : access GstPollFD) return GLIB.gboolean; -- gst/gstpoll.h:75
pragma Import (C, gst_poll_remove_fd, "gst_poll_remove_fd");
function gst_poll_fd_ctl_write
(set : System.Address;
fd : access GstPollFD;
active : GLIB.gboolean) return GLIB.gboolean; -- gst/gstpoll.h:77
pragma Import (C, gst_poll_fd_ctl_write, "gst_poll_fd_ctl_write");
function gst_poll_fd_ctl_read
(set : System.Address;
fd : access GstPollFD;
active : GLIB.gboolean) return GLIB.gboolean; -- gst/gstpoll.h:78
pragma Import (C, gst_poll_fd_ctl_read, "gst_poll_fd_ctl_read");
procedure gst_poll_fd_ignored (set : System.Address; fd : access GstPollFD); -- gst/gstpoll.h:79
pragma Import (C, gst_poll_fd_ignored, "gst_poll_fd_ignored");
function gst_poll_fd_has_closed (set : System.Address; fd : access GstPollFD) return GLIB.gboolean; -- gst/gstpoll.h:81
pragma Import (C, gst_poll_fd_has_closed, "gst_poll_fd_has_closed");
function gst_poll_fd_has_error (set : System.Address; fd : access GstPollFD) return GLIB.gboolean; -- gst/gstpoll.h:82
pragma Import (C, gst_poll_fd_has_error, "gst_poll_fd_has_error");
function gst_poll_fd_can_read (set : System.Address; fd : access GstPollFD) return GLIB.gboolean; -- gst/gstpoll.h:83
pragma Import (C, gst_poll_fd_can_read, "gst_poll_fd_can_read");
function gst_poll_fd_can_write (set : System.Address; fd : access GstPollFD) return GLIB.gboolean; -- gst/gstpoll.h:84
pragma Import (C, gst_poll_fd_can_write, "gst_poll_fd_can_write");
function gst_poll_wait (set : System.Address; timeout : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime) return GLIB.gint; -- gst/gstpoll.h:86
pragma Import (C, gst_poll_wait, "gst_poll_wait");
function gst_poll_set_controllable (set : System.Address; controllable : GLIB.gboolean) return GLIB.gboolean; -- gst/gstpoll.h:88
pragma Import (C, gst_poll_set_controllable, "gst_poll_set_controllable");
procedure gst_poll_restart (set : System.Address); -- gst/gstpoll.h:89
pragma Import (C, gst_poll_restart, "gst_poll_restart");
procedure gst_poll_set_flushing (set : System.Address; flushing : GLIB.gboolean); -- gst/gstpoll.h:90
pragma Import (C, gst_poll_set_flushing, "gst_poll_set_flushing");
function gst_poll_write_control (set : System.Address) return GLIB.gboolean; -- gst/gstpoll.h:92
pragma Import (C, gst_poll_write_control, "gst_poll_write_control");
function gst_poll_read_control (set : System.Address) return GLIB.gboolean; -- gst/gstpoll.h:93
pragma Import (C, gst_poll_read_control, "gst_poll_read_control");
end GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpoll_h;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E X P _ C H 6 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Aspects; use Aspects;
with Checks; use Checks;
with Contracts; use Contracts;
with Debug; use Debug;
with Einfo; use Einfo;
with Errout; use Errout;
with Elists; use Elists;
with Expander; use Expander;
with Exp_Aggr; use Exp_Aggr;
with Exp_Atag; use Exp_Atag;
with Exp_Ch2; use Exp_Ch2;
with Exp_Ch3; use Exp_Ch3;
with Exp_Ch7; use Exp_Ch7;
with Exp_Ch9; use Exp_Ch9;
with Exp_Dbug; use Exp_Dbug;
with Exp_Disp; use Exp_Disp;
with Exp_Dist; use Exp_Dist;
with Exp_Intr; use Exp_Intr;
with Exp_Pakd; use Exp_Pakd;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Freeze; use Freeze;
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 Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch13; use Sem_Ch13;
with Sem_Dim; use Sem_Dim;
with Sem_Disp; use Sem_Disp;
with Sem_Dist; use Sem_Dist;
with Sem_Eval; use Sem_Eval;
with Sem_Mech; use Sem_Mech;
with Sem_Res; use Sem_Res;
with Sem_SCIL; use Sem_SCIL;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Stand; use Stand;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
with Validsw; use Validsw;
package body Exp_Ch6 is
-- Suffix for BIP formals
BIP_Alloc_Suffix : constant String := "BIPalloc";
BIP_Storage_Pool_Suffix : constant String := "BIPstoragepool";
BIP_Finalization_Master_Suffix : constant String := "BIPfinalizationmaster";
BIP_Task_Master_Suffix : constant String := "BIPtaskmaster";
BIP_Activation_Chain_Suffix : constant String := "BIPactivationchain";
BIP_Object_Access_Suffix : constant String := "BIPaccess";
-----------------------
-- Local Subprograms --
-----------------------
procedure Add_Access_Actual_To_Build_In_Place_Call
(Function_Call : Node_Id;
Function_Id : Entity_Id;
Return_Object : Node_Id;
Is_Access : Boolean := False);
-- Ada 2005 (AI-318-02): Apply the Unrestricted_Access attribute to the
-- object name given by Return_Object and add the attribute to the end of
-- the actual parameter list associated with the build-in-place function
-- call denoted by Function_Call. However, if Is_Access is True, then
-- Return_Object is already an access expression, in which case it's passed
-- along directly to the build-in-place function. Finally, if Return_Object
-- is empty, then pass a null literal as the actual.
procedure Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Function_Call : Node_Id;
Function_Id : Entity_Id;
Alloc_Form : BIP_Allocation_Form := Unspecified;
Alloc_Form_Exp : Node_Id := Empty;
Pool_Actual : Node_Id := Make_Null (No_Location));
-- Ada 2005 (AI-318-02): Add the actuals needed for a build-in-place
-- function call that returns a caller-unknown-size result (BIP_Alloc_Form
-- and BIP_Storage_Pool). If Alloc_Form_Exp is present, then use it,
-- otherwise pass a literal corresponding to the Alloc_Form parameter
-- (which must not be Unspecified in that case). Pool_Actual is the
-- parameter to pass to BIP_Storage_Pool.
procedure Add_Finalization_Master_Actual_To_Build_In_Place_Call
(Func_Call : Node_Id;
Func_Id : Entity_Id;
Ptr_Typ : Entity_Id := Empty;
Master_Exp : Node_Id := Empty);
-- Ada 2005 (AI-318-02): If the result type of a build-in-place call needs
-- finalization actions, add an actual parameter which is a pointer to the
-- finalization master of the caller. If Master_Exp is not Empty, then that
-- will be passed as the actual. Otherwise, if Ptr_Typ is left Empty, this
-- will result in an automatic "null" value for the actual.
procedure Add_Task_Actuals_To_Build_In_Place_Call
(Function_Call : Node_Id;
Function_Id : Entity_Id;
Master_Actual : Node_Id;
Chain : Node_Id := Empty);
-- Ada 2005 (AI-318-02): For a build-in-place call, if the result type
-- contains tasks, add two actual parameters: the master, and a pointer to
-- the caller's activation chain. Master_Actual is the actual parameter
-- expression to pass for the master. In most cases, this is the current
-- master (_master). The two exceptions are: If the function call is the
-- initialization expression for an allocator, we pass the master of the
-- access type. If the function call is the initialization expression for a
-- return object, we pass along the master passed in by the caller. In most
-- contexts, the activation chain to pass is the local one, which is
-- indicated by No (Chain). However, in an allocator, the caller passes in
-- the activation Chain. Note: Master_Actual can be Empty, but only if
-- there are no tasks.
procedure Apply_CW_Accessibility_Check (Exp : Node_Id; Func : Entity_Id);
-- Ada 2005 (AI95-344): If the result type is class-wide, insert a check
-- that the level of the return expression's underlying type is not deeper
-- than the level of the master enclosing the function. Always generate the
-- check when the type of the return expression is class-wide, when it's a
-- type conversion, or when it's a formal parameter. Otherwise suppress the
-- check in the case where the return expression has a specific type whose
-- level is known not to be statically deeper than the result type of the
-- function.
function Caller_Known_Size
(Func_Call : Node_Id;
Result_Subt : Entity_Id) return Boolean;
-- True if result subtype is definite, or has a size that does not require
-- secondary stack usage (i.e. no variant part or components whose type
-- depends on discriminants). In particular, untagged types with only
-- access discriminants do not require secondary stack use. Note we must
-- always use the secondary stack for dispatching-on-result calls.
function Check_BIP_Actuals
(Subp_Call : Node_Id;
Subp_Id : Entity_Id) return Boolean;
-- Given a subprogram call to the given subprogram return True if the
-- names of BIP extra actual and formal parameters match.
function Check_Number_Of_Actuals
(Subp_Call : Node_Id;
Subp_Id : Entity_Id) return Boolean;
-- Given a subprogram call to the given subprogram return True if the
-- number of actual parameters (including extra actuals) is correct.
procedure Check_Overriding_Operation (Subp : Entity_Id);
-- Subp is a dispatching operation. Check whether it may override an
-- inherited private operation, in which case its DT entry is that of
-- the hidden operation, not the one it may have received earlier.
-- This must be done before emitting the code to set the corresponding
-- DT to the address of the subprogram. The actual placement of Subp in
-- the proper place in the list of primitive operations is done in
-- Declare_Inherited_Private_Subprograms, which also has to deal with
-- implicit operations. This duplication is unavoidable for now???
procedure Detect_Infinite_Recursion (N : Node_Id; Spec : Entity_Id);
-- This procedure is called only if the subprogram body N, whose spec
-- has the given entity Spec, contains a parameterless recursive call.
-- It attempts to generate runtime code to detect if this a case of
-- infinite recursion.
--
-- The body is scanned to determine dependencies. If the only external
-- dependencies are on a small set of scalar variables, then the values
-- of these variables are captured on entry to the subprogram, and if
-- the values are not changed for the call, we know immediately that
-- we have an infinite recursion.
procedure Expand_Actuals
(N : Node_Id;
Subp : Entity_Id;
Post_Call : out List_Id);
-- Return a list of actions to take place after the call in Post_Call. The
-- call will later be rewritten as an Expression_With_Actions, with the
-- Post_Call actions inserted, and the call inside.
--
-- For each actual of an in-out or out parameter which is a numeric (view)
-- conversion of the form T (A), where A denotes a variable, we insert the
-- declaration:
--
-- Temp : T[ := T (A)];
--
-- prior to the call. Then we replace the actual with a reference to Temp,
-- and append the assignment:
--
-- A := TypeA (Temp);
--
-- after the call. Here TypeA is the actual type of variable A. For out
-- parameters, the initial declaration has no expression. If A is not an
-- entity name, we generate instead:
--
-- Var : TypeA renames A;
-- Temp : T := Var; -- omitting expression for out parameter.
-- ...
-- Var := TypeA (Temp);
--
-- For other in-out parameters, we emit the required constraint checks
-- before and/or after the call.
--
-- For all parameter modes, actuals that denote components and slices of
-- packed arrays are expanded into suitable temporaries.
--
-- For nonscalar objects that are possibly unaligned, add call by copy code
-- (copy in for IN and IN OUT, copy out for OUT and IN OUT).
--
-- For OUT and IN OUT parameters, add predicate checks after the call
-- based on the predicates of the actual type.
procedure Expand_Call_Helper (N : Node_Id; Post_Call : out List_Id);
-- Does the main work of Expand_Call. Post_Call is as for Expand_Actuals.
procedure Expand_Ctrl_Function_Call (N : Node_Id);
-- N is a function call which returns a controlled object. Transform the
-- call into a temporary which retrieves the returned object from the
-- secondary stack using 'reference.
procedure Expand_Non_Function_Return (N : Node_Id);
-- Expand a simple return statement found in a procedure body, entry body,
-- accept statement, or an extended return statement. Note that all non-
-- function returns are simple return statements.
function Expand_Protected_Object_Reference
(N : Node_Id;
Scop : Entity_Id) return Node_Id;
procedure Expand_Protected_Subprogram_Call
(N : Node_Id;
Subp : Entity_Id;
Scop : Entity_Id);
-- A call to a protected subprogram within the protected object may appear
-- as a regular call. The list of actuals must be expanded to contain a
-- reference to the object itself, and the call becomes a call to the
-- corresponding protected subprogram.
procedure Expand_Simple_Function_Return (N : Node_Id);
-- Expand simple return from function. In the case where we are returning
-- from a function body this is called by Expand_N_Simple_Return_Statement.
function Has_BIP_Extra_Formal
(E : Entity_Id;
Kind : BIP_Formal_Kind) return Boolean;
-- Given a frozen subprogram, subprogram type, entry or entry family,
-- return True if E has the BIP extra formal associated with Kind. It must
-- be invoked with a frozen entity or a subprogram type of a dispatching
-- call since we can only rely on the availability of the extra formals
-- on these entities.
procedure Insert_Post_Call_Actions (N : Node_Id; Post_Call : List_Id);
-- Insert the Post_Call list previously produced by routine Expand_Actuals
-- or Expand_Call_Helper into the tree.
procedure Replace_Renaming_Declaration_Id
(New_Decl : Node_Id;
Orig_Decl : Node_Id);
-- Replace the internal identifier of the new renaming declaration New_Decl
-- with the identifier of its original declaration Orig_Decl exchanging the
-- entities containing their defining identifiers to ensure the correct
-- replacement of the object declaration by the object renaming declaration
-- to avoid homograph conflicts (since the object declaration's defining
-- identifier was already entered in the current scope). The Next_Entity
-- links of the two entities are also swapped since the entities are part
-- of the return scope's entity list and the list structure would otherwise
-- be corrupted. The homonym chain is preserved as well.
procedure Rewrite_Function_Call_For_C (N : Node_Id);
-- When generating C code, replace a call to a function that returns an
-- array into the generated procedure with an additional out parameter.
procedure Set_Enclosing_Sec_Stack_Return (N : Node_Id);
-- N is a return statement for a function that returns its result on the
-- secondary stack. This sets the Sec_Stack_Needed_For_Return flag on the
-- function and all blocks and loops that the return statement is jumping
-- out of. This ensures that the secondary stack is not released; otherwise
-- the function result would be reclaimed before returning to the caller.
procedure Warn_BIP (Func_Call : Node_Id);
-- Give a warning on a build-in-place function call if the -gnatd_B switch
-- was given.
----------------------------------------------
-- Add_Access_Actual_To_Build_In_Place_Call --
----------------------------------------------
procedure Add_Access_Actual_To_Build_In_Place_Call
(Function_Call : Node_Id;
Function_Id : Entity_Id;
Return_Object : Node_Id;
Is_Access : Boolean := False)
is
Loc : constant Source_Ptr := Sloc (Function_Call);
Obj_Address : Node_Id;
Obj_Acc_Formal : Entity_Id;
begin
-- Locate the implicit access parameter in the called function
Obj_Acc_Formal := Build_In_Place_Formal (Function_Id, BIP_Object_Access);
-- If no return object is provided, then pass null
if not Present (Return_Object) then
Obj_Address := Make_Null (Loc);
Set_Parent (Obj_Address, Function_Call);
-- If Return_Object is already an expression of an access type, then use
-- it directly, since it must be an access value denoting the return
-- object, and couldn't possibly be the return object itself.
elsif Is_Access then
Obj_Address := Return_Object;
Set_Parent (Obj_Address, Function_Call);
-- Apply Unrestricted_Access to caller's return object
else
Obj_Address :=
Make_Attribute_Reference (Loc,
Prefix => Return_Object,
Attribute_Name => Name_Unrestricted_Access);
Set_Parent (Return_Object, Obj_Address);
Set_Parent (Obj_Address, Function_Call);
end if;
Analyze_And_Resolve (Obj_Address, Etype (Obj_Acc_Formal));
-- Build the parameter association for the new actual and add it to the
-- end of the function's actuals.
Add_Extra_Actual_To_Call (Function_Call, Obj_Acc_Formal, Obj_Address);
end Add_Access_Actual_To_Build_In_Place_Call;
------------------------------------------------------
-- Add_Unconstrained_Actuals_To_Build_In_Place_Call --
------------------------------------------------------
procedure Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Function_Call : Node_Id;
Function_Id : Entity_Id;
Alloc_Form : BIP_Allocation_Form := Unspecified;
Alloc_Form_Exp : Node_Id := Empty;
Pool_Actual : Node_Id := Make_Null (No_Location))
is
Loc : constant Source_Ptr := Sloc (Function_Call);
Alloc_Form_Actual : Node_Id;
Alloc_Form_Formal : Node_Id;
Pool_Formal : Node_Id;
begin
-- Nothing to do when the size of the object is known, and the caller is
-- in charge of allocating it, and the callee doesn't unconditionally
-- require an allocation form (such as due to having a tagged result).
if not Needs_BIP_Alloc_Form (Function_Id) then
return;
end if;
-- Locate the implicit allocation form parameter in the called function.
-- Maybe it would be better for each implicit formal of a build-in-place
-- function to have a flag or a Uint attribute to identify it. ???
Alloc_Form_Formal := Build_In_Place_Formal (Function_Id, BIP_Alloc_Form);
if Present (Alloc_Form_Exp) then
pragma Assert (Alloc_Form = Unspecified);
Alloc_Form_Actual := Alloc_Form_Exp;
else
pragma Assert (Alloc_Form /= Unspecified);
Alloc_Form_Actual :=
Make_Integer_Literal (Loc,
Intval => UI_From_Int (BIP_Allocation_Form'Pos (Alloc_Form)));
end if;
Analyze_And_Resolve (Alloc_Form_Actual, Etype (Alloc_Form_Formal));
-- Build the parameter association for the new actual and add it to the
-- end of the function's actuals.
Add_Extra_Actual_To_Call
(Function_Call, Alloc_Form_Formal, Alloc_Form_Actual);
-- Pass the Storage_Pool parameter. This parameter is omitted on ZFP as
-- those targets do not support pools.
if RTE_Available (RE_Root_Storage_Pool_Ptr) then
Pool_Formal := Build_In_Place_Formal (Function_Id, BIP_Storage_Pool);
Analyze_And_Resolve (Pool_Actual, Etype (Pool_Formal));
Add_Extra_Actual_To_Call
(Function_Call, Pool_Formal, Pool_Actual);
end if;
end Add_Unconstrained_Actuals_To_Build_In_Place_Call;
-----------------------------------------------------------
-- Add_Finalization_Master_Actual_To_Build_In_Place_Call --
-----------------------------------------------------------
procedure Add_Finalization_Master_Actual_To_Build_In_Place_Call
(Func_Call : Node_Id;
Func_Id : Entity_Id;
Ptr_Typ : Entity_Id := Empty;
Master_Exp : Node_Id := Empty)
is
begin
if not Needs_BIP_Finalization_Master (Func_Id) then
return;
end if;
declare
Formal : constant Entity_Id :=
Build_In_Place_Formal (Func_Id, BIP_Finalization_Master);
Loc : constant Source_Ptr := Sloc (Func_Call);
Actual : Node_Id;
Desig_Typ : Entity_Id;
begin
-- If there is a finalization master actual, such as the implicit
-- finalization master of an enclosing build-in-place function,
-- then this must be added as an extra actual of the call.
if Present (Master_Exp) then
Actual := Master_Exp;
-- Case where the context does not require an actual master
elsif No (Ptr_Typ) then
Actual := Make_Null (Loc);
else
Desig_Typ := Directly_Designated_Type (Ptr_Typ);
-- Check for a library-level access type whose designated type has
-- suppressed finalization or the access type is subject to pragma
-- No_Heap_Finalization. Such an access type lacks a master. Pass
-- a null actual to callee in order to signal a missing master.
if Is_Library_Level_Entity (Ptr_Typ)
and then (Finalize_Storage_Only (Desig_Typ)
or else No_Heap_Finalization (Ptr_Typ))
then
Actual := Make_Null (Loc);
-- Types in need of finalization actions
elsif Needs_Finalization (Desig_Typ) then
-- The general mechanism of creating finalization masters for
-- anonymous access types is disabled by default, otherwise
-- finalization masters will pop all over the place. Such types
-- use context-specific masters.
if Ekind (Ptr_Typ) = E_Anonymous_Access_Type
and then No (Finalization_Master (Ptr_Typ))
then
Build_Anonymous_Master (Ptr_Typ);
end if;
-- Access-to-controlled types should always have a master
pragma Assert (Present (Finalization_Master (Ptr_Typ)));
Actual :=
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Finalization_Master (Ptr_Typ), Loc),
Attribute_Name => Name_Unrestricted_Access);
-- Tagged types
else
Actual := Make_Null (Loc);
end if;
end if;
Analyze_And_Resolve (Actual, Etype (Formal));
-- Build the parameter association for the new actual and add it to
-- the end of the function's actuals.
Add_Extra_Actual_To_Call (Func_Call, Formal, Actual);
end;
end Add_Finalization_Master_Actual_To_Build_In_Place_Call;
------------------------------
-- Add_Extra_Actual_To_Call --
------------------------------
procedure Add_Extra_Actual_To_Call
(Subprogram_Call : Node_Id;
Extra_Formal : Entity_Id;
Extra_Actual : Node_Id)
is
Loc : constant Source_Ptr := Sloc (Subprogram_Call);
Param_Assoc : Node_Id;
begin
Param_Assoc :=
Make_Parameter_Association (Loc,
Selector_Name => New_Occurrence_Of (Extra_Formal, Loc),
Explicit_Actual_Parameter => Extra_Actual);
Set_Parent (Param_Assoc, Subprogram_Call);
Set_Parent (Extra_Actual, Param_Assoc);
if Present (Parameter_Associations (Subprogram_Call)) then
if Nkind (Last (Parameter_Associations (Subprogram_Call))) =
N_Parameter_Association
then
-- Find last named actual, and append
declare
L : Node_Id;
begin
L := First_Actual (Subprogram_Call);
while Present (L) loop
if No (Next_Actual (L)) then
Set_Next_Named_Actual (Parent (L), Extra_Actual);
exit;
end if;
Next_Actual (L);
end loop;
end;
else
Set_First_Named_Actual (Subprogram_Call, Extra_Actual);
end if;
Append (Param_Assoc, To => Parameter_Associations (Subprogram_Call));
else
Set_Parameter_Associations (Subprogram_Call, New_List (Param_Assoc));
Set_First_Named_Actual (Subprogram_Call, Extra_Actual);
end if;
end Add_Extra_Actual_To_Call;
---------------------------------------------
-- Add_Task_Actuals_To_Build_In_Place_Call --
---------------------------------------------
procedure Add_Task_Actuals_To_Build_In_Place_Call
(Function_Call : Node_Id;
Function_Id : Entity_Id;
Master_Actual : Node_Id;
Chain : Node_Id := Empty)
is
Loc : constant Source_Ptr := Sloc (Function_Call);
Actual : Node_Id;
Chain_Actual : Node_Id;
Chain_Formal : Node_Id;
Master_Formal : Node_Id;
begin
-- No such extra parameters are needed if there are no tasks
if not Needs_BIP_Task_Actuals (Function_Id) then
return;
end if;
Actual := Master_Actual;
-- Use a dummy _master actual in case of No_Task_Hierarchy
if Restriction_Active (No_Task_Hierarchy) then
Actual := New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc);
-- In the case where we use the master associated with an access type,
-- the actual is an entity and requires an explicit reference.
elsif Nkind (Actual) = N_Defining_Identifier then
Actual := New_Occurrence_Of (Actual, Loc);
end if;
-- Locate the implicit master parameter in the called function
Master_Formal := Build_In_Place_Formal (Function_Id, BIP_Task_Master);
Analyze_And_Resolve (Actual, Etype (Master_Formal));
-- Build the parameter association for the new actual and add it to the
-- end of the function's actuals.
Add_Extra_Actual_To_Call (Function_Call, Master_Formal, Actual);
-- Locate the implicit activation chain parameter in the called function
Chain_Formal :=
Build_In_Place_Formal (Function_Id, BIP_Activation_Chain);
-- Create the actual which is a pointer to the current activation chain
if No (Chain) then
Chain_Actual :=
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Name_uChain),
Attribute_Name => Name_Unrestricted_Access);
-- Allocator case; make a reference to the Chain passed in by the caller
else
Chain_Actual :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Chain, Loc),
Attribute_Name => Name_Unrestricted_Access);
end if;
Analyze_And_Resolve (Chain_Actual, Etype (Chain_Formal));
-- Build the parameter association for the new actual and add it to the
-- end of the function's actuals.
Add_Extra_Actual_To_Call (Function_Call, Chain_Formal, Chain_Actual);
end Add_Task_Actuals_To_Build_In_Place_Call;
----------------------------------
-- Apply_CW_Accessibility_Check --
----------------------------------
procedure Apply_CW_Accessibility_Check (Exp : Node_Id; Func : Entity_Id) is
Loc : constant Source_Ptr := Sloc (Exp);
begin
if Ada_Version >= Ada_2005
and then Tagged_Type_Expansion
and then not Scope_Suppress.Suppress (Accessibility_Check)
and then
(Is_Class_Wide_Type (Etype (Exp))
or else Nkind (Exp) in
N_Type_Conversion | N_Unchecked_Type_Conversion
or else (Is_Entity_Name (Exp)
and then Is_Formal (Entity (Exp)))
or else Scope_Depth (Enclosing_Dynamic_Scope (Etype (Exp))) >
Scope_Depth (Enclosing_Dynamic_Scope (Func)))
then
declare
Tag_Node : Node_Id;
begin
-- Ada 2005 (AI-251): In class-wide interface objects we displace
-- "this" to reference the base of the object. This is required to
-- get access to the TSD of the object.
if Is_Class_Wide_Type (Etype (Exp))
and then Is_Interface (Etype (Exp))
then
-- If the expression is an explicit dereference then we can
-- directly displace the pointer to reference the base of
-- the object.
if Nkind (Exp) = N_Explicit_Dereference then
Tag_Node :=
Make_Explicit_Dereference (Loc,
Prefix =>
Unchecked_Convert_To (RTE (RE_Tag_Ptr),
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Base_Address), Loc),
Parameter_Associations => New_List (
Unchecked_Convert_To (RTE (RE_Address),
Duplicate_Subexpr (Prefix (Exp)))))));
-- Similar case to the previous one but the expression is a
-- renaming of an explicit dereference.
elsif Nkind (Exp) = N_Identifier
and then Present (Renamed_Object (Entity (Exp)))
and then Nkind (Renamed_Object (Entity (Exp)))
= N_Explicit_Dereference
then
Tag_Node :=
Make_Explicit_Dereference (Loc,
Prefix =>
Unchecked_Convert_To (RTE (RE_Tag_Ptr),
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Base_Address), Loc),
Parameter_Associations => New_List (
Unchecked_Convert_To (RTE (RE_Address),
Duplicate_Subexpr
(Prefix
(Renamed_Object (Entity (Exp)))))))));
-- Common case: obtain the address of the actual object and
-- displace the pointer to reference the base of the object.
else
Tag_Node :=
Make_Explicit_Dereference (Loc,
Prefix =>
Unchecked_Convert_To (RTE (RE_Tag_Ptr),
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Base_Address), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (Exp),
Attribute_Name => Name_Address)))));
end if;
else
Tag_Node :=
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (Exp),
Attribute_Name => Name_Tag);
end if;
-- CodePeer does not do anything useful with
-- Ada.Tags.Type_Specific_Data components.
if not CodePeer_Mode then
Insert_Action (Exp,
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Gt (Loc,
Left_Opnd => Build_Get_Access_Level (Loc, Tag_Node),
Right_Opnd =>
Make_Integer_Literal (Loc,
Scope_Depth (Enclosing_Dynamic_Scope (Func)))),
Reason => PE_Accessibility_Check_Failed));
end if;
end;
end if;
end Apply_CW_Accessibility_Check;
-----------------------
-- BIP_Formal_Suffix --
-----------------------
function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String is
begin
case Kind is
when BIP_Alloc_Form =>
return BIP_Alloc_Suffix;
when BIP_Storage_Pool =>
return BIP_Storage_Pool_Suffix;
when BIP_Finalization_Master =>
return BIP_Finalization_Master_Suffix;
when BIP_Task_Master =>
return BIP_Task_Master_Suffix;
when BIP_Activation_Chain =>
return BIP_Activation_Chain_Suffix;
when BIP_Object_Access =>
return BIP_Object_Access_Suffix;
end case;
end BIP_Formal_Suffix;
---------------------
-- BIP_Suffix_Kind --
---------------------
function BIP_Suffix_Kind (E : Entity_Id) return BIP_Formal_Kind is
Nam : constant String := Get_Name_String (Chars (E));
function Has_Suffix (Suffix : String) return Boolean;
-- Return True if Nam has suffix Suffix
function Has_Suffix (Suffix : String) return Boolean is
Len : constant Natural := Suffix'Length;
begin
return Nam'Length > Len
and then Nam (Nam'Last - Len + 1 .. Nam'Last) = Suffix;
end Has_Suffix;
-- Start of processing for BIP_Suffix_Kind
begin
if Has_Suffix (BIP_Alloc_Suffix) then
return BIP_Alloc_Form;
elsif Has_Suffix (BIP_Storage_Pool_Suffix) then
return BIP_Storage_Pool;
elsif Has_Suffix (BIP_Finalization_Master_Suffix) then
return BIP_Finalization_Master;
elsif Has_Suffix (BIP_Task_Master_Suffix) then
return BIP_Task_Master;
elsif Has_Suffix (BIP_Activation_Chain_Suffix) then
return BIP_Activation_Chain;
elsif Has_Suffix (BIP_Object_Access_Suffix) then
return BIP_Object_Access;
else
raise Program_Error;
end if;
end BIP_Suffix_Kind;
---------------------------
-- Build_In_Place_Formal --
---------------------------
function Build_In_Place_Formal
(Func : Entity_Id;
Kind : BIP_Formal_Kind) return Entity_Id
is
Extra_Formal : Entity_Id := Extra_Formals (Func);
Formal_Suffix : constant String := BIP_Formal_Suffix (Kind);
begin
-- Maybe it would be better for each implicit formal of a build-in-place
-- function to have a flag or a Uint attribute to identify it. ???
-- The return type in the function declaration may have been a limited
-- view, and the extra formals for the function were not generated at
-- that point. At the point of call the full view must be available and
-- the extra formals can be created.
if No (Extra_Formal) then
Create_Extra_Formals (Func);
Extra_Formal := Extra_Formals (Func);
end if;
-- We search for a formal with a matching suffix. We can't search
-- for the full name, because of the code at the end of Sem_Ch6.-
-- Create_Extra_Formals, which copies the Extra_Formals over to
-- the Alias of an instance, which will cause the formals to have
-- "incorrect" names.
loop
pragma Assert (Present (Extra_Formal));
declare
Name : constant String := Get_Name_String (Chars (Extra_Formal));
begin
exit when Name'Length >= Formal_Suffix'Length
and then Formal_Suffix =
Name (Name'Last - Formal_Suffix'Length + 1 .. Name'Last);
end;
Next_Formal_With_Extras (Extra_Formal);
end loop;
return Extra_Formal;
end Build_In_Place_Formal;
-------------------------------
-- Build_Procedure_Body_Form --
-------------------------------
function Build_Procedure_Body_Form
(Func_Id : Entity_Id;
Func_Body : Node_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Func_Body);
Proc_Decl : constant Node_Id :=
Next (Unit_Declaration_Node (Func_Id));
-- It is assumed that the next node following the declaration of the
-- corresponding subprogram spec is the declaration of the procedure
-- form.
Proc_Id : constant Entity_Id := Defining_Entity (Proc_Decl);
procedure Replace_Returns (Param_Id : Entity_Id; Stmts : List_Id);
-- Replace each return statement found in the list Stmts with an
-- assignment of the return expression to parameter Param_Id.
---------------------
-- Replace_Returns --
---------------------
procedure Replace_Returns (Param_Id : Entity_Id; Stmts : List_Id) is
Stmt : Node_Id;
begin
Stmt := First (Stmts);
while Present (Stmt) loop
if Nkind (Stmt) = N_Block_Statement then
Replace_Returns (Param_Id,
Statements (Handled_Statement_Sequence (Stmt)));
elsif Nkind (Stmt) = N_Case_Statement then
declare
Alt : Node_Id;
begin
Alt := First (Alternatives (Stmt));
while Present (Alt) loop
Replace_Returns (Param_Id, Statements (Alt));
Next (Alt);
end loop;
end;
elsif Nkind (Stmt) = N_Extended_Return_Statement then
declare
Ret_Obj : constant Entity_Id :=
Defining_Entity
(First (Return_Object_Declarations (Stmt)));
Assign : constant Node_Id :=
Make_Assignment_Statement (Sloc (Stmt),
Name =>
New_Occurrence_Of (Param_Id, Loc),
Expression =>
New_Occurrence_Of (Ret_Obj, Sloc (Stmt)));
Stmts : List_Id;
begin
-- The extended return may just contain the declaration
if Present (Handled_Statement_Sequence (Stmt)) then
Stmts := Statements (Handled_Statement_Sequence (Stmt));
else
Stmts := New_List;
end if;
Set_Assignment_OK (Name (Assign));
Rewrite (Stmt,
Make_Block_Statement (Sloc (Stmt),
Declarations =>
Return_Object_Declarations (Stmt),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stmts)));
Replace_Returns (Param_Id, Stmts);
Append_To (Stmts, Assign);
Append_To (Stmts, Make_Simple_Return_Statement (Loc));
end;
elsif Nkind (Stmt) = N_If_Statement then
Replace_Returns (Param_Id, Then_Statements (Stmt));
Replace_Returns (Param_Id, Else_Statements (Stmt));
declare
Part : Node_Id;
begin
Part := First (Elsif_Parts (Stmt));
while Present (Part) loop
Replace_Returns (Param_Id, Then_Statements (Part));
Next (Part);
end loop;
end;
elsif Nkind (Stmt) = N_Loop_Statement then
Replace_Returns (Param_Id, Statements (Stmt));
elsif Nkind (Stmt) = N_Simple_Return_Statement then
-- Generate:
-- Param := Expr;
-- return;
Rewrite (Stmt,
Make_Assignment_Statement (Sloc (Stmt),
Name => New_Occurrence_Of (Param_Id, Loc),
Expression => Relocate_Node (Expression (Stmt))));
Insert_After (Stmt, Make_Simple_Return_Statement (Loc));
-- Skip the added return
Next (Stmt);
end if;
Next (Stmt);
end loop;
end Replace_Returns;
-- Local variables
Stmts : List_Id;
New_Body : Node_Id;
-- Start of processing for Build_Procedure_Body_Form
begin
-- This routine replaces the original function body:
-- function F (...) return Array_Typ is
-- begin
-- ...
-- return Something;
-- end F;
-- with the following:
-- procedure P (..., Result : out Array_Typ) is
-- begin
-- ...
-- Result := Something;
-- end P;
Stmts :=
Statements (Handled_Statement_Sequence (Func_Body));
Replace_Returns (Last_Entity (Proc_Id), Stmts);
New_Body :=
Make_Subprogram_Body (Loc,
Specification =>
Copy_Subprogram_Spec (Specification (Proc_Decl)),
Declarations => Declarations (Func_Body),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stmts));
-- If the function is a generic instance, so is the new procedure.
-- Set flag accordingly so that the proper renaming declarations are
-- generated.
Set_Is_Generic_Instance (Proc_Id, Is_Generic_Instance (Func_Id));
return New_Body;
end Build_Procedure_Body_Form;
-----------------------
-- Caller_Known_Size --
-----------------------
function Caller_Known_Size
(Func_Call : Node_Id;
Result_Subt : Entity_Id) return Boolean
is
begin
return
(Is_Definite_Subtype (Underlying_Type (Result_Subt))
and then No (Controlling_Argument (Func_Call)))
or else not Requires_Transient_Scope (Underlying_Type (Result_Subt));
end Caller_Known_Size;
-----------------------
-- Check_BIP_Actuals --
-----------------------
function Check_BIP_Actuals
(Subp_Call : Node_Id;
Subp_Id : Entity_Id) return Boolean
is
Formal : Entity_Id;
Actual : Node_Id;
begin
pragma Assert (Nkind (Subp_Call) in N_Entry_Call_Statement
| N_Function_Call
| N_Procedure_Call_Statement);
Formal := First_Formal_With_Extras (Subp_Id);
Actual := First_Actual (Subp_Call);
while Present (Formal) and then Present (Actual) loop
if Is_Build_In_Place_Entity (Formal)
and then Nkind (Actual) = N_Identifier
and then Is_Build_In_Place_Entity (Entity (Actual))
and then BIP_Suffix_Kind (Formal)
/= BIP_Suffix_Kind (Entity (Actual))
then
return False;
end if;
Next_Formal_With_Extras (Formal);
Next_Actual (Actual);
end loop;
return No (Formal) and then No (Actual);
end Check_BIP_Actuals;
-----------------------------
-- Check_Number_Of_Actuals --
-----------------------------
function Check_Number_Of_Actuals
(Subp_Call : Node_Id;
Subp_Id : Entity_Id) return Boolean
is
Formal : Entity_Id;
Actual : Node_Id;
begin
pragma Assert (Nkind (Subp_Call) in N_Entry_Call_Statement
| N_Function_Call
| N_Procedure_Call_Statement);
Formal := First_Formal_With_Extras (Subp_Id);
Actual := First_Actual (Subp_Call);
while Present (Formal) and then Present (Actual) loop
Next_Formal_With_Extras (Formal);
Next_Actual (Actual);
end loop;
return No (Formal) and then No (Actual);
end Check_Number_Of_Actuals;
--------------------------------
-- Check_Overriding_Operation --
--------------------------------
procedure Check_Overriding_Operation (Subp : Entity_Id) is
Typ : constant Entity_Id := Find_Dispatching_Type (Subp);
Op_List : constant Elist_Id := Primitive_Operations (Typ);
Op_Elmt : Elmt_Id;
Prim_Op : Entity_Id;
Par_Op : Entity_Id;
begin
if Is_Derived_Type (Typ)
and then not Is_Private_Type (Typ)
and then In_Open_Scopes (Scope (Etype (Typ)))
and then Is_Base_Type (Typ)
then
-- Subp overrides an inherited private operation if there is an
-- inherited operation with a different name than Subp (see
-- Derive_Subprogram) whose Alias is a hidden subprogram with the
-- same name as Subp.
Op_Elmt := First_Elmt (Op_List);
while Present (Op_Elmt) loop
Prim_Op := Node (Op_Elmt);
Par_Op := Alias (Prim_Op);
if Present (Par_Op)
and then not Comes_From_Source (Prim_Op)
and then Chars (Prim_Op) /= Chars (Par_Op)
and then Chars (Par_Op) = Chars (Subp)
and then Is_Hidden (Par_Op)
and then Type_Conformant (Prim_Op, Subp)
then
Set_DT_Position_Value (Subp, DT_Position (Prim_Op));
end if;
Next_Elmt (Op_Elmt);
end loop;
end if;
end Check_Overriding_Operation;
-------------------------------
-- Detect_Infinite_Recursion --
-------------------------------
procedure Detect_Infinite_Recursion (N : Node_Id; Spec : Entity_Id) is
Loc : constant Source_Ptr := Sloc (N);
Var_List : constant Elist_Id := New_Elmt_List;
-- List of globals referenced by body of procedure
Call_List : constant Elist_Id := New_Elmt_List;
-- List of recursive calls in body of procedure
Shad_List : constant Elist_Id := New_Elmt_List;
-- List of entity id's for entities created to capture the value of
-- referenced globals on entry to the procedure.
Scop : constant Uint := Scope_Depth (Spec);
-- This is used to record the scope depth of the current procedure, so
-- that we can identify global references.
Max_Vars : constant := 4;
-- Do not test more than four global variables
Count_Vars : Natural := 0;
-- Count variables found so far
Var : Entity_Id;
Elm : Elmt_Id;
Ent : Entity_Id;
Call : Elmt_Id;
Decl : Node_Id;
Test : Node_Id;
Elm1 : Elmt_Id;
Elm2 : Elmt_Id;
Last : Node_Id;
function Process (Nod : Node_Id) return Traverse_Result;
-- Function to traverse the subprogram body (using Traverse_Func)
-------------
-- Process --
-------------
function Process (Nod : Node_Id) return Traverse_Result is
begin
-- Procedure call
if Nkind (Nod) = N_Procedure_Call_Statement then
-- Case of one of the detected recursive calls
if Is_Entity_Name (Name (Nod))
and then Has_Recursive_Call (Entity (Name (Nod)))
and then Entity (Name (Nod)) = Spec
then
Append_Elmt (Nod, Call_List);
return Skip;
-- Any other procedure call may have side effects
else
return Abandon;
end if;
-- A call to a pure function can always be ignored
elsif Nkind (Nod) = N_Function_Call
and then Is_Entity_Name (Name (Nod))
and then Is_Pure (Entity (Name (Nod)))
then
return Skip;
-- Case of an identifier reference
elsif Nkind (Nod) = N_Identifier then
Ent := Entity (Nod);
-- If no entity, then ignore the reference
-- Not clear why this can happen. To investigate, remove this
-- test and look at the crash that occurs here in 3401-004 ???
if No (Ent) then
return Skip;
-- Ignore entities with no Scope, again not clear how this
-- can happen, to investigate, look at 4108-008 ???
elsif No (Scope (Ent)) then
return Skip;
-- Ignore the reference if not to a more global object
elsif Scope_Depth (Scope (Ent)) >= Scop then
return Skip;
-- References to types, exceptions and constants are always OK
elsif Is_Type (Ent)
or else Ekind (Ent) = E_Exception
or else Ekind (Ent) = E_Constant
then
return Skip;
-- If other than a non-volatile scalar variable, we have some
-- kind of global reference (e.g. to a function) that we cannot
-- deal with so we forget the attempt.
elsif Ekind (Ent) /= E_Variable
or else not Is_Scalar_Type (Etype (Ent))
or else Treat_As_Volatile (Ent)
then
return Abandon;
-- Otherwise we have a reference to a global scalar
else
-- Loop through global entities already detected
Elm := First_Elmt (Var_List);
loop
-- If not detected before, record this new global reference
if No (Elm) then
Count_Vars := Count_Vars + 1;
if Count_Vars <= Max_Vars then
Append_Elmt (Entity (Nod), Var_List);
else
return Abandon;
end if;
exit;
-- If recorded before, ignore
elsif Node (Elm) = Entity (Nod) then
return Skip;
-- Otherwise keep looking
else
Next_Elmt (Elm);
end if;
end loop;
return Skip;
end if;
-- For all other node kinds, recursively visit syntactic children
else
return OK;
end if;
end Process;
function Traverse_Body is new Traverse_Func (Process);
-- Start of processing for Detect_Infinite_Recursion
begin
-- Do not attempt detection in No_Implicit_Conditional mode, since we
-- won't be able to generate the code to handle the recursion in any
-- case.
if Restriction_Active (No_Implicit_Conditionals) then
return;
end if;
-- Otherwise do traversal and quit if we get abandon signal
if Traverse_Body (N) = Abandon then
return;
-- We must have a call, since Has_Recursive_Call was set. If not just
-- ignore (this is only an error check, so if we have a funny situation,
-- due to bugs or errors, we do not want to bomb).
elsif Is_Empty_Elmt_List (Call_List) then
return;
end if;
-- Here is the case where we detect recursion at compile time
-- Push our current scope for analyzing the declarations and code that
-- we will insert for the checking.
Push_Scope (Spec);
-- This loop builds temporary variables for each of the referenced
-- globals, so that at the end of the loop the list Shad_List contains
-- these temporaries in one-to-one correspondence with the elements in
-- Var_List.
Last := Empty;
Elm := First_Elmt (Var_List);
while Present (Elm) loop
Var := Node (Elm);
Ent := Make_Temporary (Loc, 'S');
Append_Elmt (Ent, Shad_List);
-- Insert a declaration for this temporary at the start of the
-- declarations for the procedure. The temporaries are declared as
-- constant objects initialized to the current values of the
-- corresponding temporaries.
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Ent,
Object_Definition => New_Occurrence_Of (Etype (Var), Loc),
Constant_Present => True,
Expression => New_Occurrence_Of (Var, Loc));
if No (Last) then
Prepend (Decl, Declarations (N));
else
Insert_After (Last, Decl);
end if;
Last := Decl;
Analyze (Decl);
Next_Elmt (Elm);
end loop;
-- Loop through calls
Call := First_Elmt (Call_List);
while Present (Call) loop
-- Build a predicate expression of the form
-- True
-- and then global1 = temp1
-- and then global2 = temp2
-- ...
-- This predicate determines if any of the global values
-- referenced by the procedure have changed since the
-- current call, if not an infinite recursion is assured.
Test := New_Occurrence_Of (Standard_True, Loc);
Elm1 := First_Elmt (Var_List);
Elm2 := First_Elmt (Shad_List);
while Present (Elm1) loop
Test :=
Make_And_Then (Loc,
Left_Opnd => Test,
Right_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => New_Occurrence_Of (Node (Elm1), Loc),
Right_Opnd => New_Occurrence_Of (Node (Elm2), Loc)));
Next_Elmt (Elm1);
Next_Elmt (Elm2);
end loop;
-- Now we replace the call with the sequence
-- if no-changes (see above) then
-- raise Storage_Error;
-- else
-- original-call
-- end if;
Rewrite (Node (Call),
Make_If_Statement (Loc,
Condition => Test,
Then_Statements => New_List (
Make_Raise_Storage_Error (Loc,
Reason => SE_Infinite_Recursion)),
Else_Statements => New_List (
Relocate_Node (Node (Call)))));
Analyze (Node (Call));
Next_Elmt (Call);
end loop;
-- Remove temporary scope stack entry used for analysis
Pop_Scope;
end Detect_Infinite_Recursion;
--------------------
-- Expand_Actuals --
--------------------
procedure Expand_Actuals
(N : Node_Id;
Subp : Entity_Id;
Post_Call : out List_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Actual : Node_Id;
Formal : Entity_Id;
N_Node : Node_Id;
E_Actual : Entity_Id;
E_Formal : Entity_Id;
procedure Add_Call_By_Copy_Code;
-- For cases where the parameter must be passed by copy, this routine
-- generates a temporary variable into which the actual is copied and
-- then passes this as the parameter. For an OUT or IN OUT parameter,
-- an assignment is also generated to copy the result back. The call
-- also takes care of any constraint checks required for the type
-- conversion case (on both the way in and the way out).
procedure Add_Simple_Call_By_Copy_Code (Force : Boolean);
-- This is similar to the above, but is used in cases where we know
-- that all that is needed is to simply create a temporary and copy
-- the value in and out of the temporary. If Force is True, then the
-- procedure may disregard legality considerations.
-- ??? We need to do the copy for a bit-packed array because this is
-- where the rewriting into a mask-and-shift sequence is done. But of
-- course this may break the program if it expects bits to be really
-- passed by reference. That's what we have done historically though.
procedure Add_Validation_Call_By_Copy_Code (Act : Node_Id);
-- Perform copy-back for actual parameter Act which denotes a validation
-- variable.
procedure Check_Fortran_Logical;
-- A value of type Logical that is passed through a formal parameter
-- must be normalized because .TRUE. usually does not have the same
-- representation as True. We assume that .FALSE. = False = 0.
-- What about functions that return a logical type ???
function Is_Legal_Copy return Boolean;
-- Check that an actual can be copied before generating the temporary
-- to be used in the call. If the formal is of a by_reference type or
-- is aliased, then the program is illegal (this can only happen in
-- the presence of representation clauses that force a misalignment)
-- If the formal is a by_reference parameter imposed by a DEC pragma,
-- emit a warning that this might lead to unaligned arguments.
function Make_Var (Actual : Node_Id) return Entity_Id;
-- Returns an entity that refers to the given actual parameter, Actual
-- (not including any type conversion). If Actual is an entity name,
-- then this entity is returned unchanged, otherwise a renaming is
-- created to provide an entity for the actual.
procedure Reset_Packed_Prefix;
-- The expansion of a packed array component reference is delayed in
-- the context of a call. Now we need to complete the expansion, so we
-- unmark the analyzed bits in all prefixes.
function Requires_Atomic_Or_Volatile_Copy return Boolean;
-- Returns whether a copy is required as per RM C.6(19) and gives a
-- warning in this case.
---------------------------
-- Add_Call_By_Copy_Code --
---------------------------
procedure Add_Call_By_Copy_Code is
Crep : Boolean;
Expr : Node_Id;
F_Typ : Entity_Id := Etype (Formal);
Indic : Node_Id;
Init : Node_Id;
Temp : Entity_Id;
V_Typ : Entity_Id;
Var : Entity_Id;
begin
if not Is_Legal_Copy then
return;
end if;
Temp := Make_Temporary (Loc, 'T', Actual);
-- Handle formals whose type comes from the limited view
if From_Limited_With (F_Typ)
and then Has_Non_Limited_View (F_Typ)
then
F_Typ := Non_Limited_View (F_Typ);
end if;
-- Use formal type for temp, unless formal type is an unconstrained
-- array, in which case we don't have to worry about bounds checks,
-- and we use the actual type, since that has appropriate bounds.
if Is_Array_Type (F_Typ) and then not Is_Constrained (F_Typ) then
Indic := New_Occurrence_Of (Etype (Actual), Loc);
else
Indic := New_Occurrence_Of (F_Typ, Loc);
end if;
-- The new code will be properly analyzed below and the setting of
-- the Do_Range_Check flag recomputed so remove the obsolete one.
Set_Do_Range_Check (Actual, False);
if Nkind (Actual) = N_Type_Conversion then
Set_Do_Range_Check (Expression (Actual), False);
V_Typ := Etype (Expression (Actual));
-- If the formal is an (in-)out parameter, capture the name
-- of the variable in order to build the post-call assignment.
Var := Make_Var (Expression (Actual));
Crep := not Has_Compatible_Representation
(Target_Type => F_Typ,
Operand_Type => Etype (Expression (Actual)));
else
V_Typ := Etype (Actual);
Var := Make_Var (Actual);
Crep := False;
end if;
-- Setup initialization for case of in out parameter, or an out
-- parameter where the formal is an unconstrained array (in the
-- latter case, we have to pass in an object with bounds).
-- If this is an out parameter, the initial copy is wasteful, so as
-- an optimization for the one-dimensional case we extract the
-- bounds of the actual and build an uninitialized temporary of the
-- right size.
-- If the formal is an out parameter with discriminants, the
-- discriminants must be captured even if the rest of the object
-- is in principle uninitialized, because the discriminants may
-- be read by the called subprogram.
if Ekind (Formal) = E_In_Out_Parameter
or else (Is_Array_Type (F_Typ) and then not Is_Constrained (F_Typ))
or else Has_Discriminants (F_Typ)
then
if Nkind (Actual) = N_Type_Conversion then
if Conversion_OK (Actual) then
Init := OK_Convert_To (F_Typ, New_Occurrence_Of (Var, Loc));
else
Init := Convert_To (F_Typ, New_Occurrence_Of (Var, Loc));
end if;
elsif Ekind (Formal) = E_Out_Parameter
and then Is_Array_Type (F_Typ)
and then Number_Dimensions (F_Typ) = 1
and then not Has_Non_Null_Base_Init_Proc (F_Typ)
then
-- Actual is a one-dimensional array or slice, and the type
-- requires no initialization. Create a temporary of the
-- right size, but do not copy actual into it (optimization).
Init := Empty;
Indic :=
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (F_Typ, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (
Make_Range (Loc,
Low_Bound =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Var, Loc),
Attribute_Name => Name_First),
High_Bound =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Var, Loc),
Attribute_Name => Name_Last)))));
else
Init := New_Occurrence_Of (Var, Loc);
end if;
-- An initialization is created for packed conversions as
-- actuals for out parameters to enable Make_Object_Declaration
-- to determine the proper subtype for N_Node. Note that this
-- is wasteful because the extra copying on the call side is
-- not required for such out parameters. ???
elsif Ekind (Formal) = E_Out_Parameter
and then Nkind (Actual) = N_Type_Conversion
and then (Is_Bit_Packed_Array (F_Typ)
or else
Is_Bit_Packed_Array (Etype (Expression (Actual))))
then
if Conversion_OK (Actual) then
Init := OK_Convert_To (F_Typ, New_Occurrence_Of (Var, Loc));
else
Init := Convert_To (F_Typ, New_Occurrence_Of (Var, Loc));
end if;
elsif Ekind (Formal) = E_In_Parameter then
-- Handle the case in which the actual is a type conversion
if Nkind (Actual) = N_Type_Conversion then
if Conversion_OK (Actual) then
Init := OK_Convert_To (F_Typ, New_Occurrence_Of (Var, Loc));
else
Init := Convert_To (F_Typ, New_Occurrence_Of (Var, Loc));
end if;
else
Init := New_Occurrence_Of (Var, Loc);
end if;
-- Access types are passed in without checks, but if a copy-back is
-- required for a null-excluding check on an in-out or out parameter,
-- then the initial value is that of the actual.
elsif Is_Access_Type (E_Formal)
and then Can_Never_Be_Null (Etype (Actual))
and then not Can_Never_Be_Null (E_Formal)
then
Init := New_Occurrence_Of (Var, Loc);
-- View conversions when the formal type has the Default_Value aspect
-- require passing in the value of the conversion's operand. The type
-- of that operand also has Default_Value, as required by AI12-0074
-- (RM 6.4.1(5.3/4)). The subtype denoted by the subtype_indication
-- is changed to the base type of the formal subtype, to ensure that
-- the actual's value can be assigned without a constraint check
-- (note that no check is done on passing to an out parameter). Also
-- note that the two types necessarily share the same ancestor type,
-- as required by 6.4.1(5.2/4), so underlying base types will match.
elsif Ekind (Formal) = E_Out_Parameter
and then Is_Scalar_Type (Etype (F_Typ))
and then Nkind (Actual) = N_Type_Conversion
and then Present (Default_Aspect_Value (Etype (F_Typ)))
then
Indic := New_Occurrence_Of (Base_Type (F_Typ), Loc);
Init := Convert_To
(Base_Type (F_Typ), New_Occurrence_Of (Var, Loc));
else
Init := Empty;
end if;
N_Node :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition => Indic,
Expression => Init);
Set_Assignment_OK (N_Node);
Insert_Action (N, N_Node);
-- Now, normally the deal here is that we use the defining
-- identifier created by that object declaration. There is
-- one exception to this. In the change of representation case
-- the above declaration will end up looking like:
-- temp : type := identifier;
-- And in this case we might as well use the identifier directly
-- and eliminate the temporary. Note that the analysis of the
-- declaration was not a waste of time in that case, since it is
-- what generated the necessary change of representation code. If
-- the change of representation introduced additional code, as in
-- a fixed-integer conversion, the expression is not an identifier
-- and must be kept.
if Crep
and then Present (Expression (N_Node))
and then Is_Entity_Name (Expression (N_Node))
then
Temp := Entity (Expression (N_Node));
Rewrite (N_Node, Make_Null_Statement (Loc));
end if;
-- For IN parameter, all we do is to replace the actual
if Ekind (Formal) = E_In_Parameter then
Rewrite (Actual, New_Occurrence_Of (Temp, Loc));
Analyze (Actual);
-- Processing for OUT or IN OUT parameter
else
-- Kill current value indications for the temporary variable we
-- created, since we just passed it as an OUT parameter.
Kill_Current_Values (Temp);
Set_Is_Known_Valid (Temp, False);
Set_Is_True_Constant (Temp, False);
-- If type conversion, use reverse conversion on exit
if Nkind (Actual) = N_Type_Conversion then
if Conversion_OK (Actual) then
Expr := OK_Convert_To (V_Typ, New_Occurrence_Of (Temp, Loc));
else
Expr := Convert_To (V_Typ, New_Occurrence_Of (Temp, Loc));
end if;
else
Expr := New_Occurrence_Of (Temp, Loc);
end if;
Rewrite (Actual, New_Occurrence_Of (Temp, Loc));
Analyze (Actual);
-- If the actual is a conversion of a packed reference, it may
-- already have been expanded by Remove_Side_Effects, and the
-- resulting variable is a temporary which does not designate
-- the proper out-parameter, which may not be addressable. In
-- that case, generate an assignment to the original expression
-- (before expansion of the packed reference) so that the proper
-- expansion of assignment to a packed component can take place.
declare
Obj : Node_Id;
Lhs : Node_Id;
begin
if Is_Renaming_Of_Object (Var)
and then Nkind (Renamed_Object (Var)) = N_Selected_Component
and then Nkind (Original_Node (Prefix (Renamed_Object (Var))))
= N_Indexed_Component
and then
Has_Non_Standard_Rep (Etype (Prefix (Renamed_Object (Var))))
then
Obj := Renamed_Object (Var);
Lhs :=
Make_Selected_Component (Loc,
Prefix =>
New_Copy_Tree (Original_Node (Prefix (Obj))),
Selector_Name => New_Copy (Selector_Name (Obj)));
Reset_Analyzed_Flags (Lhs);
else
Lhs := New_Occurrence_Of (Var, Loc);
end if;
Set_Assignment_OK (Lhs);
if Is_Access_Type (E_Formal)
and then Is_Entity_Name (Lhs)
and then
Present (Effective_Extra_Accessibility (Entity (Lhs)))
then
-- Copyback target is an Ada 2012 stand-alone object of an
-- anonymous access type.
pragma Assert (Ada_Version >= Ada_2012);
if Type_Access_Level (E_Formal) >
Object_Access_Level (Lhs)
then
Append_To (Post_Call,
Make_Raise_Program_Error (Loc,
Reason => PE_Accessibility_Check_Failed));
end if;
Append_To (Post_Call,
Make_Assignment_Statement (Loc,
Name => Lhs,
Expression => Expr));
-- We would like to somehow suppress generation of the
-- extra_accessibility assignment generated by the expansion
-- of the above assignment statement. It's not a correctness
-- issue because the following assignment renders it dead,
-- but generating back-to-back assignments to the same
-- target is undesirable. ???
Append_To (Post_Call,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (
Effective_Extra_Accessibility (Entity (Lhs)), Loc),
Expression => Make_Integer_Literal (Loc,
Type_Access_Level (E_Formal))));
else
if Is_Access_Type (E_Formal)
and then Can_Never_Be_Null (Etype (Actual))
and then not Can_Never_Be_Null (E_Formal)
then
Append_To (Post_Call,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd => New_Occurrence_Of (Temp, Loc),
Right_Opnd => Make_Null (Loc)),
Reason => CE_Access_Check_Failed));
end if;
Append_To (Post_Call,
Make_Assignment_Statement (Loc,
Name => Lhs,
Expression => Expr));
end if;
end;
end if;
end Add_Call_By_Copy_Code;
----------------------------------
-- Add_Simple_Call_By_Copy_Code --
----------------------------------
procedure Add_Simple_Call_By_Copy_Code (Force : Boolean) is
Decl : Node_Id;
F_Typ : Entity_Id := Etype (Formal);
Incod : Node_Id;
Indic : Node_Id;
Lhs : Node_Id;
Outcod : Node_Id;
Rhs : Node_Id;
Temp : Entity_Id;
begin
-- Unless forced not to, check the legality of the copy operation
if not Force and then not Is_Legal_Copy then
return;
end if;
-- Handle formals whose type comes from the limited view
if From_Limited_With (F_Typ)
and then Has_Non_Limited_View (F_Typ)
then
F_Typ := Non_Limited_View (F_Typ);
end if;
-- Use formal type for temp, unless formal type is an unconstrained
-- array, in which case we don't have to worry about bounds checks,
-- and we use the actual type, since that has appropriate bounds.
if Is_Array_Type (F_Typ) and then not Is_Constrained (F_Typ) then
Indic := New_Occurrence_Of (Etype (Actual), Loc);
else
Indic := New_Occurrence_Of (F_Typ, Loc);
end if;
-- Prepare to generate code
Reset_Packed_Prefix;
Temp := Make_Temporary (Loc, 'T', Actual);
Incod := Relocate_Node (Actual);
Outcod := New_Copy_Tree (Incod);
-- Generate declaration of temporary variable, initializing it
-- with the input parameter unless we have an OUT formal or
-- this is an initialization call.
-- If the formal is an out parameter with discriminants, the
-- discriminants must be captured even if the rest of the object
-- is in principle uninitialized, because the discriminants may
-- be read by the called subprogram.
if Ekind (Formal) = E_Out_Parameter then
Incod := Empty;
if Has_Discriminants (F_Typ) then
Indic := New_Occurrence_Of (Etype (Actual), Loc);
end if;
elsif Inside_Init_Proc then
-- Could use a comment here to match comment below ???
if Nkind (Actual) /= N_Selected_Component
or else
not Has_Discriminant_Dependent_Constraint
(Entity (Selector_Name (Actual)))
then
Incod := Empty;
-- Otherwise, keep the component in order to generate the proper
-- actual subtype, that depends on enclosing discriminants.
else
null;
end if;
end if;
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition => Indic,
Expression => Incod);
if Inside_Init_Proc
and then No (Incod)
then
-- If the call is to initialize a component of a composite type,
-- and the component does not depend on discriminants, use the
-- actual type of the component. This is required in case the
-- component is constrained, because in general the formal of the
-- initialization procedure will be unconstrained. Note that if
-- the component being initialized is constrained by an enclosing
-- discriminant, the presence of the initialization in the
-- declaration will generate an expression for the actual subtype.
Set_No_Initialization (Decl);
Set_Object_Definition (Decl,
New_Occurrence_Of (Etype (Actual), Loc));
end if;
Insert_Action (N, Decl);
-- The actual is simply a reference to the temporary
Rewrite (Actual, New_Occurrence_Of (Temp, Loc));
-- Generate copy out if OUT or IN OUT parameter
if Ekind (Formal) /= E_In_Parameter then
Lhs := Outcod;
Rhs := New_Occurrence_Of (Temp, Loc);
Set_Is_True_Constant (Temp, False);
-- Deal with conversion
if Nkind (Lhs) = N_Type_Conversion then
Lhs := Expression (Lhs);
Rhs := Convert_To (Etype (Actual), Rhs);
end if;
Append_To (Post_Call,
Make_Assignment_Statement (Loc,
Name => Lhs,
Expression => Rhs));
Set_Assignment_OK (Name (Last (Post_Call)));
end if;
end Add_Simple_Call_By_Copy_Code;
--------------------------------------
-- Add_Validation_Call_By_Copy_Code --
--------------------------------------
procedure Add_Validation_Call_By_Copy_Code (Act : Node_Id) is
Expr : Node_Id;
Obj : Node_Id;
Obj_Typ : Entity_Id;
Var : constant Node_Id := Unqual_Conv (Act);
Var_Id : Entity_Id;
begin
-- Generate range check if required
if Do_Range_Check (Actual) then
Generate_Range_Check (Actual, E_Formal, CE_Range_Check_Failed);
end if;
-- If there is a type conversion in the actual, it will be reinstated
-- below, the new instance will be properly analyzed and the setting
-- of the Do_Range_Check flag recomputed so remove the obsolete one.
if Nkind (Actual) = N_Type_Conversion then
Set_Do_Range_Check (Expression (Actual), False);
end if;
-- Copy the value of the validation variable back into the object
-- being validated.
if Is_Entity_Name (Var) then
Var_Id := Entity (Var);
Obj := Validated_Object (Var_Id);
Obj_Typ := Etype (Obj);
Expr := New_Occurrence_Of (Var_Id, Loc);
-- A type conversion is needed when the validation variable and
-- the validated object carry different types. This case occurs
-- when the actual is qualified in some fashion.
-- Common:
-- subtype Int is Integer range ...;
-- procedure Call (Val : in out Integer);
-- Original:
-- Object : Int;
-- Call (Integer (Object));
-- Expanded:
-- Object : Int;
-- Var : Integer := Object; -- conversion to base type
-- if not Var'Valid then -- validity check
-- Call (Var); -- modify Var
-- Object := Int (Var); -- conversion to subtype
if Etype (Var_Id) /= Obj_Typ then
Expr :=
Make_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Obj_Typ, Loc),
Expression => Expr);
end if;
-- Generate:
-- Object := Var;
-- <or>
-- Object := Object_Type (Var);
Append_To (Post_Call,
Make_Assignment_Statement (Loc,
Name => Obj,
Expression => Expr));
-- If the flow reaches this point, then this routine was invoked with
-- an actual which does not denote a validation variable.
else
pragma Assert (False);
null;
end if;
end Add_Validation_Call_By_Copy_Code;
---------------------------
-- Check_Fortran_Logical --
---------------------------
procedure Check_Fortran_Logical is
Logical : constant Entity_Id := Etype (Formal);
Var : Entity_Id;
-- Note: this is very incomplete, e.g. it does not handle arrays
-- of logical values. This is really not the right approach at all???)
begin
if Convention (Subp) = Convention_Fortran
and then Root_Type (Etype (Formal)) = Standard_Boolean
and then Ekind (Formal) /= E_In_Parameter
then
Var := Make_Var (Actual);
Append_To (Post_Call,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Var, Loc),
Expression =>
Unchecked_Convert_To (
Logical,
Make_Op_Ne (Loc,
Left_Opnd => New_Occurrence_Of (Var, Loc),
Right_Opnd =>
Unchecked_Convert_To (
Logical,
New_Occurrence_Of (Standard_False, Loc))))));
end if;
end Check_Fortran_Logical;
-------------------
-- Is_Legal_Copy --
-------------------
function Is_Legal_Copy return Boolean is
begin
-- An attempt to copy a value of such a type can only occur if
-- representation clauses give the actual a misaligned address.
if Is_By_Reference_Type (Etype (Formal))
or else Is_Aliased (Formal)
or else (Mechanism (Formal) = By_Reference
and then not Has_Foreign_Convention (Subp))
then
-- The actual may in fact be properly aligned but there is not
-- enough front-end information to determine this. In that case
-- gigi will emit an error or a warning if a copy is not legal,
-- or generate the proper code.
return False;
-- For users of Starlet, we assume that the specification of by-
-- reference mechanism is mandatory. This may lead to unaligned
-- objects but at least for DEC legacy code it is known to work.
-- The warning will alert users of this code that a problem may
-- be lurking.
elsif Mechanism (Formal) = By_Reference
and then Ekind (Scope (Formal)) = E_Procedure
and then Is_Valued_Procedure (Scope (Formal))
then
Error_Msg_N
("by_reference actual may be misaligned??", Actual);
return False;
else
return True;
end if;
end Is_Legal_Copy;
--------------
-- Make_Var --
--------------
function Make_Var (Actual : Node_Id) return Entity_Id is
Var : Entity_Id;
begin
if Is_Entity_Name (Actual) then
return Entity (Actual);
else
Var := Make_Temporary (Loc, 'T', Actual);
N_Node :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Var,
Subtype_Mark =>
New_Occurrence_Of (Etype (Actual), Loc),
Name => Relocate_Node (Actual));
Insert_Action (N, N_Node);
return Var;
end if;
end Make_Var;
-------------------------
-- Reset_Packed_Prefix --
-------------------------
procedure Reset_Packed_Prefix is
Pfx : Node_Id := Actual;
begin
loop
Set_Analyzed (Pfx, False);
exit when
Nkind (Pfx) not in N_Selected_Component | N_Indexed_Component;
Pfx := Prefix (Pfx);
end loop;
end Reset_Packed_Prefix;
----------------------------------------
-- Requires_Atomic_Or_Volatile_Copy --
----------------------------------------
function Requires_Atomic_Or_Volatile_Copy return Boolean is
begin
-- If the formal is already passed by copy, no need to do anything
if Is_By_Copy_Type (E_Formal) then
return False;
end if;
-- There is no requirement inside initialization procedures and this
-- would generate copies for atomic or volatile composite components.
if Inside_Init_Proc then
return False;
end if;
-- Check for atomicity mismatch
if Is_Atomic_Object (Actual) and then not Is_Atomic (E_Formal)
then
if Comes_From_Source (N) then
Error_Msg_N
("??atomic actual passed by copy (RM C.6(19))", Actual);
end if;
return True;
end if;
-- Check for volatility mismatch
if Is_Volatile_Object (Actual) and then not Is_Volatile (E_Formal)
then
if Comes_From_Source (N) then
Error_Msg_N
("??volatile actual passed by copy (RM C.6(19))", Actual);
end if;
return True;
end if;
return False;
end Requires_Atomic_Or_Volatile_Copy;
-- Start of processing for Expand_Actuals
begin
Post_Call := New_List;
Formal := First_Formal (Subp);
Actual := First_Actual (N);
while Present (Formal) loop
E_Formal := Etype (Formal);
E_Actual := Etype (Actual);
-- Handle formals whose type comes from the limited view
if From_Limited_With (E_Formal)
and then Has_Non_Limited_View (E_Formal)
then
E_Formal := Non_Limited_View (E_Formal);
end if;
if Is_Scalar_Type (E_Formal)
or else Nkind (Actual) = N_Slice
then
Check_Fortran_Logical;
-- RM 6.4.1 (11)
elsif Ekind (Formal) /= E_Out_Parameter then
-- The unusual case of the current instance of a protected type
-- requires special handling. This can only occur in the context
-- of a call within the body of a protected operation.
if Is_Entity_Name (Actual)
and then Ekind (Entity (Actual)) = E_Protected_Type
and then In_Open_Scopes (Entity (Actual))
then
if Scope (Subp) /= Entity (Actual) then
Error_Msg_N
("operation outside protected type may not "
& "call back its protected operations??", Actual);
end if;
Rewrite (Actual,
Expand_Protected_Object_Reference (N, Entity (Actual)));
end if;
-- Ada 2005 (AI-318-02): If the actual parameter is a call to a
-- build-in-place function, then a temporary return object needs
-- to be created and access to it must be passed to the function
-- (and ensure that we have an activation chain defined for tasks
-- and a Master variable).
-- Currently we limit such functions to those with inherently
-- limited result subtypes, but eventually we plan to expand the
-- functions that are treated as build-in-place to include other
-- composite result types.
-- But do not do it here for intrinsic subprograms since this will
-- be done properly after the subprogram is expanded.
if Is_Intrinsic_Subprogram (Subp) then
null;
elsif Is_Build_In_Place_Function_Call (Actual) then
Build_Activation_Chain_Entity (N);
Build_Master_Entity (Etype (Actual));
Make_Build_In_Place_Call_In_Anonymous_Context (Actual);
-- Ada 2005 (AI-318-02): Specialization of the previous case for
-- actuals containing build-in-place function calls whose returned
-- object covers interface types.
elsif Present (Unqual_BIP_Iface_Function_Call (Actual)) then
Build_Activation_Chain_Entity (N);
Build_Master_Entity (Etype (Actual));
Make_Build_In_Place_Iface_Call_In_Anonymous_Context (Actual);
end if;
Apply_Constraint_Check (Actual, E_Formal);
-- Out parameter case. No constraint checks on access type
-- RM 6.4.1 (13), but on return a null-excluding check may be
-- required (see below).
elsif Is_Access_Type (E_Formal) then
null;
-- RM 6.4.1 (14)
elsif Has_Discriminants (Base_Type (E_Formal))
or else Has_Non_Null_Base_Init_Proc (E_Formal)
then
Apply_Constraint_Check (Actual, E_Formal);
-- RM 6.4.1 (15)
else
Apply_Constraint_Check (Actual, Base_Type (E_Formal));
end if;
-- Processing for IN-OUT and OUT parameters
if Ekind (Formal) /= E_In_Parameter then
-- For type conversions of arrays, apply length/range checks
if Is_Array_Type (E_Formal)
and then Nkind (Actual) = N_Type_Conversion
then
if Is_Constrained (E_Formal) then
Apply_Length_Check (Expression (Actual), E_Formal);
else
Apply_Range_Check (Expression (Actual), E_Formal);
end if;
end if;
-- The actual denotes a variable which captures the value of an
-- object for validation purposes. Add a copy-back to reflect any
-- potential changes in value back into the original object.
-- Var : ... := Object;
-- if not Var'Valid then -- validity check
-- Call (Var); -- modify var
-- Object := Var; -- update Object
-- This case is given higher priority because the subsequent check
-- for type conversion may add an extra copy of the variable and
-- prevent proper value propagation back in the original object.
if Is_Validation_Variable_Reference (Actual) then
Add_Validation_Call_By_Copy_Code (Actual);
-- If argument is a type conversion for a type that is passed by
-- copy, then we must pass the parameter by copy.
elsif Nkind (Actual) = N_Type_Conversion
and then
(Is_Elementary_Type (E_Formal)
or else Is_Bit_Packed_Array (Etype (Formal))
or else Is_Bit_Packed_Array (Etype (Expression (Actual)))
-- Also pass by copy if change of representation
or else not Has_Compatible_Representation
(Target_Type => Etype (Formal),
Operand_Type => Etype (Expression (Actual))))
then
Add_Call_By_Copy_Code;
-- References to components of bit-packed arrays are expanded
-- at this point, rather than at the point of analysis of the
-- actuals, to handle the expansion of the assignment to
-- [in] out parameters.
elsif Is_Ref_To_Bit_Packed_Array (Actual) then
Add_Simple_Call_By_Copy_Code (Force => True);
-- If a nonscalar actual is possibly bit-aligned, we need a copy
-- because the back-end cannot cope with such objects. In other
-- cases where alignment forces a copy, the back-end generates
-- it properly. It should not be generated unconditionally in the
-- front-end because it does not know precisely the alignment
-- requirements of the target, and makes too conservative an
-- estimate, leading to superfluous copies or spurious errors
-- on by-reference parameters.
elsif Nkind (Actual) = N_Selected_Component
and then
Component_May_Be_Bit_Aligned (Entity (Selector_Name (Actual)))
and then not Represented_As_Scalar (Etype (Formal))
then
Add_Simple_Call_By_Copy_Code (Force => False);
-- References to slices of bit-packed arrays are expanded
elsif Is_Ref_To_Bit_Packed_Slice (Actual) then
Add_Call_By_Copy_Code;
-- References to possibly unaligned slices of arrays are expanded
elsif Is_Possibly_Unaligned_Slice (Actual) then
Add_Call_By_Copy_Code;
-- Deal with access types where the actual subtype and the
-- formal subtype are not the same, requiring a check.
-- It is necessary to exclude tagged types because of "downward
-- conversion" errors, but null-excluding checks on return may be
-- required.
elsif Is_Access_Type (E_Formal)
and then not Is_Tagged_Type (Designated_Type (E_Formal))
and then (not Same_Type (E_Formal, E_Actual)
or else (Can_Never_Be_Null (E_Actual)
and then not Can_Never_Be_Null (E_Formal)))
then
Add_Call_By_Copy_Code;
-- We may need to force a copy because of atomicity or volatility
-- considerations.
elsif Requires_Atomic_Or_Volatile_Copy then
Add_Call_By_Copy_Code;
-- Add call-by-copy code for the case of scalar out parameters
-- when it is not known at compile time that the subtype of the
-- formal is a subrange of the subtype of the actual (or vice
-- versa for in out parameters), in order to get range checks
-- on such actuals. (Maybe this case should be handled earlier
-- in the if statement???)
elsif Is_Scalar_Type (E_Formal)
and then
(not In_Subrange_Of (E_Formal, E_Actual)
or else
(Ekind (Formal) = E_In_Out_Parameter
and then not In_Subrange_Of (E_Actual, E_Formal)))
then
Add_Call_By_Copy_Code;
end if;
-- RM 3.2.4 (23/3): A predicate is checked on in-out and out
-- by-reference parameters on exit from the call. If the actual
-- is a derived type and the operation is inherited, the body
-- of the operation will not contain a call to the predicate
-- function, so it must be done explicitly after the call. Ditto
-- if the actual is an entity of a predicated subtype.
-- The rule refers to by-reference types, but a check is needed
-- for by-copy types as well. That check is subsumed by the rule
-- for subtype conversion on assignment, but we can generate the
-- required check now.
-- Note also that Subp may be either a subprogram entity for
-- direct calls, or a type entity for indirect calls, which must
-- be handled separately because the name does not denote an
-- overloadable entity.
By_Ref_Predicate_Check : declare
Aund : constant Entity_Id := Underlying_Type (E_Actual);
Atyp : Entity_Id;
begin
if No (Aund) then
Atyp := E_Actual;
else
Atyp := Aund;
end if;
if Predicate_Enabled (Atyp)
-- Skip predicate checks for special cases
and then Predicate_Tests_On_Arguments (Subp)
then
Append_To (Post_Call,
Make_Predicate_Check (Atyp, Actual));
end if;
end By_Ref_Predicate_Check;
-- Processing for IN parameters
else
-- Generate range check if required
if Do_Range_Check (Actual) then
Generate_Range_Check (Actual, E_Formal, CE_Range_Check_Failed);
end if;
-- For IN parameters in the bit-packed array case, we expand an
-- indexed component (the circuit in Exp_Ch4 deliberately left
-- indexed components appearing as actuals untouched, so that
-- the special processing above for the OUT and IN OUT cases
-- could be performed. We could make the test in Exp_Ch4 more
-- complex and have it detect the parameter mode, but it is
-- easier simply to handle all cases here.)
if Nkind (Actual) = N_Indexed_Component
and then Is_Bit_Packed_Array (Etype (Prefix (Actual)))
then
Reset_Packed_Prefix;
Expand_Packed_Element_Reference (Actual);
-- If we have a reference to a bit-packed array, we copy it, since
-- the actual must be byte aligned.
-- Is this really necessary in all cases???
elsif Is_Ref_To_Bit_Packed_Array (Actual) then
Add_Simple_Call_By_Copy_Code (Force => True);
-- If we have a C++ constructor call, we need to create the object
elsif Is_CPP_Constructor_Call (Actual) then
Add_Simple_Call_By_Copy_Code (Force => True);
-- If a nonscalar actual is possibly unaligned, we need a copy
elsif Is_Possibly_Unaligned_Object (Actual)
and then not Represented_As_Scalar (Etype (Formal))
then
Add_Simple_Call_By_Copy_Code (Force => False);
-- Similarly, we have to expand slices of packed arrays here
-- because the result must be byte aligned.
elsif Is_Ref_To_Bit_Packed_Slice (Actual) then
Add_Call_By_Copy_Code;
-- Only processing remaining is to pass by copy if this is a
-- reference to a possibly unaligned slice, since the caller
-- expects an appropriately aligned argument.
elsif Is_Possibly_Unaligned_Slice (Actual) then
Add_Call_By_Copy_Code;
-- We may need to force a copy because of atomicity or volatility
-- considerations.
elsif Requires_Atomic_Or_Volatile_Copy then
Add_Call_By_Copy_Code;
-- An unusual case: a current instance of an enclosing task can be
-- an actual, and must be replaced by a reference to self.
elsif Is_Entity_Name (Actual)
and then Is_Task_Type (Entity (Actual))
then
if In_Open_Scopes (Entity (Actual)) then
Rewrite (Actual,
(Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Self), Loc))));
Analyze (Actual);
-- A task type cannot otherwise appear as an actual
else
raise Program_Error;
end if;
end if;
end if;
-- Type-invariant checks for in-out and out parameters, as well as
-- for in parameters of procedures (AI05-0289 and AI12-0044).
if Ekind (Formal) /= E_In_Parameter
or else Ekind (Subp) = E_Procedure
then
Caller_Side_Invariant_Checks : declare
function Is_Public_Subp return Boolean;
-- Check whether the subprogram being called is a visible
-- operation of the type of the actual. Used to determine
-- whether an invariant check must be generated on the
-- caller side.
---------------------
-- Is_Public_Subp --
---------------------
function Is_Public_Subp return Boolean is
Pack : constant Entity_Id := Scope (Subp);
Subp_Decl : Node_Id;
begin
if not Is_Subprogram (Subp) then
return False;
-- The operation may be inherited, or a primitive of the
-- root type.
elsif
Nkind (Parent (Subp)) in N_Private_Extension_Declaration
| N_Full_Type_Declaration
then
Subp_Decl := Parent (Subp);
else
Subp_Decl := Unit_Declaration_Node (Subp);
end if;
return Ekind (Pack) = E_Package
and then
List_Containing (Subp_Decl) =
Visible_Declarations
(Specification (Unit_Declaration_Node (Pack)));
end Is_Public_Subp;
-- Start of processing for Caller_Side_Invariant_Checks
begin
-- We generate caller-side invariant checks in two cases:
-- a) when calling an inherited operation, where there is an
-- implicit view conversion of the actual to the parent type.
-- b) When the conversion is explicit
-- We treat these cases separately because the required
-- conversion for a) is added later when expanding the call.
if Has_Invariants (Etype (Actual))
and then
Nkind (Parent (Etype (Actual)))
= N_Private_Extension_Declaration
then
if Comes_From_Source (N) and then Is_Public_Subp then
Append_To (Post_Call, Make_Invariant_Call (Actual));
end if;
elsif Nkind (Actual) = N_Type_Conversion
and then Has_Invariants (Etype (Expression (Actual)))
then
if Comes_From_Source (N) and then Is_Public_Subp then
Append_To
(Post_Call, Make_Invariant_Call (Expression (Actual)));
end if;
end if;
end Caller_Side_Invariant_Checks;
end if;
Next_Formal (Formal);
Next_Actual (Actual);
end loop;
end Expand_Actuals;
-----------------
-- Expand_Call --
-----------------
procedure Expand_Call (N : Node_Id) is
Post_Call : List_Id;
-- If this is an indirect call through an Access_To_Subprogram
-- with contract specifications, it is rewritten as a call to
-- the corresponding Access_Subprogram_Wrapper with the same
-- actuals, whose body contains a naked indirect call (which
-- itself must not be rewritten, to prevent infinite recursion).
Must_Rewrite_Indirect_Call : constant Boolean :=
Ada_Version >= Ada_2020
and then Nkind (Name (N)) = N_Explicit_Dereference
and then Ekind (Etype (Name (N))) = E_Subprogram_Type
and then Present
(Access_Subprogram_Wrapper (Etype (Name (N))));
begin
pragma Assert (Nkind (N) in N_Entry_Call_Statement
| N_Function_Call
| N_Procedure_Call_Statement);
-- Check that this is not the call in the body of the wrapper
if Must_Rewrite_Indirect_Call
and then (not Is_Overloadable (Current_Scope)
or else not Is_Access_Subprogram_Wrapper (Current_Scope))
then
declare
Loc : constant Source_Ptr := Sloc (N);
Wrapper : constant Entity_Id :=
Access_Subprogram_Wrapper (Etype (Name (N)));
Ptr : constant Node_Id := Prefix (Name (N));
Ptr_Type : constant Entity_Id := Etype (Ptr);
Typ : constant Entity_Id := Etype (N);
New_N : Node_Id;
Parms : List_Id := Parameter_Associations (N);
Ptr_Act : Node_Id;
begin
-- The last actual in the call is the pointer itself.
-- If the aspect is inherited, convert the pointer to the
-- parent type that specifies the contract.
-- If the original access_to_subprogram has defaults for
-- in_parameters, the call may include named associations, so
-- we create one for the pointer as well.
if Is_Derived_Type (Ptr_Type)
and then Ptr_Type /= Etype (Last_Formal (Wrapper))
then
Ptr_Act :=
Make_Type_Conversion (Loc,
New_Occurrence_Of
(Etype (Last_Formal (Wrapper)), Loc), Ptr);
else
Ptr_Act := Ptr;
end if;
-- Handle parameterless subprogram.
if No (Parms) then
Parms := New_List;
end if;
Append
(Make_Parameter_Association (Loc,
Selector_Name => Make_Identifier (Loc,
Chars (Last_Formal (Wrapper))),
Explicit_Actual_Parameter => Ptr_Act),
Parms);
if Nkind (N) = N_Procedure_Call_Statement then
New_N := Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Wrapper, Loc),
Parameter_Associations => Parms);
else
New_N := Make_Function_Call (Loc,
Name => New_Occurrence_Of (Wrapper, Loc),
Parameter_Associations => Parms);
end if;
Rewrite (N, New_N);
Analyze_And_Resolve (N, Typ);
end;
else
Expand_Call_Helper (N, Post_Call);
Insert_Post_Call_Actions (N, Post_Call);
end if;
end Expand_Call;
------------------------
-- Expand_Call_Helper --
------------------------
-- This procedure handles expansion of function calls and procedure call
-- statements (i.e. it serves as the body for Expand_N_Function_Call and
-- Expand_N_Procedure_Call_Statement). Processing for calls includes:
-- Replace call to Raise_Exception by Raise_Exception_Always if possible
-- Provide values of actuals for all formals in Extra_Formals list
-- Replace "call" to enumeration literal function by literal itself
-- Rewrite call to predefined operator as operator
-- Replace actuals to in-out parameters that are numeric conversions,
-- with explicit assignment to temporaries before and after the call.
-- Note that the list of actuals has been filled with default expressions
-- during semantic analysis of the call. Only the extra actuals required
-- for the 'Constrained attribute and for accessibility checks are added
-- at this point.
procedure Expand_Call_Helper (N : Node_Id; Post_Call : out List_Id) is
Loc : constant Source_Ptr := Sloc (N);
Call_Node : Node_Id := N;
Extra_Actuals : List_Id := No_List;
Prev : Node_Id := Empty;
procedure Add_Actual_Parameter (Insert_Param : Node_Id);
-- Adds one entry to the end of the actual parameter list. Used for
-- default parameters and for extra actuals (for Extra_Formals). The
-- argument is an N_Parameter_Association node.
procedure Add_Extra_Actual (Expr : Node_Id; EF : Entity_Id);
-- Adds an extra actual to the list of extra actuals. Expr is the
-- expression for the value of the actual, EF is the entity for the
-- extra formal.
procedure Add_View_Conversion_Invariants
(Formal : Entity_Id;
Actual : Node_Id);
-- Adds invariant checks for every intermediate type between the range
-- of a view converted argument to its ancestor (from parent to child).
function Can_Fold_Predicate_Call (P : Entity_Id) return Boolean;
-- Try to constant-fold a predicate check, which often enough is a
-- simple arithmetic expression that can be computed statically if
-- its argument is static. This cleans up the output of CCG, even
-- though useless predicate checks will be generally removed by
-- back-end optimizations.
procedure Check_Subprogram_Variant;
-- Emit a call to the internally generated procedure with checks for
-- aspect Subprogrgram_Variant, if present and enabled.
function Inherited_From_Formal (S : Entity_Id) return Entity_Id;
-- Within an instance, a type derived from an untagged formal derived
-- type inherits from the original parent, not from the actual. The
-- current derivation mechanism has the derived type inherit from the
-- actual, which is only correct outside of the instance. If the
-- subprogram is inherited, we test for this particular case through a
-- convoluted tree traversal before setting the proper subprogram to be
-- called.
function In_Unfrozen_Instance (E : Entity_Id) return Boolean;
-- Return true if E comes from an instance that is not yet frozen
function Is_Class_Wide_Interface_Type (E : Entity_Id) return Boolean;
-- Return True when E is a class-wide interface type or an access to
-- a class-wide interface type.
function Is_Direct_Deep_Call (Subp : Entity_Id) return Boolean;
-- Determine if Subp denotes a non-dispatching call to a Deep routine
function New_Value (From : Node_Id) return Node_Id;
-- From is the original Expression. New_Value is equivalent to a call
-- to Duplicate_Subexpr with an explicit dereference when From is an
-- access parameter.
--------------------------
-- Add_Actual_Parameter --
--------------------------
procedure Add_Actual_Parameter (Insert_Param : Node_Id) is
Actual_Expr : constant Node_Id :=
Explicit_Actual_Parameter (Insert_Param);
begin
-- Case of insertion is first named actual
if No (Prev) or else
Nkind (Parent (Prev)) /= N_Parameter_Association
then
Set_Next_Named_Actual
(Insert_Param, First_Named_Actual (Call_Node));
Set_First_Named_Actual (Call_Node, Actual_Expr);
if No (Prev) then
if No (Parameter_Associations (Call_Node)) then
Set_Parameter_Associations (Call_Node, New_List);
end if;
Append (Insert_Param, Parameter_Associations (Call_Node));
else
Insert_After (Prev, Insert_Param);
end if;
-- Case of insertion is not first named actual
else
Set_Next_Named_Actual
(Insert_Param, Next_Named_Actual (Parent (Prev)));
Set_Next_Named_Actual (Parent (Prev), Actual_Expr);
Append (Insert_Param, Parameter_Associations (Call_Node));
end if;
Prev := Actual_Expr;
end Add_Actual_Parameter;
----------------------
-- Add_Extra_Actual --
----------------------
procedure Add_Extra_Actual (Expr : Node_Id; EF : Entity_Id) is
Loc : constant Source_Ptr := Sloc (Expr);
begin
if Extra_Actuals = No_List then
Extra_Actuals := New_List;
Set_Parent (Extra_Actuals, Call_Node);
end if;
Append_To (Extra_Actuals,
Make_Parameter_Association (Loc,
Selector_Name => New_Occurrence_Of (EF, Loc),
Explicit_Actual_Parameter => Expr));
Analyze_And_Resolve (Expr, Etype (EF));
if Nkind (Call_Node) = N_Function_Call then
Set_Is_Accessibility_Actual (Parent (Expr));
end if;
end Add_Extra_Actual;
------------------------------------
-- Add_View_Conversion_Invariants --
------------------------------------
procedure Add_View_Conversion_Invariants
(Formal : Entity_Id;
Actual : Node_Id)
is
Arg : Entity_Id;
Curr_Typ : Entity_Id;
Inv_Checks : List_Id;
Par_Typ : Entity_Id;
begin
Inv_Checks := No_List;
-- Extract the argument from a potentially nested set of view
-- conversions.
Arg := Actual;
while Nkind (Arg) = N_Type_Conversion loop
Arg := Expression (Arg);
end loop;
-- Move up the derivation chain starting with the type of the formal
-- parameter down to the type of the actual object.
Curr_Typ := Empty;
Par_Typ := Etype (Arg);
while Par_Typ /= Etype (Formal) and Par_Typ /= Curr_Typ loop
Curr_Typ := Par_Typ;
if Has_Invariants (Curr_Typ)
and then Present (Invariant_Procedure (Curr_Typ))
then
-- Verify the invariant of the current type. Generate:
-- <Curr_Typ>Invariant (Curr_Typ (Arg));
Prepend_New_To (Inv_Checks,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(Invariant_Procedure (Curr_Typ), Loc),
Parameter_Associations => New_List (
Make_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Curr_Typ, Loc),
Expression => New_Copy_Tree (Arg)))));
end if;
Par_Typ := Base_Type (Etype (Curr_Typ));
end loop;
-- If the node is a function call the generated tests have been
-- already handled in Insert_Post_Call_Actions.
if not Is_Empty_List (Inv_Checks)
and then Nkind (Call_Node) = N_Procedure_Call_Statement
then
Insert_Actions_After (Call_Node, Inv_Checks);
end if;
end Add_View_Conversion_Invariants;
-----------------------------
-- Can_Fold_Predicate_Call --
-----------------------------
function Can_Fold_Predicate_Call (P : Entity_Id) return Boolean is
Actual : Node_Id;
function May_Fold (N : Node_Id) return Traverse_Result;
-- The predicate expression is foldable if it only contains operators
-- and literals. During this check, we also replace occurrences of
-- the formal of the constructed predicate function with the static
-- value of the actual. This is done on a copy of the analyzed
-- expression for the predicate.
--------------
-- May_Fold --
--------------
function May_Fold (N : Node_Id) return Traverse_Result is
begin
case Nkind (N) is
when N_Op =>
return OK;
when N_Expanded_Name
| N_Identifier
=>
if Ekind (Entity (N)) = E_In_Parameter
and then Entity (N) = First_Entity (P)
then
Rewrite (N, New_Copy (Actual));
Set_Is_Static_Expression (N);
return OK;
elsif Ekind (Entity (N)) = E_Enumeration_Literal then
return OK;
else
return Abandon;
end if;
when N_Case_Expression
| N_If_Expression
=>
return OK;
when N_Integer_Literal =>
return OK;
when others =>
return Abandon;
end case;
end May_Fold;
function Try_Fold is new Traverse_Func (May_Fold);
-- Other lLocal variables
Subt : constant Entity_Id := Etype (First_Entity (P));
Aspect : Node_Id;
Pred : Node_Id;
-- Start of processing for Can_Fold_Predicate_Call
begin
-- Folding is only interesting if the actual is static and its type
-- has a Dynamic_Predicate aspect. For CodePeer we preserve the
-- function call.
Actual := First (Parameter_Associations (Call_Node));
Aspect := Find_Aspect (Subt, Aspect_Dynamic_Predicate);
-- If actual is a declared constant, retrieve its value
if Is_Entity_Name (Actual)
and then Ekind (Entity (Actual)) = E_Constant
then
Actual := Constant_Value (Entity (Actual));
end if;
if No (Actual)
or else Nkind (Actual) /= N_Integer_Literal
or else not Has_Dynamic_Predicate_Aspect (Subt)
or else No (Aspect)
or else CodePeer_Mode
then
return False;
end if;
-- Retrieve the analyzed expression for the predicate
Pred := New_Copy_Tree (Expression (Aspect));
if Try_Fold (Pred) = OK then
Rewrite (Call_Node, Pred);
Analyze_And_Resolve (Call_Node, Standard_Boolean);
return True;
-- Otherwise continue the expansion of the function call
else
return False;
end if;
end Can_Fold_Predicate_Call;
------------------------------
-- Check_Subprogram_Variant --
------------------------------
procedure Check_Subprogram_Variant is
Variant_Prag : constant Node_Id :=
Get_Pragma (Current_Scope, Pragma_Subprogram_Variant);
Variant_Proc : Entity_Id;
begin
if Present (Variant_Prag) and then Is_Checked (Variant_Prag) then
-- Analysis of the pragma rewrites its argument with a reference
-- to the internally generated procedure.
Variant_Proc :=
Entity
(Expression
(First
(Pragma_Argument_Associations (Variant_Prag))));
Insert_Action (Call_Node,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (Variant_Proc, Loc),
Parameter_Associations =>
New_Copy_List (Parameter_Associations (Call_Node))));
end if;
end Check_Subprogram_Variant;
---------------------------
-- Inherited_From_Formal --
---------------------------
function Inherited_From_Formal (S : Entity_Id) return Entity_Id is
Par : Entity_Id;
Gen_Par : Entity_Id;
Gen_Prim : Elist_Id;
Elmt : Elmt_Id;
Indic : Node_Id;
begin
-- If the operation is inherited, it is attached to the corresponding
-- type derivation. If the parent in the derivation is a generic
-- actual, it is a subtype of the actual, and we have to recover the
-- original derived type declaration to find the proper parent.
if Nkind (Parent (S)) /= N_Full_Type_Declaration
or else not Is_Derived_Type (Defining_Identifier (Parent (S)))
or else Nkind (Type_Definition (Original_Node (Parent (S)))) /=
N_Derived_Type_Definition
or else not In_Instance
then
return Empty;
else
Indic :=
Subtype_Indication
(Type_Definition (Original_Node (Parent (S))));
if Nkind (Indic) = N_Subtype_Indication then
Par := Entity (Subtype_Mark (Indic));
else
Par := Entity (Indic);
end if;
end if;
if not Is_Generic_Actual_Type (Par)
or else Is_Tagged_Type (Par)
or else Nkind (Parent (Par)) /= N_Subtype_Declaration
or else not In_Open_Scopes (Scope (Par))
then
return Empty;
else
Gen_Par := Generic_Parent_Type (Parent (Par));
end if;
-- If the actual has no generic parent type, the formal is not
-- a formal derived type, so nothing to inherit.
if No (Gen_Par) then
return Empty;
end if;
-- If the generic parent type is still the generic type, this is a
-- private formal, not a derived formal, and there are no operations
-- inherited from the formal.
if Nkind (Parent (Gen_Par)) = N_Formal_Type_Declaration then
return Empty;
end if;
Gen_Prim := Collect_Primitive_Operations (Gen_Par);
Elmt := First_Elmt (Gen_Prim);
while Present (Elmt) loop
if Chars (Node (Elmt)) = Chars (S) then
declare
F1 : Entity_Id;
F2 : Entity_Id;
begin
F1 := First_Formal (S);
F2 := First_Formal (Node (Elmt));
while Present (F1)
and then Present (F2)
loop
if Etype (F1) = Etype (F2)
or else Etype (F2) = Gen_Par
then
Next_Formal (F1);
Next_Formal (F2);
else
Next_Elmt (Elmt);
exit; -- not the right subprogram
end if;
return Node (Elmt);
end loop;
end;
else
Next_Elmt (Elmt);
end if;
end loop;
raise Program_Error;
end Inherited_From_Formal;
--------------------------
-- In_Unfrozen_Instance --
--------------------------
function In_Unfrozen_Instance (E : Entity_Id) return Boolean is
S : Entity_Id;
begin
S := E;
while Present (S) and then S /= Standard_Standard loop
if Is_Generic_Instance (S)
and then Present (Freeze_Node (S))
and then not Analyzed (Freeze_Node (S))
then
return True;
end if;
S := Scope (S);
end loop;
return False;
end In_Unfrozen_Instance;
----------------------------------
-- Is_Class_Wide_Interface_Type --
----------------------------------
function Is_Class_Wide_Interface_Type (E : Entity_Id) return Boolean is
DDT : Entity_Id;
Typ : Entity_Id := E;
begin
if Has_Non_Limited_View (Typ) then
Typ := Non_Limited_View (Typ);
end if;
if Ekind (Typ) = E_Anonymous_Access_Type then
DDT := Directly_Designated_Type (Typ);
if Has_Non_Limited_View (DDT) then
DDT := Non_Limited_View (DDT);
end if;
return Is_Class_Wide_Type (DDT) and then Is_Interface (DDT);
else
return Is_Class_Wide_Type (Typ) and then Is_Interface (Typ);
end if;
end Is_Class_Wide_Interface_Type;
-------------------------
-- Is_Direct_Deep_Call --
-------------------------
function Is_Direct_Deep_Call (Subp : Entity_Id) return Boolean is
begin
if Is_TSS (Subp, TSS_Deep_Adjust)
or else Is_TSS (Subp, TSS_Deep_Finalize)
or else Is_TSS (Subp, TSS_Deep_Initialize)
then
declare
Actual : Node_Id;
Formal : Entity_Id;
begin
Actual := First (Parameter_Associations (Call_Node));
Formal := First_Formal (Subp);
while Present (Actual)
and then Present (Formal)
loop
if Nkind (Actual) = N_Identifier
and then Is_Controlling_Actual (Actual)
and then Etype (Actual) = Etype (Formal)
then
return True;
end if;
Next (Actual);
Next_Formal (Formal);
end loop;
end;
end if;
return False;
end Is_Direct_Deep_Call;
---------------
-- New_Value --
---------------
function New_Value (From : Node_Id) return Node_Id is
Res : constant Node_Id := Duplicate_Subexpr (From);
begin
if Is_Access_Type (Etype (From)) then
return Make_Explicit_Dereference (Sloc (From), Prefix => Res);
else
return Res;
end if;
end New_Value;
-- Local variables
Remote : constant Boolean := Is_Remote_Call (Call_Node);
Actual : Node_Id;
Formal : Entity_Id;
Orig_Subp : Entity_Id := Empty;
Param_Count : Positive;
Parent_Formal : Entity_Id;
Parent_Subp : Entity_Id;
Prev_Ult : Node_Id;
Scop : Entity_Id;
Subp : Entity_Id;
Prev_Orig : Node_Id;
-- Original node for an actual, which may have been rewritten. If the
-- actual is a function call that has been transformed from a selected
-- component, the original node is unanalyzed. Otherwise, it carries
-- semantic information used to generate additional actuals.
CW_Interface_Formals_Present : Boolean := False;
-- Start of processing for Expand_Call_Helper
begin
Post_Call := New_List;
-- Expand the function or procedure call if the first actual has a
-- declared dimension aspect, and the subprogram is declared in one
-- of the dimension I/O packages.
if Ada_Version >= Ada_2012
and then
Nkind (Call_Node) in N_Procedure_Call_Statement | N_Function_Call
and then Present (Parameter_Associations (Call_Node))
then
Expand_Put_Call_With_Symbol (Call_Node);
end if;
-- Ignore if previous error
if Nkind (Call_Node) in N_Has_Etype
and then Etype (Call_Node) = Any_Type
then
return;
end if;
-- Call using access to subprogram with explicit dereference
if Nkind (Name (Call_Node)) = N_Explicit_Dereference then
Subp := Etype (Name (Call_Node));
Parent_Subp := Empty;
-- Case of call to simple entry, where the Name is a selected component
-- whose prefix is the task, and whose selector name is the entry name
elsif Nkind (Name (Call_Node)) = N_Selected_Component then
Subp := Entity (Selector_Name (Name (Call_Node)));
Parent_Subp := Empty;
-- Case of call to member of entry family, where Name is an indexed
-- component, with the prefix being a selected component giving the
-- task and entry family name, and the index being the entry index.
elsif Nkind (Name (Call_Node)) = N_Indexed_Component then
Subp := Entity (Selector_Name (Prefix (Name (Call_Node))));
Parent_Subp := Empty;
-- Normal case
else
Subp := Entity (Name (Call_Node));
Parent_Subp := Alias (Subp);
-- Replace call to Raise_Exception by call to Raise_Exception_Always
-- if we can tell that the first parameter cannot possibly be null.
-- This improves efficiency by avoiding a run-time test.
-- We do not do this if Raise_Exception_Always does not exist, which
-- can happen in configurable run time profiles which provide only a
-- Raise_Exception.
if Is_RTE (Subp, RE_Raise_Exception)
and then RTE_Available (RE_Raise_Exception_Always)
then
declare
FA : constant Node_Id :=
Original_Node (First_Actual (Call_Node));
begin
-- The case we catch is where the first argument is obtained
-- using the Identity attribute (which must always be
-- non-null).
if Nkind (FA) = N_Attribute_Reference
and then Attribute_Name (FA) = Name_Identity
then
Subp := RTE (RE_Raise_Exception_Always);
Set_Name (Call_Node, New_Occurrence_Of (Subp, Loc));
end if;
end;
end if;
if Ekind (Subp) = E_Entry then
Parent_Subp := Empty;
end if;
end if;
-- Ada 2005 (AI-345): We have a procedure call as a triggering
-- alternative in an asynchronous select or as an entry call in
-- a conditional or timed select. Check whether the procedure call
-- is a renaming of an entry and rewrite it as an entry call.
if Ada_Version >= Ada_2005
and then Nkind (Call_Node) = N_Procedure_Call_Statement
and then
((Nkind (Parent (Call_Node)) = N_Triggering_Alternative
and then Triggering_Statement (Parent (Call_Node)) = Call_Node)
or else
(Nkind (Parent (Call_Node)) = N_Entry_Call_Alternative
and then Entry_Call_Statement (Parent (Call_Node)) = Call_Node))
then
declare
Ren_Decl : Node_Id;
Ren_Root : Entity_Id := Subp;
begin
-- This may be a chain of renamings, find the root
if Present (Alias (Ren_Root)) then
Ren_Root := Alias (Ren_Root);
end if;
if Present (Original_Node (Parent (Parent (Ren_Root)))) then
Ren_Decl := Original_Node (Parent (Parent (Ren_Root)));
if Nkind (Ren_Decl) = N_Subprogram_Renaming_Declaration then
Rewrite (Call_Node,
Make_Entry_Call_Statement (Loc,
Name =>
New_Copy_Tree (Name (Ren_Decl)),
Parameter_Associations =>
New_Copy_List_Tree
(Parameter_Associations (Call_Node))));
return;
end if;
end if;
end;
end if;
-- If this is a call to a predicate function, try to constant fold it
if Nkind (Call_Node) = N_Function_Call
and then Is_Entity_Name (Name (Call_Node))
and then Is_Predicate_Function (Subp)
and then Can_Fold_Predicate_Call (Subp)
then
return;
end if;
if Modify_Tree_For_C
and then Nkind (Call_Node) = N_Function_Call
and then Is_Entity_Name (Name (Call_Node))
then
declare
Func_Id : constant Entity_Id :=
Ultimate_Alias (Entity (Name (Call_Node)));
begin
-- When generating C code, transform a function call that returns
-- a constrained array type into procedure form.
if Rewritten_For_C (Func_Id) then
-- For internally generated calls ensure that they reference
-- the entity of the spec of the called function (needed since
-- the expander may generate calls using the entity of their
-- body). See for example Expand_Boolean_Operator().
if not (Comes_From_Source (Call_Node))
and then Nkind (Unit_Declaration_Node (Func_Id)) =
N_Subprogram_Body
then
Set_Entity (Name (Call_Node),
Corresponding_Function
(Corresponding_Procedure (Func_Id)));
end if;
Rewrite_Function_Call_For_C (Call_Node);
return;
-- Also introduce a temporary for functions that return a record
-- called within another procedure or function call, since records
-- are passed by pointer in the generated C code, and we cannot
-- take a pointer from a subprogram call.
elsif Nkind (Parent (Call_Node)) in N_Subprogram_Call
and then Is_Record_Type (Etype (Func_Id))
then
declare
Temp_Id : constant Entity_Id := Make_Temporary (Loc, 'T');
Decl : Node_Id;
begin
-- Generate:
-- Temp : ... := Func_Call (...);
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp_Id,
Object_Definition =>
New_Occurrence_Of (Etype (Func_Id), Loc),
Expression =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (Func_Id, Loc),
Parameter_Associations =>
Parameter_Associations (Call_Node)));
Insert_Action (Parent (Call_Node), Decl);
Rewrite (Call_Node, New_Occurrence_Of (Temp_Id, Loc));
return;
end;
end if;
end;
end if;
-- First step, compute extra actuals, corresponding to any Extra_Formals
-- present. Note that we do not access Extra_Formals directly, instead
-- we simply note the presence of the extra formals as we process the
-- regular formals collecting corresponding actuals in Extra_Actuals.
-- We also generate any required range checks for actuals for in formals
-- as we go through the loop, since this is a convenient place to do it.
-- (Though it seems that this would be better done in Expand_Actuals???)
-- Special case: Thunks must not compute the extra actuals; they must
-- just propagate to the target primitive their extra actuals.
if Is_Thunk (Current_Scope)
and then Thunk_Entity (Current_Scope) = Subp
and then Present (Extra_Formals (Subp))
then
pragma Assert (Present (Extra_Formals (Current_Scope)));
declare
Target_Formal : Entity_Id;
Thunk_Formal : Entity_Id;
begin
Target_Formal := Extra_Formals (Subp);
Thunk_Formal := Extra_Formals (Current_Scope);
while Present (Target_Formal) loop
Add_Extra_Actual
(Expr => New_Occurrence_Of (Thunk_Formal, Loc),
EF => Thunk_Formal);
Target_Formal := Extra_Formal (Target_Formal);
Thunk_Formal := Extra_Formal (Thunk_Formal);
end loop;
while Is_Non_Empty_List (Extra_Actuals) loop
Add_Actual_Parameter (Remove_Head (Extra_Actuals));
end loop;
Expand_Actuals (Call_Node, Subp, Post_Call);
pragma Assert (Is_Empty_List (Post_Call));
pragma Assert (Check_Number_Of_Actuals (Call_Node, Subp));
pragma Assert (Check_BIP_Actuals (Call_Node, Subp));
return;
end;
end if;
Formal := First_Formal (Subp);
Actual := First_Actual (Call_Node);
Param_Count := 1;
while Present (Formal) loop
-- Prepare to examine current entry
Prev := Actual;
Prev_Orig := Original_Node (Prev);
-- Ada 2005 (AI-251): Check if any formal is a class-wide interface
-- to expand it in a further round.
CW_Interface_Formals_Present :=
CW_Interface_Formals_Present
or else Is_Class_Wide_Interface_Type (Etype (Formal));
-- Create possible extra actual for constrained case. Usually, the
-- extra actual is of the form actual'constrained, but since this
-- attribute is only available for unconstrained records, TRUE is
-- expanded if the type of the formal happens to be constrained (for
-- instance when this procedure is inherited from an unconstrained
-- record to a constrained one) or if the actual has no discriminant
-- (its type is constrained). An exception to this is the case of a
-- private type without discriminants. In this case we pass FALSE
-- because the object has underlying discriminants with defaults.
if Present (Extra_Constrained (Formal)) then
if Ekind (Etype (Prev)) in Private_Kind
and then not Has_Discriminants (Base_Type (Etype (Prev)))
then
Add_Extra_Actual
(Expr => New_Occurrence_Of (Standard_False, Loc),
EF => Extra_Constrained (Formal));
elsif Is_Constrained (Etype (Formal))
or else not Has_Discriminants (Etype (Prev))
then
Add_Extra_Actual
(Expr => New_Occurrence_Of (Standard_True, Loc),
EF => Extra_Constrained (Formal));
-- Do not produce extra actuals for Unchecked_Union parameters.
-- Jump directly to the end of the loop.
elsif Is_Unchecked_Union (Base_Type (Etype (Actual))) then
goto Skip_Extra_Actual_Generation;
else
-- If the actual is a type conversion, then the constrained
-- test applies to the actual, not the target type.
declare
Act_Prev : Node_Id;
begin
-- Test for unchecked conversions as well, which can occur
-- as out parameter actuals on calls to stream procedures.
Act_Prev := Prev;
while Nkind (Act_Prev) in N_Type_Conversion
| N_Unchecked_Type_Conversion
loop
Act_Prev := Expression (Act_Prev);
end loop;
-- If the expression is a conversion of a dereference, this
-- is internally generated code that manipulates addresses,
-- e.g. when building interface tables. No check should
-- occur in this case, and the discriminated object is not
-- directly a hand.
if not Comes_From_Source (Actual)
and then Nkind (Actual) = N_Unchecked_Type_Conversion
and then Nkind (Act_Prev) = N_Explicit_Dereference
then
Add_Extra_Actual
(Expr => New_Occurrence_Of (Standard_False, Loc),
EF => Extra_Constrained (Formal));
else
Add_Extra_Actual
(Expr =>
Make_Attribute_Reference (Sloc (Prev),
Prefix =>
Duplicate_Subexpr_No_Checks
(Act_Prev, Name_Req => True),
Attribute_Name => Name_Constrained),
EF => Extra_Constrained (Formal));
end if;
end;
end if;
end if;
-- Create possible extra actual for accessibility level
if Present (Get_Accessibility (Formal)) then
-- Ada 2005 (AI-252): If the actual was rewritten as an Access
-- attribute, then the original actual may be an aliased object
-- occurring as the prefix in a call using "Object.Operation"
-- notation. In that case we must pass the level of the object,
-- so Prev_Orig is reset to Prev and the attribute will be
-- processed by the code for Access attributes further below.
if Prev_Orig /= Prev
and then Nkind (Prev) = N_Attribute_Reference
and then Get_Attribute_Id (Attribute_Name (Prev)) =
Attribute_Access
and then Is_Aliased_View (Prev_Orig)
then
Prev_Orig := Prev;
-- A class-wide precondition generates a test in which formals of
-- the subprogram are replaced by actuals that came from source.
-- In that case as well, the accessiblity comes from the actual.
-- This is the one case in which there are references to formals
-- outside of their subprogram.
elsif Prev_Orig /= Prev
and then Is_Entity_Name (Prev_Orig)
and then Present (Entity (Prev_Orig))
and then Is_Formal (Entity (Prev_Orig))
and then not In_Open_Scopes (Scope (Entity (Prev_Orig)))
then
Prev_Orig := Prev;
-- If the actual is a formal of an enclosing subprogram it is
-- the right entity, even if it is a rewriting. This happens
-- when the call is within an inherited condition or predicate.
elsif Is_Entity_Name (Actual)
and then Is_Formal (Entity (Actual))
and then In_Open_Scopes (Scope (Entity (Actual)))
then
Prev_Orig := Prev;
-- If the actual is an attribute reference that was expanded
-- into a reference to an entity, then get accessibility level
-- from that entity. AARM 6.1.1(27.d) says "... the implicit
-- constant declaration defines the accessibility level of X'Old".
elsif Nkind (Prev_Orig) = N_Attribute_Reference
and then Attribute_Name (Prev_Orig) in Name_Old | Name_Loop_Entry
and then Is_Entity_Name (Prev)
and then Present (Entity (Prev))
and then Is_Object (Entity (Prev))
then
Prev_Orig := Prev;
elsif Nkind (Prev_Orig) = N_Type_Conversion then
Prev_Orig := Expression (Prev_Orig);
end if;
-- Ada 2005 (AI-251): Thunks must propagate the extra actuals of
-- accessibility levels.
if Is_Thunk (Current_Scope) then
declare
Parm_Ent : Entity_Id;
begin
if Is_Controlling_Actual (Actual) then
-- Find the corresponding actual of the thunk
Parm_Ent := First_Entity (Current_Scope);
for J in 2 .. Param_Count loop
Next_Entity (Parm_Ent);
end loop;
-- Handle unchecked conversion of access types generated
-- in thunks (cf. Expand_Interface_Thunk).
elsif Is_Access_Type (Etype (Actual))
and then Nkind (Actual) = N_Unchecked_Type_Conversion
then
Parm_Ent := Entity (Expression (Actual));
else pragma Assert (Is_Entity_Name (Actual));
Parm_Ent := Entity (Actual);
end if;
Add_Extra_Actual
(Expr =>
New_Occurrence_Of (Get_Accessibility (Parm_Ent), Loc),
EF => Get_Accessibility (Formal));
end;
elsif Is_Entity_Name (Prev_Orig) then
-- When passing an access parameter, or a renaming of an access
-- parameter, as the actual to another access parameter we need
-- to pass along the actual's own access level parameter. This
-- is done if we are within the scope of the formal access
-- parameter (if this is an inlined body the extra formal is
-- irrelevant).
if (Is_Formal (Entity (Prev_Orig))
or else
(Present (Renamed_Object (Entity (Prev_Orig)))
and then
Is_Entity_Name (Renamed_Object (Entity (Prev_Orig)))
and then
Is_Formal
(Entity (Renamed_Object (Entity (Prev_Orig))))))
and then Ekind (Etype (Prev_Orig)) = E_Anonymous_Access_Type
and then In_Open_Scopes (Scope (Entity (Prev_Orig)))
then
declare
Parm_Ent : constant Entity_Id := Param_Entity (Prev_Orig);
begin
pragma Assert (Present (Parm_Ent));
if Present (Get_Accessibility (Parm_Ent)) then
Add_Extra_Actual
(Expr =>
New_Occurrence_Of
(Get_Accessibility (Parm_Ent), Loc),
EF => Get_Accessibility (Formal));
-- If the actual access parameter does not have an
-- associated extra formal providing its scope level,
-- then treat the actual as having library-level
-- accessibility.
else
Add_Extra_Actual
(Expr =>
Make_Integer_Literal (Loc,
Intval => Scope_Depth (Standard_Standard)),
EF => Get_Accessibility (Formal));
end if;
end;
-- The actual is a normal access value, so just pass the level
-- of the actual's access type.
else
Add_Extra_Actual
(Expr => Dynamic_Accessibility_Level (Prev_Orig),
EF => Get_Accessibility (Formal));
end if;
-- If the actual is an access discriminant, then pass the level
-- of the enclosing object (RM05-3.10.2(12.4/2)).
elsif Nkind (Prev_Orig) = N_Selected_Component
and then Ekind (Entity (Selector_Name (Prev_Orig))) =
E_Discriminant
and then Ekind (Etype (Entity (Selector_Name (Prev_Orig)))) =
E_Anonymous_Access_Type
then
Add_Extra_Actual
(Expr =>
Make_Integer_Literal (Loc,
Intval => Object_Access_Level (Prefix (Prev_Orig))),
EF => Get_Accessibility (Formal));
-- All other cases
else
case Nkind (Prev_Orig) is
when N_Attribute_Reference =>
case Get_Attribute_Id (Attribute_Name (Prev_Orig)) is
-- Ignore 'Result, 'Loop_Entry, and 'Old as they can
-- be used to identify access objects and do not have
-- an effect on accessibility level.
when Attribute_Loop_Entry
| Attribute_Old
| Attribute_Result
=>
null;
-- For X'Access, pass on the level of the prefix X
when Attribute_Access =>
-- Accessibility level of S'Access is that of A
Prev_Orig := Prefix (Prev_Orig);
-- If the expression is a view conversion, the
-- accessibility level is that of the expression.
if Nkind (Original_Node (Prev_Orig)) =
N_Type_Conversion
and then
Nkind (Expression (Original_Node (Prev_Orig))) =
N_Explicit_Dereference
then
Prev_Orig :=
Expression (Original_Node (Prev_Orig));
end if;
-- Obtain the ultimate prefix so we can check for
-- the case where we are taking 'Access of a
-- component of an anonymous access formal - which
-- would mean we need to pass said formal's
-- corresponding extra accessibility formal.
Prev_Ult := Ultimate_Prefix (Prev_Orig);
if Is_Entity_Name (Prev_Ult)
and then not Is_Type (Entity (Prev_Ult))
and then Present
(Get_Accessibility
(Entity (Prev_Ult)))
then
Add_Extra_Actual
(Expr =>
New_Occurrence_Of
(Get_Accessibility
(Entity (Prev_Ult)), Loc),
EF => Get_Accessibility (Formal));
-- Normal case, call Object_Access_Level. Note:
-- should be Dynamic_Accessibility_Level ???
else
Add_Extra_Actual
(Expr =>
Make_Integer_Literal (Loc,
Intval =>
Object_Access_Level (Prev_Orig)),
EF => Get_Accessibility (Formal));
end if;
-- Treat the unchecked attributes as library-level
when Attribute_Unchecked_Access
| Attribute_Unrestricted_Access
=>
Add_Extra_Actual
(Expr =>
Make_Integer_Literal (Loc,
Intval => Scope_Depth (Standard_Standard)),
EF => Get_Accessibility (Formal));
-- No other cases of attributes returning access
-- values that can be passed to access parameters.
when others =>
raise Program_Error;
end case;
-- For allocators we pass the level of the execution of the
-- called subprogram, which is one greater than the current
-- scope level. However, according to RM 3.10.2(14/3) this
-- is wrong since for an anonymous allocator defining the
-- value of an access parameter, the accessibility level is
-- that of the innermost master of the call???
when N_Allocator =>
Add_Extra_Actual
(Expr =>
Make_Integer_Literal (Loc,
Intval => Scope_Depth (Current_Scope) + 1),
EF => Get_Accessibility (Formal));
-- For most other cases we simply pass the level of the
-- actual's access type. The type is retrieved from
-- Prev rather than Prev_Orig, because in some cases
-- Prev_Orig denotes an original expression that has
-- not been analyzed.
-- However, when the actual is wrapped in a conditional
-- expression we must add a local temporary to store the
-- level at each branch, and, possibly, expand the call
-- into an expression with actions.
when others =>
if Nkind (Prev) = N_Expression_With_Actions
and then Nkind (Original_Node (Prev)) in
N_If_Expression | N_Case_Expression
then
declare
Decl : Node_Id;
pragma Warnings (Off, Decl);
-- Suppress warning for the final removal loop
Lvl : Entity_Id;
Res : Entity_Id;
Temp : Node_Id;
Typ : Node_Id;
procedure Insert_Level_Assign (Branch : Node_Id);
-- Recursivly add assignment of the level temporary
-- on each branch while moving through nested
-- conditional expressions.
-------------------------
-- Insert_Level_Assign --
-------------------------
procedure Insert_Level_Assign (Branch : Node_Id) is
procedure Expand_Branch (Res_Assn : Node_Id);
-- Perform expansion or iterate further within
-- nested conditionals given the object
-- declaration or assignment to result object
-- created during expansion which represents
-- a branch of the conditional expression.
-------------------
-- Expand_Branch --
-------------------
procedure Expand_Branch (Res_Assn : Node_Id) is
begin
pragma Assert (Nkind (Res_Assn) in
N_Assignment_Statement |
N_Object_Declaration);
-- There are more nested conditional
-- expressions so we must go deeper.
if Nkind (Expression (Res_Assn)) =
N_Expression_With_Actions
and then
Nkind
(Original_Node (Expression (Res_Assn)))
in N_Case_Expression | N_If_Expression
then
Insert_Level_Assign
(Expression (Res_Assn));
-- Add the level assignment
else
Insert_Before_And_Analyze (Res_Assn,
Make_Assignment_Statement (Loc,
Name =>
New_Occurrence_Of
(Lvl, Loc),
Expression =>
Dynamic_Accessibility_Level
(Expression (Res_Assn))));
end if;
end Expand_Branch;
Cond : Node_Id;
Alt : Node_Id;
-- Start of processing for Insert_Level_Assign
begin
-- Examine further nested condtionals
pragma Assert (Nkind (Branch) =
N_Expression_With_Actions);
-- Find the relevant statement in the actions
Cond := First (Actions (Branch));
while Present (Cond) loop
exit when Nkind (Cond) in
N_Case_Statement | N_If_Statement;
Next (Cond);
end loop;
-- The conditional expression may have been
-- optimized away, so examine the actions in
-- the branch.
if No (Cond) then
Expand_Branch (Last (Actions (Branch)));
-- Iterate through if expression branches
elsif Nkind (Cond) = N_If_Statement then
Expand_Branch (Last (Then_Statements (Cond)));
Expand_Branch (Last (Else_Statements (Cond)));
-- Iterate through case alternatives
elsif Nkind (Cond) = N_Case_Statement then
Alt := First (Alternatives (Cond));
while Present (Alt) loop
Expand_Branch (Last (Statements (Alt)));
Next (Alt);
end loop;
end if;
end Insert_Level_Assign;
-- Start of processing for cond expression case
begin
-- Create declaration of a temporary to store the
-- accessibility level of each branch of the
-- conditional expression.
Lvl := Make_Temporary (Loc, 'L');
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Lvl,
Object_Definition =>
New_Occurrence_Of (Standard_Natural, Loc));
-- Install the declaration and perform necessary
-- expansion if we are dealing with a function
-- call.
if Nkind (Call_Node) = N_Procedure_Call_Statement
then
-- Generate:
-- Lvl : Natural;
-- Call (
-- {do
-- If_Exp_Res : Typ;
-- if Cond then
-- Lvl := 0; -- Access level
-- If_Exp_Res := Exp;
-- ...
-- in If_Exp_Res end;},
-- Lvl,
-- ...
-- )
Insert_Before_And_Analyze (Call_Node, Decl);
-- A function call must be transformed into an
-- expression with actions.
else
-- Generate:
-- do
-- Lvl : Natural;
-- in Call (do{
-- If_Exp_Res : Typ
-- if Cond then
-- Lvl := 0; -- Access level
-- If_Exp_Res := Exp;
-- in If_Exp_Res end;},
-- Lvl,
-- ...
-- )
-- end;
Res := Make_Temporary (Loc, 'R');
Typ := Etype (Call_Node);
Temp := Relocate_Node (Call_Node);
-- Perform the rewrite with the dummy
Rewrite (Call_Node,
Make_Expression_With_Actions (Loc,
Expression => New_Occurrence_Of (Res, Loc),
Actions => New_List (
Decl,
Make_Object_Declaration (Loc,
Defining_Identifier => Res,
Object_Definition =>
New_Occurrence_Of (Typ, Loc)))));
-- Analyze the expression with the dummy
Analyze_And_Resolve (Call_Node, Typ);
-- Properly set the expression and move our view
-- of the call node
Set_Expression (Call_Node, Relocate_Node (Temp));
Call_Node := Expression (Call_Node);
-- Remove the declaration of the dummy and the
-- subsequent actions its analysis has created.
while Present (Remove_Next (Decl)) loop
null;
end loop;
end if;
-- Decorate the conditional expression with
-- assignments to our level temporary.
Insert_Level_Assign (Prev);
-- Make our level temporary the passed actual
Add_Extra_Actual
(Expr => New_Occurrence_Of (Lvl, Loc),
EF => Get_Accessibility (Formal));
end;
-- General case uncomplicated by conditional expressions
else
Add_Extra_Actual
(Expr => Dynamic_Accessibility_Level (Prev),
EF => Get_Accessibility (Formal));
end if;
end case;
end if;
end if;
-- Perform the check of 4.6(49) that prevents a null value from being
-- passed as an actual to an access parameter. Note that the check
-- is elided in the common cases of passing an access attribute or
-- access parameter as an actual. Also, we currently don't enforce
-- this check for expander-generated actuals and when -gnatdj is set.
if Ada_Version >= Ada_2005 then
-- Ada 2005 (AI-231): Check null-excluding access types. Note that
-- the intent of 6.4.1(13) is that null-exclusion checks should
-- not be done for 'out' parameters, even though it refers only
-- to constraint checks, and a null_exclusion is not a constraint.
-- Note that AI05-0196-1 corrects this mistake in the RM.
if Is_Access_Type (Etype (Formal))
and then Can_Never_Be_Null (Etype (Formal))
and then Ekind (Formal) /= E_Out_Parameter
and then Nkind (Prev) /= N_Raise_Constraint_Error
and then (Known_Null (Prev)
or else not Can_Never_Be_Null (Etype (Prev)))
then
Install_Null_Excluding_Check (Prev);
end if;
-- Ada_Version < Ada_2005
else
if Ekind (Etype (Formal)) /= E_Anonymous_Access_Type
or else Access_Checks_Suppressed (Subp)
then
null;
elsif Debug_Flag_J then
null;
elsif not Comes_From_Source (Prev) then
null;
elsif Is_Entity_Name (Prev)
and then Ekind (Etype (Prev)) = E_Anonymous_Access_Type
then
null;
elsif Nkind (Prev) in N_Allocator | N_Attribute_Reference then
null;
else
Install_Null_Excluding_Check (Prev);
end if;
end if;
-- Perform appropriate validity checks on parameters that
-- are entities.
if Validity_Checks_On then
if (Ekind (Formal) = E_In_Parameter
and then Validity_Check_In_Params)
or else
(Ekind (Formal) = E_In_Out_Parameter
and then Validity_Check_In_Out_Params)
then
-- If the actual is an indexed component of a packed type (or
-- is an indexed or selected component whose prefix recursively
-- meets this condition), it has not been expanded yet. It will
-- be copied in the validity code that follows, and has to be
-- expanded appropriately, so reanalyze it.
-- What we do is just to unset analyzed bits on prefixes till
-- we reach something that does not have a prefix.
declare
Nod : Node_Id;
begin
Nod := Actual;
while Nkind (Nod) in
N_Indexed_Component | N_Selected_Component
loop
Set_Analyzed (Nod, False);
Nod := Prefix (Nod);
end loop;
end;
Ensure_Valid (Actual);
end if;
end if;
-- For IN OUT and OUT parameters, ensure that subscripts are valid
-- since this is a left side reference. We only do this for calls
-- from the source program since we assume that compiler generated
-- calls explicitly generate any required checks. We also need it
-- only if we are doing standard validity checks, since clearly it is
-- not needed if validity checks are off, and in subscript validity
-- checking mode, all indexed components are checked with a call
-- directly from Expand_N_Indexed_Component.
if Comes_From_Source (Call_Node)
and then Ekind (Formal) /= E_In_Parameter
and then Validity_Checks_On
and then Validity_Check_Default
and then not Validity_Check_Subscripts
then
Check_Valid_Lvalue_Subscripts (Actual);
end if;
-- Mark any scalar OUT parameter that is a simple variable as no
-- longer known to be valid (unless the type is always valid). This
-- reflects the fact that if an OUT parameter is never set in a
-- procedure, then it can become invalid on the procedure return.
if Ekind (Formal) = E_Out_Parameter
and then Is_Entity_Name (Actual)
and then Ekind (Entity (Actual)) = E_Variable
and then not Is_Known_Valid (Etype (Actual))
then
Set_Is_Known_Valid (Entity (Actual), False);
end if;
-- For an OUT or IN OUT parameter, if the actual is an entity, then
-- clear current values, since they can be clobbered. We are probably
-- doing this in more places than we need to, but better safe than
-- sorry when it comes to retaining bad current values.
if Ekind (Formal) /= E_In_Parameter
and then Is_Entity_Name (Actual)
and then Present (Entity (Actual))
then
declare
Ent : constant Entity_Id := Entity (Actual);
Sav : Node_Id;
begin
-- For an OUT or IN OUT parameter that is an assignable entity,
-- we do not want to clobber the Last_Assignment field, since
-- if it is set, it was precisely because it is indeed an OUT
-- or IN OUT parameter. We do reset the Is_Known_Valid flag
-- since the subprogram could have returned in invalid value.
if Is_Assignable (Ent) then
Sav := Last_Assignment (Ent);
Kill_Current_Values (Ent);
Set_Last_Assignment (Ent, Sav);
Set_Is_Known_Valid (Ent, False);
Set_Is_True_Constant (Ent, False);
-- For all other cases, just kill the current values
else
Kill_Current_Values (Ent);
end if;
end;
end if;
-- If the formal is class wide and the actual is an aggregate, force
-- evaluation so that the back end who does not know about class-wide
-- type, does not generate a temporary of the wrong size.
if not Is_Class_Wide_Type (Etype (Formal)) then
null;
elsif Nkind (Actual) = N_Aggregate
or else (Nkind (Actual) = N_Qualified_Expression
and then Nkind (Expression (Actual)) = N_Aggregate)
then
Force_Evaluation (Actual);
end if;
-- In a remote call, if the formal is of a class-wide type, check
-- that the actual meets the requirements described in E.4(18).
if Remote and then Is_Class_Wide_Type (Etype (Formal)) then
Insert_Action (Actual,
Make_Transportable_Check (Loc,
Duplicate_Subexpr_Move_Checks (Actual)));
end if;
-- Perform invariant checks for all intermediate types in a view
-- conversion after successful return from a call that passes the
-- view conversion as an IN OUT or OUT parameter (RM 7.3.2 (12/3,
-- 13/3, 14/3)). Consider only source conversion in order to avoid
-- generating spurious checks on complex expansion such as object
-- initialization through an extension aggregate.
if Comes_From_Source (Call_Node)
and then Ekind (Formal) /= E_In_Parameter
and then Nkind (Actual) = N_Type_Conversion
then
Add_View_Conversion_Invariants (Formal, Actual);
end if;
-- Generating C the initialization of an allocator is performed by
-- means of individual statements, and hence it must be done before
-- the call.
if Modify_Tree_For_C
and then Nkind (Actual) = N_Allocator
and then Nkind (Expression (Actual)) = N_Qualified_Expression
then
Remove_Side_Effects (Actual);
end if;
-- This label is required when skipping extra actual generation for
-- Unchecked_Union parameters.
<<Skip_Extra_Actual_Generation>>
Param_Count := Param_Count + 1;
Next_Actual (Actual);
Next_Formal (Formal);
end loop;
-- If we are calling an Ada 2012 function which needs to have the
-- "accessibility level determined by the point of call" (AI05-0234)
-- passed in to it, then pass it in.
if Ekind (Subp) in E_Function | E_Operator | E_Subprogram_Type
and then
Present (Extra_Accessibility_Of_Result (Ultimate_Alias (Subp)))
then
declare
Ancestor : Node_Id := Parent (Call_Node);
Level : Node_Id := Empty;
Defer : Boolean := False;
begin
-- Unimplemented: if Subp returns an anonymous access type, then
-- a) if the call is the operand of an explict conversion, then
-- the target type of the conversion (a named access type)
-- determines the accessibility level pass in;
-- b) if the call defines an access discriminant of an object
-- (e.g., the discriminant of an object being created by an
-- allocator, or the discriminant of a function result),
-- then the accessibility level to pass in is that of the
-- discriminated object being initialized).
-- ???
while Nkind (Ancestor) = N_Qualified_Expression
loop
Ancestor := Parent (Ancestor);
end loop;
case Nkind (Ancestor) is
when N_Allocator =>
-- At this point, we'd like to assign
-- Level := Dynamic_Accessibility_Level (Ancestor);
-- but Etype of Ancestor may not have been set yet,
-- so that doesn't work.
-- Handle this later in Expand_Allocator_Expression.
Defer := True;
when N_Object_Declaration
| N_Object_Renaming_Declaration
=>
declare
Def_Id : constant Entity_Id :=
Defining_Identifier (Ancestor);
begin
if Is_Return_Object (Def_Id) then
if Present (Extra_Accessibility_Of_Result
(Return_Applies_To (Scope (Def_Id))))
then
-- Pass along value that was passed in if the
-- routine we are returning from also has an
-- Accessibility_Of_Result formal.
Level :=
New_Occurrence_Of
(Extra_Accessibility_Of_Result
(Return_Applies_To (Scope (Def_Id))), Loc);
end if;
else
Level :=
Make_Integer_Literal (Loc,
Intval => Object_Access_Level (Def_Id));
end if;
end;
when N_Simple_Return_Statement =>
if Present (Extra_Accessibility_Of_Result
(Return_Applies_To
(Return_Statement_Entity (Ancestor))))
then
-- Pass along value that was passed in if the returned
-- routine also has an Accessibility_Of_Result formal.
Level :=
New_Occurrence_Of
(Extra_Accessibility_Of_Result
(Return_Applies_To
(Return_Statement_Entity (Ancestor))), Loc);
end if;
when others =>
null;
end case;
if not Defer then
if not Present (Level) then
-- The "innermost master that evaluates the function call".
-- ??? - Should we use Integer'Last here instead in order
-- to deal with (some of) the problems associated with
-- calls to subps whose enclosing scope is unknown (e.g.,
-- Anon_Access_To_Subp_Param.all)?
Level :=
Make_Integer_Literal (Loc,
Intval => Scope_Depth (Current_Scope) + 1);
end if;
Add_Extra_Actual
(Expr => Level,
EF =>
Extra_Accessibility_Of_Result (Ultimate_Alias (Subp)));
end if;
end;
end if;
-- If we are expanding the RHS of an assignment we need to check if tag
-- propagation is needed. You might expect this processing to be in
-- Analyze_Assignment but has to be done earlier (bottom-up) because the
-- assignment might be transformed to a declaration for an unconstrained
-- value if the expression is classwide.
if Nkind (Call_Node) = N_Function_Call
and then Is_Tag_Indeterminate (Call_Node)
and then Is_Entity_Name (Name (Call_Node))
then
declare
Ass : Node_Id := Empty;
begin
if Nkind (Parent (Call_Node)) = N_Assignment_Statement then
Ass := Parent (Call_Node);
elsif Nkind (Parent (Call_Node)) = N_Qualified_Expression
and then Nkind (Parent (Parent (Call_Node))) =
N_Assignment_Statement
then
Ass := Parent (Parent (Call_Node));
elsif Nkind (Parent (Call_Node)) = N_Explicit_Dereference
and then Nkind (Parent (Parent (Call_Node))) =
N_Assignment_Statement
then
Ass := Parent (Parent (Call_Node));
end if;
if Present (Ass)
and then Is_Class_Wide_Type (Etype (Name (Ass)))
then
-- Move the error messages below to sem???
if Is_Access_Type (Etype (Call_Node)) then
if Designated_Type (Etype (Call_Node)) /=
Root_Type (Etype (Name (Ass)))
then
Error_Msg_NE
("tag-indeterminate expression must have designated "
& "type& (RM 5.2 (6))",
Call_Node, Root_Type (Etype (Name (Ass))));
else
Propagate_Tag (Name (Ass), Call_Node);
end if;
elsif Etype (Call_Node) /= Root_Type (Etype (Name (Ass))) then
Error_Msg_NE
("tag-indeterminate expression must have type & "
& "(RM 5.2 (6))",
Call_Node, Root_Type (Etype (Name (Ass))));
else
Propagate_Tag (Name (Ass), Call_Node);
end if;
-- The call will be rewritten as a dispatching call, and
-- expanded as such.
return;
end if;
end;
end if;
-- Ada 2005 (AI-251): If some formal is a class-wide interface, expand
-- it to point to the correct secondary virtual table.
if Nkind (Call_Node) in N_Subprogram_Call
and then CW_Interface_Formals_Present
then
Expand_Interface_Actuals (Call_Node);
end if;
-- Deals with Dispatch_Call if we still have a call, before expanding
-- extra actuals since this will be done on the re-analysis of the
-- dispatching call. Note that we do not try to shorten the actual list
-- for a dispatching call, it would not make sense to do so. Expansion
-- of dispatching calls is suppressed for VM targets, because the VM
-- back-ends directly handle the generation of dispatching calls and
-- would have to undo any expansion to an indirect call.
if Nkind (Call_Node) in N_Subprogram_Call
and then Present (Controlling_Argument (Call_Node))
then
declare
Call_Typ : constant Entity_Id := Etype (Call_Node);
Typ : constant Entity_Id := Find_Dispatching_Type (Subp);
Eq_Prim_Op : Entity_Id := Empty;
New_Call : Node_Id;
Param : Node_Id;
Prev_Call : Node_Id;
begin
if not Is_Limited_Type (Typ) then
Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
end if;
if Tagged_Type_Expansion then
Expand_Dispatching_Call (Call_Node);
-- The following return is worrisome. Is it really OK to skip
-- all remaining processing in this procedure ???
return;
-- VM targets
else
Apply_Tag_Checks (Call_Node);
-- If this is a dispatching "=", we must first compare the
-- tags so we generate: x.tag = y.tag and then x = y
if Subp = Eq_Prim_Op then
-- Mark the node as analyzed to avoid reanalyzing this
-- dispatching call (which would cause a never-ending loop)
Prev_Call := Relocate_Node (Call_Node);
Set_Analyzed (Prev_Call);
Param := First_Actual (Call_Node);
New_Call :=
Make_And_Then (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd =>
Make_Selected_Component (Loc,
Prefix => New_Value (Param),
Selector_Name =>
New_Occurrence_Of
(First_Tag_Component (Typ), Loc)),
Right_Opnd =>
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (Typ,
New_Value (Next_Actual (Param))),
Selector_Name =>
New_Occurrence_Of
(First_Tag_Component (Typ), Loc))),
Right_Opnd => Prev_Call);
Rewrite (Call_Node, New_Call);
Analyze_And_Resolve
(Call_Node, Call_Typ, Suppress => All_Checks);
end if;
-- Expansion of a dispatching call results in an indirect call,
-- which in turn causes current values to be killed (see
-- Resolve_Call), so on VM targets we do the call here to
-- ensure consistent warnings between VM and non-VM targets.
Kill_Current_Values;
end if;
-- If this is a dispatching "=" then we must update the reference
-- to the call node because we generated:
-- x.tag = y.tag and then x = y
if Subp = Eq_Prim_Op then
Call_Node := Right_Opnd (Call_Node);
end if;
end;
end if;
-- Similarly, expand calls to RCI subprograms on which pragma
-- All_Calls_Remote applies. The rewriting will be reanalyzed
-- later. Do this only when the call comes from source since we
-- do not want such a rewriting to occur in expanded code.
if Is_All_Remote_Call (Call_Node) then
Expand_All_Calls_Remote_Subprogram_Call (Call_Node);
-- Similarly, do not add extra actuals for an entry call whose entity
-- is a protected procedure, or for an internal protected subprogram
-- call, because it will be rewritten as a protected subprogram call
-- and reanalyzed (see Expand_Protected_Subprogram_Call).
elsif Is_Protected_Type (Scope (Subp))
and then Ekind (Subp) in E_Procedure | E_Function
then
null;
-- During that loop we gathered the extra actuals (the ones that
-- correspond to Extra_Formals), so now they can be appended.
else
while Is_Non_Empty_List (Extra_Actuals) loop
Add_Actual_Parameter (Remove_Head (Extra_Actuals));
end loop;
end if;
-- At this point we have all the actuals, so this is the point at which
-- the various expansion activities for actuals is carried out.
Expand_Actuals (Call_Node, Subp, Post_Call);
-- If it is a recursive call then call the internal procedure that
-- verifies Subprogram_Variant contract (if present and enabled).
-- Detecting calls to subprogram aliases is necessary for recursive
-- calls in instances of generic subprograms, where the renaming of
-- the current subprogram is called.
if Is_Subprogram (Subp)
and then Same_Or_Aliased_Subprograms (Subp, Current_Scope)
then
Check_Subprogram_Variant;
end if;
-- Verify that the actuals do not share storage. This check must be done
-- on the caller side rather that inside the subprogram to avoid issues
-- of parameter passing.
if Check_Aliasing_Of_Parameters then
Apply_Parameter_Aliasing_Checks (Call_Node, Subp);
end if;
-- If the subprogram is a renaming, or if it is inherited, replace it in
-- the call with the name of the actual subprogram being called. If this
-- is a dispatching call, the run-time decides what to call. The Alias
-- attribute does not apply to entries.
if Nkind (Call_Node) /= N_Entry_Call_Statement
and then No (Controlling_Argument (Call_Node))
and then Present (Parent_Subp)
and then not Is_Direct_Deep_Call (Subp)
then
if Present (Inherited_From_Formal (Subp)) then
Parent_Subp := Inherited_From_Formal (Subp);
else
Parent_Subp := Ultimate_Alias (Parent_Subp);
end if;
-- The below setting of Entity is suspect, see F109-018 discussion???
Set_Entity (Name (Call_Node), Parent_Subp);
-- Move this check to sem???
if Is_Abstract_Subprogram (Parent_Subp)
and then not In_Instance
then
Error_Msg_NE
("cannot call abstract subprogram &!",
Name (Call_Node), Parent_Subp);
end if;
-- Inspect all formals of derived subprogram Subp. Compare parameter
-- types with the parent subprogram and check whether an actual may
-- need a type conversion to the corresponding formal of the parent
-- subprogram.
-- Not clear whether intrinsic subprograms need such conversions. ???
if not Is_Intrinsic_Subprogram (Parent_Subp)
or else Is_Generic_Instance (Parent_Subp)
then
declare
procedure Convert (Act : Node_Id; Typ : Entity_Id);
-- Rewrite node Act as a type conversion of Act to Typ. Analyze
-- and resolve the newly generated construct.
-------------
-- Convert --
-------------
procedure Convert (Act : Node_Id; Typ : Entity_Id) is
begin
Rewrite (Act, OK_Convert_To (Typ, Act));
Analyze_And_Resolve (Act, Typ);
end Convert;
-- Local variables
Actual_Typ : Entity_Id;
Formal_Typ : Entity_Id;
Parent_Typ : Entity_Id;
begin
Actual := First_Actual (Call_Node);
Formal := First_Formal (Subp);
Parent_Formal := First_Formal (Parent_Subp);
while Present (Formal) loop
Actual_Typ := Etype (Actual);
Formal_Typ := Etype (Formal);
Parent_Typ := Etype (Parent_Formal);
-- For an IN parameter of a scalar type, the derived formal
-- type and parent formal type differ, and the parent formal
-- type and actual type do not match statically.
if Is_Scalar_Type (Formal_Typ)
and then Ekind (Formal) = E_In_Parameter
and then Formal_Typ /= Parent_Typ
and then
not Subtypes_Statically_Match (Parent_Typ, Actual_Typ)
and then not Raises_Constraint_Error (Actual)
then
Convert (Actual, Parent_Typ);
-- For access types, the parent formal type and actual type
-- differ.
elsif Is_Access_Type (Formal_Typ)
and then Base_Type (Parent_Typ) /= Base_Type (Actual_Typ)
then
if Ekind (Formal) /= E_In_Parameter then
Convert (Actual, Parent_Typ);
elsif Ekind (Parent_Typ) = E_Anonymous_Access_Type
and then Designated_Type (Parent_Typ) /=
Designated_Type (Actual_Typ)
and then not Is_Controlling_Formal (Formal)
then
-- This unchecked conversion is not necessary unless
-- inlining is enabled, because in that case the type
-- mismatch may become visible in the body about to be
-- inlined.
Rewrite (Actual,
Unchecked_Convert_To (Parent_Typ, Actual));
Analyze_And_Resolve (Actual, Parent_Typ);
end if;
-- If there is a change of representation, then generate a
-- warning, and do the change of representation.
elsif not Has_Compatible_Representation
(Target_Type => Formal_Typ,
Operand_Type => Parent_Typ)
then
Error_Msg_N
("??change of representation required", Actual);
Convert (Actual, Parent_Typ);
-- For array and record types, the parent formal type and
-- derived formal type have different sizes or pragma Pack
-- status.
elsif ((Is_Array_Type (Formal_Typ)
and then Is_Array_Type (Parent_Typ))
or else
(Is_Record_Type (Formal_Typ)
and then Is_Record_Type (Parent_Typ)))
and then
(Esize (Formal_Typ) /= Esize (Parent_Typ)
or else Has_Pragma_Pack (Formal_Typ) /=
Has_Pragma_Pack (Parent_Typ))
then
Convert (Actual, Parent_Typ);
end if;
Next_Actual (Actual);
Next_Formal (Formal);
Next_Formal (Parent_Formal);
end loop;
end;
end if;
Orig_Subp := Subp;
Subp := Parent_Subp;
end if;
-- Deal with case where call is an explicit dereference
if Nkind (Name (Call_Node)) = N_Explicit_Dereference then
-- Handle case of access to protected subprogram type
if Is_Access_Protected_Subprogram_Type
(Base_Type (Etype (Prefix (Name (Call_Node)))))
then
-- If this is a call through an access to protected operation, the
-- prefix has the form (object'address, operation'access). Rewrite
-- as a for other protected calls: the object is the 1st parameter
-- of the list of actuals.
declare
Call : Node_Id;
Parm : List_Id;
Nam : Node_Id;
Obj : Node_Id;
Ptr : constant Node_Id := Prefix (Name (Call_Node));
T : constant Entity_Id :=
Equivalent_Type (Base_Type (Etype (Ptr)));
D_T : constant Entity_Id :=
Designated_Type (Base_Type (Etype (Ptr)));
begin
Obj :=
Make_Selected_Component (Loc,
Prefix => Unchecked_Convert_To (T, Ptr),
Selector_Name =>
New_Occurrence_Of (First_Entity (T), Loc));
Nam :=
Make_Selected_Component (Loc,
Prefix => Unchecked_Convert_To (T, Ptr),
Selector_Name =>
New_Occurrence_Of (Next_Entity (First_Entity (T)), Loc));
Nam :=
Make_Explicit_Dereference (Loc,
Prefix => Nam);
if Present (Parameter_Associations (Call_Node)) then
Parm := Parameter_Associations (Call_Node);
else
Parm := New_List;
end if;
Prepend (Obj, Parm);
if Etype (D_T) = Standard_Void_Type then
Call :=
Make_Procedure_Call_Statement (Loc,
Name => Nam,
Parameter_Associations => Parm);
else
Call :=
Make_Function_Call (Loc,
Name => Nam,
Parameter_Associations => Parm);
end if;
Set_First_Named_Actual (Call, First_Named_Actual (Call_Node));
Set_Etype (Call, Etype (D_T));
-- We do not re-analyze the call to avoid infinite recursion.
-- We analyze separately the prefix and the object, and set
-- the checks on the prefix that would otherwise be emitted
-- when resolving a call.
Rewrite (Call_Node, Call);
Analyze (Nam);
Apply_Access_Check (Nam);
Analyze (Obj);
return;
end;
end if;
end if;
-- If this is a call to an intrinsic subprogram, then perform the
-- appropriate expansion to the corresponding tree node and we
-- are all done (since after that the call is gone).
-- In the case where the intrinsic is to be processed by the back end,
-- the call to Expand_Intrinsic_Call will do nothing, which is fine,
-- since the idea in this case is to pass the call unchanged. If the
-- intrinsic is an inherited unchecked conversion, and the derived type
-- is the target type of the conversion, we must retain it as the return
-- type of the expression. Otherwise the expansion below, which uses the
-- parent operation, will yield the wrong type.
if Is_Intrinsic_Subprogram (Subp) then
Expand_Intrinsic_Call (Call_Node, Subp);
if Nkind (Call_Node) = N_Unchecked_Type_Conversion
and then Parent_Subp /= Orig_Subp
and then Etype (Parent_Subp) /= Etype (Orig_Subp)
then
Set_Etype (Call_Node, Etype (Orig_Subp));
end if;
return;
end if;
if Ekind (Subp) in E_Function | E_Procedure then
-- We perform a simple optimization on calls for To_Address by
-- replacing them with an unchecked conversion. Not only is this
-- efficient, but it also avoids order of elaboration problems when
-- address clauses are inlined (address expression elaborated at the
-- wrong point).
-- We perform this optimization regardless of whether we are in the
-- main unit or in a unit in the context of the main unit, to ensure
-- that the generated tree is the same in both cases, for CodePeer
-- use.
if Is_RTE (Subp, RE_To_Address) then
Rewrite (Call_Node,
Unchecked_Convert_To
(RTE (RE_Address), Relocate_Node (First_Actual (Call_Node))));
return;
-- A call to a null procedure is replaced by a null statement, but we
-- are not allowed to ignore possible side effects of the call, so we
-- make sure that actuals are evaluated.
-- We also suppress this optimization for GNATcoverage.
elsif Is_Null_Procedure (Subp)
and then not Opt.Suppress_Control_Flow_Optimizations
then
Actual := First_Actual (Call_Node);
while Present (Actual) loop
Remove_Side_Effects (Actual);
Next_Actual (Actual);
end loop;
Rewrite (Call_Node, Make_Null_Statement (Loc));
return;
end if;
-- Handle inlining. No action needed if the subprogram is not inlined
if not Is_Inlined (Subp) then
null;
-- Front-end inlining of expression functions (performed also when
-- back-end inlining is enabled).
elsif Is_Inlinable_Expression_Function (Subp) then
Rewrite
(Call_Node, New_Copy (Expression_Of_Expression_Function (Subp)));
Analyze (Call_Node);
return;
-- Handle front-end inlining
elsif not Back_End_Inlining then
Inlined_Subprogram : declare
Bod : Node_Id;
Must_Inline : Boolean := False;
Spec : constant Node_Id := Unit_Declaration_Node (Subp);
begin
-- Verify that the body to inline has already been seen, and
-- that if the body is in the current unit the inlining does
-- not occur earlier. This avoids order-of-elaboration problems
-- in the back end.
-- This should be documented in sinfo/einfo ???
if No (Spec)
or else Nkind (Spec) /= N_Subprogram_Declaration
or else No (Body_To_Inline (Spec))
then
Must_Inline := False;
-- If this an inherited function that returns a private type,
-- do not inline if the full view is an unconstrained array,
-- because such calls cannot be inlined.
elsif Present (Orig_Subp)
and then Is_Array_Type (Etype (Orig_Subp))
and then not Is_Constrained (Etype (Orig_Subp))
then
Must_Inline := False;
elsif In_Unfrozen_Instance (Scope (Subp)) then
Must_Inline := False;
else
Bod := Body_To_Inline (Spec);
if (In_Extended_Main_Code_Unit (Call_Node)
or else In_Extended_Main_Code_Unit (Parent (Call_Node))
or else Has_Pragma_Inline_Always (Subp))
and then (not In_Same_Extended_Unit (Sloc (Bod), Loc)
or else
Earlier_In_Extended_Unit (Sloc (Bod), Loc))
then
Must_Inline := True;
-- If we are compiling a package body that is not the main
-- unit, it must be for inlining/instantiation purposes,
-- in which case we inline the call to insure that the same
-- temporaries are generated when compiling the body by
-- itself. Otherwise link errors can occur.
-- If the function being called is itself in the main unit,
-- we cannot inline, because there is a risk of double
-- elaboration and/or circularity: the inlining can make
-- visible a private entity in the body of the main unit,
-- that gigi will see before its sees its proper definition.
elsif not In_Extended_Main_Code_Unit (Call_Node)
and then In_Package_Body
then
Must_Inline := not In_Extended_Main_Source_Unit (Subp);
-- Inline calls to _postconditions when generating C code
elsif Modify_Tree_For_C
and then In_Same_Extended_Unit (Sloc (Bod), Loc)
and then Chars (Name (Call_Node)) = Name_uPostconditions
then
Must_Inline := True;
end if;
end if;
if Must_Inline then
Expand_Inlined_Call (Call_Node, Subp, Orig_Subp);
else
-- Let the back end handle it
Add_Inlined_Body (Subp, Call_Node);
if Front_End_Inlining
and then Nkind (Spec) = N_Subprogram_Declaration
and then In_Extended_Main_Code_Unit (Call_Node)
and then No (Body_To_Inline (Spec))
and then not Has_Completion (Subp)
and then In_Same_Extended_Unit (Sloc (Spec), Loc)
then
Cannot_Inline
("cannot inline& (body not seen yet)?",
Call_Node, Subp);
end if;
end if;
end Inlined_Subprogram;
-- Front-end expansion of simple functions returning unconstrained
-- types (see Check_And_Split_Unconstrained_Function). Note that the
-- case of a simple renaming (Body_To_Inline in N_Entity below, see
-- also Build_Renamed_Body) cannot be expanded here because this may
-- give rise to order-of-elaboration issues for the types of the
-- parameters of the subprogram, if any.
elsif Present (Unit_Declaration_Node (Subp))
and then Nkind (Unit_Declaration_Node (Subp)) =
N_Subprogram_Declaration
and then Present (Body_To_Inline (Unit_Declaration_Node (Subp)))
and then
Nkind (Body_To_Inline (Unit_Declaration_Node (Subp))) not in
N_Entity
then
Expand_Inlined_Call (Call_Node, Subp, Orig_Subp);
-- Back-end inlining either if optimization is enabled or the call is
-- required to be inlined.
elsif Optimization_Level > 0
or else Has_Pragma_Inline_Always (Subp)
then
Add_Inlined_Body (Subp, Call_Node);
end if;
end if;
-- Check for protected subprogram. This is either an intra-object call,
-- or a protected function call. Protected procedure calls are rewritten
-- as entry calls and handled accordingly.
-- In Ada 2005, this may be an indirect call to an access parameter that
-- is an access_to_subprogram. In that case the anonymous type has a
-- scope that is a protected operation, but the call is a regular one.
-- In either case do not expand call if subprogram is eliminated.
Scop := Scope (Subp);
if Nkind (Call_Node) /= N_Entry_Call_Statement
and then Is_Protected_Type (Scop)
and then Ekind (Subp) /= E_Subprogram_Type
and then not Is_Eliminated (Subp)
then
-- If the call is an internal one, it is rewritten as a call to the
-- corresponding unprotected subprogram.
Expand_Protected_Subprogram_Call (Call_Node, Subp, Scop);
end if;
-- Functions returning controlled objects need special attention. If
-- the return type is limited, then the context is initialization and
-- different processing applies. If the call is to a protected function,
-- the expansion above will call Expand_Call recursively. Otherwise the
-- function call is transformed into a temporary which obtains the
-- result from the secondary stack.
if Needs_Finalization (Etype (Subp)) then
if not Is_Build_In_Place_Function_Call (Call_Node)
and then
(No (First_Formal (Subp))
or else
not Is_Concurrent_Record_Type (Etype (First_Formal (Subp))))
then
Expand_Ctrl_Function_Call (Call_Node);
-- Build-in-place function calls which appear in anonymous contexts
-- need a transient scope to ensure the proper finalization of the
-- intermediate result after its use.
elsif Is_Build_In_Place_Function_Call (Call_Node)
and then Nkind (Parent (Unqual_Conv (Call_Node))) in
N_Attribute_Reference
| N_Function_Call
| N_Indexed_Component
| N_Object_Renaming_Declaration
| N_Procedure_Call_Statement
| N_Selected_Component
| N_Slice
and then
(Ekind (Current_Scope) /= E_Loop
or else Nkind (Parent (Call_Node)) /= N_Function_Call
or else not Is_Build_In_Place_Function_Call
(Parent (Call_Node)))
then
Establish_Transient_Scope (Call_Node, Manage_Sec_Stack => True);
end if;
end if;
end Expand_Call_Helper;
-------------------------------
-- Expand_Ctrl_Function_Call --
-------------------------------
procedure Expand_Ctrl_Function_Call (N : Node_Id) is
function Is_Element_Reference (N : Node_Id) return Boolean;
-- Determine whether node N denotes a reference to an Ada 2012 container
-- element.
--------------------------
-- Is_Element_Reference --
--------------------------
function Is_Element_Reference (N : Node_Id) return Boolean is
Ref : constant Node_Id := Original_Node (N);
begin
-- Analysis marks an element reference by setting the generalized
-- indexing attribute of an indexed component before the component
-- is rewritten into a function call.
return
Nkind (Ref) = N_Indexed_Component
and then Present (Generalized_Indexing (Ref));
end Is_Element_Reference;
-- Start of processing for Expand_Ctrl_Function_Call
begin
-- Optimization, if the returned value (which is on the sec-stack) is
-- returned again, no need to copy/readjust/finalize, we can just pass
-- the value thru (see Expand_N_Simple_Return_Statement), and thus no
-- attachment is needed
if Nkind (Parent (N)) = N_Simple_Return_Statement then
return;
end if;
-- Resolution is now finished, make sure we don't start analysis again
-- because of the duplication.
Set_Analyzed (N);
-- A function which returns a controlled object uses the secondary
-- stack. Rewrite the call into a temporary which obtains the result of
-- the function using 'reference.
Remove_Side_Effects (N);
-- The side effect removal of the function call produced a temporary.
-- When the context is a case expression, if expression, or expression
-- with actions, the lifetime of the temporary must be extended to match
-- that of the context. Otherwise the function result will be finalized
-- too early and affect the result of the expression. To prevent this
-- unwanted effect, the temporary should not be considered for clean up
-- actions by the general finalization machinery.
-- Exception to this rule are references to Ada 2012 container elements.
-- Such references must be finalized at the end of each iteration of the
-- related quantified expression, otherwise the container will remain
-- busy.
if Nkind (N) = N_Explicit_Dereference
and then Within_Case_Or_If_Expression (N)
and then not Is_Element_Reference (N)
then
Set_Is_Ignored_Transient (Entity (Prefix (N)));
end if;
end Expand_Ctrl_Function_Call;
----------------------------------------
-- Expand_N_Extended_Return_Statement --
----------------------------------------
-- If there is a Handled_Statement_Sequence, we rewrite this:
-- return Result : T := <expression> do
-- <handled_seq_of_stms>
-- end return;
-- to be:
-- declare
-- Result : T := <expression>;
-- begin
-- <handled_seq_of_stms>
-- return Result;
-- end;
-- Otherwise (no Handled_Statement_Sequence), we rewrite this:
-- return Result : T := <expression>;
-- to be:
-- return <expression>;
-- unless it's build-in-place or there's no <expression>, in which case
-- we generate:
-- declare
-- Result : T := <expression>;
-- begin
-- return Result;
-- end;
-- Note that this case could have been written by the user as an extended
-- return statement, or could have been transformed to this from a simple
-- return statement.
-- That is, we need to have a reified return object if there are statements
-- (which might refer to it) or if we're doing build-in-place (so we can
-- set its address to the final resting place or if there is no expression
-- (in which case default initial values might need to be set)).
procedure Expand_N_Extended_Return_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
function Build_Heap_Or_Pool_Allocator
(Temp_Id : Entity_Id;
Temp_Typ : Entity_Id;
Func_Id : Entity_Id;
Ret_Typ : Entity_Id;
Alloc_Expr : Node_Id) return Node_Id;
-- Create the statements necessary to allocate a return object on the
-- heap or user-defined storage pool. The object may need finalization
-- actions depending on the return type.
--
-- * Controlled case
--
-- if BIPfinalizationmaster = null then
-- Temp_Id := <Alloc_Expr>;
-- else
-- declare
-- type Ptr_Typ is access Ret_Typ;
-- for Ptr_Typ'Storage_Pool use
-- Base_Pool (BIPfinalizationmaster.all).all;
-- Local : Ptr_Typ;
--
-- begin
-- procedure Allocate (...) is
-- begin
-- System.Storage_Pools.Subpools.Allocate_Any (...);
-- end Allocate;
--
-- Local := <Alloc_Expr>;
-- Temp_Id := Temp_Typ (Local);
-- end;
-- end if;
--
-- * Non-controlled case
--
-- Temp_Id := <Alloc_Expr>;
--
-- Temp_Id is the temporary which is used to reference the internally
-- created object in all allocation forms. Temp_Typ is the type of the
-- temporary. Func_Id is the enclosing function. Ret_Typ is the return
-- type of Func_Id. Alloc_Expr is the actual allocator.
function Move_Activation_Chain (Func_Id : Entity_Id) return Node_Id;
-- Construct a call to System.Tasking.Stages.Move_Activation_Chain
-- with parameters:
-- From current activation chain
-- To activation chain passed in by the caller
-- New_Master master passed in by the caller
--
-- Func_Id is the entity of the function where the extended return
-- statement appears.
----------------------------------
-- Build_Heap_Or_Pool_Allocator --
----------------------------------
function Build_Heap_Or_Pool_Allocator
(Temp_Id : Entity_Id;
Temp_Typ : Entity_Id;
Func_Id : Entity_Id;
Ret_Typ : Entity_Id;
Alloc_Expr : Node_Id) return Node_Id
is
begin
pragma Assert (Is_Build_In_Place_Function (Func_Id));
-- Processing for objects that require finalization actions
if Needs_Finalization (Ret_Typ) then
declare
Decls : constant List_Id := New_List;
Fin_Mas_Id : constant Entity_Id :=
Build_In_Place_Formal
(Func_Id, BIP_Finalization_Master);
Orig_Expr : constant Node_Id :=
New_Copy_Tree
(Source => Alloc_Expr,
Scopes_In_EWA_OK => True);
Stmts : constant List_Id := New_List;
Desig_Typ : Entity_Id;
Local_Id : Entity_Id;
Pool_Id : Entity_Id;
Ptr_Typ : Entity_Id;
begin
-- Generate:
-- Pool_Id renames Base_Pool (BIPfinalizationmaster.all).all;
Pool_Id := Make_Temporary (Loc, 'P');
Append_To (Decls,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Pool_Id,
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Root_Storage_Pool), Loc),
Name =>
Make_Explicit_Dereference (Loc,
Prefix =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Base_Pool), Loc),
Parameter_Associations => New_List (
Make_Explicit_Dereference (Loc,
Prefix =>
New_Occurrence_Of (Fin_Mas_Id, Loc)))))));
-- Create an access type which uses the storage pool of the
-- caller's master. This additional type is necessary because
-- the finalization master cannot be associated with the type
-- of the temporary. Otherwise the secondary stack allocation
-- will fail.
Desig_Typ := Ret_Typ;
-- Ensure that the build-in-place machinery uses a fat pointer
-- when allocating an unconstrained array on the heap. In this
-- case the result object type is a constrained array type even
-- though the function type is unconstrained.
if Ekind (Desig_Typ) = E_Array_Subtype then
Desig_Typ := Base_Type (Desig_Typ);
end if;
-- Generate:
-- type Ptr_Typ is access Desig_Typ;
Ptr_Typ := Make_Temporary (Loc, 'P');
Append_To (Decls,
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Ptr_Typ,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
Subtype_Indication =>
New_Occurrence_Of (Desig_Typ, Loc))));
-- Perform minor decoration in order to set the master and the
-- storage pool attributes.
Set_Ekind (Ptr_Typ, E_Access_Type);
Set_Finalization_Master (Ptr_Typ, Fin_Mas_Id);
Set_Associated_Storage_Pool (Ptr_Typ, Pool_Id);
-- Create the temporary, generate:
-- Local_Id : Ptr_Typ;
Local_Id := Make_Temporary (Loc, 'T');
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Local_Id,
Object_Definition =>
New_Occurrence_Of (Ptr_Typ, Loc)));
-- Allocate the object, generate:
-- Local_Id := <Alloc_Expr>;
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Local_Id, Loc),
Expression => Alloc_Expr));
-- Generate:
-- Temp_Id := Temp_Typ (Local_Id);
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Temp_Id, Loc),
Expression =>
Unchecked_Convert_To (Temp_Typ,
New_Occurrence_Of (Local_Id, Loc))));
-- Wrap the allocation in a block. This is further conditioned
-- by checking the caller finalization master at runtime. A
-- null value indicates a non-existent master, most likely due
-- to a Finalize_Storage_Only allocation.
-- Generate:
-- if BIPfinalizationmaster = null then
-- Temp_Id := <Orig_Expr>;
-- else
-- declare
-- <Decls>
-- begin
-- <Stmts>
-- end;
-- end if;
return
Make_If_Statement (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd => New_Occurrence_Of (Fin_Mas_Id, Loc),
Right_Opnd => Make_Null (Loc)),
Then_Statements => New_List (
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Temp_Id, Loc),
Expression => Orig_Expr)),
Else_Statements => New_List (
Make_Block_Statement (Loc,
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stmts))));
end;
-- For all other cases, generate:
-- Temp_Id := <Alloc_Expr>;
else
return
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Temp_Id, Loc),
Expression => Alloc_Expr);
end if;
end Build_Heap_Or_Pool_Allocator;
---------------------------
-- Move_Activation_Chain --
---------------------------
function Move_Activation_Chain (Func_Id : Entity_Id) return Node_Id is
begin
return
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Move_Activation_Chain), Loc),
Parameter_Associations => New_List (
-- Source chain
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Name_uChain),
Attribute_Name => Name_Unrestricted_Access),
-- Destination chain
New_Occurrence_Of
(Build_In_Place_Formal (Func_Id, BIP_Activation_Chain), Loc),
-- New master
New_Occurrence_Of
(Build_In_Place_Formal (Func_Id, BIP_Task_Master), Loc)));
end Move_Activation_Chain;
-- Local variables
Func_Id : constant Entity_Id :=
Return_Applies_To (Return_Statement_Entity (N));
Is_BIP_Func : constant Boolean :=
Is_Build_In_Place_Function (Func_Id);
Ret_Obj_Id : constant Entity_Id :=
First_Entity (Return_Statement_Entity (N));
Ret_Obj_Decl : constant Node_Id := Parent (Ret_Obj_Id);
Ret_Typ : constant Entity_Id := Etype (Func_Id);
Exp : Node_Id;
HSS : Node_Id;
Result : Node_Id;
Stmts : List_Id;
Return_Stmt : Node_Id := Empty;
-- Force initialization to facilitate static analysis
-- Start of processing for Expand_N_Extended_Return_Statement
begin
-- Given that functionality of interface thunks is simple (just displace
-- the pointer to the object) they are always handled by means of
-- simple return statements.
pragma Assert (not Is_Thunk (Current_Subprogram));
if Nkind (Ret_Obj_Decl) = N_Object_Declaration then
Exp := Expression (Ret_Obj_Decl);
-- Assert that if F says "return R : T := G(...) do..."
-- then F and G are both b-i-p, or neither b-i-p.
if Nkind (Exp) = N_Function_Call then
pragma Assert (Ekind (Current_Subprogram) = E_Function);
pragma Assert
(Is_Build_In_Place_Function (Current_Subprogram) =
Is_Build_In_Place_Function_Call (Exp));
null;
end if;
-- Ada 2005 (AI95-344): If the result type is class-wide, then insert
-- a check that the level of the return expression's underlying type
-- is not deeper than the level of the master enclosing the function.
-- AI12-043: The check is made immediately after the return object
-- is created.
if Present (Exp) and then Is_Class_Wide_Type (Ret_Typ) then
Apply_CW_Accessibility_Check (Exp, Func_Id);
end if;
else
Exp := Empty;
end if;
HSS := Handled_Statement_Sequence (N);
-- If the returned object needs finalization actions, the function must
-- perform the appropriate cleanup should it fail to return. The state
-- of the function itself is tracked through a flag which is coupled
-- with the scope finalizer. There is one flag per each return object
-- in case of multiple returns.
if Is_BIP_Func and then Needs_Finalization (Etype (Ret_Obj_Id)) then
declare
Flag_Decl : Node_Id;
Flag_Id : Entity_Id;
Func_Bod : Node_Id;
begin
-- Recover the function body
Func_Bod := Unit_Declaration_Node (Func_Id);
if Nkind (Func_Bod) = N_Subprogram_Declaration then
Func_Bod := Parent (Parent (Corresponding_Body (Func_Bod)));
end if;
if Nkind (Func_Bod) = N_Function_Specification then
Func_Bod := Parent (Func_Bod); -- one more level for child units
end if;
pragma Assert (Nkind (Func_Bod) = N_Subprogram_Body);
-- Create a flag to track the function state
Flag_Id := Make_Temporary (Loc, 'F');
Set_Status_Flag_Or_Transient_Decl (Ret_Obj_Id, Flag_Id);
-- Insert the flag at the beginning of the function declarations,
-- generate:
-- Fnn : Boolean := False;
Flag_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Flag_Id,
Object_Definition =>
New_Occurrence_Of (Standard_Boolean, Loc),
Expression =>
New_Occurrence_Of (Standard_False, Loc));
Prepend_To (Declarations (Func_Bod), Flag_Decl);
Analyze (Flag_Decl);
end;
end if;
-- Build a simple_return_statement that returns the return object when
-- there is a statement sequence, or no expression, or the result will
-- be built in place. Note however that we currently do this for all
-- composite cases, even though not all are built in place.
if Present (HSS)
or else Is_Composite_Type (Ret_Typ)
or else No (Exp)
then
if No (HSS) then
Stmts := New_List;
-- If the extended return has a handled statement sequence, then wrap
-- it in a block and use the block as the first statement.
else
Stmts := New_List (
Make_Block_Statement (Loc,
Declarations => New_List,
Handled_Statement_Sequence => HSS));
end if;
-- If the result type contains tasks, we call Move_Activation_Chain.
-- Later, the cleanup code will call Complete_Master, which will
-- terminate any unactivated tasks belonging to the return statement
-- master. But Move_Activation_Chain updates their master to be that
-- of the caller, so they will not be terminated unless the return
-- statement completes unsuccessfully due to exception, abort, goto,
-- or exit. As a formality, we test whether the function requires the
-- result to be built in place, though that's necessarily true for
-- the case of result types with task parts.
if Is_BIP_Func and then Has_Task (Ret_Typ) then
-- The return expression is an aggregate for a complex type which
-- contains tasks. This particular case is left unexpanded since
-- the regular expansion would insert all temporaries and
-- initialization code in the wrong block.
if Nkind (Exp) = N_Aggregate then
Expand_N_Aggregate (Exp);
end if;
-- Do not move the activation chain if the return object does not
-- contain tasks.
if Has_Task (Etype (Ret_Obj_Id)) then
Append_To (Stmts, Move_Activation_Chain (Func_Id));
end if;
end if;
-- Update the state of the function right before the object is
-- returned.
if Is_BIP_Func and then Needs_Finalization (Etype (Ret_Obj_Id)) then
declare
Flag_Id : constant Entity_Id :=
Status_Flag_Or_Transient_Decl (Ret_Obj_Id);
begin
-- Generate:
-- Fnn := True;
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Flag_Id, Loc),
Expression => New_Occurrence_Of (Standard_True, Loc)));
end;
end if;
-- Build a simple_return_statement that returns the return object
Return_Stmt :=
Make_Simple_Return_Statement (Loc,
Expression => New_Occurrence_Of (Ret_Obj_Id, Loc));
Append_To (Stmts, Return_Stmt);
HSS := Make_Handled_Sequence_Of_Statements (Loc, Stmts);
end if;
-- Case where we build a return statement block
if Present (HSS) then
Result :=
Make_Block_Statement (Loc,
Declarations => Return_Object_Declarations (N),
Handled_Statement_Sequence => HSS);
-- We set the entity of the new block statement to be that of the
-- return statement. This is necessary so that various fields, such
-- as Finalization_Chain_Entity carry over from the return statement
-- to the block. Note that this block is unusual, in that its entity
-- is an E_Return_Statement rather than an E_Block.
Set_Identifier
(Result, New_Occurrence_Of (Return_Statement_Entity (N), Loc));
-- If the object decl was already rewritten as a renaming, then we
-- don't want to do the object allocation and transformation of
-- the return object declaration to a renaming. This case occurs
-- when the return object is initialized by a call to another
-- build-in-place function, and that function is responsible for
-- the allocation of the return object.
if Is_BIP_Func
and then Nkind (Ret_Obj_Decl) = N_Object_Renaming_Declaration
then
pragma Assert
(Nkind (Original_Node (Ret_Obj_Decl)) = N_Object_Declaration
and then
-- It is a regular BIP object declaration
(Is_Build_In_Place_Function_Call
(Expression (Original_Node (Ret_Obj_Decl)))
-- It is a BIP object declaration that displaces the pointer
-- to the object to reference a convered interface type.
or else
Present (Unqual_BIP_Iface_Function_Call
(Expression (Original_Node (Ret_Obj_Decl))))));
-- Return the build-in-place result by reference
Set_By_Ref (Return_Stmt);
elsif Is_BIP_Func then
-- Locate the implicit access parameter associated with the
-- caller-supplied return object and convert the return
-- statement's return object declaration to a renaming of a
-- dereference of the access parameter. If the return object's
-- declaration includes an expression that has not already been
-- expanded as separate assignments, then add an assignment
-- statement to ensure the return object gets initialized.
-- declare
-- Result : T [:= <expression>];
-- begin
-- ...
-- is converted to
-- declare
-- Result : T renames FuncRA.all;
-- [Result := <expression;]
-- begin
-- ...
declare
Ret_Obj_Expr : constant Node_Id := Expression (Ret_Obj_Decl);
Ret_Obj_Typ : constant Entity_Id := Etype (Ret_Obj_Id);
Init_Assignment : Node_Id := Empty;
Obj_Acc_Formal : Entity_Id;
Obj_Acc_Deref : Node_Id;
Obj_Alloc_Formal : Entity_Id;
begin
-- Build-in-place results must be returned by reference
Set_By_Ref (Return_Stmt);
-- Retrieve the implicit access parameter passed by the caller
Obj_Acc_Formal :=
Build_In_Place_Formal (Func_Id, BIP_Object_Access);
-- If the return object's declaration includes an expression
-- and the declaration isn't marked as No_Initialization, then
-- we need to generate an assignment to the object and insert
-- it after the declaration before rewriting it as a renaming
-- (otherwise we'll lose the initialization). The case where
-- the result type is an interface (or class-wide interface)
-- is also excluded because the context of the function call
-- must be unconstrained, so the initialization will always
-- be done as part of an allocator evaluation (storage pool
-- or secondary stack), never to a constrained target object
-- passed in by the caller. Besides the assignment being
-- unneeded in this case, it avoids problems with trying to
-- generate a dispatching assignment when the return expression
-- is a nonlimited descendant of a limited interface (the
-- interface has no assignment operation).
if Present (Ret_Obj_Expr)
and then not No_Initialization (Ret_Obj_Decl)
and then not Is_Interface (Ret_Obj_Typ)
then
Init_Assignment :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Ret_Obj_Id, Loc),
Expression =>
New_Copy_Tree
(Source => Ret_Obj_Expr,
Scopes_In_EWA_OK => True));
Set_Etype (Name (Init_Assignment), Etype (Ret_Obj_Id));
Set_Assignment_OK (Name (Init_Assignment));
Set_No_Ctrl_Actions (Init_Assignment);
Set_Parent (Name (Init_Assignment), Init_Assignment);
Set_Parent (Expression (Init_Assignment), Init_Assignment);
Set_Expression (Ret_Obj_Decl, Empty);
if Is_Class_Wide_Type (Etype (Ret_Obj_Id))
and then not Is_Class_Wide_Type
(Etype (Expression (Init_Assignment)))
then
Rewrite (Expression (Init_Assignment),
Make_Type_Conversion (Loc,
Subtype_Mark =>
New_Occurrence_Of (Etype (Ret_Obj_Id), Loc),
Expression =>
Relocate_Node (Expression (Init_Assignment))));
end if;
-- In the case of functions where the calling context can
-- determine the form of allocation needed, initialization
-- is done with each part of the if statement that handles
-- the different forms of allocation (this is true for
-- unconstrained, tagged, and controlled result subtypes).
if not Needs_BIP_Alloc_Form (Func_Id) then
Insert_After (Ret_Obj_Decl, Init_Assignment);
end if;
end if;
-- When the function's subtype is unconstrained, a run-time
-- test may be needed to decide the form of allocation to use
-- for the return object. The function has an implicit formal
-- parameter indicating this. If the BIP_Alloc_Form formal has
-- the value one, then the caller has passed access to an
-- existing object for use as the return object. If the value
-- is two, then the return object must be allocated on the
-- secondary stack. Otherwise, the object must be allocated in
-- a storage pool. We generate an if statement to test the
-- implicit allocation formal and initialize a local access
-- value appropriately, creating allocators in the secondary
-- stack and global heap cases. The special formal also exists
-- and must be tested when the function has a tagged result,
-- even when the result subtype is constrained, because in
-- general such functions can be called in dispatching contexts
-- and must be handled similarly to functions with a class-wide
-- result.
if Needs_BIP_Alloc_Form (Func_Id) then
Obj_Alloc_Formal :=
Build_In_Place_Formal (Func_Id, BIP_Alloc_Form);
declare
Pool_Id : constant Entity_Id :=
Make_Temporary (Loc, 'P');
Alloc_Obj_Id : Entity_Id;
Alloc_Obj_Decl : Node_Id;
Alloc_If_Stmt : Node_Id;
Guard_Except : Node_Id;
Heap_Allocator : Node_Id;
Pool_Decl : Node_Id;
Pool_Allocator : Node_Id;
Ptr_Type_Decl : Node_Id;
Ref_Type : Entity_Id;
SS_Allocator : Node_Id;
begin
-- Create an access type designating the function's
-- result subtype.
Ref_Type := Make_Temporary (Loc, 'A');
Ptr_Type_Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Ref_Type,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
All_Present => True,
Subtype_Indication =>
New_Occurrence_Of (Ret_Obj_Typ, Loc)));
Insert_Before (Ret_Obj_Decl, Ptr_Type_Decl);
-- Create an access object that will be initialized to an
-- access value denoting the return object, either coming
-- from an implicit access value passed in by the caller
-- or from the result of an allocator.
Alloc_Obj_Id := Make_Temporary (Loc, 'R');
Set_Etype (Alloc_Obj_Id, Ref_Type);
Alloc_Obj_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Alloc_Obj_Id,
Object_Definition =>
New_Occurrence_Of (Ref_Type, Loc));
Insert_Before (Ret_Obj_Decl, Alloc_Obj_Decl);
-- Create allocators for both the secondary stack and
-- global heap. If there's an initialization expression,
-- then create these as initialized allocators.
if Present (Ret_Obj_Expr)
and then not No_Initialization (Ret_Obj_Decl)
then
-- Always use the type of the expression for the
-- qualified expression, rather than the result type.
-- In general we cannot always use the result type
-- for the allocator, because the expression might be
-- of a specific type, such as in the case of an
-- aggregate or even a nonlimited object when the
-- result type is a limited class-wide interface type.
Heap_Allocator :=
Make_Allocator (Loc,
Expression =>
Make_Qualified_Expression (Loc,
Subtype_Mark =>
New_Occurrence_Of
(Etype (Ret_Obj_Expr), Loc),
Expression =>
New_Copy_Tree
(Source => Ret_Obj_Expr,
Scopes_In_EWA_OK => True)));
else
-- If the function returns a class-wide type we cannot
-- use the return type for the allocator. Instead we
-- use the type of the expression, which must be an
-- aggregate of a definite type.
if Is_Class_Wide_Type (Ret_Obj_Typ) then
Heap_Allocator :=
Make_Allocator (Loc,
Expression =>
New_Occurrence_Of
(Etype (Ret_Obj_Expr), Loc));
else
Heap_Allocator :=
Make_Allocator (Loc,
Expression =>
New_Occurrence_Of (Ret_Obj_Typ, Loc));
end if;
-- If the object requires default initialization then
-- that will happen later following the elaboration of
-- the object renaming. If we don't turn it off here
-- then the object will be default initialized twice.
Set_No_Initialization (Heap_Allocator);
end if;
-- Set the flag indicating that the allocator came from
-- a build-in-place return statement, so we can avoid
-- adjusting the allocated object. Note that this flag
-- will be inherited by the copies made below.
Set_Alloc_For_BIP_Return (Heap_Allocator);
-- The Pool_Allocator is just like the Heap_Allocator,
-- except we set Storage_Pool and Procedure_To_Call so
-- it will use the user-defined storage pool.
Pool_Allocator :=
New_Copy_Tree
(Source => Heap_Allocator,
Scopes_In_EWA_OK => True);
pragma Assert (Alloc_For_BIP_Return (Pool_Allocator));
-- Do not generate the renaming of the build-in-place
-- pool parameter on ZFP because the parameter is not
-- created in the first place.
if RTE_Available (RE_Root_Storage_Pool_Ptr) then
Pool_Decl :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Pool_Id,
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Root_Storage_Pool), Loc),
Name =>
Make_Explicit_Dereference (Loc,
New_Occurrence_Of
(Build_In_Place_Formal
(Func_Id, BIP_Storage_Pool), Loc)));
Set_Storage_Pool (Pool_Allocator, Pool_Id);
Set_Procedure_To_Call
(Pool_Allocator, RTE (RE_Allocate_Any));
else
Pool_Decl := Make_Null_Statement (Loc);
end if;
-- If the No_Allocators restriction is active, then only
-- an allocator for secondary stack allocation is needed.
-- It's OK for such allocators to have Comes_From_Source
-- set to False, because gigi knows not to flag them as
-- being a violation of No_Implicit_Heap_Allocations.
if Restriction_Active (No_Allocators) then
SS_Allocator := Heap_Allocator;
Heap_Allocator := Make_Null (Loc);
Pool_Allocator := Make_Null (Loc);
-- Otherwise the heap and pool allocators may be needed,
-- so we make another allocator for secondary stack
-- allocation.
else
SS_Allocator :=
New_Copy_Tree
(Source => Heap_Allocator,
Scopes_In_EWA_OK => True);
pragma Assert (Alloc_For_BIP_Return (SS_Allocator));
-- The heap and pool allocators are marked as
-- Comes_From_Source since they correspond to an
-- explicit user-written allocator (that is, it will
-- only be executed on behalf of callers that call the
-- function as initialization for such an allocator).
-- Prevents errors when No_Implicit_Heap_Allocations
-- is in force.
Set_Comes_From_Source (Heap_Allocator, True);
Set_Comes_From_Source (Pool_Allocator, True);
end if;
-- The allocator is returned on the secondary stack
Check_Restriction (No_Secondary_Stack, N);
Set_Storage_Pool (SS_Allocator, RTE (RE_SS_Pool));
Set_Procedure_To_Call
(SS_Allocator, RTE (RE_SS_Allocate));
-- The allocator is returned on the secondary stack,
-- so indicate that the function return, as well as
-- all blocks that encloses the allocator, must not
-- release it. The flags must be set now because
-- the decision to use the secondary stack is done
-- very late in the course of expanding the return
-- statement, past the point where these flags are
-- normally set.
Set_Uses_Sec_Stack (Func_Id);
Set_Uses_Sec_Stack (Return_Statement_Entity (N));
Set_Sec_Stack_Needed_For_Return
(Return_Statement_Entity (N));
Set_Enclosing_Sec_Stack_Return (N);
-- Guard against poor expansion on the caller side by
-- using a raise statement to catch out-of-range values
-- of formal parameter BIP_Alloc_Form.
if Exceptions_OK then
Guard_Except :=
Make_Raise_Program_Error (Loc,
Reason => PE_Build_In_Place_Mismatch);
else
Guard_Except := Make_Null_Statement (Loc);
end if;
-- Create an if statement to test the BIP_Alloc_Form
-- formal and initialize the access object to either the
-- BIP_Object_Access formal (BIP_Alloc_Form =
-- Caller_Allocation), the result of allocating the
-- object in the secondary stack (BIP_Alloc_Form =
-- Secondary_Stack), or else an allocator to create the
-- return object in the heap or user-defined pool
-- (BIP_Alloc_Form = Global_Heap or User_Storage_Pool).
-- ??? An unchecked type conversion must be made in the
-- case of assigning the access object formal to the
-- local access object, because a normal conversion would
-- be illegal in some cases (such as converting access-
-- to-unconstrained to access-to-constrained), but the
-- the unchecked conversion will presumably fail to work
-- right in just such cases. It's not clear at all how to
-- handle this. ???
Alloc_If_Stmt :=
Make_If_Statement (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (Obj_Alloc_Formal, Loc),
Right_Opnd =>
Make_Integer_Literal (Loc,
UI_From_Int (BIP_Allocation_Form'Pos
(Caller_Allocation)))),
Then_Statements => New_List (
Make_Assignment_Statement (Loc,
Name =>
New_Occurrence_Of (Alloc_Obj_Id, Loc),
Expression =>
Make_Unchecked_Type_Conversion (Loc,
Subtype_Mark =>
New_Occurrence_Of (Ref_Type, Loc),
Expression =>
New_Occurrence_Of (Obj_Acc_Formal, Loc)))),
Elsif_Parts => New_List (
Make_Elsif_Part (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (Obj_Alloc_Formal, Loc),
Right_Opnd =>
Make_Integer_Literal (Loc,
UI_From_Int (BIP_Allocation_Form'Pos
(Secondary_Stack)))),
Then_Statements => New_List (
Make_Assignment_Statement (Loc,
Name =>
New_Occurrence_Of (Alloc_Obj_Id, Loc),
Expression => SS_Allocator))),
Make_Elsif_Part (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (Obj_Alloc_Formal, Loc),
Right_Opnd =>
Make_Integer_Literal (Loc,
UI_From_Int (BIP_Allocation_Form'Pos
(Global_Heap)))),
Then_Statements => New_List (
Build_Heap_Or_Pool_Allocator
(Temp_Id => Alloc_Obj_Id,
Temp_Typ => Ref_Type,
Func_Id => Func_Id,
Ret_Typ => Ret_Obj_Typ,
Alloc_Expr => Heap_Allocator))),
-- ???If all is well, we can put the following
-- 'elsif' in the 'else', but this is a useful
-- self-check in case caller and callee don't agree
-- on whether BIPAlloc and so on should be passed.
Make_Elsif_Part (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (Obj_Alloc_Formal, Loc),
Right_Opnd =>
Make_Integer_Literal (Loc,
UI_From_Int (BIP_Allocation_Form'Pos
(User_Storage_Pool)))),
Then_Statements => New_List (
Pool_Decl,
Build_Heap_Or_Pool_Allocator
(Temp_Id => Alloc_Obj_Id,
Temp_Typ => Ref_Type,
Func_Id => Func_Id,
Ret_Typ => Ret_Obj_Typ,
Alloc_Expr => Pool_Allocator)))),
-- Raise Program_Error if it's none of the above;
-- this is a compiler bug.
Else_Statements => New_List (Guard_Except));
-- If a separate initialization assignment was created
-- earlier, append that following the assignment of the
-- implicit access formal to the access object, to ensure
-- that the return object is initialized in that case. In
-- this situation, the target of the assignment must be
-- rewritten to denote a dereference of the access to the
-- return object passed in by the caller.
if Present (Init_Assignment) then
Rewrite (Name (Init_Assignment),
Make_Explicit_Dereference (Loc,
Prefix => New_Occurrence_Of (Alloc_Obj_Id, Loc)));
pragma Assert
(Assignment_OK
(Original_Node (Name (Init_Assignment))));
Set_Assignment_OK (Name (Init_Assignment));
Set_Etype (Name (Init_Assignment), Etype (Ret_Obj_Id));
Append_To
(Then_Statements (Alloc_If_Stmt), Init_Assignment);
end if;
Insert_Before (Ret_Obj_Decl, Alloc_If_Stmt);
-- Remember the local access object for use in the
-- dereference of the renaming created below.
Obj_Acc_Formal := Alloc_Obj_Id;
end;
-- When the function's subtype is unconstrained and a run-time
-- test is not needed, we nevertheless need to build the return
-- using the function's result subtype.
elsif not Is_Constrained (Underlying_Type (Etype (Func_Id)))
then
declare
Alloc_Obj_Id : Entity_Id;
Alloc_Obj_Decl : Node_Id;
Ptr_Type_Decl : Node_Id;
Ref_Type : Entity_Id;
begin
-- Create an access type designating the function's
-- result subtype.
Ref_Type := Make_Temporary (Loc, 'A');
Ptr_Type_Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Ref_Type,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
All_Present => True,
Subtype_Indication =>
New_Occurrence_Of (Ret_Obj_Typ, Loc)));
Insert_Before (Ret_Obj_Decl, Ptr_Type_Decl);
-- Create an access object initialized to the conversion
-- of the implicit access value passed in by the caller.
Alloc_Obj_Id := Make_Temporary (Loc, 'R');
Set_Etype (Alloc_Obj_Id, Ref_Type);
-- See the ??? comment a few lines above about the use of
-- an unchecked conversion here.
Alloc_Obj_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Alloc_Obj_Id,
Object_Definition =>
New_Occurrence_Of (Ref_Type, Loc),
Expression =>
Make_Unchecked_Type_Conversion (Loc,
Subtype_Mark =>
New_Occurrence_Of (Ref_Type, Loc),
Expression =>
New_Occurrence_Of (Obj_Acc_Formal, Loc)));
Insert_Before (Ret_Obj_Decl, Alloc_Obj_Decl);
-- Remember the local access object for use in the
-- dereference of the renaming created below.
Obj_Acc_Formal := Alloc_Obj_Id;
end;
end if;
-- Replace the return object declaration with a renaming of a
-- dereference of the access value designating the return
-- object.
Obj_Acc_Deref :=
Make_Explicit_Dereference (Loc,
Prefix => New_Occurrence_Of (Obj_Acc_Formal, Loc));
Rewrite (Ret_Obj_Decl,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Ret_Obj_Id,
Access_Definition => Empty,
Subtype_Mark => New_Occurrence_Of (Ret_Obj_Typ, Loc),
Name => Obj_Acc_Deref));
Set_Renamed_Object (Ret_Obj_Id, Obj_Acc_Deref);
end;
end if;
-- Case where we do not build a block
else
-- We're about to drop Return_Object_Declarations on the floor, so
-- we need to insert it, in case it got expanded into useful code.
-- Remove side effects from expression, which may be duplicated in
-- subsequent checks (see Expand_Simple_Function_Return).
Insert_List_Before (N, Return_Object_Declarations (N));
Remove_Side_Effects (Exp);
-- Build simple_return_statement that returns the expression directly
Return_Stmt := Make_Simple_Return_Statement (Loc, Expression => Exp);
Result := Return_Stmt;
end if;
-- Set the flag to prevent infinite recursion
Set_Comes_From_Extended_Return_Statement (Return_Stmt);
Rewrite (N, Result);
-- AI12-043: The checks of 6.5(8.1/3) and 6.5(21/3) are made immediately
-- before an object is returned. A predicate that applies to the return
-- subtype is checked immediately before an object is returned.
-- Suppress access checks to avoid generating extra checks for b-i-p.
Analyze (N, Suppress => Access_Check);
end Expand_N_Extended_Return_Statement;
----------------------------
-- Expand_N_Function_Call --
----------------------------
procedure Expand_N_Function_Call (N : Node_Id) is
begin
Expand_Call (N);
end Expand_N_Function_Call;
---------------------------------------
-- Expand_N_Procedure_Call_Statement --
---------------------------------------
procedure Expand_N_Procedure_Call_Statement (N : Node_Id) is
begin
Expand_Call (N);
end Expand_N_Procedure_Call_Statement;
--------------------------------------
-- Expand_N_Simple_Return_Statement --
--------------------------------------
procedure Expand_N_Simple_Return_Statement (N : Node_Id) is
begin
-- Defend against previous errors (i.e. the return statement calls a
-- function that is not available in configurable runtime).
if Present (Expression (N))
and then Nkind (Expression (N)) = N_Empty
then
Check_Error_Detected;
return;
end if;
-- Distinguish the function and non-function cases:
case Ekind (Return_Applies_To (Return_Statement_Entity (N))) is
when E_Function
| E_Generic_Function
=>
Expand_Simple_Function_Return (N);
when E_Entry
| E_Entry_Family
| E_Generic_Procedure
| E_Procedure
| E_Return_Statement
=>
Expand_Non_Function_Return (N);
when others =>
raise Program_Error;
end case;
exception
when RE_Not_Available =>
return;
end Expand_N_Simple_Return_Statement;
------------------------------
-- Expand_N_Subprogram_Body --
------------------------------
-- Add dummy push/pop label nodes at start and end to clear any local
-- exception indications if local-exception-to-goto optimization is active.
-- Add return statement if last statement in body is not a return statement
-- (this makes things easier on Gigi which does not want to have to handle
-- a missing return).
-- Add call to Activate_Tasks if body is a task activator
-- Deal with possible detection of infinite recursion
-- Eliminate body completely if convention stubbed
-- Encode entity names within body, since we will not need to reference
-- these entities any longer in the front end.
-- Initialize scalar out parameters if Initialize/Normalize_Scalars
-- Reset Pure indication if any parameter has root type System.Address
-- or has any parameters of limited types, where limited means that the
-- run-time view is limited (i.e. the full type is limited).
-- Wrap thread body
procedure Expand_N_Subprogram_Body (N : Node_Id) is
Body_Id : constant Entity_Id := Defining_Entity (N);
HSS : constant Node_Id := Handled_Statement_Sequence (N);
Loc : constant Source_Ptr := Sloc (N);
procedure Add_Return (Spec_Id : Entity_Id; Stmts : List_Id);
-- Append a return statement to the statement sequence Stmts if the last
-- statement is not already a return or a goto statement. Note that the
-- latter test is not critical, it does not matter if we add a few extra
-- returns, since they get eliminated anyway later on. Spec_Id denotes
-- the corresponding spec of the subprogram body.
----------------
-- Add_Return --
----------------
procedure Add_Return (Spec_Id : Entity_Id; Stmts : List_Id) is
Last_Stmt : Node_Id;
Loc : Source_Ptr;
Stmt : Node_Id;
begin
-- Get last statement, ignoring any Pop_xxx_Label nodes, which are
-- not relevant in this context since they are not executable.
Last_Stmt := Last (Stmts);
while Nkind (Last_Stmt) in N_Pop_xxx_Label loop
Prev (Last_Stmt);
end loop;
-- Now insert return unless last statement is a transfer
if not Is_Transfer (Last_Stmt) then
-- The source location for the return is the end label of the
-- procedure if present. Otherwise use the sloc of the last
-- statement in the list. If the list comes from a generated
-- exception handler and we are not debugging generated code,
-- all the statements within the handler are made invisible
-- to the debugger.
if Nkind (Parent (Stmts)) = N_Exception_Handler
and then not Comes_From_Source (Parent (Stmts))
then
Loc := Sloc (Last_Stmt);
elsif Present (End_Label (HSS)) then
Loc := Sloc (End_Label (HSS));
else
Loc := Sloc (Last_Stmt);
end if;
-- Append return statement, and set analyzed manually. We can't
-- call Analyze on this return since the scope is wrong.
-- Note: it almost works to push the scope and then do the Analyze
-- call, but something goes wrong in some weird cases and it is
-- not worth worrying about ???
Stmt := Make_Simple_Return_Statement (Loc);
-- The return statement is handled properly, and the call to the
-- postcondition, inserted below, does not require information
-- from the body either. However, that call is analyzed in the
-- enclosing scope, and an elaboration check might improperly be
-- added to it. A guard in Sem_Elab is needed to prevent that
-- spurious check, see Check_Elab_Call.
Append_To (Stmts, Stmt);
Set_Analyzed (Stmt);
-- Call the _Postconditions procedure if the related subprogram
-- has contract assertions that need to be verified on exit.
if Ekind (Spec_Id) = E_Procedure
and then Present (Postconditions_Proc (Spec_Id))
then
Insert_Action (Stmt,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (Postconditions_Proc (Spec_Id), Loc)));
end if;
-- Ada 2020 (AI12-0279): append the call to 'Yield unless this is
-- a generic subprogram (since in such case it will be added to
-- the instantiations).
if Has_Yield_Aspect (Spec_Id)
and then Ekind (Spec_Id) /= E_Generic_Procedure
and then RTE_Available (RE_Yield)
then
Insert_Action (Stmt,
Make_Procedure_Call_Statement (Loc,
New_Occurrence_Of (RTE (RE_Yield), Loc)));
end if;
end if;
end Add_Return;
-- Local variables
Except_H : Node_Id;
L : List_Id;
Spec_Id : Entity_Id;
-- Start of processing for Expand_N_Subprogram_Body
begin
if Present (Corresponding_Spec (N)) then
Spec_Id := Corresponding_Spec (N);
else
Spec_Id := Body_Id;
end if;
-- If this is a Pure function which has any parameters whose root type
-- is System.Address, reset the Pure indication.
-- This check is also performed when the subprogram is frozen, but we
-- repeat it on the body so that the indication is consistent, and so
-- it applies as well to bodies without separate specifications.
if Is_Pure (Spec_Id)
and then Is_Subprogram (Spec_Id)
and then not Has_Pragma_Pure_Function (Spec_Id)
then
Check_Function_With_Address_Parameter (Spec_Id);
if Spec_Id /= Body_Id then
Set_Is_Pure (Body_Id, Is_Pure (Spec_Id));
end if;
end if;
-- Set L to either the list of declarations if present, or to the list
-- of statements if no declarations are present. This is used to insert
-- new stuff at the start.
if Is_Non_Empty_List (Declarations (N)) then
L := Declarations (N);
else
L := Statements (HSS);
end if;
-- If local-exception-to-goto optimization active, insert dummy push
-- statements at start, and dummy pop statements at end, but inhibit
-- this if we have No_Exception_Handlers, since they are useless and
-- interfere with analysis, e.g. by CodePeer. We also don't need these
-- if we're unnesting subprograms because the only purpose of these
-- nodes is to ensure we don't set a label in one subprogram and branch
-- to it in another.
if (Debug_Flag_Dot_G
or else Restriction_Active (No_Exception_Propagation))
and then not Restriction_Active (No_Exception_Handlers)
and then not CodePeer_Mode
and then not Unnest_Subprogram_Mode
and then Is_Non_Empty_List (L)
then
declare
FS : constant Node_Id := First (L);
FL : constant Source_Ptr := Sloc (FS);
LS : Node_Id;
LL : Source_Ptr;
begin
-- LS points to either last statement, if statements are present
-- or to the last declaration if there are no statements present.
-- It is the node after which the pop's are generated.
if Is_Non_Empty_List (Statements (HSS)) then
LS := Last (Statements (HSS));
else
LS := Last (L);
end if;
LL := Sloc (LS);
Insert_List_Before_And_Analyze (FS, New_List (
Make_Push_Constraint_Error_Label (FL),
Make_Push_Program_Error_Label (FL),
Make_Push_Storage_Error_Label (FL)));
Insert_List_After_And_Analyze (LS, New_List (
Make_Pop_Constraint_Error_Label (LL),
Make_Pop_Program_Error_Label (LL),
Make_Pop_Storage_Error_Label (LL)));
end;
end if;
-- Initialize any scalar OUT args if Initialize/Normalize_Scalars
if Init_Or_Norm_Scalars and then Is_Subprogram (Spec_Id) then
declare
F : Entity_Id;
A : Node_Id;
begin
-- Loop through formals
F := First_Formal (Spec_Id);
while Present (F) loop
if Is_Scalar_Type (Etype (F))
and then Ekind (F) = E_Out_Parameter
then
Check_Restriction (No_Default_Initialization, F);
-- Insert the initialization. We turn off validity checks
-- for this assignment, since we do not want any check on
-- the initial value itself (which may well be invalid).
-- Predicate checks are disabled as well (RM 6.4.1 (13/3))
A :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (F, Loc),
Expression => Get_Simple_Init_Val (Etype (F), N));
Set_Suppress_Assignment_Checks (A);
Insert_Before_And_Analyze (First (L),
A, Suppress => Validity_Check);
end if;
Next_Formal (F);
end loop;
end;
end if;
-- Clear out statement list for stubbed procedure
if Present (Corresponding_Spec (N)) then
Set_Elaboration_Flag (N, Spec_Id);
if Convention (Spec_Id) = Convention_Stubbed
or else Is_Eliminated (Spec_Id)
then
Set_Declarations (N, Empty_List);
Set_Handled_Statement_Sequence (N,
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Make_Null_Statement (Loc))));
return;
end if;
end if;
-- Create a set of discriminals for the next protected subprogram body
if Is_List_Member (N)
and then Present (Parent (List_Containing (N)))
and then Nkind (Parent (List_Containing (N))) = N_Protected_Body
and then Present (Next_Protected_Operation (N))
then
Set_Discriminals (Parent (Base_Type (Scope (Spec_Id))));
end if;
-- Returns_By_Ref flag is normally set when the subprogram is frozen but
-- subprograms with no specs are not frozen.
declare
Typ : constant Entity_Id := Etype (Spec_Id);
Utyp : constant Entity_Id := Underlying_Type (Typ);
begin
if Is_Limited_View (Typ) then
Set_Returns_By_Ref (Spec_Id);
elsif Present (Utyp) and then CW_Or_Has_Controlled_Part (Utyp) then
Set_Returns_By_Ref (Spec_Id);
end if;
end;
-- For a procedure, we add a return for all possible syntactic ends of
-- the subprogram.
if Ekind (Spec_Id) in E_Procedure | E_Generic_Procedure then
Add_Return (Spec_Id, Statements (HSS));
if Present (Exception_Handlers (HSS)) then
Except_H := First_Non_Pragma (Exception_Handlers (HSS));
while Present (Except_H) loop
Add_Return (Spec_Id, Statements (Except_H));
Next_Non_Pragma (Except_H);
end loop;
end if;
-- For a function, we must deal with the case where there is at least
-- one missing return. What we do is to wrap the entire body of the
-- function in a block:
-- begin
-- ...
-- end;
-- becomes
-- begin
-- begin
-- ...
-- end;
-- raise Program_Error;
-- end;
-- This approach is necessary because the raise must be signalled to the
-- caller, not handled by any local handler (RM 6.4(11)).
-- Note: we do not need to analyze the constructed sequence here, since
-- it has no handler, and an attempt to analyze the handled statement
-- sequence twice is risky in various ways (e.g. the issue of expanding
-- cleanup actions twice).
elsif Has_Missing_Return (Spec_Id) then
declare
Hloc : constant Source_Ptr := Sloc (HSS);
Blok : constant Node_Id :=
Make_Block_Statement (Hloc,
Handled_Statement_Sequence => HSS);
Rais : constant Node_Id :=
Make_Raise_Program_Error (Hloc,
Reason => PE_Missing_Return);
begin
Set_Handled_Statement_Sequence (N,
Make_Handled_Sequence_Of_Statements (Hloc,
Statements => New_List (Blok, Rais)));
Push_Scope (Spec_Id);
Analyze (Blok);
Analyze (Rais);
Pop_Scope;
end;
end if;
-- If subprogram contains a parameterless recursive call, then we may
-- have an infinite recursion, so see if we can generate code to check
-- for this possibility if storage checks are not suppressed.
if Ekind (Spec_Id) = E_Procedure
and then Has_Recursive_Call (Spec_Id)
and then not Storage_Checks_Suppressed (Spec_Id)
then
Detect_Infinite_Recursion (N, Spec_Id);
end if;
-- Set to encode entity names in package body before gigi is called
Qualify_Entity_Names (N);
-- If the body belongs to a nonabstract library-level source primitive
-- of a tagged type, install an elaboration check which ensures that a
-- dispatching call targeting the primitive will not execute the body
-- without it being previously elaborated.
Install_Primitive_Elaboration_Check (N);
end Expand_N_Subprogram_Body;
-----------------------------------
-- Expand_N_Subprogram_Body_Stub --
-----------------------------------
procedure Expand_N_Subprogram_Body_Stub (N : Node_Id) is
Bod : Node_Id;
begin
if Present (Corresponding_Body (N)) then
Bod := Unit_Declaration_Node (Corresponding_Body (N));
-- The body may have been expanded already when it is analyzed
-- through the subunit node. Do no expand again: it interferes
-- with the construction of unnesting tables when generating C.
if not Analyzed (Bod) then
Expand_N_Subprogram_Body (Bod);
end if;
-- Add full qualification to entities that may be created late
-- during unnesting.
Qualify_Entity_Names (N);
end if;
end Expand_N_Subprogram_Body_Stub;
-------------------------------------
-- Expand_N_Subprogram_Declaration --
-------------------------------------
-- If the declaration appears within a protected body, it is a private
-- operation of the protected type. We must create the corresponding
-- protected subprogram an associated formals. For a normal protected
-- operation, this is done when expanding the protected type declaration.
-- If the declaration is for a null procedure, emit null body
procedure Expand_N_Subprogram_Declaration (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Subp : constant Entity_Id := Defining_Entity (N);
-- Local variables
Scop : constant Entity_Id := Scope (Subp);
Prot_Bod : Node_Id;
Prot_Decl : Node_Id;
Prot_Id : Entity_Id;
begin
-- Deal with case of protected subprogram. Do not generate protected
-- operation if operation is flagged as eliminated.
if Is_List_Member (N)
and then Present (Parent (List_Containing (N)))
and then Nkind (Parent (List_Containing (N))) = N_Protected_Body
and then Is_Protected_Type (Scop)
then
if No (Protected_Body_Subprogram (Subp))
and then not Is_Eliminated (Subp)
then
Prot_Decl :=
Make_Subprogram_Declaration (Loc,
Specification =>
Build_Protected_Sub_Specification
(N, Scop, Unprotected_Mode));
-- The protected subprogram is declared outside of the protected
-- body. Given that the body has frozen all entities so far, we
-- analyze the subprogram and perform freezing actions explicitly.
-- including the generation of an explicit freeze node, to ensure
-- that gigi has the proper order of elaboration.
-- If the body is a subunit, the insertion point is before the
-- stub in the parent.
Prot_Bod := Parent (List_Containing (N));
if Nkind (Parent (Prot_Bod)) = N_Subunit then
Prot_Bod := Corresponding_Stub (Parent (Prot_Bod));
end if;
Insert_Before (Prot_Bod, Prot_Decl);
Prot_Id := Defining_Unit_Name (Specification (Prot_Decl));
Set_Has_Delayed_Freeze (Prot_Id);
Push_Scope (Scope (Scop));
Analyze (Prot_Decl);
Freeze_Before (N, Prot_Id);
Set_Protected_Body_Subprogram (Subp, Prot_Id);
Pop_Scope;
end if;
-- Ada 2005 (AI-348): Generate body for a null procedure. In most
-- cases this is superfluous because calls to it will be automatically
-- inlined, but we definitely need the body if preconditions for the
-- procedure are present, or if performing coverage analysis.
elsif Nkind (Specification (N)) = N_Procedure_Specification
and then Null_Present (Specification (N))
then
declare
Bod : constant Node_Id := Body_To_Inline (N);
begin
Set_Has_Completion (Subp, False);
Append_Freeze_Action (Subp, Bod);
-- The body now contains raise statements, so calls to it will
-- not be inlined.
Set_Is_Inlined (Subp, False);
end;
end if;
-- When generating C code, transform a function that returns a
-- constrained array type into a procedure with an out parameter
-- that carries the return value.
-- We skip this transformation for unchecked conversions, since they
-- are not needed by the C generator (and this also produces cleaner
-- output).
if Modify_Tree_For_C
and then Nkind (Specification (N)) = N_Function_Specification
and then Is_Array_Type (Etype (Subp))
and then Is_Constrained (Etype (Subp))
and then not Is_Unchecked_Conversion_Instance (Subp)
then
Build_Procedure_Form (N);
end if;
end Expand_N_Subprogram_Declaration;
--------------------------------
-- Expand_Non_Function_Return --
--------------------------------
procedure Expand_Non_Function_Return (N : Node_Id) is
pragma Assert (No (Expression (N)));
Loc : constant Source_Ptr := Sloc (N);
Scope_Id : Entity_Id := Return_Applies_To (Return_Statement_Entity (N));
Kind : constant Entity_Kind := Ekind (Scope_Id);
Call : Node_Id;
Acc_Stat : Node_Id;
Goto_Stat : Node_Id;
Lab_Node : Node_Id;
begin
-- Call the _Postconditions procedure if the related subprogram has
-- contract assertions that need to be verified on exit.
if Ekind (Scope_Id) in E_Entry | E_Entry_Family | E_Procedure
and then Present (Postconditions_Proc (Scope_Id))
then
Insert_Action (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Postconditions_Proc (Scope_Id), Loc)));
end if;
-- Ada 2020 (AI12-0279)
if Has_Yield_Aspect (Scope_Id)
and then RTE_Available (RE_Yield)
then
Insert_Action (N,
Make_Procedure_Call_Statement (Loc,
New_Occurrence_Of (RTE (RE_Yield), Loc)));
end if;
-- If it is a return from a procedure do no extra steps
if Kind = E_Procedure or else Kind = E_Generic_Procedure then
return;
-- If it is a nested return within an extended one, replace it with a
-- return of the previously declared return object.
elsif Kind = E_Return_Statement then
Rewrite (N,
Make_Simple_Return_Statement (Loc,
Expression =>
New_Occurrence_Of (First_Entity (Scope_Id), Loc)));
Set_Comes_From_Extended_Return_Statement (N);
Set_Return_Statement_Entity (N, Scope_Id);
Expand_Simple_Function_Return (N);
return;
end if;
pragma Assert (Is_Entry (Scope_Id));
-- Look at the enclosing block to see whether the return is from an
-- accept statement or an entry body.
for J in reverse 0 .. Scope_Stack.Last loop
Scope_Id := Scope_Stack.Table (J).Entity;
exit when Is_Concurrent_Type (Scope_Id);
end loop;
-- If it is a return from accept statement it is expanded as call to
-- RTS Complete_Rendezvous and a goto to the end of the accept body.
-- (cf : Expand_N_Accept_Statement, Expand_N_Selective_Accept,
-- Expand_N_Accept_Alternative in exp_ch9.adb)
if Is_Task_Type (Scope_Id) then
Call :=
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Complete_Rendezvous), Loc));
Insert_Before (N, Call);
-- why not insert actions here???
Analyze (Call);
Acc_Stat := Parent (N);
while Nkind (Acc_Stat) /= N_Accept_Statement loop
Acc_Stat := Parent (Acc_Stat);
end loop;
Lab_Node := Last (Statements
(Handled_Statement_Sequence (Acc_Stat)));
Goto_Stat := Make_Goto_Statement (Loc,
Name => New_Occurrence_Of
(Entity (Identifier (Lab_Node)), Loc));
Set_Analyzed (Goto_Stat);
Rewrite (N, Goto_Stat);
Analyze (N);
-- If it is a return from an entry body, put a Complete_Entry_Body call
-- in front of the return.
elsif Is_Protected_Type (Scope_Id) then
Call :=
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Complete_Entry_Body), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of
(Find_Protection_Object (Current_Scope), Loc),
Attribute_Name => Name_Unchecked_Access)));
Insert_Before (N, Call);
Analyze (Call);
end if;
end Expand_Non_Function_Return;
---------------------------------------
-- Expand_Protected_Object_Reference --
---------------------------------------
function Expand_Protected_Object_Reference
(N : Node_Id;
Scop : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (N);
Corr : Entity_Id;
Rec : Node_Id;
Param : Entity_Id;
Proc : Entity_Id;
begin
Rec := Make_Identifier (Loc, Name_uObject);
Set_Etype (Rec, Corresponding_Record_Type (Scop));
-- Find enclosing protected operation, and retrieve its first parameter,
-- which denotes the enclosing protected object. If the enclosing
-- operation is an entry, we are immediately within the protected body,
-- and we can retrieve the object from the service entries procedure. A
-- barrier function has the same signature as an entry. A barrier
-- function is compiled within the protected object, but unlike
-- protected operations its never needs locks, so that its protected
-- body subprogram points to itself.
Proc := Current_Scope;
while Present (Proc)
and then Scope (Proc) /= Scop
loop
Proc := Scope (Proc);
end loop;
Corr := Protected_Body_Subprogram (Proc);
if No (Corr) then
-- Previous error left expansion incomplete.
-- Nothing to do on this call.
return Empty;
end if;
Param :=
Defining_Identifier
(First (Parameter_Specifications (Parent (Corr))));
if Is_Subprogram (Proc) and then Proc /= Corr then
-- Protected function or procedure
Set_Entity (Rec, Param);
-- Rec is a reference to an entity which will not be in scope when
-- the call is reanalyzed, and needs no further analysis.
Set_Analyzed (Rec);
else
-- Entry or barrier function for entry body. The first parameter of
-- the entry body procedure is pointer to the object. We create a
-- local variable of the proper type, duplicating what is done to
-- define _object later on.
declare
Decls : List_Id;
Obj_Ptr : constant Entity_Id := Make_Temporary (Loc, 'T');
begin
Decls := New_List (
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Obj_Ptr,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
Subtype_Indication =>
New_Occurrence_Of
(Corresponding_Record_Type (Scop), Loc))));
Insert_Actions (N, Decls);
Freeze_Before (N, Obj_Ptr);
Rec :=
Make_Explicit_Dereference (Loc,
Prefix =>
Unchecked_Convert_To (Obj_Ptr,
New_Occurrence_Of (Param, Loc)));
-- Analyze new actual. Other actuals in calls are already analyzed
-- and the list of actuals is not reanalyzed after rewriting.
Set_Parent (Rec, N);
Analyze (Rec);
end;
end if;
return Rec;
end Expand_Protected_Object_Reference;
--------------------------------------
-- Expand_Protected_Subprogram_Call --
--------------------------------------
procedure Expand_Protected_Subprogram_Call
(N : Node_Id;
Subp : Entity_Id;
Scop : Entity_Id)
is
Rec : Node_Id;
procedure Expand_Internal_Init_Call;
-- A call to an operation of the type may occur in the initialization
-- of a private component. In that case the prefix of the call is an
-- entity name and the call is treated as internal even though it
-- appears in code outside of the protected type.
procedure Freeze_Called_Function;
-- If it is a function call it can appear in elaboration code and
-- the called entity must be frozen before the call. This must be
-- done before the call is expanded, as the expansion may rewrite it
-- to something other than a call (e.g. a temporary initialized in a
-- transient block).
-------------------------------
-- Expand_Internal_Init_Call --
-------------------------------
procedure Expand_Internal_Init_Call is
begin
-- If the context is a protected object (rather than a protected
-- type) the call itself is bound to raise program_error because
-- the protected body will not have been elaborated yet. This is
-- diagnosed subsequently in Sem_Elab.
Freeze_Called_Function;
-- The target of the internal call is the first formal of the
-- enclosing initialization procedure.
Rec := New_Occurrence_Of (First_Formal (Current_Scope), Sloc (N));
Build_Protected_Subprogram_Call (N,
Name => Name (N),
Rec => Rec,
External => False);
Analyze (N);
Resolve (N, Etype (Subp));
end Expand_Internal_Init_Call;
----------------------------
-- Freeze_Called_Function --
----------------------------
procedure Freeze_Called_Function is
begin
if Ekind (Subp) = E_Function then
Freeze_Expression (Name (N));
end if;
end Freeze_Called_Function;
-- Start of processing for Expand_Protected_Subprogram_Call
begin
-- If the protected object is not an enclosing scope, this is an inter-
-- object function call. Inter-object procedure calls are expanded by
-- Exp_Ch9.Build_Simple_Entry_Call. The call is intra-object only if the
-- subprogram being called is in the protected body being compiled, and
-- if the protected object in the call is statically the enclosing type.
-- The object may be a component of some other data structure, in which
-- case this must be handled as an inter-object call.
if not In_Open_Scopes (Scop)
or else Is_Entry_Wrapper (Current_Scope)
or else not Is_Entity_Name (Name (N))
then
if Nkind (Name (N)) = N_Selected_Component then
Rec := Prefix (Name (N));
elsif Nkind (Name (N)) = N_Indexed_Component then
Rec := Prefix (Prefix (Name (N)));
-- If this is a call within an entry wrapper, it appears within a
-- precondition that calls another primitive of the synchronized
-- type. The target object of the call is the first actual on the
-- wrapper. Note that this is an external call, because the wrapper
-- is called outside of the synchronized object. This means that
-- an entry call to an entry with preconditions involves two
-- synchronized operations.
elsif Ekind (Current_Scope) = E_Procedure
and then Is_Entry_Wrapper (Current_Scope)
then
Rec := New_Occurrence_Of (First_Entity (Current_Scope), Sloc (N));
-- A default parameter of a protected operation may be a call to
-- a protected function of the type. This appears as an internal
-- call in the profile of the operation, but if the context is an
-- external call we must convert the call into an external one,
-- using the protected object that is the target, so that:
-- Prot.P (F)
-- is transformed into
-- Prot.P (Prot.F)
elsif Nkind (Parent (N)) = N_Procedure_Call_Statement
and then Nkind (Name (Parent (N))) = N_Selected_Component
and then Is_Protected_Type (Etype (Prefix (Name (Parent (N)))))
and then Is_Entity_Name (Name (N))
and then Scope (Entity (Name (N))) =
Etype (Prefix (Name (Parent (N))))
then
Rewrite (Name (N),
Make_Selected_Component (Sloc (N),
Prefix => New_Copy_Tree (Prefix (Name (Parent (N)))),
Selector_Name => Relocate_Node (Name (N))));
Analyze_And_Resolve (N);
return;
else
-- If the context is the initialization procedure for a protected
-- type, the call is legal because the called entity must be a
-- function of that enclosing type, and this is treated as an
-- internal call.
pragma Assert
(Is_Entity_Name (Name (N)) and then Inside_Init_Proc);
Expand_Internal_Init_Call;
return;
end if;
Freeze_Called_Function;
Build_Protected_Subprogram_Call (N,
Name => New_Occurrence_Of (Subp, Sloc (N)),
Rec => Convert_Concurrent (Rec, Etype (Rec)),
External => True);
else
Rec := Expand_Protected_Object_Reference (N, Scop);
if No (Rec) then
return;
end if;
Freeze_Called_Function;
Build_Protected_Subprogram_Call (N,
Name => Name (N),
Rec => Rec,
External => False);
end if;
-- Analyze and resolve the new call. The actuals have already been
-- resolved, but expansion of a function call will add extra actuals
-- if needed. Analysis of a procedure call already includes resolution.
Analyze (N);
if Ekind (Subp) = E_Function then
Resolve (N, Etype (Subp));
end if;
end Expand_Protected_Subprogram_Call;
-----------------------------------
-- Expand_Simple_Function_Return --
-----------------------------------
-- The "simple" comes from the syntax rule simple_return_statement. The
-- semantics are not at all simple.
procedure Expand_Simple_Function_Return (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Scope_Id : constant Entity_Id :=
Return_Applies_To (Return_Statement_Entity (N));
-- The function we are returning from
R_Type : constant Entity_Id := Etype (Scope_Id);
-- The result type of the function
Utyp : constant Entity_Id := Underlying_Type (R_Type);
Exp : Node_Id := Expression (N);
pragma Assert (Present (Exp));
Exp_Is_Function_Call : constant Boolean :=
Nkind (Exp) = N_Function_Call
or else (Nkind (Exp) = N_Explicit_Dereference
and then Is_Entity_Name (Prefix (Exp))
and then Ekind (Entity (Prefix (Exp))) = E_Constant
and then Is_Related_To_Func_Return (Entity (Prefix (Exp))));
Exp_Typ : constant Entity_Id := Etype (Exp);
-- The type of the expression (not necessarily the same as R_Type)
Subtype_Ind : Node_Id;
-- If the result type of the function is class-wide and the expression
-- has a specific type, then we use the expression's type as the type of
-- the return object. In cases where the expression is an aggregate that
-- is built in place, this avoids the need for an expensive conversion
-- of the return object to the specific type on assignments to the
-- individual components.
procedure Check_Against_Result_Level (Level : Node_Id);
-- Check the given accessibility level against the level
-- determined by the point of call. (AI05-0234).
--------------------------------
-- Check_Against_Result_Level --
--------------------------------
procedure Check_Against_Result_Level (Level : Node_Id) is
begin
Insert_Action (N,
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Gt (Loc,
Left_Opnd => Level,
Right_Opnd =>
New_Occurrence_Of
(Extra_Accessibility_Of_Result (Scope_Id), Loc)),
Reason => PE_Accessibility_Check_Failed));
end Check_Against_Result_Level;
-- Start of processing for Expand_Simple_Function_Return
begin
if Is_Class_Wide_Type (R_Type)
and then not Is_Class_Wide_Type (Exp_Typ)
and then Nkind (Exp) /= N_Type_Conversion
then
Subtype_Ind := New_Occurrence_Of (Exp_Typ, Loc);
else
Subtype_Ind := New_Occurrence_Of (R_Type, Loc);
-- If the result type is class-wide and the expression is a view
-- conversion, the conversion plays no role in the expansion because
-- it does not modify the tag of the object. Remove the conversion
-- altogether to prevent tag overwriting.
if Is_Class_Wide_Type (R_Type)
and then not Is_Class_Wide_Type (Exp_Typ)
and then Nkind (Exp) = N_Type_Conversion
then
Exp := Expression (Exp);
end if;
end if;
-- Assert that if F says "return G(...);"
-- then F and G are both b-i-p, or neither b-i-p.
if Nkind (Exp) = N_Function_Call then
pragma Assert (Ekind (Scope_Id) = E_Function);
pragma Assert
(Is_Build_In_Place_Function (Scope_Id) =
Is_Build_In_Place_Function_Call (Exp));
null;
end if;
-- For the case of a simple return that does not come from an
-- extended return, in the case of build-in-place, we rewrite
-- "return <expression>;" to be:
-- return _anon_ : <return_subtype> := <expression>
-- The expansion produced by Expand_N_Extended_Return_Statement will
-- contain simple return statements (for example, a block containing
-- simple return of the return object), which brings us back here with
-- Comes_From_Extended_Return_Statement set. The reason for the barrier
-- checking for a simple return that does not come from an extended
-- return is to avoid this infinite recursion.
-- The reason for this design is that for Ada 2005 limited returns, we
-- need to reify the return object, so we can build it "in place", and
-- we need a block statement to hang finalization and tasking stuff.
-- ??? In order to avoid disruption, we avoid translating to extended
-- return except in the cases where we really need to (Ada 2005 for
-- inherently limited). We might prefer to do this translation in all
-- cases (except perhaps for the case of Ada 95 inherently limited),
-- in order to fully exercise the Expand_N_Extended_Return_Statement
-- code. This would also allow us to do the build-in-place optimization
-- for efficiency even in cases where it is semantically not required.
-- As before, we check the type of the return expression rather than the
-- return type of the function, because the latter may be a limited
-- class-wide interface type, which is not a limited type, even though
-- the type of the expression may be.
pragma Assert
(Comes_From_Extended_Return_Statement (N)
or else not Is_Build_In_Place_Function_Call (Exp)
or else Is_Build_In_Place_Function (Scope_Id));
if not Comes_From_Extended_Return_Statement (N)
and then Is_Build_In_Place_Function (Scope_Id)
and then not Debug_Flag_Dot_L
-- The functionality of interface thunks is simple and it is always
-- handled by means of simple return statements. This leaves their
-- expansion simple and clean.
and then not Is_Thunk (Scope_Id)
then
declare
Return_Object_Entity : constant Entity_Id :=
Make_Temporary (Loc, 'R', Exp);
Obj_Decl : constant Node_Id :=
Make_Object_Declaration (Loc,
Defining_Identifier => Return_Object_Entity,
Object_Definition => Subtype_Ind,
Expression => Exp);
Ext : constant Node_Id :=
Make_Extended_Return_Statement (Loc,
Return_Object_Declarations => New_List (Obj_Decl));
-- Do not perform this high-level optimization if the result type
-- is an interface because the "this" pointer must be displaced.
begin
Rewrite (N, Ext);
Analyze (N);
return;
end;
end if;
-- Here we have a simple return statement that is part of the expansion
-- of an extended return statement (either written by the user, or
-- generated by the above code).
-- Always normalize C/Fortran boolean result. This is not always needed,
-- but it seems a good idea to minimize the passing around of non-
-- normalized values, and in any case this handles the processing of
-- barrier functions for protected types, which turn the condition into
-- a return statement.
if Is_Boolean_Type (Exp_Typ) and then Nonzero_Is_True (Exp_Typ) then
Adjust_Condition (Exp);
Adjust_Result_Type (Exp, Exp_Typ);
end if;
-- Do validity check if enabled for returns
if Validity_Checks_On and then Validity_Check_Returns then
Ensure_Valid (Exp);
end if;
-- Check the result expression of a scalar function against the subtype
-- of the function by inserting a conversion. This conversion must
-- eventually be performed for other classes of types, but for now it's
-- only done for scalars ???
if Is_Scalar_Type (Exp_Typ) and then Exp_Typ /= R_Type then
Rewrite (Exp, Convert_To (R_Type, Exp));
-- The expression is resolved to ensure that the conversion gets
-- expanded to generate a possible constraint check.
Analyze_And_Resolve (Exp, R_Type);
end if;
-- Deal with returning variable length objects and controlled types
-- Nothing to do if we are returning by reference, or this is not a
-- type that requires special processing (indicated by the fact that
-- it requires a cleanup scope for the secondary stack case).
if Is_Build_In_Place_Function (Scope_Id)
or else Is_Limited_Interface (Exp_Typ)
then
null;
-- No copy needed for thunks returning interface type objects since
-- the object is returned by reference and the maximum functionality
-- required is just to displace the pointer.
elsif Is_Thunk (Scope_Id) and then Is_Interface (Exp_Typ) then
null;
-- If the call is within a thunk and the type is a limited view, the
-- backend will eventually see the non-limited view of the type.
elsif Is_Thunk (Scope_Id) and then Is_Incomplete_Type (Exp_Typ) then
return;
-- A return statement from an ignored Ghost function does not use the
-- secondary stack (or any other one).
elsif not Requires_Transient_Scope (R_Type)
or else Is_Ignored_Ghost_Entity (Scope_Id)
then
-- Mutable records with variable-length components are not returned
-- on the sec-stack, so we need to make sure that the back end will
-- only copy back the size of the actual value, and not the maximum
-- size. We create an actual subtype for this purpose. However we
-- need not do it if the expression is a function call since this
-- will be done in the called function and doing it here too would
-- cause a temporary with maximum size to be created.
declare
Ubt : constant Entity_Id := Underlying_Type (Base_Type (Exp_Typ));
Decl : Node_Id;
Ent : Entity_Id;
begin
if not Exp_Is_Function_Call
and then Has_Discriminants (Ubt)
and then not Is_Constrained (Ubt)
and then not Has_Unchecked_Union (Ubt)
then
Decl := Build_Actual_Subtype (Ubt, Exp);
Ent := Defining_Identifier (Decl);
Insert_Action (Exp, Decl);
Rewrite (Exp, Unchecked_Convert_To (Ent, Exp));
Analyze_And_Resolve (Exp);
end if;
end;
-- Here if secondary stack is used
else
-- Prevent the reclamation of the secondary stack by all enclosing
-- blocks and loops as well as the related function; otherwise the
-- result would be reclaimed too early.
Set_Enclosing_Sec_Stack_Return (N);
-- Optimize the case where the result is a function call. In this
-- case the result is already on the secondary stack and no further
-- processing is required except to set the By_Ref flag to ensure
-- that gigi does not attempt an extra unnecessary copy. (Actually
-- not just unnecessary but wrong in the case of a controlled type,
-- where gigi does not know how to do a copy.)
if Requires_Transient_Scope (Exp_Typ)
and then Exp_Is_Function_Call
then
Set_By_Ref (N);
-- Remove side effects from the expression now so that other parts
-- of the expander do not have to reanalyze this node without this
-- optimization
Rewrite (Exp, Duplicate_Subexpr_No_Checks (Exp));
-- Ada 2005 (AI-251): If the type of the returned object is
-- an interface then add an implicit type conversion to force
-- displacement of the "this" pointer.
if Is_Interface (R_Type) then
Rewrite (Exp, Convert_To (R_Type, Relocate_Node (Exp)));
end if;
Analyze_And_Resolve (Exp, R_Type);
-- For controlled types, do the allocation on the secondary stack
-- manually in order to call adjust at the right time:
-- type Anon1 is access R_Type;
-- for Anon1'Storage_pool use ss_pool;
-- Anon2 : anon1 := new R_Type'(expr);
-- return Anon2.all;
-- We do the same for classwide types that are not potentially
-- controlled (by the virtue of restriction No_Finalization) because
-- gigi is not able to properly allocate class-wide types.
elsif CW_Or_Has_Controlled_Part (Utyp) then
declare
Loc : constant Source_Ptr := Sloc (N);
Acc_Typ : constant Entity_Id := Make_Temporary (Loc, 'A');
Alloc_Node : Node_Id;
Temp : Entity_Id;
begin
Set_Ekind (Acc_Typ, E_Access_Type);
Set_Associated_Storage_Pool (Acc_Typ, RTE (RE_SS_Pool));
-- This is an allocator for the secondary stack, and it's fine
-- to have Comes_From_Source set False on it, as gigi knows not
-- to flag it as a violation of No_Implicit_Heap_Allocations.
Alloc_Node :=
Make_Allocator (Loc,
Expression =>
Make_Qualified_Expression (Loc,
Subtype_Mark => New_Occurrence_Of (Etype (Exp), Loc),
Expression => Relocate_Node (Exp)));
-- We do not want discriminant checks on the declaration,
-- given that it gets its value from the allocator.
Set_No_Initialization (Alloc_Node);
Temp := Make_Temporary (Loc, 'R', Alloc_Node);
Insert_List_Before_And_Analyze (N, New_List (
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Acc_Typ,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
Subtype_Indication => Subtype_Ind)),
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition => New_Occurrence_Of (Acc_Typ, Loc),
Expression => Alloc_Node)));
Rewrite (Exp,
Make_Explicit_Dereference (Loc,
Prefix => New_Occurrence_Of (Temp, Loc)));
-- Ada 2005 (AI-251): If the type of the returned object is
-- an interface then add an implicit type conversion to force
-- displacement of the "this" pointer.
if Is_Interface (R_Type) then
Rewrite (Exp, Convert_To (R_Type, Relocate_Node (Exp)));
end if;
Analyze_And_Resolve (Exp, R_Type);
end;
-- Otherwise use the gigi mechanism to allocate result on the
-- secondary stack.
else
Check_Restriction (No_Secondary_Stack, N);
Set_Storage_Pool (N, RTE (RE_SS_Pool));
Set_Procedure_To_Call (N, RTE (RE_SS_Allocate));
end if;
end if;
-- Implement the rules of 6.5(8-10), which require a tag check in
-- the case of a limited tagged return type, and tag reassignment for
-- nonlimited tagged results. These actions are needed when the return
-- type is a specific tagged type and the result expression is a
-- conversion or a formal parameter, because in that case the tag of
-- the expression might differ from the tag of the specific result type.
-- We must also verify an underlying type exists for the return type in
-- case it is incomplete - in which case is not necessary to generate a
-- check anyway since an incomplete limited tagged return type would
-- qualify as a premature usage.
if Present (Utyp)
and then Is_Tagged_Type (Utyp)
and then not Is_Class_Wide_Type (Utyp)
and then (Nkind (Exp) in
N_Type_Conversion | N_Unchecked_Type_Conversion
or else (Is_Entity_Name (Exp)
and then Is_Formal (Entity (Exp))))
then
-- When the return type is limited, perform a check that the tag of
-- the result is the same as the tag of the return type.
if Is_Limited_Type (R_Type) then
Insert_Action (Exp,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Op_Ne (Loc,
Left_Opnd =>
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (Exp),
Selector_Name => Make_Identifier (Loc, Name_uTag)),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Base_Type (Utyp), Loc),
Attribute_Name => Name_Tag)),
Reason => CE_Tag_Check_Failed));
-- If the result type is a specific nonlimited tagged type, then we
-- have to ensure that the tag of the result is that of the result
-- type. This is handled by making a copy of the expression in
-- the case where it might have a different tag, namely when the
-- expression is a conversion or a formal parameter. We create a new
-- object of the result type and initialize it from the expression,
-- which will implicitly force the tag to be set appropriately.
else
declare
ExpR : constant Node_Id := Relocate_Node (Exp);
Result_Id : constant Entity_Id :=
Make_Temporary (Loc, 'R', ExpR);
Result_Exp : constant Node_Id :=
New_Occurrence_Of (Result_Id, Loc);
Result_Obj : constant Node_Id :=
Make_Object_Declaration (Loc,
Defining_Identifier => Result_Id,
Object_Definition =>
New_Occurrence_Of (R_Type, Loc),
Constant_Present => True,
Expression => ExpR);
begin
Set_Assignment_OK (Result_Obj);
Insert_Action (Exp, Result_Obj);
Rewrite (Exp, Result_Exp);
Analyze_And_Resolve (Exp, R_Type);
end;
end if;
-- Ada 2005 (AI95-344): If the result type is class-wide, then insert
-- a check that the level of the return expression's underlying type
-- is not deeper than the level of the master enclosing the function.
-- AI12-043: The check is made immediately after the return object is
-- created. This means that we do not apply it to the simple return
-- generated by the expansion of an extended return statement.
-- No runtime check needed in interface thunks since it is performed
-- by the target primitive associated with the thunk.
elsif Is_Class_Wide_Type (R_Type)
and then not Comes_From_Extended_Return_Statement (N)
and then not Is_Thunk (Scope_Id)
then
Apply_CW_Accessibility_Check (Exp, Scope_Id);
-- Ada 2012 (AI05-0073): If the result subtype of the function is
-- defined by an access_definition designating a specific tagged
-- type T, a check is made that the result value is null or the tag
-- of the object designated by the result value identifies T.
-- The return expression is referenced twice in the code below, so it
-- must be made free of side effects. Given that different compilers
-- may evaluate these parameters in different order, both occurrences
-- perform a copy.
elsif Ekind (R_Type) = E_Anonymous_Access_Type
and then Is_Tagged_Type (Designated_Type (R_Type))
and then not Is_Class_Wide_Type (Designated_Type (R_Type))
and then Nkind (Original_Node (Exp)) /= N_Null
and then not Tag_Checks_Suppressed (Designated_Type (R_Type))
then
-- Generate:
-- [Constraint_Error
-- when Exp /= null
-- and then Exp.all not in Designated_Type]
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_And_Then (Loc,
Left_Opnd =>
Make_Op_Ne (Loc,
Left_Opnd => Duplicate_Subexpr (Exp),
Right_Opnd => Make_Null (Loc)),
Right_Opnd =>
Make_Not_In (Loc,
Left_Opnd =>
Make_Explicit_Dereference (Loc,
Prefix => Duplicate_Subexpr (Exp)),
Right_Opnd =>
New_Occurrence_Of (Designated_Type (R_Type), Loc))),
Reason => CE_Tag_Check_Failed),
Suppress => All_Checks);
end if;
-- Determine if the special rules within RM 3.10.2 for explicitly
-- aliased formals apply to Exp - in which case we require a dynamic
-- check to be generated.
if Is_Special_Aliased_Formal_Access (Exp, Scope_Id) then
Check_Against_Result_Level
(Make_Integer_Literal (Loc,
Object_Access_Level (Entity (Ultimate_Prefix (Prefix (Exp))))));
end if;
-- AI05-0234: Check unconstrained access discriminants to ensure
-- that the result does not outlive an object designated by one
-- of its discriminants (RM 6.5(21/3)).
if Present (Extra_Accessibility_Of_Result (Scope_Id))
and then Has_Unconstrained_Access_Discriminants (R_Type)
then
declare
Discrim_Source : Node_Id;
begin
Discrim_Source := Exp;
while Nkind (Discrim_Source) = N_Qualified_Expression loop
Discrim_Source := Expression (Discrim_Source);
end loop;
if Nkind (Discrim_Source) = N_Identifier
and then Is_Return_Object (Entity (Discrim_Source))
then
Discrim_Source := Entity (Discrim_Source);
if Is_Constrained (Etype (Discrim_Source)) then
Discrim_Source := Etype (Discrim_Source);
else
Discrim_Source := Expression (Parent (Discrim_Source));
end if;
elsif Nkind (Discrim_Source) = N_Identifier
and then Nkind (Original_Node (Discrim_Source)) in
N_Aggregate | N_Extension_Aggregate
then
Discrim_Source := Original_Node (Discrim_Source);
elsif Nkind (Discrim_Source) = N_Explicit_Dereference and then
Nkind (Original_Node (Discrim_Source)) = N_Function_Call
then
Discrim_Source := Original_Node (Discrim_Source);
end if;
Discrim_Source := Unqual_Conv (Discrim_Source);
case Nkind (Discrim_Source) is
when N_Defining_Identifier =>
pragma Assert (Is_Composite_Type (Discrim_Source)
and then Has_Discriminants (Discrim_Source)
and then Is_Constrained (Discrim_Source));
declare
Discrim : Entity_Id :=
First_Discriminant (Base_Type (R_Type));
Disc_Elmt : Elmt_Id :=
First_Elmt (Discriminant_Constraint
(Discrim_Source));
begin
loop
if Ekind (Etype (Discrim)) =
E_Anonymous_Access_Type
then
Check_Against_Result_Level
(Dynamic_Accessibility_Level (Node (Disc_Elmt)));
end if;
Next_Elmt (Disc_Elmt);
Next_Discriminant (Discrim);
exit when not Present (Discrim);
end loop;
end;
when N_Aggregate
| N_Extension_Aggregate
=>
-- Unimplemented: extension aggregate case where discrims
-- come from ancestor part, not extension part.
declare
Discrim : Entity_Id :=
First_Discriminant (Base_Type (R_Type));
Disc_Exp : Node_Id := Empty;
Positionals_Exhausted
: Boolean := not Present (Expressions
(Discrim_Source));
function Associated_Expr
(Comp_Id : Entity_Id;
Associations : List_Id) return Node_Id;
-- Given a component and a component associations list,
-- locate the expression for that component; returns
-- Empty if no such expression is found.
---------------------
-- Associated_Expr --
---------------------
function Associated_Expr
(Comp_Id : Entity_Id;
Associations : List_Id) return Node_Id
is
Assoc : Node_Id;
Choice : Node_Id;
begin
-- Simple linear search seems ok here
Assoc := First (Associations);
while Present (Assoc) loop
Choice := First (Choices (Assoc));
while Present (Choice) loop
if (Nkind (Choice) = N_Identifier
and then Chars (Choice) = Chars (Comp_Id))
or else (Nkind (Choice) = N_Others_Choice)
then
return Expression (Assoc);
end if;
Next (Choice);
end loop;
Next (Assoc);
end loop;
return Empty;
end Associated_Expr;
begin
if not Positionals_Exhausted then
Disc_Exp := First (Expressions (Discrim_Source));
end if;
loop
if Positionals_Exhausted then
Disc_Exp :=
Associated_Expr
(Discrim,
Component_Associations (Discrim_Source));
end if;
if Ekind (Etype (Discrim)) =
E_Anonymous_Access_Type
then
Check_Against_Result_Level
(Dynamic_Accessibility_Level (Disc_Exp));
end if;
Next_Discriminant (Discrim);
exit when not Present (Discrim);
if not Positionals_Exhausted then
Next (Disc_Exp);
Positionals_Exhausted := not Present (Disc_Exp);
end if;
end loop;
end;
when N_Function_Call =>
-- No check needed (check performed by callee)
null;
when others =>
declare
Level : constant Node_Id :=
Make_Integer_Literal (Loc,
Object_Access_Level (Discrim_Source));
begin
-- Unimplemented: check for name prefix that includes
-- a dereference of an access value with a dynamic
-- accessibility level (e.g., an access param or a
-- saooaaat) and use dynamic level in that case. For
-- example:
-- return Access_Param.all(Some_Index).Some_Component;
-- ???
Set_Etype (Level, Standard_Natural);
Check_Against_Result_Level (Level);
end;
end case;
end;
end if;
-- If we are returning a nonscalar object that is possibly unaligned,
-- then copy the value into a temporary first. This copy may need to
-- expand to a loop of component operations.
if Is_Possibly_Unaligned_Slice (Exp)
or else (Is_Possibly_Unaligned_Object (Exp)
and then not Represented_As_Scalar (Etype (Exp)))
then
declare
ExpR : constant Node_Id := Relocate_Node (Exp);
Tnn : constant Entity_Id := Make_Temporary (Loc, 'T', ExpR);
begin
Insert_Action (Exp,
Make_Object_Declaration (Loc,
Defining_Identifier => Tnn,
Constant_Present => True,
Object_Definition => New_Occurrence_Of (R_Type, Loc),
Expression => ExpR),
Suppress => All_Checks);
Rewrite (Exp, New_Occurrence_Of (Tnn, Loc));
end;
end if;
-- Call the _Postconditions procedure if the related function has
-- contract assertions that need to be verified on exit.
if Ekind (Scope_Id) = E_Function
and then Present (Postconditions_Proc (Scope_Id))
then
-- In the case of discriminated objects, we have created a
-- constrained subtype above, and used the underlying type. This
-- transformation is post-analysis and harmless, except that now the
-- call to the post-condition will be analyzed and the type kinds
-- have to match.
if Nkind (Exp) = N_Unchecked_Type_Conversion
and then Is_Private_Type (R_Type) /= Is_Private_Type (Etype (Exp))
then
Rewrite (Exp, Expression (Relocate_Node (Exp)));
end if;
-- We are going to reference the returned value twice in this case,
-- once in the call to _Postconditions, and once in the actual return
-- statement, but we can't have side effects happening twice.
Force_Evaluation (Exp, Mode => Strict);
-- Generate call to _Postconditions
Insert_Action (Exp,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (Postconditions_Proc (Scope_Id), Loc),
Parameter_Associations => New_List (New_Copy_Tree (Exp))));
end if;
-- Ada 2005 (AI-251): If this return statement corresponds with an
-- simple return statement associated with an extended return statement
-- and the type of the returned object is an interface then generate an
-- implicit conversion to force displacement of the "this" pointer.
if Ada_Version >= Ada_2005
and then Comes_From_Extended_Return_Statement (N)
and then Nkind (Expression (N)) = N_Identifier
and then Is_Interface (Utyp)
and then Utyp /= Underlying_Type (Exp_Typ)
then
Rewrite (Exp, Convert_To (Utyp, Relocate_Node (Exp)));
Analyze_And_Resolve (Exp);
end if;
-- Ada 2020 (AI12-0279)
if Has_Yield_Aspect (Scope_Id)
and then RTE_Available (RE_Yield)
then
Insert_Action (N,
Make_Procedure_Call_Statement (Loc,
New_Occurrence_Of (RTE (RE_Yield), Loc)));
end if;
end Expand_Simple_Function_Return;
-----------------------
-- Freeze_Subprogram --
-----------------------
procedure Freeze_Subprogram (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
procedure Register_Predefined_DT_Entry (Prim : Entity_Id);
-- (Ada 2005): Register a predefined primitive in all the secondary
-- dispatch tables of its primitive type.
----------------------------------
-- Register_Predefined_DT_Entry --
----------------------------------
procedure Register_Predefined_DT_Entry (Prim : Entity_Id) is
Iface_DT_Ptr : Elmt_Id;
Tagged_Typ : Entity_Id;
Thunk_Id : Entity_Id;
Thunk_Code : Node_Id;
begin
Tagged_Typ := Find_Dispatching_Type (Prim);
if No (Access_Disp_Table (Tagged_Typ))
or else not Has_Interfaces (Tagged_Typ)
or else not RTE_Available (RE_Interface_Tag)
or else Restriction_Active (No_Dispatching_Calls)
then
return;
end if;
-- Skip the first two access-to-dispatch-table pointers since they
-- leads to the primary dispatch table (predefined DT and user
-- defined DT). We are only concerned with the secondary dispatch
-- table pointers. Note that the access-to- dispatch-table pointer
-- corresponds to the first implemented interface retrieved below.
Iface_DT_Ptr :=
Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Tagged_Typ))));
while Present (Iface_DT_Ptr)
and then Ekind (Node (Iface_DT_Ptr)) = E_Constant
loop
pragma Assert (Has_Thunks (Node (Iface_DT_Ptr)));
Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code,
Iface => Related_Type (Node (Iface_DT_Ptr)));
if Present (Thunk_Code) then
Insert_Actions_After (N, New_List (
Thunk_Code,
Build_Set_Predefined_Prim_Op_Address (Loc,
Tag_Node =>
New_Occurrence_Of (Node (Next_Elmt (Iface_DT_Ptr)), Loc),
Position => DT_Position (Prim),
Address_Node =>
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Thunk_Id, Loc),
Attribute_Name => Name_Unrestricted_Access))),
Build_Set_Predefined_Prim_Op_Address (Loc,
Tag_Node =>
New_Occurrence_Of
(Node (Next_Elmt (Next_Elmt (Next_Elmt (Iface_DT_Ptr)))),
Loc),
Position => DT_Position (Prim),
Address_Node =>
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Prim, Loc),
Attribute_Name => Name_Unrestricted_Access)))));
end if;
-- Skip the tag of the predefined primitives dispatch table
Next_Elmt (Iface_DT_Ptr);
pragma Assert (Has_Thunks (Node (Iface_DT_Ptr)));
-- Skip tag of the no-thunks dispatch table
Next_Elmt (Iface_DT_Ptr);
pragma Assert (not Has_Thunks (Node (Iface_DT_Ptr)));
-- Skip tag of predefined primitives no-thunks dispatch table
Next_Elmt (Iface_DT_Ptr);
pragma Assert (not Has_Thunks (Node (Iface_DT_Ptr)));
Next_Elmt (Iface_DT_Ptr);
end loop;
end Register_Predefined_DT_Entry;
-- Local variables
Subp : constant Entity_Id := Entity (N);
-- Start of processing for Freeze_Subprogram
begin
-- We suppress the initialization of the dispatch table entry when
-- not Tagged_Type_Expansion because the dispatching mechanism is
-- handled internally by the target.
if Is_Dispatching_Operation (Subp)
and then not Is_Abstract_Subprogram (Subp)
and then Present (DTC_Entity (Subp))
and then Present (Scope (DTC_Entity (Subp)))
and then Tagged_Type_Expansion
and then not Restriction_Active (No_Dispatching_Calls)
and then RTE_Available (RE_Tag)
then
declare
Typ : constant Entity_Id := Scope (DTC_Entity (Subp));
begin
-- Handle private overridden primitives
if not Is_CPP_Class (Typ) then
Check_Overriding_Operation (Subp);
end if;
-- We assume that imported CPP primitives correspond with objects
-- whose constructor is in the CPP side; therefore we don't need
-- to generate code to register them in the dispatch table.
if Is_CPP_Class (Typ) then
null;
-- Handle CPP primitives found in derivations of CPP_Class types.
-- These primitives must have been inherited from some parent, and
-- there is no need to register them in the dispatch table because
-- Build_Inherit_Prims takes care of initializing these slots.
elsif Is_Imported (Subp)
and then Convention (Subp) in Convention_C_Family
then
null;
-- Generate code to register the primitive in non statically
-- allocated dispatch tables
elsif not Building_Static_DT (Scope (DTC_Entity (Subp))) then
-- When a primitive is frozen, enter its name in its dispatch
-- table slot.
if not Is_Interface (Typ)
or else Present (Interface_Alias (Subp))
then
if Is_Predefined_Dispatching_Operation (Subp) then
Register_Predefined_DT_Entry (Subp);
end if;
Insert_Actions_After (N,
Register_Primitive (Loc, Prim => Subp));
end if;
end if;
end;
end if;
-- Mark functions that return by reference. Note that it cannot be part
-- of the normal semantic analysis of the spec since the underlying
-- returned type may not be known yet (for private types).
declare
Typ : constant Entity_Id := Etype (Subp);
Utyp : constant Entity_Id := Underlying_Type (Typ);
begin
if Is_Limited_View (Typ) then
Set_Returns_By_Ref (Subp);
elsif Present (Utyp) and then CW_Or_Has_Controlled_Part (Utyp) then
Set_Returns_By_Ref (Subp);
end if;
end;
-- Wnen freezing a null procedure, analyze its delayed aspects now
-- because we may not have reached the end of the declarative list when
-- delayed aspects are normally analyzed. This ensures that dispatching
-- calls are properly rewritten when the generated _Postcondition
-- procedure is analyzed in the null procedure body.
if Nkind (Parent (Subp)) = N_Procedure_Specification
and then Null_Present (Parent (Subp))
then
Analyze_Entry_Or_Subprogram_Contract (Subp);
end if;
end Freeze_Subprogram;
--------------------------
-- Has_BIP_Extra_Formal --
--------------------------
function Has_BIP_Extra_Formal
(E : Entity_Id;
Kind : BIP_Formal_Kind) return Boolean
is
Extra_Formal : Entity_Id := Extra_Formals (E);
begin
-- We can only rely on the availability of the extra formals in frozen
-- entities or in subprogram types of dispatching calls (since their
-- extra formals are added when the target subprogram is frozen; see
-- Expand_Dispatching_Call).
pragma Assert (Is_Frozen (E)
or else (Ekind (E) = E_Subprogram_Type
and then Is_Dispatch_Table_Entity (E))
or else (Is_Dispatching_Operation (E)
and then Is_Frozen (Find_Dispatching_Type (E))));
while Present (Extra_Formal) loop
if Is_Build_In_Place_Entity (Extra_Formal)
and then BIP_Suffix_Kind (Extra_Formal) = Kind
then
return True;
end if;
Next_Formal_With_Extras (Extra_Formal);
end loop;
return False;
end Has_BIP_Extra_Formal;
------------------------------
-- Insert_Post_Call_Actions --
------------------------------
procedure Insert_Post_Call_Actions (N : Node_Id; Post_Call : List_Id) is
Context : constant Node_Id := Parent (N);
begin
if Is_Empty_List (Post_Call) then
return;
end if;
-- Cases where the call is not a member of a statement list. This also
-- includes the cases where the call is an actual in another function
-- call, or is an index, or is an operand of an if-expression, i.e. is
-- in an expression context.
if not Is_List_Member (N)
or else Nkind (Context) in N_Function_Call
| N_If_Expression
| N_Indexed_Component
then
-- In Ada 2012 the call may be a function call in an expression
-- (since OUT and IN OUT parameters are now allowed for such calls).
-- The write-back of (in)-out parameters is handled by the back-end,
-- but the constraint checks generated when subtypes of formal and
-- actual don't match must be inserted in the form of assignments.
if Nkind (N) = N_Function_Call
or else Nkind (Original_Node (N)) = N_Function_Call
then
pragma Assert (Ada_Version >= Ada_2012);
-- Functions with '[in] out' parameters are only allowed in Ada
-- 2012.
-- We used to handle this by climbing up parents to a
-- non-statement/declaration and then simply making a call to
-- Insert_Actions_After (P, Post_Call), but that doesn't work
-- for Ada 2012. If we are in the middle of an expression, e.g.
-- the condition of an IF, this call would insert after the IF
-- statement, which is much too late to be doing the write back.
-- For example:
-- if Clobber (X) then
-- Put_Line (X'Img);
-- else
-- goto Junk
-- end if;
-- Now assume Clobber changes X, if we put the write back after
-- the IF, the Put_Line gets the wrong value and the goto causes
-- the write back to be skipped completely.
-- To deal with this, we replace the call by
-- do
-- Tnnn : constant function-result-type := function-call;
-- Post_Call actions
-- in
-- Tnnn;
-- end;
declare
Loc : constant Source_Ptr := Sloc (N);
Tnnn : constant Entity_Id := Make_Temporary (Loc, 'T');
FRTyp : constant Entity_Id := Etype (N);
Name : constant Node_Id := Relocate_Node (N);
begin
Prepend_To (Post_Call,
Make_Object_Declaration (Loc,
Defining_Identifier => Tnnn,
Object_Definition => New_Occurrence_Of (FRTyp, Loc),
Constant_Present => True,
Expression => Name));
Rewrite (N,
Make_Expression_With_Actions (Loc,
Actions => Post_Call,
Expression => New_Occurrence_Of (Tnnn, Loc)));
-- We don't want to just blindly call Analyze_And_Resolve
-- because that would cause unwanted recursion on the call.
-- So for a moment set the call as analyzed to prevent that
-- recursion, and get the rest analyzed properly, then reset
-- the analyzed flag, so our caller can continue.
Set_Analyzed (Name, True);
Analyze_And_Resolve (N, FRTyp);
Set_Analyzed (Name, False);
end;
-- If not the special Ada 2012 case of a function call, then we must
-- have the triggering statement of a triggering alternative or an
-- entry call alternative, and we can add the post call stuff to the
-- corresponding statement list.
else
pragma Assert (Nkind (Context) in N_Entry_Call_Alternative
| N_Triggering_Alternative);
if Is_Non_Empty_List (Statements (Context)) then
Insert_List_Before_And_Analyze
(First (Statements (Context)), Post_Call);
else
Set_Statements (Context, Post_Call);
end if;
end if;
-- A procedure call is always part of a declarative or statement list,
-- however a function call may appear nested within a construct. Most
-- cases of function call nesting are handled in the special case above.
-- The only exception is when the function call acts as an actual in a
-- procedure call. In this case the function call is in a list, but the
-- post-call actions must be inserted after the procedure call.
-- What if the function call is an aggregate component ???
elsif Nkind (Context) = N_Procedure_Call_Statement then
Insert_Actions_After (Context, Post_Call);
-- Otherwise, normal case where N is in a statement sequence, just put
-- the post-call stuff after the call statement.
else
Insert_Actions_After (N, Post_Call);
end if;
end Insert_Post_Call_Actions;
-----------------------------------
-- Is_Build_In_Place_Result_Type --
-----------------------------------
function Is_Build_In_Place_Result_Type (Typ : Entity_Id) return Boolean is
begin
if not Expander_Active then
return False;
end if;
-- In Ada 2005 all functions with an inherently limited return type
-- must be handled using a build-in-place profile, including the case
-- of a function with a limited interface result, where the function
-- may return objects of nonlimited descendants.
if Is_Limited_View (Typ) then
return Ada_Version >= Ada_2005 and then not Debug_Flag_Dot_L;
else
if Debug_Flag_Dot_9 then
return False;
end if;
if Has_Interfaces (Typ) then
return False;
end if;
declare
T : Entity_Id := Typ;
begin
-- For T'Class, return True if it's True for T. This is necessary
-- because a class-wide function might say "return F (...)", where
-- F returns the corresponding specific type. We need a loop in
-- case T is a subtype of a class-wide type.
while Is_Class_Wide_Type (T) loop
T := Etype (T);
end loop;
-- If this is a generic formal type in an instance, return True if
-- it's True for the generic actual type.
if Nkind (Parent (T)) = N_Subtype_Declaration
and then Present (Generic_Parent_Type (Parent (T)))
then
T := Entity (Subtype_Indication (Parent (T)));
if Present (Full_View (T)) then
T := Full_View (T);
end if;
end if;
if Present (Underlying_Type (T)) then
T := Underlying_Type (T);
end if;
declare
Result : Boolean;
-- So we can stop here in the debugger
begin
-- ???For now, enable build-in-place for a very narrow set of
-- controlled types. Change "if True" to "if False" to
-- experiment with more controlled types. Eventually, we might
-- like to enable build-in-place for all tagged types, all
-- types that need finalization, and all caller-unknown-size
-- types.
if True then
Result := Is_Controlled (T)
and then Present (Enclosing_Subprogram (T))
and then not Is_Compilation_Unit (Enclosing_Subprogram (T))
and then Ekind (Enclosing_Subprogram (T)) = E_Procedure;
else
Result := Is_Controlled (T);
end if;
return Result;
end;
end;
end if;
end Is_Build_In_Place_Result_Type;
------------------------------
-- Is_Build_In_Place_Entity --
------------------------------
function Is_Build_In_Place_Entity (E : Entity_Id) return Boolean is
Nam : constant String := Get_Name_String (Chars (E));
function Has_Suffix (Suffix : String) return Boolean;
-- Return True if Nam has suffix Suffix
function Has_Suffix (Suffix : String) return Boolean is
Len : constant Natural := Suffix'Length;
begin
return Nam'Length > Len
and then Nam (Nam'Last - Len + 1 .. Nam'Last) = Suffix;
end Has_Suffix;
-- Start of processing for Is_Build_In_Place_Entity
begin
return Has_Suffix (BIP_Alloc_Suffix)
or else Has_Suffix (BIP_Storage_Pool_Suffix)
or else Has_Suffix (BIP_Finalization_Master_Suffix)
or else Has_Suffix (BIP_Task_Master_Suffix)
or else Has_Suffix (BIP_Activation_Chain_Suffix)
or else Has_Suffix (BIP_Object_Access_Suffix);
end Is_Build_In_Place_Entity;
--------------------------------
-- Is_Build_In_Place_Function --
--------------------------------
function Is_Build_In_Place_Function (E : Entity_Id) return Boolean is
begin
-- This function is called from Expand_Subtype_From_Expr during
-- semantic analysis, even when expansion is off. In those cases
-- the build_in_place expansion will not take place.
if not Expander_Active then
return False;
end if;
-- For now we test whether E denotes a function or access-to-function
-- type whose result subtype is inherently limited. Later this test
-- may be revised to allow composite nonlimited types.
if Ekind (E) in E_Function | E_Generic_Function
or else (Ekind (E) = E_Subprogram_Type
and then Etype (E) /= Standard_Void_Type)
then
-- If the function is imported from a foreign language, we don't do
-- build-in-place. Note that Import (Ada) functions can do
-- build-in-place. Note that it is OK for a build-in-place function
-- to return a type with a foreign convention; the build-in-place
-- machinery will ensure there is no copying.
return Is_Build_In_Place_Result_Type (Etype (E))
and then not (Has_Foreign_Convention (E) and then Is_Imported (E))
and then not Debug_Flag_Dot_L;
else
return False;
end if;
end Is_Build_In_Place_Function;
-------------------------------------
-- Is_Build_In_Place_Function_Call --
-------------------------------------
function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean is
Exp_Node : constant Node_Id := Unqual_Conv (N);
Function_Id : Entity_Id;
begin
-- Return False if the expander is currently inactive, since awareness
-- of build-in-place treatment is only relevant during expansion. Note
-- that Is_Build_In_Place_Function, which is called as part of this
-- function, is also conditioned this way, but we need to check here as
-- well to avoid blowing up on processing protected calls when expansion
-- is disabled (such as with -gnatc) since those would trip over the
-- raise of Program_Error below.
-- In SPARK mode, build-in-place calls are not expanded, so that we
-- may end up with a call that is neither resolved to an entity, nor
-- an indirect call.
if not Expander_Active or else Nkind (Exp_Node) /= N_Function_Call then
return False;
end if;
if Is_Entity_Name (Name (Exp_Node)) then
Function_Id := Entity (Name (Exp_Node));
-- In the case of an explicitly dereferenced call, use the subprogram
-- type generated for the dereference.
elsif Nkind (Name (Exp_Node)) = N_Explicit_Dereference then
Function_Id := Etype (Name (Exp_Node));
-- This may be a call to a protected function.
elsif Nkind (Name (Exp_Node)) = N_Selected_Component then
Function_Id := Etype (Entity (Selector_Name (Name (Exp_Node))));
else
raise Program_Error;
end if;
declare
Result : constant Boolean := Is_Build_In_Place_Function (Function_Id);
-- So we can stop here in the debugger
begin
return Result;
end;
end Is_Build_In_Place_Function_Call;
-----------------------
-- Is_Null_Procedure --
-----------------------
function Is_Null_Procedure (Subp : Entity_Id) return Boolean is
Decl : constant Node_Id := Unit_Declaration_Node (Subp);
begin
if Ekind (Subp) /= E_Procedure then
return False;
-- Check if this is a declared null procedure
elsif Nkind (Decl) = N_Subprogram_Declaration then
if not Null_Present (Specification (Decl)) then
return False;
elsif No (Body_To_Inline (Decl)) then
return False;
-- Check if the body contains only a null statement, followed by
-- the return statement added during expansion.
else
declare
Orig_Bod : constant Node_Id := Body_To_Inline (Decl);
Stat : Node_Id;
Stat2 : Node_Id;
begin
if Nkind (Orig_Bod) /= N_Subprogram_Body then
return False;
else
-- We must skip SCIL nodes because they are currently
-- implemented as special N_Null_Statement nodes.
Stat :=
First_Non_SCIL_Node
(Statements (Handled_Statement_Sequence (Orig_Bod)));
Stat2 := Next_Non_SCIL_Node (Stat);
return
Is_Empty_List (Declarations (Orig_Bod))
and then Nkind (Stat) = N_Null_Statement
and then
(No (Stat2)
or else
(Nkind (Stat2) = N_Simple_Return_Statement
and then No (Next (Stat2))));
end if;
end;
end if;
else
return False;
end if;
end Is_Null_Procedure;
-------------------------------------------
-- Make_Build_In_Place_Call_In_Allocator --
-------------------------------------------
procedure Make_Build_In_Place_Call_In_Allocator
(Allocator : Node_Id;
Function_Call : Node_Id)
is
Acc_Type : constant Entity_Id := Etype (Allocator);
Loc : constant Source_Ptr := Sloc (Function_Call);
Func_Call : Node_Id := Function_Call;
Ref_Func_Call : Node_Id;
Function_Id : Entity_Id;
Result_Subt : Entity_Id;
New_Allocator : Node_Id;
Return_Obj_Access : Entity_Id; -- temp for function result
Temp_Init : Node_Id; -- initial value of Return_Obj_Access
Alloc_Form : BIP_Allocation_Form;
Pool : Node_Id; -- nonnull if Alloc_Form = User_Storage_Pool
Return_Obj_Actual : Node_Id; -- the temp.all, in caller-allocates case
Chain : Entity_Id; -- activation chain, in case of tasks
begin
-- Step past qualification or unchecked conversion (the latter can occur
-- in cases of calls to 'Input).
if Nkind (Func_Call) in N_Qualified_Expression
| N_Type_Conversion
| N_Unchecked_Type_Conversion
then
Func_Call := Expression (Func_Call);
end if;
-- Mark the call as processed as a build-in-place call
pragma Assert (not Is_Expanded_Build_In_Place_Call (Func_Call));
Set_Is_Expanded_Build_In_Place_Call (Func_Call);
if Is_Entity_Name (Name (Func_Call)) then
Function_Id := Entity (Name (Func_Call));
elsif Nkind (Name (Func_Call)) = N_Explicit_Dereference then
Function_Id := Etype (Name (Func_Call));
else
raise Program_Error;
end if;
Warn_BIP (Func_Call);
Result_Subt := Available_View (Etype (Function_Id));
-- Create a temp for the function result. In the caller-allocates case,
-- this will be initialized to the result of a new uninitialized
-- allocator. Note: we do not use Allocator as the Related_Node of
-- Return_Obj_Access in call to Make_Temporary below as this would
-- create a sort of infinite "recursion".
Return_Obj_Access := Make_Temporary (Loc, 'R');
Set_Etype (Return_Obj_Access, Acc_Type);
Set_Can_Never_Be_Null (Acc_Type, False);
-- It gets initialized to null, so we can't have that
-- When the result subtype is constrained, the return object is created
-- on the caller side, and access to it is passed to the function. This
-- optimization is disabled when the result subtype needs finalization
-- actions because the caller side allocation may result in undesirable
-- finalization. Consider the following example:
--
-- function Make_Lim_Ctrl return Lim_Ctrl is
-- begin
-- return Result : Lim_Ctrl := raise Program_Error do
-- null;
-- end return;
-- end Make_Lim_Ctrl;
--
-- Obj : Lim_Ctrl_Ptr := new Lim_Ctrl'(Make_Lim_Ctrl);
--
-- Even though the size of limited controlled type Lim_Ctrl is known,
-- allocating Obj at the caller side will chain Obj on Lim_Ctrl_Ptr's
-- finalization master. The subsequent call to Make_Lim_Ctrl will fail
-- during the initialization actions for Result, which implies that
-- Result (and Obj by extension) should not be finalized. However Obj
-- will be finalized when access type Lim_Ctrl_Ptr goes out of scope
-- since it is already attached on the related finalization master.
-- Here and in related routines, we must examine the full view of the
-- type, because the view at the point of call may differ from the
-- one in the function body, and the expansion mechanism depends on
-- the characteristics of the full view.
if Needs_BIP_Alloc_Form (Function_Id) then
Temp_Init := Empty;
-- Case of a user-defined storage pool. Pass an allocation parameter
-- indicating that the function should allocate its result in the
-- pool, and pass the pool. Use 'Unrestricted_Access because the
-- pool may not be aliased.
if Present (Associated_Storage_Pool (Acc_Type)) then
Alloc_Form := User_Storage_Pool;
Pool :=
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of
(Associated_Storage_Pool (Acc_Type), Loc),
Attribute_Name => Name_Unrestricted_Access);
-- No user-defined pool; pass an allocation parameter indicating that
-- the function should allocate its result on the heap.
else
Alloc_Form := Global_Heap;
Pool := Make_Null (No_Location);
end if;
-- The caller does not provide the return object in this case, so we
-- have to pass null for the object access actual.
Return_Obj_Actual := Empty;
else
-- Replace the initialized allocator of form "new T'(Func (...))"
-- with an uninitialized allocator of form "new T", where T is the
-- result subtype of the called function. The call to the function
-- is handled separately further below.
New_Allocator :=
Make_Allocator (Loc,
Expression => New_Occurrence_Of (Result_Subt, Loc));
Set_No_Initialization (New_Allocator);
-- Copy attributes to new allocator. Note that the new allocator
-- logically comes from source if the original one did, so copy the
-- relevant flag. This ensures proper treatment of the restriction
-- No_Implicit_Heap_Allocations in this case.
Set_Storage_Pool (New_Allocator, Storage_Pool (Allocator));
Set_Procedure_To_Call (New_Allocator, Procedure_To_Call (Allocator));
Set_Comes_From_Source (New_Allocator, Comes_From_Source (Allocator));
Rewrite (Allocator, New_Allocator);
-- Initial value of the temp is the result of the uninitialized
-- allocator. Unchecked_Convert is needed for T'Input where T is
-- derived from a controlled type.
Temp_Init := Relocate_Node (Allocator);
if Nkind (Function_Call) in
N_Type_Conversion | N_Unchecked_Type_Conversion
then
Temp_Init := Unchecked_Convert_To (Acc_Type, Temp_Init);
end if;
-- Indicate that caller allocates, and pass in the return object
Alloc_Form := Caller_Allocation;
Pool := Make_Null (No_Location);
Return_Obj_Actual :=
Make_Unchecked_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Result_Subt, Loc),
Expression =>
Make_Explicit_Dereference (Loc,
Prefix => New_Occurrence_Of (Return_Obj_Access, Loc)));
-- When the result subtype is unconstrained, the function itself must
-- perform the allocation of the return object, so we pass parameters
-- indicating that.
end if;
-- Declare the temp object
Insert_Action (Allocator,
Make_Object_Declaration (Loc,
Defining_Identifier => Return_Obj_Access,
Object_Definition => New_Occurrence_Of (Acc_Type, Loc),
Expression => Temp_Init));
Ref_Func_Call := Make_Reference (Loc, Func_Call);
-- Ada 2005 (AI-251): If the type of the allocator is an interface
-- then generate an implicit conversion to force displacement of the
-- "this" pointer.
if Is_Interface (Designated_Type (Acc_Type)) then
Rewrite
(Ref_Func_Call,
OK_Convert_To (Acc_Type, Ref_Func_Call));
-- If the types are incompatible, we need an unchecked conversion. Note
-- that the full types will be compatible, but the types not visibly
-- compatible.
elsif Nkind (Function_Call)
in N_Type_Conversion | N_Unchecked_Type_Conversion
then
Ref_Func_Call := Unchecked_Convert_To (Acc_Type, Ref_Func_Call);
end if;
declare
Assign : constant Node_Id :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Return_Obj_Access, Loc),
Expression => Ref_Func_Call);
-- Assign the result of the function call into the temp. In the
-- caller-allocates case, this is overwriting the temp with its
-- initial value, which has no effect. In the callee-allocates case,
-- this is setting the temp to point to the object allocated by the
-- callee. Unchecked_Convert is needed for T'Input where T is derived
-- from a controlled type.
Actions : List_Id;
-- Actions to be inserted. If there are no tasks, this is just the
-- assignment statement. If the allocated object has tasks, we need
-- to wrap the assignment in a block that activates them. The
-- activation chain of that block must be passed to the function,
-- rather than some outer chain.
begin
if Might_Have_Tasks (Result_Subt) then
Actions := New_List;
Build_Task_Allocate_Block_With_Init_Stmts
(Actions, Allocator, Init_Stmts => New_List (Assign));
Chain := Activation_Chain_Entity (Last (Actions));
else
Actions := New_List (Assign);
Chain := Empty;
end if;
Insert_Actions (Allocator, Actions);
end;
-- When the function has a controlling result, an allocation-form
-- parameter must be passed indicating that the caller is allocating
-- the result object. This is needed because such a function can be
-- called as a dispatching operation and must be treated similarly
-- to functions with unconstrained result subtypes.
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Alloc_Form, Pool_Actual => Pool);
Add_Finalization_Master_Actual_To_Build_In_Place_Call
(Func_Call, Function_Id, Acc_Type);
Add_Task_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Master_Actual => Master_Id (Acc_Type),
Chain => Chain);
-- Add an implicit actual to the function call that provides access
-- to the allocated object. An unchecked conversion to the (specific)
-- result subtype of the function is inserted to handle cases where
-- the access type of the allocator has a class-wide designated type.
Add_Access_Actual_To_Build_In_Place_Call
(Func_Call, Function_Id, Return_Obj_Actual);
-- Finally, replace the allocator node with a reference to the temp
Rewrite (Allocator, New_Occurrence_Of (Return_Obj_Access, Loc));
Analyze_And_Resolve (Allocator, Acc_Type);
pragma Assert (Check_Number_Of_Actuals (Func_Call, Function_Id));
pragma Assert (Check_BIP_Actuals (Func_Call, Function_Id));
end Make_Build_In_Place_Call_In_Allocator;
---------------------------------------------------
-- Make_Build_In_Place_Call_In_Anonymous_Context --
---------------------------------------------------
procedure Make_Build_In_Place_Call_In_Anonymous_Context
(Function_Call : Node_Id)
is
Loc : constant Source_Ptr := Sloc (Function_Call);
Func_Call : constant Node_Id := Unqual_Conv (Function_Call);
Function_Id : Entity_Id;
Result_Subt : Entity_Id;
Return_Obj_Id : Entity_Id;
Return_Obj_Decl : Entity_Id;
begin
-- If the call has already been processed to add build-in-place actuals
-- then return. One place this can occur is for calls to build-in-place
-- functions that occur within a call to a protected operation, where
-- due to rewriting and expansion of the protected call there can be
-- more than one call to Expand_Actuals for the same set of actuals.
if Is_Expanded_Build_In_Place_Call (Func_Call) then
return;
end if;
-- Mark the call as processed as a build-in-place call
Set_Is_Expanded_Build_In_Place_Call (Func_Call);
if Is_Entity_Name (Name (Func_Call)) then
Function_Id := Entity (Name (Func_Call));
elsif Nkind (Name (Func_Call)) = N_Explicit_Dereference then
Function_Id := Etype (Name (Func_Call));
else
raise Program_Error;
end if;
Warn_BIP (Func_Call);
Result_Subt := Etype (Function_Id);
-- If the build-in-place function returns a controlled object, then the
-- object needs to be finalized immediately after the context. Since
-- this case produces a transient scope, the servicing finalizer needs
-- to name the returned object. Create a temporary which is initialized
-- with the function call:
--
-- Temp_Id : Func_Type := BIP_Func_Call;
--
-- The initialization expression of the temporary will be rewritten by
-- the expander using the appropriate mechanism in Make_Build_In_Place_
-- Call_In_Object_Declaration.
if Needs_Finalization (Result_Subt) then
declare
Temp_Id : constant Entity_Id := Make_Temporary (Loc, 'R');
Temp_Decl : Node_Id;
begin
-- Reset the guard on the function call since the following does
-- not perform actual call expansion.
Set_Is_Expanded_Build_In_Place_Call (Func_Call, False);
Temp_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp_Id,
Object_Definition =>
New_Occurrence_Of (Result_Subt, Loc),
Expression =>
New_Copy_Tree (Function_Call));
Insert_Action (Function_Call, Temp_Decl);
Rewrite (Function_Call, New_Occurrence_Of (Temp_Id, Loc));
Analyze (Function_Call);
end;
-- When the result subtype is definite, an object of the subtype is
-- declared and an access value designating it is passed as an actual.
elsif Caller_Known_Size (Func_Call, Result_Subt) then
-- Create a temporary object to hold the function result
Return_Obj_Id := Make_Temporary (Loc, 'R');
Set_Etype (Return_Obj_Id, Result_Subt);
Return_Obj_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Return_Obj_Id,
Aliased_Present => True,
Object_Definition => New_Occurrence_Of (Result_Subt, Loc));
Set_No_Initialization (Return_Obj_Decl);
Insert_Action (Func_Call, Return_Obj_Decl);
-- When the function has a controlling result, an allocation-form
-- parameter must be passed indicating that the caller is allocating
-- the result object. This is needed because such a function can be
-- called as a dispatching operation and must be treated similarly
-- to functions with unconstrained result subtypes.
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Alloc_Form => Caller_Allocation);
Add_Finalization_Master_Actual_To_Build_In_Place_Call
(Func_Call, Function_Id);
Add_Task_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Make_Identifier (Loc, Name_uMaster));
-- Add an implicit actual to the function call that provides access
-- to the caller's return object.
Add_Access_Actual_To_Build_In_Place_Call
(Func_Call, Function_Id, New_Occurrence_Of (Return_Obj_Id, Loc));
pragma Assert (Check_Number_Of_Actuals (Func_Call, Function_Id));
pragma Assert (Check_BIP_Actuals (Func_Call, Function_Id));
-- When the result subtype is unconstrained, the function must allocate
-- the return object in the secondary stack, so appropriate implicit
-- parameters are added to the call to indicate that. A transient
-- scope is established to ensure eventual cleanup of the result.
else
-- Pass an allocation parameter indicating that the function should
-- allocate its result on the secondary stack.
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Alloc_Form => Secondary_Stack);
Add_Finalization_Master_Actual_To_Build_In_Place_Call
(Func_Call, Function_Id);
Add_Task_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Make_Identifier (Loc, Name_uMaster));
-- Pass a null value to the function since no return object is
-- available on the caller side.
Add_Access_Actual_To_Build_In_Place_Call
(Func_Call, Function_Id, Empty);
pragma Assert (Check_Number_Of_Actuals (Func_Call, Function_Id));
pragma Assert (Check_BIP_Actuals (Func_Call, Function_Id));
end if;
end Make_Build_In_Place_Call_In_Anonymous_Context;
--------------------------------------------
-- Make_Build_In_Place_Call_In_Assignment --
--------------------------------------------
procedure Make_Build_In_Place_Call_In_Assignment
(Assign : Node_Id;
Function_Call : Node_Id)
is
Func_Call : constant Node_Id := Unqual_Conv (Function_Call);
Lhs : constant Node_Id := Name (Assign);
Loc : constant Source_Ptr := Sloc (Function_Call);
Func_Id : Entity_Id;
Obj_Decl : Node_Id;
Obj_Id : Entity_Id;
Ptr_Typ : Entity_Id;
Ptr_Typ_Decl : Node_Id;
New_Expr : Node_Id;
Result_Subt : Entity_Id;
begin
-- Mark the call as processed as a build-in-place call
pragma Assert (not Is_Expanded_Build_In_Place_Call (Func_Call));
Set_Is_Expanded_Build_In_Place_Call (Func_Call);
if Is_Entity_Name (Name (Func_Call)) then
Func_Id := Entity (Name (Func_Call));
elsif Nkind (Name (Func_Call)) = N_Explicit_Dereference then
Func_Id := Etype (Name (Func_Call));
else
raise Program_Error;
end if;
Warn_BIP (Func_Call);
Result_Subt := Etype (Func_Id);
-- When the result subtype is unconstrained, an additional actual must
-- be passed to indicate that the caller is providing the return object.
-- This parameter must also be passed when the called function has a
-- controlling result, because dispatching calls to the function needs
-- to be treated effectively the same as calls to class-wide functions.
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Func_Call, Func_Id, Alloc_Form => Caller_Allocation);
Add_Finalization_Master_Actual_To_Build_In_Place_Call
(Func_Call, Func_Id);
Add_Task_Actuals_To_Build_In_Place_Call
(Func_Call, Func_Id, Make_Identifier (Loc, Name_uMaster));
-- Add an implicit actual to the function call that provides access to
-- the caller's return object.
Add_Access_Actual_To_Build_In_Place_Call
(Func_Call,
Func_Id,
Make_Unchecked_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Result_Subt, Loc),
Expression => Relocate_Node (Lhs)));
-- Create an access type designating the function's result subtype
Ptr_Typ := Make_Temporary (Loc, 'A');
Ptr_Typ_Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Ptr_Typ,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
All_Present => True,
Subtype_Indication =>
New_Occurrence_Of (Result_Subt, Loc)));
Insert_After_And_Analyze (Assign, Ptr_Typ_Decl);
-- Finally, create an access object initialized to a reference to the
-- function call. We know this access value is non-null, so mark the
-- entity accordingly to suppress junk access checks.
New_Expr := Make_Reference (Loc, Relocate_Node (Func_Call));
-- Add a conversion if it's the wrong type
if Etype (New_Expr) /= Ptr_Typ then
New_Expr :=
Make_Unchecked_Type_Conversion (Loc,
New_Occurrence_Of (Ptr_Typ, Loc), New_Expr);
end if;
Obj_Id := Make_Temporary (Loc, 'R', New_Expr);
Set_Etype (Obj_Id, Ptr_Typ);
Set_Is_Known_Non_Null (Obj_Id);
Obj_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Obj_Id,
Object_Definition => New_Occurrence_Of (Ptr_Typ, Loc),
Expression => New_Expr);
Insert_After_And_Analyze (Ptr_Typ_Decl, Obj_Decl);
Rewrite (Assign, Make_Null_Statement (Loc));
pragma Assert (Check_Number_Of_Actuals (Func_Call, Func_Id));
pragma Assert (Check_BIP_Actuals (Func_Call, Func_Id));
end Make_Build_In_Place_Call_In_Assignment;
----------------------------------------------------
-- Make_Build_In_Place_Call_In_Object_Declaration --
----------------------------------------------------
procedure Make_Build_In_Place_Call_In_Object_Declaration
(Obj_Decl : Node_Id;
Function_Call : Node_Id)
is
function Get_Function_Id (Func_Call : Node_Id) return Entity_Id;
-- Get the value of Function_Id, below
---------------------
-- Get_Function_Id --
---------------------
function Get_Function_Id (Func_Call : Node_Id) return Entity_Id is
begin
if Is_Entity_Name (Name (Func_Call)) then
return Entity (Name (Func_Call));
elsif Nkind (Name (Func_Call)) = N_Explicit_Dereference then
return Etype (Name (Func_Call));
else
raise Program_Error;
end if;
end Get_Function_Id;
-- Local variables
Func_Call : constant Node_Id := Unqual_Conv (Function_Call);
Function_Id : constant Entity_Id := Get_Function_Id (Func_Call);
Loc : constant Source_Ptr := Sloc (Function_Call);
Obj_Loc : constant Source_Ptr := Sloc (Obj_Decl);
Obj_Def_Id : constant Entity_Id := Defining_Identifier (Obj_Decl);
Obj_Typ : constant Entity_Id := Etype (Obj_Def_Id);
Encl_Func : constant Entity_Id := Enclosing_Subprogram (Obj_Def_Id);
Result_Subt : constant Entity_Id := Etype (Function_Id);
Call_Deref : Node_Id;
Caller_Object : Node_Id;
Def_Id : Entity_Id;
Designated_Type : Entity_Id;
Fmaster_Actual : Node_Id := Empty;
Pool_Actual : Node_Id;
Ptr_Typ : Entity_Id;
Ptr_Typ_Decl : Node_Id;
Pass_Caller_Acc : Boolean := False;
Res_Decl : Node_Id;
Definite : constant Boolean :=
Caller_Known_Size (Func_Call, Result_Subt)
and then not Is_Class_Wide_Type (Obj_Typ);
-- In the case of "X : T'Class := F(...);", where F returns a
-- Caller_Known_Size (specific) tagged type, we treat it as
-- indefinite, because the code for the Definite case below sets the
-- initialization expression of the object to Empty, which would be
-- illegal Ada, and would cause gigi to misallocate X.
-- Start of processing for Make_Build_In_Place_Call_In_Object_Declaration
begin
-- If the call has already been processed to add build-in-place actuals
-- then return.
if Is_Expanded_Build_In_Place_Call (Func_Call) then
return;
end if;
-- Mark the call as processed as a build-in-place call
Set_Is_Expanded_Build_In_Place_Call (Func_Call);
Warn_BIP (Func_Call);
-- Create an access type designating the function's result subtype.
-- We use the type of the original call because it may be a call to an
-- inherited operation, which the expansion has replaced with the parent
-- operation that yields the parent type. Note that this access type
-- must be declared before we establish a transient scope, so that it
-- receives the proper accessibility level.
if Is_Class_Wide_Type (Obj_Typ)
and then not Is_Interface (Obj_Typ)
and then not Is_Class_Wide_Type (Etype (Function_Call))
then
Designated_Type := Obj_Typ;
else
Designated_Type := Etype (Function_Call);
end if;
Ptr_Typ := Make_Temporary (Loc, 'A');
Ptr_Typ_Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Ptr_Typ,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
All_Present => True,
Subtype_Indication =>
New_Occurrence_Of (Designated_Type, Loc)));
-- The access type and its accompanying object must be inserted after
-- the object declaration in the constrained case, so that the function
-- call can be passed access to the object. In the indefinite case, or
-- if the object declaration is for a return object, the access type and
-- object must be inserted before the object, since the object
-- declaration is rewritten to be a renaming of a dereference of the
-- access object. Note: we need to freeze Ptr_Typ explicitly, because
-- the result object is in a different (transient) scope, so won't cause
-- freezing.
if Definite and then not Is_Return_Object (Obj_Def_Id) then
-- The presence of an address clause complicates the build-in-place
-- expansion because the indicated address must be processed before
-- the indirect call is generated (including the definition of a
-- local pointer to the object). The address clause may come from
-- an aspect specification or from an explicit attribute
-- specification appearing after the object declaration. These two
-- cases require different processing.
if Has_Aspect (Obj_Def_Id, Aspect_Address) then
-- Skip non-delayed pragmas that correspond to other aspects, if
-- any, to find proper insertion point for freeze node of object.
declare
D : Node_Id := Obj_Decl;
N : Node_Id := Next (D);
begin
while Present (N)
and then Nkind (N) in N_Attribute_Reference | N_Pragma
loop
Analyze (N);
D := N;
Next (N);
end loop;
Insert_After (D, Ptr_Typ_Decl);
-- Freeze object before pointer declaration, to ensure that
-- generated attribute for address is inserted at the proper
-- place.
Freeze_Before (Ptr_Typ_Decl, Obj_Def_Id);
end;
Analyze (Ptr_Typ_Decl);
elsif Present (Following_Address_Clause (Obj_Decl)) then
-- Locate explicit address clause, which may also follow pragmas
-- generated by other aspect specifications.
declare
Addr : constant Node_Id := Following_Address_Clause (Obj_Decl);
D : Node_Id := Next (Obj_Decl);
begin
while Present (D) loop
Analyze (D);
exit when D = Addr;
Next (D);
end loop;
Insert_After_And_Analyze (Addr, Ptr_Typ_Decl);
end;
else
Insert_After_And_Analyze (Obj_Decl, Ptr_Typ_Decl);
end if;
else
Insert_Action (Obj_Decl, Ptr_Typ_Decl);
end if;
-- Force immediate freezing of Ptr_Typ because Res_Decl will be
-- elaborated in an inner (transient) scope and thus won't cause
-- freezing by itself. It's not an itype, but it needs to be frozen
-- inside the current subprogram (see Freeze_Outside in freeze.adb).
Freeze_Itype (Ptr_Typ, Ptr_Typ_Decl);
-- If the object is a return object of an enclosing build-in-place
-- function, then the implicit build-in-place parameters of the
-- enclosing function are simply passed along to the called function.
-- (Unfortunately, this won't cover the case of extension aggregates
-- where the ancestor part is a build-in-place indefinite function
-- call that should be passed along the caller's parameters.
-- Currently those get mishandled by reassigning the result of the
-- call to the aggregate return object, when the call result should
-- really be directly built in place in the aggregate and not in a
-- temporary. ???)
if Is_Return_Object (Obj_Def_Id) then
Pass_Caller_Acc := True;
-- When the enclosing function has a BIP_Alloc_Form formal then we
-- pass it along to the callee (such as when the enclosing function
-- has an unconstrained or tagged result type).
if Needs_BIP_Alloc_Form (Encl_Func) then
if RTE_Available (RE_Root_Storage_Pool_Ptr) then
Pool_Actual :=
New_Occurrence_Of
(Build_In_Place_Formal
(Encl_Func, BIP_Storage_Pool), Loc);
-- The build-in-place pool formal is not built on e.g. ZFP
else
Pool_Actual := Empty;
end if;
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Function_Call => Func_Call,
Function_Id => Function_Id,
Alloc_Form_Exp =>
New_Occurrence_Of
(Build_In_Place_Formal (Encl_Func, BIP_Alloc_Form), Loc),
Pool_Actual => Pool_Actual);
-- Otherwise, if enclosing function has a definite result subtype,
-- then caller allocation will be used.
else
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Alloc_Form => Caller_Allocation);
end if;
if Needs_BIP_Finalization_Master (Encl_Func) then
Fmaster_Actual :=
New_Occurrence_Of
(Build_In_Place_Formal
(Encl_Func, BIP_Finalization_Master), Loc);
end if;
-- Retrieve the BIPacc formal from the enclosing function and convert
-- it to the access type of the callee's BIP_Object_Access formal.
Caller_Object :=
Make_Unchecked_Type_Conversion (Loc,
Subtype_Mark =>
New_Occurrence_Of
(Etype (Build_In_Place_Formal
(Function_Id, BIP_Object_Access)),
Loc),
Expression =>
New_Occurrence_Of
(Build_In_Place_Formal (Encl_Func, BIP_Object_Access),
Loc));
-- In the definite case, add an implicit actual to the function call
-- that provides access to the declared object. An unchecked conversion
-- to the (specific) result type of the function is inserted to handle
-- the case where the object is declared with a class-wide type.
elsif Definite then
Caller_Object :=
Make_Unchecked_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Result_Subt, Loc),
Expression => New_Occurrence_Of (Obj_Def_Id, Loc));
-- When the function has a controlling result, an allocation-form
-- parameter must be passed indicating that the caller is allocating
-- the result object. This is needed because such a function can be
-- called as a dispatching operation and must be treated similarly to
-- functions with indefinite result subtypes.
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Alloc_Form => Caller_Allocation);
-- The allocation for indefinite library-level objects occurs on the
-- heap as opposed to the secondary stack. This accommodates DLLs where
-- the secondary stack is destroyed after each library unload. This is a
-- hybrid mechanism where a stack-allocated object lives on the heap.
elsif Is_Library_Level_Entity (Obj_Def_Id)
and then not Restriction_Active (No_Implicit_Heap_Allocations)
then
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Alloc_Form => Global_Heap);
Caller_Object := Empty;
-- Create a finalization master for the access result type to ensure
-- that the heap allocation can properly chain the object and later
-- finalize it when the library unit goes out of scope.
if Needs_Finalization (Etype (Func_Call)) then
Build_Finalization_Master
(Typ => Ptr_Typ,
For_Lib_Level => True,
Insertion_Node => Ptr_Typ_Decl);
Fmaster_Actual :=
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Finalization_Master (Ptr_Typ), Loc),
Attribute_Name => Name_Unrestricted_Access);
end if;
-- In other indefinite cases, pass an indication to do the allocation
-- on the secondary stack and set Caller_Object to Empty so that a null
-- value will be passed for the caller's object address. A transient
-- scope is established to ensure eventual cleanup of the result.
else
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Alloc_Form => Secondary_Stack);
Caller_Object := Empty;
Establish_Transient_Scope (Obj_Decl, Manage_Sec_Stack => True);
end if;
-- Pass along any finalization master actual, which is needed in the
-- case where the called function initializes a return object of an
-- enclosing build-in-place function.
Add_Finalization_Master_Actual_To_Build_In_Place_Call
(Func_Call => Func_Call,
Func_Id => Function_Id,
Master_Exp => Fmaster_Actual);
if Nkind (Parent (Obj_Decl)) = N_Extended_Return_Statement
and then Needs_BIP_Task_Actuals (Function_Id)
then
-- Here we're passing along the master that was passed in to this
-- function.
Add_Task_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id,
Master_Actual =>
New_Occurrence_Of
(Build_In_Place_Formal (Encl_Func, BIP_Task_Master), Loc));
else
Add_Task_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Make_Identifier (Loc, Name_uMaster));
end if;
Add_Access_Actual_To_Build_In_Place_Call
(Func_Call,
Function_Id,
Caller_Object,
Is_Access => Pass_Caller_Acc);
-- Finally, create an access object initialized to a reference to the
-- function call. We know this access value cannot be null, so mark the
-- entity accordingly to suppress the access check. We need to suppress
-- warnings, because this can be part of the expansion of "for ... of"
-- and similar constructs that generate finalization actions. Such
-- finalization actions are safe, because they check a count that
-- indicates which objects should be finalized, but the back end
-- nonetheless warns about uninitialized objects.
Def_Id := Make_Temporary (Loc, 'R', Func_Call);
Set_Warnings_Off (Def_Id);
Set_Etype (Def_Id, Ptr_Typ);
Set_Is_Known_Non_Null (Def_Id);
if Nkind (Function_Call) in N_Type_Conversion
| N_Unchecked_Type_Conversion
then
Res_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Def_Id,
Constant_Present => True,
Object_Definition => New_Occurrence_Of (Ptr_Typ, Loc),
Expression =>
Make_Unchecked_Type_Conversion (Loc,
New_Occurrence_Of (Ptr_Typ, Loc),
Make_Reference (Loc, Relocate_Node (Func_Call))));
else
Res_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Def_Id,
Constant_Present => True,
Object_Definition => New_Occurrence_Of (Ptr_Typ, Loc),
Expression =>
Make_Reference (Loc, Relocate_Node (Func_Call)));
end if;
Insert_After_And_Analyze (Ptr_Typ_Decl, Res_Decl);
-- If the result subtype of the called function is definite and is not
-- itself the return expression of an enclosing BIP function, then mark
-- the object as having no initialization.
if Definite and then not Is_Return_Object (Obj_Def_Id) then
-- The related object declaration is encased in a transient block
-- because the build-in-place function call contains at least one
-- nested function call that produces a controlled transient
-- temporary:
-- Obj : ... := BIP_Func_Call (Ctrl_Func_Call);
-- Since the build-in-place expansion decouples the call from the
-- object declaration, the finalization machinery lacks the context
-- which prompted the generation of the transient block. To resolve
-- this scenario, store the build-in-place call.
if Scope_Is_Transient then
Set_BIP_Initialization_Call (Obj_Def_Id, Res_Decl);
end if;
Set_Expression (Obj_Decl, Empty);
Set_No_Initialization (Obj_Decl);
-- In case of an indefinite result subtype, or if the call is the
-- return expression of an enclosing BIP function, rewrite the object
-- declaration as an object renaming where the renamed object is a
-- dereference of <function_Call>'reference:
--
-- Obj : Subt renames <function_call>'Ref.all;
else
Call_Deref :=
Make_Explicit_Dereference (Obj_Loc,
Prefix => New_Occurrence_Of (Def_Id, Obj_Loc));
Rewrite (Obj_Decl,
Make_Object_Renaming_Declaration (Obj_Loc,
Defining_Identifier => Make_Temporary (Obj_Loc, 'D'),
Subtype_Mark =>
New_Occurrence_Of (Designated_Type, Obj_Loc),
Name => Call_Deref));
-- At this point, Defining_Identifier (Obj_Decl) is no longer equal
-- to Obj_Def_Id.
Set_Renamed_Object (Defining_Identifier (Obj_Decl), Call_Deref);
-- If the original entity comes from source, then mark the new
-- entity as needing debug information, even though it's defined
-- by a generated renaming that does not come from source, so that
-- the Materialize_Entity flag will be set on the entity when
-- Debug_Renaming_Declaration is called during analysis.
if Comes_From_Source (Obj_Def_Id) then
Set_Debug_Info_Needed (Defining_Identifier (Obj_Decl));
end if;
Analyze (Obj_Decl);
Replace_Renaming_Declaration_Id
(Obj_Decl, Original_Node (Obj_Decl));
end if;
pragma Assert (Check_Number_Of_Actuals (Func_Call, Function_Id));
pragma Assert (Check_BIP_Actuals (Func_Call, Function_Id));
end Make_Build_In_Place_Call_In_Object_Declaration;
-------------------------------------------------
-- Make_Build_In_Place_Iface_Call_In_Allocator --
-------------------------------------------------
procedure Make_Build_In_Place_Iface_Call_In_Allocator
(Allocator : Node_Id;
Function_Call : Node_Id)
is
BIP_Func_Call : constant Node_Id :=
Unqual_BIP_Iface_Function_Call (Function_Call);
Loc : constant Source_Ptr := Sloc (Function_Call);
Anon_Type : Entity_Id;
Tmp_Decl : Node_Id;
Tmp_Id : Entity_Id;
begin
-- No action of the call has already been processed
if Is_Expanded_Build_In_Place_Call (BIP_Func_Call) then
return;
end if;
Tmp_Id := Make_Temporary (Loc, 'D');
-- Insert a temporary before N initialized with the BIP function call
-- without its enclosing type conversions and analyze it without its
-- expansion. This temporary facilitates us reusing the BIP machinery,
-- which takes care of adding the extra build-in-place actuals and
-- transforms this object declaration into an object renaming
-- declaration.
Anon_Type := Create_Itype (E_Anonymous_Access_Type, Function_Call);
Set_Directly_Designated_Type (Anon_Type, Etype (BIP_Func_Call));
Set_Etype (Anon_Type, Anon_Type);
Build_Class_Wide_Master (Anon_Type);
Tmp_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Tmp_Id,
Object_Definition => New_Occurrence_Of (Anon_Type, Loc),
Expression =>
Make_Allocator (Loc,
Expression =>
Make_Qualified_Expression (Loc,
Subtype_Mark =>
New_Occurrence_Of (Etype (BIP_Func_Call), Loc),
Expression => New_Copy_Tree (BIP_Func_Call))));
-- Manually set the associated node for the anonymous access type to
-- be its local declaration, to avoid confusing and complicating
-- the accessibility machinery.
Set_Associated_Node_For_Itype (Anon_Type, Tmp_Decl);
Expander_Mode_Save_And_Set (False);
Insert_Action (Allocator, Tmp_Decl);
Expander_Mode_Restore;
Make_Build_In_Place_Call_In_Allocator
(Allocator => Expression (Tmp_Decl),
Function_Call => Expression (Expression (Tmp_Decl)));
-- Add a conversion to displace the pointer to the allocated object
-- to reference the corresponding dispatch table.
Rewrite (Allocator,
Convert_To (Etype (Allocator),
New_Occurrence_Of (Tmp_Id, Loc)));
end Make_Build_In_Place_Iface_Call_In_Allocator;
---------------------------------------------------------
-- Make_Build_In_Place_Iface_Call_In_Anonymous_Context --
---------------------------------------------------------
procedure Make_Build_In_Place_Iface_Call_In_Anonymous_Context
(Function_Call : Node_Id)
is
BIP_Func_Call : constant Node_Id :=
Unqual_BIP_Iface_Function_Call (Function_Call);
Loc : constant Source_Ptr := Sloc (Function_Call);
Tmp_Decl : Node_Id;
Tmp_Id : Entity_Id;
begin
-- No action of the call has already been processed
if Is_Expanded_Build_In_Place_Call (BIP_Func_Call) then
return;
end if;
pragma Assert (Needs_Finalization (Etype (BIP_Func_Call)));
-- Insert a temporary before the call initialized with function call to
-- reuse the BIP machinery which takes care of adding the extra build-in
-- place actuals and transforms this object declaration into an object
-- renaming declaration.
Tmp_Id := Make_Temporary (Loc, 'D');
Tmp_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Tmp_Id,
Object_Definition =>
New_Occurrence_Of (Etype (Function_Call), Loc),
Expression => Relocate_Node (Function_Call));
Expander_Mode_Save_And_Set (False);
Insert_Action (Function_Call, Tmp_Decl);
Expander_Mode_Restore;
Make_Build_In_Place_Iface_Call_In_Object_Declaration
(Obj_Decl => Tmp_Decl,
Function_Call => Expression (Tmp_Decl));
end Make_Build_In_Place_Iface_Call_In_Anonymous_Context;
----------------------------------------------------------
-- Make_Build_In_Place_Iface_Call_In_Object_Declaration --
----------------------------------------------------------
procedure Make_Build_In_Place_Iface_Call_In_Object_Declaration
(Obj_Decl : Node_Id;
Function_Call : Node_Id)
is
BIP_Func_Call : constant Node_Id :=
Unqual_BIP_Iface_Function_Call (Function_Call);
Loc : constant Source_Ptr := Sloc (Function_Call);
Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
Tmp_Decl : Node_Id;
Tmp_Id : Entity_Id;
begin
-- No action of the call has already been processed
if Is_Expanded_Build_In_Place_Call (BIP_Func_Call) then
return;
end if;
Tmp_Id := Make_Temporary (Loc, 'D');
-- Insert a temporary before N initialized with the BIP function call
-- without its enclosing type conversions and analyze it without its
-- expansion. This temporary facilitates us reusing the BIP machinery,
-- which takes care of adding the extra build-in-place actuals and
-- transforms this object declaration into an object renaming
-- declaration.
Tmp_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Tmp_Id,
Object_Definition =>
New_Occurrence_Of (Etype (BIP_Func_Call), Loc),
Expression => New_Copy_Tree (BIP_Func_Call));
Expander_Mode_Save_And_Set (False);
Insert_Action (Obj_Decl, Tmp_Decl);
Expander_Mode_Restore;
Make_Build_In_Place_Call_In_Object_Declaration
(Obj_Decl => Tmp_Decl,
Function_Call => Expression (Tmp_Decl));
pragma Assert (Nkind (Tmp_Decl) = N_Object_Renaming_Declaration);
-- Replace the original build-in-place function call by a reference to
-- the resulting temporary object renaming declaration. In this way,
-- all the interface conversions performed in the original Function_Call
-- on the build-in-place object are preserved.
Rewrite (BIP_Func_Call, New_Occurrence_Of (Tmp_Id, Loc));
-- Replace the original object declaration by an internal object
-- renaming declaration. This leaves the generated code more clean (the
-- build-in-place function call in an object renaming declaration and
-- displacements of the pointer to the build-in-place object in another
-- renaming declaration) and allows us to invoke the routine that takes
-- care of replacing the identifier of the renaming declaration (routine
-- originally developed for the regular build-in-place management).
Rewrite (Obj_Decl,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'D'),
Subtype_Mark => New_Occurrence_Of (Etype (Obj_Id), Loc),
Name => Function_Call));
Analyze (Obj_Decl);
Replace_Renaming_Declaration_Id (Obj_Decl, Original_Node (Obj_Decl));
end Make_Build_In_Place_Iface_Call_In_Object_Declaration;
--------------------------------------------
-- Make_CPP_Constructor_Call_In_Allocator --
--------------------------------------------
procedure Make_CPP_Constructor_Call_In_Allocator
(Allocator : Node_Id;
Function_Call : Node_Id)
is
Loc : constant Source_Ptr := Sloc (Function_Call);
Acc_Type : constant Entity_Id := Etype (Allocator);
Function_Id : constant Entity_Id := Entity (Name (Function_Call));
Result_Subt : constant Entity_Id := Available_View (Etype (Function_Id));
New_Allocator : Node_Id;
Return_Obj_Access : Entity_Id;
Tmp_Obj : Node_Id;
begin
pragma Assert (Nkind (Allocator) = N_Allocator
and then Nkind (Function_Call) = N_Function_Call);
pragma Assert (Convention (Function_Id) = Convention_CPP
and then Is_Constructor (Function_Id));
pragma Assert (Is_Constrained (Underlying_Type (Result_Subt)));
-- Replace the initialized allocator of form "new T'(Func (...))" with
-- an uninitialized allocator of form "new T", where T is the result
-- subtype of the called function. The call to the function is handled
-- separately further below.
New_Allocator :=
Make_Allocator (Loc,
Expression => New_Occurrence_Of (Result_Subt, Loc));
Set_No_Initialization (New_Allocator);
-- Copy attributes to new allocator. Note that the new allocator
-- logically comes from source if the original one did, so copy the
-- relevant flag. This ensures proper treatment of the restriction
-- No_Implicit_Heap_Allocations in this case.
Set_Storage_Pool (New_Allocator, Storage_Pool (Allocator));
Set_Procedure_To_Call (New_Allocator, Procedure_To_Call (Allocator));
Set_Comes_From_Source (New_Allocator, Comes_From_Source (Allocator));
Rewrite (Allocator, New_Allocator);
-- Create a new access object and initialize it to the result of the
-- new uninitialized allocator. Note: we do not use Allocator as the
-- Related_Node of Return_Obj_Access in call to Make_Temporary below
-- as this would create a sort of infinite "recursion".
Return_Obj_Access := Make_Temporary (Loc, 'R');
Set_Etype (Return_Obj_Access, Acc_Type);
-- Generate:
-- Rnnn : constant ptr_T := new (T);
-- Init (Rnn.all,...);
Tmp_Obj :=
Make_Object_Declaration (Loc,
Defining_Identifier => Return_Obj_Access,
Constant_Present => True,
Object_Definition => New_Occurrence_Of (Acc_Type, Loc),
Expression => Relocate_Node (Allocator));
Insert_Action (Allocator, Tmp_Obj);
Insert_List_After_And_Analyze (Tmp_Obj,
Build_Initialization_Call (Loc,
Id_Ref =>
Make_Explicit_Dereference (Loc,
Prefix => New_Occurrence_Of (Return_Obj_Access, Loc)),
Typ => Etype (Function_Id),
Constructor_Ref => Function_Call));
-- Finally, replace the allocator node with a reference to the result of
-- the function call itself (which will effectively be an access to the
-- object created by the allocator).
Rewrite (Allocator, New_Occurrence_Of (Return_Obj_Access, Loc));
-- Ada 2005 (AI-251): If the type of the allocator is an interface then
-- generate an implicit conversion to force displacement of the "this"
-- pointer.
if Is_Interface (Designated_Type (Acc_Type)) then
Rewrite (Allocator, Convert_To (Acc_Type, Relocate_Node (Allocator)));
end if;
Analyze_And_Resolve (Allocator, Acc_Type);
end Make_CPP_Constructor_Call_In_Allocator;
----------------------
-- Might_Have_Tasks --
----------------------
function Might_Have_Tasks (Typ : Entity_Id) return Boolean is
begin
return not Global_No_Tasking
and then not No_Run_Time_Mode
and then (Has_Task (Typ)
or else (Is_Class_Wide_Type (Typ)
and then Is_Limited_Record (Typ)));
end Might_Have_Tasks;
----------------------------
-- Needs_BIP_Task_Actuals --
----------------------------
function Needs_BIP_Task_Actuals (Func_Id : Entity_Id) return Boolean is
pragma Assert (Is_Build_In_Place_Function (Func_Id));
Subp_Id : Entity_Id;
Func_Typ : Entity_Id;
begin
if Global_No_Tasking or else No_Run_Time_Mode then
return False;
end if;
-- For thunks we must rely on their target entity; otherwise, given that
-- the profile of thunks for functions returning a limited interface
-- type returns a class-wide type, we would erroneously add these extra
-- formals.
if Is_Thunk (Func_Id) then
Subp_Id := Thunk_Entity (Func_Id);
-- Common case
else
Subp_Id := Func_Id;
end if;
Func_Typ := Underlying_Type (Etype (Subp_Id));
-- At first sight, for all the following cases, we could add assertions
-- to ensure that if Func_Id is frozen then the computed result matches
-- with the availability of the task master extra formal; unfortunately
-- this is not feasible because we may be precisely freezing this entity
-- (that is, Is_Frozen has been set by Freeze_Entity but it has not
-- completed its work).
if Has_Task (Func_Typ) then
return True;
elsif Ekind (Func_Id) = E_Function then
return Might_Have_Tasks (Func_Typ);
-- Handle subprogram type internally generated for dispatching call. We
-- cannot rely on the return type of the subprogram type of dispatching
-- calls since it is always a class-wide type (cf. Expand_Dispatching_
-- Call).
elsif Ekind (Func_Id) = E_Subprogram_Type then
if Is_Dispatch_Table_Entity (Func_Id) then
return Has_BIP_Extra_Formal (Func_Id, BIP_Task_Master);
else
return Might_Have_Tasks (Func_Typ);
end if;
else
raise Program_Error;
end if;
end Needs_BIP_Task_Actuals;
-----------------------------------
-- Needs_BIP_Finalization_Master --
-----------------------------------
function Needs_BIP_Finalization_Master
(Func_Id : Entity_Id) return Boolean
is
pragma Assert (Is_Build_In_Place_Function (Func_Id));
Func_Typ : constant Entity_Id := Underlying_Type (Etype (Func_Id));
begin
-- A formal giving the finalization master is needed for build-in-place
-- functions whose result type needs finalization or is a tagged type.
-- Tagged primitive build-in-place functions need such a formal because
-- they can be called by a dispatching call, and extensions may require
-- finalization even if the root type doesn't. This means they're also
-- needed for tagged nonprimitive build-in-place functions with tagged
-- results, since such functions can be called via access-to-function
-- types, and those can be used to call primitives, so masters have to
-- be passed to all such build-in-place functions, primitive or not.
return
not Restriction_Active (No_Finalization)
and then (Needs_Finalization (Func_Typ)
or else Is_Tagged_Type (Func_Typ));
end Needs_BIP_Finalization_Master;
--------------------------
-- Needs_BIP_Alloc_Form --
--------------------------
function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean is
pragma Assert (Is_Build_In_Place_Function (Func_Id));
Func_Typ : constant Entity_Id := Underlying_Type (Etype (Func_Id));
begin
return Requires_Transient_Scope (Func_Typ);
end Needs_BIP_Alloc_Form;
-------------------------------------
-- Replace_Renaming_Declaration_Id --
-------------------------------------
procedure Replace_Renaming_Declaration_Id
(New_Decl : Node_Id;
Orig_Decl : Node_Id)
is
New_Id : constant Entity_Id := Defining_Entity (New_Decl);
Orig_Id : constant Entity_Id := Defining_Entity (Orig_Decl);
begin
Set_Chars (New_Id, Chars (Orig_Id));
-- Swap next entity links in preparation for exchanging entities
declare
Next_Id : constant Entity_Id := Next_Entity (New_Id);
begin
Link_Entities (New_Id, Next_Entity (Orig_Id));
Link_Entities (Orig_Id, Next_Id);
end;
Set_Homonym (New_Id, Homonym (Orig_Id));
Exchange_Entities (New_Id, Orig_Id);
-- Preserve source indication of original declaration, so that xref
-- information is properly generated for the right entity.
Preserve_Comes_From_Source (New_Decl, Orig_Decl);
Preserve_Comes_From_Source (Orig_Id, Orig_Decl);
Set_Comes_From_Source (New_Id, False);
end Replace_Renaming_Declaration_Id;
---------------------------------
-- Rewrite_Function_Call_For_C --
---------------------------------
procedure Rewrite_Function_Call_For_C (N : Node_Id) is
Orig_Func : constant Entity_Id := Entity (Name (N));
Func_Id : constant Entity_Id := Ultimate_Alias (Orig_Func);
Par : constant Node_Id := Parent (N);
Proc_Id : constant Entity_Id := Corresponding_Procedure (Func_Id);
Loc : constant Source_Ptr := Sloc (Par);
Actuals : List_Id;
Last_Actual : Node_Id;
Last_Formal : Entity_Id;
-- Start of processing for Rewrite_Function_Call_For_C
begin
-- The actuals may be given by named associations, so the added actual
-- that is the target of the return value of the call must be a named
-- association as well, so we retrieve the name of the generated
-- out_formal.
Last_Formal := First_Formal (Proc_Id);
while Present (Next_Formal (Last_Formal)) loop
Next_Formal (Last_Formal);
end loop;
Actuals := Parameter_Associations (N);
-- The original function may lack parameters
if No (Actuals) then
Actuals := New_List;
end if;
-- If the function call is the expression of an assignment statement,
-- transform the assignment into a procedure call. Generate:
-- LHS := Func_Call (...);
-- Proc_Call (..., LHS);
-- If function is inherited, a conversion may be necessary.
if Nkind (Par) = N_Assignment_Statement then
Last_Actual := Name (Par);
if not Comes_From_Source (Orig_Func)
and then Etype (Orig_Func) /= Etype (Func_Id)
then
Last_Actual :=
Make_Type_Conversion (Loc,
New_Occurrence_Of (Etype (Func_Id), Loc),
Last_Actual);
end if;
Append_To (Actuals,
Make_Parameter_Association (Loc,
Selector_Name =>
Make_Identifier (Loc, Chars (Last_Formal)),
Explicit_Actual_Parameter => Last_Actual));
Rewrite (Par,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Proc_Id, Loc),
Parameter_Associations => Actuals));
Analyze (Par);
-- Otherwise the context is an expression. Generate a temporary and a
-- procedure call to obtain the function result. Generate:
-- ... Func_Call (...) ...
-- Temp : ...;
-- Proc_Call (..., Temp);
-- ... Temp ...
else
declare
Temp_Id : constant Entity_Id := Make_Temporary (Loc, 'T');
Call : Node_Id;
Decl : Node_Id;
begin
-- Generate:
-- Temp : ...;
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp_Id,
Object_Definition =>
New_Occurrence_Of (Etype (Func_Id), Loc));
-- Generate:
-- Proc_Call (..., Temp);
Append_To (Actuals,
Make_Parameter_Association (Loc,
Selector_Name =>
Make_Identifier (Loc, Chars (Last_Formal)),
Explicit_Actual_Parameter =>
New_Occurrence_Of (Temp_Id, Loc)));
Call :=
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Proc_Id, Loc),
Parameter_Associations => Actuals);
Insert_Actions (Par, New_List (Decl, Call));
Rewrite (N, New_Occurrence_Of (Temp_Id, Loc));
end;
end if;
end Rewrite_Function_Call_For_C;
------------------------------------
-- Set_Enclosing_Sec_Stack_Return --
------------------------------------
procedure Set_Enclosing_Sec_Stack_Return (N : Node_Id) is
P : Node_Id := N;
begin
-- Due to a possible mix of internally generated blocks, source blocks
-- and loops, the scope stack may not be contiguous as all labels are
-- inserted at the top level within the related function. Instead,
-- perform a parent-based traversal and mark all appropriate constructs.
while Present (P) loop
-- Mark the label of a source or internally generated block or
-- loop.
if Nkind (P) in N_Block_Statement | N_Loop_Statement then
Set_Sec_Stack_Needed_For_Return (Entity (Identifier (P)));
-- Mark the enclosing function
elsif Nkind (P) = N_Subprogram_Body then
if Present (Corresponding_Spec (P)) then
Set_Sec_Stack_Needed_For_Return (Corresponding_Spec (P));
else
Set_Sec_Stack_Needed_For_Return (Defining_Entity (P));
end if;
-- Do not go beyond the enclosing function
exit;
end if;
P := Parent (P);
end loop;
end Set_Enclosing_Sec_Stack_Return;
------------------------------------
-- Unqual_BIP_Iface_Function_Call --
------------------------------------
function Unqual_BIP_Iface_Function_Call (Expr : Node_Id) return Node_Id is
Has_Pointer_Displacement : Boolean := False;
On_Object_Declaration : Boolean := False;
-- Remember if processing the renaming expressions on recursion we have
-- traversed an object declaration, since we can traverse many object
-- declaration renamings but just one regular object declaration.
function Unqual_BIP_Function_Call (Expr : Node_Id) return Node_Id;
-- Search for a build-in-place function call skipping any qualification
-- including qualified expressions, type conversions, references, calls
-- to displace the pointer to the object, and renamings. Return Empty if
-- no build-in-place function call is found.
------------------------------
-- Unqual_BIP_Function_Call --
------------------------------
function Unqual_BIP_Function_Call (Expr : Node_Id) return Node_Id is
begin
-- Recurse to handle case of multiple levels of qualification and/or
-- conversion.
if Nkind (Expr) in N_Qualified_Expression
| N_Type_Conversion
| N_Unchecked_Type_Conversion
then
return Unqual_BIP_Function_Call (Expression (Expr));
-- Recurse to handle case of multiple levels of references and
-- explicit dereferences.
elsif Nkind (Expr) in N_Attribute_Reference
| N_Explicit_Dereference
| N_Reference
then
return Unqual_BIP_Function_Call (Prefix (Expr));
-- Recurse on object renamings
elsif Nkind (Expr) = N_Identifier
and then Present (Entity (Expr))
and then Ekind (Entity (Expr)) in E_Constant | E_Variable
and then Nkind (Parent (Entity (Expr))) =
N_Object_Renaming_Declaration
and then Present (Renamed_Object (Entity (Expr)))
then
return Unqual_BIP_Function_Call (Renamed_Object (Entity (Expr)));
-- Recurse on the initializing expression of the first reference of
-- an object declaration.
elsif not On_Object_Declaration
and then Nkind (Expr) = N_Identifier
and then Present (Entity (Expr))
and then Ekind (Entity (Expr)) in E_Constant | E_Variable
and then Nkind (Parent (Entity (Expr))) = N_Object_Declaration
and then Present (Expression (Parent (Entity (Expr))))
then
On_Object_Declaration := True;
return
Unqual_BIP_Function_Call (Expression (Parent (Entity (Expr))));
-- Recurse to handle calls to displace the pointer to the object to
-- reference a secondary dispatch table.
elsif Nkind (Expr) = N_Function_Call
and then Nkind (Name (Expr)) in N_Has_Entity
and then Present (Entity (Name (Expr)))
and then RTU_Loaded (Ada_Tags)
and then RTE_Available (RE_Displace)
and then Is_RTE (Entity (Name (Expr)), RE_Displace)
then
Has_Pointer_Displacement := True;
return
Unqual_BIP_Function_Call (First (Parameter_Associations (Expr)));
-- Normal case: check if the inner expression is a BIP function call
-- and the pointer to the object is displaced.
elsif Has_Pointer_Displacement
and then Is_Build_In_Place_Function_Call (Expr)
then
return Expr;
else
return Empty;
end if;
end Unqual_BIP_Function_Call;
-- Start of processing for Unqual_BIP_Iface_Function_Call
begin
if Nkind (Expr) = N_Identifier and then No (Entity (Expr)) then
-- Can happen for X'Elab_Spec in the binder-generated file
return Empty;
end if;
return Unqual_BIP_Function_Call (Expr);
end Unqual_BIP_Iface_Function_Call;
--------------
-- Warn_BIP --
--------------
procedure Warn_BIP (Func_Call : Node_Id) is
begin
if Debug_Flag_Underscore_BB then
Error_Msg_N ("build-in-place function call?", Func_Call);
end if;
end Warn_BIP;
end Exp_Ch6;
|
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Elements.Declarations;
with Program.Elements.Defining_Identifiers;
with Program.Lexical_Elements;
with Program.Elements.Expressions;
package Program.Elements.Number_Declarations is
pragma Pure (Program.Elements.Number_Declarations);
type Number_Declaration is
limited interface and Program.Elements.Declarations.Declaration;
type Number_Declaration_Access is access all Number_Declaration'Class
with Storage_Size => 0;
not overriding function Names
(Self : Number_Declaration)
return not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Vector_Access is abstract;
not overriding function Expression
(Self : Number_Declaration)
return not null Program.Elements.Expressions.Expression_Access
is abstract;
type Number_Declaration_Text is limited interface;
type Number_Declaration_Text_Access is
access all Number_Declaration_Text'Class with Storage_Size => 0;
not overriding function To_Number_Declaration_Text
(Self : in out Number_Declaration)
return Number_Declaration_Text_Access is abstract;
not overriding function Colon_Token
(Self : Number_Declaration_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function Constant_Token
(Self : Number_Declaration_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function Assignment_Token
(Self : Number_Declaration_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function Semicolon_Token
(Self : Number_Declaration_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
end Program.Elements.Number_Declarations;
|
with Text_IO; use Text_IO;
procedure hello is
begin
Put_Line("Hello, world!");
end hello;
|
with Text_IO; use Text_IO;
procedure Fibtest is
Passed : Boolean := True;
function Fib(N : in Positive) return Positive is separate;
procedure Compare (N : in Positive; Right_Answer : in Positive) is
package Int_IO is new Integer_IO(Integer); use Int_IO;
My_Answer : Positive := Fib(N);
begin
if My_Answer /= Right_Answer then
Put("N:"); Put(N);
Put(" My answer:"); Put(My_Answer);
Put(" Right answer:"); Put(Right_Answer);
New_Line;
Passed := False;
end if;
end Compare;
begin
Compare(1, 1);
Compare(2, 1);
Compare(3, 2);
Compare(4, 3);
Compare(5, 5);
Compare(6, 8);
Compare(7, 13);
Compare(10, 55);
Compare(15, 610);
Compare(20, 6765);
if Passed then
Put_Line("Congratulations, you completed the assignment!");
end if;
end Fibtest;
|
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr>
-- MIT license. Please refer to the LICENSE file.
generic
type Parent is abstract new Test_Event_Base with private;
package Apsepp.Test_Event_Class.Generic_Assert_Num_Mixin is
type Child_W_Assert_Num is new Parent with private
with Type_Invariant'Class => Child_W_Assert_Num.Has_Assert_Num;
overriding
procedure Set (Obj : in out Child_W_Assert_Num; Data : Test_Event_Data);
overriding
function Has_Assert_Num (Obj : Child_W_Assert_Num) return Boolean
is (True);
overriding
function Assert_Num (Obj : Child_W_Assert_Num) return Test_Assert_Count;
private
type Child_W_Assert_Num is new Parent with record
Assert_Num : Test_Assert_Count;
end record;
end Apsepp.Test_Event_Class.Generic_Assert_Num_Mixin;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G E T _ S P A R K _ X R E F S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2011-2016, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with SPARK_Xrefs; use SPARK_Xrefs;
with Types; use Types;
with Ada.IO_Exceptions; use Ada.IO_Exceptions;
procedure Get_SPARK_Xrefs is
C : Character;
use ASCII;
-- For CR/LF
Cur_File : Nat;
-- Dependency number for the current file
Cur_Scope : Nat;
-- Scope number for the current scope entity
Cur_File_Idx : File_Index;
-- Index in SPARK_File_Table of the current file
Cur_Scope_Idx : Scope_Index;
-- Index in SPARK_Scope_Table of the current scope
Name_Str : String (1 .. 32768);
Name_Len : Natural := 0;
-- Local string used to store name of File/entity scanned as
-- Name_Str (1 .. Name_Len).
File_Name : String_Ptr;
Unit_File_Name : String_Ptr;
-----------------------
-- Local Subprograms --
-----------------------
function At_EOL return Boolean;
-- Skips any spaces, then checks if at the end of a line. If so, returns
-- True (but does not skip the EOL sequence). If not, then returns False.
procedure Check (C : Character);
-- Checks that file is positioned at given character, and if so skips past
-- it, If not, raises Data_Error.
function Get_Nat return Nat;
-- On entry the file is positioned to a digit. On return, the file is
-- positioned past the last digit, and the returned result is the decimal
-- value read. Data_Error is raised for overflow (value greater than
-- Int'Last), or if the initial character is not a digit.
procedure Get_Name;
-- On entry the file is positioned to a name. On return, the file is
-- positioned past the last character, and the name scanned is returned
-- in Name_Str (1 .. Name_Len).
procedure Skip_EOL;
-- Called with the current character about to be read being LF or CR. Skips
-- past CR/LF characters until either a non-CR/LF character is found, or
-- the end of file is encountered.
procedure Skip_Spaces;
-- Skips zero or more spaces at the current position, leaving the file
-- positioned at the first non-blank character (or Types.EOF).
------------
-- At_EOL --
------------
function At_EOL return Boolean is
begin
Skip_Spaces;
return Nextc = CR or else Nextc = LF;
end At_EOL;
-----------
-- Check --
-----------
procedure Check (C : Character) is
begin
if Nextc = C then
Skipc;
else
raise Data_Error;
end if;
end Check;
-------------
-- Get_Nat --
-------------
function Get_Nat return Nat is
C : Character := Nextc;
Val : Nat := 0;
begin
if C not in '0' .. '9' then
raise Data_Error;
end if;
-- Loop to read digits of integer value
loop
declare
pragma Unsuppress (Overflow_Check);
begin
Val := Val * 10 + (Character'Pos (C) - Character'Pos ('0'));
end;
Skipc;
C := Nextc;
exit when C not in '0' .. '9';
end loop;
return Val;
exception
when Constraint_Error =>
raise Data_Error;
end Get_Nat;
--------------
-- Get_Name --
--------------
procedure Get_Name is
N : Natural := 0;
begin
while Nextc > ' ' loop
N := N + 1;
Name_Str (N) := Getc;
end loop;
Name_Len := N;
end Get_Name;
--------------
-- Skip_EOL --
--------------
procedure Skip_EOL is
C : Character;
begin
loop
Skipc;
C := Nextc;
exit when C /= LF and then C /= CR;
if C = ' ' then
Skip_Spaces;
C := Nextc;
exit when C /= LF and then C /= CR;
end if;
end loop;
end Skip_EOL;
-----------------
-- Skip_Spaces --
-----------------
procedure Skip_Spaces is
begin
while Nextc = ' ' loop
Skipc;
end loop;
end Skip_Spaces;
-- Start of processing for Get_SPARK_Xrefs
begin
Initialize_SPARK_Tables;
Cur_File := 0;
Cur_Scope := 0;
Cur_File_Idx := 1;
Cur_Scope_Idx := 0;
-- Loop through lines of SPARK cross-reference information
while Nextc = 'F' loop
Skipc;
C := Getc;
-- Make sure first line is a File line
if SPARK_File_Table.Last = 0 and then C /= 'D' then
raise Data_Error;
end if;
-- Otherwise dispatch on type of line
case C is
-- Header entry for scope section
when 'D' =>
-- Complete previous entry if any
if SPARK_File_Table.Last /= 0 then
SPARK_File_Table.Table (SPARK_File_Table.Last).To_Scope :=
SPARK_Scope_Table.Last;
end if;
-- Scan out dependency number and file name
Skip_Spaces;
Cur_File := Get_Nat;
Skip_Spaces;
Get_Name;
File_Name := new String'(Name_Str (1 .. Name_Len));
Skip_Spaces;
-- Scan out unit file name when present (for subunits)
if Nextc = '-' then
Skipc;
Check ('>');
Skip_Spaces;
Get_Name;
Unit_File_Name := new String'(Name_Str (1 .. Name_Len));
else
Unit_File_Name := null;
end if;
-- Make new File table entry (will fill in To_Scope later)
SPARK_File_Table.Append (
(File_Name => File_Name,
Unit_File_Name => Unit_File_Name,
File_Num => Cur_File,
From_Scope => SPARK_Scope_Table.Last + 1,
To_Scope => 0));
-- Initialize counter for scopes
Cur_Scope := 1;
-- Scope entry
when 'S' =>
declare
Spec_File : Nat;
Spec_Scope : Nat;
Scope : Nat;
Line : Nat;
Col : Nat;
Typ : Character;
begin
-- Scan out location
Skip_Spaces;
Check ('.');
Scope := Get_Nat;
Check (' ');
Line := Get_Nat;
Typ := Getc;
Col := Get_Nat;
pragma Assert (Scope = Cur_Scope);
-- Scan out scope entity name
Skip_Spaces;
Get_Name;
Skip_Spaces;
if Nextc = '-' then
Skipc;
Check ('>');
Skip_Spaces;
Spec_File := Get_Nat;
Check ('.');
Spec_Scope := Get_Nat;
else
Spec_File := 0;
Spec_Scope := 0;
end if;
-- Make new scope table entry (will fill in From_Xref and
-- To_Xref later). Initial range (From_Xref .. To_Xref) is
-- empty for scopes without entities.
SPARK_Scope_Table.Append (
(Scope_Entity => Empty,
Scope_Name => new String'(Name_Str (1 .. Name_Len)),
File_Num => Cur_File,
Scope_Num => Cur_Scope,
Spec_File_Num => Spec_File,
Spec_Scope_Num => Spec_Scope,
Line => Line,
Stype => Typ,
Col => Col,
From_Xref => 1,
To_Xref => 0));
end;
-- Update counter for scopes
Cur_Scope := Cur_Scope + 1;
-- Header entry for cross-ref section
when 'X' =>
-- Scan out dependency number and file name (ignored)
Skip_Spaces;
Cur_File := Get_Nat;
Skip_Spaces;
Get_Name;
-- Update component From_Xref of current file if first reference
-- in this file.
while SPARK_File_Table.Table (Cur_File_Idx).File_Num /= Cur_File
loop
Cur_File_Idx := Cur_File_Idx + 1;
end loop;
-- Scan out scope entity number and entity name (ignored)
Skip_Spaces;
Check ('.');
Cur_Scope := Get_Nat;
Skip_Spaces;
Get_Name;
-- Update component To_Xref of previous scope
if Cur_Scope_Idx /= 0 then
SPARK_Scope_Table.Table (Cur_Scope_Idx).To_Xref :=
SPARK_Xref_Table.Last;
end if;
-- Update component From_Xref of current scope
Cur_Scope_Idx := SPARK_File_Table.Table (Cur_File_Idx).From_Scope;
while SPARK_Scope_Table.Table (Cur_Scope_Idx).Scope_Num /=
Cur_Scope
loop
Cur_Scope_Idx := Cur_Scope_Idx + 1;
end loop;
SPARK_Scope_Table.Table (Cur_Scope_Idx).From_Xref :=
SPARK_Xref_Table.Last + 1;
-- Cross reference entry
when ' ' =>
declare
XR_Entity : String_Ptr;
XR_Entity_Line : Nat;
XR_Entity_Col : Nat;
XR_Entity_Typ : Character;
XR_File : Nat;
-- Keeps track of the current file (changed by nn|)
XR_Scope : Nat;
-- Keeps track of the current scope (changed by nn:)
begin
XR_File := Cur_File;
XR_Scope := Cur_Scope;
XR_Entity_Line := Get_Nat;
XR_Entity_Typ := Getc;
XR_Entity_Col := Get_Nat;
Skip_Spaces;
Get_Name;
XR_Entity := new String'(Name_Str (1 .. Name_Len));
-- Initialize to scan items on one line
Skip_Spaces;
-- Loop through cross-references for this entity
loop
declare
Line : Nat;
Col : Nat;
N : Nat;
Rtype : Character;
begin
Skip_Spaces;
if At_EOL then
Skip_EOL;
exit when Nextc /= '.';
Skipc;
Skip_Spaces;
end if;
if Nextc = '.' then
Skipc;
XR_Scope := Get_Nat;
Check (':');
else
N := Get_Nat;
if Nextc = '|' then
XR_File := N;
Skipc;
else
Line := N;
Rtype := Getc;
Col := Get_Nat;
pragma Assert
(Rtype = 'r' or else
Rtype = 'c' or else
Rtype = 'm' or else
Rtype = 's');
SPARK_Xref_Table.Append (
(Entity_Name => XR_Entity,
Entity_Line => XR_Entity_Line,
Etype => XR_Entity_Typ,
Entity_Col => XR_Entity_Col,
File_Num => XR_File,
Scope_Num => XR_Scope,
Line => Line,
Rtype => Rtype,
Col => Col));
end if;
end if;
end;
end loop;
end;
-- No other SPARK lines are possible
when others =>
raise Data_Error;
end case;
-- For cross reference lines, the EOL character has been skipped already
if C /= ' ' then
Skip_EOL;
end if;
end loop;
-- Here with all Xrefs stored, complete last entries in File/Scope tables
if SPARK_File_Table.Last /= 0 then
SPARK_File_Table.Table (SPARK_File_Table.Last).To_Scope :=
SPARK_Scope_Table.Last;
end if;
if Cur_Scope_Idx /= 0 then
SPARK_Scope_Table.Table (Cur_Scope_Idx).To_Xref := SPARK_Xref_Table.Last;
end if;
end Get_SPARK_Xrefs;
|
-- Standard Ada library specification
-- Copyright (c) 2003-2018 Maxim Reznik <reznikmm@gmail.com>
-- Copyright (c) 2004-2016 AXE Consultants
-- Copyright (c) 2004, 2005, 2006 Ada-Europe
-- Copyright (c) 2000 The MITRE Corporation, Inc.
-- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc.
-- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual
---------------------------------------------------------------------------
with System;
package Ada.Execution_Time.Group_Budgets is
type Group_Budget is tagged limited private;
type Group_Budget_Handler is
access protected procedure (GB : in out Group_Budget);
type Task_Array is
array (Positive range <>) of Ada.Task_Identification.Task_Id;
Min_Handler_Ceiling : constant System.Any_Priority
:= implementation_defined;
procedure Add_Task (GB : in out Group_Budget;
T : in Ada.Task_Identification.Task_Id);
procedure Remove_Task (GB : in out Group_Budget;
T : in Ada.Task_Identification.Task_Id);
function Is_Member (GB : in Group_Budget;
T : in Ada.Task_Identification.Task_Id)
return Boolean;
function Is_A_Group_Member (T : in Ada.Task_Identification.Task_Id)
return Boolean;
function Members (GB : in Group_Budget) return Task_Array;
procedure Replenish (GB : in out Group_Budget;
To : in Ada.Real_Time.Time_Span);
procedure Add (GB : in out Group_Budget;
Interval : in Ada.Real_Time.Time_Span);
function Budget_Has_Expired (GB : in Group_Budget) return Boolean;
function Budget_Remaining (GB : in Group_Budget)
return Ada.Real_Time.Time_Span;
procedure Set_Handler (GB : in out Group_Budget;
Handler : in Group_Budget_Handler);
function Current_Handler (GB : in Group_Budget) return Group_Budget_Handler;
procedure Cancel_Handler (GB : in out Group_Budget;
Cancelled : out Boolean);
Group_Budget_Error : exception;
private
pragma Import (Ada, Group_Budget);
end Ada.Execution_Time.Group_Budgets;
|
-- Abstract :
--
-- Implement [McKenzie] error recovery, extended to parallel parsers.
--
-- References:
--
-- [McKenzie] McKenzie, Bruce J., Yeatman, Corey, and De Vere,
-- Lorraine. Error repair in shift reduce parsers. ACM Trans. Prog.
-- Lang. Syst., 17(4):672-689, July 1995. Described in [Grune 2008] ref 321.
--
-- [Grune 2008] Parsing Techniques, A Practical Guide, Second
-- Edition. Dick Grune, Ceriel J.H. Jacobs.
--
-- Copyright (C) 2017 - 2019 Free Software Foundation, Inc.
--
-- This library is free software; you can redistribute it and/or modify it
-- under terms of the GNU General Public License as published by the Free
-- Software Foundation; either version 3, or (at your option) any later
-- version. This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.
--
-- As a special exception under Section 7 of GPL version 3, you are granted
-- additional permissions described in the GCC Runtime Library Exception,
-- version 3.1, as published by the Free Software Foundation.
pragma License (Modified_GPL);
with Ada.Task_Attributes;
with WisiToken.Parse.LR.Parser;
with WisiToken.Lexer;
package WisiToken.Parse.LR.McKenzie_Recover is
Bad_Config : exception;
-- Raised when a config is determined to violate some programming
-- convention; abandon it.
type Recover_Status is (Fail_Check_Delta, Fail_Enqueue_Limit, Fail_No_Configs_Left, Fail_Programmer_Error, Success);
function Recover (Shared_Parser : in out WisiToken.Parse.LR.Parser.Parser) return Recover_Status;
-- Attempt to modify Parser.Parsers state and Parser.Lookahead to
-- allow recovering from an error state.
Force_Full_Explore : Boolean := False;
-- Sometimes recover throws an exception in a race condition case
-- that is hard to reproduce. Setting this True ignores all Success,
-- so all configs are checked.
Force_High_Cost_Solutions : Boolean := False;
-- Similarly, setting this true keeps all solutions that are found,
-- and forces at least three.
private
use all type WisiToken.Syntax_Trees.Node_Index;
----------
-- Visible for language-specific child packages. Alphabetical.
procedure Check (ID : Token_ID; Expected_ID : in Token_ID)
with Inline => True;
-- Check that ID = Expected_ID; raise Assertion_Error if not.
-- Implemented using 'pragma Assert'.
function Current_Token
(Terminals : in Base_Token_Arrays.Vector;
Terminals_Current : in out Base_Token_Index;
Restore_Terminals_Current : out WisiToken.Base_Token_Index;
Insert_Delete : aliased in out Sorted_Insert_Delete_Arrays.Vector;
Current_Insert_Delete : in out SAL.Base_Peek_Type;
Prev_Deleted : in Recover_Token_Index_Arrays.Vector)
return Base_Token;
-- Return the current token, from either Terminals or Insert_Delete;
-- set up for Next_Token.
--
-- See Next_Token for more info.
function Current_Token_ID_Peek
(Terminals : in Base_Token_Arrays.Vector;
Terminals_Current : in Base_Token_Index;
Insert_Delete : aliased in Sorted_Insert_Delete_Arrays.Vector;
Current_Insert_Delete : in SAL.Base_Peek_Type)
return Token_ID;
-- Return the current token from either Terminals or
-- Insert_Delete, without setting up for Next_Token.
procedure Current_Token_ID_Peek_3
(Terminals : in Base_Token_Arrays.Vector;
Terminals_Current : in Base_Token_Index;
Insert_Delete : aliased in Sorted_Insert_Delete_Arrays.Vector;
Current_Insert_Delete : in SAL.Base_Peek_Type;
Prev_Deleted : in Recover_Token_Index_Arrays.Vector;
Tokens : out Token_ID_Array_1_3);
-- Return the current token (in Tokens (1)) from either Terminals or
-- Insert_Delete, without setting up for Next_Token. Return the two
-- following tokens in Tokens (2 .. 3).
procedure Delete_Check
(Terminals : in Base_Token_Arrays.Vector;
Config : in out Configuration;
ID : in Token_ID);
-- Check that Terminals (Config.Current_Shared_Token) = ID. Append a
-- Delete op to Config.Ops, and insert it in Config.Insert_Delete in
-- token_index order.
--
-- This or the next routine must be used instead of Config.Ops.Append
-- (Delete...) unless the code also takes care of changing
-- Config.Current_Shared_Token. Note that this routine does _not_
-- increment Config.Current_Shared_Token, so it can only be used to
-- delete one token.
procedure Delete_Check
(Terminals : in Base_Token_Arrays.Vector;
Config : in out Configuration;
Index : in out WisiToken.Token_Index;
ID : in Token_ID);
-- Check that Terminals (Index) = ID. Append a Delete op to
-- Config.Ops, and insert it in Config.Insert_Delete in token_index
-- order. Increments Index, for convenience when deleting several
-- tokens.
procedure Find_ID
(Config : in Configuration;
ID : in Token_ID;
Matching_Index : in out SAL.Peek_Type);
-- Search Config.Stack for a token with ID, starting at
-- Matching_Index. If found, Matching_Index points to it.
-- If not found, Matching_Index = Config.Stack.Depth.
procedure Find_ID
(Config : in Configuration;
IDs : in Token_ID_Set;
Matching_Index : in out SAL.Peek_Type);
-- Search Config.Stack for a token with ID in IDs, starting at
-- Matching_Index. If found, Matching_Index points to it.
-- If not found, Matching_Index = Config.Stack.Depth.
procedure Find_Descendant_ID
(Tree : in Syntax_Trees.Tree;
Config : in Configuration;
ID : in Token_ID;
ID_Set : in Token_ID_Set;
Matching_Index : in out SAL.Peek_Type);
-- Search Config.Stack for a token with id in ID_Set, with a
-- descendant with id = ID, starting at Matching_Index. If found,
-- Matching_Index points to it. If not found, Matching_Index =
-- Config.Stack.Depth.
procedure Find_Matching_Name
(Config : in Configuration;
Lexer : access constant WisiToken.Lexer.Instance'Class;
Name : in String;
Matching_Name_Index : in out SAL.Peek_Type;
Case_Insensitive : in Boolean);
-- Search Config.Stack for a token matching Name, starting at
-- Matching_Name_Index. If found, Matching_Name_Index points to it.
-- If not found, Matching_Name_Index = Config.Stack.Depth.
procedure Find_Matching_Name
(Config : in Configuration;
Lexer : access constant WisiToken.Lexer.Instance'Class;
Name : in String;
Matching_Name_Index : in out SAL.Peek_Type;
Other_ID : in Token_ID;
Other_Count : out Integer;
Case_Insensitive : in Boolean);
-- Search Config.Stack for a token matching Name, starting at
-- Matching_Name_Index. If found, Matching_Name_Index points to it.
-- If not found, Matching_Name_Index = Config.Stack.Depth.
--
-- Also count tokens with ID = Other_ID.
procedure Insert (Config : in out Configuration; ID : in Token_ID);
-- Append an Insert op to Config.Ops, and insert it in
-- Config.Insert_Deleted in token_index order.
procedure Insert (Config : in out Configuration; IDs : in Token_ID_Array);
-- Call Insert for each item in IDs.
function Next_Token
(Terminals : in Base_Token_Arrays.Vector;
Terminals_Current : in out Base_Token_Index;
Restore_Terminals_Current : in out WisiToken.Base_Token_Index;
Insert_Delete : aliased in out Sorted_Insert_Delete_Arrays.Vector;
Current_Insert_Delete : in out SAL.Base_Peek_Type;
Prev_Deleted : in Recover_Token_Index_Arrays.Vector)
return Base_Token;
-- Return the next token, from either Terminals or Insert_Delete;
-- update Terminals_Current or Current_Insert_Delete.
--
-- If result is Insert_Delete.Last_Index, Current_Insert_Delete =
-- Last_Index; Insert_Delete is cleared and Current_Insert_Delete
-- reset on next call.
--
-- When done parsing, caller must reset actual Terminals_Current to
-- Restore_Terminals_Current.
--
-- Insert_Delete contains only Insert and Delete ops, in token_index
-- order. Those ops are applied when Terminals_Current =
-- op.token_index.
--
-- Prev_Deleted contains tokens deleted in previous recover
-- operations; those are skipped.
procedure Push_Back (Config : in out Configuration);
-- Pop the top Config.Stack item, set Config.Current_Shared_Token to
-- the first terminal in that item. If the item is empty,
-- Config.Current_Shared_Token is unchanged.
--
-- If any earlier Insert or Delete items in Config.Ops are for a
-- token_index after that first terminal, they are added to
-- Config.Insert_Delete in token_index order.
procedure Push_Back_Check (Config : in out Configuration; Expected_ID : in Token_ID);
-- In effect, call Check and Push_Back.
procedure Push_Back_Check (Config : in out Configuration; Expected : in Token_ID_Array);
-- Call Push_Back_Check for each item in Expected.
procedure Put
(Message : in String;
Trace : in out WisiToken.Trace'Class;
Parser_Label : in Natural;
Terminals : in Base_Token_Arrays.Vector;
Config : in Configuration;
Task_ID : in Boolean := True;
Strategy : in Boolean := False);
-- Put Message and an image of Config to Trace.
procedure Put_Line
(Trace : in out WisiToken.Trace'Class;
Parser_Label : in Natural;
Message : in String;
Task_ID : in Boolean := True);
-- Put message to Trace, with parser and task info.
function Undo_Reduce_Valid
(Stack : in Recover_Stacks.Stack;
Tree : in Syntax_Trees.Tree)
return Boolean
is (Stack.Depth > 1 and then
((Stack.Peek.Tree_Index /= WisiToken.Syntax_Trees.Invalid_Node_Index and then
Tree.Is_Nonterm (Stack.Peek.Tree_Index)) or
(Stack.Peek.Tree_Index = WisiToken.Syntax_Trees.Invalid_Node_Index and
(not Stack.Peek.Token.Virtual and
Stack.Peek.Token.Byte_Region = Null_Buffer_Region))));
-- Undo_Reduce needs to know what tokens the nonterm contains, to
-- push them on the stack. Thus we need either a valid Tree index, or
-- an empty nonterm. If Token.Virtual, we can't trust
-- Token.Byte_Region to determine empty.
function Undo_Reduce
(Stack : in out Recover_Stacks.Stack;
Tree : in Syntax_Trees.Tree)
return Ada.Containers.Count_Type
with Pre => Undo_Reduce_Valid (Stack, Tree);
-- Undo the reduction that produced the top stack item, return the
-- token count for that reduction.
procedure Undo_Reduce_Check
(Config : in out Configuration;
Tree : in Syntax_Trees.Tree;
Expected : in Token_ID)
with Inline => True;
-- Call Check, Undo_Reduce.
procedure Undo_Reduce_Check
(Config : in out Configuration;
Tree : in Syntax_Trees.Tree;
Expected : in Token_ID_Array);
-- Call Undo_Reduce_Check for each item in Expected.
package Task_Attributes is new Ada.Task_Attributes (Integer, 0);
end WisiToken.Parse.LR.McKenzie_Recover;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.Internals.Strings.Handlers.Portable;
with Matreshka.Internals.Strings.Handlers.Generic_X86_SSE2;
with Matreshka.Internals.Strings.Handlers.X86_Utilities;
package Matreshka.Internals.Strings.Handlers.X86_64_POPCNT is
new Matreshka.Internals.Strings.Handlers.Generic_X86_SSE2
(Matreshka.Internals.Strings.Handlers.Portable.Portable_String_Handler,
Matreshka.Internals.Strings.Handlers.X86_Utilities.Update_Index_Forward_POPCNT,
Matreshka.Internals.Strings.Handlers.X86_Utilities.Update_Index_Backward_POPCNT);
pragma Preelaborate (Matreshka.Internals.Strings.Handlers.X86_64_POPCNT);
|
-- This spec has been automatically generated from STM32L4x3.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.MPU is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype MPU_TYPER_DREGION_Field is HAL.UInt8;
subtype MPU_TYPER_IREGION_Field is HAL.UInt8;
-- MPU type register
type MPU_TYPER_Register is record
-- Read-only. Separate flag
SEPARATE_k : Boolean;
-- unspecified
Reserved_1_7 : HAL.UInt7;
-- Read-only. Number of MPU data regions
DREGION : MPU_TYPER_DREGION_Field;
-- Read-only. Number of MPU instruction regions
IREGION : MPU_TYPER_IREGION_Field;
-- unspecified
Reserved_24_31 : HAL.UInt8;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MPU_TYPER_Register use record
SEPARATE_k at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
DREGION at 0 range 8 .. 15;
IREGION at 0 range 16 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-- MPU control register
type MPU_CTRL_Register is record
-- Enables the MPU
ENABLE : Boolean := False;
-- Enables the operation of MPU during hard fault
HFNMIENA : Boolean := False;
-- Enable priviliged software access to default memory map
PRIVDEFENA : 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 MPU_CTRL_Register use record
ENABLE at 0 range 0 .. 0;
HFNMIENA at 0 range 1 .. 1;
PRIVDEFENA at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
subtype MPU_RNR_REGION_Field is HAL.UInt8;
-- MPU region number register
type MPU_RNR_Register is record
-- MPU region
REGION : MPU_RNR_REGION_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 MPU_RNR_Register use record
REGION at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype MPU_RBAR_REGION_Field is HAL.UInt4;
subtype MPU_RBAR_ADDR_Field is HAL.UInt27;
-- MPU region base address register
type MPU_RBAR_Register is record
-- MPU region field
REGION : MPU_RBAR_REGION_Field := 16#0#;
-- MPU region number valid
VALID : Boolean := False;
-- Region base address field
ADDR : MPU_RBAR_ADDR_Field := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MPU_RBAR_Register use record
REGION at 0 range 0 .. 3;
VALID at 0 range 4 .. 4;
ADDR at 0 range 5 .. 31;
end record;
subtype MPU_RASR_SIZE_Field is HAL.UInt5;
subtype MPU_RASR_SRD_Field is HAL.UInt8;
subtype MPU_RASR_TEX_Field is HAL.UInt3;
subtype MPU_RASR_AP_Field is HAL.UInt3;
-- MPU region attribute and size register
type MPU_RASR_Register is record
-- Region enable bit.
ENABLE : Boolean := False;
-- Size of the MPU protection region
SIZE : MPU_RASR_SIZE_Field := 16#0#;
-- unspecified
Reserved_6_7 : HAL.UInt2 := 16#0#;
-- Subregion disable bits
SRD : MPU_RASR_SRD_Field := 16#0#;
-- memory attribute
B : Boolean := False;
-- memory attribute
C : Boolean := False;
-- Shareable memory attribute
S : Boolean := False;
-- memory attribute
TEX : MPU_RASR_TEX_Field := 16#0#;
-- unspecified
Reserved_22_23 : HAL.UInt2 := 16#0#;
-- Access permission
AP : MPU_RASR_AP_Field := 16#0#;
-- unspecified
Reserved_27_27 : HAL.Bit := 16#0#;
-- Instruction access disable bit
XN : Boolean := False;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MPU_RASR_Register use record
ENABLE at 0 range 0 .. 0;
SIZE at 0 range 1 .. 5;
Reserved_6_7 at 0 range 6 .. 7;
SRD at 0 range 8 .. 15;
B at 0 range 16 .. 16;
C at 0 range 17 .. 17;
S at 0 range 18 .. 18;
TEX at 0 range 19 .. 21;
Reserved_22_23 at 0 range 22 .. 23;
AP at 0 range 24 .. 26;
Reserved_27_27 at 0 range 27 .. 27;
XN at 0 range 28 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Memory protection unit
type MPU_Peripheral is record
-- MPU type register
MPU_TYPER : aliased MPU_TYPER_Register;
-- MPU control register
MPU_CTRL : aliased MPU_CTRL_Register;
-- MPU region number register
MPU_RNR : aliased MPU_RNR_Register;
-- MPU region base address register
MPU_RBAR : aliased MPU_RBAR_Register;
-- MPU region attribute and size register
MPU_RASR : aliased MPU_RASR_Register;
end record
with Volatile;
for MPU_Peripheral use record
MPU_TYPER at 16#0# range 0 .. 31;
MPU_CTRL at 16#4# range 0 .. 31;
MPU_RNR at 16#8# range 0 .. 31;
MPU_RBAR at 16#C# range 0 .. 31;
MPU_RASR at 16#10# range 0 .. 31;
end record;
-- Memory protection unit
MPU_Periph : aliased MPU_Peripheral
with Import, Address => MPU_Base;
end STM32_SVD.MPU;
|
package Vole_Goto is
type Small_Integer is range -32_000 .. 32_000;
type Goto_Entry is record
Nonterm : Small_Integer;
Newstate : Small_Integer;
end record;
--pragma suppress(index_check);
subtype Row is Integer range -1 .. Integer'Last;
type Goto_Parse_Table is array (Row range <>) of Goto_Entry;
Goto_Matrix : constant Goto_Parse_Table :=
((-1,-1) -- Dummy Entry.
-- State 0
,(-6, 3),(-5, 2),(-3, 1),(-2, 4)
-- State 1
,(-9, 5),(-7, 9),(-4, 8)
-- State 2
-- State 3
-- State 4
-- State 5
-- State 6
,(-8, 13)
-- State 7
,(-8, 14)
-- State 8
-- State 9
-- State 10
-- State 11
,(-10, 17),(-9, 5),(-5, 15)
,(-4, 16)
-- State 12
-- State 13
-- State 14
-- State 15
-- State 16
-- State 17
-- State 18
-- State 19
,(-14, 23),(-13, 22),(-11, 26)
,(-5, 21)
-- State 20
,(-8, 27)
-- State 21
-- State 22
-- State 23
,(-14, 23),(-13, 22)
,(-11, 28),(-5, 21)
-- State 24
,(-8, 29)
-- State 25
,(-8, 30)
-- State 26
,(-29, 31),(-12, 36)
-- State 27
-- State 28
-- State 29
-- State 30
,(-16, 41)
-- State 31
-- State 32
,(-8, 43)
-- State 33
,(-8, 44)
-- State 34
,(-8, 45)
-- State 35
,(-31, 47)
-- State 36
-- State 37
,(-14, 23)
,(-13, 22),(-11, 49),(-5, 21)
-- State 38
,(-24, 56)
,(-23, 55),(-22, 54),(-21, 53),(-20, 52)
,(-19, 51),(-18, 50),(-15, 64)
-- State 39
-- State 40
,(-17, 67)
-- State 41
-- State 42
,(-30, 70),(-29, 31),(-12, 69),(-5, 68)
-- State 43
,(-31, 71)
-- State 44
-- State 45
,(-31, 73)
-- State 46
,(-35, 76),(-34, 75)
,(-33, 78),(-8, 77),(-5, 74)
-- State 47
,(-32, 80)
-- State 48
-- State 49
,(-29, 31),(-12, 81)
-- State 50
-- State 51
-- State 52
-- State 53
-- State 54
-- State 55
-- State 56
-- State 57
-- State 58
-- State 59
-- State 60
-- State 61
-- State 62
-- State 63
-- State 64
-- State 65
-- State 66
-- State 67
-- State 68
-- State 69
-- State 70
-- State 71
-- State 72
,(-8, 92)
-- State 73
-- State 74
-- State 75
-- State 76
-- State 77
-- State 78
-- State 79
,(-58, 110)
,(-56, 111),(-46, 107),(-45, 106),(-44, 105)
,(-43, 104),(-42, 103),(-41, 102),(-40, 101)
,(-39, 100),(-38, 99),(-37, 98),(-36, 121)
,(-8, 119),(-5, 97)
-- State 80
-- State 81
-- State 82
,(-63, 129),(-58, 128)
,(-25, 123),(-17, 133),(-8, 119)
-- State 83
,(-63, 129)
,(-58, 128),(-25, 134),(-17, 133),(-8, 119)
-- State 84
-- State 85
-- State 86
,(-8, 137)
-- State 87
,(-27, 140)
-- State 88
,(-63, 129),(-58, 128)
,(-25, 141),(-17, 133),(-8, 119)
-- State 89
-- State 90
-- State 91
,(-31, 142)
-- State 92
,(-31, 143)
-- State 93
,(-31, 144)
-- State 94
,(-35, 76),(-34, 145)
,(-8, 77)
-- State 95
,(-28, 152)
-- State 96
-- State 97
-- State 98
-- State 99
-- State 100
-- State 101
-- State 102
-- State 103
-- State 104
-- State 105
-- State 106
-- State 107
-- State 108
,(-63, 129),(-58, 128)
,(-25, 154),(-17, 133),(-8, 119)
-- State 109
,(-63, 129)
,(-58, 161),(-54, 160),(-53, 159),(-52, 158)
,(-51, 164),(-27, 157),(-25, 156),(-17, 133)
,(-8, 119),(-5, 155)
-- State 110
-- State 111
-- State 112
,(-8, 167)
-- State 113
,(-63, 129)
,(-58, 128),(-25, 168),(-17, 133),(-8, 119)
-- State 114
,(-58, 172),(-49, 170),(-48, 169),(-47, 173)
,(-8, 119)
-- State 115
,(-63, 129),(-58, 128),(-25, 174)
,(-17, 133),(-8, 119)
-- State 116
,(-63, 129),(-58, 128)
,(-25, 175),(-17, 133),(-8, 119)
-- State 117
,(-32, 176)
-- State 118
-- State 119
-- State 120
,(-58, 179),(-57, 180),(-8, 119),(-5, 178)
-- State 121
-- State 122
-- State 123
-- State 124
,(-63, 129),(-58, 128),(-25, 199),(-17, 133)
,(-8, 119)
-- State 125
,(-63, 129),(-58, 128),(-25, 200)
,(-17, 133),(-8, 119)
-- State 126
,(-63, 129),(-58, 128)
,(-25, 201),(-17, 133),(-8, 119)
-- State 127
,(-63, 129)
,(-58, 128),(-25, 202),(-17, 133),(-8, 119)
-- State 128
-- State 129
-- State 130
-- State 131
-- State 132
-- State 133
-- State 134
-- State 135
-- State 136
-- State 137
-- State 138
,(-8, 203)
-- State 139
,(-63, 129),(-62, 205),(-58, 128)
,(-55, 207),(-25, 206),(-17, 133),(-8, 119)
,(-5, 204)
-- State 140
-- State 141
-- State 142
,(-32, 208)
-- State 143
-- State 144
,(-32, 210)
-- State 145
-- State 146
-- State 147
-- State 148
-- State 149
-- State 150
-- State 151
-- State 152
-- State 153
,(-58, 110)
,(-56, 111),(-46, 107),(-45, 106),(-44, 105)
,(-43, 104),(-42, 103),(-41, 102),(-40, 101)
,(-39, 100),(-38, 99),(-37, 98),(-36, 211)
,(-8, 119),(-5, 97)
-- State 154
-- State 155
-- State 156
-- State 157
-- State 158
-- State 159
-- State 160
-- State 161
-- State 162
-- State 163
-- State 164
-- State 165
,(-63, 129),(-60, 219)
,(-59, 221),(-58, 161),(-54, 218),(-52, 217)
,(-25, 216),(-17, 133),(-8, 119)
-- State 166
,(-63, 129)
,(-60, 219),(-59, 222),(-58, 161),(-54, 218)
,(-52, 217),(-25, 216),(-17, 133),(-8, 119)
-- State 167
-- State 168
-- State 169
-- State 170
-- State 171
-- State 172
-- State 173
-- State 174
-- State 175
-- State 176
-- State 177
,(-8, 227)
-- State 178
-- State 179
-- State 180
-- State 181
-- State 182
,(-63, 129),(-58, 128),(-25, 231)
,(-17, 133),(-8, 119)
-- State 183
,(-63, 129),(-58, 128)
,(-25, 232),(-17, 133),(-8, 119)
-- State 184
,(-63, 129)
,(-58, 128),(-25, 233),(-17, 133),(-8, 119)
-- State 185
,(-63, 129),(-58, 128),(-25, 234),(-17, 133)
,(-8, 119)
-- State 186
,(-63, 129),(-58, 128),(-25, 235)
,(-17, 133),(-8, 119)
-- State 187
,(-63, 129),(-58, 128)
,(-25, 236),(-17, 133),(-8, 119)
-- State 188
,(-63, 129)
,(-58, 128),(-25, 237),(-17, 133),(-8, 119)
-- State 189
,(-63, 129),(-58, 128),(-25, 238),(-17, 133)
,(-8, 119)
-- State 190
,(-63, 129),(-58, 128),(-25, 239)
,(-17, 133),(-8, 119)
-- State 191
,(-63, 129),(-58, 128)
,(-25, 240),(-17, 133),(-8, 119)
-- State 192
,(-63, 129)
,(-58, 128),(-25, 241),(-17, 133),(-8, 119)
-- State 193
,(-63, 129),(-58, 128),(-25, 242),(-17, 133)
,(-8, 119)
-- State 194
,(-63, 129),(-58, 128),(-25, 243)
,(-17, 133),(-8, 119)
-- State 195
,(-63, 129),(-58, 128)
,(-25, 244),(-17, 133),(-8, 119)
-- State 196
,(-63, 129)
,(-58, 128),(-25, 245),(-17, 133),(-8, 119)
-- State 197
,(-63, 129),(-58, 128),(-25, 246),(-17, 133)
,(-8, 119)
-- State 198
,(-63, 129),(-58, 128),(-25, 247)
,(-17, 133),(-8, 119)
-- State 199
-- State 200
-- State 201
-- State 202
-- State 203
,(-26, 250)
-- State 204
-- State 205
-- State 206
-- State 207
-- State 208
-- State 209
,(-31, 253)
-- State 210
-- State 211
-- State 212
-- State 213
,(-8, 255)
-- State 214
,(-8, 256)
-- State 215
,(-8, 257)
-- State 216
-- State 217
-- State 218
-- State 219
-- State 220
,(-61, 259)
,(-8, 258)
-- State 221
-- State 222
-- State 223
,(-24, 56),(-23, 55),(-22, 54)
,(-21, 53),(-20, 52),(-19, 51),(-18, 50)
,(-15, 260)
-- State 224
,(-8, 261)
-- State 225
,(-8, 262)
-- State 226
,(-32, 263)
-- State 227
-- State 228
,(-58, 179),(-57, 264),(-8, 119),(-5, 178)
-- State 229
,(-58, 179),(-57, 265),(-8, 119),(-5, 178)
-- State 230
-- State 231
-- State 232
-- State 233
-- State 234
-- State 235
-- State 236
-- State 237
-- State 238
-- State 239
-- State 240
-- State 241
-- State 242
-- State 243
-- State 244
-- State 245
-- State 246
-- State 247
-- State 248
-- State 249
,(-63, 129),(-62, 205),(-58, 128),(-55, 266)
,(-25, 206),(-17, 133),(-8, 119),(-5, 204)
-- State 250
-- State 251
,(-63, 129),(-62, 267),(-58, 128),(-25, 206)
,(-17, 133),(-8, 119)
-- State 252
-- State 253
,(-32, 268)
-- State 254
,(-58, 110)
,(-56, 111),(-46, 107),(-45, 106),(-44, 105)
,(-43, 104),(-42, 103),(-41, 102),(-40, 101)
,(-39, 100),(-38, 99),(-37, 98),(-36, 269)
,(-8, 119),(-5, 97)
-- State 255
,(-26, 270)
-- State 256
,(-26, 271)
-- State 257
,(-26, 272)
-- State 258
,(-26, 273)
-- State 259
-- State 260
-- State 261
,(-26, 274)
-- State 262
,(-26, 275)
-- State 263
-- State 264
-- State 265
-- State 266
-- State 267
-- State 268
-- State 269
,(-50, 278)
-- State 270
-- State 271
-- State 272
-- State 273
-- State 274
-- State 275
-- State 276
-- State 277
-- State 278
-- State 279
,(-32, 281)
-- State 280
,(-63, 129),(-58, 128)
,(-25, 282),(-17, 133),(-8, 119)
-- State 281
-- State 282
-- State 283
-- State 284
,(-58, 110)
,(-56, 111),(-46, 107),(-45, 106),(-44, 105)
,(-43, 104),(-42, 103),(-41, 102),(-40, 101)
,(-39, 100),(-38, 99),(-37, 98),(-36, 285)
,(-8, 119),(-5, 97)
-- State 285
,(-50, 286)
-- State 286
);
-- The offset vector
GOTO_OFFSET : array (0.. 286) of Integer :=
( 0,
4, 7, 7, 7, 7, 7, 8, 9, 9, 9,
9, 13, 13, 13, 13, 13, 13, 13, 13, 17,
18, 18, 18, 22, 23, 24, 26, 26, 26, 26,
27, 27, 28, 29, 30, 31, 31, 35, 43, 43,
44, 44, 48, 49, 49, 50, 55, 56, 56, 58,
58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
58, 58, 59, 59, 59, 59, 59, 59, 59, 74,
74, 74, 79, 84, 84, 84, 85, 86, 91, 91,
91, 92, 93, 94, 97, 98, 98, 98, 98, 98,
98, 98, 98, 98, 98, 98, 98, 98, 103, 114,
114, 114, 115, 120, 125, 130, 135, 136, 136, 136,
140, 140, 140, 140, 145, 150, 155, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 161, 169,
169, 169, 170, 170, 171, 171, 171, 171, 171, 171,
171, 171, 171, 186, 186, 186, 186, 186, 186, 186,
186, 186, 186, 186, 186, 195, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 205, 205, 205,
205, 205, 210, 215, 220, 225, 230, 235, 240, 245,
250, 255, 260, 265, 270, 275, 280, 285, 290, 290,
290, 290, 290, 291, 291, 291, 291, 291, 291, 292,
292, 292, 292, 293, 294, 295, 295, 295, 295, 295,
297, 297, 297, 305, 306, 307, 308, 308, 312, 316,
316, 316, 316, 316, 316, 316, 316, 316, 316, 316,
316, 316, 316, 316, 316, 316, 316, 316, 316, 324,
324, 330, 330, 331, 346, 347, 348, 349, 350, 350,
350, 351, 352, 352, 352, 352, 352, 352, 352, 353,
353, 353, 353, 353, 353, 353, 353, 353, 353, 354,
359, 359, 359, 359, 374, 375);
subtype Rule is Natural;
subtype Nonterminal is Integer;
Rule_Length : array (Rule range 0 .. 146) of Natural := ( 2,
2, 0, 1, 1, 2, 3, 3, 1,
1, 6, 8, 1, 1, 2, 5, 3,
1, 3, 1, 1, 1, 1, 1, 1,
1, 1, 3, 1, 3, 1, 3, 1,
3, 1, 3, 5, 1, 3, 1, 3,
1, 1, 1, 1, 1, 1, 3, 1,
1, 6, 8, 6, 3, 3, 1, 1,
1, 3, 3, 1, 3, 1, 1, 3,
1, 1, 1, 1, 1, 1, 1, 1,
4, 2, 2, 2, 1, 1, 6, 1,
3, 7, 2, 1, 1, 1, 1, 1,
1, 3, 3, 3, 4, 4, 4, 4,
4, 3, 3, 1, 1, 1, 1, 2,
2, 3, 1, 1, 1, 3, 3, 1,
1, 1, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 2, 2, 2,
1, 1, 1, 1, 1, 1, 1, 1,
4, 2);
Get_LHS_Rule: array (Rule range 0 .. 146) of Nonterminal := (-1,
-2,-5,-3,-3,-6,-7,-4,-10,
-10,-9,-9,-11,-11,-13,-14,-14,
-16,-16,-15,-15,-15,-15,-15,-15,
-15,-18,-18,-19,-19,-20,-20,-21,
-21,-22,-22,-22,-23,-23,-24,-24,
-28,-28,-28,-28,-28,-28,-12,-30,
-30,-29,-29,-29,-29,-31,-33,-33,
-34,-34,-35,-8,-32,-36,-36,-37,
-38,-38,-38,-38,-38,-38,-38,-38,
-46,-46,-45,-44,-47,-47,-39,-50,
-50,-50,-40,-51,-51,-51,-51,-51,
-51,-26,-27,-56,-48,-49,-52,-53,
-54,-41,-41,-59,-59,-59,-59,-60,
-61,-58,-58,-57,-57,-57,-57,-55,
-55,-62,-62,-25,-25,-25,-25,-25,
-25,-25,-25,-25,-25,-25,-25,-25,
-25,-25,-25,-25,-25,-25,-25,-25,
-25,-25,-63,-63,-63,-63,-17,-17,
-42,-43);
end Vole_Goto;
|
------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding Samples --
-- --
-- Sample.Keyboard_Handler --
-- --
-- S P E C --
-- --
------------------------------------------------------------------------------
-- Copyright (c) 1998 Free Software Foundation, Inc. --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, distribute with modifications, sublicense, and/or sell --
-- copies of the Software, and to permit persons to whom the Software is --
-- furnished to do so, subject to the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
-- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1996
-- Version Control
-- $Revision: 1.5 $
-- Binding Version 00.93
------------------------------------------------------------------------------
with Terminal_Interface.Curses; use Terminal_Interface.Curses;
-- This package contains a centralized keyboard handler used throughout
-- this example. The handler establishes a timeout mechanism that provides
-- periodical updates of the common header lines used in this example.
--
package Sample.Keyboard_Handler is
function Get_Key (Win : Window := Standard_Window) return Real_Key_Code;
-- The central routine for handling keystrokes.
procedure Init_Keyboard_Handler;
-- Initialize the keyboard
end Sample.Keyboard_Handler;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T . P E R F E C T _ H A S H _ G E N E R A T O R S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2002-2019, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.IO_Exceptions; use Ada.IO_Exceptions;
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Directories;
with GNAT.Heap_Sort_G;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Table;
package body GNAT.Perfect_Hash_Generators is
-- We are using the algorithm of J. Czech as described in Zbigniew J.
-- Czech, George Havas, and Bohdan S. Majewski ``An Optimal Algorithm for
-- Generating Minimal Perfect Hash Functions'', Information Processing
-- Letters, 43(1992) pp.257-264, Oct.1992
-- This minimal perfect hash function generator is based on random graphs
-- and produces a hash function of the form:
-- h (w) = (g (f1 (w)) + g (f2 (w))) mod m
-- where f1 and f2 are functions that map strings into integers, and g is
-- a function that maps integers into [0, m-1]. h can be order preserving.
-- For instance, let W = {w_0, ..., w_i, ..., w_m-1}, h can be defined
-- such that h (w_i) = i.
-- This algorithm defines two possible constructions of f1 and f2. Method
-- b) stores the hash function in less memory space at the expense of
-- greater CPU time.
-- a) fk (w) = sum (for i in 1 .. length (w)) (Tk (i, w (i))) mod n
-- size (Tk) = max (for w in W) (length (w)) * size (used char set)
-- b) fk (w) = sum (for i in 1 .. length (w)) (Tk (i) * w (i)) mod n
-- size (Tk) = max (for w in W) (length (w)) but the table lookups are
-- replaced by multiplications.
-- where Tk values are randomly generated. n is defined later on but the
-- algorithm recommends to use a value a little bit greater than 2m. Note
-- that for large values of m, the main memory space requirements comes
-- from the memory space for storing function g (>= 2m entries).
-- Random graphs are frequently used to solve difficult problems that do
-- not have polynomial solutions. This algorithm is based on a weighted
-- undirected graph. It comprises two steps: mapping and assignment.
-- In the mapping step, a graph G = (V, E) is constructed, where = {0, 1,
-- ..., n-1} and E = {(for w in W) (f1 (w), f2 (w))}. In order for the
-- assignment step to be successful, G has to be acyclic. To have a high
-- probability of generating an acyclic graph, n >= 2m. If it is not
-- acyclic, Tk have to be regenerated.
-- In the assignment step, the algorithm builds function g. As G is
-- acyclic, there is a vertex v1 with only one neighbor v2. Let w_i be
-- the word such that v1 = f1 (w_i) and v2 = f2 (w_i). Let g (v1) = 0 by
-- construction and g (v2) = (i - g (v1)) mod n (or h (i) - g (v1) mod n).
-- If word w_j is such that v2 = f1 (w_j) and v3 = f2 (w_j), g (v3) = (j -
-- g (v2)) mod (or to be general, (h (j) - g (v2)) mod n). If w_i has no
-- neighbor, then another vertex is selected. The algorithm traverses G to
-- assign values to all the vertices. It cannot assign a value to an
-- already assigned vertex as G is acyclic.
subtype Word_Id is Integer;
subtype Key_Id is Integer;
subtype Vertex_Id is Integer;
subtype Edge_Id is Integer;
subtype Table_Id is Integer;
No_Vertex : constant Vertex_Id := -1;
No_Edge : constant Edge_Id := -1;
No_Table : constant Table_Id := -1;
type Word_Type is new String_Access;
procedure Free_Word (W : in out Word_Type) renames Free;
function New_Word (S : String) return Word_Type;
procedure Resize_Word (W : in out Word_Type; Len : Natural);
-- Resize string W to have a length Len
type Key_Type is record
Edge : Edge_Id;
end record;
-- A key corresponds to an edge in the algorithm graph
type Vertex_Type is record
First : Edge_Id;
Last : Edge_Id;
end record;
-- A vertex can be involved in several edges. First and Last are the bounds
-- of an array of edges stored in a global edge table.
type Edge_Type is record
X : Vertex_Id;
Y : Vertex_Id;
Key : Key_Id;
end record;
-- An edge is a peer of vertices. In the algorithm, a key is associated to
-- an edge.
package WT is new GNAT.Table (Word_Type, Word_Id, 0, 32, 32);
package IT is new GNAT.Table (Integer, Integer, 0, 32, 32);
-- The two main tables. WT is used to store the words in their initial
-- version and in their reduced version (that is words reduced to their
-- significant characters). As an instance of GNAT.Table, WT does not
-- initialize string pointers to null. This initialization has to be done
-- manually when the table is allocated. IT is used to store several
-- tables of components containing only integers.
function Image (Int : Integer; W : Natural := 0) return String;
function Image (Str : String; W : Natural := 0) return String;
-- Return a string which includes string Str or integer Int preceded by
-- leading spaces if required by width W.
function Trim_Trailing_Nuls (Str : String) return String;
-- Return Str with trailing NUL characters removed
Output : File_Descriptor renames GNAT.OS_Lib.Standout;
-- Shortcuts
EOL : constant Character := ASCII.LF;
Max : constant := 78;
Last : Natural := 0;
Line : String (1 .. Max);
-- Use this line to provide buffered IO
procedure Add (C : Character);
procedure Add (S : String);
-- Add a character or a string in Line and update Last
procedure Put
(F : File_Descriptor;
S : String;
F1 : Natural;
L1 : Natural;
C1 : Natural;
F2 : Natural;
L2 : Natural;
C2 : Natural);
-- Write string S into file F as a element of an array of one or two
-- dimensions. Fk (resp. Lk and Ck) indicates the first (resp last and
-- current) index in the k-th dimension. If F1 = L1 the array is considered
-- as a one dimension array. This dimension is described by F2 and L2. This
-- routine takes care of all the parenthesis, spaces and commas needed to
-- format correctly the array. Moreover, the array is well indented and is
-- wrapped to fit in a 80 col line. When the line is full, the routine
-- writes it into file F. When the array is completed, the routine adds
-- semi-colon and writes the line into file F.
procedure New_Line (File : File_Descriptor);
-- Simulate Ada.Text_IO.New_Line with GNAT.OS_Lib
procedure Put (File : File_Descriptor; Str : String);
-- Simulate Ada.Text_IO.Put with GNAT.OS_Lib
procedure Put_Used_Char_Set (File : File_Descriptor; Title : String);
-- Output a title and a used character set
procedure Put_Int_Vector
(File : File_Descriptor;
Title : String;
Vector : Integer;
Length : Natural);
-- Output a title and a vector
procedure Put_Int_Matrix
(File : File_Descriptor;
Title : String;
Table : Table_Id;
Len_1 : Natural;
Len_2 : Natural);
-- Output a title and a matrix. When the matrix has only one non-empty
-- dimension (Len_2 = 0), output a vector.
procedure Put_Edges (File : File_Descriptor; Title : String);
-- Output a title and an edge table
procedure Put_Initial_Keys (File : File_Descriptor; Title : String);
-- Output a title and a key table
procedure Put_Reduced_Keys (File : File_Descriptor; Title : String);
-- Output a title and a key table
procedure Put_Vertex_Table (File : File_Descriptor; Title : String);
-- Output a title and a vertex table
function Ada_File_Base_Name (Pkg_Name : String) return String;
-- Return the base file name (i.e. without .ads/.adb extension) for an
-- Ada source file containing the named package, using the standard GNAT
-- file-naming convention. For example, if Pkg_Name is "Parent.Child", we
-- return "parent-child".
----------------------------------
-- Character Position Selection --
----------------------------------
-- We reduce the maximum key size by selecting representative positions
-- in these keys. We build a matrix with one word per line. We fill the
-- remaining space of a line with ASCII.NUL. The heuristic selects the
-- position that induces the minimum number of collisions. If there are
-- collisions, select another position on the reduced key set responsible
-- of the collisions. Apply the heuristic until there is no more collision.
procedure Apply_Position_Selection;
-- Apply Position selection and build the reduced key table
procedure Parse_Position_Selection (Argument : String);
-- Parse Argument and compute the position set. Argument is list of
-- substrings separated by commas. Each substring represents a position
-- or a range of positions (like x-y).
procedure Select_Character_Set;
-- Define an optimized used character set like Character'Pos in order not
-- to allocate tables of 256 entries.
procedure Select_Char_Position;
-- Find a min char position set in order to reduce the max key length. The
-- heuristic selects the position that induces the minimum number of
-- collisions. If there are collisions, select another position on the
-- reduced key set responsible of the collisions. Apply the heuristic until
-- there is no collision.
-----------------------------
-- Random Graph Generation --
-----------------------------
procedure Random (Seed : in out Natural);
-- Simulate Ada.Discrete_Numerics.Random
procedure Generate_Mapping_Table
(Tab : Table_Id;
L1 : Natural;
L2 : Natural;
Seed : in out Natural);
-- Random generation of the tables below. T is already allocated
procedure Generate_Mapping_Tables
(Opt : Optimization;
Seed : in out Natural);
-- Generate the mapping tables T1 and T2. They are used to define fk (w) =
-- sum (for i in 1 .. length (w)) (Tk (i, w (i))) mod n. Keys, NK and Chars
-- are used to compute the matrix size.
---------------------------
-- Algorithm Computation --
---------------------------
procedure Compute_Edges_And_Vertices (Opt : Optimization);
-- Compute the edge and vertex tables. These are empty when a self loop is
-- detected (f1 (w) = f2 (w)). The edge table is sorted by X value and then
-- Y value. Keys is the key table and NK the number of keys. Chars is the
-- set of characters really used in Keys. NV is the number of vertices
-- recommended by the algorithm. T1 and T2 are the mapping tables needed to
-- compute f1 (w) and f2 (w).
function Acyclic return Boolean;
-- Return True when the graph is acyclic. Vertices is the current vertex
-- table and Edges the current edge table.
procedure Assign_Values_To_Vertices;
-- Execute the assignment step of the algorithm. Keys is the current key
-- table. Vertices and Edges represent the random graph. G is the result of
-- the assignment step such that:
-- h (w) = (g (f1 (w)) + g (f2 (w))) mod m
function Sum
(Word : Word_Type;
Table : Table_Id;
Opt : Optimization) return Natural;
-- For an optimization of CPU_Time return
-- fk (w) = sum (for i in 1 .. length (w)) (Tk (i, w (i))) mod n
-- For an optimization of Memory_Space return
-- fk (w) = sum (for i in 1 .. length (w)) (Tk (i) * w (i)) mod n
-- Here NV = n
-------------------------------
-- Internal Table Management --
-------------------------------
function Allocate (N : Natural; S : Natural := 1) return Table_Id;
-- Allocate N * S ints from IT table
----------
-- Keys --
----------
Keys : Table_Id := No_Table;
NK : Natural := 0;
-- NK : Number of Keys
function Initial (K : Key_Id) return Word_Id;
pragma Inline (Initial);
function Reduced (K : Key_Id) return Word_Id;
pragma Inline (Reduced);
function Get_Key (N : Key_Id) return Key_Type;
procedure Set_Key (N : Key_Id; Item : Key_Type);
-- Get or Set Nth element of Keys table
------------------
-- Char_Pos_Set --
------------------
Char_Pos_Set : Table_Id := No_Table;
Char_Pos_Set_Len : Natural;
-- Character Selected Position Set
function Get_Char_Pos (P : Natural) return Natural;
procedure Set_Char_Pos (P : Natural; Item : Natural);
-- Get or Set the string position of the Pth selected character
-------------------
-- Used_Char_Set --
-------------------
Used_Char_Set : Table_Id := No_Table;
Used_Char_Set_Len : Natural;
-- Used Character Set : Define a new character mapping. When all the
-- characters are not present in the keys, in order to reduce the size
-- of some tables, we redefine the character mapping.
function Get_Used_Char (C : Character) return Natural;
procedure Set_Used_Char (C : Character; Item : Natural);
------------
-- Tables --
------------
T1 : Table_Id := No_Table;
T2 : Table_Id := No_Table;
T1_Len : Natural;
T2_Len : Natural;
-- T1 : Values table to compute F1
-- T2 : Values table to compute F2
function Get_Table (T : Integer; X, Y : Natural) return Natural;
procedure Set_Table (T : Integer; X, Y : Natural; Item : Natural);
-----------
-- Graph --
-----------
G : Table_Id := No_Table;
G_Len : Natural;
-- Values table to compute G
NT : Natural := Default_Tries;
-- Number of tries running the algorithm before raising an error
function Get_Graph (N : Natural) return Integer;
procedure Set_Graph (N : Natural; Item : Integer);
-- Get or Set Nth element of graph
-----------
-- Edges --
-----------
Edge_Size : constant := 3;
Edges : Table_Id := No_Table;
Edges_Len : Natural;
-- Edges : Edge table of the random graph G
function Get_Edges (F : Natural) return Edge_Type;
procedure Set_Edges (F : Natural; Item : Edge_Type);
--------------
-- Vertices --
--------------
Vertex_Size : constant := 2;
Vertices : Table_Id := No_Table;
-- Vertex table of the random graph G
NV : Natural;
-- Number of Vertices
function Get_Vertices (F : Natural) return Vertex_Type;
procedure Set_Vertices (F : Natural; Item : Vertex_Type);
-- Comments needed ???
K2V : Float;
-- Ratio between Keys and Vertices (parameter of Czech's algorithm)
Opt : Optimization;
-- Optimization mode (memory vs CPU)
Max_Key_Len : Natural := 0;
Min_Key_Len : Natural := 0;
-- Maximum and minimum of all the word length
S : Natural;
-- Seed
function Type_Size (L : Natural) return Natural;
-- Given the last L of an unsigned integer type T, return its size
-------------
-- Acyclic --
-------------
function Acyclic return Boolean is
Marks : array (0 .. NV - 1) of Vertex_Id := (others => No_Vertex);
function Traverse (Edge : Edge_Id; Mark : Vertex_Id) return Boolean;
-- Propagate Mark from X to Y. X is already marked. Mark Y and propagate
-- it to the edges of Y except the one representing the same key. Return
-- False when Y is marked with Mark.
--------------
-- Traverse --
--------------
function Traverse (Edge : Edge_Id; Mark : Vertex_Id) return Boolean is
E : constant Edge_Type := Get_Edges (Edge);
K : constant Key_Id := E.Key;
Y : constant Vertex_Id := E.Y;
M : constant Vertex_Id := Marks (E.Y);
V : Vertex_Type;
begin
if M = Mark then
return False;
elsif M = No_Vertex then
Marks (Y) := Mark;
V := Get_Vertices (Y);
for J in V.First .. V.Last loop
-- Do not propagate to the edge representing the same key
if Get_Edges (J).Key /= K
and then not Traverse (J, Mark)
then
return False;
end if;
end loop;
end if;
return True;
end Traverse;
Edge : Edge_Type;
-- Start of processing for Acyclic
begin
-- Edges valid range is
for J in 1 .. Edges_Len - 1 loop
Edge := Get_Edges (J);
-- Mark X of E when it has not been already done
if Marks (Edge.X) = No_Vertex then
Marks (Edge.X) := Edge.X;
end if;
-- Traverse E when this has not already been done
if Marks (Edge.Y) = No_Vertex
and then not Traverse (J, Edge.X)
then
return False;
end if;
end loop;
return True;
end Acyclic;
------------------------
-- Ada_File_Base_Name --
------------------------
function Ada_File_Base_Name (Pkg_Name : String) return String is
begin
-- Convert to lower case, then replace '.' with '-'
return Result : String := To_Lower (Pkg_Name) do
for J in Result'Range loop
if Result (J) = '.' then
Result (J) := '-';
end if;
end loop;
end return;
end Ada_File_Base_Name;
---------
-- Add --
---------
procedure Add (C : Character) is
pragma Assert (C /= ASCII.NUL);
begin
Line (Last + 1) := C;
Last := Last + 1;
end Add;
---------
-- Add --
---------
procedure Add (S : String) is
Len : constant Natural := S'Length;
begin
for J in S'Range loop
pragma Assert (S (J) /= ASCII.NUL);
null;
end loop;
Line (Last + 1 .. Last + Len) := S;
Last := Last + Len;
end Add;
--------------
-- Allocate --
--------------
function Allocate (N : Natural; S : Natural := 1) return Table_Id is
L : constant Integer := IT.Last;
begin
IT.Set_Last (L + N * S);
-- Initialize, so debugging printouts don't trip over uninitialized
-- components.
for J in L + 1 .. IT.Last loop
IT.Table (J) := -1;
end loop;
return L + 1;
end Allocate;
------------------------------
-- Apply_Position_Selection --
------------------------------
procedure Apply_Position_Selection is
begin
for J in 0 .. NK - 1 loop
declare
IW : constant String := WT.Table (Initial (J)).all;
RW : String (1 .. IW'Length) := (others => ASCII.NUL);
N : Natural := IW'First - 1;
begin
-- Select the characters of Word included in the position
-- selection.
for C in 0 .. Char_Pos_Set_Len - 1 loop
exit when IW (Get_Char_Pos (C)) = ASCII.NUL;
N := N + 1;
RW (N) := IW (Get_Char_Pos (C));
end loop;
-- Build the new table with the reduced word. Be careful
-- to deallocate the old version to avoid memory leaks.
Free_Word (WT.Table (Reduced (J)));
WT.Table (Reduced (J)) := New_Word (RW);
Set_Key (J, (Edge => No_Edge));
end;
end loop;
end Apply_Position_Selection;
-------------------------------
-- Assign_Values_To_Vertices --
-------------------------------
procedure Assign_Values_To_Vertices is
X : Vertex_Id;
procedure Assign (X : Vertex_Id);
-- Execute assignment on X's neighbors except the vertex that we are
-- coming from which is already assigned.
------------
-- Assign --
------------
procedure Assign (X : Vertex_Id) is
E : Edge_Type;
V : constant Vertex_Type := Get_Vertices (X);
begin
for J in V.First .. V.Last loop
E := Get_Edges (J);
if Get_Graph (E.Y) = -1 then
Set_Graph (E.Y, (E.Key - Get_Graph (X)) mod NK);
Assign (E.Y);
end if;
end loop;
end Assign;
-- Start of processing for Assign_Values_To_Vertices
begin
-- Value -1 denotes an uninitialized value as it is supposed to
-- be in the range 0 .. NK.
if G = No_Table then
G_Len := NV;
G := Allocate (G_Len, 1);
end if;
for J in 0 .. G_Len - 1 loop
Set_Graph (J, -1);
end loop;
for K in 0 .. NK - 1 loop
X := Get_Edges (Get_Key (K).Edge).X;
if Get_Graph (X) = -1 then
Set_Graph (X, 0);
Assign (X);
end if;
end loop;
for J in 0 .. G_Len - 1 loop
if Get_Graph (J) = -1 then
Set_Graph (J, 0);
end if;
end loop;
if Verbose then
Put_Int_Vector (Output, "Assign Values To Vertices", G, G_Len);
end if;
end Assign_Values_To_Vertices;
-------------
-- Compute --
-------------
procedure Compute (Position : String := Default_Position) is
Success : Boolean := False;
begin
if NK = 0 then
raise Program_Error with "keywords set cannot be empty";
end if;
if Verbose then
Put_Initial_Keys (Output, "Initial Key Table");
end if;
if Position'Length /= 0 then
Parse_Position_Selection (Position);
else
Select_Char_Position;
end if;
if Verbose then
Put_Int_Vector
(Output, "Char Position Set", Char_Pos_Set, Char_Pos_Set_Len);
end if;
Apply_Position_Selection;
if Verbose then
Put_Reduced_Keys (Output, "Reduced Keys Table");
end if;
Select_Character_Set;
if Verbose then
Put_Used_Char_Set (Output, "Character Position Table");
end if;
-- Perform Czech's algorithm
for J in 1 .. NT loop
Generate_Mapping_Tables (Opt, S);
Compute_Edges_And_Vertices (Opt);
-- When graph is not empty (no self-loop from previous operation) and
-- not acyclic.
if 0 < Edges_Len and then Acyclic then
Success := True;
exit;
end if;
end loop;
if not Success then
raise Too_Many_Tries;
end if;
Assign_Values_To_Vertices;
end Compute;
--------------------------------
-- Compute_Edges_And_Vertices --
--------------------------------
procedure Compute_Edges_And_Vertices (Opt : Optimization) is
X : Natural;
Y : Natural;
Key : Key_Type;
Edge : Edge_Type;
Vertex : Vertex_Type;
Not_Acyclic : Boolean := False;
procedure Move (From : Natural; To : Natural);
function Lt (L, R : Natural) return Boolean;
-- Subprograms needed for GNAT.Heap_Sort_G
--------
-- Lt --
--------
function Lt (L, R : Natural) return Boolean is
EL : constant Edge_Type := Get_Edges (L);
ER : constant Edge_Type := Get_Edges (R);
begin
return EL.X < ER.X or else (EL.X = ER.X and then EL.Y < ER.Y);
end Lt;
----------
-- Move --
----------
procedure Move (From : Natural; To : Natural) is
begin
Set_Edges (To, Get_Edges (From));
end Move;
package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
-- Start of processing for Compute_Edges_And_Vertices
begin
-- We store edges from 1 to 2 * NK and leave zero alone in order to use
-- GNAT.Heap_Sort_G.
Edges_Len := 2 * NK + 1;
if Edges = No_Table then
Edges := Allocate (Edges_Len, Edge_Size);
end if;
if Vertices = No_Table then
Vertices := Allocate (NV, Vertex_Size);
end if;
for J in 0 .. NV - 1 loop
Set_Vertices (J, (No_Vertex, No_Vertex - 1));
end loop;
-- For each w, X = f1 (w) and Y = f2 (w)
for J in 0 .. NK - 1 loop
Key := Get_Key (J);
Key.Edge := No_Edge;
Set_Key (J, Key);
X := Sum (WT.Table (Reduced (J)), T1, Opt);
Y := Sum (WT.Table (Reduced (J)), T2, Opt);
-- Discard T1 and T2 as soon as we discover a self loop
if X = Y then
Not_Acyclic := True;
exit;
end if;
-- We store (X, Y) and (Y, X) to ease assignment step
Set_Edges (2 * J + 1, (X, Y, J));
Set_Edges (2 * J + 2, (Y, X, J));
end loop;
-- Return an empty graph when self loop detected
if Not_Acyclic then
Edges_Len := 0;
else
if Verbose then
Put_Edges (Output, "Unsorted Edge Table");
Put_Int_Matrix (Output, "Function Table 1", T1,
T1_Len, T2_Len);
Put_Int_Matrix (Output, "Function Table 2", T2,
T1_Len, T2_Len);
end if;
-- Enforce consistency between edges and keys. Construct Vertices and
-- compute the list of neighbors of a vertex First .. Last as Edges
-- is sorted by X and then Y. To compute the neighbor list, sort the
-- edges.
Sorting.Sort (Edges_Len - 1);
if Verbose then
Put_Edges (Output, "Sorted Edge Table");
Put_Int_Matrix (Output, "Function Table 1", T1,
T1_Len, T2_Len);
Put_Int_Matrix (Output, "Function Table 2", T2,
T1_Len, T2_Len);
end if;
-- Edges valid range is 1 .. 2 * NK
for E in 1 .. Edges_Len - 1 loop
Edge := Get_Edges (E);
Key := Get_Key (Edge.Key);
if Key.Edge = No_Edge then
Key.Edge := E;
Set_Key (Edge.Key, Key);
end if;
Vertex := Get_Vertices (Edge.X);
if Vertex.First = No_Edge then
Vertex.First := E;
end if;
Vertex.Last := E;
Set_Vertices (Edge.X, Vertex);
end loop;
if Verbose then
Put_Reduced_Keys (Output, "Key Table");
Put_Edges (Output, "Edge Table");
Put_Vertex_Table (Output, "Vertex Table");
end if;
end if;
end Compute_Edges_And_Vertices;
------------
-- Define --
------------
procedure Define
(Name : Table_Name;
Item_Size : out Natural;
Length_1 : out Natural;
Length_2 : out Natural)
is
begin
case Name is
when Character_Position =>
Item_Size := 8;
Length_1 := Char_Pos_Set_Len;
Length_2 := 0;
when Used_Character_Set =>
Item_Size := 8;
Length_1 := 256;
Length_2 := 0;
when Function_Table_1
| Function_Table_2
=>
Item_Size := Type_Size (NV);
Length_1 := T1_Len;
Length_2 := T2_Len;
when Graph_Table =>
Item_Size := Type_Size (NK);
Length_1 := NV;
Length_2 := 0;
end case;
end Define;
--------------
-- Finalize --
--------------
procedure Finalize is
begin
if Verbose then
Put (Output, "Finalize");
New_Line (Output);
end if;
-- Deallocate all the WT components (both initial and reduced ones) to
-- avoid memory leaks.
for W in 0 .. WT.Last loop
-- Note: WT.Table (NK) is a temporary variable, do not free it since
-- this would cause a double free.
if W /= NK then
Free_Word (WT.Table (W));
end if;
end loop;
WT.Release;
IT.Release;
-- Reset all variables for next usage
Keys := No_Table;
Char_Pos_Set := No_Table;
Char_Pos_Set_Len := 0;
Used_Char_Set := No_Table;
Used_Char_Set_Len := 0;
T1 := No_Table;
T2 := No_Table;
T1_Len := 0;
T2_Len := 0;
G := No_Table;
G_Len := 0;
Edges := No_Table;
Edges_Len := 0;
Vertices := No_Table;
NV := 0;
NK := 0;
Max_Key_Len := 0;
Min_Key_Len := 0;
end Finalize;
----------------------------
-- Generate_Mapping_Table --
----------------------------
procedure Generate_Mapping_Table
(Tab : Integer;
L1 : Natural;
L2 : Natural;
Seed : in out Natural)
is
begin
for J in 0 .. L1 - 1 loop
for K in 0 .. L2 - 1 loop
Random (Seed);
Set_Table (Tab, J, K, Seed mod NV);
end loop;
end loop;
end Generate_Mapping_Table;
-----------------------------
-- Generate_Mapping_Tables --
-----------------------------
procedure Generate_Mapping_Tables
(Opt : Optimization;
Seed : in out Natural)
is
begin
-- If T1 and T2 are already allocated no need to do it twice. Reuse them
-- as their size has not changed.
if T1 = No_Table and then T2 = No_Table then
declare
Used_Char_Last : Natural := 0;
Used_Char : Natural;
begin
if Opt = CPU_Time then
for P in reverse Character'Range loop
Used_Char := Get_Used_Char (P);
if Used_Char /= 0 then
Used_Char_Last := Used_Char;
exit;
end if;
end loop;
end if;
T1_Len := Char_Pos_Set_Len;
T2_Len := Used_Char_Last + 1;
T1 := Allocate (T1_Len * T2_Len);
T2 := Allocate (T1_Len * T2_Len);
end;
end if;
Generate_Mapping_Table (T1, T1_Len, T2_Len, Seed);
Generate_Mapping_Table (T2, T1_Len, T2_Len, Seed);
if Verbose then
Put_Used_Char_Set (Output, "Used Character Set");
Put_Int_Matrix (Output, "Function Table 1", T1,
T1_Len, T2_Len);
Put_Int_Matrix (Output, "Function Table 2", T2,
T1_Len, T2_Len);
end if;
end Generate_Mapping_Tables;
------------------
-- Get_Char_Pos --
------------------
function Get_Char_Pos (P : Natural) return Natural is
N : constant Natural := Char_Pos_Set + P;
begin
return IT.Table (N);
end Get_Char_Pos;
---------------
-- Get_Edges --
---------------
function Get_Edges (F : Natural) return Edge_Type is
N : constant Natural := Edges + (F * Edge_Size);
E : Edge_Type;
begin
E.X := IT.Table (N);
E.Y := IT.Table (N + 1);
E.Key := IT.Table (N + 2);
return E;
end Get_Edges;
---------------
-- Get_Graph --
---------------
function Get_Graph (N : Natural) return Integer is
begin
return IT.Table (G + N);
end Get_Graph;
-------------
-- Get_Key --
-------------
function Get_Key (N : Key_Id) return Key_Type is
K : Key_Type;
begin
K.Edge := IT.Table (Keys + N);
return K;
end Get_Key;
---------------
-- Get_Table --
---------------
function Get_Table (T : Integer; X, Y : Natural) return Natural is
N : constant Natural := T + (Y * T1_Len) + X;
begin
return IT.Table (N);
end Get_Table;
-------------------
-- Get_Used_Char --
-------------------
function Get_Used_Char (C : Character) return Natural is
N : constant Natural := Used_Char_Set + Character'Pos (C);
begin
return IT.Table (N);
end Get_Used_Char;
------------------
-- Get_Vertices --
------------------
function Get_Vertices (F : Natural) return Vertex_Type is
N : constant Natural := Vertices + (F * Vertex_Size);
V : Vertex_Type;
begin
V.First := IT.Table (N);
V.Last := IT.Table (N + 1);
return V;
end Get_Vertices;
-----------
-- Image --
-----------
function Image (Int : Integer; W : Natural := 0) return String is
B : String (1 .. 32);
L : Natural := 0;
procedure Img (V : Natural);
-- Compute image of V into B, starting at B (L), incrementing L
---------
-- Img --
---------
procedure Img (V : Natural) is
begin
if V > 9 then
Img (V / 10);
end if;
L := L + 1;
B (L) := Character'Val ((V mod 10) + Character'Pos ('0'));
end Img;
-- Start of processing for Image
begin
if Int < 0 then
L := L + 1;
B (L) := '-';
Img (-Int);
else
Img (Int);
end if;
return Image (B (1 .. L), W);
end Image;
-----------
-- Image --
-----------
function Image (Str : String; W : Natural := 0) return String is
Len : constant Natural := Str'Length;
Max : Natural := Len;
begin
if Max < W then
Max := W;
end if;
declare
Buf : String (1 .. Max) := (1 .. Max => ' ');
begin
for J in 0 .. Len - 1 loop
Buf (Max - Len + 1 + J) := Str (Str'First + J);
end loop;
return Buf;
end;
end Image;
-------------
-- Initial --
-------------
function Initial (K : Key_Id) return Word_Id is
begin
return K;
end Initial;
----------------
-- Initialize --
----------------
procedure Initialize
(Seed : Natural;
K_To_V : Float := Default_K_To_V;
Optim : Optimization := Memory_Space;
Tries : Positive := Default_Tries)
is
begin
if Verbose then
Put (Output, "Initialize");
New_Line (Output);
end if;
-- Deallocate the part of the table concerning the reduced words.
-- Initial words are already present in the table. We may have reduced
-- words already there because a previous computation failed. We are
-- currently retrying and the reduced words have to be deallocated.
for W in Reduced (0) .. WT.Last loop
Free_Word (WT.Table (W));
end loop;
IT.Init;
-- Initialize of computation variables
Keys := No_Table;
Char_Pos_Set := No_Table;
Char_Pos_Set_Len := 0;
Used_Char_Set := No_Table;
Used_Char_Set_Len := 0;
T1 := No_Table;
T2 := No_Table;
T1_Len := 0;
T2_Len := 0;
G := No_Table;
G_Len := 0;
Edges := No_Table;
Edges_Len := 0;
Vertices := No_Table;
NV := 0;
S := Seed;
K2V := K_To_V;
Opt := Optim;
NT := Tries;
if K2V <= 2.0 then
raise Program_Error with "K to V ratio cannot be lower than 2.0";
end if;
-- Do not accept a value of K2V too close to 2.0 such that once
-- rounded up, NV = 2 * NK because the algorithm would not converge.
NV := Natural (Float (NK) * K2V);
if NV <= 2 * NK then
NV := 2 * NK + 1;
end if;
Keys := Allocate (NK);
-- Resize initial words to have all of them at the same size
-- (so the size of the largest one).
for K in 0 .. NK - 1 loop
Resize_Word (WT.Table (Initial (K)), Max_Key_Len);
end loop;
-- Allocated the table to store the reduced words. As WT is a
-- GNAT.Table (using C memory management), pointers have to be
-- explicitly initialized to null.
WT.Set_Last (Reduced (NK - 1));
-- Note: Reduced (0) = NK + 1
WT.Table (NK) := null;
for W in 0 .. NK - 1 loop
WT.Table (Reduced (W)) := null;
end loop;
end Initialize;
------------
-- Insert --
------------
procedure Insert (Value : String) is
Len : constant Natural := Value'Length;
begin
if Verbose then
Put (Output, "Inserting """ & Value & """");
New_Line (Output);
end if;
for J in Value'Range loop
pragma Assert (Value (J) /= ASCII.NUL);
null;
end loop;
WT.Set_Last (NK);
WT.Table (NK) := New_Word (Value);
NK := NK + 1;
if Max_Key_Len < Len then
Max_Key_Len := Len;
end if;
if Min_Key_Len = 0 or else Len < Min_Key_Len then
Min_Key_Len := Len;
end if;
end Insert;
--------------
-- New_Line --
--------------
procedure New_Line (File : File_Descriptor) is
begin
if Write (File, EOL'Address, 1) /= 1 then
raise Program_Error;
end if;
end New_Line;
--------------
-- New_Word --
--------------
function New_Word (S : String) return Word_Type is
begin
return new String'(S);
end New_Word;
------------------------------
-- Parse_Position_Selection --
------------------------------
procedure Parse_Position_Selection (Argument : String) is
N : Natural := Argument'First;
L : constant Natural := Argument'Last;
M : constant Natural := Max_Key_Len;
T : array (1 .. M) of Boolean := (others => False);
function Parse_Index return Natural;
-- Parse argument starting at index N to find an index
-----------------
-- Parse_Index --
-----------------
function Parse_Index return Natural is
C : Character := Argument (N);
V : Natural := 0;
begin
if C = '$' then
N := N + 1;
return M;
end if;
if C not in '0' .. '9' then
raise Program_Error with "cannot read position argument";
end if;
while C in '0' .. '9' loop
V := V * 10 + (Character'Pos (C) - Character'Pos ('0'));
N := N + 1;
exit when L < N;
C := Argument (N);
end loop;
return V;
end Parse_Index;
-- Start of processing for Parse_Position_Selection
begin
-- Empty specification means all the positions
if L < N then
Char_Pos_Set_Len := M;
Char_Pos_Set := Allocate (Char_Pos_Set_Len);
for C in 0 .. Char_Pos_Set_Len - 1 loop
Set_Char_Pos (C, C + 1);
end loop;
else
loop
declare
First, Last : Natural;
begin
First := Parse_Index;
Last := First;
-- Detect a range
if N <= L and then Argument (N) = '-' then
N := N + 1;
Last := Parse_Index;
end if;
-- Include the positions in the selection
for J in First .. Last loop
T (J) := True;
end loop;
end;
exit when L < N;
if Argument (N) /= ',' then
raise Program_Error with "cannot read position argument";
end if;
N := N + 1;
end loop;
-- Compute position selection length
N := 0;
for J in T'Range loop
if T (J) then
N := N + 1;
end if;
end loop;
-- Fill position selection
Char_Pos_Set_Len := N;
Char_Pos_Set := Allocate (Char_Pos_Set_Len);
N := 0;
for J in T'Range loop
if T (J) then
Set_Char_Pos (N, J);
N := N + 1;
end if;
end loop;
end if;
end Parse_Position_Selection;
-------------
-- Produce --
-------------
procedure Produce
(Pkg_Name : String := Default_Pkg_Name;
Use_Stdout : Boolean := False)
is
File : File_Descriptor := Standout;
Status : Boolean;
-- For call to Close
function Array_Img (N, T, R1 : String; R2 : String := "") return String;
-- Return string "N : constant array (R1[, R2]) of T;"
function Range_Img (F, L : Natural; T : String := "") return String;
-- Return string "[T range ]F .. L"
function Type_Img (L : Natural) return String;
-- Return the larger unsigned type T such that T'Last < L
---------------
-- Array_Img --
---------------
function Array_Img
(N, T, R1 : String;
R2 : String := "") return String
is
begin
Last := 0;
Add (" ");
Add (N);
Add (" : constant array (");
Add (R1);
if R2 /= "" then
Add (", ");
Add (R2);
end if;
Add (") of ");
Add (T);
Add (" :=");
return Line (1 .. Last);
end Array_Img;
---------------
-- Range_Img --
---------------
function Range_Img (F, L : Natural; T : String := "") return String is
FI : constant String := Image (F);
FL : constant Natural := FI'Length;
LI : constant String := Image (L);
LL : constant Natural := LI'Length;
TL : constant Natural := T'Length;
RI : String (1 .. TL + 7 + FL + 4 + LL);
Len : Natural := 0;
begin
if TL /= 0 then
RI (Len + 1 .. Len + TL) := T;
Len := Len + TL;
RI (Len + 1 .. Len + 7) := " range ";
Len := Len + 7;
end if;
RI (Len + 1 .. Len + FL) := FI;
Len := Len + FL;
RI (Len + 1 .. Len + 4) := " .. ";
Len := Len + 4;
RI (Len + 1 .. Len + LL) := LI;
Len := Len + LL;
return RI (1 .. Len);
end Range_Img;
--------------
-- Type_Img --
--------------
function Type_Img (L : Natural) return String is
S : constant String := Image (Type_Size (L));
U : String := "Unsigned_ ";
N : Natural := 9;
begin
for J in S'Range loop
N := N + 1;
U (N) := S (J);
end loop;
return U (1 .. N);
end Type_Img;
F : Natural;
L : Natural;
P : Natural;
FName : String := Ada_File_Base_Name (Pkg_Name) & ".ads";
-- Initially, the name of the spec file, then modified to be the name of
-- the body file. Not used if Use_Stdout is True.
-- Start of processing for Produce
begin
if Verbose and then not Use_Stdout then
Put (Output,
"Producing " & Ada.Directories.Current_Directory & "/" & FName);
New_Line (Output);
end if;
if not Use_Stdout then
File := Create_File (FName, Binary);
if File = Invalid_FD then
raise Program_Error with "cannot create: " & FName;
end if;
end if;
Put (File, "package ");
Put (File, Pkg_Name);
Put (File, " is");
New_Line (File);
Put (File, " function Hash (S : String) return Natural;");
New_Line (File);
Put (File, "end ");
Put (File, Pkg_Name);
Put (File, ";");
New_Line (File);
if not Use_Stdout then
Close (File, Status);
if not Status then
raise Device_Error;
end if;
end if;
if not Use_Stdout then
-- Set to body file name
FName (FName'Last) := 'b';
File := Create_File (FName, Binary);
if File = Invalid_FD then
raise Program_Error with "cannot create: " & FName;
end if;
end if;
Put (File, "with Interfaces; use Interfaces;");
New_Line (File);
New_Line (File);
Put (File, "package body ");
Put (File, Pkg_Name);
Put (File, " is");
New_Line (File);
New_Line (File);
if Opt = CPU_Time then
Put (File, Array_Img ("C", Type_Img (256), "Character"));
New_Line (File);
F := Character'Pos (Character'First);
L := Character'Pos (Character'Last);
for J in Character'Range loop
P := Get_Used_Char (J);
Put (File, Image (P), 1, 0, 1, F, L, Character'Pos (J));
end loop;
New_Line (File);
end if;
F := 0;
L := Char_Pos_Set_Len - 1;
Put (File, Array_Img ("P", "Natural", Range_Img (F, L)));
New_Line (File);
for J in F .. L loop
Put (File, Image (Get_Char_Pos (J)), 1, 0, 1, F, L, J);
end loop;
New_Line (File);
case Opt is
when CPU_Time =>
Put_Int_Matrix
(File,
Array_Img ("T1", Type_Img (NV),
Range_Img (0, T1_Len - 1),
Range_Img (0, T2_Len - 1, Type_Img (256))),
T1, T1_Len, T2_Len);
when Memory_Space =>
Put_Int_Matrix
(File,
Array_Img ("T1", Type_Img (NV),
Range_Img (0, T1_Len - 1)),
T1, T1_Len, 0);
end case;
New_Line (File);
case Opt is
when CPU_Time =>
Put_Int_Matrix
(File,
Array_Img ("T2", Type_Img (NV),
Range_Img (0, T1_Len - 1),
Range_Img (0, T2_Len - 1, Type_Img (256))),
T2, T1_Len, T2_Len);
when Memory_Space =>
Put_Int_Matrix
(File,
Array_Img ("T2", Type_Img (NV),
Range_Img (0, T1_Len - 1)),
T2, T1_Len, 0);
end case;
New_Line (File);
Put_Int_Vector
(File,
Array_Img ("G", Type_Img (NK),
Range_Img (0, G_Len - 1)),
G, G_Len);
New_Line (File);
Put (File, " function Hash (S : String) return Natural is");
New_Line (File);
Put (File, " F : constant Natural := S'First - 1;");
New_Line (File);
Put (File, " L : constant Natural := S'Length;");
New_Line (File);
Put (File, " F1, F2 : Natural := 0;");
New_Line (File);
Put (File, " J : ");
case Opt is
when CPU_Time =>
Put (File, Type_Img (256));
when Memory_Space =>
Put (File, "Natural");
end case;
Put (File, ";");
New_Line (File);
Put (File, " begin");
New_Line (File);
Put (File, " for K in P'Range loop");
New_Line (File);
Put (File, " exit when L < P (K);");
New_Line (File);
Put (File, " J := ");
case Opt is
when CPU_Time =>
Put (File, "C");
when Memory_Space =>
Put (File, "Character'Pos");
end case;
Put (File, " (S (P (K) + F));");
New_Line (File);
Put (File, " F1 := (F1 + Natural (T1 (K");
if Opt = CPU_Time then
Put (File, ", J");
end if;
Put (File, "))");
if Opt = Memory_Space then
Put (File, " * J");
end if;
Put (File, ") mod ");
Put (File, Image (NV));
Put (File, ";");
New_Line (File);
Put (File, " F2 := (F2 + Natural (T2 (K");
if Opt = CPU_Time then
Put (File, ", J");
end if;
Put (File, "))");
if Opt = Memory_Space then
Put (File, " * J");
end if;
Put (File, ") mod ");
Put (File, Image (NV));
Put (File, ";");
New_Line (File);
Put (File, " end loop;");
New_Line (File);
Put (File,
" return (Natural (G (F1)) + Natural (G (F2))) mod ");
Put (File, Image (NK));
Put (File, ";");
New_Line (File);
Put (File, " end Hash;");
New_Line (File);
New_Line (File);
Put (File, "end ");
Put (File, Pkg_Name);
Put (File, ";");
New_Line (File);
if not Use_Stdout then
Close (File, Status);
if not Status then
raise Device_Error;
end if;
end if;
end Produce;
---------
-- Put --
---------
procedure Put (File : File_Descriptor; Str : String) is
Len : constant Natural := Str'Length;
begin
for J in Str'Range loop
pragma Assert (Str (J) /= ASCII.NUL);
null;
end loop;
if Write (File, Str'Address, Len) /= Len then
raise Program_Error;
end if;
end Put;
---------
-- Put --
---------
procedure Put
(F : File_Descriptor;
S : String;
F1 : Natural;
L1 : Natural;
C1 : Natural;
F2 : Natural;
L2 : Natural;
C2 : Natural)
is
Len : constant Natural := S'Length;
procedure Flush;
-- Write current line, followed by LF
-----------
-- Flush --
-----------
procedure Flush is
begin
Put (F, Line (1 .. Last));
New_Line (F);
Last := 0;
end Flush;
-- Start of processing for Put
begin
if C1 = F1 and then C2 = F2 then
Last := 0;
end if;
if Last + Len + 3 >= Max then
Flush;
end if;
if Last = 0 then
Add (" ");
if F1 <= L1 then
if C1 = F1 and then C2 = F2 then
Add ('(');
if F1 = L1 then
Add ("0 .. 0 => ");
end if;
else
Add (' ');
end if;
end if;
end if;
if C2 = F2 then
Add ('(');
if F2 = L2 then
Add ("0 .. 0 => ");
end if;
else
Add (' ');
end if;
Add (S);
if C2 = L2 then
Add (')');
if F1 > L1 then
Add (';');
Flush;
elsif C1 /= L1 then
Add (',');
Flush;
else
Add (')');
Add (';');
Flush;
end if;
else
Add (',');
end if;
end Put;
---------------
-- Put_Edges --
---------------
procedure Put_Edges (File : File_Descriptor; Title : String) is
E : Edge_Type;
F1 : constant Natural := 1;
L1 : constant Natural := Edges_Len - 1;
M : constant Natural := Max / 5;
begin
Put (File, Title);
New_Line (File);
-- Edges valid range is 1 .. Edge_Len - 1
for J in F1 .. L1 loop
E := Get_Edges (J);
Put (File, Image (J, M), F1, L1, J, 1, 4, 1);
Put (File, Image (E.X, M), F1, L1, J, 1, 4, 2);
Put (File, Image (E.Y, M), F1, L1, J, 1, 4, 3);
Put (File, Image (E.Key, M), F1, L1, J, 1, 4, 4);
end loop;
end Put_Edges;
----------------------
-- Put_Initial_Keys --
----------------------
procedure Put_Initial_Keys (File : File_Descriptor; Title : String) is
F1 : constant Natural := 0;
L1 : constant Natural := NK - 1;
M : constant Natural := Max / 5;
K : Key_Type;
begin
Put (File, Title);
New_Line (File);
for J in F1 .. L1 loop
K := Get_Key (J);
Put (File, Image (J, M), F1, L1, J, 1, 3, 1);
Put (File, Image (K.Edge, M), F1, L1, J, 1, 3, 2);
Put (File, Trim_Trailing_Nuls (WT.Table (Initial (J)).all),
F1, L1, J, 1, 3, 3);
end loop;
end Put_Initial_Keys;
--------------------
-- Put_Int_Matrix --
--------------------
procedure Put_Int_Matrix
(File : File_Descriptor;
Title : String;
Table : Integer;
Len_1 : Natural;
Len_2 : Natural)
is
F1 : constant Integer := 0;
L1 : constant Integer := Len_1 - 1;
F2 : constant Integer := 0;
L2 : constant Integer := Len_2 - 1;
Ix : Natural;
begin
Put (File, Title);
New_Line (File);
if Len_2 = 0 then
for J in F1 .. L1 loop
Ix := IT.Table (Table + J);
Put (File, Image (Ix), 1, 0, 1, F1, L1, J);
end loop;
else
for J in F1 .. L1 loop
for K in F2 .. L2 loop
Ix := IT.Table (Table + J + K * Len_1);
Put (File, Image (Ix), F1, L1, J, F2, L2, K);
end loop;
end loop;
end if;
end Put_Int_Matrix;
--------------------
-- Put_Int_Vector --
--------------------
procedure Put_Int_Vector
(File : File_Descriptor;
Title : String;
Vector : Integer;
Length : Natural)
is
F2 : constant Natural := 0;
L2 : constant Natural := Length - 1;
begin
Put (File, Title);
New_Line (File);
for J in F2 .. L2 loop
Put (File, Image (IT.Table (Vector + J)), 1, 0, 1, F2, L2, J);
end loop;
end Put_Int_Vector;
----------------------
-- Put_Reduced_Keys --
----------------------
procedure Put_Reduced_Keys (File : File_Descriptor; Title : String) is
F1 : constant Natural := 0;
L1 : constant Natural := NK - 1;
M : constant Natural := Max / 5;
K : Key_Type;
begin
Put (File, Title);
New_Line (File);
for J in F1 .. L1 loop
K := Get_Key (J);
Put (File, Image (J, M), F1, L1, J, 1, 3, 1);
Put (File, Image (K.Edge, M), F1, L1, J, 1, 3, 2);
Put (File, Trim_Trailing_Nuls (WT.Table (Reduced (J)).all),
F1, L1, J, 1, 3, 3);
end loop;
end Put_Reduced_Keys;
-----------------------
-- Put_Used_Char_Set --
-----------------------
procedure Put_Used_Char_Set (File : File_Descriptor; Title : String) is
F : constant Natural := Character'Pos (Character'First);
L : constant Natural := Character'Pos (Character'Last);
begin
Put (File, Title);
New_Line (File);
for J in Character'Range loop
Put
(File, Image (Get_Used_Char (J)), 1, 0, 1, F, L, Character'Pos (J));
end loop;
end Put_Used_Char_Set;
----------------------
-- Put_Vertex_Table --
----------------------
procedure Put_Vertex_Table (File : File_Descriptor; Title : String) is
F1 : constant Natural := 0;
L1 : constant Natural := NV - 1;
M : constant Natural := Max / 4;
V : Vertex_Type;
begin
Put (File, Title);
New_Line (File);
for J in F1 .. L1 loop
V := Get_Vertices (J);
Put (File, Image (J, M), F1, L1, J, 1, 3, 1);
Put (File, Image (V.First, M), F1, L1, J, 1, 3, 2);
Put (File, Image (V.Last, M), F1, L1, J, 1, 3, 3);
end loop;
end Put_Vertex_Table;
------------
-- Random --
------------
procedure Random (Seed : in out Natural) is
-- Park & Miller Standard Minimal using Schrage's algorithm to avoid
-- overflow: Xn+1 = 16807 * Xn mod (2 ** 31 - 1)
R : Natural;
Q : Natural;
X : Integer;
begin
R := Seed mod 127773;
Q := Seed / 127773;
X := 16807 * R - 2836 * Q;
Seed := (if X < 0 then X + 2147483647 else X);
end Random;
-------------
-- Reduced --
-------------
function Reduced (K : Key_Id) return Word_Id is
begin
return K + NK + 1;
end Reduced;
-----------------
-- Resize_Word --
-----------------
procedure Resize_Word (W : in out Word_Type; Len : Natural) is
S1 : constant String := W.all;
S2 : String (1 .. Len) := (others => ASCII.NUL);
L : constant Natural := S1'Length;
begin
if L /= Len then
Free_Word (W);
S2 (1 .. L) := S1;
W := New_Word (S2);
end if;
end Resize_Word;
--------------------------
-- Select_Char_Position --
--------------------------
procedure Select_Char_Position is
type Vertex_Table_Type is array (Natural range <>) of Vertex_Type;
procedure Build_Identical_Keys_Sets
(Table : in out Vertex_Table_Type;
Last : in out Natural;
Pos : Natural);
-- Build a list of keys subsets that are identical with the current
-- position selection plus Pos. Once this routine is called, reduced
-- words are sorted by subsets and each item (First, Last) in Sets
-- defines the range of identical keys.
-- Need comment saying exactly what Last is ???
function Count_Different_Keys
(Table : Vertex_Table_Type;
Last : Natural;
Pos : Natural) return Natural;
-- For each subset in Sets, count the number of different keys if we add
-- Pos to the current position selection.
Sel_Position : IT.Table_Type (1 .. Max_Key_Len);
Last_Sel_Pos : Natural := 0;
Max_Sel_Pos : Natural := 0;
-------------------------------
-- Build_Identical_Keys_Sets --
-------------------------------
procedure Build_Identical_Keys_Sets
(Table : in out Vertex_Table_Type;
Last : in out Natural;
Pos : Natural)
is
S : constant Vertex_Table_Type := Table (Table'First .. Last);
C : constant Natural := Pos;
-- Shortcuts (why are these not renames ???)
F : Integer;
L : Integer;
-- First and last words of a subset
Offset : Natural;
-- GNAT.Heap_Sort assumes that the first array index is 1. Offset
-- defines the translation to operate.
function Lt (L, R : Natural) return Boolean;
procedure Move (From : Natural; To : Natural);
-- Subprograms needed by GNAT.Heap_Sort_G
--------
-- Lt --
--------
function Lt (L, R : Natural) return Boolean is
C : constant Natural := Pos;
Left : Natural;
Right : Natural;
begin
if L = 0 then
Left := NK;
Right := Offset + R;
elsif R = 0 then
Left := Offset + L;
Right := NK;
else
Left := Offset + L;
Right := Offset + R;
end if;
return WT.Table (Left)(C) < WT.Table (Right)(C);
end Lt;
----------
-- Move --
----------
procedure Move (From : Natural; To : Natural) is
Target, Source : Natural;
begin
if From = 0 then
Source := NK;
Target := Offset + To;
elsif To = 0 then
Source := Offset + From;
Target := NK;
else
Source := Offset + From;
Target := Offset + To;
end if;
WT.Table (Target) := WT.Table (Source);
WT.Table (Source) := null;
end Move;
package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
-- Start of processing for Build_Identical_Key_Sets
begin
Last := 0;
-- For each subset in S, extract the new subsets we have by adding C
-- in the position selection.
for J in S'Range loop
if S (J).First = S (J).Last then
F := S (J).First;
L := S (J).Last;
Last := Last + 1;
Table (Last) := (F, L);
else
Offset := Reduced (S (J).First) - 1;
Sorting.Sort (S (J).Last - S (J).First + 1);
F := S (J).First;
L := F;
for N in S (J).First .. S (J).Last loop
-- For the last item, close the last subset
if N = S (J).Last then
Last := Last + 1;
Table (Last) := (F, N);
-- Two contiguous words are identical when they have the
-- same Cth character.
elsif WT.Table (Reduced (N))(C) =
WT.Table (Reduced (N + 1))(C)
then
L := N + 1;
-- Find a new subset of identical keys. Store the current
-- one and create a new subset.
else
Last := Last + 1;
Table (Last) := (F, L);
F := N + 1;
L := F;
end if;
end loop;
end if;
end loop;
end Build_Identical_Keys_Sets;
--------------------------
-- Count_Different_Keys --
--------------------------
function Count_Different_Keys
(Table : Vertex_Table_Type;
Last : Natural;
Pos : Natural) return Natural
is
N : array (Character) of Natural;
C : Character;
T : Natural := 0;
begin
-- For each subset, count the number of words that are still
-- different when we include Pos in the position selection. Only
-- focus on this position as the other positions already produce
-- identical keys.
for S in 1 .. Last loop
-- Count the occurrences of the different characters
N := (others => 0);
for K in Table (S).First .. Table (S).Last loop
C := WT.Table (Reduced (K))(Pos);
N (C) := N (C) + 1;
end loop;
-- Update the number of different keys. Each character used
-- denotes a different key.
for J in N'Range loop
if N (J) > 0 then
T := T + 1;
end if;
end loop;
end loop;
return T;
end Count_Different_Keys;
-- Start of processing for Select_Char_Position
begin
-- Initialize the reduced words set
for K in 0 .. NK - 1 loop
WT.Table (Reduced (K)) := New_Word (WT.Table (Initial (K)).all);
end loop;
declare
Differences : Natural;
Max_Differences : Natural := 0;
Old_Differences : Natural;
Max_Diff_Sel_Pos : Natural := 0; -- init to kill warning
Max_Diff_Sel_Pos_Idx : Natural := 0; -- init to kill warning
Same_Keys_Sets_Table : Vertex_Table_Type (1 .. NK);
Same_Keys_Sets_Last : Natural := 1;
begin
for C in Sel_Position'Range loop
Sel_Position (C) := C;
end loop;
Same_Keys_Sets_Table (1) := (0, NK - 1);
loop
-- Preserve maximum number of different keys and check later on
-- that this value is strictly incrementing. Otherwise, it means
-- that two keys are strictly identical.
Old_Differences := Max_Differences;
-- The first position should not exceed the minimum key length.
-- Otherwise, we may end up with an empty word once reduced.
Max_Sel_Pos :=
(if Last_Sel_Pos = 0 then Min_Key_Len else Max_Key_Len);
-- Find which position increases more the number of differences
for J in Last_Sel_Pos + 1 .. Max_Sel_Pos loop
Differences := Count_Different_Keys
(Same_Keys_Sets_Table,
Same_Keys_Sets_Last,
Sel_Position (J));
if Verbose then
Put (Output,
"Selecting position" & Sel_Position (J)'Img &
" results in" & Differences'Img &
" differences");
New_Line (Output);
end if;
if Differences > Max_Differences then
Max_Differences := Differences;
Max_Diff_Sel_Pos := Sel_Position (J);
Max_Diff_Sel_Pos_Idx := J;
end if;
end loop;
if Old_Differences = Max_Differences then
raise Program_Error with "some keys are identical";
end if;
-- Insert selected position and sort Sel_Position table
Last_Sel_Pos := Last_Sel_Pos + 1;
Sel_Position (Last_Sel_Pos + 1 .. Max_Diff_Sel_Pos_Idx) :=
Sel_Position (Last_Sel_Pos .. Max_Diff_Sel_Pos_Idx - 1);
Sel_Position (Last_Sel_Pos) := Max_Diff_Sel_Pos;
for P in 1 .. Last_Sel_Pos - 1 loop
if Max_Diff_Sel_Pos < Sel_Position (P) then
Sel_Position (P + 1 .. Last_Sel_Pos) :=
Sel_Position (P .. Last_Sel_Pos - 1);
Sel_Position (P) := Max_Diff_Sel_Pos;
exit;
end if;
end loop;
exit when Max_Differences = NK;
Build_Identical_Keys_Sets
(Same_Keys_Sets_Table,
Same_Keys_Sets_Last,
Max_Diff_Sel_Pos);
if Verbose then
Put (Output,
"Selecting position" & Max_Diff_Sel_Pos'Img &
" results in" & Max_Differences'Img &
" differences");
New_Line (Output);
Put (Output, "--");
New_Line (Output);
for J in 1 .. Same_Keys_Sets_Last loop
for K in
Same_Keys_Sets_Table (J).First ..
Same_Keys_Sets_Table (J).Last
loop
Put (Output,
Trim_Trailing_Nuls (WT.Table (Reduced (K)).all));
New_Line (Output);
end loop;
Put (Output, "--");
New_Line (Output);
end loop;
end if;
end loop;
end;
Char_Pos_Set_Len := Last_Sel_Pos;
Char_Pos_Set := Allocate (Char_Pos_Set_Len);
for C in 1 .. Last_Sel_Pos loop
Set_Char_Pos (C - 1, Sel_Position (C));
end loop;
end Select_Char_Position;
--------------------------
-- Select_Character_Set --
--------------------------
procedure Select_Character_Set is
Last : Natural := 0;
Used : array (Character) of Boolean := (others => False);
Char : Character;
begin
for J in 0 .. NK - 1 loop
for K in 0 .. Char_Pos_Set_Len - 1 loop
Char := WT.Table (Initial (J))(Get_Char_Pos (K));
exit when Char = ASCII.NUL;
Used (Char) := True;
end loop;
end loop;
Used_Char_Set_Len := 256;
Used_Char_Set := Allocate (Used_Char_Set_Len);
for J in Used'Range loop
if Used (J) then
Set_Used_Char (J, Last);
Last := Last + 1;
else
Set_Used_Char (J, 0);
end if;
end loop;
end Select_Character_Set;
------------------
-- Set_Char_Pos --
------------------
procedure Set_Char_Pos (P : Natural; Item : Natural) is
N : constant Natural := Char_Pos_Set + P;
begin
IT.Table (N) := Item;
end Set_Char_Pos;
---------------
-- Set_Edges --
---------------
procedure Set_Edges (F : Natural; Item : Edge_Type) is
N : constant Natural := Edges + (F * Edge_Size);
begin
IT.Table (N) := Item.X;
IT.Table (N + 1) := Item.Y;
IT.Table (N + 2) := Item.Key;
end Set_Edges;
---------------
-- Set_Graph --
---------------
procedure Set_Graph (N : Natural; Item : Integer) is
begin
IT.Table (G + N) := Item;
end Set_Graph;
-------------
-- Set_Key --
-------------
procedure Set_Key (N : Key_Id; Item : Key_Type) is
begin
IT.Table (Keys + N) := Item.Edge;
end Set_Key;
---------------
-- Set_Table --
---------------
procedure Set_Table (T : Integer; X, Y : Natural; Item : Natural) is
N : constant Natural := T + ((Y * T1_Len) + X);
begin
IT.Table (N) := Item;
end Set_Table;
-------------------
-- Set_Used_Char --
-------------------
procedure Set_Used_Char (C : Character; Item : Natural) is
N : constant Natural := Used_Char_Set + Character'Pos (C);
begin
IT.Table (N) := Item;
end Set_Used_Char;
------------------
-- Set_Vertices --
------------------
procedure Set_Vertices (F : Natural; Item : Vertex_Type) is
N : constant Natural := Vertices + (F * Vertex_Size);
begin
IT.Table (N) := Item.First;
IT.Table (N + 1) := Item.Last;
end Set_Vertices;
---------
-- Sum --
---------
function Sum
(Word : Word_Type;
Table : Table_Id;
Opt : Optimization) return Natural
is
S : Natural := 0;
R : Natural;
begin
case Opt is
when CPU_Time =>
for J in 0 .. T1_Len - 1 loop
exit when Word (J + 1) = ASCII.NUL;
R := Get_Table (Table, J, Get_Used_Char (Word (J + 1)));
S := (S + R) mod NV;
end loop;
when Memory_Space =>
for J in 0 .. T1_Len - 1 loop
exit when Word (J + 1) = ASCII.NUL;
R := Get_Table (Table, J, 0);
S := (S + R * Character'Pos (Word (J + 1))) mod NV;
end loop;
end case;
return S;
end Sum;
------------------------
-- Trim_Trailing_Nuls --
------------------------
function Trim_Trailing_Nuls (Str : String) return String is
begin
for J in reverse Str'Range loop
if Str (J) /= ASCII.NUL then
return Str (Str'First .. J);
end if;
end loop;
return Str;
end Trim_Trailing_Nuls;
---------------
-- Type_Size --
---------------
function Type_Size (L : Natural) return Natural is
begin
if L <= 2 ** 8 then
return 8;
elsif L <= 2 ** 16 then
return 16;
else
return 32;
end if;
end Type_Size;
-----------
-- Value --
-----------
function Value
(Name : Table_Name;
J : Natural;
K : Natural := 0) return Natural
is
begin
case Name is
when Character_Position =>
return Get_Char_Pos (J);
when Used_Character_Set =>
return Get_Used_Char (Character'Val (J));
when Function_Table_1 =>
return Get_Table (T1, J, K);
when Function_Table_2 =>
return Get_Table (T2, J, K);
when Graph_Table =>
return Get_Graph (J);
end case;
end Value;
end GNAT.Perfect_Hash_Generators;
|
-- part of AdaYaml, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "copying.txt"
with Ada.Containers;
with Text.Builder;
with Yaml.Tags;
package body Yaml.Parser is
use type Lexer.Token_Kind;
use type Text.Reference;
function New_Parser return Reference is
Ptr : constant not null Instance_Access := new Instance;
begin
return Reference'(Ada.Finalization.Controlled with Data => Ptr);
end New_Parser;
function Value (Object : Reference) return Accessor is
((Data => Object.Data));
procedure Adjust (Object : in out Reference) is
begin
Increase_Refcount (Object.Data);
end Adjust;
procedure Finalize (Object : in out Reference) is
begin
Decrease_Refcount (Object.Data);
end Finalize;
procedure Init (P : in out Instance) with Inline is
begin
P.Levels := Level_Stacks.New_Stack (32);
P.Levels.Push ((State => At_Stream_Start'Access, Indentation => -2));
P.Pool.Create (Text.Pool.Default_Size);
Tag_Handle_Sets.Init (P.Tag_Handles, P.Pool, 16);
P.Header_Props := Default_Properties;
P.Inline_Props := Default_Properties;
end Init;
procedure Set_Input (P : in out Instance; Input : Source.Pointer) is
begin
Init (P);
Lexer.Init (P.L, Input, P.Pool);
end Set_Input;
procedure Set_Input (P : in out Instance; Input : String) is
begin
Init (P);
Lexer.Init (P.L, Input, P.Pool);
end Set_Input;
procedure Set_Warning_Handler
(P : in out Instance; Handler : access Warning_Handler'Class) is
begin
P.Handler := Handler;
end Set_Warning_Handler;
function Next (P : in out Instance) return Event is
begin
return E : Event do
while not P.Levels.Top.State (P, E) loop
null;
end loop;
end return;
end Next;
function Pool (P : Instance) return Text.Pool.Reference is (P.Pool);
procedure Finalize (P : in out Instance) is null;
function Current_Lexer_Token_Start (P : Instance) return Mark is
(Lexer.Recent_Start_Mark (P.L));
function Current_Input_Character (P : Instance) return Mark is
(Lexer.Cur_Mark (P.L));
function Recent_Lexer_Token_Start (P : Instance) return Mark is
(P.Current.Start_Pos);
function Recent_Lexer_Token_End (P : Instance) return Mark is
(P.Current.End_Pos);
-----------------------------------------------------------------------------
-- internal utility subroutines
-----------------------------------------------------------------------------
procedure Reset_Tag_Handles (P : in out Class) is
begin
Tag_Handle_Sets.Clear (P.Tag_Handles);
pragma Warnings (Off);
if P.Tag_Handles.Set ("!", P.Pool.From_String ("!")) and
P.Tag_Handles.Set ("!!",
P.Pool.From_String ("tag:yaml.org,2002:"))
then
null;
end if;
pragma Warnings (On);
end Reset_Tag_Handles;
function Parse_Tag (P : in out Class)
return Text.Reference is
use type Ada.Containers.Hash_Type;
Tag_Handle : constant String := Lexer.Full_Lexeme (P.L);
Holder : constant access constant Tag_Handle_Sets.Holder :=
P.Tag_Handles.Get (Tag_Handle, False);
begin
if Holder.Hash = 0 then
raise Parser_Error with
"Unknown tag handle: " & Tag_Handle;
end if;
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind /= Lexer.Suffix then
raise Parser_Error with "Unexpected token (expected tag suffix): " &
P.Current.Kind'Img;
end if;
return P.Pool.From_String (Holder.Value & Lexer.Current_Content (P.L));
end Parse_Tag;
function To_Style (T : Lexer.Scalar_Token_Kind)
return Scalar_Style_Type is
(case T is
when Lexer.Plain_Scalar => Plain,
when Lexer.Single_Quoted_Scalar => Single_Quoted,
when Lexer.Double_Quoted_Scalar => Double_Quoted,
when Lexer.Literal_Scalar => Literal,
when Lexer.Folded_Scalar => Folded) with Inline;
-----------------------------------------------------------------------------
-- state implementations
-----------------------------------------------------------------------------
function At_Stream_Start (P : in out Class;
E : out Event) return Boolean is
begin
P.Levels.Top.all := (State => At_Stream_End'Access, Indentation => -2);
P.Levels.Push ((State => Before_Doc'Access, Indentation => -1));
E := Event'(Kind => Stream_Start,
Start_Position => (Line => 1, Column => 1, Index => 1),
End_Position => (Line => 1, Column => 1, Index => 1));
P.Current := Lexer.Next_Token (P.L);
Reset_Tag_Handles (P);
return True;
end At_Stream_Start;
function At_Stream_End (P : in out Class;
E : out Event) return Boolean is
T : constant Lexer.Token := Lexer.Next_Token (P.L);
begin
E := Event'(Kind => Stream_End,
Start_Position => T.Start_Pos,
End_Position => T.End_Pos);
return True;
end At_Stream_End;
function Before_Doc (P : in out Class;
E : out Event) return Boolean is
Version : Text.Reference := Text.Empty;
Seen_Directives : Boolean := False;
begin
loop
case P.Current.Kind is
when Lexer.Document_End =>
if Seen_Directives then
raise Parser_Error with "Directives must be followed by '---'";
end if;
P.Current := Lexer.Next_Token (P.L);
when Lexer.Directives_End =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Document_Start,
Implicit_Start => False,
Version => Version);
P.Current := Lexer.Next_Token (P.L);
P.Levels.Top.State := Before_Doc_End'Access;
P.Levels.Push ((State => After_Directives_End'Access,
Indentation => -1));
return True;
when Lexer.Stream_End =>
P.Levels.Pop;
return False;
when Lexer.Indentation =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Document_Start,
Implicit_Start => True,
Version => Version);
P.Levels.Top.State := Before_Doc_End'Access;
P.Levels.Push ((State => Before_Implicit_Root'Access,
Indentation => -1));
return True;
when Lexer.Yaml_Directive =>
Seen_Directives := True;
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind /= Lexer.Directive_Param then
raise Parser_Error with
"Invalid token (expected YAML version string): " &
P.Current.Kind'Img;
elsif Version /= Text.Empty then
raise Parser_Error with
"Duplicate YAML directive";
end if;
Version := P.Pool.From_String (Lexer.Full_Lexeme (P.L));
if Version /= "1.3" and then P.Handler /= null then
P.Handler.Wrong_Yaml_Version (Version.Value);
end if;
P.Current := Lexer.Next_Token (P.L);
when Lexer.Tag_Directive =>
Seen_Directives := True;
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind /= Lexer.Tag_Handle then
raise Parser_Error with
"Invalid token (expected tag handle): " & P.Current.Kind'Img;
end if;
declare
Tag_Handle : constant String := Lexer.Full_Lexeme (P.L);
Holder : access Tag_Handle_Sets.Holder;
begin
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind /= Lexer.Suffix then
raise Parser_Error with
"Invalid token (expected tag URI): " & P.Current.Kind'Img;
end if;
if Tag_Handle = "!" or Tag_Handle = "!!" then
Holder := Tag_Handle_Sets.Get (P.Tag_Handles, Tag_Handle, False);
Holder.Value := Lexer.Current_Content (P.L);
else
if not Tag_Handle_Sets.Set (P.Tag_Handles, Tag_Handle,
Lexer.Current_Content (P.L)) then
raise Parser_Error with
"Redefinition of tag handle " & Tag_Handle;
end if;
end if;
end;
P.Current := Lexer.Next_Token (P.L);
when Lexer.Unknown_Directive =>
Seen_Directives := True;
if P.Handler /= null then
declare
Name : constant String := Lexer.Short_Lexeme (P.L);
Params : Text.Builder.Reference := Text.Builder.Create (P.Pool);
First : Boolean := True;
begin
loop
P.Current := Lexer.Next_Token (P.L);
exit when P.Current.Kind /= Lexer.Directive_Param;
if First then
First := False;
else
Params.Append (' ');
end if;
Params.Append (Lexer.Full_Lexeme (P.L));
end loop;
P.Handler.Unknown_Directive (Name, Params.Lock.Value.Data.all);
end;
else
loop
P.Current := Lexer.Next_Token (P.L);
exit when P.Current.Kind /= Lexer.Directive_Param;
end loop;
end if;
when others =>
raise Parser_Error with
"Unexpected token (expected directive or document start): " &
P.Current.Kind'Img;
end case;
end loop;
end Before_Doc;
function After_Directives_End (P : in out Class;
E : out Event) return Boolean is
begin
case P.Current.Kind is
when Lexer.Node_Property_Kind =>
P.Inline_Start := P.Current.Start_Pos;
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
return False;
when Lexer.Indentation =>
P.Header_Start := P.Inline_Start;
P.Levels.Top.State := At_Block_Indentation'Access;
P.Levels.Push ((State => Before_Block_Indentation'Access,
Indentation => <>));
return False;
when Lexer.Document_End =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => Plain,
Content => Text.Empty);
P.Levels.Pop;
return True;
when Lexer.Folded_Scalar | Lexer.Literal_Scalar =>
E := Event'(
Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => (if P.Current.Kind = Lexer.Folded_Scalar then
Folded else Literal),
Content => Lexer.Current_Content (P.L));
P.Levels.Pop;
P.Current := Lexer.Next_Token (P.L);
return True;
when others =>
raise Parser_Error with "Illegal content at '---' line: " &
P.Current.Kind'Img;
end case;
end After_Directives_End;
function Before_Implicit_Root (P : in out Class;
E : out Event) return Boolean is
pragma Unreferenced (E);
begin
if P.Current.Kind /= Lexer.Indentation then
raise Parser_Error with "Unexpected token (expected line start) :" &
P.Current.Kind'Img;
end if;
P.Inline_Start := P.Current.End_Pos;
P.Levels.Top.Indentation := Lexer.Recent_Indentation (P.L);
P.Current := Lexer.Next_Token (P.L);
case P.Current.Kind is
when Lexer.Seq_Item_Ind | Lexer.Map_Key_Ind | Lexer.Map_Value_Ind =>
P.Levels.Top.State := After_Compact_Parent'Access;
return False;
when Lexer.Scalar_Token_Kind =>
P.Levels.Top.State := Require_Implicit_Map_Start'Access;
return False;
when Lexer.Node_Property_Kind =>
P.Levels.Top.State := Require_Implicit_Map_Start'Access;
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
return False;
when Lexer.Flow_Map_Start | Lexer.Flow_Seq_Start =>
P.Levels.Top.State := After_Compact_Parent_Props'Access;
return False;
when others =>
raise Parser_Error with
"Unexpected token (expected collection start): " &
P.Current.Kind'Img;
end case;
end Before_Implicit_Root;
function Require_Implicit_Map_Start (P : in out Class;
E : out Event) return Boolean is
Header_End : Mark;
begin
P.Levels.Top.Indentation := Lexer.Recent_Indentation (P.L);
case P.Current.Kind is
when Lexer.Alias =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Alias,
Target => P.Pool.From_String (Lexer.Short_Lexeme (P.L)));
Header_End := P.Current.Start_Pos;
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind = Lexer.Map_Value_Ind then
P.Cached := E;
E := Event'(Start_Position => P.Header_Start,
End_Position => Header_End,
Kind => Mapping_Start,
Collection_Properties => P.Header_Props,
Collection_Style => Block);
P.Header_Props := Default_Properties;
P.Levels.Top.State := After_Implicit_Map_Start'Access;
else
if not Is_Empty (P.Header_Props) then
raise Parser_Error with "Alias may not have properties2";
end if;
-- alias is allowed on document root without '---'
P.Levels.Pop;
end if;
return True;
when Lexer.Flow_Scalar_Token_Kind =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => To_Style (P.Current.Kind),
Content => Lexer.Current_Content (P.L));
P.Inline_Props := Default_Properties;
Header_End := P.Current.Start_Pos;
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind = Lexer.Map_Value_Ind then
if Lexer.Last_Scalar_Was_Multiline (P.L) then
raise Parser_Error with
"Implicit mapping key may not be multiline";
end if;
P.Cached := E;
E := Event'(Start_Position => P.Header_Start,
End_Position => Header_End,
Kind => Mapping_Start,
Collection_Properties => P.Header_Props,
Collection_Style => Block);
P.Header_Props := Default_Properties;
P.Levels.Top.State := After_Implicit_Map_Start'Access;
elsif P.Current.Kind in Lexer.Indentation | Lexer.Document_End |
Lexer.Directives_End | Lexer.Stream_End then
raise Parser_Error with "Scalar at root level requires '---'.";
end if;
return True;
when Lexer.Flow_Map_Start | Lexer.Flow_Seq_Start =>
P.Levels.Top.State := Before_Flow_Item_Props'Access;
return False;
when Lexer.Indentation =>
raise Parser_Error with
"Stand-alone node properties not allowed on non-header line";
when others =>
raise Parser_Error with
"Unexpected token (expected implicit mapping key): " &
P.Current.Kind'Img;
end case;
end Require_Implicit_Map_Start;
function At_Block_Indentation (P : in out Class;
E : out Event) return Boolean is
Header_End : Mark;
begin
if P.Block_Indentation = P.Levels.Top.Indentation and then
(P.Current.Kind /= Lexer.Seq_Item_Ind or else
P.Levels.Element (P.Levels.Length - 2).State = In_Block_Seq'Access)
then
-- empty element is empty scalar
E := Event'(Start_Position => P.Header_Start,
End_Position => P.Header_Start,
Kind => Scalar,
Scalar_Properties => P.Header_Props,
Scalar_Style => Plain,
Content => Text.Empty);
P.Header_Props := Default_Properties;
P.Levels.Pop;
P.Levels.Pop;
return True;
end if;
P.Inline_Start := P.Current.Start_Pos;
P.Levels.Top.Indentation := Lexer.Recent_Indentation (P.L);
case P.Current.Kind is
when Lexer.Node_Property_Kind =>
if Is_Empty (P.Header_Props) then
P.Levels.Top.State := Require_Inline_Block_Item'Access;
else
P.Levels.Top.State := Require_Implicit_Map_Start'Access;
end if;
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
return False;
when Lexer.Seq_Item_Ind =>
E := Event'(Start_Position => P.Header_Start,
End_Position => P.Current.End_Pos,
Kind => Sequence_Start,
Collection_Properties => P.Header_Props,
Collection_Style => Block);
P.Header_Props := Default_Properties;
P.Levels.Top.all :=
(In_Block_Seq'Access, Lexer.Recent_Indentation (P.L));
P.Levels.Push ((State => Before_Block_Indentation'Access,
Indentation => <>));
P.Levels.Push ((State => After_Compact_Parent'Access,
Indentation => Lexer.Recent_Indentation (P.L)));
P.Current := Lexer.Next_Token (P.L);
return True;
when Lexer.Map_Key_Ind =>
E := Event'(Start_Position => P.Header_Start,
End_Position => P.Current.End_Pos,
Kind => Mapping_Start,
Collection_Properties => P.Header_Props,
Collection_Style => Block);
P.Header_Props := Default_Properties;
P.Levels.Top.all :=
(Before_Block_Map_Value'Access, Lexer.Recent_Indentation (P.L));
P.Levels.Push ((State => Before_Block_Indentation'Access,
Indentation => <>));
P.Levels.Push ((State => After_Compact_Parent'Access,
Indentation => Lexer.Recent_Indentation (P.L)));
P.Current := Lexer.Next_Token (P.L);
return True;
when Lexer.Flow_Scalar_Token_Kind =>
P.Levels.Top.Indentation := Lexer.Recent_Indentation (P.L);
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Header_Props,
Scalar_Style => To_Style (P.Current.Kind),
Content => Lexer.Current_Content (P.L));
P.Header_Props := Default_Properties;
Header_End := P.Current.Start_Pos;
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind = Lexer.Map_Value_Ind then
if Lexer.Last_Scalar_Was_Multiline (P.L) then
raise Parser_Error with
"Implicit mapping key may not be multiline";
end if;
P.Cached := E;
E := Event'(Start_Position => P.Header_Start,
End_Position => Header_End,
Kind => Mapping_Start,
Collection_Properties => P.Cached.Scalar_Properties,
Collection_Style => Block);
P.Cached.Scalar_Properties := Default_Properties;
P.Levels.Top.State := After_Implicit_Map_Start'Access;
else
P.Levels.Pop;
end if;
return True;
when Lexer.Alias =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Alias,
Target => P.Pool.From_String (Lexer.Short_Lexeme (P.L)));
P.Inline_Props := Default_Properties;
Header_End := P.Current.Start_Pos;
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind = Lexer.Map_Value_Ind then
P.Cached := E;
E := Event'(Start_Position => P.Header_Start,
End_Position => Header_End,
Kind => Mapping_Start,
Collection_Properties => P.Header_Props,
Collection_Style => Block);
P.Header_Props := Default_Properties;
P.Levels.Top.State := After_Implicit_Map_Start'Access;
elsif not Is_Empty (P.Header_Props) then
raise Parser_Error with "Alias may not have properties1";
else
P.Levels.Pop;
end if;
return True;
when others =>
P.Levels.Top.State := At_Block_Indentation_Props'Access;
return False;
end case;
end At_Block_Indentation;
function At_Block_Indentation_Props (P : in out Class;
E : out Event) return Boolean is
Header_End : Mark;
begin
P.Levels.Top.Indentation := Lexer.Recent_Indentation (P.L);
case P.Current.Kind is
when Lexer.Map_Value_Ind =>
P.Cached := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => Plain,
Content => Text.Empty);
P.Inline_Props := Default_Properties;
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Mapping_Start,
Collection_Properties => P.Header_Props,
Collection_Style => Block);
P.Header_Props := Default_Properties;
P.Levels.Top.State := After_Implicit_Map_Start'Access;
return True;
when Lexer.Flow_Scalar_Token_Kind =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => To_Style (P.Current.Kind),
Content => Lexer.Current_Content (P.L));
P.Inline_Props := Default_Properties;
Header_End := P.Current.Start_Pos;
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind = Lexer.Map_Value_Ind then
if Lexer.Last_Scalar_Was_Multiline (P.L) then
raise Parser_Error with
"Implicit mapping key may not be multiline";
end if;
P.Cached := E;
E := Event'(Start_Position => P.Header_Start,
End_Position => Header_End,
Kind => Mapping_Start,
Collection_Properties => P.Header_Props,
Collection_Style => Block);
P.Header_Props := Default_Properties;
P.Levels.Top.State := After_Implicit_Map_Start'Access;
else
P.Levels.Pop;
end if;
return True;
when Lexer.Flow_Map_Start =>
E := Event'(Start_Position => P.Header_Start,
End_Position => P.Current.End_Pos,
Kind => Mapping_Start,
Collection_Properties => P.Header_Props,
Collection_Style => Flow);
P.Header_Props := Default_Properties;
P.Levels.Top.State := After_Flow_Map_Sep'Access;
P.Current := Lexer.Next_Token (P.L);
return True;
when Lexer.Flow_Seq_Start =>
E := Event'(Start_Position => P.Header_Start,
End_Position => P.Current.End_Pos,
Kind => Sequence_Start,
Collection_Properties => P.Header_Props,
Collection_Style => Flow);
P.Header_Props := Default_Properties;
P.Levels.Top.State := After_Flow_Seq_Sep'Access;
P.Current := Lexer.Next_Token (P.L);
return True;
when others =>
raise Parser_Error with
"Unexpected token (expected block content): " &
P.Current.Kind'Img;
end case;
end At_Block_Indentation_Props;
function Before_Node_Properties (P : in out Class;
E : out Event) return Boolean is
pragma Unreferenced (E);
begin
case P.Current.Kind is
when Lexer.Tag_Handle =>
if P.Inline_Props.Tag /= Tags.Question_Mark then
raise Parser_Error with "Only one tag allowed per element";
end if;
P.Inline_Props.Tag := Parse_Tag (P);
when Lexer.Verbatim_Tag =>
if P.Inline_Props.Tag /= Tags.Question_Mark then
raise Parser_Error with "Only one tag allowed per element";
end if;
P.Inline_Props.Tag := Lexer.Current_Content (P.L);
when Lexer.Anchor =>
if P.Inline_Props.Anchor /= Text.Empty then
raise Parser_Error with "Only one anchor allowed per element";
end if;
P.Inline_Props.Anchor :=
P.Pool.From_String (Lexer.Short_Lexeme (P.L));
when Lexer.Annotation_Handle =>
declare
NS : constant String := Lexer.Full_Lexeme (P.L);
begin
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind /= Lexer.Suffix then
raise Parser_Error with
"Unexpected token (expected annotation suffix): " &
P.Current.Kind'Img;
end if;
if NS = "@@" then
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.Start_Pos,
Kind => Annotation_Start,
Annotation_Properties => P.Inline_Props,
Namespace => Standard_Annotation_Namespace,
Name => Lexer.Current_Content (P.L));
else
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.Start_Pos,
Kind => Annotation_Start,
Annotation_Properties => P.Inline_Props,
Namespace => P.Pool.From_String (NS),
Name => Lexer.Current_Content (P.L));
end if;
end;
P.Inline_Props := Default_Properties;
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind = Lexer.Params_Start then
P.Current := Lexer.Next_Token (P.L);
P.Levels.Push ((State => After_Param_Sep'Access,
Indentation => P.Block_Indentation));
else
P.Levels.Top.State := After_Annotation'Access;
end if;
return True;
when Lexer.Indentation =>
P.Header_Props := P.Inline_Props;
P.Inline_Props := Default_Properties;
P.Levels.Pop;
return False;
when Lexer.Alias =>
raise Parser_Error with "Alias may not have node properties";
when others =>
P.Levels.Pop;
return False;
end case;
P.Current := Lexer.Next_Token (P.L);
return False;
end Before_Node_Properties;
function After_Compact_Parent (P : in out Class;
E : out Event) return Boolean is
begin
P.Inline_Start := P.Current.Start_Pos;
case P.Current.Kind is
when Lexer.Node_Property_Kind =>
P.Levels.Top.State := After_Compact_Parent_Props'Access;
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
when Lexer.Seq_Item_Ind =>
E := Event'(Start_Position => P.Header_Start,
End_Position => P.Current.End_Pos,
Kind => Sequence_Start,
Collection_Properties => P.Header_Props,
Collection_Style => Block);
P.Header_Props := Default_Properties;
P.Levels.Top.all := (In_Block_Seq'Access, Lexer.Recent_Indentation (P.L));
P.Levels.Push ((State => Before_Block_Indentation'Access,
Indentation => <>));
P.Levels.Push ((State => After_Compact_Parent'Access,
Indentation => <>));
P.Current := Lexer.Next_Token (P.L);
return True;
when Lexer.Map_Key_Ind =>
E := Event'(Start_Position => P.Header_Start,
End_Position => P.Current.End_Pos,
Kind => Mapping_Start,
Collection_Properties => P.Header_Props,
Collection_Style => Block);
P.Header_Props := Default_Properties;
P.Levels.Top.all := (Before_Block_Map_Value'Access, Lexer.Recent_Indentation (P.L));
P.Levels.Push ((State => Before_Block_Indentation'Access,
Indentation => <>));
P.Levels.Push ((State => After_Compact_Parent'Access,
Indentation => <>));
P.Current := Lexer.Next_Token (P.L);
return True;
when others =>
P.Levels.Top.State := After_Compact_Parent_Props'Access;
return False;
end case;
return False;
end After_Compact_Parent;
function After_Compact_Parent_Props (P : in out Class;
E : out Event) return Boolean is
begin
P.Levels.Top.Indentation := Lexer.Recent_Indentation (P.L);
case P.Current.Kind is
when Lexer.Node_Property_Kind =>
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
return False;
when Lexer.Indentation =>
P.Header_Start := P.Inline_Start;
P.Levels.Top.all :=
(State => At_Block_Indentation'Access,
Indentation => P.Levels.Element (P.Levels.Length - 2).Indentation);
P.Levels.Push ((State => Before_Block_Indentation'Access,
Indentation => <>));
return False;
when Lexer.Stream_End | Lexer.Document_End | Lexer.Directives_End =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.Start_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => Plain,
Content => Text.Empty);
P.Inline_Props := Default_Properties;
P.Levels.Pop;
return True;
when Lexer.Map_Value_Ind =>
P.Cached := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => Plain,
Content => Text.Empty);
P.Inline_Props := Default_Properties;
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.Start_Pos,
Kind => Mapping_Start,
Collection_Properties => Default_Properties,
Collection_Style => Block);
P.Levels.Top.State := After_Implicit_Map_Start'Access;
return True;
when Lexer.Alias =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Alias,
Target => P.Pool.From_String (Lexer.Short_Lexeme (P.L)));
declare
Header_End : constant Mark := P.Current.Start_Pos;
begin
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind = Lexer.Map_Value_Ind then
P.Cached := E;
E := Event'(Start_Position => Header_End,
End_Position => Header_End,
Kind => Mapping_Start,
Collection_Properties => Default_Properties,
Collection_Style => Block);
P.Levels.Top.State := After_Implicit_Map_Start'Access;
else
P.Levels.Pop;
end if;
end;
return True;
when Lexer.Scalar_Token_Kind =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => To_Style (P.Current.Kind),
Content => Lexer.Current_Content (P.L));
P.Inline_Props := Default_Properties;
declare
Header_End : constant Mark := P.Current.Start_Pos;
begin
P.Levels.Top.Indentation := Lexer.Recent_Indentation (P.L);
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind = Lexer.Map_Value_Ind then
if Lexer.Last_Scalar_Was_Multiline (P.L) then
raise Parser_Error with
"Implicit mapping key may not be multiline";
end if;
P.Cached := E;
E := Event'(Start_Position => Header_End,
End_Position => Header_End,
Kind => Mapping_Start,
Collection_Properties => Default_Properties,
Collection_Style => Block);
P.Levels.Top.State := After_Implicit_Map_Start'Access;
else
P.Levels.Pop;
end if;
end;
return True;
when Lexer.Flow_Map_Start =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Mapping_Start,
Collection_Properties => P.Inline_Props,
Collection_Style => Flow);
P.Inline_Props := Default_Properties;
P.Levels.Top.State := After_Flow_Map_Sep'Access;
P.Current := Lexer.Next_Token (P.L);
return True;
when Lexer.Flow_Seq_Start =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Sequence_Start,
Collection_Properties => P.Inline_Props,
Collection_Style => Flow);
P.Inline_Props := Default_Properties;
P.Levels.Top.State := After_Flow_Seq_Sep'Access;
P.Current := Lexer.Next_Token (P.L);
return True;
when others =>
raise Parser_Error with
"Unexpected token (expected newline or flow item start): " &
P.Current.Kind'Img;
end case;
end After_Compact_Parent_Props;
function After_Block_Parent (P : in out Class;
E : out Event) return Boolean is
pragma Unreferenced (E);
begin
P.Inline_Start := P.Current.Start_Pos;
case P.Current.Kind is
when Lexer.Node_Property_Kind =>
P.Levels.Top.State := After_Block_Parent_Props'Access;
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
when Lexer.Seq_Item_Ind | Lexer.Map_Key_Ind =>
raise Parser_Error with
"Compact notation not allowed after implicit key";
when others =>
P.Levels.Top.State := After_Block_Parent_Props'Access;
end case;
return False;
end After_Block_Parent;
function After_Block_Parent_Props (P : in out Class;
E : out Event) return Boolean is
begin
P.Levels.Top.Indentation := Lexer.Recent_Indentation (P.L);
case P.Current.Kind is
when Lexer.Node_Property_Kind =>
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
return False;
when Lexer.Map_Value_Ind =>
raise Parser_Error with
"Compact notation not allowed after implicit key";
when Lexer.Scalar_Token_Kind =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => To_Style (P.Current.Kind),
Content => Lexer.Current_Content (P.L));
P.Inline_Props := Default_Properties;
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind = Lexer.Map_Value_Ind then
raise Parser_Error with
"Compact notation not allowed after implicit key";
end if;
P.Levels.Pop;
return True;
when others =>
P.Levels.Top.State := After_Compact_Parent_Props'Access;
return False;
end case;
end After_Block_Parent_Props;
function Require_Inline_Block_Item (P : in out Class;
E : out Event) return Boolean is
pragma Unreferenced (E);
begin
P.Levels.Top.Indentation := Lexer.Recent_Indentation (P.L);
case P.Current.Kind is
when Lexer.Indentation =>
raise Parser_Error with
"Node properties may not stand alone on a line";
when others =>
P.Levels.Top.State := After_Compact_Parent_Props'Access;
return False;
end case;
end Require_Inline_Block_Item;
function Before_Doc_End (P : in out Class;
E : out Event) return Boolean is
begin
case P.Current.Kind is
when Lexer.Document_End =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Document_End,
Implicit_End => False);
P.Levels.Top.State := Before_Doc'Access;
Reset_Tag_Handles (P);
P.Current := Lexer.Next_Token (P.L);
when Lexer.Stream_End =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Document_End,
Implicit_End => True);
P.Levels.Pop;
when Lexer.Directives_End =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Document_End,
Implicit_End => True);
Reset_Tag_Handles (P);
P.Levels.Top.State := Before_Doc'Access;
when others =>
raise Parser_Error with
"Unexpected token (expected document end): " & P.Current.Kind'Img;
end case;
return True;
end Before_Doc_End;
function In_Block_Seq (P : in out Class;
E : out Event) return Boolean is
begin
if P.Block_Indentation > P.Levels.Top.Indentation then
raise Parser_Error with "Invalid indentation (bseq); got" &
P.Block_Indentation'Img & ", expected" & P.Levels.Top.Indentation'Img;
end if;
case P.Current.Kind is
when Lexer.Seq_Item_Ind =>
P.Current := Lexer.Next_Token (P.L);
P.Levels.Push ((State => Before_Block_Indentation'Access,
Indentation => <>));
P.Levels.Push ((State => After_Compact_Parent'Access,
Indentation => P.Block_Indentation));
return False;
when others =>
if P.Levels.Element (P.Levels.Length - 2).Indentation =
P.Levels.Top.Indentation then
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Sequence_End);
P.Levels.Pop;
P.Levels.Pop;
return True;
else
raise Parser_Error with
"Illegal token (expected block sequence indicator): " &
P.Current.Kind'Img;
end if;
end case;
end In_Block_Seq;
function After_Implicit_Map_Start (P : in out Class;
E : out Event) return Boolean is
begin
E := P.Cached;
P.Levels.Top.State := After_Implicit_Key'Access;
return True;
end After_Implicit_Map_Start;
function Before_Block_Map_Key (P : in out Class;
E : out Event) return Boolean is
begin
if P.Block_Indentation > P.Levels.Top.Indentation then
raise Parser_Error with "Invalid indentation (bmk); got" &
P.Block_Indentation'Img & ", expected" & P.Levels.Top.Indentation'Img &
", token = " & P.Current.Kind'Img;
end if;
case P.Current.Kind is
when Lexer.Map_Key_Ind =>
P.Levels.Top.State := Before_Block_Map_Value'Access;
P.Levels.Push ((State => Before_Block_Indentation'Access,
Indentation => <>));
P.Levels.Push ((State => After_Compact_Parent'Access,
Indentation => P.Levels.Top.Indentation));
P.Current := Lexer.Next_Token (P.L);
return False;
when Lexer.Node_Property_Kind =>
P.Levels.Top.State := At_Block_Map_Key_Props'Access;
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
return False;
when Lexer.Flow_Scalar_Token_Kind =>
P.Levels.Top.State := At_Block_Map_Key_Props'Access;
return False;
when Lexer.Alias =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Alias,
Target => P.Pool.From_String (Lexer.Short_Lexeme (P.L)));
P.Current := Lexer.Next_Token (P.L);
P.Levels.Top.State := After_Implicit_Key'Access;
return True;
when Lexer.Map_Value_Ind =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => Default_Properties,
Scalar_Style => Plain,
Content => Text.Empty);
P.Levels.Top.State := Before_Block_Map_Value'Access;
return True;
when others =>
raise Parser_Error with
"Unexpected token (expected mapping key): " &
P.Current.Kind'Img;
end case;
end Before_Block_Map_Key;
function At_Block_Map_Key_Props (P : in out Class;
E : out Event) return Boolean is
begin
case P.Current.Kind is
when Lexer.Node_Property_Kind =>
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
when Lexer.Alias =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Alias,
Target => P.Pool.From_String (Lexer.Short_Lexeme (P.L)));
when Lexer.Flow_Scalar_Token_Kind =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => To_Style (P.Current.Kind),
Content => Lexer.Current_Content (P.L));
P.Inline_Props := Default_Properties;
if Lexer.Last_Scalar_Was_Multiline (P.L) then
raise Parser_Error with
"Implicit mapping key may not be multiline";
end if;
when Lexer.Map_Value_Ind =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.Start_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => Plain,
Content => Text.Empty);
P.Inline_Props := Default_Properties;
P.Levels.Top.State := After_Implicit_Key'Access;
return True;
when others =>
raise Parser_Error with
"Unexpected token (expected implicit mapping key): " &
P.Current.Kind'Img;
end case;
P.Current := Lexer.Next_Token (P.L);
P.Levels.Top.State := After_Implicit_Key'Access;
return True;
end At_Block_Map_Key_Props;
function After_Implicit_Key (P : in out Class;
E : out Event) return Boolean is
pragma Unreferenced (E);
begin
if P.Current.Kind /= Lexer.Map_Value_Ind then
raise Parser_Error with "Unexpected token (expected ':'): " &
P.Current.Kind'Img;
end if;
P.Current := Lexer.Next_Token (P.L);
P.Levels.Top.State := Before_Block_Map_Key'Access;
P.Levels.Push ((State => Before_Block_Indentation'Access,
Indentation => <>));
P.Levels.Push
((State => After_Block_Parent'Access,
Indentation => P.Levels.Top.Indentation));
return False;
end After_Implicit_Key;
function Before_Block_Map_Value (P : in out Class;
E : out Event) return Boolean is
begin
if P.Block_Indentation > P.Levels.Top.Indentation then
raise Parser_Error with "Invalid indentation (bmv)";
end if;
case P.Current.Kind is
when Lexer.Map_Value_Ind =>
P.Levels.Top.State := Before_Block_Map_Key'Access;
P.Levels.Push ((State => Before_Block_Indentation'Access,
Indentation => <>));
P.Levels.Push
((State => After_Compact_Parent'Access,
Indentation => P.Levels.Top.Indentation));
P.Current := Lexer.Next_Token (P.L);
return False;
when Lexer.Map_Key_Ind | Lexer.Flow_Scalar_Token_Kind |
Lexer.Node_Property_Kind =>
-- the value is allowed to be missing after an explicit key
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => Default_Properties,
Scalar_Style => Plain,
Content => Text.Empty);
P.Levels.Top.State := Before_Block_Map_Key'Access;
return True;
when others =>
raise Parser_Error with
"Unexpected token (expected mapping value): " &
P.Current.Kind'Img;
end case;
end Before_Block_Map_Value;
function Before_Block_Indentation (P : in out Class;
E : out Event) return Boolean is
procedure End_Block_Node is
begin
if P.Levels.Top.State = Before_Block_Map_Key'Access then
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Mapping_End);
elsif P.Levels.Top.State = Before_Block_Map_Value'Access then
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => Default_Properties,
Scalar_Style => Plain,
Content => Text.Empty);
P.Levels.Top.State := Before_Block_Map_Key'Access;
P.Levels.Push ((State => Before_Block_Indentation'Access,
Indentation => <>));
return;
elsif P.Levels.Top.State = In_Block_Seq'Access then
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Sequence_End);
elsif P.Levels.Top.State = At_Block_Indentation'Access then
E := Event'(Start_Position => P.Header_Start,
End_Position => P.Header_Start,
Kind => Scalar,
Scalar_Properties => P.Header_Props,
Scalar_Style => Plain,
Content => Text.Empty);
P.Header_Props := Default_Properties;
elsif P.Levels.Top.State = Before_Block_Indentation'Access then
raise Parser_Error with "Unexpected double Before_Block_Indentation";
else
raise Parser_Error with "Internal error (please report this bug)";
end if;
P.Levels.Pop;
end End_Block_Node;
begin
P.Levels.Pop;
case P.Current.Kind is
when Lexer.Indentation =>
P.Block_Indentation := Lexer.Current_Indentation (P.L);
if P.Block_Indentation < P.Levels.Top.Indentation then
End_Block_Node;
return True;
else
P.Current := Lexer.Next_Token (P.L);
return False;
end if;
when Lexer.Stream_End | Lexer.Document_End | Lexer.Directives_End =>
P.Block_Indentation := 0;
if P.Levels.Top.State /= Before_Doc_End'Access then
End_Block_Node;
return True;
else
return False;
end if;
when others =>
raise Parser_Error with
"Unexpected content after node in block context (expected newline): "
& P.Current.Kind'Img;
end case;
end Before_Block_Indentation;
function Before_Flow_Item (P : in out Class;
E : out Event) return Boolean is
begin
P.Inline_Start := P.Current.Start_Pos;
case P.Current.Kind is
when Lexer.Node_Property_Kind =>
P.Levels.Top.State := Before_Flow_Item_Props'Access;
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
when Lexer.Alias =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Alias,
Target => P.Pool.From_String (Lexer.Short_Lexeme (P.L)));
P.Current := Lexer.Next_Token (P.L);
P.Levels.Pop;
return True;
when others =>
P.Levels.Top.State := Before_Flow_Item_Props'Access;
end case;
return False;
end Before_Flow_Item;
function Before_Flow_Item_Props (P : in out Class;
E : out Event) return Boolean is
begin
case P.Current.Kind is
when Lexer.Node_Property_Kind =>
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
when Lexer.Alias =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Alias,
Target => P.Pool.From_String (Lexer.Short_Lexeme (P.L)));
P.Current := Lexer.Next_Token (P.L);
P.Levels.Pop;
when Lexer.Scalar_Token_Kind =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => To_Style (P.Current.Kind),
Content => Lexer.Current_Content (P.L));
P.Current := Lexer.Next_Token (P.L);
P.Levels.Pop;
when Lexer.Flow_Map_Start =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Mapping_Start,
Collection_Properties => P.Inline_Props,
Collection_Style => Flow);
P.Levels.Top.State := After_Flow_Map_Sep'Access;
P.Current := Lexer.Next_Token (P.L);
when Lexer.Flow_Seq_Start =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Sequence_Start,
Collection_Properties => P.Inline_Props,
Collection_Style => Flow);
P.Levels.Top.State := After_Flow_Seq_Sep'Access;
P.Current := Lexer.Next_Token (P.L);
when Lexer.Flow_Map_End | Lexer.Flow_Seq_End |
Lexer.Flow_Separator | Lexer.Map_Value_Ind =>
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => Plain,
Content => Text.Empty);
P.Levels.Pop;
when others =>
raise Parser_Error with
"Unexpected token (expected flow node): " & P.Current.Kind'Img;
end case;
P.Inline_Props := Default_Properties;
return True;
end Before_Flow_Item_Props;
function After_Flow_Map_Key (P : in out Class;
E : out Event) return Boolean is
begin
case P.Current.Kind is
when Lexer.Map_Value_Ind =>
P.Levels.Top.State := After_Flow_Map_Value'Access;
P.Levels.Push ((State => Before_Flow_Item'Access, others => <>));
P.Current := Lexer.Next_Token (P.L);
return False;
when Lexer.Flow_Separator | Lexer.Flow_Map_End =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => Default_Properties,
Scalar_Style => Plain,
Content => Text.Empty);
P.Levels.Top.State := After_Flow_Map_Value'Access;
return True;
when others =>
raise Parser_Error with "Unexpected token (expected ':'): " &
P.Current.Kind'Img;
end case;
end After_Flow_Map_Key;
function After_Flow_Map_Value (P : in out Class;
E : out Event) return Boolean is
begin
case P.Current.Kind is
when Lexer.Flow_Separator =>
P.Levels.Top.State := After_Flow_Map_Sep'Access;
P.Current := Lexer.Next_Token (P.L);
return False;
when Lexer.Flow_Map_End =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Mapping_End);
P.Current := Lexer.Next_Token (P.L);
P.Levels.Pop;
return True;
when Lexer.Flow_Scalar_Token_Kind | Lexer.Map_Key_Ind |
Lexer.Anchor | Lexer.Alias | Lexer.Annotation_Handle |
Lexer.Flow_Map_Start | Lexer.Flow_Seq_Start =>
raise Parser_Error with "Missing ','";
when others =>
raise Parser_Error with "Unexpected token (expected ',' or '}'): " &
P.Current.Kind'Img;
end case;
end After_Flow_Map_Value;
function After_Flow_Seq_Item (P : in out Class;
E : out Event) return Boolean is
begin
case P.Current.Kind is
when Lexer.Flow_Separator =>
P.Levels.Top.State := After_Flow_Seq_Sep'Access;
P.Current := Lexer.Next_Token (P.L);
return False;
when Lexer.Flow_Seq_End =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Sequence_End);
P.Current := Lexer.Next_Token (P.L);
P.Levels.Pop;
return True;
when Lexer.Flow_Scalar_Token_Kind | Lexer.Map_Key_Ind |
Lexer.Anchor | Lexer.Alias | Lexer.Annotation_Handle |
Lexer.Flow_Map_Start | Lexer.Flow_Seq_Start =>
raise Parser_Error with "Missing ','";
when others =>
raise Parser_Error with "Unexpected token (expected ',' or ']'): " &
P.Current.Kind'Img;
end case;
end After_Flow_Seq_Item;
function After_Flow_Map_Sep (P : in out Class;
E : out Event) return Boolean is
begin
case P.Current.Kind is
when Lexer.Map_Key_Ind =>
P.Current := Lexer.Next_Token (P.L);
when Lexer.Flow_Map_End =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Mapping_End);
P.Current := Lexer.Next_Token (P.L);
P.Levels.Pop;
return True;
when others => null;
end case;
P.Levels.Top.State := After_Flow_Map_Key'Access;
P.Levels.Push ((State => Before_Flow_Item'Access, Indentation => <>));
return False;
end After_Flow_Map_Sep;
function Possible_Next_Sequence_Item (P : in out Class;
E : out Event;
End_Token : Lexer.Token_Kind;
After_Props, After_Item : State_Type)
return Boolean is
begin
P.Inline_Start := P.Current.Start_Pos;
case P.Current.Kind is
when Lexer.Flow_Separator =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.Start_Pos,
Kind => Scalar,
Scalar_Properties => Default_Properties,
Scalar_Style => Plain,
Content => Text.Empty);
P.Current := Lexer.Next_Token (P.L);
return True;
when Lexer.Node_Property_Kind =>
P.Levels.Top.State := After_Props;
P.Levels.Push ((State => Before_Node_Properties'Access,
Indentation => <>));
return False;
when Lexer.Flow_Scalar_Token_Kind =>
P.Levels.Top.State := After_Props;
return False;
when Lexer.Map_Key_Ind =>
P.Levels.Top.State := After_Item;
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Mapping_Start,
Collection_Properties => Default_Properties,
Collection_Style => Flow);
P.Current := Lexer.Next_Token (P.L);
P.Levels.Push ((State => Before_Pair_Value'Access, others => <>));
P.Levels.Push ((State => Before_Flow_Item'Access, others => <>));
return True;
when Lexer.Map_Value_Ind =>
P.Levels.Top.State := After_Item;
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Mapping_Start,
Collection_Properties => Default_Properties,
Collection_Style => Flow);
P.Levels.Push ((State => At_Empty_Pair_Key'Access, others => <>));
return True;
when others =>
if P.Current.Kind = End_Token then
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Sequence_End);
P.Current := Lexer.Next_Token (P.L);
P.Levels.Pop;
return True;
else
P.Levels.Top.State := After_Item;
P.Levels.Push ((State => Before_Flow_Item'Access, others => <>));
return False;
end if;
end case;
end Possible_Next_Sequence_Item;
function After_Flow_Seq_Sep (P : in out Class;
E : out Event) return Boolean is
begin
return Possible_Next_Sequence_Item (P, E, Lexer.Flow_Seq_End,
After_Flow_Seq_Sep_Props'Access,
After_Flow_Seq_Item'Access);
end After_Flow_Seq_Sep;
function Forced_Next_Sequence_Item (P : in out Class;
E : out Event) return Boolean is
begin
if P.Current.Kind in Lexer.Flow_Scalar_Token_Kind then
E := Event'(Start_Position => P.Inline_Start,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => P.Inline_Props,
Scalar_Style => To_Style (P.Current.Kind),
Content => Lexer.Current_Content (P.L));
P.Inline_Props := Default_Properties;
P.Current := Lexer.Next_Token (P.L);
if P.Current.Kind = Lexer.Map_Value_Ind then
P.Cached := E;
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.Start_Pos,
Kind => Mapping_Start,
Collection_Properties => Default_Properties,
Collection_Style => Flow);
P.Levels.Push ((State => After_Implicit_Pair_Start'Access,
Indentation => <>));
end if;
return True;
else
P.Levels.Push ((State => Before_Flow_Item_Props'Access, others => <>));
return False;
end if;
end Forced_Next_Sequence_Item;
function After_Flow_Seq_Sep_Props (P : in out Class;
E : out Event) return Boolean is
begin
P.Levels.Top.State := After_Flow_Seq_Item'Access;
return Forced_Next_Sequence_Item (P, E);
end After_Flow_Seq_Sep_Props;
function At_Empty_Pair_Key (P : in out Class; E : out Event) return Boolean
is begin
P.Levels.Top.State := Before_Pair_Value'Access;
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.Start_Pos,
Kind => Scalar,
Scalar_Properties => Default_Properties,
Scalar_Style => Plain,
Content => Text.Empty);
return True;
end At_Empty_Pair_Key;
function Before_Pair_Value (P : in out Class;
E : out Event) return Boolean is
begin
if P.Current.Kind = Lexer.Map_Value_Ind then
P.Levels.Top.State := After_Pair_Value'Access;
P.Levels.Push ((State => Before_Flow_Item'Access, others => <>));
P.Current := Lexer.Next_Token (P.L);
return False;
else
-- pair ends here without value.
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Scalar,
Scalar_Properties => Default_Properties,
Scalar_Style => Plain,
Content => Text.Empty);
P.Levels.Pop;
return True;
end if;
end Before_Pair_Value;
function After_Implicit_Pair_Start (P : in out Class;
E : out Event) return Boolean is
begin
E := P.Cached;
P.Current := Lexer.Next_Token (P.L);
P.Levels.Top.State := After_Pair_Value'Access;
P.Levels.Push ((State => Before_Flow_Item'Access, others => <>));
return True;
end After_Implicit_Pair_Start;
function After_Pair_Value (P : in out Class;
E : out Event) return Boolean is
begin
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Mapping_End);
P.Levels.Pop;
return True;
end After_Pair_Value;
function After_Param_Sep (P : in out Class; E : out Event)
return Boolean is
begin
return Possible_Next_Sequence_Item (P, E, Lexer.Params_End,
After_Param_Sep_Props'Access,
After_Param'Access);
end After_Param_Sep;
function After_Param_Sep_Props
(P : in out Class; E : out Event) return Boolean is
begin
P.Levels.Top.State := After_Param'Access;
return Forced_Next_Sequence_Item (P, E);
end After_Param_Sep_Props;
function After_Param (P : in out Class; E : out Event)
return Boolean is
begin
case P.Current.Kind is
when Lexer.Flow_Separator =>
P.Levels.Top.State := After_Param_Sep'Access;
P.Current := Lexer.Next_Token (P.L);
return False;
when Lexer.Params_End =>
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.End_Pos,
Kind => Annotation_End);
P.Current := Lexer.Next_Token (P.L);
P.Levels.Pop;
return True;
when Lexer.Flow_Scalar_Token_Kind | Lexer.Map_Key_Ind |
Lexer.Anchor | Lexer.Alias | Lexer.Annotation_Handle |
Lexer.Flow_Map_Start | Lexer.Flow_Seq_Start =>
raise Parser_Error with "Missing ','";
when others =>
raise Parser_Error with "Unexpected token (expected ',' or ')'): " &
P.Current.Kind'Img;
end case;
end After_Param;
function After_Annotation (P : in out Class; E : out Event)
return Boolean is
begin
E := Event'(Start_Position => P.Current.Start_Pos,
End_Position => P.Current.Start_Pos,
Kind => Annotation_End);
P.Levels.Pop;
return True;
end After_Annotation;
end Yaml.Parser;
|
package Loop_Optimization6 is
A : Integer := 0;
procedure Main;
end Loop_Optimization6;
|
-- POK header
--
-- The following file is a part of the POK project. Any modification should
-- be made according to the POK licence. You CANNOT use this file or a part
-- of a file for your own project.
--
-- For more information on the POK licence, please see our LICENCE FILE
--
-- Please follow the coding guidelines described in doc/CODING_GUIDELINES
--
-- Copyright (c) 2007-2021 POK team
with User;
use User;
package body Subprograms is
procedure Hello_Part1 is
begin
User.Hello_Part1 ();
end Hello_Part1;
end Subprograms;
|
-- C83F01C0.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.
--*
-- SEPARATELY COMPILED PACKAGE FOR USE WITH C83F01C2M
-- THIS PACKAGE IS A FULL-FLEDGED COMPILATION UNIT (AS OPPOSED TO
-- BEING A SUBUNIT; SUBUNITS ARE TESTED IN C83F01D0M ,
-- C83F01D1 ). THE PRESENT FILE CONTAINS THE SPECIFICATION
-- OF THE PACKAGE. THE BODY IS IN FILE C83F01C1.
-- RM 13 AUGUST 1980
-- RM 22 AUGUST 1980
-- PWN 11/30/94 ADDED A PROCEDURE TO KEEP PACKAGE BODIES LEGAL.
PACKAGE C83F01C0 IS
Y3 : INTEGER := 100 ;
PACKAGE P IS
X1 : BOOLEAN := FALSE ;
X2 : INTEGER RANGE 1..23 := 11 ;
Y1 , Y3 : BOOLEAN := TRUE ;
Y2 , Y4 : INTEGER := 5 ;
T1 : INTEGER := 6 ;
Z : INTEGER := 7 ;
END P ;
PROCEDURE REQUIRE_BODY;
END C83F01C0 ;
|
with Class1; use Class1;
package PrimitivePropertyTypes is
someInteger : Integer := 1;
someNatural : Natural := 2;
someBoolean : Boolean := False;
someString : String(1 .. 5) := "hello";
someFloat : Float := 1.1;
anotherFloat : Float;
someClass1 : Class1.Class1;
function someFunction (Self : in Integer) return Class1.Class1;
function someFunction2 (Self : in Class1.Class1) return Integer;
end PrimitivePropertyTypes;
|
--===========================================================================
--
-- This package is the interface the Alpha internal procedures/functions
-- for avoiding duplicating code
--
--===========================================================================
--
-- Copyright 2021 (C) Holger Rodriguez
--
-- SPDX-License-Identifier: BSD-3-Clause
--
private package Edc_Client.Alpha.Common is
--------------------------------------------------------------------------
-- Shows a Single Letter
--------------------------------------------------------------------------
procedure Show_Single_Letter (Position : Integer;
Block : Character;
Value : String);
--------------------------------------------------------------------------
-- Shows Double Letters
--------------------------------------------------------------------------
procedure Show_Double_Letters (Position : Integer;
Block : Character;
Value : String);
--------------------------------------------------------------------------
-- Shows Four Letters
--------------------------------------------------------------------------
procedure Show_Four_Letters (Position : Integer;
Block : Character;
Value : String);
end Edc_Client.Alpha.Common;
|
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Command_Line; use Ada.Command_Line;
with Arbitrary; use Arbitrary;
with Arbitrary.Log; use Arbitrary.Log;
procedure E is
precision : integer;
begin
if Argument_Count /= 1 then
Put_Line("usage: " & Command_Name & " <digits>");
return;
end if;
precision := integer'value(Argument(1));
declare
result : Arbitrary_Type(precision);
begin
result := Exp(To_Arbitrary(1, precision));
Display(result);
end;
end E;
|
-----------------------------------------------------------------------
-- util-strings-sets -- Set of strings
-- Copyright (C) 2011, 2018 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings.Hash;
with Ada.Containers.Indefinite_Hashed_Sets;
-- The <b>Util.Strings.Sets</b> package provides an instantiation
-- of a hashed set with Strings.
package Util.Strings.Sets is new Ada.Containers.Indefinite_Hashed_Sets
(Element_Type => String,
Hash => Ada.Strings.Hash,
Equivalent_Elements => "=");
|
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
package body Program.Nodes.Procedure_Body_Declarations is
function Create
(Not_Token : Program.Lexical_Elements.Lexical_Element_Access;
Overriding_Token : Program.Lexical_Elements.Lexical_Element_Access;
Procedure_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Name : not null Program.Elements.Defining_Names
.Defining_Name_Access;
Left_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access;
Parameters : Program.Elements.Parameter_Specifications
.Parameter_Specification_Vector_Access;
Right_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access;
With_Token : Program.Lexical_Elements.Lexical_Element_Access;
Aspects : Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access;
Is_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Declarations : Program.Element_Vectors.Element_Vector_Access;
Begin_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Statements : not null Program.Element_Vectors
.Element_Vector_Access;
Exception_Token : Program.Lexical_Elements.Lexical_Element_Access;
Exception_Handlers : Program.Elements.Exception_Handlers
.Exception_Handler_Vector_Access;
End_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
End_Name : Program.Elements.Expressions.Expression_Access;
Semicolon_Token : not null Program.Lexical_Elements
.Lexical_Element_Access)
return Procedure_Body_Declaration is
begin
return Result : Procedure_Body_Declaration :=
(Not_Token => Not_Token, Overriding_Token => Overriding_Token,
Procedure_Token => Procedure_Token, Name => Name,
Left_Bracket_Token => Left_Bracket_Token, Parameters => Parameters,
Right_Bracket_Token => Right_Bracket_Token, With_Token => With_Token,
Aspects => Aspects, Is_Token => Is_Token,
Declarations => Declarations, Begin_Token => Begin_Token,
Statements => Statements, Exception_Token => Exception_Token,
Exception_Handlers => Exception_Handlers, End_Token => End_Token,
End_Name => End_Name, Semicolon_Token => Semicolon_Token,
Enclosing_Element => null)
do
Initialize (Result);
end return;
end Create;
function Create
(Name : not null Program.Elements.Defining_Names
.Defining_Name_Access;
Parameters : Program.Elements.Parameter_Specifications
.Parameter_Specification_Vector_Access;
Aspects : Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access;
Declarations : Program.Element_Vectors.Element_Vector_Access;
Statements : not null Program.Element_Vectors
.Element_Vector_Access;
Exception_Handlers : Program.Elements.Exception_Handlers
.Exception_Handler_Vector_Access;
End_Name : Program.Elements.Expressions.Expression_Access;
Is_Part_Of_Implicit : Boolean := False;
Is_Part_Of_Inherited : Boolean := False;
Is_Part_Of_Instance : Boolean := False;
Has_Not : Boolean := False;
Has_Overriding : Boolean := False)
return Implicit_Procedure_Body_Declaration is
begin
return Result : Implicit_Procedure_Body_Declaration :=
(Name => Name, Parameters => Parameters, Aspects => Aspects,
Declarations => Declarations, Statements => Statements,
Exception_Handlers => Exception_Handlers, End_Name => End_Name,
Is_Part_Of_Implicit => Is_Part_Of_Implicit,
Is_Part_Of_Inherited => Is_Part_Of_Inherited,
Is_Part_Of_Instance => Is_Part_Of_Instance, Has_Not => Has_Not,
Has_Overriding => Has_Overriding, Enclosing_Element => null)
do
Initialize (Result);
end return;
end Create;
overriding function Name
(Self : Base_Procedure_Body_Declaration)
return not null Program.Elements.Defining_Names.Defining_Name_Access is
begin
return Self.Name;
end Name;
overriding function Parameters
(Self : Base_Procedure_Body_Declaration)
return Program.Elements.Parameter_Specifications
.Parameter_Specification_Vector_Access is
begin
return Self.Parameters;
end Parameters;
overriding function Aspects
(Self : Base_Procedure_Body_Declaration)
return Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access is
begin
return Self.Aspects;
end Aspects;
overriding function Declarations
(Self : Base_Procedure_Body_Declaration)
return Program.Element_Vectors.Element_Vector_Access is
begin
return Self.Declarations;
end Declarations;
overriding function Statements
(Self : Base_Procedure_Body_Declaration)
return not null Program.Element_Vectors.Element_Vector_Access is
begin
return Self.Statements;
end Statements;
overriding function Exception_Handlers
(Self : Base_Procedure_Body_Declaration)
return Program.Elements.Exception_Handlers
.Exception_Handler_Vector_Access is
begin
return Self.Exception_Handlers;
end Exception_Handlers;
overriding function End_Name
(Self : Base_Procedure_Body_Declaration)
return Program.Elements.Expressions.Expression_Access is
begin
return Self.End_Name;
end End_Name;
overriding function Not_Token
(Self : Procedure_Body_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Not_Token;
end Not_Token;
overriding function Overriding_Token
(Self : Procedure_Body_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Overriding_Token;
end Overriding_Token;
overriding function Procedure_Token
(Self : Procedure_Body_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Procedure_Token;
end Procedure_Token;
overriding function Left_Bracket_Token
(Self : Procedure_Body_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Left_Bracket_Token;
end Left_Bracket_Token;
overriding function Right_Bracket_Token
(Self : Procedure_Body_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Right_Bracket_Token;
end Right_Bracket_Token;
overriding function With_Token
(Self : Procedure_Body_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.With_Token;
end With_Token;
overriding function Is_Token
(Self : Procedure_Body_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Is_Token;
end Is_Token;
overriding function Begin_Token
(Self : Procedure_Body_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Begin_Token;
end Begin_Token;
overriding function Exception_Token
(Self : Procedure_Body_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Exception_Token;
end Exception_Token;
overriding function End_Token
(Self : Procedure_Body_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.End_Token;
end End_Token;
overriding function Semicolon_Token
(Self : Procedure_Body_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Semicolon_Token;
end Semicolon_Token;
overriding function Has_Not
(Self : Procedure_Body_Declaration)
return Boolean is
begin
return Self.Not_Token.Assigned;
end Has_Not;
overriding function Has_Overriding
(Self : Procedure_Body_Declaration)
return Boolean is
begin
return Self.Overriding_Token.Assigned;
end Has_Overriding;
overriding function Is_Part_Of_Implicit
(Self : Implicit_Procedure_Body_Declaration)
return Boolean is
begin
return Self.Is_Part_Of_Implicit;
end Is_Part_Of_Implicit;
overriding function Is_Part_Of_Inherited
(Self : Implicit_Procedure_Body_Declaration)
return Boolean is
begin
return Self.Is_Part_Of_Inherited;
end Is_Part_Of_Inherited;
overriding function Is_Part_Of_Instance
(Self : Implicit_Procedure_Body_Declaration)
return Boolean is
begin
return Self.Is_Part_Of_Instance;
end Is_Part_Of_Instance;
overriding function Has_Not
(Self : Implicit_Procedure_Body_Declaration)
return Boolean is
begin
return Self.Has_Not;
end Has_Not;
overriding function Has_Overriding
(Self : Implicit_Procedure_Body_Declaration)
return Boolean is
begin
return Self.Has_Overriding;
end Has_Overriding;
procedure Initialize
(Self : aliased in out Base_Procedure_Body_Declaration'Class) is
begin
Set_Enclosing_Element (Self.Name, Self'Unchecked_Access);
for Item in Self.Parameters.Each_Element loop
Set_Enclosing_Element (Item.Element, Self'Unchecked_Access);
end loop;
for Item in Self.Aspects.Each_Element loop
Set_Enclosing_Element (Item.Element, Self'Unchecked_Access);
end loop;
for Item in Self.Declarations.Each_Element loop
Set_Enclosing_Element (Item.Element, Self'Unchecked_Access);
end loop;
for Item in Self.Statements.Each_Element loop
Set_Enclosing_Element (Item.Element, Self'Unchecked_Access);
end loop;
for Item in Self.Exception_Handlers.Each_Element loop
Set_Enclosing_Element (Item.Element, Self'Unchecked_Access);
end loop;
if Self.End_Name.Assigned then
Set_Enclosing_Element (Self.End_Name, Self'Unchecked_Access);
end if;
null;
end Initialize;
overriding function Is_Procedure_Body_Declaration_Element
(Self : Base_Procedure_Body_Declaration)
return Boolean is
pragma Unreferenced (Self);
begin
return True;
end Is_Procedure_Body_Declaration_Element;
overriding function Is_Declaration_Element
(Self : Base_Procedure_Body_Declaration)
return Boolean is
pragma Unreferenced (Self);
begin
return True;
end Is_Declaration_Element;
overriding procedure Visit
(Self : not null access Base_Procedure_Body_Declaration;
Visitor : in out Program.Element_Visitors.Element_Visitor'Class) is
begin
Visitor.Procedure_Body_Declaration (Self);
end Visit;
overriding function To_Procedure_Body_Declaration_Text
(Self : aliased in out Procedure_Body_Declaration)
return Program.Elements.Procedure_Body_Declarations
.Procedure_Body_Declaration_Text_Access is
begin
return Self'Unchecked_Access;
end To_Procedure_Body_Declaration_Text;
overriding function To_Procedure_Body_Declaration_Text
(Self : aliased in out Implicit_Procedure_Body_Declaration)
return Program.Elements.Procedure_Body_Declarations
.Procedure_Body_Declaration_Text_Access is
pragma Unreferenced (Self);
begin
return null;
end To_Procedure_Body_Declaration_Text;
end Program.Nodes.Procedure_Body_Declarations;
|
with Ada.Text_IO; use Ada.Text_IO;
package body base_iface is
procedure class_wide(Self : The_Interface'Class) is
begin
Put_Line(" iface'Class:class-wide, calling Self.simple");
Self.simple;
end;
end base_iface;
|
------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding Samples --
-- --
-- Sample.Curses_Demo.Attributes --
-- --
-- B O D Y --
-- --
------------------------------------------------------------------------------
-- Copyright (c) 1998 Free Software Foundation, Inc. --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, distribute with modifications, sublicense, and/or sell --
-- copies of the Software, and to permit persons to whom the Software is --
-- furnished to do so, subject to the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
-- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1996
-- Version Control
-- $Revision: 1.7 $
-- Binding Version 00.93
------------------------------------------------------------------------------
with Terminal_Interface.Curses; use Terminal_Interface.Curses;
with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
with Sample.Manifest; use Sample.Manifest;
with Sample.Helpers; use Sample.Helpers;
with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
with Sample.Keyboard_Handler; use Sample.Keyboard_Handler;
with Sample.Header_Handler; use Sample.Header_Handler;
with Sample.Explanation; use Sample.Explanation;
with Sample.Menu_Demo.Handler;
with Sample.Curses_Demo.Mouse;
package body Sample.Curses_Demo.Attributes is
procedure Demo
is
P : Panel := Create (Standard_Window);
K : Real_Key_Code;
begin
Set_Meta_Mode;
Set_KeyPad_Mode;
Top (P);
Push_Environment ("ATTRIBDEMO");
Default_Labels;
Notepad ("ATTRIB-PAD00");
Set_Character_Attributes (Attr => (others => False));
Add (Line => 1, Column => Columns / 2 - 10,
Str => "This is NORMAL");
Set_Character_Attributes (Attr => (Stand_Out => True,
others => False));
Add (Line => 2, Column => Columns / 2 - 10,
Str => "This is Stand_Out");
Set_Character_Attributes (Attr => (Under_Line => True,
others => False));
Add (Line => 3, Column => Columns / 2 - 10,
Str => "This is Under_Line");
Set_Character_Attributes (Attr => (Reverse_Video => True,
others => False));
Add (Line => 4, Column => Columns / 2 - 10,
Str => "This is Reverse_Video");
Set_Character_Attributes (Attr => (Blink => True,
others => False));
Add (Line => 5, Column => Columns / 2 - 10,
Str => "This is Blink");
Set_Character_Attributes (Attr => (Dim_Character => True,
others => False));
Add (Line => 6, Column => Columns / 2 - 10,
Str => "This is Dim_Character");
Set_Character_Attributes (Attr => (Bold_Character => True,
others => False));
Add (Line => 7, Column => Columns / 2 - 10,
Str => "This is Bold_Character");
Refresh_Without_Update;
Update_Panels; Update_Screen;
loop
K := Get_Key;
if K in Special_Key_Code'Range then
case K is
when QUIT_CODE => exit;
when HELP_CODE => Explain_Context;
when EXPLAIN_CODE => Explain ("ATTRIBKEYS");
when others => null;
end case;
end if;
end loop;
Pop_Environment;
Clear;
Refresh_Without_Update;
Delete (P);
Update_Panels; Update_Screen;
end Demo;
end Sample.Curses_Demo.Attributes;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ C H 1 2 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Expander; use Expander;
with Fname; use Fname;
with Fname.UF; use Fname.UF;
with Freeze; use Freeze;
with Hostparm;
with Lib; use Lib;
with Lib.Load; use Lib.Load;
with Lib.Xref; use Lib.Xref;
with Nlists; use Nlists;
with Namet; use Namet;
with Nmake; use Nmake;
with Opt; use Opt;
with Rident; use Rident;
with Restrict; use Restrict;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Cat; use Sem_Cat;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch7; use Sem_Ch7;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch10; use Sem_Ch10;
with Sem_Ch13; use Sem_Ch13;
with Sem_Disp; use Sem_Disp;
with Sem_Elab; use Sem_Elab;
with Sem_Elim; use Sem_Elim;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Type; use Sem_Type;
with Sem_Util; use Sem_Util;
with Sem_Warn; use Sem_Warn;
with Stand; use Stand;
with Sinfo; use Sinfo;
with Sinfo.CN; use Sinfo.CN;
with Sinput; use Sinput;
with Sinput.L; use Sinput.L;
with Snames; use Snames;
with Stringt; use Stringt;
with Uname; use Uname;
with Table;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
with Urealp; use Urealp;
with GNAT.HTable;
package body Sem_Ch12 is
----------------------------------------------------------
-- Implementation of Generic Analysis and Instantiation --
-----------------------------------------------------------
-- GNAT implements generics by macro expansion. No attempt is made to
-- share generic instantiations (for now). Analysis of a generic definition
-- does not perform any expansion action, but the expander must be called
-- on the tree for each instantiation, because the expansion may of course
-- depend on the generic actuals. All of this is best achieved as follows:
--
-- a) Semantic analysis of a generic unit is performed on a copy of the
-- tree for the generic unit. All tree modifications that follow analysis
-- do not affect the original tree. Links are kept between the original
-- tree and the copy, in order to recognize non-local references within
-- the generic, and propagate them to each instance (recall that name
-- resolution is done on the generic declaration: generics are not really
-- macros!). This is summarized in the following diagram:
--
-- .-----------. .----------.
-- | semantic |<--------------| generic |
-- | copy | | unit |
-- | |==============>| |
-- |___________| global |__________|
-- references | | |
-- | | |
-- .-----|--|.
-- | .-----|---.
-- | | .----------.
-- | | | generic |
-- |__| | |
-- |__| instance |
-- |__________|
--
-- b) Each instantiation copies the original tree, and inserts into it a
-- series of declarations that describe the mapping between generic formals
-- and actuals. For example, a generic In OUT parameter is an object
-- renaming of the corresponing actual, etc. Generic IN parameters are
-- constant declarations.
--
-- c) In order to give the right visibility for these renamings, we use
-- a different scheme for package and subprogram instantiations. For
-- packages, the list of renamings is inserted into the package
-- specification, before the visible declarations of the package. The
-- renamings are analyzed before any of the text of the instance, and are
-- thus visible at the right place. Furthermore, outside of the instance,
-- the generic parameters are visible and denote their corresponding
-- actuals.
-- For subprograms, we create a container package to hold the renamings
-- and the subprogram instance itself. Analysis of the package makes the
-- renaming declarations visible to the subprogram. After analyzing the
-- package, the defining entity for the subprogram is touched-up so that
-- it appears declared in the current scope, and not inside the container
-- package.
-- If the instantiation is a compilation unit, the container package is
-- given the same name as the subprogram instance. This ensures that
-- the elaboration procedure called by the binder, using the compilation
-- unit name, calls in fact the elaboration procedure for the package.
-- Not surprisingly, private types complicate this approach. By saving in
-- the original generic object the non-local references, we guarantee that
-- the proper entities are referenced at the point of instantiation.
-- However, for private types, this by itself does not insure that the
-- proper VIEW of the entity is used (the full type may be visible at the
-- point of generic definition, but not at instantiation, or vice-versa).
-- In order to reference the proper view, we special-case any reference
-- to private types in the generic object, by saving both views, one in
-- the generic and one in the semantic copy. At time of instantiation, we
-- check whether the two views are consistent, and exchange declarations if
-- necessary, in order to restore the correct visibility. Similarly, if
-- the instance view is private when the generic view was not, we perform
-- the exchange. After completing the instantiation, we restore the
-- current visibility. The flag Has_Private_View marks identifiers in the
-- the generic unit that require checking.
-- Visibility within nested generic units requires special handling.
-- Consider the following scheme:
--
-- type Global is ... -- outside of generic unit.
-- generic ...
-- package Outer is
-- ...
-- type Semi_Global is ... -- global to inner.
--
-- generic ... -- 1
-- procedure inner (X1 : Global; X2 : Semi_Global);
--
-- procedure in2 is new inner (...); -- 4
-- end Outer;
-- package New_Outer is new Outer (...); -- 2
-- procedure New_Inner is new New_Outer.Inner (...); -- 3
-- The semantic analysis of Outer captures all occurrences of Global.
-- The semantic analysis of Inner (at 1) captures both occurrences of
-- Global and Semi_Global.
-- At point 2 (instantiation of Outer), we also produce a generic copy
-- of Inner, even though Inner is, at that point, not being instantiated.
-- (This is just part of the semantic analysis of New_Outer).
-- Critically, references to Global within Inner must be preserved, while
-- references to Semi_Global should not preserved, because they must now
-- resolve to an entity within New_Outer. To distinguish between these, we
-- use a global variable, Current_Instantiated_Parent, which is set when
-- performing a generic copy during instantiation (at 2). This variable is
-- used when performing a generic copy that is not an instantiation, but
-- that is nested within one, as the occurrence of 1 within 2. The analysis
-- of a nested generic only preserves references that are global to the
-- enclosing Current_Instantiated_Parent. We use the Scope_Depth value to
-- determine whether a reference is external to the given parent.
-- The instantiation at point 3 requires no special treatment. The method
-- works as well for further nestings of generic units, but of course the
-- variable Current_Instantiated_Parent must be stacked because nested
-- instantiations can occur, e.g. the occurrence of 4 within 2.
-- The instantiation of package and subprogram bodies is handled in a
-- similar manner, except that it is delayed until after semantic
-- analysis is complete. In this fashion complex cross-dependencies
-- between several package declarations and bodies containing generics
-- can be compiled which otherwise would diagnose spurious circularities.
-- For example, it is possible to compile two packages A and B that
-- have the following structure:
-- package A is package B is
-- generic ... generic ...
-- package G_A is package G_B is
-- with B; with A;
-- package body A is package body B is
-- package N_B is new G_B (..) package N_A is new G_A (..)
-- The table Pending_Instantiations in package Inline is used to keep
-- track of body instantiations that are delayed in this manner. Inline
-- handles the actual calls to do the body instantiations. This activity
-- is part of Inline, since the processing occurs at the same point, and
-- for essentially the same reason, as the handling of inlined routines.
----------------------------------------------
-- Detection of Instantiation Circularities --
----------------------------------------------
-- If we have a chain of instantiations that is circular, this is a
-- static error which must be detected at compile time. The detection
-- of these circularities is carried out at the point that we insert
-- a generic instance spec or body. If there is a circularity, then
-- the analysis of the offending spec or body will eventually result
-- in trying to load the same unit again, and we detect this problem
-- as we analyze the package instantiation for the second time.
-- At least in some cases after we have detected the circularity, we
-- get into trouble if we try to keep going. The following flag is
-- set if a circularity is detected, and used to abandon compilation
-- after the messages have been posted.
Circularity_Detected : Boolean := False;
-- This should really be reset on encountering a new main unit, but in
-- practice we are not using multiple main units so it is not critical.
-----------------------
-- Local subprograms --
-----------------------
procedure Abandon_Instantiation (N : Node_Id);
pragma No_Return (Abandon_Instantiation);
-- Posts an error message "instantiation abandoned" at the indicated
-- node and then raises the exception Instantiation_Error to do it.
procedure Analyze_Formal_Array_Type
(T : in out Entity_Id;
Def : Node_Id);
-- A formal array type is treated like an array type declaration, and
-- invokes Array_Type_Declaration (sem_ch3) whose first parameter is
-- in-out, because in the case of an anonymous type the entity is
-- actually created in the procedure.
-- The following procedures treat other kinds of formal parameters
procedure Analyze_Formal_Derived_Interface_Type
(T : Entity_Id;
Def : Node_Id);
procedure Analyze_Formal_Derived_Type
(N : Node_Id;
T : Entity_Id;
Def : Node_Id);
-- The following subprograms create abbreviated declarations for formal
-- scalar types. We introduce an anonymous base of the proper class for
-- each of them, and define the formals as constrained first subtypes of
-- their bases. The bounds are expressions that are non-static in the
-- generic.
procedure Analyze_Formal_Decimal_Fixed_Point_Type
(T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Discrete_Type (T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Floating_Type (T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Interface_Type (T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Signed_Integer_Type (T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Modular_Type (T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Ordinary_Fixed_Point_Type
(T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Private_Type
(N : Node_Id;
T : Entity_Id;
Def : Node_Id);
-- This needs comments???
procedure Analyze_Generic_Formal_Part (N : Node_Id);
procedure Analyze_Generic_Access_Type (T : Entity_Id; Def : Node_Id);
-- This needs comments ???
function Analyze_Associations
(I_Node : Node_Id;
Formals : List_Id;
F_Copy : List_Id) return List_Id;
-- At instantiation time, build the list of associations between formals
-- and actuals. Each association becomes a renaming declaration for the
-- formal entity. F_Copy is the analyzed list of formals in the generic
-- copy. It is used to apply legality checks to the actuals. I_Node is the
-- instantiation node itself.
procedure Analyze_Subprogram_Instantiation
(N : Node_Id;
K : Entity_Kind);
procedure Build_Instance_Compilation_Unit_Nodes
(N : Node_Id;
Act_Body : Node_Id;
Act_Decl : Node_Id);
-- This procedure is used in the case where the generic instance of a
-- subprogram body or package body is a library unit. In this case, the
-- original library unit node for the generic instantiation must be
-- replaced by the resulting generic body, and a link made to a new
-- compilation unit node for the generic declaration. The argument N is
-- the original generic instantiation. Act_Body and Act_Decl are the body
-- and declaration of the instance (either package body and declaration
-- nodes or subprogram body and declaration nodes depending on the case).
-- On return, the node N has been rewritten with the actual body.
procedure Check_Formal_Packages (P_Id : Entity_Id);
-- Apply the following to all formal packages in generic associations
procedure Check_Formal_Package_Instance
(Formal_Pack : Entity_Id;
Actual_Pack : Entity_Id);
-- Verify that the actuals of the actual instance match the actuals of
-- the template for a formal package that is not declared with a box.
procedure Check_Forward_Instantiation (Decl : Node_Id);
-- If the generic is a local entity and the corresponding body has not
-- been seen yet, flag enclosing packages to indicate that it will be
-- elaborated after the generic body. Subprograms declared in the same
-- package cannot be inlined by the front-end because front-end inlining
-- requires a strict linear order of elaboration.
procedure Check_Hidden_Child_Unit
(N : Node_Id;
Gen_Unit : Entity_Id;
Act_Decl_Id : Entity_Id);
-- If the generic unit is an implicit child instance within a parent
-- instance, we need to make an explicit test that it is not hidden by
-- a child instance of the same name and parent.
procedure Check_Private_View (N : Node_Id);
-- Check whether the type of a generic entity has a different view between
-- the point of generic analysis and the point of instantiation. If the
-- view has changed, then at the point of instantiation we restore the
-- correct view to perform semantic analysis of the instance, and reset
-- the current view after instantiation. The processing is driven by the
-- current private status of the type of the node, and Has_Private_View,
-- a flag that is set at the point of generic compilation. If view and
-- flag are inconsistent then the type is updated appropriately.
procedure Check_Generic_Actuals
(Instance : Entity_Id;
Is_Formal_Box : Boolean);
-- Similar to previous one. Check the actuals in the instantiation,
-- whose views can change between the point of instantiation and the point
-- of instantiation of the body. In addition, mark the generic renamings
-- as generic actuals, so that they are not compatible with other actuals.
-- Recurse on an actual that is a formal package whose declaration has
-- a box.
function Contains_Instance_Of
(Inner : Entity_Id;
Outer : Entity_Id;
N : Node_Id) return Boolean;
-- Inner is instantiated within the generic Outer. Check whether Inner
-- directly or indirectly contains an instance of Outer or of one of its
-- parents, in the case of a subunit. Each generic unit holds a list of
-- the entities instantiated within (at any depth). This procedure
-- determines whether the set of such lists contains a cycle, i.e. an
-- illegal circular instantiation.
function Denotes_Formal_Package
(Pack : Entity_Id;
On_Exit : Boolean := False) return Boolean;
-- Returns True if E is a formal package of an enclosing generic, or
-- the actual for such a formal in an enclosing instantiation. If such
-- a package is used as a formal in an nested generic, or as an actual
-- in a nested instantiation, the visibility of ITS formals should not
-- be modified. When called from within Restore_Private_Views, the flag
-- On_Exit is true, to indicate that the search for a possible enclosing
-- instance should ignore the current one.
function Find_Actual_Type
(Typ : Entity_Id;
Gen_Scope : Entity_Id) return Entity_Id;
-- When validating the actual types of a child instance, check whether
-- the formal is a formal type of the parent unit, and retrieve the current
-- actual for it. Typ is the entity in the analyzed formal type declaration
-- (component or index type of an array type) and Gen_Scope is the scope of
-- the analyzed formal array type.
function In_Same_Declarative_Part
(F_Node : Node_Id;
Inst : Node_Id) return Boolean;
-- True if the instantiation Inst and the given freeze_node F_Node appear
-- within the same declarative part, ignoring subunits, but with no inter-
-- vening suprograms or concurrent units. If true, the freeze node
-- of the instance can be placed after the freeze node of the parent,
-- which it itself an instance.
function In_Main_Context (E : Entity_Id) return Boolean;
-- Check whether an instantiation is in the context of the main unit.
-- Used to determine whether its body should be elaborated to allow
-- front-end inlining.
procedure Set_Instance_Env
(Gen_Unit : Entity_Id;
Act_Unit : Entity_Id);
-- Save current instance on saved environment, to be used to determine
-- the global status of entities in nested instances. Part of Save_Env.
-- called after verifying that the generic unit is legal for the instance.
procedure Set_Instance_Of (A : Entity_Id; B : Entity_Id);
-- Associate analyzed generic parameter with corresponding
-- instance. Used for semantic checks at instantiation time.
function Has_Been_Exchanged (E : Entity_Id) return Boolean;
-- Traverse the Exchanged_Views list to see if a type was private
-- and has already been flipped during this phase of instantiation.
procedure Hide_Current_Scope;
-- When compiling a generic child unit, the parent context must be
-- present, but the instance and all entities that may be generated
-- must be inserted in the current scope. We leave the current scope
-- on the stack, but make its entities invisible to avoid visibility
-- problems. This is reversed at the end of instantiations. This is
-- not done for the instantiation of the bodies, which only require the
-- instances of the generic parents to be in scope.
procedure Install_Body
(Act_Body : Node_Id;
N : Node_Id;
Gen_Body : Node_Id;
Gen_Decl : Node_Id);
-- If the instantiation happens textually before the body of the generic,
-- the instantiation of the body must be analyzed after the generic body,
-- and not at the point of instantiation. Such early instantiations can
-- happen if the generic and the instance appear in a package declaration
-- because the generic body can only appear in the corresponding package
-- body. Early instantiations can also appear if generic, instance and
-- body are all in the declarative part of a subprogram or entry. Entities
-- of packages that are early instantiations are delayed, and their freeze
-- node appears after the generic body.
procedure Insert_After_Last_Decl (N : Node_Id; F_Node : Node_Id);
-- Insert freeze node at the end of the declarative part that includes the
-- instance node N. If N is in the visible part of an enclosing package
-- declaration, the freeze node has to be inserted at the end of the
-- private declarations, if any.
procedure Freeze_Subprogram_Body
(Inst_Node : Node_Id;
Gen_Body : Node_Id;
Pack_Id : Entity_Id);
-- The generic body may appear textually after the instance, including
-- in the proper body of a stub, or within a different package instance.
-- Given that the instance can only be elaborated after the generic, we
-- place freeze_nodes for the instance and/or for packages that may enclose
-- the instance and the generic, so that the back-end can establish the
-- proper order of elaboration.
procedure Init_Env;
-- Establish environment for subsequent instantiation. Separated from
-- Save_Env because data-structures for visibility handling must be
-- initialized before call to Check_Generic_Child_Unit.
procedure Install_Parent (P : Entity_Id; In_Body : Boolean := False);
-- When compiling an instance of a child unit the parent (which is
-- itself an instance) is an enclosing scope that must be made
-- immediately visible. This procedure is also used to install the non-
-- generic parent of a generic child unit when compiling its body, so
-- that full views of types in the parent are made visible.
procedure Remove_Parent (In_Body : Boolean := False);
-- Reverse effect after instantiation of child is complete
procedure Inline_Instance_Body
(N : Node_Id;
Gen_Unit : Entity_Id;
Act_Decl : Node_Id);
-- If front-end inlining is requested, instantiate the package body,
-- and preserve the visibility of its compilation unit, to insure
-- that successive instantiations succeed.
-- The functions Instantiate_XXX perform various legality checks and build
-- the declarations for instantiated generic parameters. In all of these
-- Formal is the entity in the generic unit, Actual is the entity of
-- expression in the generic associations, and Analyzed_Formal is the
-- formal in the generic copy, which contains the semantic information to
-- be used to validate the actual.
function Instantiate_Object
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return List_Id;
function Instantiate_Type
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id;
Actual_Decls : List_Id) return Node_Id;
function Instantiate_Formal_Subprogram
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return Node_Id;
function Instantiate_Formal_Package
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return List_Id;
-- If the formal package is declared with a box, special visibility rules
-- apply to its formals: they are in the visible part of the package. This
-- is true in the declarative region of the formal package, that is to say
-- in the enclosing generic or instantiation. For an instantiation, the
-- parameters of the formal package are made visible in an explicit step.
-- Furthermore, if the actual is a visible use_clause, these formals must
-- be made potentially use_visible as well. On exit from the enclosing
-- instantiation, the reverse must be done.
-- For a formal package declared without a box, there are conformance rules
-- that apply to the actuals in the generic declaration and the actuals of
-- the actual package in the enclosing instantiation. The simplest way to
-- apply these rules is to repeat the instantiation of the formal package
-- in the context of the enclosing instance, and compare the generic
-- associations of this instantiation with those of the actual package.
function Is_In_Main_Unit (N : Node_Id) return Boolean;
-- Test if given node is in the main unit
procedure Load_Parent_Of_Generic (N : Node_Id; Spec : Node_Id);
-- If the generic appears in a separate non-generic library unit,
-- load the corresponding body to retrieve the body of the generic.
-- N is the node for the generic instantiation, Spec is the generic
-- package declaration.
procedure Inherit_Context (Gen_Decl : Node_Id; Inst : Node_Id);
-- Add the context clause of the unit containing a generic unit to
-- an instantiation that is a compilation unit.
function Get_Associated_Node (N : Node_Id) return Node_Id;
-- In order to propagate semantic information back from the analyzed
-- copy to the original generic, we maintain links between selected nodes
-- in the generic and their corresponding copies. At the end of generic
-- analysis, the routine Save_Global_References traverses the generic
-- tree, examines the semantic information, and preserves the links to
-- those nodes that contain global information. At instantiation, the
-- information from the associated node is placed on the new copy, so
-- that name resolution is not repeated.
--
-- Three kinds of source nodes have associated nodes:
--
-- a) those that can reference (denote) entities, that is identifiers,
-- character literals, expanded_names, operator symbols, operators,
-- and attribute reference nodes. These nodes have an Entity field
-- and are the set of nodes that are in N_Has_Entity.
--
-- b) aggregates (N_Aggregate and N_Extension_Aggregate)
--
-- c) selected components (N_Selected_Component)
--
-- For the first class, the associated node preserves the entity if it is
-- global. If the generic contains nested instantiations, the associated
-- node itself has been recopied, and a chain of them must be followed.
--
-- For aggregates, the associated node allows retrieval of the type, which
-- may otherwise not appear in the generic. The view of this type may be
-- different between generic and instantiation, and the full view can be
-- installed before the instantiation is analyzed. For aggregates of
-- type extensions, the same view exchange may have to be performed for
-- some of the ancestor types, if their view is private at the point of
-- instantiation.
--
-- Nodes that are selected components in the parse tree may be rewritten
-- as expanded names after resolution, and must be treated as potential
-- entity holders. which is why they also have an Associated_Node.
--
-- Nodes that do not come from source, such as freeze nodes, do not appear
-- in the generic tree, and need not have an associated node.
--
-- The associated node is stored in the Associated_Node field. Note that
-- this field overlaps Entity, which is fine, because the whole point is
-- that we don't need or want the normal Entity field in this situation.
procedure Move_Freeze_Nodes
(Out_Of : Entity_Id;
After : Node_Id;
L : List_Id);
-- Freeze nodes can be generated in the analysis of a generic unit, but
-- will not be seen by the back-end. It is necessary to move those nodes
-- to the enclosing scope if they freeze an outer entity. We place them
-- at the end of the enclosing generic package, which is semantically
-- neutral.
procedure Pre_Analyze_Actuals (N : Node_Id);
-- Analyze actuals to perform name resolution. Full resolution is done
-- later, when the expected types are known, but names have to be captured
-- before installing parents of generics, that are not visible for the
-- actuals themselves.
procedure Valid_Default_Attribute (Nam : Entity_Id; Def : Node_Id);
-- Verify that an attribute that appears as the default for a formal
-- subprogram is a function or procedure with the correct profile.
-------------------------------------------
-- Data Structures for Generic Renamings --
-------------------------------------------
-- The map Generic_Renamings associates generic entities with their
-- corresponding actuals. Currently used to validate type instances.
-- It will eventually be used for all generic parameters to eliminate
-- the need for overload resolution in the instance.
type Assoc_Ptr is new Int;
Assoc_Null : constant Assoc_Ptr := -1;
type Assoc is record
Gen_Id : Entity_Id;
Act_Id : Entity_Id;
Next_In_HTable : Assoc_Ptr;
end record;
package Generic_Renamings is new Table.Table
(Table_Component_Type => Assoc,
Table_Index_Type => Assoc_Ptr,
Table_Low_Bound => 0,
Table_Initial => 10,
Table_Increment => 100,
Table_Name => "Generic_Renamings");
-- Variable to hold enclosing instantiation. When the environment is
-- saved for a subprogram inlining, the corresponding Act_Id is empty.
Current_Instantiated_Parent : Assoc := (Empty, Empty, Assoc_Null);
-- Hash table for associations
HTable_Size : constant := 37;
type HTable_Range is range 0 .. HTable_Size - 1;
procedure Set_Next_Assoc (E : Assoc_Ptr; Next : Assoc_Ptr);
function Next_Assoc (E : Assoc_Ptr) return Assoc_Ptr;
function Get_Gen_Id (E : Assoc_Ptr) return Entity_Id;
function Hash (F : Entity_Id) return HTable_Range;
package Generic_Renamings_HTable is new GNAT.HTable.Static_HTable (
Header_Num => HTable_Range,
Element => Assoc,
Elmt_Ptr => Assoc_Ptr,
Null_Ptr => Assoc_Null,
Set_Next => Set_Next_Assoc,
Next => Next_Assoc,
Key => Entity_Id,
Get_Key => Get_Gen_Id,
Hash => Hash,
Equal => "=");
Exchanged_Views : Elist_Id;
-- This list holds the private views that have been exchanged during
-- instantiation to restore the visibility of the generic declaration.
-- (see comments above). After instantiation, the current visibility is
-- reestablished by means of a traversal of this list.
Hidden_Entities : Elist_Id;
-- This list holds the entities of the current scope that are removed
-- from immediate visibility when instantiating a child unit. Their
-- visibility is restored in Remove_Parent.
-- Because instantiations can be recursive, the following must be saved
-- on entry and restored on exit from an instantiation (spec or body).
-- This is done by the two procedures Save_Env and Restore_Env. For
-- package and subprogram instantiations (but not for the body instances)
-- the action of Save_Env is done in two steps: Init_Env is called before
-- Check_Generic_Child_Unit, because setting the parent instances requires
-- that the visibility data structures be properly initialized. Once the
-- generic is unit is validated, Set_Instance_Env completes Save_Env.
Parent_Unit_Visible : Boolean := False;
-- Parent_Unit_Visible is used when the generic is a child unit, and
-- indicates whether the ultimate parent of the generic is visible in the
-- instantiation environment. It is used to reset the visibility of the
-- parent at the end of the instantiation (see Remove_Parent).
Instance_Parent_Unit : Entity_Id := Empty;
-- This records the ultimate parent unit of an instance of a generic
-- child unit and is used in conjunction with Parent_Unit_Visible to
-- indicate the unit to which the Parent_Unit_Visible flag corresponds.
type Instance_Env is record
Ada_Version : Ada_Version_Type;
Ada_Version_Explicit : Ada_Version_Type;
Instantiated_Parent : Assoc;
Exchanged_Views : Elist_Id;
Hidden_Entities : Elist_Id;
Current_Sem_Unit : Unit_Number_Type;
Parent_Unit_Visible : Boolean := False;
Instance_Parent_Unit : Entity_Id := Empty;
end record;
package Instance_Envs is new Table.Table (
Table_Component_Type => Instance_Env,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => 32,
Table_Increment => 100,
Table_Name => "Instance_Envs");
procedure Restore_Private_Views
(Pack_Id : Entity_Id;
Is_Package : Boolean := True);
-- Restore the private views of external types, and unmark the generic
-- renamings of actuals, so that they become comptible subtypes again.
-- For subprograms, Pack_Id is the package constructed to hold the
-- renamings.
procedure Switch_View (T : Entity_Id);
-- Switch the partial and full views of a type and its private
-- dependents (i.e. its subtypes and derived types).
------------------------------------
-- Structures for Error Reporting --
------------------------------------
Instantiation_Node : Node_Id;
-- Used by subprograms that validate instantiation of formal parameters
-- where there might be no actual on which to place the error message.
-- Also used to locate the instantiation node for generic subunits.
Instantiation_Error : exception;
-- When there is a semantic error in the generic parameter matching,
-- there is no point in continuing the instantiation, because the
-- number of cascaded errors is unpredictable. This exception aborts
-- the instantiation process altogether.
S_Adjustment : Sloc_Adjustment;
-- Offset created for each node in an instantiation, in order to keep
-- track of the source position of the instantiation in each of its nodes.
-- A subsequent semantic error or warning on a construct of the instance
-- points to both places: the original generic node, and the point of
-- instantiation. See Sinput and Sinput.L for additional details.
------------------------------------------------------------
-- Data structure for keeping track when inside a Generic --
------------------------------------------------------------
-- The following table is used to save values of the Inside_A_Generic
-- flag (see spec of Sem) when they are saved by Start_Generic.
package Generic_Flags is new Table.Table (
Table_Component_Type => Boolean,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => 32,
Table_Increment => 200,
Table_Name => "Generic_Flags");
---------------------------
-- Abandon_Instantiation --
---------------------------
procedure Abandon_Instantiation (N : Node_Id) is
begin
Error_Msg_N ("instantiation abandoned!", N);
raise Instantiation_Error;
end Abandon_Instantiation;
--------------------------
-- Analyze_Associations --
--------------------------
function Analyze_Associations
(I_Node : Node_Id;
Formals : List_Id;
F_Copy : List_Id) return List_Id
is
Actual_Types : constant Elist_Id := New_Elmt_List;
Assoc : constant List_Id := New_List;
Defaults : constant Elist_Id := New_Elmt_List;
Gen_Unit : constant Entity_Id := Defining_Entity (Parent (F_Copy));
Actuals : List_Id;
Actual : Node_Id;
Formal : Node_Id;
Next_Formal : Node_Id;
Temp_Formal : Node_Id;
Analyzed_Formal : Node_Id;
Match : Node_Id;
Named : Node_Id;
First_Named : Node_Id := Empty;
Found_Assoc : Node_Id;
Is_Named_Assoc : Boolean;
Num_Matched : Int := 0;
Num_Actuals : Int := 0;
function Matching_Actual
(F : Entity_Id;
A_F : Entity_Id) return Node_Id;
-- Find actual that corresponds to a given a formal parameter. If the
-- actuals are positional, return the next one, if any. If the actuals
-- are named, scan the parameter associations to find the right one.
-- A_F is the corresponding entity in the analyzed generic,which is
-- placed on the selector name for ASIS use.
procedure Set_Analyzed_Formal;
-- Find the node in the generic copy that corresponds to a given formal.
-- The semantic information on this node is used to perform legality
-- checks on the actuals. Because semantic analysis can introduce some
-- anonymous entities or modify the declaration node itself, the
-- correspondence between the two lists is not one-one. In addition to
-- anonymous types, the presence a formal equality will introduce an
-- implicit declaration for the corresponding inequality.
---------------------
-- Matching_Actual --
---------------------
function Matching_Actual
(F : Entity_Id;
A_F : Entity_Id) return Node_Id
is
Found : Node_Id;
Prev : Node_Id;
begin
Is_Named_Assoc := False;
-- End of list of purely positional parameters
if No (Actual) then
Found := Empty;
-- Case of positional parameter corresponding to current formal
elsif No (Selector_Name (Actual)) then
Found := Explicit_Generic_Actual_Parameter (Actual);
Found_Assoc := Actual;
Num_Matched := Num_Matched + 1;
Next (Actual);
-- Otherwise scan list of named actuals to find the one with the
-- desired name. All remaining actuals have explicit names.
else
Is_Named_Assoc := True;
Found := Empty;
Prev := Empty;
while Present (Actual) loop
if Chars (Selector_Name (Actual)) = Chars (F) then
Found := Explicit_Generic_Actual_Parameter (Actual);
Set_Entity (Selector_Name (Actual), A_F);
Set_Etype (Selector_Name (Actual), Etype (A_F));
Generate_Reference (A_F, Selector_Name (Actual));
Found_Assoc := Actual;
Num_Matched := Num_Matched + 1;
exit;
end if;
Prev := Actual;
Next (Actual);
end loop;
-- Reset for subsequent searches. In most cases the named
-- associations are in order. If they are not, we reorder them
-- to avoid scanning twice the same actual. This is not just a
-- question of efficiency: there may be multiple defaults with
-- boxes that have the same name. In a nested instantiation we
-- insert actuals for those defaults, and cannot rely on their
-- names to disambiguate them.
if Actual = First_Named then
Next (First_Named);
elsif Present (Actual) then
Insert_Before (First_Named, Remove_Next (Prev));
end if;
Actual := First_Named;
end if;
return Found;
end Matching_Actual;
-------------------------
-- Set_Analyzed_Formal --
-------------------------
procedure Set_Analyzed_Formal is
Kind : Node_Kind;
begin
while Present (Analyzed_Formal) loop
Kind := Nkind (Analyzed_Formal);
case Nkind (Formal) is
when N_Formal_Subprogram_Declaration =>
exit when Kind in N_Formal_Subprogram_Declaration
and then
Chars
(Defining_Unit_Name (Specification (Formal))) =
Chars
(Defining_Unit_Name (Specification (Analyzed_Formal)));
when N_Formal_Package_Declaration =>
exit when
Kind = N_Formal_Package_Declaration
or else
Kind = N_Generic_Package_Declaration;
when N_Use_Package_Clause | N_Use_Type_Clause => exit;
when others =>
-- Skip freeze nodes, and nodes inserted to replace
-- unrecognized pragmas.
exit when
Kind not in N_Formal_Subprogram_Declaration
and then Kind /= N_Subprogram_Declaration
and then Kind /= N_Freeze_Entity
and then Kind /= N_Null_Statement
and then Kind /= N_Itype_Reference
and then Chars (Defining_Identifier (Formal)) =
Chars (Defining_Identifier (Analyzed_Formal));
end case;
Next (Analyzed_Formal);
end loop;
end Set_Analyzed_Formal;
-- Start of processing for Analyze_Associations
begin
-- If named associations are present, save the first named association
-- (it may of course be Empty) to facilitate subsequent name search.
Actuals := Generic_Associations (I_Node);
if Present (Actuals) then
First_Named := First (Actuals);
while Present (First_Named)
and then No (Selector_Name (First_Named))
loop
Num_Actuals := Num_Actuals + 1;
Next (First_Named);
end loop;
end if;
Named := First_Named;
while Present (Named) loop
if No (Selector_Name (Named)) then
Error_Msg_N ("invalid positional actual after named one", Named);
Abandon_Instantiation (Named);
end if;
-- A named association may lack an actual parameter, if it was
-- introduced for a default subprogram that turns out to be local
-- to the outer instantiation.
if Present (Explicit_Generic_Actual_Parameter (Named)) then
Num_Actuals := Num_Actuals + 1;
end if;
Next (Named);
end loop;
if Present (Formals) then
Formal := First_Non_Pragma (Formals);
Analyzed_Formal := First_Non_Pragma (F_Copy);
if Present (Actuals) then
Actual := First (Actuals);
-- All formals should have default values
else
Actual := Empty;
end if;
while Present (Formal) loop
Set_Analyzed_Formal;
Next_Formal := Next_Non_Pragma (Formal);
case Nkind (Formal) is
when N_Formal_Object_Declaration =>
Match :=
Matching_Actual (
Defining_Identifier (Formal),
Defining_Identifier (Analyzed_Formal));
Append_List
(Instantiate_Object (Formal, Match, Analyzed_Formal),
Assoc);
when N_Formal_Type_Declaration =>
Match :=
Matching_Actual (
Defining_Identifier (Formal),
Defining_Identifier (Analyzed_Formal));
if No (Match) then
Error_Msg_Sloc := Sloc (Gen_Unit);
Error_Msg_NE
("missing actual&",
Instantiation_Node, Defining_Identifier (Formal));
Error_Msg_NE ("\in instantiation of & declared#",
Instantiation_Node, Gen_Unit);
Abandon_Instantiation (Instantiation_Node);
else
Analyze (Match);
Append_To (Assoc,
Instantiate_Type
(Formal, Match, Analyzed_Formal, Assoc));
-- An instantiation is a freeze point for the actuals,
-- unless this is a rewritten formal package.
if Nkind (I_Node) /= N_Formal_Package_Declaration then
Append_Elmt (Entity (Match), Actual_Types);
end if;
end if;
-- A remote access-to-class-wide type must not be an
-- actual parameter for a generic formal of an access
-- type (E.2.2 (17)).
if Nkind (Analyzed_Formal) = N_Formal_Type_Declaration
and then
Nkind (Formal_Type_Definition (Analyzed_Formal)) =
N_Access_To_Object_Definition
then
Validate_Remote_Access_To_Class_Wide_Type (Match);
end if;
when N_Formal_Subprogram_Declaration =>
Match :=
Matching_Actual (
Defining_Unit_Name (Specification (Formal)),
Defining_Unit_Name (Specification (Analyzed_Formal)));
-- If the formal subprogram has the same name as
-- another formal subprogram of the generic, then
-- a named association is illegal (12.3(9)). Exclude
-- named associations that are generated for a nested
-- instance.
if Present (Match)
and then Is_Named_Assoc
and then Comes_From_Source (Found_Assoc)
then
Temp_Formal := First (Formals);
while Present (Temp_Formal) loop
if Nkind (Temp_Formal) in
N_Formal_Subprogram_Declaration
and then Temp_Formal /= Formal
and then
Chars (Selector_Name (Found_Assoc)) =
Chars (Defining_Unit_Name
(Specification (Temp_Formal)))
then
Error_Msg_N
("name not allowed for overloaded formal",
Found_Assoc);
Abandon_Instantiation (Instantiation_Node);
end if;
Next (Temp_Formal);
end loop;
end if;
Append_To (Assoc,
Instantiate_Formal_Subprogram
(Formal, Match, Analyzed_Formal));
if No (Match)
and then Box_Present (Formal)
then
Append_Elmt
(Defining_Unit_Name (Specification (Last (Assoc))),
Defaults);
end if;
when N_Formal_Package_Declaration =>
Match :=
Matching_Actual (
Defining_Identifier (Formal),
Defining_Identifier (Original_Node (Analyzed_Formal)));
if No (Match) then
Error_Msg_Sloc := Sloc (Gen_Unit);
Error_Msg_NE
("missing actual&",
Instantiation_Node, Defining_Identifier (Formal));
Error_Msg_NE ("\in instantiation of & declared#",
Instantiation_Node, Gen_Unit);
Abandon_Instantiation (Instantiation_Node);
else
Analyze (Match);
Append_List
(Instantiate_Formal_Package
(Formal, Match, Analyzed_Formal),
Assoc);
end if;
-- For use type and use package appearing in the context
-- clause, we have already copied them, so we can just
-- move them where they belong (we mustn't recopy them
-- since this would mess up the Sloc values).
when N_Use_Package_Clause |
N_Use_Type_Clause =>
Remove (Formal);
Append (Formal, Assoc);
when others =>
raise Program_Error;
end case;
Formal := Next_Formal;
Next_Non_Pragma (Analyzed_Formal);
end loop;
if Num_Actuals > Num_Matched then
Error_Msg_Sloc := Sloc (Gen_Unit);
if Present (Selector_Name (Actual)) then
Error_Msg_NE
("unmatched actual&",
Actual, Selector_Name (Actual));
Error_Msg_NE ("\in instantiation of& declared#",
Actual, Gen_Unit);
else
Error_Msg_NE
("unmatched actual in instantiation of& declared#",
Actual, Gen_Unit);
end if;
end if;
elsif Present (Actuals) then
Error_Msg_N
("too many actuals in generic instantiation", Instantiation_Node);
end if;
declare
Elmt : Elmt_Id := First_Elmt (Actual_Types);
begin
while Present (Elmt) loop
Freeze_Before (I_Node, Node (Elmt));
Next_Elmt (Elmt);
end loop;
end;
-- If there are default subprograms, normalize the tree by adding
-- explicit associations for them. This is required if the instance
-- appears within a generic.
declare
Elmt : Elmt_Id;
Subp : Entity_Id;
New_D : Node_Id;
begin
Elmt := First_Elmt (Defaults);
while Present (Elmt) loop
if No (Actuals) then
Actuals := New_List;
Set_Generic_Associations (I_Node, Actuals);
end if;
Subp := Node (Elmt);
New_D :=
Make_Generic_Association (Sloc (Subp),
Selector_Name => New_Occurrence_Of (Subp, Sloc (Subp)),
Explicit_Generic_Actual_Parameter =>
New_Occurrence_Of (Subp, Sloc (Subp)));
Mark_Rewrite_Insertion (New_D);
Append_To (Actuals, New_D);
Next_Elmt (Elmt);
end loop;
end;
return Assoc;
end Analyze_Associations;
-------------------------------
-- Analyze_Formal_Array_Type --
-------------------------------
procedure Analyze_Formal_Array_Type
(T : in out Entity_Id;
Def : Node_Id)
is
DSS : Node_Id;
begin
-- Treated like a non-generic array declaration, with
-- additional semantic checks.
Enter_Name (T);
if Nkind (Def) = N_Constrained_Array_Definition then
DSS := First (Discrete_Subtype_Definitions (Def));
while Present (DSS) loop
if Nkind (DSS) = N_Subtype_Indication
or else Nkind (DSS) = N_Range
or else Nkind (DSS) = N_Attribute_Reference
then
Error_Msg_N ("only a subtype mark is allowed in a formal", DSS);
end if;
Next (DSS);
end loop;
end if;
Array_Type_Declaration (T, Def);
Set_Is_Generic_Type (Base_Type (T));
if Ekind (Component_Type (T)) = E_Incomplete_Type
and then No (Full_View (Component_Type (T)))
then
Error_Msg_N ("premature usage of incomplete type", Def);
-- Check that range constraint is not allowed on the component type
-- of a generic formal array type (AARM 12.5.3(3))
elsif Is_Internal (Component_Type (T))
and then Present (Subtype_Indication (Component_Definition (Def)))
and then Nkind (Original_Node
(Subtype_Indication (Component_Definition (Def))))
= N_Subtype_Indication
then
Error_Msg_N
("in a formal, a subtype indication can only be "
& "a subtype mark ('R'M 12.5.3(3))",
Subtype_Indication (Component_Definition (Def)));
end if;
end Analyze_Formal_Array_Type;
---------------------------------------------
-- Analyze_Formal_Decimal_Fixed_Point_Type --
---------------------------------------------
-- As for other generic types, we create a valid type representation
-- with legal but arbitrary attributes, whose values are never considered
-- static. For all scalar types we introduce an anonymous base type, with
-- the same attributes. We choose the corresponding integer type to be
-- Standard_Integer.
procedure Analyze_Formal_Decimal_Fixed_Point_Type
(T : Entity_Id;
Def : Node_Id)
is
Loc : constant Source_Ptr := Sloc (Def);
Base : constant Entity_Id :=
New_Internal_Entity
(E_Decimal_Fixed_Point_Type,
Current_Scope, Sloc (Def), 'G');
Int_Base : constant Entity_Id := Standard_Integer;
Delta_Val : constant Ureal := Ureal_1;
Digs_Val : constant Uint := Uint_6;
begin
Enter_Name (T);
Set_Etype (Base, Base);
Set_Size_Info (Base, Int_Base);
Set_RM_Size (Base, RM_Size (Int_Base));
Set_First_Rep_Item (Base, First_Rep_Item (Int_Base));
Set_Digits_Value (Base, Digs_Val);
Set_Delta_Value (Base, Delta_Val);
Set_Small_Value (Base, Delta_Val);
Set_Scalar_Range (Base,
Make_Range (Loc,
Low_Bound => Make_Real_Literal (Loc, Ureal_1),
High_Bound => Make_Real_Literal (Loc, Ureal_1)));
Set_Is_Generic_Type (Base);
Set_Parent (Base, Parent (Def));
Set_Ekind (T, E_Decimal_Fixed_Point_Subtype);
Set_Etype (T, Base);
Set_Size_Info (T, Int_Base);
Set_RM_Size (T, RM_Size (Int_Base));
Set_First_Rep_Item (T, First_Rep_Item (Int_Base));
Set_Digits_Value (T, Digs_Val);
Set_Delta_Value (T, Delta_Val);
Set_Small_Value (T, Delta_Val);
Set_Scalar_Range (T, Scalar_Range (Base));
Set_Is_Constrained (T);
Check_Restriction (No_Fixed_Point, Def);
end Analyze_Formal_Decimal_Fixed_Point_Type;
-------------------------------------------
-- Analyze_Formal_Derived_Interface_Type --
-------------------------------------------
procedure Analyze_Formal_Derived_Interface_Type
(T : Entity_Id;
Def : Node_Id)
is
begin
Enter_Name (T);
Set_Ekind (T, E_Record_Type);
Set_Etype (T, T);
Analyze (Subtype_Indication (Def));
Analyze_Interface_Declaration (T, Def);
Make_Class_Wide_Type (T);
Set_Primitive_Operations (T, New_Elmt_List);
Analyze_List (Interface_List (Def));
Collect_Interfaces (Def, T);
end Analyze_Formal_Derived_Interface_Type;
---------------------------------
-- Analyze_Formal_Derived_Type --
---------------------------------
procedure Analyze_Formal_Derived_Type
(N : Node_Id;
T : Entity_Id;
Def : Node_Id)
is
Loc : constant Source_Ptr := Sloc (Def);
Unk_Disc : constant Boolean := Unknown_Discriminants_Present (N);
New_N : Node_Id;
begin
Set_Is_Generic_Type (T);
if Private_Present (Def) then
New_N :=
Make_Private_Extension_Declaration (Loc,
Defining_Identifier => T,
Discriminant_Specifications => Discriminant_Specifications (N),
Unknown_Discriminants_Present => Unk_Disc,
Subtype_Indication => Subtype_Mark (Def));
Set_Abstract_Present (New_N, Abstract_Present (Def));
Set_Limited_Present (New_N, Limited_Present (Def));
else
New_N :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => T,
Discriminant_Specifications =>
Discriminant_Specifications (Parent (T)),
Type_Definition =>
Make_Derived_Type_Definition (Loc,
Subtype_Indication => Subtype_Mark (Def)));
Set_Abstract_Present
(Type_Definition (New_N), Abstract_Present (Def));
Set_Limited_Present
(Type_Definition (New_N), Limited_Present (Def));
end if;
Rewrite (N, New_N);
Analyze (N);
if Unk_Disc then
if not Is_Composite_Type (T) then
Error_Msg_N
("unknown discriminants not allowed for elementary types", N);
else
Set_Has_Unknown_Discriminants (T);
Set_Is_Constrained (T, False);
end if;
end if;
-- If the parent type has a known size, so does the formal, which
-- makes legal representation clauses that involve the formal.
Set_Size_Known_At_Compile_Time
(T, Size_Known_At_Compile_Time (Entity (Subtype_Mark (Def))));
end Analyze_Formal_Derived_Type;
----------------------------------
-- Analyze_Formal_Discrete_Type --
----------------------------------
-- The operations defined for a discrete types are those of an
-- enumeration type. The size is set to an arbitrary value, for use
-- in analyzing the generic unit.
procedure Analyze_Formal_Discrete_Type (T : Entity_Id; Def : Node_Id) is
Loc : constant Source_Ptr := Sloc (Def);
Lo : Node_Id;
Hi : Node_Id;
Base : constant Entity_Id :=
New_Internal_Entity
(E_Floating_Point_Type, Current_Scope, Sloc (Def), 'G');
begin
Enter_Name (T);
Set_Ekind (T, E_Enumeration_Subtype);
Set_Etype (T, Base);
Init_Size (T, 8);
Init_Alignment (T);
Set_Is_Generic_Type (T);
Set_Is_Constrained (T);
-- For semantic analysis, the bounds of the type must be set to some
-- non-static value. The simplest is to create attribute nodes for
-- those bounds, that refer to the type itself. These bounds are never
-- analyzed but serve as place-holders.
Lo :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_First,
Prefix => New_Reference_To (T, Loc));
Set_Etype (Lo, T);
Hi :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Last,
Prefix => New_Reference_To (T, Loc));
Set_Etype (Hi, T);
Set_Scalar_Range (T,
Make_Range (Loc,
Low_Bound => Lo,
High_Bound => Hi));
Set_Ekind (Base, E_Enumeration_Type);
Set_Etype (Base, Base);
Init_Size (Base, 8);
Init_Alignment (Base);
Set_Is_Generic_Type (Base);
Set_Scalar_Range (Base, Scalar_Range (T));
Set_Parent (Base, Parent (Def));
end Analyze_Formal_Discrete_Type;
----------------------------------
-- Analyze_Formal_Floating_Type --
---------------------------------
procedure Analyze_Formal_Floating_Type (T : Entity_Id; Def : Node_Id) is
Base : constant Entity_Id :=
New_Internal_Entity
(E_Floating_Point_Type, Current_Scope, Sloc (Def), 'G');
begin
-- The various semantic attributes are taken from the predefined type
-- Float, just so that all of them are initialized. Their values are
-- never used because no constant folding or expansion takes place in
-- the generic itself.
Enter_Name (T);
Set_Ekind (T, E_Floating_Point_Subtype);
Set_Etype (T, Base);
Set_Size_Info (T, (Standard_Float));
Set_RM_Size (T, RM_Size (Standard_Float));
Set_Digits_Value (T, Digits_Value (Standard_Float));
Set_Scalar_Range (T, Scalar_Range (Standard_Float));
Set_Is_Constrained (T);
Set_Is_Generic_Type (Base);
Set_Etype (Base, Base);
Set_Size_Info (Base, (Standard_Float));
Set_RM_Size (Base, RM_Size (Standard_Float));
Set_Digits_Value (Base, Digits_Value (Standard_Float));
Set_Scalar_Range (Base, Scalar_Range (Standard_Float));
Set_Parent (Base, Parent (Def));
Check_Restriction (No_Floating_Point, Def);
end Analyze_Formal_Floating_Type;
-----------------------------------
-- Analyze_Formal_Interface_Type;--
-----------------------------------
procedure Analyze_Formal_Interface_Type (T : Entity_Id; Def : Node_Id) is
begin
Enter_Name (T);
Set_Ekind (T, E_Record_Type);
Set_Etype (T, T);
Analyze_Interface_Declaration (T, Def);
Make_Class_Wide_Type (T);
Set_Primitive_Operations (T, New_Elmt_List);
end Analyze_Formal_Interface_Type;
---------------------------------
-- Analyze_Formal_Modular_Type --
---------------------------------
procedure Analyze_Formal_Modular_Type (T : Entity_Id; Def : Node_Id) is
begin
-- Apart from their entity kind, generic modular types are treated
-- like signed integer types, and have the same attributes.
Analyze_Formal_Signed_Integer_Type (T, Def);
Set_Ekind (T, E_Modular_Integer_Subtype);
Set_Ekind (Etype (T), E_Modular_Integer_Type);
end Analyze_Formal_Modular_Type;
---------------------------------------
-- Analyze_Formal_Object_Declaration --
---------------------------------------
procedure Analyze_Formal_Object_Declaration (N : Node_Id) is
E : constant Node_Id := Expression (N);
Id : constant Node_Id := Defining_Identifier (N);
K : Entity_Kind;
T : Node_Id;
begin
Enter_Name (Id);
-- Determine the mode of the formal object
if Out_Present (N) then
K := E_Generic_In_Out_Parameter;
if not In_Present (N) then
Error_Msg_N ("formal generic objects cannot have mode OUT", N);
end if;
else
K := E_Generic_In_Parameter;
end if;
Find_Type (Subtype_Mark (N));
T := Entity (Subtype_Mark (N));
if Ekind (T) = E_Incomplete_Type then
Error_Msg_N ("premature usage of incomplete type", Subtype_Mark (N));
end if;
if K = E_Generic_In_Parameter then
-- Ada 2005 (AI-287): Limited aggregates allowed in generic formals
if Ada_Version < Ada_05 and then Is_Limited_Type (T) then
Error_Msg_N
("generic formal of mode IN must not be of limited type", N);
Explain_Limited_Type (T, N);
end if;
if Is_Abstract (T) then
Error_Msg_N
("generic formal of mode IN must not be of abstract type", N);
end if;
if Present (E) then
Analyze_Per_Use_Expression (E, T);
end if;
Set_Ekind (Id, K);
Set_Etype (Id, T);
-- Case of generic IN OUT parameter
else
-- If the formal has an unconstrained type, construct its
-- actual subtype, as is done for subprogram formals. In this
-- fashion, all its uses can refer to specific bounds.
Set_Ekind (Id, K);
Set_Etype (Id, T);
if (Is_Array_Type (T)
and then not Is_Constrained (T))
or else
(Ekind (T) = E_Record_Type
and then Has_Discriminants (T))
then
declare
Non_Freezing_Ref : constant Node_Id :=
New_Reference_To (Id, Sloc (Id));
Decl : Node_Id;
begin
-- Make sure that the actual subtype doesn't generate
-- bogus freezing.
Set_Must_Not_Freeze (Non_Freezing_Ref);
Decl := Build_Actual_Subtype (T, Non_Freezing_Ref);
Insert_Before_And_Analyze (N, Decl);
Set_Actual_Subtype (Id, Defining_Identifier (Decl));
end;
else
Set_Actual_Subtype (Id, T);
end if;
if Present (E) then
Error_Msg_N
("initialization not allowed for `IN OUT` formals", N);
end if;
end if;
end Analyze_Formal_Object_Declaration;
----------------------------------------------
-- Analyze_Formal_Ordinary_Fixed_Point_Type --
----------------------------------------------
procedure Analyze_Formal_Ordinary_Fixed_Point_Type
(T : Entity_Id;
Def : Node_Id)
is
Loc : constant Source_Ptr := Sloc (Def);
Base : constant Entity_Id :=
New_Internal_Entity
(E_Ordinary_Fixed_Point_Type, Current_Scope, Sloc (Def), 'G');
begin
-- The semantic attributes are set for completeness only, their
-- values will never be used, because all properties of the type
-- are non-static.
Enter_Name (T);
Set_Ekind (T, E_Ordinary_Fixed_Point_Subtype);
Set_Etype (T, Base);
Set_Size_Info (T, Standard_Integer);
Set_RM_Size (T, RM_Size (Standard_Integer));
Set_Small_Value (T, Ureal_1);
Set_Delta_Value (T, Ureal_1);
Set_Scalar_Range (T,
Make_Range (Loc,
Low_Bound => Make_Real_Literal (Loc, Ureal_1),
High_Bound => Make_Real_Literal (Loc, Ureal_1)));
Set_Is_Constrained (T);
Set_Is_Generic_Type (Base);
Set_Etype (Base, Base);
Set_Size_Info (Base, Standard_Integer);
Set_RM_Size (Base, RM_Size (Standard_Integer));
Set_Small_Value (Base, Ureal_1);
Set_Delta_Value (Base, Ureal_1);
Set_Scalar_Range (Base, Scalar_Range (T));
Set_Parent (Base, Parent (Def));
Check_Restriction (No_Fixed_Point, Def);
end Analyze_Formal_Ordinary_Fixed_Point_Type;
----------------------------
-- Analyze_Formal_Package --
----------------------------
procedure Analyze_Formal_Package (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Pack_Id : constant Entity_Id := Defining_Identifier (N);
Formal : Entity_Id;
Gen_Id : constant Node_Id := Name (N);
Gen_Decl : Node_Id;
Gen_Unit : Entity_Id;
New_N : Node_Id;
Parent_Installed : Boolean := False;
Renaming : Node_Id;
Parent_Instance : Entity_Id;
Renaming_In_Par : Entity_Id;
begin
Text_IO_Kludge (Gen_Id);
Init_Env;
Check_Generic_Child_Unit (Gen_Id, Parent_Installed);
Gen_Unit := Entity (Gen_Id);
-- Check for a formal package that is a package renaming
if Present (Renamed_Object (Gen_Unit)) then
Gen_Unit := Renamed_Object (Gen_Unit);
end if;
if Ekind (Gen_Unit) /= E_Generic_Package then
Error_Msg_N ("expect generic package name", Gen_Id);
Restore_Env;
return;
elsif Gen_Unit = Current_Scope then
Error_Msg_N
("generic package cannot be used as a formal package of itself",
Gen_Id);
Restore_Env;
return;
elsif In_Open_Scopes (Gen_Unit) then
if Is_Compilation_Unit (Gen_Unit)
and then Is_Child_Unit (Current_Scope)
then
-- Special-case the error when the formal is a parent, and
-- continue analysis to minimize cascaded errors.
Error_Msg_N
("generic parent cannot be used as formal package "
& "of a child unit",
Gen_Id);
else
Error_Msg_N
("generic package cannot be used as a formal package "
& "within itself",
Gen_Id);
Restore_Env;
return;
end if;
end if;
-- The formal package is treated like a regular instance, but only
-- the specification needs to be instantiated, to make entities visible.
if not Box_Present (N) then
Hidden_Entities := New_Elmt_List;
Analyze_Package_Instantiation (N);
if Parent_Installed then
Remove_Parent;
end if;
else
-- If there are no generic associations, the generic parameters
-- appear as local entities and are instantiated like them. We copy
-- the generic package declaration as if it were an instantiation,
-- and analyze it like a regular package, except that we treat the
-- formals as additional visible components.
Gen_Decl := Unit_Declaration_Node (Gen_Unit);
if In_Extended_Main_Source_Unit (N) then
Set_Is_Instantiated (Gen_Unit);
Generate_Reference (Gen_Unit, N);
end if;
Formal := New_Copy (Pack_Id);
Create_Instantiation_Source (N, Gen_Unit, False, S_Adjustment);
New_N :=
Copy_Generic_Node
(Original_Node (Gen_Decl), Empty, Instantiating => True);
Rewrite (N, New_N);
Set_Defining_Unit_Name (Specification (New_N), Formal);
Set_Generic_Parent (Specification (N), Gen_Unit);
Set_Instance_Env (Gen_Unit, Formal);
Enter_Name (Formal);
Set_Ekind (Formal, E_Generic_Package);
Set_Etype (Formal, Standard_Void_Type);
Set_Inner_Instances (Formal, New_Elmt_List);
New_Scope (Formal);
-- Within the formal, the name of the generic package is a renaming
-- of the formal (as for a regular instantiation).
Renaming := Make_Package_Renaming_Declaration (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc, Chars (Gen_Unit)),
Name => New_Reference_To (Formal, Loc));
if Present (Visible_Declarations (Specification (N))) then
Prepend (Renaming, To => Visible_Declarations (Specification (N)));
elsif Present (Private_Declarations (Specification (N))) then
Prepend (Renaming, To => Private_Declarations (Specification (N)));
end if;
if Is_Child_Unit (Gen_Unit)
and then Parent_Installed
then
-- Similarly, we have to make the name of the formal visible in
-- the parent instance, to resolve properly fully qualified names
-- that may appear in the generic unit. The parent instance has
-- been placed on the scope stack ahead of the current scope.
Parent_Instance := Scope_Stack.Table (Scope_Stack.Last - 1).Entity;
Renaming_In_Par :=
Make_Defining_Identifier (Loc, Chars (Gen_Unit));
Set_Ekind (Renaming_In_Par, E_Package);
Set_Etype (Renaming_In_Par, Standard_Void_Type);
Set_Scope (Renaming_In_Par, Parent_Instance);
Set_Parent (Renaming_In_Par, Parent (Formal));
Set_Renamed_Object (Renaming_In_Par, Formal);
Append_Entity (Renaming_In_Par, Parent_Instance);
end if;
Analyze_Generic_Formal_Part (N);
Analyze (Specification (N));
End_Package_Scope (Formal);
if Parent_Installed then
Remove_Parent;
end if;
Restore_Env;
-- Inside the generic unit, the formal package is a regular
-- package, but no body is needed for it. Note that after
-- instantiation, the defining_unit_name we need is in the
-- new tree and not in the original. (see Package_Instantiation).
-- A generic formal package is an instance, and can be used as
-- an actual for an inner instance.
Set_Ekind (Formal, E_Package);
Set_Has_Completion (Formal, True);
Set_Ekind (Pack_Id, E_Package);
Set_Etype (Pack_Id, Standard_Void_Type);
Set_Scope (Pack_Id, Scope (Formal));
Set_Has_Completion (Pack_Id, True);
end if;
end Analyze_Formal_Package;
---------------------------------
-- Analyze_Formal_Private_Type --
---------------------------------
procedure Analyze_Formal_Private_Type
(N : Node_Id;
T : Entity_Id;
Def : Node_Id)
is
begin
New_Private_Type (N, T, Def);
-- Set the size to an arbitrary but legal value
Set_Size_Info (T, Standard_Integer);
Set_RM_Size (T, RM_Size (Standard_Integer));
end Analyze_Formal_Private_Type;
----------------------------------------
-- Analyze_Formal_Signed_Integer_Type --
----------------------------------------
procedure Analyze_Formal_Signed_Integer_Type
(T : Entity_Id;
Def : Node_Id)
is
Base : constant Entity_Id :=
New_Internal_Entity
(E_Signed_Integer_Type, Current_Scope, Sloc (Def), 'G');
begin
Enter_Name (T);
Set_Ekind (T, E_Signed_Integer_Subtype);
Set_Etype (T, Base);
Set_Size_Info (T, Standard_Integer);
Set_RM_Size (T, RM_Size (Standard_Integer));
Set_Scalar_Range (T, Scalar_Range (Standard_Integer));
Set_Is_Constrained (T);
Set_Is_Generic_Type (Base);
Set_Size_Info (Base, Standard_Integer);
Set_RM_Size (Base, RM_Size (Standard_Integer));
Set_Etype (Base, Base);
Set_Scalar_Range (Base, Scalar_Range (Standard_Integer));
Set_Parent (Base, Parent (Def));
end Analyze_Formal_Signed_Integer_Type;
-------------------------------
-- Analyze_Formal_Subprogram --
-------------------------------
procedure Analyze_Formal_Subprogram (N : Node_Id) is
Spec : constant Node_Id := Specification (N);
Def : constant Node_Id := Default_Name (N);
Nam : constant Entity_Id := Defining_Unit_Name (Spec);
Subp : Entity_Id;
begin
if Nam = Error then
return;
end if;
if Nkind (Nam) = N_Defining_Program_Unit_Name then
Error_Msg_N ("name of formal subprogram must be a direct name", Nam);
return;
end if;
Analyze_Subprogram_Declaration (N);
Set_Is_Formal_Subprogram (Nam);
Set_Has_Completion (Nam);
if Nkind (N) = N_Formal_Abstract_Subprogram_Declaration then
Set_Is_Abstract (Nam);
Set_Is_Dispatching_Operation (Nam);
declare
Ctrl_Type : constant Entity_Id := Find_Dispatching_Type (Nam);
begin
if No (Ctrl_Type) then
Error_Msg_N
("abstract formal subprogram must have a controlling type",
N);
else
Check_Controlling_Formals (Ctrl_Type, Nam);
end if;
end;
end if;
-- Default name is resolved at the point of instantiation
if Box_Present (N) then
null;
-- Else default is bound at the point of generic declaration
elsif Present (Def) then
if Nkind (Def) = N_Operator_Symbol then
Find_Direct_Name (Def);
elsif Nkind (Def) /= N_Attribute_Reference then
Analyze (Def);
else
-- For an attribute reference, analyze the prefix and verify
-- that it has the proper profile for the subprogram.
Analyze (Prefix (Def));
Valid_Default_Attribute (Nam, Def);
return;
end if;
-- Default name may be overloaded, in which case the interpretation
-- with the correct profile must be selected, as for a renaming.
if Etype (Def) = Any_Type then
return;
elsif Nkind (Def) = N_Selected_Component then
Subp := Entity (Selector_Name (Def));
if Ekind (Subp) /= E_Entry then
Error_Msg_N ("expect valid subprogram name as default", Def);
return;
end if;
elsif Nkind (Def) = N_Indexed_Component then
if Nkind (Prefix (Def)) /= N_Selected_Component then
Error_Msg_N ("expect valid subprogram name as default", Def);
return;
else
Subp := Entity (Selector_Name (Prefix (Def)));
if Ekind (Subp) /= E_Entry_Family then
Error_Msg_N ("expect valid subprogram name as default", Def);
return;
end if;
end if;
elsif Nkind (Def) = N_Character_Literal then
-- Needs some type checks: subprogram should be parameterless???
Resolve (Def, (Etype (Nam)));
elsif not Is_Entity_Name (Def)
or else not Is_Overloadable (Entity (Def))
then
Error_Msg_N ("expect valid subprogram name as default", Def);
return;
elsif not Is_Overloaded (Def) then
Subp := Entity (Def);
if Subp = Nam then
Error_Msg_N ("premature usage of formal subprogram", Def);
elsif not Entity_Matches_Spec (Subp, Nam) then
Error_Msg_N ("no visible entity matches specification", Def);
end if;
else
declare
I : Interp_Index;
I1 : Interp_Index := 0;
It : Interp;
It1 : Interp;
begin
Subp := Any_Id;
Get_First_Interp (Def, I, It);
while Present (It.Nam) loop
if Entity_Matches_Spec (It.Nam, Nam) then
if Subp /= Any_Id then
It1 := Disambiguate (Def, I1, I, Etype (Subp));
if It1 = No_Interp then
Error_Msg_N ("ambiguous default subprogram", Def);
else
Subp := It1.Nam;
end if;
exit;
else
I1 := I;
Subp := It.Nam;
end if;
end if;
Get_Next_Interp (I, It);
end loop;
end;
if Subp /= Any_Id then
Set_Entity (Def, Subp);
if Subp = Nam then
Error_Msg_N ("premature usage of formal subprogram", Def);
elsif Ekind (Subp) /= E_Operator then
Check_Mode_Conformant (Subp, Nam);
end if;
else
Error_Msg_N ("no visible subprogram matches specification", N);
end if;
end if;
end if;
end Analyze_Formal_Subprogram;
-------------------------------------
-- Analyze_Formal_Type_Declaration --
-------------------------------------
procedure Analyze_Formal_Type_Declaration (N : Node_Id) is
Def : constant Node_Id := Formal_Type_Definition (N);
T : Entity_Id;
begin
T := Defining_Identifier (N);
if Present (Discriminant_Specifications (N))
and then Nkind (Def) /= N_Formal_Private_Type_Definition
then
Error_Msg_N
("discriminants not allowed for this formal type",
Defining_Identifier (First (Discriminant_Specifications (N))));
end if;
-- Enter the new name, and branch to specific routine
case Nkind (Def) is
when N_Formal_Private_Type_Definition =>
Analyze_Formal_Private_Type (N, T, Def);
when N_Formal_Derived_Type_Definition =>
Analyze_Formal_Derived_Type (N, T, Def);
when N_Formal_Discrete_Type_Definition =>
Analyze_Formal_Discrete_Type (T, Def);
when N_Formal_Signed_Integer_Type_Definition =>
Analyze_Formal_Signed_Integer_Type (T, Def);
when N_Formal_Modular_Type_Definition =>
Analyze_Formal_Modular_Type (T, Def);
when N_Formal_Floating_Point_Definition =>
Analyze_Formal_Floating_Type (T, Def);
when N_Formal_Ordinary_Fixed_Point_Definition =>
Analyze_Formal_Ordinary_Fixed_Point_Type (T, Def);
when N_Formal_Decimal_Fixed_Point_Definition =>
Analyze_Formal_Decimal_Fixed_Point_Type (T, Def);
when N_Array_Type_Definition =>
Analyze_Formal_Array_Type (T, Def);
when N_Access_To_Object_Definition |
N_Access_Function_Definition |
N_Access_Procedure_Definition =>
Analyze_Generic_Access_Type (T, Def);
-- Ada 2005: a interface declaration is encoded as an abstract
-- record declaration or a abstract type derivation.
when N_Record_Definition =>
Analyze_Formal_Interface_Type (T, Def);
when N_Derived_Type_Definition =>
Analyze_Formal_Derived_Interface_Type (T, Def);
when N_Error =>
null;
when others =>
raise Program_Error;
end case;
Set_Is_Generic_Type (T);
end Analyze_Formal_Type_Declaration;
------------------------------------
-- Analyze_Function_Instantiation --
------------------------------------
procedure Analyze_Function_Instantiation (N : Node_Id) is
begin
Analyze_Subprogram_Instantiation (N, E_Function);
end Analyze_Function_Instantiation;
---------------------------------
-- Analyze_Generic_Access_Type --
---------------------------------
procedure Analyze_Generic_Access_Type (T : Entity_Id; Def : Node_Id) is
begin
Enter_Name (T);
if Nkind (Def) = N_Access_To_Object_Definition then
Access_Type_Declaration (T, Def);
if Is_Incomplete_Or_Private_Type (Designated_Type (T))
and then No (Full_View (Designated_Type (T)))
and then not Is_Generic_Type (Designated_Type (T))
then
Error_Msg_N ("premature usage of incomplete type", Def);
elsif Is_Internal (Designated_Type (T)) then
Error_Msg_N
("only a subtype mark is allowed in a formal", Def);
end if;
else
Access_Subprogram_Declaration (T, Def);
end if;
end Analyze_Generic_Access_Type;
---------------------------------
-- Analyze_Generic_Formal_Part --
---------------------------------
procedure Analyze_Generic_Formal_Part (N : Node_Id) is
Gen_Parm_Decl : Node_Id;
begin
-- The generic formals are processed in the scope of the generic
-- unit, where they are immediately visible. The scope is installed
-- by the caller.
Gen_Parm_Decl := First (Generic_Formal_Declarations (N));
while Present (Gen_Parm_Decl) loop
Analyze (Gen_Parm_Decl);
Next (Gen_Parm_Decl);
end loop;
Generate_Reference_To_Generic_Formals (Current_Scope);
end Analyze_Generic_Formal_Part;
------------------------------------------
-- Analyze_Generic_Package_Declaration --
------------------------------------------
procedure Analyze_Generic_Package_Declaration (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Id : Entity_Id;
New_N : Node_Id;
Save_Parent : Node_Id;
Renaming : Node_Id;
Decls : constant List_Id :=
Visible_Declarations (Specification (N));
Decl : Node_Id;
begin
-- We introduce a renaming of the enclosing package, to have a usable
-- entity as the prefix of an expanded name for a local entity of the
-- form Par.P.Q, where P is the generic package. This is because a local
-- entity named P may hide it, so that the usual visibility rules in
-- the instance will not resolve properly.
Renaming :=
Make_Package_Renaming_Declaration (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Defining_Entity (N)), "GH")),
Name => Make_Identifier (Loc, Chars (Defining_Entity (N))));
if Present (Decls) then
Decl := First (Decls);
while Present (Decl)
and then Nkind (Decl) = N_Pragma
loop
Next (Decl);
end loop;
if Present (Decl) then
Insert_Before (Decl, Renaming);
else
Append (Renaming, Visible_Declarations (Specification (N)));
end if;
else
Set_Visible_Declarations (Specification (N), New_List (Renaming));
end if;
-- Create copy of generic unit, and save for instantiation.
-- If the unit is a child unit, do not copy the specifications
-- for the parent, which are not part of the generic tree.
Save_Parent := Parent_Spec (N);
Set_Parent_Spec (N, Empty);
New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
Set_Parent_Spec (New_N, Save_Parent);
Rewrite (N, New_N);
Id := Defining_Entity (N);
Generate_Definition (Id);
-- Expansion is not applied to generic units
Start_Generic;
Enter_Name (Id);
Set_Ekind (Id, E_Generic_Package);
Set_Etype (Id, Standard_Void_Type);
New_Scope (Id);
Enter_Generic_Scope (Id);
Set_Inner_Instances (Id, New_Elmt_List);
Set_Categorization_From_Pragmas (N);
Set_Is_Pure (Id, Is_Pure (Current_Scope));
-- Link the declaration of the generic homonym in the generic copy
-- to the package it renames, so that it is always resolved properly.
Set_Generic_Homonym (Id, Defining_Unit_Name (Renaming));
Set_Entity (Associated_Node (Name (Renaming)), Id);
-- For a library unit, we have reconstructed the entity for the
-- unit, and must reset it in the library tables.
if Nkind (Parent (N)) = N_Compilation_Unit then
Set_Cunit_Entity (Current_Sem_Unit, Id);
end if;
Analyze_Generic_Formal_Part (N);
-- After processing the generic formals, analysis proceeds
-- as for a non-generic package.
Analyze (Specification (N));
Validate_Categorization_Dependency (N, Id);
End_Generic;
End_Package_Scope (Id);
Exit_Generic_Scope (Id);
if Nkind (Parent (N)) /= N_Compilation_Unit then
Move_Freeze_Nodes (Id, N, Visible_Declarations (Specification (N)));
Move_Freeze_Nodes (Id, N, Private_Declarations (Specification (N)));
Move_Freeze_Nodes (Id, N, Generic_Formal_Declarations (N));
else
Set_Body_Required (Parent (N), Unit_Requires_Body (Id));
Validate_RT_RAT_Component (N);
-- If this is a spec without a body, check that generic parameters
-- are referenced.
if not Body_Required (Parent (N)) then
Check_References (Id);
end if;
end if;
end Analyze_Generic_Package_Declaration;
--------------------------------------------
-- Analyze_Generic_Subprogram_Declaration --
--------------------------------------------
procedure Analyze_Generic_Subprogram_Declaration (N : Node_Id) is
Spec : Node_Id;
Id : Entity_Id;
Formals : List_Id;
New_N : Node_Id;
Result_Type : Entity_Id;
Save_Parent : Node_Id;
begin
-- Create copy of generic unit,and save for instantiation.
-- If the unit is a child unit, do not copy the specifications
-- for the parent, which are not part of the generic tree.
Save_Parent := Parent_Spec (N);
Set_Parent_Spec (N, Empty);
New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
Set_Parent_Spec (New_N, Save_Parent);
Rewrite (N, New_N);
Spec := Specification (N);
Id := Defining_Entity (Spec);
Generate_Definition (Id);
if Nkind (Id) = N_Defining_Operator_Symbol then
Error_Msg_N
("operator symbol not allowed for generic subprogram", Id);
end if;
Start_Generic;
Enter_Name (Id);
Set_Scope_Depth_Value (Id, Scope_Depth (Current_Scope) + 1);
New_Scope (Id);
Enter_Generic_Scope (Id);
Set_Inner_Instances (Id, New_Elmt_List);
Set_Is_Pure (Id, Is_Pure (Current_Scope));
Analyze_Generic_Formal_Part (N);
Formals := Parameter_Specifications (Spec);
if Present (Formals) then
Process_Formals (Formals, Spec);
end if;
if Nkind (Spec) = N_Function_Specification then
Set_Ekind (Id, E_Generic_Function);
if Nkind (Result_Definition (Spec)) = N_Access_Definition then
Result_Type := Access_Definition (Spec, Result_Definition (Spec));
Set_Etype (Id, Result_Type);
else
Find_Type (Result_Definition (Spec));
Set_Etype (Id, Entity (Result_Definition (Spec)));
end if;
else
Set_Ekind (Id, E_Generic_Procedure);
Set_Etype (Id, Standard_Void_Type);
end if;
-- For a library unit, we have reconstructed the entity for the unit,
-- and must reset it in the library tables. We also make sure that
-- Body_Required is set properly in the original compilation unit node.
if Nkind (Parent (N)) = N_Compilation_Unit then
Set_Cunit_Entity (Current_Sem_Unit, Id);
Set_Body_Required (Parent (N), Unit_Requires_Body (Id));
end if;
Set_Categorization_From_Pragmas (N);
Validate_Categorization_Dependency (N, Id);
Save_Global_References (Original_Node (N));
End_Generic;
End_Scope;
Exit_Generic_Scope (Id);
Generate_Reference_To_Formals (Id);
end Analyze_Generic_Subprogram_Declaration;
-----------------------------------
-- Analyze_Package_Instantiation --
-----------------------------------
-- Note: this procedure is also used for formal package declarations, in
-- which case the argument N is an N_Formal_Package_Declaration node.
-- This should really be noted in the spec! ???
procedure Analyze_Package_Instantiation (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Gen_Id : constant Node_Id := Name (N);
Act_Decl : Node_Id;
Act_Decl_Name : Node_Id;
Act_Decl_Id : Entity_Id;
Act_Spec : Node_Id;
Act_Tree : Node_Id;
Gen_Decl : Node_Id;
Gen_Unit : Entity_Id;
Is_Actual_Pack : constant Boolean :=
Is_Internal (Defining_Entity (N));
Env_Installed : Boolean := False;
Parent_Installed : Boolean := False;
Renaming_List : List_Id;
Unit_Renaming : Node_Id;
Needs_Body : Boolean;
Inline_Now : Boolean := False;
procedure Delay_Descriptors (E : Entity_Id);
-- Delay generation of subprogram descriptors for given entity
function Might_Inline_Subp return Boolean;
-- If inlining is active and the generic contains inlined subprograms,
-- we instantiate the body. This may cause superfluous instantiations,
-- but it is simpler than detecting the need for the body at the point
-- of inlining, when the context of the instance is not available.
-----------------------
-- Delay_Descriptors --
-----------------------
procedure Delay_Descriptors (E : Entity_Id) is
begin
if not Delay_Subprogram_Descriptors (E) then
Set_Delay_Subprogram_Descriptors (E);
Pending_Descriptor.Increment_Last;
Pending_Descriptor.Table (Pending_Descriptor.Last) := E;
end if;
end Delay_Descriptors;
-----------------------
-- Might_Inline_Subp --
-----------------------
function Might_Inline_Subp return Boolean is
E : Entity_Id;
begin
if not Inline_Processing_Required then
return False;
else
E := First_Entity (Gen_Unit);
while Present (E) loop
if Is_Subprogram (E)
and then Is_Inlined (E)
then
return True;
end if;
Next_Entity (E);
end loop;
end if;
return False;
end Might_Inline_Subp;
-- Start of processing for Analyze_Package_Instantiation
begin
-- Very first thing: apply the special kludge for Text_IO processing
-- in case we are instantiating one of the children of [Wide_]Text_IO.
Text_IO_Kludge (Name (N));
-- Make node global for error reporting
Instantiation_Node := N;
-- Case of instantiation of a generic package
if Nkind (N) = N_Package_Instantiation then
Act_Decl_Id := New_Copy (Defining_Entity (N));
Set_Comes_From_Source (Act_Decl_Id, True);
if Nkind (Defining_Unit_Name (N)) = N_Defining_Program_Unit_Name then
Act_Decl_Name :=
Make_Defining_Program_Unit_Name (Loc,
Name => New_Copy_Tree (Name (Defining_Unit_Name (N))),
Defining_Identifier => Act_Decl_Id);
else
Act_Decl_Name := Act_Decl_Id;
end if;
-- Case of instantiation of a formal package
else
Act_Decl_Id := Defining_Identifier (N);
Act_Decl_Name := Act_Decl_Id;
end if;
Generate_Definition (Act_Decl_Id);
Pre_Analyze_Actuals (N);
Init_Env;
Env_Installed := True;
Check_Generic_Child_Unit (Gen_Id, Parent_Installed);
Gen_Unit := Entity (Gen_Id);
-- Verify that it is the name of a generic package
if Etype (Gen_Unit) = Any_Type then
Restore_Env;
return;
elsif Ekind (Gen_Unit) /= E_Generic_Package then
-- Ada 2005 (AI-50217): Cannot use instance in limited with_clause
if From_With_Type (Gen_Unit) then
Error_Msg_N
("cannot instantiate a limited withed package", Gen_Id);
else
Error_Msg_N
("expect name of generic package in instantiation", Gen_Id);
end if;
Restore_Env;
return;
end if;
if In_Extended_Main_Source_Unit (N) then
Set_Is_Instantiated (Gen_Unit);
Generate_Reference (Gen_Unit, N);
if Present (Renamed_Object (Gen_Unit)) then
Set_Is_Instantiated (Renamed_Object (Gen_Unit));
Generate_Reference (Renamed_Object (Gen_Unit), N);
end if;
end if;
if Nkind (Gen_Id) = N_Identifier
and then Chars (Gen_Unit) = Chars (Defining_Entity (N))
then
Error_Msg_NE
("& is hidden within declaration of instance", Gen_Id, Gen_Unit);
elsif Nkind (Gen_Id) = N_Expanded_Name
and then Is_Child_Unit (Gen_Unit)
and then Nkind (Prefix (Gen_Id)) = N_Identifier
and then Chars (Act_Decl_Id) = Chars (Prefix (Gen_Id))
then
Error_Msg_N
("& is hidden within declaration of instance ", Prefix (Gen_Id));
end if;
Set_Entity (Gen_Id, Gen_Unit);
-- If generic is a renaming, get original generic unit
if Present (Renamed_Object (Gen_Unit))
and then Ekind (Renamed_Object (Gen_Unit)) = E_Generic_Package
then
Gen_Unit := Renamed_Object (Gen_Unit);
end if;
-- Verify that there are no circular instantiations
if In_Open_Scopes (Gen_Unit) then
Error_Msg_NE ("instantiation of & within itself", N, Gen_Unit);
Restore_Env;
return;
elsif Contains_Instance_Of (Gen_Unit, Current_Scope, Gen_Id) then
Error_Msg_Node_2 := Current_Scope;
Error_Msg_NE
("circular Instantiation: & instantiated in &!", N, Gen_Unit);
Circularity_Detected := True;
Restore_Env;
return;
else
Set_Instance_Env (Gen_Unit, Act_Decl_Id);
Gen_Decl := Unit_Declaration_Node (Gen_Unit);
-- Initialize renamings map, for error checking, and the list
-- that holds private entities whose views have changed between
-- generic definition and instantiation. If this is the instance
-- created to validate an actual package, the instantiation
-- environment is that of the enclosing instance.
Generic_Renamings.Set_Last (0);
Generic_Renamings_HTable.Reset;
Create_Instantiation_Source (N, Gen_Unit, False, S_Adjustment);
-- Copy original generic tree, to produce text for instantiation
Act_Tree :=
Copy_Generic_Node
(Original_Node (Gen_Decl), Empty, Instantiating => True);
Act_Spec := Specification (Act_Tree);
-- If this is the instance created to validate an actual package,
-- only the formals matter, do not examine the package spec itself.
if Is_Actual_Pack then
Set_Visible_Declarations (Act_Spec, New_List);
Set_Private_Declarations (Act_Spec, New_List);
end if;
Renaming_List :=
Analyze_Associations
(N,
Generic_Formal_Declarations (Act_Tree),
Generic_Formal_Declarations (Gen_Decl));
Set_Defining_Unit_Name (Act_Spec, Act_Decl_Name);
Set_Is_Generic_Instance (Act_Decl_Id);
Set_Generic_Parent (Act_Spec, Gen_Unit);
-- References to the generic in its own declaration or its body
-- are references to the instance. Add a renaming declaration for
-- the generic unit itself. This declaration, as well as the renaming
-- declarations for the generic formals, must remain private to the
-- unit: the formals, because this is the language semantics, and
-- the unit because its use is an artifact of the implementation.
Unit_Renaming :=
Make_Package_Renaming_Declaration (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc, Chars (Gen_Unit)),
Name => New_Reference_To (Act_Decl_Id, Loc));
Append (Unit_Renaming, Renaming_List);
-- The renaming declarations are the first local declarations of
-- the new unit.
if Is_Non_Empty_List (Visible_Declarations (Act_Spec)) then
Insert_List_Before
(First (Visible_Declarations (Act_Spec)), Renaming_List);
else
Set_Visible_Declarations (Act_Spec, Renaming_List);
end if;
Act_Decl :=
Make_Package_Declaration (Loc,
Specification => Act_Spec);
-- Save the instantiation node, for subsequent instantiation
-- of the body, if there is one and we are generating code for
-- the current unit. Mark the unit as having a body, to avoid
-- a premature error message.
-- We instantiate the body if we are generating code, if we are
-- generating cross-reference information, or if we are building
-- trees for ASIS use.
declare
Enclosing_Body_Present : Boolean := False;
-- If the generic unit is not a compilation unit, then a body
-- may be present in its parent even if none is required. We
-- create a tentative pending instantiation for the body, which
-- will be discarded if none is actually present.
Scop : Entity_Id;
begin
if Scope (Gen_Unit) /= Standard_Standard
and then not Is_Child_Unit (Gen_Unit)
then
Scop := Scope (Gen_Unit);
while Present (Scop)
and then Scop /= Standard_Standard
loop
if Unit_Requires_Body (Scop) then
Enclosing_Body_Present := True;
exit;
elsif In_Open_Scopes (Scop)
and then In_Package_Body (Scop)
then
Enclosing_Body_Present := True;
exit;
end if;
exit when Is_Compilation_Unit (Scop);
Scop := Scope (Scop);
end loop;
end if;
-- If front-end inlining is enabled, and this is a unit for which
-- code will be generated, we instantiate the body at once.
-- This is done if the instance is not the main unit, and if the
-- generic is not a child unit of another generic, to avoid scope
-- problems and the reinstallation of parent instances.
if Expander_Active
and then (not Is_Child_Unit (Gen_Unit)
or else not Is_Generic_Unit (Scope (Gen_Unit)))
and then Might_Inline_Subp
and then not Is_Actual_Pack
then
if Front_End_Inlining
and then (Is_In_Main_Unit (N)
or else In_Main_Context (Current_Scope))
and then Nkind (Parent (N)) /= N_Compilation_Unit
then
Inline_Now := True;
-- In configurable_run_time mode we force the inlining of
-- predefined subprogram marked Inline_Always, to minimize
-- the use of the run-time library.
elsif Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (Gen_Decl)))
and then Configurable_Run_Time_Mode
and then Nkind (Parent (N)) /= N_Compilation_Unit
then
Inline_Now := True;
end if;
-- If the current scope is itself an instance within a child
-- unit,there will be duplications in the scope stack, and the
-- unstacking mechanism in Inline_Instance_Body will fail.
-- This loses some rare cases of optimization, and might be
-- improved some day, if we can find a proper abstraction for
-- "the complete compilation context" that can be saved and
-- restored ???
if Is_Generic_Instance (Current_Scope) then
declare
Curr_Unit : constant Entity_Id :=
Cunit_Entity (Current_Sem_Unit);
begin
if Curr_Unit /= Current_Scope
and then Is_Child_Unit (Curr_Unit)
then
Inline_Now := False;
end if;
end;
end if;
end if;
Needs_Body :=
(Unit_Requires_Body (Gen_Unit)
or else Enclosing_Body_Present
or else Present (Corresponding_Body (Gen_Decl)))
and then (Is_In_Main_Unit (N)
or else Might_Inline_Subp)
and then not Is_Actual_Pack
and then not Inline_Now
and then (Operating_Mode = Generate_Code
or else (Operating_Mode = Check_Semantics
and then ASIS_Mode));
-- If front_end_inlining is enabled, do not instantiate a
-- body if within a generic context.
if (Front_End_Inlining
and then not Expander_Active)
or else Is_Generic_Unit (Cunit_Entity (Main_Unit))
then
Needs_Body := False;
end if;
-- If the current context is generic, and the package being
-- instantiated is declared within a formal package, there is no
-- body to instantiate until the enclosing generic is instantiated
-- and there is an actual for the formal package. If the formal
-- package has parameters, we build regular package instance for
-- it, that preceeds the original formal package declaration.
if In_Open_Scopes (Scope (Scope (Gen_Unit))) then
declare
Decl : constant Node_Id :=
Original_Node
(Unit_Declaration_Node (Scope (Gen_Unit)));
begin
if Nkind (Decl) = N_Formal_Package_Declaration
or else (Nkind (Decl) = N_Package_Declaration
and then Is_List_Member (Decl)
and then Present (Next (Decl))
and then
Nkind (Next (Decl)) = N_Formal_Package_Declaration)
then
Needs_Body := False;
end if;
end;
end if;
end;
-- If we are generating the calling stubs from the instantiation of
-- a generic RCI package, we will not use the body of the generic
-- package.
if Distribution_Stub_Mode = Generate_Caller_Stub_Body
and then Is_Compilation_Unit (Defining_Entity (N))
then
Needs_Body := False;
end if;
if Needs_Body then
-- Here is a defence against a ludicrous number of instantiations
-- caused by a circular set of instantiation attempts.
if Pending_Instantiations.Last >
Hostparm.Max_Instantiations
then
Error_Msg_N ("too many instantiations", N);
raise Unrecoverable_Error;
end if;
-- Indicate that the enclosing scopes contain an instantiation,
-- and that cleanup actions should be delayed until after the
-- instance body is expanded.
Check_Forward_Instantiation (Gen_Decl);
if Nkind (N) = N_Package_Instantiation then
declare
Enclosing_Master : Entity_Id := Current_Scope;
begin
while Enclosing_Master /= Standard_Standard loop
if Ekind (Enclosing_Master) = E_Package then
if Is_Compilation_Unit (Enclosing_Master) then
if In_Package_Body (Enclosing_Master) then
Delay_Descriptors
(Body_Entity (Enclosing_Master));
else
Delay_Descriptors
(Enclosing_Master);
end if;
exit;
else
Enclosing_Master := Scope (Enclosing_Master);
end if;
elsif Ekind (Enclosing_Master) = E_Generic_Package then
Enclosing_Master := Scope (Enclosing_Master);
elsif Is_Generic_Subprogram (Enclosing_Master)
or else Ekind (Enclosing_Master) = E_Void
then
-- Cleanup actions will eventually be performed on
-- the enclosing instance, if any. enclosing scope
-- is void in the formal part of a generic subp.
exit;
else
if Ekind (Enclosing_Master) = E_Entry
and then
Ekind (Scope (Enclosing_Master)) = E_Protected_Type
then
Enclosing_Master :=
Protected_Body_Subprogram (Enclosing_Master);
end if;
Set_Delay_Cleanups (Enclosing_Master);
while Ekind (Enclosing_Master) = E_Block loop
Enclosing_Master := Scope (Enclosing_Master);
end loop;
if Is_Subprogram (Enclosing_Master) then
Delay_Descriptors (Enclosing_Master);
elsif Is_Task_Type (Enclosing_Master) then
declare
TBP : constant Node_Id :=
Get_Task_Body_Procedure
(Enclosing_Master);
begin
if Present (TBP) then
Delay_Descriptors (TBP);
Set_Delay_Cleanups (TBP);
end if;
end;
end if;
exit;
end if;
end loop;
end;
-- Make entry in table
Pending_Instantiations.Increment_Last;
Pending_Instantiations.Table (Pending_Instantiations.Last) :=
(N, Act_Decl, Expander_Active, Current_Sem_Unit);
end if;
end if;
Set_Categorization_From_Pragmas (Act_Decl);
if Parent_Installed then
Hide_Current_Scope;
end if;
Set_Instance_Spec (N, Act_Decl);
-- If not a compilation unit, insert the package declaration
-- before the original instantiation node.
if Nkind (Parent (N)) /= N_Compilation_Unit then
Mark_Rewrite_Insertion (Act_Decl);
Insert_Before (N, Act_Decl);
Analyze (Act_Decl);
-- For an instantiation that is a compilation unit, place
-- declaration on current node so context is complete
-- for analysis (including nested instantiations). It this
-- is the main unit, the declaration eventually replaces the
-- instantiation node. If the instance body is later created, it
-- replaces the instance node, and the declation is attached to
-- it (see Build_Instance_Compilation_Unit_Nodes).
else
if Cunit_Entity (Current_Sem_Unit) = Defining_Entity (N) then
-- The entity for the current unit is the newly created one,
-- and all semantic information is attached to it.
Set_Cunit_Entity (Current_Sem_Unit, Act_Decl_Id);
-- If this is the main unit, replace the main entity as well
if Current_Sem_Unit = Main_Unit then
Main_Unit_Entity := Act_Decl_Id;
end if;
end if;
-- There is a problem with inlining here
-- More comments needed??? what problem
Set_Unit (Parent (N), Act_Decl);
Set_Parent_Spec (Act_Decl, Parent_Spec (N));
Set_Package_Instantiation (Act_Decl_Id, N);
Analyze (Act_Decl);
Set_Unit (Parent (N), N);
Set_Body_Required (Parent (N), False);
-- We never need elaboration checks on instantiations, since
-- by definition, the body instantiation is elaborated at the
-- same time as the spec instantiation.
Set_Suppress_Elaboration_Warnings (Act_Decl_Id);
Set_Kill_Elaboration_Checks (Act_Decl_Id);
end if;
Check_Elab_Instantiation (N);
if ABE_Is_Certain (N) and then Needs_Body then
Pending_Instantiations.Decrement_Last;
end if;
Check_Hidden_Child_Unit (N, Gen_Unit, Act_Decl_Id);
Set_First_Private_Entity (Defining_Unit_Name (Unit_Renaming),
First_Private_Entity (Act_Decl_Id));
-- If the instantiation will receive a body, the unit will
-- be transformed into a package body, and receive its own
-- elaboration entity. Otherwise, the nature of the unit is
-- now a package declaration.
if Nkind (Parent (N)) = N_Compilation_Unit
and then not Needs_Body
then
Rewrite (N, Act_Decl);
end if;
if Present (Corresponding_Body (Gen_Decl))
or else Unit_Requires_Body (Gen_Unit)
then
Set_Has_Completion (Act_Decl_Id);
end if;
Check_Formal_Packages (Act_Decl_Id);
Restore_Private_Views (Act_Decl_Id);
if not Generic_Separately_Compiled (Gen_Unit) then
Inherit_Context (Gen_Decl, N);
end if;
if Parent_Installed then
Remove_Parent;
end if;
Restore_Env;
Env_Installed := False;
end if;
Validate_Categorization_Dependency (N, Act_Decl_Id);
-- Check restriction, but skip this if something went wrong in
-- the above analysis, indicated by Act_Decl_Id being void.
if Ekind (Act_Decl_Id) /= E_Void
and then not Is_Library_Level_Entity (Act_Decl_Id)
then
Check_Restriction (No_Local_Allocators, N);
end if;
if Inline_Now then
Inline_Instance_Body (N, Gen_Unit, Act_Decl);
end if;
-- The following is a tree patch for ASIS: ASIS needs separate nodes
-- to be used as defining identifiers for a formal package and for the
-- corresponding expanded package
if Nkind (N) = N_Formal_Package_Declaration then
Act_Decl_Id := New_Copy (Defining_Entity (N));
Set_Comes_From_Source (Act_Decl_Id, True);
Set_Is_Generic_Instance (Act_Decl_Id, False);
Set_Defining_Identifier (N, Act_Decl_Id);
end if;
exception
when Instantiation_Error =>
if Parent_Installed then
Remove_Parent;
end if;
if Env_Installed then
Restore_Env;
end if;
end Analyze_Package_Instantiation;
--------------------------
-- Inline_Instance_Body --
--------------------------
procedure Inline_Instance_Body
(N : Node_Id;
Gen_Unit : Entity_Id;
Act_Decl : Node_Id)
is
Vis : Boolean;
Gen_Comp : constant Entity_Id :=
Cunit_Entity (Get_Source_Unit (Gen_Unit));
Curr_Comp : constant Node_Id := Cunit (Current_Sem_Unit);
Curr_Scope : Entity_Id := Empty;
Curr_Unit : constant Entity_Id :=
Cunit_Entity (Current_Sem_Unit);
Removed : Boolean := False;
Num_Scopes : Int := 0;
Scope_Stack_Depth : constant Int :=
Scope_Stack.Last - Scope_Stack.First + 1;
Use_Clauses : array (1 .. Scope_Stack_Depth) of Node_Id;
Instances : array (1 .. Scope_Stack_Depth) of Entity_Id;
Inner_Scopes : array (1 .. Scope_Stack_Depth) of Entity_Id;
Num_Inner : Int := 0;
N_Instances : Int := 0;
S : Entity_Id;
begin
-- Case of generic unit defined in another unit. We must remove the
-- complete context of the current unit to install that of the generic.
if Gen_Comp /= Cunit_Entity (Current_Sem_Unit) then
-- Add some comments for the following two loops ???
S := Current_Scope;
while Present (S) and then S /= Standard_Standard loop
loop
Num_Scopes := Num_Scopes + 1;
Use_Clauses (Num_Scopes) :=
(Scope_Stack.Table
(Scope_Stack.Last - Num_Scopes + 1).
First_Use_Clause);
End_Use_Clauses (Use_Clauses (Num_Scopes));
exit when Scope_Stack.Last - Num_Scopes + 1 = Scope_Stack.First
or else Scope_Stack.Table
(Scope_Stack.Last - Num_Scopes).Entity
= Scope (S);
end loop;
exit when Is_Generic_Instance (S)
and then (In_Package_Body (S)
or else Ekind (S) = E_Procedure
or else Ekind (S) = E_Function);
S := Scope (S);
end loop;
Vis := Is_Immediately_Visible (Gen_Comp);
-- Find and save all enclosing instances
S := Current_Scope;
while Present (S)
and then S /= Standard_Standard
loop
if Is_Generic_Instance (S) then
N_Instances := N_Instances + 1;
Instances (N_Instances) := S;
exit when In_Package_Body (S);
end if;
S := Scope (S);
end loop;
-- Remove context of current compilation unit, unless we are within a
-- nested package instantiation, in which case the context has been
-- removed previously.
-- If current scope is the body of a child unit, remove context of
-- spec as well.
S := Current_Scope;
while Present (S)
and then S /= Standard_Standard
loop
exit when Is_Generic_Instance (S)
and then (In_Package_Body (S)
or else Ekind (S) = E_Procedure
or else Ekind (S) = E_Function);
if S = Curr_Unit
or else (Ekind (Curr_Unit) = E_Package_Body
and then S = Spec_Entity (Curr_Unit))
or else (Ekind (Curr_Unit) = E_Subprogram_Body
and then S =
Corresponding_Spec
(Unit_Declaration_Node (Curr_Unit)))
then
Removed := True;
-- Remove entities in current scopes from visibility, so
-- that instance body is compiled in a clean environment.
Save_Scope_Stack (Handle_Use => False);
if Is_Child_Unit (S) then
-- Remove child unit from stack, as well as inner scopes.
-- Removing the context of a child unit removes parent
-- units as well.
while Current_Scope /= S loop
Num_Inner := Num_Inner + 1;
Inner_Scopes (Num_Inner) := Current_Scope;
Pop_Scope;
end loop;
Pop_Scope;
Remove_Context (Curr_Comp);
Curr_Scope := S;
else
Remove_Context (Curr_Comp);
end if;
if Ekind (Curr_Unit) = E_Package_Body then
Remove_Context (Library_Unit (Curr_Comp));
end if;
end if;
S := Scope (S);
end loop;
pragma Assert (Num_Inner < Num_Scopes);
New_Scope (Standard_Standard);
Scope_Stack.Table (Scope_Stack.Last).Is_Active_Stack_Base := True;
Instantiate_Package_Body
((N, Act_Decl, Expander_Active, Current_Sem_Unit), True);
Pop_Scope;
-- Restore context
Set_Is_Immediately_Visible (Gen_Comp, Vis);
-- Reset Generic_Instance flag so that use clauses can be installed
-- in the proper order. (See Use_One_Package for effect of enclosing
-- instances on processing of use clauses).
for J in 1 .. N_Instances loop
Set_Is_Generic_Instance (Instances (J), False);
end loop;
if Removed then
Install_Context (Curr_Comp);
if Present (Curr_Scope)
and then Is_Child_Unit (Curr_Scope)
then
New_Scope (Curr_Scope);
Set_Is_Immediately_Visible (Curr_Scope);
-- Finally, restore inner scopes as well
for J in reverse 1 .. Num_Inner loop
New_Scope (Inner_Scopes (J));
end loop;
end if;
Restore_Scope_Stack (Handle_Use => False);
if Present (Curr_Scope)
and then
(In_Private_Part (Curr_Scope)
or else In_Package_Body (Curr_Scope))
then
-- Install private declaration of ancestor units, which
-- are currently available. Restore_Scope_Stack and
-- Install_Context only install the visible part of parents.
declare
Par : Entity_Id;
begin
Par := Scope (Curr_Scope);
while (Present (Par))
and then Par /= Standard_Standard
loop
Install_Private_Declarations (Par);
Par := Scope (Par);
end loop;
end;
end if;
end if;
-- Restore use clauses. For a child unit, use clauses in the parents
-- are restored when installing the context, so only those in inner
-- scopes (and those local to the child unit itself) need to be
-- installed explicitly.
if Is_Child_Unit (Curr_Unit)
and then Removed
then
for J in reverse 1 .. Num_Inner + 1 loop
Scope_Stack.Table (Scope_Stack.Last - J + 1).First_Use_Clause :=
Use_Clauses (J);
Install_Use_Clauses (Use_Clauses (J));
end loop;
else
for J in reverse 1 .. Num_Scopes loop
Scope_Stack.Table (Scope_Stack.Last - J + 1).First_Use_Clause :=
Use_Clauses (J);
Install_Use_Clauses (Use_Clauses (J));
end loop;
end if;
for J in 1 .. N_Instances loop
Set_Is_Generic_Instance (Instances (J), True);
end loop;
-- If generic unit is in current unit, current context is correct
else
Instantiate_Package_Body
((N, Act_Decl, Expander_Active, Current_Sem_Unit), True);
end if;
end Inline_Instance_Body;
-------------------------------------
-- Analyze_Procedure_Instantiation --
-------------------------------------
procedure Analyze_Procedure_Instantiation (N : Node_Id) is
begin
Analyze_Subprogram_Instantiation (N, E_Procedure);
end Analyze_Procedure_Instantiation;
--------------------------------------
-- Analyze_Subprogram_Instantiation --
--------------------------------------
procedure Analyze_Subprogram_Instantiation
(N : Node_Id;
K : Entity_Kind)
is
Loc : constant Source_Ptr := Sloc (N);
Gen_Id : constant Node_Id := Name (N);
Anon_Id : constant Entity_Id :=
Make_Defining_Identifier (Sloc (Defining_Entity (N)),
Chars => New_External_Name
(Chars (Defining_Entity (N)), 'R'));
Act_Decl_Id : Entity_Id;
Act_Decl : Node_Id;
Act_Spec : Node_Id;
Act_Tree : Node_Id;
Env_Installed : Boolean := False;
Gen_Unit : Entity_Id;
Gen_Decl : Node_Id;
Pack_Id : Entity_Id;
Parent_Installed : Boolean := False;
Renaming_List : List_Id;
procedure Analyze_Instance_And_Renamings;
-- The instance must be analyzed in a context that includes the
-- mappings of generic parameters into actuals. We create a package
-- declaration for this purpose, and a subprogram with an internal
-- name within the package. The subprogram instance is simply an
-- alias for the internal subprogram, declared in the current scope.
------------------------------------
-- Analyze_Instance_And_Renamings --
------------------------------------
procedure Analyze_Instance_And_Renamings is
Def_Ent : constant Entity_Id := Defining_Entity (N);
Pack_Decl : Node_Id;
begin
if Nkind (Parent (N)) = N_Compilation_Unit then
-- For the case of a compilation unit, the container package
-- has the same name as the instantiation, to insure that the
-- binder calls the elaboration procedure with the right name.
-- Copy the entity of the instance, which may have compilation
-- level flags (e.g. Is_Child_Unit) set.
Pack_Id := New_Copy (Def_Ent);
else
-- Otherwise we use the name of the instantiation concatenated
-- with its source position to ensure uniqueness if there are
-- several instantiations with the same name.
Pack_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name
(Related_Id => Chars (Def_Ent),
Suffix => "GP",
Suffix_Index => Source_Offset (Sloc (Def_Ent))));
end if;
Pack_Decl := Make_Package_Declaration (Loc,
Specification => Make_Package_Specification (Loc,
Defining_Unit_Name => Pack_Id,
Visible_Declarations => Renaming_List,
End_Label => Empty));
Set_Instance_Spec (N, Pack_Decl);
Set_Is_Generic_Instance (Pack_Id);
Set_Needs_Debug_Info (Pack_Id);
-- Case of not a compilation unit
if Nkind (Parent (N)) /= N_Compilation_Unit then
Mark_Rewrite_Insertion (Pack_Decl);
Insert_Before (N, Pack_Decl);
Set_Has_Completion (Pack_Id);
-- Case of an instantiation that is a compilation unit
-- Place declaration on current node so context is complete
-- for analysis (including nested instantiations), and for
-- use in a context_clause (see Analyze_With_Clause).
else
Set_Unit (Parent (N), Pack_Decl);
Set_Parent_Spec (Pack_Decl, Parent_Spec (N));
end if;
Analyze (Pack_Decl);
Check_Formal_Packages (Pack_Id);
Set_Is_Generic_Instance (Pack_Id, False);
-- Body of the enclosing package is supplied when instantiating
-- the subprogram body, after semantic analysis is completed.
if Nkind (Parent (N)) = N_Compilation_Unit then
-- Remove package itself from visibility, so it does not
-- conflict with subprogram.
Set_Name_Entity_Id (Chars (Pack_Id), Homonym (Pack_Id));
-- Set name and scope of internal subprogram so that the
-- proper external name will be generated. The proper scope
-- is the scope of the wrapper package. We need to generate
-- debugging information for the internal subprogram, so set
-- flag accordingly.
Set_Chars (Anon_Id, Chars (Defining_Entity (N)));
Set_Scope (Anon_Id, Scope (Pack_Id));
-- Mark wrapper package as referenced, to avoid spurious
-- warnings if the instantiation appears in various with_
-- clauses of subunits of the main unit.
Set_Referenced (Pack_Id);
end if;
Set_Is_Generic_Instance (Anon_Id);
Set_Needs_Debug_Info (Anon_Id);
Act_Decl_Id := New_Copy (Anon_Id);
Set_Parent (Act_Decl_Id, Parent (Anon_Id));
Set_Chars (Act_Decl_Id, Chars (Defining_Entity (N)));
Set_Sloc (Act_Decl_Id, Sloc (Defining_Entity (N)));
Set_Comes_From_Source (Act_Decl_Id, True);
-- The signature may involve types that are not frozen yet, but
-- the subprogram will be frozen at the point the wrapper package
-- is frozen, so it does not need its own freeze node. In fact, if
-- one is created, it might conflict with the freezing actions from
-- the wrapper package (see 7206-013).
Set_Has_Delayed_Freeze (Anon_Id, False);
-- If the instance is a child unit, mark the Id accordingly. Mark
-- the anonymous entity as well, which is the real subprogram and
-- which is used when the instance appears in a context clause.
Set_Is_Child_Unit (Act_Decl_Id, Is_Child_Unit (Defining_Entity (N)));
Set_Is_Child_Unit (Anon_Id, Is_Child_Unit (Defining_Entity (N)));
New_Overloaded_Entity (Act_Decl_Id);
Check_Eliminated (Act_Decl_Id);
-- In compilation unit case, kill elaboration checks on the
-- instantiation, since they are never needed -- the body is
-- instantiated at the same point as the spec.
if Nkind (Parent (N)) = N_Compilation_Unit then
Set_Suppress_Elaboration_Warnings (Act_Decl_Id);
Set_Kill_Elaboration_Checks (Act_Decl_Id);
Set_Is_Compilation_Unit (Anon_Id);
Set_Cunit_Entity (Current_Sem_Unit, Pack_Id);
end if;
-- The instance is not a freezing point for the new subprogram
Set_Is_Frozen (Act_Decl_Id, False);
if Nkind (Defining_Entity (N)) = N_Defining_Operator_Symbol then
Valid_Operator_Definition (Act_Decl_Id);
end if;
Set_Alias (Act_Decl_Id, Anon_Id);
Set_Parent (Act_Decl_Id, Parent (Anon_Id));
Set_Has_Completion (Act_Decl_Id);
Set_Related_Instance (Pack_Id, Act_Decl_Id);
if Nkind (Parent (N)) = N_Compilation_Unit then
Set_Body_Required (Parent (N), False);
end if;
end Analyze_Instance_And_Renamings;
-- Start of processing for Analyze_Subprogram_Instantiation
begin
-- Very first thing: apply the special kludge for Text_IO processing
-- in case we are instantiating one of the children of [Wide_]Text_IO.
-- Of course such an instantiation is bogus (these are packages, not
-- subprograms), but we get a better error message if we do this.
Text_IO_Kludge (Gen_Id);
-- Make node global for error reporting
Instantiation_Node := N;
Pre_Analyze_Actuals (N);
Init_Env;
Env_Installed := True;
Check_Generic_Child_Unit (Gen_Id, Parent_Installed);
Gen_Unit := Entity (Gen_Id);
Generate_Reference (Gen_Unit, Gen_Id);
if Nkind (Gen_Id) = N_Identifier
and then Chars (Gen_Unit) = Chars (Defining_Entity (N))
then
Error_Msg_NE
("& is hidden within declaration of instance", Gen_Id, Gen_Unit);
end if;
if Etype (Gen_Unit) = Any_Type then
Restore_Env;
return;
end if;
-- Verify that it is a generic subprogram of the right kind, and that
-- it does not lead to a circular instantiation.
if Ekind (Gen_Unit) /= E_Generic_Procedure
and then Ekind (Gen_Unit) /= E_Generic_Function
then
Error_Msg_N ("expect generic subprogram in instantiation", Gen_Id);
elsif In_Open_Scopes (Gen_Unit) then
Error_Msg_NE ("instantiation of & within itself", N, Gen_Unit);
elsif K = E_Procedure
and then Ekind (Gen_Unit) /= E_Generic_Procedure
then
if Ekind (Gen_Unit) = E_Generic_Function then
Error_Msg_N
("cannot instantiate generic function as procedure", Gen_Id);
else
Error_Msg_N
("expect name of generic procedure in instantiation", Gen_Id);
end if;
elsif K = E_Function
and then Ekind (Gen_Unit) /= E_Generic_Function
then
if Ekind (Gen_Unit) = E_Generic_Procedure then
Error_Msg_N
("cannot instantiate generic procedure as function", Gen_Id);
else
Error_Msg_N
("expect name of generic function in instantiation", Gen_Id);
end if;
else
Set_Entity (Gen_Id, Gen_Unit);
Set_Is_Instantiated (Gen_Unit);
if In_Extended_Main_Source_Unit (N) then
Generate_Reference (Gen_Unit, N);
end if;
-- If renaming, get original unit
if Present (Renamed_Object (Gen_Unit))
and then (Ekind (Renamed_Object (Gen_Unit)) = E_Generic_Procedure
or else
Ekind (Renamed_Object (Gen_Unit)) = E_Generic_Function)
then
Gen_Unit := Renamed_Object (Gen_Unit);
Set_Is_Instantiated (Gen_Unit);
Generate_Reference (Gen_Unit, N);
end if;
if Contains_Instance_Of (Gen_Unit, Current_Scope, Gen_Id) then
Error_Msg_Node_2 := Current_Scope;
Error_Msg_NE
("circular Instantiation: & instantiated in &!", N, Gen_Unit);
Circularity_Detected := True;
return;
end if;
Gen_Decl := Unit_Declaration_Node (Gen_Unit);
-- The subprogram itself cannot contain a nested instance, so
-- the current parent is left empty.
Set_Instance_Env (Gen_Unit, Empty);
-- Initialize renamings map, for error checking
Generic_Renamings.Set_Last (0);
Generic_Renamings_HTable.Reset;
Create_Instantiation_Source (N, Gen_Unit, False, S_Adjustment);
-- Copy original generic tree, to produce text for instantiation
Act_Tree :=
Copy_Generic_Node
(Original_Node (Gen_Decl), Empty, Instantiating => True);
Act_Spec := Specification (Act_Tree);
Renaming_List :=
Analyze_Associations
(N,
Generic_Formal_Declarations (Act_Tree),
Generic_Formal_Declarations (Gen_Decl));
-- Build the subprogram declaration, which does not appear
-- in the generic template, and give it a sloc consistent
-- with that of the template.
Set_Defining_Unit_Name (Act_Spec, Anon_Id);
Set_Generic_Parent (Act_Spec, Gen_Unit);
Act_Decl :=
Make_Subprogram_Declaration (Sloc (Act_Spec),
Specification => Act_Spec);
Set_Categorization_From_Pragmas (Act_Decl);
if Parent_Installed then
Hide_Current_Scope;
end if;
Append (Act_Decl, Renaming_List);
Analyze_Instance_And_Renamings;
-- If the generic is marked Import (Intrinsic), then so is the
-- instance. This indicates that there is no body to instantiate.
-- If generic is marked inline, so it the instance, and the
-- anonymous subprogram it renames. If inlined, or else if inlining
-- is enabled for the compilation, we generate the instance body
-- even if it is not within the main unit.
-- Any other pragmas might also be inherited ???
if Is_Intrinsic_Subprogram (Gen_Unit) then
Set_Is_Intrinsic_Subprogram (Anon_Id);
Set_Is_Intrinsic_Subprogram (Act_Decl_Id);
if Chars (Gen_Unit) = Name_Unchecked_Conversion then
Validate_Unchecked_Conversion (N, Act_Decl_Id);
end if;
end if;
Generate_Definition (Act_Decl_Id);
Set_Is_Inlined (Act_Decl_Id, Is_Inlined (Gen_Unit));
Set_Is_Inlined (Anon_Id, Is_Inlined (Gen_Unit));
if not Is_Intrinsic_Subprogram (Gen_Unit) then
Check_Elab_Instantiation (N);
end if;
if Is_Dispatching_Operation (Act_Decl_Id)
and then Ada_Version >= Ada_05
then
declare
Formal : Entity_Id;
begin
Formal := First_Formal (Act_Decl_Id);
while Present (Formal) loop
if Ekind (Etype (Formal)) = E_Anonymous_Access_Type
and then Is_Controlling_Formal (Formal)
and then not Can_Never_Be_Null (Formal)
then
Error_Msg_NE ("access parameter& is controlling,",
N, Formal);
Error_Msg_NE ("\corresponding parameter of & must be"
& " explicitly null-excluding", N, Gen_Id);
end if;
Next_Formal (Formal);
end loop;
end;
end if;
Check_Hidden_Child_Unit (N, Gen_Unit, Act_Decl_Id);
-- Subject to change, pending on if other pragmas are inherited ???
Validate_Categorization_Dependency (N, Act_Decl_Id);
if not Is_Intrinsic_Subprogram (Act_Decl_Id) then
if not Generic_Separately_Compiled (Gen_Unit) then
Inherit_Context (Gen_Decl, N);
end if;
Restore_Private_Views (Pack_Id, False);
-- If the context requires a full instantiation, mark node for
-- subsequent construction of the body.
if (Is_In_Main_Unit (N)
or else Is_Inlined (Act_Decl_Id))
and then (Operating_Mode = Generate_Code
or else (Operating_Mode = Check_Semantics
and then ASIS_Mode))
and then (Expander_Active or else ASIS_Mode)
and then not ABE_Is_Certain (N)
and then not Is_Eliminated (Act_Decl_Id)
then
Pending_Instantiations.Increment_Last;
Pending_Instantiations.Table (Pending_Instantiations.Last) :=
(N, Act_Decl, Expander_Active, Current_Sem_Unit);
Check_Forward_Instantiation (Gen_Decl);
-- The wrapper package is always delayed, because it does
-- not constitute a freeze point, but to insure that the
-- freeze node is placed properly, it is created directly
-- when instantiating the body (otherwise the freeze node
-- might appear to early for nested instantiations).
elsif Nkind (Parent (N)) = N_Compilation_Unit then
-- For ASIS purposes, indicate that the wrapper package has
-- replaced the instantiation node.
Rewrite (N, Unit (Parent (N)));
Set_Unit (Parent (N), N);
end if;
elsif Nkind (Parent (N)) = N_Compilation_Unit then
-- Replace instance node for library-level instantiations
-- of intrinsic subprograms, for ASIS use.
Rewrite (N, Unit (Parent (N)));
Set_Unit (Parent (N), N);
end if;
if Parent_Installed then
Remove_Parent;
end if;
Restore_Env;
Env_Installed := False;
Generic_Renamings.Set_Last (0);
Generic_Renamings_HTable.Reset;
end if;
exception
when Instantiation_Error =>
if Parent_Installed then
Remove_Parent;
end if;
if Env_Installed then
Restore_Env;
end if;
end Analyze_Subprogram_Instantiation;
-------------------------
-- Get_Associated_Node --
-------------------------
function Get_Associated_Node (N : Node_Id) return Node_Id is
Assoc : Node_Id := Associated_Node (N);
begin
if Nkind (Assoc) /= Nkind (N) then
return Assoc;
elsif Nkind (Assoc) = N_Aggregate
or else Nkind (Assoc) = N_Extension_Aggregate
then
return Assoc;
else
-- If the node is part of an inner generic, it may itself have been
-- remapped into a further generic copy. Associated_Node is otherwise
-- used for the entity of the node, and will be of a different node
-- kind, or else N has been rewritten as a literal or function call.
while Present (Associated_Node (Assoc))
and then Nkind (Associated_Node (Assoc)) = Nkind (Assoc)
loop
Assoc := Associated_Node (Assoc);
end loop;
-- Follow and additional link in case the final node was rewritten.
-- This can only happen with nested generic units.
if (Nkind (Assoc) = N_Identifier or else Nkind (Assoc) in N_Op)
and then Present (Associated_Node (Assoc))
and then (Nkind (Associated_Node (Assoc)) = N_Function_Call
or else
Nkind (Associated_Node (Assoc)) = N_Explicit_Dereference
or else
Nkind (Associated_Node (Assoc)) = N_Integer_Literal
or else
Nkind (Associated_Node (Assoc)) = N_Real_Literal
or else
Nkind (Associated_Node (Assoc)) = N_String_Literal)
then
Assoc := Associated_Node (Assoc);
end if;
return Assoc;
end if;
end Get_Associated_Node;
-------------------------------------------
-- Build_Instance_Compilation_Unit_Nodes --
-------------------------------------------
procedure Build_Instance_Compilation_Unit_Nodes
(N : Node_Id;
Act_Body : Node_Id;
Act_Decl : Node_Id)
is
Decl_Cunit : Node_Id;
Body_Cunit : Node_Id;
Citem : Node_Id;
New_Main : constant Entity_Id := Defining_Entity (Act_Decl);
Old_Main : constant Entity_Id := Cunit_Entity (Main_Unit);
begin
-- A new compilation unit node is built for the instance declaration
Decl_Cunit :=
Make_Compilation_Unit (Sloc (N),
Context_Items => Empty_List,
Unit => Act_Decl,
Aux_Decls_Node =>
Make_Compilation_Unit_Aux (Sloc (N)));
Set_Parent_Spec (Act_Decl, Parent_Spec (N));
Set_Body_Required (Decl_Cunit, True);
-- We use the original instantiation compilation unit as the resulting
-- compilation unit of the instance, since this is the main unit.
Rewrite (N, Act_Body);
Body_Cunit := Parent (N);
-- The two compilation unit nodes are linked by the Library_Unit field
Set_Library_Unit (Decl_Cunit, Body_Cunit);
Set_Library_Unit (Body_Cunit, Decl_Cunit);
-- Preserve the private nature of the package if needed
Set_Private_Present (Decl_Cunit, Private_Present (Body_Cunit));
-- If the instance is not the main unit, its context, categorization,
-- and elaboration entity are not relevant to the compilation.
if Parent (N) /= Cunit (Main_Unit) then
return;
end if;
-- The context clause items on the instantiation, which are now
-- attached to the body compilation unit (since the body overwrote
-- the original instantiation node), semantically belong on the spec,
-- so copy them there. It's harmless to leave them on the body as well.
-- In fact one could argue that they belong in both places.
Citem := First (Context_Items (Body_Cunit));
while Present (Citem) loop
Append (New_Copy (Citem), Context_Items (Decl_Cunit));
Next (Citem);
end loop;
-- Propagate categorization flags on packages, so that they appear
-- in ali file for the spec of the unit.
if Ekind (New_Main) = E_Package then
Set_Is_Pure (Old_Main, Is_Pure (New_Main));
Set_Is_Preelaborated (Old_Main, Is_Preelaborated (New_Main));
Set_Is_Remote_Types (Old_Main, Is_Remote_Types (New_Main));
Set_Is_Shared_Passive (Old_Main, Is_Shared_Passive (New_Main));
Set_Is_Remote_Call_Interface
(Old_Main, Is_Remote_Call_Interface (New_Main));
end if;
-- Make entry in Units table, so that binder can generate call to
-- elaboration procedure for body, if any.
Make_Instance_Unit (Body_Cunit);
Main_Unit_Entity := New_Main;
Set_Cunit_Entity (Main_Unit, Main_Unit_Entity);
-- Build elaboration entity, since the instance may certainly
-- generate elaboration code requiring a flag for protection.
Build_Elaboration_Entity (Decl_Cunit, New_Main);
end Build_Instance_Compilation_Unit_Nodes;
-----------------------------------
-- Check_Formal_Package_Instance --
-----------------------------------
-- If the formal has specific parameters, they must match those of the
-- actual. Both of them are instances, and the renaming declarations
-- for their formal parameters appear in the same order in both. The
-- analyzed formal has been analyzed in the context of the current
-- instance.
procedure Check_Formal_Package_Instance
(Formal_Pack : Entity_Id;
Actual_Pack : Entity_Id)
is
E1 : Entity_Id := First_Entity (Actual_Pack);
E2 : Entity_Id := First_Entity (Formal_Pack);
Expr1 : Node_Id;
Expr2 : Node_Id;
procedure Check_Mismatch (B : Boolean);
-- Common error routine for mismatch between the parameters of
-- the actual instance and those of the formal package.
function Same_Instantiated_Constant (E1, E2 : Entity_Id) return Boolean;
-- The formal may come from a nested formal package, and the actual
-- may have been constant-folded. To determine whether the two denote
-- the same entity we may have to traverse several definitions to
-- recover the ultimate entity that they refer to.
function Same_Instantiated_Variable (E1, E2 : Entity_Id) return Boolean;
-- Similarly, if the formal comes from a nested formal package, the
-- actual may designate the formal through multiple renamings, which
-- have to be followed to determine the original variable in question.
--------------------
-- Check_Mismatch --
--------------------
procedure Check_Mismatch (B : Boolean) is
begin
if B then
Error_Msg_NE
("actual for & in actual instance does not match formal",
Parent (Actual_Pack), E1);
end if;
end Check_Mismatch;
--------------------------------
-- Same_Instantiated_Constant --
--------------------------------
function Same_Instantiated_Constant
(E1, E2 : Entity_Id) return Boolean
is
Ent : Entity_Id;
begin
Ent := E2;
while Present (Ent) loop
if E1 = Ent then
return True;
elsif Ekind (Ent) /= E_Constant then
return False;
elsif Is_Entity_Name (Constant_Value (Ent)) then
if Entity (Constant_Value (Ent)) = E1 then
return True;
else
Ent := Entity (Constant_Value (Ent));
end if;
-- The actual may be a constant that has been folded. Recover
-- original name.
elsif Is_Entity_Name (Original_Node (Constant_Value (Ent))) then
Ent := Entity (Original_Node (Constant_Value (Ent)));
else
return False;
end if;
end loop;
return False;
end Same_Instantiated_Constant;
--------------------------------
-- Same_Instantiated_Variable --
--------------------------------
function Same_Instantiated_Variable
(E1, E2 : Entity_Id) return Boolean
is
function Original_Entity (E : Entity_Id) return Entity_Id;
-- Follow chain of renamings to the ultimate ancestor
---------------------
-- Original_Entity --
---------------------
function Original_Entity (E : Entity_Id) return Entity_Id is
Orig : Entity_Id;
begin
Orig := E;
while Nkind (Parent (Orig)) = N_Object_Renaming_Declaration
and then Present (Renamed_Object (Orig))
and then Is_Entity_Name (Renamed_Object (Orig))
loop
Orig := Entity (Renamed_Object (Orig));
end loop;
return Orig;
end Original_Entity;
-- Start of processing for Same_Instantiated_Variable
begin
return Ekind (E1) = Ekind (E2)
and then Original_Entity (E1) = Original_Entity (E2);
end Same_Instantiated_Variable;
-- Start of processing for Check_Formal_Package_Instance
begin
while Present (E1)
and then Present (E2)
loop
exit when Ekind (E1) = E_Package
and then Renamed_Entity (E1) = Renamed_Entity (Actual_Pack);
if Is_Type (E1) then
-- Subtypes must statically match. E1 and E2 are the
-- local entities that are subtypes of the actuals.
-- Itypes generated for other parameters need not be checked,
-- the check will be performed on the parameters themselves.
if not Is_Itype (E1)
and then not Is_Itype (E2)
then
Check_Mismatch
(not Is_Type (E2)
or else Etype (E1) /= Etype (E2)
or else not Subtypes_Statically_Match (E1, E2));
end if;
elsif Ekind (E1) = E_Constant then
-- IN parameters must denote the same static value, or
-- the same constant, or the literal null.
Expr1 := Expression (Parent (E1));
if Ekind (E2) /= E_Constant then
Check_Mismatch (True);
goto Next_E;
else
Expr2 := Expression (Parent (E2));
end if;
if Is_Static_Expression (Expr1) then
if not Is_Static_Expression (Expr2) then
Check_Mismatch (True);
elsif Is_Integer_Type (Etype (E1)) then
declare
V1 : constant Uint := Expr_Value (Expr1);
V2 : constant Uint := Expr_Value (Expr2);
begin
Check_Mismatch (V1 /= V2);
end;
elsif Is_Real_Type (Etype (E1)) then
declare
V1 : constant Ureal := Expr_Value_R (Expr1);
V2 : constant Ureal := Expr_Value_R (Expr2);
begin
Check_Mismatch (V1 /= V2);
end;
elsif Is_String_Type (Etype (E1))
and then Nkind (Expr1) = N_String_Literal
then
if Nkind (Expr2) /= N_String_Literal then
Check_Mismatch (True);
else
Check_Mismatch
(not String_Equal (Strval (Expr1), Strval (Expr2)));
end if;
end if;
elsif Is_Entity_Name (Expr1) then
if Is_Entity_Name (Expr2) then
if Entity (Expr1) = Entity (Expr2) then
null;
else
Check_Mismatch
(not Same_Instantiated_Constant
(Entity (Expr1), Entity (Expr2)));
end if;
else
Check_Mismatch (True);
end if;
elsif Is_Entity_Name (Original_Node (Expr1))
and then Is_Entity_Name (Expr2)
and then
Same_Instantiated_Constant
(Entity (Original_Node (Expr1)), Entity (Expr2))
then
null;
elsif Nkind (Expr1) = N_Null then
Check_Mismatch (Nkind (Expr1) /= N_Null);
else
Check_Mismatch (True);
end if;
elsif Ekind (E1) = E_Variable then
Check_Mismatch (not Same_Instantiated_Variable (E1, E2));
elsif Ekind (E1) = E_Package then
Check_Mismatch
(Ekind (E1) /= Ekind (E2)
or else Renamed_Object (E1) /= Renamed_Object (E2));
elsif Is_Overloadable (E1) then
-- Verify that the names of the entities match.
-- What if actual is an attribute ???
Check_Mismatch
(Ekind (E2) /= Ekind (E1) or else (Alias (E1)) /= Alias (E2));
else
raise Program_Error;
end if;
<<Next_E>>
Next_Entity (E1);
Next_Entity (E2);
end loop;
end Check_Formal_Package_Instance;
---------------------------
-- Check_Formal_Packages --
---------------------------
procedure Check_Formal_Packages (P_Id : Entity_Id) is
E : Entity_Id;
Formal_P : Entity_Id;
begin
-- Iterate through the declarations in the instance, looking for
-- package renaming declarations that denote instances of formal
-- packages. Stop when we find the renaming of the current package
-- itself. The declaration for a formal package without a box is
-- followed by an internal entity that repeats the instantiation.
E := First_Entity (P_Id);
while Present (E) loop
if Ekind (E) = E_Package then
if Renamed_Object (E) = P_Id then
exit;
elsif Nkind (Parent (E)) /= N_Package_Renaming_Declaration then
null;
elsif not Box_Present (Parent (Associated_Formal_Package (E))) then
Formal_P := Next_Entity (E);
Check_Formal_Package_Instance (Formal_P, E);
end if;
end if;
Next_Entity (E);
end loop;
end Check_Formal_Packages;
---------------------------------
-- Check_Forward_Instantiation --
---------------------------------
procedure Check_Forward_Instantiation (Decl : Node_Id) is
S : Entity_Id;
Gen_Comp : Entity_Id := Cunit_Entity (Get_Source_Unit (Decl));
begin
-- The instantiation appears before the generic body if we are in the
-- scope of the unit containing the generic, either in its spec or in
-- the package body. and before the generic body.
if Ekind (Gen_Comp) = E_Package_Body then
Gen_Comp := Spec_Entity (Gen_Comp);
end if;
if In_Open_Scopes (Gen_Comp)
and then No (Corresponding_Body (Decl))
then
S := Current_Scope;
while Present (S)
and then not Is_Compilation_Unit (S)
and then not Is_Child_Unit (S)
loop
if Ekind (S) = E_Package then
Set_Has_Forward_Instantiation (S);
end if;
S := Scope (S);
end loop;
end if;
end Check_Forward_Instantiation;
---------------------------
-- Check_Generic_Actuals --
---------------------------
-- The visibility of the actuals may be different between the
-- point of generic instantiation and the instantiation of the body.
procedure Check_Generic_Actuals
(Instance : Entity_Id;
Is_Formal_Box : Boolean)
is
E : Entity_Id;
Astype : Entity_Id;
function Denotes_Previous_Actual (Typ : Entity_Id) return Boolean;
-- For a formal that is an array type, the component type is often
-- a previous formal in the same unit. The privacy status of the
-- component type will have been examined earlier in the traversal
-- of the corresponding actuals, and this status should not be
-- modified for the array type itself.
-- To detect this case we have to rescan the list of formals, which
-- is usually short enough to ignore the resulting inefficiency.
function Denotes_Previous_Actual (Typ : Entity_Id) return Boolean is
Prev : Entity_Id;
begin
Prev := First_Entity (Instance);
while Present (Prev) loop
if Is_Type (Prev)
and then Nkind (Parent (Prev)) = N_Subtype_Declaration
and then Is_Entity_Name (Subtype_Indication (Parent (Prev)))
and then Entity (Subtype_Indication (Parent (Prev))) = Typ
then
return True;
elsif Prev = E then
return False;
else
Next_Entity (Prev);
end if;
end loop;
return False;
end Denotes_Previous_Actual;
-- Start of processing for Check_Generic_Actuals
begin
E := First_Entity (Instance);
while Present (E) loop
if Is_Type (E)
and then Nkind (Parent (E)) = N_Subtype_Declaration
and then Scope (Etype (E)) /= Instance
and then Is_Entity_Name (Subtype_Indication (Parent (E)))
then
if Is_Array_Type (E)
and then Denotes_Previous_Actual (Component_Type (E))
then
null;
else
Check_Private_View (Subtype_Indication (Parent (E)));
end if;
Set_Is_Generic_Actual_Type (E, True);
Set_Is_Hidden (E, False);
Set_Is_Potentially_Use_Visible (E,
In_Use (Instance));
-- We constructed the generic actual type as a subtype of
-- the supplied type. This means that it normally would not
-- inherit subtype specific attributes of the actual, which
-- is wrong for the generic case.
Astype := Ancestor_Subtype (E);
if No (Astype) then
-- can happen when E is an itype that is the full view of
-- a private type completed, e.g. with a constrained array.
Astype := Base_Type (E);
end if;
Set_Size_Info (E, (Astype));
Set_RM_Size (E, RM_Size (Astype));
Set_First_Rep_Item (E, First_Rep_Item (Astype));
if Is_Discrete_Or_Fixed_Point_Type (E) then
Set_RM_Size (E, RM_Size (Astype));
-- In nested instances, the base type of an access actual
-- may itself be private, and need to be exchanged.
elsif Is_Access_Type (E)
and then Is_Private_Type (Etype (E))
then
Check_Private_View
(New_Occurrence_Of (Etype (E), Sloc (Instance)));
end if;
elsif Ekind (E) = E_Package then
-- If this is the renaming for the current instance, we're done.
-- Otherwise it is a formal package. If the corresponding formal
-- was declared with a box, the (instantiations of the) generic
-- formal part are also visible. Otherwise, ignore the entity
-- created to validate the actuals.
if Renamed_Object (E) = Instance then
exit;
elsif Nkind (Parent (E)) /= N_Package_Renaming_Declaration then
null;
-- The visibility of a formal of an enclosing generic is already
-- correct.
elsif Denotes_Formal_Package (E) then
null;
elsif Present (Associated_Formal_Package (E)) then
if Box_Present (Parent (Associated_Formal_Package (E))) then
Check_Generic_Actuals (Renamed_Object (E), True);
end if;
Set_Is_Hidden (E, False);
end if;
-- If this is a subprogram instance (in a wrapper package) the
-- actual is fully visible.
elsif Is_Wrapper_Package (Instance) then
Set_Is_Hidden (E, False);
else
Set_Is_Hidden (E, not Is_Formal_Box);
end if;
Next_Entity (E);
end loop;
end Check_Generic_Actuals;
------------------------------
-- Check_Generic_Child_Unit --
------------------------------
procedure Check_Generic_Child_Unit
(Gen_Id : Node_Id;
Parent_Installed : in out Boolean)
is
Loc : constant Source_Ptr := Sloc (Gen_Id);
Gen_Par : Entity_Id := Empty;
Inst_Par : Entity_Id;
E : Entity_Id;
S : Node_Id;
function Find_Generic_Child
(Scop : Entity_Id;
Id : Node_Id) return Entity_Id;
-- Search generic parent for possible child unit with the given name
function In_Enclosing_Instance return Boolean;
-- Within an instance of the parent, the child unit may be denoted
-- by a simple name, or an abbreviated expanded name. Examine enclosing
-- scopes to locate a possible parent instantiation.
------------------------
-- Find_Generic_Child --
------------------------
function Find_Generic_Child
(Scop : Entity_Id;
Id : Node_Id) return Entity_Id
is
E : Entity_Id;
begin
-- If entity of name is already set, instance has already been
-- resolved, e.g. in an enclosing instantiation.
if Present (Entity (Id)) then
if Scope (Entity (Id)) = Scop then
return Entity (Id);
else
return Empty;
end if;
else
E := First_Entity (Scop);
while Present (E) loop
if Chars (E) = Chars (Id)
and then Is_Child_Unit (E)
then
if Is_Child_Unit (E)
and then not Is_Visible_Child_Unit (E)
then
Error_Msg_NE
("generic child unit& is not visible", Gen_Id, E);
end if;
Set_Entity (Id, E);
return E;
end if;
Next_Entity (E);
end loop;
return Empty;
end if;
end Find_Generic_Child;
---------------------------
-- In_Enclosing_Instance --
---------------------------
function In_Enclosing_Instance return Boolean is
Enclosing_Instance : Node_Id;
Instance_Decl : Node_Id;
begin
-- We do not inline any call that contains instantiations, except
-- for instantiations of Unchecked_Conversion, so if we are within
-- an inlined body the current instance does not require parents.
if In_Inlined_Body then
pragma Assert (Chars (Gen_Id) = Name_Unchecked_Conversion);
return False;
end if;
-- Loop to check enclosing scopes
Enclosing_Instance := Current_Scope;
while Present (Enclosing_Instance) loop
Instance_Decl := Unit_Declaration_Node (Enclosing_Instance);
if Ekind (Enclosing_Instance) = E_Package
and then Is_Generic_Instance (Enclosing_Instance)
and then Present
(Generic_Parent (Specification (Instance_Decl)))
then
-- Check whether the generic we are looking for is a child
-- of this instance.
E := Find_Generic_Child
(Generic_Parent (Specification (Instance_Decl)), Gen_Id);
exit when Present (E);
else
E := Empty;
end if;
Enclosing_Instance := Scope (Enclosing_Instance);
end loop;
if No (E) then
-- Not a child unit
Analyze (Gen_Id);
return False;
else
Rewrite (Gen_Id,
Make_Expanded_Name (Loc,
Chars => Chars (E),
Prefix => New_Occurrence_Of (Enclosing_Instance, Loc),
Selector_Name => New_Occurrence_Of (E, Loc)));
Set_Entity (Gen_Id, E);
Set_Etype (Gen_Id, Etype (E));
Parent_Installed := False; -- Already in scope.
return True;
end if;
end In_Enclosing_Instance;
-- Start of processing for Check_Generic_Child_Unit
begin
-- If the name of the generic is given by a selected component, it
-- may be the name of a generic child unit, and the prefix is the name
-- of an instance of the parent, in which case the child unit must be
-- visible. If this instance is not in scope, it must be placed there
-- and removed after instantiation, because what is being instantiated
-- is not the original child, but the corresponding child present in
-- the instance of the parent.
-- If the child is instantiated within the parent, it can be given by
-- a simple name. In this case the instance is already in scope, but
-- the child generic must be recovered from the generic parent as well.
if Nkind (Gen_Id) = N_Selected_Component then
S := Selector_Name (Gen_Id);
Analyze (Prefix (Gen_Id));
Inst_Par := Entity (Prefix (Gen_Id));
if Ekind (Inst_Par) = E_Package
and then Present (Renamed_Object (Inst_Par))
then
Inst_Par := Renamed_Object (Inst_Par);
end if;
if Ekind (Inst_Par) = E_Package then
if Nkind (Parent (Inst_Par)) = N_Package_Specification then
Gen_Par := Generic_Parent (Parent (Inst_Par));
elsif Nkind (Parent (Inst_Par)) = N_Defining_Program_Unit_Name
and then
Nkind (Parent (Parent (Inst_Par))) = N_Package_Specification
then
Gen_Par := Generic_Parent (Parent (Parent (Inst_Par)));
end if;
elsif Ekind (Inst_Par) = E_Generic_Package
and then Nkind (Parent (Gen_Id)) = N_Formal_Package_Declaration
then
-- A formal package may be a real child package, and not the
-- implicit instance within a parent. In this case the child is
-- not visible and has to be retrieved explicitly as well.
Gen_Par := Inst_Par;
end if;
if Present (Gen_Par) then
-- The prefix denotes an instantiation. The entity itself
-- may be a nested generic, or a child unit.
E := Find_Generic_Child (Gen_Par, S);
if Present (E) then
Change_Selected_Component_To_Expanded_Name (Gen_Id);
Set_Entity (Gen_Id, E);
Set_Etype (Gen_Id, Etype (E));
Set_Entity (S, E);
Set_Etype (S, Etype (E));
-- Indicate that this is a reference to the parent
if In_Extended_Main_Source_Unit (Gen_Id) then
Set_Is_Instantiated (Inst_Par);
end if;
-- A common mistake is to replicate the naming scheme of
-- a hierarchy by instantiating a generic child directly,
-- rather than the implicit child in a parent instance:
-- generic .. package Gpar is ..
-- generic .. package Gpar.Child is ..
-- package Par is new Gpar ();
-- with Gpar.Child;
-- package Par.Child is new Gpar.Child ();
-- rather than Par.Child
-- In this case the instantiation is within Par, which is
-- an instance, but Gpar does not denote Par because we are
-- not IN the instance of Gpar, so this is illegal. The test
-- below recognizes this particular case.
if Is_Child_Unit (E)
and then not Comes_From_Source (Entity (Prefix (Gen_Id)))
and then (not In_Instance
or else Nkind (Parent (Parent (Gen_Id))) =
N_Compilation_Unit)
then
Error_Msg_N
("prefix of generic child unit must be instance of parent",
Gen_Id);
end if;
if not In_Open_Scopes (Inst_Par)
and then Nkind (Parent (Gen_Id)) not in
N_Generic_Renaming_Declaration
then
Install_Parent (Inst_Par);
Parent_Installed := True;
end if;
else
-- If the generic parent does not contain an entity that
-- corresponds to the selector, the instance doesn't either.
-- Analyzing the node will yield the appropriate error message.
-- If the entity is not a child unit, then it is an inner
-- generic in the parent.
Analyze (Gen_Id);
end if;
else
Analyze (Gen_Id);
if Is_Child_Unit (Entity (Gen_Id))
and then
Nkind (Parent (Gen_Id)) not in N_Generic_Renaming_Declaration
and then not In_Open_Scopes (Inst_Par)
then
Install_Parent (Inst_Par);
Parent_Installed := True;
end if;
end if;
elsif Nkind (Gen_Id) = N_Expanded_Name then
-- Entity already present, analyze prefix, whose meaning may be
-- an instance in the current context. If it is an instance of
-- a relative within another, the proper parent may still have
-- to be installed, if they are not of the same generation.
Analyze (Prefix (Gen_Id));
Inst_Par := Entity (Prefix (Gen_Id));
if In_Enclosing_Instance then
null;
elsif Present (Entity (Gen_Id))
and then Is_Child_Unit (Entity (Gen_Id))
and then not In_Open_Scopes (Inst_Par)
then
Install_Parent (Inst_Par);
Parent_Installed := True;
end if;
elsif In_Enclosing_Instance then
-- The child unit is found in some enclosing scope
null;
else
Analyze (Gen_Id);
-- If this is the renaming of the implicit child in a parent
-- instance, recover the parent name and install it.
if Is_Entity_Name (Gen_Id) then
E := Entity (Gen_Id);
if Is_Generic_Unit (E)
and then Nkind (Parent (E)) in N_Generic_Renaming_Declaration
and then Is_Child_Unit (Renamed_Object (E))
and then Is_Generic_Unit (Scope (Renamed_Object (E)))
and then Nkind (Name (Parent (E))) = N_Expanded_Name
then
Rewrite (Gen_Id,
New_Copy_Tree (Name (Parent (E))));
Inst_Par := Entity (Prefix (Gen_Id));
if not In_Open_Scopes (Inst_Par) then
Install_Parent (Inst_Par);
Parent_Installed := True;
end if;
-- If it is a child unit of a non-generic parent, it may be
-- use-visible and given by a direct name. Install parent as
-- for other cases.
elsif Is_Generic_Unit (E)
and then Is_Child_Unit (E)
and then
Nkind (Parent (Gen_Id)) not in N_Generic_Renaming_Declaration
and then not Is_Generic_Unit (Scope (E))
then
if not In_Open_Scopes (Scope (E)) then
Install_Parent (Scope (E));
Parent_Installed := True;
end if;
end if;
end if;
end if;
end Check_Generic_Child_Unit;
-----------------------------
-- Check_Hidden_Child_Unit --
-----------------------------
procedure Check_Hidden_Child_Unit
(N : Node_Id;
Gen_Unit : Entity_Id;
Act_Decl_Id : Entity_Id)
is
Gen_Id : constant Node_Id := Name (N);
begin
if Is_Child_Unit (Gen_Unit)
and then Is_Child_Unit (Act_Decl_Id)
and then Nkind (Gen_Id) = N_Expanded_Name
and then Entity (Prefix (Gen_Id)) = Scope (Act_Decl_Id)
and then Chars (Gen_Unit) = Chars (Act_Decl_Id)
then
Error_Msg_Node_2 := Scope (Act_Decl_Id);
Error_Msg_NE
("generic unit & is implicitly declared in &",
Defining_Unit_Name (N), Gen_Unit);
Error_Msg_N ("\instance must have different name",
Defining_Unit_Name (N));
end if;
end Check_Hidden_Child_Unit;
------------------------
-- Check_Private_View --
------------------------
procedure Check_Private_View (N : Node_Id) is
T : constant Entity_Id := Etype (N);
BT : Entity_Id;
begin
-- Exchange views if the type was not private in the generic but is
-- private at the point of instantiation. Do not exchange views if
-- the scope of the type is in scope. This can happen if both generic
-- and instance are sibling units, or if type is defined in a parent.
-- In this case the visibility of the type will be correct for all
-- semantic checks.
if Present (T) then
BT := Base_Type (T);
if Is_Private_Type (T)
and then not Has_Private_View (N)
and then Present (Full_View (T))
and then not In_Open_Scopes (Scope (T))
then
-- In the generic, the full type was visible. Save the
-- private entity, for subsequent exchange.
Switch_View (T);
elsif Has_Private_View (N)
and then not Is_Private_Type (T)
and then not Has_Been_Exchanged (T)
and then Etype (Get_Associated_Node (N)) /= T
then
-- Only the private declaration was visible in the generic. If
-- the type appears in a subtype declaration, the subtype in the
-- instance must have a view compatible with that of its parent,
-- which must be exchanged (see corresponding code in Restore_
-- Private_Views). Otherwise, if the type is defined in a parent
-- unit, leave full visibility within instance, which is safe.
if In_Open_Scopes (Scope (Base_Type (T)))
and then not Is_Private_Type (Base_Type (T))
and then Comes_From_Source (Base_Type (T))
then
null;
elsif Nkind (Parent (N)) = N_Subtype_Declaration
or else not In_Private_Part (Scope (Base_Type (T)))
then
Prepend_Elmt (T, Exchanged_Views);
Exchange_Declarations (Etype (Get_Associated_Node (N)));
end if;
-- For composite types with inconsistent representation
-- exchange component types accordingly.
elsif Is_Access_Type (T)
and then Is_Private_Type (Designated_Type (T))
and then not Has_Private_View (N)
and then Present (Full_View (Designated_Type (T)))
then
Switch_View (Designated_Type (T));
elsif Is_Array_Type (T)
and then Is_Private_Type (Component_Type (T))
and then not Has_Private_View (N)
and then Present (Full_View (Component_Type (T)))
then
Switch_View (Component_Type (T));
elsif Is_Private_Type (T)
and then Present (Full_View (T))
and then Is_Array_Type (Full_View (T))
and then Is_Private_Type (Component_Type (Full_View (T)))
then
Switch_View (T);
-- Finally, a non-private subtype may have a private base type,
-- which must be exchanged for consistency. This can happen when
-- instantiating a package body, when the scope stack is empty
-- but in fact the subtype and the base type are declared in an
-- enclosing scope.
elsif not Is_Private_Type (T)
and then not Has_Private_View (N)
and then Is_Private_Type (Base_Type (T))
and then Present (Full_View (BT))
and then not Is_Generic_Type (BT)
and then not In_Open_Scopes (BT)
then
Prepend_Elmt (Full_View (BT), Exchanged_Views);
Exchange_Declarations (BT);
end if;
end if;
end Check_Private_View;
--------------------------
-- Contains_Instance_Of --
--------------------------
function Contains_Instance_Of
(Inner : Entity_Id;
Outer : Entity_Id;
N : Node_Id) return Boolean
is
Elmt : Elmt_Id;
Scop : Entity_Id;
begin
Scop := Outer;
-- Verify that there are no circular instantiations. We check whether
-- the unit contains an instance of the current scope or some enclosing
-- scope (in case one of the instances appears in a subunit). Longer
-- circularities involving subunits might seem too pathological to
-- consider, but they were not too pathological for the authors of
-- DEC bc30vsq, so we loop over all enclosing scopes, and mark all
-- enclosing generic scopes as containing an instance.
loop
-- Within a generic subprogram body, the scope is not generic, to
-- allow for recursive subprograms. Use the declaration to determine
-- whether this is a generic unit.
if Ekind (Scop) = E_Generic_Package
or else (Is_Subprogram (Scop)
and then Nkind (Unit_Declaration_Node (Scop)) =
N_Generic_Subprogram_Declaration)
then
Elmt := First_Elmt (Inner_Instances (Inner));
while Present (Elmt) loop
if Node (Elmt) = Scop then
Error_Msg_Node_2 := Inner;
Error_Msg_NE
("circular Instantiation: & instantiated within &!",
N, Scop);
return True;
elsif Node (Elmt) = Inner then
return True;
elsif Contains_Instance_Of (Node (Elmt), Scop, N) then
Error_Msg_Node_2 := Inner;
Error_Msg_NE
("circular Instantiation: & instantiated within &!",
N, Node (Elmt));
return True;
end if;
Next_Elmt (Elmt);
end loop;
-- Indicate that Inner is being instantiated within Scop
Append_Elmt (Inner, Inner_Instances (Scop));
end if;
if Scop = Standard_Standard then
exit;
else
Scop := Scope (Scop);
end if;
end loop;
return False;
end Contains_Instance_Of;
-----------------------
-- Copy_Generic_Node --
-----------------------
function Copy_Generic_Node
(N : Node_Id;
Parent_Id : Node_Id;
Instantiating : Boolean) return Node_Id
is
Ent : Entity_Id;
New_N : Node_Id;
function Copy_Generic_Descendant (D : Union_Id) return Union_Id;
-- Check the given value of one of the Fields referenced by the
-- current node to determine whether to copy it recursively. The
-- field may hold a Node_Id, a List_Id, or an Elist_Id, or a plain
-- value (Sloc, Uint, Char) in which case it need not be copied.
procedure Copy_Descendants;
-- Common utility for various nodes
function Copy_Generic_Elist (E : Elist_Id) return Elist_Id;
-- Make copy of element list
function Copy_Generic_List
(L : List_Id;
Parent_Id : Node_Id) return List_Id;
-- Apply Copy_Node recursively to the members of a node list
function In_Defining_Unit_Name (Nam : Node_Id) return Boolean;
-- True if an identifier is part of the defining program unit name
-- of a child unit. The entity of such an identifier must be kept
-- (for ASIS use) even though as the name of an enclosing generic
-- it would otherwise not be preserved in the generic tree.
----------------------
-- Copy_Descendants --
----------------------
procedure Copy_Descendants is
use Atree.Unchecked_Access;
-- This code section is part of the implementation of an untyped
-- tree traversal, so it needs direct access to node fields.
begin
Set_Field1 (New_N, Copy_Generic_Descendant (Field1 (N)));
Set_Field2 (New_N, Copy_Generic_Descendant (Field2 (N)));
Set_Field3 (New_N, Copy_Generic_Descendant (Field3 (N)));
Set_Field4 (New_N, Copy_Generic_Descendant (Field4 (N)));
Set_Field5 (New_N, Copy_Generic_Descendant (Field5 (N)));
end Copy_Descendants;
-----------------------------
-- Copy_Generic_Descendant --
-----------------------------
function Copy_Generic_Descendant (D : Union_Id) return Union_Id is
begin
if D = Union_Id (Empty) then
return D;
elsif D in Node_Range then
return Union_Id
(Copy_Generic_Node (Node_Id (D), New_N, Instantiating));
elsif D in List_Range then
return Union_Id (Copy_Generic_List (List_Id (D), New_N));
elsif D in Elist_Range then
return Union_Id (Copy_Generic_Elist (Elist_Id (D)));
-- Nothing else is copyable (e.g. Uint values), return as is
else
return D;
end if;
end Copy_Generic_Descendant;
------------------------
-- Copy_Generic_Elist --
------------------------
function Copy_Generic_Elist (E : Elist_Id) return Elist_Id is
M : Elmt_Id;
L : Elist_Id;
begin
if Present (E) then
L := New_Elmt_List;
M := First_Elmt (E);
while Present (M) loop
Append_Elmt
(Copy_Generic_Node (Node (M), Empty, Instantiating), L);
Next_Elmt (M);
end loop;
return L;
else
return No_Elist;
end if;
end Copy_Generic_Elist;
-----------------------
-- Copy_Generic_List --
-----------------------
function Copy_Generic_List
(L : List_Id;
Parent_Id : Node_Id) return List_Id
is
N : Node_Id;
New_L : List_Id;
begin
if Present (L) then
New_L := New_List;
Set_Parent (New_L, Parent_Id);
N := First (L);
while Present (N) loop
Append (Copy_Generic_Node (N, Empty, Instantiating), New_L);
Next (N);
end loop;
return New_L;
else
return No_List;
end if;
end Copy_Generic_List;
---------------------------
-- In_Defining_Unit_Name --
---------------------------
function In_Defining_Unit_Name (Nam : Node_Id) return Boolean is
begin
return Present (Parent (Nam))
and then (Nkind (Parent (Nam)) = N_Defining_Program_Unit_Name
or else
(Nkind (Parent (Nam)) = N_Expanded_Name
and then In_Defining_Unit_Name (Parent (Nam))));
end In_Defining_Unit_Name;
-- Start of processing for Copy_Generic_Node
begin
if N = Empty then
return N;
end if;
New_N := New_Copy (N);
if Instantiating then
Adjust_Instantiation_Sloc (New_N, S_Adjustment);
end if;
if not Is_List_Member (N) then
Set_Parent (New_N, Parent_Id);
end if;
-- If defining identifier, then all fields have been copied already
if Nkind (New_N) in N_Entity then
null;
-- Special casing for identifiers and other entity names and operators
elsif Nkind (New_N) = N_Identifier
or else Nkind (New_N) = N_Character_Literal
or else Nkind (New_N) = N_Expanded_Name
or else Nkind (New_N) = N_Operator_Symbol
or else Nkind (New_N) in N_Op
then
if not Instantiating then
-- Link both nodes in order to assign subsequently the
-- entity of the copy to the original node, in case this
-- is a global reference.
Set_Associated_Node (N, New_N);
-- If we are within an instantiation, this is a nested generic
-- that has already been analyzed at the point of definition. We
-- must preserve references that were global to the enclosing
-- parent at that point. Other occurrences, whether global or
-- local to the current generic, must be resolved anew, so we
-- reset the entity in the generic copy. A global reference has
-- a smaller depth than the parent, or else the same depth in
-- case both are distinct compilation units.
-- It is also possible for Current_Instantiated_Parent to be
-- defined, and for this not to be a nested generic, namely
-- if the unit is loaded through Rtsfind. In that case, the
-- entity of New_N is only a link to the associated node, and
-- not a defining occurrence.
-- The entities for parent units in the defining_program_unit
-- of a generic child unit are established when the context of
-- the unit is first analyzed, before the generic copy is made.
-- They are preserved in the copy for use in ASIS queries.
Ent := Entity (New_N);
if No (Current_Instantiated_Parent.Gen_Id) then
if No (Ent)
or else Nkind (Ent) /= N_Defining_Identifier
or else not In_Defining_Unit_Name (N)
then
Set_Associated_Node (New_N, Empty);
end if;
elsif No (Ent)
or else
not (Nkind (Ent) = N_Defining_Identifier
or else
Nkind (Ent) = N_Defining_Character_Literal
or else
Nkind (Ent) = N_Defining_Operator_Symbol)
or else No (Scope (Ent))
or else Scope (Ent) = Current_Instantiated_Parent.Gen_Id
or else (Scope_Depth (Scope (Ent)) >
Scope_Depth (Current_Instantiated_Parent.Gen_Id)
and then
Get_Source_Unit (Ent) =
Get_Source_Unit (Current_Instantiated_Parent.Gen_Id))
then
Set_Associated_Node (New_N, Empty);
end if;
-- Case of instantiating identifier or some other name or operator
else
-- If the associated node is still defined, the entity in
-- it is global, and must be copied to the instance.
-- If this copy is being made for a body to inline, it is
-- applied to an instantiated tree, and the entity is already
-- present and must be also preserved.
declare
Assoc : constant Node_Id := Get_Associated_Node (N);
begin
if Present (Assoc) then
if Nkind (Assoc) = Nkind (N) then
Set_Entity (New_N, Entity (Assoc));
Check_Private_View (N);
elsif Nkind (Assoc) = N_Function_Call then
Set_Entity (New_N, Entity (Name (Assoc)));
elsif (Nkind (Assoc) = N_Defining_Identifier
or else Nkind (Assoc) = N_Defining_Character_Literal
or else Nkind (Assoc) = N_Defining_Operator_Symbol)
and then Expander_Active
then
-- Inlining case: we are copying a tree that contains
-- global entities, which are preserved in the copy
-- to be used for subsequent inlining.
null;
else
Set_Entity (New_N, Empty);
end if;
end if;
end;
end if;
-- For expanded name, we must copy the Prefix and Selector_Name
if Nkind (N) = N_Expanded_Name then
Set_Prefix
(New_N, Copy_Generic_Node (Prefix (N), New_N, Instantiating));
Set_Selector_Name (New_N,
Copy_Generic_Node (Selector_Name (N), New_N, Instantiating));
-- For operators, we must copy the right operand
elsif Nkind (N) in N_Op then
Set_Right_Opnd (New_N,
Copy_Generic_Node (Right_Opnd (N), New_N, Instantiating));
-- And for binary operators, the left operand as well
if Nkind (N) in N_Binary_Op then
Set_Left_Opnd (New_N,
Copy_Generic_Node (Left_Opnd (N), New_N, Instantiating));
end if;
end if;
-- Special casing for stubs
elsif Nkind (N) in N_Body_Stub then
-- In any case, we must copy the specification or defining
-- identifier as appropriate.
if Nkind (N) = N_Subprogram_Body_Stub then
Set_Specification (New_N,
Copy_Generic_Node (Specification (N), New_N, Instantiating));
else
Set_Defining_Identifier (New_N,
Copy_Generic_Node
(Defining_Identifier (N), New_N, Instantiating));
end if;
-- If we are not instantiating, then this is where we load and
-- analyze subunits, i.e. at the point where the stub occurs. A
-- more permissivle system might defer this analysis to the point
-- of instantiation, but this seems to complicated for now.
if not Instantiating then
declare
Subunit_Name : constant Unit_Name_Type := Get_Unit_Name (N);
Subunit : Node_Id;
Unum : Unit_Number_Type;
New_Body : Node_Id;
begin
Unum :=
Load_Unit
(Load_Name => Subunit_Name,
Required => False,
Subunit => True,
Error_Node => N);
-- If the proper body is not found, a warning message will
-- be emitted when analyzing the stub, or later at the the
-- point of instantiation. Here we just leave the stub as is.
if Unum = No_Unit then
Subunits_Missing := True;
goto Subunit_Not_Found;
end if;
Subunit := Cunit (Unum);
if Nkind (Unit (Subunit)) /= N_Subunit then
Error_Msg_Sloc := Sloc (N);
Error_Msg_N
("expected SEPARATE subunit to complete stub at#,"
& " found child unit", Subunit);
goto Subunit_Not_Found;
end if;
-- We must create a generic copy of the subunit, in order
-- to perform semantic analysis on it, and we must replace
-- the stub in the original generic unit with the subunit,
-- in order to preserve non-local references within.
-- Only the proper body needs to be copied. Library_Unit and
-- context clause are simply inherited by the generic copy.
-- Note that the copy (which may be recursive if there are
-- nested subunits) must be done first, before attaching it
-- to the enclosing generic.
New_Body :=
Copy_Generic_Node
(Proper_Body (Unit (Subunit)),
Empty, Instantiating => False);
-- Now place the original proper body in the original
-- generic unit. This is a body, not a compilation unit.
Rewrite (N, Proper_Body (Unit (Subunit)));
Set_Is_Compilation_Unit (Defining_Entity (N), False);
Set_Was_Originally_Stub (N);
-- Finally replace the body of the subunit with its copy,
-- and make this new subunit into the library unit of the
-- generic copy, which does not have stubs any longer.
Set_Proper_Body (Unit (Subunit), New_Body);
Set_Library_Unit (New_N, Subunit);
Inherit_Context (Unit (Subunit), N);
end;
-- If we are instantiating, this must be an error case, since
-- otherwise we would have replaced the stub node by the proper
-- body that corresponds. So just ignore it in the copy (i.e.
-- we have copied it, and that is good enough).
else
null;
end if;
<<Subunit_Not_Found>> null;
-- If the node is a compilation unit, it is the subunit of a stub,
-- which has been loaded already (see code below). In this case,
-- the library unit field of N points to the parent unit (which
-- is a compilation unit) and need not (and cannot!) be copied.
-- When the proper body of the stub is analyzed, thie library_unit
-- link is used to establish the proper context (see sem_ch10).
-- The other fields of a compilation unit are copied as usual
elsif Nkind (N) = N_Compilation_Unit then
-- This code can only be executed when not instantiating, because
-- in the copy made for an instantiation, the compilation unit
-- node has disappeared at the point that a stub is replaced by
-- its proper body.
pragma Assert (not Instantiating);
Set_Context_Items (New_N,
Copy_Generic_List (Context_Items (N), New_N));
Set_Unit (New_N,
Copy_Generic_Node (Unit (N), New_N, False));
Set_First_Inlined_Subprogram (New_N,
Copy_Generic_Node
(First_Inlined_Subprogram (N), New_N, False));
Set_Aux_Decls_Node (New_N,
Copy_Generic_Node (Aux_Decls_Node (N), New_N, False));
-- For an assignment node, the assignment is known to be semantically
-- legal if we are instantiating the template. This avoids incorrect
-- diagnostics in generated code.
elsif Nkind (N) = N_Assignment_Statement then
-- Copy name and expression fields in usual manner
Set_Name (New_N,
Copy_Generic_Node (Name (N), New_N, Instantiating));
Set_Expression (New_N,
Copy_Generic_Node (Expression (N), New_N, Instantiating));
if Instantiating then
Set_Assignment_OK (Name (New_N), True);
end if;
elsif Nkind (N) = N_Aggregate
or else Nkind (N) = N_Extension_Aggregate
then
if not Instantiating then
Set_Associated_Node (N, New_N);
else
if Present (Get_Associated_Node (N))
and then Nkind (Get_Associated_Node (N)) = Nkind (N)
then
-- In the generic the aggregate has some composite type. If at
-- the point of instantiation the type has a private view,
-- install the full view (and that of its ancestors, if any).
declare
T : Entity_Id := (Etype (Get_Associated_Node (New_N)));
Rt : Entity_Id;
begin
if Present (T)
and then Is_Private_Type (T)
then
Switch_View (T);
end if;
if Present (T)
and then Is_Tagged_Type (T)
and then Is_Derived_Type (T)
then
Rt := Root_Type (T);
loop
T := Etype (T);
if Is_Private_Type (T) then
Switch_View (T);
end if;
exit when T = Rt;
end loop;
end if;
end;
end if;
end if;
-- Do not copy the associated node, which points to
-- the generic copy of the aggregate.
declare
use Atree.Unchecked_Access;
-- This code section is part of the implementation of an untyped
-- tree traversal, so it needs direct access to node fields.
begin
Set_Field1 (New_N, Copy_Generic_Descendant (Field1 (N)));
Set_Field2 (New_N, Copy_Generic_Descendant (Field2 (N)));
Set_Field3 (New_N, Copy_Generic_Descendant (Field3 (N)));
Set_Field5 (New_N, Copy_Generic_Descendant (Field5 (N)));
end;
-- Allocators do not have an identifier denoting the access type,
-- so we must locate it through the expression to check whether
-- the views are consistent.
elsif Nkind (N) = N_Allocator
and then Nkind (Expression (N)) = N_Qualified_Expression
and then Is_Entity_Name (Subtype_Mark (Expression (N)))
and then Instantiating
then
declare
T : constant Node_Id :=
Get_Associated_Node (Subtype_Mark (Expression (N)));
Acc_T : Entity_Id;
begin
if Present (T) then
-- Retrieve the allocator node in the generic copy
Acc_T := Etype (Parent (Parent (T)));
if Present (Acc_T)
and then Is_Private_Type (Acc_T)
then
Switch_View (Acc_T);
end if;
end if;
Copy_Descendants;
end;
-- For a proper body, we must catch the case of a proper body that
-- replaces a stub. This represents the point at which a separate
-- compilation unit, and hence template file, may be referenced, so
-- we must make a new source instantiation entry for the template
-- of the subunit, and ensure that all nodes in the subunit are
-- adjusted using this new source instantiation entry.
elsif Nkind (N) in N_Proper_Body then
declare
Save_Adjustment : constant Sloc_Adjustment := S_Adjustment;
begin
if Instantiating and then Was_Originally_Stub (N) then
Create_Instantiation_Source
(Instantiation_Node,
Defining_Entity (N),
False,
S_Adjustment);
end if;
-- Now copy the fields of the proper body, using the new
-- adjustment factor if one was needed as per test above.
Copy_Descendants;
-- Restore the original adjustment factor in case changed
S_Adjustment := Save_Adjustment;
end;
-- Don't copy Ident or Comment pragmas, since the comment belongs
-- to the generic unit, not to the instantiating unit.
elsif Nkind (N) = N_Pragma
and then Instantiating
then
declare
Prag_Id : constant Pragma_Id := Get_Pragma_Id (Chars (N));
begin
if Prag_Id = Pragma_Ident
or else Prag_Id = Pragma_Comment
then
New_N := Make_Null_Statement (Sloc (N));
else
Copy_Descendants;
end if;
end;
elsif Nkind (N) = N_Integer_Literal
or else Nkind (N) = N_Real_Literal
then
-- No descendant fields need traversing
null;
-- For the remaining nodes, copy recursively their descendants
else
Copy_Descendants;
if Instantiating
and then Nkind (N) = N_Subprogram_Body
then
Set_Generic_Parent (Specification (New_N), N);
end if;
end if;
return New_N;
end Copy_Generic_Node;
----------------------------
-- Denotes_Formal_Package --
----------------------------
function Denotes_Formal_Package
(Pack : Entity_Id;
On_Exit : Boolean := False) return Boolean
is
Par : Entity_Id;
Scop : constant Entity_Id := Scope (Pack);
E : Entity_Id;
begin
if On_Exit then
Par :=
Instance_Envs.Table
(Instance_Envs.Last).Instantiated_Parent.Act_Id;
else
Par := Current_Instantiated_Parent.Act_Id;
end if;
if Ekind (Scop) = E_Generic_Package
or else Nkind (Unit_Declaration_Node (Scop)) =
N_Generic_Subprogram_Declaration
then
return True;
elsif Nkind (Parent (Pack)) = N_Formal_Package_Declaration then
return True;
elsif No (Par) then
return False;
else
-- Check whether this package is associated with a formal
-- package of the enclosing instantiation. Iterate over the
-- list of renamings.
E := First_Entity (Par);
while Present (E) loop
if Ekind (E) /= E_Package
or else Nkind (Parent (E)) /= N_Package_Renaming_Declaration
then
null;
elsif Renamed_Object (E) = Par then
return False;
elsif Renamed_Object (E) = Pack then
return True;
end if;
Next_Entity (E);
end loop;
return False;
end if;
end Denotes_Formal_Package;
-----------------
-- End_Generic --
-----------------
procedure End_Generic is
begin
-- ??? More things could be factored out in this
-- routine. Should probably be done at a later stage.
Inside_A_Generic := Generic_Flags.Table (Generic_Flags.Last);
Generic_Flags.Decrement_Last;
Expander_Mode_Restore;
end End_Generic;
----------------------
-- Find_Actual_Type --
----------------------
function Find_Actual_Type
(Typ : Entity_Id;
Gen_Scope : Entity_Id) return Entity_Id
is
T : Entity_Id;
begin
if not Is_Child_Unit (Gen_Scope) then
return Get_Instance_Of (Typ);
elsif not Is_Generic_Type (Typ)
or else Scope (Typ) = Gen_Scope
then
return Get_Instance_Of (Typ);
else
T := Current_Entity (Typ);
while Present (T) loop
if In_Open_Scopes (Scope (T)) then
return T;
end if;
T := Homonym (T);
end loop;
return Typ;
end if;
end Find_Actual_Type;
----------------------------
-- Freeze_Subprogram_Body --
----------------------------
procedure Freeze_Subprogram_Body
(Inst_Node : Node_Id;
Gen_Body : Node_Id;
Pack_Id : Entity_Id)
is
F_Node : Node_Id;
Gen_Unit : constant Entity_Id := Get_Generic_Entity (Inst_Node);
Par : constant Entity_Id := Scope (Gen_Unit);
Enc_G : Entity_Id;
Enc_I : Node_Id;
E_G_Id : Entity_Id;
function Earlier (N1, N2 : Node_Id) return Boolean;
-- Yields True if N1 and N2 appear in the same compilation unit,
-- ignoring subunits, and if N1 is to the left of N2 in a left-to-right
-- traversal of the tree for the unit.
function Enclosing_Body (N : Node_Id) return Node_Id;
-- Find innermost package body that encloses the given node, and which
-- is not a compilation unit. Freeze nodes for the instance, or for its
-- enclosing body, may be inserted after the enclosing_body of the
-- generic unit.
function Package_Freeze_Node (B : Node_Id) return Node_Id;
-- Find entity for given package body, and locate or create a freeze
-- node for it.
function True_Parent (N : Node_Id) return Node_Id;
-- For a subunit, return parent of corresponding stub
-------------
-- Earlier --
-------------
function Earlier (N1, N2 : Node_Id) return Boolean is
D1 : Integer := 0;
D2 : Integer := 0;
P1 : Node_Id := N1;
P2 : Node_Id := N2;
procedure Find_Depth (P : in out Node_Id; D : in out Integer);
-- Find distance from given node to enclosing compilation unit
----------------
-- Find_Depth --
----------------
procedure Find_Depth (P : in out Node_Id; D : in out Integer) is
begin
while Present (P)
and then Nkind (P) /= N_Compilation_Unit
loop
P := True_Parent (P);
D := D + 1;
end loop;
end Find_Depth;
-- Start of procesing for Earlier
begin
Find_Depth (P1, D1);
Find_Depth (P2, D2);
if P1 /= P2 then
return False;
else
P1 := N1;
P2 := N2;
end if;
while D1 > D2 loop
P1 := True_Parent (P1);
D1 := D1 - 1;
end loop;
while D2 > D1 loop
P2 := True_Parent (P2);
D2 := D2 - 1;
end loop;
-- At this point P1 and P2 are at the same distance from the root.
-- We examine their parents until we find a common declarative
-- list, at which point we can establish their relative placement
-- by comparing their ultimate slocs. If we reach the root,
-- N1 and N2 do not descend from the same declarative list (e.g.
-- one is nested in the declarative part and the other is in a block
-- in the statement part) and the earlier one is already frozen.
while not Is_List_Member (P1)
or else not Is_List_Member (P2)
or else List_Containing (P1) /= List_Containing (P2)
loop
P1 := True_Parent (P1);
P2 := True_Parent (P2);
if Nkind (Parent (P1)) = N_Subunit then
P1 := Corresponding_Stub (Parent (P1));
end if;
if Nkind (Parent (P2)) = N_Subunit then
P2 := Corresponding_Stub (Parent (P2));
end if;
if P1 = P2 then
return False;
end if;
end loop;
return
Top_Level_Location (Sloc (P1)) < Top_Level_Location (Sloc (P2));
end Earlier;
--------------------
-- Enclosing_Body --
--------------------
function Enclosing_Body (N : Node_Id) return Node_Id is
P : Node_Id := Parent (N);
begin
while Present (P)
and then Nkind (Parent (P)) /= N_Compilation_Unit
loop
if Nkind (P) = N_Package_Body then
if Nkind (Parent (P)) = N_Subunit then
return Corresponding_Stub (Parent (P));
else
return P;
end if;
end if;
P := True_Parent (P);
end loop;
return Empty;
end Enclosing_Body;
-------------------------
-- Package_Freeze_Node --
-------------------------
function Package_Freeze_Node (B : Node_Id) return Node_Id is
Id : Entity_Id;
begin
if Nkind (B) = N_Package_Body then
Id := Corresponding_Spec (B);
else pragma Assert (Nkind (B) = N_Package_Body_Stub);
Id := Corresponding_Spec (Proper_Body (Unit (Library_Unit (B))));
end if;
Ensure_Freeze_Node (Id);
return Freeze_Node (Id);
end Package_Freeze_Node;
-----------------
-- True_Parent --
-----------------
function True_Parent (N : Node_Id) return Node_Id is
begin
if Nkind (Parent (N)) = N_Subunit then
return Parent (Corresponding_Stub (Parent (N)));
else
return Parent (N);
end if;
end True_Parent;
-- Start of processing of Freeze_Subprogram_Body
begin
-- If the instance and the generic body appear within the same
-- unit, and the instance preceeds the generic, the freeze node for
-- the instance must appear after that of the generic. If the generic
-- is nested within another instance I2, then current instance must
-- be frozen after I2. In both cases, the freeze nodes are those of
-- enclosing packages. Otherwise, the freeze node is placed at the end
-- of the current declarative part.
Enc_G := Enclosing_Body (Gen_Body);
Enc_I := Enclosing_Body (Inst_Node);
Ensure_Freeze_Node (Pack_Id);
F_Node := Freeze_Node (Pack_Id);
if Is_Generic_Instance (Par)
and then Present (Freeze_Node (Par))
and then
In_Same_Declarative_Part (Freeze_Node (Par), Inst_Node)
then
if ABE_Is_Certain (Get_Package_Instantiation_Node (Par)) then
-- The parent was a premature instantiation. Insert freeze
-- node at the end the current declarative part.
Insert_After_Last_Decl (Inst_Node, F_Node);
else
Insert_After (Freeze_Node (Par), F_Node);
end if;
-- The body enclosing the instance should be frozen after the body
-- that includes the generic, because the body of the instance may
-- make references to entities therein. If the two are not in the
-- same declarative part, or if the one enclosing the instance is
-- frozen already, freeze the instance at the end of the current
-- declarative part.
elsif Is_Generic_Instance (Par)
and then Present (Freeze_Node (Par))
and then Present (Enc_I)
then
if In_Same_Declarative_Part (Freeze_Node (Par), Enc_I)
or else
(Nkind (Enc_I) = N_Package_Body
and then
In_Same_Declarative_Part (Freeze_Node (Par), Parent (Enc_I)))
then
-- The enclosing package may contain several instances. Rather
-- than computing the earliest point at which to insert its
-- freeze node, we place it at the end of the declarative part
-- of the parent of the generic.
Insert_After_Last_Decl
(Freeze_Node (Par), Package_Freeze_Node (Enc_I));
end if;
Insert_After_Last_Decl (Inst_Node, F_Node);
elsif Present (Enc_G)
and then Present (Enc_I)
and then Enc_G /= Enc_I
and then Earlier (Inst_Node, Gen_Body)
then
if Nkind (Enc_G) = N_Package_Body then
E_G_Id := Corresponding_Spec (Enc_G);
else pragma Assert (Nkind (Enc_G) = N_Package_Body_Stub);
E_G_Id :=
Corresponding_Spec (Proper_Body (Unit (Library_Unit (Enc_G))));
end if;
-- Freeze package that encloses instance, and place node after
-- package that encloses generic. If enclosing package is already
-- frozen we have to assume it is at the proper place. This may
-- be a potential ABE that requires dynamic checking.
Insert_After_Last_Decl (Enc_G, Package_Freeze_Node (Enc_I));
-- Freeze enclosing subunit before instance
Ensure_Freeze_Node (E_G_Id);
if not Is_List_Member (Freeze_Node (E_G_Id)) then
Insert_After (Enc_G, Freeze_Node (E_G_Id));
end if;
Insert_After_Last_Decl (Inst_Node, F_Node);
else
-- If none of the above, insert freeze node at the end of the
-- current declarative part.
Insert_After_Last_Decl (Inst_Node, F_Node);
end if;
end Freeze_Subprogram_Body;
----------------
-- Get_Gen_Id --
----------------
function Get_Gen_Id (E : Assoc_Ptr) return Entity_Id is
begin
return Generic_Renamings.Table (E).Gen_Id;
end Get_Gen_Id;
---------------------
-- Get_Instance_Of --
---------------------
function Get_Instance_Of (A : Entity_Id) return Entity_Id is
Res : constant Assoc_Ptr := Generic_Renamings_HTable.Get (A);
begin
if Res /= Assoc_Null then
return Generic_Renamings.Table (Res).Act_Id;
else
-- On exit, entity is not instantiated: not a generic parameter,
-- or else parameter of an inner generic unit.
return A;
end if;
end Get_Instance_Of;
------------------------------------
-- Get_Package_Instantiation_Node --
------------------------------------
function Get_Package_Instantiation_Node (A : Entity_Id) return Node_Id is
Decl : Node_Id := Unit_Declaration_Node (A);
Inst : Node_Id;
begin
-- If the Package_Instantiation attribute has been set on the package
-- entity, then use it directly when it (or its Original_Node) refers
-- to an N_Package_Instantiation node. In principle it should be
-- possible to have this field set in all cases, which should be
-- investigated, and would allow this function to be significantly
-- simplified. ???
if Present (Package_Instantiation (A)) then
if Nkind (Package_Instantiation (A)) = N_Package_Instantiation then
return Package_Instantiation (A);
elsif Nkind (Original_Node (Package_Instantiation (A)))
= N_Package_Instantiation
then
return Original_Node (Package_Instantiation (A));
end if;
end if;
-- If the instantiation is a compilation unit that does not need a
-- body then the instantiation node has been rewritten as a package
-- declaration for the instance, and we return the original node.
-- If it is a compilation unit and the instance node has not been
-- rewritten, then it is still the unit of the compilation. Finally,
-- if a body is present, this is a parent of the main unit whose body
-- has been compiled for inlining purposes, and the instantiation node
-- has been rewritten with the instance body.
-- Otherwise the instantiation node appears after the declaration.
-- If the entity is a formal package, the declaration may have been
-- rewritten as a generic declaration (in the case of a formal with a
-- box) or left as a formal package declaration if it has actuals, and
-- is found with a forward search.
if Nkind (Parent (Decl)) = N_Compilation_Unit then
if Nkind (Decl) = N_Package_Declaration
and then Present (Corresponding_Body (Decl))
then
Decl := Unit_Declaration_Node (Corresponding_Body (Decl));
end if;
if Nkind (Original_Node (Decl)) = N_Package_Instantiation then
return Original_Node (Decl);
else
return Unit (Parent (Decl));
end if;
elsif Nkind (Decl) = N_Generic_Package_Declaration
and then Nkind (Original_Node (Decl)) = N_Formal_Package_Declaration
then
return Original_Node (Decl);
else
Inst := Next (Decl);
while Nkind (Inst) /= N_Package_Instantiation
and then Nkind (Inst) /= N_Formal_Package_Declaration
loop
Next (Inst);
end loop;
return Inst;
end if;
end Get_Package_Instantiation_Node;
------------------------
-- Has_Been_Exchanged --
------------------------
function Has_Been_Exchanged (E : Entity_Id) return Boolean is
Next : Elmt_Id := First_Elmt (Exchanged_Views);
begin
while Present (Next) loop
if Full_View (Node (Next)) = E then
return True;
end if;
Next_Elmt (Next);
end loop;
return False;
end Has_Been_Exchanged;
----------
-- Hash --
----------
function Hash (F : Entity_Id) return HTable_Range is
begin
return HTable_Range (F mod HTable_Size);
end Hash;
------------------------
-- Hide_Current_Scope --
------------------------
procedure Hide_Current_Scope is
C : constant Entity_Id := Current_Scope;
E : Entity_Id;
begin
Set_Is_Hidden_Open_Scope (C);
E := First_Entity (C);
while Present (E) loop
if Is_Immediately_Visible (E) then
Set_Is_Immediately_Visible (E, False);
Append_Elmt (E, Hidden_Entities);
end if;
Next_Entity (E);
end loop;
-- Make the scope name invisible as well. This is necessary, but
-- might conflict with calls to Rtsfind later on, in case the scope
-- is a predefined one. There is no clean solution to this problem, so
-- for now we depend on the user not redefining Standard itself in one
-- of the parent units.
if Is_Immediately_Visible (C)
and then C /= Standard_Standard
then
Set_Is_Immediately_Visible (C, False);
Append_Elmt (C, Hidden_Entities);
end if;
end Hide_Current_Scope;
--------------
-- Init_Env --
--------------
procedure Init_Env is
Saved : Instance_Env;
begin
Saved.Ada_Version := Ada_Version;
Saved.Ada_Version_Explicit := Ada_Version_Explicit;
Saved.Instantiated_Parent := Current_Instantiated_Parent;
Saved.Exchanged_Views := Exchanged_Views;
Saved.Hidden_Entities := Hidden_Entities;
Saved.Current_Sem_Unit := Current_Sem_Unit;
Saved.Parent_Unit_Visible := Parent_Unit_Visible;
Saved.Instance_Parent_Unit := Instance_Parent_Unit;
Instance_Envs.Increment_Last;
Instance_Envs.Table (Instance_Envs.Last) := Saved;
Exchanged_Views := New_Elmt_List;
Hidden_Entities := New_Elmt_List;
-- Make dummy entry for Instantiated parent. If generic unit is
-- legal, this is set properly in Set_Instance_Env.
Current_Instantiated_Parent :=
(Current_Scope, Current_Scope, Assoc_Null);
end Init_Env;
------------------------------
-- In_Same_Declarative_Part --
------------------------------
function In_Same_Declarative_Part
(F_Node : Node_Id;
Inst : Node_Id) return Boolean
is
Decls : constant Node_Id := Parent (F_Node);
Nod : Node_Id := Parent (Inst);
begin
while Present (Nod) loop
if Nod = Decls then
return True;
elsif Nkind (Nod) = N_Subprogram_Body
or else Nkind (Nod) = N_Package_Body
or else Nkind (Nod) = N_Task_Body
or else Nkind (Nod) = N_Protected_Body
or else Nkind (Nod) = N_Block_Statement
then
return False;
elsif Nkind (Nod) = N_Subunit then
Nod := Corresponding_Stub (Nod);
elsif Nkind (Nod) = N_Compilation_Unit then
return False;
else
Nod := Parent (Nod);
end if;
end loop;
return False;
end In_Same_Declarative_Part;
---------------------
-- In_Main_Context --
---------------------
function In_Main_Context (E : Entity_Id) return Boolean is
Context : List_Id;
Clause : Node_Id;
Nam : Node_Id;
begin
if not Is_Compilation_Unit (E)
or else Ekind (E) /= E_Package
or else In_Private_Part (E)
then
return False;
end if;
Context := Context_Items (Cunit (Main_Unit));
Clause := First (Context);
while Present (Clause) loop
if Nkind (Clause) = N_With_Clause then
Nam := Name (Clause);
-- If the current scope is part of the context of the main unit,
-- analysis of the corresponding with_clause is not complete, and
-- the entity is not set. We use the Chars field directly, which
-- might produce false positives in rare cases, but guarantees
-- that we produce all the instance bodies we will need.
if (Nkind (Nam) = N_Identifier
and then Chars (Nam) = Chars (E))
or else (Nkind (Nam) = N_Selected_Component
and then Chars (Selector_Name (Nam)) = Chars (E))
then
return True;
end if;
end if;
Next (Clause);
end loop;
return False;
end In_Main_Context;
---------------------
-- Inherit_Context --
---------------------
procedure Inherit_Context (Gen_Decl : Node_Id; Inst : Node_Id) is
Current_Context : List_Id;
Current_Unit : Node_Id;
Item : Node_Id;
New_I : Node_Id;
begin
if Nkind (Parent (Gen_Decl)) = N_Compilation_Unit then
-- The inherited context is attached to the enclosing compilation
-- unit. This is either the main unit, or the declaration for the
-- main unit (in case the instantation appears within the package
-- declaration and the main unit is its body).
Current_Unit := Parent (Inst);
while Present (Current_Unit)
and then Nkind (Current_Unit) /= N_Compilation_Unit
loop
Current_Unit := Parent (Current_Unit);
end loop;
Current_Context := Context_Items (Current_Unit);
Item := First (Context_Items (Parent (Gen_Decl)));
while Present (Item) loop
if Nkind (Item) = N_With_Clause then
New_I := New_Copy (Item);
Set_Implicit_With (New_I, True);
Append (New_I, Current_Context);
end if;
Next (Item);
end loop;
end if;
end Inherit_Context;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
Generic_Renamings.Init;
Instance_Envs.Init;
Generic_Flags.Init;
Generic_Renamings_HTable.Reset;
Circularity_Detected := False;
Exchanged_Views := No_Elist;
Hidden_Entities := No_Elist;
end Initialize;
----------------------------
-- Insert_After_Last_Decl --
----------------------------
procedure Insert_After_Last_Decl (N : Node_Id; F_Node : Node_Id) is
L : List_Id := List_Containing (N);
P : constant Node_Id := Parent (L);
begin
if not Is_List_Member (F_Node) then
if Nkind (P) = N_Package_Specification
and then L = Visible_Declarations (P)
and then Present (Private_Declarations (P))
and then not Is_Empty_List (Private_Declarations (P))
then
L := Private_Declarations (P);
end if;
Insert_After (Last (L), F_Node);
end if;
end Insert_After_Last_Decl;
------------------
-- Install_Body --
------------------
procedure Install_Body
(Act_Body : Node_Id;
N : Node_Id;
Gen_Body : Node_Id;
Gen_Decl : Node_Id)
is
Act_Id : constant Entity_Id := Corresponding_Spec (Act_Body);
Act_Unit : constant Node_Id := Unit (Cunit (Get_Source_Unit (N)));
Gen_Id : constant Entity_Id := Corresponding_Spec (Gen_Body);
Par : constant Entity_Id := Scope (Gen_Id);
Gen_Unit : constant Node_Id :=
Unit (Cunit (Get_Source_Unit (Gen_Decl)));
Orig_Body : Node_Id := Gen_Body;
F_Node : Node_Id;
Body_Unit : Node_Id;
Must_Delay : Boolean;
function Enclosing_Subp (Id : Entity_Id) return Entity_Id;
-- Find subprogram (if any) that encloses instance and/or generic body
function True_Sloc (N : Node_Id) return Source_Ptr;
-- If the instance is nested inside a generic unit, the Sloc of the
-- instance indicates the place of the original definition, not the
-- point of the current enclosing instance. Pending a better usage of
-- Slocs to indicate instantiation places, we determine the place of
-- origin of a node by finding the maximum sloc of any ancestor node.
-- Why is this not equivalent to Top_Level_Location ???
--------------------
-- Enclosing_Subp --
--------------------
function Enclosing_Subp (Id : Entity_Id) return Entity_Id is
Scop : Entity_Id := Scope (Id);
begin
while Scop /= Standard_Standard
and then not Is_Overloadable (Scop)
loop
Scop := Scope (Scop);
end loop;
return Scop;
end Enclosing_Subp;
---------------
-- True_Sloc --
---------------
function True_Sloc (N : Node_Id) return Source_Ptr is
Res : Source_Ptr;
N1 : Node_Id;
begin
Res := Sloc (N);
N1 := N;
while Present (N1) and then N1 /= Act_Unit loop
if Sloc (N1) > Res then
Res := Sloc (N1);
end if;
N1 := Parent (N1);
end loop;
return Res;
end True_Sloc;
-- Start of processing for Install_Body
begin
-- If the body is a subunit, the freeze point is the corresponding
-- stub in the current compilation, not the subunit itself.
if Nkind (Parent (Gen_Body)) = N_Subunit then
Orig_Body := Corresponding_Stub (Parent (Gen_Body));
else
Orig_Body := Gen_Body;
end if;
Body_Unit := Unit (Cunit (Get_Source_Unit (Orig_Body)));
-- If the instantiation and the generic definition appear in the
-- same package declaration, this is an early instantiation.
-- If they appear in the same declarative part, it is an early
-- instantiation only if the generic body appears textually later,
-- and the generic body is also in the main unit.
-- If instance is nested within a subprogram, and the generic body is
-- not, the instance is delayed because the enclosing body is. If
-- instance and body are within the same scope, or the same sub-
-- program body, indicate explicitly that the instance is delayed.
Must_Delay :=
(Gen_Unit = Act_Unit
and then ((Nkind (Gen_Unit) = N_Package_Declaration)
or else Nkind (Gen_Unit) = N_Generic_Package_Declaration
or else (Gen_Unit = Body_Unit
and then True_Sloc (N) < Sloc (Orig_Body)))
and then Is_In_Main_Unit (Gen_Unit)
and then (Scope (Act_Id) = Scope (Gen_Id)
or else
Enclosing_Subp (Act_Id) = Enclosing_Subp (Gen_Id)));
-- If this is an early instantiation, the freeze node is placed after
-- the generic body. Otherwise, if the generic appears in an instance,
-- we cannot freeze the current instance until the outer one is frozen.
-- This is only relevant if the current instance is nested within some
-- inner scope not itself within the outer instance. If this scope is
-- a package body in the same declarative part as the outer instance,
-- then that body needs to be frozen after the outer instance. Finally,
-- if no delay is needed, we place the freeze node at the end of the
-- current declarative part.
if Expander_Active then
Ensure_Freeze_Node (Act_Id);
F_Node := Freeze_Node (Act_Id);
if Must_Delay then
Insert_After (Orig_Body, F_Node);
elsif Is_Generic_Instance (Par)
and then Present (Freeze_Node (Par))
and then Scope (Act_Id) /= Par
then
-- Freeze instance of inner generic after instance of enclosing
-- generic.
if In_Same_Declarative_Part (Freeze_Node (Par), N) then
Insert_After (Freeze_Node (Par), F_Node);
-- Freeze package enclosing instance of inner generic after
-- instance of enclosing generic.
elsif Nkind (Parent (N)) = N_Package_Body
and then In_Same_Declarative_Part (Freeze_Node (Par), Parent (N))
then
declare
Enclosing : constant Entity_Id :=
Corresponding_Spec (Parent (N));
begin
Insert_After_Last_Decl (N, F_Node);
Ensure_Freeze_Node (Enclosing);
if not Is_List_Member (Freeze_Node (Enclosing)) then
Insert_After (Freeze_Node (Par), Freeze_Node (Enclosing));
end if;
end;
else
Insert_After_Last_Decl (N, F_Node);
end if;
else
Insert_After_Last_Decl (N, F_Node);
end if;
end if;
Set_Is_Frozen (Act_Id);
Insert_Before (N, Act_Body);
Mark_Rewrite_Insertion (Act_Body);
end Install_Body;
--------------------
-- Install_Parent --
--------------------
procedure Install_Parent (P : Entity_Id; In_Body : Boolean := False) is
Ancestors : constant Elist_Id := New_Elmt_List;
S : constant Entity_Id := Current_Scope;
Inst_Par : Entity_Id;
First_Par : Entity_Id;
Inst_Node : Node_Id;
Gen_Par : Entity_Id;
First_Gen : Entity_Id;
Elmt : Elmt_Id;
procedure Install_Formal_Packages (Par : Entity_Id);
-- If any of the formals of the parent are formal packages with box,
-- their formal parts are visible in the parent and thus in the child
-- unit as well. Analogous to what is done in Check_Generic_Actuals
-- for the unit itself.
procedure Install_Noninstance_Specs (Par : Entity_Id);
-- Install the scopes of noninstance parent units ending with Par
procedure Install_Spec (Par : Entity_Id);
-- The child unit is within the declarative part of the parent, so
-- the declarations within the parent are immediately visible.
-----------------------------
-- Install_Formal_Packages --
-----------------------------
procedure Install_Formal_Packages (Par : Entity_Id) is
E : Entity_Id;
begin
E := First_Entity (Par);
while Present (E) loop
if Ekind (E) = E_Package
and then Nkind (Parent (E)) = N_Package_Renaming_Declaration
then
-- If this is the renaming for the parent instance, done
if Renamed_Object (E) = Par then
exit;
-- The visibility of a formal of an enclosing generic is
-- already correct.
elsif Denotes_Formal_Package (E) then
null;
elsif Present (Associated_Formal_Package (E))
and then Box_Present (Parent (Associated_Formal_Package (E)))
then
Check_Generic_Actuals (Renamed_Object (E), True);
Set_Is_Hidden (E, False);
end if;
end if;
Next_Entity (E);
end loop;
end Install_Formal_Packages;
-------------------------------
-- Install_Noninstance_Specs --
-------------------------------
procedure Install_Noninstance_Specs (Par : Entity_Id) is
begin
if Present (Par)
and then Par /= Standard_Standard
and then not In_Open_Scopes (Par)
then
Install_Noninstance_Specs (Scope (Par));
Install_Spec (Par);
end if;
end Install_Noninstance_Specs;
------------------
-- Install_Spec --
------------------
procedure Install_Spec (Par : Entity_Id) is
Spec : constant Node_Id :=
Specification (Unit_Declaration_Node (Par));
begin
-- If this parent of the child instance is a top-level unit,
-- then record the unit and its visibility for later resetting
-- in Remove_Parent. We exclude units that are generic instances,
-- as we only want to record this information for the ultimate
-- top-level noninstance parent (is that always correct???).
if Scope (Par) = Standard_Standard
and then not Is_Generic_Instance (Par)
then
Parent_Unit_Visible := Is_Immediately_Visible (Par);
Instance_Parent_Unit := Par;
end if;
-- Open the parent scope and make it and its declarations visible.
-- If this point is not within a body, then only the visible
-- declarations should be made visible, and installation of the
-- private declarations is deferred until the appropriate point
-- within analysis of the spec being instantiated (see the handling
-- of parent visibility in Analyze_Package_Specification). This is
-- relaxed in the case where the parent unit is Ada.Tags, to avoid
-- private view problems that occur when compiling instantiations of
-- a generic child of that package (Generic_Dispatching_Constructor).
-- If the instance freezes a tagged type, inlinings of operations
-- from Ada.Tags may need the full view of type Tag. If inlining
-- took proper account of establishing visibility of inlined
-- subprograms' parents then it should be possible to remove this
-- special check. ???
New_Scope (Par);
Set_Is_Immediately_Visible (Par);
Install_Visible_Declarations (Par);
Set_Use (Visible_Declarations (Spec));
if In_Body or else Is_RTU (Par, Ada_Tags) then
Install_Private_Declarations (Par);
Set_Use (Private_Declarations (Spec));
end if;
end Install_Spec;
-- Start of processing for Install_Parent
begin
-- We need to install the parent instance to compile the instantiation
-- of the child, but the child instance must appear in the current
-- scope. Given that we cannot place the parent above the current
-- scope in the scope stack, we duplicate the current scope and unstack
-- both after the instantiation is complete.
-- If the parent is itself the instantiation of a child unit, we must
-- also stack the instantiation of its parent, and so on. Each such
-- ancestor is the prefix of the name in a prior instantiation.
-- If this is a nested instance, the parent unit itself resolves to
-- a renaming of the parent instance, whose declaration we need.
-- Finally, the parent may be a generic (not an instance) when the
-- child unit appears as a formal package.
Inst_Par := P;
if Present (Renamed_Entity (Inst_Par)) then
Inst_Par := Renamed_Entity (Inst_Par);
end if;
First_Par := Inst_Par;
Gen_Par :=
Generic_Parent (Specification (Unit_Declaration_Node (Inst_Par)));
First_Gen := Gen_Par;
while Present (Gen_Par)
and then Is_Child_Unit (Gen_Par)
loop
-- Load grandparent instance as well
Inst_Node := Get_Package_Instantiation_Node (Inst_Par);
if Nkind (Name (Inst_Node)) = N_Expanded_Name then
Inst_Par := Entity (Prefix (Name (Inst_Node)));
if Present (Renamed_Entity (Inst_Par)) then
Inst_Par := Renamed_Entity (Inst_Par);
end if;
Gen_Par :=
Generic_Parent
(Specification (Unit_Declaration_Node (Inst_Par)));
if Present (Gen_Par) then
Prepend_Elmt (Inst_Par, Ancestors);
else
-- Parent is not the name of an instantiation
Install_Noninstance_Specs (Inst_Par);
exit;
end if;
else
-- Previous error
exit;
end if;
end loop;
if Present (First_Gen) then
Append_Elmt (First_Par, Ancestors);
else
Install_Noninstance_Specs (First_Par);
end if;
if not Is_Empty_Elmt_List (Ancestors) then
Elmt := First_Elmt (Ancestors);
while Present (Elmt) loop
Install_Spec (Node (Elmt));
Install_Formal_Packages (Node (Elmt));
Next_Elmt (Elmt);
end loop;
end if;
if not In_Body then
New_Scope (S);
end if;
end Install_Parent;
--------------------------------
-- Instantiate_Formal_Package --
--------------------------------
function Instantiate_Formal_Package
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return List_Id
is
Loc : constant Source_Ptr := Sloc (Actual);
Actual_Pack : Entity_Id;
Formal_Pack : Entity_Id;
Gen_Parent : Entity_Id;
Decls : List_Id;
Nod : Node_Id;
Parent_Spec : Node_Id;
procedure Find_Matching_Actual
(F : Node_Id;
Act : in out Entity_Id);
-- We need to associate each formal entity in the formal package
-- with the corresponding entity in the actual package. The actual
-- package has been analyzed and possibly expanded, and as a result
-- there is no one-to-one correspondence between the two lists (for
-- example, the actual may include subtypes, itypes, and inherited
-- primitive operations, interspersed among the renaming declarations
-- for the actuals) . We retrieve the corresponding actual by name
-- because each actual has the same name as the formal, and they do
-- appear in the same order.
function Get_Formal_Entity (N : Node_Id) return Entity_Id;
-- Retrieve entity of defining entity of generic formal parameter.
-- Only the declarations of formals need to be considered when
-- linking them to actuals, but the declarative list may include
-- internal entities generated during analysis, and those are ignored.
procedure Match_Formal_Entity
(Formal_Node : Node_Id;
Formal_Ent : Entity_Id;
Actual_Ent : Entity_Id);
-- Associates the formal entity with the actual. In the case
-- where Formal_Ent is a formal package, this procedure iterates
-- through all of its formals and enters associations betwen the
-- actuals occurring in the formal package's corresponding actual
-- package (given by Actual_Ent) and the formal package's formal
-- parameters. This procedure recurses if any of the parameters is
-- itself a package.
function Is_Instance_Of
(Act_Spec : Entity_Id;
Gen_Anc : Entity_Id) return Boolean;
-- The actual can be an instantiation of a generic within another
-- instance, in which case there is no direct link from it to the
-- original generic ancestor. In that case, we recognize that the
-- ultimate ancestor is the same by examining names and scopes.
procedure Map_Entities (Form : Entity_Id; Act : Entity_Id);
-- Within the generic part, entities in the formal package are
-- visible. To validate subsequent type declarations, indicate
-- the correspondence betwen the entities in the analyzed formal,
-- and the entities in the actual package. There are three packages
-- involved in the instantiation of a formal package: the parent
-- generic P1 which appears in the generic declaration, the fake
-- instantiation P2 which appears in the analyzed generic, and whose
-- visible entities may be used in subsequent formals, and the actual
-- P3 in the instance. To validate subsequent formals, me indicate
-- that the entities in P2 are mapped into those of P3. The mapping of
-- entities has to be done recursively for nested packages.
procedure Process_Nested_Formal (Formal : Entity_Id);
-- If the current formal is declared with a box, its own formals are
-- visible in the instance, as they were in the generic, and their
-- Hidden flag must be reset. If some of these formals are themselves
-- packages declared with a box, the processing must be recursive.
--------------------------
-- Find_Matching_Actual --
--------------------------
procedure Find_Matching_Actual
(F : Node_Id;
Act : in out Entity_Id)
is
Formal_Ent : Entity_Id;
begin
case Nkind (Original_Node (F)) is
when N_Formal_Object_Declaration |
N_Formal_Type_Declaration =>
Formal_Ent := Defining_Identifier (F);
while Chars (Act) /= Chars (Formal_Ent) loop
Next_Entity (Act);
end loop;
when N_Formal_Subprogram_Declaration |
N_Formal_Package_Declaration |
N_Package_Declaration |
N_Generic_Package_Declaration =>
Formal_Ent := Defining_Entity (F);
while Chars (Act) /= Chars (Formal_Ent) loop
Next_Entity (Act);
end loop;
when others =>
raise Program_Error;
end case;
end Find_Matching_Actual;
-------------------------
-- Match_Formal_Entity --
-------------------------
procedure Match_Formal_Entity
(Formal_Node : Node_Id;
Formal_Ent : Entity_Id;
Actual_Ent : Entity_Id)
is
Act_Pkg : Entity_Id;
begin
Set_Instance_Of (Formal_Ent, Actual_Ent);
if Ekind (Actual_Ent) = E_Package then
-- Record associations for each parameter
Act_Pkg := Actual_Ent;
declare
A_Ent : Entity_Id := First_Entity (Act_Pkg);
F_Ent : Entity_Id;
F_Node : Node_Id;
Gen_Decl : Node_Id;
Formals : List_Id;
Actual : Entity_Id;
begin
-- Retrieve the actual given in the formal package declaration
Actual := Entity (Name (Original_Node (Formal_Node)));
-- The actual in the formal package declaration may be a
-- renamed generic package, in which case we want to retrieve
-- the original generic in order to traverse its formal part.
if Present (Renamed_Entity (Actual)) then
Gen_Decl := Unit_Declaration_Node (Renamed_Entity (Actual));
else
Gen_Decl := Unit_Declaration_Node (Actual);
end if;
Formals := Generic_Formal_Declarations (Gen_Decl);
if Present (Formals) then
F_Node := First_Non_Pragma (Formals);
else
F_Node := Empty;
end if;
while Present (A_Ent)
and then Present (F_Node)
and then A_Ent /= First_Private_Entity (Act_Pkg)
loop
F_Ent := Get_Formal_Entity (F_Node);
if Present (F_Ent) then
-- This is a formal of the original package. Record
-- association and recurse.
Find_Matching_Actual (F_Node, A_Ent);
Match_Formal_Entity (F_Node, F_Ent, A_Ent);
Next_Entity (A_Ent);
end if;
Next_Non_Pragma (F_Node);
end loop;
end;
end if;
end Match_Formal_Entity;
-----------------------
-- Get_Formal_Entity --
-----------------------
function Get_Formal_Entity (N : Node_Id) return Entity_Id is
Kind : constant Node_Kind := Nkind (Original_Node (N));
begin
case Kind is
when N_Formal_Object_Declaration =>
return Defining_Identifier (N);
when N_Formal_Type_Declaration =>
return Defining_Identifier (N);
when N_Formal_Subprogram_Declaration =>
return Defining_Unit_Name (Specification (N));
when N_Formal_Package_Declaration =>
return Defining_Identifier (Original_Node (N));
when N_Generic_Package_Declaration =>
return Defining_Identifier (Original_Node (N));
-- All other declarations are introduced by semantic analysis
-- and have no match in the actual.
when others =>
return Empty;
end case;
end Get_Formal_Entity;
--------------------
-- Is_Instance_Of --
--------------------
function Is_Instance_Of
(Act_Spec : Entity_Id;
Gen_Anc : Entity_Id) return Boolean
is
Gen_Par : constant Entity_Id := Generic_Parent (Act_Spec);
begin
if No (Gen_Par) then
return False;
-- Simplest case: the generic parent of the actual is the formal
elsif Gen_Par = Gen_Anc then
return True;
elsif Chars (Gen_Par) /= Chars (Gen_Anc) then
return False;
-- The actual may be obtained through several instantiations. Its
-- scope must itself be an instance of a generic declared in the
-- same scope as the formal. Any other case is detected above.
elsif not Is_Generic_Instance (Scope (Gen_Par)) then
return False;
else
return Generic_Parent (Parent (Scope (Gen_Par))) = Scope (Gen_Anc);
end if;
end Is_Instance_Of;
------------------
-- Map_Entities --
------------------
procedure Map_Entities (Form : Entity_Id; Act : Entity_Id) is
E1 : Entity_Id;
E2 : Entity_Id;
begin
Set_Instance_Of (Form, Act);
-- Traverse formal and actual package to map the corresponding
-- entities. We skip over internal entities that may be generated
-- during semantic analysis, and find the matching entities by
-- name, given that they must appear in the same order.
E1 := First_Entity (Form);
E2 := First_Entity (Act);
while Present (E1)
and then E1 /= First_Private_Entity (Form)
loop
-- Could this test be a single condition???
-- Seems like it could, and isn't FPE (Form) a constant anyway???
if not Is_Internal (E1)
and then Present (Parent (E1))
and then not Is_Class_Wide_Type (E1)
and then not Is_Internal_Name (Chars (E1))
then
while Present (E2)
and then Chars (E2) /= Chars (E1)
loop
Next_Entity (E2);
end loop;
if No (E2) then
exit;
else
Set_Instance_Of (E1, E2);
if Is_Type (E1)
and then Is_Tagged_Type (E2)
then
Set_Instance_Of
(Class_Wide_Type (E1), Class_Wide_Type (E2));
end if;
if Ekind (E1) = E_Package
and then No (Renamed_Object (E1))
then
Map_Entities (E1, E2);
end if;
end if;
end if;
Next_Entity (E1);
end loop;
end Map_Entities;
---------------------------
-- Process_Nested_Formal --
---------------------------
procedure Process_Nested_Formal (Formal : Entity_Id) is
Ent : Entity_Id;
begin
if Present (Associated_Formal_Package (Formal))
and then Box_Present (Parent (Associated_Formal_Package (Formal)))
then
Ent := First_Entity (Formal);
while Present (Ent) loop
Set_Is_Hidden (Ent, False);
Set_Is_Potentially_Use_Visible
(Ent, Is_Potentially_Use_Visible (Formal));
if Ekind (Ent) = E_Package then
exit when Renamed_Entity (Ent) = Renamed_Entity (Formal);
Process_Nested_Formal (Ent);
end if;
Next_Entity (Ent);
end loop;
end if;
end Process_Nested_Formal;
-- Start of processing for Instantiate_Formal_Package
begin
Analyze (Actual);
if not Is_Entity_Name (Actual)
or else Ekind (Entity (Actual)) /= E_Package
then
Error_Msg_N
("expect package instance to instantiate formal", Actual);
Abandon_Instantiation (Actual);
raise Program_Error;
else
Actual_Pack := Entity (Actual);
Set_Is_Instantiated (Actual_Pack);
-- The actual may be a renamed package, or an outer generic
-- formal package whose instantiation is converted into a renaming.
if Present (Renamed_Object (Actual_Pack)) then
Actual_Pack := Renamed_Object (Actual_Pack);
end if;
if Nkind (Analyzed_Formal) = N_Formal_Package_Declaration then
Gen_Parent := Get_Instance_Of (Entity (Name (Analyzed_Formal)));
Formal_Pack := Defining_Identifier (Analyzed_Formal);
else
Gen_Parent :=
Generic_Parent (Specification (Analyzed_Formal));
Formal_Pack :=
Defining_Unit_Name (Specification (Analyzed_Formal));
end if;
if Nkind (Parent (Actual_Pack)) = N_Defining_Program_Unit_Name then
Parent_Spec := Specification (Unit_Declaration_Node (Actual_Pack));
else
Parent_Spec := Parent (Actual_Pack);
end if;
if Gen_Parent = Any_Id then
Error_Msg_N
("previous error in declaration of formal package", Actual);
Abandon_Instantiation (Actual);
elsif
Is_Instance_Of (Parent_Spec, Get_Instance_Of (Gen_Parent))
then
null;
else
Error_Msg_NE
("actual parameter must be instance of&", Actual, Gen_Parent);
Abandon_Instantiation (Actual);
end if;
Set_Instance_Of (Defining_Identifier (Formal), Actual_Pack);
Map_Entities (Formal_Pack, Actual_Pack);
Nod :=
Make_Package_Renaming_Declaration (Loc,
Defining_Unit_Name => New_Copy (Defining_Identifier (Formal)),
Name => New_Reference_To (Actual_Pack, Loc));
Set_Associated_Formal_Package (Defining_Unit_Name (Nod),
Defining_Identifier (Formal));
Decls := New_List (Nod);
-- If the formal F has a box, then the generic declarations are
-- visible in the generic G. In an instance of G, the corresponding
-- entities in the actual for F (which are the actuals for the
-- instantiation of the generic that F denotes) must also be made
-- visible for analysis of the current instance. On exit from the
-- current instance, those entities are made private again. If the
-- actual is currently in use, these entities are also use-visible.
-- The loop through the actual entities also steps through the
-- formal entities and enters associations from formals to
-- actuals into the renaming map. This is necessary to properly
-- handle checking of actual parameter associations for later
-- formals that depend on actuals declared in the formal package.
if Box_Present (Formal) then
declare
Gen_Decl : constant Node_Id :=
Unit_Declaration_Node (Gen_Parent);
Formals : constant List_Id :=
Generic_Formal_Declarations (Gen_Decl);
Actual_Ent : Entity_Id;
Formal_Node : Node_Id;
Formal_Ent : Entity_Id;
begin
if Present (Formals) then
Formal_Node := First_Non_Pragma (Formals);
else
Formal_Node := Empty;
end if;
Actual_Ent := First_Entity (Actual_Pack);
while Present (Actual_Ent)
and then Actual_Ent /= First_Private_Entity (Actual_Pack)
loop
Set_Is_Hidden (Actual_Ent, False);
Set_Is_Potentially_Use_Visible
(Actual_Ent, In_Use (Actual_Pack));
if Ekind (Actual_Ent) = E_Package then
Process_Nested_Formal (Actual_Ent);
end if;
if Present (Formal_Node) then
Formal_Ent := Get_Formal_Entity (Formal_Node);
if Present (Formal_Ent) then
Find_Matching_Actual (Formal_Node, Actual_Ent);
Match_Formal_Entity
(Formal_Node, Formal_Ent, Actual_Ent);
end if;
Next_Non_Pragma (Formal_Node);
else
-- No further formals to match, but the generic
-- part may contain inherited operation that are
-- not hidden in the enclosing instance.
Next_Entity (Actual_Ent);
end if;
end loop;
end;
-- If the formal is not declared with a box, reanalyze it as
-- an instantiation, to verify the matching rules of 12.7. The
-- actual checks are performed after the generic associations
-- been analyzed.
else
declare
I_Pack : constant Entity_Id :=
Make_Defining_Identifier (Sloc (Actual),
Chars => New_Internal_Name ('P'));
begin
Set_Is_Internal (I_Pack);
Append_To (Decls,
Make_Package_Instantiation (Sloc (Actual),
Defining_Unit_Name => I_Pack,
Name => New_Occurrence_Of (Gen_Parent, Sloc (Actual)),
Generic_Associations =>
Generic_Associations (Formal)));
end;
end if;
return Decls;
end if;
end Instantiate_Formal_Package;
-----------------------------------
-- Instantiate_Formal_Subprogram --
-----------------------------------
function Instantiate_Formal_Subprogram
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return Node_Id
is
Loc : Source_Ptr := Sloc (Instantiation_Node);
Formal_Sub : constant Entity_Id :=
Defining_Unit_Name (Specification (Formal));
Analyzed_S : constant Entity_Id :=
Defining_Unit_Name (Specification (Analyzed_Formal));
Decl_Node : Node_Id;
Nam : Node_Id;
New_Spec : Node_Id;
function From_Parent_Scope (Subp : Entity_Id) return Boolean;
-- If the generic is a child unit, the parent has been installed on the
-- scope stack, but a default subprogram cannot resolve to something on
-- the parent because that parent is not really part of the visible
-- context (it is there to resolve explicit local entities). If the
-- default has resolved in this way, we remove the entity from
-- immediate visibility and analyze the node again to emit an error
-- message or find another visible candidate.
procedure Valid_Actual_Subprogram (Act : Node_Id);
-- Perform legality check and raise exception on failure
-----------------------
-- From_Parent_Scope --
-----------------------
function From_Parent_Scope (Subp : Entity_Id) return Boolean is
Gen_Scope : Node_Id := Scope (Analyzed_S);
begin
while Present (Gen_Scope)
and then Is_Child_Unit (Gen_Scope)
loop
if Scope (Subp) = Scope (Gen_Scope) then
return True;
end if;
Gen_Scope := Scope (Gen_Scope);
end loop;
return False;
end From_Parent_Scope;
-----------------------------
-- Valid_Actual_Subprogram --
-----------------------------
procedure Valid_Actual_Subprogram (Act : Node_Id) is
Act_E : Entity_Id := Empty;
begin
if Is_Entity_Name (Act) then
Act_E := Entity (Act);
elsif Nkind (Act) = N_Selected_Component
and then Is_Entity_Name (Selector_Name (Act))
then
Act_E := Entity (Selector_Name (Act));
end if;
if (Present (Act_E) and then Is_Overloadable (Act_E))
or else Nkind (Act) = N_Attribute_Reference
or else Nkind (Act) = N_Indexed_Component
or else Nkind (Act) = N_Character_Literal
or else Nkind (Act) = N_Explicit_Dereference
then
return;
end if;
Error_Msg_NE
("expect subprogram or entry name in instantiation of&",
Instantiation_Node, Formal_Sub);
Abandon_Instantiation (Instantiation_Node);
end Valid_Actual_Subprogram;
-- Start of processing for Instantiate_Formal_Subprogram
begin
New_Spec := New_Copy_Tree (Specification (Formal));
-- Create new entity for the actual (New_Copy_Tree does not)
Set_Defining_Unit_Name
(New_Spec, Make_Defining_Identifier (Loc, Chars (Formal_Sub)));
-- Find entity of actual. If the actual is an attribute reference, it
-- cannot be resolved here (its formal is missing) but is handled
-- instead in Attribute_Renaming. If the actual is overloaded, it is
-- fully resolved subsequently, when the renaming declaration for the
-- formal is analyzed. If it is an explicit dereference, resolve the
-- prefix but not the actual itself, to prevent interpretation as a
-- call.
if Present (Actual) then
Loc := Sloc (Actual);
Set_Sloc (New_Spec, Loc);
if Nkind (Actual) = N_Operator_Symbol then
Find_Direct_Name (Actual);
elsif Nkind (Actual) = N_Explicit_Dereference then
Analyze (Prefix (Actual));
elsif Nkind (Actual) /= N_Attribute_Reference then
Analyze (Actual);
end if;
Valid_Actual_Subprogram (Actual);
Nam := Actual;
elsif Present (Default_Name (Formal)) then
if Nkind (Default_Name (Formal)) /= N_Attribute_Reference
and then Nkind (Default_Name (Formal)) /= N_Selected_Component
and then Nkind (Default_Name (Formal)) /= N_Indexed_Component
and then Nkind (Default_Name (Formal)) /= N_Character_Literal
and then Present (Entity (Default_Name (Formal)))
then
Nam := New_Occurrence_Of (Entity (Default_Name (Formal)), Loc);
else
Nam := New_Copy (Default_Name (Formal));
Set_Sloc (Nam, Loc);
end if;
elsif Box_Present (Formal) then
-- Actual is resolved at the point of instantiation. Create
-- an identifier or operator with the same name as the formal.
if Nkind (Formal_Sub) = N_Defining_Operator_Symbol then
Nam := Make_Operator_Symbol (Loc,
Chars => Chars (Formal_Sub),
Strval => No_String);
else
Nam := Make_Identifier (Loc, Chars (Formal_Sub));
end if;
elsif Nkind (Specification (Formal)) = N_Procedure_Specification
and then Null_Present (Specification (Formal))
then
-- Generate null body for procedure, for use in the instance
Decl_Node :=
Make_Subprogram_Body (Loc,
Specification => New_Spec,
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Make_Null_Statement (Loc))));
Set_Is_Intrinsic_Subprogram (Defining_Unit_Name (New_Spec));
return Decl_Node;
else
Error_Msg_Sloc := Sloc (Scope (Analyzed_S));
Error_Msg_NE
("missing actual&", Instantiation_Node, Formal_Sub);
Error_Msg_NE
("\in instantiation of & declared#",
Instantiation_Node, Scope (Analyzed_S));
Abandon_Instantiation (Instantiation_Node);
end if;
Decl_Node :=
Make_Subprogram_Renaming_Declaration (Loc,
Specification => New_Spec,
Name => Nam);
-- If we do not have an actual and the formal specified <> then
-- set to get proper default.
if No (Actual) and then Box_Present (Formal) then
Set_From_Default (Decl_Node);
end if;
-- Gather possible interpretations for the actual before analyzing the
-- instance. If overloaded, it will be resolved when analyzing the
-- renaming declaration.
if Box_Present (Formal)
and then No (Actual)
then
Analyze (Nam);
if Is_Child_Unit (Scope (Analyzed_S))
and then Present (Entity (Nam))
then
if not Is_Overloaded (Nam) then
if From_Parent_Scope (Entity (Nam)) then
Set_Is_Immediately_Visible (Entity (Nam), False);
Set_Entity (Nam, Empty);
Set_Etype (Nam, Empty);
Analyze (Nam);
Set_Is_Immediately_Visible (Entity (Nam));
end if;
else
declare
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (Nam, I, It);
while Present (It.Nam) loop
if From_Parent_Scope (It.Nam) then
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
end;
end if;
end if;
end if;
-- The generic instantiation freezes the actual. This can only be
-- done once the actual is resolved, in the analysis of the renaming
-- declaration. To make the formal subprogram entity available, we set
-- Corresponding_Formal_Spec to point to the formal subprogram entity.
-- This is also needed in Analyze_Subprogram_Renaming for the processing
-- of formal abstract subprograms.
Set_Corresponding_Formal_Spec (Decl_Node, Analyzed_S);
-- We cannot analyze the renaming declaration, and thus find the
-- actual, until the all the actuals are assembled in the instance.
-- For subsequent checks of other actuals, indicate the node that
-- will hold the instance of this formal.
Set_Instance_Of (Analyzed_S, Nam);
if Nkind (Actual) = N_Selected_Component
and then Is_Task_Type (Etype (Prefix (Actual)))
and then not Is_Frozen (Etype (Prefix (Actual)))
then
-- The renaming declaration will create a body, which must appear
-- outside of the instantiation, We move the renaming declaration
-- out of the instance, and create an additional renaming inside,
-- to prevent freezing anomalies.
declare
Anon_Id : constant Entity_Id :=
Make_Defining_Identifier
(Loc, New_Internal_Name ('E'));
begin
Set_Defining_Unit_Name (New_Spec, Anon_Id);
Insert_Before (Instantiation_Node, Decl_Node);
Analyze (Decl_Node);
-- Now create renaming within the instance
Decl_Node :=
Make_Subprogram_Renaming_Declaration (Loc,
Specification => New_Copy_Tree (New_Spec),
Name => New_Occurrence_Of (Anon_Id, Loc));
Set_Defining_Unit_Name (Specification (Decl_Node),
Make_Defining_Identifier (Loc, Chars (Formal_Sub)));
end;
end if;
return Decl_Node;
end Instantiate_Formal_Subprogram;
------------------------
-- Instantiate_Object --
------------------------
function Instantiate_Object
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return List_Id
is
Formal_Id : constant Entity_Id := Defining_Identifier (Formal);
Type_Id : constant Node_Id := Subtype_Mark (Formal);
Loc : constant Source_Ptr := Sloc (Actual);
Act_Assoc : constant Node_Id := Parent (Actual);
Orig_Ftyp : constant Entity_Id :=
Etype (Defining_Identifier (Analyzed_Formal));
List : constant List_Id := New_List;
Ftyp : Entity_Id;
Decl_Node : Node_Id;
Subt_Decl : Node_Id := Empty;
begin
-- Sloc for error message on missing actual
Error_Msg_Sloc := Sloc (Scope (Defining_Identifier (Analyzed_Formal)));
if Get_Instance_Of (Formal_Id) /= Formal_Id then
Error_Msg_N ("duplicate instantiation of generic parameter", Actual);
end if;
Set_Parent (List, Parent (Actual));
-- OUT present
if Out_Present (Formal) then
-- An IN OUT generic actual must be a name. The instantiation is a
-- renaming declaration. The actual is the name being renamed. We
-- use the actual directly, rather than a copy, because it is not
-- used further in the list of actuals, and because a copy or a use
-- of relocate_node is incorrect if the instance is nested within a
-- generic. In order to simplify ASIS searches, the Generic_Parent
-- field links the declaration to the generic association.
if No (Actual) then
Error_Msg_NE
("missing actual&",
Instantiation_Node, Formal_Id);
Error_Msg_NE
("\in instantiation of & declared#",
Instantiation_Node,
Scope (Defining_Identifier (Analyzed_Formal)));
Abandon_Instantiation (Instantiation_Node);
end if;
Decl_Node :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => New_Copy (Formal_Id),
Subtype_Mark => New_Copy_Tree (Type_Id),
Name => Actual);
Set_Corresponding_Generic_Association (Decl_Node, Act_Assoc);
-- The analysis of the actual may produce insert_action nodes, so
-- the declaration must have a context in which to attach them.
Append (Decl_Node, List);
Analyze (Actual);
-- Return if the analysis of the actual reported some error
if Etype (Actual) = Any_Type then
return List;
end if;
-- This check is performed here because Analyze_Object_Renaming
-- will not check it when Comes_From_Source is False. Note
-- though that the check for the actual being the name of an
-- object will be performed in Analyze_Object_Renaming.
if Is_Object_Reference (Actual)
and then Is_Dependent_Component_Of_Mutable_Object (Actual)
then
Error_Msg_N
("illegal discriminant-dependent component for in out parameter",
Actual);
end if;
-- The actual has to be resolved in order to check that it is
-- a variable (due to cases such as F(1), where F returns
-- access to an array, and for overloaded prefixes).
Ftyp :=
Get_Instance_Of (Etype (Defining_Identifier (Analyzed_Formal)));
if Is_Private_Type (Ftyp)
and then not Is_Private_Type (Etype (Actual))
and then (Base_Type (Full_View (Ftyp)) = Base_Type (Etype (Actual))
or else Base_Type (Etype (Actual)) = Ftyp)
then
-- If the actual has the type of the full view of the formal,
-- or else a non-private subtype of the formal, then
-- the visibility of the formal type has changed. Add to the
-- actuals a subtype declaration that will force the exchange
-- of views in the body of the instance as well.
Subt_Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, New_Internal_Name ('P')),
Subtype_Indication => New_Occurrence_Of (Ftyp, Loc));
Prepend (Subt_Decl, List);
Prepend_Elmt (Full_View (Ftyp), Exchanged_Views);
Exchange_Declarations (Ftyp);
end if;
Resolve (Actual, Ftyp);
if not Is_Variable (Actual) or else Paren_Count (Actual) > 0 then
Error_Msg_NE
("actual for& must be a variable", Actual, Formal_Id);
elsif Base_Type (Ftyp) /= Base_Type (Etype (Actual)) then
Error_Msg_NE (
"type of actual does not match type of&", Actual, Formal_Id);
end if;
Note_Possible_Modification (Actual);
-- Check for instantiation of atomic/volatile actual for
-- non-atomic/volatile formal (RM C.6 (12)).
if Is_Atomic_Object (Actual)
and then not Is_Atomic (Orig_Ftyp)
then
Error_Msg_N
("cannot instantiate non-atomic formal object " &
"with atomic actual", Actual);
elsif Is_Volatile_Object (Actual)
and then not Is_Volatile (Orig_Ftyp)
then
Error_Msg_N
("cannot instantiate non-volatile formal object " &
"with volatile actual", Actual);
end if;
-- OUT not present
else
-- The instantiation of a generic formal in-parameter
-- is a constant declaration. The actual is the expression for
-- that declaration.
if Present (Actual) then
Decl_Node := Make_Object_Declaration (Loc,
Defining_Identifier => New_Copy (Formal_Id),
Constant_Present => True,
Object_Definition => New_Copy_Tree (Type_Id),
Expression => Actual);
Set_Corresponding_Generic_Association (Decl_Node, Act_Assoc);
-- A generic formal object of a tagged type is defined
-- to be aliased so the new constant must also be treated
-- as aliased.
if Is_Tagged_Type
(Etype (Defining_Identifier (Analyzed_Formal)))
then
Set_Aliased_Present (Decl_Node);
end if;
Append (Decl_Node, List);
-- No need to repeat (pre-)analysis of some expression nodes
-- already handled in Pre_Analyze_Actuals.
if Nkind (Actual) /= N_Allocator then
Analyze (Actual);
-- Return if the analysis of the actual reported some error
if Etype (Actual) = Any_Type then
return List;
end if;
end if;
declare
Typ : constant Entity_Id :=
Get_Instance_Of
(Etype (Defining_Identifier (Analyzed_Formal)));
begin
Freeze_Before (Instantiation_Node, Typ);
-- If the actual is an aggregate, perform name resolution on
-- its components (the analysis of an aggregate does not do
-- it) to capture local names that may be hidden if the
-- generic is a child unit.
if Nkind (Actual) = N_Aggregate then
Pre_Analyze_And_Resolve (Actual, Typ);
end if;
end;
elsif Present (Expression (Formal)) then
-- Use default to construct declaration
Decl_Node :=
Make_Object_Declaration (Sloc (Formal),
Defining_Identifier => New_Copy (Formal_Id),
Constant_Present => True,
Object_Definition => New_Copy (Type_Id),
Expression => New_Copy_Tree (Expression (Formal)));
Append (Decl_Node, List);
Set_Analyzed (Expression (Decl_Node), False);
else
Error_Msg_NE
("missing actual&",
Instantiation_Node, Formal_Id);
Error_Msg_NE ("\in instantiation of & declared#",
Instantiation_Node,
Scope (Defining_Identifier (Analyzed_Formal)));
if Is_Scalar_Type
(Etype (Defining_Identifier (Analyzed_Formal)))
then
-- Create dummy constant declaration so that instance can
-- be analyzed, to minimize cascaded visibility errors.
Decl_Node :=
Make_Object_Declaration (Loc,
Defining_Identifier => New_Copy (Formal_Id),
Constant_Present => True,
Object_Definition => New_Copy (Type_Id),
Expression =>
Make_Attribute_Reference (Sloc (Formal_Id),
Attribute_Name => Name_First,
Prefix => New_Copy (Type_Id)));
Append (Decl_Node, List);
else
Abandon_Instantiation (Instantiation_Node);
end if;
end if;
end if;
return List;
end Instantiate_Object;
------------------------------
-- Instantiate_Package_Body --
------------------------------
procedure Instantiate_Package_Body
(Body_Info : Pending_Body_Info;
Inlined_Body : Boolean := False)
is
Act_Decl : constant Node_Id := Body_Info.Act_Decl;
Inst_Node : constant Node_Id := Body_Info.Inst_Node;
Loc : constant Source_Ptr := Sloc (Inst_Node);
Gen_Id : constant Node_Id := Name (Inst_Node);
Gen_Unit : constant Entity_Id := Get_Generic_Entity (Inst_Node);
Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Unit);
Act_Spec : constant Node_Id := Specification (Act_Decl);
Act_Decl_Id : constant Entity_Id := Defining_Entity (Act_Spec);
Act_Body_Name : Node_Id;
Gen_Body : Node_Id;
Gen_Body_Id : Node_Id;
Act_Body : Node_Id;
Act_Body_Id : Entity_Id;
Parent_Installed : Boolean := False;
Save_Style_Check : constant Boolean := Style_Check;
begin
Gen_Body_Id := Corresponding_Body (Gen_Decl);
-- The instance body may already have been processed, as the parent
-- of another instance that is inlined. (Load_Parent_Of_Generic).
if Present (Corresponding_Body (Instance_Spec (Inst_Node))) then
return;
end if;
Expander_Mode_Save_And_Set (Body_Info.Expander_Status);
if No (Gen_Body_Id) then
Load_Parent_Of_Generic (Inst_Node, Specification (Gen_Decl));
Gen_Body_Id := Corresponding_Body (Gen_Decl);
end if;
-- Establish global variable for sloc adjustment and for error
-- recovery.
Instantiation_Node := Inst_Node;
if Present (Gen_Body_Id) then
Save_Env (Gen_Unit, Act_Decl_Id);
Style_Check := False;
Current_Sem_Unit := Body_Info.Current_Sem_Unit;
Gen_Body := Unit_Declaration_Node (Gen_Body_Id);
Create_Instantiation_Source
(Inst_Node, Gen_Body_Id, False, S_Adjustment);
Act_Body :=
Copy_Generic_Node
(Original_Node (Gen_Body), Empty, Instantiating => True);
-- Build new name (possibly qualified) for body declaration
Act_Body_Id := New_Copy (Act_Decl_Id);
-- Some attributes of the spec entity are not inherited by the
-- body entity.
Set_Handler_Records (Act_Body_Id, No_List);
if Nkind (Defining_Unit_Name (Act_Spec)) =
N_Defining_Program_Unit_Name
then
Act_Body_Name :=
Make_Defining_Program_Unit_Name (Loc,
Name => New_Copy_Tree (Name (Defining_Unit_Name (Act_Spec))),
Defining_Identifier => Act_Body_Id);
else
Act_Body_Name := Act_Body_Id;
end if;
Set_Defining_Unit_Name (Act_Body, Act_Body_Name);
Set_Corresponding_Spec (Act_Body, Act_Decl_Id);
Check_Generic_Actuals (Act_Decl_Id, False);
-- If it is a child unit, make the parent instance (which is an
-- instance of the parent of the generic) visible. The parent
-- instance is the prefix of the name of the generic unit.
if Ekind (Scope (Gen_Unit)) = E_Generic_Package
and then Nkind (Gen_Id) = N_Expanded_Name
then
Install_Parent (Entity (Prefix (Gen_Id)), In_Body => True);
Parent_Installed := True;
elsif Is_Child_Unit (Gen_Unit) then
Install_Parent (Scope (Gen_Unit), In_Body => True);
Parent_Installed := True;
end if;
-- If the instantiation is a library unit, and this is the main
-- unit, then build the resulting compilation unit nodes for the
-- instance. If this is a compilation unit but it is not the main
-- unit, then it is the body of a unit in the context, that is being
-- compiled because it is encloses some inlined unit or another
-- generic unit being instantiated. In that case, this body is not
-- part of the current compilation, and is not attached to the tree,
-- but its parent must be set for analysis.
if Nkind (Parent (Inst_Node)) = N_Compilation_Unit then
-- Replace instance node with body of instance, and create
-- new node for corresponding instance declaration.
Build_Instance_Compilation_Unit_Nodes
(Inst_Node, Act_Body, Act_Decl);
Analyze (Inst_Node);
if Parent (Inst_Node) = Cunit (Main_Unit) then
-- If the instance is a child unit itself, then set the
-- scope of the expanded body to be the parent of the
-- instantiation (ensuring that the fully qualified name
-- will be generated for the elaboration subprogram).
if Nkind (Defining_Unit_Name (Act_Spec)) =
N_Defining_Program_Unit_Name
then
Set_Scope
(Defining_Entity (Inst_Node), Scope (Act_Decl_Id));
end if;
end if;
-- Case where instantiation is not a library unit
else
-- If this is an early instantiation, i.e. appears textually
-- before the corresponding body and must be elaborated first,
-- indicate that the body instance is to be delayed.
Install_Body (Act_Body, Inst_Node, Gen_Body, Gen_Decl);
-- Now analyze the body. We turn off all checks if this is
-- an internal unit, since there is no reason to have checks
-- on for any predefined run-time library code. All such
-- code is designed to be compiled with checks off.
-- Note that we do NOT apply this criterion to children of
-- GNAT (or on VMS, children of DEC). The latter units must
-- suppress checks explicitly if this is needed.
if Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (Gen_Decl)))
then
Analyze (Act_Body, Suppress => All_Checks);
else
Analyze (Act_Body);
end if;
end if;
if not Generic_Separately_Compiled (Gen_Unit) then
Inherit_Context (Gen_Body, Inst_Node);
end if;
-- Remove the parent instances if they have been placed on the
-- scope stack to compile the body.
if Parent_Installed then
Remove_Parent (In_Body => True);
end if;
Restore_Private_Views (Act_Decl_Id);
-- Remove the current unit from visibility if this is an instance
-- that is not elaborated on the fly for inlining purposes.
if not Inlined_Body then
Set_Is_Immediately_Visible (Act_Decl_Id, False);
end if;
Restore_Env;
Style_Check := Save_Style_Check;
-- If we have no body, and the unit requires a body, then complain.
-- This complaint is suppressed if we have detected other errors
-- (since a common reason for missing the body is that it had errors).
elsif Unit_Requires_Body (Gen_Unit) then
if Serious_Errors_Detected = 0 then
Error_Msg_NE
("cannot find body of generic package &", Inst_Node, Gen_Unit);
-- Don't attempt to perform any cleanup actions if some other
-- error was aready detected, since this can cause blowups.
else
return;
end if;
-- Case of package that does not need a body
else
-- If the instantiation of the declaration is a library unit,
-- rewrite the original package instantiation as a package
-- declaration in the compilation unit node.
if Nkind (Parent (Inst_Node)) = N_Compilation_Unit then
Set_Parent_Spec (Act_Decl, Parent_Spec (Inst_Node));
Rewrite (Inst_Node, Act_Decl);
-- Generate elaboration entity, in case spec has elaboration
-- code. This cannot be done when the instance is analyzed,
-- because it is not known yet whether the body exists.
Set_Elaboration_Entity_Required (Act_Decl_Id, False);
Build_Elaboration_Entity (Parent (Inst_Node), Act_Decl_Id);
-- If the instantiation is not a library unit, then append the
-- declaration to the list of implicitly generated entities.
-- unless it is already a list member which means that it was
-- already processed
elsif not Is_List_Member (Act_Decl) then
Mark_Rewrite_Insertion (Act_Decl);
Insert_Before (Inst_Node, Act_Decl);
end if;
end if;
Expander_Mode_Restore;
end Instantiate_Package_Body;
---------------------------------
-- Instantiate_Subprogram_Body --
---------------------------------
procedure Instantiate_Subprogram_Body
(Body_Info : Pending_Body_Info)
is
Act_Decl : constant Node_Id := Body_Info.Act_Decl;
Inst_Node : constant Node_Id := Body_Info.Inst_Node;
Loc : constant Source_Ptr := Sloc (Inst_Node);
Gen_Id : constant Node_Id := Name (Inst_Node);
Gen_Unit : constant Entity_Id := Get_Generic_Entity (Inst_Node);
Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Unit);
Anon_Id : constant Entity_Id :=
Defining_Unit_Name (Specification (Act_Decl));
Pack_Id : constant Entity_Id :=
Defining_Unit_Name (Parent (Act_Decl));
Decls : List_Id;
Gen_Body : Node_Id;
Gen_Body_Id : Node_Id;
Act_Body : Node_Id;
Act_Body_Id : Entity_Id;
Pack_Body : Node_Id;
Prev_Formal : Entity_Id;
Ret_Expr : Node_Id;
Unit_Renaming : Node_Id;
Parent_Installed : Boolean := False;
Save_Style_Check : constant Boolean := Style_Check;
begin
Gen_Body_Id := Corresponding_Body (Gen_Decl);
Expander_Mode_Save_And_Set (Body_Info.Expander_Status);
if No (Gen_Body_Id) then
Load_Parent_Of_Generic (Inst_Node, Specification (Gen_Decl));
Gen_Body_Id := Corresponding_Body (Gen_Decl);
end if;
Instantiation_Node := Inst_Node;
if Present (Gen_Body_Id) then
Gen_Body := Unit_Declaration_Node (Gen_Body_Id);
if Nkind (Gen_Body) = N_Subprogram_Body_Stub then
-- Either body is not present, or context is non-expanding, as
-- when compiling a subunit. Mark the instance as completed, and
-- diagnose a missing body when needed.
if Expander_Active
and then Operating_Mode = Generate_Code
then
Error_Msg_N
("missing proper body for instantiation", Gen_Body);
end if;
Set_Has_Completion (Anon_Id);
return;
end if;
Save_Env (Gen_Unit, Anon_Id);
Style_Check := False;
Current_Sem_Unit := Body_Info.Current_Sem_Unit;
Create_Instantiation_Source
(Inst_Node,
Gen_Body_Id,
False,
S_Adjustment);
Act_Body :=
Copy_Generic_Node
(Original_Node (Gen_Body), Empty, Instantiating => True);
Act_Body_Id := Defining_Entity (Act_Body);
Set_Chars (Act_Body_Id, Chars (Anon_Id));
Set_Sloc (Act_Body_Id, Sloc (Defining_Entity (Inst_Node)));
Set_Corresponding_Spec (Act_Body, Anon_Id);
Set_Has_Completion (Anon_Id);
Check_Generic_Actuals (Pack_Id, False);
-- If it is a child unit, make the parent instance (which is an
-- instance of the parent of the generic) visible. The parent
-- instance is the prefix of the name of the generic unit.
if Ekind (Scope (Gen_Unit)) = E_Generic_Package
and then Nkind (Gen_Id) = N_Expanded_Name
then
Install_Parent (Entity (Prefix (Gen_Id)), In_Body => True);
Parent_Installed := True;
elsif Is_Child_Unit (Gen_Unit) then
Install_Parent (Scope (Gen_Unit), In_Body => True);
Parent_Installed := True;
end if;
-- Inside its body, a reference to the generic unit is a reference
-- to the instance. The corresponding renaming is the first
-- declaration in the body.
Unit_Renaming :=
Make_Subprogram_Renaming_Declaration (Loc,
Specification =>
Copy_Generic_Node (
Specification (Original_Node (Gen_Body)),
Empty,
Instantiating => True),
Name => New_Occurrence_Of (Anon_Id, Loc));
-- If there is a formal subprogram with the same name as the
-- unit itself, do not add this renaming declaration. This is
-- a temporary fix for one ACVC test. ???
Prev_Formal := First_Entity (Pack_Id);
while Present (Prev_Formal) loop
if Chars (Prev_Formal) = Chars (Gen_Unit)
and then Is_Overloadable (Prev_Formal)
then
exit;
end if;
Next_Entity (Prev_Formal);
end loop;
if Present (Prev_Formal) then
Decls := New_List (Act_Body);
else
Decls := New_List (Unit_Renaming, Act_Body);
end if;
-- The subprogram body is placed in the body of a dummy package
-- body, whose spec contains the subprogram declaration as well
-- as the renaming declarations for the generic parameters.
Pack_Body := Make_Package_Body (Loc,
Defining_Unit_Name => New_Copy (Pack_Id),
Declarations => Decls);
Set_Corresponding_Spec (Pack_Body, Pack_Id);
-- If the instantiation is a library unit, then build resulting
-- compilation unit nodes for the instance. The declaration of
-- the enclosing package is the grandparent of the subprogram
-- declaration. First replace the instantiation node as the unit
-- of the corresponding compilation.
if Nkind (Parent (Inst_Node)) = N_Compilation_Unit then
if Parent (Inst_Node) = Cunit (Main_Unit) then
Set_Unit (Parent (Inst_Node), Inst_Node);
Build_Instance_Compilation_Unit_Nodes
(Inst_Node, Pack_Body, Parent (Parent (Act_Decl)));
Analyze (Inst_Node);
else
Set_Parent (Pack_Body, Parent (Inst_Node));
Analyze (Pack_Body);
end if;
else
Insert_Before (Inst_Node, Pack_Body);
Mark_Rewrite_Insertion (Pack_Body);
Analyze (Pack_Body);
if Expander_Active then
Freeze_Subprogram_Body (Inst_Node, Gen_Body, Pack_Id);
end if;
end if;
if not Generic_Separately_Compiled (Gen_Unit) then
Inherit_Context (Gen_Body, Inst_Node);
end if;
Restore_Private_Views (Pack_Id, False);
if Parent_Installed then
Remove_Parent (In_Body => True);
end if;
Restore_Env;
Style_Check := Save_Style_Check;
-- Body not found. Error was emitted already. If there were no
-- previous errors, this may be an instance whose scope is a premature
-- instance. In that case we must insure that the (legal) program does
-- raise program error if executed. We generate a subprogram body for
-- this purpose. See DEC ac30vso.
elsif Serious_Errors_Detected = 0
and then Nkind (Parent (Inst_Node)) /= N_Compilation_Unit
then
if Ekind (Anon_Id) = E_Procedure then
Act_Body :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc, Chars (Anon_Id)),
Parameter_Specifications =>
New_Copy_List
(Parameter_Specifications (Parent (Anon_Id)))),
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements =>
New_List (
Make_Raise_Program_Error (Loc,
Reason =>
PE_Access_Before_Elaboration))));
else
Ret_Expr :=
Make_Raise_Program_Error (Loc,
Reason => PE_Access_Before_Elaboration);
Set_Etype (Ret_Expr, (Etype (Anon_Id)));
Set_Analyzed (Ret_Expr);
Act_Body :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc, Chars (Anon_Id)),
Parameter_Specifications =>
New_Copy_List
(Parameter_Specifications (Parent (Anon_Id))),
Result_Definition =>
New_Occurrence_Of (Etype (Anon_Id), Loc)),
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements =>
New_List (Make_Return_Statement (Loc, Ret_Expr))));
end if;
Pack_Body := Make_Package_Body (Loc,
Defining_Unit_Name => New_Copy (Pack_Id),
Declarations => New_List (Act_Body));
Insert_After (Inst_Node, Pack_Body);
Set_Corresponding_Spec (Pack_Body, Pack_Id);
Analyze (Pack_Body);
end if;
Expander_Mode_Restore;
end Instantiate_Subprogram_Body;
----------------------
-- Instantiate_Type --
----------------------
function Instantiate_Type
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id;
Actual_Decls : List_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Actual);
Gen_T : constant Entity_Id := Defining_Identifier (Formal);
A_Gen_T : constant Entity_Id := Defining_Identifier (Analyzed_Formal);
Ancestor : Entity_Id := Empty;
Def : constant Node_Id := Formal_Type_Definition (Formal);
Act_T : Entity_Id;
Decl_Node : Node_Id;
procedure Validate_Array_Type_Instance;
procedure Validate_Access_Subprogram_Instance;
procedure Validate_Access_Type_Instance;
procedure Validate_Derived_Type_Instance;
procedure Validate_Derived_Interface_Type_Instance;
procedure Validate_Interface_Type_Instance;
procedure Validate_Private_Type_Instance;
-- These procedures perform validation tests for the named case
function Subtypes_Match (Gen_T, Act_T : Entity_Id) return Boolean;
-- Check that base types are the same and that the subtypes match
-- statically. Used in several of the above.
--------------------
-- Subtypes_Match --
--------------------
function Subtypes_Match (Gen_T, Act_T : Entity_Id) return Boolean is
T : constant Entity_Id := Get_Instance_Of (Gen_T);
begin
return (Base_Type (T) = Base_Type (Act_T)
and then Subtypes_Statically_Match (T, Act_T))
or else (Is_Class_Wide_Type (Gen_T)
and then Is_Class_Wide_Type (Act_T)
and then
Subtypes_Match
(Get_Instance_Of (Root_Type (Gen_T)),
Root_Type (Act_T)))
or else
((Ekind (Gen_T) = E_Anonymous_Access_Subprogram_Type
or else Ekind (Gen_T) = E_Anonymous_Access_Type)
and then Ekind (Act_T) = Ekind (Gen_T)
and then
Subtypes_Statically_Match
(Designated_Type (Gen_T), Designated_Type (Act_T)));
end Subtypes_Match;
-----------------------------------------
-- Validate_Access_Subprogram_Instance --
-----------------------------------------
procedure Validate_Access_Subprogram_Instance is
begin
if not Is_Access_Type (Act_T)
or else Ekind (Designated_Type (Act_T)) /= E_Subprogram_Type
then
Error_Msg_NE
("expect access type in instantiation of &", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
Check_Mode_Conformant
(Designated_Type (Act_T),
Designated_Type (A_Gen_T),
Actual,
Get_Inst => True);
if Ekind (Base_Type (Act_T)) = E_Access_Protected_Subprogram_Type then
if Ekind (A_Gen_T) = E_Access_Subprogram_Type then
Error_Msg_NE
("protected access type not allowed for formal &",
Actual, Gen_T);
end if;
elsif Ekind (A_Gen_T) = E_Access_Protected_Subprogram_Type then
Error_Msg_NE
("expect protected access type for formal &",
Actual, Gen_T);
end if;
end Validate_Access_Subprogram_Instance;
-----------------------------------
-- Validate_Access_Type_Instance --
-----------------------------------
procedure Validate_Access_Type_Instance is
Desig_Type : constant Entity_Id :=
Find_Actual_Type
(Designated_Type (A_Gen_T), Scope (A_Gen_T));
begin
if not Is_Access_Type (Act_T) then
Error_Msg_NE
("expect access type in instantiation of &", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
if Is_Access_Constant (A_Gen_T) then
if not Is_Access_Constant (Act_T) then
Error_Msg_N
("actual type must be access-to-constant type", Actual);
Abandon_Instantiation (Actual);
end if;
else
if Is_Access_Constant (Act_T) then
Error_Msg_N
("actual type must be access-to-variable type", Actual);
Abandon_Instantiation (Actual);
elsif Ekind (A_Gen_T) = E_General_Access_Type
and then Ekind (Base_Type (Act_T)) /= E_General_Access_Type
then
Error_Msg_N ("actual must be general access type!", Actual);
Error_Msg_NE ("add ALL to }!", Actual, Act_T);
Abandon_Instantiation (Actual);
end if;
end if;
-- The designated subtypes, that is to say the subtypes introduced
-- by an access type declaration (and not by a subtype declaration)
-- must match.
if not Subtypes_Match
(Desig_Type, Designated_Type (Base_Type (Act_T)))
then
Error_Msg_NE
("designated type of actual does not match that of formal &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
elsif Is_Access_Type (Designated_Type (Act_T))
and then Is_Constrained (Designated_Type (Designated_Type (Act_T)))
/=
Is_Constrained (Designated_Type (Desig_Type))
then
Error_Msg_NE
("designated type of actual does not match that of formal &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
end Validate_Access_Type_Instance;
----------------------------------
-- Validate_Array_Type_Instance --
----------------------------------
procedure Validate_Array_Type_Instance is
I1 : Node_Id;
I2 : Node_Id;
T2 : Entity_Id;
function Formal_Dimensions return Int;
-- Count number of dimensions in array type formal
-----------------------
-- Formal_Dimensions --
-----------------------
function Formal_Dimensions return Int is
Num : Int := 0;
Index : Node_Id;
begin
if Nkind (Def) = N_Constrained_Array_Definition then
Index := First (Discrete_Subtype_Definitions (Def));
else
Index := First (Subtype_Marks (Def));
end if;
while Present (Index) loop
Num := Num + 1;
Next_Index (Index);
end loop;
return Num;
end Formal_Dimensions;
-- Start of processing for Validate_Array_Type_Instance
begin
if not Is_Array_Type (Act_T) then
Error_Msg_NE
("expect array type in instantiation of &", Actual, Gen_T);
Abandon_Instantiation (Actual);
elsif Nkind (Def) = N_Constrained_Array_Definition then
if not (Is_Constrained (Act_T)) then
Error_Msg_NE
("expect constrained array in instantiation of &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
else
if Is_Constrained (Act_T) then
Error_Msg_NE
("expect unconstrained array in instantiation of &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
end if;
if Formal_Dimensions /= Number_Dimensions (Act_T) then
Error_Msg_NE
("dimensions of actual do not match formal &", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
I1 := First_Index (A_Gen_T);
I2 := First_Index (Act_T);
for J in 1 .. Formal_Dimensions loop
-- If the indices of the actual were given by a subtype_mark,
-- the index was transformed into a range attribute. Retrieve
-- the original type mark for checking.
if Is_Entity_Name (Original_Node (I2)) then
T2 := Entity (Original_Node (I2));
else
T2 := Etype (I2);
end if;
if not Subtypes_Match
(Find_Actual_Type (Etype (I1), Scope (A_Gen_T)), T2)
then
Error_Msg_NE
("index types of actual do not match those of formal &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
Next_Index (I1);
Next_Index (I2);
end loop;
if not Subtypes_Match (
Find_Actual_Type (Component_Type (A_Gen_T), Scope (A_Gen_T)),
Component_Type (Act_T))
then
Error_Msg_NE
("component subtype of actual does not match that of formal &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
if Has_Aliased_Components (A_Gen_T)
and then not Has_Aliased_Components (Act_T)
then
Error_Msg_NE
("actual must have aliased components to match formal type &",
Actual, Gen_T);
end if;
end Validate_Array_Type_Instance;
-----------------------------------------------
-- Validate_Derived_Interface_Type_Instance --
-----------------------------------------------
procedure Validate_Derived_Interface_Type_Instance is
Par : constant Entity_Id := Entity (Subtype_Indication (Def));
Elmt : Elmt_Id;
begin
-- First apply interface instance checks
Validate_Interface_Type_Instance;
-- Verify that immediate parent interface is an ancestor of
-- the actual.
if Present (Par)
and then not Interface_Present_In_Ancestor (Act_T, Par)
then
Error_Msg_NE
("interface actual must include progenitor&", Actual, Par);
end if;
-- Now verify that the actual includes all other ancestors of
-- the formal.
Elmt := First_Elmt (Abstract_Interfaces (A_Gen_T));
while Present (Elmt) loop
if not Interface_Present_In_Ancestor (Act_T, Node (Elmt)) then
Error_Msg_NE
("interface actual must include progenitor&",
Actual, Node (Elmt));
end if;
Next_Elmt (Elmt);
end loop;
end Validate_Derived_Interface_Type_Instance;
------------------------------------
-- Validate_Derived_Type_Instance --
------------------------------------
procedure Validate_Derived_Type_Instance is
Actual_Discr : Entity_Id;
Ancestor_Discr : Entity_Id;
begin
-- If the parent type in the generic declaration is itself a previous
-- formal type, then it is local to the generic and absent from the
-- analyzed generic definition. In that case the ancestor is the
-- instance of the formal (which must have been instantiated
-- previously), unless the ancestor is itself a formal derived type.
-- In this latter case (which is the subject of Corrigendum 8652/0038
-- (AI-202) the ancestor of the formals is the ancestor of its
-- parent. Otherwise, the analyzed generic carries the parent type.
-- If the parent type is defined in a previous formal package, then
-- the scope of that formal package is that of the generic type
-- itself, and it has already been mapped into the corresponding type
-- in the actual package.
-- Common case: parent type defined outside of the generic
if Is_Entity_Name (Subtype_Mark (Def))
and then Present (Entity (Subtype_Mark (Def)))
then
Ancestor := Get_Instance_Of (Entity (Subtype_Mark (Def)));
-- Check whether parent is defined in a previous formal package
elsif
Scope (Scope (Base_Type (Etype (A_Gen_T)))) = Scope (A_Gen_T)
then
Ancestor :=
Get_Instance_Of (Base_Type (Etype (A_Gen_T)));
-- The type may be a local derivation, or a type extension of
-- a previous formal, or of a formal of a parent package.
elsif Is_Derived_Type (Get_Instance_Of (A_Gen_T))
or else
Ekind (Get_Instance_Of (A_Gen_T)) = E_Record_Type_With_Private
then
-- Check whether the parent is another derived formal type
-- in the same generic unit.
if Etype (A_Gen_T) /= A_Gen_T
and then Is_Generic_Type (Etype (A_Gen_T))
and then Scope (Etype (A_Gen_T)) = Scope (A_Gen_T)
and then Etype (Etype (A_Gen_T)) /= Etype (A_Gen_T)
then
-- Locate ancestor of parent from the subtype declaration
-- created for the actual.
declare
Decl : Node_Id;
begin
Decl := First (Actual_Decls);
while Present (Decl) loop
if Nkind (Decl) = N_Subtype_Declaration
and then Chars (Defining_Identifier (Decl)) =
Chars (Etype (A_Gen_T))
then
Ancestor := Generic_Parent_Type (Decl);
exit;
else
Next (Decl);
end if;
end loop;
end;
pragma Assert (Present (Ancestor));
else
Ancestor :=
Get_Instance_Of (Base_Type (Get_Instance_Of (A_Gen_T)));
end if;
else
Ancestor := Get_Instance_Of (Etype (Base_Type (A_Gen_T)));
end if;
-- Ada 2005 (AI-251)
if Ada_Version >= Ada_05
and then Is_Interface (Ancestor)
then
if not Interface_Present_In_Ancestor (Act_T, Ancestor) then
Error_Msg_NE
("(Ada 2005) expected type implementing & in instantiation",
Actual, Ancestor);
end if;
elsif not Is_Ancestor (Base_Type (Ancestor), Act_T) then
Error_Msg_NE
("expect type derived from & in instantiation",
Actual, First_Subtype (Ancestor));
Abandon_Instantiation (Actual);
end if;
-- Perform atomic/volatile checks (RM C.6(12))
if Is_Atomic (Act_T) and then not Is_Atomic (Ancestor) then
Error_Msg_N
("cannot have atomic actual type for non-atomic formal type",
Actual);
elsif Is_Volatile (Act_T)
and then not Is_Volatile (Ancestor)
and then Is_By_Reference_Type (Ancestor)
then
Error_Msg_N
("cannot have volatile actual type for non-volatile formal type",
Actual);
end if;
-- It should not be necessary to check for unknown discriminants
-- on Formal, but for some reason Has_Unknown_Discriminants is
-- false for A_Gen_T, so Is_Indefinite_Subtype incorrectly
-- returns False. This needs fixing. ???
if not Is_Indefinite_Subtype (A_Gen_T)
and then not Unknown_Discriminants_Present (Formal)
and then Is_Indefinite_Subtype (Act_T)
then
Error_Msg_N
("actual subtype must be constrained", Actual);
Abandon_Instantiation (Actual);
end if;
if not Unknown_Discriminants_Present (Formal) then
if Is_Constrained (Ancestor) then
if not Is_Constrained (Act_T) then
Error_Msg_N
("actual subtype must be constrained", Actual);
Abandon_Instantiation (Actual);
end if;
-- Ancestor is unconstrained
elsif Is_Constrained (Act_T) then
if Ekind (Ancestor) = E_Access_Type
or else Is_Composite_Type (Ancestor)
then
Error_Msg_N
("actual subtype must be unconstrained", Actual);
Abandon_Instantiation (Actual);
end if;
-- A class-wide type is only allowed if the formal has
-- unknown discriminants.
elsif Is_Class_Wide_Type (Act_T)
and then not Has_Unknown_Discriminants (Ancestor)
then
Error_Msg_NE
("actual for & cannot be a class-wide type", Actual, Gen_T);
Abandon_Instantiation (Actual);
-- Otherwise, the formal and actual shall have the same
-- number of discriminants and each discriminant of the
-- actual must correspond to a discriminant of the formal.
elsif Has_Discriminants (Act_T)
and then not Has_Unknown_Discriminants (Act_T)
and then Has_Discriminants (Ancestor)
then
Actual_Discr := First_Discriminant (Act_T);
Ancestor_Discr := First_Discriminant (Ancestor);
while Present (Actual_Discr)
and then Present (Ancestor_Discr)
loop
if Base_Type (Act_T) /= Base_Type (Ancestor) and then
No (Corresponding_Discriminant (Actual_Discr))
then
Error_Msg_NE
("discriminant & does not correspond " &
"to ancestor discriminant", Actual, Actual_Discr);
Abandon_Instantiation (Actual);
end if;
Next_Discriminant (Actual_Discr);
Next_Discriminant (Ancestor_Discr);
end loop;
if Present (Actual_Discr) or else Present (Ancestor_Discr) then
Error_Msg_NE
("actual for & must have same number of discriminants",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
-- This case should be caught by the earlier check for
-- for constrainedness, but the check here is added for
-- completeness.
elsif Has_Discriminants (Act_T)
and then not Has_Unknown_Discriminants (Act_T)
then
Error_Msg_NE
("actual for & must not have discriminants", Actual, Gen_T);
Abandon_Instantiation (Actual);
elsif Has_Discriminants (Ancestor) then
Error_Msg_NE
("actual for & must have known discriminants", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
if not Subtypes_Statically_Compatible (Act_T, Ancestor) then
Error_Msg_N
("constraint on actual is incompatible with formal", Actual);
Abandon_Instantiation (Actual);
end if;
end if;
end Validate_Derived_Type_Instance;
--------------------------------------
-- Validate_Interface_Type_Instance --
--------------------------------------
procedure Validate_Interface_Type_Instance is
begin
if not Is_Interface (Act_T) then
Error_Msg_NE
("actual for formal interface type must be an interface",
Actual, Gen_T);
elsif Is_Limited_Type (Act_T) /= Is_Limited_Type (A_Gen_T)
or else
Is_Task_Interface (A_Gen_T) /= Is_Task_Interface (Act_T)
or else
Is_Protected_Interface (A_Gen_T) /=
Is_Protected_Interface (Act_T)
or else
Is_Synchronized_Interface (A_Gen_T) /=
Is_Synchronized_Interface (Act_T)
then
Error_Msg_NE
("actual for interface& does not match ('R'M 12.5.5(5))",
Actual, Gen_T);
end if;
end Validate_Interface_Type_Instance;
------------------------------------
-- Validate_Private_Type_Instance --
------------------------------------
procedure Validate_Private_Type_Instance is
Formal_Discr : Entity_Id;
Actual_Discr : Entity_Id;
Formal_Subt : Entity_Id;
begin
if Is_Limited_Type (Act_T)
and then not Is_Limited_Type (A_Gen_T)
then
Error_Msg_NE
("actual for non-limited & cannot be a limited type", Actual,
Gen_T);
Explain_Limited_Type (Act_T, Actual);
Abandon_Instantiation (Actual);
elsif Is_Indefinite_Subtype (Act_T)
and then not Is_Indefinite_Subtype (A_Gen_T)
and then Ada_Version >= Ada_95
then
Error_Msg_NE
("actual for & must be a definite subtype", Actual, Gen_T);
elsif not Is_Tagged_Type (Act_T)
and then Is_Tagged_Type (A_Gen_T)
then
Error_Msg_NE
("actual for & must be a tagged type", Actual, Gen_T);
elsif Has_Discriminants (A_Gen_T) then
if not Has_Discriminants (Act_T) then
Error_Msg_NE
("actual for & must have discriminants", Actual, Gen_T);
Abandon_Instantiation (Actual);
elsif Is_Constrained (Act_T) then
Error_Msg_NE
("actual for & must be unconstrained", Actual, Gen_T);
Abandon_Instantiation (Actual);
else
Formal_Discr := First_Discriminant (A_Gen_T);
Actual_Discr := First_Discriminant (Act_T);
while Formal_Discr /= Empty loop
if Actual_Discr = Empty then
Error_Msg_NE
("discriminants on actual do not match formal",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
Formal_Subt := Get_Instance_Of (Etype (Formal_Discr));
-- Access discriminants match if designated types do
if Ekind (Base_Type (Formal_Subt)) = E_Anonymous_Access_Type
and then (Ekind (Base_Type (Etype (Actual_Discr)))) =
E_Anonymous_Access_Type
and then
Get_Instance_Of
(Designated_Type (Base_Type (Formal_Subt))) =
Designated_Type (Base_Type (Etype (Actual_Discr)))
then
null;
elsif Base_Type (Formal_Subt) /=
Base_Type (Etype (Actual_Discr))
then
Error_Msg_NE
("types of actual discriminants must match formal",
Actual, Gen_T);
Abandon_Instantiation (Actual);
elsif not Subtypes_Statically_Match
(Formal_Subt, Etype (Actual_Discr))
and then Ada_Version >= Ada_95
then
Error_Msg_NE
("subtypes of actual discriminants must match formal",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
Next_Discriminant (Formal_Discr);
Next_Discriminant (Actual_Discr);
end loop;
if Actual_Discr /= Empty then
Error_Msg_NE
("discriminants on actual do not match formal",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
end if;
end if;
Ancestor := Gen_T;
end Validate_Private_Type_Instance;
-- Start of processing for Instantiate_Type
begin
if Get_Instance_Of (A_Gen_T) /= A_Gen_T then
Error_Msg_N ("duplicate instantiation of generic type", Actual);
return Error;
elsif not Is_Entity_Name (Actual)
or else not Is_Type (Entity (Actual))
then
Error_Msg_NE
("expect valid subtype mark to instantiate &", Actual, Gen_T);
Abandon_Instantiation (Actual);
else
Act_T := Entity (Actual);
-- Ada 2005 (AI-216): An Unchecked_Union subtype shall only be passed
-- as a generic actual parameter if the corresponding formal type
-- does not have a known_discriminant_part, or is a formal derived
-- type that is an Unchecked_Union type.
if Is_Unchecked_Union (Base_Type (Act_T)) then
if not Has_Discriminants (A_Gen_T)
or else
(Is_Derived_Type (A_Gen_T)
and then
Is_Unchecked_Union (A_Gen_T))
then
null;
else
Error_Msg_N ("Unchecked_Union cannot be the actual for a" &
" discriminated formal type", Act_T);
end if;
end if;
-- Deal with fixed/floating restrictions
if Is_Floating_Point_Type (Act_T) then
Check_Restriction (No_Floating_Point, Actual);
elsif Is_Fixed_Point_Type (Act_T) then
Check_Restriction (No_Fixed_Point, Actual);
end if;
-- Deal with error of using incomplete type as generic actual
if Ekind (Act_T) = E_Incomplete_Type then
if No (Underlying_Type (Act_T)) then
Error_Msg_N ("premature use of incomplete type", Actual);
Abandon_Instantiation (Actual);
else
Act_T := Full_View (Act_T);
Set_Entity (Actual, Act_T);
if Has_Private_Component (Act_T) then
Error_Msg_N
("premature use of type with private component", Actual);
end if;
end if;
-- Deal with error of premature use of private type as generic actual
elsif Is_Private_Type (Act_T)
and then Is_Private_Type (Base_Type (Act_T))
and then not Is_Generic_Type (Act_T)
and then not Is_Derived_Type (Act_T)
and then No (Full_View (Root_Type (Act_T)))
then
Error_Msg_N ("premature use of private type", Actual);
elsif Has_Private_Component (Act_T) then
Error_Msg_N
("premature use of type with private component", Actual);
end if;
Set_Instance_Of (A_Gen_T, Act_T);
-- If the type is generic, the class-wide type may also be used
if Is_Tagged_Type (A_Gen_T)
and then Is_Tagged_Type (Act_T)
and then not Is_Class_Wide_Type (A_Gen_T)
then
Set_Instance_Of (Class_Wide_Type (A_Gen_T),
Class_Wide_Type (Act_T));
end if;
if not Is_Abstract (A_Gen_T)
and then Is_Abstract (Act_T)
then
Error_Msg_N
("actual of non-abstract formal cannot be abstract", Actual);
end if;
if Is_Scalar_Type (Gen_T) then
Set_Instance_Of (Etype (A_Gen_T), Etype (Act_T));
end if;
end if;
case Nkind (Def) is
when N_Formal_Private_Type_Definition =>
Validate_Private_Type_Instance;
when N_Formal_Derived_Type_Definition =>
Validate_Derived_Type_Instance;
when N_Formal_Discrete_Type_Definition =>
if not Is_Discrete_Type (Act_T) then
Error_Msg_NE
("expect discrete type in instantiation of&", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Formal_Signed_Integer_Type_Definition =>
if not Is_Signed_Integer_Type (Act_T) then
Error_Msg_NE
("expect signed integer type in instantiation of&",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Formal_Modular_Type_Definition =>
if not Is_Modular_Integer_Type (Act_T) then
Error_Msg_NE
("expect modular type in instantiation of &", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Formal_Floating_Point_Definition =>
if not Is_Floating_Point_Type (Act_T) then
Error_Msg_NE
("expect float type in instantiation of &", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Formal_Ordinary_Fixed_Point_Definition =>
if not Is_Ordinary_Fixed_Point_Type (Act_T) then
Error_Msg_NE
("expect ordinary fixed point type in instantiation of &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Formal_Decimal_Fixed_Point_Definition =>
if not Is_Decimal_Fixed_Point_Type (Act_T) then
Error_Msg_NE
("expect decimal type in instantiation of &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Array_Type_Definition =>
Validate_Array_Type_Instance;
when N_Access_To_Object_Definition =>
Validate_Access_Type_Instance;
when N_Access_Function_Definition |
N_Access_Procedure_Definition =>
Validate_Access_Subprogram_Instance;
when N_Record_Definition =>
Validate_Interface_Type_Instance;
when N_Derived_Type_Definition =>
Validate_Derived_Interface_Type_Instance;
when others =>
raise Program_Error;
end case;
Decl_Node :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => New_Copy (Gen_T),
Subtype_Indication => New_Reference_To (Act_T, Loc));
if Is_Private_Type (Act_T) then
Set_Has_Private_View (Subtype_Indication (Decl_Node));
elsif Is_Access_Type (Act_T)
and then Is_Private_Type (Designated_Type (Act_T))
then
Set_Has_Private_View (Subtype_Indication (Decl_Node));
end if;
-- Flag actual derived types so their elaboration produces the
-- appropriate renamings for the primitive operations of the ancestor.
-- Flag actual for formal private types as well, to determine whether
-- operations in the private part may override inherited operations.
if Nkind (Def) = N_Formal_Derived_Type_Definition
or else Nkind (Def) = N_Formal_Private_Type_Definition
then
Set_Generic_Parent_Type (Decl_Node, Ancestor);
end if;
return Decl_Node;
end Instantiate_Type;
---------------------
-- Is_In_Main_Unit --
---------------------
function Is_In_Main_Unit (N : Node_Id) return Boolean is
Unum : constant Unit_Number_Type := Get_Source_Unit (N);
Current_Unit : Node_Id;
begin
if Unum = Main_Unit then
return True;
-- If the current unit is a subunit then it is either the main unit
-- or is being compiled as part of the main unit.
elsif Nkind (N) = N_Compilation_Unit then
return Nkind (Unit (N)) = N_Subunit;
end if;
Current_Unit := Parent (N);
while Present (Current_Unit)
and then Nkind (Current_Unit) /= N_Compilation_Unit
loop
Current_Unit := Parent (Current_Unit);
end loop;
-- The instantiation node is in the main unit, or else the current
-- node (perhaps as the result of nested instantiations) is in the
-- main unit, or in the declaration of the main unit, which in this
-- last case must be a body.
return Unum = Main_Unit
or else Current_Unit = Cunit (Main_Unit)
or else Current_Unit = Library_Unit (Cunit (Main_Unit))
or else (Present (Library_Unit (Current_Unit))
and then Is_In_Main_Unit (Library_Unit (Current_Unit)));
end Is_In_Main_Unit;
----------------------------
-- Load_Parent_Of_Generic --
----------------------------
procedure Load_Parent_Of_Generic (N : Node_Id; Spec : Node_Id) is
Comp_Unit : constant Node_Id := Cunit (Get_Source_Unit (Spec));
Save_Style_Check : constant Boolean := Style_Check;
True_Parent : Node_Id;
Inst_Node : Node_Id;
OK : Boolean;
begin
if not In_Same_Source_Unit (N, Spec)
or else Nkind (Unit (Comp_Unit)) = N_Package_Declaration
or else (Nkind (Unit (Comp_Unit)) = N_Package_Body
and then not Is_In_Main_Unit (Spec))
then
-- Find body of parent of spec, and analyze it. A special case
-- arises when the parent is an instantiation, that is to say when
-- we are currently instantiating a nested generic. In that case,
-- there is no separate file for the body of the enclosing instance.
-- Instead, the enclosing body must be instantiated as if it were
-- a pending instantiation, in order to produce the body for the
-- nested generic we require now. Note that in that case the
-- generic may be defined in a package body, the instance defined
-- in the same package body, and the original enclosing body may not
-- be in the main unit.
True_Parent := Parent (Spec);
Inst_Node := Empty;
while Present (True_Parent)
and then Nkind (True_Parent) /= N_Compilation_Unit
loop
if Nkind (True_Parent) = N_Package_Declaration
and then
Nkind (Original_Node (True_Parent)) = N_Package_Instantiation
then
-- Parent is a compilation unit that is an instantiation.
-- Instantiation node has been replaced with package decl.
Inst_Node := Original_Node (True_Parent);
exit;
elsif Nkind (True_Parent) = N_Package_Declaration
and then Present (Generic_Parent (Specification (True_Parent)))
and then Nkind (Parent (True_Parent)) /= N_Compilation_Unit
then
-- Parent is an instantiation within another specification.
-- Declaration for instance has been inserted before original
-- instantiation node. A direct link would be preferable?
Inst_Node := Next (True_Parent);
while Present (Inst_Node)
and then Nkind (Inst_Node) /= N_Package_Instantiation
loop
Next (Inst_Node);
end loop;
-- If the instance appears within a generic, and the generic
-- unit is defined within a formal package of the enclosing
-- generic, there is no generic body available, and none
-- needed. A more precise test should be used ???
if No (Inst_Node) then
return;
end if;
exit;
else
True_Parent := Parent (True_Parent);
end if;
end loop;
-- Case where we are currently instantiating a nested generic
if Present (Inst_Node) then
if Nkind (Parent (True_Parent)) = N_Compilation_Unit then
-- Instantiation node and declaration of instantiated package
-- were exchanged when only the declaration was needed.
-- Restore instantiation node before proceeding with body.
Set_Unit (Parent (True_Parent), Inst_Node);
end if;
-- Now complete instantiation of enclosing body, if it appears
-- in some other unit. If it appears in the current unit, the
-- body will have been instantiated already.
if No (Corresponding_Body (Instance_Spec (Inst_Node))) then
-- We need to determine the expander mode to instantiate
-- the enclosing body. Because the generic body we need
-- may use global entities declared in the enclosing package
-- (including aggregates) it is in general necessary to
-- compile this body with expansion enabled. The exception
-- is if we are within a generic package, in which case
-- the usual generic rule applies.
declare
Exp_Status : Boolean := True;
Scop : Entity_Id;
begin
-- Loop through scopes looking for generic package
Scop := Scope (Defining_Entity (Instance_Spec (Inst_Node)));
while Present (Scop)
and then Scop /= Standard_Standard
loop
if Ekind (Scop) = E_Generic_Package then
Exp_Status := False;
exit;
end if;
Scop := Scope (Scop);
end loop;
Instantiate_Package_Body
(Pending_Body_Info'(
Inst_Node, True_Parent, Exp_Status,
Get_Code_Unit (Sloc (Inst_Node))));
end;
end if;
-- Case where we are not instantiating a nested generic
else
Opt.Style_Check := False;
Expander_Mode_Save_And_Set (True);
Load_Needed_Body (Comp_Unit, OK);
Opt.Style_Check := Save_Style_Check;
Expander_Mode_Restore;
if not OK
and then Unit_Requires_Body (Defining_Entity (Spec))
then
declare
Bname : constant Unit_Name_Type :=
Get_Body_Name (Get_Unit_Name (Unit (Comp_Unit)));
begin
Error_Msg_Unit_1 := Bname;
Error_Msg_N ("this instantiation requires$!", N);
Error_Msg_Name_1 :=
Get_File_Name (Bname, Subunit => False);
Error_Msg_N ("\but file{ was not found!", N);
raise Unrecoverable_Error;
end;
end if;
end if;
end if;
-- If loading the parent of the generic caused an instantiation
-- circularity, we abandon compilation at this point, because
-- otherwise in some cases we get into trouble with infinite
-- recursions after this point.
if Circularity_Detected then
raise Unrecoverable_Error;
end if;
end Load_Parent_Of_Generic;
-----------------------
-- Move_Freeze_Nodes --
-----------------------
procedure Move_Freeze_Nodes
(Out_Of : Entity_Id;
After : Node_Id;
L : List_Id)
is
Decl : Node_Id;
Next_Decl : Node_Id;
Next_Node : Node_Id := After;
Spec : Node_Id;
function Is_Outer_Type (T : Entity_Id) return Boolean;
-- Check whether entity is declared in a scope external to that
-- of the generic unit.
-------------------
-- Is_Outer_Type --
-------------------
function Is_Outer_Type (T : Entity_Id) return Boolean is
Scop : Entity_Id := Scope (T);
begin
if Scope_Depth (Scop) < Scope_Depth (Out_Of) then
return True;
else
while Scop /= Standard_Standard loop
if Scop = Out_Of then
return False;
else
Scop := Scope (Scop);
end if;
end loop;
return True;
end if;
end Is_Outer_Type;
-- Start of processing for Move_Freeze_Nodes
begin
if No (L) then
return;
end if;
-- First remove the freeze nodes that may appear before all other
-- declarations.
Decl := First (L);
while Present (Decl)
and then Nkind (Decl) = N_Freeze_Entity
and then Is_Outer_Type (Entity (Decl))
loop
Decl := Remove_Head (L);
Insert_After (Next_Node, Decl);
Set_Analyzed (Decl, False);
Next_Node := Decl;
Decl := First (L);
end loop;
-- Next scan the list of declarations and remove each freeze node that
-- appears ahead of the current node.
while Present (Decl) loop
while Present (Next (Decl))
and then Nkind (Next (Decl)) = N_Freeze_Entity
and then Is_Outer_Type (Entity (Next (Decl)))
loop
Next_Decl := Remove_Next (Decl);
Insert_After (Next_Node, Next_Decl);
Set_Analyzed (Next_Decl, False);
Next_Node := Next_Decl;
end loop;
-- If the declaration is a nested package or concurrent type, then
-- recurse. Nested generic packages will have been processed from the
-- inside out.
if Nkind (Decl) = N_Package_Declaration then
Spec := Specification (Decl);
elsif Nkind (Decl) = N_Task_Type_Declaration then
Spec := Task_Definition (Decl);
elsif Nkind (Decl) = N_Protected_Type_Declaration then
Spec := Protected_Definition (Decl);
else
Spec := Empty;
end if;
if Present (Spec) then
Move_Freeze_Nodes (Out_Of, Next_Node,
Visible_Declarations (Spec));
Move_Freeze_Nodes (Out_Of, Next_Node,
Private_Declarations (Spec));
end if;
Next (Decl);
end loop;
end Move_Freeze_Nodes;
----------------
-- Next_Assoc --
----------------
function Next_Assoc (E : Assoc_Ptr) return Assoc_Ptr is
begin
return Generic_Renamings.Table (E).Next_In_HTable;
end Next_Assoc;
------------------------
-- Preanalyze_Actuals --
------------------------
procedure Pre_Analyze_Actuals (N : Node_Id) is
Assoc : Node_Id;
Act : Node_Id;
Errs : constant Int := Serious_Errors_Detected;
begin
Assoc := First (Generic_Associations (N));
while Present (Assoc) loop
Act := Explicit_Generic_Actual_Parameter (Assoc);
-- Within a nested instantiation, a defaulted actual is an
-- empty association, so nothing to analyze. If the actual for
-- a subprogram is an attribute, analyze prefix only, because
-- actual is not a complete attribute reference.
-- If actual is an allocator, analyze expression only. The full
-- analysis can generate code, and if the instance is a compilation
-- unit we have to wait until the package instance is installed to
-- have a proper place to insert this code.
-- String literals may be operators, but at this point we do not
-- know whether the actual is a formal subprogram or a string.
if No (Act) then
null;
elsif Nkind (Act) = N_Attribute_Reference then
Analyze (Prefix (Act));
elsif Nkind (Act) = N_Explicit_Dereference then
Analyze (Prefix (Act));
elsif Nkind (Act) = N_Allocator then
declare
Expr : constant Node_Id := Expression (Act);
begin
if Nkind (Expr) = N_Subtype_Indication then
Analyze (Subtype_Mark (Expr));
Analyze_List (Constraints (Constraint (Expr)));
else
Analyze (Expr);
end if;
end;
elsif Nkind (Act) /= N_Operator_Symbol then
Analyze (Act);
end if;
if Errs /= Serious_Errors_Detected then
Abandon_Instantiation (Act);
end if;
Next (Assoc);
end loop;
end Pre_Analyze_Actuals;
-------------------
-- Remove_Parent --
-------------------
procedure Remove_Parent (In_Body : Boolean := False) is
S : Entity_Id := Current_Scope;
E : Entity_Id;
P : Entity_Id;
Hidden : Elmt_Id;
begin
-- After child instantiation is complete, remove from scope stack
-- the extra copy of the current scope, and then remove parent
-- instances.
if not In_Body then
Pop_Scope;
while Current_Scope /= S loop
P := Current_Scope;
End_Package_Scope (Current_Scope);
if In_Open_Scopes (P) then
E := First_Entity (P);
while Present (E) loop
Set_Is_Immediately_Visible (E, True);
Next_Entity (E);
end loop;
if Is_Generic_Instance (Current_Scope)
and then P /= Current_Scope
then
-- We are within an instance of some sibling. Retain
-- visibility of parent, for proper subsequent cleanup,
-- and reinstall private declarations as well.
Set_In_Private_Part (P);
Install_Private_Declarations (P);
end if;
-- If the ultimate parent is a top-level unit recorded in
-- Instance_Parent_Unit, then reset its visibility to what
-- it was before instantiation. (It's not clear what the
-- purpose is of testing whether Scope (P) is In_Open_Scopes,
-- but that test was present before the ultimate parent test
-- was added.???)
elsif not In_Open_Scopes (Scope (P))
or else (P = Instance_Parent_Unit
and then not Parent_Unit_Visible)
then
Set_Is_Immediately_Visible (P, False);
end if;
end loop;
-- Reset visibility of entities in the enclosing scope
Set_Is_Hidden_Open_Scope (Current_Scope, False);
Hidden := First_Elmt (Hidden_Entities);
while Present (Hidden) loop
Set_Is_Immediately_Visible (Node (Hidden), True);
Next_Elmt (Hidden);
end loop;
else
-- Each body is analyzed separately, and there is no context
-- that needs preserving from one body instance to the next,
-- so remove all parent scopes that have been installed.
while Present (S) loop
End_Package_Scope (S);
Set_Is_Immediately_Visible (S, False);
S := Current_Scope;
exit when S = Standard_Standard;
end loop;
end if;
end Remove_Parent;
-----------------
-- Restore_Env --
-----------------
procedure Restore_Env is
Saved : Instance_Env renames Instance_Envs.Table (Instance_Envs.Last);
begin
Ada_Version := Saved.Ada_Version;
Ada_Version_Explicit := Saved.Ada_Version_Explicit;
if No (Current_Instantiated_Parent.Act_Id) then
-- Restore environment after subprogram inlining
Restore_Private_Views (Empty);
end if;
Current_Instantiated_Parent := Saved.Instantiated_Parent;
Exchanged_Views := Saved.Exchanged_Views;
Hidden_Entities := Saved.Hidden_Entities;
Current_Sem_Unit := Saved.Current_Sem_Unit;
Parent_Unit_Visible := Saved.Parent_Unit_Visible;
Instance_Parent_Unit := Saved.Instance_Parent_Unit;
Instance_Envs.Decrement_Last;
end Restore_Env;
---------------------------
-- Restore_Private_Views --
---------------------------
procedure Restore_Private_Views
(Pack_Id : Entity_Id;
Is_Package : Boolean := True)
is
M : Elmt_Id;
E : Entity_Id;
Typ : Entity_Id;
Dep_Elmt : Elmt_Id;
Dep_Typ : Node_Id;
procedure Restore_Nested_Formal (Formal : Entity_Id);
-- Hide the generic formals of formal packages declared with box
-- which were reachable in the current instantiation.
procedure Restore_Nested_Formal (Formal : Entity_Id) is
Ent : Entity_Id;
begin
if Present (Renamed_Object (Formal))
and then Denotes_Formal_Package (Renamed_Object (Formal), True)
then
return;
elsif Present (Associated_Formal_Package (Formal))
and then Box_Present (Parent (Associated_Formal_Package (Formal)))
then
Ent := First_Entity (Formal);
while Present (Ent) loop
exit when Ekind (Ent) = E_Package
and then Renamed_Entity (Ent) = Renamed_Entity (Formal);
Set_Is_Hidden (Ent);
Set_Is_Potentially_Use_Visible (Ent, False);
-- If package, then recurse
if Ekind (Ent) = E_Package then
Restore_Nested_Formal (Ent);
end if;
Next_Entity (Ent);
end loop;
end if;
end Restore_Nested_Formal;
begin
M := First_Elmt (Exchanged_Views);
while Present (M) loop
Typ := Node (M);
-- Subtypes of types whose views have been exchanged, and that
-- are defined within the instance, were not on the list of
-- Private_Dependents on entry to the instance, so they have to
-- be exchanged explicitly now, in order to remain consistent with
-- the view of the parent type.
if Ekind (Typ) = E_Private_Type
or else Ekind (Typ) = E_Limited_Private_Type
or else Ekind (Typ) = E_Record_Type_With_Private
then
Dep_Elmt := First_Elmt (Private_Dependents (Typ));
while Present (Dep_Elmt) loop
Dep_Typ := Node (Dep_Elmt);
if Scope (Dep_Typ) = Pack_Id
and then Present (Full_View (Dep_Typ))
then
Replace_Elmt (Dep_Elmt, Full_View (Dep_Typ));
Exchange_Declarations (Dep_Typ);
end if;
Next_Elmt (Dep_Elmt);
end loop;
end if;
Exchange_Declarations (Node (M));
Next_Elmt (M);
end loop;
if No (Pack_Id) then
return;
end if;
-- Make the generic formal parameters private, and make the formal
-- types into subtypes of the actuals again.
E := First_Entity (Pack_Id);
while Present (E) loop
Set_Is_Hidden (E, True);
if Is_Type (E)
and then Nkind (Parent (E)) = N_Subtype_Declaration
then
Set_Is_Generic_Actual_Type (E, False);
-- An unusual case of aliasing: the actual may also be directly
-- visible in the generic, and be private there, while it is
-- fully visible in the context of the instance. The internal
-- subtype is private in the instance, but has full visibility
-- like its parent in the enclosing scope. This enforces the
-- invariant that the privacy status of all private dependents of
-- a type coincide with that of the parent type. This can only
-- happen when a generic child unit is instantiated within a
-- sibling.
if Is_Private_Type (E)
and then not Is_Private_Type (Etype (E))
then
Exchange_Declarations (E);
end if;
elsif Ekind (E) = E_Package then
-- The end of the renaming list is the renaming of the generic
-- package itself. If the instance is a subprogram, all entities
-- in the corresponding package are renamings. If this entity is
-- a formal package, make its own formals private as well. The
-- actual in this case is itself the renaming of an instantation.
-- If the entity is not a package renaming, it is the entity
-- created to validate formal package actuals: ignore.
-- If the actual is itself a formal package for the enclosing
-- generic, or the actual for such a formal package, it remains
-- visible on exit from the instance, and therefore nothing
-- needs to be done either, except to keep it accessible.
if Is_Package
and then Renamed_Object (E) = Pack_Id
then
exit;
elsif Nkind (Parent (E)) /= N_Package_Renaming_Declaration then
null;
elsif Denotes_Formal_Package (Renamed_Object (E), True) then
Set_Is_Hidden (E, False);
else
declare
Act_P : constant Entity_Id := Renamed_Object (E);
Id : Entity_Id;
begin
Id := First_Entity (Act_P);
while Present (Id)
and then Id /= First_Private_Entity (Act_P)
loop
exit when Ekind (Id) = E_Package
and then Renamed_Object (Id) = Act_P;
Set_Is_Hidden (Id, True);
Set_Is_Potentially_Use_Visible (Id, In_Use (Act_P));
if Ekind (Id) = E_Package then
Restore_Nested_Formal (Id);
end if;
Next_Entity (Id);
end loop;
end;
end if;
end if;
Next_Entity (E);
end loop;
end Restore_Private_Views;
--------------
-- Save_Env --
--------------
procedure Save_Env
(Gen_Unit : Entity_Id;
Act_Unit : Entity_Id)
is
begin
Init_Env;
Set_Instance_Env (Gen_Unit, Act_Unit);
end Save_Env;
----------------------------
-- Save_Global_References --
----------------------------
procedure Save_Global_References (N : Node_Id) is
Gen_Scope : Entity_Id;
E : Entity_Id;
N2 : Node_Id;
function Is_Global (E : Entity_Id) return Boolean;
-- Check whether entity is defined outside of generic unit.
-- Examine the scope of an entity, and the scope of the scope,
-- etc, until we find either Standard, in which case the entity
-- is global, or the generic unit itself, which indicates that
-- the entity is local. If the entity is the generic unit itself,
-- as in the case of a recursive call, or the enclosing generic unit,
-- if different from the current scope, then it is local as well,
-- because it will be replaced at the point of instantiation. On
-- the other hand, if it is a reference to a child unit of a common
-- ancestor, which appears in an instantiation, it is global because
-- it is used to denote a specific compilation unit at the time the
-- instantiations will be analyzed.
procedure Reset_Entity (N : Node_Id);
-- Save semantic information on global entity, so that it is not
-- resolved again at instantiation time.
procedure Save_Entity_Descendants (N : Node_Id);
-- Apply Save_Global_References to the two syntactic descendants of
-- non-terminal nodes that carry an Associated_Node and are processed
-- through Reset_Entity. Once the global entity (if any) has been
-- captured together with its type, only two syntactic descendants
-- need to be traversed to complete the processing of the tree rooted
-- at N. This applies to Selected_Components, Expanded_Names, and to
-- Operator nodes. N can also be a character literal, identifier, or
-- operator symbol node, but the call has no effect in these cases.
procedure Save_Global_Defaults (N1, N2 : Node_Id);
-- Default actuals in nested instances must be handled specially
-- because there is no link to them from the original tree. When an
-- actual subprogram is given by a default, we add an explicit generic
-- association for it in the instantiation node. When we save the
-- global references on the name of the instance, we recover the list
-- of generic associations, and add an explicit one to the original
-- generic tree, through which a global actual can be preserved.
-- Similarly, if a child unit is instantiated within a sibling, in the
-- context of the parent, we must preserve the identifier of the parent
-- so that it can be properly resolved in a subsequent instantiation.
procedure Save_Global_Descendant (D : Union_Id);
-- Apply Save_Global_References recursively to the descendents of
-- current node.
procedure Save_References (N : Node_Id);
-- This is the recursive procedure that does the work, once the
-- enclosing generic scope has been established.
---------------
-- Is_Global --
---------------
function Is_Global (E : Entity_Id) return Boolean is
Se : Entity_Id := Scope (E);
function Is_Instance_Node (Decl : Node_Id) return Boolean;
-- Determine whether the parent node of a reference to a child unit
-- denotes an instantiation or a formal package, in which case the
-- reference to the child unit is global, even if it appears within
-- the current scope (e.g. when the instance appears within the body
-- of an ancestor).
----------------------
-- Is_Instance_Node --
----------------------
function Is_Instance_Node (Decl : Node_Id) return Boolean is
begin
return (Nkind (Decl) in N_Generic_Instantiation
or else
Nkind (Original_Node (Decl)) = N_Formal_Package_Declaration);
end Is_Instance_Node;
-- Start of processing for Is_Global
begin
if E = Gen_Scope then
return False;
elsif E = Standard_Standard then
return True;
elsif Is_Child_Unit (E)
and then (Is_Instance_Node (Parent (N2))
or else (Nkind (Parent (N2)) = N_Expanded_Name
and then N2 = Selector_Name (Parent (N2))
and then Is_Instance_Node (Parent (Parent (N2)))))
then
return True;
else
while Se /= Gen_Scope loop
if Se = Standard_Standard then
return True;
else
Se := Scope (Se);
end if;
end loop;
return False;
end if;
end Is_Global;
------------------
-- Reset_Entity --
------------------
procedure Reset_Entity (N : Node_Id) is
procedure Set_Global_Type (N : Node_Id; N2 : Node_Id);
-- The type of N2 is global to the generic unit. Save the
-- type in the generic node.
function Top_Ancestor (E : Entity_Id) return Entity_Id;
-- Find the ultimate ancestor of the current unit. If it is
-- not a generic unit, then the name of the current unit
-- in the prefix of an expanded name must be replaced with
-- its generic homonym to ensure that it will be properly
-- resolved in an instance.
---------------------
-- Set_Global_Type --
---------------------
procedure Set_Global_Type (N : Node_Id; N2 : Node_Id) is
Typ : constant Entity_Id := Etype (N2);
begin
Set_Etype (N, Typ);
if Entity (N) /= N2
and then Has_Private_View (Entity (N))
then
-- If the entity of N is not the associated node, this is
-- a nested generic and it has an associated node as well,
-- whose type is already the full view (see below). Indicate
-- that the original node has a private view.
Set_Has_Private_View (N);
end if;
-- If not a private type, nothing else to do
if not Is_Private_Type (Typ) then
if Is_Array_Type (Typ)
and then Is_Private_Type (Component_Type (Typ))
then
Set_Has_Private_View (N);
end if;
-- If it is a derivation of a private type in a context where
-- no full view is needed, nothing to do either.
elsif No (Full_View (Typ)) and then Typ /= Etype (Typ) then
null;
-- Otherwise mark the type for flipping and use the full_view
-- when available.
else
Set_Has_Private_View (N);
if Present (Full_View (Typ)) then
Set_Etype (N2, Full_View (Typ));
end if;
end if;
end Set_Global_Type;
------------------
-- Top_Ancestor --
------------------
function Top_Ancestor (E : Entity_Id) return Entity_Id is
Par : Entity_Id := E;
begin
while Is_Child_Unit (Par) loop
Par := Scope (Par);
end loop;
return Par;
end Top_Ancestor;
-- Start of processing for Reset_Entity
begin
N2 := Get_Associated_Node (N);
E := Entity (N2);
if Present (E) then
if Is_Global (E) then
Set_Global_Type (N, N2);
elsif Nkind (N) = N_Op_Concat
and then Is_Generic_Type (Etype (N2))
and then
(Base_Type (Etype (Right_Opnd (N2))) = Etype (N2)
or else Base_Type (Etype (Left_Opnd (N2))) = Etype (N2))
and then Is_Intrinsic_Subprogram (E)
then
null;
else
-- Entity is local. Mark generic node as unresolved.
-- Note that now it does not have an entity.
Set_Associated_Node (N, Empty);
Set_Etype (N, Empty);
end if;
if Nkind (Parent (N)) in N_Generic_Instantiation
and then N = Name (Parent (N))
then
Save_Global_Defaults (Parent (N), Parent (N2));
end if;
elsif Nkind (Parent (N)) = N_Selected_Component
and then Nkind (Parent (N2)) = N_Expanded_Name
then
if Is_Global (Entity (Parent (N2))) then
Change_Selected_Component_To_Expanded_Name (Parent (N));
Set_Associated_Node (Parent (N), Parent (N2));
Set_Global_Type (Parent (N), Parent (N2));
Save_Entity_Descendants (N);
-- If this is a reference to the current generic entity,
-- replace by the name of the generic homonym of the current
-- package. This is because in an instantiation Par.P.Q will
-- not resolve to the name of the instance, whose enclosing
-- scope is not necessarily Par. We use the generic homonym
-- rather that the name of the generic itself, because it may
-- be hidden by a local declaration.
elsif In_Open_Scopes (Entity (Parent (N2)))
and then not
Is_Generic_Unit (Top_Ancestor (Entity (Prefix (Parent (N2)))))
then
if Ekind (Entity (Parent (N2))) = E_Generic_Package then
Rewrite (Parent (N),
Make_Identifier (Sloc (N),
Chars =>
Chars (Generic_Homonym (Entity (Parent (N2))))));
else
Rewrite (Parent (N),
Make_Identifier (Sloc (N),
Chars => Chars (Selector_Name (Parent (N2)))));
end if;
end if;
if Nkind (Parent (Parent (N))) in N_Generic_Instantiation
and then Parent (N) = Name (Parent (Parent (N)))
then
Save_Global_Defaults
(Parent (Parent (N)), Parent (Parent ((N2))));
end if;
-- A selected component may denote a static constant that has
-- been folded. Make the same replacement in original tree.
elsif Nkind (Parent (N)) = N_Selected_Component
and then (Nkind (Parent (N2)) = N_Integer_Literal
or else Nkind (Parent (N2)) = N_Real_Literal)
then
Rewrite (Parent (N),
New_Copy (Parent (N2)));
Set_Analyzed (Parent (N), False);
-- A selected component may be transformed into a parameterless
-- function call. If the called entity is global, rewrite the
-- node appropriately, i.e. as an extended name for the global
-- entity.
elsif Nkind (Parent (N)) = N_Selected_Component
and then Nkind (Parent (N2)) = N_Function_Call
and then Is_Global (Entity (Name (Parent (N2))))
then
Change_Selected_Component_To_Expanded_Name (Parent (N));
Set_Associated_Node (Parent (N), Name (Parent (N2)));
Set_Global_Type (Parent (N), Name (Parent (N2)));
Save_Entity_Descendants (N);
else
-- Entity is local. Reset in generic unit, so that node
-- is resolved anew at the point of instantiation.
Set_Associated_Node (N, Empty);
Set_Etype (N, Empty);
end if;
end Reset_Entity;
-----------------------------
-- Save_Entity_Descendants --
-----------------------------
procedure Save_Entity_Descendants (N : Node_Id) is
begin
case Nkind (N) is
when N_Binary_Op =>
Save_Global_Descendant (Union_Id (Left_Opnd (N)));
Save_Global_Descendant (Union_Id (Right_Opnd (N)));
when N_Unary_Op =>
Save_Global_Descendant (Union_Id (Right_Opnd (N)));
when N_Expanded_Name | N_Selected_Component =>
Save_Global_Descendant (Union_Id (Prefix (N)));
Save_Global_Descendant (Union_Id (Selector_Name (N)));
when N_Identifier | N_Character_Literal | N_Operator_Symbol =>
null;
when others =>
raise Program_Error;
end case;
end Save_Entity_Descendants;
--------------------------
-- Save_Global_Defaults --
--------------------------
procedure Save_Global_Defaults (N1, N2 : Node_Id) is
Loc : constant Source_Ptr := Sloc (N1);
Assoc2 : constant List_Id := Generic_Associations (N2);
Gen_Id : constant Entity_Id := Get_Generic_Entity (N2);
Assoc1 : List_Id;
Act1 : Node_Id;
Act2 : Node_Id;
Def : Node_Id;
Ndec : Node_Id;
Subp : Entity_Id;
Actual : Entity_Id;
begin
Assoc1 := Generic_Associations (N1);
if Present (Assoc1) then
Act1 := First (Assoc1);
else
Act1 := Empty;
Set_Generic_Associations (N1, New_List);
Assoc1 := Generic_Associations (N1);
end if;
if Present (Assoc2) then
Act2 := First (Assoc2);
else
return;
end if;
while Present (Act1) and then Present (Act2) loop
Next (Act1);
Next (Act2);
end loop;
-- Find the associations added for default suprograms
if Present (Act2) then
while Nkind (Act2) /= N_Generic_Association
or else No (Entity (Selector_Name (Act2)))
or else not Is_Overloadable (Entity (Selector_Name (Act2)))
loop
Next (Act2);
end loop;
-- Add a similar association if the default is global. The
-- renaming declaration for the actual has been analyzed, and
-- its alias is the program it renames. Link the actual in the
-- original generic tree with the node in the analyzed tree.
while Present (Act2) loop
Subp := Entity (Selector_Name (Act2));
Def := Explicit_Generic_Actual_Parameter (Act2);
-- Following test is defence against rubbish errors
if No (Alias (Subp)) then
return;
end if;
-- Retrieve the resolved actual from the renaming declaration
-- created for the instantiated formal.
Actual := Entity (Name (Parent (Parent (Subp))));
Set_Entity (Def, Actual);
Set_Etype (Def, Etype (Actual));
if Is_Global (Actual) then
Ndec :=
Make_Generic_Association (Loc,
Selector_Name => New_Occurrence_Of (Subp, Loc),
Explicit_Generic_Actual_Parameter =>
New_Occurrence_Of (Actual, Loc));
Set_Associated_Node
(Explicit_Generic_Actual_Parameter (Ndec), Def);
Append (Ndec, Assoc1);
-- If there are other defaults, add a dummy association
-- in case there are other defaulted formals with the same
-- name.
elsif Present (Next (Act2)) then
Ndec :=
Make_Generic_Association (Loc,
Selector_Name => New_Occurrence_Of (Subp, Loc),
Explicit_Generic_Actual_Parameter => Empty);
Append (Ndec, Assoc1);
end if;
Next (Act2);
end loop;
end if;
if Nkind (Name (N1)) = N_Identifier
and then Is_Child_Unit (Gen_Id)
and then Is_Global (Gen_Id)
and then Is_Generic_Unit (Scope (Gen_Id))
and then In_Open_Scopes (Scope (Gen_Id))
then
-- This is an instantiation of a child unit within a sibling,
-- so that the generic parent is in scope. An eventual instance
-- must occur within the scope of an instance of the parent.
-- Make name in instance into an expanded name, to preserve the
-- identifier of the parent, so it can be resolved subsequently.
Rewrite (Name (N2),
Make_Expanded_Name (Loc,
Chars => Chars (Gen_Id),
Prefix => New_Occurrence_Of (Scope (Gen_Id), Loc),
Selector_Name => New_Occurrence_Of (Gen_Id, Loc)));
Set_Entity (Name (N2), Gen_Id);
Rewrite (Name (N1),
Make_Expanded_Name (Loc,
Chars => Chars (Gen_Id),
Prefix => New_Occurrence_Of (Scope (Gen_Id), Loc),
Selector_Name => New_Occurrence_Of (Gen_Id, Loc)));
Set_Associated_Node (Name (N1), Name (N2));
Set_Associated_Node (Prefix (Name (N1)), Empty);
Set_Associated_Node
(Selector_Name (Name (N1)), Selector_Name (Name (N2)));
Set_Etype (Name (N1), Etype (Gen_Id));
end if;
end Save_Global_Defaults;
----------------------------
-- Save_Global_Descendant --
----------------------------
procedure Save_Global_Descendant (D : Union_Id) is
N1 : Node_Id;
begin
if D in Node_Range then
if D = Union_Id (Empty) then
null;
elsif Nkind (Node_Id (D)) /= N_Compilation_Unit then
Save_References (Node_Id (D));
end if;
elsif D in List_Range then
if D = Union_Id (No_List)
or else Is_Empty_List (List_Id (D))
then
null;
else
N1 := First (List_Id (D));
while Present (N1) loop
Save_References (N1);
Next (N1);
end loop;
end if;
-- Element list or other non-node field, nothing to do
else
null;
end if;
end Save_Global_Descendant;
---------------------
-- Save_References --
---------------------
-- This is the recursive procedure that does the work, once the
-- enclosing generic scope has been established. We have to treat
-- specially a number of node rewritings that are required by semantic
-- processing and which change the kind of nodes in the generic copy:
-- typically constant-folding, replacing an operator node by a string
-- literal, or a selected component by an expanded name. In each of
-- those cases, the transformation is propagated to the generic unit.
procedure Save_References (N : Node_Id) is
begin
if N = Empty then
null;
elsif Nkind (N) = N_Character_Literal
or else Nkind (N) = N_Operator_Symbol
then
if Nkind (N) = Nkind (Get_Associated_Node (N)) then
Reset_Entity (N);
elsif Nkind (N) = N_Operator_Symbol
and then Nkind (Get_Associated_Node (N)) = N_String_Literal
then
Change_Operator_Symbol_To_String_Literal (N);
end if;
elsif Nkind (N) in N_Op then
if Nkind (N) = Nkind (Get_Associated_Node (N)) then
if Nkind (N) = N_Op_Concat then
Set_Is_Component_Left_Opnd (N,
Is_Component_Left_Opnd (Get_Associated_Node (N)));
Set_Is_Component_Right_Opnd (N,
Is_Component_Right_Opnd (Get_Associated_Node (N)));
end if;
Reset_Entity (N);
else
-- Node may be transformed into call to a user-defined operator
N2 := Get_Associated_Node (N);
if Nkind (N2) = N_Function_Call then
E := Entity (Name (N2));
if Present (E)
and then Is_Global (E)
then
Set_Etype (N, Etype (N2));
else
Set_Associated_Node (N, Empty);
Set_Etype (N, Empty);
end if;
elsif Nkind (N2) = N_Integer_Literal
or else Nkind (N2) = N_Real_Literal
or else Nkind (N2) = N_String_Literal
then
-- Operation was constant-folded, perform the same
-- replacement in generic.
Rewrite (N, New_Copy (N2));
Set_Analyzed (N, False);
elsif Nkind (N2) = N_Identifier
and then Ekind (Entity (N2)) = E_Enumeration_Literal
then
-- Same if call was folded into a literal, but in this
-- case retain the entity to avoid spurious ambiguities
-- if id is overloaded at the point of instantiation or
-- inlining.
Rewrite (N, New_Copy (N2));
Set_Analyzed (N, False);
end if;
end if;
-- Complete the check on operands, if node has not been
-- constant-folded.
if Nkind (N) in N_Op then
Save_Entity_Descendants (N);
end if;
elsif Nkind (N) = N_Identifier then
if Nkind (N) = Nkind (Get_Associated_Node (N)) then
-- If this is a discriminant reference, always save it.
-- It is used in the instance to find the corresponding
-- discriminant positionally rather than by name.
Set_Original_Discriminant
(N, Original_Discriminant (Get_Associated_Node (N)));
Reset_Entity (N);
else
N2 := Get_Associated_Node (N);
if Nkind (N2) = N_Function_Call then
E := Entity (Name (N2));
-- Name resolves to a call to parameterless function.
-- If original entity is global, mark node as resolved.
if Present (E)
and then Is_Global (E)
then
Set_Etype (N, Etype (N2));
else
Set_Associated_Node (N, Empty);
Set_Etype (N, Empty);
end if;
elsif
Nkind (N2) = N_Integer_Literal or else
Nkind (N2) = N_Real_Literal or else
Nkind (N2) = N_String_Literal
then
-- Name resolves to named number that is constant-folded,
-- or to string literal from concatenation.
-- Perform the same replacement in generic.
Rewrite (N, New_Copy (N2));
Set_Analyzed (N, False);
elsif Nkind (N2) = N_Explicit_Dereference then
-- An identifier is rewritten as a dereference if it is
-- the prefix in a selected component, and it denotes an
-- access to a composite type, or a parameterless function
-- call that returns an access type.
-- Check whether corresponding entity in prefix is global
if Is_Entity_Name (Prefix (N2))
and then Present (Entity (Prefix (N2)))
and then Is_Global (Entity (Prefix (N2)))
then
Rewrite (N,
Make_Explicit_Dereference (Sloc (N),
Prefix => Make_Identifier (Sloc (N),
Chars => Chars (N))));
Set_Associated_Node (Prefix (N), Prefix (N2));
elsif Nkind (Prefix (N2)) = N_Function_Call
and then Is_Global (Entity (Name (Prefix (N2))))
then
Rewrite (N,
Make_Explicit_Dereference (Sloc (N),
Prefix => Make_Function_Call (Sloc (N),
Name =>
Make_Identifier (Sloc (N),
Chars => Chars (N)))));
Set_Associated_Node
(Name (Prefix (N)), Name (Prefix (N2)));
else
Set_Associated_Node (N, Empty);
Set_Etype (N, Empty);
end if;
-- The subtype mark of a nominally unconstrained object
-- is rewritten as a subtype indication using the bounds
-- of the expression. Recover the original subtype mark.
elsif Nkind (N2) = N_Subtype_Indication
and then Is_Entity_Name (Original_Node (N2))
then
Set_Associated_Node (N, Original_Node (N2));
Reset_Entity (N);
else
null;
end if;
end if;
elsif Nkind (N) in N_Entity then
null;
else
declare
Loc : constant Source_Ptr := Sloc (N);
Qual : Node_Id := Empty;
Typ : Entity_Id := Empty;
Nam : Node_Id;
use Atree.Unchecked_Access;
-- This code section is part of implementing an untyped tree
-- traversal, so it needs direct access to node fields.
begin
if Nkind (N) = N_Aggregate
or else
Nkind (N) = N_Extension_Aggregate
then
N2 := Get_Associated_Node (N);
if No (N2) then
Typ := Empty;
else
Typ := Etype (N2);
-- In an instance within a generic, use the name of
-- the actual and not the original generic parameter.
-- If the actual is global in the current generic it
-- must be preserved for its instantiation.
if Nkind (Parent (Typ)) = N_Subtype_Declaration
and then
Present (Generic_Parent_Type (Parent (Typ)))
then
Typ := Base_Type (Typ);
Set_Etype (N2, Typ);
end if;
end if;
if No (N2)
or else No (Typ)
or else not Is_Global (Typ)
then
Set_Associated_Node (N, Empty);
-- If the aggregate is an actual in a call, it has been
-- resolved in the current context, to some local type.
-- The enclosing call may have been disambiguated by
-- the aggregate, and this disambiguation might fail at
-- instantiation time because the type to which the
-- aggregate did resolve is not preserved. In order to
-- preserve some of this information, we wrap the
-- aggregate in a qualified expression, using the id of
-- its type. For further disambiguation we qualify the
-- type name with its scope (if visible) because both
-- id's will have corresponding entities in an instance.
-- This resolves most of the problems with missing type
-- information on aggregates in instances.
if Nkind (N2) = Nkind (N)
and then
(Nkind (Parent (N2)) = N_Procedure_Call_Statement
or else Nkind (Parent (N2)) = N_Function_Call)
and then Comes_From_Source (Typ)
then
if Is_Immediately_Visible (Scope (Typ)) then
Nam := Make_Selected_Component (Loc,
Prefix =>
Make_Identifier (Loc, Chars (Scope (Typ))),
Selector_Name =>
Make_Identifier (Loc, Chars (Typ)));
else
Nam := Make_Identifier (Loc, Chars (Typ));
end if;
Qual :=
Make_Qualified_Expression (Loc,
Subtype_Mark => Nam,
Expression => Relocate_Node (N));
end if;
end if;
Save_Global_Descendant (Field1 (N));
Save_Global_Descendant (Field2 (N));
Save_Global_Descendant (Field3 (N));
Save_Global_Descendant (Field5 (N));
if Present (Qual) then
Rewrite (N, Qual);
end if;
-- All other cases than aggregates
else
Save_Global_Descendant (Field1 (N));
Save_Global_Descendant (Field2 (N));
Save_Global_Descendant (Field3 (N));
Save_Global_Descendant (Field4 (N));
Save_Global_Descendant (Field5 (N));
end if;
end;
end if;
end Save_References;
-- Start of processing for Save_Global_References
begin
Gen_Scope := Current_Scope;
-- If the generic unit is a child unit, references to entities in
-- the parent are treated as local, because they will be resolved
-- anew in the context of the instance of the parent.
while Is_Child_Unit (Gen_Scope)
and then Ekind (Scope (Gen_Scope)) = E_Generic_Package
loop
Gen_Scope := Scope (Gen_Scope);
end loop;
Save_References (N);
end Save_Global_References;
--------------------------------------
-- Set_Copied_Sloc_For_Inlined_Body --
--------------------------------------
procedure Set_Copied_Sloc_For_Inlined_Body (N : Node_Id; E : Entity_Id) is
begin
Create_Instantiation_Source (N, E, True, S_Adjustment);
end Set_Copied_Sloc_For_Inlined_Body;
---------------------
-- Set_Instance_Of --
---------------------
procedure Set_Instance_Of (A : Entity_Id; B : Entity_Id) is
begin
Generic_Renamings.Table (Generic_Renamings.Last) := (A, B, Assoc_Null);
Generic_Renamings_HTable.Set (Generic_Renamings.Last);
Generic_Renamings.Increment_Last;
end Set_Instance_Of;
--------------------
-- Set_Next_Assoc --
--------------------
procedure Set_Next_Assoc (E : Assoc_Ptr; Next : Assoc_Ptr) is
begin
Generic_Renamings.Table (E).Next_In_HTable := Next;
end Set_Next_Assoc;
-------------------
-- Start_Generic --
-------------------
procedure Start_Generic is
begin
-- ??? I am sure more things could be factored out in this
-- routine. Should probably be done at a later stage.
Generic_Flags.Increment_Last;
Generic_Flags.Table (Generic_Flags.Last) := Inside_A_Generic;
Inside_A_Generic := True;
Expander_Mode_Save_And_Set (False);
end Start_Generic;
----------------------
-- Set_Instance_Env --
----------------------
procedure Set_Instance_Env
(Gen_Unit : Entity_Id;
Act_Unit : Entity_Id)
is
begin
-- Regardless of the current mode, predefined units are analyzed in
-- the most current Ada mode, and earlier version Ada checks do not
-- apply to predefined units.
-- Why is this not using the routine Opt.Set_Opt_Config_Switches ???
if Is_Internal_File_Name
(Fname => Unit_File_Name (Get_Source_Unit (Gen_Unit)),
Renamings_Included => True) then
Ada_Version := Ada_Version_Type'Last;
end if;
Current_Instantiated_Parent := (Gen_Unit, Act_Unit, Assoc_Null);
end Set_Instance_Env;
-----------------
-- Switch_View --
-----------------
procedure Switch_View (T : Entity_Id) is
BT : constant Entity_Id := Base_Type (T);
Priv_Elmt : Elmt_Id := No_Elmt;
Priv_Sub : Entity_Id;
begin
-- T may be private but its base type may have been exchanged through
-- some other occurrence, in which case there is nothing to switch.
if not Is_Private_Type (BT) then
return;
end if;
Priv_Elmt := First_Elmt (Private_Dependents (BT));
if Present (Full_View (BT)) then
Prepend_Elmt (Full_View (BT), Exchanged_Views);
Exchange_Declarations (BT);
end if;
while Present (Priv_Elmt) loop
Priv_Sub := (Node (Priv_Elmt));
-- We avoid flipping the subtype if the Etype of its full
-- view is private because this would result in a malformed
-- subtype. This occurs when the Etype of the subtype full
-- view is the full view of the base type (and since the
-- base types were just switched, the subtype is pointing
-- to the wrong view). This is currently the case for
-- tagged record types, access types (maybe more?) and
-- needs to be resolved. ???
if Present (Full_View (Priv_Sub))
and then not Is_Private_Type (Etype (Full_View (Priv_Sub)))
then
Prepend_Elmt (Full_View (Priv_Sub), Exchanged_Views);
Exchange_Declarations (Priv_Sub);
end if;
Next_Elmt (Priv_Elmt);
end loop;
end Switch_View;
-----------------------------
-- Valid_Default_Attribute --
-----------------------------
procedure Valid_Default_Attribute (Nam : Entity_Id; Def : Node_Id) is
Attr_Id : constant Attribute_Id :=
Get_Attribute_Id (Attribute_Name (Def));
T : constant Entity_Id := Entity (Prefix (Def));
Is_Fun : constant Boolean := (Ekind (Nam) = E_Function);
F : Entity_Id;
Num_F : Int;
OK : Boolean;
begin
if No (T)
or else T = Any_Id
then
return;
end if;
Num_F := 0;
F := First_Formal (Nam);
while Present (F) loop
Num_F := Num_F + 1;
Next_Formal (F);
end loop;
case Attr_Id is
when Attribute_Adjacent | Attribute_Ceiling | Attribute_Copy_Sign |
Attribute_Floor | Attribute_Fraction | Attribute_Machine |
Attribute_Model | Attribute_Remainder | Attribute_Rounding |
Attribute_Unbiased_Rounding =>
OK := Is_Fun
and then Num_F = 1
and then Is_Floating_Point_Type (T);
when Attribute_Image | Attribute_Pred | Attribute_Succ |
Attribute_Value | Attribute_Wide_Image |
Attribute_Wide_Value =>
OK := (Is_Fun and then Num_F = 1 and then Is_Scalar_Type (T));
when Attribute_Max | Attribute_Min =>
OK := (Is_Fun and then Num_F = 2 and then Is_Scalar_Type (T));
when Attribute_Input =>
OK := (Is_Fun and then Num_F = 1);
when Attribute_Output | Attribute_Read | Attribute_Write =>
OK := (not Is_Fun and then Num_F = 2);
when others =>
OK := False;
end case;
if not OK then
Error_Msg_N ("attribute reference has wrong profile for subprogram",
Def);
end if;
end Valid_Default_Attribute;
end Sem_Ch12;
|
-- --
-- package Copyright (c) Dmitry A. Kazakov --
-- Strings_Edit.Streams Luebeck --
-- Interface Spring, 2009 --
-- --
-- Last revision : 14:23 11 Feb 2012 --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public License as --
-- published by the Free Software Foundation; either version 2 of --
-- the License, or (at your option) any later version. This library --
-- is distributed in the hope that it will be useful, but WITHOUT --
-- ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from --
-- this unit, or you link this unit with other files to produce an --
-- executable, this unit does not by itself cause the resulting --
-- executable to be covered by the GNU General Public License. This --
-- exception does not however invalidate any other reasons why the --
-- executable file might be covered by the GNU Public License. --
--____________________________________________________________________--
--
-- The package provides stream interface to string. A string can be
-- read and written using stream I/O attributes.
--
with Ada.Streams; use Ada.Streams;
with System.Storage_Elements;
package Strings_Edit.Streams is
--
-- String_Stream -- A string stream, when read, Data (Position..Length)
-- is amount of data available to read/write. Note that
-- before reading from the stream is must be initialized using Set.
-- Otherwise the result of reading will be the unitialized contents of
-- the Data field.
--
type String_Stream (Length : Natural) is
new Root_Stream_Type with
record
Position : Positive := 1;
Data : String (1..Length);
end record;
--
-- Get -- Written contents of the stream
--
-- Stream - The stream object
--
-- Get is an operation inverse to T'Write.
--
-- Returns :
--
-- String written
--
function Get (Stream : String_Stream) return String;
--
-- Get_Size -- Number of stream elements available to write or to read
--
-- Stream - The stream object
--
function Get_Size (Stream : String_Stream)
return Stream_Element_Count;
--
-- Read -- Overrides Ada.Streams...
--
procedure Read
( Stream : in out String_Stream;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset
);
--
-- Rewind -- The stream
--
-- Stream - The stream object
--
-- This procedure moves Stream.Position to the beginning. This undoes
-- all reading/writing actions.
--
procedure Rewind (Stream : in out String_Stream);
--
-- Set -- Contents
--
-- Stream - The stream object
-- Content - String to read
--
-- The stream is changed to contain Content. The next read operation
-- will yield the first character of Content. Set is an operation
-- inverse to T'Read.
--
-- Exceptions :
--
-- Contraint_Error - no room in Stream
--
procedure Set (Stream : in out String_Stream; Content : String);
--
-- Write -- Overrides Ada.Streams...
--
-- Exceptions :
--
-- End_Error - No room in the string
--
procedure Write
( Stream : in out String_Stream;
Item : Stream_Element_Array
);
private
use System.Storage_Elements;
pragma Inline (Get_Size);
--
-- Char_Count -- Number of characters per string elements
--
Char_Count : constant := Stream_Element'Size / Character'Size;
--
-- Stream_Element'Size must be a multiple of Character'Size and the
-- later be a multiple of Storage_Element'Size.
--
subtype Confirmed is Boolean range True..True;
Assert : constant Confirmed :=
( Char_Count * Character'Size = Stream_Element'Size
and then
Character'Size mod Storage_Element'Size = 0
);
end Strings_Edit.Streams;
|
with Ada.Text_IO; use Ada.Text_IO;
with AAA.Strings;
with CLIC.User_Input; use CLIC.User_Input;
with GNAT.OS_Lib;
package body CLIC_Ex.Commands.User_Input is
function Valid_Number (Str : String) return Boolean
is (for all C of Str => C in '0' .. '9');
-------------
-- Execute --
-------------
overriding procedure Execute
(Cmd : in out Instance; Args : AAA.Strings.Vector)
is
begin
declare
Answer : Answer_Kind;
begin
Answer := Query (Question => "Do you like this tool?",
Valid => (others => True),
Default => Yes);
if Answer = No then
Put_Line ("Fine then.");
GNAT.OS_Lib.OS_Exit (42);
end if;
end;
declare
Languages : constant AAA.Strings.Vector :=
AAA.Strings.Empty_Vector
.Append ("Ada")
.Append ("C")
.Append ("C++")
.Append ("Rust")
.Append ("OCAML")
.Append ("Fortran")
.Append ("Go");
Answer : Positive;
begin
Answer := Query_Multi
(Question => "What is you favorite programming language?",
Choices => Languages);
if Answer /= 1 then
Put_Line ("Wrong answer.");
GNAT.OS_Lib.OS_Exit (42);
end if;
end;
Continue_Or_Abort;
declare
Answer : constant String :=
Query_String (Question => "Enter a number please",
Default => "42",
Validation => Valid_Number'Access);
begin
Put_Line ("Thanks for your answer: '" & Answer & "'");
end;
end Execute;
end CLIC_Ex.Commands.User_Input;
|
with STM32GD.Board; use STM32GD.Board;
procedure Main is
Now : RTC.Date_Time_Type;
Wait_Time : RTC.Second_Delta_Type := 5;
begin
Init;
Text_IO.Put_Line ("RTC Test Starting");
loop
RTC.Read (Now);
LED.Set;
Text_IO.Put ("Seconds: ");
Text_IO.Put_Integer (RTC.To_Seconds (Now));
Text_IO.New_Line;
RTC.Add_Seconds (Now, Wait_Time);
RTC.Set_Alarm (Now);
Text_IO.Put ("Waking up in: ");
Text_IO.Put_Integer (RTC.To_Seconds (Now));
Text_IO.New_Line;
LED.Clear;
RTC.Wait_For_Alarm;
end loop;
end Main;
|
-- This package is intended to set up and tear down the test environment.
-- Once created by GNATtest, this package will never be overwritten
-- automatically. Contents of this package can be modified in any way
-- except for sections surrounded by a 'read only' marker.
with AUnit.Test_Fixtures;
package Tashy2.Test_Data is
-- begin read only
type Test is new AUnit.Test_Fixtures.Test_Fixture
-- end read only
with null record;
procedure Set_Up(Gnattest_T: in out Test);
procedure Tear_Down(Gnattest_T: in out Test);
end Tashy2.Test_Data;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M --
-- --
-- S p e c --
-- (Darwin/ARM Version) --
-- --
-- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
-- apply solely to the contents of the part following the private keyword. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package System is
pragma Pure;
-- Note that we take advantage of the implementation permission to make
-- this unit Pure instead of Preelaborable; see RM 13.7.1(15). In Ada
-- 2005, this is Pure in any case (AI-362).
pragma No_Elaboration_Code_All;
-- Allow the use of that restriction in units that WITH this unit
type Name is (SYSTEM_NAME_GNAT);
System_Name : constant Name := SYSTEM_NAME_GNAT;
-- System-Dependent Named Numbers
Min_Int : constant := Long_Long_Integer'First;
Max_Int : constant := Long_Long_Integer'Last;
Max_Binary_Modulus : constant := 2 ** Long_Long_Integer'Size;
Max_Nonbinary_Modulus : constant := 2 ** Integer'Size - 1;
Max_Base_Digits : constant := Long_Long_Float'Digits;
Max_Digits : constant := Long_Long_Float'Digits;
Max_Mantissa : constant := 63;
Fine_Delta : constant := 2.0 ** (-Max_Mantissa);
Tick : constant := 0.01;
-- Storage-related Declarations
type Address is private;
pragma Preelaborable_Initialization (Address);
Null_Address : constant Address;
Storage_Unit : constant := 8;
Word_Size : constant := Standard'Word_Size;
Memory_Size : constant := 2 ** Word_Size;
-- Address comparison
function "<" (Left, Right : Address) return Boolean;
function "<=" (Left, Right : Address) return Boolean;
function ">" (Left, Right : Address) return Boolean;
function ">=" (Left, Right : Address) return Boolean;
function "=" (Left, Right : Address) return Boolean;
pragma Import (Intrinsic, "<");
pragma Import (Intrinsic, "<=");
pragma Import (Intrinsic, ">");
pragma Import (Intrinsic, ">=");
pragma Import (Intrinsic, "=");
-- Other System-Dependent Declarations
type Bit_Order is (High_Order_First, Low_Order_First);
Default_Bit_Order : constant Bit_Order := Low_Order_First;
pragma Warnings (Off, Default_Bit_Order); -- kill constant condition warning
-- Priority-related Declarations (RM D.1)
-- The values defined here are derived from the following Darwin
-- sources:
--
-- Libc/pthreads/pthread.c
-- pthread_init calls host_info to retrieve the HOST_PRIORITY_INFO.
-- This file includes "pthread_internals".
-- Libc/pthreads/pthread_internals.h
-- This file includes <mach/mach.h>.
-- xnu/osfmk/mach/mach.h
-- This file includes <mach/mach_types.h>.
-- xnu/osfmk/mach/mach_types.h
-- This file includes <mach/host_info.h>.
-- xnu/osfmk/mach/host_info.h
-- This file contains the definition of the host_info_t data structure
-- and the function prototype for host_info.
-- xnu/osfmk/kern/host.c
-- This file defines the function host_info which sets the
-- priority_info field of struct host_info_t. This file includes
-- <kern/processor.h>.
-- xnu/osfmk/kern/processor.h
-- This file includes <kern/sched.h>.
-- xnu/osfmk/kern/sched.h
-- This file defines the values for each level of priority.
Max_Interrupt_Priority : constant Positive := 63;
Max_Priority : constant Positive := Max_Interrupt_Priority - 1;
subtype Any_Priority is Integer range 0 .. Max_Interrupt_Priority;
subtype Priority is Any_Priority range 0 .. Max_Priority;
subtype Interrupt_Priority is Any_Priority
range Priority'Last + 1 .. Max_Interrupt_Priority;
Default_Priority : constant Priority :=
(Priority'Last - Priority'First) / 2;
private
type Address is mod Memory_Size;
Null_Address : constant Address := 0;
--------------------------------------
-- System Implementation Parameters --
--------------------------------------
-- These parameters provide information about the target that is used
-- by the compiler. They are in the private part of System, where they
-- can be accessed using the special circuitry in the Targparm unit
-- whose source should be consulted for more detailed descriptions
-- of the individual switch values.
Backend_Divide_Checks : constant Boolean := False;
Backend_Overflow_Checks : constant Boolean := True;
Command_Line_Args : constant Boolean := True;
Configurable_Run_Time : constant Boolean := False;
Denorm : constant Boolean := True;
Duration_32_Bits : constant Boolean := False;
Exit_Status_Supported : constant Boolean := True;
Fractional_Fixed_Ops : constant Boolean := False;
Frontend_Layout : constant Boolean := False;
Machine_Overflows : constant Boolean := False;
Machine_Rounds : constant Boolean := True;
Preallocated_Stacks : constant Boolean := False;
Signed_Zeros : constant Boolean := True;
Stack_Check_Default : constant Boolean := False;
Stack_Check_Probes : constant Boolean := True;
Stack_Check_Limits : constant Boolean := False;
Support_Aggregates : constant Boolean := True;
Support_Atomic_Primitives : constant Boolean := True;
Support_Composite_Assign : constant Boolean := True;
Support_Composite_Compare : constant Boolean := True;
Support_Long_Shifts : constant Boolean := True;
Always_Compatible_Rep : constant Boolean := False;
Suppress_Standard_Library : constant Boolean := False;
Use_Ada_Main_Program_Name : constant Boolean := False;
Frontend_Exceptions : constant Boolean := False;
ZCX_By_Default : constant Boolean := True;
end System;
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="14">
<syndb class_id="0" tracking_level="0" version="0">
<userIPLatency>-1</userIPLatency>
<userIPName></userIPName>
<cdfg class_id="1" tracking_level="1" version="0" object_id="_0">
<name>Stream2Mem</name>
<ret_bitwidth>0</ret_bitwidth>
<ports class_id="2" tracking_level="0" version="0">
<count>4</count>
<item_version>0</item_version>
<item class_id="3" tracking_level="1" version="0" object_id="_1">
<Value class_id="4" tracking_level="0" version="0">
<Obj class_id="5" tracking_level="0" version="0">
<type>1</type>
<id>1</id>
<name>in_V_V</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo class_id="6" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>in.V.V</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>64</bitwidth>
</Value>
<direction>0</direction>
<if_type>3</if_type>
<array_size>0</array_size>
<bit_vecs class_id="7" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</bit_vecs>
</item>
<item class_id_reference="3" object_id="_2">
<Value>
<Obj>
<type>1</type>
<id>2</id>
<name>out_V</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>out.V</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>64</bitwidth>
</Value>
<direction>1</direction>
<if_type>4</if_type>
<array_size>0</array_size>
<bit_vecs>
<count>0</count>
<item_version>0</item_version>
</bit_vecs>
</item>
<item class_id_reference="3" object_id="_3">
<Value>
<Obj>
<type>1</type>
<id>3</id>
<name>out_V3</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>61</bitwidth>
</Value>
<direction>0</direction>
<if_type>0</if_type>
<array_size>0</array_size>
<bit_vecs>
<count>0</count>
<item_version>0</item_version>
</bit_vecs>
</item>
<item class_id_reference="3" object_id="_4">
<Value>
<Obj>
<type>1</type>
<id>4</id>
<name>tmp_2</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>32</bitwidth>
</Value>
<direction>0</direction>
<if_type>0</if_type>
<array_size>0</array_size>
<bit_vecs>
<count>0</count>
<item_version>0</item_version>
</bit_vecs>
</item>
</ports>
<nodes class_id="8" tracking_level="0" version="0">
<count>18</count>
<item_version>0</item_version>
<item class_id="9" tracking_level="1" version="0" object_id="_5">
<Value>
<Obj>
<type>0</type>
<id>5</id>
<name>tmp_2_read</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>32</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>34</item>
<item>35</item>
</oprand_edges>
<opcode>read</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_6">
<Value>
<Obj>
<type>0</type>
<id>6</id>
<name>out_V3_read</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>61</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>37</item>
<item>38</item>
</oprand_edges>
<opcode>read</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_7">
<Value>
<Obj>
<type>0</type>
<id>9</id>
<name>tmp_5_cast</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>62</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>39</item>
</oprand_edges>
<opcode>zext</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_8">
<Value>
<Obj>
<type>0</type>
<id>10</id>
<name>out_V3_cast8</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>62</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>40</item>
</oprand_edges>
<opcode>zext</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_9">
<Value>
<Obj>
<type>0</type>
<id>11</id>
<name>sum1</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>62</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>41</item>
<item>42</item>
</oprand_edges>
<opcode>add</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_10">
<Value>
<Obj>
<type>0</type>
<id>12</id>
<name>sum1_cast</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>64</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>43</item>
</oprand_edges>
<opcode>zext</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_11">
<Value>
<Obj>
<type>0</type>
<id>13</id>
<name>out_V_addr</name>
<fileName>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</fileName>
<fileDirectory>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</fileDirectory>
<lineNumber>156</lineNumber>
<contextFuncName>Stream2Mem&lt;64, 128&gt;</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item class_id="11" tracking_level="0" version="0">
<first>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</first>
<second class_id="12" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="13" tracking_level="0" version="0">
<first class_id="14" tracking_level="0" version="0">
<first>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</first>
<second>Stream2Mem&lt;64, 128&gt;</second>
</first>
<second>156</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>64</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>44</item>
<item>45</item>
</oprand_edges>
<opcode>getelementptr</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_12">
<Value>
<Obj>
<type>0</type>
<id>14</id>
<name>out_V_addr_wr_req</name>
<fileName>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</fileName>
<fileDirectory>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</fileDirectory>
<lineNumber>156</lineNumber>
<contextFuncName>Stream2Mem&lt;64, 128&gt;</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</first>
<second>Stream2Mem&lt;64, 128&gt;</second>
</first>
<second>156</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>1</bitwidth>
</Value>
<oprand_edges>
<count>3</count>
<item_version>0</item_version>
<item>47</item>
<item>48</item>
<item>50</item>
</oprand_edges>
<opcode>writereq</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_13">
<Value>
<Obj>
<type>0</type>
<id>15</id>
<name></name>
<fileName>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</fileName>
<fileDirectory>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</fileDirectory>
<lineNumber>153</lineNumber>
<contextFuncName>Stream2Mem&lt;64, 128&gt;</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</first>
<second>Stream2Mem&lt;64, 128&gt;</second>
</first>
<second>153</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>51</item>
</oprand_edges>
<opcode>br</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_14">
<Value>
<Obj>
<type>0</type>
<id>17</id>
<name>i</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>i</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>5</bitwidth>
</Value>
<oprand_edges>
<count>4</count>
<item_version>0</item_version>
<item>53</item>
<item>54</item>
<item>55</item>
<item>56</item>
</oprand_edges>
<opcode>phi</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_15">
<Value>
<Obj>
<type>0</type>
<id>18</id>
<name>tmp</name>
<fileName>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</fileName>
<fileDirectory>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</fileDirectory>
<lineNumber>153</lineNumber>
<contextFuncName>Stream2Mem&lt;64, 128&gt;</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</first>
<second>Stream2Mem&lt;64, 128&gt;</second>
</first>
<second>153</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>1</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>57</item>
<item>59</item>
</oprand_edges>
<opcode>icmp</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_16">
<Value>
<Obj>
<type>0</type>
<id>19</id>
<name>i_1</name>
<fileName>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</fileName>
<fileDirectory>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</fileDirectory>
<lineNumber>153</lineNumber>
<contextFuncName>Stream2Mem&lt;64, 128&gt;</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</first>
<second>Stream2Mem&lt;64, 128&gt;</second>
</first>
<second>153</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName>i</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>5</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>60</item>
<item>62</item>
</oprand_edges>
<opcode>add</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_17">
<Value>
<Obj>
<type>0</type>
<id>20</id>
<name></name>
<fileName>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</fileName>
<fileDirectory>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</fileDirectory>
<lineNumber>153</lineNumber>
<contextFuncName>Stream2Mem&lt;64, 128&gt;</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</first>
<second>Stream2Mem&lt;64, 128&gt;</second>
</first>
<second>153</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>3</count>
<item_version>0</item_version>
<item>63</item>
<item>64</item>
<item>65</item>
</oprand_edges>
<opcode>br</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_18">
<Value>
<Obj>
<type>0</type>
<id>25</id>
<name>tmp_V</name>
<fileName>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</fileName>
<fileDirectory>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</fileDirectory>
<lineNumber>155</lineNumber>
<contextFuncName>Stream2Mem&lt;64, 128&gt;</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</first>
<second>Stream2Mem&lt;64, 128&gt;</second>
</first>
<second>155</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName>tmp.V</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>64</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>67</item>
<item>68</item>
</oprand_edges>
<opcode>read</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_19">
<Value>
<Obj>
<type>0</type>
<id>26</id>
<name></name>
<fileName>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</fileName>
<fileDirectory>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</fileDirectory>
<lineNumber>156</lineNumber>
<contextFuncName>Stream2Mem&lt;64, 128&gt;</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</first>
<second>Stream2Mem&lt;64, 128&gt;</second>
</first>
<second>156</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>5</count>
<item_version>0</item_version>
<item>70</item>
<item>71</item>
<item>72</item>
<item>74</item>
<item>149</item>
</oprand_edges>
<opcode>write</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_20">
<Value>
<Obj>
<type>0</type>
<id>28</id>
<name></name>
<fileName>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</fileName>
<fileDirectory>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</fileDirectory>
<lineNumber>153</lineNumber>
<contextFuncName>Stream2Mem&lt;64, 128&gt;</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</first>
<second>Stream2Mem&lt;64, 128&gt;</second>
</first>
<second>153</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>75</item>
</oprand_edges>
<opcode>br</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_21">
<Value>
<Obj>
<type>0</type>
<id>30</id>
<name>out_V_addr_wr_resp</name>
<fileName>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</fileName>
<fileDirectory>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</fileDirectory>
<lineNumber>156</lineNumber>
<contextFuncName>Stream2Mem&lt;64, 128&gt;</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</first>
<second>Stream2Mem&lt;64, 128&gt;</second>
</first>
<second>156</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>1</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>77</item>
<item>78</item>
</oprand_edges>
<opcode>writeresp</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_22">
<Value>
<Obj>
<type>0</type>
<id>31</id>
<name></name>
<fileName>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</fileName>
<fileDirectory>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</fileDirectory>
<lineNumber>158</lineNumber>
<contextFuncName>Stream2Mem&lt;64, 128&gt;</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/jf2715/BNN-PYNQ/bnn/src/network/output/hls-syn</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>/home/jf2715/BNN-PYNQ/bnn/src//library/finn-hlslib/dma.h</first>
<second>Stream2Mem&lt;64, 128&gt;</second>
</first>
<second>158</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>0</count>
<item_version>0</item_version>
</oprand_edges>
<opcode>ret</opcode>
<m_Display>0</m_Display>
</item>
</nodes>
<consts class_id="15" tracking_level="0" version="0">
<count>5</count>
<item_version>0</item_version>
<item class_id="16" tracking_level="1" version="0" object_id="_23">
<Value>
<Obj>
<type>2</type>
<id>49</id>
<name>empty</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>32</bitwidth>
</Value>
<const_type>0</const_type>
<content>16</content>
</item>
<item class_id_reference="16" object_id="_24">
<Value>
<Obj>
<type>2</type>
<id>52</id>
<name>empty</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>5</bitwidth>
</Value>
<const_type>0</const_type>
<content>0</content>
</item>
<item class_id_reference="16" object_id="_25">
<Value>
<Obj>
<type>2</type>
<id>58</id>
<name>empty</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>5</bitwidth>
</Value>
<const_type>0</const_type>
<content>16</content>
</item>
<item class_id_reference="16" object_id="_26">
<Value>
<Obj>
<type>2</type>
<id>61</id>
<name>empty</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>5</bitwidth>
</Value>
<const_type>0</const_type>
<content>1</content>
</item>
<item class_id_reference="16" object_id="_27">
<Value>
<Obj>
<type>2</type>
<id>73</id>
<name>empty</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>8</bitwidth>
</Value>
<const_type>0</const_type>
<content>255</content>
</item>
</consts>
<blocks class_id="17" tracking_level="0" version="0">
<count>4</count>
<item_version>0</item_version>
<item class_id="18" tracking_level="1" version="0" object_id="_28">
<Obj>
<type>3</type>
<id>16</id>
<name></name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<node_objs>
<count>9</count>
<item_version>0</item_version>
<item>5</item>
<item>6</item>
<item>9</item>
<item>10</item>
<item>11</item>
<item>12</item>
<item>13</item>
<item>14</item>
<item>15</item>
</node_objs>
</item>
<item class_id_reference="18" object_id="_29">
<Obj>
<type>3</type>
<id>21</id>
<name></name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<node_objs>
<count>4</count>
<item_version>0</item_version>
<item>17</item>
<item>18</item>
<item>19</item>
<item>20</item>
</node_objs>
</item>
<item class_id_reference="18" object_id="_30">
<Obj>
<type>3</type>
<id>29</id>
<name></name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<node_objs>
<count>3</count>
<item_version>0</item_version>
<item>25</item>
<item>26</item>
<item>28</item>
</node_objs>
</item>
<item class_id_reference="18" object_id="_31">
<Obj>
<type>3</type>
<id>32</id>
<name></name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<node_objs>
<count>2</count>
<item_version>0</item_version>
<item>30</item>
<item>31</item>
</node_objs>
</item>
</blocks>
<edges class_id="19" tracking_level="0" version="0">
<count>34</count>
<item_version>0</item_version>
<item class_id="20" tracking_level="1" version="0" object_id="_32">
<id>35</id>
<edge_type>1</edge_type>
<source_obj>4</source_obj>
<sink_obj>5</sink_obj>
</item>
<item class_id_reference="20" object_id="_33">
<id>38</id>
<edge_type>1</edge_type>
<source_obj>3</source_obj>
<sink_obj>6</sink_obj>
</item>
<item class_id_reference="20" object_id="_34">
<id>39</id>
<edge_type>1</edge_type>
<source_obj>5</source_obj>
<sink_obj>9</sink_obj>
</item>
<item class_id_reference="20" object_id="_35">
<id>40</id>
<edge_type>1</edge_type>
<source_obj>6</source_obj>
<sink_obj>10</sink_obj>
</item>
<item class_id_reference="20" object_id="_36">
<id>41</id>
<edge_type>1</edge_type>
<source_obj>10</source_obj>
<sink_obj>11</sink_obj>
</item>
<item class_id_reference="20" object_id="_37">
<id>42</id>
<edge_type>1</edge_type>
<source_obj>9</source_obj>
<sink_obj>11</sink_obj>
</item>
<item class_id_reference="20" object_id="_38">
<id>43</id>
<edge_type>1</edge_type>
<source_obj>11</source_obj>
<sink_obj>12</sink_obj>
</item>
<item class_id_reference="20" object_id="_39">
<id>44</id>
<edge_type>1</edge_type>
<source_obj>2</source_obj>
<sink_obj>13</sink_obj>
</item>
<item class_id_reference="20" object_id="_40">
<id>45</id>
<edge_type>1</edge_type>
<source_obj>12</source_obj>
<sink_obj>13</sink_obj>
</item>
<item class_id_reference="20" object_id="_41">
<id>48</id>
<edge_type>1</edge_type>
<source_obj>13</source_obj>
<sink_obj>14</sink_obj>
</item>
<item class_id_reference="20" object_id="_42">
<id>50</id>
<edge_type>1</edge_type>
<source_obj>49</source_obj>
<sink_obj>14</sink_obj>
</item>
<item class_id_reference="20" object_id="_43">
<id>51</id>
<edge_type>2</edge_type>
<source_obj>21</source_obj>
<sink_obj>15</sink_obj>
</item>
<item class_id_reference="20" object_id="_44">
<id>53</id>
<edge_type>1</edge_type>
<source_obj>52</source_obj>
<sink_obj>17</sink_obj>
</item>
<item class_id_reference="20" object_id="_45">
<id>54</id>
<edge_type>2</edge_type>
<source_obj>16</source_obj>
<sink_obj>17</sink_obj>
</item>
<item class_id_reference="20" object_id="_46">
<id>55</id>
<edge_type>1</edge_type>
<source_obj>19</source_obj>
<sink_obj>17</sink_obj>
</item>
<item class_id_reference="20" object_id="_47">
<id>56</id>
<edge_type>2</edge_type>
<source_obj>29</source_obj>
<sink_obj>17</sink_obj>
</item>
<item class_id_reference="20" object_id="_48">
<id>57</id>
<edge_type>1</edge_type>
<source_obj>17</source_obj>
<sink_obj>18</sink_obj>
</item>
<item class_id_reference="20" object_id="_49">
<id>59</id>
<edge_type>1</edge_type>
<source_obj>58</source_obj>
<sink_obj>18</sink_obj>
</item>
<item class_id_reference="20" object_id="_50">
<id>60</id>
<edge_type>1</edge_type>
<source_obj>17</source_obj>
<sink_obj>19</sink_obj>
</item>
<item class_id_reference="20" object_id="_51">
<id>62</id>
<edge_type>1</edge_type>
<source_obj>61</source_obj>
<sink_obj>19</sink_obj>
</item>
<item class_id_reference="20" object_id="_52">
<id>63</id>
<edge_type>1</edge_type>
<source_obj>18</source_obj>
<sink_obj>20</sink_obj>
</item>
<item class_id_reference="20" object_id="_53">
<id>64</id>
<edge_type>2</edge_type>
<source_obj>29</source_obj>
<sink_obj>20</sink_obj>
</item>
<item class_id_reference="20" object_id="_54">
<id>65</id>
<edge_type>2</edge_type>
<source_obj>32</source_obj>
<sink_obj>20</sink_obj>
</item>
<item class_id_reference="20" object_id="_55">
<id>68</id>
<edge_type>1</edge_type>
<source_obj>1</source_obj>
<sink_obj>25</sink_obj>
</item>
<item class_id_reference="20" object_id="_56">
<id>71</id>
<edge_type>1</edge_type>
<source_obj>13</source_obj>
<sink_obj>26</sink_obj>
</item>
<item class_id_reference="20" object_id="_57">
<id>72</id>
<edge_type>1</edge_type>
<source_obj>25</source_obj>
<sink_obj>26</sink_obj>
</item>
<item class_id_reference="20" object_id="_58">
<id>74</id>
<edge_type>1</edge_type>
<source_obj>73</source_obj>
<sink_obj>26</sink_obj>
</item>
<item class_id_reference="20" object_id="_59">
<id>75</id>
<edge_type>2</edge_type>
<source_obj>21</source_obj>
<sink_obj>28</sink_obj>
</item>
<item class_id_reference="20" object_id="_60">
<id>78</id>
<edge_type>1</edge_type>
<source_obj>13</source_obj>
<sink_obj>30</sink_obj>
</item>
<item class_id_reference="20" object_id="_61">
<id>145</id>
<edge_type>2</edge_type>
<source_obj>16</source_obj>
<sink_obj>21</sink_obj>
</item>
<item class_id_reference="20" object_id="_62">
<id>146</id>
<edge_type>2</edge_type>
<source_obj>21</source_obj>
<sink_obj>32</sink_obj>
</item>
<item class_id_reference="20" object_id="_63">
<id>147</id>
<edge_type>2</edge_type>
<source_obj>21</source_obj>
<sink_obj>29</sink_obj>
</item>
<item class_id_reference="20" object_id="_64">
<id>148</id>
<edge_type>2</edge_type>
<source_obj>29</source_obj>
<sink_obj>21</sink_obj>
</item>
<item class_id_reference="20" object_id="_65">
<id>149</id>
<edge_type>4</edge_type>
<source_obj>14</source_obj>
<sink_obj>26</sink_obj>
</item>
</edges>
</cdfg>
<cdfg_regions class_id="21" tracking_level="0" version="0">
<count>4</count>
<item_version>0</item_version>
<item class_id="22" tracking_level="1" version="0" object_id="_66">
<mId>1</mId>
<mTag>Stream2Mem</mTag>
<mType>0</mType>
<sub_regions>
<count>3</count>
<item_version>0</item_version>
<item>2</item>
<item>3</item>
<item>4</item>
</sub_regions>
<basic_blocks>
<count>0</count>
<item_version>0</item_version>
</basic_blocks>
<mII>-1</mII>
<mDepth>-1</mDepth>
<mMinTripCount>-1</mMinTripCount>
<mMaxTripCount>-1</mMaxTripCount>
<mMinLatency>24</mMinLatency>
<mMaxLatency>-1</mMaxLatency>
<mIsDfPipe>0</mIsDfPipe>
<mDfPipe class_id="-1"></mDfPipe>
</item>
<item class_id_reference="22" object_id="_67">
<mId>2</mId>
<mTag>Entry</mTag>
<mType>0</mType>
<sub_regions>
<count>0</count>
<item_version>0</item_version>
</sub_regions>
<basic_blocks>
<count>1</count>
<item_version>0</item_version>
<item>16</item>
</basic_blocks>
<mII>-1</mII>
<mDepth>-1</mDepth>
<mMinTripCount>-1</mMinTripCount>
<mMaxTripCount>-1</mMaxTripCount>
<mMinLatency>1</mMinLatency>
<mMaxLatency>-1</mMaxLatency>
<mIsDfPipe>0</mIsDfPipe>
<mDfPipe class_id="-1"></mDfPipe>
</item>
<item class_id_reference="22" object_id="_68">
<mId>3</mId>
<mTag>Loop 1</mTag>
<mType>1</mType>
<sub_regions>
<count>0</count>
<item_version>0</item_version>
</sub_regions>
<basic_blocks>
<count>2</count>
<item_version>0</item_version>
<item>21</item>
<item>29</item>
</basic_blocks>
<mII>1</mII>
<mDepth>3</mDepth>
<mMinTripCount>16</mMinTripCount>
<mMaxTripCount>16</mMaxTripCount>
<mMinLatency>17</mMinLatency>
<mMaxLatency>-1</mMaxLatency>
<mIsDfPipe>0</mIsDfPipe>
<mDfPipe class_id="-1"></mDfPipe>
</item>
<item class_id_reference="22" object_id="_69">
<mId>4</mId>
<mTag>Return</mTag>
<mType>0</mType>
<sub_regions>
<count>0</count>
<item_version>0</item_version>
</sub_regions>
<basic_blocks>
<count>1</count>
<item_version>0</item_version>
<item>32</item>
</basic_blocks>
<mII>-1</mII>
<mDepth>-1</mDepth>
<mMinTripCount>-1</mMinTripCount>
<mMaxTripCount>-1</mMaxTripCount>
<mMinLatency>4</mMinLatency>
<mMaxLatency>-1</mMaxLatency>
<mIsDfPipe>0</mIsDfPipe>
<mDfPipe class_id="-1"></mDfPipe>
</item>
</cdfg_regions>
<fsm class_id="-1"></fsm>
<res class_id="-1"></res>
<node_label_latency class_id="26" tracking_level="0" version="0">
<count>18</count>
<item_version>0</item_version>
<item class_id="27" tracking_level="0" version="0">
<first>5</first>
<second class_id="28" tracking_level="0" version="0">
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>6</first>
<second>
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>9</first>
<second>
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>10</first>
<second>
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>11</first>
<second>
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>12</first>
<second>
<first>1</first>
<second>0</second>
</second>
</item>
<item>
<first>13</first>
<second>
<first>1</first>
<second>0</second>
</second>
</item>
<item>
<first>14</first>
<second>
<first>1</first>
<second>0</second>
</second>
</item>
<item>
<first>15</first>
<second>
<first>1</first>
<second>0</second>
</second>
</item>
<item>
<first>17</first>
<second>
<first>2</first>
<second>0</second>
</second>
</item>
<item>
<first>18</first>
<second>
<first>2</first>
<second>0</second>
</second>
</item>
<item>
<first>19</first>
<second>
<first>2</first>
<second>0</second>
</second>
</item>
<item>
<first>20</first>
<second>
<first>2</first>
<second>0</second>
</second>
</item>
<item>
<first>25</first>
<second>
<first>3</first>
<second>0</second>
</second>
</item>
<item>
<first>26</first>
<second>
<first>4</first>
<second>0</second>
</second>
</item>
<item>
<first>28</first>
<second>
<first>4</first>
<second>0</second>
</second>
</item>
<item>
<first>30</first>
<second>
<first>3</first>
<second>4</second>
</second>
</item>
<item>
<first>31</first>
<second>
<first>7</first>
<second>0</second>
</second>
</item>
</node_label_latency>
<bblk_ent_exit class_id="29" tracking_level="0" version="0">
<count>4</count>
<item_version>0</item_version>
<item class_id="30" tracking_level="0" version="0">
<first>16</first>
<second class_id="31" tracking_level="0" version="0">
<first>0</first>
<second>1</second>
</second>
</item>
<item>
<first>21</first>
<second>
<first>2</first>
<second>2</second>
</second>
</item>
<item>
<first>29</first>
<second>
<first>3</first>
<second>4</second>
</second>
</item>
<item>
<first>32</first>
<second>
<first>3</first>
<second>7</second>
</second>
</item>
</bblk_ent_exit>
<regions class_id="32" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="33" tracking_level="1" version="0" object_id="_70">
<region_name>Loop 1</region_name>
<basic_blocks>
<count>2</count>
<item_version>0</item_version>
<item>21</item>
<item>29</item>
</basic_blocks>
<nodes>
<count>0</count>
<item_version>0</item_version>
</nodes>
<anchor_node>-1</anchor_node>
<region_type>8</region_type>
<interval>1</interval>
<pipe_depth>3</pipe_depth>
</item>
</regions>
<dp_fu_nodes class_id="34" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</dp_fu_nodes>
<dp_fu_nodes_expression class_id="35" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</dp_fu_nodes_expression>
<dp_fu_nodes_module>
<count>0</count>
<item_version>0</item_version>
</dp_fu_nodes_module>
<dp_fu_nodes_io>
<count>0</count>
<item_version>0</item_version>
</dp_fu_nodes_io>
<return_ports>
<count>0</count>
<item_version>0</item_version>
</return_ports>
<dp_mem_port_nodes class_id="36" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</dp_mem_port_nodes>
<dp_reg_nodes>
<count>0</count>
<item_version>0</item_version>
</dp_reg_nodes>
<dp_regname_nodes>
<count>0</count>
<item_version>0</item_version>
</dp_regname_nodes>
<dp_reg_phi>
<count>0</count>
<item_version>0</item_version>
</dp_reg_phi>
<dp_regname_phi>
<count>0</count>
<item_version>0</item_version>
</dp_regname_phi>
<dp_port_io_nodes class_id="37" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</dp_port_io_nodes>
<port2core class_id="38" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</port2core>
<node2core>
<count>0</count>
<item_version>0</item_version>
</node2core>
</syndb>
</boost_serialization>
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
-- An action input pin is a kind of pin that executes an action to determine
-- the values to input to another.
------------------------------------------------------------------------------
limited with AMF.UML.Actions;
with AMF.UML.Input_Pins;
package AMF.UML.Action_Input_Pins is
pragma Preelaborate;
type UML_Action_Input_Pin is limited interface
and AMF.UML.Input_Pins.UML_Input_Pin;
type UML_Action_Input_Pin_Access is
access all UML_Action_Input_Pin'Class;
for UML_Action_Input_Pin_Access'Storage_Size use 0;
not overriding function Get_From_Action
(Self : not null access constant UML_Action_Input_Pin)
return AMF.UML.Actions.UML_Action_Access is abstract;
-- Getter of ActionInputPin::fromAction.
--
-- The action used to provide values.
not overriding procedure Set_From_Action
(Self : not null access UML_Action_Input_Pin;
To : AMF.UML.Actions.UML_Action_Access) is abstract;
-- Setter of ActionInputPin::fromAction.
--
-- The action used to provide values.
end AMF.UML.Action_Input_Pins;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
-- A clause is an element that represents a single branch of a conditional
-- construct, including a test and a body section. The body section is
-- executed only if (but not necessarily if) the test section evaluates true.
------------------------------------------------------------------------------
limited with AMF.UML.Clauses.Collections;
with AMF.UML.Elements;
limited with AMF.UML.Executable_Nodes.Collections;
limited with AMF.UML.Output_Pins.Collections;
package AMF.UML.Clauses is
pragma Preelaborate;
type UML_Clause is limited interface
and AMF.UML.Elements.UML_Element;
type UML_Clause_Access is
access all UML_Clause'Class;
for UML_Clause_Access'Storage_Size use 0;
not overriding function Get_Body
(Self : not null access constant UML_Clause)
return AMF.UML.Executable_Nodes.Collections.Set_Of_UML_Executable_Node is abstract;
-- Getter of Clause::body.
--
-- A nested activity fragment that is executed if the test evaluates to
-- true and the clause is chosen over any concurrent clauses that also
-- evaluate to true.
not overriding function Get_Body_Output
(Self : not null access constant UML_Clause)
return AMF.UML.Output_Pins.Collections.Ordered_Set_Of_UML_Output_Pin is abstract;
-- Getter of Clause::bodyOutput.
--
-- A list of output pins within the body fragment whose values are moved
-- to the result pins of the containing conditional node after execution
-- of the clause body.
not overriding function Get_Decider
(Self : not null access constant UML_Clause)
return AMF.UML.Output_Pins.UML_Output_Pin_Access is abstract;
-- Getter of Clause::decider.
--
-- An output pin within the test fragment the value of which is examined
-- after execution of the test to determine whether the body should be
-- executed.
not overriding procedure Set_Decider
(Self : not null access UML_Clause;
To : AMF.UML.Output_Pins.UML_Output_Pin_Access) is abstract;
-- Setter of Clause::decider.
--
-- An output pin within the test fragment the value of which is examined
-- after execution of the test to determine whether the body should be
-- executed.
not overriding function Get_Predecessor_Clause
(Self : not null access constant UML_Clause)
return AMF.UML.Clauses.Collections.Set_Of_UML_Clause is abstract;
-- Getter of Clause::predecessorClause.
--
-- A set of clauses whose tests must all evaluate false before the current
-- clause can be tested.
not overriding function Get_Successor_Clause
(Self : not null access constant UML_Clause)
return AMF.UML.Clauses.Collections.Set_Of_UML_Clause is abstract;
-- Getter of Clause::successorClause.
--
-- A set of clauses which may not be tested unless the current clause
-- tests false.
not overriding function Get_Test
(Self : not null access constant UML_Clause)
return AMF.UML.Executable_Nodes.Collections.Set_Of_UML_Executable_Node is abstract;
-- Getter of Clause::test.
--
-- A nested activity fragment with a designated output pin that specifies
-- the result of the test.
end AMF.UML.Clauses;
|
with Ada.Text_Io; use Ada.Text_Io;
procedure Exceptions_From_Nested_Calls is
U0 : exception;
U1 : exception;
Baz_Count : Natural := 0;
procedure Baz is
begin
Baz_Count := Baz_Count + 1;
if Baz_Count = 1 then
raise U0;
else
raise U1;
end if;
end Baz;
procedure Bar is
begin
Baz;
end Bar;
procedure Foo is
begin
Bar;
exception
when U0 =>
Put_Line("Procedure Foo caught exception U0");
end Foo;
begin
for I in 1..2 loop
Foo;
end loop;
end Exceptions_From_Nested_Calls;
|
-----------------------------------------------------------------------
-- babel-testsuite - Babel Testsuite
-- Copyright (C) 2015, 2016 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Babel.Base.Users.Tests;
with Babel.Streams.Tests;
with Babel.Stores.Local.Tests;
with Babel.Base.Text.Tests;
package body Babel.Testsuite is
Tests : aliased Util.Tests.Test_Suite;
function Suite return Util.Tests.Access_Test_Suite is
Ret : constant Util.Tests.Access_Test_Suite := Tests'Access;
begin
Babel.Base.Users.Tests.Add_Tests (Ret);
Babel.Base.Text.Tests.Add_Tests (Ret);
Babel.Streams.Tests.Add_Tests (Ret);
Babel.Stores.Local.Tests.Add_Tests (Ret);
return Ret;
end Suite;
end Babel.Testsuite;
|
--- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../../License.txt
package AdaBase.Results.Field is
type Std_Field is tagged private;
type Field_Access is access Std_Field;
type Variant (datatype : field_types := ft_nbyte8) is
record
case datatype is
when ft_nbyte0 => v00 : Boolean;
when ft_nbyte1 => v01 : NByte1;
when ft_nbyte2 => v02 : NByte2;
when ft_nbyte3 => v03 : NByte3;
when ft_nbyte4 => v04 : NByte4;
when ft_nbyte8 => v05 : NByte8;
when ft_byte1 => v06 : Byte1;
when ft_byte2 => v07 : Byte2;
when ft_byte3 => v08 : Byte3;
when ft_byte4 => v09 : Byte4;
when ft_byte8 => v10 : Byte8;
when ft_real9 => v11 : Real9;
when ft_real18 => v12 : Real18;
when ft_textual => v13 : Textual;
when ft_widetext => v14 : Textwide;
when ft_supertext => v15 : Textsuper;
when ft_timestamp => v16 : AC.Time;
when ft_chain => v17 : Textual;
when ft_enumtype => v18 : Enumtype;
when ft_settype => v19 : Textual;
when ft_bits => v20 : Textual;
when ft_utf8 => v21 : Textual;
when ft_geometry => v22 : Textual;
end case;
end record;
function as_nbyte0 (field : Std_Field) return NByte0;
function as_nbyte1 (field : Std_Field) return NByte1;
function as_nbyte2 (field : Std_Field) return NByte2;
function as_nbyte3 (field : Std_Field) return NByte3;
function as_nbyte4 (field : Std_Field) return NByte4;
function as_nbyte8 (field : Std_Field) return NByte8;
function as_byte1 (field : Std_Field) return Byte1;
function as_byte2 (field : Std_Field) return Byte2;
function as_byte3 (field : Std_Field) return Byte3;
function as_byte4 (field : Std_Field) return Byte4;
function as_byte8 (field : Std_Field) return Byte8;
function as_real9 (field : Std_Field) return Real9;
function as_real18 (field : Std_Field) return Real18;
function as_string (field : Std_Field) return String;
function as_wstring (field : Std_Field) return Wide_String;
function as_wwstring (field : Std_Field) return Wide_Wide_String;
function as_time (field : Std_Field) return AC.Time;
function as_chain (field : Std_Field) return Chain;
function as_enumtype (field : Std_Field) return Enumtype;
function as_settype (field : Std_Field) return Settype;
function as_bits (field : Std_Field) return Bits;
function as_utf8 (field : Std_Field) return Text_UTF8;
function as_geometry (field : Std_Field) return GEO.Geometry;
function is_null (field : Std_Field) return Boolean;
function native_type (field : Std_Field) return field_types;
function spawn_field (data : Variant; null_data : Boolean := False)
return Std_Field;
function spawn_field (binob : Chain) return Std_Field;
function spawn_field (enumset : String) return Std_Field;
function spawn_bits_field (bitstring : String) return Std_Field;
function spawn_null_field (data_type : field_types) return Std_Field;
private
type Std_Field is tagged record
native : Variant;
explicit_null : Boolean := False;
end record;
procedure set (field : out Std_Field; data : Variant; exnull : Boolean);
end AdaBase.Results.Field;
|
package body Loop_Optimization8_Pkg2 is
function Length (Set : T) return Natural is
begin
return Set.Length;
end Length;
function Index (Set : T; Position : Natural) return Integer is
begin
return Set.Elements (Position);
end Index;
end Loop_Optimization8_Pkg2;
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="14">
<syndb class_id="0" tracking_level="0" version="0">
<userIPLatency>-1</userIPLatency>
<userIPName/>
<cdfg class_id="1" tracking_level="1" version="0" object_id="_0">
<name>power</name>
<ret_bitwidth>64</ret_bitwidth>
<ports class_id="2" tracking_level="0" version="0">
<count>2</count>
<item_version>0</item_version>
<item class_id="3" tracking_level="1" version="0" object_id="_1">
<Value class_id="4" tracking_level="0" version="0">
<Obj class_id="5" tracking_level="0" version="0">
<type>1</type>
<id>1</id>
<name>x</name>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo class_id="6" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>x</originalName>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>64</bitwidth>
</Value>
<direction>0</direction>
<if_type>0</if_type>
<array_size>0</array_size>
<bit_vecs class_id="7" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</bit_vecs>
</item>
<item class_id_reference="3" object_id="_2">
<Value>
<Obj>
<type>1</type>
<id>2</id>
<name>y</name>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>y</originalName>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>5</bitwidth>
</Value>
<direction>0</direction>
<if_type>0</if_type>
<array_size>0</array_size>
<bit_vecs>
<count>0</count>
<item_version>0</item_version>
</bit_vecs>
</item>
</ports>
<nodes class_id="8" tracking_level="0" version="0">
<count>13</count>
<item_version>0</item_version>
<item class_id="9" tracking_level="1" version="0" object_id="_3">
<Value>
<Obj>
<type>0</type>
<id>3</id>
<name>y_read</name>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>y</originalName>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>5</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>26</item>
<item>27</item>
</oprand_edges>
<opcode>read</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_4">
<Value>
<Obj>
<type>0</type>
<id>4</id>
<name>x_read</name>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>x</originalName>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>64</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>29</item>
<item>30</item>
</oprand_edges>
<opcode>read</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_5">
<Value>
<Obj>
<type>0</type>
<id>5</id>
<name>tmp_cast</name>
<fileName>../source_files/src/dut.cpp</fileName>
<fileDirectory>..</fileDirectory>
<lineNumber>16</lineNumber>
<contextFuncName>power</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item class_id="11" tracking_level="0" version="0">
<first>/mnt/centos_share/Vivado_Projects/hls_scratchpad/hls_cmd_line_testing/cmd_line_proj</first>
<second class_id="12" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="13" tracking_level="0" version="0">
<first class_id="14" tracking_level="0" version="0">
<first>../source_files/src/dut.cpp</first>
<second>power</second>
</first>
<second>16</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName/>
<rtlName>tmp_cast_fu_76_p1</rtlName>
<coreName/>
</Obj>
<bitwidth>6</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>31</item>
</oprand_edges>
<opcode>zext</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_6">
<Value>
<Obj>
<type>0</type>
<id>6</id>
<name>tmp_2</name>
<fileName>../source_files/src/dut.cpp</fileName>
<fileDirectory>..</fileDirectory>
<lineNumber>16</lineNumber>
<contextFuncName>power</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/mnt/centos_share/Vivado_Projects/hls_scratchpad/hls_cmd_line_testing/cmd_line_proj</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>../source_files/src/dut.cpp</first>
<second>power</second>
</first>
<second>16</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName/>
<rtlName>tmp_2_fu_80_p2</rtlName>
<coreName/>
</Obj>
<bitwidth>6</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>32</item>
<item>34</item>
</oprand_edges>
<opcode>add</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_7">
<Value>
<Obj>
<type>0</type>
<id>7</id>
<name/>
<fileName>../source_files/src/dut.cpp</fileName>
<fileDirectory>..</fileDirectory>
<lineNumber>16</lineNumber>
<contextFuncName>power</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/mnt/centos_share/Vivado_Projects/hls_scratchpad/hls_cmd_line_testing/cmd_line_proj</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>../source_files/src/dut.cpp</first>
<second>power</second>
</first>
<second>16</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName/>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>35</item>
</oprand_edges>
<opcode>br</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_8">
<Value>
<Obj>
<type>0</type>
<id>9</id>
<name>result_int</name>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>result_int</originalName>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>64</bitwidth>
</Value>
<oprand_edges>
<count>4</count>
<item_version>0</item_version>
<item>37</item>
<item>38</item>
<item>39</item>
<item>40</item>
</oprand_edges>
<opcode>phi</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_9">
<Value>
<Obj>
<type>0</type>
<id>10</id>
<name>i</name>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>i</originalName>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>6</bitwidth>
</Value>
<oprand_edges>
<count>4</count>
<item_version>0</item_version>
<item>41</item>
<item>42</item>
<item>43</item>
<item>44</item>
</oprand_edges>
<opcode>phi</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_10">
<Value>
<Obj>
<type>0</type>
<id>11</id>
<name>exitcond</name>
<fileName>../source_files/src/dut.cpp</fileName>
<fileDirectory>..</fileDirectory>
<lineNumber>16</lineNumber>
<contextFuncName>power</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/mnt/centos_share/Vivado_Projects/hls_scratchpad/hls_cmd_line_testing/cmd_line_proj</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>../source_files/src/dut.cpp</first>
<second>power</second>
</first>
<second>16</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName/>
<rtlName>exitcond_fu_86_p2</rtlName>
<coreName/>
</Obj>
<bitwidth>1</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>45</item>
<item>46</item>
</oprand_edges>
<opcode>icmp</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_11">
<Value>
<Obj>
<type>0</type>
<id>12</id>
<name/>
<fileName>../source_files/src/dut.cpp</fileName>
<fileDirectory>..</fileDirectory>
<lineNumber>16</lineNumber>
<contextFuncName>power</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/mnt/centos_share/Vivado_Projects/hls_scratchpad/hls_cmd_line_testing/cmd_line_proj</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>../source_files/src/dut.cpp</first>
<second>power</second>
</first>
<second>16</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName/>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>3</count>
<item_version>0</item_version>
<item>47</item>
<item>48</item>
<item>49</item>
</oprand_edges>
<opcode>br</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_12">
<Value>
<Obj>
<type>0</type>
<id>18</id>
<name>result_int_1</name>
<fileName>../source_files/src/dut.cpp</fileName>
<fileDirectory>..</fileDirectory>
<lineNumber>18</lineNumber>
<contextFuncName>power</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/mnt/centos_share/Vivado_Projects/hls_scratchpad/hls_cmd_line_testing/cmd_line_proj</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>../source_files/src/dut.cpp</first>
<second>power</second>
</first>
<second>18</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName>result_int</originalName>
<rtlName>sin_taylor_seriesbkb_U1</rtlName>
<coreName/>
</Obj>
<bitwidth>64</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>50</item>
<item>51</item>
</oprand_edges>
<opcode>dmul</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_13">
<Value>
<Obj>
<type>0</type>
<id>20</id>
<name>i_1</name>
<fileName>../source_files/src/dut.cpp</fileName>
<fileDirectory>..</fileDirectory>
<lineNumber>16</lineNumber>
<contextFuncName>power</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/mnt/centos_share/Vivado_Projects/hls_scratchpad/hls_cmd_line_testing/cmd_line_proj</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>../source_files/src/dut.cpp</first>
<second>power</second>
</first>
<second>16</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName>i</originalName>
<rtlName>i_1_fu_91_p2</rtlName>
<coreName/>
</Obj>
<bitwidth>6</bitwidth>
</Value>
<oprand_edges>
<count>2</count>
<item_version>0</item_version>
<item>52</item>
<item>53</item>
</oprand_edges>
<opcode>add</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_14">
<Value>
<Obj>
<type>0</type>
<id>21</id>
<name/>
<fileName>../source_files/src/dut.cpp</fileName>
<fileDirectory>..</fileDirectory>
<lineNumber>16</lineNumber>
<contextFuncName>power</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/mnt/centos_share/Vivado_Projects/hls_scratchpad/hls_cmd_line_testing/cmd_line_proj</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>../source_files/src/dut.cpp</first>
<second>power</second>
</first>
<second>16</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName/>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>54</item>
</oprand_edges>
<opcode>br</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_15">
<Value>
<Obj>
<type>0</type>
<id>23</id>
<name/>
<fileName>../source_files/src/dut.cpp</fileName>
<fileDirectory>..</fileDirectory>
<lineNumber>20</lineNumber>
<contextFuncName>power</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/mnt/centos_share/Vivado_Projects/hls_scratchpad/hls_cmd_line_testing/cmd_line_proj</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>../source_files/src/dut.cpp</first>
<second>power</second>
</first>
<second>20</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName/>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>55</item>
</oprand_edges>
<opcode>ret</opcode>
<m_Display>0</m_Display>
</item>
</nodes>
<consts class_id="15" tracking_level="0" version="0">
<count>2</count>
<item_version>0</item_version>
<item class_id="16" tracking_level="1" version="0" object_id="_16">
<Value>
<Obj>
<type>2</type>
<id>33</id>
<name>empty</name>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName/>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>6</bitwidth>
</Value>
<const_type>0</const_type>
<content>1</content>
</item>
<item class_id_reference="16" object_id="_17">
<Value>
<Obj>
<type>2</type>
<id>36</id>
<name>empty</name>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName/>
<rtlName/>
<coreName/>
</Obj>
<bitwidth>64</bitwidth>
</Value>
<const_type>1</const_type>
<content>1</content>
</item>
</consts>
<blocks class_id="17" tracking_level="0" version="0">
<count>4</count>
<item_version>0</item_version>
<item class_id="18" tracking_level="1" version="0" object_id="_18">
<Obj>
<type>3</type>
<id>8</id>
<name/>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName/>
<rtlName/>
<coreName/>
</Obj>
<node_objs>
<count>5</count>
<item_version>0</item_version>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
</node_objs>
</item>
<item class_id_reference="18" object_id="_19">
<Obj>
<type>3</type>
<id>13</id>
<name/>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName/>
<rtlName/>
<coreName/>
</Obj>
<node_objs>
<count>4</count>
<item_version>0</item_version>
<item>9</item>
<item>10</item>
<item>11</item>
<item>12</item>
</node_objs>
</item>
<item class_id_reference="18" object_id="_20">
<Obj>
<type>3</type>
<id>22</id>
<name/>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName/>
<rtlName/>
<coreName/>
</Obj>
<node_objs>
<count>3</count>
<item_version>0</item_version>
<item>18</item>
<item>20</item>
<item>21</item>
</node_objs>
</item>
<item class_id_reference="18" object_id="_21">
<Obj>
<type>3</type>
<id>24</id>
<name/>
<fileName/>
<fileDirectory/>
<lineNumber>0</lineNumber>
<contextFuncName/>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName/>
<rtlName/>
<coreName/>
</Obj>
<node_objs>
<count>1</count>
<item_version>0</item_version>
<item>23</item>
</node_objs>
</item>
</blocks>
<edges class_id="19" tracking_level="0" version="0">
<count>29</count>
<item_version>0</item_version>
<item class_id="20" tracking_level="1" version="0" object_id="_22">
<id>27</id>
<edge_type>1</edge_type>
<source_obj>2</source_obj>
<sink_obj>3</sink_obj>
</item>
<item class_id_reference="20" object_id="_23">
<id>30</id>
<edge_type>1</edge_type>
<source_obj>1</source_obj>
<sink_obj>4</sink_obj>
</item>
<item class_id_reference="20" object_id="_24">
<id>31</id>
<edge_type>1</edge_type>
<source_obj>3</source_obj>
<sink_obj>5</sink_obj>
</item>
<item class_id_reference="20" object_id="_25">
<id>32</id>
<edge_type>1</edge_type>
<source_obj>5</source_obj>
<sink_obj>6</sink_obj>
</item>
<item class_id_reference="20" object_id="_26">
<id>34</id>
<edge_type>1</edge_type>
<source_obj>33</source_obj>
<sink_obj>6</sink_obj>
</item>
<item class_id_reference="20" object_id="_27">
<id>35</id>
<edge_type>2</edge_type>
<source_obj>13</source_obj>
<sink_obj>7</sink_obj>
</item>
<item class_id_reference="20" object_id="_28">
<id>37</id>
<edge_type>1</edge_type>
<source_obj>36</source_obj>
<sink_obj>9</sink_obj>
</item>
<item class_id_reference="20" object_id="_29">
<id>38</id>
<edge_type>2</edge_type>
<source_obj>8</source_obj>
<sink_obj>9</sink_obj>
</item>
<item class_id_reference="20" object_id="_30">
<id>39</id>
<edge_type>1</edge_type>
<source_obj>18</source_obj>
<sink_obj>9</sink_obj>
</item>
<item class_id_reference="20" object_id="_31">
<id>40</id>
<edge_type>2</edge_type>
<source_obj>22</source_obj>
<sink_obj>9</sink_obj>
</item>
<item class_id_reference="20" object_id="_32">
<id>41</id>
<edge_type>1</edge_type>
<source_obj>33</source_obj>
<sink_obj>10</sink_obj>
</item>
<item class_id_reference="20" object_id="_33">
<id>42</id>
<edge_type>2</edge_type>
<source_obj>8</source_obj>
<sink_obj>10</sink_obj>
</item>
<item class_id_reference="20" object_id="_34">
<id>43</id>
<edge_type>1</edge_type>
<source_obj>20</source_obj>
<sink_obj>10</sink_obj>
</item>
<item class_id_reference="20" object_id="_35">
<id>44</id>
<edge_type>2</edge_type>
<source_obj>22</source_obj>
<sink_obj>10</sink_obj>
</item>
<item class_id_reference="20" object_id="_36">
<id>45</id>
<edge_type>1</edge_type>
<source_obj>10</source_obj>
<sink_obj>11</sink_obj>
</item>
<item class_id_reference="20" object_id="_37">
<id>46</id>
<edge_type>1</edge_type>
<source_obj>6</source_obj>
<sink_obj>11</sink_obj>
</item>
<item class_id_reference="20" object_id="_38">
<id>47</id>
<edge_type>1</edge_type>
<source_obj>11</source_obj>
<sink_obj>12</sink_obj>
</item>
<item class_id_reference="20" object_id="_39">
<id>48</id>
<edge_type>2</edge_type>
<source_obj>22</source_obj>
<sink_obj>12</sink_obj>
</item>
<item class_id_reference="20" object_id="_40">
<id>49</id>
<edge_type>2</edge_type>
<source_obj>24</source_obj>
<sink_obj>12</sink_obj>
</item>
<item class_id_reference="20" object_id="_41">
<id>50</id>
<edge_type>1</edge_type>
<source_obj>9</source_obj>
<sink_obj>18</sink_obj>
</item>
<item class_id_reference="20" object_id="_42">
<id>51</id>
<edge_type>1</edge_type>
<source_obj>4</source_obj>
<sink_obj>18</sink_obj>
</item>
<item class_id_reference="20" object_id="_43">
<id>52</id>
<edge_type>1</edge_type>
<source_obj>10</source_obj>
<sink_obj>20</sink_obj>
</item>
<item class_id_reference="20" object_id="_44">
<id>53</id>
<edge_type>1</edge_type>
<source_obj>33</source_obj>
<sink_obj>20</sink_obj>
</item>
<item class_id_reference="20" object_id="_45">
<id>54</id>
<edge_type>2</edge_type>
<source_obj>13</source_obj>
<sink_obj>21</sink_obj>
</item>
<item class_id_reference="20" object_id="_46">
<id>55</id>
<edge_type>1</edge_type>
<source_obj>9</source_obj>
<sink_obj>23</sink_obj>
</item>
<item class_id_reference="20" object_id="_47">
<id>85</id>
<edge_type>2</edge_type>
<source_obj>8</source_obj>
<sink_obj>13</sink_obj>
</item>
<item class_id_reference="20" object_id="_48">
<id>86</id>
<edge_type>2</edge_type>
<source_obj>13</source_obj>
<sink_obj>24</sink_obj>
</item>
<item class_id_reference="20" object_id="_49">
<id>87</id>
<edge_type>2</edge_type>
<source_obj>13</source_obj>
<sink_obj>22</sink_obj>
</item>
<item class_id_reference="20" object_id="_50">
<id>88</id>
<edge_type>2</edge_type>
<source_obj>22</source_obj>
<sink_obj>13</sink_obj>
</item>
</edges>
</cdfg>
<cdfg_regions class_id="21" tracking_level="0" version="0">
<count>4</count>
<item_version>0</item_version>
<item class_id="22" tracking_level="1" version="0" object_id="_51">
<mId>1</mId>
<mTag>power</mTag>
<mType>0</mType>
<sub_regions>
<count>3</count>
<item_version>0</item_version>
<item>2</item>
<item>3</item>
<item>4</item>
</sub_regions>
<basic_blocks>
<count>0</count>
<item_version>0</item_version>
</basic_blocks>
<mII>-1</mII>
<mDepth>-1</mDepth>
<mMinTripCount>-1</mMinTripCount>
<mMaxTripCount>-1</mMaxTripCount>
<mMinLatency>188</mMinLatency>
<mMaxLatency>-1</mMaxLatency>
<mIsDfPipe>0</mIsDfPipe>
<mDfPipe class_id="-1"/>
</item>
<item class_id_reference="22" object_id="_52">
<mId>2</mId>
<mTag>Entry</mTag>
<mType>0</mType>
<sub_regions>
<count>0</count>
<item_version>0</item_version>
</sub_regions>
<basic_blocks>
<count>1</count>
<item_version>0</item_version>
<item>8</item>
</basic_blocks>
<mII>-1</mII>
<mDepth>-1</mDepth>
<mMinTripCount>-1</mMinTripCount>
<mMaxTripCount>-1</mMaxTripCount>
<mMinLatency>0</mMinLatency>
<mMaxLatency>-1</mMaxLatency>
<mIsDfPipe>0</mIsDfPipe>
<mDfPipe class_id="-1"/>
</item>
<item class_id_reference="22" object_id="_53">
<mId>3</mId>
<mTag>power_loop</mTag>
<mType>1</mType>
<sub_regions>
<count>0</count>
<item_version>0</item_version>
</sub_regions>
<basic_blocks>
<count>2</count>
<item_version>0</item_version>
<item>13</item>
<item>22</item>
</basic_blocks>
<mII>6</mII>
<mDepth>6</mDepth>
<mMinTripCount>0</mMinTripCount>
<mMaxTripCount>31</mMaxTripCount>
<mMinLatency>186</mMinLatency>
<mMaxLatency>-1</mMaxLatency>
<mIsDfPipe>0</mIsDfPipe>
<mDfPipe class_id="-1"/>
</item>
<item class_id_reference="22" object_id="_54">
<mId>4</mId>
<mTag>Return</mTag>
<mType>0</mType>
<sub_regions>
<count>0</count>
<item_version>0</item_version>
</sub_regions>
<basic_blocks>
<count>1</count>
<item_version>0</item_version>
<item>24</item>
</basic_blocks>
<mII>-1</mII>
<mDepth>-1</mDepth>
<mMinTripCount>-1</mMinTripCount>
<mMaxTripCount>-1</mMaxTripCount>
<mMinLatency>0</mMinLatency>
<mMaxLatency>-1</mMaxLatency>
<mIsDfPipe>0</mIsDfPipe>
<mDfPipe class_id="-1"/>
</item>
</cdfg_regions>
<fsm class_id="24" tracking_level="1" version="0" object_id="_55">
<states class_id="25" tracking_level="0" version="0">
<count>8</count>
<item_version>0</item_version>
<item class_id="26" tracking_level="1" version="0" object_id="_56">
<id>1</id>
<operations class_id="27" tracking_level="0" version="0">
<count>5</count>
<item_version>0</item_version>
<item class_id="28" tracking_level="1" version="0" object_id="_57">
<id>3</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_58">
<id>4</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_59">
<id>5</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_60">
<id>6</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_61">
<id>7</id>
<stage>1</stage>
<latency>1</latency>
</item>
</operations>
</item>
<item class_id_reference="26" object_id="_62">
<id>2</id>
<operations>
<count>6</count>
<item_version>0</item_version>
<item class_id_reference="28" object_id="_63">
<id>9</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_64">
<id>10</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_65">
<id>11</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_66">
<id>12</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_67">
<id>18</id>
<stage>6</stage>
<latency>6</latency>
</item>
<item class_id_reference="28" object_id="_68">
<id>20</id>
<stage>1</stage>
<latency>1</latency>
</item>
</operations>
</item>
<item class_id_reference="26" object_id="_69">
<id>3</id>
<operations>
<count>1</count>
<item_version>0</item_version>
<item class_id_reference="28" object_id="_70">
<id>18</id>
<stage>5</stage>
<latency>6</latency>
</item>
</operations>
</item>
<item class_id_reference="26" object_id="_71">
<id>4</id>
<operations>
<count>1</count>
<item_version>0</item_version>
<item class_id_reference="28" object_id="_72">
<id>18</id>
<stage>4</stage>
<latency>6</latency>
</item>
</operations>
</item>
<item class_id_reference="26" object_id="_73">
<id>5</id>
<operations>
<count>1</count>
<item_version>0</item_version>
<item class_id_reference="28" object_id="_74">
<id>18</id>
<stage>3</stage>
<latency>6</latency>
</item>
</operations>
</item>
<item class_id_reference="26" object_id="_75">
<id>6</id>
<operations>
<count>1</count>
<item_version>0</item_version>
<item class_id_reference="28" object_id="_76">
<id>18</id>
<stage>2</stage>
<latency>6</latency>
</item>
</operations>
</item>
<item class_id_reference="26" object_id="_77">
<id>7</id>
<operations>
<count>7</count>
<item_version>0</item_version>
<item class_id_reference="28" object_id="_78">
<id>14</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_79">
<id>15</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_80">
<id>16</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_81">
<id>17</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_82">
<id>18</id>
<stage>1</stage>
<latency>6</latency>
</item>
<item class_id_reference="28" object_id="_83">
<id>19</id>
<stage>1</stage>
<latency>1</latency>
</item>
<item class_id_reference="28" object_id="_84">
<id>21</id>
<stage>1</stage>
<latency>1</latency>
</item>
</operations>
</item>
<item class_id_reference="26" object_id="_85">
<id>8</id>
<operations>
<count>1</count>
<item_version>0</item_version>
<item class_id_reference="28" object_id="_86">
<id>23</id>
<stage>1</stage>
<latency>1</latency>
</item>
</operations>
</item>
</states>
<transitions class_id="29" tracking_level="0" version="0">
<count>8</count>
<item_version>0</item_version>
<item class_id="30" tracking_level="1" version="0" object_id="_87">
<inState>1</inState>
<outState>2</outState>
<condition class_id="31" tracking_level="0" version="0">
<id>57</id>
<sop class_id="32" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="33" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</item>
</sop>
</condition>
</item>
<item class_id_reference="30" object_id="_88">
<inState>3</inState>
<outState>4</outState>
<condition>
<id>69</id>
<sop>
<count>1</count>
<item_version>0</item_version>
<item>
<count>0</count>
<item_version>0</item_version>
</item>
</sop>
</condition>
</item>
<item class_id_reference="30" object_id="_89">
<inState>4</inState>
<outState>5</outState>
<condition>
<id>70</id>
<sop>
<count>1</count>
<item_version>0</item_version>
<item>
<count>0</count>
<item_version>0</item_version>
</item>
</sop>
</condition>
</item>
<item class_id_reference="30" object_id="_90">
<inState>5</inState>
<outState>6</outState>
<condition>
<id>71</id>
<sop>
<count>1</count>
<item_version>0</item_version>
<item>
<count>0</count>
<item_version>0</item_version>
</item>
</sop>
</condition>
</item>
<item class_id_reference="30" object_id="_91">
<inState>6</inState>
<outState>7</outState>
<condition>
<id>72</id>
<sop>
<count>1</count>
<item_version>0</item_version>
<item>
<count>0</count>
<item_version>0</item_version>
</item>
</sop>
</condition>
</item>
<item class_id_reference="30" object_id="_92">
<inState>7</inState>
<outState>2</outState>
<condition>
<id>73</id>
<sop>
<count>1</count>
<item_version>0</item_version>
<item>
<count>0</count>
<item_version>0</item_version>
</item>
</sop>
</condition>
</item>
<item class_id_reference="30" object_id="_93">
<inState>2</inState>
<outState>8</outState>
<condition>
<id>68</id>
<sop>
<count>1</count>
<item_version>0</item_version>
<item>
<count>1</count>
<item_version>0</item_version>
<item class_id="34" tracking_level="0" version="0">
<first class_id="35" tracking_level="0" version="0">
<first>11</first>
<second>0</second>
</first>
<second>0</second>
</item>
</item>
</sop>
</condition>
</item>
<item class_id_reference="30" object_id="_94">
<inState>2</inState>
<outState>3</outState>
<condition>
<id>74</id>
<sop>
<count>1</count>
<item_version>0</item_version>
<item>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>11</first>
<second>0</second>
</first>
<second>1</second>
</item>
</item>
</sop>
</condition>
</item>
</transitions>
</fsm>
<res class_id="36" tracking_level="1" version="0" object_id="_95">
<dp_component_resource class_id="37" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="38" tracking_level="0" version="0">
<first>sin_taylor_seriesbkb_U1 (sin_taylor_seriesbkb)</first>
<second class_id="39" tracking_level="0" version="0">
<count>3</count>
<item_version>0</item_version>
<item class_id="40" tracking_level="0" version="0">
<first>DSP48E</first>
<second>11</second>
</item>
<item>
<first>FF</first>
<second>317</second>
</item>
<item>
<first>LUT</first>
<second>578</second>
</item>
</second>
</item>
</dp_component_resource>
<dp_expression_resource>
<count>3</count>
<item_version>0</item_version>
<item>
<first>exitcond_fu_86_p2 ( icmp ) </first>
<second>
<count>4</count>
<item_version>0</item_version>
<item>
<first>(0P0)</first>
<second>6</second>
</item>
<item>
<first>(1P1)</first>
<second>6</second>
</item>
<item>
<first>FF</first>
<second>0</second>
</item>
<item>
<first>LUT</first>
<second>3</second>
</item>
</second>
</item>
<item>
<first>i_1_fu_91_p2 ( + ) </first>
<second>
<count>4</count>
<item_version>0</item_version>
<item>
<first>(0P0)</first>
<second>6</second>
</item>
<item>
<first>(1P1)</first>
<second>1</second>
</item>
<item>
<first>FF</first>
<second>0</second>
</item>
<item>
<first>LUT</first>
<second>15</second>
</item>
</second>
</item>
<item>
<first>tmp_2_fu_80_p2 ( + ) </first>
<second>
<count>4</count>
<item_version>0</item_version>
<item>
<first>(0P0)</first>
<second>6</second>
</item>
<item>
<first>(1P1)</first>
<second>1</second>
</item>
<item>
<first>FF</first>
<second>0</second>
</item>
<item>
<first>LUT</first>
<second>15</second>
</item>
</second>
</item>
</dp_expression_resource>
<dp_fifo_resource>
<count>0</count>
<item_version>0</item_version>
</dp_fifo_resource>
<dp_memory_resource>
<count>0</count>
<item_version>0</item_version>
</dp_memory_resource>
<dp_multiplexer_resource>
<count>3</count>
<item_version>0</item_version>
<item>
<first>ap_NS_fsm</first>
<second>
<count>4</count>
<item_version>0</item_version>
<item>
<first>(0Size)</first>
<second>9</second>
</item>
<item>
<first>(1Bits)</first>
<second>1</second>
</item>
<item>
<first>(2Count)</first>
<second>9</second>
</item>
<item>
<first>LUT</first>
<second>44</second>
</item>
</second>
</item>
<item>
<first>i_reg_60</first>
<second>
<count>4</count>
<item_version>0</item_version>
<item>
<first>(0Size)</first>
<second>2</second>
</item>
<item>
<first>(1Bits)</first>
<second>6</second>
</item>
<item>
<first>(2Count)</first>
<second>12</second>
</item>
<item>
<first>LUT</first>
<second>9</second>
</item>
</second>
</item>
<item>
<first>result_int_reg_48</first>
<second>
<count>4</count>
<item_version>0</item_version>
<item>
<first>(0Size)</first>
<second>2</second>
</item>
<item>
<first>(1Bits)</first>
<second>64</second>
</item>
<item>
<first>(2Count)</first>
<second>128</second>
</item>
<item>
<first>LUT</first>
<second>9</second>
</item>
</second>
</item>
</dp_multiplexer_resource>
<dp_register_resource>
<count>5</count>
<item_version>0</item_version>
<item>
<first>ap_CS_fsm</first>
<second>
<count>3</count>
<item_version>0</item_version>
<item>
<first>(Bits)</first>
<second>8</second>
</item>
<item>
<first>(Consts)</first>
<second>0</second>
</item>
<item>
<first>FF</first>
<second>8</second>
</item>
</second>
</item>
<item>
<first>i_1_reg_110</first>
<second>
<count>3</count>
<item_version>0</item_version>
<item>
<first>(Bits)</first>
<second>6</second>
</item>
<item>
<first>(Consts)</first>
<second>0</second>
</item>
<item>
<first>FF</first>
<second>6</second>
</item>
</second>
</item>
<item>
<first>i_reg_60</first>
<second>
<count>3</count>
<item_version>0</item_version>
<item>
<first>(Bits)</first>
<second>6</second>
</item>
<item>
<first>(Consts)</first>
<second>0</second>
</item>
<item>
<first>FF</first>
<second>6</second>
</item>
</second>
</item>
<item>
<first>result_int_reg_48</first>
<second>
<count>3</count>
<item_version>0</item_version>
<item>
<first>(Bits)</first>
<second>64</second>
</item>
<item>
<first>(Consts)</first>
<second>0</second>
</item>
<item>
<first>FF</first>
<second>64</second>
</item>
</second>
</item>
<item>
<first>tmp_2_reg_102</first>
<second>
<count>3</count>
<item_version>0</item_version>
<item>
<first>(Bits)</first>
<second>6</second>
</item>
<item>
<first>(Consts)</first>
<second>0</second>
</item>
<item>
<first>FF</first>
<second>6</second>
</item>
</second>
</item>
</dp_register_resource>
<dp_component_map class_id="41" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="42" tracking_level="0" version="0">
<first>sin_taylor_seriesbkb_U1 (sin_taylor_seriesbkb)</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>18</item>
</second>
</item>
</dp_component_map>
<dp_expression_map>
<count>3</count>
<item_version>0</item_version>
<item>
<first>exitcond_fu_86_p2 ( icmp ) </first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>11</item>
</second>
</item>
<item>
<first>i_1_fu_91_p2 ( + ) </first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>20</item>
</second>
</item>
<item>
<first>tmp_2_fu_80_p2 ( + ) </first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>6</item>
</second>
</item>
</dp_expression_map>
<dp_fifo_map>
<count>0</count>
<item_version>0</item_version>
</dp_fifo_map>
<dp_memory_map>
<count>0</count>
<item_version>0</item_version>
</dp_memory_map>
</res>
<node_label_latency class_id="43" tracking_level="0" version="0">
<count>13</count>
<item_version>0</item_version>
<item class_id="44" tracking_level="0" version="0">
<first>3</first>
<second class_id="45" tracking_level="0" version="0">
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>4</first>
<second>
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>5</first>
<second>
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>6</first>
<second>
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>7</first>
<second>
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>9</first>
<second>
<first>1</first>
<second>0</second>
</second>
</item>
<item>
<first>10</first>
<second>
<first>1</first>
<second>0</second>
</second>
</item>
<item>
<first>11</first>
<second>
<first>1</first>
<second>0</second>
</second>
</item>
<item>
<first>12</first>
<second>
<first>1</first>
<second>0</second>
</second>
</item>
<item>
<first>18</first>
<second>
<first>1</first>
<second>5</second>
</second>
</item>
<item>
<first>20</first>
<second>
<first>1</first>
<second>0</second>
</second>
</item>
<item>
<first>21</first>
<second>
<first>6</first>
<second>0</second>
</second>
</item>
<item>
<first>23</first>
<second>
<first>2</first>
<second>0</second>
</second>
</item>
</node_label_latency>
<bblk_ent_exit class_id="46" tracking_level="0" version="0">
<count>4</count>
<item_version>0</item_version>
<item class_id="47" tracking_level="0" version="0">
<first>8</first>
<second class_id="48" tracking_level="0" version="0">
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>13</first>
<second>
<first>1</first>
<second>1</second>
</second>
</item>
<item>
<first>22</first>
<second>
<first>1</first>
<second>6</second>
</second>
</item>
<item>
<first>24</first>
<second>
<first>2</first>
<second>2</second>
</second>
</item>
</bblk_ent_exit>
<regions class_id="49" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="50" tracking_level="1" version="0" object_id="_96">
<region_name>power_loop</region_name>
<basic_blocks>
<count>2</count>
<item_version>0</item_version>
<item>13</item>
<item>22</item>
</basic_blocks>
<nodes>
<count>0</count>
<item_version>0</item_version>
</nodes>
<anchor_node>-1</anchor_node>
<region_type>8</region_type>
<interval>6</interval>
<pipe_depth>6</pipe_depth>
</item>
</regions>
<dp_fu_nodes class_id="51" tracking_level="0" version="0">
<count>9</count>
<item_version>0</item_version>
<item class_id="52" tracking_level="0" version="0">
<first>36</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>3</item>
</second>
</item>
<item>
<first>42</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>4</item>
</second>
</item>
<item>
<first>52</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>9</item>
</second>
</item>
<item>
<first>64</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>10</item>
</second>
</item>
<item>
<first>71</first>
<second>
<count>6</count>
<item_version>0</item_version>
<item>18</item>
<item>18</item>
<item>18</item>
<item>18</item>
<item>18</item>
<item>18</item>
</second>
</item>
<item>
<first>76</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>5</item>
</second>
</item>
<item>
<first>80</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>6</item>
</second>
</item>
<item>
<first>86</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>11</item>
</second>
</item>
<item>
<first>91</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>20</item>
</second>
</item>
</dp_fu_nodes>
<dp_fu_nodes_expression class_id="54" tracking_level="0" version="0">
<count>6</count>
<item_version>0</item_version>
<item class_id="55" tracking_level="0" version="0">
<first>exitcond_fu_86</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>11</item>
</second>
</item>
<item>
<first>i_1_fu_91</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>20</item>
</second>
</item>
<item>
<first>i_phi_fu_64</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>10</item>
</second>
</item>
<item>
<first>result_int_phi_fu_52</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>9</item>
</second>
</item>
<item>
<first>tmp_2_fu_80</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>6</item>
</second>
</item>
<item>
<first>tmp_cast_fu_76</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>5</item>
</second>
</item>
</dp_fu_nodes_expression>
<dp_fu_nodes_module>
<count>1</count>
<item_version>0</item_version>
<item>
<first>grp_fu_71</first>
<second>
<count>6</count>
<item_version>0</item_version>
<item>18</item>
<item>18</item>
<item>18</item>
<item>18</item>
<item>18</item>
<item>18</item>
</second>
</item>
</dp_fu_nodes_module>
<dp_fu_nodes_io>
<count>2</count>
<item_version>0</item_version>
<item>
<first>x_read_read_fu_42</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>4</item>
</second>
</item>
<item>
<first>y_read_read_fu_36</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>3</item>
</second>
</item>
</dp_fu_nodes_io>
<return_ports>
<count>1</count>
<item_version>0</item_version>
<item>
<first>ap_return</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>23</item>
</second>
</item>
</return_ports>
<dp_mem_port_nodes class_id="56" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</dp_mem_port_nodes>
<dp_reg_nodes>
<count>6</count>
<item_version>0</item_version>
<item>
<first>48</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>9</item>
</second>
</item>
<item>
<first>60</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>10</item>
</second>
</item>
<item>
<first>97</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>4</item>
</second>
</item>
<item>
<first>102</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>6</item>
</second>
</item>
<item>
<first>110</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>20</item>
</second>
</item>
<item>
<first>115</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>18</item>
</second>
</item>
</dp_reg_nodes>
<dp_regname_nodes>
<count>6</count>
<item_version>0</item_version>
<item>
<first>i_1_reg_110</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>20</item>
</second>
</item>
<item>
<first>i_reg_60</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>10</item>
</second>
</item>
<item>
<first>result_int_1_reg_115</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>18</item>
</second>
</item>
<item>
<first>result_int_reg_48</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>9</item>
</second>
</item>
<item>
<first>tmp_2_reg_102</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>6</item>
</second>
</item>
<item>
<first>x_read_reg_97</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>4</item>
</second>
</item>
</dp_regname_nodes>
<dp_reg_phi>
<count>2</count>
<item_version>0</item_version>
<item>
<first>48</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>9</item>
</second>
</item>
<item>
<first>60</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>10</item>
</second>
</item>
</dp_reg_phi>
<dp_regname_phi>
<count>2</count>
<item_version>0</item_version>
<item>
<first>i_reg_60</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>10</item>
</second>
</item>
<item>
<first>result_int_reg_48</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>9</item>
</second>
</item>
</dp_regname_phi>
<dp_port_io_nodes class_id="57" tracking_level="0" version="0">
<count>2</count>
<item_version>0</item_version>
<item class_id="58" tracking_level="0" version="0">
<first>x</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>read</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>4</item>
</second>
</item>
</second>
</item>
<item>
<first>y</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>read</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>3</item>
</second>
</item>
</second>
</item>
</dp_port_io_nodes>
<port2core class_id="59" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</port2core>
<node2core>
<count>0</count>
<item_version>0</item_version>
</node2core>
</syndb>
</boost_serialization>
|
with Ada.Unchecked_Conversion;
package Tkmrpc.Request.Ike.Nc_Reset.Convert is
function To_Request is new Ada.Unchecked_Conversion (
Source => Nc_Reset.Request_Type,
Target => Request.Data_Type);
function From_Request is new Ada.Unchecked_Conversion (
Source => Request.Data_Type,
Target => Nc_Reset.Request_Type);
end Tkmrpc.Request.Ike.Nc_Reset.Convert;
|
with Libadalang.Analysis; use Libadalang.Analysis;
with Libadalang.Common; use Libadalang.Common;
with Rejuvenation.Navigation; use Rejuvenation.Navigation;
with Rewriters_Sequence; use Rewriters_Sequence;
package Rewriters_Sequence_Utils is
function Rewrite (RS : Rewriters_Sequence.Vector;
Node : Ada_Node'Class;
Top_Level : Boolean := False;
Rule : Grammar_Rule := Default_Grammar_Rule)
return String;
function Rewrite_Context
(RS : Rewriters_Sequence.Vector;
Node : Ada_Node'Class)
return Ada_Node
with Post => Is_Reflexive_Ancestor (Rewrite_Context'Result, Node);
end Rewriters_Sequence_Utils;
|
-------------------------------------------------------------------------------
-- Copyright (c) 2019, Daniel King
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
-- * Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
-- * The name of the copyright holder may not be used to endorse or promote
-- Products derived from this software without specific prior written
-- permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------------
with Interfaces;
with Keccak.Types;
package Keccak.Util
with SPARK_Mode => On
is
use type Interfaces.Unsigned_8;
function To_Byte_Array (Str : in String) return Types.Byte_Array
with Inline,
Post => (To_Byte_Array'Result'Length = Str'Length
and To_Byte_Array'Result'First = 0);
-- Return the byte array representation of a string.
--
-- This function uses an Ada.Unchecked_Conversion internally to convert the
-- String to the byte array.
--
-- @param Str The string to convert to a byte array.
function Left_Encode_NIST (Length : in Natural) return Types.Byte_Array
with
Post => (Left_Encode_NIST'Result'Length in 1 .. (Natural'Size / 8) + 2
and Left_Encode_NIST'Result'First in 1 .. (Natural'Size / 8) + 2);
-- Encode a length using the left_encode(n) method described in
-- NIST SP 800-185.
--
-- Example, the length 16#ABCDEF# will be encoded as the byte array
-- (3, 16#AB#, 16#CD#, 16#EF#)
function Left_Encode_NIST_Bit_Length (Byte_Length : in Natural)
return Types.Byte_Array
with
Post => (Left_Encode_NIST_Bit_Length'Result'Length
in 1 .. Natural'Size + 1
and Left_Encode_NIST_Bit_Length'Result'First
in 1 .. Natural'Size + 1);
-- A version of left_encode(n) (as defined by NIST) where the output
-- represents the input value multiplied by 8.
--
-- The output of calling Left_Encode_NIST_Bit_Length (N) is equivalent
-- to calling Left_Encode_NIST (N * 8). This function is useful to avoid
-- doing the multiplication in the call to Left_Encode_NIST and thus
-- avoiding the possibility of an integer overflow.
--
-- @param Byte_Length The length to left_encode. Usually represents a
-- quantity of bytes, as the output represents this value multiplied by 8.
function Right_Encode_NIST (Length : in Natural) return Types.Byte_Array
with
Post => (Right_Encode_NIST'Result'Length
in 1 .. (Natural'Size / 8) + 2
and Right_Encode_NIST'Result'First
in 1 .. (Natural'Size / 8) + 2);
-- Encode a length using the right_encode(n) method described in
-- NIST SP 800-185.
--
-- Example, the length 16#ABCDEF# will be encoded as the byte array
-- (16#AB#, 16#CD#, 16#EF#, 3)
function Right_Encode_NIST_Long_Long (Length : in Long_Long_Integer)
return Types.Byte_Array
with
Pre => Length >= 0,
Post => (Right_Encode_NIST_Long_Long'Result'Length
in 1 .. (Long_Long_Integer'Size / 8) + 2
and Right_Encode_NIST_Long_Long'Result'First
in 1 .. (Long_Long_Integer'Size / 8) + 2);
-- Equivalent to Right_Encode_NIST, except this function accepts a much
-- longer input range (as a Long_Long_Integer).
function Right_Encode_NIST_Bit_Length (Byte_Length : in Natural)
return Types.Byte_Array
with
Post => (Right_Encode_NIST_Bit_Length'Result'Length
in 1 .. Natural'Size + 1
and Right_Encode_NIST_Bit_Length'Result'First
in 1 .. Natural'Size + 1);
-- A version of right_encode(n) (as defined by NIST) where the output
-- represents the input value multiplied by 8.
--
-- The output of calling Right_Encode_NIST_Bit_Length (N) is equivalent
-- to calling Right_Encode_NIST (N * 8). This function is useful to avoid
-- doing the multiplication in the call to Right_Encode_NIST and thus
-- avoiding the possibility of an integer overflow.
--
-- @param Byte_Length The length to right_encode. Usually represents a
-- quantity of bytes, as the output represents this value multiplied by 8.
function Right_Encode_K12 (Length : in Long_Long_Integer)
return Types.Byte_Array
with
Pre => Length >= 0,
Post => (Right_Encode_K12'Result'Length
in 1 .. (Long_Long_Integer'Size / 8) + 2
and Right_Encode_K12'Result'First
in 1 .. (Long_Long_Integer'Size / 8) + 2);
-- Version of right_encode(n) as defined by the KangarooTwelve document.
--
-- The definition of right_encode(n) in the KangarooTwelve document is
-- different to the definition in NIST SP 800-185, and they produce different
-- outputs.
procedure Compare (A1 : in Keccak.Types.Byte_Array;
A2 : in Keccak.Types.Byte_Array;
Accumulator : in out Keccak.Types.Byte)
with Global => null,
Depends => (Accumulator =>+ (A1, A2)),
Pre => A1'Length = A2'Length;
-- Compare two arrays in constant time.
--
-- If the two arrays are equal, then the Accumulator will retain its
-- initial value (e.g. zero). Otherwise, the Accumulator will be set
-- to a non-zero value.
end Keccak.Util;
|
-- Copyright 2010-2017 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with System;
package Pck is
type Rec is record
X: Integer;
S: String (1..8);
end record;
function Bar return Rec;
procedure Do_Nothing (A : System.Address);
end Pck;
|
-- This package has been generated automatically by GNATtest.
-- Do not edit any part of it, see GNATtest documentation for more details.
-- begin read only
with Gnattest_Generated;
package Bases.Test_Data.Tests.BaseCargo_Container.Test_Data.Tests is
type Test is new GNATtest_Generated.GNATtest_Standard.Bases.Test_Data.Tests
.BaseCargo_Container
.Test_Data
.New_Test with
null record;
end Bases.Test_Data.Tests.BaseCargo_Container.Test_Data.Tests;
-- end read only
|
package openGL.Geometry.textured
--
-- Supports per-vertex site and texture.
--
is
type Item is new openGL.Geometry.item with private;
function new_Geometry return access Geometry.textured.item'Class;
----------
-- Vertex
--
type Vertex is
record
Site : Vector_3;
Coords : Coordinate_2D;
end record;
type Vertex_array is array (Index_t range <>) of aliased Vertex;
--------------
-- Attributes
--
overriding
function is_Transparent (Self : in Item) return Boolean;
procedure Vertices_are (Self : in out Item; Now : in Vertex_array);
overriding
procedure Indices_are (Self : in out Item; Now : in Indices;
for_Facia : in Positive);
private
type Item is new Geometry.item with null record;
overriding
procedure enable_Texture (Self : in Item);
end openGL.Geometry.textured;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . V A L U E _ F --
-- --
-- B o d y --
-- --
-- Copyright (C) 2020-2021, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System.Unsigned_Types; use System.Unsigned_Types;
with System.Val_Util; use System.Val_Util;
with System.Value_R;
package body System.Value_F is
-- The prerequisite of the implementation is that the computation of the
-- operands of the scaled divide does not unduly overflow when the small
-- is neither an integer nor the reciprocal of an integer, which means
-- that its numerator and denominator must be both not larger than the
-- smallest divide 2**(Int'Size - 1) / Base where Base ranges over the
-- supported values for the base of the literal. Given that the largest
-- supported base is 16, this gives a limit of 2**(Int'Size - 5).
pragma Assert (Int'Size <= Uns'Size);
-- We need an unsigned type large enough to represent the mantissa
package Impl is new Value_R (Uns, 2**(Int'Size - 1), Round => True);
-- We use the Extra digit for ordinary fixed-point types
function Integer_To_Fixed
(Str : String;
Val : Uns;
Base : Unsigned;
ScaleB : Integer;
Extra : Unsigned;
Minus : Boolean;
Num : Int;
Den : Int) return Int;
-- Convert the real value from integer to fixed point representation
-- The goal is to compute Val * (Base ** ScaleB) / (Num / Den) with correct
-- rounding for all decimal values output by Typ'Image, that is to say up
-- to Typ'Aft decimal digits. Unlike for the output, the RM does not say
-- what the rounding must be for the input, but a reasonable exegesis of
-- the intent is that Typ'Value o Typ'Image should be the identity, which
-- is made possible because 'Aft is defined such that 'Image is injective.
-- For a type with a mantissa of M bits including the sign, the number N1
-- of decimal digits required to represent all the numbers is given by:
-- N1 = ceil ((M - 1) * log 2 / log 10) [N1 = 10/19/39 for M = 32/64/128]
-- but this mantissa can represent any set of contiguous numbers with only
-- N2 different decimal digits where:
-- N2 = floor ((M - 1) * log 2 / log 10) [N2 = 9/18/38 for M = 32/64/128]
-- Of course N1 = N2 + 1 holds, which means both that Val may not contain
-- enough significant bits to represent all the values of the type and that
-- 1 extra decimal digit contains the information for the missing bits.
-- Therefore the actual computation to be performed is
-- V = (Val * Base + Extra) * (Base ** (ScaleB - 1)) / (Num / Den)
-- using two steps of scaled divide if Extra is positive and ScaleB too
-- (1) Val * (Den * (Base ** ScaleB)) = Q1 * Num + R1
-- (2) Extra * (Den * (Base ** ScaleB)) = Q2 * -Base + R2
-- which yields after dividing (1) by Num and (2) by Num * Base and summing
-- V = Q1 + (R1 - Q2) / Num + R2 / (Num * Base)
-- but we get rid of the third term by using a rounding divide for (2).
-- This works only if Den * (Base ** ScaleB) does not overflow for inputs
-- corresponding to 'Image. Let S = Num / Den, B = Base and N the scale in
-- base B of S, i.e. the smallest integer such that B**N * S >= 1. Then,
-- for X a positive of the mantissa, i.e. 1 <= X <= 2**(M-1), we have
-- 1/B <= X * S * B**(N-1) < 2**(M-1)
-- which means that the inputs corresponding to the output of 'Image have a
-- ScaleB equal either to 1 - N or (after multiplying the inequality by B)
-- to -N, possibly after renormalizing X, i.e. multiplying it by a suitable
-- power of B. Therefore
-- Den * (Base ** ScaleB) <= Den * (B ** (1 - N)) < Num * B
-- which means that the product does not overflow if Num <= 2**(M-1) / B.
-- On the other hand, if Extra is positive and ScaleB negative, the above
-- two steps are
-- (1b) Val * Den = Q1 * (Num * (Base ** -ScaleB)) + R1
-- (2b) Extra * Den = Q2 * -Base + R2
-- which yields after dividing (1b) by Num * (Base ** -ScaleB) and (2b) by
-- Num * (Base ** (1 - ScaleB)) and summing
-- V = Q1 + (R1 - Q2) / (Num * (Base ** -ScaleB)) + R2 / ...
-- but we get rid of the third term by using a rounding divide for (2b).
-- This works only if Num * (Base ** -ScaleB) does not overflow for inputs
-- corresponding to 'Image. With the determination of ScaleB above, we have
-- Num * (Base ** -ScaleB) <= Num * (B ** N) < Den * B
-- which means that the product does not overflow if Den <= 2**(M-1) / B.
----------------------
-- Integer_To_Fixed --
----------------------
function Integer_To_Fixed
(Str : String;
Val : Uns;
Base : Unsigned;
ScaleB : Integer;
Extra : Unsigned;
Minus : Boolean;
Num : Int;
Den : Int) return Int
is
pragma Assert (Base in 2 .. 16);
pragma Assert (Extra < Base);
-- Accept only one extra digit after those used for Val
pragma Assert (Num < 0 and then Den < 0);
-- Accept only negative numbers to allow -2**(Int'Size - 1)
function Safe_Expont
(Base : Int;
Exp : in out Natural;
Factor : Int) return Int;
-- Return (Base ** Exp) * Factor if the computation does not overflow,
-- or else the number of the form (Base ** K) * Factor with the largest
-- magnitude if the former computation overflows. In both cases, Exp is
-- updated to contain the remaining power in the computation. Note that
-- Factor is expected to be negative in this context.
function Unsigned_To_Signed (Val : Uns) return Int;
-- Convert an integer value from unsigned to signed representation
-----------------
-- Safe_Expont --
-----------------
function Safe_Expont
(Base : Int;
Exp : in out Natural;
Factor : Int) return Int
is
pragma Assert (Base /= 0 and then Factor < 0);
Min : constant Int := Int'First / Base;
Result : Int := Factor;
begin
while Exp > 0 and then Result >= Min loop
Result := Result * Base;
Exp := Exp - 1;
end loop;
return Result;
end Safe_Expont;
------------------------
-- Unsigned_To_Signed --
------------------------
function Unsigned_To_Signed (Val : Uns) return Int is
begin
-- Deal with overflow cases, and also with largest negative number
if Val > Uns (Int'Last) then
if Minus and then Val = Uns (-(Int'First)) then
return Int'First;
else
Bad_Value (Str);
end if;
-- Negative values
elsif Minus then
return -(Int (Val));
-- Positive values
else
return Int (Val);
end if;
end Unsigned_To_Signed;
-- Local variables
B : constant Int := Int (Base);
V : Uns := Val;
E : Uns := Uns (Extra);
Y, Z, Q1, R1, Q2, R2 : Int;
begin
-- We will use a scaled divide operation for which we must control the
-- magnitude of operands so that an overflow exception is not unduly
-- raised during the computation. The only real concern is the exponent.
-- If ScaleB is too negative, then drop trailing digits, but preserve
-- the last dropped digit.
if ScaleB < 0 then
declare
LS : Integer := -ScaleB;
begin
Y := Den;
Z := Safe_Expont (B, LS, Num);
for J in 1 .. LS loop
E := V rem Uns (B);
V := V / Uns (B);
end loop;
end;
-- If ScaleB is too positive, then scale V up, which may then overflow
elsif ScaleB > 0 then
declare
LS : Integer := ScaleB;
begin
Y := Safe_Expont (B, LS, Den);
Z := Num;
for J in 1 .. LS loop
if V <= (Uns'Last - E) / Uns (B) then
V := V * Uns (B) + E;
E := 0;
else
Bad_Value (Str);
end if;
end loop;
end;
-- If ScaleB is zero, then proceed directly
else
Y := Den;
Z := Num;
end if;
-- Perform a scaled divide operation with final rounding to match Image
-- using two steps if there is an extra digit available. The second and
-- third operands are always negative so the sign of the quotient is the
-- sign of the first operand and the sign of the remainder the opposite.
if E > 0 then
Scaled_Divide (Unsigned_To_Signed (V), Y, Z, Q1, R1, Round => False);
Scaled_Divide (Unsigned_To_Signed (E), Y, -B, Q2, R2, Round => True);
-- Avoid an overflow during the subtraction. Note that Q2 is smaller
-- than Y and R1 smaller than Z in magnitude, so it is safe to take
-- their absolute value.
if abs Q2 >= 2 ** (Int'Size - 2)
or else abs R1 >= 2 ** (Int'Size - 2)
then
declare
Bit : constant Int := Q2 rem 2;
begin
Q2 := (Q2 - Bit) / 2;
R1 := (R1 - Bit) / 2;
Y := -2;
end;
else
Y := -1;
end if;
Scaled_Divide (Q2 - R1, Y, Z, Q2, R2, Round => True);
return Q1 + Q2;
else
Scaled_Divide (Unsigned_To_Signed (V), Y, Z, Q1, R1, Round => True);
return Q1;
end if;
exception
when Constraint_Error => Bad_Value (Str);
end Integer_To_Fixed;
----------------
-- Scan_Fixed --
----------------
function Scan_Fixed
(Str : String;
Ptr : not null access Integer;
Max : Integer;
Num : Int;
Den : Int) return Int
is
Base : Unsigned;
ScaleB : Integer;
Extra : Unsigned;
Minus : Boolean;
Val : Uns;
begin
Val := Impl.Scan_Raw_Real (Str, Ptr, Max, Base, ScaleB, Extra, Minus);
return Integer_To_Fixed (Str, Val, Base, ScaleB, Extra, Minus, Num, Den);
end Scan_Fixed;
-----------------
-- Value_Fixed --
-----------------
function Value_Fixed
(Str : String;
Num : Int;
Den : Int) return Int
is
Base : Unsigned;
ScaleB : Integer;
Extra : Unsigned;
Minus : Boolean;
Val : Uns;
begin
Val := Impl.Value_Raw_Real (Str, Base, ScaleB, Extra, Minus);
return Integer_To_Fixed (Str, Val, Base, ScaleB, Extra, Minus, Num, Den);
end Value_Fixed;
end System.Value_F;
|
-- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces.C;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_glx_get_color_table_parameteriv_cookie_t is
-- Item
--
type Item is record
sequence : aliased Interfaces.C.unsigned;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb
.xcb_glx_get_color_table_parameteriv_cookie_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_get_color_table_parameteriv_cookie_t.Item,
Element_Array =>
xcb.xcb_glx_get_color_table_parameteriv_cookie_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb
.xcb_glx_get_color_table_parameteriv_cookie_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_get_color_table_parameteriv_cookie_t.Pointer,
Element_Array =>
xcb.xcb_glx_get_color_table_parameteriv_cookie_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_glx_get_color_table_parameteriv_cookie_t;
|
pragma Ada_2005;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Interfaces.C; use Interfaces.C;
with System;
with glib;
with glib.Values;
with System;
package GStreamer.GST_Low_Level.gstreamer_0_10_gst_gst_h is
-- GStreamer
-- * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
-- * 2000 Wim Taymans <wtay@chello.be>
-- *
-- * gst.h: Main header for GStreamer, apps should include this
-- *
-- * This library is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU Library General Public
-- * License as published by the Free Software Foundation; either
-- * version 2 of the License, or (at your option) any later version.
-- *
-- * This library is distributed in the hope that it will be useful,
-- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- * Library General Public License for more details.
-- *
-- * You should have received a copy of the GNU Library General Public
-- * License along with this library; if not, write to the
-- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- * Boston, MA 02111-1307, USA.
--
-- API compatibility stuff
procedure gst_init (argc : access int; argv : System.Address); -- gst/gst.h:86
pragma Import (C, gst_init, "gst_init");
function gst_init_check
(argc : access int;
argv : System.Address;
err : System.Address) return GLIB.gboolean; -- gst/gst.h:87
pragma Import (C, gst_init_check, "gst_init_check");
function gst_is_initialized return GLIB.gboolean; -- gst/gst.h:89
pragma Import (C, gst_is_initialized, "gst_is_initialized");
function gst_init_get_option_group return System.Address; -- gst/gst.h:90
pragma Import (C, gst_init_get_option_group, "gst_init_get_option_group");
procedure gst_deinit; -- gst/gst.h:91
pragma Import (C, gst_deinit, "gst_deinit");
procedure gst_version
(major : access GLIB.guint;
minor : access GLIB.guint;
micro : access GLIB.guint;
nano : access GLIB.guint); -- gst/gst.h:93
pragma Import (C, gst_version, "gst_version");
function gst_version_string return access GLIB.gchar; -- gst/gst.h:95
pragma Import (C, gst_version_string, "gst_version_string");
function gst_segtrap_is_enabled return GLIB.gboolean; -- gst/gst.h:97
pragma Import (C, gst_segtrap_is_enabled, "gst_segtrap_is_enabled");
procedure gst_segtrap_set_enabled (enabled : GLIB.gboolean); -- gst/gst.h:98
pragma Import (C, gst_segtrap_set_enabled, "gst_segtrap_set_enabled");
function gst_registry_fork_is_enabled return GLIB.gboolean; -- gst/gst.h:100
pragma Import (C, gst_registry_fork_is_enabled, "gst_registry_fork_is_enabled");
procedure gst_registry_fork_set_enabled (enabled : GLIB.gboolean); -- gst/gst.h:101
pragma Import (C, gst_registry_fork_set_enabled, "gst_registry_fork_set_enabled");
function gst_update_registry return GLIB.gboolean; -- gst/gst.h:103
pragma Import (C, gst_update_registry, "gst_update_registry");
end GStreamer.GST_Low_Level.gstreamer_0_10_gst_gst_h;
|
with Ada.Text_IO;
use Ada.Text_IO;
-- Dans ce programme, les commentaires de spécification
-- ont **volontairement** été omis !
procedure Comprendre_Mode_Parametre is
function Double (N : in Integer) return Integer is
begin
return 2 * N;
end Double;
procedure Incrementer (N : in out Integer) is
begin
N := N + 1;
end Incrementer;
procedure Mettre_A_Zero (N : out Integer) is
begin
N := 0;
end Mettre_A_Zero;
procedure Comprendre_Les_Contraintes_Sur_L_Appelant is
A, B, R : Integer;
begin
A := 5;
-- Indiquer pour chacune des instructions suivantes si elles sont
-- acceptées par le compilateur. Si elles sont refusées, expliquer
-- pourquoi dans un commentaire sur la ligne.
R := Double (A); -- Accepté: Double est une fonction qui admet un 'in integer' et retourne un integer
R := Double (10); -- De même, même si 10 est une valeur mais le 'in' autorise ça
R := Double (10 * A); -- De même
R := Double (B); -- Accepté même si B n'est pas initialisé, B prend la valeur des bits déja presents dans son emplacement dans la memoire.
Incrementer (A); -- Accepté: A est une variable Integer et la fonction demande un parametre Integer
--Incrementer (10); -- Refusé: Le out de 'Incrementer' refuse qu'une valeur soit passée.
--Incrementer (10 * A); -- De même refusé: 10*A est une valeur non pas variable.
Incrementer (B); -- Accepté: Même si B n'est pas initialisée mais elle a une valeur aléatoire des bits déja présents dans son emplacement.
Mettre_A_Zero (A); -- Accepté: A variable de type Integer et la fonction demande un Integer
--Mettre_A_Zero (10); -- Refusé: 10 n'est pas une variable.
--Mettre_A_Zero (10 * A); -- Refusé: 10*A n'est pas une variable.
Mettre_A_Zero (B); -- Accepté: B variable de type Integer et la fonction demande un Integer
end Comprendre_Les_Contraintes_Sur_L_Appelant;
procedure Comprendre_Les_Contrainte_Dans_Le_Corps (
A : in Integer;
B1, B2 : in out Integer;
C1, C2 : out Integer)
is
L: Integer;
begin
-- pour chaque affectation suivante indiquer si elle est autorisée
L := A; -- Autorisé
--A := 1; -- Non autorisé (A en mode in)
B1 := 5; -- Autorisé (B1 en mode in out)
L := B2; -- Autorisé
B2 := B2 + 1; -- Autorisé (mode in ET out)
C1 := L; -- Autorisé
L := C2; -- Autorisé à partir d'une certaine version de ADA
C2 := A; -- Autorisé car C2 en 'out'
C2 := C2 + 1; -- Autorisé à partir d'une certaine version de ADA (la lecture de C2 pose ce problème)
end Comprendre_Les_Contrainte_Dans_Le_Corps;
begin
--Comprendre_Mode_Parametre;
Comprendre_Les_Contraintes_Sur_L_Appelant;
--Put_Line ("Fin");
end Comprendre_Mode_Parametre;
|
-- ----------------------------------------------------------------- --
-- --
-- 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 --
-- ----------------------------------------------------------------- --
-- Simple program: Loop, watching keystrokes
-- Note that you need to call SDL.Events.PollEvent
-- or SDL.Events.WaitEvent to pump the event loop
-- and catch keystrokes.
with Interfaces.C.Strings;
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.OS_Lib;
with SDL.Types; use SDL.Types;
with SDL.Keysym;
with SDL.Keyboard;
with SDL.Error;
with SDL.Quit;
with SDL.Events;
with SDL.Video;
procedure CheckKeys is
package C renames Interfaces.C;
use type C.int;
use type C.wchar_t;
package CS renames Interfaces.C.Strings;
package Ks renames SDL.Keysym;
use type Ks.Key;
package Kb renames SDL.Keyboard;
package Er renames SDL.Error;
package Ev renames SDL.Events;
package V renames SDL.Video;
Screen_Width : constant := 640;
Screen_Height : constant := 480;
-- ===============================================
procedure PrintKey (sym : in Kb.keysym; pressed : Boolean) is
begin
-- Print the keycode, name and state
if sym.sym /= 0 then
Put ("Key ");
if pressed then
Put ("pressed: ");
else
Put ("released: ");
end if;
Put (Ks.Key'Image (sym.sym) & "-" &
CS.Value (Kb.GetKeyName (sym.sym)) &
" ");
else
Put ("Unknown Key (scancode = " &
Uint8'Image (sym.scancode) & ") ");
if pressed then
Put_Line ("pressed: ");
else
Put_Line ("released: ");
end if;
end if;
-- Print the translated character, if one exists
if sym.unicode /= 0 then
-- Is it a control-character?
if C.wchar_t'Val (sym.unicode) < C.wchar_t'(' ') then
Put_Line (" (^"
& C.wchar_t'Image (C.wchar_t'Val
(sym.unicode)) & "@)");
-- & Uint16'Image (sym.unicode) & "@)");
else
-- #ifdef UNICODE
-- Put_Line (" (" & Uint16'Image (sym.unicode) & ")");
Put_Line (" (" & C.wchar_t'Image (C.wchar_t'Val
(sym.unicode)) & ")");
-- #else
-- This is a Latin-1 program, so only show 8-bits */
-- if (sym.unicode and 16#FF00#) = 0 then
-- Put_Line (" (" & Uint16'Image (sym.unicode) & ")");
-- end if;
-- #endif
end if;
end if;
New_Line;
end PrintKey;
-- ===============================================
event : Ev.Event;
done : C.int; -- Boolean should be better.
begin
-- Initialize SDL
if SDL.Init (SDL.INIT_VIDEO) < 0 then
Put_Line ("Couldn't initialize SDl: " & Er.Get_Error);
GNAT.OS_Lib.OS_Exit (1);
end if;
SDL.Quit.atexit (SDL.SDL_Quit'Access);
declare
screen : V.Surface_ptr;
use type V.Surface_ptr;
begin
-- Set video mode
screen := V.SetVideoMode (Screen_Width, Screen_Height,
0, V.SWSURFACE);
if screen = null then
Put_Line ("Couldn't set " & Integer'Image (Screen_Width) &
"x" & Integer'Image (Screen_Height) &
" video mode: " & Er.Get_Error);
GNAT.OS_Lib.OS_Exit (2);
end if;
end;
-- Enable UNICODE translation for keyboard input
Kb.EnableUNICODE (1);
Kb.EnableKeyRepeat (
Kb.DEFAULT_REPEAT_DELAY,
Kb.DEFAULT_REPEAT_INTERVAL);
-- Watch keystrokes
done := 0;
while done = 0 loop
-- Check for events
-- Read the note in the "event" declaration point.
Ev.WaitEvent (event);
case event.the_type is
when Ev.KEYDOWN =>
-- Read the note in the "event" declaration point.
PrintKey (event.key.keysym, True);
when Ev.KEYUP =>
-- Read the note in the "event" declaration point.
PrintKey (event.key.keysym, False);
when Ev.MOUSEBUTTONDOWN | Ev.QUIT =>
-- Any button press quits the app...
done := 1;
when others => null;
end case;
end loop;
end CheckKeys;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- Abstract interface of SOAP fault encoder. Application specific encoders
-- must be derived from this interface type.
------------------------------------------------------------------------------
with XML.SAX.Writers;
package Web_Services.SOAP.Payloads.Faults.Encoders is
-- pragma Preelaborate;
type SOAP_Fault_Encoder is limited interface;
type SOAP_Fault_Encoder_Access is access all SOAP_Fault_Encoder'Class;
not overriding function Create
(Dummy : not null access Boolean)
return SOAP_Fault_Encoder is abstract;
-- This subprogram is used by dispatching constructor to create instance of
-- the encoder.
not overriding procedure Encode
(Self : SOAP_Fault_Encoder;
Message : Web_Services.SOAP.Payloads.Faults.Abstract_SOAP_Fault'Class;
Writer : in out XML.SAX.Writers.SAX_Writer'Class) is abstract;
end Web_Services.SOAP.Payloads.Faults.Encoders;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
-- An opaque expression is an uninterpreted textual statement that denotes a
-- (possibly empty) set of values when evaluated in a context.
------------------------------------------------------------------------------
with AMF.CMOF.Value_Specifications;
with AMF.String_Collections;
package AMF.CMOF.Opaque_Expressions is
pragma Preelaborate;
type CMOF_Opaque_Expression is limited interface
and AMF.CMOF.Value_Specifications.CMOF_Value_Specification;
type CMOF_Opaque_Expression_Access is
access all CMOF_Opaque_Expression'Class;
for CMOF_Opaque_Expression_Access'Storage_Size use 0;
not overriding function Get_Body
(Self : not null access constant CMOF_Opaque_Expression)
return AMF.String_Collections.Sequence_Of_String is abstract;
-- Getter of OpaqueExpression::body.
--
-- The text of the expression, possibly in multiple languages.
not overriding function Get_Language
(Self : not null access constant CMOF_Opaque_Expression)
return AMF.String_Collections.Ordered_Set_Of_String is abstract;
-- Getter of OpaqueExpression::language.
--
-- Specifies the languages in which the expression is stated. The
-- interpretation of the expression body depends on the languages. If the
-- languages are unspecified, they might be implicit from the expression
-- body or the context. Languages are matched to body strings by order.
end AMF.CMOF.Opaque_Expressions;
|
-- { dg-do compile }
-- { dg-options "-O2 -gnatp" }
function Scalar_Mode_Agg_Compare_Loop return Boolean is
S : constant String (1 .. 4) := "ABCD";
F : constant Natural := S'First;
L : constant Natural := S'Last;
begin
for J in F .. L - 1 loop
if S (F .. F) = "X" or (J <= L - 2 and S (J .. J + 1) = "YY") then
return True;
end if;
end loop;
return False;
end;
|
pragma Ada_2005;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Interfaces.C; use Interfaces.C;
with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstsegment_h;
with GLIB; -- with GStreamer.GST_Low_Level.glibconfig_h;
with glib;
with glib.Values;
with System;
with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h;
with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h;
-- limited with GStreamer.GST_Low_Level.glib_2_0_glib_gqueue_h;
with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h;
with System;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstcaps_h;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstevent_h;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstquery_h;
with glib;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstminiobject_h;
package GStreamer.GST_Low_Level.gstreamer_0_10_gst_base_gstbasesink_h is
-- unsupported macro: GST_TYPE_BASE_SINK (gst_base_sink_get_type())
-- arg-macro: function GST_BASE_SINK (obj)
-- return G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_SINK,GstBaseSink);
-- arg-macro: function GST_BASE_SINK_CLASS (klass)
-- return G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_SINK,GstBaseSinkClass);
-- arg-macro: function GST_BASE_SINK_GET_CLASS (obj)
-- return G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BASE_SINK, GstBaseSinkClass);
-- arg-macro: function GST_IS_BASE_SINK (obj)
-- return G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_SINK);
-- arg-macro: function GST_IS_BASE_SINK_CLASS (klass)
-- return G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_SINK);
-- arg-macro: function GST_BASE_SINK_CAST (obj)
-- return (GstBaseSink *) (obj);
-- arg-macro: function GST_BASE_SINK_PAD (obj)
-- return GST_BASE_SINK_CAST (obj).sinkpad;
-- GStreamer
-- * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
-- * 2000 Wim Taymans <wtay@chello.be>
-- *
-- * gstbasesink.h:
-- *
-- * This library is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU Library General Public
-- * License as published by the Free Software Foundation; either
-- * version 2 of the License, or (at your option) any later version.
-- *
-- * This library is distributed in the hope that it will be useful,
-- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- * Library General Public License for more details.
-- *
-- * You should have received a copy of the GNU Library General Public
-- * License along with this library; if not, write to the
-- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- * Boston, MA 02111-1307, USA.
--
--*
-- * GST_BASE_SINK_PAD:
-- * @obj: base sink instance
-- *
-- * Gives the pointer to the #GstPad object of the element.
--
type GstBaseSink;
type anon_313;
type anon_314 is record
clip_segment : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstsegment_h.GstSegment; -- gst/base/gstbasesink.h:94
max_lateness : aliased GLIB.gint64; -- gst/base/gstbasesink.h:96
running : aliased GLIB.gboolean; -- gst/base/gstbasesink.h:97
end record;
pragma Convention (C_Pass_By_Copy, anon_314);
type u_GstBaseSink_u_gst_reserved_array is array (0 .. 18) of System.Address;
type anon_313 (discr : unsigned := 0) is record
case discr is
when 0 =>
ABI : aliased anon_314; -- gst/base/gstbasesink.h:98
when others =>
u_gst_reserved : u_GstBaseSink_u_gst_reserved_array; -- gst/base/gstbasesink.h:99
end case;
end record;
pragma Convention (C_Pass_By_Copy, anon_313);
pragma Unchecked_Union (anon_313);--subtype GstBaseSink is u_GstBaseSink; -- gst/base/gstbasesink.h:47
type GstBaseSinkClass;
type u_GstBaseSinkClass_u_gst_reserved_array is array (0 .. 13) of System.Address;
--subtype GstBaseSinkClass is u_GstBaseSinkClass; -- gst/base/gstbasesink.h:48
-- skipped empty struct u_GstBaseSinkPrivate
-- skipped empty struct GstBaseSinkPrivate
--*
-- * GstBaseSink:
-- *
-- * The opaque #GstBaseSink data structure.
--
type GstBaseSink is record
element : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h.GstElement; -- gst/base/gstbasesink.h:57
sinkpad : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstPad; -- gst/base/gstbasesink.h:60
pad_mode : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstActivateMode; -- gst/base/gstbasesink.h:61
offset : aliased GLIB.guint64; -- gst/base/gstbasesink.h:64
can_activate_pull : aliased GLIB.gboolean; -- gst/base/gstbasesink.h:65
can_activate_push : aliased GLIB.gboolean; -- gst/base/gstbasesink.h:66
preroll_queue : access GStreamer.GST_Low_Level.glib_2_0_glib_gqueue_h.GQueue; -- gst/base/gstbasesink.h:69
preroll_queue_max_len : aliased GLIB.gint; -- gst/base/gstbasesink.h:70
preroll_queued : aliased GLIB.gint; -- gst/base/gstbasesink.h:71
buffers_queued : aliased GLIB.gint; -- gst/base/gstbasesink.h:72
events_queued : aliased GLIB.gint; -- gst/base/gstbasesink.h:73
eos : aliased GLIB.gboolean; -- gst/base/gstbasesink.h:74
eos_queued : aliased GLIB.gboolean; -- gst/base/gstbasesink.h:75
need_preroll : aliased GLIB.gboolean; -- gst/base/gstbasesink.h:76
have_preroll : aliased GLIB.gboolean; -- gst/base/gstbasesink.h:77
playing_async : aliased GLIB.gboolean; -- gst/base/gstbasesink.h:78
have_newsegment : aliased GLIB.gboolean; -- gst/base/gstbasesink.h:81
segment : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstsegment_h.GstSegment; -- gst/base/gstbasesink.h:82
clock_id : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockID; -- gst/base/gstbasesink.h:85
end_time : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime; -- gst/base/gstbasesink.h:86
sync : aliased GLIB.gboolean; -- gst/base/gstbasesink.h:87
flushing : aliased GLIB.gboolean; -- gst/base/gstbasesink.h:88
abidata : aliased anon_313; -- gst/base/gstbasesink.h:100
priv : System.Address; -- gst/base/gstbasesink.h:102
end record;
pragma Convention (C_Pass_By_Copy, GstBaseSink); -- gst/base/gstbasesink.h:56
--< protected >
--< protected >
-- with LOCK
--< protected >
-- with PREROLL_LOCK
-- FIXME-0.11: the property is guint
--< protected >
-- with STREAM_LOCK
--< private >
-- with LOCK
--< private >
-- segment used for clipping incoming buffers
-- max amount of time a buffer can be late, -1 no limit.
--*
-- * GstBaseSinkClass:
-- * @parent_class: Element parent class
-- * @get_caps: Called to get sink pad caps from the subclass
-- * @set_caps: Notify subclass of changed caps
-- * @buffer_alloc: Subclasses can override to perform custom buffer allocations
-- * @get_times: Called to get the start and end times for synchronising
-- * the passed buffer to the clock
-- * @start: Start processing. Ideal for opening resources in the subclass
-- * @stop: Stop processing. Subclasses should use this to close resources.
-- * @unlock: Unlock any pending access to the resource. Subclasses should
-- * unblock any blocked function ASAP
-- * @unlock_stop: Clear the previous unlock request. Subclasses should clear
-- * any state they set during unlock(), such as clearing command queues.
-- * @event: Override this to handle events arriving on the sink pad
-- * @preroll: Called to present the preroll buffer if desired
-- * @render: Called when a buffer should be presented or output, at the
-- * correct moment if the #GstBaseSink has been set to sync to the clock.
-- * @render_list: Same as @render but used whith buffer lists instead of
-- * buffers. Since: 0.10.24
-- * @async_play: Subclasses should override this when they need to perform
-- * special processing when changing to the PLAYING state asynchronously.
-- * Called with the OBJECT_LOCK held.
-- * @activate_pull: Subclasses should override this when they can provide an
-- * alternate method of spawning a thread to drive the pipeline in pull mode.
-- * Should start or stop the pulling thread, depending on the value of the
-- * "active" argument. Called after actually activating the sink pad in pull
-- * mode. The default implementation starts a task on the sink pad.
-- * @fixate: Only useful in pull mode, this vmethod will be called in response to
-- * gst_pad_fixate_caps() being called on the sink pad. Implement if you have
-- * ideas about what should be the default values for the caps you support.
-- * @query: perform a #GstQuery on the element. Since: 0.10.36
-- *
-- * Subclasses can override any of the available virtual methods or not, as
-- * needed. At the minimum, the @render method should be overridden to
-- * output/present buffers.
--
type GstBaseSinkClass is record
parent_class : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h.GstElementClass; -- gst/base/gstbasesink.h:143
get_caps : access function (arg1 : access GstBaseSink) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstcaps_h.GstCaps; -- gst/base/gstbasesink.h:146
set_caps : access function (arg1 : access GstBaseSink; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstcaps_h.GstCaps) return GLIB.gboolean; -- gst/base/gstbasesink.h:148
buffer_alloc : access function
(arg1 : access GstBaseSink;
arg2 : GLIB.guint64;
arg3 : GLIB.guint;
arg4 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstcaps_h.GstCaps;
arg5 : System.Address) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstFlowReturn; -- gst/base/gstbasesink.h:152
get_times : access procedure
(arg1 : access GstBaseSink;
arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h.GstBuffer;
arg3 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime;
arg4 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime); -- gst/base/gstbasesink.h:156
start : access function (arg1 : access GstBaseSink) return GLIB.gboolean; -- gst/base/gstbasesink.h:159
stop : access function (arg1 : access GstBaseSink) return GLIB.gboolean; -- gst/base/gstbasesink.h:160
unlock : access function (arg1 : access GstBaseSink) return GLIB.gboolean; -- gst/base/gstbasesink.h:164
event : access function (arg1 : access GstBaseSink; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstevent_h.GstEvent) return GLIB.gboolean; -- gst/base/gstbasesink.h:167
preroll : access function (arg1 : access GstBaseSink; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h.GstBuffer) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstFlowReturn; -- gst/base/gstbasesink.h:168
render : access function (arg1 : access GstBaseSink; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h.GstBuffer) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstFlowReturn; -- gst/base/gstbasesink.h:169
async_play : access function (arg1 : access GstBaseSink) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h.GstStateChangeReturn; -- gst/base/gstbasesink.h:174
activate_pull : access function (arg1 : access GstBaseSink; arg2 : GLIB.gboolean) return GLIB.gboolean; -- gst/base/gstbasesink.h:177
fixate : access procedure (arg1 : access GstBaseSink; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstcaps_h.GstCaps); -- gst/base/gstbasesink.h:180
unlock_stop : access function (arg1 : access GstBaseSink) return GLIB.gboolean; -- gst/base/gstbasesink.h:185
render_list : access function (arg1 : access GstBaseSink; arg2 : System.Address) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstFlowReturn; -- gst/base/gstbasesink.h:188
query : access function (arg1 : access GstBaseSink; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstquery_h.GstQuery) return GLIB.gboolean; -- gst/base/gstbasesink.h:191
u_gst_reserved : u_GstBaseSinkClass_u_gst_reserved_array; -- gst/base/gstbasesink.h:194
end record;
pragma Convention (C_Pass_By_Copy, GstBaseSinkClass); -- gst/base/gstbasesink.h:142
-- get caps from subclass
-- notify subclass of new caps
-- allocate a new buffer with given caps
-- get the start and end times for syncing on this buffer
-- start and stop processing, ideal for opening/closing the resource
-- unlock any pending access to the resource. subclasses should unlock
-- * any function ASAP.
-- notify subclass of event, preroll buffer or real buffer
-- ABI additions
-- when an ASYNC state change to PLAYING happens
-- with LOCK
-- start or stop a pulling thread
-- fixate sink caps during pull-mode negotiation
-- Clear a previously indicated unlock request not that unlocking is
-- * complete. Sub-classes should clear any command queue or indicator they
-- * set during unlock
-- Render a BufferList
-- notify subclass of query
--< private >
function gst_base_sink_get_type return GLIB.GType; -- gst/base/gstbasesink.h:197
pragma Import (C, gst_base_sink_get_type, "gst_base_sink_get_type");
function gst_base_sink_do_preroll (sink : access GstBaseSink; obj : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstminiobject_h.GstMiniObject) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstFlowReturn; -- gst/base/gstbasesink.h:199
pragma Import (C, gst_base_sink_do_preroll, "gst_base_sink_do_preroll");
function gst_base_sink_wait_preroll (sink : access GstBaseSink) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstFlowReturn; -- gst/base/gstbasesink.h:200
pragma Import (C, gst_base_sink_wait_preroll, "gst_base_sink_wait_preroll");
-- synchronizing against the clock
procedure gst_base_sink_set_sync (sink : access GstBaseSink; sync : GLIB.gboolean); -- gst/base/gstbasesink.h:203
pragma Import (C, gst_base_sink_set_sync, "gst_base_sink_set_sync");
function gst_base_sink_get_sync (sink : access GstBaseSink) return GLIB.gboolean; -- gst/base/gstbasesink.h:204
pragma Import (C, gst_base_sink_get_sync, "gst_base_sink_get_sync");
-- dropping late buffers
procedure gst_base_sink_set_max_lateness (sink : access GstBaseSink; max_lateness : GLIB.gint64); -- gst/base/gstbasesink.h:207
pragma Import (C, gst_base_sink_set_max_lateness, "gst_base_sink_set_max_lateness");
function gst_base_sink_get_max_lateness (sink : access GstBaseSink) return GLIB.gint64; -- gst/base/gstbasesink.h:208
pragma Import (C, gst_base_sink_get_max_lateness, "gst_base_sink_get_max_lateness");
-- performing QoS
procedure gst_base_sink_set_qos_enabled (sink : access GstBaseSink; enabled : GLIB.gboolean); -- gst/base/gstbasesink.h:211
pragma Import (C, gst_base_sink_set_qos_enabled, "gst_base_sink_set_qos_enabled");
function gst_base_sink_is_qos_enabled (sink : access GstBaseSink) return GLIB.gboolean; -- gst/base/gstbasesink.h:212
pragma Import (C, gst_base_sink_is_qos_enabled, "gst_base_sink_is_qos_enabled");
-- doing async state changes
procedure gst_base_sink_set_async_enabled (sink : access GstBaseSink; enabled : GLIB.gboolean); -- gst/base/gstbasesink.h:215
pragma Import (C, gst_base_sink_set_async_enabled, "gst_base_sink_set_async_enabled");
function gst_base_sink_is_async_enabled (sink : access GstBaseSink) return GLIB.gboolean; -- gst/base/gstbasesink.h:216
pragma Import (C, gst_base_sink_is_async_enabled, "gst_base_sink_is_async_enabled");
-- tuning synchronisation
procedure gst_base_sink_set_ts_offset (sink : access GstBaseSink; offset : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTimeDiff); -- gst/base/gstbasesink.h:219
pragma Import (C, gst_base_sink_set_ts_offset, "gst_base_sink_set_ts_offset");
function gst_base_sink_get_ts_offset (sink : access GstBaseSink) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTimeDiff; -- gst/base/gstbasesink.h:220
pragma Import (C, gst_base_sink_get_ts_offset, "gst_base_sink_get_ts_offset");
-- last buffer
function gst_base_sink_get_last_buffer (sink : access GstBaseSink) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h.GstBuffer; -- gst/base/gstbasesink.h:223
pragma Import (C, gst_base_sink_get_last_buffer, "gst_base_sink_get_last_buffer");
procedure gst_base_sink_set_last_buffer_enabled (sink : access GstBaseSink; enabled : GLIB.gboolean); -- gst/base/gstbasesink.h:224
pragma Import (C, gst_base_sink_set_last_buffer_enabled, "gst_base_sink_set_last_buffer_enabled");
function gst_base_sink_is_last_buffer_enabled (sink : access GstBaseSink) return GLIB.gboolean; -- gst/base/gstbasesink.h:225
pragma Import (C, gst_base_sink_is_last_buffer_enabled, "gst_base_sink_is_last_buffer_enabled");
-- latency
function gst_base_sink_query_latency
(sink : access GstBaseSink;
live : access GLIB.gboolean;
upstream_live : access GLIB.gboolean;
min_latency : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime;
max_latency : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime) return GLIB.gboolean; -- gst/base/gstbasesink.h:228
pragma Import (C, gst_base_sink_query_latency, "gst_base_sink_query_latency");
function gst_base_sink_get_latency (sink : access GstBaseSink) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime; -- gst/base/gstbasesink.h:230
pragma Import (C, gst_base_sink_get_latency, "gst_base_sink_get_latency");
-- render delay
procedure gst_base_sink_set_render_delay (sink : access GstBaseSink; c_delay : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime); -- gst/base/gstbasesink.h:233
pragma Import (C, gst_base_sink_set_render_delay, "gst_base_sink_set_render_delay");
function gst_base_sink_get_render_delay (sink : access GstBaseSink) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime; -- gst/base/gstbasesink.h:234
pragma Import (C, gst_base_sink_get_render_delay, "gst_base_sink_get_render_delay");
-- blocksize
procedure gst_base_sink_set_blocksize (sink : access GstBaseSink; blocksize : GLIB.guint); -- gst/base/gstbasesink.h:237
pragma Import (C, gst_base_sink_set_blocksize, "gst_base_sink_set_blocksize");
function gst_base_sink_get_blocksize (sink : access GstBaseSink) return GLIB.guint; -- gst/base/gstbasesink.h:238
pragma Import (C, gst_base_sink_get_blocksize, "gst_base_sink_get_blocksize");
-- throttle-time
procedure gst_base_sink_set_throttle_time (sink : access GstBaseSink; throttle : GLIB.guint64); -- gst/base/gstbasesink.h:241
pragma Import (C, gst_base_sink_set_throttle_time, "gst_base_sink_set_throttle_time");
function gst_base_sink_get_throttle_time (sink : access GstBaseSink) return GLIB.guint64; -- gst/base/gstbasesink.h:242
pragma Import (C, gst_base_sink_get_throttle_time, "gst_base_sink_get_throttle_time");
function gst_base_sink_wait_clock
(sink : access GstBaseSink;
time : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime;
jitter : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTimeDiff) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockReturn; -- gst/base/gstbasesink.h:244
pragma Import (C, gst_base_sink_wait_clock, "gst_base_sink_wait_clock");
function gst_base_sink_wait_eos
(sink : access GstBaseSink;
time : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime;
jitter : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTimeDiff) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstFlowReturn; -- gst/base/gstbasesink.h:246
pragma Import (C, gst_base_sink_wait_eos, "gst_base_sink_wait_eos");
end GStreamer.GST_Low_Level.gstreamer_0_10_gst_base_gstbasesink_h;
|
--
-- Copyright (C) 2015-2016 secunet Security Networks AG
-- Copyright (C) 2016 Nico Huber <nico.h@gmx.de>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
with HW.GFX.GMA.Config;
with HW.GFX.GMA.Panel;
with HW.GFX.GMA.Connectors.EDP;
with HW.GFX.GMA.Connectors.FDI;
with HW.GFX.GMA.PCH.VGA;
with HW.GFX.GMA.PCH.LVDS;
with HW.GFX.GMA.PCH.HDMI;
with HW.GFX.GMA.PCH.DP;
with HW.GFX.GMA.PCH.Transcoder;
with HW.Debug;
with GNAT.Source_Info;
package body HW.GFX.GMA.Connectors
is
procedure Post_Reset_Off is null;
procedure Initialize is null;
function Is_Internal (Port_Cfg : Port_Config) return Boolean
is
begin
return
Port_Cfg.Port = DIGI_A or
(Port_Cfg.Is_FDI and Port_Cfg.PCH_Port = PCH_LVDS);
end Is_Internal;
----------------------------------------------------------------------------
procedure Pre_On
(Pipe : in Pipe_Index;
Port_Cfg : in Port_Config;
PLL_Hint : in Word32;
Success : out Boolean)
is
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
if Port_Cfg.Port = DIGI_A then
EDP.Pre_On (Pipe, Port_Cfg);
elsif Port_Cfg.Port in FDI.GPU_FDI_Port then
FDI.Pre_On (Port_Cfg);
end if;
Success := True;
end Pre_On;
procedure Post_On
(Pipe : in Pipe_Index;
Port_Cfg : in Port_Config;
PLL_Hint : in Word32;
Success : out Boolean)
is
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
if Port_Cfg.Port = DIGI_A then
EDP.Pre_Training;
Panel.On (Wait => True);
EDP.Post_On (Port_Cfg.DP, Success);
elsif Port_Cfg.Port in FDI.GPU_FDI_Port then
declare
FDI_Port : constant PCH.FDI_Port_Type :=
FDI.PCH_FDIs (Port_Cfg.Port);
begin
FDI.Post_On (Port_Cfg, Success);
if Success then
PCH.Transcoder.On (Port_Cfg, FDI_Port, PLL_Hint);
if Port_Cfg.PCH_Port = PCH_DAC then
PCH.VGA.On (FDI_Port, Port_Cfg.Mode);
elsif Port_Cfg.PCH_Port = PCH_LVDS then
PCH.LVDS.On (Port_Cfg, FDI_Port);
elsif Port_Cfg.PCH_Port in PCH_HDMI_Port then
PCH.HDMI.On (Port_Cfg, FDI_Port);
elsif Port_Cfg.PCH_Port in PCH_DP_Port then
PCH.DP.On (Port_Cfg, Success);
end if;
end if;
end;
else
Success := False;
end if;
if Success and Is_Internal (Port_Cfg) then
Panel.On (Wait => False);
Panel.Backlight_On;
end if;
end Post_On;
----------------------------------------------------------------------------
procedure Pre_Off (Port_Cfg : Port_Config)
is
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
if Is_Internal (Port_Cfg) then
Panel.Backlight_Off;
Panel.Off;
end if;
end Pre_Off;
procedure Post_Off (Port_Cfg : Port_Config)
is
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
if Port_Cfg.Port = DIGI_A then
EDP.Off (Port_Cfg.Port);
elsif Port_Cfg.Port in FDI.GPU_FDI_Port then
declare
FDI_Port : constant PCH.FDI_Port_Type :=
FDI.PCH_FDIs (Port_Cfg.Port);
begin
if Port_Cfg.PCH_Port in PCH_DP_Port then
PCH.DP.Off (Port_Cfg.PCH_Port);
end if;
FDI.Off (Port_Cfg.Port, FDI.Link_Off);
if Port_Cfg.PCH_Port = PCH_DAC then
PCH.VGA.Off;
elsif Port_Cfg.PCH_Port = PCH_LVDS then
PCH.LVDS.Off;
elsif Port_Cfg.PCH_Port in PCH_HDMI_Port then
PCH.HDMI.Off (Port_Cfg.PCH_Port);
end if;
PCH.Transcoder.Off (FDI_Port);
FDI.Off (Port_Cfg.Port, FDI.Clock_Off);
end;
end if;
end Post_Off;
----------------------------------------------------------------------------
procedure Pre_All_Off
is
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
Panel.Backlight_Off;
Panel.Off;
end Pre_All_Off;
procedure Post_All_Off
is
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
EDP.Off (DIGI_A);
for Port in FDI.GPU_FDI_Port loop
FDI.Off (Port, FDI.Link_Off);
end loop;
PCH.VGA.Off;
PCH.LVDS.Off;
PCH.HDMI.All_Off;
PCH.DP.All_Off;
for Port in PCH.FDI_Port_Type loop
PCH.Transcoder.Off (Port);
end loop;
for Port in FDI.GPU_FDI_Port loop
FDI.Off (Port, FDI.Clock_Off);
end loop;
end Post_All_Off;
end HW.GFX.GMA.Connectors;
|
-- C87B43A.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 OVERLOADING RESOLUTION USES THE RULE THAT:
--
-- IN A CASE STATEMENT, THE TYPE OF EACH CHOICE MUST MATCH THE TYPE
-- OF THE EXPRESSION.
-- TRH 3 AUG 82
-- DSJ 10 JUN 83
WITH REPORT; USE REPORT;
PROCEDURE C87B43A IS
TYPE WHOLE IS NEW INTEGER RANGE 0 .. INTEGER'LAST;
FUNCTION "+" (X, Y : INTEGER) RETURN INTEGER
RENAMES "*";
ERR : BOOLEAN := FALSE;
X : WHOLE := 6;
BEGIN
TEST ("C87B43A","TYPE OF CASE CHOICE MUST MATCH TYPE OF " &
"EXPRESSION");
CASE X IS
WHEN (2 + 3) => ERR := TRUE;
WHEN (3 + 3) => NULL;
WHEN OTHERS => ERR := TRUE;
END CASE;
IF ERR THEN
FAILED ("CASE STATEMENT CHOICE MUST MATCH TYPE OF EXPRESSION");
END IF;
RESULT;
END C87B43A;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ E L I M --
-- --
-- S p e c --
-- --
-- Copyright (C) 1997-2008, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package contains the routines used to process the Eliminate pragma
with Types; use Types;
package Sem_Elim is
procedure Initialize;
-- Initialize for new main source program
procedure Process_Eliminate_Pragma
(Pragma_Node : Node_Id;
Arg_Unit_Name : Node_Id;
Arg_Entity : Node_Id;
Arg_Parameter_Types : Node_Id;
Arg_Result_Type : Node_Id;
Arg_Source_Location : Node_Id);
-- Process eliminate pragma (given by Pragma_Node). The number of
-- arguments has been checked, as well as possible optional identifiers,
-- but no other checks have been made. This subprogram completes the
-- checking, and then if the pragma is well formed, makes appropriate
-- entries in the internal tables used to keep track of Eliminate pragmas.
-- The other five arguments are expressions (rather than pragma argument
-- associations) for the possible pragma arguments. A parameter that
-- is not present is set to Empty.
procedure Check_Eliminated (E : Entity_Id);
-- Checks if entity E is eliminated, and if so sets the Is_Eliminated
-- flag on the given entity.
procedure Check_For_Eliminated_Subprogram (N : Node_Id; S : Entity_Id);
-- Check that the subprogram S (or its ultimate parent in the case of a
-- derived subprogram or renaming) has not been eliminated. An error will
-- be flagged if the subprogram has been eliminated, unless the node N
-- occurs within an eliminated subprogram or within a generic unit. The
-- error will be posted on N.
procedure Eliminate_Error_Msg (N : Node_Id; E : Entity_Id);
-- Called by the front-end and back-end on encountering a reference to an
-- eliminated subprogram. N is the node for the reference (such as occurs
-- in a call or attribute), and E is the entity of the subprogram that has
-- been eliminated.
end Sem_Elim;
|
package body Array25_Pkg is
procedure Get_Inner (A : out Arr1) is
begin
null;
end;
procedure Get (A : out Arr2) is
begin
for I in Arr2'Range loop
Get_Inner (A (I).Data);
end loop;
end;
end Array25_Pkg;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2017-2020, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision: 5720 $ $Date: 2017-01-24 19:41:12 +0300 (Tue, 24 Jan 2017) $
------------------------------------------------------------------------------
with Web.Strings;
package Web.UI.Widgets.Labels is
type Label is new Web.UI.Widgets.Abstract_Widget with private;
type Label_Access is access all Label'Class
with Storage_Size => 0;
procedure Set_Text
(Self : in out Label'Class;
To : Web.Strings.Web_String);
package Constructors is
function Create
(Element : Web.HTML.Elements.HTML_Element'Class)
return not null Label_Access;
function Create
(Id : Web.Strings.Web_String) return not null Label_Access;
procedure Initialize
(Self : in out Label'Class;
Element : Web.HTML.Elements.HTML_Element'Class);
end Constructors;
private
type Label is new Web.UI.Widgets.Abstract_Widget with null record;
overriding procedure Set_Disabled
(Self : in out Label;
Disabled : Boolean := True);
end Web.UI.Widgets.Labels;
|
-- Procedure tests Fourier8. Code fragments
-- demonstrate some features of FFT's.
with Fourier8;
with Text_IO; use Text_IO;
with Ada.Numerics.Generic_Elementary_Functions;
procedure fourier8_demo_1 is
type Real is digits 15;
package math is new Ada.Numerics.Generic_Elementary_Functions (Real);
use math;
package rio is new Float_IO(Real);
use rio;
package iio is new Integer_IO(Integer);
use iio;
Log_Of_Max_Data_Length : constant := 12;
-- NOTICE this means max data array size is 2**Log_Of_Max_Data_Length.
-- The larger you make this array, the slower program might run.
type Array_Index is range 0..2**(Log_Of_Max_Data_Length+1)-1;
type Data_Array is array(Array_Index) of Real;
package fft8 is new Fourier8
(Real, Array_Index, Data_Array, Log_Of_Max_Data_Length);
use fft8;
D_Re, D_Im : Data_Array;
Data_Set_Last : Data_Index;
Basis_Function_Last : Data_Index;
Transformed_Data_Last : Data_Index;
Theta, Frequency, Norm : Real;
Two_Pi_Over_N : Real;
Num, Mode : Integer;
Area1, Area2 : Real;
DeltaRE, DeltaIM : Real;
Dat_Re, Dat_Im : Real;
Exp_Table : Exp_Storage;
-- And put the following in calls to FFT:
-- Exp_Table => Exp_Table,
Max_Error, Del : Real;
Pii : constant Real := 3.14159_26535_89793_23846;
-----------
-- Pause --
-----------
procedure Pause (s1,s2,s3,s4,s5,s6,s7,s8,s9,s10 : string := "") is
Continue : Character := ' ';
begin
new_line(2);
if S1 /= "" then put_line (S1); end if;
if S2 /= "" then put_line (S2); end if;
if S3 /= "" then put_line (S3); end if;
if S4 /= "" then put_line (S4); end if;
if S5 /= "" then put_line (S5); end if;
if S6 /= "" then put_line (S6); end if;
if S7 /= "" then put_line (S7); end if;
if S8 /= "" then put_line (S8); end if;
if S9 /= "" then put_line (S9); end if;
if S10 /= "" then put_line (S10); end if;
dialog: loop
begin
new_line(1);
put ("Type a character to continue: ");
get_immediate (Continue);
exit dialog;
exception
when others => null;
end;
end loop dialog;
new_line(2);
end pause;
begin
new_line;
put ("Input number of data points to use in the following tests.");
new_line;
put ("The maximum allowed number is ");
put (Integer'Image(2**Log_Of_Max_Data_Length));
new_line;
put ("A good number to start with is 37");
new_line;
put ("Enter the desired number: ");
get (Num);
Data_Set_Last := Data_Index (Num - 1);
-- Get nearest power of 2.
declare
Pow : Integer := 0;
begin
for I in Integer range 0..Log_Of_Max_Data_Length loop
if 2**I >= Num then
Pow := I; exit;
end if;
end loop;
Basis_Function_Last := Data_Index (2**Pow - 1);
end;
new_line;
put ("You requested an FFT on the first ");
put (Integer'Image (Num));
put (" data points.");
new_line;
put ("The actual FFT will be performed on ");
put (Integer'Image (Integer (Basis_Function_Last)+1));
put (" data points.");
new_line;
put ("Data is set to 0 beyond the first ");
put (Integer'Image (Num));
put (" data points.");
new_line(2);
--*****************************************************************
-- Test 1.
-- Make a basis element of the set of Fourier basis states:
-- Its FFT should zero everywhere except for the element = Mode.
-- There, the value of the FFT should be (1.0, 0.0). Below
-- we normalize the basis element with the factor Norm = 1/Sqrt(N).
--*****************************************************************
Pause
("Test 1: take the FFT of the Fourier basis function:",
" ",
" Exp (i*T*Mode*2*Pi/N) / SQRT(N),", " ",
"where N is the number of points. The result of the FFT",
"should be a delta-function peaked at position Mode.");
put_line ("Input Mode (0, 1, 2, ...) of the basis function you wish to FFT: ");
Get (Mode);
Frequency := Real (Mode);
--*****************************************************************
Two_Pi_Over_N := 2.0 * Pii / (Real (Basis_Function_Last) + 1.0);
Norm := 1.0 / SQRT ((Real (Basis_Function_Last) + 1.0));
for I in 0..Basis_Function_Last loop
Theta := Two_Pi_Over_N * Frequency * Real (I);
D_Re(I) := Norm * Cos (Theta);
D_Im(I) := Norm * Sin (Theta);
end loop;
put_line ("Starting Test 1:");
new_line; put ("Basis function was constructed using "); put(Num);
put(" data points.");
FFT
(Data_Re => D_Re,
Data_Im => D_Im,
Transformed_Data_Last => Transformed_Data_Last,
Input_Data_Last => Basis_Function_Last,
Exp_Table => Exp_Table,
Inverse_FFT_Desired => False,
Normalized_Data_Desired => True);
Pause
("Ending FFT.",
"We have taken the FFT of Exp (i*T*Mode*2*Pi/N) / SQRT(N).",
"The result should be (0.0, 0.0) everywhere except for ",
"a (1.0, 0.0) at data point Mode.");
for I in Data_Index range 0..Basis_Function_Last loop
new_line; put (Integer(I)); put(' ');
put (D_Re(I)); put(' '); put(D_Im(I));
end loop;
--*****************************************************************
-- test 1b.
-- We 1st make a basis element of the set of Fourier basis states:
-- Its FFT should zero everywhere except for the element = Mode.
-- There, the value of the FFT should be (1.0, 0.0). Below
-- we normalize the basis element with the factor Norm = 1/Sqrt(N).
--*****************************************************************
Pause
("Test 1b: take the inverse FFT of the Fourier basis function:",
" ",
" Exp (-i*T*Mode*2*Pi/N) / SQRT(N),",
" ",
"where N is the number of points. The result of the FFT",
"should be a delta-function peaked at position Mode.");
put_line ("Input Mode (0, 1, 2, ...) of the basis function you wish to FFT: ");
Get (Mode);
Frequency := Real (Mode);
--*****************************************************************
Two_Pi_Over_N := 2.0 * Pii / (Real (Basis_Function_Last) + 1.0);
Norm := 1.0 / SQRT ((Real (Basis_Function_Last) + 1.0));
for I in 0..Basis_Function_Last loop
Theta := Two_Pi_Over_N * Frequency * Real (I);
D_Re(I) := Norm * Cos (Theta);
D_Im(I) := -Norm * Sin (Theta);
end loop;
put_line ("Starting Test 1b:");
new_Line; put ("Basis function was constructed using ");
put(Integer(Basis_Function_Last)+1);
put(" data points.");
new_line(2);
FFT
(Data_Re => D_Re,
Data_Im => D_Im,
Transformed_Data_Last => Transformed_Data_Last,
Input_Data_Last => Basis_Function_Last,
Exp_Table => Exp_Table,
Inverse_FFT_Desired => True,
Normalized_Data_Desired => True);
Pause
("Ending FFT.",
"We have taken the inverse FFT of Exp (-i*T*Mode*2*Pi/N) / SQRT(N).",
"The result should be (0.0, 0.0) everywhere except for ",
"a (1.0, 0.0) at data point Mode.");
for I in Data_Index range 0..Basis_Function_Last loop
new_line; put (Integer(I)); put(' ');
put (D_Re(I)); put(' '); put(D_Im(I));
end loop;
--*****************************************************************
-- Test2.
-- Verify Parceval's Theorem. The area under the FFT coefficients
-- should equal the area under the data. Notice that was true in the
-- above test, because Sum (|exp(i*T*Mode*2*Pi/N) / Sqrt(N)|**2) is
-- one on the interval [0,N-1].
-- First we create a new data set:
--*****************************************************************
for I in 0..Data_Set_Last loop
Theta := Real (I);
D_Re(I) := 1.0 / (Theta + 1.0);
D_Im(I) := Theta**2;
end loop;
Area1 := 0.0;
for I in 0..Data_Set_Last loop
Area1 := Area1 + D_Re(I)*D_Re(I) + D_Im(I)*D_Im(I);
end loop;
Pause
("Test 2: test of Parceval's theorem. The area under the",
"FFT curve (sum of coefficients modulus squared) should equal",
"area under the original curve. This requires the use of the",
"normalized version of the FFT.");
put_line ("Starting Test 2:");
FFT
(Data_Re => D_Re,
Data_Im => D_Im,
Transformed_Data_Last => Transformed_Data_Last, --output padded data length-1
Input_Data_Last => Data_Set_Last, --input desired data length-1
Exp_Table => Exp_Table,
Inverse_FFT_Desired => False,
Normalized_Data_Desired => True);
put_line ("Ending FFT");
Area2 := 0.0;
for I in 0..Transformed_Data_Last loop
Area2 := Area2 + D_Re(I)*D_Re(I) + D_Im(I)*D_Im(I);
end loop;
new_line; put ("Area under the original curve: "); put(Area1);
new_line; put ("Area under Fourier transformed curve: "); put(Area2);
-- Test3.
-- Inverse FFT of the FFT.
Pause
("Test 3: take the inverse FFT of the FFT of some",
"artificial data, and compare with the original data.",
"The test calculates: Data - Inverse_FFT (FFT (Data),",
"then prints the max error.");
for I in 0..Data_Set_Last loop
Theta := Real (I);
D_Re(I) := Sqrt (Theta) / (Theta + 1.0);
D_Im(I) := Cos (0.03737*Theta**2/(Theta + 1.0)) * Theta / (Theta + 1.0);
end loop;
put_line("Starting Test 3:");
FFT
(Data_Re => D_Re,
Data_Im => D_Im,
Transformed_Data_Last => Transformed_Data_Last,
Input_Data_Last => Data_Set_Last,
Exp_Table => Exp_Table,
Inverse_FFT_Desired => False,
Normalized_Data_Desired => True);
FFT
(Data_Re => D_Re,
Data_Im => D_Im,
Transformed_Data_Last => Transformed_Data_Last,
Input_Data_Last => Transformed_Data_Last,
Exp_Table => Exp_Table,
Inverse_FFT_Desired => True,
Normalized_Data_Desired => True);
Max_Error := 0.0;
for I in 0..Data_Set_Last loop
Theta := Real (I);
Dat_Re := Sqrt (Theta) / (Theta + 1.0);
Dat_Im := Cos (0.03737*Theta**2/(Theta + 1.0)) * Theta / (Theta + 1.0);
Del := Abs (Dat_Re - D_Re(I));
if Max_Error < Del then Max_Error := Del; end if;
Del := Abs (Dat_Im - D_Im(I));
if Max_Error < Del then Max_Error := Del; end if;
end loop;
new_line(2);
put ("Max error in Data - Inverse_FFT (FFT (Data)):"); put (Max_Error);
new_line;
Pause
("If the number of data points FFT'd was not a power",
"of 2 in length, then the data set was padded with zeros",
"out to the nearest power of 2. To see if these data",
"values were preserved by the two transformations, type",
"a character. Should get a number near 10.0**(-15):");
-- These points were padded with zero's in the FFT routine, prior
-- to being FFT'd. The application of the inverse FFT should
-- bring them back to zero again.
if Data_Set_Last < Data_Index'Last then
Max_Error := 0.0;
for I in Data_Set_Last+1 .. Transformed_Data_Last loop
Del := Abs (D_Re(I) - 0.0);
if Max_Error < Del then Max_Error := Del; end if;
Del := Abs (D_Im(I) - 0.0);
if Max_Error < Del then Max_Error := Del; end if;
end loop;
put ("Max error in [Data - Inverse_FFT (FFT (Data))]: "); put (Max_Error);
end if;
Pause
("Test 4 is a long test..runs through entire range of Array_Index ",
"to see if FFT_Inverse (FFT (Data)) = Data. Nothing is printed",
"unless large errors are detected. (Use 15 digit floating point.)",
"Interrupt the program here if you do not want a long wait.");
for N in Array_Index range 0..Basis_Function_Last loop
for I in Array_Index range 0..N loop
Theta := Real (I);
D_Re(I) := 1.0 / (Theta + 1.0);
D_Im(I) := Cos (0.03737 * Theta**2 / (Theta + 1.0));
end loop;
FFT
(Data_Re => D_Re,
Data_Im => D_Im,
Transformed_Data_Last => Transformed_Data_Last, --output padded data length-1
Input_Data_Last => N, --input desired data length-1
Exp_Table => Exp_Table,
Inverse_FFT_Desired => False,
Normalized_Data_Desired => True);
FFT
(Data_Re => D_Re,
Data_Im => D_Im,
Transformed_Data_Last => Transformed_Data_Last,
Input_Data_Last => Transformed_Data_Last,
Exp_Table => Exp_Table,
Inverse_FFT_Desired => True,
Normalized_Data_Desired => True);
for I in Array_Index range 0..N loop
Theta := Real (I);
Dat_Re := 1.0 / (Theta + 1.0);
Dat_Im := Cos (0.03737 * Theta**2 / (Theta + 1.0));
DeltaRE := Abs (Dat_Re - D_Re(I));
DeltaIM := Abs (Dat_Im - D_Im(I));
if DeltaRE > 1.0E-11 then
new_line;
put("FAILURE: "); put (DeltaRE); put(" at "); put(Real(I));
end if;
if DeltaIM > 1.0E-11 then
new_line;
put("FAILURE: "); put (DeltaIM); put(" at "); put(Real(I));
end if;
end loop;
end loop;
end;
|
-----------------------------------------------------------------------
-- awa-workspaces -- Module workspaces
-- Copyright (C) 2011, 2012, 2015, 2017 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
-- == Introduction ==
-- The *workspaces* plugin defines a workspace area for other plugins.
-- The workspace is intended to link together all the data objects that an application
-- manages for a given user or group of users. A workspace is a possible mechanism
-- to provide and implement multi-tenancy in a web application. By using the workspace plugin,
-- application data from different customers can be kept separate from each other in the
-- same database.
--
-- @include awa-workspaces-modules.ads
--
-- == Ada Beans ==
-- @include workspaces.xml
--
-- == Data Model ==
-- [images/awa_workspace_model.png]
--
package AWA.Workspaces is
end AWA.Workspaces;
|
package body COBS.Stream.Decoder is
subtype Dispatch is Instance'Class;
--------------
-- Do_Flush --
--------------
procedure Do_Flush (This : in out Instance) is
begin
if This.Out_Index > This.Buffer'First then
Dispatch (This).Flush
(This.Buffer (This.Buffer'First .. This.Out_Index - 1));
end if;
This.Out_Index := This.Buffer'First;
end Do_Flush;
----------
-- Push --
----------
procedure Push (This : in out Instance; Data : Storage_Element) is
begin
if This.Start_Of_Frame then
This.Code := Data;
This.Last_Code := This.Code;
This.Start_Of_Frame := False;
if This.Code = 0 then
raise Program_Error;
end if;
elsif This.Code > 1 then
This.Buffer (This.Out_Index) := Data;
This.Out_Index := This.Out_Index + 1;
This.Code := This.Code - 1;
else
if Data /= 0 and then This.Last_Code /= 16#FF# then
This.Buffer (This.Out_Index) := 0;
This.Out_Index := This.Out_Index + 1;
end if;
This.Code := Data;
This.Last_Code := This.Code;
This.Do_Flush;
if Data = 0 then
Dispatch (This).End_Of_Frame;
This.Start_Of_Frame := True;
end if;
end if;
end Push;
end COBS.Stream.Decoder;
|
------------------------------------------------------------------------------
-- --
-- Ada User Repository Annex (AURA) --
-- Reference Implementation --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2020, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * Richard Wai (ANNEXI-STRAYLINE) --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- --
-- * Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A --
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
package body Stream_Hashing.Collective is
-----------------------------
-- Compute_Collective_Hash --
-----------------------------
procedure Compute_Collective_Hash
(Collection : in Hash_Collections.Set;
Collective_Hash: out Hash_Type)
is
Engine: aliased Modular_Hashing.SHA1.SHA1_Engine;
begin
for H of Collection loop
Hash_Type'Write (Engine'Access, H);
end loop;
Collective_Hash
:= Hash_Type'(Modular_Hashing.SHA1.SHA1_Hash(Engine.Digest)
with null record);
end Compute_Collective_Hash;
--------------------------------------------------
procedure Compute_Collective_Hash
(Hash_Queue : in out Hash_Queues.Queue;
Collective_Hash: out Hash_Type)
is
Collection: Hash_Collections.Set;
New_Hash: Hash_Type;
begin
loop
select
Hash_Queue.Dequeue (New_Hash);
else
exit;
end select;
Collection.Include (New_Hash);
end loop;
Compute_Collective_Hash (Collection, Collective_Hash);
end Compute_Collective_Hash;
end Stream_Hashing.Collective;
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . S P A N _ B E G I N N I N G --
-- --
-- S p e c --
-- --
-- Copyright (C) 1995-2012, Free Software Foundation, Inc. --
-- --
-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIS-for-GNAT is distributed in the hope that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with ASIS-for-GNAT; see file --
-- COPYING. If not, write to the Free Software Foundation, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Asis;
with A4G.Int_Knds; use A4G.Int_Knds;
with Types; use Types;
package A4G.Span_Beginning is
function Set_Image_Beginning (E : Asis.Element) return Source_Ptr;
-- The driver function for computing the beginning of the element image
-- in the GNAT source text buffer. In case if the argument is a labeled
-- statement returns the baginning of the first attachecd label. Otherwise
-- calls the element-kind-specific function for computing the image
-- beginning
-- The functions below compute the beginning of the text image for some
-- specific set of ELement kinds/
function Subunit_Beginning (E : Asis.Element) return Source_Ptr;
function Private_Unit_Beginning (E : Asis.Element) return Source_Ptr;
-- Assuming that E is an element representing the top Unit element of a
-- subunit or of a library item representing a private unit, returns the
-- source pointer to the beginning of the keyword SEPARATE or PRIVATE
-- accordingly.
function No_Search (E : Asis.Element) return Source_Ptr;
-- That is, we can just use Sloc from the node the Element is based upon.
function Search_Identifier_Beginning
(E : Asis.Element)
return Source_Ptr;
-- A special processing is needed for an identifier representing the
-- attribute designator in pseudo-attribute-reference in an attribute
-- definition clause and for 'Class attribute in aspect indication
function Search_Subtype_Indication_Beginning
(E : Asis.Element)
return Source_Ptr;
-- If the subtype mark is an expanded name, we have to look for its prefix
function Defining_Identifier_Beginning
(E : Asis.Element)
return Source_Ptr;
-- Returns the beginning of A_Defining_Identifier elements. In case of
-- labels we have to get rid of '<<'
function Short_Circuit_Beginning (E : Asis.Element) return Source_Ptr;
-- Returns the beginning of short circuit expression
function Membership_Test_Beginning (E : Asis.Element) return Source_Ptr;
-- Returns the beginning of membership test expression
function Null_Component_Beginning (E : Asis.Element) return Source_Ptr;
-- In case of A_Nil_Component element Sloc of its Node points to
-- "record" (it's easy) or to variant (it's a pain)
function Search_Prefix_Beginning (E : Asis.Element) return Source_Ptr;
-- Is needed when the Argument has a "prefix" in its structure, but Sloc
-- points somewhere inside the elemen structure
-- --|A2005 start
function Possible_Null_Exclusion_Beginning
(E : Asis.Element)
return Source_Ptr;
-- Should be used for constructs that can contain null_exclusion
function Possible_Overriding_Indicator_Beginning
(E : Asis.Element)
return Source_Ptr;
-- Is supposed to be used for some of the constructs that can contain
-- overriding_indicator
-- --|A2005 end
function Component_And_Parameter_Declaration_Beginning
(E : Asis.Element)
return Source_Ptr;
function Exception_Declaration_Beginning
(E : Asis.Element)
return Source_Ptr;
function Derived_Definition_Beginning (E : Asis.Element) return Source_Ptr;
function Type_Definition_Beginning (E : Asis.Element) return Source_Ptr;
function Interface_Definition_Beginning
(E : Asis.Element)
return Source_Ptr;
function Tagged_Type_Definition_Beginning
(E : Asis.Element)
return Source_Ptr;
function Simple_Expression_Range_Beginning
(E : Asis.Element)
return Source_Ptr;
function Component_Definition_Beginning
(E : Asis.Element)
return Source_Ptr;
function Search_Left_Parenthesis_After (E : Asis.Element) return Source_Ptr;
-- Is needed when the Element does not have its "own" node (in particular,
-- for A_Known_Discriminant_Part Element)
function Private_Extension_Definition_Beginning
(E : Asis.Element)
return Source_Ptr;
function Private_Type_Definition_Beginning
(E : Asis.Element)
return Source_Ptr;
function Explicit_Dereference_Beginning
(E : Asis.Element)
return Source_Ptr;
function Function_Call_Beginning (E : Asis.Element) return Source_Ptr;
function Indexed_Component_Beginning (E : Asis.Element) return Source_Ptr;
function Component_Association_Beginning
(E : Asis.Element)
return Source_Ptr;
function Association_Beginning
(E : Asis.Element)
return Source_Ptr;
function Parenthesized_Expression_Beginning
(E : Asis.Element)
return Source_Ptr;
function Assignment_Statement_Beginning
(E : Asis.Element)
return Source_Ptr;
function Named_Statement_Beginning
(E : Asis.Element)
return Source_Ptr;
-- Takes care of loop and block names
function Call_Statement_Beginning (E : Asis.Element) return Source_Ptr;
function While_Loop_Statement_Beginning
(E : Asis.Element)
return Source_Ptr;
function For_Loop_Statement_Beginning (E : Asis.Element) return Source_Ptr;
function Else_Path_Beginning (E : Asis.Element) return Source_Ptr;
function With_Clause_Beginning (E : Asis.Element) return Source_Ptr;
function Component_Clause_Beginning (E : Asis.Element) return Source_Ptr;
function Subprogram_Spec_Beginning (E : Asis.Element) return Source_Ptr;
function Formal_Object_Declaration_Beginning
(E : Asis.Element)
return Source_Ptr;
function A_Then_Abort_Path_Beginning (E : Asis.Element) return Source_Ptr;
function Select_Alternative_Beginning (E : Asis.Element) return Source_Ptr;
-- --|A2015 start
function Case_Expression_Path_Beginning
(E : Asis.Element)
return Source_Ptr;
function If_Expression_Beginning
(E : Asis.Element)
return Source_Ptr;
function Conditional_Expression_Path_Beginning
(E : Asis.Element)
return Source_Ptr;
function An_Else_Expression_Path_Beginning
(E : Asis.Element)
return Source_Ptr;
-- --|A2015 end
-- The look-up table below defines the mapping from Element kinds onto
-- specific routines for computing the Element image beginning
type Set_Source_Location_type is
access function (E : Asis.Element) return Source_Ptr;
Switch : array (Internal_Element_Kinds) of Set_Source_Location_type := (
An_All_Calls_Remote_Pragma ..
-- An_Asynchronous_Pragma
-- An_Atomic_Pragma
-- An_Atomic_Components_Pragma
-- An_Attach_Handler_Pragma
-- A_Controlled_Pragma
-- A_Convention_Pragma
-- An_Elaborate_All_Pragma
-- An_Elaborate_Body_Pragma
-- An_Export_Pragma
-- An_Import_Pragma
-- An_Inline_Pragma
-- An_Inspection_Point_Pragma
-- An_Interrupt_Handler_Pragma
-- An_Interrupt_Priority_Pragma
-- A_List_Pragma
-- A_Locking_Policy_Pragma
-- A_Normalize_Scalars_Pragma
-- An_Optimize_Pragma
-- A_Pack_Pragma
-- A_Page_Pragma
-- A_Preelaborate_Pragma
-- A_Priority_Pragma
-- A_Pure_Pragma
-- A_Queuing_Policy_Pragma
-- A_Remote_Call_Interface_Pragma
-- A_Remote_Types_Pragma
-- A_Restrictions_Pragma
-- A_Reviewable_Pragma
-- A_Shared_Passive_Pragma
-- A_Suppress_Pragma
-- A_Task_Dispatching_Policy_Pragma
-- A_Volatile_Pragma
-- A_Volatile_Components_Pragma
-- An_Implementation_Defined_Pragma
An_Unknown_Pragma => No_Search'Access,
A_Defining_Identifier => Defining_Identifier_Beginning'Access,
A_Defining_Character_Literal ..
-- A_Defining_Enumeration_Literal
-- A_Defining_Or_Operator
-- A_Defining_Xor_Operator
-- A_Defining_Equal_Operator
-- A_Defining_Not_Equal_Operator
-- A_Defining_Less_Than_Operator
-- A_Defining_Less_Than_Or_Equal_Operator
-- A_Defining_Greater_Than_Operator
-- A_Defining_Greater_Than_Or_Equal_Operator
-- A_Defining_Plus_Operator
-- A_Defining_Minus_Operator
-- A_Defining_Concatenate_Operator
-- A_Defining_Unary_Plus_Operator
-- A_Defining_Unary_Minus_Operator
-- A_Defining_Multiply_Operator
-- A_Defining_Divide_Operator
-- A_Defining_Mod_Operator
-- A_Defining_Rem_Operator
-- A_Defining_Exponentiate_Operator
-- A_Defining_Abs_Operator
A_Defining_Not_Operator => No_Search'Access,
A_Defining_Expanded_Name => Search_Prefix_Beginning'Access,
An_Ordinary_Type_Declaration ..
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- An_Incomplete_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
-- A_Subtype_Declaration
-- A_Variable_Declaration
-- A_Constant_Declaration
-- A_Deferred_Constant_Declaration
-- A_Single_Task_Declaration
-- A_Single_Protected_Declaration
-- An_Integer_Number_Decl
-- A_Real_Number_Declaration
-- An_Enumeration_Literal_Specification
A_Discriminant_Specification => No_Search'Access,
A_Component_Declaration =>
Component_And_Parameter_Declaration_Beginning'Access,
A_Loop_Parameter_Specification => No_Search'Access,
-- --|A2012 start
A_Generalized_Iterator_Specification => No_Search'Access, -- ???
An_Element_Iterator_Specification => No_Search'Access, -- ???
-- --|A2012 end
A_Procedure_Declaration ..
A_Function_Declaration => Subprogram_Spec_Beginning'Access,
-- --|A2005 start
A_Null_Procedure_Declaration => Subprogram_Spec_Beginning'Access,
-- --|A2005 end
-- --|A2012 start
An_Expression_Function_Declaration => Subprogram_Spec_Beginning'Access,
-- --|A2012 end
A_Parameter_Specification =>
Component_And_Parameter_Declaration_Beginning'Access,
A_Procedure_Body_Declaration ..
A_Function_Body_Declaration => Subprogram_Spec_Beginning'Access,
A_Package_Declaration ..
-- A_Package_Body_Declaration
-- An_Object_Renaming_Declaration
-- An_Exception_Renaming_Declaration
A_Package_Renaming_Declaration => No_Search'Access,
A_Procedure_Renaming_Declaration => Subprogram_Spec_Beginning'Access,
A_Function_Renaming_Declaration => Subprogram_Spec_Beginning'Access,
A_Generic_Package_Renaming_Declaration ..
-- A_Generic_Procedure_Renaming_Declaration
-- A_Generic_Function_Renaming_Declaration
-- A_Task_Body_Declaration
A_Protected_Body_Declaration => No_Search'Access,
An_Entry_Declaration => Possible_Overriding_Indicator_Beginning'Access,
An_Entry_Body_Declaration ..
An_Entry_Index_Specification => No_Search'Access,
A_Procedure_Body_Stub ..
A_Function_Body_Stub => Subprogram_Spec_Beginning'Access,
A_Package_Body_Stub ..
-- A_Task_Body_Stub
A_Protected_Body_Stub => No_Search'Access,
An_Exception_Declaration =>
Exception_Declaration_Beginning'Access,
A_Choice_Parameter_Specification ..
-- A_Generic_Procedure_Declaration
-- A_Generic_Function_Declaration
-- A_Generic_Package_Declaration
A_Package_Instantiation => No_Search'Access,
A_Procedure_Instantiation ..
A_Function_Instantiation =>
Possible_Overriding_Indicator_Beginning'Access,
A_Formal_Object_Declaration =>
Formal_Object_Declaration_Beginning'Access,
A_Formal_Type_Declaration ..
-- A_Formal_Procedure_Declaration
-- A_Formal_Function_Declaration
-- A_Formal_Package_Declaration
A_Formal_Package_Declaration_With_Box => No_Search'Access,
A_Derived_Type_Definition => Derived_Definition_Beginning'Access,
A_Derived_Record_Extension_Definition =>
Derived_Definition_Beginning'Access,
An_Enumeration_Type_Definition ..
-- A_Signed_Integer_Type_Definition
-- A_Modular_Type_Definition
---------------------------------------------------------
-- !!! They all are implicit and cannot have image
-- |
-- |-> A_Root_Integer_Definition
-- |-> A_Root_Real_Definition
-- |-> A_Root_Fixed_Definition
-- |-> A_Universal_Integer_Definition
-- |-> A_Universal_Real_Definition
-- +-> A_Universal_Fixed_Definition
---------------------------------------------------------
-- A_Floating_Point_Definition
-- An_Ordinary_Fixed_Point_Definition
-- A_Decimal_Fixed_Point_Definition
-- An_Unconstrained_Array_Definition
A_Constrained_Array_Definition => No_Search'Access,
A_Record_Type_Definition => Type_Definition_Beginning'Access,
A_Tagged_Record_Type_Definition =>
Tagged_Type_Definition_Beginning'Access,
-- --|A2005 start
An_Ordinary_Interface ..
-- A_Limited_Interface,
-- A_Task_Interface,
-- A_Protected_Interface,
A_Synchronized_Interface => Interface_Definition_Beginning'Access,
-- --|A2005 end
A_Pool_Specific_Access_To_Variable ..
-- An_Access_To_Variable
-- An_Access_To_Constant
-- An_Access_To_Procedure
-- An_Access_To_Protected_Procedure
-- An_Access_To_Function
An_Access_To_Protected_Function => No_Search'Access,
A_Subtype_Indication => Search_Subtype_Indication_Beginning'Access,
A_Range_Attribute_Reference => Search_Prefix_Beginning'Access,
A_Simple_Expression_Range => Simple_Expression_Range_Beginning'Access,
A_Digits_Constraint ..
-- A_Delta_Constraint
-- An_Index_Constraint
A_Discriminant_Constraint => No_Search'Access,
A_Component_Definition => Component_Definition_Beginning'Access,
A_Discrete_Subtype_Indication_As_Subtype_Definition =>
Search_Subtype_Indication_Beginning'Access,
A_Discrete_Range_Attribute_Reference_As_Subtype_Definition =>
Search_Prefix_Beginning'Access,
A_Discrete_Simple_Expression_Range_As_Subtype_Definition =>
Simple_Expression_Range_Beginning'Access,
A_Discrete_Subtype_Indication =>
Search_Subtype_Indication_Beginning'Access,
A_Discrete_Range_Attribute_Reference => Search_Prefix_Beginning'Access,
A_Discrete_Simple_Expression_Range =>
Simple_Expression_Range_Beginning'Access,
An_Unknown_Discriminant_Part ..
A_Known_Discriminant_Part => Search_Left_Parenthesis_After'Access,
A_Record_Definition ..
A_Null_Record_Definition => No_Search'Access,
A_Null_Component => Null_Component_Beginning'Access,
A_Variant_Part ..
-- A_Variant
An_Others_Choice => No_Search'Access,
-- --|A2005 start
An_Anonymous_Access_To_Variable ..
-- An_Anonymous_Access_To_Constant,
-- An_Anonymous_Access_To_Procedure,
-- An_Anonymous_Access_To_Protected_Procedure,
-- An_Anonymous_Access_To_Function,
An_Anonymous_Access_To_Protected_Function =>
Possible_Null_Exclusion_Beginning'Access,
-- --|A2005 end
A_Private_Type_Definition => Private_Type_Definition_Beginning'Access,
A_Tagged_Private_Type_Definition =>
Private_Type_Definition_Beginning'Access,
A_Private_Extension_Definition =>
Private_Extension_Definition_Beginning'Access,
A_Task_Definition => No_Search'Access,
A_Protected_Definition => No_Search'Access,
A_Formal_Private_Type_Definition =>
Private_Type_Definition_Beginning'Access,
A_Formal_Tagged_Private_Type_Definition =>
Private_Type_Definition_Beginning'Access,
A_Formal_Derived_Type_Definition => Derived_Definition_Beginning'Access,
A_Formal_Discrete_Type_Definition => No_Search'Access,
A_Formal_Signed_Integer_Type_Definition ..
-- A_Formal_Modular_Type_Definition
-- A_Formal_Floating_Point_Definition
-- A_Formal_Ordinary_Fixed_Point_Definition
A_Formal_Decimal_Fixed_Point_Definition => No_Search'Access,
A_Formal_Ordinary_Interface ..
-- A_Formal_Limited_Interface
-- A_Formal_Task_Interface
-- A_Formal_Protected_Interface
A_Formal_Synchronized_Interface => Interface_Definition_Beginning'Access,
A_Formal_Unconstrained_Array_Definition ..
-- A_Formal_Constrained_Array_Definition
-- A_Formal_Pool_Specific_Access_To_Variable
-- A_Formal_Access_To_Variable
-- A_Formal_Access_To_Constant
-- A_Formal_Access_To_Procedure
-- A_Formal_Access_To_Protected_Procedure
-- A_Formal_Access_To_Function
A_Formal_Access_To_Protected_Function => No_Search'Access,
An_Aspect_Specification => No_Search'Access,
An_Integer_Literal ..
-- A_Real_Literal
A_String_Literal => No_Search'Access,
An_Identifier => Search_Identifier_Beginning'Access,
An_And_Operator ..
-- An_Or_Operator
-- An_Xor_Operator
-- An_Equal_Operator
-- A_Not_Equal_Operator
-- A_Less_Than_Operator
-- A_Less_Than_Or_Equal_Operator
-- A_Greater_Than_Operator
-- A_Greater_Than_Or_Equal_Operator
-- A_Plus_Operator
-- A_Minus_Operator
-- A_Concatenate_Operator
-- A_Unary_Plus_Operator
-- A_Unary_Minus_Operator
-- A_Multiply_Operator
-- A_Divide_Operator
-- A_Mod_Operator
-- A_Rem_Operator
-- An_Exponentiate_Operator
-- An_Abs_Operator
-- A_Not_Operator
-- A_Character_Literal
An_Enumeration_Literal => No_Search'Access,
An_Explicit_Dereference => Explicit_Dereference_Beginning'Access,
A_Function_Call => Function_Call_Beginning'Access,
An_Indexed_Component => Indexed_Component_Beginning'Access,
A_Slice => Indexed_Component_Beginning'Access,
A_Selected_Component ..
-- An_Access_Attribute
-- An_Address_Attribute
-- An_Adjacent_Attribute
-- An_Aft_Attribute
-- An_Alignment_Attribute
-- A_Base_Attribute
-- A_Bit_Order_Attribute
-- A_Body_Version_Attribute
-- A_Callable_Attribute
-- A_Caller_Attribute
-- A_Ceiling_Attribute
-- A_Class_Attribute
-- A_Component_Size_Attribute
-- A_Compose_Attribute
-- A_Constrained_Attribute
-- A_Copy_Sign_Attribute
-- A_Count_Attribute
-- A_Definite_Attribute
-- A_Delta_Attribute
-- A_Denorm_Attribute
-- A_Digits_Attribute
-- An_Exponent_Attribute
-- An_External_Tag_Attribute
-- A_First_Attribute
-- A_First_Bit_Attribute
-- A_Floor_Attribute
-- A_Fore_Attribute
-- A_Fraction_Attribute
-- An_Identity_Attribute
-- An_Image_Attribute
-- An_Input_Attribute
-- A_Last_Attribute
-- A_Last_Bit_Attribute
-- A_Leading_Part_Attribute
-- A_Length_Attribute
-- A_Machine_Attribute
-- A_Machine_Emax_Attribute
-- A_Machine_Emin_Attribute
-- A_Machine_Mantissa_Attribute
-- A_Machine_Overflows_Attribute
-- A_Machine_Radix_Attribute
-- A_Machine_Rounds_Attribute
-- A_Max_Attribute
-- A_Max_Size_In_Storage_Elements_Attribute
-- A_Min_Attribute
-- A_Model_Attribute
-- A_Model_Emin_Attribute
-- A_Model_Epsilon_Attribute
-- A_Model_Mantissa_Attribute
-- A_Model_Small_Attribute
-- A_Modulus_Attribute
-- An_Output_Attribute
-- A_Partition_ID_Attribute
-- A_Pos_Attribute
-- A_Position_Attribute
-- A_Pred_Attribute
-- A_Range_Attribute
-- A_Read_Attribute
-- A_Remainder_Attribute
-- A_Round_Attribute
-- A_Rounding_Attribute
-- A_Safe_First_Attribute
-- A_Safe_Last_Attribute
-- A_Scale_Attribute
-- A_Scaling_Attribute
-- A_Signed_Zeros_Attribute
-- A_Size_Attribute
-- A_Small_Attribute
-- A_Storage_Pool_Attribute
-- A_Storage_Size_Attribute
-- A_Succ_Attribute
-- A_Tag_Attribute
-- A_Terminated_Attribute
-- A_Truncation_Attribute
-- An_Unbiased_Rounding_Attribute
-- An_Unchecked_Access_Attribute
-- A_Val_Attribute
-- A_Valid_Attribute
-- A_Value_Attribute
-- A_Version_Attribute
-- A_Wide_Image_Attribute
-- A_Wide_Value_Attribute
-- A_Wide_Width_Attribute
-- A_Width_Attribute
-- A_Write_Attribute
-- An_Implementation_Defined_Attribute
An_Unknown_Attribute => Search_Prefix_Beginning'Access,
A_Record_Aggregate ..
-- An_Extension_Aggregate
-- An_Positional_Array_Aggregate
A_Named_Array_Aggregate => No_Search'Access,
An_And_Then_Short_Circuit ..
An_Or_Else_Short_Circuit => Short_Circuit_Beginning'Access,
An_In_Membership_Test ..
A_Not_In_Membership_Test => Membership_Test_Beginning'Access,
A_Null_Literal => No_Search'Access,
A_Parenthesized_Expression =>
Parenthesized_Expression_Beginning'Access,
A_Type_Conversion => Search_Prefix_Beginning'Access,
A_Qualified_Expression => Search_Prefix_Beginning'Access,
An_Allocation_From_Subtype => No_Search'Access,
An_Allocation_From_Qualified_Expression => No_Search'Access,
-- --|A2012 start
A_Case_Expression => No_Search'Access,
An_If_Expression => If_Expression_Beginning'Access,
-- --|A2012 end
A_Pragma_Argument_Association => Association_Beginning'Access,
A_Discriminant_Association => Association_Beginning'Access,
A_Record_Component_Association => Component_Association_Beginning'Access,
An_Array_Component_Association => Component_Association_Beginning'Access,
A_Parameter_Association => Association_Beginning'Access,
A_Generic_Association => No_Search'Access,
A_Null_Statement => No_Search'Access,
An_Assignment_Statement => Assignment_Statement_Beginning'Access,
An_If_Statement => No_Search'Access,
A_Case_Statement => No_Search'Access,
A_Loop_Statement => Named_Statement_Beginning'Access,
A_While_Loop_Statement => While_Loop_Statement_Beginning'Access,
A_For_Loop_Statement => For_Loop_Statement_Beginning'Access,
A_Block_Statement => Named_Statement_Beginning'Access,
An_Exit_Statement => No_Search'Access,
A_Goto_Statement => No_Search'Access,
A_Procedure_Call_Statement => Call_Statement_Beginning'Access,
A_Return_Statement => No_Search'Access,
An_Accept_Statement => No_Search'Access,
An_Entry_Call_Statement => Call_Statement_Beginning'Access,
A_Requeue_Statement ..
-- A_Requeue_Statement_With_Abort
-- A_Delay_Until_Statement
-- A_Delay_Relative_Statement
-- A_Terminate_Alternative_Statement
-- A_Selective_Accept_Statement
-- A_Timed_Entry_Call_Statement
-- A_Conditional_Entry_Call_Statement
-- An_Asynchronous_Select_Statement
-- An_Abort_Statement
-- A_Raise_Statement
-- A_Code_Statement
-- An_If_Path
-- NOTE: There is no explicit node in GNAT AST tree corresponding to
-- this Internal_Element_Kind's. It's supposed that corresponding
-- Element's record field contains Source_Ptr type value that points to
-- word IF.
-- If it isn't so, we should change this part.
-- I believe it's more correct to have A_Then_Path in spite of
-- An_If_Path which should point to the word THEN.
An_Elsif_Path => No_Search'Access,
An_Else_Path => Else_Path_Beginning'Access,
A_Case_Path => No_Search'Access,
A_Select_Path ..
-- NOTE: There is no explicit node in GNAT AST tree corresponding to
-- this Internal_Element_Kind's. It's supposed that corresponding
-- Element's record field contains Source_Ptr type value that
-- points to word SELECT.
-- If it isn't so, we should change this part.
An_Or_Path => Select_Alternative_Beginning'Access,
-- NOTE: There is no explicit node in GNAT AST tree corresponding to
-- this Internal_Element_Kind's. It's supposed that corresponding
-- Element's record field contains Source_Ptr type value that points to
-- word OR. If it isn't so, we should change this part.
A_Then_Abort_Path => A_Then_Abort_Path_Beginning'Access,
-- --|A2015 start
A_Case_Expression_Path => Case_Expression_Path_Beginning'Access,
An_If_Expression_Path ..
An_Elsif_Expression_Path => Conditional_Expression_Path_Beginning'Access,
An_Else_Expression_Path => An_Else_Expression_Path_Beginning'Access,
-- --|A2015 end
A_Use_Package_Clause ..
-- A_Use_Type_Clause
A_Use_All_Type_Clause => No_Search'Access, -- Ada 2012
A_With_Clause => With_Clause_Beginning'Access,
An_Attribute_Definition_Clause ..
-- An_Enumeration_Representation_Clause
-- A_Record_Representation_Clause
An_At_Clause => No_Search'Access,
A_Component_Clause => Component_Clause_Beginning'Access,
An_Exception_Handler => No_Search'Access,
others => No_Search'Access);
end A4G.Span_Beginning;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . W C H _ W T S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System.WCh_Con; use System.WCh_Con;
with System.WCh_Cnv; use System.WCh_Cnv;
package body System.WCh_WtS is
-----------------------
-- Local Subprograms --
-----------------------
procedure Store_UTF_32_Character
(U : UTF_32_Code;
S : out String;
P : in out Integer;
EM : WC_Encoding_Method);
-- Stores the string representation of the wide or wide wide character
-- whose code is given as U, starting at S (P + 1). P is incremented to
-- point to the last character stored. Raises CE if character cannot be
-- stored using the given encoding method.
----------------------------
-- Store_UTF_32_Character --
----------------------------
procedure Store_UTF_32_Character
(U : UTF_32_Code;
S : out String;
P : in out Integer;
EM : WC_Encoding_Method)
is
procedure Out_Char (C : Character);
pragma Inline (Out_Char);
-- Procedure to increment P and store C at S (P)
procedure Store_Chars is new UTF_32_To_Char_Sequence (Out_Char);
--------------
-- Out_Char --
--------------
procedure Out_Char (C : Character) is
begin
P := P + 1;
S (P) := C;
end Out_Char;
begin
Store_Chars (U, EM);
end Store_UTF_32_Character;
---------------------------
-- Wide_String_To_String --
---------------------------
function Wide_String_To_String
(S : Wide_String;
EM : WC_Encoding_Method) return String
is
Max_Chars : constant Natural := WC_Longest_Sequences (EM);
Result : String (S'First .. S'First + Max_Chars * S'Length);
Result_Idx : Natural;
begin
Result_Idx := Result'First - 1;
for S_Idx in S'Range loop
Store_UTF_32_Character
(U => Wide_Character'Pos (S (S_Idx)),
S => Result,
P => Result_Idx,
EM => EM);
end loop;
return Result (Result'First .. Result_Idx);
end Wide_String_To_String;
--------------------------------
-- Wide_Wide_String_To_String --
--------------------------------
function Wide_Wide_String_To_String
(S : Wide_Wide_String;
EM : WC_Encoding_Method) return String
is
Max_Chars : constant Natural := WC_Longest_Sequences (EM);
Result : String (S'First .. S'First + Max_Chars * S'Length);
Result_Idx : Natural;
begin
Result_Idx := Result'First - 1;
for S_Idx in S'Range loop
Store_UTF_32_Character
(U => Wide_Wide_Character'Pos (S (S_Idx)),
S => Result,
P => Result_Idx,
EM => EM);
end loop;
return Result (Result'First .. Result_Idx);
end Wide_Wide_String_To_String;
end System.WCh_WtS;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- I N T E R F A C E S . A A R C H 6 4 --
-- --
-- S p e c --
-- --
-- Copyright (C) 2017, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
------------------------------------------------------------------------------
with System; use System;
with System.Machine_Code; use System.Machine_Code;
with Interfaces; use Interfaces;
package body Interfaces.AArch64 is
-------------------
-- Get_CPACR_EL1 --
-------------------
function Get_CPACR_EL1 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, cpacr_el1",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_CPACR_EL1;
-------------------
-- Set_CPACR_EL1 --
-------------------
procedure Set_CPACR_EL1 (Val : Unsigned_64) is
begin
Asm ("msr cpacr_el1, %0",
Inputs => Unsigned_64'Asm_Input ("r", Val),
Volatile => True);
end Set_CPACR_EL1;
------------------
-- Get_CPTR_EL2 --
------------------
function Get_CPTR_EL2 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, cptr_el2",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_CPTR_EL2;
------------------
-- Set_CPTR_EL2 --
------------------
procedure Set_CPTR_EL2 (Val : Unsigned_64) is
begin
Asm ("msr cptr_el2, %0",
Inputs => Unsigned_64'Asm_Input ("r", Val),
Volatile => True);
end Set_CPTR_EL2;
----------------------
-- Set_CNTP_CTL_EL0 --
----------------------
procedure Set_CNTP_CTL_EL0 (Val : Unsigned_32) is
begin
Asm ("msr cntp_ctl_el0, %0",
Inputs => Unsigned_32'Asm_Input ("r", Val),
Volatile => True);
end Set_CNTP_CTL_EL0;
----------------------
-- Set_CNTP_CTL_EL2 --
----------------------
procedure Set_CNTHP_CTL_EL2 (Val : Unsigned_32) is
begin
Asm ("msr cnthp_ctl_el2, %0",
Inputs => Unsigned_32'Asm_Input ("r", Val),
Volatile => True);
end Set_CNTHP_CTL_EL2;
----------------------
-- Set_CNTV_CTL_EL0 --
----------------------
procedure Set_CNTV_CTL_EL0 (Val : Unsigned_32) is
begin
Asm ("msr cntv_ctl_el0, %0",
Inputs => Unsigned_32'Asm_Input ("r", Val),
Volatile => True);
end Set_CNTV_CTL_EL0;
-----------------------
-- Set_CNTV_TVAL_EL0 --
-----------------------
procedure Set_CNTP_TVAL_EL0 (Val : Unsigned_32) is
begin
Asm ("msr cntp_tval_el0, %0",
Inputs => Unsigned_32'Asm_Input ("r", Val),
Volatile => True);
end Set_CNTP_TVAL_EL0;
-----------------------
-- Set_CNTV_TVAL_EL2 --
-----------------------
procedure Set_CNTHP_TVAL_EL2 (Val : Unsigned_32) is
begin
Asm ("msr cnthp_tval_el2, %0",
Inputs => Unsigned_32'Asm_Input ("r", Val),
Volatile => True);
end Set_CNTHP_TVAL_EL2;
-----------------------
-- Set_CNTP_CVAL_EL0 --
-----------------------
procedure Set_CNTP_CVAL_EL0 (Val : Unsigned_64) is
begin
Asm ("msr cntp_cval_el0, %0",
Inputs => Unsigned_64'Asm_Input ("r", Val),
Volatile => True);
end Set_CNTP_CVAL_EL0;
-----------------------
-- Set_CNTHP_CVAL_EL2 --
-----------------------
procedure Set_CNTHP_CVAL_EL2 (Val : Unsigned_64) is
begin
Asm ("msr cnthp_cval_el2, %0",
Inputs => Unsigned_64'Asm_Input ("r", Val),
Volatile => True);
end Set_CNTHP_CVAL_EL2;
--------------------
-- Get_CNTPCT_EL0 --
--------------------
function Get_CNTPCT_EL0 return Unsigned_64 is
Res : Unsigned_64;
begin
-- Read CNTPCT
Asm ("mrs %0, cntpct_el0",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_CNTPCT_EL0;
-------------
-- DC_CVAU --
-------------
procedure DC_CVAU (Addr : Address) is
begin
Asm ("dc cvau, %0",
Inputs => Address'Asm_Input ("r", Addr),
Volatile => True);
end DC_CVAU;
-------------
-- DC_CVAC --
-------------
procedure DC_CVAC (Addr : Address) is
begin
Asm ("dc cvac, %0",
Inputs => Address'Asm_Input ("r", Addr),
Volatile => True);
end DC_CVAC;
-------------
-- IC_IVAU --
-------------
procedure IC_IVAU (Addr : Address) is
begin
Asm ("ic ivau, %0",
Inputs => Address'Asm_Input ("r", Addr),
Volatile => True);
end IC_IVAU;
-------------
-- DSB_ISH --
-------------
procedure DSB_ISH is
begin
Asm ("dsb ish", Volatile => True);
end DSB_ISH;
---------
-- ISB --
---------
procedure ISB is
begin
Asm ("isb", Volatile => True);
end ISB;
---------------------
-- TLBI_VMALLS12E1 --
---------------------
procedure TLBI_VMALLS12E1 is
begin
Asm ("tlbi vmalls12e1", Volatile => True);
end TLBI_VMALLS12E1;
--------------------
-- Get_Current_EL --
--------------------
function Get_Current_EL return Unsigned_32
is
Res : Unsigned_32;
begin
Asm ("mrs %0, currentel",
Outputs => Unsigned_32'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_Current_EL;
-----------------
-- Get_ELR_EL3 --
-----------------
function Get_ELR_EL3 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, elr_el3",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_ELR_EL3;
-----------------
-- Set_ELR_EL3 --
-----------------
procedure Set_ELR_EL3 (V : Unsigned_64) is
begin
Asm ("msr elr_el3, %0",
Inputs => Unsigned_64'Asm_Input ("r", V),
Volatile => True);
end Set_ELR_EL3;
------------------
-- Get_SPSR_EL3 --
------------------
function Get_SPSR_EL3 return Unsigned_32
is
Res : Unsigned_32;
begin
Asm ("mrs %0, spsr_el3",
Outputs => Unsigned_32'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_SPSR_EL3;
-----------------
-- Get_ESR_EL3 --
-----------------
function Get_ESR_EL3 return Unsigned_32
is
Res : Unsigned_32;
begin
Asm ("mrs %0, esr_el3",
Outputs => Unsigned_32'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_ESR_EL3;
-----------------
-- Get_FAR_EL3 --
-----------------
function Get_FAR_EL3 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, far_el3",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_FAR_EL3;
-----------------
-- Get_ELR_EL2 --
-----------------
function Get_ELR_EL2 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, elr_el2",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_ELR_EL2;
-----------------
-- Set_ELR_EL2 --
-----------------
procedure Set_ELR_EL2 (V : Unsigned_64) is
begin
Asm ("msr elr_el2, %0",
Inputs => Unsigned_64'Asm_Input ("r", V),
Volatile => True);
end Set_ELR_EL2;
------------------
-- Get_SPSR_EL2 --
------------------
function Get_SPSR_EL2 return Unsigned_32
is
Res : Unsigned_32;
begin
Asm ("mrs %0, spsr_el2",
Outputs => Unsigned_32'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_SPSR_EL2;
-----------------
-- Get_ESR_EL2 --
-----------------
function Get_ESR_EL2 return Unsigned_32
is
Res : Unsigned_32;
begin
Asm ("mrs %0, esr_el2",
Outputs => Unsigned_32'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_ESR_EL2;
-----------------
-- Get_FAR_EL2 --
-----------------
function Get_FAR_EL2 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, far_el2",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_FAR_EL2;
-------------------
-- Get_HPFAR_EL2 --
-------------------
function Get_HPFAR_EL2 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, hpfar_el2",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_HPFAR_EL2;
------------------
-- Get_VTCR_EL2 --
------------------
function Get_VTCR_EL2 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, vtcr_el2",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_VTCR_EL2;
-------------------
-- Get_VTTBR_EL2 --
-------------------
function Get_VTTBR_EL2 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, vttbr_el2",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_VTTBR_EL2;
-------------------
-- Set_VTTBR_EL2 --
-------------------
procedure Set_VTTBR_EL2 (V : Unsigned_64) is
begin
Asm ("msr vttbr_el2, %0",
Inputs => Unsigned_64'Asm_Input ("r", V),
Volatile => True);
end Set_VTTBR_EL2;
-----------------
-- Get_HCR_EL2 --
-----------------
function Get_HCR_EL2 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, hcr_el2",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_HCR_EL2;
-----------------
-- Set_HCR_EL2 --
-----------------
procedure Set_HCR_EL2 (V : Unsigned_64) is
begin
Asm ("msr hcr_el2, %0",
Inputs => Unsigned_64'Asm_Input ("r", V),
Volatile => True);
end Set_HCR_EL2;
----------------
-- Get_SP_EL2 --
----------------
function Get_SP_EL2 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, sp_el2",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_SP_EL2;
-------------------
-- Get_SCTLR_EL2 --
-------------------
function Get_SCTLR_EL2 return Unsigned_32
is
Res : Unsigned_32;
begin
Asm ("mrs %0, sctlr_el2",
Outputs => Unsigned_32'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_SCTLR_EL2;
-------------------
-- Set_VPIDR_EL2 --
-------------------
procedure Set_VPIDR_EL2 (V : Unsigned_32) is
begin
Asm ("msr vpidr_el2, %0",
Inputs => Unsigned_32'Asm_Input ("r", V),
Volatile => True);
end Set_VPIDR_EL2;
--------------------
-- Set_VMPIDR_EL2 --
--------------------
procedure Set_VMPIDR_EL2 (V : Unsigned_64) is
begin
Asm ("msr vmpidr_el2, %0",
Inputs => Unsigned_64'Asm_Input ("r", V),
Volatile => True);
end Set_VMPIDR_EL2;
-----------------
-- Get_ELR_EL1 --
-----------------
function Get_ELR_EL1 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, elr_el1",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_ELR_EL1;
-----------------
-- Set_ELR_EL1 --
-----------------
procedure Set_ELR_EL1 (V : Unsigned_64) is
begin
Asm ("msr elr_el1, %0",
Inputs => Unsigned_64'Asm_Input ("r", V),
Volatile => True);
end Set_ELR_EL1;
------------------
-- Get_SPSR_EL1 --
------------------
function Get_SPSR_EL1 return Unsigned_32
is
Res : Unsigned_32;
begin
Asm ("mrs %0, spsr_el1",
Outputs => Unsigned_32'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_SPSR_EL1;
------------------
-- Get_VBAR_EL1 --
------------------
function Get_VBAR_EL1 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, vbar_el1",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_VBAR_EL1;
-----------------
-- Get_ESR_EL1 --
-----------------
function Get_ESR_EL1 return Unsigned_32
is
Res : Unsigned_32;
begin
Asm ("mrs %0, esr_el1",
Outputs => Unsigned_32'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_ESR_EL1;
-----------------
-- Get_FAR_EL1 --
-----------------
function Get_FAR_EL1 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, far_el1",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_FAR_EL1;
----------------
-- Get_SP_EL1 --
----------------
function Get_SP_EL1 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, sp_el1",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_SP_EL1;
-------------------
-- Get_SCTLR_EL1 --
-------------------
function Get_SCTLR_EL1 return Unsigned_32
is
Res : Unsigned_32;
begin
Asm ("mrs %0, sctlr_el1",
Outputs => Unsigned_32'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_SCTLR_EL1;
-----------------
-- Get_TCR_EL1 --
-----------------
function Get_TCR_EL1 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, tcr_el1",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_TCR_EL1;
-------------------
-- Get_TTBR0_EL1 --
-------------------
function Get_TTBR0_EL1 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, ttbr0_el1",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_TTBR0_EL1;
-------------------
-- Get_TTBR1_EL1 --
-------------------
function Get_TTBR1_EL1 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, ttbr1_el1",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_TTBR1_EL1;
-------------------
-- Get_MPIDR_EL1 --
-------------------
function Get_MPIDR_EL1 return Unsigned_32 is
R : Unsigned_32;
begin
Asm ("mrs %0, mpidr_el1",
Outputs => Unsigned_32'Asm_Output ("=r", R),
Volatile => True);
return R;
end Get_MPIDR_EL1;
----------------
-- Get_SP_EL0 --
----------------
function Get_SP_EL0 return Unsigned_64
is
Res : Unsigned_64;
begin
Asm ("mrs %0, sp_el0",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_SP_EL0;
--------------------------
-- Get_ID_AA64MMFR0_EL1 --
--------------------------
function Get_ID_AA64MMFR0_EL1 return Unsigned_64 is
Res : Unsigned_64;
begin
Asm ("mrs %0, ID_AA64MMFR0_EL1",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_ID_AA64MMFR0_EL1;
--------------------------
-- Get_ID_AA64MMFR1_EL1 --
--------------------------
function Get_ID_AA64MMFR1_EL1 return Unsigned_64 is
Res : Unsigned_64;
begin
Asm ("mrs %0, ID_AA64MMFR1_EL1",
Outputs => Unsigned_64'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Get_ID_AA64MMFR1_EL1;
end Interfaces.AArch64;
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="14">
<syndb class_id="0" tracking_level="0" version="0">
<userIPLatency>-1</userIPLatency>
<userIPName></userIPName>
<cdfg class_id="1" tracking_level="1" version="0" object_id="_0">
<name>hls_target</name>
<ret_bitwidth>0</ret_bitwidth>
<ports class_id="2" tracking_level="0" version="0">
<count>4</count>
<item_version>0</item_version>
<item class_id="3" tracking_level="1" version="0" object_id="_1">
<Value class_id="4" tracking_level="0" version="0">
<Obj class_id="5" tracking_level="0" version="0">
<type>1</type>
<id>1</id>
<name>hw_input_V_value_V</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo class_id="6" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>hw_input.V.value.V</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>8</bitwidth>
</Value>
<direction>0</direction>
<if_type>0</if_type>
<array_size>0</array_size>
<bit_vecs class_id="7" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</bit_vecs>
</item>
<item class_id_reference="3" object_id="_2">
<Value>
<Obj>
<type>1</type>
<id>2</id>
<name>hw_input_V_last_V</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>hw_input.V.last.V</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>1</bitwidth>
</Value>
<direction>0</direction>
<if_type>0</if_type>
<array_size>0</array_size>
<bit_vecs>
<count>0</count>
<item_version>0</item_version>
</bit_vecs>
</item>
<item class_id_reference="3" object_id="_3">
<Value>
<Obj>
<type>1</type>
<id>3</id>
<name>hw_output_V_value_V</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>hw_output.V.value.V</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>8</bitwidth>
</Value>
<direction>1</direction>
<if_type>0</if_type>
<array_size>0</array_size>
<bit_vecs>
<count>0</count>
<item_version>0</item_version>
</bit_vecs>
</item>
<item class_id_reference="3" object_id="_4">
<Value>
<Obj>
<type>1</type>
<id>4</id>
<name>hw_output_V_last_V</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName>hw_output.V.last.V</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>1</bitwidth>
</Value>
<direction>1</direction>
<if_type>0</if_type>
<array_size>0</array_size>
<bit_vecs>
<count>0</count>
<item_version>0</item_version>
</bit_vecs>
</item>
</ports>
<nodes class_id="8" tracking_level="0" version="0">
<count>10</count>
<item_version>0</item_version>
<item class_id="9" tracking_level="1" version="0" object_id="_5">
<Value>
<Obj>
<type>0</type>
<id>11</id>
<name>p_hw_input_stencil_st</name>
<fileName>hls_target.cpp</fileName>
<fileDirectory>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</fileDirectory>
<lineNumber>50</lineNumber>
<contextFuncName>hls_target</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item class_id="10" tracking_level="0" version="0">
<first>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</first>
<second class_id="11" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="12" tracking_level="0" version="0">
<first class_id="13" tracking_level="0" version="0">
<first>hls_target.cpp</first>
<second>hls_target</second>
</first>
<second>50</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName>_hw_input_stencil_stream.V.value.V</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>72</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>37</item>
</oprand_edges>
<opcode>alloca</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_6">
<Value>
<Obj>
<type>0</type>
<id>15</id>
<name>p_mul_stencil_update_1</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>32</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>38</item>
</oprand_edges>
<opcode>alloca</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_7">
<Value>
<Obj>
<type>0</type>
<id>19</id>
<name>p_mul_stencil_stream_s</name>
<fileName>hls_target.cpp</fileName>
<fileDirectory>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</fileDirectory>
<lineNumber>164</lineNumber>
<contextFuncName>hls_target</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>hls_target.cpp</first>
<second>hls_target</second>
</first>
<second>164</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName>_mul_stencil_stream.V.value.V</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>128</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>39</item>
</oprand_edges>
<opcode>alloca</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_8">
<Value>
<Obj>
<type>0</type>
<id>23</id>
<name>p_p2_mul1_stencil_str</name>
<fileName>hls_target.cpp</fileName>
<fileDirectory>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</fileDirectory>
<lineNumber>173</lineNumber>
<contextFuncName>hls_target</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>hls_target.cpp</first>
<second>hls_target</second>
</first>
<second>173</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName>_p2_mul1_stencil_stream.V.value.V</originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>32</bitwidth>
</Value>
<oprand_edges>
<count>1</count>
<item_version>0</item_version>
<item>40</item>
</oprand_edges>
<opcode>alloca</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_9">
<Value>
<Obj>
<type>0</type>
<id>29</id>
<name></name>
<fileName>hls_target.cpp</fileName>
<fileDirectory>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</fileDirectory>
<lineNumber>54</lineNumber>
<contextFuncName>hls_target</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>hls_target.cpp</first>
<second>hls_target</second>
</first>
<second>54</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>4</count>
<item_version>0</item_version>
<item>42</item>
<item>43</item>
<item>44</item>
<item>45</item>
</oprand_edges>
<opcode>call</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_10">
<Value>
<Obj>
<type>0</type>
<id>30</id>
<name></name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>5</count>
<item_version>0</item_version>
<item>47</item>
<item>48</item>
<item>49</item>
<item>283</item>
<item>284</item>
</oprand_edges>
<opcode>call</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_11">
<Value>
<Obj>
<type>0</type>
<id>31</id>
<name></name>
<fileName>hls_target.cpp</fileName>
<fileDirectory>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</fileDirectory>
<lineNumber>168</lineNumber>
<contextFuncName>hls_target</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>hls_target.cpp</first>
<second>hls_target</second>
</first>
<second>168</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>5</count>
<item_version>0</item_version>
<item>51</item>
<item>52</item>
<item>53</item>
<item>282</item>
<item>285</item>
</oprand_edges>
<opcode>call</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_12">
<Value>
<Obj>
<type>0</type>
<id>32</id>
<name></name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>5</count>
<item_version>0</item_version>
<item>55</item>
<item>56</item>
<item>57</item>
<item>281</item>
<item>286</item>
</oprand_edges>
<opcode>call</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_13">
<Value>
<Obj>
<type>0</type>
<id>33</id>
<name></name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>6</count>
<item_version>0</item_version>
<item>59</item>
<item>60</item>
<item>61</item>
<item>62</item>
<item>280</item>
<item>287</item>
</oprand_edges>
<opcode>call</opcode>
<m_Display>0</m_Display>
</item>
<item class_id_reference="9" object_id="_14">
<Value>
<Obj>
<type>0</type>
<id>34</id>
<name></name>
<fileName>hls_target.cpp</fileName>
<fileDirectory>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</fileDirectory>
<lineNumber>272</lineNumber>
<contextFuncName>hls_target</contextFuncName>
<inlineStackInfo>
<count>1</count>
<item_version>0</item_version>
<item>
<first>/home/dhuff/Halide-HLS/apps/hls_examples/camera_ready_synthesis/app_files/big_apps_8_shifts/conv2d_b2b</first>
<second>
<count>1</count>
<item_version>0</item_version>
<item>
<first>
<first>hls_target.cpp</first>
<second>hls_target</second>
</first>
<second>272</second>
</item>
</second>
</item>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<oprand_edges>
<count>0</count>
<item_version>0</item_version>
</oprand_edges>
<opcode>ret</opcode>
<m_Display>0</m_Display>
</item>
</nodes>
<consts class_id="15" tracking_level="0" version="0">
<count>6</count>
<item_version>0</item_version>
<item class_id="16" tracking_level="1" version="0" object_id="_15">
<Value>
<Obj>
<type>2</type>
<id>36</id>
<name>empty</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>64</bitwidth>
</Value>
<const_type>0</const_type>
<content>1</content>
</item>
<item class_id_reference="16" object_id="_16">
<Value>
<Obj>
<type>2</type>
<id>41</id>
<name>linebuffer_1</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<const_type>6</const_type>
<content><constant:linebuffer.1></content>
</item>
<item class_id_reference="16" object_id="_17">
<Value>
<Obj>
<type>2</type>
<id>46</id>
<name>Loop_1_proc</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<const_type>6</const_type>
<content><constant:Loop_1_proc></content>
</item>
<item class_id_reference="16" object_id="_18">
<Value>
<Obj>
<type>2</type>
<id>50</id>
<name>linebuffer_2</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<const_type>6</const_type>
<content><constant:linebuffer.2></content>
</item>
<item class_id_reference="16" object_id="_19">
<Value>
<Obj>
<type>2</type>
<id>54</id>
<name>Loop_2_proc</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<const_type>6</const_type>
<content><constant:Loop_2_proc></content>
</item>
<item class_id_reference="16" object_id="_20">
<Value>
<Obj>
<type>2</type>
<id>58</id>
<name>Loop_3_proc</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<bitwidth>0</bitwidth>
</Value>
<const_type>6</const_type>
<content><constant:Loop_3_proc></content>
</item>
</consts>
<blocks class_id="17" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="18" tracking_level="1" version="0" object_id="_21">
<Obj>
<type>3</type>
<id>35</id>
<name>hls_target</name>
<fileName></fileName>
<fileDirectory></fileDirectory>
<lineNumber>0</lineNumber>
<contextFuncName></contextFuncName>
<inlineStackInfo>
<count>0</count>
<item_version>0</item_version>
</inlineStackInfo>
<originalName></originalName>
<rtlName></rtlName>
<coreName></coreName>
</Obj>
<node_objs>
<count>10</count>
<item_version>0</item_version>
<item>11</item>
<item>15</item>
<item>19</item>
<item>23</item>
<item>29</item>
<item>30</item>
<item>31</item>
<item>32</item>
<item>33</item>
<item>34</item>
</node_objs>
</item>
</blocks>
<edges class_id="19" tracking_level="0" version="0">
<count>29</count>
<item_version>0</item_version>
<item class_id="20" tracking_level="1" version="0" object_id="_22">
<id>37</id>
<edge_type>1</edge_type>
<source_obj>36</source_obj>
<sink_obj>11</sink_obj>
</item>
<item class_id_reference="20" object_id="_23">
<id>38</id>
<edge_type>1</edge_type>
<source_obj>36</source_obj>
<sink_obj>15</sink_obj>
</item>
<item class_id_reference="20" object_id="_24">
<id>39</id>
<edge_type>1</edge_type>
<source_obj>36</source_obj>
<sink_obj>19</sink_obj>
</item>
<item class_id_reference="20" object_id="_25">
<id>40</id>
<edge_type>1</edge_type>
<source_obj>36</source_obj>
<sink_obj>23</sink_obj>
</item>
<item class_id_reference="20" object_id="_26">
<id>42</id>
<edge_type>1</edge_type>
<source_obj>41</source_obj>
<sink_obj>29</sink_obj>
</item>
<item class_id_reference="20" object_id="_27">
<id>43</id>
<edge_type>1</edge_type>
<source_obj>1</source_obj>
<sink_obj>29</sink_obj>
</item>
<item class_id_reference="20" object_id="_28">
<id>44</id>
<edge_type>1</edge_type>
<source_obj>2</source_obj>
<sink_obj>29</sink_obj>
</item>
<item class_id_reference="20" object_id="_29">
<id>45</id>
<edge_type>1</edge_type>
<source_obj>11</source_obj>
<sink_obj>29</sink_obj>
</item>
<item class_id_reference="20" object_id="_30">
<id>47</id>
<edge_type>1</edge_type>
<source_obj>46</source_obj>
<sink_obj>30</sink_obj>
</item>
<item class_id_reference="20" object_id="_31">
<id>48</id>
<edge_type>1</edge_type>
<source_obj>11</source_obj>
<sink_obj>30</sink_obj>
</item>
<item class_id_reference="20" object_id="_32">
<id>49</id>
<edge_type>1</edge_type>
<source_obj>15</source_obj>
<sink_obj>30</sink_obj>
</item>
<item class_id_reference="20" object_id="_33">
<id>51</id>
<edge_type>1</edge_type>
<source_obj>50</source_obj>
<sink_obj>31</sink_obj>
</item>
<item class_id_reference="20" object_id="_34">
<id>52</id>
<edge_type>1</edge_type>
<source_obj>15</source_obj>
<sink_obj>31</sink_obj>
</item>
<item class_id_reference="20" object_id="_35">
<id>53</id>
<edge_type>1</edge_type>
<source_obj>19</source_obj>
<sink_obj>31</sink_obj>
</item>
<item class_id_reference="20" object_id="_36">
<id>55</id>
<edge_type>1</edge_type>
<source_obj>54</source_obj>
<sink_obj>32</sink_obj>
</item>
<item class_id_reference="20" object_id="_37">
<id>56</id>
<edge_type>1</edge_type>
<source_obj>19</source_obj>
<sink_obj>32</sink_obj>
</item>
<item class_id_reference="20" object_id="_38">
<id>57</id>
<edge_type>1</edge_type>
<source_obj>23</source_obj>
<sink_obj>32</sink_obj>
</item>
<item class_id_reference="20" object_id="_39">
<id>59</id>
<edge_type>1</edge_type>
<source_obj>58</source_obj>
<sink_obj>33</sink_obj>
</item>
<item class_id_reference="20" object_id="_40">
<id>60</id>
<edge_type>1</edge_type>
<source_obj>23</source_obj>
<sink_obj>33</sink_obj>
</item>
<item class_id_reference="20" object_id="_41">
<id>61</id>
<edge_type>1</edge_type>
<source_obj>3</source_obj>
<sink_obj>33</sink_obj>
</item>
<item class_id_reference="20" object_id="_42">
<id>62</id>
<edge_type>1</edge_type>
<source_obj>4</source_obj>
<sink_obj>33</sink_obj>
</item>
<item class_id_reference="20" object_id="_43">
<id>280</id>
<edge_type>4</edge_type>
<source_obj>32</source_obj>
<sink_obj>33</sink_obj>
</item>
<item class_id_reference="20" object_id="_44">
<id>281</id>
<edge_type>4</edge_type>
<source_obj>31</source_obj>
<sink_obj>32</sink_obj>
</item>
<item class_id_reference="20" object_id="_45">
<id>282</id>
<edge_type>4</edge_type>
<source_obj>30</source_obj>
<sink_obj>31</sink_obj>
</item>
<item class_id_reference="20" object_id="_46">
<id>283</id>
<edge_type>4</edge_type>
<source_obj>29</source_obj>
<sink_obj>30</sink_obj>
</item>
<item class_id_reference="20" object_id="_47">
<id>284</id>
<edge_type>4</edge_type>
<source_obj>29</source_obj>
<sink_obj>30</sink_obj>
</item>
<item class_id_reference="20" object_id="_48">
<id>285</id>
<edge_type>4</edge_type>
<source_obj>30</source_obj>
<sink_obj>31</sink_obj>
</item>
<item class_id_reference="20" object_id="_49">
<id>286</id>
<edge_type>4</edge_type>
<source_obj>31</source_obj>
<sink_obj>32</sink_obj>
</item>
<item class_id_reference="20" object_id="_50">
<id>287</id>
<edge_type>4</edge_type>
<source_obj>32</source_obj>
<sink_obj>33</sink_obj>
</item>
</edges>
</cdfg>
<cdfg_regions class_id="21" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="22" tracking_level="1" version="0" object_id="_51">
<mId>1</mId>
<mTag>hls_target</mTag>
<mType>0</mType>
<sub_regions>
<count>0</count>
<item_version>0</item_version>
</sub_regions>
<basic_blocks>
<count>1</count>
<item_version>0</item_version>
<item>35</item>
</basic_blocks>
<mII>-1</mII>
<mDepth>-1</mDepth>
<mMinTripCount>-1</mMinTripCount>
<mMaxTripCount>-1</mMaxTripCount>
<mMinLatency>2077921</mMinLatency>
<mMaxLatency>-1</mMaxLatency>
<mIsDfPipe>1</mIsDfPipe>
<mDfPipe class_id="23" tracking_level="1" version="0" object_id="_52">
<port_list class_id="24" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</port_list>
<process_list class_id="25" tracking_level="0" version="0">
<count>5</count>
<item_version>0</item_version>
<item class_id="26" tracking_level="1" version="0" object_id="_53">
<type>0</type>
<name>linebuffer_1_U0</name>
<ssdmobj_id>29</ssdmobj_id>
<pins class_id="27" tracking_level="0" version="0">
<count>3</count>
<item_version>0</item_version>
<item class_id="28" tracking_level="1" version="0" object_id="_54">
<port class_id="29" tracking_level="1" version="0" object_id="_55">
<name>in_axi_stream_V_value_V</name>
<dir>3</dir>
<type>0</type>
</port>
<inst class_id="30" tracking_level="1" version="0" object_id="_56">
<type>0</type>
<name>linebuffer_1_U0</name>
<ssdmobj_id>29</ssdmobj_id>
</inst>
</item>
<item class_id_reference="28" object_id="_57">
<port class_id_reference="29" object_id="_58">
<name>in_axi_stream_V_last_V</name>
<dir>3</dir>
<type>0</type>
</port>
<inst class_id_reference="30" object_id_reference="_56"></inst>
</item>
<item class_id_reference="28" object_id="_59">
<port class_id_reference="29" object_id="_60">
<name>out_stream_V_value_V</name>
<dir>0</dir>
<type>1</type>
</port>
<inst class_id_reference="30" object_id_reference="_56"></inst>
</item>
</pins>
</item>
<item class_id_reference="26" object_id="_61">
<type>0</type>
<name>Loop_1_proc_U0</name>
<ssdmobj_id>30</ssdmobj_id>
<pins>
<count>2</count>
<item_version>0</item_version>
<item class_id_reference="28" object_id="_62">
<port class_id_reference="29" object_id="_63">
<name>p_hw_input_stencil_stream_V_value_V</name>
<dir>0</dir>
<type>0</type>
</port>
<inst class_id_reference="30" object_id="_64">
<type>0</type>
<name>Loop_1_proc_U0</name>
<ssdmobj_id>30</ssdmobj_id>
</inst>
</item>
<item class_id_reference="28" object_id="_65">
<port class_id_reference="29" object_id="_66">
<name>p_mul_stencil_update_stream_V_value_V</name>
<dir>0</dir>
<type>1</type>
</port>
<inst class_id_reference="30" object_id_reference="_64"></inst>
</item>
</pins>
</item>
<item class_id_reference="26" object_id="_67">
<type>0</type>
<name>linebuffer_2_U0</name>
<ssdmobj_id>31</ssdmobj_id>
<pins>
<count>2</count>
<item_version>0</item_version>
<item class_id_reference="28" object_id="_68">
<port class_id_reference="29" object_id="_69">
<name>in_stream_V_value_V</name>
<dir>0</dir>
<type>0</type>
</port>
<inst class_id_reference="30" object_id="_70">
<type>0</type>
<name>linebuffer_2_U0</name>
<ssdmobj_id>31</ssdmobj_id>
</inst>
</item>
<item class_id_reference="28" object_id="_71">
<port class_id_reference="29" object_id="_72">
<name>out_stream_V_value_V</name>
<dir>0</dir>
<type>1</type>
</port>
<inst class_id_reference="30" object_id_reference="_70"></inst>
</item>
</pins>
</item>
<item class_id_reference="26" object_id="_73">
<type>0</type>
<name>Loop_2_proc_U0</name>
<ssdmobj_id>32</ssdmobj_id>
<pins>
<count>2</count>
<item_version>0</item_version>
<item class_id_reference="28" object_id="_74">
<port class_id_reference="29" object_id="_75">
<name>p_mul_stencil_stream_V_value_V</name>
<dir>0</dir>
<type>0</type>
</port>
<inst class_id_reference="30" object_id="_76">
<type>0</type>
<name>Loop_2_proc_U0</name>
<ssdmobj_id>32</ssdmobj_id>
</inst>
</item>
<item class_id_reference="28" object_id="_77">
<port class_id_reference="29" object_id="_78">
<name>p_p2_mul1_stencil_stream_V_value_V</name>
<dir>0</dir>
<type>1</type>
</port>
<inst class_id_reference="30" object_id_reference="_76"></inst>
</item>
</pins>
</item>
<item class_id_reference="26" object_id="_79">
<type>0</type>
<name>Loop_3_proc_U0</name>
<ssdmobj_id>33</ssdmobj_id>
<pins>
<count>3</count>
<item_version>0</item_version>
<item class_id_reference="28" object_id="_80">
<port class_id_reference="29" object_id="_81">
<name>p_p2_mul1_stencil_stream_V_value_V</name>
<dir>0</dir>
<type>0</type>
</port>
<inst class_id_reference="30" object_id="_82">
<type>0</type>
<name>Loop_3_proc_U0</name>
<ssdmobj_id>33</ssdmobj_id>
</inst>
</item>
<item class_id_reference="28" object_id="_83">
<port class_id_reference="29" object_id="_84">
<name>hw_output_V_value_V</name>
<dir>3</dir>
<type>1</type>
</port>
<inst class_id_reference="30" object_id_reference="_82"></inst>
</item>
<item class_id_reference="28" object_id="_85">
<port class_id_reference="29" object_id="_86">
<name>hw_output_V_last_V</name>
<dir>3</dir>
<type>1</type>
</port>
<inst class_id_reference="30" object_id_reference="_82"></inst>
</item>
</pins>
</item>
</process_list>
<channel_list class_id="31" tracking_level="0" version="0">
<count>4</count>
<item_version>0</item_version>
<item class_id="32" tracking_level="1" version="0" object_id="_87">
<type>1</type>
<name>p_hw_input_stencil_st</name>
<ssdmobj_id>11</ssdmobj_id>
<ctype>0</ctype>
<depth>1</depth>
<bitwidth>72</bitwidth>
<source class_id_reference="28" object_id="_88">
<port class_id_reference="29" object_id="_89">
<name>in</name>
<dir>3</dir>
<type>0</type>
</port>
<inst class_id_reference="30" object_id_reference="_56"></inst>
</source>
<sink class_id_reference="28" object_id="_90">
<port class_id_reference="29" object_id="_91">
<name>out</name>
<dir>3</dir>
<type>1</type>
</port>
<inst class_id_reference="30" object_id_reference="_64"></inst>
</sink>
</item>
<item class_id_reference="32" object_id="_92">
<type>1</type>
<name>p_mul_stencil_update_1</name>
<ssdmobj_id>15</ssdmobj_id>
<ctype>0</ctype>
<depth>1</depth>
<bitwidth>32</bitwidth>
<source class_id_reference="28" object_id="_93">
<port class_id_reference="29" object_id="_94">
<name>in</name>
<dir>3</dir>
<type>0</type>
</port>
<inst class_id_reference="30" object_id_reference="_64"></inst>
</source>
<sink class_id_reference="28" object_id="_95">
<port class_id_reference="29" object_id="_96">
<name>out</name>
<dir>3</dir>
<type>1</type>
</port>
<inst class_id_reference="30" object_id_reference="_70"></inst>
</sink>
</item>
<item class_id_reference="32" object_id="_97">
<type>1</type>
<name>p_mul_stencil_stream_s</name>
<ssdmobj_id>19</ssdmobj_id>
<ctype>0</ctype>
<depth>1</depth>
<bitwidth>128</bitwidth>
<source class_id_reference="28" object_id="_98">
<port class_id_reference="29" object_id="_99">
<name>in</name>
<dir>3</dir>
<type>0</type>
</port>
<inst class_id_reference="30" object_id_reference="_70"></inst>
</source>
<sink class_id_reference="28" object_id="_100">
<port class_id_reference="29" object_id="_101">
<name>out</name>
<dir>3</dir>
<type>1</type>
</port>
<inst class_id_reference="30" object_id_reference="_76"></inst>
</sink>
</item>
<item class_id_reference="32" object_id="_102">
<type>1</type>
<name>p_p2_mul1_stencil_str</name>
<ssdmobj_id>23</ssdmobj_id>
<ctype>0</ctype>
<depth>1</depth>
<bitwidth>32</bitwidth>
<source class_id_reference="28" object_id="_103">
<port class_id_reference="29" object_id="_104">
<name>in</name>
<dir>3</dir>
<type>0</type>
</port>
<inst class_id_reference="30" object_id_reference="_76"></inst>
</source>
<sink class_id_reference="28" object_id="_105">
<port class_id_reference="29" object_id="_106">
<name>out</name>
<dir>3</dir>
<type>1</type>
</port>
<inst class_id_reference="30" object_id_reference="_82"></inst>
</sink>
</item>
</channel_list>
<net_list class_id="33" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</net_list>
</mDfPipe>
</item>
</cdfg_regions>
<fsm class_id="-1"></fsm>
<res class_id="-1"></res>
<node_label_latency class_id="36" tracking_level="0" version="0">
<count>10</count>
<item_version>0</item_version>
<item class_id="37" tracking_level="0" version="0">
<first>11</first>
<second class_id="38" tracking_level="0" version="0">
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>15</first>
<second>
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>19</first>
<second>
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>23</first>
<second>
<first>0</first>
<second>0</second>
</second>
</item>
<item>
<first>29</first>
<second>
<first>0</first>
<second>1</second>
</second>
</item>
<item>
<first>30</first>
<second>
<first>2</first>
<second>1</second>
</second>
</item>
<item>
<first>31</first>
<second>
<first>4</first>
<second>1</second>
</second>
</item>
<item>
<first>32</first>
<second>
<first>6</first>
<second>1</second>
</second>
</item>
<item>
<first>33</first>
<second>
<first>8</first>
<second>1</second>
</second>
</item>
<item>
<first>34</first>
<second>
<first>9</first>
<second>0</second>
</second>
</item>
</node_label_latency>
<bblk_ent_exit class_id="39" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="40" tracking_level="0" version="0">
<first>35</first>
<second class_id="41" tracking_level="0" version="0">
<first>0</first>
<second>9</second>
</second>
</item>
</bblk_ent_exit>
<regions class_id="42" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id="43" tracking_level="1" version="0" object_id="_107">
<region_name>hls_target</region_name>
<basic_blocks>
<count>1</count>
<item_version>0</item_version>
<item>35</item>
</basic_blocks>
<nodes>
<count>30</count>
<item_version>0</item_version>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
<item>11</item>
<item>12</item>
<item>13</item>
<item>14</item>
<item>15</item>
<item>16</item>
<item>17</item>
<item>18</item>
<item>19</item>
<item>20</item>
<item>21</item>
<item>22</item>
<item>23</item>
<item>24</item>
<item>25</item>
<item>26</item>
<item>27</item>
<item>28</item>
<item>29</item>
<item>30</item>
<item>31</item>
<item>32</item>
<item>33</item>
<item>34</item>
</nodes>
<anchor_node>-1</anchor_node>
<region_type>16</region_type>
<interval>0</interval>
<pipe_depth>0</pipe_depth>
</item>
</regions>
<dp_fu_nodes class_id="44" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</dp_fu_nodes>
<dp_fu_nodes_expression class_id="45" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</dp_fu_nodes_expression>
<dp_fu_nodes_module>
<count>0</count>
<item_version>0</item_version>
</dp_fu_nodes_module>
<dp_fu_nodes_io>
<count>0</count>
<item_version>0</item_version>
</dp_fu_nodes_io>
<return_ports>
<count>0</count>
<item_version>0</item_version>
</return_ports>
<dp_mem_port_nodes class_id="46" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</dp_mem_port_nodes>
<dp_reg_nodes>
<count>0</count>
<item_version>0</item_version>
</dp_reg_nodes>
<dp_regname_nodes>
<count>0</count>
<item_version>0</item_version>
</dp_regname_nodes>
<dp_reg_phi>
<count>0</count>
<item_version>0</item_version>
</dp_reg_phi>
<dp_regname_phi>
<count>0</count>
<item_version>0</item_version>
</dp_regname_phi>
<dp_port_io_nodes class_id="47" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</dp_port_io_nodes>
<port2core class_id="48" tracking_level="0" version="0">
<count>0</count>
<item_version>0</item_version>
</port2core>
<node2core>
<count>0</count>
<item_version>0</item_version>
</node2core>
</syndb>
</boost_serialization>
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
generic
type Index_Type is (<>);
type Element_Type is private;
with function "+" (Left, Right : Element_Type) return Element_Type is <>;
with function "-" (Left, Right : Element_Type) return Element_Type is <>;
with function "-" (Left : Element_Type) return Element_Type is <>;
with function "*" (Left, Right : Element_Type) return Element_Type is <>;
with function "/" (Left, Right : Element_Type) return Element_Type is <>;
package GL.Vectors is
pragma Preelaborate;
type Vector is array (Index_Type) of aliased Element_Type;
pragma Convention (C, Vector);
function "+" (Left, Right : Vector) return Vector;
function "-" (Left, Right : Vector) return Vector;
function "-" (Left : Vector) return Vector;
function "*" (Left : Vector; Right : Element_Type) return Vector;
function "*" (Left : Element_Type; Right : Vector) return Vector;
function "/" (Left : Vector; Right : Element_Type) return Vector;
function Dot_Product (Left, Right : Vector) return Element_Type;
pragma Inline ("+");
pragma Inline ("-");
pragma Inline ("*");
pragma Inline ("/");
end GL.Vectors;
|
with Estimator;
with Units.Navigation; use Units.Navigation;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;
with Simulation;
with Units; use Units;
with Units.Vectors; use Units.Vectors;
with Kalman;
procedure main is
subtype Elevon_Angle_Type is Angle_Type range -45.0 * Degree .. 45.0 * Degree;
type Elevon_Index_Type is (LEFT, RIGHT);
type Elevon_Angle_Array is array(Elevon_Index_Type) of Elevon_Angle_Type;
est_ort : Orientation_Type;
est_loc : GPS_Loacation_Type;
est_gfx : GPS_Fix_Type;
est_calt : Altitude_Type;
est_malt : Altitude_Type;
outfile : File_Type;
next : Ada.Real_Time.Time;
Elevons : Elevon_Angle_Array := (0.0*Degree, 0.0*Degree);
init_state : Kalman.State_Vector := Kalman.DEFAULT_INIT_STATES;
procedure startfile is
begin
Put_Line (outfile, "time;roll;pitch;yaw;alt");
end startfile;
procedure write2file (o : Orientation_Type; a: Altitude_Type) is
t : Float := Simulation.CSV_here.Get_Column ("time");
begin
Put_Line (outfile, t'img & ";" & Float (o.Roll)'img & ";" & Float (o.Pitch)'img & ";" & Float (o.Yaw)'img & ";" & Float (a)'Img);
end write2file;
begin
Simulation.init;
Estimator.initialize;
Create (File => outfile, Mode => Out_File, Name => "../estimate.csv");
if not Is_Open (outfile) then
Put_Line ("Error creating output file");
return;
end if;
startfile;
-- Initial States
init_state.orientation.Roll := -50.0*Degree;
init_state.orientation.Pitch := 70.0*Degree;
init_state.rates(X) := Angular_Velocity_Type( Simulation.CSV_here.Get_Column ("gyroX") );
init_state.rates(Y) := Angular_Velocity_Type( Simulation.CSV_here.Get_Column ("gyroY") );
init_state.bias(X) := 2.0*Degree/Second;
init_state.bias(Y) := 2.6*Degree/Second;
Kalman.reset( init_state );
Estimator.update( (0.0*Degree, 0.0*Degree) );
next := Clock;
Read_Loop :
loop
Simulation.update;
exit Read_Loop when Simulation.Finished;
-- Read Control Signals
Elevons(LEFT) := Angle_Type( Simulation.CSV_here.Get_Column ("EleL") );
Elevons(RIGHT) := Angle_Type( Simulation.CSV_here.Get_Column ("EleR") );
Estimator.update( ( Elevons( RIGHT ) / 2.0 + Elevons( LEFT ) / 2.0,
Elevons( RIGHT ) / 2.0 - Elevons( LEFT ) / 2.0 ) );
est_ort := Estimator.get_Orientation;
est_loc := Estimator.get_Position;
est_gfx := Estimator.get_GPS_Fix;
est_calt := Estimator.get_current_Height;
est_malt := Estimator.get_max_Height;
-- log to file
write2file (est_ort, est_calt);
-- time to display output
delay until next;
next := next + Milliseconds (20);
end loop Read_Loop;
Simulation.close;
Close (outfile);
end main;
|
------------------------------------------------------------------------------
-- --
-- Copyright (c) 2014-2017 Vitalij Bondarenko <vibondare@gmail.com> --
-- --
------------------------------------------------------------------------------
-- --
-- The MIT License (MIT) --
-- --
-- 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 Interfaces.C.Strings; use Interfaces.C.Strings;
package body I18n is
pragma Warnings (Off);
-------------
-- Gettext --
-------------
function Gettext (Msg : String) return String is
function Internal (Msg : String) return chars_ptr;
pragma Import (C, Internal, "gettext");
P : chars_ptr := Internal (Msg & ASCII.NUL);
begin
if P = Null_Ptr then
return "";
else
return Value (P);
end if;
end Gettext;
--------------
-- Dgettext --
--------------
function Dgettext (Domain : String; Msg : String) return String is
function Internal
(Domain : String; Msg : String) return chars_ptr;
pragma Import (C, Internal, "dgettext");
P : chars_ptr := Internal (Domain & ASCII.NUL, Msg & ASCII.NUL);
begin
if P = Null_Ptr then
return "";
else
return Value (P);
end if;
end Dgettext;
---------------
-- Dcgettext --
---------------
function Dcgettext
(Domain : String; Msg : String; Category : Locale_Category) return String
is
function Internal
(Domain : String; Msg : String; Category : Locale_Category)
return chars_ptr;
pragma Import (C, Internal, "dcgettext");
P : chars_ptr :=
Internal (Domain & ASCII.NUL, Msg & ASCII.NUL, Category);
begin
if P = Null_Ptr then
return "";
else
return Value (P);
end if;
end Dcgettext;
--------------
-- Ngettext --
--------------
function Ngettext
(Msg1 : String; Msg2 : String; N : unsigned_long) return String
is
function Internal
(Msg1 : String; Msg2 : String; N : unsigned_long) return chars_ptr;
pragma Import (C, Internal, "ngettext");
P : chars_ptr :=
Internal (Msg1 & ASCII.NUL, Msg2 & ASCII.NUL, N);
begin
if P = Null_Ptr then
return "";
else
return Value (P);
end if;
end Ngettext;
---------------
-- Dngettext --
---------------
function Dngettext
(Domain : String;
Msg1 : String;
Msg2 : String;
N : unsigned_long) return String
is
function Internal
(Domain : String;
Msg1 : String;
Msg2 : String;
N : unsigned_long) return chars_ptr;
pragma Import (C, Internal, "dngettext");
P : chars_ptr :=
Internal (Domain & ASCII.NUL, Msg1 & ASCII.NUL, Msg2 & ASCII.NUL, N);
begin
if P = Null_Ptr then
return "";
else
return Value (P);
end if;
end Dngettext;
----------------
-- Dcngettext --
----------------
function Dcngettext
(Domain : String;
Msg1 : String;
Msg2 : String;
N : unsigned_long;
Category : Locale_Category) return String
is
function Internal
(Domain : String;
Msg1 : String;
Msg2 : String;
N : unsigned_long;
Category : Locale_Category) return chars_ptr;
pragma Import (C, Internal, "dcngettext");
P : chars_ptr :=
Internal
(Domain & ASCII.NUL,
Msg1 & ASCII.NUL,
Msg2 & ASCII.NUL,
N,
Category);
begin
if P = Null_Ptr then
return "";
else
return Value (P);
end if;
end Dcngettext;
-----------------
-- Text_Domain --
-----------------
procedure Text_Domain (Domain_Name : String) is
procedure Internal (Domain_Name : String);
pragma Import (C, Internal, "textdomain");
begin
Internal (Domain_Name & ASCII.NUL);
end Text_Domain;
-------------------------
-- Default_Text_Domain --
-------------------------
function Default_Text_Domain return String is
function Internal (Domain : chars_ptr) return chars_ptr;
pragma Import (C, Internal, "textdomain");
P : chars_ptr := Internal (Null_Ptr);
begin
if P = Null_Ptr then
return "";
else
return Value (P);
end if;
end Default_Text_Domain;
----------------------
-- Bind_Text_Domain --
----------------------
procedure Bind_Text_Domain (Domain_Name : String; Dirname : String) is
procedure Internal (Domain_Name, Dirname : String);
pragma Import (C, Internal, "bindtextdomain");
begin
Internal (Domain_Name & ASCII.NUL, Dirname & ASCII.NUL);
end Bind_Text_Domain;
---------------------------
-- Text_Domain_Directory --
---------------------------
function Text_Domain_Directory (Domain_Name : String) return String is
function Internal
(Domain_Name : String; Dirname : chars_ptr) return chars_ptr;
pragma Import (C, Internal, "bindtextdomain");
P : chars_ptr := Internal (Domain_Name & ASCII.NUL, Null_Ptr);
begin
if P = Null_Ptr then
return "";
else
return Value (P);
end if;
end Text_Domain_Directory;
------------------------------
-- Bind_Text_Domain_Codeset --
------------------------------
procedure Bind_Text_Domain_Codeset
(Domain_Name : String; Codeset : String)
is
procedure Internal (Domain_Name : String; Codeset : String);
pragma Import (C, Internal, "bind_textdomain_codeset");
begin
Internal (Domain_Name & ASCII.NUL, Codeset & ASCII.NUL);
end Bind_Text_Domain_Codeset;
-------------------------
-- Text_Domain_Codeset --
-------------------------
function Text_Domain_Codeset (Domain_Name : String) return String is
function Internal
(Domain_Name : String; Codeset : chars_ptr) return chars_ptr;
pragma Import (C, Internal, "bind_textdomain_codeset");
P : chars_ptr := Internal (Domain_Name & ASCII.NUL, Null_Ptr);
begin
if P = Null_Ptr then
return "";
else
return Value (P);
end if;
end Text_Domain_Codeset;
end I18n;
|
-- This spec has been automatically generated from STM32WL5x_CM0P.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.EXTI is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype RTSR1_RT_Field is HAL.UInt17;
subtype RTSR1_RT21_Field is HAL.UInt2;
-- rising trigger selection register
type RTSR1_Register is record
-- Rising trigger event configuration bit of Configurable Event input
RT : RTSR1_RT_Field := 16#0#;
-- unspecified
Reserved_17_20 : HAL.UInt4 := 16#0#;
-- Rising trigger event configuration bit of Configurable Event input
RT21 : RTSR1_RT21_Field := 16#0#;
-- unspecified
Reserved_23_31 : HAL.UInt9 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for RTSR1_Register use record
RT at 0 range 0 .. 16;
Reserved_17_20 at 0 range 17 .. 20;
RT21 at 0 range 21 .. 22;
Reserved_23_31 at 0 range 23 .. 31;
end record;
subtype FTSR1_FT_Field is HAL.UInt17;
subtype FTSR1_FT21_Field is HAL.UInt2;
-- falling trigger selection register
type FTSR1_Register is record
-- Falling trigger event configuration bit of Configurable Event input
FT : FTSR1_FT_Field := 16#0#;
-- unspecified
Reserved_17_20 : HAL.UInt4 := 16#0#;
-- Falling trigger event configuration bit of Configurable Event input
FT21 : FTSR1_FT21_Field := 16#0#;
-- unspecified
Reserved_23_31 : HAL.UInt9 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for FTSR1_Register use record
FT at 0 range 0 .. 16;
Reserved_17_20 at 0 range 17 .. 20;
FT21 at 0 range 21 .. 22;
Reserved_23_31 at 0 range 23 .. 31;
end record;
subtype SWIER1_SWI_Field is HAL.UInt17;
subtype SWIER1_SWI21_Field is HAL.UInt2;
-- software interrupt event register
type SWIER1_Register is record
-- Software interrupt on event
SWI : SWIER1_SWI_Field := 16#0#;
-- unspecified
Reserved_17_20 : HAL.UInt4 := 16#0#;
-- Software interrupt on event
SWI21 : SWIER1_SWI21_Field := 16#0#;
-- unspecified
Reserved_23_31 : HAL.UInt9 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for SWIER1_Register use record
SWI at 0 range 0 .. 16;
Reserved_17_20 at 0 range 17 .. 20;
SWI21 at 0 range 21 .. 22;
Reserved_23_31 at 0 range 23 .. 31;
end record;
subtype PR1_PIF_Field is HAL.UInt17;
subtype PR1_PIF21_Field is HAL.UInt2;
-- EXTI pending register
type PR1_Register is record
-- Configurable event inputs Pending bit
PIF : PR1_PIF_Field := 16#0#;
-- unspecified
Reserved_17_20 : HAL.UInt4 := 16#0#;
-- Configurable event inputs Pending bit
PIF21 : PR1_PIF21_Field := 16#0#;
-- unspecified
Reserved_23_31 : HAL.UInt9 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PR1_Register use record
PIF at 0 range 0 .. 16;
Reserved_17_20 at 0 range 17 .. 20;
PIF21 at 0 range 21 .. 22;
Reserved_23_31 at 0 range 23 .. 31;
end record;
-- RTSR2_RT array
type RTSR2_RT_Field_Array is array (40 .. 41) of Boolean
with Component_Size => 1, Size => 2;
-- Type definition for RTSR2_RT
type RTSR2_RT_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- RT as a value
Val : HAL.UInt2;
when True =>
-- RT as an array
Arr : RTSR2_RT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 2;
for RTSR2_RT_Field use record
Val at 0 range 0 .. 1;
Arr at 0 range 0 .. 1;
end record;
-- rising trigger selection register
type RTSR2_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- Rising trigger event configuration bit of Configurable Event input
RT34 : Boolean := False;
-- unspecified
Reserved_3_7 : HAL.UInt5 := 16#0#;
-- Rising trigger event configuration bit of Configurable Event input
RT : RTSR2_RT_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_10_12 : HAL.UInt3 := 16#0#;
-- Rising trigger event configuration bit of Configurable Event input
RT45 : Boolean := False;
-- unspecified
Reserved_14_31 : HAL.UInt18 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for RTSR2_Register use record
Reserved_0_1 at 0 range 0 .. 1;
RT34 at 0 range 2 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
RT at 0 range 8 .. 9;
Reserved_10_12 at 0 range 10 .. 12;
RT45 at 0 range 13 .. 13;
Reserved_14_31 at 0 range 14 .. 31;
end record;
-- FTSR2_FT array
type FTSR2_FT_Field_Array is array (40 .. 41) of Boolean
with Component_Size => 1, Size => 2;
-- Type definition for FTSR2_FT
type FTSR2_FT_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FT as a value
Val : HAL.UInt2;
when True =>
-- FT as an array
Arr : FTSR2_FT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 2;
for FTSR2_FT_Field use record
Val at 0 range 0 .. 1;
Arr at 0 range 0 .. 1;
end record;
-- falling trigger selection register
type FTSR2_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- Falling trigger event configuration bit of Configurable Event input
FT34 : Boolean := False;
-- unspecified
Reserved_3_7 : HAL.UInt5 := 16#0#;
-- Falling trigger event configuration bit of Configurable Event input
FT : FTSR2_FT_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_10_12 : HAL.UInt3 := 16#0#;
-- Falling trigger event configuration bit of Configurable Event input
FT45 : Boolean := False;
-- unspecified
Reserved_14_31 : HAL.UInt18 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for FTSR2_Register use record
Reserved_0_1 at 0 range 0 .. 1;
FT34 at 0 range 2 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
FT at 0 range 8 .. 9;
Reserved_10_12 at 0 range 10 .. 12;
FT45 at 0 range 13 .. 13;
Reserved_14_31 at 0 range 14 .. 31;
end record;
-- SWIER2_SWI array
type SWIER2_SWI_Field_Array is array (40 .. 41) of Boolean
with Component_Size => 1, Size => 2;
-- Type definition for SWIER2_SWI
type SWIER2_SWI_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- SWI as a value
Val : HAL.UInt2;
when True =>
-- SWI as an array
Arr : SWIER2_SWI_Field_Array;
end case;
end record
with Unchecked_Union, Size => 2;
for SWIER2_SWI_Field use record
Val at 0 range 0 .. 1;
Arr at 0 range 0 .. 1;
end record;
-- software interrupt event register
type SWIER2_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- Software interrupt on event
SWI34 : Boolean := False;
-- unspecified
Reserved_3_7 : HAL.UInt5 := 16#0#;
-- Software interrupt on event
SWI : SWIER2_SWI_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_10_12 : HAL.UInt3 := 16#0#;
-- Software interrupt on event 45
SWI45 : Boolean := False;
-- unspecified
Reserved_14_31 : HAL.UInt18 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for SWIER2_Register use record
Reserved_0_1 at 0 range 0 .. 1;
SWI34 at 0 range 2 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
SWI at 0 range 8 .. 9;
Reserved_10_12 at 0 range 10 .. 12;
SWI45 at 0 range 13 .. 13;
Reserved_14_31 at 0 range 14 .. 31;
end record;
-- PR2_PIF array
type PR2_PIF_Field_Array is array (40 .. 41) of Boolean
with Component_Size => 1, Size => 2;
-- Type definition for PR2_PIF
type PR2_PIF_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- PIF as a value
Val : HAL.UInt2;
when True =>
-- PIF as an array
Arr : PR2_PIF_Field_Array;
end case;
end record
with Unchecked_Union, Size => 2;
for PR2_PIF_Field use record
Val at 0 range 0 .. 1;
Arr at 0 range 0 .. 1;
end record;
-- pending register
type PR2_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- Configurable event inputs 33 Pending bit.
PIF34 : Boolean := False;
-- unspecified
Reserved_3_7 : HAL.UInt5 := 16#0#;
-- Configurable event inputs 40_41 Pending bit.
PIF : PR2_PIF_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_10_12 : HAL.UInt3 := 16#0#;
-- Configurable event inputs 45 Pending bit.
PIF45 : Boolean := False;
-- unspecified
Reserved_14_31 : HAL.UInt18 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PR2_Register use record
Reserved_0_1 at 0 range 0 .. 1;
PIF34 at 0 range 2 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
PIF at 0 range 8 .. 9;
Reserved_10_12 at 0 range 10 .. 12;
PIF45 at 0 range 13 .. 13;
Reserved_14_31 at 0 range 14 .. 31;
end record;
-- C1EMR1_EM array
type C1EMR1_EM_Field_Array is array (0 .. 15) of Boolean
with Component_Size => 1, Size => 16;
-- Type definition for C1EMR1_EM
type C1EMR1_EM_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- EM as a value
Val : HAL.UInt16;
when True =>
-- EM as an array
Arr : C1EMR1_EM_Field_Array;
end case;
end record
with Unchecked_Union, Size => 16;
for C1EMR1_EM_Field use record
Val at 0 range 0 .. 15;
Arr at 0 range 0 .. 15;
end record;
-- C1EMR1_EM array
type C1EMR1_EM_Field_Array_1 is array (17 .. 22) of Boolean
with Component_Size => 1, Size => 6;
-- Type definition for C1EMR1_EM
type C1EMR1_EM_Field_1
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- EM as a value
Val : HAL.UInt6;
when True =>
-- EM as an array
Arr : C1EMR1_EM_Field_Array_1;
end case;
end record
with Unchecked_Union, Size => 6;
for C1EMR1_EM_Field_1 use record
Val at 0 range 0 .. 5;
Arr at 0 range 0 .. 5;
end record;
-- event mask register
type C1EMR1_Register is record
-- Wakeup with event generation Mask on Event input
EM : C1EMR1_EM_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_16_16 : HAL.Bit := 16#0#;
-- Wakeup with event generation Mask on Event input
EM_1 : C1EMR1_EM_Field_1 := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_23_31 : HAL.UInt9 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for C1EMR1_Register use record
EM at 0 range 0 .. 15;
Reserved_16_16 at 0 range 16 .. 16;
EM_1 at 0 range 17 .. 22;
Reserved_23_31 at 0 range 23 .. 31;
end record;
-- C1IMR2_IM array
type C1IMR2_IM_Field_Array is array (36 .. 46) of Boolean
with Component_Size => 1, Size => 11;
-- Type definition for C1IMR2_IM
type C1IMR2_IM_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- IM as a value
Val : HAL.UInt11;
when True =>
-- IM as an array
Arr : C1IMR2_IM_Field_Array;
end case;
end record
with Unchecked_Union, Size => 11;
for C1IMR2_IM_Field use record
Val at 0 range 0 .. 10;
Arr at 0 range 0 .. 10;
end record;
-- wakeup with interrupt mask register
type C1IMR2_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- wakeup with interrupt mask on event input
IM34 : Boolean := False;
-- unspecified
Reserved_3_3 : HAL.Bit := 16#0#;
-- wakeup with interrupt mask on event input
IM : C1IMR2_IM_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_15_31 : HAL.UInt17 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for C1IMR2_Register use record
Reserved_0_1 at 0 range 0 .. 1;
IM34 at 0 range 2 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
IM at 0 range 4 .. 14;
Reserved_15_31 at 0 range 15 .. 31;
end record;
-- C1EMR2_EM array
type C1EMR2_EM_Field_Array is array (40 .. 41) of Boolean
with Component_Size => 1, Size => 2;
-- Type definition for C1EMR2_EM
type C1EMR2_EM_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- EM as a value
Val : HAL.UInt2;
when True =>
-- EM as an array
Arr : C1EMR2_EM_Field_Array;
end case;
end record
with Unchecked_Union, Size => 2;
for C1EMR2_EM_Field use record
Val at 0 range 0 .. 1;
Arr at 0 range 0 .. 1;
end record;
-- wakeup with event mask register
type C1EMR2_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#0#;
-- Wakeup with event generation Mask on Event input
EM : C1EMR2_EM_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_10_31 : HAL.UInt22 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for C1EMR2_Register use record
Reserved_0_7 at 0 range 0 .. 7;
EM at 0 range 8 .. 9;
Reserved_10_31 at 0 range 10 .. 31;
end record;
-- C2EMR1_EM array
type C2EMR1_EM_Field_Array is array (0 .. 15) of Boolean
with Component_Size => 1, Size => 16;
-- Type definition for C2EMR1_EM
type C2EMR1_EM_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- EM as a value
Val : HAL.UInt16;
when True =>
-- EM as an array
Arr : C2EMR1_EM_Field_Array;
end case;
end record
with Unchecked_Union, Size => 16;
for C2EMR1_EM_Field use record
Val at 0 range 0 .. 15;
Arr at 0 range 0 .. 15;
end record;
-- C2EMR1_EM array
type C2EMR1_EM_Field_Array_1 is array (17 .. 22) of Boolean
with Component_Size => 1, Size => 6;
-- Type definition for C2EMR1_EM
type C2EMR1_EM_Field_1
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- EM as a value
Val : HAL.UInt6;
when True =>
-- EM as an array
Arr : C2EMR1_EM_Field_Array_1;
end case;
end record
with Unchecked_Union, Size => 6;
for C2EMR1_EM_Field_1 use record
Val at 0 range 0 .. 5;
Arr at 0 range 0 .. 5;
end record;
-- event mask register
type C2EMR1_Register is record
-- Wakeup with event generation Mask on Event input
EM : C2EMR1_EM_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_16_16 : HAL.Bit := 16#0#;
-- Wakeup with event generation Mask on Event input
EM_1 : C2EMR1_EM_Field_1 := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_23_31 : HAL.UInt9 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for C2EMR1_Register use record
EM at 0 range 0 .. 15;
Reserved_16_16 at 0 range 16 .. 16;
EM_1 at 0 range 17 .. 22;
Reserved_23_31 at 0 range 23 .. 31;
end record;
-- C2IMR2_IM array
type C2IMR2_IM_Field_Array is array (36 .. 46) of Boolean
with Component_Size => 1, Size => 11;
-- Type definition for C2IMR2_IM
type C2IMR2_IM_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- IM as a value
Val : HAL.UInt11;
when True =>
-- IM as an array
Arr : C2IMR2_IM_Field_Array;
end case;
end record
with Unchecked_Union, Size => 11;
for C2IMR2_IM_Field use record
Val at 0 range 0 .. 10;
Arr at 0 range 0 .. 10;
end record;
-- wakeup with interrupt mask register
type C2IMR2_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- wakeup with interrupt mask on event input
IM34 : Boolean := False;
-- unspecified
Reserved_3_3 : HAL.Bit := 16#0#;
-- wakeup with interrupt mask on event input
IM : C2IMR2_IM_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_15_31 : HAL.UInt17 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for C2IMR2_Register use record
Reserved_0_1 at 0 range 0 .. 1;
IM34 at 0 range 2 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
IM at 0 range 4 .. 14;
Reserved_15_31 at 0 range 15 .. 31;
end record;
-- C2EMR2_EM array
type C2EMR2_EM_Field_Array is array (40 .. 41) of Boolean
with Component_Size => 1, Size => 2;
-- Type definition for C2EMR2_EM
type C2EMR2_EM_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- EM as a value
Val : HAL.UInt2;
when True =>
-- EM as an array
Arr : C2EMR2_EM_Field_Array;
end case;
end record
with Unchecked_Union, Size => 2;
for C2EMR2_EM_Field use record
Val at 0 range 0 .. 1;
Arr at 0 range 0 .. 1;
end record;
-- wakeup with event mask register
type C2EMR2_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#0#;
-- Wakeup with event generation Mask on Event input
EM : C2EMR2_EM_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_10_31 : HAL.UInt22 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for C2EMR2_Register use record
Reserved_0_7 at 0 range 0 .. 7;
EM at 0 range 8 .. 9;
Reserved_10_31 at 0 range 10 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- External interrupt/event controller
type EXTI_Peripheral is record
-- rising trigger selection register
RTSR1 : aliased RTSR1_Register;
-- falling trigger selection register
FTSR1 : aliased FTSR1_Register;
-- software interrupt event register
SWIER1 : aliased SWIER1_Register;
-- EXTI pending register
PR1 : aliased PR1_Register;
-- rising trigger selection register
RTSR2 : aliased RTSR2_Register;
-- falling trigger selection register
FTSR2 : aliased FTSR2_Register;
-- software interrupt event register
SWIER2 : aliased SWIER2_Register;
-- pending register
PR2 : aliased PR2_Register;
-- interrupt mask register
C1IMR1 : aliased HAL.UInt32;
-- event mask register
C1EMR1 : aliased C1EMR1_Register;
-- wakeup with interrupt mask register
C1IMR2 : aliased C1IMR2_Register;
-- wakeup with event mask register
C1EMR2 : aliased C1EMR2_Register;
-- interrupt mask register
C2IMR1 : aliased HAL.UInt32;
-- event mask register
C2EMR1 : aliased C2EMR1_Register;
-- wakeup with interrupt mask register
C2IMR2 : aliased C2IMR2_Register;
-- wakeup with event mask register
C2EMR2 : aliased C2EMR2_Register;
end record
with Volatile;
for EXTI_Peripheral use record
RTSR1 at 16#0# range 0 .. 31;
FTSR1 at 16#4# range 0 .. 31;
SWIER1 at 16#8# range 0 .. 31;
PR1 at 16#C# range 0 .. 31;
RTSR2 at 16#20# range 0 .. 31;
FTSR2 at 16#24# range 0 .. 31;
SWIER2 at 16#28# range 0 .. 31;
PR2 at 16#2C# range 0 .. 31;
C1IMR1 at 16#80# range 0 .. 31;
C1EMR1 at 16#84# range 0 .. 31;
C1IMR2 at 16#90# range 0 .. 31;
C1EMR2 at 16#94# range 0 .. 31;
C2IMR1 at 16#C0# range 0 .. 31;
C2EMR1 at 16#C4# range 0 .. 31;
C2IMR2 at 16#D0# range 0 .. 31;
C2EMR2 at 16#D4# range 0 .. 31;
end record;
-- External interrupt/event controller
EXTI_Periph : aliased EXTI_Peripheral
with Import, Address => EXTI_Base;
end STM32_SVD.EXTI;
|
------------------------------------------------------------------------------
-- --
-- Ada User Repository Annex (AURA) --
-- ANNEXI-STRAYLINE Reference Implementation --
-- --
-- Command Line Interface --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2020, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * Richard Wai (ANNEXI-STRAYLINE) --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- --
-- * Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A --
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
separate (Specification_Scanner)
procedure Scan_Generic
(Buffer : in out Ada_Lexical_Parser.Source_Buffer;
Unit_Tree: in out Declaration_Trees.Tree;
Root : in Declaration_Trees.Cursor)
is
use Ada_Lexical_Parser;
use Declaration_Trees;
package Toolkit is new Parse_Toolkit (Buffer); use Toolkit;
use type WWU.Unbounded_Wide_Wide_String;
begin
Unit_Tree(Root).Is_Generic := True;
-- Try to keep this as simple as possible, for now we really don't need
-- this information to generate the configuration extractor programs.
loop
Skip_To_Semicolon;
Next_Element;
exit when Category = Reserved_Word
and then Content in "package" | "procedure" | "function";
end loop;
if Content = "package" then
Scan_Specification (Buffer => Buffer,
Unit_Tree => Unit_Tree,
Root => Root);
elsif Content in "procedure" | "function" then
Scan_Subprogram (Buffer => Buffer,
Unit_Tree => Unit_Tree,
Subprogram_Node => Root);
end if;
end Scan_Generic;
|
pragma License (Unrestricted);
private with System.Shared_Locking; -- implementation unit
package GNAT.Task_Lock is
pragma Preelaborate;
procedure Lock;
procedure Unlock;
pragma Inline (Lock); -- renamed
pragma Inline (Unlock); -- renamed
private
procedure Lock
renames System.Shared_Locking.Enter;
procedure Unlock
renames System.Shared_Locking.Leave;
end GNAT.Task_Lock;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- A D A . I N T E R R U P T S . N A M E S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1991-2014, Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
------------------------------------------------------------------------------
-- This is a GNU/Linux version of this package
-- The following signals are reserved by the run time:
-- SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGTRAP, SIGABRT, SIGINT,
-- SIGUSR1, SIGUSR2, SIGVTALRM, SIGUNUSED, SIGSTOP, SIGKILL
-- The pragma Unreserve_All_Interrupts affects the following signal(s):
-- SIGINT: made available for Ada handler
-- This target-dependent package spec contains names of interrupts
-- supported by the local system.
with System.OS_Interface;
package Ada.Interrupts.Names is
-- All identifiers in this unit are implementation defined
pragma Implementation_Defined;
-- Beware that the mapping of names to signals may be many-to-one. There
-- may be aliases. Also, for all signal names that are not supported on the
-- current system the value of the corresponding constant will be zero.
SIGHUP : constant Interrupt_ID :=
System.OS_Interface.SIGHUP; -- hangup
SIGINT : constant Interrupt_ID :=
System.OS_Interface.SIGINT; -- interrupt (rubout)
SIGQUIT : constant Interrupt_ID :=
System.OS_Interface.SIGQUIT; -- quit (ASCD FS)
SIGILL : constant Interrupt_ID :=
System.OS_Interface.SIGILL; -- illegal instruction (not reset)
SIGTRAP : constant Interrupt_ID :=
System.OS_Interface.SIGTRAP; -- trace trap (not reset)
SIGIOT : constant Interrupt_ID :=
System.OS_Interface.SIGIOT; -- IOT instruction
SIGABRT : constant Interrupt_ID := -- used by abort,
System.OS_Interface.SIGABRT; -- replace SIGIOT in the future
SIGFPE : constant Interrupt_ID :=
System.OS_Interface.SIGFPE; -- floating point exception
SIGKILL : constant Interrupt_ID :=
System.OS_Interface.SIGKILL; -- kill (cannot be caught or ignored)
SIGBUS : constant Interrupt_ID :=
System.OS_Interface.SIGBUS; -- bus error
SIGSEGV : constant Interrupt_ID :=
System.OS_Interface.SIGSEGV; -- segmentation violation
SIGPIPE : constant Interrupt_ID := -- write on a pipe with
System.OS_Interface.SIGPIPE; -- no one to read it
SIGALRM : constant Interrupt_ID :=
System.OS_Interface.SIGALRM; -- alarm clock
SIGTERM : constant Interrupt_ID :=
System.OS_Interface.SIGTERM; -- software termination signal from kill
SIGUSR1 : constant Interrupt_ID :=
System.OS_Interface.SIGUSR1; -- user defined signal 1
SIGUSR2 : constant Interrupt_ID :=
System.OS_Interface.SIGUSR2; -- user defined signal 2
SIGCLD : constant Interrupt_ID :=
System.OS_Interface.SIGCLD; -- child status change
SIGCHLD : constant Interrupt_ID :=
System.OS_Interface.SIGCHLD; -- 4.3BSD's/POSIX name for SIGCLD
SIGWINCH : constant Interrupt_ID :=
System.OS_Interface.SIGWINCH; -- window size change
SIGURG : constant Interrupt_ID :=
System.OS_Interface.SIGURG; -- urgent condition on IO channel
SIGPOLL : constant Interrupt_ID :=
System.OS_Interface.SIGPOLL; -- pollable event occurred
SIGIO : constant Interrupt_ID := -- input/output possible,
System.OS_Interface.SIGIO; -- SIGPOLL alias (Solaris)
SIGSTOP : constant Interrupt_ID :=
System.OS_Interface.SIGSTOP; -- stop (cannot be caught or ignored)
SIGTSTP : constant Interrupt_ID :=
System.OS_Interface.SIGTSTP; -- user stop requested from tty
SIGCONT : constant Interrupt_ID :=
System.OS_Interface.SIGCONT; -- stopped process has been continued
SIGTTIN : constant Interrupt_ID :=
System.OS_Interface.SIGTTIN; -- background tty read attempted
SIGTTOU : constant Interrupt_ID :=
System.OS_Interface.SIGTTOU; -- background tty write attempted
SIGVTALRM : constant Interrupt_ID :=
System.OS_Interface.SIGVTALRM; -- virtual timer expired
SIGPROF : constant Interrupt_ID :=
System.OS_Interface.SIGPROF; -- profiling timer expired
SIGXCPU : constant Interrupt_ID :=
System.OS_Interface.SIGXCPU; -- CPU time limit exceeded
SIGXFSZ : constant Interrupt_ID :=
System.OS_Interface.SIGXFSZ; -- filesize limit exceeded
SIGUNUSED : constant Interrupt_ID :=
System.OS_Interface.SIGUNUSED; -- unused signal
SIGSTKFLT : constant Interrupt_ID :=
System.OS_Interface.SIGSTKFLT; -- stack fault on coprocessor
SIGLOST : constant Interrupt_ID :=
System.OS_Interface.SIGLOST; -- Linux alias for SIGIO
SIGPWR : constant Interrupt_ID :=
System.OS_Interface.SIGPWR; -- Power failure
end Ada.Interrupts.Names;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- S Y S T E M . C R C 3 2 --
-- --
-- B o d y --
-- --
-- Copyright (C) 2001-2021, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
pragma Compiler_Unit_Warning;
package body System.CRC32 is
Init : constant CRC32 := 16#FFFF_FFFF#; -- Initial value
XorOut : constant CRC32 := 16#FFFF_FFFF#; -- To compute final result.
-- The following table contains precomputed values for contributions
-- from various possible byte values. Doing a table lookup is quicker
-- than processing the byte bit by bit.
Table : constant array (CRC32 range 0 .. 255) of CRC32 :=
(16#0000_0000#, 16#7707_3096#, 16#EE0E_612C#, 16#9909_51BA#,
16#076D_C419#, 16#706A_F48F#, 16#E963_A535#, 16#9E64_95A3#,
16#0EDB_8832#, 16#79DC_B8A4#, 16#E0D5_E91E#, 16#97D2_D988#,
16#09B6_4C2B#, 16#7EB1_7CBD#, 16#E7B8_2D07#, 16#90BF_1D91#,
16#1DB7_1064#, 16#6AB0_20F2#, 16#F3B9_7148#, 16#84BE_41DE#,
16#1ADA_D47D#, 16#6DDD_E4EB#, 16#F4D4_B551#, 16#83D3_85C7#,
16#136C_9856#, 16#646B_A8C0#, 16#FD62_F97A#, 16#8A65_C9EC#,
16#1401_5C4F#, 16#6306_6CD9#, 16#FA0F_3D63#, 16#8D08_0DF5#,
16#3B6E_20C8#, 16#4C69_105E#, 16#D560_41E4#, 16#A267_7172#,
16#3C03_E4D1#, 16#4B04_D447#, 16#D20D_85FD#, 16#A50A_B56B#,
16#35B5_A8FA#, 16#42B2_986C#, 16#DBBB_C9D6#, 16#ACBC_F940#,
16#32D8_6CE3#, 16#45DF_5C75#, 16#DCD6_0DCF#, 16#ABD1_3D59#,
16#26D9_30AC#, 16#51DE_003A#, 16#C8D7_5180#, 16#BFD0_6116#,
16#21B4_F4B5#, 16#56B3_C423#, 16#CFBA_9599#, 16#B8BD_A50F#,
16#2802_B89E#, 16#5F05_8808#, 16#C60C_D9B2#, 16#B10B_E924#,
16#2F6F_7C87#, 16#5868_4C11#, 16#C161_1DAB#, 16#B666_2D3D#,
16#76DC_4190#, 16#01DB_7106#, 16#98D2_20BC#, 16#EFD5_102A#,
16#71B1_8589#, 16#06B6_B51F#, 16#9FBF_E4A5#, 16#E8B8_D433#,
16#7807_C9A2#, 16#0F00_F934#, 16#9609_A88E#, 16#E10E_9818#,
16#7F6A_0DBB#, 16#086D_3D2D#, 16#9164_6C97#, 16#E663_5C01#,
16#6B6B_51F4#, 16#1C6C_6162#, 16#8565_30D8#, 16#F262_004E#,
16#6C06_95ED#, 16#1B01_A57B#, 16#8208_F4C1#, 16#F50F_C457#,
16#65B0_D9C6#, 16#12B7_E950#, 16#8BBE_B8EA#, 16#FCB9_887C#,
16#62DD_1DDF#, 16#15DA_2D49#, 16#8CD3_7CF3#, 16#FBD4_4C65#,
16#4DB2_6158#, 16#3AB5_51CE#, 16#A3BC_0074#, 16#D4BB_30E2#,
16#4ADF_A541#, 16#3DD8_95D7#, 16#A4D1_C46D#, 16#D3D6_F4FB#,
16#4369_E96A#, 16#346E_D9FC#, 16#AD67_8846#, 16#DA60_B8D0#,
16#4404_2D73#, 16#3303_1DE5#, 16#AA0A_4C5F#, 16#DD0D_7CC9#,
16#5005_713C#, 16#2702_41AA#, 16#BE0B_1010#, 16#C90C_2086#,
16#5768_B525#, 16#206F_85B3#, 16#B966_D409#, 16#CE61_E49F#,
16#5EDE_F90E#, 16#29D9_C998#, 16#B0D0_9822#, 16#C7D7_A8B4#,
16#59B3_3D17#, 16#2EB4_0D81#, 16#B7BD_5C3B#, 16#C0BA_6CAD#,
16#EDB8_8320#, 16#9ABF_B3B6#, 16#03B6_E20C#, 16#74B1_D29A#,
16#EAD5_4739#, 16#9DD2_77AF#, 16#04DB_2615#, 16#73DC_1683#,
16#E363_0B12#, 16#9464_3B84#, 16#0D6D_6A3E#, 16#7A6A_5AA8#,
16#E40E_CF0B#, 16#9309_FF9D#, 16#0A00_AE27#, 16#7D07_9EB1#,
16#F00F_9344#, 16#8708_A3D2#, 16#1E01_F268#, 16#6906_C2FE#,
16#F762_575D#, 16#8065_67CB#, 16#196C_3671#, 16#6E6B_06E7#,
16#FED4_1B76#, 16#89D3_2BE0#, 16#10DA_7A5A#, 16#67DD_4ACC#,
16#F9B9_DF6F#, 16#8EBE_EFF9#, 16#17B7_BE43#, 16#60B0_8ED5#,
16#D6D6_A3E8#, 16#A1D1_937E#, 16#38D8_C2C4#, 16#4FDF_F252#,
16#D1BB_67F1#, 16#A6BC_5767#, 16#3FB5_06DD#, 16#48B2_364B#,
16#D80D_2BDA#, 16#AF0A_1B4C#, 16#3603_4AF6#, 16#4104_7A60#,
16#DF60_EFC3#, 16#A867_DF55#, 16#316E_8EEF#, 16#4669_BE79#,
16#CB61_B38C#, 16#BC66_831A#, 16#256F_D2A0#, 16#5268_E236#,
16#CC0C_7795#, 16#BB0B_4703#, 16#2202_16B9#, 16#5505_262F#,
16#C5BA_3BBE#, 16#B2BD_0B28#, 16#2BB4_5A92#, 16#5CB3_6A04#,
16#C2D7_FFA7#, 16#B5D0_CF31#, 16#2CD9_9E8B#, 16#5BDE_AE1D#,
16#9B64_C2B0#, 16#EC63_F226#, 16#756A_A39C#, 16#026D_930A#,
16#9C09_06A9#, 16#EB0E_363F#, 16#7207_6785#, 16#0500_5713#,
16#95BF_4A82#, 16#E2B8_7A14#, 16#7BB1_2BAE#, 16#0CB6_1B38#,
16#92D2_8E9B#, 16#E5D5_BE0D#, 16#7CDC_EFB7#, 16#0BDB_DF21#,
16#86D3_D2D4#, 16#F1D4_E242#, 16#68DD_B3F8#, 16#1FDA_836E#,
16#81BE_16CD#, 16#F6B9_265B#, 16#6FB0_77E1#, 16#18B7_4777#,
16#8808_5AE6#, 16#FF0F_6A70#, 16#6606_3BCA#, 16#1101_0B5C#,
16#8F65_9EFF#, 16#F862_AE69#, 16#616B_FFD3#, 16#166C_CF45#,
16#A00A_E278#, 16#D70D_D2EE#, 16#4E04_8354#, 16#3903_B3C2#,
16#A767_2661#, 16#D060_16F7#, 16#4969_474D#, 16#3E6E_77DB#,
16#AED1_6A4A#, 16#D9D6_5ADC#, 16#40DF_0B66#, 16#37D8_3BF0#,
16#A9BC_AE53#, 16#DEBB_9EC5#, 16#47B2_CF7F#, 16#30B5_FFE9#,
16#BDBD_F21C#, 16#CABA_C28A#, 16#53B3_9330#, 16#24B4_A3A6#,
16#BAD0_3605#, 16#CDD7_0693#, 16#54DE_5729#, 16#23D9_67BF#,
16#B366_7A2E#, 16#C461_4AB8#, 16#5D68_1B02#, 16#2A6F_2B94#,
16#B40B_BE37#, 16#C30C_8EA1#, 16#5A05_DF1B#, 16#2D02_EF8D#);
---------------
-- Get_Value --
---------------
function Get_Value (C : CRC32) return Interfaces.Unsigned_32 is
begin
return Interfaces.Unsigned_32 (C xor XorOut);
end Get_Value;
----------------
-- Initialize --
----------------
procedure Initialize (C : out CRC32) is
begin
C := Init;
end Initialize;
------------
-- Update --
------------
procedure Update (C : in out CRC32; Value : Character) is
V : constant CRC32 := CRC32 (Character'Pos (Value));
begin
C := Shift_Right (C, 8) xor Table (V xor (C and 16#0000_00FF#));
end Update;
end System.CRC32;
|
package Natools.Static_Maps.S_Expressions.Templates.Dates.Cmds is
pragma Pure;
function Hash (S : String) return Natural;
end Natools.Static_Maps.S_Expressions.Templates.Dates.Cmds;
|
-- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces.C;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_glx_gen_queries_arb_cookie_t is
-- Item
--
type Item is record
sequence : aliased Interfaces.C.unsigned;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_glx_gen_queries_arb_cookie_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_gen_queries_arb_cookie_t.Item,
Element_Array => xcb.xcb_glx_gen_queries_arb_cookie_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_glx_gen_queries_arb_cookie_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_gen_queries_arb_cookie_t.Pointer,
Element_Array => xcb.xcb_glx_gen_queries_arb_cookie_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_glx_gen_queries_arb_cookie_t;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012-2013, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.OCL.Call_Exps;
limited with AMF.OCL.Ocl_Expressions;
limited with AMF.OCL.Variables.Collections;
package AMF.OCL.Loop_Exps is
pragma Preelaborate;
type OCL_Loop_Exp is limited interface
and AMF.OCL.Call_Exps.OCL_Call_Exp;
type OCL_Loop_Exp_Access is
access all OCL_Loop_Exp'Class;
for OCL_Loop_Exp_Access'Storage_Size use 0;
not overriding function Get_Body
(Self : not null access constant OCL_Loop_Exp)
return AMF.OCL.Ocl_Expressions.OCL_Ocl_Expression_Access is abstract;
-- Getter of LoopExp::body.
--
not overriding procedure Set_Body
(Self : not null access OCL_Loop_Exp;
To : AMF.OCL.Ocl_Expressions.OCL_Ocl_Expression_Access) is abstract;
-- Setter of LoopExp::body.
--
not overriding function Get_Iterator
(Self : not null access constant OCL_Loop_Exp)
return AMF.OCL.Variables.Collections.Ordered_Set_Of_OCL_Variable is abstract;
-- Getter of LoopExp::iterator.
--
end AMF.OCL.Loop_Exps;
|
with RASCAL.Utility; use RASCAL.Utility;
with RASCAL.Heap; use RASCAL.Heap;
package AcronymList is
------------------------------------------------------------------------
-- | Generic ADT for one-way linked lists
-- | Author: Michael B. Feldman, The George Washington University
-- | Last Modified: January 1996
------------------------------------------------------------------------
-- exported types
type Meaning_Type is
record
Category: UString;
Buffer : Heap_Block_Pointer;
FileSize: natural;
end record;
type Meaning_Pointer is access Meaning_Type;
type Position is private;
type List is limited private;
type ListPointer is access List;
-- exported exceptions
OutOfSpace : exception; -- raised if no space left for a new node
PastEnd : exception; -- raised if a Position is past the end
PastBegin : exception; -- raised if a Position is before the begin
EmptyList : exception;
-- basic constructors
procedure AddToRear (L : in out List; X : Meaning_Pointer);
-- Pre: L and X are defined
-- Post: a node containing X is inserted
-- at the front or rear of L, respectively
-- basic selectors
function First (L : List) return Position;
function Retrieve (L : in List; P : in Position)
return Meaning_Pointer;
-- Pre: L and P are defined; P designates a node in L
-- Post: returns the value of the element at position P
-- Raises: EmptyList if L is empty
-- PastBegin if P points before the beginning of L
-- PastEnd if P points beyond the end of L
-- other constructors
procedure Delete (L : in out List; P : Position);
-- Pre: L and P are defined; P designates a node in L
-- Post: the node at position P of L is deleted
-- Raises: EmptyList if L is empty
-- PastBegin if P is NULL
-- iterator operations
procedure GoAhead (L : List; P : in out Position);
-- Pre: L and P are defined; P designates a node in L
-- Post: P is advanced to designate the next node of L
-- Raises: EmptyList if L is empty
-- PastEnd if P points beyond the end of L
procedure GoBack (L : List; P : in out Position);
-- Pre: L and P are defined; P designates a node in L
-- Post: P is moved to designate the previous node of L
-- Raises: EmptyList if L is empty
-- PastBegin if P points beyond the end of L
-- inquiry operators
function IsEmpty (L : List) return Boolean;
function IsFirst (L : List; P : Position) return Boolean;
function IsLast (L : List; P : Position) return Boolean;
function IsPastEnd (L : List; P : Position) return Boolean;
function IsPastBegin (L : List; P : Position) return Boolean;
-- Pre: L and P are defined
-- Post: return True if the condition is met; False otherwise
private
type Node;
type Position is access Node;
type Node is record
Info : Meaning_Pointer;
Link : Position;
end record;
type List is record
Head : Position;
Tail : Position;
end record;
end AcronymList;
|
pragma Ada_2005;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Interfaces.C; use Interfaces.C;
-- with GStreamer.GST_Low_Level.glib_2_0_glib_gquark_h;
with glib;
with System;
with glib;
with glib.Values;
with System;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h;
package GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstparse_h is
-- unsupported macro: GST_PARSE_ERROR gst_parse_error_quark ()
-- unsupported macro: GST_TYPE_PARSE_CONTEXT (gst_parse_context_get_type())
-- GStreamer
-- * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
-- * 2000 Wim Taymans <wtay@chello.be>
-- *
-- * gstparse.h: get a pipeline from a text pipeline description
-- *
-- * This library is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU Library General Public
-- * License as published by the Free Software Foundation; either
-- * version 2 of the License, or (at your option) any later version.
-- *
-- * This library is distributed in the hope that it will be useful,
-- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- * Library General Public License for more details.
-- *
-- * You should have received a copy of the GNU Library General Public
-- * License along with this library; if not, write to the
-- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- * Boston, MA 02111-1307, USA.
--
function gst_parse_error_quark return Glib.GQuark; -- gst/gstparse.h:30
pragma Import (C, gst_parse_error_quark, "gst_parse_error_quark");
--*
-- * GST_PARSE_ERROR:
-- *
-- * Get access to the error quark of the parse subsystem.
--
--*
-- * GstParseError:
-- * @GST_PARSE_ERROR_SYNTAX: A syntax error occured.
-- * @GST_PARSE_ERROR_NO_SUCH_ELEMENT: The description contained an unknown element
-- * @GST_PARSE_ERROR_NO_SUCH_PROPERTY: An element did not have a specified property
-- * @GST_PARSE_ERROR_LINK: There was an error linking two pads.
-- * @GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY: There was an error setting a property
-- * @GST_PARSE_ERROR_EMPTY_BIN: An empty bin was specified.
-- * @GST_PARSE_ERROR_EMPTY: An empty description was specified
-- *
-- * The different parsing errors that can occur.
--
type GstParseError is
(GST_PARSE_ERROR_SYNTAX,
GST_PARSE_ERROR_NO_SUCH_ELEMENT,
GST_PARSE_ERROR_NO_SUCH_PROPERTY,
GST_PARSE_ERROR_LINK,
GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
GST_PARSE_ERROR_EMPTY_BIN,
GST_PARSE_ERROR_EMPTY);
pragma Convention (C, GstParseError); -- gst/gstparse.h:59
--*
-- * GstParseFlags:
-- * @GST_PARSE_FLAG_NONE: Do not use any special parsing options.
-- * @GST_PARSE_FLAG_FATAL_ERRORS: Always return NULL when an error occurs
-- * (default behaviour is to return partially constructed bins or elements
-- * in some cases)
-- *
-- * Parsing options.
-- *
-- * Since: 0.10.20
--
type GstParseFlags is
(GST_PARSE_FLAG_NONE,
GST_PARSE_FLAG_FATAL_ERRORS);
pragma Convention (C, GstParseFlags); -- gst/gstparse.h:76
--*
-- * GstParseContext:
-- *
-- * Opaque structure.
-- *
-- * Since: 0.10.20
--
-- skipped empty struct u_GstParseContext
-- skipped empty struct GstParseContext
-- create, process and free a parse context
function gst_parse_context_get_type return GLIB.GType; -- gst/gstparse.h:91
pragma Import (C, gst_parse_context_get_type, "gst_parse_context_get_type");
function gst_parse_context_new return System.Address; -- gst/gstparse.h:92
pragma Import (C, gst_parse_context_new, "gst_parse_context_new");
function gst_parse_context_get_missing_elements (context : System.Address) return System.Address; -- gst/gstparse.h:94
pragma Import (C, gst_parse_context_get_missing_elements, "gst_parse_context_get_missing_elements");
procedure gst_parse_context_free (context : System.Address); -- gst/gstparse.h:96
pragma Import (C, gst_parse_context_free, "gst_parse_context_free");
-- parse functions
function gst_parse_launch (pipeline_description : access GLIB.gchar; error : System.Address) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h.GstElement; -- gst/gstparse.h:101
pragma Import (C, gst_parse_launch, "gst_parse_launch");
function gst_parse_launchv (argv : System.Address; error : System.Address) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h.GstElement; -- gst/gstparse.h:104
pragma Import (C, gst_parse_launchv, "gst_parse_launchv");
function gst_parse_launch_full
(pipeline_description : access GLIB.gchar;
context : System.Address;
flags : GstParseFlags;
error : System.Address) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h.GstElement; -- gst/gstparse.h:107
pragma Import (C, gst_parse_launch_full, "gst_parse_launch_full");
function gst_parse_launchv_full
(argv : System.Address;
context : System.Address;
flags : GstParseFlags;
error : System.Address) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h.GstElement; -- gst/gstparse.h:112
pragma Import (C, gst_parse_launchv_full, "gst_parse_launchv_full");
end GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstparse_h;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- A D A . F I N A L I Z A T I O N --
-- --
-- B o d y --
-- --
-- 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, 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.Finalization_Root; use System.Finalization_Root;
package body Ada.Finalization is
---------
-- "=" --
---------
function "=" (A, B : Controlled) return Boolean is
begin
return Empty_Root_Controlled (A) = Empty_Root_Controlled (B);
end "=";
------------
-- Adjust --
------------
procedure Adjust (Object : in out Controlled) is
pragma Warnings (Off, Object);
begin
null;
end Adjust;
--------------
-- Finalize --
--------------
procedure Finalize (Object : in out Controlled) is
pragma Warnings (Off, Object);
begin
null;
end Finalize;
procedure Finalize (Object : in out Limited_Controlled) is
pragma Warnings (Off, Object);
begin
null;
end Finalize;
----------------
-- Initialize --
----------------
procedure Initialize (Object : in out Controlled) is
pragma Warnings (Off, Object);
begin
null;
end Initialize;
procedure Initialize (Object : in out Limited_Controlled) is
pragma Warnings (Off, Object);
begin
null;
end Initialize;
end Ada.Finalization;
|
------------------------------------------------------------------------------
-- A d a r u n - t i m e s p e c i f i c a t i o n --
-- ASIS implementation for Gela project, a portable Ada compiler --
-- http://gela.ada-ru.org --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license at the end of ada.ads file --
------------------------------------------------------------------------------
-- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $
package Ada.Streams is
pragma Pure (Streams);
type Root_Stream_Type is abstract tagged limited private;
pragma Preelaborable_Initialization (Root_Stream_Type);
type Stream_Element is mod implementation-defined;
type Stream_Element_Offset is range
implementation-defined .. implementation-defined;
subtype Stream_Element_Count is
Stream_Element_Offset range 0..Stream_Element_Offset'Last;
type Stream_Element_Array is
array (Stream_Element_Offset range <>) of aliased Stream_Element;
procedure Read (Stream : in out Root_Stream_Type;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset) is abstract;
procedure Write (Stream : in out Root_Stream_Type;
Item : in Stream_Element_Array) is abstract;
private
pragma Import (Ada, Root_Stream_Type);
end Ada.Streams;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2021, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
package USB.Logging is
end USB.Logging;
|
-- Copyright (c) 2015-2019 Marcel Schneider
-- for details see License.txt
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
-- with Ada.Strings; use Ada.Strings;
with Ada.Text_IO; use Ada.Text_IO;
with Punctuation; use Punctuation;
package body Lexer_Base is
procedure OpenFile (O : in out Object;
File_Name : String) is
B : Boolean;
begin
O.File_Name := To_Unbounded_String (File_Name);
B := IsPunctuation('.');
Put_Line(Boolean'Image(B));
end OpenFile;
function ReadToken (O : Object) return TokenValue.Object is
TO : TokenValue.Object;
begin
return TO;
end ReadToken;
function ReadWhiteSpace return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadWhiteSpace;
function ReadString return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadString;
function ReadLineComment return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadLineComment;
function ReadBlockComment return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadBlockComment;
function ReadRegEx return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadRegEx;
function ReadOperator return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadOperator;
function ReadNumber return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadNumber;
function IsPunctuationUsed (C : Character) return Boolean is
-- B : Boolean;
begin
return false;
end IsPunctuationUsed;
function SetNumberPunctuation (C : Character;
IsHexNumber : Boolean) return Boolean is
begin
return false;
end SetNumberPunctuation;
function ReadIdentifier return TokenValue.Object is
O : TokenValue.Object;
C : Character;
P : Punctuation.Object;
begin
while True loop
C := Peek;
if IsName(C) OR IsDigit(C) then
C := Advance;
else
if P.FutureReservedWords.Contains(To_Unbounded_String("")) then
return O;
end if;
if P.Keywords.Contains(To_Unbounded_String("")) then
return O;
end if;
return O;
end if;
end loop;
-- return O;
end ReadIdentifier;
function IsName (C : Character) return Boolean is
begin
return (C >= 'a' AND C <= 'z')
OR (C >= 'A' AND C <= 'Z')
OR C = '$'
OR C = '_';
end IsName;
function IsOperator (C : Character) return Boolean is
Op : constant String := "~!%^&*/-=+|/?<>:";
I : Integer := 1;
begin
while I <= Op'Length loop
if (Op(I) = C) then
return true;
end if;
I := I + 1;
end loop;
return false;
end IsOperator;
function IsDigit (C : Character) return Boolean is
begin
return C >= '0' AND C <= '9';
end IsDigit;
function IsPunctuation (C : Character) return Boolean is
P : constant String := "(){}[];,.";
I : Integer := 1;
begin
while I <= P'Length loop
if (P(I) = C) then
return true;
end if;
I := I + 1;
end loop;
return false;
end IsPunctuation;
function Peek return Character is
C : Character;
begin
return C;
end Peek;
function Advance return Character is
C : Character;
begin
return C;
end Advance;
function CreateToken (TokenId : Token;
Literal : Unbounded_String;
Message : Unbounded_String) return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end CreateToken;
function CreatePosition return Position.Object is
O : Position.Object;
begin
return O;
end CreatePosition;
end Lexer_Base;
|
----------------------------------------------------------------
-- ZLib for Ada thick binding. --
-- --
-- Copyright (C) 2002-2004 Dmitriy Anisimkov --
-- --
-- Open source license information is in the zlib.ads file. --
----------------------------------------------------------------
--
-- $Id: buffer_demo.adb,v 1.2 2020/09/15 02:05:31 christos Exp $
-- This demo program provided by Dr Steve Sangwine <sjs@essex.ac.uk>
--
-- Demonstration of a problem with Zlib-Ada (already fixed) when a buffer
-- of exactly the correct size is used for decompressed data, and the last
-- few bytes passed in to Zlib are checksum bytes.
-- This program compresses a string of text, and then decompresses the
-- compressed text into a buffer of the same size as the original text.
with Ada.Streams; use Ada.Streams;
with Ada.Text_IO;
with ZLib; use ZLib;
procedure Buffer_Demo is
EOL : Character renames ASCII.LF;
Text : constant String
:= "Four score and seven years ago our fathers brought forth," & EOL &
"upon this continent, a new nation, conceived in liberty," & EOL &
"and dedicated to the proposition that `all men are created equal'.";
Source : Stream_Element_Array (1 .. Text'Length);
for Source'Address use Text'Address;
begin
Ada.Text_IO.Put (Text);
Ada.Text_IO.New_Line;
Ada.Text_IO.Put_Line
("Uncompressed size : " & Positive'Image (Text'Length) & " bytes");
declare
Compressed_Data : Stream_Element_Array (1 .. Text'Length);
L : Stream_Element_Offset;
begin
Compress : declare
Compressor : Filter_Type;
I : Stream_Element_Offset;
begin
Deflate_Init (Compressor);
-- Compress the whole of T at once.
Translate (Compressor, Source, I, Compressed_Data, L, Finish);
pragma Assert (I = Source'Last);
Close (Compressor);
Ada.Text_IO.Put_Line
("Compressed size : "
& Stream_Element_Offset'Image (L) & " bytes");
end Compress;
-- Now we decompress the data, passing short blocks of data to Zlib
-- (because this demonstrates the problem - the last block passed will
-- contain checksum information and there will be no output, only a
-- check inside Zlib that the checksum is correct).
Decompress : declare
Decompressor : Filter_Type;
Uncompressed_Data : Stream_Element_Array (1 .. Text'Length);
Block_Size : constant := 4;
-- This makes sure that the last block contains
-- only Adler checksum data.
P : Stream_Element_Offset := Compressed_Data'First - 1;
O : Stream_Element_Offset;
begin
Inflate_Init (Decompressor);
loop
Translate
(Decompressor,
Compressed_Data
(P + 1 .. Stream_Element_Offset'Min (P + Block_Size, L)),
P,
Uncompressed_Data
(Total_Out (Decompressor) + 1 .. Uncompressed_Data'Last),
O,
No_Flush);
Ada.Text_IO.Put_Line
("Total in : " & Count'Image (Total_In (Decompressor)) &
", out : " & Count'Image (Total_Out (Decompressor)));
exit when P = L;
end loop;
Ada.Text_IO.New_Line;
Ada.Text_IO.Put_Line
("Decompressed text matches original text : "
& Boolean'Image (Uncompressed_Data = Source));
end Decompress;
end;
end Buffer_Demo;
|
with
xml.Reader,
ada.Text_IO;
package body XML
is
------------------
--- Attribute type
--
function Name (Self : in Attribute_t) return String
is
begin
return to_String (Self.Name);
end Name;
function Value (Self : in Attribute_t) return String
is
begin
return to_String (Self.Value);
end Value;
----------------
--- Element type
--
function to_XML (Filename : in String) return Element
is
use xml.Reader, xml.element_Vectors,
ada.Text_IO;
the_Root : aliased Element;
Line_Max : constant := 800_000;
Depth : Natural := 0;
the_XML_File : File_Type;
the_Parser : xml.reader.Parser;
Done : Boolean;
Buffer : String (1 .. Line_Max);
Buffer_Length : Natural;
element_Stack : element_Vector;
function current_Element return Element_view
is
begin
return element_Stack.last_Element;
end current_Element;
procedure Starter (Name: in unbounded_String;
Atts: in Attributes_view)
is
new_Element : constant Element_view := new Element' (name => Name,
attributes => new Attributes_t' (Atts.all),
data => <>,
parent => current_Element,
children => <>);
begin
current_Element.add_Child (new_Element);
element_Stack .append (new_Element);
end Starter;
procedure Ender (Name: in unbounded_String)
is
pragma Unreferenced (Name);
begin
element_Stack.delete_Last;
end Ender;
procedure data_Handler (Data: in unbounded_String)
is
begin
append (current_Element.Data, "" & Data);
end data_Handler;
begin
append (element_Stack, the_Root'unchecked_Access);
open (the_XML_File, In_File, Filename);
the_Parser := Create_Parser;
set_Element_Handler (the_Parser, Starter 'unrestricted_Access,
Ender 'unrestricted_Access);
set_Character_Data_Handler (the_Parser, data_Handler'unrestricted_Access);
loop
Get_Line (the_XML_File, Buffer, Buffer_Length);
Done := End_Of_File (the_XML_File);
Parse (the_Parser, Buffer (1 .. Buffer_Length), Done);
exit when Done;
end loop;
close (the_XML_File);
return the_Root;
end to_XML;
function Name (Self : in Element) return String
is
begin
return to_String (Self.Name);
end Name;
function Data (Self : in Element) return String
is
begin
return to_String (Self.Data);
end Data;
function Children (Self : in Element) return Elements
is
the_Children : Elements (1 .. Integer (Self.children.Length));
begin
for Each in the_Children'Range
loop
the_Children (Each) := Self.Children.Element (Each);
end loop;
return the_Children;
end Children;
function Children (Self : in Element; Named : in String) return Elements
is
the_Children : Elements (1 .. Integer (Self.children.Length));
Count : Natural := 0;
begin
for Each in the_Children'Range
loop
if Self.Children.Element (Each).Name = Named
then
Count := Count + 1;
the_Children (Count) := Self.Children.Element (Each);
end if;
end loop;
return the_Children (1 .. Count);
end Children;
procedure add_Child (Self : in out Element; the_Child : access Element)
is
begin
Self.Children.append (the_Child.all'Access);
end add_Child;
function Child (Self : in Element; Named : in String) return access Element
is
use element_Vectors;
Cursor : element_Vectors.Cursor := Self.children.First;
begin
while has_Element (Cursor)
loop
if element_Vectors.Element (Cursor).Name = Named
then
return element_Vectors.Element (Cursor);
end if;
next (Cursor);
end loop;
return null;
end Child;
function Attributes (Self : in Element) return Attributes_t
is
begin
return Self.Attributes.all;
end Attributes;
function Attribute (Self : in Element; Named : in String) return access Attribute_t'Class
is
begin
for Each in Self.Attributes'Range
loop
if Self.Attributes (Each).Name = Named
then
return Self.Attributes (Each)'Access;
end if;
end loop;
return null;
end Attribute;
function Parent (Self : in Element) return access Element
is
begin
return Self.Parent;
end Parent;
end XML;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . A R I T H _ 6 4 --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This unit provides software routines for doing arithmetic on 64-bit
-- signed integer values in cases where either overflow checking is
-- required, or intermediate results are longer than 64 bits.
with Interfaces;
package System.Arith_64 is
pragma Pure;
subtype Int64 is Interfaces.Integer_64;
function Add_With_Ovflo_Check (X, Y : Int64) return Int64;
-- Raises Constraint_Error if sum of operands overflows 64 bits,
-- otherwise returns the 64-bit signed integer sum.
function Subtract_With_Ovflo_Check (X, Y : Int64) return Int64;
-- Raises Constraint_Error if difference of operands overflows 64
-- bits, otherwise returns the 64-bit signed integer difference.
function Multiply_With_Ovflo_Check (X, Y : Int64) return Int64;
-- Raises Constraint_Error if product of operands overflows 64
-- bits, otherwise returns the 64-bit signed integer product.
procedure Scaled_Divide
(X, Y, Z : Int64;
Q, R : out Int64;
Round : Boolean);
-- Performs the division of (X * Y) / Z, storing the quotient in Q
-- and the remainder in R. Constraint_Error is raised if Z is zero,
-- or if the quotient does not fit in 64-bits. Round indicates if
-- the result should be rounded. If Round is False, then Q, R are
-- the normal quotient and remainder from a truncating division.
-- If Round is True, then Q is the rounded quotient. The remainder
-- R is not affected by the setting of the Round flag.
procedure Double_Divide
(X, Y, Z : Int64;
Q, R : out Int64;
Round : Boolean);
-- Performs the division X / (Y * Z), storing the quotient in Q and
-- the remainder in R. Constraint_Error is raised if Y or Z is zero,
-- or if the quotient does not fit in 64-bits. Round indicates if the
-- result should be rounded. If Round is False, then Q, R are the normal
-- quotient and remainder from a truncating division. If Round is True,
-- then Q is the rounded quotient. The remainder R is not affected by the
-- setting of the Round flag.
end System.Arith_64;
|
--- src/gprlib.adb.orig 2021-05-19 05:22:13 UTC
+++ src/gprlib.adb
@@ -745,9 +745,6 @@ procedure Gprlib is
for Dir of Imported_Library_Directories loop
Library_Switches_Table.Append ("-L" & Dir);
- if Path_Option /= null then
- Add_Rpath (Dir);
- end if;
end loop;
for Libname of Imported_Library_Names loop
@@ -941,12 +938,6 @@ procedure Gprlib is
Shared_Lib_Suffix.all);
end if;
- if Path_Option /= null then
- for Path of Library_Rpath_Options_Table loop
- Add_Rpath (Path);
- end loop;
- end if;
-
if Path_Option /= null and then not Rpath.Is_Empty then
if Separate_Run_Path_Options then
for J in 1 .. Rpath.Last_Index loop
@@ -1477,9 +1468,7 @@ procedure Gprlib is
Object_Files.Append (Opt);
else
if Partial_Linker_Path = null then
- Fail_Program
- (null,
- "unknown object file """ & Opt & """");
+ Put_Line ("WARNING: unknown object '" & Opt & "'");
else
Trailing_PL_Options.Append (Opt);
end if;
@@ -2130,10 +2119,10 @@ procedure Gprlib is
Libgnat :=
new String'
- ("-lgnat-" & Line (6 .. Last));
+ ("-lgnat-" & Line (6 .. 7));
Libgnarl :=
new String'
- ("-lgnarl-" & Line (6 .. Last));
+ ("-lgnarl-" & Line (6 .. 7));
end if;
else
|
pragma Style_Checks (Off);
-- This spec has been automatically generated from ATSAMD51G19A.svd
pragma Restrictions (No_Elaboration_Code);
with System;
-- Microchip ATSAMD51G19A Microcontroller
package SAM_SVD is
pragma Preelaborate;
--------------------
-- Base addresses --
--------------------
AC_Base : constant System.Address := System'To_Address (16#42002000#);
ADC0_Base : constant System.Address := System'To_Address (16#43001C00#);
ADC1_Base : constant System.Address := System'To_Address (16#43002000#);
AES_Base : constant System.Address := System'To_Address (16#42002400#);
CCL_Base : constant System.Address := System'To_Address (16#42003800#);
CMCC_Base : constant System.Address := System'To_Address (16#41006000#);
DAC_Base : constant System.Address := System'To_Address (16#43002400#);
DMAC_Base : constant System.Address := System'To_Address (16#4100A000#);
DSU_Base : constant System.Address := System'To_Address (16#41002000#);
EIC_Base : constant System.Address := System'To_Address (16#40002800#);
EVSYS_Base : constant System.Address := System'To_Address (16#4100E000#);
FREQM_Base : constant System.Address := System'To_Address (16#40002C00#);
GCLK_Base : constant System.Address := System'To_Address (16#40001C00#);
HMATRIX_Base : constant System.Address := System'To_Address (16#4100C000#);
ICM_Base : constant System.Address := System'To_Address (16#42002C00#);
MCLK_Base : constant System.Address := System'To_Address (16#40000800#);
NVMCTRL_Base : constant System.Address := System'To_Address (16#41004000#);
OSCCTRL_Base : constant System.Address := System'To_Address (16#40001000#);
OSC32KCTRL_Base : constant System.Address := System'To_Address (16#40001400#);
PAC_Base : constant System.Address := System'To_Address (16#40000000#);
PCC_Base : constant System.Address := System'To_Address (16#43002C00#);
PDEC_Base : constant System.Address := System'To_Address (16#42001C00#);
PM_Base : constant System.Address := System'To_Address (16#40000400#);
PORT_Base : constant System.Address := System'To_Address (16#41008000#);
QSPI_Base : constant System.Address := System'To_Address (16#42003400#);
RAMECC_Base : constant System.Address := System'To_Address (16#41020000#);
RSTC_Base : constant System.Address := System'To_Address (16#40000C00#);
RTC_Base : constant System.Address := System'To_Address (16#40002400#);
SDHC0_Base : constant System.Address := System'To_Address (16#45000000#);
SERCOM0_Base : constant System.Address := System'To_Address (16#40003000#);
SERCOM1_Base : constant System.Address := System'To_Address (16#40003400#);
SERCOM2_Base : constant System.Address := System'To_Address (16#41012000#);
SERCOM3_Base : constant System.Address := System'To_Address (16#41014000#);
SERCOM4_Base : constant System.Address := System'To_Address (16#43000000#);
SERCOM5_Base : constant System.Address := System'To_Address (16#43000400#);
SUPC_Base : constant System.Address := System'To_Address (16#40001800#);
TC0_Base : constant System.Address := System'To_Address (16#40003800#);
TC1_Base : constant System.Address := System'To_Address (16#40003C00#);
TC2_Base : constant System.Address := System'To_Address (16#4101A000#);
TC3_Base : constant System.Address := System'To_Address (16#4101C000#);
TCC0_Base : constant System.Address := System'To_Address (16#41016000#);
TCC1_Base : constant System.Address := System'To_Address (16#41018000#);
TCC2_Base : constant System.Address := System'To_Address (16#42000C00#);
TRNG_Base : constant System.Address := System'To_Address (16#42002800#);
USB_Base : constant System.Address := System'To_Address (16#41000000#);
WDT_Base : constant System.Address := System'To_Address (16#40002000#);
CoreDebug_Base : constant System.Address := System'To_Address (16#E000EDF0#);
DWT_Base : constant System.Address := System'To_Address (16#E0001000#);
ETM_Base : constant System.Address := System'To_Address (16#E0041000#);
FPU_Base : constant System.Address := System'To_Address (16#E000EF30#);
ITM_Base : constant System.Address := System'To_Address (16#E0000000#);
MPU_Base : constant System.Address := System'To_Address (16#E000ED90#);
NVIC_Base : constant System.Address := System'To_Address (16#E000E100#);
SysTick_Base : constant System.Address := System'To_Address (16#E000E010#);
SystemControl_Base : constant System.Address := System'To_Address (16#E000E000#);
TPI_Base : constant System.Address := System'To_Address (16#E0040000#);
end SAM_SVD;
|
package body Array_Swapping
is
procedure Swap (A: in out ArrayType; I, J: in IndexType)
with Depends => (A => (A, I, J))
is
T: ElementType;
begin
T := A(I);
A(I) := A(J);
A(J) := T;
end Swap;
procedure Rotate3(A: in out ArrayType; X, Y, Z: in IndexType)
is
begin
Swap(A, X, Y);
Swap(A, X, Z);
end Rotate3;
end Array_Swapping;
|
with Ada.Synchronous_Task_Control; use Ada.Synchronous_Task_Control;
with Ada.Real_Time; use Ada.Real_Time;
with STM32GD.GPIO;
with STM32GD.GPIO.Pin;
with STM32GD.EXTI;
with STM32GD.Timer;
with STM32GD.Timer.Peripheral;
with STM32GD.Board; use STM32GD.Board;
with Peripherals;
procedure Main is
package GPIO renames STM32GD.GPIO;
package EXTI renames STM32GD.EXTI;
Next_Release : Time := Clock;
Period : constant Time_Span := Milliseconds (50);
procedure Polling_Test is
begin
loop
if EXTI.IRQ_Handler.Status (EXTI.EXTI_Line_0) = True then
LED.Toggle;
EXTI.IRQ_Handler.Reset_Status (EXTI.EXTI_Line_0);
end if;
Next_Release := Next_Release + Period;
delay until Next_Release;
end loop;
end Polling_Test;
procedure Waiting_Test is
begin
loop
Button.Wait_For_Trigger;
LED.Toggle;
end loop;
end Waiting_Test;
procedure Cancel_Test is
begin
Peripherals.Timer.Init;
loop
Peripherals.Timer.After (Milliseconds (5000), Button.Cancel_Wait'Access);
Button.Wait_For_Trigger;
if Button.Triggered then
LED.Toggle;
else
LED.Toggle;
end if;
Button.Clear_Trigger;
end loop;
end Cancel_Test;
begin
Init;
TX.Init;
USART.Init;
Button.Configure_Trigger (EXTI.Interrupt_Falling_Edge);
LED.Set;
-- Polling_Test;
-- Waiting_Test;
Cancel_Test;
end Main;
|
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
package body Program.Nodes.Generic_Procedure_Renaming_Declarations is
function Create
(Generic_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Procedure_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Name : not null Program.Elements.Defining_Names
.Defining_Name_Access;
Renames_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Renamed_Procedure : not null Program.Elements.Expressions
.Expression_Access;
With_Token : Program.Lexical_Elements.Lexical_Element_Access;
Aspects : Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access;
Semicolon_Token : not null Program.Lexical_Elements
.Lexical_Element_Access)
return Generic_Procedure_Renaming_Declaration is
begin
return Result : Generic_Procedure_Renaming_Declaration :=
(Generic_Token => Generic_Token, Procedure_Token => Procedure_Token,
Name => Name, Renames_Token => Renames_Token,
Renamed_Procedure => Renamed_Procedure, With_Token => With_Token,
Aspects => Aspects, Semicolon_Token => Semicolon_Token,
Enclosing_Element => null)
do
Initialize (Result);
end return;
end Create;
function Create
(Name : not null Program.Elements.Defining_Names
.Defining_Name_Access;
Renamed_Procedure : not null Program.Elements.Expressions
.Expression_Access;
Aspects : Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access;
Is_Part_Of_Implicit : Boolean := False;
Is_Part_Of_Inherited : Boolean := False;
Is_Part_Of_Instance : Boolean := False)
return Implicit_Generic_Procedure_Renaming_Declaration is
begin
return Result : Implicit_Generic_Procedure_Renaming_Declaration :=
(Name => Name, Renamed_Procedure => Renamed_Procedure,
Aspects => Aspects, Is_Part_Of_Implicit => Is_Part_Of_Implicit,
Is_Part_Of_Inherited => Is_Part_Of_Inherited,
Is_Part_Of_Instance => Is_Part_Of_Instance, Enclosing_Element => null)
do
Initialize (Result);
end return;
end Create;
overriding function Name
(Self : Base_Generic_Procedure_Renaming_Declaration)
return not null Program.Elements.Defining_Names.Defining_Name_Access is
begin
return Self.Name;
end Name;
overriding function Renamed_Procedure
(Self : Base_Generic_Procedure_Renaming_Declaration)
return not null Program.Elements.Expressions.Expression_Access is
begin
return Self.Renamed_Procedure;
end Renamed_Procedure;
overriding function Aspects
(Self : Base_Generic_Procedure_Renaming_Declaration)
return Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access is
begin
return Self.Aspects;
end Aspects;
overriding function Generic_Token
(Self : Generic_Procedure_Renaming_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Generic_Token;
end Generic_Token;
overriding function Procedure_Token
(Self : Generic_Procedure_Renaming_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Procedure_Token;
end Procedure_Token;
overriding function Renames_Token
(Self : Generic_Procedure_Renaming_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Renames_Token;
end Renames_Token;
overriding function With_Token
(Self : Generic_Procedure_Renaming_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.With_Token;
end With_Token;
overriding function Semicolon_Token
(Self : Generic_Procedure_Renaming_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Semicolon_Token;
end Semicolon_Token;
overriding function Is_Part_Of_Implicit
(Self : Implicit_Generic_Procedure_Renaming_Declaration)
return Boolean is
begin
return Self.Is_Part_Of_Implicit;
end Is_Part_Of_Implicit;
overriding function Is_Part_Of_Inherited
(Self : Implicit_Generic_Procedure_Renaming_Declaration)
return Boolean is
begin
return Self.Is_Part_Of_Inherited;
end Is_Part_Of_Inherited;
overriding function Is_Part_Of_Instance
(Self : Implicit_Generic_Procedure_Renaming_Declaration)
return Boolean is
begin
return Self.Is_Part_Of_Instance;
end Is_Part_Of_Instance;
procedure Initialize
(Self : in out Base_Generic_Procedure_Renaming_Declaration'Class)
is
begin
Set_Enclosing_Element (Self.Name, Self'Unchecked_Access);
Set_Enclosing_Element (Self.Renamed_Procedure, Self'Unchecked_Access);
for Item in Self.Aspects.Each_Element loop
Set_Enclosing_Element (Item.Element, Self'Unchecked_Access);
end loop;
null;
end Initialize;
overriding function Is_Generic_Procedure_Renaming_Declaration
(Self : Base_Generic_Procedure_Renaming_Declaration)
return Boolean is
pragma Unreferenced (Self);
begin
return True;
end Is_Generic_Procedure_Renaming_Declaration;
overriding function Is_Declaration
(Self : Base_Generic_Procedure_Renaming_Declaration)
return Boolean is
pragma Unreferenced (Self);
begin
return True;
end Is_Declaration;
overriding procedure Visit
(Self : not null access Base_Generic_Procedure_Renaming_Declaration;
Visitor : in out Program.Element_Visitors.Element_Visitor'Class) is
begin
Visitor.Generic_Procedure_Renaming_Declaration (Self);
end Visit;
overriding function To_Generic_Procedure_Renaming_Declaration_Text
(Self : in out Generic_Procedure_Renaming_Declaration)
return Program.Elements.Generic_Procedure_Renaming_Declarations
.Generic_Procedure_Renaming_Declaration_Text_Access is
begin
return Self'Unchecked_Access;
end To_Generic_Procedure_Renaming_Declaration_Text;
overriding function To_Generic_Procedure_Renaming_Declaration_Text
(Self : in out Implicit_Generic_Procedure_Renaming_Declaration)
return Program.Elements.Generic_Procedure_Renaming_Declarations
.Generic_Procedure_Renaming_Declaration_Text_Access is
pragma Unreferenced (Self);
begin
return null;
end To_Generic_Procedure_Renaming_Declaration_Text;
end Program.Nodes.Generic_Procedure_Renaming_Declarations;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . V E R S I O N _ C O N T R O L --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2021, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System.Unsigned_Types; use System.Unsigned_Types;
package body System.Version_Control is
------------------------
-- Get_Version_String --
------------------------
function Get_Version_String
(V : System.Unsigned_Types.Unsigned)
return Version_String
is
S : Version_String;
D : Unsigned := V;
H : constant array (Unsigned range 0 .. 15) of Character :=
"0123456789abcdef";
begin
for J in reverse 1 .. 8 loop
S (J) := H (D mod 16);
D := D / 16;
end loop;
return S;
end Get_Version_String;
end System.Version_Control;
|
-- Standard Ada library specification
-- Copyright (c) 2003-2018 Maxim Reznik <reznikmm@gmail.com>
-- Copyright (c) 2004-2016 AXE Consultants
-- Copyright (c) 2004, 2005, 2006 Ada-Europe
-- Copyright (c) 2000 The MITRE Corporation, Inc.
-- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc.
-- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual
---------------------------------------------------------------------------
with System;
package Ada.Interrupts is
type Interrupt_ID is (Implementation_Defined);
type Parameterless_Handler is access protected procedure;
function Is_Reserved (Interrupt : in Interrupt_ID) return Boolean;
function Is_Attached (Interrupt : in Interrupt_ID) return Boolean;
function Current_Handler (Interrupt : in Interrupt_ID)
return Parameterless_Handler;
procedure Attach_Handler (New_Handler : in Parameterless_Handler;
Interrupt : in Interrupt_ID);
procedure Exchange_Handler (Old_Handler : out Parameterless_Handler;
New_Handler : in Parameterless_Handler;
Interrupt : in Interrupt_ID);
procedure Detach_Handler (Interrupt : in Interrupt_ID);
function Reference (Interrupt : in Interrupt_ID) return System.Address;
private
end Ada.Interrupts;
|
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_IO;
procedure Closest is
package Math is new Ada.Numerics.Generic_Elementary_Functions (Float);
Dimension : constant := 2;
type Vector is array (1 .. Dimension) of Float;
type Matrix is array (Positive range <>) of Vector;
-- calculate the distance of two points
function Distance (Left, Right : Vector) return Float is
Result : Float := 0.0;
Offset : Natural := 0;
begin
loop
Result := Result + (Left(Left'First + Offset) - Right(Right'First + Offset))**2;
Offset := Offset + 1;
exit when Offset >= Left'Length;
end loop;
return Math.Sqrt (Result);
end Distance;
-- determine the two closest points inside a cloud of vectors
function Get_Closest_Points (Cloud : Matrix) return Matrix is
Result : Matrix (1..2);
Min_Distance : Float;
begin
if Cloud'Length(1) < 2 then
raise Constraint_Error;
end if;
Result := (Cloud (Cloud'First), Cloud (Cloud'First + 1));
Min_Distance := Distance (Cloud (Cloud'First), Cloud (Cloud'First + 1));
for I in Cloud'First (1) .. Cloud'Last(1) - 1 loop
for J in I + 1 .. Cloud'Last(1) loop
if Distance (Cloud (I), Cloud (J)) < Min_Distance then
Min_Distance := Distance (Cloud (I), Cloud (J));
Result := (Cloud (I), Cloud (J));
end if;
end loop;
end loop;
return Result;
end Get_Closest_Points;
Test_Cloud : constant Matrix (1 .. 10) := ( (5.0, 9.0), (9.0, 3.0),
(2.0, 0.0), (8.0, 4.0),
(7.0, 4.0), (9.0, 10.0),
(1.0, 9.0), (8.0, 2.0),
(0.0, 10.0), (9.0, 6.0));
Closest_Points : Matrix := Get_Closest_Points (Test_Cloud);
Second_Test : constant Matrix (1 .. 10) := ( (0.654682, 0.925557), (0.409382, 0.619391),
(0.891663, 0.888594), (0.716629, 0.9962),
(0.477721, 0.946355), (0.925092, 0.81822),
(0.624291, 0.142924), (0.211332, 0.221507),
(0.293786, 0.691701), (0.839186, 0.72826));
Second_Points : Matrix := Get_Closest_Points (Second_Test);
begin
Ada.Text_IO.Put_Line ("Closest Points:");
Ada.Text_IO.Put_Line ("P1: " & Float'Image (Closest_Points (1) (1)) & " " & Float'Image (Closest_Points (1) (2)));
Ada.Text_IO.Put_Line ("P2: " & Float'Image (Closest_Points (2) (1)) & " " & Float'Image (Closest_Points (2) (2)));
Ada.Text_IO.Put_Line ("Distance: " & Float'Image (Distance (Closest_Points (1), Closest_Points (2))));
Ada.Text_IO.Put_Line ("Closest Points 2:");
Ada.Text_IO.Put_Line ("P1: " & Float'Image (Second_Points (1) (1)) & " " & Float'Image (Second_Points (1) (2)));
Ada.Text_IO.Put_Line ("P2: " & Float'Image (Second_Points (2) (1)) & " " & Float'Image (Second_Points (2) (2)));
Ada.Text_IO.Put_Line ("Distance: " & Float'Image (Distance (Second_Points (1), Second_Points (2))));
end Closest;
|
------------------------------------------------------------------------------
-- A d a r u n - t i m e s p e c i f i c a t i o n --
-- ASIS implementation for Gela project, a portable Ada compiler --
-- http://gela.ada-ru.org --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license at the end of ada.ads file --
------------------------------------------------------------------------------
-- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $
with System;
package Ada.Execution_Time.Timers is
type Timer (T : not null access constant Ada.Task_Identification.Task_Id) is
tagged limited private;
type Timer_Handler is access protected procedure (TM : in out Timer);
Min_Handler_Ceiling : constant System.Any_Priority :=
implementation-defined;
procedure Set_Handler (TM : in out Timer;
In_Time : in Ada.Real_Time.Time_Span;
Handler : in Timer_Handler);
procedure Set_Handler (TM : in out Timer;
At_Time : in CPU_Time;
Handler : in Timer_Handler);
function Current_Handler (TM : Timer) return Timer_Handler;
procedure Cancel_Handler (TM : in out Timer;
Cancelled : out Boolean);
function Time_Remaining (TM : Timer) return Ada.Real_Time.Time_Span;
Timer_Resource_Error : exception;
private
pragma Import (Ada, Timer);
end Ada.Execution_Time.Timers;
|
with Ada.Unchecked_Deallocation;
with SDA_Exceptions; use SDA_Exceptions;
package body LCA is
procedure Free is
new Ada.Unchecked_Deallocation (Object => T_Cellule, Name => T_LCA);
procedure Initialiser(Sda: out T_LCA) is
begin
Sda := null;
end Initialiser;
function Est_Vide (Sda : T_LCA) return Boolean is
begin
return Sda = null;
end Est_Vide;
function Cellule(Sda: in T_LCA; Cle: in T_Cle) return T_LCA is
Temp: T_LCA;
begin
Temp := Sda;
while not Est_Vide(Temp) loop
if Temp.all.Cle = Cle then
return Temp;
end if;
Temp := Temp.Suivant;
end loop;
return null;
end Cellule;
function Taille (Sda : in T_LCA) return Integer is
Temp: T_LCA;
Taille: Integer;
begin
Temp := Sda;
Taille := 0;
while not Est_Vide(Temp) loop
Taille := Taille + 1;
Temp := Temp.Suivant;
end loop;
return Taille;
end Taille;
procedure Enregistrer (Sda : in out T_LCA ; Cle : in T_Cle ; Donnee : in T_Donnee) is
Temp: T_LCA;
begin
Temp := Cellule(Sda, Cle);
if Temp /= null then
Temp.all.Donnee := Donnee;
else
Temp := Sda;
Sda := new T_Cellule;
Sda.all.Cle := Cle;
Sda.all.Donnee := Donnee;
Sda.all.Suivant := Temp;
end if;
end Enregistrer;
function Cle_Presente (Sda : in T_LCA ; Cle : in T_Cle) return Boolean is
begin
return Cellule(Sda, Cle) /= null;
end Cle_Presente;
function La_Donnee (Sda : in T_LCA ; Cle : in T_Cle) return T_Donnee is
Temp: T_LCA;
begin
Temp := Cellule(Sda, Cle);
if Temp = null then
raise Cle_Absente_Exception;
end if;
return Temp.all.Donnee;
end La_Donnee;
procedure Supprimer (Sda : in out T_LCA ; Cle : in T_Cle) is
Temp: T_LCA;
begin
if Est_Vide(Sda) then
raise Cle_Absente_Exception;
elsif Sda.all.Cle = Cle then
Temp := Sda;
Sda := Sda.all.Suivant;
Free(Temp);
else
Supprimer(Sda.all.Suivant, Cle);
end if;
end Supprimer;
procedure Vider (Sda : in out T_LCA) is
Temp: T_LCA;
begin
while not Est_Vide(Sda) loop
Temp := Sda;
Sda := Sda.all.Suivant;
Free(Temp);
end loop;
end Vider;
procedure Pour_Chaque (Sda : in T_LCA) is
Temp: T_LCA;
begin
Temp := Sda;
while not Est_Vide(Temp) loop
begin
Traiter(Temp.all.Cle, Temp.all.Donnee);
exception
when others => null;
end;
Temp := Temp.Suivant;
end loop;
end Pour_Chaque;
end LCA;
|
-- C87B14C.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 OVERLOADING RESOLUTION USES THE RULE THAT:
--
-- IN SUBTYPE INDICATIONS WITH INDEX CONSTRAINTS, THE LOWER AND UPPER
-- BOUNDS MUST BE OF THE INDEX BASE TYPE.
--
-- TEST (C): INDEX CONSTRAINTS WITH OVERLOADED INFIX OPERATORS.
-- TRH 30 JUNE 82
WITH REPORT; USE REPORT;
PROCEDURE C87B14C IS
TYPE DAY IS (MON, TUE, WED, THU, FRI, SAT, SUN);
TYPE LIST IS ARRAY (DAY RANGE <>) OF BOOLEAN;
TYPE GRID IS ARRAY (DAY RANGE <>, DAY RANGE <>) OF BOOLEAN;
SUBTYPE WEEKEND IS DAY RANGE SAT .. SUN;
SUBTYPE WEEKDAY IS DAY RANGE MON .. FRI;
FUNCTION "*" (X, Y : INTEGER) RETURN WEEKDAY IS
BEGIN
RETURN MON;
END "*";
FUNCTION "*" (X, Y : INTEGER) RETURN BOOLEAN IS
BEGIN
FAILED ("RESOLUTION INCORRECT - INDEX CONSTRAINTS " &
" IN SUBTYPE INDICATIONS");
RETURN TRUE;
END "*";
FUNCTION "+" (X, Y : INTEGER) RETURN WEEKEND IS
BEGIN
RETURN SAT;
END "+";
FUNCTION "+" (X, Y : INTEGER) RETURN FLOAT IS
BEGIN
FAILED ("RESOLUTION INCORRECT - INDEX CONSTRAINTS " &
" IN SUBTYPE INDICATIONS");
RETURN 2.0;
END "+";
BEGIN
TEST ("C87B14C","OVERLOADED EXPRESSIONS IN INDEX CONSTRAINTS " &
"OF SUBTYPE INDICATIONS");
DECLARE
SUBTYPE LIST1 IS LIST (WED .. (0 + 0));
SUBTYPE LIST2 IS LIST ( 0 * 0 .. TUE);
SUBTYPE LIST3 IS LIST ((0 + 0) .. (0 + 0));
SUBTYPE LIST4 IS LIST ((0 * 0) .. (0 + 0));
SUBTYPE GRID1 IS GRID (MON .. (0 * 0), (0 * 0) .. TUE);
SUBTYPE GRID2 IS GRID ((0 * 0) .. WED, FRI .. (0 + 0));
SUBTYPE GRID3 IS GRID
((0 * 0) .. (0 * 0), (0 + 0) .. (0 + 0));
SUBTYPE GRID4 IS GRID ((0 * 0) .. (0 + 0), TUE .. THU);
BEGIN
NULL;
END;
RESULT;
END C87B14C;
|
--
-- Copyright 2021 (C) Holger Rodriguez
--
-- SPDX-License-Identifier: BSD-3-Clause
--
with LED_Control;
package body Execute.LEDs is
--------------------------------------------------------------------------
-- definition of the look up table for the procedures to execute
-- based on the command given
--------------------------------------------------------------------------
type LED_Execute is access procedure;
type LED_Execute_Map is array (LED_Commands) of LED_Execute;
LED_Execute_Mapper : constant LED_Execute_Map
:= (
------------------------------
-- Red LED operation mappings
------------------------------
Red_Off => LED_Control.LED_0_Red_Off'Access,
Red_On => LED_Control.LED_0_Red_On'Access,
Red_Toggle => LED_Control.LED_0_Red_Toggle'Access,
--------------------------------
-- Amber LED operation mappings
--------------------------------
Amber_Off => LED_Control.LED_0_Amber_Off'Access,
Amber_On => LED_Control.LED_0_Amber_On'Access,
Amber_Toggle => LED_Control.LED_0_Amber_Toggle'Access,
--------------------------------
-- Green LED operation mappings
--------------------------------
Green_Off => LED_Control.LED_0_Green_Off'Access,
Green_On => LED_Control.LED_0_Green_On'Access,
Green_Toggle => LED_Control.LED_0_Green_Toggle'Access,
--------------------------------
-- White LED operation mappings
--------------------------------
White_Off => LED_Control.LED_0_White_Off'Access,
White_On => LED_Control.LED_0_White_On'Access,
White_Toggle => LED_Control.LED_0_White_Toggle'Access,
--------------------------------
-- Blue LED operation mappings
--------------------------------
Blue_Off => LED_Control.LED_0_Blue_Off'Access,
Blue_On => LED_Control.LED_0_Blue_On'Access,
Blue_Toggle => LED_Control.LED_0_Blue_Toggle'Access
);
--------------------------------------------------------------------------
-- see .ads
--------------------------------------------------------------------------
procedure Execute (Cmd : LED_Commands) is
begin
LED_Execute_Mapper (Cmd).all;
end Execute;
end Execute.LEDs;
|
-- 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.CAN is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype CAN_MCR_INRQ_Field is STM32_SVD.Bit;
subtype CAN_MCR_SLEEP_Field is STM32_SVD.Bit;
subtype CAN_MCR_TXFP_Field is STM32_SVD.Bit;
subtype CAN_MCR_RFLM_Field is STM32_SVD.Bit;
subtype CAN_MCR_NART_Field is STM32_SVD.Bit;
subtype CAN_MCR_AWUM_Field is STM32_SVD.Bit;
subtype CAN_MCR_ABOM_Field is STM32_SVD.Bit;
subtype CAN_MCR_TTCM_Field is STM32_SVD.Bit;
subtype CAN_MCR_RESET_Field is STM32_SVD.Bit;
subtype CAN_MCR_DBF_Field is STM32_SVD.Bit;
-- CAN_MCR
type CAN_MCR_Register is record
-- INRQ
INRQ : CAN_MCR_INRQ_Field := 16#0#;
-- SLEEP
SLEEP : CAN_MCR_SLEEP_Field := 16#0#;
-- TXFP
TXFP : CAN_MCR_TXFP_Field := 16#0#;
-- RFLM
RFLM : CAN_MCR_RFLM_Field := 16#0#;
-- NART
NART : CAN_MCR_NART_Field := 16#0#;
-- AWUM
AWUM : CAN_MCR_AWUM_Field := 16#0#;
-- ABOM
ABOM : CAN_MCR_ABOM_Field := 16#0#;
-- TTCM
TTCM : CAN_MCR_TTCM_Field := 16#0#;
-- unspecified
Reserved_8_14 : STM32_SVD.UInt7 := 16#0#;
-- RESET
RESET : CAN_MCR_RESET_Field := 16#0#;
-- DBF
DBF : CAN_MCR_DBF_Field := 16#0#;
-- unspecified
Reserved_17_31 : STM32_SVD.UInt15 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_MCR_Register use record
INRQ at 0 range 0 .. 0;
SLEEP at 0 range 1 .. 1;
TXFP at 0 range 2 .. 2;
RFLM at 0 range 3 .. 3;
NART at 0 range 4 .. 4;
AWUM at 0 range 5 .. 5;
ABOM at 0 range 6 .. 6;
TTCM at 0 range 7 .. 7;
Reserved_8_14 at 0 range 8 .. 14;
RESET at 0 range 15 .. 15;
DBF at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
subtype CAN_MSR_INAK_Field is STM32_SVD.Bit;
subtype CAN_MSR_SLAK_Field is STM32_SVD.Bit;
subtype CAN_MSR_ERRI_Field is STM32_SVD.Bit;
subtype CAN_MSR_WKUI_Field is STM32_SVD.Bit;
subtype CAN_MSR_SLAKI_Field is STM32_SVD.Bit;
subtype CAN_MSR_TXM_Field is STM32_SVD.Bit;
subtype CAN_MSR_RXM_Field is STM32_SVD.Bit;
subtype CAN_MSR_SAMP_Field is STM32_SVD.Bit;
subtype CAN_MSR_RX_Field is STM32_SVD.Bit;
-- CAN_MSR
type CAN_MSR_Register is record
-- Read-only. INAK
INAK : CAN_MSR_INAK_Field := 16#0#;
-- Read-only. SLAK
SLAK : CAN_MSR_SLAK_Field := 16#0#;
-- ERRI
ERRI : CAN_MSR_ERRI_Field := 16#0#;
-- WKUI
WKUI : CAN_MSR_WKUI_Field := 16#0#;
-- SLAKI
SLAKI : CAN_MSR_SLAKI_Field := 16#0#;
-- unspecified
Reserved_5_7 : STM32_SVD.UInt3 := 16#0#;
-- Read-only. TXM
TXM : CAN_MSR_TXM_Field := 16#0#;
-- Read-only. RXM
RXM : CAN_MSR_RXM_Field := 16#0#;
-- Read-only. SAMP
SAMP : CAN_MSR_SAMP_Field := 16#0#;
-- Read-only. RX
RX : CAN_MSR_RX_Field := 16#0#;
-- unspecified
Reserved_12_31 : STM32_SVD.UInt20 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_MSR_Register use record
INAK at 0 range 0 .. 0;
SLAK at 0 range 1 .. 1;
ERRI at 0 range 2 .. 2;
WKUI at 0 range 3 .. 3;
SLAKI at 0 range 4 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
TXM at 0 range 8 .. 8;
RXM at 0 range 9 .. 9;
SAMP at 0 range 10 .. 10;
RX at 0 range 11 .. 11;
Reserved_12_31 at 0 range 12 .. 31;
end record;
subtype CAN_TSR_RQCP0_Field is STM32_SVD.Bit;
subtype CAN_TSR_TXOK0_Field is STM32_SVD.Bit;
subtype CAN_TSR_ALST0_Field is STM32_SVD.Bit;
subtype CAN_TSR_TERR0_Field is STM32_SVD.Bit;
subtype CAN_TSR_ABRQ0_Field is STM32_SVD.Bit;
subtype CAN_TSR_RQCP1_Field is STM32_SVD.Bit;
subtype CAN_TSR_TXOK1_Field is STM32_SVD.Bit;
subtype CAN_TSR_ALST1_Field is STM32_SVD.Bit;
subtype CAN_TSR_TERR1_Field is STM32_SVD.Bit;
subtype CAN_TSR_ABRQ1_Field is STM32_SVD.Bit;
subtype CAN_TSR_RQCP2_Field is STM32_SVD.Bit;
subtype CAN_TSR_TXOK2_Field is STM32_SVD.Bit;
subtype CAN_TSR_ALST2_Field is STM32_SVD.Bit;
subtype CAN_TSR_TERR2_Field is STM32_SVD.Bit;
subtype CAN_TSR_ABRQ2_Field is STM32_SVD.Bit;
subtype CAN_TSR_CODE_Field is STM32_SVD.UInt2;
-- CAN_TSR_TME array element
subtype CAN_TSR_TME_Element is STM32_SVD.Bit;
-- CAN_TSR_TME array
type CAN_TSR_TME_Field_Array is array (0 .. 2) of CAN_TSR_TME_Element
with Component_Size => 1, Size => 3;
-- Type definition for CAN_TSR_TME
type CAN_TSR_TME_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- TME as a value
Val : STM32_SVD.UInt3;
when True =>
-- TME as an array
Arr : CAN_TSR_TME_Field_Array;
end case;
end record
with Unchecked_Union, Size => 3;
for CAN_TSR_TME_Field use record
Val at 0 range 0 .. 2;
Arr at 0 range 0 .. 2;
end record;
-- CAN_TSR_LOW array element
subtype CAN_TSR_LOW_Element is STM32_SVD.Bit;
-- CAN_TSR_LOW array
type CAN_TSR_LOW_Field_Array is array (0 .. 2) of CAN_TSR_LOW_Element
with Component_Size => 1, Size => 3;
-- Type definition for CAN_TSR_LOW
type CAN_TSR_LOW_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- LOW as a value
Val : STM32_SVD.UInt3;
when True =>
-- LOW as an array
Arr : CAN_TSR_LOW_Field_Array;
end case;
end record
with Unchecked_Union, Size => 3;
for CAN_TSR_LOW_Field use record
Val at 0 range 0 .. 2;
Arr at 0 range 0 .. 2;
end record;
-- CAN_TSR
type CAN_TSR_Register is record
-- RQCP0
RQCP0 : CAN_TSR_RQCP0_Field := 16#0#;
-- TXOK0
TXOK0 : CAN_TSR_TXOK0_Field := 16#0#;
-- ALST0
ALST0 : CAN_TSR_ALST0_Field := 16#0#;
-- TERR0
TERR0 : CAN_TSR_TERR0_Field := 16#0#;
-- unspecified
Reserved_4_6 : STM32_SVD.UInt3 := 16#0#;
-- ABRQ0
ABRQ0 : CAN_TSR_ABRQ0_Field := 16#0#;
-- RQCP1
RQCP1 : CAN_TSR_RQCP1_Field := 16#0#;
-- TXOK1
TXOK1 : CAN_TSR_TXOK1_Field := 16#0#;
-- ALST1
ALST1 : CAN_TSR_ALST1_Field := 16#0#;
-- TERR1
TERR1 : CAN_TSR_TERR1_Field := 16#0#;
-- unspecified
Reserved_12_14 : STM32_SVD.UInt3 := 16#0#;
-- ABRQ1
ABRQ1 : CAN_TSR_ABRQ1_Field := 16#0#;
-- RQCP2
RQCP2 : CAN_TSR_RQCP2_Field := 16#0#;
-- TXOK2
TXOK2 : CAN_TSR_TXOK2_Field := 16#0#;
-- ALST2
ALST2 : CAN_TSR_ALST2_Field := 16#0#;
-- TERR2
TERR2 : CAN_TSR_TERR2_Field := 16#0#;
-- unspecified
Reserved_20_22 : STM32_SVD.UInt3 := 16#0#;
-- ABRQ2
ABRQ2 : CAN_TSR_ABRQ2_Field := 16#0#;
-- Read-only. CODE
CODE : CAN_TSR_CODE_Field := 16#0#;
-- Read-only. Lowest priority flag for mailbox 0
TME : CAN_TSR_TME_Field := (As_Array => False, Val => 16#0#);
-- Read-only. Lowest priority flag for mailbox 0
LOW : CAN_TSR_LOW_Field := (As_Array => False, Val => 16#0#);
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_TSR_Register use record
RQCP0 at 0 range 0 .. 0;
TXOK0 at 0 range 1 .. 1;
ALST0 at 0 range 2 .. 2;
TERR0 at 0 range 3 .. 3;
Reserved_4_6 at 0 range 4 .. 6;
ABRQ0 at 0 range 7 .. 7;
RQCP1 at 0 range 8 .. 8;
TXOK1 at 0 range 9 .. 9;
ALST1 at 0 range 10 .. 10;
TERR1 at 0 range 11 .. 11;
Reserved_12_14 at 0 range 12 .. 14;
ABRQ1 at 0 range 15 .. 15;
RQCP2 at 0 range 16 .. 16;
TXOK2 at 0 range 17 .. 17;
ALST2 at 0 range 18 .. 18;
TERR2 at 0 range 19 .. 19;
Reserved_20_22 at 0 range 20 .. 22;
ABRQ2 at 0 range 23 .. 23;
CODE at 0 range 24 .. 25;
TME at 0 range 26 .. 28;
LOW at 0 range 29 .. 31;
end record;
subtype CAN_RF0R_FMP0_Field is STM32_SVD.UInt2;
subtype CAN_RF0R_FULL0_Field is STM32_SVD.Bit;
subtype CAN_RF0R_FOVR0_Field is STM32_SVD.Bit;
subtype CAN_RF0R_RFOM0_Field is STM32_SVD.Bit;
-- CAN_RF0R
type CAN_RF0R_Register is record
-- Read-only. FMP0
FMP0 : CAN_RF0R_FMP0_Field := 16#0#;
-- unspecified
Reserved_2_2 : STM32_SVD.Bit := 16#0#;
-- FULL0
FULL0 : CAN_RF0R_FULL0_Field := 16#0#;
-- FOVR0
FOVR0 : CAN_RF0R_FOVR0_Field := 16#0#;
-- RFOM0
RFOM0 : CAN_RF0R_RFOM0_Field := 16#0#;
-- unspecified
Reserved_6_31 : STM32_SVD.UInt26 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_RF0R_Register use record
FMP0 at 0 range 0 .. 1;
Reserved_2_2 at 0 range 2 .. 2;
FULL0 at 0 range 3 .. 3;
FOVR0 at 0 range 4 .. 4;
RFOM0 at 0 range 5 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
subtype CAN_RF1R_FMP1_Field is STM32_SVD.UInt2;
subtype CAN_RF1R_FULL1_Field is STM32_SVD.Bit;
subtype CAN_RF1R_FOVR1_Field is STM32_SVD.Bit;
subtype CAN_RF1R_RFOM1_Field is STM32_SVD.Bit;
-- CAN_RF1R
type CAN_RF1R_Register is record
-- Read-only. FMP1
FMP1 : CAN_RF1R_FMP1_Field := 16#0#;
-- unspecified
Reserved_2_2 : STM32_SVD.Bit := 16#0#;
-- FULL1
FULL1 : CAN_RF1R_FULL1_Field := 16#0#;
-- FOVR1
FOVR1 : CAN_RF1R_FOVR1_Field := 16#0#;
-- RFOM1
RFOM1 : CAN_RF1R_RFOM1_Field := 16#0#;
-- unspecified
Reserved_6_31 : STM32_SVD.UInt26 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_RF1R_Register use record
FMP1 at 0 range 0 .. 1;
Reserved_2_2 at 0 range 2 .. 2;
FULL1 at 0 range 3 .. 3;
FOVR1 at 0 range 4 .. 4;
RFOM1 at 0 range 5 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
subtype CAN_IER_TMEIE_Field is STM32_SVD.Bit;
subtype CAN_IER_FMPIE0_Field is STM32_SVD.Bit;
subtype CAN_IER_FFIE0_Field is STM32_SVD.Bit;
subtype CAN_IER_FOVIE0_Field is STM32_SVD.Bit;
subtype CAN_IER_FMPIE1_Field is STM32_SVD.Bit;
subtype CAN_IER_FFIE1_Field is STM32_SVD.Bit;
subtype CAN_IER_FOVIE1_Field is STM32_SVD.Bit;
subtype CAN_IER_EWGIE_Field is STM32_SVD.Bit;
subtype CAN_IER_EPVIE_Field is STM32_SVD.Bit;
subtype CAN_IER_BOFIE_Field is STM32_SVD.Bit;
subtype CAN_IER_LECIE_Field is STM32_SVD.Bit;
subtype CAN_IER_ERRIE_Field is STM32_SVD.Bit;
subtype CAN_IER_WKUIE_Field is STM32_SVD.Bit;
subtype CAN_IER_SLKIE_Field is STM32_SVD.Bit;
-- CAN_IER
type CAN_IER_Register is record
-- TMEIE
TMEIE : CAN_IER_TMEIE_Field := 16#0#;
-- FMPIE0
FMPIE0 : CAN_IER_FMPIE0_Field := 16#0#;
-- FFIE0
FFIE0 : CAN_IER_FFIE0_Field := 16#0#;
-- FOVIE0
FOVIE0 : CAN_IER_FOVIE0_Field := 16#0#;
-- FMPIE1
FMPIE1 : CAN_IER_FMPIE1_Field := 16#0#;
-- FFIE1
FFIE1 : CAN_IER_FFIE1_Field := 16#0#;
-- FOVIE1
FOVIE1 : CAN_IER_FOVIE1_Field := 16#0#;
-- unspecified
Reserved_7_7 : STM32_SVD.Bit := 16#0#;
-- EWGIE
EWGIE : CAN_IER_EWGIE_Field := 16#0#;
-- EPVIE
EPVIE : CAN_IER_EPVIE_Field := 16#0#;
-- BOFIE
BOFIE : CAN_IER_BOFIE_Field := 16#0#;
-- LECIE
LECIE : CAN_IER_LECIE_Field := 16#0#;
-- unspecified
Reserved_12_14 : STM32_SVD.UInt3 := 16#0#;
-- ERRIE
ERRIE : CAN_IER_ERRIE_Field := 16#0#;
-- WKUIE
WKUIE : CAN_IER_WKUIE_Field := 16#0#;
-- SLKIE
SLKIE : CAN_IER_SLKIE_Field := 16#0#;
-- unspecified
Reserved_18_31 : STM32_SVD.UInt14 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_IER_Register use record
TMEIE at 0 range 0 .. 0;
FMPIE0 at 0 range 1 .. 1;
FFIE0 at 0 range 2 .. 2;
FOVIE0 at 0 range 3 .. 3;
FMPIE1 at 0 range 4 .. 4;
FFIE1 at 0 range 5 .. 5;
FOVIE1 at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
EWGIE at 0 range 8 .. 8;
EPVIE at 0 range 9 .. 9;
BOFIE at 0 range 10 .. 10;
LECIE at 0 range 11 .. 11;
Reserved_12_14 at 0 range 12 .. 14;
ERRIE at 0 range 15 .. 15;
WKUIE at 0 range 16 .. 16;
SLKIE at 0 range 17 .. 17;
Reserved_18_31 at 0 range 18 .. 31;
end record;
subtype CAN_ESR_EWGF_Field is STM32_SVD.Bit;
subtype CAN_ESR_EPVF_Field is STM32_SVD.Bit;
subtype CAN_ESR_BOFF_Field is STM32_SVD.Bit;
subtype CAN_ESR_LEC_Field is STM32_SVD.UInt3;
subtype CAN_ESR_TEC_Field is STM32_SVD.Byte;
subtype CAN_ESR_REC_Field is STM32_SVD.Byte;
-- CAN_ESR
type CAN_ESR_Register is record
-- Read-only. EWGF
EWGF : CAN_ESR_EWGF_Field := 16#0#;
-- Read-only. EPVF
EPVF : CAN_ESR_EPVF_Field := 16#0#;
-- Read-only. BOFF
BOFF : CAN_ESR_BOFF_Field := 16#0#;
-- unspecified
Reserved_3_3 : STM32_SVD.Bit := 16#0#;
-- LEC
LEC : CAN_ESR_LEC_Field := 16#0#;
-- unspecified
Reserved_7_15 : STM32_SVD.UInt9 := 16#0#;
-- Read-only. TEC
TEC : CAN_ESR_TEC_Field := 16#0#;
-- Read-only. REC
REC : CAN_ESR_REC_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_ESR_Register use record
EWGF at 0 range 0 .. 0;
EPVF at 0 range 1 .. 1;
BOFF at 0 range 2 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
LEC at 0 range 4 .. 6;
Reserved_7_15 at 0 range 7 .. 15;
TEC at 0 range 16 .. 23;
REC at 0 range 24 .. 31;
end record;
subtype CAN_BTR_BRP_Field is STM32_SVD.UInt10;
subtype CAN_BTR_TS1_Field is STM32_SVD.UInt4;
subtype CAN_BTR_TS2_Field is STM32_SVD.UInt3;
subtype CAN_BTR_SJW_Field is STM32_SVD.UInt2;
subtype CAN_BTR_LBKM_Field is STM32_SVD.Bit;
subtype CAN_BTR_SILM_Field is STM32_SVD.Bit;
-- CAN_BTR
type CAN_BTR_Register is record
-- BRP
BRP : CAN_BTR_BRP_Field := 16#0#;
-- unspecified
Reserved_10_15 : STM32_SVD.UInt6 := 16#0#;
-- TS1
TS1 : CAN_BTR_TS1_Field := 16#0#;
-- TS2
TS2 : CAN_BTR_TS2_Field := 16#0#;
-- unspecified
Reserved_23_23 : STM32_SVD.Bit := 16#0#;
-- SJW
SJW : CAN_BTR_SJW_Field := 16#0#;
-- unspecified
Reserved_26_29 : STM32_SVD.UInt4 := 16#0#;
-- LBKM
LBKM : CAN_BTR_LBKM_Field := 16#0#;
-- SILM
SILM : CAN_BTR_SILM_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_BTR_Register use record
BRP at 0 range 0 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
TS1 at 0 range 16 .. 19;
TS2 at 0 range 20 .. 22;
Reserved_23_23 at 0 range 23 .. 23;
SJW at 0 range 24 .. 25;
Reserved_26_29 at 0 range 26 .. 29;
LBKM at 0 range 30 .. 30;
SILM at 0 range 31 .. 31;
end record;
subtype CAN_TI0R_TXRQ_Field is STM32_SVD.Bit;
subtype CAN_TI0R_RTR_Field is STM32_SVD.Bit;
subtype CAN_TI0R_IDE_Field is STM32_SVD.Bit;
subtype CAN_TI0R_EXID_Field is STM32_SVD.UInt18;
subtype CAN_TI0R_STID_Field is STM32_SVD.UInt11;
-- CAN_TI0R
type CAN_TI0R_Register is record
-- TXRQ
TXRQ : CAN_TI0R_TXRQ_Field := 16#0#;
-- RTR
RTR : CAN_TI0R_RTR_Field := 16#0#;
-- IDE
IDE : CAN_TI0R_IDE_Field := 16#0#;
-- EXID
EXID : CAN_TI0R_EXID_Field := 16#0#;
-- STID
STID : CAN_TI0R_STID_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_TI0R_Register use record
TXRQ at 0 range 0 .. 0;
RTR at 0 range 1 .. 1;
IDE at 0 range 2 .. 2;
EXID at 0 range 3 .. 20;
STID at 0 range 21 .. 31;
end record;
subtype CAN_TDT0R_DLC_Field is STM32_SVD.UInt4;
subtype CAN_TDT0R_TGT_Field is STM32_SVD.Bit;
subtype CAN_TDT0R_TIME_Field is STM32_SVD.UInt16;
-- CAN_TDT0R
type CAN_TDT0R_Register is record
-- DLC
DLC : CAN_TDT0R_DLC_Field := 16#0#;
-- unspecified
Reserved_4_7 : STM32_SVD.UInt4 := 16#0#;
-- TGT
TGT : CAN_TDT0R_TGT_Field := 16#0#;
-- unspecified
Reserved_9_15 : STM32_SVD.UInt7 := 16#0#;
-- TIME
TIME : CAN_TDT0R_TIME_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_TDT0R_Register use record
DLC at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
TGT at 0 range 8 .. 8;
Reserved_9_15 at 0 range 9 .. 15;
TIME at 0 range 16 .. 31;
end record;
-- CAN_TDL0R_DATA array element
subtype CAN_TDL0R_DATA_Element is STM32_SVD.Byte;
-- CAN_TDL0R_DATA array
type CAN_TDL0R_DATA_Field_Array is array (0 .. 3)
of CAN_TDL0R_DATA_Element
with Component_Size => 8, Size => 32;
-- CAN_TDL0R
type CAN_TDL0R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- DATA as a value
Val : STM32_SVD.UInt32;
when True =>
-- DATA as an array
Arr : CAN_TDL0R_DATA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for CAN_TDL0R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- CAN_TDH0R_DATA array element
subtype CAN_TDH0R_DATA_Element is STM32_SVD.Byte;
-- CAN_TDH0R_DATA array
type CAN_TDH0R_DATA_Field_Array is array (4 .. 7)
of CAN_TDH0R_DATA_Element
with Component_Size => 8, Size => 32;
-- CAN_TDH0R
type CAN_TDH0R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- DATA as a value
Val : STM32_SVD.UInt32;
when True =>
-- DATA as an array
Arr : CAN_TDH0R_DATA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for CAN_TDH0R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
subtype CAN_TI1R_TXRQ_Field is STM32_SVD.Bit;
subtype CAN_TI1R_RTR_Field is STM32_SVD.Bit;
subtype CAN_TI1R_IDE_Field is STM32_SVD.Bit;
subtype CAN_TI1R_EXID_Field is STM32_SVD.UInt18;
subtype CAN_TI1R_STID_Field is STM32_SVD.UInt11;
-- CAN_TI1R
type CAN_TI1R_Register is record
-- TXRQ
TXRQ : CAN_TI1R_TXRQ_Field := 16#0#;
-- RTR
RTR : CAN_TI1R_RTR_Field := 16#0#;
-- IDE
IDE : CAN_TI1R_IDE_Field := 16#0#;
-- EXID
EXID : CAN_TI1R_EXID_Field := 16#0#;
-- STID
STID : CAN_TI1R_STID_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_TI1R_Register use record
TXRQ at 0 range 0 .. 0;
RTR at 0 range 1 .. 1;
IDE at 0 range 2 .. 2;
EXID at 0 range 3 .. 20;
STID at 0 range 21 .. 31;
end record;
subtype CAN_TDT1R_DLC_Field is STM32_SVD.UInt4;
subtype CAN_TDT1R_TGT_Field is STM32_SVD.Bit;
subtype CAN_TDT1R_TIME_Field is STM32_SVD.UInt16;
-- CAN_TDT1R
type CAN_TDT1R_Register is record
-- DLC
DLC : CAN_TDT1R_DLC_Field := 16#0#;
-- unspecified
Reserved_4_7 : STM32_SVD.UInt4 := 16#0#;
-- TGT
TGT : CAN_TDT1R_TGT_Field := 16#0#;
-- unspecified
Reserved_9_15 : STM32_SVD.UInt7 := 16#0#;
-- TIME
TIME : CAN_TDT1R_TIME_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_TDT1R_Register use record
DLC at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
TGT at 0 range 8 .. 8;
Reserved_9_15 at 0 range 9 .. 15;
TIME at 0 range 16 .. 31;
end record;
-- CAN_TDL1R_DATA array element
subtype CAN_TDL1R_DATA_Element is STM32_SVD.Byte;
-- CAN_TDL1R_DATA array
type CAN_TDL1R_DATA_Field_Array is array (0 .. 3)
of CAN_TDL1R_DATA_Element
with Component_Size => 8, Size => 32;
-- CAN_TDL1R
type CAN_TDL1R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- DATA as a value
Val : STM32_SVD.UInt32;
when True =>
-- DATA as an array
Arr : CAN_TDL1R_DATA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for CAN_TDL1R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- CAN_TDH1R_DATA array element
subtype CAN_TDH1R_DATA_Element is STM32_SVD.Byte;
-- CAN_TDH1R_DATA array
type CAN_TDH1R_DATA_Field_Array is array (4 .. 7)
of CAN_TDH1R_DATA_Element
with Component_Size => 8, Size => 32;
-- CAN_TDH1R
type CAN_TDH1R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- DATA as a value
Val : STM32_SVD.UInt32;
when True =>
-- DATA as an array
Arr : CAN_TDH1R_DATA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for CAN_TDH1R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
subtype CAN_TI2R_TXRQ_Field is STM32_SVD.Bit;
subtype CAN_TI2R_RTR_Field is STM32_SVD.Bit;
subtype CAN_TI2R_IDE_Field is STM32_SVD.Bit;
subtype CAN_TI2R_EXID_Field is STM32_SVD.UInt18;
subtype CAN_TI2R_STID_Field is STM32_SVD.UInt11;
-- CAN_TI2R
type CAN_TI2R_Register is record
-- TXRQ
TXRQ : CAN_TI2R_TXRQ_Field := 16#0#;
-- RTR
RTR : CAN_TI2R_RTR_Field := 16#0#;
-- IDE
IDE : CAN_TI2R_IDE_Field := 16#0#;
-- EXID
EXID : CAN_TI2R_EXID_Field := 16#0#;
-- STID
STID : CAN_TI2R_STID_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_TI2R_Register use record
TXRQ at 0 range 0 .. 0;
RTR at 0 range 1 .. 1;
IDE at 0 range 2 .. 2;
EXID at 0 range 3 .. 20;
STID at 0 range 21 .. 31;
end record;
subtype CAN_TDT2R_DLC_Field is STM32_SVD.UInt4;
subtype CAN_TDT2R_TGT_Field is STM32_SVD.Bit;
subtype CAN_TDT2R_TIME_Field is STM32_SVD.UInt16;
-- CAN_TDT2R
type CAN_TDT2R_Register is record
-- DLC
DLC : CAN_TDT2R_DLC_Field := 16#0#;
-- unspecified
Reserved_4_7 : STM32_SVD.UInt4 := 16#0#;
-- TGT
TGT : CAN_TDT2R_TGT_Field := 16#0#;
-- unspecified
Reserved_9_15 : STM32_SVD.UInt7 := 16#0#;
-- TIME
TIME : CAN_TDT2R_TIME_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_TDT2R_Register use record
DLC at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
TGT at 0 range 8 .. 8;
Reserved_9_15 at 0 range 9 .. 15;
TIME at 0 range 16 .. 31;
end record;
-- CAN_TDL2R_DATA array element
subtype CAN_TDL2R_DATA_Element is STM32_SVD.Byte;
-- CAN_TDL2R_DATA array
type CAN_TDL2R_DATA_Field_Array is array (0 .. 3)
of CAN_TDL2R_DATA_Element
with Component_Size => 8, Size => 32;
-- CAN_TDL2R
type CAN_TDL2R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- DATA as a value
Val : STM32_SVD.UInt32;
when True =>
-- DATA as an array
Arr : CAN_TDL2R_DATA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for CAN_TDL2R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- CAN_TDH2R_DATA array element
subtype CAN_TDH2R_DATA_Element is STM32_SVD.Byte;
-- CAN_TDH2R_DATA array
type CAN_TDH2R_DATA_Field_Array is array (4 .. 7)
of CAN_TDH2R_DATA_Element
with Component_Size => 8, Size => 32;
-- CAN_TDH2R
type CAN_TDH2R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- DATA as a value
Val : STM32_SVD.UInt32;
when True =>
-- DATA as an array
Arr : CAN_TDH2R_DATA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for CAN_TDH2R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
subtype CAN_RI0R_RTR_Field is STM32_SVD.Bit;
subtype CAN_RI0R_IDE_Field is STM32_SVD.Bit;
subtype CAN_RI0R_EXID_Field is STM32_SVD.UInt18;
subtype CAN_RI0R_STID_Field is STM32_SVD.UInt11;
-- CAN_RI0R
type CAN_RI0R_Register is record
-- unspecified
Reserved_0_0 : STM32_SVD.Bit;
-- Read-only. RTR
RTR : CAN_RI0R_RTR_Field;
-- Read-only. IDE
IDE : CAN_RI0R_IDE_Field;
-- Read-only. EXID
EXID : CAN_RI0R_EXID_Field;
-- Read-only. STID
STID : CAN_RI0R_STID_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_RI0R_Register use record
Reserved_0_0 at 0 range 0 .. 0;
RTR at 0 range 1 .. 1;
IDE at 0 range 2 .. 2;
EXID at 0 range 3 .. 20;
STID at 0 range 21 .. 31;
end record;
subtype CAN_RDT0R_DLC_Field is STM32_SVD.UInt4;
subtype CAN_RDT0R_FMI_Field is STM32_SVD.Byte;
subtype CAN_RDT0R_TIME_Field is STM32_SVD.UInt16;
-- CAN_RDT0R
type CAN_RDT0R_Register is record
-- Read-only. DLC
DLC : CAN_RDT0R_DLC_Field;
-- unspecified
Reserved_4_7 : STM32_SVD.UInt4;
-- Read-only. FMI
FMI : CAN_RDT0R_FMI_Field;
-- Read-only. TIME
TIME : CAN_RDT0R_TIME_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_RDT0R_Register use record
DLC at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
FMI at 0 range 8 .. 15;
TIME at 0 range 16 .. 31;
end record;
-- CAN_RDL0R_DATA array element
subtype CAN_RDL0R_DATA_Element is STM32_SVD.Byte;
-- CAN_RDL0R_DATA array
type CAN_RDL0R_DATA_Field_Array is array (0 .. 3)
of CAN_RDL0R_DATA_Element
with Component_Size => 8, Size => 32;
-- CAN_RDL0R
type CAN_RDL0R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- DATA as a value
Val : STM32_SVD.UInt32;
when True =>
-- DATA as an array
Arr : CAN_RDL0R_DATA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for CAN_RDL0R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- CAN_RDH0R_DATA array element
subtype CAN_RDH0R_DATA_Element is STM32_SVD.Byte;
-- CAN_RDH0R_DATA array
type CAN_RDH0R_DATA_Field_Array is array (4 .. 7)
of CAN_RDH0R_DATA_Element
with Component_Size => 8, Size => 32;
-- CAN_RDH0R
type CAN_RDH0R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- DATA as a value
Val : STM32_SVD.UInt32;
when True =>
-- DATA as an array
Arr : CAN_RDH0R_DATA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for CAN_RDH0R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
subtype CAN_RI1R_RTR_Field is STM32_SVD.Bit;
subtype CAN_RI1R_IDE_Field is STM32_SVD.Bit;
subtype CAN_RI1R_EXID_Field is STM32_SVD.UInt18;
subtype CAN_RI1R_STID_Field is STM32_SVD.UInt11;
-- CAN_RI1R
type CAN_RI1R_Register is record
-- unspecified
Reserved_0_0 : STM32_SVD.Bit;
-- Read-only. RTR
RTR : CAN_RI1R_RTR_Field;
-- Read-only. IDE
IDE : CAN_RI1R_IDE_Field;
-- Read-only. EXID
EXID : CAN_RI1R_EXID_Field;
-- Read-only. STID
STID : CAN_RI1R_STID_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_RI1R_Register use record
Reserved_0_0 at 0 range 0 .. 0;
RTR at 0 range 1 .. 1;
IDE at 0 range 2 .. 2;
EXID at 0 range 3 .. 20;
STID at 0 range 21 .. 31;
end record;
subtype CAN_RDT1R_DLC_Field is STM32_SVD.UInt4;
subtype CAN_RDT1R_FMI_Field is STM32_SVD.Byte;
subtype CAN_RDT1R_TIME_Field is STM32_SVD.UInt16;
-- CAN_RDT1R
type CAN_RDT1R_Register is record
-- Read-only. DLC
DLC : CAN_RDT1R_DLC_Field;
-- unspecified
Reserved_4_7 : STM32_SVD.UInt4;
-- Read-only. FMI
FMI : CAN_RDT1R_FMI_Field;
-- Read-only. TIME
TIME : CAN_RDT1R_TIME_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_RDT1R_Register use record
DLC at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
FMI at 0 range 8 .. 15;
TIME at 0 range 16 .. 31;
end record;
-- CAN_RDL1R_DATA array element
subtype CAN_RDL1R_DATA_Element is STM32_SVD.Byte;
-- CAN_RDL1R_DATA array
type CAN_RDL1R_DATA_Field_Array is array (0 .. 3)
of CAN_RDL1R_DATA_Element
with Component_Size => 8, Size => 32;
-- CAN_RDL1R
type CAN_RDL1R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- DATA as a value
Val : STM32_SVD.UInt32;
when True =>
-- DATA as an array
Arr : CAN_RDL1R_DATA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for CAN_RDL1R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- CAN_RDH1R_DATA array element
subtype CAN_RDH1R_DATA_Element is STM32_SVD.Byte;
-- CAN_RDH1R_DATA array
type CAN_RDH1R_DATA_Field_Array is array (4 .. 7)
of CAN_RDH1R_DATA_Element
with Component_Size => 8, Size => 32;
-- CAN_RDH1R
type CAN_RDH1R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- DATA as a value
Val : STM32_SVD.UInt32;
when True =>
-- DATA as an array
Arr : CAN_RDH1R_DATA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for CAN_RDH1R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
subtype CAN_FMR_FINIT_Field is STM32_SVD.Bit;
-- CAN_FMR
type CAN_FMR_Register is record
-- FINIT
FINIT : CAN_FMR_FINIT_Field := 16#0#;
-- unspecified
Reserved_1_31 : STM32_SVD.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_FMR_Register use record
FINIT at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
-- CAN_FM1R_FBM array element
subtype CAN_FM1R_FBM_Element is STM32_SVD.Bit;
-- CAN_FM1R_FBM array
type CAN_FM1R_FBM_Field_Array is array (0 .. 13) of CAN_FM1R_FBM_Element
with Component_Size => 1, Size => 14;
-- Type definition for CAN_FM1R_FBM
type CAN_FM1R_FBM_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FBM as a value
Val : STM32_SVD.UInt14;
when True =>
-- FBM as an array
Arr : CAN_FM1R_FBM_Field_Array;
end case;
end record
with Unchecked_Union, Size => 14;
for CAN_FM1R_FBM_Field use record
Val at 0 range 0 .. 13;
Arr at 0 range 0 .. 13;
end record;
-- CAN_FM1R
type CAN_FM1R_Register is record
-- Filter mode
FBM : CAN_FM1R_FBM_Field :=
(As_Array => False, Val => 16#0#);
-- unspecified
Reserved_14_31 : STM32_SVD.UInt18 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_FM1R_Register use record
FBM at 0 range 0 .. 13;
Reserved_14_31 at 0 range 14 .. 31;
end record;
-- CAN_FS1R_FSC array element
subtype CAN_FS1R_FSC_Element is STM32_SVD.Bit;
-- CAN_FS1R_FSC array
type CAN_FS1R_FSC_Field_Array is array (0 .. 13) of CAN_FS1R_FSC_Element
with Component_Size => 1, Size => 14;
-- Type definition for CAN_FS1R_FSC
type CAN_FS1R_FSC_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FSC as a value
Val : STM32_SVD.UInt14;
when True =>
-- FSC as an array
Arr : CAN_FS1R_FSC_Field_Array;
end case;
end record
with Unchecked_Union, Size => 14;
for CAN_FS1R_FSC_Field use record
Val at 0 range 0 .. 13;
Arr at 0 range 0 .. 13;
end record;
-- CAN_FS1R
type CAN_FS1R_Register is record
-- Filter scale configuration
FSC : CAN_FS1R_FSC_Field :=
(As_Array => False, Val => 16#0#);
-- unspecified
Reserved_14_31 : STM32_SVD.UInt18 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_FS1R_Register use record
FSC at 0 range 0 .. 13;
Reserved_14_31 at 0 range 14 .. 31;
end record;
-- CAN_FFA1R_FFA array element
subtype CAN_FFA1R_FFA_Element is STM32_SVD.Bit;
-- CAN_FFA1R_FFA array
type CAN_FFA1R_FFA_Field_Array is array (0 .. 13) of CAN_FFA1R_FFA_Element
with Component_Size => 1, Size => 14;
-- Type definition for CAN_FFA1R_FFA
type CAN_FFA1R_FFA_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FFA as a value
Val : STM32_SVD.UInt14;
when True =>
-- FFA as an array
Arr : CAN_FFA1R_FFA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 14;
for CAN_FFA1R_FFA_Field use record
Val at 0 range 0 .. 13;
Arr at 0 range 0 .. 13;
end record;
-- CAN_FFA1R
type CAN_FFA1R_Register is record
-- Filter FIFO assignment for filter 0
FFA : CAN_FFA1R_FFA_Field :=
(As_Array => False, Val => 16#0#);
-- unspecified
Reserved_14_31 : STM32_SVD.UInt18 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_FFA1R_Register use record
FFA at 0 range 0 .. 13;
Reserved_14_31 at 0 range 14 .. 31;
end record;
-- CAN_FA1R_FACT array element
subtype CAN_FA1R_FACT_Element is STM32_SVD.Bit;
-- CAN_FA1R_FACT array
type CAN_FA1R_FACT_Field_Array is array (0 .. 13) of CAN_FA1R_FACT_Element
with Component_Size => 1, Size => 14;
-- Type definition for CAN_FA1R_FACT
type CAN_FA1R_FACT_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FACT as a value
Val : STM32_SVD.UInt14;
when True =>
-- FACT as an array
Arr : CAN_FA1R_FACT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 14;
for CAN_FA1R_FACT_Field use record
Val at 0 range 0 .. 13;
Arr at 0 range 0 .. 13;
end record;
-- CAN_FA1R
type CAN_FA1R_Register is record
-- Filter active
FACT : CAN_FA1R_FACT_Field :=
(As_Array => False, Val => 16#0#);
-- unspecified
Reserved_14_31 : STM32_SVD.UInt18 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CAN_FA1R_Register use record
FACT at 0 range 0 .. 13;
Reserved_14_31 at 0 range 14 .. 31;
end record;
-- F0R_FB array element
subtype F0R_FB_Element is STM32_SVD.Bit;
-- F0R_FB array
type F0R_FB_Field_Array is array (0 .. 31) of F0R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 0 register 1
type F0R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F0R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F0R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F1R_FB array element
subtype F1R_FB_Element is STM32_SVD.Bit;
-- F1R_FB array
type F1R_FB_Field_Array is array (0 .. 31) of F1R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 1 register 1
type F1R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F1R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F1R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F2R_FB array element
subtype F2R_FB_Element is STM32_SVD.Bit;
-- F2R_FB array
type F2R_FB_Field_Array is array (0 .. 31) of F2R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 2 register 1
type F2R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F2R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F2R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F3R_FB array element
subtype F3R_FB_Element is STM32_SVD.Bit;
-- F3R_FB array
type F3R_FB_Field_Array is array (0 .. 31) of F3R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 3 register 1
type F3R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F3R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F3R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F4R_FB array element
subtype F4R_FB_Element is STM32_SVD.Bit;
-- F4R_FB array
type F4R_FB_Field_Array is array (0 .. 31) of F4R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 4 register 1
type F4R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F4R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F4R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F5R_FB array element
subtype F5R_FB_Element is STM32_SVD.Bit;
-- F5R_FB array
type F5R_FB_Field_Array is array (0 .. 31) of F5R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 5 register 1
type F5R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F5R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F5R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F6R_FB array element
subtype F6R_FB_Element is STM32_SVD.Bit;
-- F6R_FB array
type F6R_FB_Field_Array is array (0 .. 31) of F6R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 6 register 1
type F6R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F6R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F6R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F7R_FB array element
subtype F7R_FB_Element is STM32_SVD.Bit;
-- F7R_FB array
type F7R_FB_Field_Array is array (0 .. 31) of F7R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 7 register 1
type F7R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F7R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F7R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F8R_FB array element
subtype F8R_FB_Element is STM32_SVD.Bit;
-- F8R_FB array
type F8R_FB_Field_Array is array (0 .. 31) of F8R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 8 register 1
type F8R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F8R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F8R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F9R_FB array element
subtype F9R_FB_Element is STM32_SVD.Bit;
-- F9R_FB array
type F9R_FB_Field_Array is array (0 .. 31) of F9R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 9 register 1
type F9R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F9R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F9R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F10R_FB array element
subtype F10R_FB_Element is STM32_SVD.Bit;
-- F10R_FB array
type F10R_FB_Field_Array is array (0 .. 31) of F10R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 10 register 1
type F10R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F10R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F10R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F11R_FB array element
subtype F11R_FB_Element is STM32_SVD.Bit;
-- F11R_FB array
type F11R_FB_Field_Array is array (0 .. 31) of F11R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 11 register 1
type F11R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F11R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F11R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F12R_FB array element
subtype F12R_FB_Element is STM32_SVD.Bit;
-- F12R_FB array
type F12R_FB_Field_Array is array (0 .. 31) of F12R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 4 register 1
type F12R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F12R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F12R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- F13R_FB array element
subtype F13R_FB_Element is STM32_SVD.Bit;
-- F13R_FB array
type F13R_FB_Field_Array is array (0 .. 31) of F13R_FB_Element
with Component_Size => 1, Size => 32;
-- Filter bank 13 register 1
type F13R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- FB as a value
Val : STM32_SVD.UInt32;
when True =>
-- FB as an array
Arr : F13R_FB_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for F13R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Controller area network
type CAN_Peripheral is record
-- CAN_MCR
CAN_MCR : aliased CAN_MCR_Register;
-- CAN_MSR
CAN_MSR : aliased CAN_MSR_Register;
-- CAN_TSR
CAN_TSR : aliased CAN_TSR_Register;
-- CAN_RF0R
CAN_RF0R : aliased CAN_RF0R_Register;
-- CAN_RF1R
CAN_RF1R : aliased CAN_RF1R_Register;
-- CAN_IER
CAN_IER : aliased CAN_IER_Register;
-- CAN_ESR
CAN_ESR : aliased CAN_ESR_Register;
-- CAN_BTR
CAN_BTR : aliased CAN_BTR_Register;
-- CAN_TI0R
CAN_TI0R : aliased CAN_TI0R_Register;
-- CAN_TDT0R
CAN_TDT0R : aliased CAN_TDT0R_Register;
-- CAN_TDL0R
CAN_TDL0R : aliased CAN_TDL0R_Register;
-- CAN_TDH0R
CAN_TDH0R : aliased CAN_TDH0R_Register;
-- CAN_TI1R
CAN_TI1R : aliased CAN_TI1R_Register;
-- CAN_TDT1R
CAN_TDT1R : aliased CAN_TDT1R_Register;
-- CAN_TDL1R
CAN_TDL1R : aliased CAN_TDL1R_Register;
-- CAN_TDH1R
CAN_TDH1R : aliased CAN_TDH1R_Register;
-- CAN_TI2R
CAN_TI2R : aliased CAN_TI2R_Register;
-- CAN_TDT2R
CAN_TDT2R : aliased CAN_TDT2R_Register;
-- CAN_TDL2R
CAN_TDL2R : aliased CAN_TDL2R_Register;
-- CAN_TDH2R
CAN_TDH2R : aliased CAN_TDH2R_Register;
-- CAN_RI0R
CAN_RI0R : aliased CAN_RI0R_Register;
-- CAN_RDT0R
CAN_RDT0R : aliased CAN_RDT0R_Register;
-- CAN_RDL0R
CAN_RDL0R : aliased CAN_RDL0R_Register;
-- CAN_RDH0R
CAN_RDH0R : aliased CAN_RDH0R_Register;
-- CAN_RI1R
CAN_RI1R : aliased CAN_RI1R_Register;
-- CAN_RDT1R
CAN_RDT1R : aliased CAN_RDT1R_Register;
-- CAN_RDL1R
CAN_RDL1R : aliased CAN_RDL1R_Register;
-- CAN_RDH1R
CAN_RDH1R : aliased CAN_RDH1R_Register;
-- CAN_FMR
CAN_FMR : aliased CAN_FMR_Register;
-- CAN_FM1R
CAN_FM1R : aliased CAN_FM1R_Register;
-- CAN_FS1R
CAN_FS1R : aliased CAN_FS1R_Register;
-- CAN_FFA1R
CAN_FFA1R : aliased CAN_FFA1R_Register;
-- CAN_FA1R
CAN_FA1R : aliased CAN_FA1R_Register;
-- Filter bank 0 register 1
F0R1 : aliased F0R_Register;
-- Filter bank 0 register 2
F0R2 : aliased F0R_Register;
-- Filter bank 1 register 1
F1R1 : aliased F1R_Register;
-- Filter bank 1 register 2
F1R2 : aliased F1R_Register;
-- Filter bank 2 register 1
F2R1 : aliased F2R_Register;
-- Filter bank 2 register 2
F2R2 : aliased F2R_Register;
-- Filter bank 3 register 1
F3R1 : aliased F3R_Register;
-- Filter bank 3 register 2
F3R2 : aliased F3R_Register;
-- Filter bank 4 register 1
F4R1 : aliased F4R_Register;
-- Filter bank 4 register 2
F4R2 : aliased F4R_Register;
-- Filter bank 5 register 1
F5R1 : aliased F5R_Register;
-- Filter bank 5 register 2
F5R2 : aliased F5R_Register;
-- Filter bank 6 register 1
F6R1 : aliased F6R_Register;
-- Filter bank 6 register 2
F6R2 : aliased F6R_Register;
-- Filter bank 7 register 1
F7R1 : aliased F7R_Register;
-- Filter bank 7 register 2
F7R2 : aliased F7R_Register;
-- Filter bank 8 register 1
F8R1 : aliased F8R_Register;
-- Filter bank 8 register 2
F8R2 : aliased F8R_Register;
-- Filter bank 9 register 1
F9R1 : aliased F9R_Register;
-- Filter bank 9 register 2
F9R2 : aliased F9R_Register;
-- Filter bank 10 register 1
F10R1 : aliased F10R_Register;
-- Filter bank 10 register 2
F10R2 : aliased F10R_Register;
-- Filter bank 11 register 1
F11R1 : aliased F11R_Register;
-- Filter bank 11 register 2
F11R2 : aliased F11R_Register;
-- Filter bank 4 register 1
F12R1 : aliased F12R_Register;
-- Filter bank 12 register 2
F12R2 : aliased F12R_Register;
-- Filter bank 13 register 1
F13R1 : aliased F13R_Register;
-- Filter bank 13 register 2
F13R2 : aliased F13R_Register;
end record
with Volatile;
for CAN_Peripheral use record
CAN_MCR at 16#0# range 0 .. 31;
CAN_MSR at 16#4# range 0 .. 31;
CAN_TSR at 16#8# range 0 .. 31;
CAN_RF0R at 16#C# range 0 .. 31;
CAN_RF1R at 16#10# range 0 .. 31;
CAN_IER at 16#14# range 0 .. 31;
CAN_ESR at 16#18# range 0 .. 31;
CAN_BTR at 16#1C# range 0 .. 31;
CAN_TI0R at 16#180# range 0 .. 31;
CAN_TDT0R at 16#184# range 0 .. 31;
CAN_TDL0R at 16#188# range 0 .. 31;
CAN_TDH0R at 16#18C# range 0 .. 31;
CAN_TI1R at 16#190# range 0 .. 31;
CAN_TDT1R at 16#194# range 0 .. 31;
CAN_TDL1R at 16#198# range 0 .. 31;
CAN_TDH1R at 16#19C# range 0 .. 31;
CAN_TI2R at 16#1A0# range 0 .. 31;
CAN_TDT2R at 16#1A4# range 0 .. 31;
CAN_TDL2R at 16#1A8# range 0 .. 31;
CAN_TDH2R at 16#1AC# range 0 .. 31;
CAN_RI0R at 16#1B0# range 0 .. 31;
CAN_RDT0R at 16#1B4# range 0 .. 31;
CAN_RDL0R at 16#1B8# range 0 .. 31;
CAN_RDH0R at 16#1BC# range 0 .. 31;
CAN_RI1R at 16#1C0# range 0 .. 31;
CAN_RDT1R at 16#1C4# range 0 .. 31;
CAN_RDL1R at 16#1C8# range 0 .. 31;
CAN_RDH1R at 16#1CC# range 0 .. 31;
CAN_FMR at 16#200# range 0 .. 31;
CAN_FM1R at 16#204# range 0 .. 31;
CAN_FS1R at 16#20C# range 0 .. 31;
CAN_FFA1R at 16#214# range 0 .. 31;
CAN_FA1R at 16#21C# range 0 .. 31;
F0R1 at 16#240# range 0 .. 31;
F0R2 at 16#244# range 0 .. 31;
F1R1 at 16#248# range 0 .. 31;
F1R2 at 16#24C# range 0 .. 31;
F2R1 at 16#250# range 0 .. 31;
F2R2 at 16#254# range 0 .. 31;
F3R1 at 16#258# range 0 .. 31;
F3R2 at 16#25C# range 0 .. 31;
F4R1 at 16#260# range 0 .. 31;
F4R2 at 16#264# range 0 .. 31;
F5R1 at 16#268# range 0 .. 31;
F5R2 at 16#26C# range 0 .. 31;
F6R1 at 16#270# range 0 .. 31;
F6R2 at 16#274# range 0 .. 31;
F7R1 at 16#278# range 0 .. 31;
F7R2 at 16#27C# range 0 .. 31;
F8R1 at 16#280# range 0 .. 31;
F8R2 at 16#284# range 0 .. 31;
F9R1 at 16#288# range 0 .. 31;
F9R2 at 16#28C# range 0 .. 31;
F10R1 at 16#290# range 0 .. 31;
F10R2 at 16#294# range 0 .. 31;
F11R1 at 16#298# range 0 .. 31;
F11R2 at 16#29C# range 0 .. 31;
F12R1 at 16#2A0# range 0 .. 31;
F12R2 at 16#2A4# range 0 .. 31;
F13R1 at 16#2A8# range 0 .. 31;
F13R2 at 16#2AC# range 0 .. 31;
end record;
-- Controller area network
CAN1_Periph : aliased CAN_Peripheral
with Import, Address => System'To_Address (16#40006400#);
-- Controller area network
CAN2_Periph : aliased CAN_Peripheral
with Import, Address => System'To_Address (16#40006800#);
end STM32_SVD.CAN;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.