------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
-- --
|
-- --
|
-- GNAT COMPILER COMPONENTS --
|
-- GNAT COMPILER COMPONENTS --
|
-- --
|
-- --
|
-- E X P _ U T I L --
|
-- E X P _ U T I L --
|
-- --
|
-- --
|
-- B o d y --
|
-- B o d y --
|
-- --
|
-- --
|
-- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
|
-- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
|
-- --
|
-- --
|
-- GNAT is free software; you can redistribute it and/or modify it under --
|
-- 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- --
|
-- 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- --
|
-- 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- --
|
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
|
-- 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 --
|
-- 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 --
|
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
|
-- http://www.gnu.org/licenses for a complete copy of the license. --
|
-- http://www.gnu.org/licenses for a complete copy of the license. --
|
-- --
|
-- --
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
-- --
|
-- --
|
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
|
|
with Aspects; use Aspects;
|
with Aspects; use Aspects;
|
with Atree; use Atree;
|
with Atree; use Atree;
|
with Casing; use Casing;
|
with Casing; use Casing;
|
with Checks; use Checks;
|
with Checks; use Checks;
|
with Debug; use Debug;
|
with Debug; use Debug;
|
with Einfo; use Einfo;
|
with Einfo; use Einfo;
|
with Elists; use Elists;
|
with Elists; use Elists;
|
with Errout; use Errout;
|
with Errout; use Errout;
|
with Exp_Aggr; use Exp_Aggr;
|
with Exp_Aggr; use Exp_Aggr;
|
with Exp_Ch6; use Exp_Ch6;
|
with Exp_Ch6; use Exp_Ch6;
|
with Exp_Ch7; use Exp_Ch7;
|
with Exp_Ch7; use Exp_Ch7;
|
with Inline; use Inline;
|
with Inline; use Inline;
|
with Itypes; use Itypes;
|
with Itypes; use Itypes;
|
with Lib; use Lib;
|
with Lib; use Lib;
|
with Nlists; use Nlists;
|
with Nlists; use Nlists;
|
with Nmake; use Nmake;
|
with Nmake; use Nmake;
|
with Opt; use Opt;
|
with Opt; use Opt;
|
with Restrict; use Restrict;
|
with Restrict; use Restrict;
|
with Rident; use Rident;
|
with Rident; use Rident;
|
with Sem; use Sem;
|
with Sem; use Sem;
|
with Sem_Aux; use Sem_Aux;
|
with Sem_Aux; use Sem_Aux;
|
with Sem_Ch8; use Sem_Ch8;
|
with Sem_Ch8; use Sem_Ch8;
|
with Sem_Eval; use Sem_Eval;
|
with Sem_Eval; use Sem_Eval;
|
with Sem_Prag; use Sem_Prag;
|
with Sem_Prag; use Sem_Prag;
|
with Sem_Res; use Sem_Res;
|
with Sem_Res; use Sem_Res;
|
with Sem_Type; use Sem_Type;
|
with Sem_Type; use Sem_Type;
|
with Sem_Util; use Sem_Util;
|
with Sem_Util; use Sem_Util;
|
with Snames; use Snames;
|
with Snames; use Snames;
|
with Stand; use Stand;
|
with Stand; use Stand;
|
with Stringt; use Stringt;
|
with Stringt; use Stringt;
|
with Targparm; use Targparm;
|
with Targparm; use Targparm;
|
with Tbuild; use Tbuild;
|
with Tbuild; use Tbuild;
|
with Ttypes; use Ttypes;
|
with Ttypes; use Ttypes;
|
with Urealp; use Urealp;
|
with Urealp; use Urealp;
|
with Validsw; use Validsw;
|
with Validsw; use Validsw;
|
|
|
package body Exp_Util is
|
package body Exp_Util is
|
|
|
-----------------------
|
-----------------------
|
-- Local Subprograms --
|
-- Local Subprograms --
|
-----------------------
|
-----------------------
|
|
|
function Build_Task_Array_Image
|
function Build_Task_Array_Image
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
Id_Ref : Node_Id;
|
Id_Ref : Node_Id;
|
A_Type : Entity_Id;
|
A_Type : Entity_Id;
|
Dyn : Boolean := False) return Node_Id;
|
Dyn : Boolean := False) return Node_Id;
|
-- Build function to generate the image string for a task that is an array
|
-- Build function to generate the image string for a task that is an array
|
-- component, concatenating the images of each index. To avoid storage
|
-- component, concatenating the images of each index. To avoid storage
|
-- leaks, the string is built with successive slice assignments. The flag
|
-- leaks, the string is built with successive slice assignments. The flag
|
-- Dyn indicates whether this is called for the initialization procedure of
|
-- Dyn indicates whether this is called for the initialization procedure of
|
-- an array of tasks, or for the name of a dynamically created task that is
|
-- an array of tasks, or for the name of a dynamically created task that is
|
-- assigned to an indexed component.
|
-- assigned to an indexed component.
|
|
|
function Build_Task_Image_Function
|
function Build_Task_Image_Function
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
Decls : List_Id;
|
Decls : List_Id;
|
Stats : List_Id;
|
Stats : List_Id;
|
Res : Entity_Id) return Node_Id;
|
Res : Entity_Id) return Node_Id;
|
-- Common processing for Task_Array_Image and Task_Record_Image. Build
|
-- Common processing for Task_Array_Image and Task_Record_Image. Build
|
-- function body that computes image.
|
-- function body that computes image.
|
|
|
procedure Build_Task_Image_Prefix
|
procedure Build_Task_Image_Prefix
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
Len : out Entity_Id;
|
Len : out Entity_Id;
|
Res : out Entity_Id;
|
Res : out Entity_Id;
|
Pos : out Entity_Id;
|
Pos : out Entity_Id;
|
Prefix : Entity_Id;
|
Prefix : Entity_Id;
|
Sum : Node_Id;
|
Sum : Node_Id;
|
Decls : List_Id;
|
Decls : List_Id;
|
Stats : List_Id);
|
Stats : List_Id);
|
-- Common processing for Task_Array_Image and Task_Record_Image. Create
|
-- Common processing for Task_Array_Image and Task_Record_Image. Create
|
-- local variables and assign prefix of name to result string.
|
-- local variables and assign prefix of name to result string.
|
|
|
function Build_Task_Record_Image
|
function Build_Task_Record_Image
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
Id_Ref : Node_Id;
|
Id_Ref : Node_Id;
|
Dyn : Boolean := False) return Node_Id;
|
Dyn : Boolean := False) return Node_Id;
|
-- Build function to generate the image string for a task that is a record
|
-- Build function to generate the image string for a task that is a record
|
-- component. Concatenate name of variable with that of selector. The flag
|
-- component. Concatenate name of variable with that of selector. The flag
|
-- Dyn indicates whether this is called for the initialization procedure of
|
-- Dyn indicates whether this is called for the initialization procedure of
|
-- record with task components, or for a dynamically created task that is
|
-- record with task components, or for a dynamically created task that is
|
-- assigned to a selected component.
|
-- assigned to a selected component.
|
|
|
function Make_CW_Equivalent_Type
|
function Make_CW_Equivalent_Type
|
(T : Entity_Id;
|
(T : Entity_Id;
|
E : Node_Id) return Entity_Id;
|
E : Node_Id) return Entity_Id;
|
-- T is a class-wide type entity, E is the initial expression node that
|
-- T is a class-wide type entity, E is the initial expression node that
|
-- constrains T in case such as: " X: T := E" or "new T'(E)". This function
|
-- constrains T in case such as: " X: T := E" or "new T'(E)". This function
|
-- returns the entity of the Equivalent type and inserts on the fly the
|
-- returns the entity of the Equivalent type and inserts on the fly the
|
-- necessary declaration such as:
|
-- necessary declaration such as:
|
--
|
--
|
-- type anon is record
|
-- type anon is record
|
-- _parent : Root_Type (T); constrained with E discriminants (if any)
|
-- _parent : Root_Type (T); constrained with E discriminants (if any)
|
-- Extension : String (1 .. expr to match size of E);
|
-- Extension : String (1 .. expr to match size of E);
|
-- end record;
|
-- end record;
|
--
|
--
|
-- This record is compatible with any object of the class of T thanks to
|
-- This record is compatible with any object of the class of T thanks to
|
-- the first field and has the same size as E thanks to the second.
|
-- the first field and has the same size as E thanks to the second.
|
|
|
function Make_Literal_Range
|
function Make_Literal_Range
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
Literal_Typ : Entity_Id) return Node_Id;
|
Literal_Typ : Entity_Id) return Node_Id;
|
-- Produce a Range node whose bounds are:
|
-- Produce a Range node whose bounds are:
|
-- Low_Bound (Literal_Type) ..
|
-- Low_Bound (Literal_Type) ..
|
-- Low_Bound (Literal_Type) + (Length (Literal_Typ) - 1)
|
-- Low_Bound (Literal_Type) + (Length (Literal_Typ) - 1)
|
-- this is used for expanding declarations like X : String := "sdfgdfg";
|
-- this is used for expanding declarations like X : String := "sdfgdfg";
|
--
|
--
|
-- If the index type of the target array is not integer, we generate:
|
-- If the index type of the target array is not integer, we generate:
|
-- Low_Bound (Literal_Type) ..
|
-- Low_Bound (Literal_Type) ..
|
-- Literal_Type'Val
|
-- Literal_Type'Val
|
-- (Literal_Type'Pos (Low_Bound (Literal_Type))
|
-- (Literal_Type'Pos (Low_Bound (Literal_Type))
|
-- + (Length (Literal_Typ) -1))
|
-- + (Length (Literal_Typ) -1))
|
|
|
function Make_Non_Empty_Check
|
function Make_Non_Empty_Check
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
N : Node_Id) return Node_Id;
|
N : Node_Id) return Node_Id;
|
-- Produce a boolean expression checking that the unidimensional array
|
-- Produce a boolean expression checking that the unidimensional array
|
-- node N is not empty.
|
-- node N is not empty.
|
|
|
function New_Class_Wide_Subtype
|
function New_Class_Wide_Subtype
|
(CW_Typ : Entity_Id;
|
(CW_Typ : Entity_Id;
|
N : Node_Id) return Entity_Id;
|
N : Node_Id) return Entity_Id;
|
-- Create an implicit subtype of CW_Typ attached to node N
|
-- Create an implicit subtype of CW_Typ attached to node N
|
|
|
function Requires_Cleanup_Actions
|
function Requires_Cleanup_Actions
|
(L : List_Id;
|
(L : List_Id;
|
For_Package : Boolean;
|
For_Package : Boolean;
|
Nested_Constructs : Boolean) return Boolean;
|
Nested_Constructs : Boolean) return Boolean;
|
-- Given a list L, determine whether it contains one of the following:
|
-- Given a list L, determine whether it contains one of the following:
|
--
|
--
|
-- 1) controlled objects
|
-- 1) controlled objects
|
-- 2) library-level tagged types
|
-- 2) library-level tagged types
|
--
|
--
|
-- Flag For_Package should be set when the list comes from a package spec
|
-- Flag For_Package should be set when the list comes from a package spec
|
-- or body. Flag Nested_Constructs should be set when any nested packages
|
-- or body. Flag Nested_Constructs should be set when any nested packages
|
-- declared in L must be processed.
|
-- declared in L must be processed.
|
|
|
-------------------------------------
|
-------------------------------------
|
-- Activate_Atomic_Synchronization --
|
-- Activate_Atomic_Synchronization --
|
-------------------------------------
|
-------------------------------------
|
|
|
procedure Activate_Atomic_Synchronization (N : Node_Id) is
|
procedure Activate_Atomic_Synchronization (N : Node_Id) is
|
Msg_Node : Node_Id;
|
Msg_Node : Node_Id;
|
|
|
begin
|
begin
|
case Nkind (Parent (N)) is
|
case Nkind (Parent (N)) is
|
|
|
-- Check for cases of appearing in the prefix of a construct where
|
-- Check for cases of appearing in the prefix of a construct where
|
-- we don't need atomic synchronization for this kind of usage.
|
-- we don't need atomic synchronization for this kind of usage.
|
|
|
when
|
when
|
-- Nothing to do if we are the prefix of an attribute, since we
|
-- Nothing to do if we are the prefix of an attribute, since we
|
-- do not want an atomic sync operation for things like 'Size.
|
-- do not want an atomic sync operation for things like 'Size.
|
|
|
N_Attribute_Reference |
|
N_Attribute_Reference |
|
|
|
-- The N_Reference node is like an attribute
|
-- The N_Reference node is like an attribute
|
|
|
N_Reference |
|
N_Reference |
|
|
|
-- Nothing to do for a reference to a component (or components)
|
-- Nothing to do for a reference to a component (or components)
|
-- of a composite object. Only reads and updates of the object
|
-- of a composite object. Only reads and updates of the object
|
-- as a whole require atomic synchronization (RM C.6 (15)).
|
-- as a whole require atomic synchronization (RM C.6 (15)).
|
|
|
N_Indexed_Component |
|
N_Indexed_Component |
|
N_Selected_Component |
|
N_Selected_Component |
|
N_Slice =>
|
N_Slice =>
|
|
|
-- For all the above cases, nothing to do if we are the prefix
|
-- For all the above cases, nothing to do if we are the prefix
|
|
|
if Prefix (Parent (N)) = N then
|
if Prefix (Parent (N)) = N then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
when others => null;
|
when others => null;
|
end case;
|
end case;
|
|
|
-- Go ahead and set the flag
|
-- Go ahead and set the flag
|
|
|
Set_Atomic_Sync_Required (N);
|
Set_Atomic_Sync_Required (N);
|
|
|
-- Generate info message if requested
|
-- Generate info message if requested
|
|
|
if Warn_On_Atomic_Synchronization then
|
if Warn_On_Atomic_Synchronization then
|
case Nkind (N) is
|
case Nkind (N) is
|
when N_Identifier =>
|
when N_Identifier =>
|
Msg_Node := N;
|
Msg_Node := N;
|
|
|
when N_Selected_Component | N_Expanded_Name =>
|
when N_Selected_Component | N_Expanded_Name =>
|
Msg_Node := Selector_Name (N);
|
Msg_Node := Selector_Name (N);
|
|
|
when N_Explicit_Dereference | N_Indexed_Component =>
|
when N_Explicit_Dereference | N_Indexed_Component =>
|
Msg_Node := Empty;
|
Msg_Node := Empty;
|
|
|
when others =>
|
when others =>
|
pragma Assert (False);
|
pragma Assert (False);
|
return;
|
return;
|
end case;
|
end case;
|
|
|
if Present (Msg_Node) then
|
if Present (Msg_Node) then
|
Error_Msg_N ("?info: atomic synchronization set for &", Msg_Node);
|
Error_Msg_N ("?info: atomic synchronization set for &", Msg_Node);
|
else
|
else
|
Error_Msg_N ("?info: atomic synchronization set", N);
|
Error_Msg_N ("?info: atomic synchronization set", N);
|
end if;
|
end if;
|
end if;
|
end if;
|
end Activate_Atomic_Synchronization;
|
end Activate_Atomic_Synchronization;
|
|
|
----------------------
|
----------------------
|
-- Adjust_Condition --
|
-- Adjust_Condition --
|
----------------------
|
----------------------
|
|
|
procedure Adjust_Condition (N : Node_Id) is
|
procedure Adjust_Condition (N : Node_Id) is
|
begin
|
begin
|
if No (N) then
|
if No (N) then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
declare
|
declare
|
Loc : constant Source_Ptr := Sloc (N);
|
Loc : constant Source_Ptr := Sloc (N);
|
T : constant Entity_Id := Etype (N);
|
T : constant Entity_Id := Etype (N);
|
Ti : Entity_Id;
|
Ti : Entity_Id;
|
|
|
begin
|
begin
|
-- Defend against a call where the argument has no type, or has a
|
-- Defend against a call where the argument has no type, or has a
|
-- type that is not Boolean. This can occur because of prior errors.
|
-- type that is not Boolean. This can occur because of prior errors.
|
|
|
if No (T) or else not Is_Boolean_Type (T) then
|
if No (T) or else not Is_Boolean_Type (T) then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Apply validity checking if needed
|
-- Apply validity checking if needed
|
|
|
if Validity_Checks_On and Validity_Check_Tests then
|
if Validity_Checks_On and Validity_Check_Tests then
|
Ensure_Valid (N);
|
Ensure_Valid (N);
|
end if;
|
end if;
|
|
|
-- Immediate return if standard boolean, the most common case,
|
-- Immediate return if standard boolean, the most common case,
|
-- where nothing needs to be done.
|
-- where nothing needs to be done.
|
|
|
if Base_Type (T) = Standard_Boolean then
|
if Base_Type (T) = Standard_Boolean then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Case of zero/non-zero semantics or non-standard enumeration
|
-- Case of zero/non-zero semantics or non-standard enumeration
|
-- representation. In each case, we rewrite the node as:
|
-- representation. In each case, we rewrite the node as:
|
|
|
-- ityp!(N) /= False'Enum_Rep
|
-- ityp!(N) /= False'Enum_Rep
|
|
|
-- where ityp is an integer type with large enough size to hold any
|
-- where ityp is an integer type with large enough size to hold any
|
-- value of type T.
|
-- value of type T.
|
|
|
if Nonzero_Is_True (T) or else Has_Non_Standard_Rep (T) then
|
if Nonzero_Is_True (T) or else Has_Non_Standard_Rep (T) then
|
if Esize (T) <= Esize (Standard_Integer) then
|
if Esize (T) <= Esize (Standard_Integer) then
|
Ti := Standard_Integer;
|
Ti := Standard_Integer;
|
else
|
else
|
Ti := Standard_Long_Long_Integer;
|
Ti := Standard_Long_Long_Integer;
|
end if;
|
end if;
|
|
|
Rewrite (N,
|
Rewrite (N,
|
Make_Op_Ne (Loc,
|
Make_Op_Ne (Loc,
|
Left_Opnd => Unchecked_Convert_To (Ti, N),
|
Left_Opnd => Unchecked_Convert_To (Ti, N),
|
Right_Opnd =>
|
Right_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Attribute_Name => Name_Enum_Rep,
|
Attribute_Name => Name_Enum_Rep,
|
Prefix =>
|
Prefix =>
|
New_Occurrence_Of (First_Literal (T), Loc))));
|
New_Occurrence_Of (First_Literal (T), Loc))));
|
Analyze_And_Resolve (N, Standard_Boolean);
|
Analyze_And_Resolve (N, Standard_Boolean);
|
|
|
else
|
else
|
Rewrite (N, Convert_To (Standard_Boolean, N));
|
Rewrite (N, Convert_To (Standard_Boolean, N));
|
Analyze_And_Resolve (N, Standard_Boolean);
|
Analyze_And_Resolve (N, Standard_Boolean);
|
end if;
|
end if;
|
end;
|
end;
|
end Adjust_Condition;
|
end Adjust_Condition;
|
|
|
------------------------
|
------------------------
|
-- Adjust_Result_Type --
|
-- Adjust_Result_Type --
|
------------------------
|
------------------------
|
|
|
procedure Adjust_Result_Type (N : Node_Id; T : Entity_Id) is
|
procedure Adjust_Result_Type (N : Node_Id; T : Entity_Id) is
|
begin
|
begin
|
-- Ignore call if current type is not Standard.Boolean
|
-- Ignore call if current type is not Standard.Boolean
|
|
|
if Etype (N) /= Standard_Boolean then
|
if Etype (N) /= Standard_Boolean then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- If result is already of correct type, nothing to do. Note that
|
-- If result is already of correct type, nothing to do. Note that
|
-- this will get the most common case where everything has a type
|
-- this will get the most common case where everything has a type
|
-- of Standard.Boolean.
|
-- of Standard.Boolean.
|
|
|
if Base_Type (T) = Standard_Boolean then
|
if Base_Type (T) = Standard_Boolean then
|
return;
|
return;
|
|
|
else
|
else
|
declare
|
declare
|
KP : constant Node_Kind := Nkind (Parent (N));
|
KP : constant Node_Kind := Nkind (Parent (N));
|
|
|
begin
|
begin
|
-- If result is to be used as a Condition in the syntax, no need
|
-- If result is to be used as a Condition in the syntax, no need
|
-- to convert it back, since if it was changed to Standard.Boolean
|
-- to convert it back, since if it was changed to Standard.Boolean
|
-- using Adjust_Condition, that is just fine for this usage.
|
-- using Adjust_Condition, that is just fine for this usage.
|
|
|
if KP in N_Raise_xxx_Error or else KP in N_Has_Condition then
|
if KP in N_Raise_xxx_Error or else KP in N_Has_Condition then
|
return;
|
return;
|
|
|
-- If result is an operand of another logical operation, no need
|
-- If result is an operand of another logical operation, no need
|
-- to reset its type, since Standard.Boolean is just fine, and
|
-- to reset its type, since Standard.Boolean is just fine, and
|
-- such operations always do Adjust_Condition on their operands.
|
-- such operations always do Adjust_Condition on their operands.
|
|
|
elsif KP in N_Op_Boolean
|
elsif KP in N_Op_Boolean
|
or else KP in N_Short_Circuit
|
or else KP in N_Short_Circuit
|
or else KP = N_Op_Not
|
or else KP = N_Op_Not
|
then
|
then
|
return;
|
return;
|
|
|
-- Otherwise we perform a conversion from the current type, which
|
-- Otherwise we perform a conversion from the current type, which
|
-- must be Standard.Boolean, to the desired type.
|
-- must be Standard.Boolean, to the desired type.
|
|
|
else
|
else
|
Set_Analyzed (N);
|
Set_Analyzed (N);
|
Rewrite (N, Convert_To (T, N));
|
Rewrite (N, Convert_To (T, N));
|
Analyze_And_Resolve (N, T);
|
Analyze_And_Resolve (N, T);
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
end Adjust_Result_Type;
|
end Adjust_Result_Type;
|
|
|
--------------------------
|
--------------------------
|
-- Append_Freeze_Action --
|
-- Append_Freeze_Action --
|
--------------------------
|
--------------------------
|
|
|
procedure Append_Freeze_Action (T : Entity_Id; N : Node_Id) is
|
procedure Append_Freeze_Action (T : Entity_Id; N : Node_Id) is
|
Fnode : Node_Id;
|
Fnode : Node_Id;
|
|
|
begin
|
begin
|
Ensure_Freeze_Node (T);
|
Ensure_Freeze_Node (T);
|
Fnode := Freeze_Node (T);
|
Fnode := Freeze_Node (T);
|
|
|
if No (Actions (Fnode)) then
|
if No (Actions (Fnode)) then
|
Set_Actions (Fnode, New_List);
|
Set_Actions (Fnode, New_List);
|
end if;
|
end if;
|
|
|
Append (N, Actions (Fnode));
|
Append (N, Actions (Fnode));
|
end Append_Freeze_Action;
|
end Append_Freeze_Action;
|
|
|
---------------------------
|
---------------------------
|
-- Append_Freeze_Actions --
|
-- Append_Freeze_Actions --
|
---------------------------
|
---------------------------
|
|
|
procedure Append_Freeze_Actions (T : Entity_Id; L : List_Id) is
|
procedure Append_Freeze_Actions (T : Entity_Id; L : List_Id) is
|
Fnode : constant Node_Id := Freeze_Node (T);
|
Fnode : constant Node_Id := Freeze_Node (T);
|
|
|
begin
|
begin
|
if No (L) then
|
if No (L) then
|
return;
|
return;
|
|
|
else
|
else
|
if No (Actions (Fnode)) then
|
if No (Actions (Fnode)) then
|
Set_Actions (Fnode, L);
|
Set_Actions (Fnode, L);
|
else
|
else
|
Append_List (L, Actions (Fnode));
|
Append_List (L, Actions (Fnode));
|
end if;
|
end if;
|
end if;
|
end if;
|
end Append_Freeze_Actions;
|
end Append_Freeze_Actions;
|
|
|
------------------------------------
|
------------------------------------
|
-- Build_Allocate_Deallocate_Proc --
|
-- Build_Allocate_Deallocate_Proc --
|
------------------------------------
|
------------------------------------
|
|
|
procedure Build_Allocate_Deallocate_Proc
|
procedure Build_Allocate_Deallocate_Proc
|
(N : Node_Id;
|
(N : Node_Id;
|
Is_Allocate : Boolean)
|
Is_Allocate : Boolean)
|
is
|
is
|
Desig_Typ : Entity_Id;
|
Desig_Typ : Entity_Id;
|
Expr : Node_Id;
|
Expr : Node_Id;
|
Pool_Id : Entity_Id;
|
Pool_Id : Entity_Id;
|
Proc_To_Call : Node_Id := Empty;
|
Proc_To_Call : Node_Id := Empty;
|
Ptr_Typ : Entity_Id;
|
Ptr_Typ : Entity_Id;
|
|
|
function Find_Finalize_Address (Typ : Entity_Id) return Entity_Id;
|
function Find_Finalize_Address (Typ : Entity_Id) return Entity_Id;
|
-- Locate TSS primitive Finalize_Address in type Typ
|
-- Locate TSS primitive Finalize_Address in type Typ
|
|
|
function Find_Object (E : Node_Id) return Node_Id;
|
function Find_Object (E : Node_Id) return Node_Id;
|
-- Given an arbitrary expression of an allocator, try to find an object
|
-- Given an arbitrary expression of an allocator, try to find an object
|
-- reference in it, otherwise return the original expression.
|
-- reference in it, otherwise return the original expression.
|
|
|
function Is_Allocate_Deallocate_Proc (Subp : Entity_Id) return Boolean;
|
function Is_Allocate_Deallocate_Proc (Subp : Entity_Id) return Boolean;
|
-- Determine whether subprogram Subp denotes a custom allocate or
|
-- Determine whether subprogram Subp denotes a custom allocate or
|
-- deallocate.
|
-- deallocate.
|
|
|
---------------------------
|
---------------------------
|
-- Find_Finalize_Address --
|
-- Find_Finalize_Address --
|
---------------------------
|
---------------------------
|
|
|
function Find_Finalize_Address (Typ : Entity_Id) return Entity_Id is
|
function Find_Finalize_Address (Typ : Entity_Id) return Entity_Id is
|
Utyp : Entity_Id := Typ;
|
Utyp : Entity_Id := Typ;
|
|
|
begin
|
begin
|
-- Handle protected class-wide or task class-wide types
|
-- Handle protected class-wide or task class-wide types
|
|
|
if Is_Class_Wide_Type (Utyp) then
|
if Is_Class_Wide_Type (Utyp) then
|
if Is_Concurrent_Type (Root_Type (Utyp)) then
|
if Is_Concurrent_Type (Root_Type (Utyp)) then
|
Utyp := Root_Type (Utyp);
|
Utyp := Root_Type (Utyp);
|
|
|
elsif Is_Private_Type (Root_Type (Utyp))
|
elsif Is_Private_Type (Root_Type (Utyp))
|
and then Present (Full_View (Root_Type (Utyp)))
|
and then Present (Full_View (Root_Type (Utyp)))
|
and then Is_Concurrent_Type (Full_View (Root_Type (Utyp)))
|
and then Is_Concurrent_Type (Full_View (Root_Type (Utyp)))
|
then
|
then
|
Utyp := Full_View (Root_Type (Utyp));
|
Utyp := Full_View (Root_Type (Utyp));
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- Handle private types
|
-- Handle private types
|
|
|
if Is_Private_Type (Utyp)
|
if Is_Private_Type (Utyp)
|
and then Present (Full_View (Utyp))
|
and then Present (Full_View (Utyp))
|
then
|
then
|
Utyp := Full_View (Utyp);
|
Utyp := Full_View (Utyp);
|
end if;
|
end if;
|
|
|
-- Handle protected and task types
|
-- Handle protected and task types
|
|
|
if Is_Concurrent_Type (Utyp)
|
if Is_Concurrent_Type (Utyp)
|
and then Present (Corresponding_Record_Type (Utyp))
|
and then Present (Corresponding_Record_Type (Utyp))
|
then
|
then
|
Utyp := Corresponding_Record_Type (Utyp);
|
Utyp := Corresponding_Record_Type (Utyp);
|
end if;
|
end if;
|
|
|
Utyp := Underlying_Type (Base_Type (Utyp));
|
Utyp := Underlying_Type (Base_Type (Utyp));
|
|
|
-- Deal with non-tagged derivation of private views. If the parent is
|
-- Deal with non-tagged derivation of private views. If the parent is
|
-- now known to be protected, the finalization routine is the one
|
-- now known to be protected, the finalization routine is the one
|
-- defined on the corresponding record of the ancestor (corresponding
|
-- defined on the corresponding record of the ancestor (corresponding
|
-- records do not automatically inherit operations, but maybe they
|
-- records do not automatically inherit operations, but maybe they
|
-- should???)
|
-- should???)
|
|
|
if Is_Untagged_Derivation (Typ) then
|
if Is_Untagged_Derivation (Typ) then
|
if Is_Protected_Type (Typ) then
|
if Is_Protected_Type (Typ) then
|
Utyp := Corresponding_Record_Type (Root_Type (Base_Type (Typ)));
|
Utyp := Corresponding_Record_Type (Root_Type (Base_Type (Typ)));
|
else
|
else
|
Utyp := Underlying_Type (Root_Type (Base_Type (Typ)));
|
Utyp := Underlying_Type (Root_Type (Base_Type (Typ)));
|
|
|
if Is_Protected_Type (Utyp) then
|
if Is_Protected_Type (Utyp) then
|
Utyp := Corresponding_Record_Type (Utyp);
|
Utyp := Corresponding_Record_Type (Utyp);
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- If the underlying_type is a subtype, we are dealing with the
|
-- If the underlying_type is a subtype, we are dealing with the
|
-- completion of a private type. We need to access the base type and
|
-- completion of a private type. We need to access the base type and
|
-- generate a conversion to it.
|
-- generate a conversion to it.
|
|
|
if Utyp /= Base_Type (Utyp) then
|
if Utyp /= Base_Type (Utyp) then
|
pragma Assert (Is_Private_Type (Typ));
|
pragma Assert (Is_Private_Type (Typ));
|
|
|
Utyp := Base_Type (Utyp);
|
Utyp := Base_Type (Utyp);
|
end if;
|
end if;
|
|
|
-- When dealing with an internally built full view for a type with
|
-- When dealing with an internally built full view for a type with
|
-- unknown discriminants, use the original record type.
|
-- unknown discriminants, use the original record type.
|
|
|
if Is_Underlying_Record_View (Utyp) then
|
if Is_Underlying_Record_View (Utyp) then
|
Utyp := Etype (Utyp);
|
Utyp := Etype (Utyp);
|
end if;
|
end if;
|
|
|
return TSS (Utyp, TSS_Finalize_Address);
|
return TSS (Utyp, TSS_Finalize_Address);
|
end Find_Finalize_Address;
|
end Find_Finalize_Address;
|
|
|
-----------------
|
-----------------
|
-- Find_Object --
|
-- Find_Object --
|
-----------------
|
-----------------
|
|
|
function Find_Object (E : Node_Id) return Node_Id is
|
function Find_Object (E : Node_Id) return Node_Id is
|
Expr : Node_Id;
|
Expr : Node_Id;
|
|
|
begin
|
begin
|
pragma Assert (Is_Allocate);
|
pragma Assert (Is_Allocate);
|
|
|
Expr := E;
|
Expr := E;
|
loop
|
loop
|
if Nkind_In (Expr, N_Qualified_Expression,
|
if Nkind_In (Expr, N_Qualified_Expression,
|
N_Unchecked_Type_Conversion)
|
N_Unchecked_Type_Conversion)
|
then
|
then
|
Expr := Expression (Expr);
|
Expr := Expression (Expr);
|
|
|
elsif Nkind (Expr) = N_Explicit_Dereference then
|
elsif Nkind (Expr) = N_Explicit_Dereference then
|
Expr := Prefix (Expr);
|
Expr := Prefix (Expr);
|
|
|
else
|
else
|
exit;
|
exit;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
return Expr;
|
return Expr;
|
end Find_Object;
|
end Find_Object;
|
|
|
---------------------------------
|
---------------------------------
|
-- Is_Allocate_Deallocate_Proc --
|
-- Is_Allocate_Deallocate_Proc --
|
---------------------------------
|
---------------------------------
|
|
|
function Is_Allocate_Deallocate_Proc (Subp : Entity_Id) return Boolean is
|
function Is_Allocate_Deallocate_Proc (Subp : Entity_Id) return Boolean is
|
begin
|
begin
|
-- Look for a subprogram body with only one statement which is a
|
-- Look for a subprogram body with only one statement which is a
|
-- call to Allocate_Any_Controlled / Deallocate_Any_Controlled.
|
-- call to Allocate_Any_Controlled / Deallocate_Any_Controlled.
|
|
|
if Ekind (Subp) = E_Procedure
|
if Ekind (Subp) = E_Procedure
|
and then Nkind (Parent (Parent (Subp))) = N_Subprogram_Body
|
and then Nkind (Parent (Parent (Subp))) = N_Subprogram_Body
|
then
|
then
|
declare
|
declare
|
HSS : constant Node_Id :=
|
HSS : constant Node_Id :=
|
Handled_Statement_Sequence (Parent (Parent (Subp)));
|
Handled_Statement_Sequence (Parent (Parent (Subp)));
|
Proc : Entity_Id;
|
Proc : Entity_Id;
|
|
|
begin
|
begin
|
if Present (Statements (HSS))
|
if Present (Statements (HSS))
|
and then Nkind (First (Statements (HSS))) =
|
and then Nkind (First (Statements (HSS))) =
|
N_Procedure_Call_Statement
|
N_Procedure_Call_Statement
|
then
|
then
|
Proc := Entity (Name (First (Statements (HSS))));
|
Proc := Entity (Name (First (Statements (HSS))));
|
|
|
return
|
return
|
Is_RTE (Proc, RE_Allocate_Any_Controlled)
|
Is_RTE (Proc, RE_Allocate_Any_Controlled)
|
or else Is_RTE (Proc, RE_Deallocate_Any_Controlled);
|
or else Is_RTE (Proc, RE_Deallocate_Any_Controlled);
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
return False;
|
return False;
|
end Is_Allocate_Deallocate_Proc;
|
end Is_Allocate_Deallocate_Proc;
|
|
|
-- Start of processing for Build_Allocate_Deallocate_Proc
|
-- Start of processing for Build_Allocate_Deallocate_Proc
|
|
|
begin
|
begin
|
-- Do not perform this expansion in Alfa mode because it is not
|
-- Do not perform this expansion in Alfa mode because it is not
|
-- necessary.
|
-- necessary.
|
|
|
if Alfa_Mode then
|
if Alfa_Mode then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Obtain the attributes of the allocation / deallocation
|
-- Obtain the attributes of the allocation / deallocation
|
|
|
if Nkind (N) = N_Free_Statement then
|
if Nkind (N) = N_Free_Statement then
|
Expr := Expression (N);
|
Expr := Expression (N);
|
Ptr_Typ := Base_Type (Etype (Expr));
|
Ptr_Typ := Base_Type (Etype (Expr));
|
Proc_To_Call := Procedure_To_Call (N);
|
Proc_To_Call := Procedure_To_Call (N);
|
|
|
else
|
else
|
if Nkind (N) = N_Object_Declaration then
|
if Nkind (N) = N_Object_Declaration then
|
Expr := Expression (N);
|
Expr := Expression (N);
|
else
|
else
|
Expr := N;
|
Expr := N;
|
end if;
|
end if;
|
|
|
-- In certain cases an allocator with a qualified expression may
|
-- In certain cases an allocator with a qualified expression may
|
-- be relocated and used as the initialization expression of a
|
-- be relocated and used as the initialization expression of a
|
-- temporary:
|
-- temporary:
|
|
|
-- before:
|
-- before:
|
-- Obj : Ptr_Typ := new Desig_Typ'(...);
|
-- Obj : Ptr_Typ := new Desig_Typ'(...);
|
|
|
-- after:
|
-- after:
|
-- Tmp : Ptr_Typ := new Desig_Typ'(...);
|
-- Tmp : Ptr_Typ := new Desig_Typ'(...);
|
-- Obj : Ptr_Typ := Tmp;
|
-- Obj : Ptr_Typ := Tmp;
|
|
|
-- Since the allocator is always marked as analyzed to avoid infinite
|
-- Since the allocator is always marked as analyzed to avoid infinite
|
-- expansion, it will never be processed by this routine given that
|
-- expansion, it will never be processed by this routine given that
|
-- the designated type needs finalization actions. Detect this case
|
-- the designated type needs finalization actions. Detect this case
|
-- and complete the expansion of the allocator.
|
-- and complete the expansion of the allocator.
|
|
|
if Nkind (Expr) = N_Identifier
|
if Nkind (Expr) = N_Identifier
|
and then Nkind (Parent (Entity (Expr))) = N_Object_Declaration
|
and then Nkind (Parent (Entity (Expr))) = N_Object_Declaration
|
and then Nkind (Expression (Parent (Entity (Expr)))) = N_Allocator
|
and then Nkind (Expression (Parent (Entity (Expr)))) = N_Allocator
|
then
|
then
|
Build_Allocate_Deallocate_Proc (Parent (Entity (Expr)), True);
|
Build_Allocate_Deallocate_Proc (Parent (Entity (Expr)), True);
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- The allocator may have been rewritten into something else in which
|
-- The allocator may have been rewritten into something else in which
|
-- case the expansion performed by this routine does not apply.
|
-- case the expansion performed by this routine does not apply.
|
|
|
if Nkind (Expr) /= N_Allocator then
|
if Nkind (Expr) /= N_Allocator then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
Ptr_Typ := Base_Type (Etype (Expr));
|
Ptr_Typ := Base_Type (Etype (Expr));
|
Proc_To_Call := Procedure_To_Call (Expr);
|
Proc_To_Call := Procedure_To_Call (Expr);
|
end if;
|
end if;
|
|
|
Pool_Id := Associated_Storage_Pool (Ptr_Typ);
|
Pool_Id := Associated_Storage_Pool (Ptr_Typ);
|
Desig_Typ := Available_View (Designated_Type (Ptr_Typ));
|
Desig_Typ := Available_View (Designated_Type (Ptr_Typ));
|
|
|
-- Handle concurrent types
|
-- Handle concurrent types
|
|
|
if Is_Concurrent_Type (Desig_Typ)
|
if Is_Concurrent_Type (Desig_Typ)
|
and then Present (Corresponding_Record_Type (Desig_Typ))
|
and then Present (Corresponding_Record_Type (Desig_Typ))
|
then
|
then
|
Desig_Typ := Corresponding_Record_Type (Desig_Typ);
|
Desig_Typ := Corresponding_Record_Type (Desig_Typ);
|
end if;
|
end if;
|
|
|
-- Do not process allocations / deallocations without a pool
|
-- Do not process allocations / deallocations without a pool
|
|
|
if No (Pool_Id) then
|
if No (Pool_Id) then
|
return;
|
return;
|
|
|
-- Do not process allocations on / deallocations from the secondary
|
-- Do not process allocations on / deallocations from the secondary
|
-- stack.
|
-- stack.
|
|
|
elsif Is_RTE (Pool_Id, RE_SS_Pool) then
|
elsif Is_RTE (Pool_Id, RE_SS_Pool) then
|
return;
|
return;
|
|
|
-- Do not replicate the machinery if the allocator / free has already
|
-- Do not replicate the machinery if the allocator / free has already
|
-- been expanded and has a custom Allocate / Deallocate.
|
-- been expanded and has a custom Allocate / Deallocate.
|
|
|
elsif Present (Proc_To_Call)
|
elsif Present (Proc_To_Call)
|
and then Is_Allocate_Deallocate_Proc (Proc_To_Call)
|
and then Is_Allocate_Deallocate_Proc (Proc_To_Call)
|
then
|
then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
if Needs_Finalization (Desig_Typ) then
|
if Needs_Finalization (Desig_Typ) then
|
|
|
-- Certain run-time configurations and targets do not provide support
|
-- Certain run-time configurations and targets do not provide support
|
-- for controlled types.
|
-- for controlled types.
|
|
|
if Restriction_Active (No_Finalization) then
|
if Restriction_Active (No_Finalization) then
|
return;
|
return;
|
|
|
-- Do nothing if the access type may never allocate / deallocate
|
-- Do nothing if the access type may never allocate / deallocate
|
-- objects.
|
-- objects.
|
|
|
elsif No_Pool_Assigned (Ptr_Typ) then
|
elsif No_Pool_Assigned (Ptr_Typ) then
|
return;
|
return;
|
|
|
-- Access-to-controlled types are not supported on .NET/JVM since
|
-- Access-to-controlled types are not supported on .NET/JVM since
|
-- these targets cannot support pools and address arithmetic.
|
-- these targets cannot support pools and address arithmetic.
|
|
|
elsif VM_Target /= No_VM then
|
elsif VM_Target /= No_VM then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- The allocation / deallocation of a controlled object must be
|
-- The allocation / deallocation of a controlled object must be
|
-- chained on / detached from a finalization master.
|
-- chained on / detached from a finalization master.
|
|
|
pragma Assert (Present (Finalization_Master (Ptr_Typ)));
|
pragma Assert (Present (Finalization_Master (Ptr_Typ)));
|
|
|
-- The only other kind of allocation / deallocation supported by this
|
-- The only other kind of allocation / deallocation supported by this
|
-- routine is on / from a subpool.
|
-- routine is on / from a subpool.
|
|
|
elsif Nkind (Expr) = N_Allocator
|
elsif Nkind (Expr) = N_Allocator
|
and then No (Subpool_Handle_Name (Expr))
|
and then No (Subpool_Handle_Name (Expr))
|
then
|
then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
declare
|
declare
|
Loc : constant Source_Ptr := Sloc (N);
|
Loc : constant Source_Ptr := Sloc (N);
|
Addr_Id : constant Entity_Id := Make_Temporary (Loc, 'A');
|
Addr_Id : constant Entity_Id := Make_Temporary (Loc, 'A');
|
Alig_Id : constant Entity_Id := Make_Temporary (Loc, 'L');
|
Alig_Id : constant Entity_Id := Make_Temporary (Loc, 'L');
|
Proc_Id : constant Entity_Id := Make_Temporary (Loc, 'P');
|
Proc_Id : constant Entity_Id := Make_Temporary (Loc, 'P');
|
Size_Id : constant Entity_Id := Make_Temporary (Loc, 'S');
|
Size_Id : constant Entity_Id := Make_Temporary (Loc, 'S');
|
|
|
Actuals : List_Id;
|
Actuals : List_Id;
|
Fin_Addr_Id : Entity_Id;
|
Fin_Addr_Id : Entity_Id;
|
Fin_Mas_Act : Node_Id;
|
Fin_Mas_Act : Node_Id;
|
Fin_Mas_Id : Entity_Id;
|
Fin_Mas_Id : Entity_Id;
|
Proc_To_Call : Entity_Id;
|
Proc_To_Call : Entity_Id;
|
Subpool : Node_Id := Empty;
|
Subpool : Node_Id := Empty;
|
|
|
begin
|
begin
|
-- Step 1: Construct all the actuals for the call to library routine
|
-- Step 1: Construct all the actuals for the call to library routine
|
-- Allocate_Any_Controlled / Deallocate_Any_Controlled.
|
-- Allocate_Any_Controlled / Deallocate_Any_Controlled.
|
|
|
-- a) Storage pool
|
-- a) Storage pool
|
|
|
Actuals := New_List (New_Reference_To (Pool_Id, Loc));
|
Actuals := New_List (New_Reference_To (Pool_Id, Loc));
|
|
|
if Is_Allocate then
|
if Is_Allocate then
|
|
|
-- b) Subpool
|
-- b) Subpool
|
|
|
if Nkind (Expr) = N_Allocator then
|
if Nkind (Expr) = N_Allocator then
|
Subpool := Subpool_Handle_Name (Expr);
|
Subpool := Subpool_Handle_Name (Expr);
|
end if;
|
end if;
|
|
|
if Present (Subpool) then
|
if Present (Subpool) then
|
Append_To (Actuals, New_Reference_To (Entity (Subpool), Loc));
|
Append_To (Actuals, New_Reference_To (Entity (Subpool), Loc));
|
else
|
else
|
Append_To (Actuals, Make_Null (Loc));
|
Append_To (Actuals, Make_Null (Loc));
|
end if;
|
end if;
|
|
|
-- c) Finalization master
|
-- c) Finalization master
|
|
|
if Needs_Finalization (Desig_Typ) then
|
if Needs_Finalization (Desig_Typ) then
|
Fin_Mas_Id := Finalization_Master (Ptr_Typ);
|
Fin_Mas_Id := Finalization_Master (Ptr_Typ);
|
Fin_Mas_Act := New_Reference_To (Fin_Mas_Id, Loc);
|
Fin_Mas_Act := New_Reference_To (Fin_Mas_Id, Loc);
|
|
|
-- Handle the case where the master is actually a pointer to a
|
-- Handle the case where the master is actually a pointer to a
|
-- master. This case arises in build-in-place functions.
|
-- master. This case arises in build-in-place functions.
|
|
|
if Is_Access_Type (Etype (Fin_Mas_Id)) then
|
if Is_Access_Type (Etype (Fin_Mas_Id)) then
|
Append_To (Actuals, Fin_Mas_Act);
|
Append_To (Actuals, Fin_Mas_Act);
|
else
|
else
|
Append_To (Actuals,
|
Append_To (Actuals,
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix => Fin_Mas_Act,
|
Prefix => Fin_Mas_Act,
|
Attribute_Name => Name_Unrestricted_Access));
|
Attribute_Name => Name_Unrestricted_Access));
|
end if;
|
end if;
|
else
|
else
|
Append_To (Actuals, Make_Null (Loc));
|
Append_To (Actuals, Make_Null (Loc));
|
end if;
|
end if;
|
|
|
-- d) Finalize_Address
|
-- d) Finalize_Address
|
|
|
-- Primitive Finalize_Address is never generated in CodePeer mode
|
-- Primitive Finalize_Address is never generated in CodePeer mode
|
-- since it contains an Unchecked_Conversion.
|
-- since it contains an Unchecked_Conversion.
|
|
|
if Needs_Finalization (Desig_Typ)
|
if Needs_Finalization (Desig_Typ)
|
and then not CodePeer_Mode
|
and then not CodePeer_Mode
|
then
|
then
|
Fin_Addr_Id := Find_Finalize_Address (Desig_Typ);
|
Fin_Addr_Id := Find_Finalize_Address (Desig_Typ);
|
pragma Assert (Present (Fin_Addr_Id));
|
pragma Assert (Present (Fin_Addr_Id));
|
|
|
Append_To (Actuals,
|
Append_To (Actuals,
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix => New_Reference_To (Fin_Addr_Id, Loc),
|
Prefix => New_Reference_To (Fin_Addr_Id, Loc),
|
Attribute_Name => Name_Unrestricted_Access));
|
Attribute_Name => Name_Unrestricted_Access));
|
else
|
else
|
Append_To (Actuals, Make_Null (Loc));
|
Append_To (Actuals, Make_Null (Loc));
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- e) Address
|
-- e) Address
|
-- f) Storage_Size
|
-- f) Storage_Size
|
-- g) Alignment
|
-- g) Alignment
|
|
|
Append_To (Actuals, New_Reference_To (Addr_Id, Loc));
|
Append_To (Actuals, New_Reference_To (Addr_Id, Loc));
|
Append_To (Actuals, New_Reference_To (Size_Id, Loc));
|
Append_To (Actuals, New_Reference_To (Size_Id, Loc));
|
|
|
if Is_Allocate or else not Is_Class_Wide_Type (Desig_Typ) then
|
if Is_Allocate or else not Is_Class_Wide_Type (Desig_Typ) then
|
Append_To (Actuals, New_Reference_To (Alig_Id, Loc));
|
Append_To (Actuals, New_Reference_To (Alig_Id, Loc));
|
|
|
-- For deallocation of class wide types we obtain the value of
|
-- For deallocation of class wide types we obtain the value of
|
-- alignment from the Type Specific Record of the deallocated object.
|
-- alignment from the Type Specific Record of the deallocated object.
|
-- This is needed because the frontend expansion of class-wide types
|
-- This is needed because the frontend expansion of class-wide types
|
-- into equivalent types confuses the backend.
|
-- into equivalent types confuses the backend.
|
|
|
else
|
else
|
-- Generate:
|
-- Generate:
|
-- Obj.all'Alignment
|
-- Obj.all'Alignment
|
|
|
-- ... because 'Alignment applied to class-wide types is expanded
|
-- ... because 'Alignment applied to class-wide types is expanded
|
-- into the code that reads the value of alignment from the TSD
|
-- into the code that reads the value of alignment from the TSD
|
-- (see Expand_N_Attribute_Reference)
|
-- (see Expand_N_Attribute_Reference)
|
|
|
Append_To (Actuals,
|
Append_To (Actuals,
|
Unchecked_Convert_To (RTE (RE_Storage_Offset),
|
Unchecked_Convert_To (RTE (RE_Storage_Offset),
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix =>
|
Prefix =>
|
Make_Explicit_Dereference (Loc, Relocate_Node (Expr)),
|
Make_Explicit_Dereference (Loc, Relocate_Node (Expr)),
|
Attribute_Name => Name_Alignment)));
|
Attribute_Name => Name_Alignment)));
|
end if;
|
end if;
|
|
|
-- h) Is_Controlled
|
-- h) Is_Controlled
|
|
|
-- Generate a run-time check to determine whether a class-wide object
|
-- Generate a run-time check to determine whether a class-wide object
|
-- is truly controlled.
|
-- is truly controlled.
|
|
|
if Needs_Finalization (Desig_Typ) then
|
if Needs_Finalization (Desig_Typ) then
|
if Is_Class_Wide_Type (Desig_Typ)
|
if Is_Class_Wide_Type (Desig_Typ)
|
or else Is_Generic_Actual_Type (Desig_Typ)
|
or else Is_Generic_Actual_Type (Desig_Typ)
|
then
|
then
|
declare
|
declare
|
Flag_Id : constant Entity_Id := Make_Temporary (Loc, 'F');
|
Flag_Id : constant Entity_Id := Make_Temporary (Loc, 'F');
|
Flag_Expr : Node_Id;
|
Flag_Expr : Node_Id;
|
Param : Node_Id;
|
Param : Node_Id;
|
Temp : Node_Id;
|
Temp : Node_Id;
|
|
|
begin
|
begin
|
if Is_Allocate then
|
if Is_Allocate then
|
Temp := Find_Object (Expression (Expr));
|
Temp := Find_Object (Expression (Expr));
|
else
|
else
|
Temp := Expr;
|
Temp := Expr;
|
end if;
|
end if;
|
|
|
-- Processing for generic actuals
|
-- Processing for generic actuals
|
|
|
if Is_Generic_Actual_Type (Desig_Typ) then
|
if Is_Generic_Actual_Type (Desig_Typ) then
|
Flag_Expr :=
|
Flag_Expr :=
|
New_Reference_To (Boolean_Literals
|
New_Reference_To (Boolean_Literals
|
(Needs_Finalization (Base_Type (Desig_Typ))), Loc);
|
(Needs_Finalization (Base_Type (Desig_Typ))), Loc);
|
|
|
-- Processing for subtype indications
|
-- Processing for subtype indications
|
|
|
elsif Nkind (Temp) in N_Has_Entity
|
elsif Nkind (Temp) in N_Has_Entity
|
and then Is_Type (Entity (Temp))
|
and then Is_Type (Entity (Temp))
|
then
|
then
|
Flag_Expr :=
|
Flag_Expr :=
|
New_Reference_To (Boolean_Literals
|
New_Reference_To (Boolean_Literals
|
(Needs_Finalization (Entity (Temp))), Loc);
|
(Needs_Finalization (Entity (Temp))), Loc);
|
|
|
-- Generate a runtime check to test the controlled state of
|
-- Generate a runtime check to test the controlled state of
|
-- an object for the purposes of allocation / deallocation.
|
-- an object for the purposes of allocation / deallocation.
|
|
|
else
|
else
|
-- The following case arises when allocating through an
|
-- The following case arises when allocating through an
|
-- interface class-wide type, generate:
|
-- interface class-wide type, generate:
|
--
|
--
|
-- Temp.all
|
-- Temp.all
|
|
|
if Is_RTE (Etype (Temp), RE_Tag_Ptr) then
|
if Is_RTE (Etype (Temp), RE_Tag_Ptr) then
|
Param :=
|
Param :=
|
Make_Explicit_Dereference (Loc,
|
Make_Explicit_Dereference (Loc,
|
Prefix =>
|
Prefix =>
|
Relocate_Node (Temp));
|
Relocate_Node (Temp));
|
|
|
-- Generate:
|
-- Generate:
|
-- Temp'Tag
|
-- Temp'Tag
|
|
|
else
|
else
|
Param :=
|
Param :=
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix =>
|
Prefix =>
|
Relocate_Node (Temp),
|
Relocate_Node (Temp),
|
Attribute_Name => Name_Tag);
|
Attribute_Name => Name_Tag);
|
end if;
|
end if;
|
|
|
-- Generate:
|
-- Generate:
|
-- Needs_Finalization (<Param>)
|
-- Needs_Finalization (<Param>)
|
|
|
Flag_Expr :=
|
Flag_Expr :=
|
Make_Function_Call (Loc,
|
Make_Function_Call (Loc,
|
Name =>
|
Name =>
|
New_Reference_To (RTE (RE_Needs_Finalization), Loc),
|
New_Reference_To (RTE (RE_Needs_Finalization), Loc),
|
Parameter_Associations => New_List (Param));
|
Parameter_Associations => New_List (Param));
|
end if;
|
end if;
|
|
|
-- Create the temporary which represents the finalization
|
-- Create the temporary which represents the finalization
|
-- state of the expression. Generate:
|
-- state of the expression. Generate:
|
--
|
--
|
-- F : constant Boolean := <Flag_Expr>;
|
-- F : constant Boolean := <Flag_Expr>;
|
|
|
Insert_Action (N,
|
Insert_Action (N,
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Flag_Id,
|
Defining_Identifier => Flag_Id,
|
Constant_Present => True,
|
Constant_Present => True,
|
Object_Definition =>
|
Object_Definition =>
|
New_Reference_To (Standard_Boolean, Loc),
|
New_Reference_To (Standard_Boolean, Loc),
|
Expression => Flag_Expr));
|
Expression => Flag_Expr));
|
|
|
-- The flag acts as the last actual
|
-- The flag acts as the last actual
|
|
|
Append_To (Actuals, New_Reference_To (Flag_Id, Loc));
|
Append_To (Actuals, New_Reference_To (Flag_Id, Loc));
|
end;
|
end;
|
|
|
-- The object is statically known to be controlled
|
-- The object is statically known to be controlled
|
|
|
else
|
else
|
Append_To (Actuals, New_Reference_To (Standard_True, Loc));
|
Append_To (Actuals, New_Reference_To (Standard_True, Loc));
|
end if;
|
end if;
|
|
|
else
|
else
|
Append_To (Actuals, New_Reference_To (Standard_False, Loc));
|
Append_To (Actuals, New_Reference_To (Standard_False, Loc));
|
end if;
|
end if;
|
|
|
-- i) On_Subpool
|
-- i) On_Subpool
|
|
|
if Is_Allocate then
|
if Is_Allocate then
|
Append_To (Actuals,
|
Append_To (Actuals,
|
New_Reference_To (Boolean_Literals (Present (Subpool)), Loc));
|
New_Reference_To (Boolean_Literals (Present (Subpool)), Loc));
|
end if;
|
end if;
|
|
|
-- Step 2: Build a wrapper Allocate / Deallocate which internally
|
-- Step 2: Build a wrapper Allocate / Deallocate which internally
|
-- calls Allocate_Any_Controlled / Deallocate_Any_Controlled.
|
-- calls Allocate_Any_Controlled / Deallocate_Any_Controlled.
|
|
|
-- Select the proper routine to call
|
-- Select the proper routine to call
|
|
|
if Is_Allocate then
|
if Is_Allocate then
|
Proc_To_Call := RTE (RE_Allocate_Any_Controlled);
|
Proc_To_Call := RTE (RE_Allocate_Any_Controlled);
|
else
|
else
|
Proc_To_Call := RTE (RE_Deallocate_Any_Controlled);
|
Proc_To_Call := RTE (RE_Deallocate_Any_Controlled);
|
end if;
|
end if;
|
|
|
-- Create a custom Allocate / Deallocate routine which has identical
|
-- Create a custom Allocate / Deallocate routine which has identical
|
-- profile to that of System.Storage_Pools.
|
-- profile to that of System.Storage_Pools.
|
|
|
Insert_Action (N,
|
Insert_Action (N,
|
Make_Subprogram_Body (Loc,
|
Make_Subprogram_Body (Loc,
|
Specification =>
|
Specification =>
|
|
|
-- procedure Pnn
|
-- procedure Pnn
|
|
|
Make_Procedure_Specification (Loc,
|
Make_Procedure_Specification (Loc,
|
Defining_Unit_Name => Proc_Id,
|
Defining_Unit_Name => Proc_Id,
|
Parameter_Specifications => New_List (
|
Parameter_Specifications => New_List (
|
|
|
-- P : Root_Storage_Pool
|
-- P : Root_Storage_Pool
|
|
|
Make_Parameter_Specification (Loc,
|
Make_Parameter_Specification (Loc,
|
Defining_Identifier => Make_Temporary (Loc, 'P'),
|
Defining_Identifier => Make_Temporary (Loc, 'P'),
|
Parameter_Type =>
|
Parameter_Type =>
|
New_Reference_To (RTE (RE_Root_Storage_Pool), Loc)),
|
New_Reference_To (RTE (RE_Root_Storage_Pool), Loc)),
|
|
|
-- A : [out] Address
|
-- A : [out] Address
|
|
|
Make_Parameter_Specification (Loc,
|
Make_Parameter_Specification (Loc,
|
Defining_Identifier => Addr_Id,
|
Defining_Identifier => Addr_Id,
|
Out_Present => Is_Allocate,
|
Out_Present => Is_Allocate,
|
Parameter_Type =>
|
Parameter_Type =>
|
New_Reference_To (RTE (RE_Address), Loc)),
|
New_Reference_To (RTE (RE_Address), Loc)),
|
|
|
-- S : Storage_Count
|
-- S : Storage_Count
|
|
|
Make_Parameter_Specification (Loc,
|
Make_Parameter_Specification (Loc,
|
Defining_Identifier => Size_Id,
|
Defining_Identifier => Size_Id,
|
Parameter_Type =>
|
Parameter_Type =>
|
New_Reference_To (RTE (RE_Storage_Count), Loc)),
|
New_Reference_To (RTE (RE_Storage_Count), Loc)),
|
|
|
-- L : Storage_Count
|
-- L : Storage_Count
|
|
|
Make_Parameter_Specification (Loc,
|
Make_Parameter_Specification (Loc,
|
Defining_Identifier => Alig_Id,
|
Defining_Identifier => Alig_Id,
|
Parameter_Type =>
|
Parameter_Type =>
|
New_Reference_To (RTE (RE_Storage_Count), Loc)))),
|
New_Reference_To (RTE (RE_Storage_Count), Loc)))),
|
|
|
Declarations => No_List,
|
Declarations => No_List,
|
|
|
Handled_Statement_Sequence =>
|
Handled_Statement_Sequence =>
|
Make_Handled_Sequence_Of_Statements (Loc,
|
Make_Handled_Sequence_Of_Statements (Loc,
|
Statements => New_List (
|
Statements => New_List (
|
Make_Procedure_Call_Statement (Loc,
|
Make_Procedure_Call_Statement (Loc,
|
Name => New_Reference_To (Proc_To_Call, Loc),
|
Name => New_Reference_To (Proc_To_Call, Loc),
|
Parameter_Associations => Actuals)))));
|
Parameter_Associations => Actuals)))));
|
|
|
-- The newly generated Allocate / Deallocate becomes the default
|
-- The newly generated Allocate / Deallocate becomes the default
|
-- procedure to call when the back end processes the allocation /
|
-- procedure to call when the back end processes the allocation /
|
-- deallocation.
|
-- deallocation.
|
|
|
if Is_Allocate then
|
if Is_Allocate then
|
Set_Procedure_To_Call (Expr, Proc_Id);
|
Set_Procedure_To_Call (Expr, Proc_Id);
|
else
|
else
|
Set_Procedure_To_Call (N, Proc_Id);
|
Set_Procedure_To_Call (N, Proc_Id);
|
end if;
|
end if;
|
end;
|
end;
|
end Build_Allocate_Deallocate_Proc;
|
end Build_Allocate_Deallocate_Proc;
|
|
|
------------------------
|
------------------------
|
-- Build_Runtime_Call --
|
-- Build_Runtime_Call --
|
------------------------
|
------------------------
|
|
|
function Build_Runtime_Call (Loc : Source_Ptr; RE : RE_Id) return Node_Id is
|
function Build_Runtime_Call (Loc : Source_Ptr; RE : RE_Id) return Node_Id is
|
begin
|
begin
|
-- If entity is not available, we can skip making the call (this avoids
|
-- If entity is not available, we can skip making the call (this avoids
|
-- junk duplicated error messages in a number of cases).
|
-- junk duplicated error messages in a number of cases).
|
|
|
if not RTE_Available (RE) then
|
if not RTE_Available (RE) then
|
return Make_Null_Statement (Loc);
|
return Make_Null_Statement (Loc);
|
else
|
else
|
return
|
return
|
Make_Procedure_Call_Statement (Loc,
|
Make_Procedure_Call_Statement (Loc,
|
Name => New_Reference_To (RTE (RE), Loc));
|
Name => New_Reference_To (RTE (RE), Loc));
|
end if;
|
end if;
|
end Build_Runtime_Call;
|
end Build_Runtime_Call;
|
|
|
----------------------------
|
----------------------------
|
-- Build_Task_Array_Image --
|
-- Build_Task_Array_Image --
|
----------------------------
|
----------------------------
|
|
|
-- This function generates the body for a function that constructs the
|
-- This function generates the body for a function that constructs the
|
-- image string for a task that is an array component. The function is
|
-- image string for a task that is an array component. The function is
|
-- local to the init proc for the array type, and is called for each one
|
-- local to the init proc for the array type, and is called for each one
|
-- of the components. The constructed image has the form of an indexed
|
-- of the components. The constructed image has the form of an indexed
|
-- component, whose prefix is the outer variable of the array type.
|
-- component, whose prefix is the outer variable of the array type.
|
-- The n-dimensional array type has known indexes Index, Index2...
|
-- The n-dimensional array type has known indexes Index, Index2...
|
|
|
-- Id_Ref is an indexed component form created by the enclosing init proc.
|
-- Id_Ref is an indexed component form created by the enclosing init proc.
|
-- Its successive indexes are Val1, Val2, ... which are the loop variables
|
-- Its successive indexes are Val1, Val2, ... which are the loop variables
|
-- in the loops that call the individual task init proc on each component.
|
-- in the loops that call the individual task init proc on each component.
|
|
|
-- The generated function has the following structure:
|
-- The generated function has the following structure:
|
|
|
-- function F return String is
|
-- function F return String is
|
-- Pref : string renames Task_Name;
|
-- Pref : string renames Task_Name;
|
-- T1 : String := Index1'Image (Val1);
|
-- T1 : String := Index1'Image (Val1);
|
-- ...
|
-- ...
|
-- Tn : String := indexn'image (Valn);
|
-- Tn : String := indexn'image (Valn);
|
-- Len : Integer := T1'Length + ... + Tn'Length + n + 1;
|
-- Len : Integer := T1'Length + ... + Tn'Length + n + 1;
|
-- -- Len includes commas and the end parentheses.
|
-- -- Len includes commas and the end parentheses.
|
-- Res : String (1..Len);
|
-- Res : String (1..Len);
|
-- Pos : Integer := Pref'Length;
|
-- Pos : Integer := Pref'Length;
|
--
|
--
|
-- begin
|
-- begin
|
-- Res (1 .. Pos) := Pref;
|
-- Res (1 .. Pos) := Pref;
|
-- Pos := Pos + 1;
|
-- Pos := Pos + 1;
|
-- Res (Pos) := '(';
|
-- Res (Pos) := '(';
|
-- Pos := Pos + 1;
|
-- Pos := Pos + 1;
|
-- Res (Pos .. Pos + T1'Length - 1) := T1;
|
-- Res (Pos .. Pos + T1'Length - 1) := T1;
|
-- Pos := Pos + T1'Length;
|
-- Pos := Pos + T1'Length;
|
-- Res (Pos) := '.';
|
-- Res (Pos) := '.';
|
-- Pos := Pos + 1;
|
-- Pos := Pos + 1;
|
-- ...
|
-- ...
|
-- Res (Pos .. Pos + Tn'Length - 1) := Tn;
|
-- Res (Pos .. Pos + Tn'Length - 1) := Tn;
|
-- Res (Len) := ')';
|
-- Res (Len) := ')';
|
--
|
--
|
-- return Res;
|
-- return Res;
|
-- end F;
|
-- end F;
|
--
|
--
|
-- Needless to say, multidimensional arrays of tasks are rare enough that
|
-- Needless to say, multidimensional arrays of tasks are rare enough that
|
-- the bulkiness of this code is not really a concern.
|
-- the bulkiness of this code is not really a concern.
|
|
|
function Build_Task_Array_Image
|
function Build_Task_Array_Image
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
Id_Ref : Node_Id;
|
Id_Ref : Node_Id;
|
A_Type : Entity_Id;
|
A_Type : Entity_Id;
|
Dyn : Boolean := False) return Node_Id
|
Dyn : Boolean := False) return Node_Id
|
is
|
is
|
Dims : constant Nat := Number_Dimensions (A_Type);
|
Dims : constant Nat := Number_Dimensions (A_Type);
|
-- Number of dimensions for array of tasks
|
-- Number of dimensions for array of tasks
|
|
|
Temps : array (1 .. Dims) of Entity_Id;
|
Temps : array (1 .. Dims) of Entity_Id;
|
-- Array of temporaries to hold string for each index
|
-- Array of temporaries to hold string for each index
|
|
|
Indx : Node_Id;
|
Indx : Node_Id;
|
-- Index expression
|
-- Index expression
|
|
|
Len : Entity_Id;
|
Len : Entity_Id;
|
-- Total length of generated name
|
-- Total length of generated name
|
|
|
Pos : Entity_Id;
|
Pos : Entity_Id;
|
-- Running index for substring assignments
|
-- Running index for substring assignments
|
|
|
Pref : constant Entity_Id := Make_Temporary (Loc, 'P');
|
Pref : constant Entity_Id := Make_Temporary (Loc, 'P');
|
-- Name of enclosing variable, prefix of resulting name
|
-- Name of enclosing variable, prefix of resulting name
|
|
|
Res : Entity_Id;
|
Res : Entity_Id;
|
-- String to hold result
|
-- String to hold result
|
|
|
Val : Node_Id;
|
Val : Node_Id;
|
-- Value of successive indexes
|
-- Value of successive indexes
|
|
|
Sum : Node_Id;
|
Sum : Node_Id;
|
-- Expression to compute total size of string
|
-- Expression to compute total size of string
|
|
|
T : Entity_Id;
|
T : Entity_Id;
|
-- Entity for name at one index position
|
-- Entity for name at one index position
|
|
|
Decls : constant List_Id := New_List;
|
Decls : constant List_Id := New_List;
|
Stats : constant List_Id := New_List;
|
Stats : constant List_Id := New_List;
|
|
|
begin
|
begin
|
-- For a dynamic task, the name comes from the target variable. For a
|
-- For a dynamic task, the name comes from the target variable. For a
|
-- static one it is a formal of the enclosing init proc.
|
-- static one it is a formal of the enclosing init proc.
|
|
|
if Dyn then
|
if Dyn then
|
Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
|
Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
|
Append_To (Decls,
|
Append_To (Decls,
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Pref,
|
Defining_Identifier => Pref,
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Expression =>
|
Expression =>
|
Make_String_Literal (Loc,
|
Make_String_Literal (Loc,
|
Strval => String_From_Name_Buffer)));
|
Strval => String_From_Name_Buffer)));
|
|
|
else
|
else
|
Append_To (Decls,
|
Append_To (Decls,
|
Make_Object_Renaming_Declaration (Loc,
|
Make_Object_Renaming_Declaration (Loc,
|
Defining_Identifier => Pref,
|
Defining_Identifier => Pref,
|
Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
|
Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
|
Name => Make_Identifier (Loc, Name_uTask_Name)));
|
Name => Make_Identifier (Loc, Name_uTask_Name)));
|
end if;
|
end if;
|
|
|
Indx := First_Index (A_Type);
|
Indx := First_Index (A_Type);
|
Val := First (Expressions (Id_Ref));
|
Val := First (Expressions (Id_Ref));
|
|
|
for J in 1 .. Dims loop
|
for J in 1 .. Dims loop
|
T := Make_Temporary (Loc, 'T');
|
T := Make_Temporary (Loc, 'T');
|
Temps (J) := T;
|
Temps (J) := T;
|
|
|
Append_To (Decls,
|
Append_To (Decls,
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => T,
|
Defining_Identifier => T,
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Expression =>
|
Expression =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Attribute_Name => Name_Image,
|
Attribute_Name => Name_Image,
|
Prefix => New_Occurrence_Of (Etype (Indx), Loc),
|
Prefix => New_Occurrence_Of (Etype (Indx), Loc),
|
Expressions => New_List (New_Copy_Tree (Val)))));
|
Expressions => New_List (New_Copy_Tree (Val)))));
|
|
|
Next_Index (Indx);
|
Next_Index (Indx);
|
Next (Val);
|
Next (Val);
|
end loop;
|
end loop;
|
|
|
Sum := Make_Integer_Literal (Loc, Dims + 1);
|
Sum := Make_Integer_Literal (Loc, Dims + 1);
|
|
|
Sum :=
|
Sum :=
|
Make_Op_Add (Loc,
|
Make_Op_Add (Loc,
|
Left_Opnd => Sum,
|
Left_Opnd => Sum,
|
Right_Opnd =>
|
Right_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Attribute_Name => Name_Length,
|
Attribute_Name => Name_Length,
|
Prefix =>
|
Prefix =>
|
New_Occurrence_Of (Pref, Loc),
|
New_Occurrence_Of (Pref, Loc),
|
Expressions => New_List (Make_Integer_Literal (Loc, 1))));
|
Expressions => New_List (Make_Integer_Literal (Loc, 1))));
|
|
|
for J in 1 .. Dims loop
|
for J in 1 .. Dims loop
|
Sum :=
|
Sum :=
|
Make_Op_Add (Loc,
|
Make_Op_Add (Loc,
|
Left_Opnd => Sum,
|
Left_Opnd => Sum,
|
Right_Opnd =>
|
Right_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Attribute_Name => Name_Length,
|
Attribute_Name => Name_Length,
|
Prefix =>
|
Prefix =>
|
New_Occurrence_Of (Temps (J), Loc),
|
New_Occurrence_Of (Temps (J), Loc),
|
Expressions => New_List (Make_Integer_Literal (Loc, 1))));
|
Expressions => New_List (Make_Integer_Literal (Loc, 1))));
|
end loop;
|
end loop;
|
|
|
Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
|
Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
|
|
|
Set_Character_Literal_Name (Char_Code (Character'Pos ('(')));
|
Set_Character_Literal_Name (Char_Code (Character'Pos ('(')));
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => Make_Indexed_Component (Loc,
|
Name => Make_Indexed_Component (Loc,
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
|
Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
|
Expression =>
|
Expression =>
|
Make_Character_Literal (Loc,
|
Make_Character_Literal (Loc,
|
Chars => Name_Find,
|
Chars => Name_Find,
|
Char_Literal_Value =>
|
Char_Literal_Value =>
|
UI_From_Int (Character'Pos ('(')))));
|
UI_From_Int (Character'Pos ('(')))));
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => New_Occurrence_Of (Pos, Loc),
|
Name => New_Occurrence_Of (Pos, Loc),
|
Expression =>
|
Expression =>
|
Make_Op_Add (Loc,
|
Make_Op_Add (Loc,
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Right_Opnd => Make_Integer_Literal (Loc, 1))));
|
Right_Opnd => Make_Integer_Literal (Loc, 1))));
|
|
|
for J in 1 .. Dims loop
|
for J in 1 .. Dims loop
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => Make_Slice (Loc,
|
Name => Make_Slice (Loc,
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Discrete_Range =>
|
Discrete_Range =>
|
Make_Range (Loc,
|
Make_Range (Loc,
|
Low_Bound => New_Occurrence_Of (Pos, Loc),
|
Low_Bound => New_Occurrence_Of (Pos, Loc),
|
High_Bound => Make_Op_Subtract (Loc,
|
High_Bound => Make_Op_Subtract (Loc,
|
Left_Opnd =>
|
Left_Opnd =>
|
Make_Op_Add (Loc,
|
Make_Op_Add (Loc,
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Right_Opnd =>
|
Right_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Attribute_Name => Name_Length,
|
Attribute_Name => Name_Length,
|
Prefix =>
|
Prefix =>
|
New_Occurrence_Of (Temps (J), Loc),
|
New_Occurrence_Of (Temps (J), Loc),
|
Expressions =>
|
Expressions =>
|
New_List (Make_Integer_Literal (Loc, 1)))),
|
New_List (Make_Integer_Literal (Loc, 1)))),
|
Right_Opnd => Make_Integer_Literal (Loc, 1)))),
|
Right_Opnd => Make_Integer_Literal (Loc, 1)))),
|
|
|
Expression => New_Occurrence_Of (Temps (J), Loc)));
|
Expression => New_Occurrence_Of (Temps (J), Loc)));
|
|
|
if J < Dims then
|
if J < Dims then
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => New_Occurrence_Of (Pos, Loc),
|
Name => New_Occurrence_Of (Pos, Loc),
|
Expression =>
|
Expression =>
|
Make_Op_Add (Loc,
|
Make_Op_Add (Loc,
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Right_Opnd =>
|
Right_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Attribute_Name => Name_Length,
|
Attribute_Name => Name_Length,
|
Prefix => New_Occurrence_Of (Temps (J), Loc),
|
Prefix => New_Occurrence_Of (Temps (J), Loc),
|
Expressions =>
|
Expressions =>
|
New_List (Make_Integer_Literal (Loc, 1))))));
|
New_List (Make_Integer_Literal (Loc, 1))))));
|
|
|
Set_Character_Literal_Name (Char_Code (Character'Pos (',')));
|
Set_Character_Literal_Name (Char_Code (Character'Pos (',')));
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => Make_Indexed_Component (Loc,
|
Name => Make_Indexed_Component (Loc,
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
|
Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
|
Expression =>
|
Expression =>
|
Make_Character_Literal (Loc,
|
Make_Character_Literal (Loc,
|
Chars => Name_Find,
|
Chars => Name_Find,
|
Char_Literal_Value =>
|
Char_Literal_Value =>
|
UI_From_Int (Character'Pos (',')))));
|
UI_From_Int (Character'Pos (',')))));
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => New_Occurrence_Of (Pos, Loc),
|
Name => New_Occurrence_Of (Pos, Loc),
|
Expression =>
|
Expression =>
|
Make_Op_Add (Loc,
|
Make_Op_Add (Loc,
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Right_Opnd => Make_Integer_Literal (Loc, 1))));
|
Right_Opnd => Make_Integer_Literal (Loc, 1))));
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
Set_Character_Literal_Name (Char_Code (Character'Pos (')')));
|
Set_Character_Literal_Name (Char_Code (Character'Pos (')')));
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => Make_Indexed_Component (Loc,
|
Name => Make_Indexed_Component (Loc,
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Expressions => New_List (New_Occurrence_Of (Len, Loc))),
|
Expressions => New_List (New_Occurrence_Of (Len, Loc))),
|
Expression =>
|
Expression =>
|
Make_Character_Literal (Loc,
|
Make_Character_Literal (Loc,
|
Chars => Name_Find,
|
Chars => Name_Find,
|
Char_Literal_Value =>
|
Char_Literal_Value =>
|
UI_From_Int (Character'Pos (')')))));
|
UI_From_Int (Character'Pos (')')))));
|
return Build_Task_Image_Function (Loc, Decls, Stats, Res);
|
return Build_Task_Image_Function (Loc, Decls, Stats, Res);
|
end Build_Task_Array_Image;
|
end Build_Task_Array_Image;
|
|
|
----------------------------
|
----------------------------
|
-- Build_Task_Image_Decls --
|
-- Build_Task_Image_Decls --
|
----------------------------
|
----------------------------
|
|
|
function Build_Task_Image_Decls
|
function Build_Task_Image_Decls
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
Id_Ref : Node_Id;
|
Id_Ref : Node_Id;
|
A_Type : Entity_Id;
|
A_Type : Entity_Id;
|
In_Init_Proc : Boolean := False) return List_Id
|
In_Init_Proc : Boolean := False) return List_Id
|
is
|
is
|
Decls : constant List_Id := New_List;
|
Decls : constant List_Id := New_List;
|
T_Id : Entity_Id := Empty;
|
T_Id : Entity_Id := Empty;
|
Decl : Node_Id;
|
Decl : Node_Id;
|
Expr : Node_Id := Empty;
|
Expr : Node_Id := Empty;
|
Fun : Node_Id := Empty;
|
Fun : Node_Id := Empty;
|
Is_Dyn : constant Boolean :=
|
Is_Dyn : constant Boolean :=
|
Nkind (Parent (Id_Ref)) = N_Assignment_Statement
|
Nkind (Parent (Id_Ref)) = N_Assignment_Statement
|
and then
|
and then
|
Nkind (Expression (Parent (Id_Ref))) = N_Allocator;
|
Nkind (Expression (Parent (Id_Ref))) = N_Allocator;
|
|
|
begin
|
begin
|
-- If Discard_Names or No_Implicit_Heap_Allocations are in effect,
|
-- If Discard_Names or No_Implicit_Heap_Allocations are in effect,
|
-- generate a dummy declaration only.
|
-- generate a dummy declaration only.
|
|
|
if Restriction_Active (No_Implicit_Heap_Allocations)
|
if Restriction_Active (No_Implicit_Heap_Allocations)
|
or else Global_Discard_Names
|
or else Global_Discard_Names
|
then
|
then
|
T_Id := Make_Temporary (Loc, 'J');
|
T_Id := Make_Temporary (Loc, 'J');
|
Name_Len := 0;
|
Name_Len := 0;
|
|
|
return
|
return
|
New_List (
|
New_List (
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => T_Id,
|
Defining_Identifier => T_Id,
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Expression =>
|
Expression =>
|
Make_String_Literal (Loc,
|
Make_String_Literal (Loc,
|
Strval => String_From_Name_Buffer)));
|
Strval => String_From_Name_Buffer)));
|
|
|
else
|
else
|
if Nkind (Id_Ref) = N_Identifier
|
if Nkind (Id_Ref) = N_Identifier
|
or else Nkind (Id_Ref) = N_Defining_Identifier
|
or else Nkind (Id_Ref) = N_Defining_Identifier
|
then
|
then
|
-- For a simple variable, the image of the task is built from
|
-- For a simple variable, the image of the task is built from
|
-- the name of the variable. To avoid possible conflict with the
|
-- the name of the variable. To avoid possible conflict with the
|
-- anonymous type created for a single protected object, add a
|
-- anonymous type created for a single protected object, add a
|
-- numeric suffix.
|
-- numeric suffix.
|
|
|
T_Id :=
|
T_Id :=
|
Make_Defining_Identifier (Loc,
|
Make_Defining_Identifier (Loc,
|
New_External_Name (Chars (Id_Ref), 'T', 1));
|
New_External_Name (Chars (Id_Ref), 'T', 1));
|
|
|
Get_Name_String (Chars (Id_Ref));
|
Get_Name_String (Chars (Id_Ref));
|
|
|
Expr :=
|
Expr :=
|
Make_String_Literal (Loc,
|
Make_String_Literal (Loc,
|
Strval => String_From_Name_Buffer);
|
Strval => String_From_Name_Buffer);
|
|
|
elsif Nkind (Id_Ref) = N_Selected_Component then
|
elsif Nkind (Id_Ref) = N_Selected_Component then
|
T_Id :=
|
T_Id :=
|
Make_Defining_Identifier (Loc,
|
Make_Defining_Identifier (Loc,
|
New_External_Name (Chars (Selector_Name (Id_Ref)), 'T'));
|
New_External_Name (Chars (Selector_Name (Id_Ref)), 'T'));
|
Fun := Build_Task_Record_Image (Loc, Id_Ref, Is_Dyn);
|
Fun := Build_Task_Record_Image (Loc, Id_Ref, Is_Dyn);
|
|
|
elsif Nkind (Id_Ref) = N_Indexed_Component then
|
elsif Nkind (Id_Ref) = N_Indexed_Component then
|
T_Id :=
|
T_Id :=
|
Make_Defining_Identifier (Loc,
|
Make_Defining_Identifier (Loc,
|
New_External_Name (Chars (A_Type), 'N'));
|
New_External_Name (Chars (A_Type), 'N'));
|
|
|
Fun := Build_Task_Array_Image (Loc, Id_Ref, A_Type, Is_Dyn);
|
Fun := Build_Task_Array_Image (Loc, Id_Ref, A_Type, Is_Dyn);
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
if Present (Fun) then
|
if Present (Fun) then
|
Append (Fun, Decls);
|
Append (Fun, Decls);
|
Expr := Make_Function_Call (Loc,
|
Expr := Make_Function_Call (Loc,
|
Name => New_Occurrence_Of (Defining_Entity (Fun), Loc));
|
Name => New_Occurrence_Of (Defining_Entity (Fun), Loc));
|
|
|
if not In_Init_Proc and then VM_Target = No_VM then
|
if not In_Init_Proc and then VM_Target = No_VM then
|
Set_Uses_Sec_Stack (Defining_Entity (Fun));
|
Set_Uses_Sec_Stack (Defining_Entity (Fun));
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Decl := Make_Object_Declaration (Loc,
|
Decl := Make_Object_Declaration (Loc,
|
Defining_Identifier => T_Id,
|
Defining_Identifier => T_Id,
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Constant_Present => True,
|
Constant_Present => True,
|
Expression => Expr);
|
Expression => Expr);
|
|
|
Append (Decl, Decls);
|
Append (Decl, Decls);
|
return Decls;
|
return Decls;
|
end Build_Task_Image_Decls;
|
end Build_Task_Image_Decls;
|
|
|
-------------------------------
|
-------------------------------
|
-- Build_Task_Image_Function --
|
-- Build_Task_Image_Function --
|
-------------------------------
|
-------------------------------
|
|
|
function Build_Task_Image_Function
|
function Build_Task_Image_Function
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
Decls : List_Id;
|
Decls : List_Id;
|
Stats : List_Id;
|
Stats : List_Id;
|
Res : Entity_Id) return Node_Id
|
Res : Entity_Id) return Node_Id
|
is
|
is
|
Spec : Node_Id;
|
Spec : Node_Id;
|
|
|
begin
|
begin
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Simple_Return_Statement (Loc,
|
Make_Simple_Return_Statement (Loc,
|
Expression => New_Occurrence_Of (Res, Loc)));
|
Expression => New_Occurrence_Of (Res, Loc)));
|
|
|
Spec := Make_Function_Specification (Loc,
|
Spec := Make_Function_Specification (Loc,
|
Defining_Unit_Name => Make_Temporary (Loc, 'F'),
|
Defining_Unit_Name => Make_Temporary (Loc, 'F'),
|
Result_Definition => New_Occurrence_Of (Standard_String, Loc));
|
Result_Definition => New_Occurrence_Of (Standard_String, Loc));
|
|
|
-- Calls to 'Image use the secondary stack, which must be cleaned up
|
-- Calls to 'Image use the secondary stack, which must be cleaned up
|
-- after the task name is built.
|
-- after the task name is built.
|
|
|
return Make_Subprogram_Body (Loc,
|
return Make_Subprogram_Body (Loc,
|
Specification => Spec,
|
Specification => Spec,
|
Declarations => Decls,
|
Declarations => Decls,
|
Handled_Statement_Sequence =>
|
Handled_Statement_Sequence =>
|
Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats));
|
Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats));
|
end Build_Task_Image_Function;
|
end Build_Task_Image_Function;
|
|
|
-----------------------------
|
-----------------------------
|
-- Build_Task_Image_Prefix --
|
-- Build_Task_Image_Prefix --
|
-----------------------------
|
-----------------------------
|
|
|
procedure Build_Task_Image_Prefix
|
procedure Build_Task_Image_Prefix
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
Len : out Entity_Id;
|
Len : out Entity_Id;
|
Res : out Entity_Id;
|
Res : out Entity_Id;
|
Pos : out Entity_Id;
|
Pos : out Entity_Id;
|
Prefix : Entity_Id;
|
Prefix : Entity_Id;
|
Sum : Node_Id;
|
Sum : Node_Id;
|
Decls : List_Id;
|
Decls : List_Id;
|
Stats : List_Id)
|
Stats : List_Id)
|
is
|
is
|
begin
|
begin
|
Len := Make_Temporary (Loc, 'L', Sum);
|
Len := Make_Temporary (Loc, 'L', Sum);
|
|
|
Append_To (Decls,
|
Append_To (Decls,
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Len,
|
Defining_Identifier => Len,
|
Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
|
Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
|
Expression => Sum));
|
Expression => Sum));
|
|
|
Res := Make_Temporary (Loc, 'R');
|
Res := Make_Temporary (Loc, 'R');
|
|
|
Append_To (Decls,
|
Append_To (Decls,
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Res,
|
Defining_Identifier => Res,
|
Object_Definition =>
|
Object_Definition =>
|
Make_Subtype_Indication (Loc,
|
Make_Subtype_Indication (Loc,
|
Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
|
Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
|
Constraint =>
|
Constraint =>
|
Make_Index_Or_Discriminant_Constraint (Loc,
|
Make_Index_Or_Discriminant_Constraint (Loc,
|
Constraints =>
|
Constraints =>
|
New_List (
|
New_List (
|
Make_Range (Loc,
|
Make_Range (Loc,
|
Low_Bound => Make_Integer_Literal (Loc, 1),
|
Low_Bound => Make_Integer_Literal (Loc, 1),
|
High_Bound => New_Occurrence_Of (Len, Loc)))))));
|
High_Bound => New_Occurrence_Of (Len, Loc)))))));
|
|
|
Pos := Make_Temporary (Loc, 'P');
|
Pos := Make_Temporary (Loc, 'P');
|
|
|
Append_To (Decls,
|
Append_To (Decls,
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Pos,
|
Defining_Identifier => Pos,
|
Object_Definition => New_Occurrence_Of (Standard_Integer, Loc)));
|
Object_Definition => New_Occurrence_Of (Standard_Integer, Loc)));
|
|
|
-- Pos := Prefix'Length;
|
-- Pos := Prefix'Length;
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => New_Occurrence_Of (Pos, Loc),
|
Name => New_Occurrence_Of (Pos, Loc),
|
Expression =>
|
Expression =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Attribute_Name => Name_Length,
|
Attribute_Name => Name_Length,
|
Prefix => New_Occurrence_Of (Prefix, Loc),
|
Prefix => New_Occurrence_Of (Prefix, Loc),
|
Expressions => New_List (Make_Integer_Literal (Loc, 1)))));
|
Expressions => New_List (Make_Integer_Literal (Loc, 1)))));
|
|
|
-- Res (1 .. Pos) := Prefix;
|
-- Res (1 .. Pos) := Prefix;
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name =>
|
Name =>
|
Make_Slice (Loc,
|
Make_Slice (Loc,
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Discrete_Range =>
|
Discrete_Range =>
|
Make_Range (Loc,
|
Make_Range (Loc,
|
Low_Bound => Make_Integer_Literal (Loc, 1),
|
Low_Bound => Make_Integer_Literal (Loc, 1),
|
High_Bound => New_Occurrence_Of (Pos, Loc))),
|
High_Bound => New_Occurrence_Of (Pos, Loc))),
|
|
|
Expression => New_Occurrence_Of (Prefix, Loc)));
|
Expression => New_Occurrence_Of (Prefix, Loc)));
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => New_Occurrence_Of (Pos, Loc),
|
Name => New_Occurrence_Of (Pos, Loc),
|
Expression =>
|
Expression =>
|
Make_Op_Add (Loc,
|
Make_Op_Add (Loc,
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Right_Opnd => Make_Integer_Literal (Loc, 1))));
|
Right_Opnd => Make_Integer_Literal (Loc, 1))));
|
end Build_Task_Image_Prefix;
|
end Build_Task_Image_Prefix;
|
|
|
-----------------------------
|
-----------------------------
|
-- Build_Task_Record_Image --
|
-- Build_Task_Record_Image --
|
-----------------------------
|
-----------------------------
|
|
|
function Build_Task_Record_Image
|
function Build_Task_Record_Image
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
Id_Ref : Node_Id;
|
Id_Ref : Node_Id;
|
Dyn : Boolean := False) return Node_Id
|
Dyn : Boolean := False) return Node_Id
|
is
|
is
|
Len : Entity_Id;
|
Len : Entity_Id;
|
-- Total length of generated name
|
-- Total length of generated name
|
|
|
Pos : Entity_Id;
|
Pos : Entity_Id;
|
-- Index into result
|
-- Index into result
|
|
|
Res : Entity_Id;
|
Res : Entity_Id;
|
-- String to hold result
|
-- String to hold result
|
|
|
Pref : constant Entity_Id := Make_Temporary (Loc, 'P');
|
Pref : constant Entity_Id := Make_Temporary (Loc, 'P');
|
-- Name of enclosing variable, prefix of resulting name
|
-- Name of enclosing variable, prefix of resulting name
|
|
|
Sum : Node_Id;
|
Sum : Node_Id;
|
-- Expression to compute total size of string
|
-- Expression to compute total size of string
|
|
|
Sel : Entity_Id;
|
Sel : Entity_Id;
|
-- Entity for selector name
|
-- Entity for selector name
|
|
|
Decls : constant List_Id := New_List;
|
Decls : constant List_Id := New_List;
|
Stats : constant List_Id := New_List;
|
Stats : constant List_Id := New_List;
|
|
|
begin
|
begin
|
-- For a dynamic task, the name comes from the target variable. For a
|
-- For a dynamic task, the name comes from the target variable. For a
|
-- static one it is a formal of the enclosing init proc.
|
-- static one it is a formal of the enclosing init proc.
|
|
|
if Dyn then
|
if Dyn then
|
Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
|
Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
|
Append_To (Decls,
|
Append_To (Decls,
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Pref,
|
Defining_Identifier => Pref,
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Expression =>
|
Expression =>
|
Make_String_Literal (Loc,
|
Make_String_Literal (Loc,
|
Strval => String_From_Name_Buffer)));
|
Strval => String_From_Name_Buffer)));
|
|
|
else
|
else
|
Append_To (Decls,
|
Append_To (Decls,
|
Make_Object_Renaming_Declaration (Loc,
|
Make_Object_Renaming_Declaration (Loc,
|
Defining_Identifier => Pref,
|
Defining_Identifier => Pref,
|
Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
|
Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
|
Name => Make_Identifier (Loc, Name_uTask_Name)));
|
Name => Make_Identifier (Loc, Name_uTask_Name)));
|
end if;
|
end if;
|
|
|
Sel := Make_Temporary (Loc, 'S');
|
Sel := Make_Temporary (Loc, 'S');
|
|
|
Get_Name_String (Chars (Selector_Name (Id_Ref)));
|
Get_Name_String (Chars (Selector_Name (Id_Ref)));
|
|
|
Append_To (Decls,
|
Append_To (Decls,
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Sel,
|
Defining_Identifier => Sel,
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
|
Expression =>
|
Expression =>
|
Make_String_Literal (Loc,
|
Make_String_Literal (Loc,
|
Strval => String_From_Name_Buffer)));
|
Strval => String_From_Name_Buffer)));
|
|
|
Sum := Make_Integer_Literal (Loc, Nat (Name_Len + 1));
|
Sum := Make_Integer_Literal (Loc, Nat (Name_Len + 1));
|
|
|
Sum :=
|
Sum :=
|
Make_Op_Add (Loc,
|
Make_Op_Add (Loc,
|
Left_Opnd => Sum,
|
Left_Opnd => Sum,
|
Right_Opnd =>
|
Right_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Attribute_Name => Name_Length,
|
Attribute_Name => Name_Length,
|
Prefix =>
|
Prefix =>
|
New_Occurrence_Of (Pref, Loc),
|
New_Occurrence_Of (Pref, Loc),
|
Expressions => New_List (Make_Integer_Literal (Loc, 1))));
|
Expressions => New_List (Make_Integer_Literal (Loc, 1))));
|
|
|
Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
|
Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
|
|
|
Set_Character_Literal_Name (Char_Code (Character'Pos ('.')));
|
Set_Character_Literal_Name (Char_Code (Character'Pos ('.')));
|
|
|
-- Res (Pos) := '.';
|
-- Res (Pos) := '.';
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => Make_Indexed_Component (Loc,
|
Name => Make_Indexed_Component (Loc,
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
|
Expressions => New_List (New_Occurrence_Of (Pos, Loc))),
|
Expression =>
|
Expression =>
|
Make_Character_Literal (Loc,
|
Make_Character_Literal (Loc,
|
Chars => Name_Find,
|
Chars => Name_Find,
|
Char_Literal_Value =>
|
Char_Literal_Value =>
|
UI_From_Int (Character'Pos ('.')))));
|
UI_From_Int (Character'Pos ('.')))));
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => New_Occurrence_Of (Pos, Loc),
|
Name => New_Occurrence_Of (Pos, Loc),
|
Expression =>
|
Expression =>
|
Make_Op_Add (Loc,
|
Make_Op_Add (Loc,
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Left_Opnd => New_Occurrence_Of (Pos, Loc),
|
Right_Opnd => Make_Integer_Literal (Loc, 1))));
|
Right_Opnd => Make_Integer_Literal (Loc, 1))));
|
|
|
-- Res (Pos .. Len) := Selector;
|
-- Res (Pos .. Len) := Selector;
|
|
|
Append_To (Stats,
|
Append_To (Stats,
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => Make_Slice (Loc,
|
Name => Make_Slice (Loc,
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Prefix => New_Occurrence_Of (Res, Loc),
|
Discrete_Range =>
|
Discrete_Range =>
|
Make_Range (Loc,
|
Make_Range (Loc,
|
Low_Bound => New_Occurrence_Of (Pos, Loc),
|
Low_Bound => New_Occurrence_Of (Pos, Loc),
|
High_Bound => New_Occurrence_Of (Len, Loc))),
|
High_Bound => New_Occurrence_Of (Len, Loc))),
|
Expression => New_Occurrence_Of (Sel, Loc)));
|
Expression => New_Occurrence_Of (Sel, Loc)));
|
|
|
return Build_Task_Image_Function (Loc, Decls, Stats, Res);
|
return Build_Task_Image_Function (Loc, Decls, Stats, Res);
|
end Build_Task_Record_Image;
|
end Build_Task_Record_Image;
|
|
|
----------------------------------
|
----------------------------------
|
-- Component_May_Be_Bit_Aligned --
|
-- Component_May_Be_Bit_Aligned --
|
----------------------------------
|
----------------------------------
|
|
|
function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean is
|
function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean is
|
UT : Entity_Id;
|
UT : Entity_Id;
|
|
|
begin
|
begin
|
-- If no component clause, then everything is fine, since the back end
|
-- If no component clause, then everything is fine, since the back end
|
-- never bit-misaligns by default, even if there is a pragma Packed for
|
-- never bit-misaligns by default, even if there is a pragma Packed for
|
-- the record.
|
-- the record.
|
|
|
if No (Comp) or else No (Component_Clause (Comp)) then
|
if No (Comp) or else No (Component_Clause (Comp)) then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
UT := Underlying_Type (Etype (Comp));
|
UT := Underlying_Type (Etype (Comp));
|
|
|
-- It is only array and record types that cause trouble
|
-- It is only array and record types that cause trouble
|
|
|
if not Is_Record_Type (UT)
|
if not Is_Record_Type (UT)
|
and then not Is_Array_Type (UT)
|
and then not Is_Array_Type (UT)
|
then
|
then
|
return False;
|
return False;
|
|
|
-- If we know that we have a small (64 bits or less) record or small
|
-- If we know that we have a small (64 bits or less) record or small
|
-- bit-packed array, then everything is fine, since the back end can
|
-- bit-packed array, then everything is fine, since the back end can
|
-- handle these cases correctly.
|
-- handle these cases correctly.
|
|
|
elsif Esize (Comp) <= 64
|
elsif Esize (Comp) <= 64
|
and then (Is_Record_Type (UT)
|
and then (Is_Record_Type (UT)
|
or else Is_Bit_Packed_Array (UT))
|
or else Is_Bit_Packed_Array (UT))
|
then
|
then
|
return False;
|
return False;
|
|
|
-- Otherwise if the component is not byte aligned, we know we have the
|
-- Otherwise if the component is not byte aligned, we know we have the
|
-- nasty unaligned case.
|
-- nasty unaligned case.
|
|
|
elsif Normalized_First_Bit (Comp) /= Uint_0
|
elsif Normalized_First_Bit (Comp) /= Uint_0
|
or else Esize (Comp) mod System_Storage_Unit /= Uint_0
|
or else Esize (Comp) mod System_Storage_Unit /= Uint_0
|
then
|
then
|
return True;
|
return True;
|
|
|
-- If we are large and byte aligned, then OK at this level
|
-- If we are large and byte aligned, then OK at this level
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Component_May_Be_Bit_Aligned;
|
end Component_May_Be_Bit_Aligned;
|
|
|
-----------------------------------
|
-----------------------------------
|
-- Corresponding_Runtime_Package --
|
-- Corresponding_Runtime_Package --
|
-----------------------------------
|
-----------------------------------
|
|
|
function Corresponding_Runtime_Package (Typ : Entity_Id) return RTU_Id is
|
function Corresponding_Runtime_Package (Typ : Entity_Id) return RTU_Id is
|
Pkg_Id : RTU_Id := RTU_Null;
|
Pkg_Id : RTU_Id := RTU_Null;
|
|
|
begin
|
begin
|
pragma Assert (Is_Concurrent_Type (Typ));
|
pragma Assert (Is_Concurrent_Type (Typ));
|
|
|
if Ekind (Typ) in Protected_Kind then
|
if Ekind (Typ) in Protected_Kind then
|
if Has_Entries (Typ)
|
if Has_Entries (Typ)
|
|
|
-- A protected type without entries that covers an interface and
|
-- A protected type without entries that covers an interface and
|
-- overrides the abstract routines with protected procedures is
|
-- overrides the abstract routines with protected procedures is
|
-- considered equivalent to a protected type with entries in the
|
-- considered equivalent to a protected type with entries in the
|
-- context of dispatching select statements. It is sufficient to
|
-- context of dispatching select statements. It is sufficient to
|
-- check for the presence of an interface list in the declaration
|
-- check for the presence of an interface list in the declaration
|
-- node to recognize this case.
|
-- node to recognize this case.
|
|
|
or else Present (Interface_List (Parent (Typ)))
|
or else Present (Interface_List (Parent (Typ)))
|
or else
|
or else
|
(((Has_Attach_Handler (Typ) and then not Restricted_Profile)
|
(((Has_Attach_Handler (Typ) and then not Restricted_Profile)
|
or else Has_Interrupt_Handler (Typ))
|
or else Has_Interrupt_Handler (Typ))
|
and then not Restriction_Active (No_Dynamic_Attachment))
|
and then not Restriction_Active (No_Dynamic_Attachment))
|
then
|
then
|
if Abort_Allowed
|
if Abort_Allowed
|
or else Restriction_Active (No_Entry_Queue) = False
|
or else Restriction_Active (No_Entry_Queue) = False
|
or else Number_Entries (Typ) > 1
|
or else Number_Entries (Typ) > 1
|
or else (Has_Attach_Handler (Typ)
|
or else (Has_Attach_Handler (Typ)
|
and then not Restricted_Profile)
|
and then not Restricted_Profile)
|
then
|
then
|
Pkg_Id := System_Tasking_Protected_Objects_Entries;
|
Pkg_Id := System_Tasking_Protected_Objects_Entries;
|
else
|
else
|
Pkg_Id := System_Tasking_Protected_Objects_Single_Entry;
|
Pkg_Id := System_Tasking_Protected_Objects_Single_Entry;
|
end if;
|
end if;
|
|
|
else
|
else
|
Pkg_Id := System_Tasking_Protected_Objects;
|
Pkg_Id := System_Tasking_Protected_Objects;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
return Pkg_Id;
|
return Pkg_Id;
|
end Corresponding_Runtime_Package;
|
end Corresponding_Runtime_Package;
|
|
|
-------------------------------
|
-------------------------------
|
-- Convert_To_Actual_Subtype --
|
-- Convert_To_Actual_Subtype --
|
-------------------------------
|
-------------------------------
|
|
|
procedure Convert_To_Actual_Subtype (Exp : Entity_Id) is
|
procedure Convert_To_Actual_Subtype (Exp : Entity_Id) is
|
Act_ST : Entity_Id;
|
Act_ST : Entity_Id;
|
|
|
begin
|
begin
|
Act_ST := Get_Actual_Subtype (Exp);
|
Act_ST := Get_Actual_Subtype (Exp);
|
|
|
if Act_ST = Etype (Exp) then
|
if Act_ST = Etype (Exp) then
|
return;
|
return;
|
else
|
else
|
Rewrite (Exp, Convert_To (Act_ST, Relocate_Node (Exp)));
|
Rewrite (Exp, Convert_To (Act_ST, Relocate_Node (Exp)));
|
Analyze_And_Resolve (Exp, Act_ST);
|
Analyze_And_Resolve (Exp, Act_ST);
|
end if;
|
end if;
|
end Convert_To_Actual_Subtype;
|
end Convert_To_Actual_Subtype;
|
|
|
-----------------------------------
|
-----------------------------------
|
-- Current_Sem_Unit_Declarations --
|
-- Current_Sem_Unit_Declarations --
|
-----------------------------------
|
-----------------------------------
|
|
|
function Current_Sem_Unit_Declarations return List_Id is
|
function Current_Sem_Unit_Declarations return List_Id is
|
U : Node_Id := Unit (Cunit (Current_Sem_Unit));
|
U : Node_Id := Unit (Cunit (Current_Sem_Unit));
|
Decls : List_Id;
|
Decls : List_Id;
|
|
|
begin
|
begin
|
-- If the current unit is a package body, locate the visible
|
-- If the current unit is a package body, locate the visible
|
-- declarations of the package spec.
|
-- declarations of the package spec.
|
|
|
if Nkind (U) = N_Package_Body then
|
if Nkind (U) = N_Package_Body then
|
U := Unit (Library_Unit (Cunit (Current_Sem_Unit)));
|
U := Unit (Library_Unit (Cunit (Current_Sem_Unit)));
|
end if;
|
end if;
|
|
|
if Nkind (U) = N_Package_Declaration then
|
if Nkind (U) = N_Package_Declaration then
|
U := Specification (U);
|
U := Specification (U);
|
Decls := Visible_Declarations (U);
|
Decls := Visible_Declarations (U);
|
|
|
if No (Decls) then
|
if No (Decls) then
|
Decls := New_List;
|
Decls := New_List;
|
Set_Visible_Declarations (U, Decls);
|
Set_Visible_Declarations (U, Decls);
|
end if;
|
end if;
|
|
|
else
|
else
|
Decls := Declarations (U);
|
Decls := Declarations (U);
|
|
|
if No (Decls) then
|
if No (Decls) then
|
Decls := New_List;
|
Decls := New_List;
|
Set_Declarations (U, Decls);
|
Set_Declarations (U, Decls);
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
return Decls;
|
return Decls;
|
end Current_Sem_Unit_Declarations;
|
end Current_Sem_Unit_Declarations;
|
|
|
-----------------------
|
-----------------------
|
-- Duplicate_Subexpr --
|
-- Duplicate_Subexpr --
|
-----------------------
|
-----------------------
|
|
|
function Duplicate_Subexpr
|
function Duplicate_Subexpr
|
(Exp : Node_Id;
|
(Exp : Node_Id;
|
Name_Req : Boolean := False) return Node_Id
|
Name_Req : Boolean := False) return Node_Id
|
is
|
is
|
begin
|
begin
|
Remove_Side_Effects (Exp, Name_Req);
|
Remove_Side_Effects (Exp, Name_Req);
|
return New_Copy_Tree (Exp);
|
return New_Copy_Tree (Exp);
|
end Duplicate_Subexpr;
|
end Duplicate_Subexpr;
|
|
|
---------------------------------
|
---------------------------------
|
-- Duplicate_Subexpr_No_Checks --
|
-- Duplicate_Subexpr_No_Checks --
|
---------------------------------
|
---------------------------------
|
|
|
function Duplicate_Subexpr_No_Checks
|
function Duplicate_Subexpr_No_Checks
|
(Exp : Node_Id;
|
(Exp : Node_Id;
|
Name_Req : Boolean := False) return Node_Id
|
Name_Req : Boolean := False) return Node_Id
|
is
|
is
|
New_Exp : Node_Id;
|
New_Exp : Node_Id;
|
|
|
begin
|
begin
|
Remove_Side_Effects (Exp, Name_Req);
|
Remove_Side_Effects (Exp, Name_Req);
|
New_Exp := New_Copy_Tree (Exp);
|
New_Exp := New_Copy_Tree (Exp);
|
Remove_Checks (New_Exp);
|
Remove_Checks (New_Exp);
|
return New_Exp;
|
return New_Exp;
|
end Duplicate_Subexpr_No_Checks;
|
end Duplicate_Subexpr_No_Checks;
|
|
|
-----------------------------------
|
-----------------------------------
|
-- Duplicate_Subexpr_Move_Checks --
|
-- Duplicate_Subexpr_Move_Checks --
|
-----------------------------------
|
-----------------------------------
|
|
|
function Duplicate_Subexpr_Move_Checks
|
function Duplicate_Subexpr_Move_Checks
|
(Exp : Node_Id;
|
(Exp : Node_Id;
|
Name_Req : Boolean := False) return Node_Id
|
Name_Req : Boolean := False) return Node_Id
|
is
|
is
|
New_Exp : Node_Id;
|
New_Exp : Node_Id;
|
begin
|
begin
|
Remove_Side_Effects (Exp, Name_Req);
|
Remove_Side_Effects (Exp, Name_Req);
|
New_Exp := New_Copy_Tree (Exp);
|
New_Exp := New_Copy_Tree (Exp);
|
Remove_Checks (Exp);
|
Remove_Checks (Exp);
|
return New_Exp;
|
return New_Exp;
|
end Duplicate_Subexpr_Move_Checks;
|
end Duplicate_Subexpr_Move_Checks;
|
|
|
--------------------
|
--------------------
|
-- Ensure_Defined --
|
-- Ensure_Defined --
|
--------------------
|
--------------------
|
|
|
procedure Ensure_Defined (Typ : Entity_Id; N : Node_Id) is
|
procedure Ensure_Defined (Typ : Entity_Id; N : Node_Id) is
|
IR : Node_Id;
|
IR : Node_Id;
|
|
|
begin
|
begin
|
-- An itype reference must only be created if this is a local itype, so
|
-- An itype reference must only be created if this is a local itype, so
|
-- that gigi can elaborate it on the proper objstack.
|
-- that gigi can elaborate it on the proper objstack.
|
|
|
if Is_Itype (Typ)
|
if Is_Itype (Typ)
|
and then Scope (Typ) = Current_Scope
|
and then Scope (Typ) = Current_Scope
|
then
|
then
|
IR := Make_Itype_Reference (Sloc (N));
|
IR := Make_Itype_Reference (Sloc (N));
|
Set_Itype (IR, Typ);
|
Set_Itype (IR, Typ);
|
Insert_Action (N, IR);
|
Insert_Action (N, IR);
|
end if;
|
end if;
|
end Ensure_Defined;
|
end Ensure_Defined;
|
|
|
--------------------
|
--------------------
|
-- Entry_Names_OK --
|
-- Entry_Names_OK --
|
--------------------
|
--------------------
|
|
|
function Entry_Names_OK return Boolean is
|
function Entry_Names_OK return Boolean is
|
begin
|
begin
|
return
|
return
|
not Restricted_Profile
|
not Restricted_Profile
|
and then not Global_Discard_Names
|
and then not Global_Discard_Names
|
and then not Restriction_Active (No_Implicit_Heap_Allocations)
|
and then not Restriction_Active (No_Implicit_Heap_Allocations)
|
and then not Restriction_Active (No_Local_Allocators);
|
and then not Restriction_Active (No_Local_Allocators);
|
end Entry_Names_OK;
|
end Entry_Names_OK;
|
|
|
-------------------
|
-------------------
|
-- Evaluate_Name --
|
-- Evaluate_Name --
|
-------------------
|
-------------------
|
|
|
procedure Evaluate_Name (Nam : Node_Id) is
|
procedure Evaluate_Name (Nam : Node_Id) is
|
K : constant Node_Kind := Nkind (Nam);
|
K : constant Node_Kind := Nkind (Nam);
|
|
|
begin
|
begin
|
-- For an explicit dereference, we simply force the evaluation of the
|
-- For an explicit dereference, we simply force the evaluation of the
|
-- name expression. The dereference provides a value that is the address
|
-- name expression. The dereference provides a value that is the address
|
-- for the renamed object, and it is precisely this value that we want
|
-- for the renamed object, and it is precisely this value that we want
|
-- to preserve.
|
-- to preserve.
|
|
|
if K = N_Explicit_Dereference then
|
if K = N_Explicit_Dereference then
|
Force_Evaluation (Prefix (Nam));
|
Force_Evaluation (Prefix (Nam));
|
|
|
-- For a selected component, we simply evaluate the prefix
|
-- For a selected component, we simply evaluate the prefix
|
|
|
elsif K = N_Selected_Component then
|
elsif K = N_Selected_Component then
|
Evaluate_Name (Prefix (Nam));
|
Evaluate_Name (Prefix (Nam));
|
|
|
-- For an indexed component, or an attribute reference, we evaluate the
|
-- For an indexed component, or an attribute reference, we evaluate the
|
-- prefix, which is itself a name, recursively, and then force the
|
-- prefix, which is itself a name, recursively, and then force the
|
-- evaluation of all the subscripts (or attribute expressions).
|
-- evaluation of all the subscripts (or attribute expressions).
|
|
|
elsif Nkind_In (K, N_Indexed_Component, N_Attribute_Reference) then
|
elsif Nkind_In (K, N_Indexed_Component, N_Attribute_Reference) then
|
Evaluate_Name (Prefix (Nam));
|
Evaluate_Name (Prefix (Nam));
|
|
|
declare
|
declare
|
E : Node_Id;
|
E : Node_Id;
|
|
|
begin
|
begin
|
E := First (Expressions (Nam));
|
E := First (Expressions (Nam));
|
while Present (E) loop
|
while Present (E) loop
|
Force_Evaluation (E);
|
Force_Evaluation (E);
|
|
|
if Original_Node (E) /= E then
|
if Original_Node (E) /= E then
|
Set_Do_Range_Check (E, Do_Range_Check (Original_Node (E)));
|
Set_Do_Range_Check (E, Do_Range_Check (Original_Node (E)));
|
end if;
|
end if;
|
|
|
Next (E);
|
Next (E);
|
end loop;
|
end loop;
|
end;
|
end;
|
|
|
-- For a slice, we evaluate the prefix, as for the indexed component
|
-- For a slice, we evaluate the prefix, as for the indexed component
|
-- case and then, if there is a range present, either directly or as the
|
-- case and then, if there is a range present, either directly or as the
|
-- constraint of a discrete subtype indication, we evaluate the two
|
-- constraint of a discrete subtype indication, we evaluate the two
|
-- bounds of this range.
|
-- bounds of this range.
|
|
|
elsif K = N_Slice then
|
elsif K = N_Slice then
|
Evaluate_Name (Prefix (Nam));
|
Evaluate_Name (Prefix (Nam));
|
|
|
declare
|
declare
|
DR : constant Node_Id := Discrete_Range (Nam);
|
DR : constant Node_Id := Discrete_Range (Nam);
|
Constr : Node_Id;
|
Constr : Node_Id;
|
Rexpr : Node_Id;
|
Rexpr : Node_Id;
|
|
|
begin
|
begin
|
if Nkind (DR) = N_Range then
|
if Nkind (DR) = N_Range then
|
Force_Evaluation (Low_Bound (DR));
|
Force_Evaluation (Low_Bound (DR));
|
Force_Evaluation (High_Bound (DR));
|
Force_Evaluation (High_Bound (DR));
|
|
|
elsif Nkind (DR) = N_Subtype_Indication then
|
elsif Nkind (DR) = N_Subtype_Indication then
|
Constr := Constraint (DR);
|
Constr := Constraint (DR);
|
|
|
if Nkind (Constr) = N_Range_Constraint then
|
if Nkind (Constr) = N_Range_Constraint then
|
Rexpr := Range_Expression (Constr);
|
Rexpr := Range_Expression (Constr);
|
|
|
Force_Evaluation (Low_Bound (Rexpr));
|
Force_Evaluation (Low_Bound (Rexpr));
|
Force_Evaluation (High_Bound (Rexpr));
|
Force_Evaluation (High_Bound (Rexpr));
|
end if;
|
end if;
|
end if;
|
end if;
|
end;
|
end;
|
|
|
-- For a type conversion, the expression of the conversion must be the
|
-- For a type conversion, the expression of the conversion must be the
|
-- name of an object, and we simply need to evaluate this name.
|
-- name of an object, and we simply need to evaluate this name.
|
|
|
elsif K = N_Type_Conversion then
|
elsif K = N_Type_Conversion then
|
Evaluate_Name (Expression (Nam));
|
Evaluate_Name (Expression (Nam));
|
|
|
-- For a function call, we evaluate the call
|
-- For a function call, we evaluate the call
|
|
|
elsif K = N_Function_Call then
|
elsif K = N_Function_Call then
|
Force_Evaluation (Nam);
|
Force_Evaluation (Nam);
|
|
|
-- The remaining cases are direct name, operator symbol and character
|
-- The remaining cases are direct name, operator symbol and character
|
-- literal. In all these cases, we do nothing, since we want to
|
-- literal. In all these cases, we do nothing, since we want to
|
-- reevaluate each time the renamed object is used.
|
-- reevaluate each time the renamed object is used.
|
|
|
else
|
else
|
return;
|
return;
|
end if;
|
end if;
|
end Evaluate_Name;
|
end Evaluate_Name;
|
|
|
---------------------
|
---------------------
|
-- Evolve_And_Then --
|
-- Evolve_And_Then --
|
---------------------
|
---------------------
|
|
|
procedure Evolve_And_Then (Cond : in out Node_Id; Cond1 : Node_Id) is
|
procedure Evolve_And_Then (Cond : in out Node_Id; Cond1 : Node_Id) is
|
begin
|
begin
|
if No (Cond) then
|
if No (Cond) then
|
Cond := Cond1;
|
Cond := Cond1;
|
else
|
else
|
Cond :=
|
Cond :=
|
Make_And_Then (Sloc (Cond1),
|
Make_And_Then (Sloc (Cond1),
|
Left_Opnd => Cond,
|
Left_Opnd => Cond,
|
Right_Opnd => Cond1);
|
Right_Opnd => Cond1);
|
end if;
|
end if;
|
end Evolve_And_Then;
|
end Evolve_And_Then;
|
|
|
--------------------
|
--------------------
|
-- Evolve_Or_Else --
|
-- Evolve_Or_Else --
|
--------------------
|
--------------------
|
|
|
procedure Evolve_Or_Else (Cond : in out Node_Id; Cond1 : Node_Id) is
|
procedure Evolve_Or_Else (Cond : in out Node_Id; Cond1 : Node_Id) is
|
begin
|
begin
|
if No (Cond) then
|
if No (Cond) then
|
Cond := Cond1;
|
Cond := Cond1;
|
else
|
else
|
Cond :=
|
Cond :=
|
Make_Or_Else (Sloc (Cond1),
|
Make_Or_Else (Sloc (Cond1),
|
Left_Opnd => Cond,
|
Left_Opnd => Cond,
|
Right_Opnd => Cond1);
|
Right_Opnd => Cond1);
|
end if;
|
end if;
|
end Evolve_Or_Else;
|
end Evolve_Or_Else;
|
|
|
------------------------------
|
------------------------------
|
-- Expand_Subtype_From_Expr --
|
-- Expand_Subtype_From_Expr --
|
------------------------------
|
------------------------------
|
|
|
-- This function is applicable for both static and dynamic allocation of
|
-- This function is applicable for both static and dynamic allocation of
|
-- objects which are constrained by an initial expression. Basically it
|
-- objects which are constrained by an initial expression. Basically it
|
-- transforms an unconstrained subtype indication into a constrained one.
|
-- transforms an unconstrained subtype indication into a constrained one.
|
|
|
-- The expression may also be transformed in certain cases in order to
|
-- The expression may also be transformed in certain cases in order to
|
-- avoid multiple evaluation. In the static allocation case, the general
|
-- avoid multiple evaluation. In the static allocation case, the general
|
-- scheme is:
|
-- scheme is:
|
|
|
-- Val : T := Expr;
|
-- Val : T := Expr;
|
|
|
-- is transformed into
|
-- is transformed into
|
|
|
-- Val : Constrained_Subtype_of_T := Maybe_Modified_Expr;
|
-- Val : Constrained_Subtype_of_T := Maybe_Modified_Expr;
|
--
|
--
|
-- Here are the main cases :
|
-- Here are the main cases :
|
--
|
--
|
-- <if Expr is a Slice>
|
-- <if Expr is a Slice>
|
-- Val : T ([Index_Subtype (Expr)]) := Expr;
|
-- Val : T ([Index_Subtype (Expr)]) := Expr;
|
--
|
--
|
-- <elsif Expr is a String Literal>
|
-- <elsif Expr is a String Literal>
|
-- Val : T (T'First .. T'First + Length (string literal) - 1) := Expr;
|
-- Val : T (T'First .. T'First + Length (string literal) - 1) := Expr;
|
--
|
--
|
-- <elsif Expr is Constrained>
|
-- <elsif Expr is Constrained>
|
-- subtype T is Type_Of_Expr
|
-- subtype T is Type_Of_Expr
|
-- Val : T := Expr;
|
-- Val : T := Expr;
|
--
|
--
|
-- <elsif Expr is an entity_name>
|
-- <elsif Expr is an entity_name>
|
-- Val : T (constraints taken from Expr) := Expr;
|
-- Val : T (constraints taken from Expr) := Expr;
|
--
|
--
|
-- <else>
|
-- <else>
|
-- type Axxx is access all T;
|
-- type Axxx is access all T;
|
-- Rval : Axxx := Expr'ref;
|
-- Rval : Axxx := Expr'ref;
|
-- Val : T (constraints taken from Rval) := Rval.all;
|
-- Val : T (constraints taken from Rval) := Rval.all;
|
|
|
-- ??? note: when the Expression is allocated in the secondary stack
|
-- ??? note: when the Expression is allocated in the secondary stack
|
-- we could use it directly instead of copying it by declaring
|
-- we could use it directly instead of copying it by declaring
|
-- Val : T (...) renames Rval.all
|
-- Val : T (...) renames Rval.all
|
|
|
procedure Expand_Subtype_From_Expr
|
procedure Expand_Subtype_From_Expr
|
(N : Node_Id;
|
(N : Node_Id;
|
Unc_Type : Entity_Id;
|
Unc_Type : Entity_Id;
|
Subtype_Indic : Node_Id;
|
Subtype_Indic : Node_Id;
|
Exp : Node_Id)
|
Exp : Node_Id)
|
is
|
is
|
Loc : constant Source_Ptr := Sloc (N);
|
Loc : constant Source_Ptr := Sloc (N);
|
Exp_Typ : constant Entity_Id := Etype (Exp);
|
Exp_Typ : constant Entity_Id := Etype (Exp);
|
T : Entity_Id;
|
T : Entity_Id;
|
|
|
begin
|
begin
|
-- In general we cannot build the subtype if expansion is disabled,
|
-- In general we cannot build the subtype if expansion is disabled,
|
-- because internal entities may not have been defined. However, to
|
-- because internal entities may not have been defined. However, to
|
-- avoid some cascaded errors, we try to continue when the expression is
|
-- avoid some cascaded errors, we try to continue when the expression is
|
-- an array (or string), because it is safe to compute the bounds. It is
|
-- an array (or string), because it is safe to compute the bounds. It is
|
-- in fact required to do so even in a generic context, because there
|
-- in fact required to do so even in a generic context, because there
|
-- may be constants that depend on the bounds of a string literal, both
|
-- may be constants that depend on the bounds of a string literal, both
|
-- standard string types and more generally arrays of characters.
|
-- standard string types and more generally arrays of characters.
|
|
|
if not Expander_Active
|
if not Expander_Active
|
and then (No (Etype (Exp))
|
and then (No (Etype (Exp))
|
or else not Is_String_Type (Etype (Exp)))
|
or else not Is_String_Type (Etype (Exp)))
|
then
|
then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
if Nkind (Exp) = N_Slice then
|
if Nkind (Exp) = N_Slice then
|
declare
|
declare
|
Slice_Type : constant Entity_Id := Etype (First_Index (Exp_Typ));
|
Slice_Type : constant Entity_Id := Etype (First_Index (Exp_Typ));
|
|
|
begin
|
begin
|
Rewrite (Subtype_Indic,
|
Rewrite (Subtype_Indic,
|
Make_Subtype_Indication (Loc,
|
Make_Subtype_Indication (Loc,
|
Subtype_Mark => New_Reference_To (Unc_Type, Loc),
|
Subtype_Mark => New_Reference_To (Unc_Type, Loc),
|
Constraint =>
|
Constraint =>
|
Make_Index_Or_Discriminant_Constraint (Loc,
|
Make_Index_Or_Discriminant_Constraint (Loc,
|
Constraints => New_List
|
Constraints => New_List
|
(New_Reference_To (Slice_Type, Loc)))));
|
(New_Reference_To (Slice_Type, Loc)))));
|
|
|
-- This subtype indication may be used later for constraint checks
|
-- This subtype indication may be used later for constraint checks
|
-- we better make sure that if a variable was used as a bound of
|
-- we better make sure that if a variable was used as a bound of
|
-- of the original slice, its value is frozen.
|
-- of the original slice, its value is frozen.
|
|
|
Force_Evaluation (Low_Bound (Scalar_Range (Slice_Type)));
|
Force_Evaluation (Low_Bound (Scalar_Range (Slice_Type)));
|
Force_Evaluation (High_Bound (Scalar_Range (Slice_Type)));
|
Force_Evaluation (High_Bound (Scalar_Range (Slice_Type)));
|
end;
|
end;
|
|
|
elsif Ekind (Exp_Typ) = E_String_Literal_Subtype then
|
elsif Ekind (Exp_Typ) = E_String_Literal_Subtype then
|
Rewrite (Subtype_Indic,
|
Rewrite (Subtype_Indic,
|
Make_Subtype_Indication (Loc,
|
Make_Subtype_Indication (Loc,
|
Subtype_Mark => New_Reference_To (Unc_Type, Loc),
|
Subtype_Mark => New_Reference_To (Unc_Type, Loc),
|
Constraint =>
|
Constraint =>
|
Make_Index_Or_Discriminant_Constraint (Loc,
|
Make_Index_Or_Discriminant_Constraint (Loc,
|
Constraints => New_List (
|
Constraints => New_List (
|
Make_Literal_Range (Loc,
|
Make_Literal_Range (Loc,
|
Literal_Typ => Exp_Typ)))));
|
Literal_Typ => Exp_Typ)))));
|
|
|
elsif Is_Constrained (Exp_Typ)
|
elsif Is_Constrained (Exp_Typ)
|
and then not Is_Class_Wide_Type (Unc_Type)
|
and then not Is_Class_Wide_Type (Unc_Type)
|
then
|
then
|
if Is_Itype (Exp_Typ) then
|
if Is_Itype (Exp_Typ) then
|
|
|
-- Within an initialization procedure, a selected component
|
-- Within an initialization procedure, a selected component
|
-- denotes a component of the enclosing record, and it appears as
|
-- denotes a component of the enclosing record, and it appears as
|
-- an actual in a call to its own initialization procedure. If
|
-- an actual in a call to its own initialization procedure. If
|
-- this component depends on the outer discriminant, we must
|
-- this component depends on the outer discriminant, we must
|
-- generate the proper actual subtype for it.
|
-- generate the proper actual subtype for it.
|
|
|
if Nkind (Exp) = N_Selected_Component
|
if Nkind (Exp) = N_Selected_Component
|
and then Within_Init_Proc
|
and then Within_Init_Proc
|
then
|
then
|
declare
|
declare
|
Decl : constant Node_Id :=
|
Decl : constant Node_Id :=
|
Build_Actual_Subtype_Of_Component (Exp_Typ, Exp);
|
Build_Actual_Subtype_Of_Component (Exp_Typ, Exp);
|
begin
|
begin
|
if Present (Decl) then
|
if Present (Decl) then
|
Insert_Action (N, Decl);
|
Insert_Action (N, Decl);
|
T := Defining_Identifier (Decl);
|
T := Defining_Identifier (Decl);
|
else
|
else
|
T := Exp_Typ;
|
T := Exp_Typ;
|
end if;
|
end if;
|
end;
|
end;
|
|
|
-- No need to generate a new one (new what???)
|
-- No need to generate a new one (new what???)
|
|
|
else
|
else
|
T := Exp_Typ;
|
T := Exp_Typ;
|
end if;
|
end if;
|
|
|
else
|
else
|
T := Make_Temporary (Loc, 'T');
|
T := Make_Temporary (Loc, 'T');
|
|
|
Insert_Action (N,
|
Insert_Action (N,
|
Make_Subtype_Declaration (Loc,
|
Make_Subtype_Declaration (Loc,
|
Defining_Identifier => T,
|
Defining_Identifier => T,
|
Subtype_Indication => New_Reference_To (Exp_Typ, Loc)));
|
Subtype_Indication => New_Reference_To (Exp_Typ, Loc)));
|
|
|
-- This type is marked as an itype even though it has an explicit
|
-- This type is marked as an itype even though it has an explicit
|
-- declaration since otherwise Is_Generic_Actual_Type can get
|
-- declaration since otherwise Is_Generic_Actual_Type can get
|
-- set, resulting in the generation of spurious errors. (See
|
-- set, resulting in the generation of spurious errors. (See
|
-- sem_ch8.Analyze_Package_Renaming and sem_type.covers)
|
-- sem_ch8.Analyze_Package_Renaming and sem_type.covers)
|
|
|
Set_Is_Itype (T);
|
Set_Is_Itype (T);
|
Set_Associated_Node_For_Itype (T, Exp);
|
Set_Associated_Node_For_Itype (T, Exp);
|
end if;
|
end if;
|
|
|
Rewrite (Subtype_Indic, New_Reference_To (T, Loc));
|
Rewrite (Subtype_Indic, New_Reference_To (T, Loc));
|
|
|
-- Nothing needs to be done for private types with unknown discriminants
|
-- Nothing needs to be done for private types with unknown discriminants
|
-- if the underlying type is not an unconstrained composite type or it
|
-- if the underlying type is not an unconstrained composite type or it
|
-- is an unchecked union.
|
-- is an unchecked union.
|
|
|
elsif Is_Private_Type (Unc_Type)
|
elsif Is_Private_Type (Unc_Type)
|
and then Has_Unknown_Discriminants (Unc_Type)
|
and then Has_Unknown_Discriminants (Unc_Type)
|
and then (not Is_Composite_Type (Underlying_Type (Unc_Type))
|
and then (not Is_Composite_Type (Underlying_Type (Unc_Type))
|
or else Is_Constrained (Underlying_Type (Unc_Type))
|
or else Is_Constrained (Underlying_Type (Unc_Type))
|
or else Is_Unchecked_Union (Underlying_Type (Unc_Type)))
|
or else Is_Unchecked_Union (Underlying_Type (Unc_Type)))
|
then
|
then
|
null;
|
null;
|
|
|
-- Case of derived type with unknown discriminants where the parent type
|
-- Case of derived type with unknown discriminants where the parent type
|
-- also has unknown discriminants.
|
-- also has unknown discriminants.
|
|
|
elsif Is_Record_Type (Unc_Type)
|
elsif Is_Record_Type (Unc_Type)
|
and then not Is_Class_Wide_Type (Unc_Type)
|
and then not Is_Class_Wide_Type (Unc_Type)
|
and then Has_Unknown_Discriminants (Unc_Type)
|
and then Has_Unknown_Discriminants (Unc_Type)
|
and then Has_Unknown_Discriminants (Underlying_Type (Unc_Type))
|
and then Has_Unknown_Discriminants (Underlying_Type (Unc_Type))
|
then
|
then
|
-- Nothing to be done if no underlying record view available
|
-- Nothing to be done if no underlying record view available
|
|
|
if No (Underlying_Record_View (Unc_Type)) then
|
if No (Underlying_Record_View (Unc_Type)) then
|
null;
|
null;
|
|
|
-- Otherwise use the Underlying_Record_View to create the proper
|
-- Otherwise use the Underlying_Record_View to create the proper
|
-- constrained subtype for an object of a derived type with unknown
|
-- constrained subtype for an object of a derived type with unknown
|
-- discriminants.
|
-- discriminants.
|
|
|
else
|
else
|
Remove_Side_Effects (Exp);
|
Remove_Side_Effects (Exp);
|
Rewrite (Subtype_Indic,
|
Rewrite (Subtype_Indic,
|
Make_Subtype_From_Expr (Exp, Underlying_Record_View (Unc_Type)));
|
Make_Subtype_From_Expr (Exp, Underlying_Record_View (Unc_Type)));
|
end if;
|
end if;
|
|
|
-- Renamings of class-wide interface types require no equivalent
|
-- Renamings of class-wide interface types require no equivalent
|
-- constrained type declarations because we only need to reference
|
-- constrained type declarations because we only need to reference
|
-- the tag component associated with the interface. The same is
|
-- the tag component associated with the interface. The same is
|
-- presumably true for class-wide types in general, so this test
|
-- presumably true for class-wide types in general, so this test
|
-- is broadened to include all class-wide renamings, which also
|
-- is broadened to include all class-wide renamings, which also
|
-- avoids cases of unbounded recursion in Remove_Side_Effects.
|
-- avoids cases of unbounded recursion in Remove_Side_Effects.
|
-- (Is this really correct, or are there some cases of class-wide
|
-- (Is this really correct, or are there some cases of class-wide
|
-- renamings that require action in this procedure???)
|
-- renamings that require action in this procedure???)
|
|
|
elsif Present (N)
|
elsif Present (N)
|
and then Nkind (N) = N_Object_Renaming_Declaration
|
and then Nkind (N) = N_Object_Renaming_Declaration
|
and then Is_Class_Wide_Type (Unc_Type)
|
and then Is_Class_Wide_Type (Unc_Type)
|
then
|
then
|
null;
|
null;
|
|
|
-- In Ada 95 nothing to be done if the type of the expression is limited
|
-- In Ada 95 nothing to be done if the type of the expression is limited
|
-- because in this case the expression cannot be copied, and its use can
|
-- because in this case the expression cannot be copied, and its use can
|
-- only be by reference.
|
-- only be by reference.
|
|
|
-- In Ada 2005 the context can be an object declaration whose expression
|
-- In Ada 2005 the context can be an object declaration whose expression
|
-- is a function that returns in place. If the nominal subtype has
|
-- is a function that returns in place. If the nominal subtype has
|
-- unknown discriminants, the call still provides constraints on the
|
-- unknown discriminants, the call still provides constraints on the
|
-- object, and we have to create an actual subtype from it.
|
-- object, and we have to create an actual subtype from it.
|
|
|
-- If the type is class-wide, the expression is dynamically tagged and
|
-- If the type is class-wide, the expression is dynamically tagged and
|
-- we do not create an actual subtype either. Ditto for an interface.
|
-- we do not create an actual subtype either. Ditto for an interface.
|
-- For now this applies only if the type is immutably limited, and the
|
-- For now this applies only if the type is immutably limited, and the
|
-- function being called is build-in-place. This will have to be revised
|
-- function being called is build-in-place. This will have to be revised
|
-- when build-in-place functions are generalized to other types.
|
-- when build-in-place functions are generalized to other types.
|
|
|
elsif Is_Immutably_Limited_Type (Exp_Typ)
|
elsif Is_Immutably_Limited_Type (Exp_Typ)
|
and then
|
and then
|
(Is_Class_Wide_Type (Exp_Typ)
|
(Is_Class_Wide_Type (Exp_Typ)
|
or else Is_Interface (Exp_Typ)
|
or else Is_Interface (Exp_Typ)
|
or else not Has_Unknown_Discriminants (Exp_Typ)
|
or else not Has_Unknown_Discriminants (Exp_Typ)
|
or else not Is_Composite_Type (Unc_Type))
|
or else not Is_Composite_Type (Unc_Type))
|
then
|
then
|
null;
|
null;
|
|
|
-- For limited objects initialized with build in place function calls,
|
-- For limited objects initialized with build in place function calls,
|
-- nothing to be done; otherwise we prematurely introduce an N_Reference
|
-- nothing to be done; otherwise we prematurely introduce an N_Reference
|
-- node in the expression initializing the object, which breaks the
|
-- node in the expression initializing the object, which breaks the
|
-- circuitry that detects and adds the additional arguments to the
|
-- circuitry that detects and adds the additional arguments to the
|
-- called function.
|
-- called function.
|
|
|
elsif Is_Build_In_Place_Function_Call (Exp) then
|
elsif Is_Build_In_Place_Function_Call (Exp) then
|
null;
|
null;
|
|
|
else
|
else
|
Remove_Side_Effects (Exp);
|
Remove_Side_Effects (Exp);
|
Rewrite (Subtype_Indic,
|
Rewrite (Subtype_Indic,
|
Make_Subtype_From_Expr (Exp, Unc_Type));
|
Make_Subtype_From_Expr (Exp, Unc_Type));
|
end if;
|
end if;
|
end Expand_Subtype_From_Expr;
|
end Expand_Subtype_From_Expr;
|
|
|
--------------------
|
--------------------
|
-- Find_Init_Call --
|
-- Find_Init_Call --
|
--------------------
|
--------------------
|
|
|
function Find_Init_Call
|
function Find_Init_Call
|
(Var : Entity_Id;
|
(Var : Entity_Id;
|
Rep_Clause : Node_Id) return Node_Id
|
Rep_Clause : Node_Id) return Node_Id
|
is
|
is
|
Typ : constant Entity_Id := Etype (Var);
|
Typ : constant Entity_Id := Etype (Var);
|
|
|
Init_Proc : Entity_Id;
|
Init_Proc : Entity_Id;
|
-- Initialization procedure for Typ
|
-- Initialization procedure for Typ
|
|
|
function Find_Init_Call_In_List (From : Node_Id) return Node_Id;
|
function Find_Init_Call_In_List (From : Node_Id) return Node_Id;
|
-- Look for init call for Var starting at From and scanning the
|
-- Look for init call for Var starting at From and scanning the
|
-- enclosing list until Rep_Clause or the end of the list is reached.
|
-- enclosing list until Rep_Clause or the end of the list is reached.
|
|
|
----------------------------
|
----------------------------
|
-- Find_Init_Call_In_List --
|
-- Find_Init_Call_In_List --
|
----------------------------
|
----------------------------
|
|
|
function Find_Init_Call_In_List (From : Node_Id) return Node_Id is
|
function Find_Init_Call_In_List (From : Node_Id) return Node_Id is
|
Init_Call : Node_Id;
|
Init_Call : Node_Id;
|
begin
|
begin
|
Init_Call := From;
|
Init_Call := From;
|
|
|
while Present (Init_Call) and then Init_Call /= Rep_Clause loop
|
while Present (Init_Call) and then Init_Call /= Rep_Clause loop
|
if Nkind (Init_Call) = N_Procedure_Call_Statement
|
if Nkind (Init_Call) = N_Procedure_Call_Statement
|
and then Is_Entity_Name (Name (Init_Call))
|
and then Is_Entity_Name (Name (Init_Call))
|
and then Entity (Name (Init_Call)) = Init_Proc
|
and then Entity (Name (Init_Call)) = Init_Proc
|
then
|
then
|
return Init_Call;
|
return Init_Call;
|
end if;
|
end if;
|
|
|
Next (Init_Call);
|
Next (Init_Call);
|
end loop;
|
end loop;
|
|
|
return Empty;
|
return Empty;
|
end Find_Init_Call_In_List;
|
end Find_Init_Call_In_List;
|
|
|
Init_Call : Node_Id;
|
Init_Call : Node_Id;
|
|
|
-- Start of processing for Find_Init_Call
|
-- Start of processing for Find_Init_Call
|
|
|
begin
|
begin
|
if not Has_Non_Null_Base_Init_Proc (Typ) then
|
if not Has_Non_Null_Base_Init_Proc (Typ) then
|
-- No init proc for the type, so obviously no call to be found
|
-- No init proc for the type, so obviously no call to be found
|
|
|
return Empty;
|
return Empty;
|
end if;
|
end if;
|
|
|
Init_Proc := Base_Init_Proc (Typ);
|
Init_Proc := Base_Init_Proc (Typ);
|
|
|
-- First scan the list containing the declaration of Var
|
-- First scan the list containing the declaration of Var
|
|
|
Init_Call := Find_Init_Call_In_List (From => Next (Parent (Var)));
|
Init_Call := Find_Init_Call_In_List (From => Next (Parent (Var)));
|
|
|
-- If not found, also look on Var's freeze actions list, if any, since
|
-- If not found, also look on Var's freeze actions list, if any, since
|
-- the init call may have been moved there (case of an address clause
|
-- the init call may have been moved there (case of an address clause
|
-- applying to Var).
|
-- applying to Var).
|
|
|
if No (Init_Call) and then Present (Freeze_Node (Var)) then
|
if No (Init_Call) and then Present (Freeze_Node (Var)) then
|
Init_Call :=
|
Init_Call :=
|
Find_Init_Call_In_List (First (Actions (Freeze_Node (Var))));
|
Find_Init_Call_In_List (First (Actions (Freeze_Node (Var))));
|
end if;
|
end if;
|
|
|
return Init_Call;
|
return Init_Call;
|
end Find_Init_Call;
|
end Find_Init_Call;
|
|
|
------------------------
|
------------------------
|
-- Find_Interface_ADT --
|
-- Find_Interface_ADT --
|
------------------------
|
------------------------
|
|
|
function Find_Interface_ADT
|
function Find_Interface_ADT
|
(T : Entity_Id;
|
(T : Entity_Id;
|
Iface : Entity_Id) return Elmt_Id
|
Iface : Entity_Id) return Elmt_Id
|
is
|
is
|
ADT : Elmt_Id;
|
ADT : Elmt_Id;
|
Typ : Entity_Id := T;
|
Typ : Entity_Id := T;
|
|
|
begin
|
begin
|
pragma Assert (Is_Interface (Iface));
|
pragma Assert (Is_Interface (Iface));
|
|
|
-- Handle private types
|
-- Handle private types
|
|
|
if Has_Private_Declaration (Typ)
|
if Has_Private_Declaration (Typ)
|
and then Present (Full_View (Typ))
|
and then Present (Full_View (Typ))
|
then
|
then
|
Typ := Full_View (Typ);
|
Typ := Full_View (Typ);
|
end if;
|
end if;
|
|
|
-- Handle access types
|
-- Handle access types
|
|
|
if Is_Access_Type (Typ) then
|
if Is_Access_Type (Typ) then
|
Typ := Designated_Type (Typ);
|
Typ := Designated_Type (Typ);
|
end if;
|
end if;
|
|
|
-- Handle task and protected types implementing interfaces
|
-- Handle task and protected types implementing interfaces
|
|
|
if Is_Concurrent_Type (Typ) then
|
if Is_Concurrent_Type (Typ) then
|
Typ := Corresponding_Record_Type (Typ);
|
Typ := Corresponding_Record_Type (Typ);
|
end if;
|
end if;
|
|
|
pragma Assert
|
pragma Assert
|
(not Is_Class_Wide_Type (Typ)
|
(not Is_Class_Wide_Type (Typ)
|
and then Ekind (Typ) /= E_Incomplete_Type);
|
and then Ekind (Typ) /= E_Incomplete_Type);
|
|
|
if Is_Ancestor (Iface, Typ, Use_Full_View => True) then
|
if Is_Ancestor (Iface, Typ, Use_Full_View => True) then
|
return First_Elmt (Access_Disp_Table (Typ));
|
return First_Elmt (Access_Disp_Table (Typ));
|
|
|
else
|
else
|
ADT :=
|
ADT :=
|
Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
|
Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
|
while Present (ADT)
|
while Present (ADT)
|
and then Present (Related_Type (Node (ADT)))
|
and then Present (Related_Type (Node (ADT)))
|
and then Related_Type (Node (ADT)) /= Iface
|
and then Related_Type (Node (ADT)) /= Iface
|
and then not Is_Ancestor (Iface, Related_Type (Node (ADT)),
|
and then not Is_Ancestor (Iface, Related_Type (Node (ADT)),
|
Use_Full_View => True)
|
Use_Full_View => True)
|
loop
|
loop
|
Next_Elmt (ADT);
|
Next_Elmt (ADT);
|
end loop;
|
end loop;
|
|
|
pragma Assert (Present (Related_Type (Node (ADT))));
|
pragma Assert (Present (Related_Type (Node (ADT))));
|
return ADT;
|
return ADT;
|
end if;
|
end if;
|
end Find_Interface_ADT;
|
end Find_Interface_ADT;
|
|
|
------------------------
|
------------------------
|
-- Find_Interface_Tag --
|
-- Find_Interface_Tag --
|
------------------------
|
------------------------
|
|
|
function Find_Interface_Tag
|
function Find_Interface_Tag
|
(T : Entity_Id;
|
(T : Entity_Id;
|
Iface : Entity_Id) return Entity_Id
|
Iface : Entity_Id) return Entity_Id
|
is
|
is
|
AI_Tag : Entity_Id;
|
AI_Tag : Entity_Id;
|
Found : Boolean := False;
|
Found : Boolean := False;
|
Typ : Entity_Id := T;
|
Typ : Entity_Id := T;
|
|
|
procedure Find_Tag (Typ : Entity_Id);
|
procedure Find_Tag (Typ : Entity_Id);
|
-- Internal subprogram used to recursively climb to the ancestors
|
-- Internal subprogram used to recursively climb to the ancestors
|
|
|
--------------
|
--------------
|
-- Find_Tag --
|
-- Find_Tag --
|
--------------
|
--------------
|
|
|
procedure Find_Tag (Typ : Entity_Id) is
|
procedure Find_Tag (Typ : Entity_Id) is
|
AI_Elmt : Elmt_Id;
|
AI_Elmt : Elmt_Id;
|
AI : Node_Id;
|
AI : Node_Id;
|
|
|
begin
|
begin
|
-- This routine does not handle the case in which the interface is an
|
-- This routine does not handle the case in which the interface is an
|
-- ancestor of Typ. That case is handled by the enclosing subprogram.
|
-- ancestor of Typ. That case is handled by the enclosing subprogram.
|
|
|
pragma Assert (Typ /= Iface);
|
pragma Assert (Typ /= Iface);
|
|
|
-- Climb to the root type handling private types
|
-- Climb to the root type handling private types
|
|
|
if Present (Full_View (Etype (Typ))) then
|
if Present (Full_View (Etype (Typ))) then
|
if Full_View (Etype (Typ)) /= Typ then
|
if Full_View (Etype (Typ)) /= Typ then
|
Find_Tag (Full_View (Etype (Typ)));
|
Find_Tag (Full_View (Etype (Typ)));
|
end if;
|
end if;
|
|
|
elsif Etype (Typ) /= Typ then
|
elsif Etype (Typ) /= Typ then
|
Find_Tag (Etype (Typ));
|
Find_Tag (Etype (Typ));
|
end if;
|
end if;
|
|
|
-- Traverse the list of interfaces implemented by the type
|
-- Traverse the list of interfaces implemented by the type
|
|
|
if not Found
|
if not Found
|
and then Present (Interfaces (Typ))
|
and then Present (Interfaces (Typ))
|
and then not (Is_Empty_Elmt_List (Interfaces (Typ)))
|
and then not (Is_Empty_Elmt_List (Interfaces (Typ)))
|
then
|
then
|
-- Skip the tag associated with the primary table
|
-- Skip the tag associated with the primary table
|
|
|
pragma Assert (Etype (First_Tag_Component (Typ)) = RTE (RE_Tag));
|
pragma Assert (Etype (First_Tag_Component (Typ)) = RTE (RE_Tag));
|
AI_Tag := Next_Tag_Component (First_Tag_Component (Typ));
|
AI_Tag := Next_Tag_Component (First_Tag_Component (Typ));
|
pragma Assert (Present (AI_Tag));
|
pragma Assert (Present (AI_Tag));
|
|
|
AI_Elmt := First_Elmt (Interfaces (Typ));
|
AI_Elmt := First_Elmt (Interfaces (Typ));
|
while Present (AI_Elmt) loop
|
while Present (AI_Elmt) loop
|
AI := Node (AI_Elmt);
|
AI := Node (AI_Elmt);
|
|
|
if AI = Iface
|
if AI = Iface
|
or else Is_Ancestor (Iface, AI, Use_Full_View => True)
|
or else Is_Ancestor (Iface, AI, Use_Full_View => True)
|
then
|
then
|
Found := True;
|
Found := True;
|
return;
|
return;
|
end if;
|
end if;
|
|
|
AI_Tag := Next_Tag_Component (AI_Tag);
|
AI_Tag := Next_Tag_Component (AI_Tag);
|
Next_Elmt (AI_Elmt);
|
Next_Elmt (AI_Elmt);
|
end loop;
|
end loop;
|
end if;
|
end if;
|
end Find_Tag;
|
end Find_Tag;
|
|
|
-- Start of processing for Find_Interface_Tag
|
-- Start of processing for Find_Interface_Tag
|
|
|
begin
|
begin
|
pragma Assert (Is_Interface (Iface));
|
pragma Assert (Is_Interface (Iface));
|
|
|
-- Handle access types
|
-- Handle access types
|
|
|
if Is_Access_Type (Typ) then
|
if Is_Access_Type (Typ) then
|
Typ := Designated_Type (Typ);
|
Typ := Designated_Type (Typ);
|
end if;
|
end if;
|
|
|
-- Handle class-wide types
|
-- Handle class-wide types
|
|
|
if Is_Class_Wide_Type (Typ) then
|
if Is_Class_Wide_Type (Typ) then
|
Typ := Root_Type (Typ);
|
Typ := Root_Type (Typ);
|
end if;
|
end if;
|
|
|
-- Handle private types
|
-- Handle private types
|
|
|
if Has_Private_Declaration (Typ)
|
if Has_Private_Declaration (Typ)
|
and then Present (Full_View (Typ))
|
and then Present (Full_View (Typ))
|
then
|
then
|
Typ := Full_View (Typ);
|
Typ := Full_View (Typ);
|
end if;
|
end if;
|
|
|
-- Handle entities from the limited view
|
-- Handle entities from the limited view
|
|
|
if Ekind (Typ) = E_Incomplete_Type then
|
if Ekind (Typ) = E_Incomplete_Type then
|
pragma Assert (Present (Non_Limited_View (Typ)));
|
pragma Assert (Present (Non_Limited_View (Typ)));
|
Typ := Non_Limited_View (Typ);
|
Typ := Non_Limited_View (Typ);
|
end if;
|
end if;
|
|
|
-- Handle task and protected types implementing interfaces
|
-- Handle task and protected types implementing interfaces
|
|
|
if Is_Concurrent_Type (Typ) then
|
if Is_Concurrent_Type (Typ) then
|
Typ := Corresponding_Record_Type (Typ);
|
Typ := Corresponding_Record_Type (Typ);
|
end if;
|
end if;
|
|
|
-- If the interface is an ancestor of the type, then it shared the
|
-- If the interface is an ancestor of the type, then it shared the
|
-- primary dispatch table.
|
-- primary dispatch table.
|
|
|
if Is_Ancestor (Iface, Typ, Use_Full_View => True) then
|
if Is_Ancestor (Iface, Typ, Use_Full_View => True) then
|
pragma Assert (Etype (First_Tag_Component (Typ)) = RTE (RE_Tag));
|
pragma Assert (Etype (First_Tag_Component (Typ)) = RTE (RE_Tag));
|
return First_Tag_Component (Typ);
|
return First_Tag_Component (Typ);
|
|
|
-- Otherwise we need to search for its associated tag component
|
-- Otherwise we need to search for its associated tag component
|
|
|
else
|
else
|
Find_Tag (Typ);
|
Find_Tag (Typ);
|
pragma Assert (Found);
|
pragma Assert (Found);
|
return AI_Tag;
|
return AI_Tag;
|
end if;
|
end if;
|
end Find_Interface_Tag;
|
end Find_Interface_Tag;
|
|
|
------------------
|
------------------
|
-- Find_Prim_Op --
|
-- Find_Prim_Op --
|
------------------
|
------------------
|
|
|
function Find_Prim_Op (T : Entity_Id; Name : Name_Id) return Entity_Id is
|
function Find_Prim_Op (T : Entity_Id; Name : Name_Id) return Entity_Id is
|
Prim : Elmt_Id;
|
Prim : Elmt_Id;
|
Typ : Entity_Id := T;
|
Typ : Entity_Id := T;
|
Op : Entity_Id;
|
Op : Entity_Id;
|
|
|
begin
|
begin
|
if Is_Class_Wide_Type (Typ) then
|
if Is_Class_Wide_Type (Typ) then
|
Typ := Root_Type (Typ);
|
Typ := Root_Type (Typ);
|
end if;
|
end if;
|
|
|
Typ := Underlying_Type (Typ);
|
Typ := Underlying_Type (Typ);
|
|
|
-- Loop through primitive operations
|
-- Loop through primitive operations
|
|
|
Prim := First_Elmt (Primitive_Operations (Typ));
|
Prim := First_Elmt (Primitive_Operations (Typ));
|
while Present (Prim) loop
|
while Present (Prim) loop
|
Op := Node (Prim);
|
Op := Node (Prim);
|
|
|
-- We can retrieve primitive operations by name if it is an internal
|
-- We can retrieve primitive operations by name if it is an internal
|
-- name. For equality we must check that both of its operands have
|
-- name. For equality we must check that both of its operands have
|
-- the same type, to avoid confusion with user-defined equalities
|
-- the same type, to avoid confusion with user-defined equalities
|
-- than may have a non-symmetric signature.
|
-- than may have a non-symmetric signature.
|
|
|
exit when Chars (Op) = Name
|
exit when Chars (Op) = Name
|
and then
|
and then
|
(Name /= Name_Op_Eq
|
(Name /= Name_Op_Eq
|
or else Etype (First_Formal (Op)) = Etype (Last_Formal (Op)));
|
or else Etype (First_Formal (Op)) = Etype (Last_Formal (Op)));
|
|
|
Next_Elmt (Prim);
|
Next_Elmt (Prim);
|
|
|
-- Raise Program_Error if no primitive found
|
-- Raise Program_Error if no primitive found
|
|
|
if No (Prim) then
|
if No (Prim) then
|
raise Program_Error;
|
raise Program_Error;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
return Node (Prim);
|
return Node (Prim);
|
end Find_Prim_Op;
|
end Find_Prim_Op;
|
|
|
------------------
|
------------------
|
-- Find_Prim_Op --
|
-- Find_Prim_Op --
|
------------------
|
------------------
|
|
|
function Find_Prim_Op
|
function Find_Prim_Op
|
(T : Entity_Id;
|
(T : Entity_Id;
|
Name : TSS_Name_Type) return Entity_Id
|
Name : TSS_Name_Type) return Entity_Id
|
is
|
is
|
Inher_Op : Entity_Id := Empty;
|
Inher_Op : Entity_Id := Empty;
|
Own_Op : Entity_Id := Empty;
|
Own_Op : Entity_Id := Empty;
|
Prim_Elmt : Elmt_Id;
|
Prim_Elmt : Elmt_Id;
|
Prim_Id : Entity_Id;
|
Prim_Id : Entity_Id;
|
Typ : Entity_Id := T;
|
Typ : Entity_Id := T;
|
|
|
begin
|
begin
|
if Is_Class_Wide_Type (Typ) then
|
if Is_Class_Wide_Type (Typ) then
|
Typ := Root_Type (Typ);
|
Typ := Root_Type (Typ);
|
end if;
|
end if;
|
|
|
Typ := Underlying_Type (Typ);
|
Typ := Underlying_Type (Typ);
|
|
|
-- This search is based on the assertion that the dispatching version
|
-- This search is based on the assertion that the dispatching version
|
-- of the TSS routine always precedes the real primitive.
|
-- of the TSS routine always precedes the real primitive.
|
|
|
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
|
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
|
while Present (Prim_Elmt) loop
|
while Present (Prim_Elmt) loop
|
Prim_Id := Node (Prim_Elmt);
|
Prim_Id := Node (Prim_Elmt);
|
|
|
if Is_TSS (Prim_Id, Name) then
|
if Is_TSS (Prim_Id, Name) then
|
if Present (Alias (Prim_Id)) then
|
if Present (Alias (Prim_Id)) then
|
Inher_Op := Prim_Id;
|
Inher_Op := Prim_Id;
|
else
|
else
|
Own_Op := Prim_Id;
|
Own_Op := Prim_Id;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Next_Elmt (Prim_Elmt);
|
Next_Elmt (Prim_Elmt);
|
end loop;
|
end loop;
|
|
|
if Present (Own_Op) then
|
if Present (Own_Op) then
|
return Own_Op;
|
return Own_Op;
|
elsif Present (Inher_Op) then
|
elsif Present (Inher_Op) then
|
return Inher_Op;
|
return Inher_Op;
|
else
|
else
|
raise Program_Error;
|
raise Program_Error;
|
end if;
|
end if;
|
end Find_Prim_Op;
|
end Find_Prim_Op;
|
|
|
----------------------------
|
----------------------------
|
-- Find_Protection_Object --
|
-- Find_Protection_Object --
|
----------------------------
|
----------------------------
|
|
|
function Find_Protection_Object (Scop : Entity_Id) return Entity_Id is
|
function Find_Protection_Object (Scop : Entity_Id) return Entity_Id is
|
S : Entity_Id;
|
S : Entity_Id;
|
|
|
begin
|
begin
|
S := Scop;
|
S := Scop;
|
while Present (S) loop
|
while Present (S) loop
|
if (Ekind (S) = E_Entry
|
if (Ekind (S) = E_Entry
|
or else Ekind (S) = E_Entry_Family
|
or else Ekind (S) = E_Entry_Family
|
or else Ekind (S) = E_Function
|
or else Ekind (S) = E_Function
|
or else Ekind (S) = E_Procedure)
|
or else Ekind (S) = E_Procedure)
|
and then Present (Protection_Object (S))
|
and then Present (Protection_Object (S))
|
then
|
then
|
return Protection_Object (S);
|
return Protection_Object (S);
|
end if;
|
end if;
|
|
|
S := Scope (S);
|
S := Scope (S);
|
end loop;
|
end loop;
|
|
|
-- If we do not find a Protection object in the scope chain, then
|
-- If we do not find a Protection object in the scope chain, then
|
-- something has gone wrong, most likely the object was never created.
|
-- something has gone wrong, most likely the object was never created.
|
|
|
raise Program_Error;
|
raise Program_Error;
|
end Find_Protection_Object;
|
end Find_Protection_Object;
|
|
|
--------------------------
|
--------------------------
|
-- Find_Protection_Type --
|
-- Find_Protection_Type --
|
--------------------------
|
--------------------------
|
|
|
function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id is
|
function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id is
|
Comp : Entity_Id;
|
Comp : Entity_Id;
|
Typ : Entity_Id := Conc_Typ;
|
Typ : Entity_Id := Conc_Typ;
|
|
|
begin
|
begin
|
if Is_Concurrent_Type (Typ) then
|
if Is_Concurrent_Type (Typ) then
|
Typ := Corresponding_Record_Type (Typ);
|
Typ := Corresponding_Record_Type (Typ);
|
end if;
|
end if;
|
|
|
-- Since restriction violations are not considered serious errors, the
|
-- Since restriction violations are not considered serious errors, the
|
-- expander remains active, but may leave the corresponding record type
|
-- expander remains active, but may leave the corresponding record type
|
-- malformed. In such cases, component _object is not available so do
|
-- malformed. In such cases, component _object is not available so do
|
-- not look for it.
|
-- not look for it.
|
|
|
if not Analyzed (Typ) then
|
if not Analyzed (Typ) then
|
return Empty;
|
return Empty;
|
end if;
|
end if;
|
|
|
Comp := First_Component (Typ);
|
Comp := First_Component (Typ);
|
while Present (Comp) loop
|
while Present (Comp) loop
|
if Chars (Comp) = Name_uObject then
|
if Chars (Comp) = Name_uObject then
|
return Base_Type (Etype (Comp));
|
return Base_Type (Etype (Comp));
|
end if;
|
end if;
|
|
|
Next_Component (Comp);
|
Next_Component (Comp);
|
end loop;
|
end loop;
|
|
|
-- The corresponding record of a protected type should always have an
|
-- The corresponding record of a protected type should always have an
|
-- _object field.
|
-- _object field.
|
|
|
raise Program_Error;
|
raise Program_Error;
|
end Find_Protection_Type;
|
end Find_Protection_Type;
|
|
|
----------------------
|
----------------------
|
-- Force_Evaluation --
|
-- Force_Evaluation --
|
----------------------
|
----------------------
|
|
|
procedure Force_Evaluation (Exp : Node_Id; Name_Req : Boolean := False) is
|
procedure Force_Evaluation (Exp : Node_Id; Name_Req : Boolean := False) is
|
begin
|
begin
|
Remove_Side_Effects (Exp, Name_Req, Variable_Ref => True);
|
Remove_Side_Effects (Exp, Name_Req, Variable_Ref => True);
|
end Force_Evaluation;
|
end Force_Evaluation;
|
|
|
---------------------------------
|
---------------------------------
|
-- Fully_Qualified_Name_String --
|
-- Fully_Qualified_Name_String --
|
---------------------------------
|
---------------------------------
|
|
|
function Fully_Qualified_Name_String (E : Entity_Id) return String_Id is
|
function Fully_Qualified_Name_String (E : Entity_Id) return String_Id is
|
procedure Internal_Full_Qualified_Name (E : Entity_Id);
|
procedure Internal_Full_Qualified_Name (E : Entity_Id);
|
-- Compute recursively the qualified name without NUL at the end, adding
|
-- Compute recursively the qualified name without NUL at the end, adding
|
-- it to the currently started string being generated
|
-- it to the currently started string being generated
|
|
|
----------------------------------
|
----------------------------------
|
-- Internal_Full_Qualified_Name --
|
-- Internal_Full_Qualified_Name --
|
----------------------------------
|
----------------------------------
|
|
|
procedure Internal_Full_Qualified_Name (E : Entity_Id) is
|
procedure Internal_Full_Qualified_Name (E : Entity_Id) is
|
Ent : Entity_Id;
|
Ent : Entity_Id;
|
|
|
begin
|
begin
|
-- Deal properly with child units
|
-- Deal properly with child units
|
|
|
if Nkind (E) = N_Defining_Program_Unit_Name then
|
if Nkind (E) = N_Defining_Program_Unit_Name then
|
Ent := Defining_Identifier (E);
|
Ent := Defining_Identifier (E);
|
else
|
else
|
Ent := E;
|
Ent := E;
|
end if;
|
end if;
|
|
|
-- Compute qualification recursively (only "Standard" has no scope)
|
-- Compute qualification recursively (only "Standard" has no scope)
|
|
|
if Present (Scope (Scope (Ent))) then
|
if Present (Scope (Scope (Ent))) then
|
Internal_Full_Qualified_Name (Scope (Ent));
|
Internal_Full_Qualified_Name (Scope (Ent));
|
Store_String_Char (Get_Char_Code ('.'));
|
Store_String_Char (Get_Char_Code ('.'));
|
end if;
|
end if;
|
|
|
-- Every entity should have a name except some expanded blocks
|
-- Every entity should have a name except some expanded blocks
|
-- don't bother about those.
|
-- don't bother about those.
|
|
|
if Chars (Ent) = No_Name then
|
if Chars (Ent) = No_Name then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Generates the entity name in upper case
|
-- Generates the entity name in upper case
|
|
|
Get_Decoded_Name_String (Chars (Ent));
|
Get_Decoded_Name_String (Chars (Ent));
|
Set_All_Upper_Case;
|
Set_All_Upper_Case;
|
Store_String_Chars (Name_Buffer (1 .. Name_Len));
|
Store_String_Chars (Name_Buffer (1 .. Name_Len));
|
return;
|
return;
|
end Internal_Full_Qualified_Name;
|
end Internal_Full_Qualified_Name;
|
|
|
-- Start of processing for Full_Qualified_Name
|
-- Start of processing for Full_Qualified_Name
|
|
|
begin
|
begin
|
Start_String;
|
Start_String;
|
Internal_Full_Qualified_Name (E);
|
Internal_Full_Qualified_Name (E);
|
Store_String_Char (Get_Char_Code (ASCII.NUL));
|
Store_String_Char (Get_Char_Code (ASCII.NUL));
|
return End_String;
|
return End_String;
|
end Fully_Qualified_Name_String;
|
end Fully_Qualified_Name_String;
|
|
|
------------------------
|
------------------------
|
-- Generate_Poll_Call --
|
-- Generate_Poll_Call --
|
------------------------
|
------------------------
|
|
|
procedure Generate_Poll_Call (N : Node_Id) is
|
procedure Generate_Poll_Call (N : Node_Id) is
|
begin
|
begin
|
-- No poll call if polling not active
|
-- No poll call if polling not active
|
|
|
if not Polling_Required then
|
if not Polling_Required then
|
return;
|
return;
|
|
|
-- Otherwise generate require poll call
|
-- Otherwise generate require poll call
|
|
|
else
|
else
|
Insert_Before_And_Analyze (N,
|
Insert_Before_And_Analyze (N,
|
Make_Procedure_Call_Statement (Sloc (N),
|
Make_Procedure_Call_Statement (Sloc (N),
|
Name => New_Occurrence_Of (RTE (RE_Poll), Sloc (N))));
|
Name => New_Occurrence_Of (RTE (RE_Poll), Sloc (N))));
|
end if;
|
end if;
|
end Generate_Poll_Call;
|
end Generate_Poll_Call;
|
|
|
---------------------------------
|
---------------------------------
|
-- Get_Current_Value_Condition --
|
-- Get_Current_Value_Condition --
|
---------------------------------
|
---------------------------------
|
|
|
-- Note: the implementation of this procedure is very closely tied to the
|
-- Note: the implementation of this procedure is very closely tied to the
|
-- implementation of Set_Current_Value_Condition. In the Get procedure, we
|
-- implementation of Set_Current_Value_Condition. In the Get procedure, we
|
-- interpret Current_Value fields set by the Set procedure, so the two
|
-- interpret Current_Value fields set by the Set procedure, so the two
|
-- procedures need to be closely coordinated.
|
-- procedures need to be closely coordinated.
|
|
|
procedure Get_Current_Value_Condition
|
procedure Get_Current_Value_Condition
|
(Var : Node_Id;
|
(Var : Node_Id;
|
Op : out Node_Kind;
|
Op : out Node_Kind;
|
Val : out Node_Id)
|
Val : out Node_Id)
|
is
|
is
|
Loc : constant Source_Ptr := Sloc (Var);
|
Loc : constant Source_Ptr := Sloc (Var);
|
Ent : constant Entity_Id := Entity (Var);
|
Ent : constant Entity_Id := Entity (Var);
|
|
|
procedure Process_Current_Value_Condition
|
procedure Process_Current_Value_Condition
|
(N : Node_Id;
|
(N : Node_Id;
|
S : Boolean);
|
S : Boolean);
|
-- N is an expression which holds either True (S = True) or False (S =
|
-- N is an expression which holds either True (S = True) or False (S =
|
-- False) in the condition. This procedure digs out the expression and
|
-- False) in the condition. This procedure digs out the expression and
|
-- if it refers to Ent, sets Op and Val appropriately.
|
-- if it refers to Ent, sets Op and Val appropriately.
|
|
|
-------------------------------------
|
-------------------------------------
|
-- Process_Current_Value_Condition --
|
-- Process_Current_Value_Condition --
|
-------------------------------------
|
-------------------------------------
|
|
|
procedure Process_Current_Value_Condition
|
procedure Process_Current_Value_Condition
|
(N : Node_Id;
|
(N : Node_Id;
|
S : Boolean)
|
S : Boolean)
|
is
|
is
|
Cond : Node_Id;
|
Cond : Node_Id;
|
Sens : Boolean;
|
Sens : Boolean;
|
|
|
begin
|
begin
|
Cond := N;
|
Cond := N;
|
Sens := S;
|
Sens := S;
|
|
|
-- Deal with NOT operators, inverting sense
|
-- Deal with NOT operators, inverting sense
|
|
|
while Nkind (Cond) = N_Op_Not loop
|
while Nkind (Cond) = N_Op_Not loop
|
Cond := Right_Opnd (Cond);
|
Cond := Right_Opnd (Cond);
|
Sens := not Sens;
|
Sens := not Sens;
|
end loop;
|
end loop;
|
|
|
-- Deal with AND THEN and AND cases
|
-- Deal with AND THEN and AND cases
|
|
|
if Nkind (Cond) = N_And_Then
|
if Nkind (Cond) = N_And_Then
|
or else Nkind (Cond) = N_Op_And
|
or else Nkind (Cond) = N_Op_And
|
then
|
then
|
-- Don't ever try to invert a condition that is of the form of an
|
-- Don't ever try to invert a condition that is of the form of an
|
-- AND or AND THEN (since we are not doing sufficiently general
|
-- AND or AND THEN (since we are not doing sufficiently general
|
-- processing to allow this).
|
-- processing to allow this).
|
|
|
if Sens = False then
|
if Sens = False then
|
Op := N_Empty;
|
Op := N_Empty;
|
Val := Empty;
|
Val := Empty;
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Recursively process AND and AND THEN branches
|
-- Recursively process AND and AND THEN branches
|
|
|
Process_Current_Value_Condition (Left_Opnd (Cond), True);
|
Process_Current_Value_Condition (Left_Opnd (Cond), True);
|
|
|
if Op /= N_Empty then
|
if Op /= N_Empty then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
Process_Current_Value_Condition (Right_Opnd (Cond), True);
|
Process_Current_Value_Condition (Right_Opnd (Cond), True);
|
return;
|
return;
|
|
|
-- Case of relational operator
|
-- Case of relational operator
|
|
|
elsif Nkind (Cond) in N_Op_Compare then
|
elsif Nkind (Cond) in N_Op_Compare then
|
Op := Nkind (Cond);
|
Op := Nkind (Cond);
|
|
|
-- Invert sense of test if inverted test
|
-- Invert sense of test if inverted test
|
|
|
if Sens = False then
|
if Sens = False then
|
case Op is
|
case Op is
|
when N_Op_Eq => Op := N_Op_Ne;
|
when N_Op_Eq => Op := N_Op_Ne;
|
when N_Op_Ne => Op := N_Op_Eq;
|
when N_Op_Ne => Op := N_Op_Eq;
|
when N_Op_Lt => Op := N_Op_Ge;
|
when N_Op_Lt => Op := N_Op_Ge;
|
when N_Op_Gt => Op := N_Op_Le;
|
when N_Op_Gt => Op := N_Op_Le;
|
when N_Op_Le => Op := N_Op_Gt;
|
when N_Op_Le => Op := N_Op_Gt;
|
when N_Op_Ge => Op := N_Op_Lt;
|
when N_Op_Ge => Op := N_Op_Lt;
|
when others => raise Program_Error;
|
when others => raise Program_Error;
|
end case;
|
end case;
|
end if;
|
end if;
|
|
|
-- Case of entity op value
|
-- Case of entity op value
|
|
|
if Is_Entity_Name (Left_Opnd (Cond))
|
if Is_Entity_Name (Left_Opnd (Cond))
|
and then Ent = Entity (Left_Opnd (Cond))
|
and then Ent = Entity (Left_Opnd (Cond))
|
and then Compile_Time_Known_Value (Right_Opnd (Cond))
|
and then Compile_Time_Known_Value (Right_Opnd (Cond))
|
then
|
then
|
Val := Right_Opnd (Cond);
|
Val := Right_Opnd (Cond);
|
|
|
-- Case of value op entity
|
-- Case of value op entity
|
|
|
elsif Is_Entity_Name (Right_Opnd (Cond))
|
elsif Is_Entity_Name (Right_Opnd (Cond))
|
and then Ent = Entity (Right_Opnd (Cond))
|
and then Ent = Entity (Right_Opnd (Cond))
|
and then Compile_Time_Known_Value (Left_Opnd (Cond))
|
and then Compile_Time_Known_Value (Left_Opnd (Cond))
|
then
|
then
|
Val := Left_Opnd (Cond);
|
Val := Left_Opnd (Cond);
|
|
|
-- We are effectively swapping operands
|
-- We are effectively swapping operands
|
|
|
case Op is
|
case Op is
|
when N_Op_Eq => null;
|
when N_Op_Eq => null;
|
when N_Op_Ne => null;
|
when N_Op_Ne => null;
|
when N_Op_Lt => Op := N_Op_Gt;
|
when N_Op_Lt => Op := N_Op_Gt;
|
when N_Op_Gt => Op := N_Op_Lt;
|
when N_Op_Gt => Op := N_Op_Lt;
|
when N_Op_Le => Op := N_Op_Ge;
|
when N_Op_Le => Op := N_Op_Ge;
|
when N_Op_Ge => Op := N_Op_Le;
|
when N_Op_Ge => Op := N_Op_Le;
|
when others => raise Program_Error;
|
when others => raise Program_Error;
|
end case;
|
end case;
|
|
|
else
|
else
|
Op := N_Empty;
|
Op := N_Empty;
|
end if;
|
end if;
|
|
|
return;
|
return;
|
|
|
-- Case of Boolean variable reference, return as though the
|
-- Case of Boolean variable reference, return as though the
|
-- reference had said var = True.
|
-- reference had said var = True.
|
|
|
else
|
else
|
if Is_Entity_Name (Cond)
|
if Is_Entity_Name (Cond)
|
and then Ent = Entity (Cond)
|
and then Ent = Entity (Cond)
|
then
|
then
|
Val := New_Occurrence_Of (Standard_True, Sloc (Cond));
|
Val := New_Occurrence_Of (Standard_True, Sloc (Cond));
|
|
|
if Sens = False then
|
if Sens = False then
|
Op := N_Op_Ne;
|
Op := N_Op_Ne;
|
else
|
else
|
Op := N_Op_Eq;
|
Op := N_Op_Eq;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end Process_Current_Value_Condition;
|
end Process_Current_Value_Condition;
|
|
|
-- Start of processing for Get_Current_Value_Condition
|
-- Start of processing for Get_Current_Value_Condition
|
|
|
begin
|
begin
|
Op := N_Empty;
|
Op := N_Empty;
|
Val := Empty;
|
Val := Empty;
|
|
|
-- Immediate return, nothing doing, if this is not an object
|
-- Immediate return, nothing doing, if this is not an object
|
|
|
if Ekind (Ent) not in Object_Kind then
|
if Ekind (Ent) not in Object_Kind then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Otherwise examine current value
|
-- Otherwise examine current value
|
|
|
declare
|
declare
|
CV : constant Node_Id := Current_Value (Ent);
|
CV : constant Node_Id := Current_Value (Ent);
|
Sens : Boolean;
|
Sens : Boolean;
|
Stm : Node_Id;
|
Stm : Node_Id;
|
|
|
begin
|
begin
|
-- If statement. Condition is known true in THEN section, known False
|
-- If statement. Condition is known true in THEN section, known False
|
-- in any ELSIF or ELSE part, and unknown outside the IF statement.
|
-- in any ELSIF or ELSE part, and unknown outside the IF statement.
|
|
|
if Nkind (CV) = N_If_Statement then
|
if Nkind (CV) = N_If_Statement then
|
|
|
-- Before start of IF statement
|
-- Before start of IF statement
|
|
|
if Loc < Sloc (CV) then
|
if Loc < Sloc (CV) then
|
return;
|
return;
|
|
|
-- After end of IF statement
|
-- After end of IF statement
|
|
|
elsif Loc >= Sloc (CV) + Text_Ptr (UI_To_Int (End_Span (CV))) then
|
elsif Loc >= Sloc (CV) + Text_Ptr (UI_To_Int (End_Span (CV))) then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- At this stage we know that we are within the IF statement, but
|
-- At this stage we know that we are within the IF statement, but
|
-- unfortunately, the tree does not record the SLOC of the ELSE so
|
-- unfortunately, the tree does not record the SLOC of the ELSE so
|
-- we cannot use a simple SLOC comparison to distinguish between
|
-- we cannot use a simple SLOC comparison to distinguish between
|
-- the then/else statements, so we have to climb the tree.
|
-- the then/else statements, so we have to climb the tree.
|
|
|
declare
|
declare
|
N : Node_Id;
|
N : Node_Id;
|
|
|
begin
|
begin
|
N := Parent (Var);
|
N := Parent (Var);
|
while Parent (N) /= CV loop
|
while Parent (N) /= CV loop
|
N := Parent (N);
|
N := Parent (N);
|
|
|
-- If we fall off the top of the tree, then that's odd, but
|
-- If we fall off the top of the tree, then that's odd, but
|
-- perhaps it could occur in some error situation, and the
|
-- perhaps it could occur in some error situation, and the
|
-- safest response is simply to assume that the outcome of
|
-- safest response is simply to assume that the outcome of
|
-- the condition is unknown. No point in bombing during an
|
-- the condition is unknown. No point in bombing during an
|
-- attempt to optimize things.
|
-- attempt to optimize things.
|
|
|
if No (N) then
|
if No (N) then
|
return;
|
return;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
-- Now we have N pointing to a node whose parent is the IF
|
-- Now we have N pointing to a node whose parent is the IF
|
-- statement in question, so now we can tell if we are within
|
-- statement in question, so now we can tell if we are within
|
-- the THEN statements.
|
-- the THEN statements.
|
|
|
if Is_List_Member (N)
|
if Is_List_Member (N)
|
and then List_Containing (N) = Then_Statements (CV)
|
and then List_Containing (N) = Then_Statements (CV)
|
then
|
then
|
Sens := True;
|
Sens := True;
|
|
|
-- If the variable reference does not come from source, we
|
-- If the variable reference does not come from source, we
|
-- cannot reliably tell whether it appears in the else part.
|
-- cannot reliably tell whether it appears in the else part.
|
-- In particular, if it appears in generated code for a node
|
-- In particular, if it appears in generated code for a node
|
-- that requires finalization, it may be attached to a list
|
-- that requires finalization, it may be attached to a list
|
-- that has not been yet inserted into the code. For now,
|
-- that has not been yet inserted into the code. For now,
|
-- treat it as unknown.
|
-- treat it as unknown.
|
|
|
elsif not Comes_From_Source (N) then
|
elsif not Comes_From_Source (N) then
|
return;
|
return;
|
|
|
-- Otherwise we must be in ELSIF or ELSE part
|
-- Otherwise we must be in ELSIF or ELSE part
|
|
|
else
|
else
|
Sens := False;
|
Sens := False;
|
end if;
|
end if;
|
end;
|
end;
|
|
|
-- ELSIF part. Condition is known true within the referenced
|
-- ELSIF part. Condition is known true within the referenced
|
-- ELSIF, known False in any subsequent ELSIF or ELSE part,
|
-- ELSIF, known False in any subsequent ELSIF or ELSE part,
|
-- and unknown before the ELSE part or after the IF statement.
|
-- and unknown before the ELSE part or after the IF statement.
|
|
|
elsif Nkind (CV) = N_Elsif_Part then
|
elsif Nkind (CV) = N_Elsif_Part then
|
|
|
-- if the Elsif_Part had condition_actions, the elsif has been
|
-- if the Elsif_Part had condition_actions, the elsif has been
|
-- rewritten as a nested if, and the original elsif_part is
|
-- rewritten as a nested if, and the original elsif_part is
|
-- detached from the tree, so there is no way to obtain useful
|
-- detached from the tree, so there is no way to obtain useful
|
-- information on the current value of the variable.
|
-- information on the current value of the variable.
|
-- Can this be improved ???
|
-- Can this be improved ???
|
|
|
if No (Parent (CV)) then
|
if No (Parent (CV)) then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
Stm := Parent (CV);
|
Stm := Parent (CV);
|
|
|
-- Before start of ELSIF part
|
-- Before start of ELSIF part
|
|
|
if Loc < Sloc (CV) then
|
if Loc < Sloc (CV) then
|
return;
|
return;
|
|
|
-- After end of IF statement
|
-- After end of IF statement
|
|
|
elsif Loc >= Sloc (Stm) +
|
elsif Loc >= Sloc (Stm) +
|
Text_Ptr (UI_To_Int (End_Span (Stm)))
|
Text_Ptr (UI_To_Int (End_Span (Stm)))
|
then
|
then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Again we lack the SLOC of the ELSE, so we need to climb the
|
-- Again we lack the SLOC of the ELSE, so we need to climb the
|
-- tree to see if we are within the ELSIF part in question.
|
-- tree to see if we are within the ELSIF part in question.
|
|
|
declare
|
declare
|
N : Node_Id;
|
N : Node_Id;
|
|
|
begin
|
begin
|
N := Parent (Var);
|
N := Parent (Var);
|
while Parent (N) /= Stm loop
|
while Parent (N) /= Stm loop
|
N := Parent (N);
|
N := Parent (N);
|
|
|
-- If we fall off the top of the tree, then that's odd, but
|
-- If we fall off the top of the tree, then that's odd, but
|
-- perhaps it could occur in some error situation, and the
|
-- perhaps it could occur in some error situation, and the
|
-- safest response is simply to assume that the outcome of
|
-- safest response is simply to assume that the outcome of
|
-- the condition is unknown. No point in bombing during an
|
-- the condition is unknown. No point in bombing during an
|
-- attempt to optimize things.
|
-- attempt to optimize things.
|
|
|
if No (N) then
|
if No (N) then
|
return;
|
return;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
-- Now we have N pointing to a node whose parent is the IF
|
-- Now we have N pointing to a node whose parent is the IF
|
-- statement in question, so see if is the ELSIF part we want.
|
-- statement in question, so see if is the ELSIF part we want.
|
-- the THEN statements.
|
-- the THEN statements.
|
|
|
if N = CV then
|
if N = CV then
|
Sens := True;
|
Sens := True;
|
|
|
-- Otherwise we must be in subsequent ELSIF or ELSE part
|
-- Otherwise we must be in subsequent ELSIF or ELSE part
|
|
|
else
|
else
|
Sens := False;
|
Sens := False;
|
end if;
|
end if;
|
end;
|
end;
|
|
|
-- Iteration scheme of while loop. The condition is known to be
|
-- Iteration scheme of while loop. The condition is known to be
|
-- true within the body of the loop.
|
-- true within the body of the loop.
|
|
|
elsif Nkind (CV) = N_Iteration_Scheme then
|
elsif Nkind (CV) = N_Iteration_Scheme then
|
declare
|
declare
|
Loop_Stmt : constant Node_Id := Parent (CV);
|
Loop_Stmt : constant Node_Id := Parent (CV);
|
|
|
begin
|
begin
|
-- Before start of body of loop
|
-- Before start of body of loop
|
|
|
if Loc < Sloc (Loop_Stmt) then
|
if Loc < Sloc (Loop_Stmt) then
|
return;
|
return;
|
|
|
-- After end of LOOP statement
|
-- After end of LOOP statement
|
|
|
elsif Loc >= Sloc (End_Label (Loop_Stmt)) then
|
elsif Loc >= Sloc (End_Label (Loop_Stmt)) then
|
return;
|
return;
|
|
|
-- We are within the body of the loop
|
-- We are within the body of the loop
|
|
|
else
|
else
|
Sens := True;
|
Sens := True;
|
end if;
|
end if;
|
end;
|
end;
|
|
|
-- All other cases of Current_Value settings
|
-- All other cases of Current_Value settings
|
|
|
else
|
else
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- If we fall through here, then we have a reportable condition, Sens
|
-- If we fall through here, then we have a reportable condition, Sens
|
-- is True if the condition is true and False if it needs inverting.
|
-- is True if the condition is true and False if it needs inverting.
|
|
|
Process_Current_Value_Condition (Condition (CV), Sens);
|
Process_Current_Value_Condition (Condition (CV), Sens);
|
end;
|
end;
|
end Get_Current_Value_Condition;
|
end Get_Current_Value_Condition;
|
|
|
---------------------
|
---------------------
|
-- Get_Stream_Size --
|
-- Get_Stream_Size --
|
---------------------
|
---------------------
|
|
|
function Get_Stream_Size (E : Entity_Id) return Uint is
|
function Get_Stream_Size (E : Entity_Id) return Uint is
|
begin
|
begin
|
-- If we have a Stream_Size clause for this type use it
|
-- If we have a Stream_Size clause for this type use it
|
|
|
if Has_Stream_Size_Clause (E) then
|
if Has_Stream_Size_Clause (E) then
|
return Static_Integer (Expression (Stream_Size_Clause (E)));
|
return Static_Integer (Expression (Stream_Size_Clause (E)));
|
|
|
-- Otherwise the Stream_Size if the size of the type
|
-- Otherwise the Stream_Size if the size of the type
|
|
|
else
|
else
|
return Esize (E);
|
return Esize (E);
|
end if;
|
end if;
|
end Get_Stream_Size;
|
end Get_Stream_Size;
|
|
|
---------------------------
|
---------------------------
|
-- Has_Access_Constraint --
|
-- Has_Access_Constraint --
|
---------------------------
|
---------------------------
|
|
|
function Has_Access_Constraint (E : Entity_Id) return Boolean is
|
function Has_Access_Constraint (E : Entity_Id) return Boolean is
|
Disc : Entity_Id;
|
Disc : Entity_Id;
|
T : constant Entity_Id := Etype (E);
|
T : constant Entity_Id := Etype (E);
|
|
|
begin
|
begin
|
if Has_Per_Object_Constraint (E)
|
if Has_Per_Object_Constraint (E)
|
and then Has_Discriminants (T)
|
and then Has_Discriminants (T)
|
then
|
then
|
Disc := First_Discriminant (T);
|
Disc := First_Discriminant (T);
|
while Present (Disc) loop
|
while Present (Disc) loop
|
if Is_Access_Type (Etype (Disc)) then
|
if Is_Access_Type (Etype (Disc)) then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
Next_Discriminant (Disc);
|
Next_Discriminant (Disc);
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Has_Access_Constraint;
|
end Has_Access_Constraint;
|
|
|
----------------------------------
|
----------------------------------
|
-- Has_Following_Address_Clause --
|
-- Has_Following_Address_Clause --
|
----------------------------------
|
----------------------------------
|
|
|
-- Should this function check the private part in a package ???
|
-- Should this function check the private part in a package ???
|
|
|
function Has_Following_Address_Clause (D : Node_Id) return Boolean is
|
function Has_Following_Address_Clause (D : Node_Id) return Boolean is
|
Id : constant Entity_Id := Defining_Identifier (D);
|
Id : constant Entity_Id := Defining_Identifier (D);
|
Decl : Node_Id;
|
Decl : Node_Id;
|
|
|
begin
|
begin
|
Decl := Next (D);
|
Decl := Next (D);
|
while Present (Decl) loop
|
while Present (Decl) loop
|
if Nkind (Decl) = N_At_Clause
|
if Nkind (Decl) = N_At_Clause
|
and then Chars (Identifier (Decl)) = Chars (Id)
|
and then Chars (Identifier (Decl)) = Chars (Id)
|
then
|
then
|
return True;
|
return True;
|
|
|
elsif Nkind (Decl) = N_Attribute_Definition_Clause
|
elsif Nkind (Decl) = N_Attribute_Definition_Clause
|
and then Chars (Decl) = Name_Address
|
and then Chars (Decl) = Name_Address
|
and then Chars (Name (Decl)) = Chars (Id)
|
and then Chars (Name (Decl)) = Chars (Id)
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
Next (Decl);
|
Next (Decl);
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
end Has_Following_Address_Clause;
|
end Has_Following_Address_Clause;
|
|
|
--------------------
|
--------------------
|
-- Homonym_Number --
|
-- Homonym_Number --
|
--------------------
|
--------------------
|
|
|
function Homonym_Number (Subp : Entity_Id) return Nat is
|
function Homonym_Number (Subp : Entity_Id) return Nat is
|
Count : Nat;
|
Count : Nat;
|
Hom : Entity_Id;
|
Hom : Entity_Id;
|
|
|
begin
|
begin
|
Count := 1;
|
Count := 1;
|
Hom := Homonym (Subp);
|
Hom := Homonym (Subp);
|
while Present (Hom) loop
|
while Present (Hom) loop
|
if Scope (Hom) = Scope (Subp) then
|
if Scope (Hom) = Scope (Subp) then
|
Count := Count + 1;
|
Count := Count + 1;
|
end if;
|
end if;
|
|
|
Hom := Homonym (Hom);
|
Hom := Homonym (Hom);
|
end loop;
|
end loop;
|
|
|
return Count;
|
return Count;
|
end Homonym_Number;
|
end Homonym_Number;
|
|
|
-----------------------------------
|
-----------------------------------
|
-- In_Library_Level_Package_Body --
|
-- In_Library_Level_Package_Body --
|
-----------------------------------
|
-----------------------------------
|
|
|
function In_Library_Level_Package_Body (Id : Entity_Id) return Boolean is
|
function In_Library_Level_Package_Body (Id : Entity_Id) return Boolean is
|
begin
|
begin
|
-- First determine whether the entity appears at the library level, then
|
-- First determine whether the entity appears at the library level, then
|
-- look at the containing unit.
|
-- look at the containing unit.
|
|
|
if Is_Library_Level_Entity (Id) then
|
if Is_Library_Level_Entity (Id) then
|
declare
|
declare
|
Container : constant Node_Id := Cunit (Get_Source_Unit (Id));
|
Container : constant Node_Id := Cunit (Get_Source_Unit (Id));
|
|
|
begin
|
begin
|
return Nkind (Unit (Container)) = N_Package_Body;
|
return Nkind (Unit (Container)) = N_Package_Body;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
return False;
|
return False;
|
end In_Library_Level_Package_Body;
|
end In_Library_Level_Package_Body;
|
|
|
------------------------------
|
------------------------------
|
-- In_Unconditional_Context --
|
-- In_Unconditional_Context --
|
------------------------------
|
------------------------------
|
|
|
function In_Unconditional_Context (Node : Node_Id) return Boolean is
|
function In_Unconditional_Context (Node : Node_Id) return Boolean is
|
P : Node_Id;
|
P : Node_Id;
|
|
|
begin
|
begin
|
P := Node;
|
P := Node;
|
while Present (P) loop
|
while Present (P) loop
|
case Nkind (P) is
|
case Nkind (P) is
|
when N_Subprogram_Body =>
|
when N_Subprogram_Body =>
|
return True;
|
return True;
|
|
|
when N_If_Statement =>
|
when N_If_Statement =>
|
return False;
|
return False;
|
|
|
when N_Loop_Statement =>
|
when N_Loop_Statement =>
|
return False;
|
return False;
|
|
|
when N_Case_Statement =>
|
when N_Case_Statement =>
|
return False;
|
return False;
|
|
|
when others =>
|
when others =>
|
P := Parent (P);
|
P := Parent (P);
|
end case;
|
end case;
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
end In_Unconditional_Context;
|
end In_Unconditional_Context;
|
|
|
-------------------
|
-------------------
|
-- Insert_Action --
|
-- Insert_Action --
|
-------------------
|
-------------------
|
|
|
procedure Insert_Action (Assoc_Node : Node_Id; Ins_Action : Node_Id) is
|
procedure Insert_Action (Assoc_Node : Node_Id; Ins_Action : Node_Id) is
|
begin
|
begin
|
if Present (Ins_Action) then
|
if Present (Ins_Action) then
|
Insert_Actions (Assoc_Node, New_List (Ins_Action));
|
Insert_Actions (Assoc_Node, New_List (Ins_Action));
|
end if;
|
end if;
|
end Insert_Action;
|
end Insert_Action;
|
|
|
-- Version with check(s) suppressed
|
-- Version with check(s) suppressed
|
|
|
procedure Insert_Action
|
procedure Insert_Action
|
(Assoc_Node : Node_Id; Ins_Action : Node_Id; Suppress : Check_Id)
|
(Assoc_Node : Node_Id; Ins_Action : Node_Id; Suppress : Check_Id)
|
is
|
is
|
begin
|
begin
|
Insert_Actions (Assoc_Node, New_List (Ins_Action), Suppress);
|
Insert_Actions (Assoc_Node, New_List (Ins_Action), Suppress);
|
end Insert_Action;
|
end Insert_Action;
|
|
|
-------------------------
|
-------------------------
|
-- Insert_Action_After --
|
-- Insert_Action_After --
|
-------------------------
|
-------------------------
|
|
|
procedure Insert_Action_After
|
procedure Insert_Action_After
|
(Assoc_Node : Node_Id;
|
(Assoc_Node : Node_Id;
|
Ins_Action : Node_Id)
|
Ins_Action : Node_Id)
|
is
|
is
|
begin
|
begin
|
Insert_Actions_After (Assoc_Node, New_List (Ins_Action));
|
Insert_Actions_After (Assoc_Node, New_List (Ins_Action));
|
end Insert_Action_After;
|
end Insert_Action_After;
|
|
|
--------------------
|
--------------------
|
-- Insert_Actions --
|
-- Insert_Actions --
|
--------------------
|
--------------------
|
|
|
procedure Insert_Actions (Assoc_Node : Node_Id; Ins_Actions : List_Id) is
|
procedure Insert_Actions (Assoc_Node : Node_Id; Ins_Actions : List_Id) is
|
N : Node_Id;
|
N : Node_Id;
|
P : Node_Id;
|
P : Node_Id;
|
|
|
Wrapped_Node : Node_Id := Empty;
|
Wrapped_Node : Node_Id := Empty;
|
|
|
begin
|
begin
|
if No (Ins_Actions) or else Is_Empty_List (Ins_Actions) then
|
if No (Ins_Actions) or else Is_Empty_List (Ins_Actions) then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Ignore insert of actions from inside default expression (or other
|
-- Ignore insert of actions from inside default expression (or other
|
-- similar "spec expression") in the special spec-expression analyze
|
-- similar "spec expression") in the special spec-expression analyze
|
-- mode. Any insertions at this point have no relevance, since we are
|
-- mode. Any insertions at this point have no relevance, since we are
|
-- only doing the analyze to freeze the types of any static expressions.
|
-- only doing the analyze to freeze the types of any static expressions.
|
-- See section "Handling of Default Expressions" in the spec of package
|
-- See section "Handling of Default Expressions" in the spec of package
|
-- Sem for further details.
|
-- Sem for further details.
|
|
|
if In_Spec_Expression then
|
if In_Spec_Expression then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- If the action derives from stuff inside a record, then the actions
|
-- If the action derives from stuff inside a record, then the actions
|
-- are attached to the current scope, to be inserted and analyzed on
|
-- are attached to the current scope, to be inserted and analyzed on
|
-- exit from the scope. The reason for this is that we may also be
|
-- exit from the scope. The reason for this is that we may also be
|
-- generating freeze actions at the same time, and they must eventually
|
-- generating freeze actions at the same time, and they must eventually
|
-- be elaborated in the correct order.
|
-- be elaborated in the correct order.
|
|
|
if Is_Record_Type (Current_Scope)
|
if Is_Record_Type (Current_Scope)
|
and then not Is_Frozen (Current_Scope)
|
and then not Is_Frozen (Current_Scope)
|
then
|
then
|
if No (Scope_Stack.Table
|
if No (Scope_Stack.Table
|
(Scope_Stack.Last).Pending_Freeze_Actions)
|
(Scope_Stack.Last).Pending_Freeze_Actions)
|
then
|
then
|
Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions :=
|
Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions :=
|
Ins_Actions;
|
Ins_Actions;
|
else
|
else
|
Append_List
|
Append_List
|
(Ins_Actions,
|
(Ins_Actions,
|
Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions);
|
Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions);
|
end if;
|
end if;
|
|
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- We now intend to climb up the tree to find the right point to
|
-- We now intend to climb up the tree to find the right point to
|
-- insert the actions. We start at Assoc_Node, unless this node is a
|
-- insert the actions. We start at Assoc_Node, unless this node is a
|
-- subexpression in which case we start with its parent. We do this for
|
-- subexpression in which case we start with its parent. We do this for
|
-- two reasons. First it speeds things up. Second, if Assoc_Node is
|
-- two reasons. First it speeds things up. Second, if Assoc_Node is
|
-- itself one of the special nodes like N_And_Then, then we assume that
|
-- itself one of the special nodes like N_And_Then, then we assume that
|
-- an initial request to insert actions for such a node does not expect
|
-- an initial request to insert actions for such a node does not expect
|
-- the actions to get deposited in the node for later handling when the
|
-- the actions to get deposited in the node for later handling when the
|
-- node is expanded, since clearly the node is being dealt with by the
|
-- node is expanded, since clearly the node is being dealt with by the
|
-- caller. Note that in the subexpression case, N is always the child we
|
-- caller. Note that in the subexpression case, N is always the child we
|
-- came from.
|
-- came from.
|
|
|
-- N_Raise_xxx_Error is an annoying special case, it is a statement if
|
-- N_Raise_xxx_Error is an annoying special case, it is a statement if
|
-- it has type Standard_Void_Type, and a subexpression otherwise.
|
-- it has type Standard_Void_Type, and a subexpression otherwise.
|
-- otherwise. Procedure attribute references are also statements.
|
-- otherwise. Procedure attribute references are also statements.
|
|
|
if Nkind (Assoc_Node) in N_Subexpr
|
if Nkind (Assoc_Node) in N_Subexpr
|
and then (Nkind (Assoc_Node) in N_Raise_xxx_Error
|
and then (Nkind (Assoc_Node) in N_Raise_xxx_Error
|
or else Etype (Assoc_Node) /= Standard_Void_Type)
|
or else Etype (Assoc_Node) /= Standard_Void_Type)
|
and then (Nkind (Assoc_Node) /= N_Attribute_Reference
|
and then (Nkind (Assoc_Node) /= N_Attribute_Reference
|
or else
|
or else
|
not Is_Procedure_Attribute_Name
|
not Is_Procedure_Attribute_Name
|
(Attribute_Name (Assoc_Node)))
|
(Attribute_Name (Assoc_Node)))
|
then
|
then
|
P := Assoc_Node; -- ??? does not agree with above!
|
P := Assoc_Node; -- ??? does not agree with above!
|
N := Parent (Assoc_Node);
|
N := Parent (Assoc_Node);
|
|
|
-- Non-subexpression case. Note that N is initially Empty in this case
|
-- Non-subexpression case. Note that N is initially Empty in this case
|
-- (N is only guaranteed Non-Empty in the subexpr case).
|
-- (N is only guaranteed Non-Empty in the subexpr case).
|
|
|
else
|
else
|
P := Assoc_Node;
|
P := Assoc_Node;
|
N := Empty;
|
N := Empty;
|
end if;
|
end if;
|
|
|
-- Capture root of the transient scope
|
-- Capture root of the transient scope
|
|
|
if Scope_Is_Transient then
|
if Scope_Is_Transient then
|
Wrapped_Node := Node_To_Be_Wrapped;
|
Wrapped_Node := Node_To_Be_Wrapped;
|
end if;
|
end if;
|
|
|
loop
|
loop
|
pragma Assert (Present (P));
|
pragma Assert (Present (P));
|
|
|
case Nkind (P) is
|
case Nkind (P) is
|
|
|
-- Case of right operand of AND THEN or OR ELSE. Put the actions
|
-- Case of right operand of AND THEN or OR ELSE. Put the actions
|
-- in the Actions field of the right operand. They will be moved
|
-- in the Actions field of the right operand. They will be moved
|
-- out further when the AND THEN or OR ELSE operator is expanded.
|
-- out further when the AND THEN or OR ELSE operator is expanded.
|
-- Nothing special needs to be done for the left operand since
|
-- Nothing special needs to be done for the left operand since
|
-- in that case the actions are executed unconditionally.
|
-- in that case the actions are executed unconditionally.
|
|
|
when N_Short_Circuit =>
|
when N_Short_Circuit =>
|
if N = Right_Opnd (P) then
|
if N = Right_Opnd (P) then
|
|
|
-- We are now going to either append the actions to the
|
-- We are now going to either append the actions to the
|
-- actions field of the short-circuit operation. We will
|
-- actions field of the short-circuit operation. We will
|
-- also analyze the actions now.
|
-- also analyze the actions now.
|
|
|
-- This analysis is really too early, the proper thing would
|
-- This analysis is really too early, the proper thing would
|
-- be to just park them there now, and only analyze them if
|
-- be to just park them there now, and only analyze them if
|
-- we find we really need them, and to it at the proper
|
-- we find we really need them, and to it at the proper
|
-- final insertion point. However attempting to this proved
|
-- final insertion point. However attempting to this proved
|
-- tricky, so for now we just kill current values before and
|
-- tricky, so for now we just kill current values before and
|
-- after the analyze call to make sure we avoid peculiar
|
-- after the analyze call to make sure we avoid peculiar
|
-- optimizations from this out of order insertion.
|
-- optimizations from this out of order insertion.
|
|
|
Kill_Current_Values;
|
Kill_Current_Values;
|
|
|
if Present (Actions (P)) then
|
if Present (Actions (P)) then
|
Insert_List_After_And_Analyze
|
Insert_List_After_And_Analyze
|
(Last (Actions (P)), Ins_Actions);
|
(Last (Actions (P)), Ins_Actions);
|
else
|
else
|
Set_Actions (P, Ins_Actions);
|
Set_Actions (P, Ins_Actions);
|
Analyze_List (Actions (P));
|
Analyze_List (Actions (P));
|
end if;
|
end if;
|
|
|
Kill_Current_Values;
|
Kill_Current_Values;
|
|
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Then or Else operand of conditional expression. Add actions to
|
-- Then or Else operand of conditional expression. Add actions to
|
-- Then_Actions or Else_Actions field as appropriate. The actions
|
-- Then_Actions or Else_Actions field as appropriate. The actions
|
-- will be moved further out when the conditional is expanded.
|
-- will be moved further out when the conditional is expanded.
|
|
|
when N_Conditional_Expression =>
|
when N_Conditional_Expression =>
|
declare
|
declare
|
ThenX : constant Node_Id := Next (First (Expressions (P)));
|
ThenX : constant Node_Id := Next (First (Expressions (P)));
|
ElseX : constant Node_Id := Next (ThenX);
|
ElseX : constant Node_Id := Next (ThenX);
|
|
|
begin
|
begin
|
-- If the enclosing expression is already analyzed, as
|
-- If the enclosing expression is already analyzed, as
|
-- is the case for nested elaboration checks, insert the
|
-- is the case for nested elaboration checks, insert the
|
-- conditional further out.
|
-- conditional further out.
|
|
|
if Analyzed (P) then
|
if Analyzed (P) then
|
null;
|
null;
|
|
|
-- Actions belong to the then expression, temporarily place
|
-- Actions belong to the then expression, temporarily place
|
-- them as Then_Actions of the conditional expr. They will
|
-- them as Then_Actions of the conditional expr. They will
|
-- be moved to the proper place later when the conditional
|
-- be moved to the proper place later when the conditional
|
-- expression is expanded.
|
-- expression is expanded.
|
|
|
elsif N = ThenX then
|
elsif N = ThenX then
|
if Present (Then_Actions (P)) then
|
if Present (Then_Actions (P)) then
|
Insert_List_After_And_Analyze
|
Insert_List_After_And_Analyze
|
(Last (Then_Actions (P)), Ins_Actions);
|
(Last (Then_Actions (P)), Ins_Actions);
|
else
|
else
|
Set_Then_Actions (P, Ins_Actions);
|
Set_Then_Actions (P, Ins_Actions);
|
Analyze_List (Then_Actions (P));
|
Analyze_List (Then_Actions (P));
|
end if;
|
end if;
|
|
|
return;
|
return;
|
|
|
-- Actions belong to the else expression, temporarily
|
-- Actions belong to the else expression, temporarily
|
-- place them as Else_Actions of the conditional expr.
|
-- place them as Else_Actions of the conditional expr.
|
-- They will be moved to the proper place later when
|
-- They will be moved to the proper place later when
|
-- the conditional expression is expanded.
|
-- the conditional expression is expanded.
|
|
|
elsif N = ElseX then
|
elsif N = ElseX then
|
if Present (Else_Actions (P)) then
|
if Present (Else_Actions (P)) then
|
Insert_List_After_And_Analyze
|
Insert_List_After_And_Analyze
|
(Last (Else_Actions (P)), Ins_Actions);
|
(Last (Else_Actions (P)), Ins_Actions);
|
else
|
else
|
Set_Else_Actions (P, Ins_Actions);
|
Set_Else_Actions (P, Ins_Actions);
|
Analyze_List (Else_Actions (P));
|
Analyze_List (Else_Actions (P));
|
end if;
|
end if;
|
|
|
return;
|
return;
|
|
|
-- Actions belong to the condition. In this case they are
|
-- Actions belong to the condition. In this case they are
|
-- unconditionally executed, and so we can continue the
|
-- unconditionally executed, and so we can continue the
|
-- search for the proper insert point.
|
-- search for the proper insert point.
|
|
|
else
|
else
|
null;
|
null;
|
end if;
|
end if;
|
end;
|
end;
|
|
|
-- Alternative of case expression, we place the action in the
|
-- Alternative of case expression, we place the action in the
|
-- Actions field of the case expression alternative, this will
|
-- Actions field of the case expression alternative, this will
|
-- be handled when the case expression is expanded.
|
-- be handled when the case expression is expanded.
|
|
|
when N_Case_Expression_Alternative =>
|
when N_Case_Expression_Alternative =>
|
if Present (Actions (P)) then
|
if Present (Actions (P)) then
|
Insert_List_After_And_Analyze
|
Insert_List_After_And_Analyze
|
(Last (Actions (P)), Ins_Actions);
|
(Last (Actions (P)), Ins_Actions);
|
else
|
else
|
Set_Actions (P, Ins_Actions);
|
Set_Actions (P, Ins_Actions);
|
Analyze_List (Actions (P));
|
Analyze_List (Actions (P));
|
end if;
|
end if;
|
|
|
return;
|
return;
|
|
|
-- Case of appearing within an Expressions_With_Actions node. We
|
-- Case of appearing within an Expressions_With_Actions node. We
|
-- prepend the actions to the list of actions already there, if
|
-- prepend the actions to the list of actions already there, if
|
-- the node has not been analyzed yet. Otherwise find insertion
|
-- the node has not been analyzed yet. Otherwise find insertion
|
-- location further up the tree.
|
-- location further up the tree.
|
|
|
when N_Expression_With_Actions =>
|
when N_Expression_With_Actions =>
|
if not Analyzed (P) then
|
if not Analyzed (P) then
|
Prepend_List (Ins_Actions, Actions (P));
|
Prepend_List (Ins_Actions, Actions (P));
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Case of appearing in the condition of a while expression or
|
-- Case of appearing in the condition of a while expression or
|
-- elsif. We insert the actions into the Condition_Actions field.
|
-- elsif. We insert the actions into the Condition_Actions field.
|
-- They will be moved further out when the while loop or elsif
|
-- They will be moved further out when the while loop or elsif
|
-- is analyzed.
|
-- is analyzed.
|
|
|
when N_Iteration_Scheme |
|
when N_Iteration_Scheme |
|
N_Elsif_Part
|
N_Elsif_Part
|
=>
|
=>
|
if N = Condition (P) then
|
if N = Condition (P) then
|
if Present (Condition_Actions (P)) then
|
if Present (Condition_Actions (P)) then
|
Insert_List_After_And_Analyze
|
Insert_List_After_And_Analyze
|
(Last (Condition_Actions (P)), Ins_Actions);
|
(Last (Condition_Actions (P)), Ins_Actions);
|
else
|
else
|
Set_Condition_Actions (P, Ins_Actions);
|
Set_Condition_Actions (P, Ins_Actions);
|
|
|
-- Set the parent of the insert actions explicitly. This
|
-- Set the parent of the insert actions explicitly. This
|
-- is not a syntactic field, but we need the parent field
|
-- is not a syntactic field, but we need the parent field
|
-- set, in particular so that freeze can understand that
|
-- set, in particular so that freeze can understand that
|
-- it is dealing with condition actions, and properly
|
-- it is dealing with condition actions, and properly
|
-- insert the freezing actions.
|
-- insert the freezing actions.
|
|
|
Set_Parent (Ins_Actions, P);
|
Set_Parent (Ins_Actions, P);
|
Analyze_List (Condition_Actions (P));
|
Analyze_List (Condition_Actions (P));
|
end if;
|
end if;
|
|
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Statements, declarations, pragmas, representation clauses
|
-- Statements, declarations, pragmas, representation clauses
|
|
|
when
|
when
|
-- Statements
|
-- Statements
|
|
|
N_Procedure_Call_Statement |
|
N_Procedure_Call_Statement |
|
N_Statement_Other_Than_Procedure_Call |
|
N_Statement_Other_Than_Procedure_Call |
|
|
|
-- Pragmas
|
-- Pragmas
|
|
|
N_Pragma |
|
N_Pragma |
|
|
|
-- Representation_Clause
|
-- Representation_Clause
|
|
|
N_At_Clause |
|
N_At_Clause |
|
N_Attribute_Definition_Clause |
|
N_Attribute_Definition_Clause |
|
N_Enumeration_Representation_Clause |
|
N_Enumeration_Representation_Clause |
|
N_Record_Representation_Clause |
|
N_Record_Representation_Clause |
|
|
|
-- Declarations
|
-- Declarations
|
|
|
N_Abstract_Subprogram_Declaration |
|
N_Abstract_Subprogram_Declaration |
|
N_Entry_Body |
|
N_Entry_Body |
|
N_Exception_Declaration |
|
N_Exception_Declaration |
|
N_Exception_Renaming_Declaration |
|
N_Exception_Renaming_Declaration |
|
N_Expression_Function |
|
N_Expression_Function |
|
N_Formal_Abstract_Subprogram_Declaration |
|
N_Formal_Abstract_Subprogram_Declaration |
|
N_Formal_Concrete_Subprogram_Declaration |
|
N_Formal_Concrete_Subprogram_Declaration |
|
N_Formal_Object_Declaration |
|
N_Formal_Object_Declaration |
|
N_Formal_Type_Declaration |
|
N_Formal_Type_Declaration |
|
N_Full_Type_Declaration |
|
N_Full_Type_Declaration |
|
N_Function_Instantiation |
|
N_Function_Instantiation |
|
N_Generic_Function_Renaming_Declaration |
|
N_Generic_Function_Renaming_Declaration |
|
N_Generic_Package_Declaration |
|
N_Generic_Package_Declaration |
|
N_Generic_Package_Renaming_Declaration |
|
N_Generic_Package_Renaming_Declaration |
|
N_Generic_Procedure_Renaming_Declaration |
|
N_Generic_Procedure_Renaming_Declaration |
|
N_Generic_Subprogram_Declaration |
|
N_Generic_Subprogram_Declaration |
|
N_Implicit_Label_Declaration |
|
N_Implicit_Label_Declaration |
|
N_Incomplete_Type_Declaration |
|
N_Incomplete_Type_Declaration |
|
N_Number_Declaration |
|
N_Number_Declaration |
|
N_Object_Declaration |
|
N_Object_Declaration |
|
N_Object_Renaming_Declaration |
|
N_Object_Renaming_Declaration |
|
N_Package_Body |
|
N_Package_Body |
|
N_Package_Body_Stub |
|
N_Package_Body_Stub |
|
N_Package_Declaration |
|
N_Package_Declaration |
|
N_Package_Instantiation |
|
N_Package_Instantiation |
|
N_Package_Renaming_Declaration |
|
N_Package_Renaming_Declaration |
|
N_Private_Extension_Declaration |
|
N_Private_Extension_Declaration |
|
N_Private_Type_Declaration |
|
N_Private_Type_Declaration |
|
N_Procedure_Instantiation |
|
N_Procedure_Instantiation |
|
N_Protected_Body |
|
N_Protected_Body |
|
N_Protected_Body_Stub |
|
N_Protected_Body_Stub |
|
N_Protected_Type_Declaration |
|
N_Protected_Type_Declaration |
|
N_Single_Task_Declaration |
|
N_Single_Task_Declaration |
|
N_Subprogram_Body |
|
N_Subprogram_Body |
|
N_Subprogram_Body_Stub |
|
N_Subprogram_Body_Stub |
|
N_Subprogram_Declaration |
|
N_Subprogram_Declaration |
|
N_Subprogram_Renaming_Declaration |
|
N_Subprogram_Renaming_Declaration |
|
N_Subtype_Declaration |
|
N_Subtype_Declaration |
|
N_Task_Body |
|
N_Task_Body |
|
N_Task_Body_Stub |
|
N_Task_Body_Stub |
|
N_Task_Type_Declaration |
|
N_Task_Type_Declaration |
|
|
|
-- Use clauses can appear in lists of declarations
|
-- Use clauses can appear in lists of declarations
|
|
|
N_Use_Package_Clause |
|
N_Use_Package_Clause |
|
N_Use_Type_Clause |
|
N_Use_Type_Clause |
|
|
|
-- Freeze entity behaves like a declaration or statement
|
-- Freeze entity behaves like a declaration or statement
|
|
|
N_Freeze_Entity
|
N_Freeze_Entity
|
=>
|
=>
|
-- Do not insert here if the item is not a list member (this
|
-- Do not insert here if the item is not a list member (this
|
-- happens for example with a triggering statement, and the
|
-- happens for example with a triggering statement, and the
|
-- proper approach is to insert before the entire select).
|
-- proper approach is to insert before the entire select).
|
|
|
if not Is_List_Member (P) then
|
if not Is_List_Member (P) then
|
null;
|
null;
|
|
|
-- Do not insert if parent of P is an N_Component_Association
|
-- Do not insert if parent of P is an N_Component_Association
|
-- node (i.e. we are in the context of an N_Aggregate or
|
-- node (i.e. we are in the context of an N_Aggregate or
|
-- N_Extension_Aggregate node. In this case we want to insert
|
-- N_Extension_Aggregate node. In this case we want to insert
|
-- before the entire aggregate.
|
-- before the entire aggregate.
|
|
|
elsif Nkind (Parent (P)) = N_Component_Association then
|
elsif Nkind (Parent (P)) = N_Component_Association then
|
null;
|
null;
|
|
|
-- Do not insert if the parent of P is either an N_Variant node
|
-- Do not insert if the parent of P is either an N_Variant node
|
-- or an N_Record_Definition node, meaning in either case that
|
-- or an N_Record_Definition node, meaning in either case that
|
-- P is a member of a component list, and that therefore the
|
-- P is a member of a component list, and that therefore the
|
-- actions should be inserted outside the complete record
|
-- actions should be inserted outside the complete record
|
-- declaration.
|
-- declaration.
|
|
|
elsif Nkind (Parent (P)) = N_Variant
|
elsif Nkind (Parent (P)) = N_Variant
|
or else Nkind (Parent (P)) = N_Record_Definition
|
or else Nkind (Parent (P)) = N_Record_Definition
|
then
|
then
|
null;
|
null;
|
|
|
-- Do not insert freeze nodes within the loop generated for
|
-- Do not insert freeze nodes within the loop generated for
|
-- an aggregate, because they may be elaborated too late for
|
-- an aggregate, because they may be elaborated too late for
|
-- subsequent use in the back end: within a package spec the
|
-- subsequent use in the back end: within a package spec the
|
-- loop is part of the elaboration procedure and is only
|
-- loop is part of the elaboration procedure and is only
|
-- elaborated during the second pass.
|
-- elaborated during the second pass.
|
|
|
-- If the loop comes from source, or the entity is local to the
|
-- If the loop comes from source, or the entity is local to the
|
-- loop itself it must remain within.
|
-- loop itself it must remain within.
|
|
|
elsif Nkind (Parent (P)) = N_Loop_Statement
|
elsif Nkind (Parent (P)) = N_Loop_Statement
|
and then not Comes_From_Source (Parent (P))
|
and then not Comes_From_Source (Parent (P))
|
and then Nkind (First (Ins_Actions)) = N_Freeze_Entity
|
and then Nkind (First (Ins_Actions)) = N_Freeze_Entity
|
and then
|
and then
|
Scope (Entity (First (Ins_Actions))) /= Current_Scope
|
Scope (Entity (First (Ins_Actions))) /= Current_Scope
|
then
|
then
|
null;
|
null;
|
|
|
-- Otherwise we can go ahead and do the insertion
|
-- Otherwise we can go ahead and do the insertion
|
|
|
elsif P = Wrapped_Node then
|
elsif P = Wrapped_Node then
|
Store_Before_Actions_In_Scope (Ins_Actions);
|
Store_Before_Actions_In_Scope (Ins_Actions);
|
return;
|
return;
|
|
|
else
|
else
|
Insert_List_Before_And_Analyze (P, Ins_Actions);
|
Insert_List_Before_And_Analyze (P, Ins_Actions);
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- A special case, N_Raise_xxx_Error can act either as a statement
|
-- A special case, N_Raise_xxx_Error can act either as a statement
|
-- or a subexpression. We tell the difference by looking at the
|
-- or a subexpression. We tell the difference by looking at the
|
-- Etype. It is set to Standard_Void_Type in the statement case.
|
-- Etype. It is set to Standard_Void_Type in the statement case.
|
|
|
when
|
when
|
N_Raise_xxx_Error =>
|
N_Raise_xxx_Error =>
|
if Etype (P) = Standard_Void_Type then
|
if Etype (P) = Standard_Void_Type then
|
if P = Wrapped_Node then
|
if P = Wrapped_Node then
|
Store_Before_Actions_In_Scope (Ins_Actions);
|
Store_Before_Actions_In_Scope (Ins_Actions);
|
else
|
else
|
Insert_List_Before_And_Analyze (P, Ins_Actions);
|
Insert_List_Before_And_Analyze (P, Ins_Actions);
|
end if;
|
end if;
|
|
|
return;
|
return;
|
|
|
-- In the subexpression case, keep climbing
|
-- In the subexpression case, keep climbing
|
|
|
else
|
else
|
null;
|
null;
|
end if;
|
end if;
|
|
|
-- If a component association appears within a loop created for
|
-- If a component association appears within a loop created for
|
-- an array aggregate, attach the actions to the association so
|
-- an array aggregate, attach the actions to the association so
|
-- they can be subsequently inserted within the loop. For other
|
-- they can be subsequently inserted within the loop. For other
|
-- component associations insert outside of the aggregate. For
|
-- component associations insert outside of the aggregate. For
|
-- an association that will generate a loop, its Loop_Actions
|
-- an association that will generate a loop, its Loop_Actions
|
-- attribute is already initialized (see exp_aggr.adb).
|
-- attribute is already initialized (see exp_aggr.adb).
|
|
|
-- The list of loop_actions can in turn generate additional ones,
|
-- The list of loop_actions can in turn generate additional ones,
|
-- that are inserted before the associated node. If the associated
|
-- that are inserted before the associated node. If the associated
|
-- node is outside the aggregate, the new actions are collected
|
-- node is outside the aggregate, the new actions are collected
|
-- at the end of the loop actions, to respect the order in which
|
-- at the end of the loop actions, to respect the order in which
|
-- they are to be elaborated.
|
-- they are to be elaborated.
|
|
|
when
|
when
|
N_Component_Association =>
|
N_Component_Association =>
|
if Nkind (Parent (P)) = N_Aggregate
|
if Nkind (Parent (P)) = N_Aggregate
|
and then Present (Loop_Actions (P))
|
and then Present (Loop_Actions (P))
|
then
|
then
|
if Is_Empty_List (Loop_Actions (P)) then
|
if Is_Empty_List (Loop_Actions (P)) then
|
Set_Loop_Actions (P, Ins_Actions);
|
Set_Loop_Actions (P, Ins_Actions);
|
Analyze_List (Ins_Actions);
|
Analyze_List (Ins_Actions);
|
|
|
else
|
else
|
declare
|
declare
|
Decl : Node_Id;
|
Decl : Node_Id;
|
|
|
begin
|
begin
|
-- Check whether these actions were generated by a
|
-- Check whether these actions were generated by a
|
-- declaration that is part of the loop_ actions
|
-- declaration that is part of the loop_ actions
|
-- for the component_association.
|
-- for the component_association.
|
|
|
Decl := Assoc_Node;
|
Decl := Assoc_Node;
|
while Present (Decl) loop
|
while Present (Decl) loop
|
exit when Parent (Decl) = P
|
exit when Parent (Decl) = P
|
and then Is_List_Member (Decl)
|
and then Is_List_Member (Decl)
|
and then
|
and then
|
List_Containing (Decl) = Loop_Actions (P);
|
List_Containing (Decl) = Loop_Actions (P);
|
Decl := Parent (Decl);
|
Decl := Parent (Decl);
|
end loop;
|
end loop;
|
|
|
if Present (Decl) then
|
if Present (Decl) then
|
Insert_List_Before_And_Analyze
|
Insert_List_Before_And_Analyze
|
(Decl, Ins_Actions);
|
(Decl, Ins_Actions);
|
else
|
else
|
Insert_List_After_And_Analyze
|
Insert_List_After_And_Analyze
|
(Last (Loop_Actions (P)), Ins_Actions);
|
(Last (Loop_Actions (P)), Ins_Actions);
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
return;
|
return;
|
|
|
else
|
else
|
null;
|
null;
|
end if;
|
end if;
|
|
|
-- Another special case, an attribute denoting a procedure call
|
-- Another special case, an attribute denoting a procedure call
|
|
|
when
|
when
|
N_Attribute_Reference =>
|
N_Attribute_Reference =>
|
if Is_Procedure_Attribute_Name (Attribute_Name (P)) then
|
if Is_Procedure_Attribute_Name (Attribute_Name (P)) then
|
if P = Wrapped_Node then
|
if P = Wrapped_Node then
|
Store_Before_Actions_In_Scope (Ins_Actions);
|
Store_Before_Actions_In_Scope (Ins_Actions);
|
else
|
else
|
Insert_List_Before_And_Analyze (P, Ins_Actions);
|
Insert_List_Before_And_Analyze (P, Ins_Actions);
|
end if;
|
end if;
|
|
|
return;
|
return;
|
|
|
-- In the subexpression case, keep climbing
|
-- In the subexpression case, keep climbing
|
|
|
else
|
else
|
null;
|
null;
|
end if;
|
end if;
|
|
|
-- A contract node should not belong to the tree
|
-- A contract node should not belong to the tree
|
|
|
when N_Contract =>
|
when N_Contract =>
|
raise Program_Error;
|
raise Program_Error;
|
|
|
-- For all other node types, keep climbing tree
|
-- For all other node types, keep climbing tree
|
|
|
when
|
when
|
N_Abortable_Part |
|
N_Abortable_Part |
|
N_Accept_Alternative |
|
N_Accept_Alternative |
|
N_Access_Definition |
|
N_Access_Definition |
|
N_Access_Function_Definition |
|
N_Access_Function_Definition |
|
N_Access_Procedure_Definition |
|
N_Access_Procedure_Definition |
|
N_Access_To_Object_Definition |
|
N_Access_To_Object_Definition |
|
N_Aggregate |
|
N_Aggregate |
|
N_Allocator |
|
N_Allocator |
|
N_Aspect_Specification |
|
N_Aspect_Specification |
|
N_Case_Expression |
|
N_Case_Expression |
|
N_Case_Statement_Alternative |
|
N_Case_Statement_Alternative |
|
N_Character_Literal |
|
N_Character_Literal |
|
N_Compilation_Unit |
|
N_Compilation_Unit |
|
N_Compilation_Unit_Aux |
|
N_Compilation_Unit_Aux |
|
N_Component_Clause |
|
N_Component_Clause |
|
N_Component_Declaration |
|
N_Component_Declaration |
|
N_Component_Definition |
|
N_Component_Definition |
|
N_Component_List |
|
N_Component_List |
|
N_Constrained_Array_Definition |
|
N_Constrained_Array_Definition |
|
N_Decimal_Fixed_Point_Definition |
|
N_Decimal_Fixed_Point_Definition |
|
N_Defining_Character_Literal |
|
N_Defining_Character_Literal |
|
N_Defining_Identifier |
|
N_Defining_Identifier |
|
N_Defining_Operator_Symbol |
|
N_Defining_Operator_Symbol |
|
N_Defining_Program_Unit_Name |
|
N_Defining_Program_Unit_Name |
|
N_Delay_Alternative |
|
N_Delay_Alternative |
|
N_Delta_Constraint |
|
N_Delta_Constraint |
|
N_Derived_Type_Definition |
|
N_Derived_Type_Definition |
|
N_Designator |
|
N_Designator |
|
N_Digits_Constraint |
|
N_Digits_Constraint |
|
N_Discriminant_Association |
|
N_Discriminant_Association |
|
N_Discriminant_Specification |
|
N_Discriminant_Specification |
|
N_Empty |
|
N_Empty |
|
N_Entry_Body_Formal_Part |
|
N_Entry_Body_Formal_Part |
|
N_Entry_Call_Alternative |
|
N_Entry_Call_Alternative |
|
N_Entry_Declaration |
|
N_Entry_Declaration |
|
N_Entry_Index_Specification |
|
N_Entry_Index_Specification |
|
N_Enumeration_Type_Definition |
|
N_Enumeration_Type_Definition |
|
N_Error |
|
N_Error |
|
N_Exception_Handler |
|
N_Exception_Handler |
|
N_Expanded_Name |
|
N_Expanded_Name |
|
N_Explicit_Dereference |
|
N_Explicit_Dereference |
|
N_Extension_Aggregate |
|
N_Extension_Aggregate |
|
N_Floating_Point_Definition |
|
N_Floating_Point_Definition |
|
N_Formal_Decimal_Fixed_Point_Definition |
|
N_Formal_Decimal_Fixed_Point_Definition |
|
N_Formal_Derived_Type_Definition |
|
N_Formal_Derived_Type_Definition |
|
N_Formal_Discrete_Type_Definition |
|
N_Formal_Discrete_Type_Definition |
|
N_Formal_Floating_Point_Definition |
|
N_Formal_Floating_Point_Definition |
|
N_Formal_Modular_Type_Definition |
|
N_Formal_Modular_Type_Definition |
|
N_Formal_Ordinary_Fixed_Point_Definition |
|
N_Formal_Ordinary_Fixed_Point_Definition |
|
N_Formal_Package_Declaration |
|
N_Formal_Package_Declaration |
|
N_Formal_Private_Type_Definition |
|
N_Formal_Private_Type_Definition |
|
N_Formal_Incomplete_Type_Definition |
|
N_Formal_Incomplete_Type_Definition |
|
N_Formal_Signed_Integer_Type_Definition |
|
N_Formal_Signed_Integer_Type_Definition |
|
N_Function_Call |
|
N_Function_Call |
|
N_Function_Specification |
|
N_Function_Specification |
|
N_Generic_Association |
|
N_Generic_Association |
|
N_Handled_Sequence_Of_Statements |
|
N_Handled_Sequence_Of_Statements |
|
N_Identifier |
|
N_Identifier |
|
N_In |
|
N_In |
|
N_Index_Or_Discriminant_Constraint |
|
N_Index_Or_Discriminant_Constraint |
|
N_Indexed_Component |
|
N_Indexed_Component |
|
N_Integer_Literal |
|
N_Integer_Literal |
|
N_Iterator_Specification |
|
N_Iterator_Specification |
|
N_Itype_Reference |
|
N_Itype_Reference |
|
N_Label |
|
N_Label |
|
N_Loop_Parameter_Specification |
|
N_Loop_Parameter_Specification |
|
N_Mod_Clause |
|
N_Mod_Clause |
|
N_Modular_Type_Definition |
|
N_Modular_Type_Definition |
|
N_Not_In |
|
N_Not_In |
|
N_Null |
|
N_Null |
|
N_Op_Abs |
|
N_Op_Abs |
|
N_Op_Add |
|
N_Op_Add |
|
N_Op_And |
|
N_Op_And |
|
N_Op_Concat |
|
N_Op_Concat |
|
N_Op_Divide |
|
N_Op_Divide |
|
N_Op_Eq |
|
N_Op_Eq |
|
N_Op_Expon |
|
N_Op_Expon |
|
N_Op_Ge |
|
N_Op_Ge |
|
N_Op_Gt |
|
N_Op_Gt |
|
N_Op_Le |
|
N_Op_Le |
|
N_Op_Lt |
|
N_Op_Lt |
|
N_Op_Minus |
|
N_Op_Minus |
|
N_Op_Mod |
|
N_Op_Mod |
|
N_Op_Multiply |
|
N_Op_Multiply |
|
N_Op_Ne |
|
N_Op_Ne |
|
N_Op_Not |
|
N_Op_Not |
|
N_Op_Or |
|
N_Op_Or |
|
N_Op_Plus |
|
N_Op_Plus |
|
N_Op_Rem |
|
N_Op_Rem |
|
N_Op_Rotate_Left |
|
N_Op_Rotate_Left |
|
N_Op_Rotate_Right |
|
N_Op_Rotate_Right |
|
N_Op_Shift_Left |
|
N_Op_Shift_Left |
|
N_Op_Shift_Right |
|
N_Op_Shift_Right |
|
N_Op_Shift_Right_Arithmetic |
|
N_Op_Shift_Right_Arithmetic |
|
N_Op_Subtract |
|
N_Op_Subtract |
|
N_Op_Xor |
|
N_Op_Xor |
|
N_Operator_Symbol |
|
N_Operator_Symbol |
|
N_Ordinary_Fixed_Point_Definition |
|
N_Ordinary_Fixed_Point_Definition |
|
N_Others_Choice |
|
N_Others_Choice |
|
N_Package_Specification |
|
N_Package_Specification |
|
N_Parameter_Association |
|
N_Parameter_Association |
|
N_Parameter_Specification |
|
N_Parameter_Specification |
|
N_Pop_Constraint_Error_Label |
|
N_Pop_Constraint_Error_Label |
|
N_Pop_Program_Error_Label |
|
N_Pop_Program_Error_Label |
|
N_Pop_Storage_Error_Label |
|
N_Pop_Storage_Error_Label |
|
N_Pragma_Argument_Association |
|
N_Pragma_Argument_Association |
|
N_Procedure_Specification |
|
N_Procedure_Specification |
|
N_Protected_Definition |
|
N_Protected_Definition |
|
N_Push_Constraint_Error_Label |
|
N_Push_Constraint_Error_Label |
|
N_Push_Program_Error_Label |
|
N_Push_Program_Error_Label |
|
N_Push_Storage_Error_Label |
|
N_Push_Storage_Error_Label |
|
N_Qualified_Expression |
|
N_Qualified_Expression |
|
N_Quantified_Expression |
|
N_Quantified_Expression |
|
N_Range |
|
N_Range |
|
N_Range_Constraint |
|
N_Range_Constraint |
|
N_Real_Literal |
|
N_Real_Literal |
|
N_Real_Range_Specification |
|
N_Real_Range_Specification |
|
N_Record_Definition |
|
N_Record_Definition |
|
N_Reference |
|
N_Reference |
|
N_SCIL_Dispatch_Table_Tag_Init |
|
N_SCIL_Dispatch_Table_Tag_Init |
|
N_SCIL_Dispatching_Call |
|
N_SCIL_Dispatching_Call |
|
N_SCIL_Membership_Test |
|
N_SCIL_Membership_Test |
|
N_Selected_Component |
|
N_Selected_Component |
|
N_Signed_Integer_Type_Definition |
|
N_Signed_Integer_Type_Definition |
|
N_Single_Protected_Declaration |
|
N_Single_Protected_Declaration |
|
N_Slice |
|
N_Slice |
|
N_String_Literal |
|
N_String_Literal |
|
N_Subprogram_Info |
|
N_Subprogram_Info |
|
N_Subtype_Indication |
|
N_Subtype_Indication |
|
N_Subunit |
|
N_Subunit |
|
N_Task_Definition |
|
N_Task_Definition |
|
N_Terminate_Alternative |
|
N_Terminate_Alternative |
|
N_Triggering_Alternative |
|
N_Triggering_Alternative |
|
N_Type_Conversion |
|
N_Type_Conversion |
|
N_Unchecked_Expression |
|
N_Unchecked_Expression |
|
N_Unchecked_Type_Conversion |
|
N_Unchecked_Type_Conversion |
|
N_Unconstrained_Array_Definition |
|
N_Unconstrained_Array_Definition |
|
N_Unused_At_End |
|
N_Unused_At_End |
|
N_Unused_At_Start |
|
N_Unused_At_Start |
|
N_Variant |
|
N_Variant |
|
N_Variant_Part |
|
N_Variant_Part |
|
N_Validate_Unchecked_Conversion |
|
N_Validate_Unchecked_Conversion |
|
N_With_Clause
|
N_With_Clause
|
=>
|
=>
|
null;
|
null;
|
|
|
end case;
|
end case;
|
|
|
-- Make sure that inserted actions stay in the transient scope
|
-- Make sure that inserted actions stay in the transient scope
|
|
|
if P = Wrapped_Node then
|
if P = Wrapped_Node then
|
Store_Before_Actions_In_Scope (Ins_Actions);
|
Store_Before_Actions_In_Scope (Ins_Actions);
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- If we fall through above tests, keep climbing tree
|
-- If we fall through above tests, keep climbing tree
|
|
|
N := P;
|
N := P;
|
|
|
if Nkind (Parent (N)) = N_Subunit then
|
if Nkind (Parent (N)) = N_Subunit then
|
|
|
-- This is the proper body corresponding to a stub. Insertion must
|
-- This is the proper body corresponding to a stub. Insertion must
|
-- be done at the point of the stub, which is in the declarative
|
-- be done at the point of the stub, which is in the declarative
|
-- part of the parent unit.
|
-- part of the parent unit.
|
|
|
P := Corresponding_Stub (Parent (N));
|
P := Corresponding_Stub (Parent (N));
|
|
|
else
|
else
|
P := Parent (N);
|
P := Parent (N);
|
end if;
|
end if;
|
end loop;
|
end loop;
|
end Insert_Actions;
|
end Insert_Actions;
|
|
|
-- Version with check(s) suppressed
|
-- Version with check(s) suppressed
|
|
|
procedure Insert_Actions
|
procedure Insert_Actions
|
(Assoc_Node : Node_Id;
|
(Assoc_Node : Node_Id;
|
Ins_Actions : List_Id;
|
Ins_Actions : List_Id;
|
Suppress : Check_Id)
|
Suppress : Check_Id)
|
is
|
is
|
begin
|
begin
|
if Suppress = All_Checks then
|
if Suppress = All_Checks then
|
declare
|
declare
|
Svg : constant Suppress_Array := Scope_Suppress;
|
Svg : constant Suppress_Array := Scope_Suppress;
|
begin
|
begin
|
Scope_Suppress := (others => True);
|
Scope_Suppress := (others => True);
|
Insert_Actions (Assoc_Node, Ins_Actions);
|
Insert_Actions (Assoc_Node, Ins_Actions);
|
Scope_Suppress := Svg;
|
Scope_Suppress := Svg;
|
end;
|
end;
|
|
|
else
|
else
|
declare
|
declare
|
Svg : constant Boolean := Scope_Suppress (Suppress);
|
Svg : constant Boolean := Scope_Suppress (Suppress);
|
begin
|
begin
|
Scope_Suppress (Suppress) := True;
|
Scope_Suppress (Suppress) := True;
|
Insert_Actions (Assoc_Node, Ins_Actions);
|
Insert_Actions (Assoc_Node, Ins_Actions);
|
Scope_Suppress (Suppress) := Svg;
|
Scope_Suppress (Suppress) := Svg;
|
end;
|
end;
|
end if;
|
end if;
|
end Insert_Actions;
|
end Insert_Actions;
|
|
|
--------------------------
|
--------------------------
|
-- Insert_Actions_After --
|
-- Insert_Actions_After --
|
--------------------------
|
--------------------------
|
|
|
procedure Insert_Actions_After
|
procedure Insert_Actions_After
|
(Assoc_Node : Node_Id;
|
(Assoc_Node : Node_Id;
|
Ins_Actions : List_Id)
|
Ins_Actions : List_Id)
|
is
|
is
|
begin
|
begin
|
if Scope_Is_Transient
|
if Scope_Is_Transient
|
and then Assoc_Node = Node_To_Be_Wrapped
|
and then Assoc_Node = Node_To_Be_Wrapped
|
then
|
then
|
Store_After_Actions_In_Scope (Ins_Actions);
|
Store_After_Actions_In_Scope (Ins_Actions);
|
else
|
else
|
Insert_List_After_And_Analyze (Assoc_Node, Ins_Actions);
|
Insert_List_After_And_Analyze (Assoc_Node, Ins_Actions);
|
end if;
|
end if;
|
end Insert_Actions_After;
|
end Insert_Actions_After;
|
|
|
---------------------------------
|
---------------------------------
|
-- Insert_Library_Level_Action --
|
-- Insert_Library_Level_Action --
|
---------------------------------
|
---------------------------------
|
|
|
procedure Insert_Library_Level_Action (N : Node_Id) is
|
procedure Insert_Library_Level_Action (N : Node_Id) is
|
Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
|
Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
|
|
|
begin
|
begin
|
Push_Scope (Cunit_Entity (Main_Unit));
|
Push_Scope (Cunit_Entity (Main_Unit));
|
-- ??? should this be Current_Sem_Unit instead of Main_Unit?
|
-- ??? should this be Current_Sem_Unit instead of Main_Unit?
|
|
|
if No (Actions (Aux)) then
|
if No (Actions (Aux)) then
|
Set_Actions (Aux, New_List (N));
|
Set_Actions (Aux, New_List (N));
|
else
|
else
|
Append (N, Actions (Aux));
|
Append (N, Actions (Aux));
|
end if;
|
end if;
|
|
|
Analyze (N);
|
Analyze (N);
|
Pop_Scope;
|
Pop_Scope;
|
end Insert_Library_Level_Action;
|
end Insert_Library_Level_Action;
|
|
|
----------------------------------
|
----------------------------------
|
-- Insert_Library_Level_Actions --
|
-- Insert_Library_Level_Actions --
|
----------------------------------
|
----------------------------------
|
|
|
procedure Insert_Library_Level_Actions (L : List_Id) is
|
procedure Insert_Library_Level_Actions (L : List_Id) is
|
Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
|
Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit));
|
|
|
begin
|
begin
|
if Is_Non_Empty_List (L) then
|
if Is_Non_Empty_List (L) then
|
Push_Scope (Cunit_Entity (Main_Unit));
|
Push_Scope (Cunit_Entity (Main_Unit));
|
-- ??? should this be Current_Sem_Unit instead of Main_Unit?
|
-- ??? should this be Current_Sem_Unit instead of Main_Unit?
|
|
|
if No (Actions (Aux)) then
|
if No (Actions (Aux)) then
|
Set_Actions (Aux, L);
|
Set_Actions (Aux, L);
|
Analyze_List (L);
|
Analyze_List (L);
|
else
|
else
|
Insert_List_After_And_Analyze (Last (Actions (Aux)), L);
|
Insert_List_After_And_Analyze (Last (Actions (Aux)), L);
|
end if;
|
end if;
|
|
|
Pop_Scope;
|
Pop_Scope;
|
end if;
|
end if;
|
end Insert_Library_Level_Actions;
|
end Insert_Library_Level_Actions;
|
|
|
----------------------
|
----------------------
|
-- Inside_Init_Proc --
|
-- Inside_Init_Proc --
|
----------------------
|
----------------------
|
|
|
function Inside_Init_Proc return Boolean is
|
function Inside_Init_Proc return Boolean is
|
S : Entity_Id;
|
S : Entity_Id;
|
|
|
begin
|
begin
|
S := Current_Scope;
|
S := Current_Scope;
|
while Present (S)
|
while Present (S)
|
and then S /= Standard_Standard
|
and then S /= Standard_Standard
|
loop
|
loop
|
if Is_Init_Proc (S) then
|
if Is_Init_Proc (S) then
|
return True;
|
return True;
|
else
|
else
|
S := Scope (S);
|
S := Scope (S);
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
end Inside_Init_Proc;
|
end Inside_Init_Proc;
|
|
|
----------------------------
|
----------------------------
|
-- Is_All_Null_Statements --
|
-- Is_All_Null_Statements --
|
----------------------------
|
----------------------------
|
|
|
function Is_All_Null_Statements (L : List_Id) return Boolean is
|
function Is_All_Null_Statements (L : List_Id) return Boolean is
|
Stm : Node_Id;
|
Stm : Node_Id;
|
|
|
begin
|
begin
|
Stm := First (L);
|
Stm := First (L);
|
while Present (Stm) loop
|
while Present (Stm) loop
|
if Nkind (Stm) /= N_Null_Statement then
|
if Nkind (Stm) /= N_Null_Statement then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
Next (Stm);
|
Next (Stm);
|
end loop;
|
end loop;
|
|
|
return True;
|
return True;
|
end Is_All_Null_Statements;
|
end Is_All_Null_Statements;
|
|
|
---------------------------------------------
|
---------------------------------------------
|
-- Is_Displacement_Of_Ctrl_Function_Result --
|
-- Is_Displacement_Of_Ctrl_Function_Result --
|
---------------------------------------------
|
---------------------------------------------
|
|
|
function Is_Displacement_Of_Ctrl_Function_Result
|
function Is_Displacement_Of_Ctrl_Function_Result
|
(Obj_Id : Entity_Id) return Boolean
|
(Obj_Id : Entity_Id) return Boolean
|
is
|
is
|
function Initialized_By_Ctrl_Function (N : Node_Id) return Boolean;
|
function Initialized_By_Ctrl_Function (N : Node_Id) return Boolean;
|
-- Determine whether object declaration N is initialized by a controlled
|
-- Determine whether object declaration N is initialized by a controlled
|
-- function call.
|
-- function call.
|
|
|
function Is_Displace_Call (N : Node_Id) return Boolean;
|
function Is_Displace_Call (N : Node_Id) return Boolean;
|
-- Determine whether a particular node is a call to Ada.Tags.Displace.
|
-- Determine whether a particular node is a call to Ada.Tags.Displace.
|
-- The call might be nested within other actions such as conversions.
|
-- The call might be nested within other actions such as conversions.
|
|
|
----------------------------------
|
----------------------------------
|
-- Initialized_By_Ctrl_Function --
|
-- Initialized_By_Ctrl_Function --
|
----------------------------------
|
----------------------------------
|
|
|
function Initialized_By_Ctrl_Function (N : Node_Id) return Boolean is
|
function Initialized_By_Ctrl_Function (N : Node_Id) return Boolean is
|
Expr : constant Node_Id := Original_Node (Expression (N));
|
Expr : constant Node_Id := Original_Node (Expression (N));
|
begin
|
begin
|
return
|
return
|
Nkind (Expr) = N_Function_Call
|
Nkind (Expr) = N_Function_Call
|
and then Needs_Finalization (Etype (Expr));
|
and then Needs_Finalization (Etype (Expr));
|
end Initialized_By_Ctrl_Function;
|
end Initialized_By_Ctrl_Function;
|
|
|
----------------------
|
----------------------
|
-- Is_Displace_Call --
|
-- Is_Displace_Call --
|
----------------------
|
----------------------
|
|
|
function Is_Displace_Call (N : Node_Id) return Boolean is
|
function Is_Displace_Call (N : Node_Id) return Boolean is
|
Call : Node_Id := N;
|
Call : Node_Id := N;
|
|
|
begin
|
begin
|
-- Strip various actions which may precede a call to Displace
|
-- Strip various actions which may precede a call to Displace
|
|
|
loop
|
loop
|
if Nkind (Call) = N_Explicit_Dereference then
|
if Nkind (Call) = N_Explicit_Dereference then
|
Call := Prefix (Call);
|
Call := Prefix (Call);
|
|
|
elsif Nkind_In (Call, N_Type_Conversion,
|
elsif Nkind_In (Call, N_Type_Conversion,
|
N_Unchecked_Type_Conversion)
|
N_Unchecked_Type_Conversion)
|
then
|
then
|
Call := Expression (Call);
|
Call := Expression (Call);
|
|
|
else
|
else
|
exit;
|
exit;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
return
|
return
|
Nkind (Call) = N_Function_Call
|
Nkind (Call) = N_Function_Call
|
and then Is_RTE (Entity (Name (Call)), RE_Displace);
|
and then Is_RTE (Entity (Name (Call)), RE_Displace);
|
end Is_Displace_Call;
|
end Is_Displace_Call;
|
|
|
-- Local variables
|
-- Local variables
|
|
|
Decl : constant Node_Id := Parent (Obj_Id);
|
Decl : constant Node_Id := Parent (Obj_Id);
|
Obj_Typ : constant Entity_Id := Base_Type (Etype (Obj_Id));
|
Obj_Typ : constant Entity_Id := Base_Type (Etype (Obj_Id));
|
Orig_Decl : constant Node_Id := Original_Node (Decl);
|
Orig_Decl : constant Node_Id := Original_Node (Decl);
|
|
|
-- Start of processing for Is_Displacement_Of_Ctrl_Function_Result
|
-- Start of processing for Is_Displacement_Of_Ctrl_Function_Result
|
|
|
begin
|
begin
|
-- Detect the following case:
|
-- Detect the following case:
|
|
|
-- Obj : Class_Wide_Type := Function_Call (...);
|
-- Obj : Class_Wide_Type := Function_Call (...);
|
|
|
-- which is rewritten into:
|
-- which is rewritten into:
|
|
|
-- Temp : ... := Function_Call (...)'reference;
|
-- Temp : ... := Function_Call (...)'reference;
|
-- Obj : Class_Wide_Type renames (... Ada.Tags.Displace (Temp));
|
-- Obj : Class_Wide_Type renames (... Ada.Tags.Displace (Temp));
|
|
|
-- when the return type of the function and the class-wide type require
|
-- when the return type of the function and the class-wide type require
|
-- dispatch table pointer displacement.
|
-- dispatch table pointer displacement.
|
|
|
return
|
return
|
Nkind (Decl) = N_Object_Renaming_Declaration
|
Nkind (Decl) = N_Object_Renaming_Declaration
|
and then Nkind (Orig_Decl) = N_Object_Declaration
|
and then Nkind (Orig_Decl) = N_Object_Declaration
|
and then Comes_From_Source (Orig_Decl)
|
and then Comes_From_Source (Orig_Decl)
|
and then Initialized_By_Ctrl_Function (Orig_Decl)
|
and then Initialized_By_Ctrl_Function (Orig_Decl)
|
and then Is_Class_Wide_Type (Obj_Typ)
|
and then Is_Class_Wide_Type (Obj_Typ)
|
and then Is_Displace_Call (Renamed_Object (Obj_Id));
|
and then Is_Displace_Call (Renamed_Object (Obj_Id));
|
end Is_Displacement_Of_Ctrl_Function_Result;
|
end Is_Displacement_Of_Ctrl_Function_Result;
|
|
|
------------------------------
|
------------------------------
|
-- Is_Finalizable_Transient --
|
-- Is_Finalizable_Transient --
|
------------------------------
|
------------------------------
|
|
|
function Is_Finalizable_Transient
|
function Is_Finalizable_Transient
|
(Decl : Node_Id;
|
(Decl : Node_Id;
|
Rel_Node : Node_Id) return Boolean
|
Rel_Node : Node_Id) return Boolean
|
is
|
is
|
Obj_Id : constant Entity_Id := Defining_Identifier (Decl);
|
Obj_Id : constant Entity_Id := Defining_Identifier (Decl);
|
Obj_Typ : constant Entity_Id := Base_Type (Etype (Obj_Id));
|
Obj_Typ : constant Entity_Id := Base_Type (Etype (Obj_Id));
|
Desig : Entity_Id := Obj_Typ;
|
Desig : Entity_Id := Obj_Typ;
|
|
|
function Initialized_By_Access (Trans_Id : Entity_Id) return Boolean;
|
function Initialized_By_Access (Trans_Id : Entity_Id) return Boolean;
|
-- Determine whether transient object Trans_Id is initialized either
|
-- Determine whether transient object Trans_Id is initialized either
|
-- by a function call which returns an access type or simply renames
|
-- by a function call which returns an access type or simply renames
|
-- another pointer.
|
-- another pointer.
|
|
|
function Initialized_By_Aliased_BIP_Func_Call
|
function Initialized_By_Aliased_BIP_Func_Call
|
(Trans_Id : Entity_Id) return Boolean;
|
(Trans_Id : Entity_Id) return Boolean;
|
-- Determine whether transient object Trans_Id is initialized by a
|
-- Determine whether transient object Trans_Id is initialized by a
|
-- build-in-place function call where the BIPalloc parameter is of
|
-- build-in-place function call where the BIPalloc parameter is of
|
-- value 1 and BIPaccess is not null. This case creates an aliasing
|
-- value 1 and BIPaccess is not null. This case creates an aliasing
|
-- between the returned value and the value denoted by BIPaccess.
|
-- between the returned value and the value denoted by BIPaccess.
|
|
|
function Is_Aliased
|
function Is_Aliased
|
(Trans_Id : Entity_Id;
|
(Trans_Id : Entity_Id;
|
First_Stmt : Node_Id) return Boolean;
|
First_Stmt : Node_Id) return Boolean;
|
-- Determine whether transient object Trans_Id has been renamed or
|
-- Determine whether transient object Trans_Id has been renamed or
|
-- aliased through 'reference in the statement list starting from
|
-- aliased through 'reference in the statement list starting from
|
-- First_Stmt.
|
-- First_Stmt.
|
|
|
function Is_Allocated (Trans_Id : Entity_Id) return Boolean;
|
function Is_Allocated (Trans_Id : Entity_Id) return Boolean;
|
-- Determine whether transient object Trans_Id is allocated on the heap
|
-- Determine whether transient object Trans_Id is allocated on the heap
|
|
|
function Is_Iterated_Container
|
function Is_Iterated_Container
|
(Trans_Id : Entity_Id;
|
(Trans_Id : Entity_Id;
|
First_Stmt : Node_Id) return Boolean;
|
First_Stmt : Node_Id) return Boolean;
|
-- Determine whether transient object Trans_Id denotes a container which
|
-- Determine whether transient object Trans_Id denotes a container which
|
-- is in the process of being iterated in the statement list starting
|
-- is in the process of being iterated in the statement list starting
|
-- from First_Stmt.
|
-- from First_Stmt.
|
|
|
---------------------------
|
---------------------------
|
-- Initialized_By_Access --
|
-- Initialized_By_Access --
|
---------------------------
|
---------------------------
|
|
|
function Initialized_By_Access (Trans_Id : Entity_Id) return Boolean is
|
function Initialized_By_Access (Trans_Id : Entity_Id) return Boolean is
|
Expr : constant Node_Id := Expression (Parent (Trans_Id));
|
Expr : constant Node_Id := Expression (Parent (Trans_Id));
|
|
|
begin
|
begin
|
return
|
return
|
Present (Expr)
|
Present (Expr)
|
and then Nkind (Expr) /= N_Reference
|
and then Nkind (Expr) /= N_Reference
|
and then Is_Access_Type (Etype (Expr));
|
and then Is_Access_Type (Etype (Expr));
|
end Initialized_By_Access;
|
end Initialized_By_Access;
|
|
|
------------------------------------------
|
------------------------------------------
|
-- Initialized_By_Aliased_BIP_Func_Call --
|
-- Initialized_By_Aliased_BIP_Func_Call --
|
------------------------------------------
|
------------------------------------------
|
|
|
function Initialized_By_Aliased_BIP_Func_Call
|
function Initialized_By_Aliased_BIP_Func_Call
|
(Trans_Id : Entity_Id) return Boolean
|
(Trans_Id : Entity_Id) return Boolean
|
is
|
is
|
Call : Node_Id := Expression (Parent (Trans_Id));
|
Call : Node_Id := Expression (Parent (Trans_Id));
|
|
|
begin
|
begin
|
-- Build-in-place calls usually appear in 'reference format
|
-- Build-in-place calls usually appear in 'reference format
|
|
|
if Nkind (Call) = N_Reference then
|
if Nkind (Call) = N_Reference then
|
Call := Prefix (Call);
|
Call := Prefix (Call);
|
end if;
|
end if;
|
|
|
if Is_Build_In_Place_Function_Call (Call) then
|
if Is_Build_In_Place_Function_Call (Call) then
|
declare
|
declare
|
Access_Nam : Name_Id := No_Name;
|
Access_Nam : Name_Id := No_Name;
|
Access_OK : Boolean := False;
|
Access_OK : Boolean := False;
|
Actual : Node_Id;
|
Actual : Node_Id;
|
Alloc_Nam : Name_Id := No_Name;
|
Alloc_Nam : Name_Id := No_Name;
|
Alloc_OK : Boolean := False;
|
Alloc_OK : Boolean := False;
|
Formal : Node_Id;
|
Formal : Node_Id;
|
Func_Id : Entity_Id;
|
Func_Id : Entity_Id;
|
Param : Node_Id;
|
Param : Node_Id;
|
|
|
begin
|
begin
|
-- Examine all parameter associations of the function call
|
-- Examine all parameter associations of the function call
|
|
|
Param := First (Parameter_Associations (Call));
|
Param := First (Parameter_Associations (Call));
|
while Present (Param) loop
|
while Present (Param) loop
|
if Nkind (Param) = N_Parameter_Association
|
if Nkind (Param) = N_Parameter_Association
|
and then Nkind (Selector_Name (Param)) = N_Identifier
|
and then Nkind (Selector_Name (Param)) = N_Identifier
|
then
|
then
|
Actual := Explicit_Actual_Parameter (Param);
|
Actual := Explicit_Actual_Parameter (Param);
|
Formal := Selector_Name (Param);
|
Formal := Selector_Name (Param);
|
|
|
-- Construct the names of formals BIPaccess and BIPalloc
|
-- Construct the names of formals BIPaccess and BIPalloc
|
-- using the function name retrieved from an arbitrary
|
-- using the function name retrieved from an arbitrary
|
-- formal.
|
-- formal.
|
|
|
if Access_Nam = No_Name
|
if Access_Nam = No_Name
|
and then Alloc_Nam = No_Name
|
and then Alloc_Nam = No_Name
|
and then Present (Entity (Formal))
|
and then Present (Entity (Formal))
|
then
|
then
|
Func_Id := Scope (Entity (Formal));
|
Func_Id := Scope (Entity (Formal));
|
|
|
Access_Nam :=
|
Access_Nam :=
|
New_External_Name (Chars (Func_Id),
|
New_External_Name (Chars (Func_Id),
|
BIP_Formal_Suffix (BIP_Object_Access));
|
BIP_Formal_Suffix (BIP_Object_Access));
|
|
|
Alloc_Nam :=
|
Alloc_Nam :=
|
New_External_Name (Chars (Func_Id),
|
New_External_Name (Chars (Func_Id),
|
BIP_Formal_Suffix (BIP_Alloc_Form));
|
BIP_Formal_Suffix (BIP_Alloc_Form));
|
end if;
|
end if;
|
|
|
-- A match for BIPaccess => Temp has been found
|
-- A match for BIPaccess => Temp has been found
|
|
|
if Chars (Formal) = Access_Nam
|
if Chars (Formal) = Access_Nam
|
and then Nkind (Actual) /= N_Null
|
and then Nkind (Actual) /= N_Null
|
then
|
then
|
Access_OK := True;
|
Access_OK := True;
|
end if;
|
end if;
|
|
|
-- A match for BIPalloc => 1 has been found
|
-- A match for BIPalloc => 1 has been found
|
|
|
if Chars (Formal) = Alloc_Nam
|
if Chars (Formal) = Alloc_Nam
|
and then Nkind (Actual) = N_Integer_Literal
|
and then Nkind (Actual) = N_Integer_Literal
|
and then Intval (Actual) = Uint_1
|
and then Intval (Actual) = Uint_1
|
then
|
then
|
Alloc_OK := True;
|
Alloc_OK := True;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Next (Param);
|
Next (Param);
|
end loop;
|
end loop;
|
|
|
return Access_OK and then Alloc_OK;
|
return Access_OK and then Alloc_OK;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
return False;
|
return False;
|
end Initialized_By_Aliased_BIP_Func_Call;
|
end Initialized_By_Aliased_BIP_Func_Call;
|
|
|
----------------
|
----------------
|
-- Is_Aliased --
|
-- Is_Aliased --
|
----------------
|
----------------
|
|
|
function Is_Aliased
|
function Is_Aliased
|
(Trans_Id : Entity_Id;
|
(Trans_Id : Entity_Id;
|
First_Stmt : Node_Id) return Boolean
|
First_Stmt : Node_Id) return Boolean
|
is
|
is
|
function Find_Renamed_Object (Ren_Decl : Node_Id) return Entity_Id;
|
function Find_Renamed_Object (Ren_Decl : Node_Id) return Entity_Id;
|
-- Given an object renaming declaration, retrieve the entity of the
|
-- Given an object renaming declaration, retrieve the entity of the
|
-- renamed name. Return Empty if the renamed name is anything other
|
-- renamed name. Return Empty if the renamed name is anything other
|
-- than a variable or a constant.
|
-- than a variable or a constant.
|
|
|
-------------------------
|
-------------------------
|
-- Find_Renamed_Object --
|
-- Find_Renamed_Object --
|
-------------------------
|
-------------------------
|
|
|
function Find_Renamed_Object (Ren_Decl : Node_Id) return Entity_Id is
|
function Find_Renamed_Object (Ren_Decl : Node_Id) return Entity_Id is
|
Ren_Obj : Node_Id := Empty;
|
Ren_Obj : Node_Id := Empty;
|
|
|
function Find_Object (N : Node_Id) return Traverse_Result;
|
function Find_Object (N : Node_Id) return Traverse_Result;
|
-- Try to detect an object which is either a constant or a
|
-- Try to detect an object which is either a constant or a
|
-- variable.
|
-- variable.
|
|
|
-----------------
|
-----------------
|
-- Find_Object --
|
-- Find_Object --
|
-----------------
|
-----------------
|
|
|
function Find_Object (N : Node_Id) return Traverse_Result is
|
function Find_Object (N : Node_Id) return Traverse_Result is
|
begin
|
begin
|
-- Stop the search once a constant or a variable has been
|
-- Stop the search once a constant or a variable has been
|
-- detected.
|
-- detected.
|
|
|
if Nkind (N) = N_Identifier
|
if Nkind (N) = N_Identifier
|
and then Present (Entity (N))
|
and then Present (Entity (N))
|
and then Ekind_In (Entity (N), E_Constant, E_Variable)
|
and then Ekind_In (Entity (N), E_Constant, E_Variable)
|
then
|
then
|
Ren_Obj := Entity (N);
|
Ren_Obj := Entity (N);
|
return Abandon;
|
return Abandon;
|
end if;
|
end if;
|
|
|
return OK;
|
return OK;
|
end Find_Object;
|
end Find_Object;
|
|
|
procedure Search is new Traverse_Proc (Find_Object);
|
procedure Search is new Traverse_Proc (Find_Object);
|
|
|
-- Local variables
|
-- Local variables
|
|
|
Typ : constant Entity_Id := Etype (Defining_Identifier (Ren_Decl));
|
Typ : constant Entity_Id := Etype (Defining_Identifier (Ren_Decl));
|
|
|
-- Start of processing for Find_Renamed_Object
|
-- Start of processing for Find_Renamed_Object
|
|
|
begin
|
begin
|
-- Actions related to dispatching calls may appear as renamings of
|
-- Actions related to dispatching calls may appear as renamings of
|
-- tags. Do not process this type of renaming because it does not
|
-- tags. Do not process this type of renaming because it does not
|
-- use the actual value of the object.
|
-- use the actual value of the object.
|
|
|
if not Is_RTE (Typ, RE_Tag_Ptr) then
|
if not Is_RTE (Typ, RE_Tag_Ptr) then
|
Search (Name (Ren_Decl));
|
Search (Name (Ren_Decl));
|
end if;
|
end if;
|
|
|
return Ren_Obj;
|
return Ren_Obj;
|
end Find_Renamed_Object;
|
end Find_Renamed_Object;
|
|
|
-- Local variables
|
-- Local variables
|
|
|
Expr : Node_Id;
|
Expr : Node_Id;
|
Ren_Obj : Entity_Id;
|
Ren_Obj : Entity_Id;
|
Stmt : Node_Id;
|
Stmt : Node_Id;
|
|
|
-- Start of processing for Is_Aliased
|
-- Start of processing for Is_Aliased
|
|
|
begin
|
begin
|
Stmt := First_Stmt;
|
Stmt := First_Stmt;
|
while Present (Stmt) loop
|
while Present (Stmt) loop
|
if Nkind (Stmt) = N_Object_Declaration then
|
if Nkind (Stmt) = N_Object_Declaration then
|
Expr := Expression (Stmt);
|
Expr := Expression (Stmt);
|
|
|
if Present (Expr)
|
if Present (Expr)
|
and then Nkind (Expr) = N_Reference
|
and then Nkind (Expr) = N_Reference
|
and then Nkind (Prefix (Expr)) = N_Identifier
|
and then Nkind (Prefix (Expr)) = N_Identifier
|
and then Entity (Prefix (Expr)) = Trans_Id
|
and then Entity (Prefix (Expr)) = Trans_Id
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
elsif Nkind (Stmt) = N_Object_Renaming_Declaration then
|
elsif Nkind (Stmt) = N_Object_Renaming_Declaration then
|
Ren_Obj := Find_Renamed_Object (Stmt);
|
Ren_Obj := Find_Renamed_Object (Stmt);
|
|
|
if Present (Ren_Obj)
|
if Present (Ren_Obj)
|
and then Ren_Obj = Trans_Id
|
and then Ren_Obj = Trans_Id
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Next (Stmt);
|
Next (Stmt);
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
end Is_Aliased;
|
end Is_Aliased;
|
|
|
------------------
|
------------------
|
-- Is_Allocated --
|
-- Is_Allocated --
|
------------------
|
------------------
|
|
|
function Is_Allocated (Trans_Id : Entity_Id) return Boolean is
|
function Is_Allocated (Trans_Id : Entity_Id) return Boolean is
|
Expr : constant Node_Id := Expression (Parent (Trans_Id));
|
Expr : constant Node_Id := Expression (Parent (Trans_Id));
|
begin
|
begin
|
return
|
return
|
Is_Access_Type (Etype (Trans_Id))
|
Is_Access_Type (Etype (Trans_Id))
|
and then Present (Expr)
|
and then Present (Expr)
|
and then Nkind (Expr) = N_Allocator;
|
and then Nkind (Expr) = N_Allocator;
|
end Is_Allocated;
|
end Is_Allocated;
|
|
|
---------------------------
|
---------------------------
|
-- Is_Iterated_Container --
|
-- Is_Iterated_Container --
|
---------------------------
|
---------------------------
|
|
|
function Is_Iterated_Container
|
function Is_Iterated_Container
|
(Trans_Id : Entity_Id;
|
(Trans_Id : Entity_Id;
|
First_Stmt : Node_Id) return Boolean
|
First_Stmt : Node_Id) return Boolean
|
is
|
is
|
Aspect : Node_Id;
|
Aspect : Node_Id;
|
Call : Node_Id;
|
Call : Node_Id;
|
Iter : Entity_Id;
|
Iter : Entity_Id;
|
Param : Node_Id;
|
Param : Node_Id;
|
Stmt : Node_Id;
|
Stmt : Node_Id;
|
Typ : Entity_Id;
|
Typ : Entity_Id;
|
|
|
begin
|
begin
|
-- It is not possible to iterate over containers in non-Ada 2012 code
|
-- It is not possible to iterate over containers in non-Ada 2012 code
|
|
|
if Ada_Version < Ada_2012 then
|
if Ada_Version < Ada_2012 then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
Typ := Etype (Trans_Id);
|
Typ := Etype (Trans_Id);
|
|
|
-- Handle access type created for secondary stack use
|
-- Handle access type created for secondary stack use
|
|
|
if Is_Access_Type (Typ) then
|
if Is_Access_Type (Typ) then
|
Typ := Designated_Type (Typ);
|
Typ := Designated_Type (Typ);
|
end if;
|
end if;
|
|
|
-- Look for aspect Default_Iterator
|
-- Look for aspect Default_Iterator
|
|
|
if Has_Aspects (Parent (Typ)) then
|
if Has_Aspects (Parent (Typ)) then
|
Aspect := Find_Aspect (Typ, Aspect_Default_Iterator);
|
Aspect := Find_Aspect (Typ, Aspect_Default_Iterator);
|
|
|
if Present (Aspect) then
|
if Present (Aspect) then
|
Iter := Entity (Aspect);
|
Iter := Entity (Aspect);
|
|
|
-- Examine the statements following the container object and
|
-- Examine the statements following the container object and
|
-- look for a call to the default iterate routine where the
|
-- look for a call to the default iterate routine where the
|
-- first parameter is the transient. Such a call appears as:
|
-- first parameter is the transient. Such a call appears as:
|
|
|
-- It : Access_To_CW_Iterator :=
|
-- It : Access_To_CW_Iterator :=
|
-- Iterate (Tran_Id.all, ...)'reference;
|
-- Iterate (Tran_Id.all, ...)'reference;
|
|
|
Stmt := First_Stmt;
|
Stmt := First_Stmt;
|
while Present (Stmt) loop
|
while Present (Stmt) loop
|
|
|
-- Detect an object declaration which is initialized by a
|
-- Detect an object declaration which is initialized by a
|
-- secondary stack function call.
|
-- secondary stack function call.
|
|
|
if Nkind (Stmt) = N_Object_Declaration
|
if Nkind (Stmt) = N_Object_Declaration
|
and then Present (Expression (Stmt))
|
and then Present (Expression (Stmt))
|
and then Nkind (Expression (Stmt)) = N_Reference
|
and then Nkind (Expression (Stmt)) = N_Reference
|
and then Nkind (Prefix (Expression (Stmt))) =
|
and then Nkind (Prefix (Expression (Stmt))) =
|
N_Function_Call
|
N_Function_Call
|
then
|
then
|
Call := Prefix (Expression (Stmt));
|
Call := Prefix (Expression (Stmt));
|
|
|
-- The call must invoke the default iterate routine of
|
-- The call must invoke the default iterate routine of
|
-- the container and the transient object must appear as
|
-- the container and the transient object must appear as
|
-- the first actual parameter. Skip any calls whose names
|
-- the first actual parameter. Skip any calls whose names
|
-- are not entities.
|
-- are not entities.
|
|
|
if Is_Entity_Name (Name (Call))
|
if Is_Entity_Name (Name (Call))
|
and then Entity (Name (Call)) = Iter
|
and then Entity (Name (Call)) = Iter
|
and then Present (Parameter_Associations (Call))
|
and then Present (Parameter_Associations (Call))
|
then
|
then
|
Param := First (Parameter_Associations (Call));
|
Param := First (Parameter_Associations (Call));
|
|
|
if Nkind (Param) = N_Explicit_Dereference
|
if Nkind (Param) = N_Explicit_Dereference
|
and then Entity (Prefix (Param)) = Trans_Id
|
and then Entity (Prefix (Param)) = Trans_Id
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Next (Stmt);
|
Next (Stmt);
|
end loop;
|
end loop;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
return False;
|
return False;
|
end Is_Iterated_Container;
|
end Is_Iterated_Container;
|
|
|
-- Start of processing for Is_Finalizable_Transient
|
-- Start of processing for Is_Finalizable_Transient
|
|
|
begin
|
begin
|
-- Handle access types
|
-- Handle access types
|
|
|
if Is_Access_Type (Desig) then
|
if Is_Access_Type (Desig) then
|
Desig := Available_View (Designated_Type (Desig));
|
Desig := Available_View (Designated_Type (Desig));
|
end if;
|
end if;
|
|
|
return
|
return
|
Ekind_In (Obj_Id, E_Constant, E_Variable)
|
Ekind_In (Obj_Id, E_Constant, E_Variable)
|
and then Needs_Finalization (Desig)
|
and then Needs_Finalization (Desig)
|
and then Requires_Transient_Scope (Desig)
|
and then Requires_Transient_Scope (Desig)
|
and then Nkind (Rel_Node) /= N_Simple_Return_Statement
|
and then Nkind (Rel_Node) /= N_Simple_Return_Statement
|
|
|
-- Do not consider renamed or 'reference-d transient objects because
|
-- Do not consider renamed or 'reference-d transient objects because
|
-- the act of renaming extends the object's lifetime.
|
-- the act of renaming extends the object's lifetime.
|
|
|
and then not Is_Aliased (Obj_Id, Decl)
|
and then not Is_Aliased (Obj_Id, Decl)
|
|
|
-- Do not consider transient objects allocated on the heap since
|
-- Do not consider transient objects allocated on the heap since
|
-- they are attached to a finalization master.
|
-- they are attached to a finalization master.
|
|
|
and then not Is_Allocated (Obj_Id)
|
and then not Is_Allocated (Obj_Id)
|
|
|
-- If the transient object is a pointer, check that it is not
|
-- If the transient object is a pointer, check that it is not
|
-- initialized by a function which returns a pointer or acts as a
|
-- initialized by a function which returns a pointer or acts as a
|
-- renaming of another pointer.
|
-- renaming of another pointer.
|
|
|
and then
|
and then
|
(not Is_Access_Type (Obj_Typ)
|
(not Is_Access_Type (Obj_Typ)
|
or else not Initialized_By_Access (Obj_Id))
|
or else not Initialized_By_Access (Obj_Id))
|
|
|
-- Do not consider transient objects which act as indirect aliases
|
-- Do not consider transient objects which act as indirect aliases
|
-- of build-in-place function results.
|
-- of build-in-place function results.
|
|
|
and then not Initialized_By_Aliased_BIP_Func_Call (Obj_Id)
|
and then not Initialized_By_Aliased_BIP_Func_Call (Obj_Id)
|
|
|
-- Do not consider conversions of tags to class-wide types
|
-- Do not consider conversions of tags to class-wide types
|
|
|
and then not Is_Tag_To_Class_Wide_Conversion (Obj_Id)
|
and then not Is_Tag_To_Class_Wide_Conversion (Obj_Id)
|
|
|
-- Do not consider containers in the context of iterator loops. Such
|
-- Do not consider containers in the context of iterator loops. Such
|
-- transient objects must exist for as long as the loop is around,
|
-- transient objects must exist for as long as the loop is around,
|
-- otherwise any operation carried out by the iterator will fail.
|
-- otherwise any operation carried out by the iterator will fail.
|
|
|
and then not Is_Iterated_Container (Obj_Id, Decl);
|
and then not Is_Iterated_Container (Obj_Id, Decl);
|
end Is_Finalizable_Transient;
|
end Is_Finalizable_Transient;
|
|
|
---------------------------------
|
---------------------------------
|
-- Is_Fully_Repped_Tagged_Type --
|
-- Is_Fully_Repped_Tagged_Type --
|
---------------------------------
|
---------------------------------
|
|
|
function Is_Fully_Repped_Tagged_Type (T : Entity_Id) return Boolean is
|
function Is_Fully_Repped_Tagged_Type (T : Entity_Id) return Boolean is
|
U : constant Entity_Id := Underlying_Type (T);
|
U : constant Entity_Id := Underlying_Type (T);
|
Comp : Entity_Id;
|
Comp : Entity_Id;
|
|
|
begin
|
begin
|
if No (U) or else not Is_Tagged_Type (U) then
|
if No (U) or else not Is_Tagged_Type (U) then
|
return False;
|
return False;
|
elsif Has_Discriminants (U) then
|
elsif Has_Discriminants (U) then
|
return False;
|
return False;
|
elsif not Has_Specified_Layout (U) then
|
elsif not Has_Specified_Layout (U) then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
-- Here we have a tagged type, see if it has any unlayed out fields
|
-- Here we have a tagged type, see if it has any unlayed out fields
|
-- other than a possible tag and parent fields. If so, we return False.
|
-- other than a possible tag and parent fields. If so, we return False.
|
|
|
Comp := First_Component (U);
|
Comp := First_Component (U);
|
while Present (Comp) loop
|
while Present (Comp) loop
|
if not Is_Tag (Comp)
|
if not Is_Tag (Comp)
|
and then Chars (Comp) /= Name_uParent
|
and then Chars (Comp) /= Name_uParent
|
and then No (Component_Clause (Comp))
|
and then No (Component_Clause (Comp))
|
then
|
then
|
return False;
|
return False;
|
else
|
else
|
Next_Component (Comp);
|
Next_Component (Comp);
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
-- All components are layed out
|
-- All components are layed out
|
|
|
return True;
|
return True;
|
end Is_Fully_Repped_Tagged_Type;
|
end Is_Fully_Repped_Tagged_Type;
|
|
|
----------------------------------
|
----------------------------------
|
-- Is_Library_Level_Tagged_Type --
|
-- Is_Library_Level_Tagged_Type --
|
----------------------------------
|
----------------------------------
|
|
|
function Is_Library_Level_Tagged_Type (Typ : Entity_Id) return Boolean is
|
function Is_Library_Level_Tagged_Type (Typ : Entity_Id) return Boolean is
|
begin
|
begin
|
return Is_Tagged_Type (Typ)
|
return Is_Tagged_Type (Typ)
|
and then Is_Library_Level_Entity (Typ);
|
and then Is_Library_Level_Entity (Typ);
|
end Is_Library_Level_Tagged_Type;
|
end Is_Library_Level_Tagged_Type;
|
|
|
----------------------------------
|
----------------------------------
|
-- Is_Null_Access_BIP_Func_Call --
|
-- Is_Null_Access_BIP_Func_Call --
|
----------------------------------
|
----------------------------------
|
|
|
function Is_Null_Access_BIP_Func_Call (Expr : Node_Id) return Boolean is
|
function Is_Null_Access_BIP_Func_Call (Expr : Node_Id) return Boolean is
|
Call : Node_Id := Expr;
|
Call : Node_Id := Expr;
|
|
|
begin
|
begin
|
-- Build-in-place calls usually appear in 'reference format
|
-- Build-in-place calls usually appear in 'reference format
|
|
|
if Nkind (Call) = N_Reference then
|
if Nkind (Call) = N_Reference then
|
Call := Prefix (Call);
|
Call := Prefix (Call);
|
end if;
|
end if;
|
|
|
if Nkind_In (Call, N_Qualified_Expression,
|
if Nkind_In (Call, N_Qualified_Expression,
|
N_Unchecked_Type_Conversion)
|
N_Unchecked_Type_Conversion)
|
then
|
then
|
Call := Expression (Call);
|
Call := Expression (Call);
|
end if;
|
end if;
|
|
|
if Is_Build_In_Place_Function_Call (Call) then
|
if Is_Build_In_Place_Function_Call (Call) then
|
declare
|
declare
|
Access_Nam : Name_Id := No_Name;
|
Access_Nam : Name_Id := No_Name;
|
Actual : Node_Id;
|
Actual : Node_Id;
|
Param : Node_Id;
|
Param : Node_Id;
|
Formal : Node_Id;
|
Formal : Node_Id;
|
|
|
begin
|
begin
|
-- Examine all parameter associations of the function call
|
-- Examine all parameter associations of the function call
|
|
|
Param := First (Parameter_Associations (Call));
|
Param := First (Parameter_Associations (Call));
|
while Present (Param) loop
|
while Present (Param) loop
|
if Nkind (Param) = N_Parameter_Association
|
if Nkind (Param) = N_Parameter_Association
|
and then Nkind (Selector_Name (Param)) = N_Identifier
|
and then Nkind (Selector_Name (Param)) = N_Identifier
|
then
|
then
|
Formal := Selector_Name (Param);
|
Formal := Selector_Name (Param);
|
Actual := Explicit_Actual_Parameter (Param);
|
Actual := Explicit_Actual_Parameter (Param);
|
|
|
-- Construct the name of formal BIPaccess. It is much easier
|
-- Construct the name of formal BIPaccess. It is much easier
|
-- to extract the name of the function using an arbitrary
|
-- to extract the name of the function using an arbitrary
|
-- formal's scope rather than the Name field of Call.
|
-- formal's scope rather than the Name field of Call.
|
|
|
if Access_Nam = No_Name
|
if Access_Nam = No_Name
|
and then Present (Entity (Formal))
|
and then Present (Entity (Formal))
|
then
|
then
|
Access_Nam :=
|
Access_Nam :=
|
New_External_Name
|
New_External_Name
|
(Chars (Scope (Entity (Formal))),
|
(Chars (Scope (Entity (Formal))),
|
BIP_Formal_Suffix (BIP_Object_Access));
|
BIP_Formal_Suffix (BIP_Object_Access));
|
end if;
|
end if;
|
|
|
-- A match for BIPaccess => null has been found
|
-- A match for BIPaccess => null has been found
|
|
|
if Chars (Formal) = Access_Nam
|
if Chars (Formal) = Access_Nam
|
and then Nkind (Actual) = N_Null
|
and then Nkind (Actual) = N_Null
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Next (Param);
|
Next (Param);
|
end loop;
|
end loop;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
return False;
|
return False;
|
end Is_Null_Access_BIP_Func_Call;
|
end Is_Null_Access_BIP_Func_Call;
|
|
|
--------------------------
|
--------------------------
|
-- Is_Non_BIP_Func_Call --
|
-- Is_Non_BIP_Func_Call --
|
--------------------------
|
--------------------------
|
|
|
function Is_Non_BIP_Func_Call (Expr : Node_Id) return Boolean is
|
function Is_Non_BIP_Func_Call (Expr : Node_Id) return Boolean is
|
begin
|
begin
|
-- The expected call is of the format
|
-- The expected call is of the format
|
--
|
--
|
-- Func_Call'reference
|
-- Func_Call'reference
|
|
|
return
|
return
|
Nkind (Expr) = N_Reference
|
Nkind (Expr) = N_Reference
|
and then Nkind (Prefix (Expr)) = N_Function_Call
|
and then Nkind (Prefix (Expr)) = N_Function_Call
|
and then not Is_Build_In_Place_Function_Call (Prefix (Expr));
|
and then not Is_Build_In_Place_Function_Call (Prefix (Expr));
|
end Is_Non_BIP_Func_Call;
|
end Is_Non_BIP_Func_Call;
|
|
|
----------------------------------
|
----------------------------------
|
-- Is_Possibly_Unaligned_Object --
|
-- Is_Possibly_Unaligned_Object --
|
----------------------------------
|
----------------------------------
|
|
|
function Is_Possibly_Unaligned_Object (N : Node_Id) return Boolean is
|
function Is_Possibly_Unaligned_Object (N : Node_Id) return Boolean is
|
T : constant Entity_Id := Etype (N);
|
T : constant Entity_Id := Etype (N);
|
|
|
begin
|
begin
|
-- If renamed object, apply test to underlying object
|
-- If renamed object, apply test to underlying object
|
|
|
if Is_Entity_Name (N)
|
if Is_Entity_Name (N)
|
and then Is_Object (Entity (N))
|
and then Is_Object (Entity (N))
|
and then Present (Renamed_Object (Entity (N)))
|
and then Present (Renamed_Object (Entity (N)))
|
then
|
then
|
return Is_Possibly_Unaligned_Object (Renamed_Object (Entity (N)));
|
return Is_Possibly_Unaligned_Object (Renamed_Object (Entity (N)));
|
end if;
|
end if;
|
|
|
-- Tagged and controlled types and aliased types are always aligned, as
|
-- Tagged and controlled types and aliased types are always aligned, as
|
-- are concurrent types.
|
-- are concurrent types.
|
|
|
if Is_Aliased (T)
|
if Is_Aliased (T)
|
or else Has_Controlled_Component (T)
|
or else Has_Controlled_Component (T)
|
or else Is_Concurrent_Type (T)
|
or else Is_Concurrent_Type (T)
|
or else Is_Tagged_Type (T)
|
or else Is_Tagged_Type (T)
|
or else Is_Controlled (T)
|
or else Is_Controlled (T)
|
then
|
then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
-- If this is an element of a packed array, may be unaligned
|
-- If this is an element of a packed array, may be unaligned
|
|
|
if Is_Ref_To_Bit_Packed_Array (N) then
|
if Is_Ref_To_Bit_Packed_Array (N) then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- Case of indexed component reference: test whether prefix is unaligned
|
-- Case of indexed component reference: test whether prefix is unaligned
|
|
|
if Nkind (N) = N_Indexed_Component then
|
if Nkind (N) = N_Indexed_Component then
|
return Is_Possibly_Unaligned_Object (Prefix (N));
|
return Is_Possibly_Unaligned_Object (Prefix (N));
|
|
|
-- Case of selected component reference
|
-- Case of selected component reference
|
|
|
elsif Nkind (N) = N_Selected_Component then
|
elsif Nkind (N) = N_Selected_Component then
|
declare
|
declare
|
P : constant Node_Id := Prefix (N);
|
P : constant Node_Id := Prefix (N);
|
C : constant Entity_Id := Entity (Selector_Name (N));
|
C : constant Entity_Id := Entity (Selector_Name (N));
|
M : Nat;
|
M : Nat;
|
S : Nat;
|
S : Nat;
|
|
|
begin
|
begin
|
-- If component reference is for an array with non-static bounds,
|
-- If component reference is for an array with non-static bounds,
|
-- then it is always aligned: we can only process unaligned arrays
|
-- then it is always aligned: we can only process unaligned arrays
|
-- with static bounds (more precisely compile time known bounds).
|
-- with static bounds (more precisely compile time known bounds).
|
|
|
if Is_Array_Type (T)
|
if Is_Array_Type (T)
|
and then not Compile_Time_Known_Bounds (T)
|
and then not Compile_Time_Known_Bounds (T)
|
then
|
then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
-- If component is aliased, it is definitely properly aligned
|
-- If component is aliased, it is definitely properly aligned
|
|
|
if Is_Aliased (C) then
|
if Is_Aliased (C) then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
-- If component is for a type implemented as a scalar, and the
|
-- If component is for a type implemented as a scalar, and the
|
-- record is packed, and the component is other than the first
|
-- record is packed, and the component is other than the first
|
-- component of the record, then the component may be unaligned.
|
-- component of the record, then the component may be unaligned.
|
|
|
if Is_Packed (Etype (P))
|
if Is_Packed (Etype (P))
|
and then Represented_As_Scalar (Etype (C))
|
and then Represented_As_Scalar (Etype (C))
|
and then First_Entity (Scope (C)) /= C
|
and then First_Entity (Scope (C)) /= C
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- Compute maximum possible alignment for T
|
-- Compute maximum possible alignment for T
|
|
|
-- If alignment is known, then that settles things
|
-- If alignment is known, then that settles things
|
|
|
if Known_Alignment (T) then
|
if Known_Alignment (T) then
|
M := UI_To_Int (Alignment (T));
|
M := UI_To_Int (Alignment (T));
|
|
|
-- If alignment is not known, tentatively set max alignment
|
-- If alignment is not known, tentatively set max alignment
|
|
|
else
|
else
|
M := Ttypes.Maximum_Alignment;
|
M := Ttypes.Maximum_Alignment;
|
|
|
-- We can reduce this if the Esize is known since the default
|
-- We can reduce this if the Esize is known since the default
|
-- alignment will never be more than the smallest power of 2
|
-- alignment will never be more than the smallest power of 2
|
-- that does not exceed this Esize value.
|
-- that does not exceed this Esize value.
|
|
|
if Known_Esize (T) then
|
if Known_Esize (T) then
|
S := UI_To_Int (Esize (T));
|
S := UI_To_Int (Esize (T));
|
|
|
while (M / 2) >= S loop
|
while (M / 2) >= S loop
|
M := M / 2;
|
M := M / 2;
|
end loop;
|
end loop;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- The following code is historical, it used to be present but it
|
-- The following code is historical, it used to be present but it
|
-- is too cautious, because the front-end does not know the proper
|
-- is too cautious, because the front-end does not know the proper
|
-- default alignments for the target. Also, if the alignment is
|
-- default alignments for the target. Also, if the alignment is
|
-- not known, the front end can't know in any case! If a copy is
|
-- not known, the front end can't know in any case! If a copy is
|
-- needed, the back-end will take care of it. This whole section
|
-- needed, the back-end will take care of it. This whole section
|
-- including this comment can be removed later ???
|
-- including this comment can be removed later ???
|
|
|
-- If the component reference is for a record that has a specified
|
-- If the component reference is for a record that has a specified
|
-- alignment, and we either know it is too small, or cannot tell,
|
-- alignment, and we either know it is too small, or cannot tell,
|
-- then the component may be unaligned.
|
-- then the component may be unaligned.
|
|
|
-- What is the following commented out code ???
|
-- What is the following commented out code ???
|
|
|
-- if Known_Alignment (Etype (P))
|
-- if Known_Alignment (Etype (P))
|
-- and then Alignment (Etype (P)) < Ttypes.Maximum_Alignment
|
-- and then Alignment (Etype (P)) < Ttypes.Maximum_Alignment
|
-- and then M > Alignment (Etype (P))
|
-- and then M > Alignment (Etype (P))
|
-- then
|
-- then
|
-- return True;
|
-- return True;
|
-- end if;
|
-- end if;
|
|
|
-- Case of component clause present which may specify an
|
-- Case of component clause present which may specify an
|
-- unaligned position.
|
-- unaligned position.
|
|
|
if Present (Component_Clause (C)) then
|
if Present (Component_Clause (C)) then
|
|
|
-- Otherwise we can do a test to make sure that the actual
|
-- Otherwise we can do a test to make sure that the actual
|
-- start position in the record, and the length, are both
|
-- start position in the record, and the length, are both
|
-- consistent with the required alignment. If not, we know
|
-- consistent with the required alignment. If not, we know
|
-- that we are unaligned.
|
-- that we are unaligned.
|
|
|
declare
|
declare
|
Align_In_Bits : constant Nat := M * System_Storage_Unit;
|
Align_In_Bits : constant Nat := M * System_Storage_Unit;
|
begin
|
begin
|
if Component_Bit_Offset (C) mod Align_In_Bits /= 0
|
if Component_Bit_Offset (C) mod Align_In_Bits /= 0
|
or else Esize (C) mod Align_In_Bits /= 0
|
or else Esize (C) mod Align_In_Bits /= 0
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
-- Otherwise, for a component reference, test prefix
|
-- Otherwise, for a component reference, test prefix
|
|
|
return Is_Possibly_Unaligned_Object (P);
|
return Is_Possibly_Unaligned_Object (P);
|
end;
|
end;
|
|
|
-- If not a component reference, must be aligned
|
-- If not a component reference, must be aligned
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Is_Possibly_Unaligned_Object;
|
end Is_Possibly_Unaligned_Object;
|
|
|
---------------------------------
|
---------------------------------
|
-- Is_Possibly_Unaligned_Slice --
|
-- Is_Possibly_Unaligned_Slice --
|
---------------------------------
|
---------------------------------
|
|
|
function Is_Possibly_Unaligned_Slice (N : Node_Id) return Boolean is
|
function Is_Possibly_Unaligned_Slice (N : Node_Id) return Boolean is
|
begin
|
begin
|
-- Go to renamed object
|
-- Go to renamed object
|
|
|
if Is_Entity_Name (N)
|
if Is_Entity_Name (N)
|
and then Is_Object (Entity (N))
|
and then Is_Object (Entity (N))
|
and then Present (Renamed_Object (Entity (N)))
|
and then Present (Renamed_Object (Entity (N)))
|
then
|
then
|
return Is_Possibly_Unaligned_Slice (Renamed_Object (Entity (N)));
|
return Is_Possibly_Unaligned_Slice (Renamed_Object (Entity (N)));
|
end if;
|
end if;
|
|
|
-- The reference must be a slice
|
-- The reference must be a slice
|
|
|
if Nkind (N) /= N_Slice then
|
if Nkind (N) /= N_Slice then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
-- Always assume the worst for a nested record component with a
|
-- Always assume the worst for a nested record component with a
|
-- component clause, which gigi/gcc does not appear to handle well.
|
-- component clause, which gigi/gcc does not appear to handle well.
|
-- It is not clear why this special test is needed at all ???
|
-- It is not clear why this special test is needed at all ???
|
|
|
if Nkind (Prefix (N)) = N_Selected_Component
|
if Nkind (Prefix (N)) = N_Selected_Component
|
and then Nkind (Prefix (Prefix (N))) = N_Selected_Component
|
and then Nkind (Prefix (Prefix (N))) = N_Selected_Component
|
and then
|
and then
|
Present (Component_Clause (Entity (Selector_Name (Prefix (N)))))
|
Present (Component_Clause (Entity (Selector_Name (Prefix (N)))))
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- We only need to worry if the target has strict alignment
|
-- We only need to worry if the target has strict alignment
|
|
|
if not Target_Strict_Alignment then
|
if not Target_Strict_Alignment then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
-- If it is a slice, then look at the array type being sliced
|
-- If it is a slice, then look at the array type being sliced
|
|
|
declare
|
declare
|
Sarr : constant Node_Id := Prefix (N);
|
Sarr : constant Node_Id := Prefix (N);
|
-- Prefix of the slice, i.e. the array being sliced
|
-- Prefix of the slice, i.e. the array being sliced
|
|
|
Styp : constant Entity_Id := Etype (Prefix (N));
|
Styp : constant Entity_Id := Etype (Prefix (N));
|
-- Type of the array being sliced
|
-- Type of the array being sliced
|
|
|
Pref : Node_Id;
|
Pref : Node_Id;
|
Ptyp : Entity_Id;
|
Ptyp : Entity_Id;
|
|
|
begin
|
begin
|
-- The problems arise if the array object that is being sliced
|
-- The problems arise if the array object that is being sliced
|
-- is a component of a record or array, and we cannot guarantee
|
-- is a component of a record or array, and we cannot guarantee
|
-- the alignment of the array within its containing object.
|
-- the alignment of the array within its containing object.
|
|
|
-- To investigate this, we look at successive prefixes to see
|
-- To investigate this, we look at successive prefixes to see
|
-- if we have a worrisome indexed or selected component.
|
-- if we have a worrisome indexed or selected component.
|
|
|
Pref := Sarr;
|
Pref := Sarr;
|
loop
|
loop
|
-- Case of array is part of an indexed component reference
|
-- Case of array is part of an indexed component reference
|
|
|
if Nkind (Pref) = N_Indexed_Component then
|
if Nkind (Pref) = N_Indexed_Component then
|
Ptyp := Etype (Prefix (Pref));
|
Ptyp := Etype (Prefix (Pref));
|
|
|
-- The only problematic case is when the array is packed, in
|
-- The only problematic case is when the array is packed, in
|
-- which case we really know nothing about the alignment of
|
-- which case we really know nothing about the alignment of
|
-- individual components.
|
-- individual components.
|
|
|
if Is_Bit_Packed_Array (Ptyp) then
|
if Is_Bit_Packed_Array (Ptyp) then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- Case of array is part of a selected component reference
|
-- Case of array is part of a selected component reference
|
|
|
elsif Nkind (Pref) = N_Selected_Component then
|
elsif Nkind (Pref) = N_Selected_Component then
|
Ptyp := Etype (Prefix (Pref));
|
Ptyp := Etype (Prefix (Pref));
|
|
|
-- We are definitely in trouble if the record in question
|
-- We are definitely in trouble if the record in question
|
-- has an alignment, and either we know this alignment is
|
-- has an alignment, and either we know this alignment is
|
-- inconsistent with the alignment of the slice, or we don't
|
-- inconsistent with the alignment of the slice, or we don't
|
-- know what the alignment of the slice should be.
|
-- know what the alignment of the slice should be.
|
|
|
if Known_Alignment (Ptyp)
|
if Known_Alignment (Ptyp)
|
and then (Unknown_Alignment (Styp)
|
and then (Unknown_Alignment (Styp)
|
or else Alignment (Styp) > Alignment (Ptyp))
|
or else Alignment (Styp) > Alignment (Ptyp))
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- We are in potential trouble if the record type is packed.
|
-- We are in potential trouble if the record type is packed.
|
-- We could special case when we know that the array is the
|
-- We could special case when we know that the array is the
|
-- first component, but that's not such a simple case ???
|
-- first component, but that's not such a simple case ???
|
|
|
if Is_Packed (Ptyp) then
|
if Is_Packed (Ptyp) then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- We are in trouble if there is a component clause, and
|
-- We are in trouble if there is a component clause, and
|
-- either we do not know the alignment of the slice, or
|
-- either we do not know the alignment of the slice, or
|
-- the alignment of the slice is inconsistent with the
|
-- the alignment of the slice is inconsistent with the
|
-- bit position specified by the component clause.
|
-- bit position specified by the component clause.
|
|
|
declare
|
declare
|
Field : constant Entity_Id := Entity (Selector_Name (Pref));
|
Field : constant Entity_Id := Entity (Selector_Name (Pref));
|
begin
|
begin
|
if Present (Component_Clause (Field))
|
if Present (Component_Clause (Field))
|
and then
|
and then
|
(Unknown_Alignment (Styp)
|
(Unknown_Alignment (Styp)
|
or else
|
or else
|
(Component_Bit_Offset (Field) mod
|
(Component_Bit_Offset (Field) mod
|
(System_Storage_Unit * Alignment (Styp))) /= 0)
|
(System_Storage_Unit * Alignment (Styp))) /= 0)
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
end;
|
end;
|
|
|
-- For cases other than selected or indexed components we know we
|
-- For cases other than selected or indexed components we know we
|
-- are OK, since no issues arise over alignment.
|
-- are OK, since no issues arise over alignment.
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
-- We processed an indexed component or selected component
|
-- We processed an indexed component or selected component
|
-- reference that looked safe, so keep checking prefixes.
|
-- reference that looked safe, so keep checking prefixes.
|
|
|
Pref := Prefix (Pref);
|
Pref := Prefix (Pref);
|
end loop;
|
end loop;
|
end;
|
end;
|
end Is_Possibly_Unaligned_Slice;
|
end Is_Possibly_Unaligned_Slice;
|
|
|
-------------------------------
|
-------------------------------
|
-- Is_Related_To_Func_Return --
|
-- Is_Related_To_Func_Return --
|
-------------------------------
|
-------------------------------
|
|
|
function Is_Related_To_Func_Return (Id : Entity_Id) return Boolean is
|
function Is_Related_To_Func_Return (Id : Entity_Id) return Boolean is
|
Expr : constant Node_Id := Related_Expression (Id);
|
Expr : constant Node_Id := Related_Expression (Id);
|
begin
|
begin
|
return
|
return
|
Present (Expr)
|
Present (Expr)
|
and then Nkind (Expr) = N_Explicit_Dereference
|
and then Nkind (Expr) = N_Explicit_Dereference
|
and then Nkind (Parent (Expr)) = N_Simple_Return_Statement;
|
and then Nkind (Parent (Expr)) = N_Simple_Return_Statement;
|
end Is_Related_To_Func_Return;
|
end Is_Related_To_Func_Return;
|
|
|
--------------------------------
|
--------------------------------
|
-- Is_Ref_To_Bit_Packed_Array --
|
-- Is_Ref_To_Bit_Packed_Array --
|
--------------------------------
|
--------------------------------
|
|
|
function Is_Ref_To_Bit_Packed_Array (N : Node_Id) return Boolean is
|
function Is_Ref_To_Bit_Packed_Array (N : Node_Id) return Boolean is
|
Result : Boolean;
|
Result : Boolean;
|
Expr : Node_Id;
|
Expr : Node_Id;
|
|
|
begin
|
begin
|
if Is_Entity_Name (N)
|
if Is_Entity_Name (N)
|
and then Is_Object (Entity (N))
|
and then Is_Object (Entity (N))
|
and then Present (Renamed_Object (Entity (N)))
|
and then Present (Renamed_Object (Entity (N)))
|
then
|
then
|
return Is_Ref_To_Bit_Packed_Array (Renamed_Object (Entity (N)));
|
return Is_Ref_To_Bit_Packed_Array (Renamed_Object (Entity (N)));
|
end if;
|
end if;
|
|
|
if Nkind (N) = N_Indexed_Component
|
if Nkind (N) = N_Indexed_Component
|
or else
|
or else
|
Nkind (N) = N_Selected_Component
|
Nkind (N) = N_Selected_Component
|
then
|
then
|
if Is_Bit_Packed_Array (Etype (Prefix (N))) then
|
if Is_Bit_Packed_Array (Etype (Prefix (N))) then
|
Result := True;
|
Result := True;
|
else
|
else
|
Result := Is_Ref_To_Bit_Packed_Array (Prefix (N));
|
Result := Is_Ref_To_Bit_Packed_Array (Prefix (N));
|
end if;
|
end if;
|
|
|
if Result and then Nkind (N) = N_Indexed_Component then
|
if Result and then Nkind (N) = N_Indexed_Component then
|
Expr := First (Expressions (N));
|
Expr := First (Expressions (N));
|
while Present (Expr) loop
|
while Present (Expr) loop
|
Force_Evaluation (Expr);
|
Force_Evaluation (Expr);
|
Next (Expr);
|
Next (Expr);
|
end loop;
|
end loop;
|
end if;
|
end if;
|
|
|
return Result;
|
return Result;
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Is_Ref_To_Bit_Packed_Array;
|
end Is_Ref_To_Bit_Packed_Array;
|
|
|
--------------------------------
|
--------------------------------
|
-- Is_Ref_To_Bit_Packed_Slice --
|
-- Is_Ref_To_Bit_Packed_Slice --
|
--------------------------------
|
--------------------------------
|
|
|
function Is_Ref_To_Bit_Packed_Slice (N : Node_Id) return Boolean is
|
function Is_Ref_To_Bit_Packed_Slice (N : Node_Id) return Boolean is
|
begin
|
begin
|
if Nkind (N) = N_Type_Conversion then
|
if Nkind (N) = N_Type_Conversion then
|
return Is_Ref_To_Bit_Packed_Slice (Expression (N));
|
return Is_Ref_To_Bit_Packed_Slice (Expression (N));
|
|
|
elsif Is_Entity_Name (N)
|
elsif Is_Entity_Name (N)
|
and then Is_Object (Entity (N))
|
and then Is_Object (Entity (N))
|
and then Present (Renamed_Object (Entity (N)))
|
and then Present (Renamed_Object (Entity (N)))
|
then
|
then
|
return Is_Ref_To_Bit_Packed_Slice (Renamed_Object (Entity (N)));
|
return Is_Ref_To_Bit_Packed_Slice (Renamed_Object (Entity (N)));
|
|
|
elsif Nkind (N) = N_Slice
|
elsif Nkind (N) = N_Slice
|
and then Is_Bit_Packed_Array (Etype (Prefix (N)))
|
and then Is_Bit_Packed_Array (Etype (Prefix (N)))
|
then
|
then
|
return True;
|
return True;
|
|
|
elsif Nkind (N) = N_Indexed_Component
|
elsif Nkind (N) = N_Indexed_Component
|
or else
|
or else
|
Nkind (N) = N_Selected_Component
|
Nkind (N) = N_Selected_Component
|
then
|
then
|
return Is_Ref_To_Bit_Packed_Slice (Prefix (N));
|
return Is_Ref_To_Bit_Packed_Slice (Prefix (N));
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Is_Ref_To_Bit_Packed_Slice;
|
end Is_Ref_To_Bit_Packed_Slice;
|
|
|
-----------------------
|
-----------------------
|
-- Is_Renamed_Object --
|
-- Is_Renamed_Object --
|
-----------------------
|
-----------------------
|
|
|
function Is_Renamed_Object (N : Node_Id) return Boolean is
|
function Is_Renamed_Object (N : Node_Id) return Boolean is
|
Pnod : constant Node_Id := Parent (N);
|
Pnod : constant Node_Id := Parent (N);
|
Kind : constant Node_Kind := Nkind (Pnod);
|
Kind : constant Node_Kind := Nkind (Pnod);
|
begin
|
begin
|
if Kind = N_Object_Renaming_Declaration then
|
if Kind = N_Object_Renaming_Declaration then
|
return True;
|
return True;
|
elsif Nkind_In (Kind, N_Indexed_Component, N_Selected_Component) then
|
elsif Nkind_In (Kind, N_Indexed_Component, N_Selected_Component) then
|
return Is_Renamed_Object (Pnod);
|
return Is_Renamed_Object (Pnod);
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Is_Renamed_Object;
|
end Is_Renamed_Object;
|
|
|
-------------------------------------
|
-------------------------------------
|
-- Is_Tag_To_Class_Wide_Conversion --
|
-- Is_Tag_To_Class_Wide_Conversion --
|
-------------------------------------
|
-------------------------------------
|
|
|
function Is_Tag_To_Class_Wide_Conversion
|
function Is_Tag_To_Class_Wide_Conversion
|
(Obj_Id : Entity_Id) return Boolean
|
(Obj_Id : Entity_Id) return Boolean
|
is
|
is
|
Expr : constant Node_Id := Expression (Parent (Obj_Id));
|
Expr : constant Node_Id := Expression (Parent (Obj_Id));
|
|
|
begin
|
begin
|
return
|
return
|
Is_Class_Wide_Type (Etype (Obj_Id))
|
Is_Class_Wide_Type (Etype (Obj_Id))
|
and then Present (Expr)
|
and then Present (Expr)
|
and then Nkind (Expr) = N_Unchecked_Type_Conversion
|
and then Nkind (Expr) = N_Unchecked_Type_Conversion
|
and then Etype (Expression (Expr)) = RTE (RE_Tag);
|
and then Etype (Expression (Expr)) = RTE (RE_Tag);
|
end Is_Tag_To_Class_Wide_Conversion;
|
end Is_Tag_To_Class_Wide_Conversion;
|
|
|
----------------------------
|
----------------------------
|
-- Is_Untagged_Derivation --
|
-- Is_Untagged_Derivation --
|
----------------------------
|
----------------------------
|
|
|
function Is_Untagged_Derivation (T : Entity_Id) return Boolean is
|
function Is_Untagged_Derivation (T : Entity_Id) return Boolean is
|
begin
|
begin
|
return (not Is_Tagged_Type (T) and then Is_Derived_Type (T))
|
return (not Is_Tagged_Type (T) and then Is_Derived_Type (T))
|
or else
|
or else
|
(Is_Private_Type (T) and then Present (Full_View (T))
|
(Is_Private_Type (T) and then Present (Full_View (T))
|
and then not Is_Tagged_Type (Full_View (T))
|
and then not Is_Tagged_Type (Full_View (T))
|
and then Is_Derived_Type (Full_View (T))
|
and then Is_Derived_Type (Full_View (T))
|
and then Etype (Full_View (T)) /= T);
|
and then Etype (Full_View (T)) /= T);
|
end Is_Untagged_Derivation;
|
end Is_Untagged_Derivation;
|
|
|
---------------------------
|
---------------------------
|
-- Is_Volatile_Reference --
|
-- Is_Volatile_Reference --
|
---------------------------
|
---------------------------
|
|
|
function Is_Volatile_Reference (N : Node_Id) return Boolean is
|
function Is_Volatile_Reference (N : Node_Id) return Boolean is
|
begin
|
begin
|
if Nkind (N) in N_Has_Etype
|
if Nkind (N) in N_Has_Etype
|
and then Present (Etype (N))
|
and then Present (Etype (N))
|
and then Treat_As_Volatile (Etype (N))
|
and then Treat_As_Volatile (Etype (N))
|
then
|
then
|
return True;
|
return True;
|
|
|
elsif Is_Entity_Name (N) then
|
elsif Is_Entity_Name (N) then
|
return Treat_As_Volatile (Entity (N));
|
return Treat_As_Volatile (Entity (N));
|
|
|
elsif Nkind (N) = N_Slice then
|
elsif Nkind (N) = N_Slice then
|
return Is_Volatile_Reference (Prefix (N));
|
return Is_Volatile_Reference (Prefix (N));
|
|
|
elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
|
elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
|
if (Is_Entity_Name (Prefix (N))
|
if (Is_Entity_Name (Prefix (N))
|
and then Has_Volatile_Components (Entity (Prefix (N))))
|
and then Has_Volatile_Components (Entity (Prefix (N))))
|
or else (Present (Etype (Prefix (N)))
|
or else (Present (Etype (Prefix (N)))
|
and then Has_Volatile_Components (Etype (Prefix (N))))
|
and then Has_Volatile_Components (Etype (Prefix (N))))
|
then
|
then
|
return True;
|
return True;
|
else
|
else
|
return Is_Volatile_Reference (Prefix (N));
|
return Is_Volatile_Reference (Prefix (N));
|
end if;
|
end if;
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Is_Volatile_Reference;
|
end Is_Volatile_Reference;
|
|
|
--------------------------
|
--------------------------
|
-- Is_VM_By_Copy_Actual --
|
-- Is_VM_By_Copy_Actual --
|
--------------------------
|
--------------------------
|
|
|
function Is_VM_By_Copy_Actual (N : Node_Id) return Boolean is
|
function Is_VM_By_Copy_Actual (N : Node_Id) return Boolean is
|
begin
|
begin
|
return VM_Target /= No_VM
|
return VM_Target /= No_VM
|
and then (Nkind (N) = N_Slice
|
and then (Nkind (N) = N_Slice
|
or else
|
or else
|
(Nkind (N) = N_Identifier
|
(Nkind (N) = N_Identifier
|
and then Present (Renamed_Object (Entity (N)))
|
and then Present (Renamed_Object (Entity (N)))
|
and then Nkind (Renamed_Object (Entity (N)))
|
and then Nkind (Renamed_Object (Entity (N)))
|
= N_Slice));
|
= N_Slice));
|
end Is_VM_By_Copy_Actual;
|
end Is_VM_By_Copy_Actual;
|
|
|
--------------------
|
--------------------
|
-- Kill_Dead_Code --
|
-- Kill_Dead_Code --
|
--------------------
|
--------------------
|
|
|
procedure Kill_Dead_Code (N : Node_Id; Warn : Boolean := False) is
|
procedure Kill_Dead_Code (N : Node_Id; Warn : Boolean := False) is
|
W : Boolean := Warn;
|
W : Boolean := Warn;
|
-- Set False if warnings suppressed
|
-- Set False if warnings suppressed
|
|
|
begin
|
begin
|
if Present (N) then
|
if Present (N) then
|
Remove_Warning_Messages (N);
|
Remove_Warning_Messages (N);
|
|
|
-- Generate warning if appropriate
|
-- Generate warning if appropriate
|
|
|
if W then
|
if W then
|
|
|
-- We suppress the warning if this code is under control of an
|
-- We suppress the warning if this code is under control of an
|
-- if statement, whose condition is a simple identifier, and
|
-- if statement, whose condition is a simple identifier, and
|
-- either we are in an instance, or warnings off is set for this
|
-- either we are in an instance, or warnings off is set for this
|
-- identifier. The reason for killing it in the instance case is
|
-- identifier. The reason for killing it in the instance case is
|
-- that it is common and reasonable for code to be deleted in
|
-- that it is common and reasonable for code to be deleted in
|
-- instances for various reasons.
|
-- instances for various reasons.
|
|
|
if Nkind (Parent (N)) = N_If_Statement then
|
if Nkind (Parent (N)) = N_If_Statement then
|
declare
|
declare
|
C : constant Node_Id := Condition (Parent (N));
|
C : constant Node_Id := Condition (Parent (N));
|
begin
|
begin
|
if Nkind (C) = N_Identifier
|
if Nkind (C) = N_Identifier
|
and then
|
and then
|
(In_Instance
|
(In_Instance
|
or else (Present (Entity (C))
|
or else (Present (Entity (C))
|
and then Has_Warnings_Off (Entity (C))))
|
and then Has_Warnings_Off (Entity (C))))
|
then
|
then
|
W := False;
|
W := False;
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
-- Generate warning if not suppressed
|
-- Generate warning if not suppressed
|
|
|
if W then
|
if W then
|
Error_Msg_F
|
Error_Msg_F
|
("?this code can never be executed and has been deleted!", N);
|
("?this code can never be executed and has been deleted!", N);
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- Recurse into block statements and bodies to process declarations
|
-- Recurse into block statements and bodies to process declarations
|
-- and statements.
|
-- and statements.
|
|
|
if Nkind (N) = N_Block_Statement
|
if Nkind (N) = N_Block_Statement
|
or else Nkind (N) = N_Subprogram_Body
|
or else Nkind (N) = N_Subprogram_Body
|
or else Nkind (N) = N_Package_Body
|
or else Nkind (N) = N_Package_Body
|
then
|
then
|
Kill_Dead_Code (Declarations (N), False);
|
Kill_Dead_Code (Declarations (N), False);
|
Kill_Dead_Code (Statements (Handled_Statement_Sequence (N)));
|
Kill_Dead_Code (Statements (Handled_Statement_Sequence (N)));
|
|
|
if Nkind (N) = N_Subprogram_Body then
|
if Nkind (N) = N_Subprogram_Body then
|
Set_Is_Eliminated (Defining_Entity (N));
|
Set_Is_Eliminated (Defining_Entity (N));
|
end if;
|
end if;
|
|
|
elsif Nkind (N) = N_Package_Declaration then
|
elsif Nkind (N) = N_Package_Declaration then
|
Kill_Dead_Code (Visible_Declarations (Specification (N)));
|
Kill_Dead_Code (Visible_Declarations (Specification (N)));
|
Kill_Dead_Code (Private_Declarations (Specification (N)));
|
Kill_Dead_Code (Private_Declarations (Specification (N)));
|
|
|
-- ??? After this point, Delete_Tree has been called on all
|
-- ??? After this point, Delete_Tree has been called on all
|
-- declarations in Specification (N), so references to entities
|
-- declarations in Specification (N), so references to entities
|
-- therein look suspicious.
|
-- therein look suspicious.
|
|
|
declare
|
declare
|
E : Entity_Id := First_Entity (Defining_Entity (N));
|
E : Entity_Id := First_Entity (Defining_Entity (N));
|
begin
|
begin
|
while Present (E) loop
|
while Present (E) loop
|
if Ekind (E) = E_Operator then
|
if Ekind (E) = E_Operator then
|
Set_Is_Eliminated (E);
|
Set_Is_Eliminated (E);
|
end if;
|
end if;
|
|
|
Next_Entity (E);
|
Next_Entity (E);
|
end loop;
|
end loop;
|
end;
|
end;
|
|
|
-- Recurse into composite statement to kill individual statements in
|
-- Recurse into composite statement to kill individual statements in
|
-- particular instantiations.
|
-- particular instantiations.
|
|
|
elsif Nkind (N) = N_If_Statement then
|
elsif Nkind (N) = N_If_Statement then
|
Kill_Dead_Code (Then_Statements (N));
|
Kill_Dead_Code (Then_Statements (N));
|
Kill_Dead_Code (Elsif_Parts (N));
|
Kill_Dead_Code (Elsif_Parts (N));
|
Kill_Dead_Code (Else_Statements (N));
|
Kill_Dead_Code (Else_Statements (N));
|
|
|
elsif Nkind (N) = N_Loop_Statement then
|
elsif Nkind (N) = N_Loop_Statement then
|
Kill_Dead_Code (Statements (N));
|
Kill_Dead_Code (Statements (N));
|
|
|
elsif Nkind (N) = N_Case_Statement then
|
elsif Nkind (N) = N_Case_Statement then
|
declare
|
declare
|
Alt : Node_Id;
|
Alt : Node_Id;
|
begin
|
begin
|
Alt := First (Alternatives (N));
|
Alt := First (Alternatives (N));
|
while Present (Alt) loop
|
while Present (Alt) loop
|
Kill_Dead_Code (Statements (Alt));
|
Kill_Dead_Code (Statements (Alt));
|
Next (Alt);
|
Next (Alt);
|
end loop;
|
end loop;
|
end;
|
end;
|
|
|
elsif Nkind (N) = N_Case_Statement_Alternative then
|
elsif Nkind (N) = N_Case_Statement_Alternative then
|
Kill_Dead_Code (Statements (N));
|
Kill_Dead_Code (Statements (N));
|
|
|
-- Deal with dead instances caused by deleting instantiations
|
-- Deal with dead instances caused by deleting instantiations
|
|
|
elsif Nkind (N) in N_Generic_Instantiation then
|
elsif Nkind (N) in N_Generic_Instantiation then
|
Remove_Dead_Instance (N);
|
Remove_Dead_Instance (N);
|
end if;
|
end if;
|
end if;
|
end if;
|
end Kill_Dead_Code;
|
end Kill_Dead_Code;
|
|
|
-- Case where argument is a list of nodes to be killed
|
-- Case where argument is a list of nodes to be killed
|
|
|
procedure Kill_Dead_Code (L : List_Id; Warn : Boolean := False) is
|
procedure Kill_Dead_Code (L : List_Id; Warn : Boolean := False) is
|
N : Node_Id;
|
N : Node_Id;
|
W : Boolean;
|
W : Boolean;
|
begin
|
begin
|
W := Warn;
|
W := Warn;
|
if Is_Non_Empty_List (L) then
|
if Is_Non_Empty_List (L) then
|
N := First (L);
|
N := First (L);
|
while Present (N) loop
|
while Present (N) loop
|
Kill_Dead_Code (N, W);
|
Kill_Dead_Code (N, W);
|
W := False;
|
W := False;
|
Next (N);
|
Next (N);
|
end loop;
|
end loop;
|
end if;
|
end if;
|
end Kill_Dead_Code;
|
end Kill_Dead_Code;
|
|
|
------------------------
|
------------------------
|
-- Known_Non_Negative --
|
-- Known_Non_Negative --
|
------------------------
|
------------------------
|
|
|
function Known_Non_Negative (Opnd : Node_Id) return Boolean is
|
function Known_Non_Negative (Opnd : Node_Id) return Boolean is
|
begin
|
begin
|
if Is_OK_Static_Expression (Opnd)
|
if Is_OK_Static_Expression (Opnd)
|
and then Expr_Value (Opnd) >= 0
|
and then Expr_Value (Opnd) >= 0
|
then
|
then
|
return True;
|
return True;
|
|
|
else
|
else
|
declare
|
declare
|
Lo : constant Node_Id := Type_Low_Bound (Etype (Opnd));
|
Lo : constant Node_Id := Type_Low_Bound (Etype (Opnd));
|
|
|
begin
|
begin
|
return
|
return
|
Is_OK_Static_Expression (Lo) and then Expr_Value (Lo) >= 0;
|
Is_OK_Static_Expression (Lo) and then Expr_Value (Lo) >= 0;
|
end;
|
end;
|
end if;
|
end if;
|
end Known_Non_Negative;
|
end Known_Non_Negative;
|
|
|
--------------------
|
--------------------
|
-- Known_Non_Null --
|
-- Known_Non_Null --
|
--------------------
|
--------------------
|
|
|
function Known_Non_Null (N : Node_Id) return Boolean is
|
function Known_Non_Null (N : Node_Id) return Boolean is
|
begin
|
begin
|
-- Checks for case where N is an entity reference
|
-- Checks for case where N is an entity reference
|
|
|
if Is_Entity_Name (N) and then Present (Entity (N)) then
|
if Is_Entity_Name (N) and then Present (Entity (N)) then
|
declare
|
declare
|
E : constant Entity_Id := Entity (N);
|
E : constant Entity_Id := Entity (N);
|
Op : Node_Kind;
|
Op : Node_Kind;
|
Val : Node_Id;
|
Val : Node_Id;
|
|
|
begin
|
begin
|
-- First check if we are in decisive conditional
|
-- First check if we are in decisive conditional
|
|
|
Get_Current_Value_Condition (N, Op, Val);
|
Get_Current_Value_Condition (N, Op, Val);
|
|
|
if Known_Null (Val) then
|
if Known_Null (Val) then
|
if Op = N_Op_Eq then
|
if Op = N_Op_Eq then
|
return False;
|
return False;
|
elsif Op = N_Op_Ne then
|
elsif Op = N_Op_Ne then
|
return True;
|
return True;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- If OK to do replacement, test Is_Known_Non_Null flag
|
-- If OK to do replacement, test Is_Known_Non_Null flag
|
|
|
if OK_To_Do_Constant_Replacement (E) then
|
if OK_To_Do_Constant_Replacement (E) then
|
return Is_Known_Non_Null (E);
|
return Is_Known_Non_Null (E);
|
|
|
-- Otherwise if not safe to do replacement, then say so
|
-- Otherwise if not safe to do replacement, then say so
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end;
|
end;
|
|
|
-- True if access attribute
|
-- True if access attribute
|
|
|
elsif Nkind (N) = N_Attribute_Reference
|
elsif Nkind (N) = N_Attribute_Reference
|
and then (Attribute_Name (N) = Name_Access
|
and then (Attribute_Name (N) = Name_Access
|
or else
|
or else
|
Attribute_Name (N) = Name_Unchecked_Access
|
Attribute_Name (N) = Name_Unchecked_Access
|
or else
|
or else
|
Attribute_Name (N) = Name_Unrestricted_Access)
|
Attribute_Name (N) = Name_Unrestricted_Access)
|
then
|
then
|
return True;
|
return True;
|
|
|
-- True if allocator
|
-- True if allocator
|
|
|
elsif Nkind (N) = N_Allocator then
|
elsif Nkind (N) = N_Allocator then
|
return True;
|
return True;
|
|
|
-- For a conversion, true if expression is known non-null
|
-- For a conversion, true if expression is known non-null
|
|
|
elsif Nkind (N) = N_Type_Conversion then
|
elsif Nkind (N) = N_Type_Conversion then
|
return Known_Non_Null (Expression (N));
|
return Known_Non_Null (Expression (N));
|
|
|
-- Above are all cases where the value could be determined to be
|
-- Above are all cases where the value could be determined to be
|
-- non-null. In all other cases, we don't know, so return False.
|
-- non-null. In all other cases, we don't know, so return False.
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Known_Non_Null;
|
end Known_Non_Null;
|
|
|
----------------
|
----------------
|
-- Known_Null --
|
-- Known_Null --
|
----------------
|
----------------
|
|
|
function Known_Null (N : Node_Id) return Boolean is
|
function Known_Null (N : Node_Id) return Boolean is
|
begin
|
begin
|
-- Checks for case where N is an entity reference
|
-- Checks for case where N is an entity reference
|
|
|
if Is_Entity_Name (N) and then Present (Entity (N)) then
|
if Is_Entity_Name (N) and then Present (Entity (N)) then
|
declare
|
declare
|
E : constant Entity_Id := Entity (N);
|
E : constant Entity_Id := Entity (N);
|
Op : Node_Kind;
|
Op : Node_Kind;
|
Val : Node_Id;
|
Val : Node_Id;
|
|
|
begin
|
begin
|
-- Constant null value is for sure null
|
-- Constant null value is for sure null
|
|
|
if Ekind (E) = E_Constant
|
if Ekind (E) = E_Constant
|
and then Known_Null (Constant_Value (E))
|
and then Known_Null (Constant_Value (E))
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- First check if we are in decisive conditional
|
-- First check if we are in decisive conditional
|
|
|
Get_Current_Value_Condition (N, Op, Val);
|
Get_Current_Value_Condition (N, Op, Val);
|
|
|
if Known_Null (Val) then
|
if Known_Null (Val) then
|
if Op = N_Op_Eq then
|
if Op = N_Op_Eq then
|
return True;
|
return True;
|
elsif Op = N_Op_Ne then
|
elsif Op = N_Op_Ne then
|
return False;
|
return False;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- If OK to do replacement, test Is_Known_Null flag
|
-- If OK to do replacement, test Is_Known_Null flag
|
|
|
if OK_To_Do_Constant_Replacement (E) then
|
if OK_To_Do_Constant_Replacement (E) then
|
return Is_Known_Null (E);
|
return Is_Known_Null (E);
|
|
|
-- Otherwise if not safe to do replacement, then say so
|
-- Otherwise if not safe to do replacement, then say so
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end;
|
end;
|
|
|
-- True if explicit reference to null
|
-- True if explicit reference to null
|
|
|
elsif Nkind (N) = N_Null then
|
elsif Nkind (N) = N_Null then
|
return True;
|
return True;
|
|
|
-- For a conversion, true if expression is known null
|
-- For a conversion, true if expression is known null
|
|
|
elsif Nkind (N) = N_Type_Conversion then
|
elsif Nkind (N) = N_Type_Conversion then
|
return Known_Null (Expression (N));
|
return Known_Null (Expression (N));
|
|
|
-- Above are all cases where the value could be determined to be null.
|
-- Above are all cases where the value could be determined to be null.
|
-- In all other cases, we don't know, so return False.
|
-- In all other cases, we don't know, so return False.
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Known_Null;
|
end Known_Null;
|
|
|
-----------------------------
|
-----------------------------
|
-- Make_CW_Equivalent_Type --
|
-- Make_CW_Equivalent_Type --
|
-----------------------------
|
-----------------------------
|
|
|
-- Create a record type used as an equivalent of any member of the class
|
-- Create a record type used as an equivalent of any member of the class
|
-- which takes its size from exp.
|
-- which takes its size from exp.
|
|
|
-- Generate the following code:
|
-- Generate the following code:
|
|
|
-- type Equiv_T is record
|
-- type Equiv_T is record
|
-- _parent : T (List of discriminant constraints taken from Exp);
|
-- _parent : T (List of discriminant constraints taken from Exp);
|
-- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'object_size)/8);
|
-- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'object_size)/8);
|
-- end Equiv_T;
|
-- end Equiv_T;
|
--
|
--
|
-- ??? Note that this type does not guarantee same alignment as all
|
-- ??? Note that this type does not guarantee same alignment as all
|
-- derived types
|
-- derived types
|
|
|
function Make_CW_Equivalent_Type
|
function Make_CW_Equivalent_Type
|
(T : Entity_Id;
|
(T : Entity_Id;
|
E : Node_Id) return Entity_Id
|
E : Node_Id) return Entity_Id
|
is
|
is
|
Loc : constant Source_Ptr := Sloc (E);
|
Loc : constant Source_Ptr := Sloc (E);
|
Root_Typ : constant Entity_Id := Root_Type (T);
|
Root_Typ : constant Entity_Id := Root_Type (T);
|
List_Def : constant List_Id := Empty_List;
|
List_Def : constant List_Id := Empty_List;
|
Comp_List : constant List_Id := New_List;
|
Comp_List : constant List_Id := New_List;
|
Equiv_Type : Entity_Id;
|
Equiv_Type : Entity_Id;
|
Range_Type : Entity_Id;
|
Range_Type : Entity_Id;
|
Str_Type : Entity_Id;
|
Str_Type : Entity_Id;
|
Constr_Root : Entity_Id;
|
Constr_Root : Entity_Id;
|
Sizexpr : Node_Id;
|
Sizexpr : Node_Id;
|
|
|
begin
|
begin
|
-- If the root type is already constrained, there are no discriminants
|
-- If the root type is already constrained, there are no discriminants
|
-- in the expression.
|
-- in the expression.
|
|
|
if not Has_Discriminants (Root_Typ)
|
if not Has_Discriminants (Root_Typ)
|
or else Is_Constrained (Root_Typ)
|
or else Is_Constrained (Root_Typ)
|
then
|
then
|
Constr_Root := Root_Typ;
|
Constr_Root := Root_Typ;
|
else
|
else
|
Constr_Root := Make_Temporary (Loc, 'R');
|
Constr_Root := Make_Temporary (Loc, 'R');
|
|
|
-- subtype cstr__n is T (List of discr constraints taken from Exp)
|
-- subtype cstr__n is T (List of discr constraints taken from Exp)
|
|
|
Append_To (List_Def,
|
Append_To (List_Def,
|
Make_Subtype_Declaration (Loc,
|
Make_Subtype_Declaration (Loc,
|
Defining_Identifier => Constr_Root,
|
Defining_Identifier => Constr_Root,
|
Subtype_Indication => Make_Subtype_From_Expr (E, Root_Typ)));
|
Subtype_Indication => Make_Subtype_From_Expr (E, Root_Typ)));
|
end if;
|
end if;
|
|
|
-- Generate the range subtype declaration
|
-- Generate the range subtype declaration
|
|
|
Range_Type := Make_Temporary (Loc, 'G');
|
Range_Type := Make_Temporary (Loc, 'G');
|
|
|
if not Is_Interface (Root_Typ) then
|
if not Is_Interface (Root_Typ) then
|
|
|
-- subtype rg__xx is
|
-- subtype rg__xx is
|
-- Storage_Offset range 1 .. (Expr'size - typ'size) / Storage_Unit
|
-- Storage_Offset range 1 .. (Expr'size - typ'size) / Storage_Unit
|
|
|
Sizexpr :=
|
Sizexpr :=
|
Make_Op_Subtract (Loc,
|
Make_Op_Subtract (Loc,
|
Left_Opnd =>
|
Left_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix =>
|
Prefix =>
|
OK_Convert_To (T, Duplicate_Subexpr_No_Checks (E)),
|
OK_Convert_To (T, Duplicate_Subexpr_No_Checks (E)),
|
Attribute_Name => Name_Size),
|
Attribute_Name => Name_Size),
|
Right_Opnd =>
|
Right_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix => New_Reference_To (Constr_Root, Loc),
|
Prefix => New_Reference_To (Constr_Root, Loc),
|
Attribute_Name => Name_Object_Size));
|
Attribute_Name => Name_Object_Size));
|
else
|
else
|
-- subtype rg__xx is
|
-- subtype rg__xx is
|
-- Storage_Offset range 1 .. Expr'size / Storage_Unit
|
-- Storage_Offset range 1 .. Expr'size / Storage_Unit
|
|
|
Sizexpr :=
|
Sizexpr :=
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix =>
|
Prefix =>
|
OK_Convert_To (T, Duplicate_Subexpr_No_Checks (E)),
|
OK_Convert_To (T, Duplicate_Subexpr_No_Checks (E)),
|
Attribute_Name => Name_Size);
|
Attribute_Name => Name_Size);
|
end if;
|
end if;
|
|
|
Set_Paren_Count (Sizexpr, 1);
|
Set_Paren_Count (Sizexpr, 1);
|
|
|
Append_To (List_Def,
|
Append_To (List_Def,
|
Make_Subtype_Declaration (Loc,
|
Make_Subtype_Declaration (Loc,
|
Defining_Identifier => Range_Type,
|
Defining_Identifier => Range_Type,
|
Subtype_Indication =>
|
Subtype_Indication =>
|
Make_Subtype_Indication (Loc,
|
Make_Subtype_Indication (Loc,
|
Subtype_Mark => New_Reference_To (RTE (RE_Storage_Offset), Loc),
|
Subtype_Mark => New_Reference_To (RTE (RE_Storage_Offset), Loc),
|
Constraint => Make_Range_Constraint (Loc,
|
Constraint => Make_Range_Constraint (Loc,
|
Range_Expression =>
|
Range_Expression =>
|
Make_Range (Loc,
|
Make_Range (Loc,
|
Low_Bound => Make_Integer_Literal (Loc, 1),
|
Low_Bound => Make_Integer_Literal (Loc, 1),
|
High_Bound =>
|
High_Bound =>
|
Make_Op_Divide (Loc,
|
Make_Op_Divide (Loc,
|
Left_Opnd => Sizexpr,
|
Left_Opnd => Sizexpr,
|
Right_Opnd => Make_Integer_Literal (Loc,
|
Right_Opnd => Make_Integer_Literal (Loc,
|
Intval => System_Storage_Unit)))))));
|
Intval => System_Storage_Unit)))))));
|
|
|
-- subtype str__nn is Storage_Array (rg__x);
|
-- subtype str__nn is Storage_Array (rg__x);
|
|
|
Str_Type := Make_Temporary (Loc, 'S');
|
Str_Type := Make_Temporary (Loc, 'S');
|
Append_To (List_Def,
|
Append_To (List_Def,
|
Make_Subtype_Declaration (Loc,
|
Make_Subtype_Declaration (Loc,
|
Defining_Identifier => Str_Type,
|
Defining_Identifier => Str_Type,
|
Subtype_Indication =>
|
Subtype_Indication =>
|
Make_Subtype_Indication (Loc,
|
Make_Subtype_Indication (Loc,
|
Subtype_Mark => New_Reference_To (RTE (RE_Storage_Array), Loc),
|
Subtype_Mark => New_Reference_To (RTE (RE_Storage_Array), Loc),
|
Constraint =>
|
Constraint =>
|
Make_Index_Or_Discriminant_Constraint (Loc,
|
Make_Index_Or_Discriminant_Constraint (Loc,
|
Constraints =>
|
Constraints =>
|
New_List (New_Reference_To (Range_Type, Loc))))));
|
New_List (New_Reference_To (Range_Type, Loc))))));
|
|
|
-- type Equiv_T is record
|
-- type Equiv_T is record
|
-- [ _parent : Tnn; ]
|
-- [ _parent : Tnn; ]
|
-- E : Str_Type;
|
-- E : Str_Type;
|
-- end Equiv_T;
|
-- end Equiv_T;
|
|
|
Equiv_Type := Make_Temporary (Loc, 'T');
|
Equiv_Type := Make_Temporary (Loc, 'T');
|
Set_Ekind (Equiv_Type, E_Record_Type);
|
Set_Ekind (Equiv_Type, E_Record_Type);
|
Set_Parent_Subtype (Equiv_Type, Constr_Root);
|
Set_Parent_Subtype (Equiv_Type, Constr_Root);
|
|
|
-- Set Is_Class_Wide_Equivalent_Type very early to trigger the special
|
-- Set Is_Class_Wide_Equivalent_Type very early to trigger the special
|
-- treatment for this type. In particular, even though _parent's type
|
-- treatment for this type. In particular, even though _parent's type
|
-- is a controlled type or contains controlled components, we do not
|
-- is a controlled type or contains controlled components, we do not
|
-- want to set Has_Controlled_Component on it to avoid making it gain
|
-- want to set Has_Controlled_Component on it to avoid making it gain
|
-- an unwanted _controller component.
|
-- an unwanted _controller component.
|
|
|
Set_Is_Class_Wide_Equivalent_Type (Equiv_Type);
|
Set_Is_Class_Wide_Equivalent_Type (Equiv_Type);
|
|
|
if not Is_Interface (Root_Typ) then
|
if not Is_Interface (Root_Typ) then
|
Append_To (Comp_List,
|
Append_To (Comp_List,
|
Make_Component_Declaration (Loc,
|
Make_Component_Declaration (Loc,
|
Defining_Identifier =>
|
Defining_Identifier =>
|
Make_Defining_Identifier (Loc, Name_uParent),
|
Make_Defining_Identifier (Loc, Name_uParent),
|
Component_Definition =>
|
Component_Definition =>
|
Make_Component_Definition (Loc,
|
Make_Component_Definition (Loc,
|
Aliased_Present => False,
|
Aliased_Present => False,
|
Subtype_Indication => New_Reference_To (Constr_Root, Loc))));
|
Subtype_Indication => New_Reference_To (Constr_Root, Loc))));
|
end if;
|
end if;
|
|
|
Append_To (Comp_List,
|
Append_To (Comp_List,
|
Make_Component_Declaration (Loc,
|
Make_Component_Declaration (Loc,
|
Defining_Identifier => Make_Temporary (Loc, 'C'),
|
Defining_Identifier => Make_Temporary (Loc, 'C'),
|
Component_Definition =>
|
Component_Definition =>
|
Make_Component_Definition (Loc,
|
Make_Component_Definition (Loc,
|
Aliased_Present => False,
|
Aliased_Present => False,
|
Subtype_Indication => New_Reference_To (Str_Type, Loc))));
|
Subtype_Indication => New_Reference_To (Str_Type, Loc))));
|
|
|
Append_To (List_Def,
|
Append_To (List_Def,
|
Make_Full_Type_Declaration (Loc,
|
Make_Full_Type_Declaration (Loc,
|
Defining_Identifier => Equiv_Type,
|
Defining_Identifier => Equiv_Type,
|
Type_Definition =>
|
Type_Definition =>
|
Make_Record_Definition (Loc,
|
Make_Record_Definition (Loc,
|
Component_List =>
|
Component_List =>
|
Make_Component_List (Loc,
|
Make_Component_List (Loc,
|
Component_Items => Comp_List,
|
Component_Items => Comp_List,
|
Variant_Part => Empty))));
|
Variant_Part => Empty))));
|
|
|
-- Suppress all checks during the analysis of the expanded code to avoid
|
-- Suppress all checks during the analysis of the expanded code to avoid
|
-- the generation of spurious warnings under ZFP run-time.
|
-- the generation of spurious warnings under ZFP run-time.
|
|
|
Insert_Actions (E, List_Def, Suppress => All_Checks);
|
Insert_Actions (E, List_Def, Suppress => All_Checks);
|
return Equiv_Type;
|
return Equiv_Type;
|
end Make_CW_Equivalent_Type;
|
end Make_CW_Equivalent_Type;
|
|
|
-------------------------
|
-------------------------
|
-- Make_Invariant_Call --
|
-- Make_Invariant_Call --
|
-------------------------
|
-------------------------
|
|
|
function Make_Invariant_Call (Expr : Node_Id) return Node_Id is
|
function Make_Invariant_Call (Expr : Node_Id) return Node_Id is
|
Loc : constant Source_Ptr := Sloc (Expr);
|
Loc : constant Source_Ptr := Sloc (Expr);
|
Typ : constant Entity_Id := Etype (Expr);
|
Typ : constant Entity_Id := Etype (Expr);
|
|
|
begin
|
begin
|
pragma Assert
|
pragma Assert
|
(Has_Invariants (Typ) and then Present (Invariant_Procedure (Typ)));
|
(Has_Invariants (Typ) and then Present (Invariant_Procedure (Typ)));
|
|
|
if Check_Enabled (Name_Invariant)
|
if Check_Enabled (Name_Invariant)
|
or else
|
or else
|
Check_Enabled (Name_Assertion)
|
Check_Enabled (Name_Assertion)
|
then
|
then
|
return
|
return
|
Make_Procedure_Call_Statement (Loc,
|
Make_Procedure_Call_Statement (Loc,
|
Name =>
|
Name =>
|
New_Occurrence_Of (Invariant_Procedure (Typ), Loc),
|
New_Occurrence_Of (Invariant_Procedure (Typ), Loc),
|
Parameter_Associations => New_List (Relocate_Node (Expr)));
|
Parameter_Associations => New_List (Relocate_Node (Expr)));
|
|
|
else
|
else
|
return
|
return
|
Make_Null_Statement (Loc);
|
Make_Null_Statement (Loc);
|
end if;
|
end if;
|
end Make_Invariant_Call;
|
end Make_Invariant_Call;
|
|
|
------------------------
|
------------------------
|
-- Make_Literal_Range --
|
-- Make_Literal_Range --
|
------------------------
|
------------------------
|
|
|
function Make_Literal_Range
|
function Make_Literal_Range
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
Literal_Typ : Entity_Id) return Node_Id
|
Literal_Typ : Entity_Id) return Node_Id
|
is
|
is
|
Lo : constant Node_Id :=
|
Lo : constant Node_Id :=
|
New_Copy_Tree (String_Literal_Low_Bound (Literal_Typ));
|
New_Copy_Tree (String_Literal_Low_Bound (Literal_Typ));
|
Index : constant Entity_Id := Etype (Lo);
|
Index : constant Entity_Id := Etype (Lo);
|
|
|
Hi : Node_Id;
|
Hi : Node_Id;
|
Length_Expr : constant Node_Id :=
|
Length_Expr : constant Node_Id :=
|
Make_Op_Subtract (Loc,
|
Make_Op_Subtract (Loc,
|
Left_Opnd =>
|
Left_Opnd =>
|
Make_Integer_Literal (Loc,
|
Make_Integer_Literal (Loc,
|
Intval => String_Literal_Length (Literal_Typ)),
|
Intval => String_Literal_Length (Literal_Typ)),
|
Right_Opnd =>
|
Right_Opnd =>
|
Make_Integer_Literal (Loc, 1));
|
Make_Integer_Literal (Loc, 1));
|
|
|
begin
|
begin
|
Set_Analyzed (Lo, False);
|
Set_Analyzed (Lo, False);
|
|
|
if Is_Integer_Type (Index) then
|
if Is_Integer_Type (Index) then
|
Hi :=
|
Hi :=
|
Make_Op_Add (Loc,
|
Make_Op_Add (Loc,
|
Left_Opnd => New_Copy_Tree (Lo),
|
Left_Opnd => New_Copy_Tree (Lo),
|
Right_Opnd => Length_Expr);
|
Right_Opnd => Length_Expr);
|
else
|
else
|
Hi :=
|
Hi :=
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Attribute_Name => Name_Val,
|
Attribute_Name => Name_Val,
|
Prefix => New_Occurrence_Of (Index, Loc),
|
Prefix => New_Occurrence_Of (Index, Loc),
|
Expressions => New_List (
|
Expressions => New_List (
|
Make_Op_Add (Loc,
|
Make_Op_Add (Loc,
|
Left_Opnd =>
|
Left_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Attribute_Name => Name_Pos,
|
Attribute_Name => Name_Pos,
|
Prefix => New_Occurrence_Of (Index, Loc),
|
Prefix => New_Occurrence_Of (Index, Loc),
|
Expressions => New_List (New_Copy_Tree (Lo))),
|
Expressions => New_List (New_Copy_Tree (Lo))),
|
Right_Opnd => Length_Expr)));
|
Right_Opnd => Length_Expr)));
|
end if;
|
end if;
|
|
|
return
|
return
|
Make_Range (Loc,
|
Make_Range (Loc,
|
Low_Bound => Lo,
|
Low_Bound => Lo,
|
High_Bound => Hi);
|
High_Bound => Hi);
|
end Make_Literal_Range;
|
end Make_Literal_Range;
|
|
|
--------------------------
|
--------------------------
|
-- Make_Non_Empty_Check --
|
-- Make_Non_Empty_Check --
|
--------------------------
|
--------------------------
|
|
|
function Make_Non_Empty_Check
|
function Make_Non_Empty_Check
|
(Loc : Source_Ptr;
|
(Loc : Source_Ptr;
|
N : Node_Id) return Node_Id
|
N : Node_Id) return Node_Id
|
is
|
is
|
begin
|
begin
|
return
|
return
|
Make_Op_Ne (Loc,
|
Make_Op_Ne (Loc,
|
Left_Opnd =>
|
Left_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Attribute_Name => Name_Length,
|
Attribute_Name => Name_Length,
|
Prefix => Duplicate_Subexpr_No_Checks (N, Name_Req => True)),
|
Prefix => Duplicate_Subexpr_No_Checks (N, Name_Req => True)),
|
Right_Opnd =>
|
Right_Opnd =>
|
Make_Integer_Literal (Loc, 0));
|
Make_Integer_Literal (Loc, 0));
|
end Make_Non_Empty_Check;
|
end Make_Non_Empty_Check;
|
|
|
-------------------------
|
-------------------------
|
-- Make_Predicate_Call --
|
-- Make_Predicate_Call --
|
-------------------------
|
-------------------------
|
|
|
function Make_Predicate_Call
|
function Make_Predicate_Call
|
(Typ : Entity_Id;
|
(Typ : Entity_Id;
|
Expr : Node_Id) return Node_Id
|
Expr : Node_Id) return Node_Id
|
is
|
is
|
Loc : constant Source_Ptr := Sloc (Expr);
|
Loc : constant Source_Ptr := Sloc (Expr);
|
|
|
begin
|
begin
|
pragma Assert (Present (Predicate_Function (Typ)));
|
pragma Assert (Present (Predicate_Function (Typ)));
|
|
|
return
|
return
|
Make_Function_Call (Loc,
|
Make_Function_Call (Loc,
|
Name =>
|
Name =>
|
New_Occurrence_Of (Predicate_Function (Typ), Loc),
|
New_Occurrence_Of (Predicate_Function (Typ), Loc),
|
Parameter_Associations => New_List (Relocate_Node (Expr)));
|
Parameter_Associations => New_List (Relocate_Node (Expr)));
|
end Make_Predicate_Call;
|
end Make_Predicate_Call;
|
|
|
--------------------------
|
--------------------------
|
-- Make_Predicate_Check --
|
-- Make_Predicate_Check --
|
--------------------------
|
--------------------------
|
|
|
function Make_Predicate_Check
|
function Make_Predicate_Check
|
(Typ : Entity_Id;
|
(Typ : Entity_Id;
|
Expr : Node_Id) return Node_Id
|
Expr : Node_Id) return Node_Id
|
is
|
is
|
Loc : constant Source_Ptr := Sloc (Expr);
|
Loc : constant Source_Ptr := Sloc (Expr);
|
|
|
begin
|
begin
|
return
|
return
|
Make_Pragma (Loc,
|
Make_Pragma (Loc,
|
Pragma_Identifier => Make_Identifier (Loc, Name_Check),
|
Pragma_Identifier => Make_Identifier (Loc, Name_Check),
|
Pragma_Argument_Associations => New_List (
|
Pragma_Argument_Associations => New_List (
|
Make_Pragma_Argument_Association (Loc,
|
Make_Pragma_Argument_Association (Loc,
|
Expression => Make_Identifier (Loc, Name_Predicate)),
|
Expression => Make_Identifier (Loc, Name_Predicate)),
|
Make_Pragma_Argument_Association (Loc,
|
Make_Pragma_Argument_Association (Loc,
|
Expression => Make_Predicate_Call (Typ, Expr))));
|
Expression => Make_Predicate_Call (Typ, Expr))));
|
end Make_Predicate_Check;
|
end Make_Predicate_Check;
|
|
|
----------------------------
|
----------------------------
|
-- Make_Subtype_From_Expr --
|
-- Make_Subtype_From_Expr --
|
----------------------------
|
----------------------------
|
|
|
-- 1. If Expr is an unconstrained array expression, creates
|
-- 1. If Expr is an unconstrained array expression, creates
|
-- Unc_Type(Expr'first(1)..Expr'last(1),..., Expr'first(n)..Expr'last(n))
|
-- Unc_Type(Expr'first(1)..Expr'last(1),..., Expr'first(n)..Expr'last(n))
|
|
|
-- 2. If Expr is a unconstrained discriminated type expression, creates
|
-- 2. If Expr is a unconstrained discriminated type expression, creates
|
-- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
|
-- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
|
|
|
-- 3. If Expr is class-wide, creates an implicit class wide subtype
|
-- 3. If Expr is class-wide, creates an implicit class wide subtype
|
|
|
function Make_Subtype_From_Expr
|
function Make_Subtype_From_Expr
|
(E : Node_Id;
|
(E : Node_Id;
|
Unc_Typ : Entity_Id) return Node_Id
|
Unc_Typ : Entity_Id) return Node_Id
|
is
|
is
|
Loc : constant Source_Ptr := Sloc (E);
|
Loc : constant Source_Ptr := Sloc (E);
|
List_Constr : constant List_Id := New_List;
|
List_Constr : constant List_Id := New_List;
|
D : Entity_Id;
|
D : Entity_Id;
|
|
|
Full_Subtyp : Entity_Id;
|
Full_Subtyp : Entity_Id;
|
Priv_Subtyp : Entity_Id;
|
Priv_Subtyp : Entity_Id;
|
Utyp : Entity_Id;
|
Utyp : Entity_Id;
|
Full_Exp : Node_Id;
|
Full_Exp : Node_Id;
|
|
|
begin
|
begin
|
if Is_Private_Type (Unc_Typ)
|
if Is_Private_Type (Unc_Typ)
|
and then Has_Unknown_Discriminants (Unc_Typ)
|
and then Has_Unknown_Discriminants (Unc_Typ)
|
then
|
then
|
-- Prepare the subtype completion, Go to base type to
|
-- Prepare the subtype completion, Go to base type to
|
-- find underlying type, because the type may be a generic
|
-- find underlying type, because the type may be a generic
|
-- actual or an explicit subtype.
|
-- actual or an explicit subtype.
|
|
|
Utyp := Underlying_Type (Base_Type (Unc_Typ));
|
Utyp := Underlying_Type (Base_Type (Unc_Typ));
|
Full_Subtyp := Make_Temporary (Loc, 'C');
|
Full_Subtyp := Make_Temporary (Loc, 'C');
|
Full_Exp :=
|
Full_Exp :=
|
Unchecked_Convert_To (Utyp, Duplicate_Subexpr_No_Checks (E));
|
Unchecked_Convert_To (Utyp, Duplicate_Subexpr_No_Checks (E));
|
Set_Parent (Full_Exp, Parent (E));
|
Set_Parent (Full_Exp, Parent (E));
|
|
|
Priv_Subtyp := Make_Temporary (Loc, 'P');
|
Priv_Subtyp := Make_Temporary (Loc, 'P');
|
|
|
Insert_Action (E,
|
Insert_Action (E,
|
Make_Subtype_Declaration (Loc,
|
Make_Subtype_Declaration (Loc,
|
Defining_Identifier => Full_Subtyp,
|
Defining_Identifier => Full_Subtyp,
|
Subtype_Indication => Make_Subtype_From_Expr (Full_Exp, Utyp)));
|
Subtype_Indication => Make_Subtype_From_Expr (Full_Exp, Utyp)));
|
|
|
-- Define the dummy private subtype
|
-- Define the dummy private subtype
|
|
|
Set_Ekind (Priv_Subtyp, Subtype_Kind (Ekind (Unc_Typ)));
|
Set_Ekind (Priv_Subtyp, Subtype_Kind (Ekind (Unc_Typ)));
|
Set_Etype (Priv_Subtyp, Base_Type (Unc_Typ));
|
Set_Etype (Priv_Subtyp, Base_Type (Unc_Typ));
|
Set_Scope (Priv_Subtyp, Full_Subtyp);
|
Set_Scope (Priv_Subtyp, Full_Subtyp);
|
Set_Is_Constrained (Priv_Subtyp);
|
Set_Is_Constrained (Priv_Subtyp);
|
Set_Is_Tagged_Type (Priv_Subtyp, Is_Tagged_Type (Unc_Typ));
|
Set_Is_Tagged_Type (Priv_Subtyp, Is_Tagged_Type (Unc_Typ));
|
Set_Is_Itype (Priv_Subtyp);
|
Set_Is_Itype (Priv_Subtyp);
|
Set_Associated_Node_For_Itype (Priv_Subtyp, E);
|
Set_Associated_Node_For_Itype (Priv_Subtyp, E);
|
|
|
if Is_Tagged_Type (Priv_Subtyp) then
|
if Is_Tagged_Type (Priv_Subtyp) then
|
Set_Class_Wide_Type
|
Set_Class_Wide_Type
|
(Base_Type (Priv_Subtyp), Class_Wide_Type (Unc_Typ));
|
(Base_Type (Priv_Subtyp), Class_Wide_Type (Unc_Typ));
|
Set_Direct_Primitive_Operations (Priv_Subtyp,
|
Set_Direct_Primitive_Operations (Priv_Subtyp,
|
Direct_Primitive_Operations (Unc_Typ));
|
Direct_Primitive_Operations (Unc_Typ));
|
end if;
|
end if;
|
|
|
Set_Full_View (Priv_Subtyp, Full_Subtyp);
|
Set_Full_View (Priv_Subtyp, Full_Subtyp);
|
|
|
return New_Reference_To (Priv_Subtyp, Loc);
|
return New_Reference_To (Priv_Subtyp, Loc);
|
|
|
elsif Is_Array_Type (Unc_Typ) then
|
elsif Is_Array_Type (Unc_Typ) then
|
for J in 1 .. Number_Dimensions (Unc_Typ) loop
|
for J in 1 .. Number_Dimensions (Unc_Typ) loop
|
Append_To (List_Constr,
|
Append_To (List_Constr,
|
Make_Range (Loc,
|
Make_Range (Loc,
|
Low_Bound =>
|
Low_Bound =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix => Duplicate_Subexpr_No_Checks (E),
|
Prefix => Duplicate_Subexpr_No_Checks (E),
|
Attribute_Name => Name_First,
|
Attribute_Name => Name_First,
|
Expressions => New_List (
|
Expressions => New_List (
|
Make_Integer_Literal (Loc, J))),
|
Make_Integer_Literal (Loc, J))),
|
|
|
High_Bound =>
|
High_Bound =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix => Duplicate_Subexpr_No_Checks (E),
|
Prefix => Duplicate_Subexpr_No_Checks (E),
|
Attribute_Name => Name_Last,
|
Attribute_Name => Name_Last,
|
Expressions => New_List (
|
Expressions => New_List (
|
Make_Integer_Literal (Loc, J)))));
|
Make_Integer_Literal (Loc, J)))));
|
end loop;
|
end loop;
|
|
|
elsif Is_Class_Wide_Type (Unc_Typ) then
|
elsif Is_Class_Wide_Type (Unc_Typ) then
|
declare
|
declare
|
CW_Subtype : Entity_Id;
|
CW_Subtype : Entity_Id;
|
EQ_Typ : Entity_Id := Empty;
|
EQ_Typ : Entity_Id := Empty;
|
|
|
begin
|
begin
|
-- A class-wide equivalent type is not needed when VM_Target
|
-- A class-wide equivalent type is not needed when VM_Target
|
-- because the VM back-ends handle the class-wide object
|
-- because the VM back-ends handle the class-wide object
|
-- initialization itself (and doesn't need or want the
|
-- initialization itself (and doesn't need or want the
|
-- additional intermediate type to handle the assignment).
|
-- additional intermediate type to handle the assignment).
|
|
|
if Expander_Active and then Tagged_Type_Expansion then
|
if Expander_Active and then Tagged_Type_Expansion then
|
|
|
-- If this is the class_wide type of a completion that is a
|
-- If this is the class_wide type of a completion that is a
|
-- record subtype, set the type of the class_wide type to be
|
-- record subtype, set the type of the class_wide type to be
|
-- the full base type, for use in the expanded code for the
|
-- the full base type, for use in the expanded code for the
|
-- equivalent type. Should this be done earlier when the
|
-- equivalent type. Should this be done earlier when the
|
-- completion is analyzed ???
|
-- completion is analyzed ???
|
|
|
if Is_Private_Type (Etype (Unc_Typ))
|
if Is_Private_Type (Etype (Unc_Typ))
|
and then
|
and then
|
Ekind (Full_View (Etype (Unc_Typ))) = E_Record_Subtype
|
Ekind (Full_View (Etype (Unc_Typ))) = E_Record_Subtype
|
then
|
then
|
Set_Etype (Unc_Typ, Base_Type (Full_View (Etype (Unc_Typ))));
|
Set_Etype (Unc_Typ, Base_Type (Full_View (Etype (Unc_Typ))));
|
end if;
|
end if;
|
|
|
EQ_Typ := Make_CW_Equivalent_Type (Unc_Typ, E);
|
EQ_Typ := Make_CW_Equivalent_Type (Unc_Typ, E);
|
end if;
|
end if;
|
|
|
CW_Subtype := New_Class_Wide_Subtype (Unc_Typ, E);
|
CW_Subtype := New_Class_Wide_Subtype (Unc_Typ, E);
|
Set_Equivalent_Type (CW_Subtype, EQ_Typ);
|
Set_Equivalent_Type (CW_Subtype, EQ_Typ);
|
Set_Cloned_Subtype (CW_Subtype, Base_Type (Unc_Typ));
|
Set_Cloned_Subtype (CW_Subtype, Base_Type (Unc_Typ));
|
|
|
return New_Occurrence_Of (CW_Subtype, Loc);
|
return New_Occurrence_Of (CW_Subtype, Loc);
|
end;
|
end;
|
|
|
-- Indefinite record type with discriminants
|
-- Indefinite record type with discriminants
|
|
|
else
|
else
|
D := First_Discriminant (Unc_Typ);
|
D := First_Discriminant (Unc_Typ);
|
while Present (D) loop
|
while Present (D) loop
|
Append_To (List_Constr,
|
Append_To (List_Constr,
|
Make_Selected_Component (Loc,
|
Make_Selected_Component (Loc,
|
Prefix => Duplicate_Subexpr_No_Checks (E),
|
Prefix => Duplicate_Subexpr_No_Checks (E),
|
Selector_Name => New_Reference_To (D, Loc)));
|
Selector_Name => New_Reference_To (D, Loc)));
|
|
|
Next_Discriminant (D);
|
Next_Discriminant (D);
|
end loop;
|
end loop;
|
end if;
|
end if;
|
|
|
return
|
return
|
Make_Subtype_Indication (Loc,
|
Make_Subtype_Indication (Loc,
|
Subtype_Mark => New_Reference_To (Unc_Typ, Loc),
|
Subtype_Mark => New_Reference_To (Unc_Typ, Loc),
|
Constraint =>
|
Constraint =>
|
Make_Index_Or_Discriminant_Constraint (Loc,
|
Make_Index_Or_Discriminant_Constraint (Loc,
|
Constraints => List_Constr));
|
Constraints => List_Constr));
|
end Make_Subtype_From_Expr;
|
end Make_Subtype_From_Expr;
|
|
|
-----------------------------
|
-----------------------------
|
-- May_Generate_Large_Temp --
|
-- May_Generate_Large_Temp --
|
-----------------------------
|
-----------------------------
|
|
|
-- At the current time, the only types that we return False for (i.e. where
|
-- At the current time, the only types that we return False for (i.e. where
|
-- we decide we know they cannot generate large temps) are ones where we
|
-- we decide we know they cannot generate large temps) are ones where we
|
-- know the size is 256 bits or less at compile time, and we are still not
|
-- know the size is 256 bits or less at compile time, and we are still not
|
-- doing a thorough job on arrays and records ???
|
-- doing a thorough job on arrays and records ???
|
|
|
function May_Generate_Large_Temp (Typ : Entity_Id) return Boolean is
|
function May_Generate_Large_Temp (Typ : Entity_Id) return Boolean is
|
begin
|
begin
|
if not Size_Known_At_Compile_Time (Typ) then
|
if not Size_Known_At_Compile_Time (Typ) then
|
return False;
|
return False;
|
|
|
elsif Esize (Typ) /= 0 and then Esize (Typ) <= 256 then
|
elsif Esize (Typ) /= 0 and then Esize (Typ) <= 256 then
|
return False;
|
return False;
|
|
|
elsif Is_Array_Type (Typ)
|
elsif Is_Array_Type (Typ)
|
and then Present (Packed_Array_Type (Typ))
|
and then Present (Packed_Array_Type (Typ))
|
then
|
then
|
return May_Generate_Large_Temp (Packed_Array_Type (Typ));
|
return May_Generate_Large_Temp (Packed_Array_Type (Typ));
|
|
|
-- We could do more here to find other small types ???
|
-- We could do more here to find other small types ???
|
|
|
else
|
else
|
return True;
|
return True;
|
end if;
|
end if;
|
end May_Generate_Large_Temp;
|
end May_Generate_Large_Temp;
|
|
|
------------------------
|
------------------------
|
-- Needs_Finalization --
|
-- Needs_Finalization --
|
------------------------
|
------------------------
|
|
|
function Needs_Finalization (T : Entity_Id) return Boolean is
|
function Needs_Finalization (T : Entity_Id) return Boolean is
|
function Has_Some_Controlled_Component (Rec : Entity_Id) return Boolean;
|
function Has_Some_Controlled_Component (Rec : Entity_Id) return Boolean;
|
-- If type is not frozen yet, check explicitly among its components,
|
-- If type is not frozen yet, check explicitly among its components,
|
-- because the Has_Controlled_Component flag is not necessarily set.
|
-- because the Has_Controlled_Component flag is not necessarily set.
|
|
|
-----------------------------------
|
-----------------------------------
|
-- Has_Some_Controlled_Component --
|
-- Has_Some_Controlled_Component --
|
-----------------------------------
|
-----------------------------------
|
|
|
function Has_Some_Controlled_Component
|
function Has_Some_Controlled_Component
|
(Rec : Entity_Id) return Boolean
|
(Rec : Entity_Id) return Boolean
|
is
|
is
|
Comp : Entity_Id;
|
Comp : Entity_Id;
|
|
|
begin
|
begin
|
if Has_Controlled_Component (Rec) then
|
if Has_Controlled_Component (Rec) then
|
return True;
|
return True;
|
|
|
elsif not Is_Frozen (Rec) then
|
elsif not Is_Frozen (Rec) then
|
if Is_Record_Type (Rec) then
|
if Is_Record_Type (Rec) then
|
Comp := First_Entity (Rec);
|
Comp := First_Entity (Rec);
|
|
|
while Present (Comp) loop
|
while Present (Comp) loop
|
if not Is_Type (Comp)
|
if not Is_Type (Comp)
|
and then Needs_Finalization (Etype (Comp))
|
and then Needs_Finalization (Etype (Comp))
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
Next_Entity (Comp);
|
Next_Entity (Comp);
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
|
|
elsif Is_Array_Type (Rec) then
|
elsif Is_Array_Type (Rec) then
|
return Needs_Finalization (Component_Type (Rec));
|
return Needs_Finalization (Component_Type (Rec));
|
|
|
else
|
else
|
return Has_Controlled_Component (Rec);
|
return Has_Controlled_Component (Rec);
|
end if;
|
end if;
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Has_Some_Controlled_Component;
|
end Has_Some_Controlled_Component;
|
|
|
-- Start of processing for Needs_Finalization
|
-- Start of processing for Needs_Finalization
|
|
|
begin
|
begin
|
-- Certain run-time configurations and targets do not provide support
|
-- Certain run-time configurations and targets do not provide support
|
-- for controlled types.
|
-- for controlled types.
|
|
|
if Restriction_Active (No_Finalization) then
|
if Restriction_Active (No_Finalization) then
|
return False;
|
return False;
|
|
|
-- C, C++, CIL and Java types are not considered controlled. It is
|
-- C, C++, CIL and Java types are not considered controlled. It is
|
-- assumed that the non-Ada side will handle their clean up.
|
-- assumed that the non-Ada side will handle their clean up.
|
|
|
elsif Convention (T) = Convention_C
|
elsif Convention (T) = Convention_C
|
or else Convention (T) = Convention_CIL
|
or else Convention (T) = Convention_CIL
|
or else Convention (T) = Convention_CPP
|
or else Convention (T) = Convention_CPP
|
or else Convention (T) = Convention_Java
|
or else Convention (T) = Convention_Java
|
then
|
then
|
return False;
|
return False;
|
|
|
else
|
else
|
-- Class-wide types are treated as controlled because derivations
|
-- Class-wide types are treated as controlled because derivations
|
-- from the root type can introduce controlled components.
|
-- from the root type can introduce controlled components.
|
|
|
return
|
return
|
Is_Class_Wide_Type (T)
|
Is_Class_Wide_Type (T)
|
or else Is_Controlled (T)
|
or else Is_Controlled (T)
|
or else Has_Controlled_Component (T)
|
or else Has_Controlled_Component (T)
|
or else Has_Some_Controlled_Component (T)
|
or else Has_Some_Controlled_Component (T)
|
or else
|
or else
|
(Is_Concurrent_Type (T)
|
(Is_Concurrent_Type (T)
|
and then Present (Corresponding_Record_Type (T))
|
and then Present (Corresponding_Record_Type (T))
|
and then Needs_Finalization (Corresponding_Record_Type (T)));
|
and then Needs_Finalization (Corresponding_Record_Type (T)));
|
end if;
|
end if;
|
end Needs_Finalization;
|
end Needs_Finalization;
|
|
|
----------------------------
|
----------------------------
|
-- Needs_Constant_Address --
|
-- Needs_Constant_Address --
|
----------------------------
|
----------------------------
|
|
|
function Needs_Constant_Address
|
function Needs_Constant_Address
|
(Decl : Node_Id;
|
(Decl : Node_Id;
|
Typ : Entity_Id) return Boolean
|
Typ : Entity_Id) return Boolean
|
is
|
is
|
begin
|
begin
|
|
|
-- If we have no initialization of any kind, then we don't need to place
|
-- If we have no initialization of any kind, then we don't need to place
|
-- any restrictions on the address clause, because the object will be
|
-- any restrictions on the address clause, because the object will be
|
-- elaborated after the address clause is evaluated. This happens if the
|
-- elaborated after the address clause is evaluated. This happens if the
|
-- declaration has no initial expression, or the type has no implicit
|
-- declaration has no initial expression, or the type has no implicit
|
-- initialization, or the object is imported.
|
-- initialization, or the object is imported.
|
|
|
-- The same holds for all initialized scalar types and all access types.
|
-- The same holds for all initialized scalar types and all access types.
|
-- Packed bit arrays of size up to 64 are represented using a modular
|
-- Packed bit arrays of size up to 64 are represented using a modular
|
-- type with an initialization (to zero) and can be processed like other
|
-- type with an initialization (to zero) and can be processed like other
|
-- initialized scalar types.
|
-- initialized scalar types.
|
|
|
-- If the type is controlled, code to attach the object to a
|
-- If the type is controlled, code to attach the object to a
|
-- finalization chain is generated at the point of declaration, and
|
-- finalization chain is generated at the point of declaration, and
|
-- therefore the elaboration of the object cannot be delayed: the
|
-- therefore the elaboration of the object cannot be delayed: the
|
-- address expression must be a constant.
|
-- address expression must be a constant.
|
|
|
if No (Expression (Decl))
|
if No (Expression (Decl))
|
and then not Needs_Finalization (Typ)
|
and then not Needs_Finalization (Typ)
|
and then
|
and then
|
(not Has_Non_Null_Base_Init_Proc (Typ)
|
(not Has_Non_Null_Base_Init_Proc (Typ)
|
or else Is_Imported (Defining_Identifier (Decl)))
|
or else Is_Imported (Defining_Identifier (Decl)))
|
then
|
then
|
return False;
|
return False;
|
|
|
elsif (Present (Expression (Decl)) and then Is_Scalar_Type (Typ))
|
elsif (Present (Expression (Decl)) and then Is_Scalar_Type (Typ))
|
or else Is_Access_Type (Typ)
|
or else Is_Access_Type (Typ)
|
or else
|
or else
|
(Is_Bit_Packed_Array (Typ)
|
(Is_Bit_Packed_Array (Typ)
|
and then Is_Modular_Integer_Type (Packed_Array_Type (Typ)))
|
and then Is_Modular_Integer_Type (Packed_Array_Type (Typ)))
|
then
|
then
|
return False;
|
return False;
|
|
|
else
|
else
|
|
|
-- Otherwise, we require the address clause to be constant because
|
-- Otherwise, we require the address clause to be constant because
|
-- the call to the initialization procedure (or the attach code) has
|
-- the call to the initialization procedure (or the attach code) has
|
-- to happen at the point of the declaration.
|
-- to happen at the point of the declaration.
|
|
|
-- Actually the IP call has been moved to the freeze actions anyway,
|
-- Actually the IP call has been moved to the freeze actions anyway,
|
-- so maybe we can relax this restriction???
|
-- so maybe we can relax this restriction???
|
|
|
return True;
|
return True;
|
end if;
|
end if;
|
end Needs_Constant_Address;
|
end Needs_Constant_Address;
|
|
|
----------------------------
|
----------------------------
|
-- New_Class_Wide_Subtype --
|
-- New_Class_Wide_Subtype --
|
----------------------------
|
----------------------------
|
|
|
function New_Class_Wide_Subtype
|
function New_Class_Wide_Subtype
|
(CW_Typ : Entity_Id;
|
(CW_Typ : Entity_Id;
|
N : Node_Id) return Entity_Id
|
N : Node_Id) return Entity_Id
|
is
|
is
|
Res : constant Entity_Id := Create_Itype (E_Void, N);
|
Res : constant Entity_Id := Create_Itype (E_Void, N);
|
Res_Name : constant Name_Id := Chars (Res);
|
Res_Name : constant Name_Id := Chars (Res);
|
Res_Scope : constant Entity_Id := Scope (Res);
|
Res_Scope : constant Entity_Id := Scope (Res);
|
|
|
begin
|
begin
|
Copy_Node (CW_Typ, Res);
|
Copy_Node (CW_Typ, Res);
|
Set_Comes_From_Source (Res, False);
|
Set_Comes_From_Source (Res, False);
|
Set_Sloc (Res, Sloc (N));
|
Set_Sloc (Res, Sloc (N));
|
Set_Is_Itype (Res);
|
Set_Is_Itype (Res);
|
Set_Associated_Node_For_Itype (Res, N);
|
Set_Associated_Node_For_Itype (Res, N);
|
Set_Is_Public (Res, False); -- By default, may be changed below.
|
Set_Is_Public (Res, False); -- By default, may be changed below.
|
Set_Public_Status (Res);
|
Set_Public_Status (Res);
|
Set_Chars (Res, Res_Name);
|
Set_Chars (Res, Res_Name);
|
Set_Scope (Res, Res_Scope);
|
Set_Scope (Res, Res_Scope);
|
Set_Ekind (Res, E_Class_Wide_Subtype);
|
Set_Ekind (Res, E_Class_Wide_Subtype);
|
Set_Next_Entity (Res, Empty);
|
Set_Next_Entity (Res, Empty);
|
Set_Etype (Res, Base_Type (CW_Typ));
|
Set_Etype (Res, Base_Type (CW_Typ));
|
Set_Is_Frozen (Res, False);
|
Set_Is_Frozen (Res, False);
|
Set_Freeze_Node (Res, Empty);
|
Set_Freeze_Node (Res, Empty);
|
return (Res);
|
return (Res);
|
end New_Class_Wide_Subtype;
|
end New_Class_Wide_Subtype;
|
|
|
--------------------------------
|
--------------------------------
|
-- Non_Limited_Designated_Type --
|
-- Non_Limited_Designated_Type --
|
---------------------------------
|
---------------------------------
|
|
|
function Non_Limited_Designated_Type (T : Entity_Id) return Entity_Id is
|
function Non_Limited_Designated_Type (T : Entity_Id) return Entity_Id is
|
Desig : constant Entity_Id := Designated_Type (T);
|
Desig : constant Entity_Id := Designated_Type (T);
|
begin
|
begin
|
if Ekind (Desig) = E_Incomplete_Type
|
if Ekind (Desig) = E_Incomplete_Type
|
and then Present (Non_Limited_View (Desig))
|
and then Present (Non_Limited_View (Desig))
|
then
|
then
|
return Non_Limited_View (Desig);
|
return Non_Limited_View (Desig);
|
else
|
else
|
return Desig;
|
return Desig;
|
end if;
|
end if;
|
end Non_Limited_Designated_Type;
|
end Non_Limited_Designated_Type;
|
|
|
-----------------------------------
|
-----------------------------------
|
-- OK_To_Do_Constant_Replacement --
|
-- OK_To_Do_Constant_Replacement --
|
-----------------------------------
|
-----------------------------------
|
|
|
function OK_To_Do_Constant_Replacement (E : Entity_Id) return Boolean is
|
function OK_To_Do_Constant_Replacement (E : Entity_Id) return Boolean is
|
ES : constant Entity_Id := Scope (E);
|
ES : constant Entity_Id := Scope (E);
|
CS : Entity_Id;
|
CS : Entity_Id;
|
|
|
begin
|
begin
|
-- Do not replace statically allocated objects, because they may be
|
-- Do not replace statically allocated objects, because they may be
|
-- modified outside the current scope.
|
-- modified outside the current scope.
|
|
|
if Is_Statically_Allocated (E) then
|
if Is_Statically_Allocated (E) then
|
return False;
|
return False;
|
|
|
-- Do not replace aliased or volatile objects, since we don't know what
|
-- Do not replace aliased or volatile objects, since we don't know what
|
-- else might change the value.
|
-- else might change the value.
|
|
|
elsif Is_Aliased (E) or else Treat_As_Volatile (E) then
|
elsif Is_Aliased (E) or else Treat_As_Volatile (E) then
|
return False;
|
return False;
|
|
|
-- Debug flag -gnatdM disconnects this optimization
|
-- Debug flag -gnatdM disconnects this optimization
|
|
|
elsif Debug_Flag_MM then
|
elsif Debug_Flag_MM then
|
return False;
|
return False;
|
|
|
-- Otherwise check scopes
|
-- Otherwise check scopes
|
|
|
else
|
else
|
CS := Current_Scope;
|
CS := Current_Scope;
|
|
|
loop
|
loop
|
-- If we are in right scope, replacement is safe
|
-- If we are in right scope, replacement is safe
|
|
|
if CS = ES then
|
if CS = ES then
|
return True;
|
return True;
|
|
|
-- Packages do not affect the determination of safety
|
-- Packages do not affect the determination of safety
|
|
|
elsif Ekind (CS) = E_Package then
|
elsif Ekind (CS) = E_Package then
|
exit when CS = Standard_Standard;
|
exit when CS = Standard_Standard;
|
CS := Scope (CS);
|
CS := Scope (CS);
|
|
|
-- Blocks do not affect the determination of safety
|
-- Blocks do not affect the determination of safety
|
|
|
elsif Ekind (CS) = E_Block then
|
elsif Ekind (CS) = E_Block then
|
CS := Scope (CS);
|
CS := Scope (CS);
|
|
|
-- Loops do not affect the determination of safety. Note that we
|
-- Loops do not affect the determination of safety. Note that we
|
-- kill all current values on entry to a loop, so we are just
|
-- kill all current values on entry to a loop, so we are just
|
-- talking about processing within a loop here.
|
-- talking about processing within a loop here.
|
|
|
elsif Ekind (CS) = E_Loop then
|
elsif Ekind (CS) = E_Loop then
|
CS := Scope (CS);
|
CS := Scope (CS);
|
|
|
-- Otherwise, the reference is dubious, and we cannot be sure that
|
-- Otherwise, the reference is dubious, and we cannot be sure that
|
-- it is safe to do the replacement.
|
-- it is safe to do the replacement.
|
|
|
else
|
else
|
exit;
|
exit;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
end if;
|
end if;
|
end OK_To_Do_Constant_Replacement;
|
end OK_To_Do_Constant_Replacement;
|
|
|
------------------------------------
|
------------------------------------
|
-- Possible_Bit_Aligned_Component --
|
-- Possible_Bit_Aligned_Component --
|
------------------------------------
|
------------------------------------
|
|
|
function Possible_Bit_Aligned_Component (N : Node_Id) return Boolean is
|
function Possible_Bit_Aligned_Component (N : Node_Id) return Boolean is
|
begin
|
begin
|
case Nkind (N) is
|
case Nkind (N) is
|
|
|
-- Case of indexed component
|
-- Case of indexed component
|
|
|
when N_Indexed_Component =>
|
when N_Indexed_Component =>
|
declare
|
declare
|
P : constant Node_Id := Prefix (N);
|
P : constant Node_Id := Prefix (N);
|
Ptyp : constant Entity_Id := Etype (P);
|
Ptyp : constant Entity_Id := Etype (P);
|
|
|
begin
|
begin
|
-- If we know the component size and it is less than 64, then
|
-- If we know the component size and it is less than 64, then
|
-- we are definitely OK. The back end always does assignment of
|
-- we are definitely OK. The back end always does assignment of
|
-- misaligned small objects correctly.
|
-- misaligned small objects correctly.
|
|
|
if Known_Static_Component_Size (Ptyp)
|
if Known_Static_Component_Size (Ptyp)
|
and then Component_Size (Ptyp) <= 64
|
and then Component_Size (Ptyp) <= 64
|
then
|
then
|
return False;
|
return False;
|
|
|
-- Otherwise, we need to test the prefix, to see if we are
|
-- Otherwise, we need to test the prefix, to see if we are
|
-- indexing from a possibly unaligned component.
|
-- indexing from a possibly unaligned component.
|
|
|
else
|
else
|
return Possible_Bit_Aligned_Component (P);
|
return Possible_Bit_Aligned_Component (P);
|
end if;
|
end if;
|
end;
|
end;
|
|
|
-- Case of selected component
|
-- Case of selected component
|
|
|
when N_Selected_Component =>
|
when N_Selected_Component =>
|
declare
|
declare
|
P : constant Node_Id := Prefix (N);
|
P : constant Node_Id := Prefix (N);
|
Comp : constant Entity_Id := Entity (Selector_Name (N));
|
Comp : constant Entity_Id := Entity (Selector_Name (N));
|
|
|
begin
|
begin
|
-- If there is no component clause, then we are in the clear
|
-- If there is no component clause, then we are in the clear
|
-- since the back end will never misalign a large component
|
-- since the back end will never misalign a large component
|
-- unless it is forced to do so. In the clear means we need
|
-- unless it is forced to do so. In the clear means we need
|
-- only the recursive test on the prefix.
|
-- only the recursive test on the prefix.
|
|
|
if Component_May_Be_Bit_Aligned (Comp) then
|
if Component_May_Be_Bit_Aligned (Comp) then
|
return True;
|
return True;
|
else
|
else
|
return Possible_Bit_Aligned_Component (P);
|
return Possible_Bit_Aligned_Component (P);
|
end if;
|
end if;
|
end;
|
end;
|
|
|
-- For a slice, test the prefix, if that is possibly misaligned,
|
-- For a slice, test the prefix, if that is possibly misaligned,
|
-- then for sure the slice is!
|
-- then for sure the slice is!
|
|
|
when N_Slice =>
|
when N_Slice =>
|
return Possible_Bit_Aligned_Component (Prefix (N));
|
return Possible_Bit_Aligned_Component (Prefix (N));
|
|
|
-- For an unchecked conversion, check whether the expression may
|
-- For an unchecked conversion, check whether the expression may
|
-- be bit-aligned.
|
-- be bit-aligned.
|
|
|
when N_Unchecked_Type_Conversion =>
|
when N_Unchecked_Type_Conversion =>
|
return Possible_Bit_Aligned_Component (Expression (N));
|
return Possible_Bit_Aligned_Component (Expression (N));
|
|
|
-- If we have none of the above, it means that we have fallen off the
|
-- If we have none of the above, it means that we have fallen off the
|
-- top testing prefixes recursively, and we now have a stand alone
|
-- top testing prefixes recursively, and we now have a stand alone
|
-- object, where we don't have a problem.
|
-- object, where we don't have a problem.
|
|
|
when others =>
|
when others =>
|
return False;
|
return False;
|
|
|
end case;
|
end case;
|
end Possible_Bit_Aligned_Component;
|
end Possible_Bit_Aligned_Component;
|
|
|
-----------------------------------------------
|
-----------------------------------------------
|
-- Process_Statements_For_Controlled_Objects --
|
-- Process_Statements_For_Controlled_Objects --
|
-----------------------------------------------
|
-----------------------------------------------
|
|
|
procedure Process_Statements_For_Controlled_Objects (N : Node_Id) is
|
procedure Process_Statements_For_Controlled_Objects (N : Node_Id) is
|
Loc : constant Source_Ptr := Sloc (N);
|
Loc : constant Source_Ptr := Sloc (N);
|
|
|
function Are_Wrapped (L : List_Id) return Boolean;
|
function Are_Wrapped (L : List_Id) return Boolean;
|
-- Determine whether list L contains only one statement which is a block
|
-- Determine whether list L contains only one statement which is a block
|
|
|
function Wrap_Statements_In_Block (L : List_Id) return Node_Id;
|
function Wrap_Statements_In_Block (L : List_Id) return Node_Id;
|
-- Given a list of statements L, wrap it in a block statement and return
|
-- Given a list of statements L, wrap it in a block statement and return
|
-- the generated node.
|
-- the generated node.
|
|
|
-----------------
|
-----------------
|
-- Are_Wrapped --
|
-- Are_Wrapped --
|
-----------------
|
-----------------
|
|
|
function Are_Wrapped (L : List_Id) return Boolean is
|
function Are_Wrapped (L : List_Id) return Boolean is
|
Stmt : constant Node_Id := First (L);
|
Stmt : constant Node_Id := First (L);
|
begin
|
begin
|
return
|
return
|
Present (Stmt)
|
Present (Stmt)
|
and then No (Next (Stmt))
|
and then No (Next (Stmt))
|
and then Nkind (Stmt) = N_Block_Statement;
|
and then Nkind (Stmt) = N_Block_Statement;
|
end Are_Wrapped;
|
end Are_Wrapped;
|
|
|
------------------------------
|
------------------------------
|
-- Wrap_Statements_In_Block --
|
-- Wrap_Statements_In_Block --
|
------------------------------
|
------------------------------
|
|
|
function Wrap_Statements_In_Block (L : List_Id) return Node_Id is
|
function Wrap_Statements_In_Block (L : List_Id) return Node_Id is
|
begin
|
begin
|
return
|
return
|
Make_Block_Statement (Loc,
|
Make_Block_Statement (Loc,
|
Declarations => No_List,
|
Declarations => No_List,
|
Handled_Statement_Sequence =>
|
Handled_Statement_Sequence =>
|
Make_Handled_Sequence_Of_Statements (Loc,
|
Make_Handled_Sequence_Of_Statements (Loc,
|
Statements => L));
|
Statements => L));
|
end Wrap_Statements_In_Block;
|
end Wrap_Statements_In_Block;
|
|
|
-- Local variables
|
-- Local variables
|
|
|
Block : Node_Id;
|
Block : Node_Id;
|
|
|
-- Start of processing for Process_Statements_For_Controlled_Objects
|
-- Start of processing for Process_Statements_For_Controlled_Objects
|
|
|
begin
|
begin
|
-- Whenever a non-handled statement list is wrapped in a block, the
|
-- Whenever a non-handled statement list is wrapped in a block, the
|
-- block must be explicitly analyzed to redecorate all entities in the
|
-- block must be explicitly analyzed to redecorate all entities in the
|
-- list and ensure that a finalizer is properly built.
|
-- list and ensure that a finalizer is properly built.
|
|
|
case Nkind (N) is
|
case Nkind (N) is
|
when N_Elsif_Part |
|
when N_Elsif_Part |
|
N_If_Statement |
|
N_If_Statement |
|
N_Conditional_Entry_Call |
|
N_Conditional_Entry_Call |
|
N_Selective_Accept =>
|
N_Selective_Accept =>
|
|
|
-- Check the "then statements" for elsif parts and if statements
|
-- Check the "then statements" for elsif parts and if statements
|
|
|
if Nkind_In (N, N_Elsif_Part, N_If_Statement)
|
if Nkind_In (N, N_Elsif_Part, N_If_Statement)
|
and then not Is_Empty_List (Then_Statements (N))
|
and then not Is_Empty_List (Then_Statements (N))
|
and then not Are_Wrapped (Then_Statements (N))
|
and then not Are_Wrapped (Then_Statements (N))
|
and then Requires_Cleanup_Actions
|
and then Requires_Cleanup_Actions
|
(Then_Statements (N), False, False)
|
(Then_Statements (N), False, False)
|
then
|
then
|
Block := Wrap_Statements_In_Block (Then_Statements (N));
|
Block := Wrap_Statements_In_Block (Then_Statements (N));
|
Set_Then_Statements (N, New_List (Block));
|
Set_Then_Statements (N, New_List (Block));
|
|
|
Analyze (Block);
|
Analyze (Block);
|
end if;
|
end if;
|
|
|
-- Check the "else statements" for conditional entry calls, if
|
-- Check the "else statements" for conditional entry calls, if
|
-- statements and selective accepts.
|
-- statements and selective accepts.
|
|
|
if Nkind_In (N, N_Conditional_Entry_Call,
|
if Nkind_In (N, N_Conditional_Entry_Call,
|
N_If_Statement,
|
N_If_Statement,
|
N_Selective_Accept)
|
N_Selective_Accept)
|
and then not Is_Empty_List (Else_Statements (N))
|
and then not Is_Empty_List (Else_Statements (N))
|
and then not Are_Wrapped (Else_Statements (N))
|
and then not Are_Wrapped (Else_Statements (N))
|
and then Requires_Cleanup_Actions
|
and then Requires_Cleanup_Actions
|
(Else_Statements (N), False, False)
|
(Else_Statements (N), False, False)
|
then
|
then
|
Block := Wrap_Statements_In_Block (Else_Statements (N));
|
Block := Wrap_Statements_In_Block (Else_Statements (N));
|
Set_Else_Statements (N, New_List (Block));
|
Set_Else_Statements (N, New_List (Block));
|
|
|
Analyze (Block);
|
Analyze (Block);
|
end if;
|
end if;
|
|
|
when N_Abortable_Part |
|
when N_Abortable_Part |
|
N_Accept_Alternative |
|
N_Accept_Alternative |
|
N_Case_Statement_Alternative |
|
N_Case_Statement_Alternative |
|
N_Delay_Alternative |
|
N_Delay_Alternative |
|
N_Entry_Call_Alternative |
|
N_Entry_Call_Alternative |
|
N_Exception_Handler |
|
N_Exception_Handler |
|
N_Loop_Statement |
|
N_Loop_Statement |
|
N_Triggering_Alternative =>
|
N_Triggering_Alternative =>
|
|
|
if not Is_Empty_List (Statements (N))
|
if not Is_Empty_List (Statements (N))
|
and then not Are_Wrapped (Statements (N))
|
and then not Are_Wrapped (Statements (N))
|
and then Requires_Cleanup_Actions (Statements (N), False, False)
|
and then Requires_Cleanup_Actions (Statements (N), False, False)
|
then
|
then
|
Block := Wrap_Statements_In_Block (Statements (N));
|
Block := Wrap_Statements_In_Block (Statements (N));
|
Set_Statements (N, New_List (Block));
|
Set_Statements (N, New_List (Block));
|
|
|
Analyze (Block);
|
Analyze (Block);
|
end if;
|
end if;
|
|
|
when others =>
|
when others =>
|
null;
|
null;
|
end case;
|
end case;
|
end Process_Statements_For_Controlled_Objects;
|
end Process_Statements_For_Controlled_Objects;
|
|
|
-------------------------
|
-------------------------
|
-- Remove_Side_Effects --
|
-- Remove_Side_Effects --
|
-------------------------
|
-------------------------
|
|
|
procedure Remove_Side_Effects
|
procedure Remove_Side_Effects
|
(Exp : Node_Id;
|
(Exp : Node_Id;
|
Name_Req : Boolean := False;
|
Name_Req : Boolean := False;
|
Variable_Ref : Boolean := False)
|
Variable_Ref : Boolean := False)
|
is
|
is
|
Loc : constant Source_Ptr := Sloc (Exp);
|
Loc : constant Source_Ptr := Sloc (Exp);
|
Exp_Type : constant Entity_Id := Etype (Exp);
|
Exp_Type : constant Entity_Id := Etype (Exp);
|
Svg_Suppress : constant Suppress_Array := Scope_Suppress;
|
Svg_Suppress : constant Suppress_Array := Scope_Suppress;
|
Def_Id : Entity_Id;
|
Def_Id : Entity_Id;
|
E : Node_Id;
|
E : Node_Id;
|
New_Exp : Node_Id;
|
New_Exp : Node_Id;
|
Ptr_Typ_Decl : Node_Id;
|
Ptr_Typ_Decl : Node_Id;
|
Ref_Type : Entity_Id;
|
Ref_Type : Entity_Id;
|
Res : Node_Id;
|
Res : Node_Id;
|
|
|
function Side_Effect_Free (N : Node_Id) return Boolean;
|
function Side_Effect_Free (N : Node_Id) return Boolean;
|
-- Determines if the tree N represents an expression that is known not
|
-- Determines if the tree N represents an expression that is known not
|
-- to have side effects, and for which no processing is required.
|
-- to have side effects, and for which no processing is required.
|
|
|
function Side_Effect_Free (L : List_Id) return Boolean;
|
function Side_Effect_Free (L : List_Id) return Boolean;
|
-- Determines if all elements of the list L are side effect free
|
-- Determines if all elements of the list L are side effect free
|
|
|
function Safe_Prefixed_Reference (N : Node_Id) return Boolean;
|
function Safe_Prefixed_Reference (N : Node_Id) return Boolean;
|
-- The argument N is a construct where the Prefix is dereferenced if it
|
-- The argument N is a construct where the Prefix is dereferenced if it
|
-- is an access type and the result is a variable. The call returns True
|
-- is an access type and the result is a variable. The call returns True
|
-- if the construct is side effect free (not considering side effects in
|
-- if the construct is side effect free (not considering side effects in
|
-- other than the prefix which are to be tested by the caller).
|
-- other than the prefix which are to be tested by the caller).
|
|
|
function Within_In_Parameter (N : Node_Id) return Boolean;
|
function Within_In_Parameter (N : Node_Id) return Boolean;
|
-- Determines if N is a subcomponent of a composite in-parameter. If so,
|
-- Determines if N is a subcomponent of a composite in-parameter. If so,
|
-- N is not side-effect free when the actual is global and modifiable
|
-- N is not side-effect free when the actual is global and modifiable
|
-- indirectly from within a subprogram, because it may be passed by
|
-- indirectly from within a subprogram, because it may be passed by
|
-- reference. The front-end must be conservative here and assume that
|
-- reference. The front-end must be conservative here and assume that
|
-- this may happen with any array or record type. On the other hand, we
|
-- this may happen with any array or record type. On the other hand, we
|
-- cannot create temporaries for all expressions for which this
|
-- cannot create temporaries for all expressions for which this
|
-- condition is true, for various reasons that might require clearing up
|
-- condition is true, for various reasons that might require clearing up
|
-- ??? For example, discriminant references that appear out of place, or
|
-- ??? For example, discriminant references that appear out of place, or
|
-- spurious type errors with class-wide expressions. As a result, we
|
-- spurious type errors with class-wide expressions. As a result, we
|
-- limit the transformation to loop bounds, which is so far the only
|
-- limit the transformation to loop bounds, which is so far the only
|
-- case that requires it.
|
-- case that requires it.
|
|
|
-----------------------------
|
-----------------------------
|
-- Safe_Prefixed_Reference --
|
-- Safe_Prefixed_Reference --
|
-----------------------------
|
-----------------------------
|
|
|
function Safe_Prefixed_Reference (N : Node_Id) return Boolean is
|
function Safe_Prefixed_Reference (N : Node_Id) return Boolean is
|
begin
|
begin
|
-- If prefix is not side effect free, definitely not safe
|
-- If prefix is not side effect free, definitely not safe
|
|
|
if not Side_Effect_Free (Prefix (N)) then
|
if not Side_Effect_Free (Prefix (N)) then
|
return False;
|
return False;
|
|
|
-- If the prefix is of an access type that is not access-to-constant,
|
-- If the prefix is of an access type that is not access-to-constant,
|
-- then this construct is a variable reference, which means it is to
|
-- then this construct is a variable reference, which means it is to
|
-- be considered to have side effects if Variable_Ref is set True.
|
-- be considered to have side effects if Variable_Ref is set True.
|
|
|
elsif Is_Access_Type (Etype (Prefix (N)))
|
elsif Is_Access_Type (Etype (Prefix (N)))
|
and then not Is_Access_Constant (Etype (Prefix (N)))
|
and then not Is_Access_Constant (Etype (Prefix (N)))
|
and then Variable_Ref
|
and then Variable_Ref
|
then
|
then
|
-- Exception is a prefix that is the result of a previous removal
|
-- Exception is a prefix that is the result of a previous removal
|
-- of side-effects.
|
-- of side-effects.
|
|
|
return Is_Entity_Name (Prefix (N))
|
return Is_Entity_Name (Prefix (N))
|
and then not Comes_From_Source (Prefix (N))
|
and then not Comes_From_Source (Prefix (N))
|
and then Ekind (Entity (Prefix (N))) = E_Constant
|
and then Ekind (Entity (Prefix (N))) = E_Constant
|
and then Is_Internal_Name (Chars (Entity (Prefix (N))));
|
and then Is_Internal_Name (Chars (Entity (Prefix (N))));
|
|
|
-- If the prefix is an explicit dereference then this construct is a
|
-- If the prefix is an explicit dereference then this construct is a
|
-- variable reference, which means it is to be considered to have
|
-- variable reference, which means it is to be considered to have
|
-- side effects if Variable_Ref is True.
|
-- side effects if Variable_Ref is True.
|
|
|
-- We do NOT exclude dereferences of access-to-constant types because
|
-- We do NOT exclude dereferences of access-to-constant types because
|
-- we handle them as constant view of variables.
|
-- we handle them as constant view of variables.
|
|
|
elsif Nkind (Prefix (N)) = N_Explicit_Dereference
|
elsif Nkind (Prefix (N)) = N_Explicit_Dereference
|
and then Variable_Ref
|
and then Variable_Ref
|
then
|
then
|
return False;
|
return False;
|
|
|
-- Note: The following test is the simplest way of solving a complex
|
-- Note: The following test is the simplest way of solving a complex
|
-- problem uncovered by the following test (Side effect on loop bound
|
-- problem uncovered by the following test (Side effect on loop bound
|
-- that is a subcomponent of a global variable:
|
-- that is a subcomponent of a global variable:
|
|
|
-- with Text_Io; use Text_Io;
|
-- with Text_Io; use Text_Io;
|
-- procedure Tloop is
|
-- procedure Tloop is
|
-- type X is
|
-- type X is
|
-- record
|
-- record
|
-- V : Natural := 4;
|
-- V : Natural := 4;
|
-- S : String (1..5) := (others => 'a');
|
-- S : String (1..5) := (others => 'a');
|
-- end record;
|
-- end record;
|
-- X1 : X;
|
-- X1 : X;
|
|
|
-- procedure Modi;
|
-- procedure Modi;
|
|
|
-- generic
|
-- generic
|
-- with procedure Action;
|
-- with procedure Action;
|
-- procedure Loop_G (Arg : X; Msg : String)
|
-- procedure Loop_G (Arg : X; Msg : String)
|
|
|
-- procedure Loop_G (Arg : X; Msg : String) is
|
-- procedure Loop_G (Arg : X; Msg : String) is
|
-- begin
|
-- begin
|
-- Put_Line ("begin loop_g " & Msg & " will loop till: "
|
-- Put_Line ("begin loop_g " & Msg & " will loop till: "
|
-- & Natural'Image (Arg.V));
|
-- & Natural'Image (Arg.V));
|
-- for Index in 1 .. Arg.V loop
|
-- for Index in 1 .. Arg.V loop
|
-- Text_Io.Put_Line
|
-- Text_Io.Put_Line
|
-- (Natural'Image (Index) & " " & Arg.S (Index));
|
-- (Natural'Image (Index) & " " & Arg.S (Index));
|
-- if Index > 2 then
|
-- if Index > 2 then
|
-- Modi;
|
-- Modi;
|
-- end if;
|
-- end if;
|
-- end loop;
|
-- end loop;
|
-- Put_Line ("end loop_g " & Msg);
|
-- Put_Line ("end loop_g " & Msg);
|
-- end;
|
-- end;
|
|
|
-- procedure Loop1 is new Loop_G (Modi);
|
-- procedure Loop1 is new Loop_G (Modi);
|
-- procedure Modi is
|
-- procedure Modi is
|
-- begin
|
-- begin
|
-- X1.V := 1;
|
-- X1.V := 1;
|
-- Loop1 (X1, "from modi");
|
-- Loop1 (X1, "from modi");
|
-- end;
|
-- end;
|
--
|
--
|
-- begin
|
-- begin
|
-- Loop1 (X1, "initial");
|
-- Loop1 (X1, "initial");
|
-- end;
|
-- end;
|
|
|
-- The output of the above program should be:
|
-- The output of the above program should be:
|
|
|
-- begin loop_g initial will loop till: 4
|
-- begin loop_g initial will loop till: 4
|
-- 1 a
|
-- 1 a
|
-- 2 a
|
-- 2 a
|
-- 3 a
|
-- 3 a
|
-- begin loop_g from modi will loop till: 1
|
-- begin loop_g from modi will loop till: 1
|
-- 1 a
|
-- 1 a
|
-- end loop_g from modi
|
-- end loop_g from modi
|
-- 4 a
|
-- 4 a
|
-- begin loop_g from modi will loop till: 1
|
-- begin loop_g from modi will loop till: 1
|
-- 1 a
|
-- 1 a
|
-- end loop_g from modi
|
-- end loop_g from modi
|
-- end loop_g initial
|
-- end loop_g initial
|
|
|
-- If a loop bound is a subcomponent of a global variable, a
|
-- If a loop bound is a subcomponent of a global variable, a
|
-- modification of that variable within the loop may incorrectly
|
-- modification of that variable within the loop may incorrectly
|
-- affect the execution of the loop.
|
-- affect the execution of the loop.
|
|
|
elsif Nkind (Parent (Parent (N))) = N_Loop_Parameter_Specification
|
elsif Nkind (Parent (Parent (N))) = N_Loop_Parameter_Specification
|
and then Within_In_Parameter (Prefix (N))
|
and then Within_In_Parameter (Prefix (N))
|
and then Variable_Ref
|
and then Variable_Ref
|
then
|
then
|
return False;
|
return False;
|
|
|
-- All other cases are side effect free
|
-- All other cases are side effect free
|
|
|
else
|
else
|
return True;
|
return True;
|
end if;
|
end if;
|
end Safe_Prefixed_Reference;
|
end Safe_Prefixed_Reference;
|
|
|
----------------------
|
----------------------
|
-- Side_Effect_Free --
|
-- Side_Effect_Free --
|
----------------------
|
----------------------
|
|
|
function Side_Effect_Free (N : Node_Id) return Boolean is
|
function Side_Effect_Free (N : Node_Id) return Boolean is
|
begin
|
begin
|
-- Note on checks that could raise Constraint_Error. Strictly, if we
|
-- Note on checks that could raise Constraint_Error. Strictly, if we
|
-- take advantage of 11.6, these checks do not count as side effects.
|
-- take advantage of 11.6, these checks do not count as side effects.
|
-- However, we would prefer to consider that they are side effects,
|
-- However, we would prefer to consider that they are side effects,
|
-- since the backend CSE does not work very well on expressions which
|
-- since the backend CSE does not work very well on expressions which
|
-- can raise Constraint_Error. On the other hand if we don't consider
|
-- can raise Constraint_Error. On the other hand if we don't consider
|
-- them to be side effect free, then we get some awkward expansions
|
-- them to be side effect free, then we get some awkward expansions
|
-- in -gnato mode, resulting in code insertions at a point where we
|
-- in -gnato mode, resulting in code insertions at a point where we
|
-- do not have a clear model for performing the insertions.
|
-- do not have a clear model for performing the insertions.
|
|
|
-- Special handling for entity names
|
-- Special handling for entity names
|
|
|
if Is_Entity_Name (N) then
|
if Is_Entity_Name (N) then
|
|
|
-- Variables are considered to be a side effect if Variable_Ref
|
-- Variables are considered to be a side effect if Variable_Ref
|
-- is set or if we have a volatile reference and Name_Req is off.
|
-- is set or if we have a volatile reference and Name_Req is off.
|
-- If Name_Req is True then we can't help returning a name which
|
-- If Name_Req is True then we can't help returning a name which
|
-- effectively allows multiple references in any case.
|
-- effectively allows multiple references in any case.
|
|
|
if Is_Variable (N, Use_Original_Node => False) then
|
if Is_Variable (N, Use_Original_Node => False) then
|
return not Variable_Ref
|
return not Variable_Ref
|
and then (not Is_Volatile_Reference (N) or else Name_Req);
|
and then (not Is_Volatile_Reference (N) or else Name_Req);
|
|
|
-- Any other entity (e.g. a subtype name) is definitely side
|
-- Any other entity (e.g. a subtype name) is definitely side
|
-- effect free.
|
-- effect free.
|
|
|
else
|
else
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- A value known at compile time is always side effect free
|
-- A value known at compile time is always side effect free
|
|
|
elsif Compile_Time_Known_Value (N) then
|
elsif Compile_Time_Known_Value (N) then
|
return True;
|
return True;
|
|
|
-- A variable renaming is not side-effect free, because the renaming
|
-- A variable renaming is not side-effect free, because the renaming
|
-- will function like a macro in the front-end in some cases, and an
|
-- will function like a macro in the front-end in some cases, and an
|
-- assignment can modify the component designated by N, so we need to
|
-- assignment can modify the component designated by N, so we need to
|
-- create a temporary for it.
|
-- create a temporary for it.
|
|
|
-- The guard testing for Entity being present is needed at least in
|
-- The guard testing for Entity being present is needed at least in
|
-- the case of rewritten predicate expressions, and may well also be
|
-- the case of rewritten predicate expressions, and may well also be
|
-- appropriate elsewhere. Obviously we can't go testing the entity
|
-- appropriate elsewhere. Obviously we can't go testing the entity
|
-- field if it does not exist, so it's reasonable to say that this is
|
-- field if it does not exist, so it's reasonable to say that this is
|
-- not the renaming case if it does not exist.
|
-- not the renaming case if it does not exist.
|
|
|
elsif Is_Entity_Name (Original_Node (N))
|
elsif Is_Entity_Name (Original_Node (N))
|
and then Present (Entity (Original_Node (N)))
|
and then Present (Entity (Original_Node (N)))
|
and then Is_Renaming_Of_Object (Entity (Original_Node (N)))
|
and then Is_Renaming_Of_Object (Entity (Original_Node (N)))
|
and then Ekind (Entity (Original_Node (N))) /= E_Constant
|
and then Ekind (Entity (Original_Node (N))) /= E_Constant
|
then
|
then
|
return False;
|
return False;
|
|
|
-- Remove_Side_Effects generates an object renaming declaration to
|
-- Remove_Side_Effects generates an object renaming declaration to
|
-- capture the expression of a class-wide expression. In VM targets
|
-- capture the expression of a class-wide expression. In VM targets
|
-- the frontend performs no expansion for dispatching calls to
|
-- the frontend performs no expansion for dispatching calls to
|
-- class- wide types since they are handled by the VM. Hence, we must
|
-- class- wide types since they are handled by the VM. Hence, we must
|
-- locate here if this node corresponds to a previous invocation of
|
-- locate here if this node corresponds to a previous invocation of
|
-- Remove_Side_Effects to avoid a never ending loop in the frontend.
|
-- Remove_Side_Effects to avoid a never ending loop in the frontend.
|
|
|
elsif VM_Target /= No_VM
|
elsif VM_Target /= No_VM
|
and then not Comes_From_Source (N)
|
and then not Comes_From_Source (N)
|
and then Nkind (Parent (N)) = N_Object_Renaming_Declaration
|
and then Nkind (Parent (N)) = N_Object_Renaming_Declaration
|
and then Is_Class_Wide_Type (Etype (N))
|
and then Is_Class_Wide_Type (Etype (N))
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- For other than entity names and compile time known values,
|
-- For other than entity names and compile time known values,
|
-- check the node kind for special processing.
|
-- check the node kind for special processing.
|
|
|
case Nkind (N) is
|
case Nkind (N) is
|
|
|
-- An attribute reference is side effect free if its expressions
|
-- An attribute reference is side effect free if its expressions
|
-- are side effect free and its prefix is side effect free or
|
-- are side effect free and its prefix is side effect free or
|
-- is an entity reference.
|
-- is an entity reference.
|
|
|
-- Is this right? what about x'first where x is a variable???
|
-- Is this right? what about x'first where x is a variable???
|
|
|
when N_Attribute_Reference =>
|
when N_Attribute_Reference =>
|
return Side_Effect_Free (Expressions (N))
|
return Side_Effect_Free (Expressions (N))
|
and then Attribute_Name (N) /= Name_Input
|
and then Attribute_Name (N) /= Name_Input
|
and then (Is_Entity_Name (Prefix (N))
|
and then (Is_Entity_Name (Prefix (N))
|
or else Side_Effect_Free (Prefix (N)));
|
or else Side_Effect_Free (Prefix (N)));
|
|
|
-- A binary operator is side effect free if and both operands are
|
-- A binary operator is side effect free if and both operands are
|
-- side effect free. For this purpose binary operators include
|
-- side effect free. For this purpose binary operators include
|
-- membership tests and short circuit forms.
|
-- membership tests and short circuit forms.
|
|
|
when N_Binary_Op | N_Membership_Test | N_Short_Circuit =>
|
when N_Binary_Op | N_Membership_Test | N_Short_Circuit =>
|
return Side_Effect_Free (Left_Opnd (N))
|
return Side_Effect_Free (Left_Opnd (N))
|
and then
|
and then
|
Side_Effect_Free (Right_Opnd (N));
|
Side_Effect_Free (Right_Opnd (N));
|
|
|
-- An explicit dereference is side effect free only if it is
|
-- An explicit dereference is side effect free only if it is
|
-- a side effect free prefixed reference.
|
-- a side effect free prefixed reference.
|
|
|
when N_Explicit_Dereference =>
|
when N_Explicit_Dereference =>
|
return Safe_Prefixed_Reference (N);
|
return Safe_Prefixed_Reference (N);
|
|
|
-- A call to _rep_to_pos is side effect free, since we generate
|
-- A call to _rep_to_pos is side effect free, since we generate
|
-- this pure function call ourselves. Moreover it is critically
|
-- this pure function call ourselves. Moreover it is critically
|
-- important to make this exception, since otherwise we can have
|
-- important to make this exception, since otherwise we can have
|
-- discriminants in array components which don't look side effect
|
-- discriminants in array components which don't look side effect
|
-- free in the case of an array whose index type is an enumeration
|
-- free in the case of an array whose index type is an enumeration
|
-- type with an enumeration rep clause.
|
-- type with an enumeration rep clause.
|
|
|
-- All other function calls are not side effect free
|
-- All other function calls are not side effect free
|
|
|
when N_Function_Call =>
|
when N_Function_Call =>
|
return Nkind (Name (N)) = N_Identifier
|
return Nkind (Name (N)) = N_Identifier
|
and then Is_TSS (Name (N), TSS_Rep_To_Pos)
|
and then Is_TSS (Name (N), TSS_Rep_To_Pos)
|
and then
|
and then
|
Side_Effect_Free (First (Parameter_Associations (N)));
|
Side_Effect_Free (First (Parameter_Associations (N)));
|
|
|
-- An indexed component is side effect free if it is a side
|
-- An indexed component is side effect free if it is a side
|
-- effect free prefixed reference and all the indexing
|
-- effect free prefixed reference and all the indexing
|
-- expressions are side effect free.
|
-- expressions are side effect free.
|
|
|
when N_Indexed_Component =>
|
when N_Indexed_Component =>
|
return Side_Effect_Free (Expressions (N))
|
return Side_Effect_Free (Expressions (N))
|
and then Safe_Prefixed_Reference (N);
|
and then Safe_Prefixed_Reference (N);
|
|
|
-- A type qualification is side effect free if the expression
|
-- A type qualification is side effect free if the expression
|
-- is side effect free.
|
-- is side effect free.
|
|
|
when N_Qualified_Expression =>
|
when N_Qualified_Expression =>
|
return Side_Effect_Free (Expression (N));
|
return Side_Effect_Free (Expression (N));
|
|
|
-- A selected component is side effect free only if it is a side
|
-- A selected component is side effect free only if it is a side
|
-- effect free prefixed reference. If it designates a component
|
-- effect free prefixed reference. If it designates a component
|
-- with a rep. clause it must be treated has having a potential
|
-- with a rep. clause it must be treated has having a potential
|
-- side effect, because it may be modified through a renaming, and
|
-- side effect, because it may be modified through a renaming, and
|
-- a subsequent use of the renaming as a macro will yield the
|
-- a subsequent use of the renaming as a macro will yield the
|
-- wrong value. This complex interaction between renaming and
|
-- wrong value. This complex interaction between renaming and
|
-- removing side effects is a reminder that the latter has become
|
-- removing side effects is a reminder that the latter has become
|
-- a headache to maintain, and that it should be removed in favor
|
-- a headache to maintain, and that it should be removed in favor
|
-- of the gcc mechanism to capture values ???
|
-- of the gcc mechanism to capture values ???
|
|
|
when N_Selected_Component =>
|
when N_Selected_Component =>
|
if Nkind (Parent (N)) = N_Explicit_Dereference
|
if Nkind (Parent (N)) = N_Explicit_Dereference
|
and then Has_Non_Standard_Rep (Designated_Type (Etype (N)))
|
and then Has_Non_Standard_Rep (Designated_Type (Etype (N)))
|
then
|
then
|
return False;
|
return False;
|
else
|
else
|
return Safe_Prefixed_Reference (N);
|
return Safe_Prefixed_Reference (N);
|
end if;
|
end if;
|
|
|
-- A range is side effect free if the bounds are side effect free
|
-- A range is side effect free if the bounds are side effect free
|
|
|
when N_Range =>
|
when N_Range =>
|
return Side_Effect_Free (Low_Bound (N))
|
return Side_Effect_Free (Low_Bound (N))
|
and then Side_Effect_Free (High_Bound (N));
|
and then Side_Effect_Free (High_Bound (N));
|
|
|
-- A slice is side effect free if it is a side effect free
|
-- A slice is side effect free if it is a side effect free
|
-- prefixed reference and the bounds are side effect free.
|
-- prefixed reference and the bounds are side effect free.
|
|
|
when N_Slice =>
|
when N_Slice =>
|
return Side_Effect_Free (Discrete_Range (N))
|
return Side_Effect_Free (Discrete_Range (N))
|
and then Safe_Prefixed_Reference (N);
|
and then Safe_Prefixed_Reference (N);
|
|
|
-- A type conversion is side effect free if the expression to be
|
-- A type conversion is side effect free if the expression to be
|
-- converted is side effect free.
|
-- converted is side effect free.
|
|
|
when N_Type_Conversion =>
|
when N_Type_Conversion =>
|
return Side_Effect_Free (Expression (N));
|
return Side_Effect_Free (Expression (N));
|
|
|
-- A unary operator is side effect free if the operand
|
-- A unary operator is side effect free if the operand
|
-- is side effect free.
|
-- is side effect free.
|
|
|
when N_Unary_Op =>
|
when N_Unary_Op =>
|
return Side_Effect_Free (Right_Opnd (N));
|
return Side_Effect_Free (Right_Opnd (N));
|
|
|
-- An unchecked type conversion is side effect free only if it
|
-- An unchecked type conversion is side effect free only if it
|
-- is safe and its argument is side effect free.
|
-- is safe and its argument is side effect free.
|
|
|
when N_Unchecked_Type_Conversion =>
|
when N_Unchecked_Type_Conversion =>
|
return Safe_Unchecked_Type_Conversion (N)
|
return Safe_Unchecked_Type_Conversion (N)
|
and then Side_Effect_Free (Expression (N));
|
and then Side_Effect_Free (Expression (N));
|
|
|
-- An unchecked expression is side effect free if its expression
|
-- An unchecked expression is side effect free if its expression
|
-- is side effect free.
|
-- is side effect free.
|
|
|
when N_Unchecked_Expression =>
|
when N_Unchecked_Expression =>
|
return Side_Effect_Free (Expression (N));
|
return Side_Effect_Free (Expression (N));
|
|
|
-- A literal is side effect free
|
-- A literal is side effect free
|
|
|
when N_Character_Literal |
|
when N_Character_Literal |
|
N_Integer_Literal |
|
N_Integer_Literal |
|
N_Real_Literal |
|
N_Real_Literal |
|
N_String_Literal =>
|
N_String_Literal =>
|
return True;
|
return True;
|
|
|
-- We consider that anything else has side effects. This is a bit
|
-- We consider that anything else has side effects. This is a bit
|
-- crude, but we are pretty close for most common cases, and we
|
-- crude, but we are pretty close for most common cases, and we
|
-- are certainly correct (i.e. we never return True when the
|
-- are certainly correct (i.e. we never return True when the
|
-- answer should be False).
|
-- answer should be False).
|
|
|
when others =>
|
when others =>
|
return False;
|
return False;
|
end case;
|
end case;
|
end Side_Effect_Free;
|
end Side_Effect_Free;
|
|
|
-- A list is side effect free if all elements of the list are side
|
-- A list is side effect free if all elements of the list are side
|
-- effect free.
|
-- effect free.
|
|
|
function Side_Effect_Free (L : List_Id) return Boolean is
|
function Side_Effect_Free (L : List_Id) return Boolean is
|
N : Node_Id;
|
N : Node_Id;
|
|
|
begin
|
begin
|
if L = No_List or else L = Error_List then
|
if L = No_List or else L = Error_List then
|
return True;
|
return True;
|
|
|
else
|
else
|
N := First (L);
|
N := First (L);
|
while Present (N) loop
|
while Present (N) loop
|
if not Side_Effect_Free (N) then
|
if not Side_Effect_Free (N) then
|
return False;
|
return False;
|
else
|
else
|
Next (N);
|
Next (N);
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
return True;
|
return True;
|
end if;
|
end if;
|
end Side_Effect_Free;
|
end Side_Effect_Free;
|
|
|
-------------------------
|
-------------------------
|
-- Within_In_Parameter --
|
-- Within_In_Parameter --
|
-------------------------
|
-------------------------
|
|
|
function Within_In_Parameter (N : Node_Id) return Boolean is
|
function Within_In_Parameter (N : Node_Id) return Boolean is
|
begin
|
begin
|
if not Comes_From_Source (N) then
|
if not Comes_From_Source (N) then
|
return False;
|
return False;
|
|
|
elsif Is_Entity_Name (N) then
|
elsif Is_Entity_Name (N) then
|
return Ekind (Entity (N)) = E_In_Parameter;
|
return Ekind (Entity (N)) = E_In_Parameter;
|
|
|
elsif Nkind (N) = N_Indexed_Component
|
elsif Nkind (N) = N_Indexed_Component
|
or else Nkind (N) = N_Selected_Component
|
or else Nkind (N) = N_Selected_Component
|
then
|
then
|
return Within_In_Parameter (Prefix (N));
|
return Within_In_Parameter (Prefix (N));
|
else
|
else
|
|
|
return False;
|
return False;
|
end if;
|
end if;
|
end Within_In_Parameter;
|
end Within_In_Parameter;
|
|
|
-- Start of processing for Remove_Side_Effects
|
-- Start of processing for Remove_Side_Effects
|
|
|
begin
|
begin
|
-- Handle cases in which there is nothing to do
|
-- Handle cases in which there is nothing to do
|
|
|
if not Expander_Active then
|
if not Expander_Active then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Cannot generate temporaries if the invocation to remove side effects
|
-- Cannot generate temporaries if the invocation to remove side effects
|
-- was issued too early and the type of the expression is not resolved
|
-- was issued too early and the type of the expression is not resolved
|
-- (this happens because routines Duplicate_Subexpr_XX implicitly invoke
|
-- (this happens because routines Duplicate_Subexpr_XX implicitly invoke
|
-- Remove_Side_Effects).
|
-- Remove_Side_Effects).
|
|
|
if No (Exp_Type)
|
if No (Exp_Type)
|
or else Ekind (Exp_Type) = E_Access_Attribute_Type
|
or else Ekind (Exp_Type) = E_Access_Attribute_Type
|
then
|
then
|
return;
|
return;
|
|
|
-- No action needed for side-effect free expressions
|
-- No action needed for side-effect free expressions
|
|
|
elsif Side_Effect_Free (Exp) then
|
elsif Side_Effect_Free (Exp) then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- All this must not have any checks
|
-- All this must not have any checks
|
|
|
Scope_Suppress := (others => True);
|
Scope_Suppress := (others => True);
|
|
|
-- If it is a scalar type and we need to capture the value, just make
|
-- If it is a scalar type and we need to capture the value, just make
|
-- a copy. Likewise for a function call, an attribute reference, an
|
-- a copy. Likewise for a function call, an attribute reference, an
|
-- allocator, or an operator. And if we have a volatile reference and
|
-- allocator, or an operator. And if we have a volatile reference and
|
-- Name_Req is not set (see comments above for Side_Effect_Free).
|
-- Name_Req is not set (see comments above for Side_Effect_Free).
|
|
|
if Is_Elementary_Type (Exp_Type)
|
if Is_Elementary_Type (Exp_Type)
|
and then (Variable_Ref
|
and then (Variable_Ref
|
or else Nkind (Exp) = N_Function_Call
|
or else Nkind (Exp) = N_Function_Call
|
or else Nkind (Exp) = N_Attribute_Reference
|
or else Nkind (Exp) = N_Attribute_Reference
|
or else Nkind (Exp) = N_Allocator
|
or else Nkind (Exp) = N_Allocator
|
or else Nkind (Exp) in N_Op
|
or else Nkind (Exp) in N_Op
|
or else (not Name_Req and then Is_Volatile_Reference (Exp)))
|
or else (not Name_Req and then Is_Volatile_Reference (Exp)))
|
then
|
then
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
Set_Etype (Def_Id, Exp_Type);
|
Set_Etype (Def_Id, Exp_Type);
|
Res := New_Reference_To (Def_Id, Loc);
|
Res := New_Reference_To (Def_Id, Loc);
|
|
|
-- If the expression is a packed reference, it must be reanalyzed and
|
-- If the expression is a packed reference, it must be reanalyzed and
|
-- expanded, depending on context. This is the case for actuals where
|
-- expanded, depending on context. This is the case for actuals where
|
-- a constraint check may capture the actual before expansion of the
|
-- a constraint check may capture the actual before expansion of the
|
-- call is complete.
|
-- call is complete.
|
|
|
if Nkind (Exp) = N_Indexed_Component
|
if Nkind (Exp) = N_Indexed_Component
|
and then Is_Packed (Etype (Prefix (Exp)))
|
and then Is_Packed (Etype (Prefix (Exp)))
|
then
|
then
|
Set_Analyzed (Exp, False);
|
Set_Analyzed (Exp, False);
|
Set_Analyzed (Prefix (Exp), False);
|
Set_Analyzed (Prefix (Exp), False);
|
end if;
|
end if;
|
|
|
E :=
|
E :=
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Def_Id,
|
Defining_Identifier => Def_Id,
|
Object_Definition => New_Reference_To (Exp_Type, Loc),
|
Object_Definition => New_Reference_To (Exp_Type, Loc),
|
Constant_Present => True,
|
Constant_Present => True,
|
Expression => Relocate_Node (Exp));
|
Expression => Relocate_Node (Exp));
|
|
|
Set_Assignment_OK (E);
|
Set_Assignment_OK (E);
|
Insert_Action (Exp, E);
|
Insert_Action (Exp, E);
|
|
|
-- If the expression has the form v.all then we can just capture the
|
-- If the expression has the form v.all then we can just capture the
|
-- pointer, and then do an explicit dereference on the result.
|
-- pointer, and then do an explicit dereference on the result.
|
|
|
elsif Nkind (Exp) = N_Explicit_Dereference then
|
elsif Nkind (Exp) = N_Explicit_Dereference then
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
Res :=
|
Res :=
|
Make_Explicit_Dereference (Loc, New_Reference_To (Def_Id, Loc));
|
Make_Explicit_Dereference (Loc, New_Reference_To (Def_Id, Loc));
|
|
|
Insert_Action (Exp,
|
Insert_Action (Exp,
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Def_Id,
|
Defining_Identifier => Def_Id,
|
Object_Definition =>
|
Object_Definition =>
|
New_Reference_To (Etype (Prefix (Exp)), Loc),
|
New_Reference_To (Etype (Prefix (Exp)), Loc),
|
Constant_Present => True,
|
Constant_Present => True,
|
Expression => Relocate_Node (Prefix (Exp))));
|
Expression => Relocate_Node (Prefix (Exp))));
|
|
|
-- Similar processing for an unchecked conversion of an expression of
|
-- Similar processing for an unchecked conversion of an expression of
|
-- the form v.all, where we want the same kind of treatment.
|
-- the form v.all, where we want the same kind of treatment.
|
|
|
elsif Nkind (Exp) = N_Unchecked_Type_Conversion
|
elsif Nkind (Exp) = N_Unchecked_Type_Conversion
|
and then Nkind (Expression (Exp)) = N_Explicit_Dereference
|
and then Nkind (Expression (Exp)) = N_Explicit_Dereference
|
then
|
then
|
Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
|
Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
|
Scope_Suppress := Svg_Suppress;
|
Scope_Suppress := Svg_Suppress;
|
return;
|
return;
|
|
|
-- If this is a type conversion, leave the type conversion and remove
|
-- If this is a type conversion, leave the type conversion and remove
|
-- the side effects in the expression. This is important in several
|
-- the side effects in the expression. This is important in several
|
-- circumstances: for change of representations, and also when this is a
|
-- circumstances: for change of representations, and also when this is a
|
-- view conversion to a smaller object, where gigi can end up creating
|
-- view conversion to a smaller object, where gigi can end up creating
|
-- its own temporary of the wrong size.
|
-- its own temporary of the wrong size.
|
|
|
elsif Nkind (Exp) = N_Type_Conversion then
|
elsif Nkind (Exp) = N_Type_Conversion then
|
Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
|
Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
|
Scope_Suppress := Svg_Suppress;
|
Scope_Suppress := Svg_Suppress;
|
return;
|
return;
|
|
|
-- If this is an unchecked conversion that Gigi can't handle, make
|
-- If this is an unchecked conversion that Gigi can't handle, make
|
-- a copy or a use a renaming to capture the value.
|
-- a copy or a use a renaming to capture the value.
|
|
|
elsif Nkind (Exp) = N_Unchecked_Type_Conversion
|
elsif Nkind (Exp) = N_Unchecked_Type_Conversion
|
and then not Safe_Unchecked_Type_Conversion (Exp)
|
and then not Safe_Unchecked_Type_Conversion (Exp)
|
then
|
then
|
if CW_Or_Has_Controlled_Part (Exp_Type) then
|
if CW_Or_Has_Controlled_Part (Exp_Type) then
|
|
|
-- Use a renaming to capture the expression, rather than create
|
-- Use a renaming to capture the expression, rather than create
|
-- a controlled temporary.
|
-- a controlled temporary.
|
|
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
Res := New_Reference_To (Def_Id, Loc);
|
Res := New_Reference_To (Def_Id, Loc);
|
|
|
Insert_Action (Exp,
|
Insert_Action (Exp,
|
Make_Object_Renaming_Declaration (Loc,
|
Make_Object_Renaming_Declaration (Loc,
|
Defining_Identifier => Def_Id,
|
Defining_Identifier => Def_Id,
|
Subtype_Mark => New_Reference_To (Exp_Type, Loc),
|
Subtype_Mark => New_Reference_To (Exp_Type, Loc),
|
Name => Relocate_Node (Exp)));
|
Name => Relocate_Node (Exp)));
|
|
|
else
|
else
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
Set_Etype (Def_Id, Exp_Type);
|
Set_Etype (Def_Id, Exp_Type);
|
Res := New_Reference_To (Def_Id, Loc);
|
Res := New_Reference_To (Def_Id, Loc);
|
|
|
E :=
|
E :=
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Def_Id,
|
Defining_Identifier => Def_Id,
|
Object_Definition => New_Reference_To (Exp_Type, Loc),
|
Object_Definition => New_Reference_To (Exp_Type, Loc),
|
Constant_Present => not Is_Variable (Exp),
|
Constant_Present => not Is_Variable (Exp),
|
Expression => Relocate_Node (Exp));
|
Expression => Relocate_Node (Exp));
|
|
|
Set_Assignment_OK (E);
|
Set_Assignment_OK (E);
|
Insert_Action (Exp, E);
|
Insert_Action (Exp, E);
|
end if;
|
end if;
|
|
|
-- For expressions that denote objects, we can use a renaming scheme.
|
-- For expressions that denote objects, we can use a renaming scheme.
|
-- This is needed for correctness in the case of a volatile object of a
|
-- This is needed for correctness in the case of a volatile object of a
|
-- non-volatile type because the Make_Reference call of the "default"
|
-- non-volatile type because the Make_Reference call of the "default"
|
-- approach would generate an illegal access value (an access value
|
-- approach would generate an illegal access value (an access value
|
-- cannot designate such an object - see Analyze_Reference). We skip
|
-- cannot designate such an object - see Analyze_Reference). We skip
|
-- using this scheme if we have an object of a volatile type and we do
|
-- using this scheme if we have an object of a volatile type and we do
|
-- not have Name_Req set true (see comments above for Side_Effect_Free).
|
-- not have Name_Req set true (see comments above for Side_Effect_Free).
|
|
|
elsif Is_Object_Reference (Exp)
|
elsif Is_Object_Reference (Exp)
|
and then Nkind (Exp) /= N_Function_Call
|
and then Nkind (Exp) /= N_Function_Call
|
and then (Name_Req or else not Treat_As_Volatile (Exp_Type))
|
and then (Name_Req or else not Treat_As_Volatile (Exp_Type))
|
then
|
then
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
|
|
if Nkind (Exp) = N_Selected_Component
|
if Nkind (Exp) = N_Selected_Component
|
and then Nkind (Prefix (Exp)) = N_Function_Call
|
and then Nkind (Prefix (Exp)) = N_Function_Call
|
and then Is_Array_Type (Exp_Type)
|
and then Is_Array_Type (Exp_Type)
|
then
|
then
|
-- Avoid generating a variable-sized temporary, by generating
|
-- Avoid generating a variable-sized temporary, by generating
|
-- the renaming declaration just for the function call. The
|
-- the renaming declaration just for the function call. The
|
-- transformation could be refined to apply only when the array
|
-- transformation could be refined to apply only when the array
|
-- component is constrained by a discriminant???
|
-- component is constrained by a discriminant???
|
|
|
Res :=
|
Res :=
|
Make_Selected_Component (Loc,
|
Make_Selected_Component (Loc,
|
Prefix => New_Occurrence_Of (Def_Id, Loc),
|
Prefix => New_Occurrence_Of (Def_Id, Loc),
|
Selector_Name => Selector_Name (Exp));
|
Selector_Name => Selector_Name (Exp));
|
|
|
Insert_Action (Exp,
|
Insert_Action (Exp,
|
Make_Object_Renaming_Declaration (Loc,
|
Make_Object_Renaming_Declaration (Loc,
|
Defining_Identifier => Def_Id,
|
Defining_Identifier => Def_Id,
|
Subtype_Mark =>
|
Subtype_Mark =>
|
New_Reference_To (Base_Type (Etype (Prefix (Exp))), Loc),
|
New_Reference_To (Base_Type (Etype (Prefix (Exp))), Loc),
|
Name => Relocate_Node (Prefix (Exp))));
|
Name => Relocate_Node (Prefix (Exp))));
|
|
|
else
|
else
|
Res := New_Reference_To (Def_Id, Loc);
|
Res := New_Reference_To (Def_Id, Loc);
|
|
|
Insert_Action (Exp,
|
Insert_Action (Exp,
|
Make_Object_Renaming_Declaration (Loc,
|
Make_Object_Renaming_Declaration (Loc,
|
Defining_Identifier => Def_Id,
|
Defining_Identifier => Def_Id,
|
Subtype_Mark => New_Reference_To (Exp_Type, Loc),
|
Subtype_Mark => New_Reference_To (Exp_Type, Loc),
|
Name => Relocate_Node (Exp)));
|
Name => Relocate_Node (Exp)));
|
end if;
|
end if;
|
|
|
-- If this is a packed reference, or a selected component with
|
-- If this is a packed reference, or a selected component with
|
-- a non-standard representation, a reference to the temporary
|
-- a non-standard representation, a reference to the temporary
|
-- will be replaced by a copy of the original expression (see
|
-- will be replaced by a copy of the original expression (see
|
-- Exp_Ch2.Expand_Renaming). Otherwise the temporary must be
|
-- Exp_Ch2.Expand_Renaming). Otherwise the temporary must be
|
-- elaborated by gigi, and is of course not to be replaced in-line
|
-- elaborated by gigi, and is of course not to be replaced in-line
|
-- by the expression it renames, which would defeat the purpose of
|
-- by the expression it renames, which would defeat the purpose of
|
-- removing the side-effect.
|
-- removing the side-effect.
|
|
|
if (Nkind (Exp) = N_Selected_Component
|
if (Nkind (Exp) = N_Selected_Component
|
or else Nkind (Exp) = N_Indexed_Component)
|
or else Nkind (Exp) = N_Indexed_Component)
|
and then Has_Non_Standard_Rep (Etype (Prefix (Exp)))
|
and then Has_Non_Standard_Rep (Etype (Prefix (Exp)))
|
then
|
then
|
null;
|
null;
|
else
|
else
|
Set_Is_Renaming_Of_Object (Def_Id, False);
|
Set_Is_Renaming_Of_Object (Def_Id, False);
|
end if;
|
end if;
|
|
|
-- Otherwise we generate a reference to the value
|
-- Otherwise we generate a reference to the value
|
|
|
else
|
else
|
-- An expression which is in Alfa mode is considered side effect free
|
-- An expression which is in Alfa mode is considered side effect free
|
-- if the resulting value is captured by a variable or a constant.
|
-- if the resulting value is captured by a variable or a constant.
|
|
|
if Alfa_Mode
|
if Alfa_Mode
|
and then Nkind (Parent (Exp)) = N_Object_Declaration
|
and then Nkind (Parent (Exp)) = N_Object_Declaration
|
then
|
then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Special processing for function calls that return a limited type.
|
-- Special processing for function calls that return a limited type.
|
-- We need to build a declaration that will enable build-in-place
|
-- We need to build a declaration that will enable build-in-place
|
-- expansion of the call. This is not done if the context is already
|
-- expansion of the call. This is not done if the context is already
|
-- an object declaration, to prevent infinite recursion.
|
-- an object declaration, to prevent infinite recursion.
|
|
|
-- This is relevant only in Ada 2005 mode. In Ada 95 programs we have
|
-- This is relevant only in Ada 2005 mode. In Ada 95 programs we have
|
-- to accommodate functions returning limited objects by reference.
|
-- to accommodate functions returning limited objects by reference.
|
|
|
if Ada_Version >= Ada_2005
|
if Ada_Version >= Ada_2005
|
and then Nkind (Exp) = N_Function_Call
|
and then Nkind (Exp) = N_Function_Call
|
and then Is_Immutably_Limited_Type (Etype (Exp))
|
and then Is_Immutably_Limited_Type (Etype (Exp))
|
and then Nkind (Parent (Exp)) /= N_Object_Declaration
|
and then Nkind (Parent (Exp)) /= N_Object_Declaration
|
then
|
then
|
declare
|
declare
|
Obj : constant Entity_Id := Make_Temporary (Loc, 'F', Exp);
|
Obj : constant Entity_Id := Make_Temporary (Loc, 'F', Exp);
|
Decl : Node_Id;
|
Decl : Node_Id;
|
|
|
begin
|
begin
|
Decl :=
|
Decl :=
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Obj,
|
Defining_Identifier => Obj,
|
Object_Definition => New_Occurrence_Of (Exp_Type, Loc),
|
Object_Definition => New_Occurrence_Of (Exp_Type, Loc),
|
Expression => Relocate_Node (Exp));
|
Expression => Relocate_Node (Exp));
|
|
|
Insert_Action (Exp, Decl);
|
Insert_Action (Exp, Decl);
|
Set_Etype (Obj, Exp_Type);
|
Set_Etype (Obj, Exp_Type);
|
Rewrite (Exp, New_Occurrence_Of (Obj, Loc));
|
Rewrite (Exp, New_Occurrence_Of (Obj, Loc));
|
return;
|
return;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
Def_Id := Make_Temporary (Loc, 'R', Exp);
|
Set_Etype (Def_Id, Exp_Type);
|
Set_Etype (Def_Id, Exp_Type);
|
|
|
-- The regular expansion of functions with side effects involves the
|
-- The regular expansion of functions with side effects involves the
|
-- generation of an access type to capture the return value found on
|
-- generation of an access type to capture the return value found on
|
-- the secondary stack. Since Alfa (and why) cannot process access
|
-- the secondary stack. Since Alfa (and why) cannot process access
|
-- types, use a different approach which ignores the secondary stack
|
-- types, use a different approach which ignores the secondary stack
|
-- and "copies" the returned object.
|
-- and "copies" the returned object.
|
|
|
if Alfa_Mode then
|
if Alfa_Mode then
|
Res := New_Reference_To (Def_Id, Loc);
|
Res := New_Reference_To (Def_Id, Loc);
|
Ref_Type := Exp_Type;
|
Ref_Type := Exp_Type;
|
|
|
-- Regular expansion utilizing an access type and 'reference
|
-- Regular expansion utilizing an access type and 'reference
|
|
|
else
|
else
|
Res :=
|
Res :=
|
Make_Explicit_Dereference (Loc,
|
Make_Explicit_Dereference (Loc,
|
Prefix => New_Reference_To (Def_Id, Loc));
|
Prefix => New_Reference_To (Def_Id, Loc));
|
|
|
-- Generate:
|
-- Generate:
|
-- type Ann is access all <Exp_Type>;
|
-- type Ann is access all <Exp_Type>;
|
|
|
Ref_Type := Make_Temporary (Loc, 'A');
|
Ref_Type := Make_Temporary (Loc, 'A');
|
|
|
Ptr_Typ_Decl :=
|
Ptr_Typ_Decl :=
|
Make_Full_Type_Declaration (Loc,
|
Make_Full_Type_Declaration (Loc,
|
Defining_Identifier => Ref_Type,
|
Defining_Identifier => Ref_Type,
|
Type_Definition =>
|
Type_Definition =>
|
Make_Access_To_Object_Definition (Loc,
|
Make_Access_To_Object_Definition (Loc,
|
All_Present => True,
|
All_Present => True,
|
Subtype_Indication =>
|
Subtype_Indication =>
|
New_Reference_To (Exp_Type, Loc)));
|
New_Reference_To (Exp_Type, Loc)));
|
|
|
Insert_Action (Exp, Ptr_Typ_Decl);
|
Insert_Action (Exp, Ptr_Typ_Decl);
|
end if;
|
end if;
|
|
|
E := Exp;
|
E := Exp;
|
if Nkind (E) = N_Explicit_Dereference then
|
if Nkind (E) = N_Explicit_Dereference then
|
New_Exp := Relocate_Node (Prefix (E));
|
New_Exp := Relocate_Node (Prefix (E));
|
else
|
else
|
E := Relocate_Node (E);
|
E := Relocate_Node (E);
|
|
|
-- Do not generate a 'reference in Alfa mode since the access type
|
-- Do not generate a 'reference in Alfa mode since the access type
|
-- is not created in the first place.
|
-- is not created in the first place.
|
|
|
if Alfa_Mode then
|
if Alfa_Mode then
|
New_Exp := E;
|
New_Exp := E;
|
|
|
-- Otherwise generate reference, marking the value as non-null
|
-- Otherwise generate reference, marking the value as non-null
|
-- since we know it cannot be null and we don't want a check.
|
-- since we know it cannot be null and we don't want a check.
|
|
|
else
|
else
|
New_Exp := Make_Reference (Loc, E);
|
New_Exp := Make_Reference (Loc, E);
|
Set_Is_Known_Non_Null (Def_Id);
|
Set_Is_Known_Non_Null (Def_Id);
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
if Is_Delayed_Aggregate (E) then
|
if Is_Delayed_Aggregate (E) then
|
|
|
-- The expansion of nested aggregates is delayed until the
|
-- The expansion of nested aggregates is delayed until the
|
-- enclosing aggregate is expanded. As aggregates are often
|
-- enclosing aggregate is expanded. As aggregates are often
|
-- qualified, the predicate applies to qualified expressions as
|
-- qualified, the predicate applies to qualified expressions as
|
-- well, indicating that the enclosing aggregate has not been
|
-- well, indicating that the enclosing aggregate has not been
|
-- expanded yet. At this point the aggregate is part of a
|
-- expanded yet. At this point the aggregate is part of a
|
-- stand-alone declaration, and must be fully expanded.
|
-- stand-alone declaration, and must be fully expanded.
|
|
|
if Nkind (E) = N_Qualified_Expression then
|
if Nkind (E) = N_Qualified_Expression then
|
Set_Expansion_Delayed (Expression (E), False);
|
Set_Expansion_Delayed (Expression (E), False);
|
Set_Analyzed (Expression (E), False);
|
Set_Analyzed (Expression (E), False);
|
else
|
else
|
Set_Expansion_Delayed (E, False);
|
Set_Expansion_Delayed (E, False);
|
end if;
|
end if;
|
|
|
Set_Analyzed (E, False);
|
Set_Analyzed (E, False);
|
end if;
|
end if;
|
|
|
Insert_Action (Exp,
|
Insert_Action (Exp,
|
Make_Object_Declaration (Loc,
|
Make_Object_Declaration (Loc,
|
Defining_Identifier => Def_Id,
|
Defining_Identifier => Def_Id,
|
Object_Definition => New_Reference_To (Ref_Type, Loc),
|
Object_Definition => New_Reference_To (Ref_Type, Loc),
|
Constant_Present => True,
|
Constant_Present => True,
|
Expression => New_Exp));
|
Expression => New_Exp));
|
end if;
|
end if;
|
|
|
-- Preserve the Assignment_OK flag in all copies, since at least one
|
-- Preserve the Assignment_OK flag in all copies, since at least one
|
-- copy may be used in a context where this flag must be set (otherwise
|
-- copy may be used in a context where this flag must be set (otherwise
|
-- why would the flag be set in the first place).
|
-- why would the flag be set in the first place).
|
|
|
Set_Assignment_OK (Res, Assignment_OK (Exp));
|
Set_Assignment_OK (Res, Assignment_OK (Exp));
|
|
|
-- Finally rewrite the original expression and we are done
|
-- Finally rewrite the original expression and we are done
|
|
|
Rewrite (Exp, Res);
|
Rewrite (Exp, Res);
|
Analyze_And_Resolve (Exp, Exp_Type);
|
Analyze_And_Resolve (Exp, Exp_Type);
|
Scope_Suppress := Svg_Suppress;
|
Scope_Suppress := Svg_Suppress;
|
end Remove_Side_Effects;
|
end Remove_Side_Effects;
|
|
|
---------------------------
|
---------------------------
|
-- Represented_As_Scalar --
|
-- Represented_As_Scalar --
|
---------------------------
|
---------------------------
|
|
|
function Represented_As_Scalar (T : Entity_Id) return Boolean is
|
function Represented_As_Scalar (T : Entity_Id) return Boolean is
|
UT : constant Entity_Id := Underlying_Type (T);
|
UT : constant Entity_Id := Underlying_Type (T);
|
begin
|
begin
|
return Is_Scalar_Type (UT)
|
return Is_Scalar_Type (UT)
|
or else (Is_Bit_Packed_Array (UT)
|
or else (Is_Bit_Packed_Array (UT)
|
and then Is_Scalar_Type (Packed_Array_Type (UT)));
|
and then Is_Scalar_Type (Packed_Array_Type (UT)));
|
end Represented_As_Scalar;
|
end Represented_As_Scalar;
|
|
|
------------------------------
|
------------------------------
|
-- Requires_Cleanup_Actions --
|
-- Requires_Cleanup_Actions --
|
------------------------------
|
------------------------------
|
|
|
function Requires_Cleanup_Actions (N : Node_Id) return Boolean is
|
function Requires_Cleanup_Actions (N : Node_Id) return Boolean is
|
For_Pkg : constant Boolean :=
|
For_Pkg : constant Boolean :=
|
Nkind_In (N, N_Package_Body, N_Package_Specification);
|
Nkind_In (N, N_Package_Body, N_Package_Specification);
|
|
|
begin
|
begin
|
case Nkind (N) is
|
case Nkind (N) is
|
when N_Accept_Statement |
|
when N_Accept_Statement |
|
N_Block_Statement |
|
N_Block_Statement |
|
N_Entry_Body |
|
N_Entry_Body |
|
N_Package_Body |
|
N_Package_Body |
|
N_Protected_Body |
|
N_Protected_Body |
|
N_Subprogram_Body |
|
N_Subprogram_Body |
|
N_Task_Body =>
|
N_Task_Body =>
|
return
|
return
|
Requires_Cleanup_Actions (Declarations (N), For_Pkg, True)
|
Requires_Cleanup_Actions (Declarations (N), For_Pkg, True)
|
or else
|
or else
|
(Present (Handled_Statement_Sequence (N))
|
(Present (Handled_Statement_Sequence (N))
|
and then
|
and then
|
Requires_Cleanup_Actions (Statements
|
Requires_Cleanup_Actions (Statements
|
(Handled_Statement_Sequence (N)), For_Pkg, True));
|
(Handled_Statement_Sequence (N)), For_Pkg, True));
|
|
|
when N_Package_Specification =>
|
when N_Package_Specification =>
|
return
|
return
|
Requires_Cleanup_Actions
|
Requires_Cleanup_Actions
|
(Visible_Declarations (N), For_Pkg, True)
|
(Visible_Declarations (N), For_Pkg, True)
|
or else
|
or else
|
Requires_Cleanup_Actions
|
Requires_Cleanup_Actions
|
(Private_Declarations (N), For_Pkg, True);
|
(Private_Declarations (N), For_Pkg, True);
|
|
|
when others =>
|
when others =>
|
return False;
|
return False;
|
end case;
|
end case;
|
end Requires_Cleanup_Actions;
|
end Requires_Cleanup_Actions;
|
|
|
------------------------------
|
------------------------------
|
-- Requires_Cleanup_Actions --
|
-- Requires_Cleanup_Actions --
|
------------------------------
|
------------------------------
|
|
|
function Requires_Cleanup_Actions
|
function Requires_Cleanup_Actions
|
(L : List_Id;
|
(L : List_Id;
|
For_Package : Boolean;
|
For_Package : Boolean;
|
Nested_Constructs : Boolean) return Boolean
|
Nested_Constructs : Boolean) return Boolean
|
is
|
is
|
Decl : Node_Id;
|
Decl : Node_Id;
|
Expr : Node_Id;
|
Expr : Node_Id;
|
Obj_Id : Entity_Id;
|
Obj_Id : Entity_Id;
|
Obj_Typ : Entity_Id;
|
Obj_Typ : Entity_Id;
|
Pack_Id : Entity_Id;
|
Pack_Id : Entity_Id;
|
Typ : Entity_Id;
|
Typ : Entity_Id;
|
|
|
begin
|
begin
|
if No (L)
|
if No (L)
|
or else Is_Empty_List (L)
|
or else Is_Empty_List (L)
|
then
|
then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
Decl := First (L);
|
Decl := First (L);
|
while Present (Decl) loop
|
while Present (Decl) loop
|
|
|
-- Library-level tagged types
|
-- Library-level tagged types
|
|
|
if Nkind (Decl) = N_Full_Type_Declaration then
|
if Nkind (Decl) = N_Full_Type_Declaration then
|
Typ := Defining_Identifier (Decl);
|
Typ := Defining_Identifier (Decl);
|
|
|
if Is_Tagged_Type (Typ)
|
if Is_Tagged_Type (Typ)
|
and then Is_Library_Level_Entity (Typ)
|
and then Is_Library_Level_Entity (Typ)
|
and then Convention (Typ) = Convention_Ada
|
and then Convention (Typ) = Convention_Ada
|
and then Present (Access_Disp_Table (Typ))
|
and then Present (Access_Disp_Table (Typ))
|
and then RTE_Available (RE_Unregister_Tag)
|
and then RTE_Available (RE_Unregister_Tag)
|
and then not No_Run_Time_Mode
|
and then not No_Run_Time_Mode
|
and then not Is_Abstract_Type (Typ)
|
and then not Is_Abstract_Type (Typ)
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- Regular object declarations
|
-- Regular object declarations
|
|
|
elsif Nkind (Decl) = N_Object_Declaration then
|
elsif Nkind (Decl) = N_Object_Declaration then
|
Obj_Id := Defining_Identifier (Decl);
|
Obj_Id := Defining_Identifier (Decl);
|
Obj_Typ := Base_Type (Etype (Obj_Id));
|
Obj_Typ := Base_Type (Etype (Obj_Id));
|
Expr := Expression (Decl);
|
Expr := Expression (Decl);
|
|
|
-- Bypass any form of processing for objects which have their
|
-- Bypass any form of processing for objects which have their
|
-- finalization disabled. This applies only to objects at the
|
-- finalization disabled. This applies only to objects at the
|
-- library level.
|
-- library level.
|
|
|
if For_Package
|
if For_Package
|
and then Finalize_Storage_Only (Obj_Typ)
|
and then Finalize_Storage_Only (Obj_Typ)
|
then
|
then
|
null;
|
null;
|
|
|
-- Transient variables are treated separately in order to minimize
|
-- Transient variables are treated separately in order to minimize
|
-- the size of the generated code. See Exp_Ch7.Process_Transient_
|
-- the size of the generated code. See Exp_Ch7.Process_Transient_
|
-- Objects.
|
-- Objects.
|
|
|
elsif Is_Processed_Transient (Obj_Id) then
|
elsif Is_Processed_Transient (Obj_Id) then
|
null;
|
null;
|
|
|
-- The object is of the form:
|
-- The object is of the form:
|
-- Obj : Typ [:= Expr];
|
-- Obj : Typ [:= Expr];
|
--
|
--
|
-- Do not process the incomplete view of a deferred constant. Do
|
-- Do not process the incomplete view of a deferred constant. Do
|
-- not consider tag-to-class-wide conversions.
|
-- not consider tag-to-class-wide conversions.
|
|
|
elsif not Is_Imported (Obj_Id)
|
elsif not Is_Imported (Obj_Id)
|
and then Needs_Finalization (Obj_Typ)
|
and then Needs_Finalization (Obj_Typ)
|
and then not (Ekind (Obj_Id) = E_Constant
|
and then not (Ekind (Obj_Id) = E_Constant
|
and then not Has_Completion (Obj_Id))
|
and then not Has_Completion (Obj_Id))
|
and then not Is_Tag_To_Class_Wide_Conversion (Obj_Id)
|
and then not Is_Tag_To_Class_Wide_Conversion (Obj_Id)
|
then
|
then
|
return True;
|
return True;
|
|
|
-- The object is of the form:
|
-- The object is of the form:
|
-- Obj : Access_Typ := Non_BIP_Function_Call'reference;
|
-- Obj : Access_Typ := Non_BIP_Function_Call'reference;
|
--
|
--
|
-- Obj : Access_Typ :=
|
-- Obj : Access_Typ :=
|
-- BIP_Function_Call
|
-- BIP_Function_Call
|
-- (..., BIPaccess => null, ...)'reference;
|
-- (..., BIPaccess => null, ...)'reference;
|
|
|
elsif Is_Access_Type (Obj_Typ)
|
elsif Is_Access_Type (Obj_Typ)
|
and then Needs_Finalization
|
and then Needs_Finalization
|
(Available_View (Designated_Type (Obj_Typ)))
|
(Available_View (Designated_Type (Obj_Typ)))
|
and then Present (Expr)
|
and then Present (Expr)
|
and then
|
and then
|
(Is_Null_Access_BIP_Func_Call (Expr)
|
(Is_Null_Access_BIP_Func_Call (Expr)
|
or else
|
or else
|
(Is_Non_BIP_Func_Call (Expr)
|
(Is_Non_BIP_Func_Call (Expr)
|
and then not Is_Related_To_Func_Return (Obj_Id)))
|
and then not Is_Related_To_Func_Return (Obj_Id)))
|
then
|
then
|
return True;
|
return True;
|
|
|
-- Processing for "hook" objects generated for controlled
|
-- Processing for "hook" objects generated for controlled
|
-- transients declared inside an Expression_With_Actions.
|
-- transients declared inside an Expression_With_Actions.
|
|
|
elsif Is_Access_Type (Obj_Typ)
|
elsif Is_Access_Type (Obj_Typ)
|
and then Present (Return_Flag_Or_Transient_Decl (Obj_Id))
|
and then Present (Return_Flag_Or_Transient_Decl (Obj_Id))
|
and then Nkind (Return_Flag_Or_Transient_Decl (Obj_Id)) =
|
and then Nkind (Return_Flag_Or_Transient_Decl (Obj_Id)) =
|
N_Object_Declaration
|
N_Object_Declaration
|
and then Is_Finalizable_Transient
|
and then Is_Finalizable_Transient
|
(Return_Flag_Or_Transient_Decl (Obj_Id), Decl)
|
(Return_Flag_Or_Transient_Decl (Obj_Id), Decl)
|
then
|
then
|
return True;
|
return True;
|
|
|
-- Simple protected objects which use type System.Tasking.
|
-- Simple protected objects which use type System.Tasking.
|
-- Protected_Objects.Protection to manage their locks should be
|
-- Protected_Objects.Protection to manage their locks should be
|
-- treated as controlled since they require manual cleanup.
|
-- treated as controlled since they require manual cleanup.
|
|
|
elsif Ekind (Obj_Id) = E_Variable
|
elsif Ekind (Obj_Id) = E_Variable
|
and then
|
and then
|
(Is_Simple_Protected_Type (Obj_Typ)
|
(Is_Simple_Protected_Type (Obj_Typ)
|
or else Has_Simple_Protected_Object (Obj_Typ))
|
or else Has_Simple_Protected_Object (Obj_Typ))
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- Specific cases of object renamings
|
-- Specific cases of object renamings
|
|
|
elsif Nkind (Decl) = N_Object_Renaming_Declaration then
|
elsif Nkind (Decl) = N_Object_Renaming_Declaration then
|
Obj_Id := Defining_Identifier (Decl);
|
Obj_Id := Defining_Identifier (Decl);
|
Obj_Typ := Base_Type (Etype (Obj_Id));
|
Obj_Typ := Base_Type (Etype (Obj_Id));
|
|
|
-- Bypass any form of processing for objects which have their
|
-- Bypass any form of processing for objects which have their
|
-- finalization disabled. This applies only to objects at the
|
-- finalization disabled. This applies only to objects at the
|
-- library level.
|
-- library level.
|
|
|
if For_Package
|
if For_Package
|
and then Finalize_Storage_Only (Obj_Typ)
|
and then Finalize_Storage_Only (Obj_Typ)
|
then
|
then
|
null;
|
null;
|
|
|
-- Return object of a build-in-place function. This case is
|
-- Return object of a build-in-place function. This case is
|
-- recognized and marked by the expansion of an extended return
|
-- recognized and marked by the expansion of an extended return
|
-- statement (see Expand_N_Extended_Return_Statement).
|
-- statement (see Expand_N_Extended_Return_Statement).
|
|
|
elsif Needs_Finalization (Obj_Typ)
|
elsif Needs_Finalization (Obj_Typ)
|
and then Is_Return_Object (Obj_Id)
|
and then Is_Return_Object (Obj_Id)
|
and then Present (Return_Flag_Or_Transient_Decl (Obj_Id))
|
and then Present (Return_Flag_Or_Transient_Decl (Obj_Id))
|
then
|
then
|
return True;
|
return True;
|
|
|
-- Detect a case where a source object has been initialized by a
|
-- Detect a case where a source object has been initialized by a
|
-- controlled function call which was later rewritten as a class-
|
-- controlled function call which was later rewritten as a class-
|
-- wide conversion of Ada.Tags.Displace.
|
-- wide conversion of Ada.Tags.Displace.
|
|
|
-- Obj : Class_Wide_Type := Function_Call (...);
|
-- Obj : Class_Wide_Type := Function_Call (...);
|
|
|
-- Temp : ... := Function_Call (...)'reference;
|
-- Temp : ... := Function_Call (...)'reference;
|
-- Obj : Class_Wide_Type renames
|
-- Obj : Class_Wide_Type renames
|
-- (... Ada.Tags.Displace (Temp));
|
-- (... Ada.Tags.Displace (Temp));
|
|
|
elsif Is_Displacement_Of_Ctrl_Function_Result (Obj_Id) then
|
elsif Is_Displacement_Of_Ctrl_Function_Result (Obj_Id) then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- Inspect the freeze node of an access-to-controlled type and look
|
-- Inspect the freeze node of an access-to-controlled type and look
|
-- for a delayed finalization master. This case arises when the
|
-- for a delayed finalization master. This case arises when the
|
-- freeze actions are inserted at a later time than the expansion of
|
-- freeze actions are inserted at a later time than the expansion of
|
-- the context. Since Build_Finalizer is never called on a single
|
-- the context. Since Build_Finalizer is never called on a single
|
-- construct twice, the master will be ultimately left out and never
|
-- construct twice, the master will be ultimately left out and never
|
-- finalized. This is also needed for freeze actions of designated
|
-- finalized. This is also needed for freeze actions of designated
|
-- types themselves, since in some cases the finalization master is
|
-- types themselves, since in some cases the finalization master is
|
-- associated with a designated type's freeze node rather than that
|
-- associated with a designated type's freeze node rather than that
|
-- of the access type (see handling for freeze actions in
|
-- of the access type (see handling for freeze actions in
|
-- Build_Finalization_Master).
|
-- Build_Finalization_Master).
|
|
|
elsif Nkind (Decl) = N_Freeze_Entity
|
elsif Nkind (Decl) = N_Freeze_Entity
|
and then Present (Actions (Decl))
|
and then Present (Actions (Decl))
|
then
|
then
|
Typ := Entity (Decl);
|
Typ := Entity (Decl);
|
|
|
if ((Is_Access_Type (Typ)
|
if ((Is_Access_Type (Typ)
|
and then not Is_Access_Subprogram_Type (Typ)
|
and then not Is_Access_Subprogram_Type (Typ)
|
and then Needs_Finalization
|
and then Needs_Finalization
|
(Available_View (Designated_Type (Typ))))
|
(Available_View (Designated_Type (Typ))))
|
or else
|
or else
|
(Is_Type (Typ)
|
(Is_Type (Typ)
|
and then Needs_Finalization (Typ)))
|
and then Needs_Finalization (Typ)))
|
and then Requires_Cleanup_Actions
|
and then Requires_Cleanup_Actions
|
(Actions (Decl), For_Package, Nested_Constructs)
|
(Actions (Decl), For_Package, Nested_Constructs)
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- Nested package declarations
|
-- Nested package declarations
|
|
|
elsif Nested_Constructs
|
elsif Nested_Constructs
|
and then Nkind (Decl) = N_Package_Declaration
|
and then Nkind (Decl) = N_Package_Declaration
|
then
|
then
|
Pack_Id := Defining_Unit_Name (Specification (Decl));
|
Pack_Id := Defining_Unit_Name (Specification (Decl));
|
|
|
if Nkind (Pack_Id) = N_Defining_Program_Unit_Name then
|
if Nkind (Pack_Id) = N_Defining_Program_Unit_Name then
|
Pack_Id := Defining_Identifier (Pack_Id);
|
Pack_Id := Defining_Identifier (Pack_Id);
|
end if;
|
end if;
|
|
|
if Ekind (Pack_Id) /= E_Generic_Package
|
if Ekind (Pack_Id) /= E_Generic_Package
|
and then Requires_Cleanup_Actions (Specification (Decl))
|
and then Requires_Cleanup_Actions (Specification (Decl))
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- Nested package bodies
|
-- Nested package bodies
|
|
|
elsif Nested_Constructs
|
elsif Nested_Constructs
|
and then Nkind (Decl) = N_Package_Body
|
and then Nkind (Decl) = N_Package_Body
|
then
|
then
|
Pack_Id := Corresponding_Spec (Decl);
|
Pack_Id := Corresponding_Spec (Decl);
|
|
|
if Ekind (Pack_Id) /= E_Generic_Package
|
if Ekind (Pack_Id) /= E_Generic_Package
|
and then Requires_Cleanup_Actions (Decl)
|
and then Requires_Cleanup_Actions (Decl)
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Next (Decl);
|
Next (Decl);
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
end Requires_Cleanup_Actions;
|
end Requires_Cleanup_Actions;
|
|
|
------------------------------------
|
------------------------------------
|
-- Safe_Unchecked_Type_Conversion --
|
-- Safe_Unchecked_Type_Conversion --
|
------------------------------------
|
------------------------------------
|
|
|
-- Note: this function knows quite a bit about the exact requirements of
|
-- Note: this function knows quite a bit about the exact requirements of
|
-- Gigi with respect to unchecked type conversions, and its code must be
|
-- Gigi with respect to unchecked type conversions, and its code must be
|
-- coordinated with any changes in Gigi in this area.
|
-- coordinated with any changes in Gigi in this area.
|
|
|
-- The above requirements should be documented in Sinfo ???
|
-- The above requirements should be documented in Sinfo ???
|
|
|
function Safe_Unchecked_Type_Conversion (Exp : Node_Id) return Boolean is
|
function Safe_Unchecked_Type_Conversion (Exp : Node_Id) return Boolean is
|
Otyp : Entity_Id;
|
Otyp : Entity_Id;
|
Ityp : Entity_Id;
|
Ityp : Entity_Id;
|
Oalign : Uint;
|
Oalign : Uint;
|
Ialign : Uint;
|
Ialign : Uint;
|
Pexp : constant Node_Id := Parent (Exp);
|
Pexp : constant Node_Id := Parent (Exp);
|
|
|
begin
|
begin
|
-- If the expression is the RHS of an assignment or object declaration
|
-- If the expression is the RHS of an assignment or object declaration
|
-- we are always OK because there will always be a target.
|
-- we are always OK because there will always be a target.
|
|
|
-- Object renaming declarations, (generated for view conversions of
|
-- Object renaming declarations, (generated for view conversions of
|
-- actuals in inlined calls), like object declarations, provide an
|
-- actuals in inlined calls), like object declarations, provide an
|
-- explicit type, and are safe as well.
|
-- explicit type, and are safe as well.
|
|
|
if (Nkind (Pexp) = N_Assignment_Statement
|
if (Nkind (Pexp) = N_Assignment_Statement
|
and then Expression (Pexp) = Exp)
|
and then Expression (Pexp) = Exp)
|
or else Nkind (Pexp) = N_Object_Declaration
|
or else Nkind (Pexp) = N_Object_Declaration
|
or else Nkind (Pexp) = N_Object_Renaming_Declaration
|
or else Nkind (Pexp) = N_Object_Renaming_Declaration
|
then
|
then
|
return True;
|
return True;
|
|
|
-- If the expression is the prefix of an N_Selected_Component we should
|
-- If the expression is the prefix of an N_Selected_Component we should
|
-- also be OK because GCC knows to look inside the conversion except if
|
-- also be OK because GCC knows to look inside the conversion except if
|
-- the type is discriminated. We assume that we are OK anyway if the
|
-- the type is discriminated. We assume that we are OK anyway if the
|
-- type is not set yet or if it is controlled since we can't afford to
|
-- type is not set yet or if it is controlled since we can't afford to
|
-- introduce a temporary in this case.
|
-- introduce a temporary in this case.
|
|
|
elsif Nkind (Pexp) = N_Selected_Component
|
elsif Nkind (Pexp) = N_Selected_Component
|
and then Prefix (Pexp) = Exp
|
and then Prefix (Pexp) = Exp
|
then
|
then
|
if No (Etype (Pexp)) then
|
if No (Etype (Pexp)) then
|
return True;
|
return True;
|
else
|
else
|
return
|
return
|
not Has_Discriminants (Etype (Pexp))
|
not Has_Discriminants (Etype (Pexp))
|
or else Is_Constrained (Etype (Pexp));
|
or else Is_Constrained (Etype (Pexp));
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- Set the output type, this comes from Etype if it is set, otherwise we
|
-- Set the output type, this comes from Etype if it is set, otherwise we
|
-- take it from the subtype mark, which we assume was already fully
|
-- take it from the subtype mark, which we assume was already fully
|
-- analyzed.
|
-- analyzed.
|
|
|
if Present (Etype (Exp)) then
|
if Present (Etype (Exp)) then
|
Otyp := Etype (Exp);
|
Otyp := Etype (Exp);
|
else
|
else
|
Otyp := Entity (Subtype_Mark (Exp));
|
Otyp := Entity (Subtype_Mark (Exp));
|
end if;
|
end if;
|
|
|
-- The input type always comes from the expression, and we assume
|
-- The input type always comes from the expression, and we assume
|
-- this is indeed always analyzed, so we can simply get the Etype.
|
-- this is indeed always analyzed, so we can simply get the Etype.
|
|
|
Ityp := Etype (Expression (Exp));
|
Ityp := Etype (Expression (Exp));
|
|
|
-- Initialize alignments to unknown so far
|
-- Initialize alignments to unknown so far
|
|
|
Oalign := No_Uint;
|
Oalign := No_Uint;
|
Ialign := No_Uint;
|
Ialign := No_Uint;
|
|
|
-- Replace a concurrent type by its corresponding record type and each
|
-- Replace a concurrent type by its corresponding record type and each
|
-- type by its underlying type and do the tests on those. The original
|
-- type by its underlying type and do the tests on those. The original
|
-- type may be a private type whose completion is a concurrent type, so
|
-- type may be a private type whose completion is a concurrent type, so
|
-- find the underlying type first.
|
-- find the underlying type first.
|
|
|
if Present (Underlying_Type (Otyp)) then
|
if Present (Underlying_Type (Otyp)) then
|
Otyp := Underlying_Type (Otyp);
|
Otyp := Underlying_Type (Otyp);
|
end if;
|
end if;
|
|
|
if Present (Underlying_Type (Ityp)) then
|
if Present (Underlying_Type (Ityp)) then
|
Ityp := Underlying_Type (Ityp);
|
Ityp := Underlying_Type (Ityp);
|
end if;
|
end if;
|
|
|
if Is_Concurrent_Type (Otyp) then
|
if Is_Concurrent_Type (Otyp) then
|
Otyp := Corresponding_Record_Type (Otyp);
|
Otyp := Corresponding_Record_Type (Otyp);
|
end if;
|
end if;
|
|
|
if Is_Concurrent_Type (Ityp) then
|
if Is_Concurrent_Type (Ityp) then
|
Ityp := Corresponding_Record_Type (Ityp);
|
Ityp := Corresponding_Record_Type (Ityp);
|
end if;
|
end if;
|
|
|
-- If the base types are the same, we know there is no problem since
|
-- If the base types are the same, we know there is no problem since
|
-- this conversion will be a noop.
|
-- this conversion will be a noop.
|
|
|
if Implementation_Base_Type (Otyp) = Implementation_Base_Type (Ityp) then
|
if Implementation_Base_Type (Otyp) = Implementation_Base_Type (Ityp) then
|
return True;
|
return True;
|
|
|
-- Same if this is an upwards conversion of an untagged type, and there
|
-- Same if this is an upwards conversion of an untagged type, and there
|
-- are no constraints involved (could be more general???)
|
-- are no constraints involved (could be more general???)
|
|
|
elsif Etype (Ityp) = Otyp
|
elsif Etype (Ityp) = Otyp
|
and then not Is_Tagged_Type (Ityp)
|
and then not Is_Tagged_Type (Ityp)
|
and then not Has_Discriminants (Ityp)
|
and then not Has_Discriminants (Ityp)
|
and then No (First_Rep_Item (Base_Type (Ityp)))
|
and then No (First_Rep_Item (Base_Type (Ityp)))
|
then
|
then
|
return True;
|
return True;
|
|
|
-- If the expression has an access type (object or subprogram) we assume
|
-- If the expression has an access type (object or subprogram) we assume
|
-- that the conversion is safe, because the size of the target is safe,
|
-- that the conversion is safe, because the size of the target is safe,
|
-- even if it is a record (which might be treated as having unknown size
|
-- even if it is a record (which might be treated as having unknown size
|
-- at this point).
|
-- at this point).
|
|
|
elsif Is_Access_Type (Ityp) then
|
elsif Is_Access_Type (Ityp) then
|
return True;
|
return True;
|
|
|
-- If the size of output type is known at compile time, there is never
|
-- If the size of output type is known at compile time, there is never
|
-- a problem. Note that unconstrained records are considered to be of
|
-- a problem. Note that unconstrained records are considered to be of
|
-- known size, but we can't consider them that way here, because we are
|
-- known size, but we can't consider them that way here, because we are
|
-- talking about the actual size of the object.
|
-- talking about the actual size of the object.
|
|
|
-- We also make sure that in addition to the size being known, we do not
|
-- We also make sure that in addition to the size being known, we do not
|
-- have a case which might generate an embarrassingly large temp in
|
-- have a case which might generate an embarrassingly large temp in
|
-- stack checking mode.
|
-- stack checking mode.
|
|
|
elsif Size_Known_At_Compile_Time (Otyp)
|
elsif Size_Known_At_Compile_Time (Otyp)
|
and then
|
and then
|
(not Stack_Checking_Enabled
|
(not Stack_Checking_Enabled
|
or else not May_Generate_Large_Temp (Otyp))
|
or else not May_Generate_Large_Temp (Otyp))
|
and then not (Is_Record_Type (Otyp) and then not Is_Constrained (Otyp))
|
and then not (Is_Record_Type (Otyp) and then not Is_Constrained (Otyp))
|
then
|
then
|
return True;
|
return True;
|
|
|
-- If either type is tagged, then we know the alignment is OK so
|
-- If either type is tagged, then we know the alignment is OK so
|
-- Gigi will be able to use pointer punning.
|
-- Gigi will be able to use pointer punning.
|
|
|
elsif Is_Tagged_Type (Otyp) or else Is_Tagged_Type (Ityp) then
|
elsif Is_Tagged_Type (Otyp) or else Is_Tagged_Type (Ityp) then
|
return True;
|
return True;
|
|
|
-- If either type is a limited record type, we cannot do a copy, so say
|
-- If either type is a limited record type, we cannot do a copy, so say
|
-- safe since there's nothing else we can do.
|
-- safe since there's nothing else we can do.
|
|
|
elsif Is_Limited_Record (Otyp) or else Is_Limited_Record (Ityp) then
|
elsif Is_Limited_Record (Otyp) or else Is_Limited_Record (Ityp) then
|
return True;
|
return True;
|
|
|
-- Conversions to and from packed array types are always ignored and
|
-- Conversions to and from packed array types are always ignored and
|
-- hence are safe.
|
-- hence are safe.
|
|
|
elsif Is_Packed_Array_Type (Otyp)
|
elsif Is_Packed_Array_Type (Otyp)
|
or else Is_Packed_Array_Type (Ityp)
|
or else Is_Packed_Array_Type (Ityp)
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
-- The only other cases known to be safe is if the input type's
|
-- The only other cases known to be safe is if the input type's
|
-- alignment is known to be at least the maximum alignment for the
|
-- alignment is known to be at least the maximum alignment for the
|
-- target or if both alignments are known and the output type's
|
-- target or if both alignments are known and the output type's
|
-- alignment is no stricter than the input's. We can use the component
|
-- alignment is no stricter than the input's. We can use the component
|
-- type alignement for an array if a type is an unpacked array type.
|
-- type alignement for an array if a type is an unpacked array type.
|
|
|
if Present (Alignment_Clause (Otyp)) then
|
if Present (Alignment_Clause (Otyp)) then
|
Oalign := Expr_Value (Expression (Alignment_Clause (Otyp)));
|
Oalign := Expr_Value (Expression (Alignment_Clause (Otyp)));
|
|
|
elsif Is_Array_Type (Otyp)
|
elsif Is_Array_Type (Otyp)
|
and then Present (Alignment_Clause (Component_Type (Otyp)))
|
and then Present (Alignment_Clause (Component_Type (Otyp)))
|
then
|
then
|
Oalign := Expr_Value (Expression (Alignment_Clause
|
Oalign := Expr_Value (Expression (Alignment_Clause
|
(Component_Type (Otyp))));
|
(Component_Type (Otyp))));
|
end if;
|
end if;
|
|
|
if Present (Alignment_Clause (Ityp)) then
|
if Present (Alignment_Clause (Ityp)) then
|
Ialign := Expr_Value (Expression (Alignment_Clause (Ityp)));
|
Ialign := Expr_Value (Expression (Alignment_Clause (Ityp)));
|
|
|
elsif Is_Array_Type (Ityp)
|
elsif Is_Array_Type (Ityp)
|
and then Present (Alignment_Clause (Component_Type (Ityp)))
|
and then Present (Alignment_Clause (Component_Type (Ityp)))
|
then
|
then
|
Ialign := Expr_Value (Expression (Alignment_Clause
|
Ialign := Expr_Value (Expression (Alignment_Clause
|
(Component_Type (Ityp))));
|
(Component_Type (Ityp))));
|
end if;
|
end if;
|
|
|
if Ialign /= No_Uint and then Ialign > Maximum_Alignment then
|
if Ialign /= No_Uint and then Ialign > Maximum_Alignment then
|
return True;
|
return True;
|
|
|
elsif Ialign /= No_Uint and then Oalign /= No_Uint
|
elsif Ialign /= No_Uint and then Oalign /= No_Uint
|
and then Ialign <= Oalign
|
and then Ialign <= Oalign
|
then
|
then
|
return True;
|
return True;
|
|
|
-- Otherwise, Gigi cannot handle this and we must make a temporary
|
-- Otherwise, Gigi cannot handle this and we must make a temporary
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Safe_Unchecked_Type_Conversion;
|
end Safe_Unchecked_Type_Conversion;
|
|
|
---------------------------------
|
---------------------------------
|
-- Set_Current_Value_Condition --
|
-- Set_Current_Value_Condition --
|
---------------------------------
|
---------------------------------
|
|
|
-- Note: the implementation of this procedure is very closely tied to the
|
-- Note: the implementation of this procedure is very closely tied to the
|
-- implementation of Get_Current_Value_Condition. Here we set required
|
-- implementation of Get_Current_Value_Condition. Here we set required
|
-- Current_Value fields, and in Get_Current_Value_Condition, we interpret
|
-- Current_Value fields, and in Get_Current_Value_Condition, we interpret
|
-- them, so they must have a consistent view.
|
-- them, so they must have a consistent view.
|
|
|
procedure Set_Current_Value_Condition (Cnode : Node_Id) is
|
procedure Set_Current_Value_Condition (Cnode : Node_Id) is
|
|
|
procedure Set_Entity_Current_Value (N : Node_Id);
|
procedure Set_Entity_Current_Value (N : Node_Id);
|
-- If N is an entity reference, where the entity is of an appropriate
|
-- If N is an entity reference, where the entity is of an appropriate
|
-- kind, then set the current value of this entity to Cnode, unless
|
-- kind, then set the current value of this entity to Cnode, unless
|
-- there is already a definite value set there.
|
-- there is already a definite value set there.
|
|
|
procedure Set_Expression_Current_Value (N : Node_Id);
|
procedure Set_Expression_Current_Value (N : Node_Id);
|
-- If N is of an appropriate form, sets an appropriate entry in current
|
-- If N is of an appropriate form, sets an appropriate entry in current
|
-- value fields of relevant entities. Multiple entities can be affected
|
-- value fields of relevant entities. Multiple entities can be affected
|
-- in the case of an AND or AND THEN.
|
-- in the case of an AND or AND THEN.
|
|
|
------------------------------
|
------------------------------
|
-- Set_Entity_Current_Value --
|
-- Set_Entity_Current_Value --
|
------------------------------
|
------------------------------
|
|
|
procedure Set_Entity_Current_Value (N : Node_Id) is
|
procedure Set_Entity_Current_Value (N : Node_Id) is
|
begin
|
begin
|
if Is_Entity_Name (N) then
|
if Is_Entity_Name (N) then
|
declare
|
declare
|
Ent : constant Entity_Id := Entity (N);
|
Ent : constant Entity_Id := Entity (N);
|
|
|
begin
|
begin
|
-- Don't capture if not safe to do so
|
-- Don't capture if not safe to do so
|
|
|
if not Safe_To_Capture_Value (N, Ent, Cond => True) then
|
if not Safe_To_Capture_Value (N, Ent, Cond => True) then
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Here we have a case where the Current_Value field may need
|
-- Here we have a case where the Current_Value field may need
|
-- to be set. We set it if it is not already set to a compile
|
-- to be set. We set it if it is not already set to a compile
|
-- time expression value.
|
-- time expression value.
|
|
|
-- Note that this represents a decision that one condition
|
-- Note that this represents a decision that one condition
|
-- blots out another previous one. That's certainly right if
|
-- blots out another previous one. That's certainly right if
|
-- they occur at the same level. If the second one is nested,
|
-- they occur at the same level. If the second one is nested,
|
-- then the decision is neither right nor wrong (it would be
|
-- then the decision is neither right nor wrong (it would be
|
-- equally OK to leave the outer one in place, or take the new
|
-- equally OK to leave the outer one in place, or take the new
|
-- inner one. Really we should record both, but our data
|
-- inner one. Really we should record both, but our data
|
-- structures are not that elaborate.
|
-- structures are not that elaborate.
|
|
|
if Nkind (Current_Value (Ent)) not in N_Subexpr then
|
if Nkind (Current_Value (Ent)) not in N_Subexpr then
|
Set_Current_Value (Ent, Cnode);
|
Set_Current_Value (Ent, Cnode);
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
end Set_Entity_Current_Value;
|
end Set_Entity_Current_Value;
|
|
|
----------------------------------
|
----------------------------------
|
-- Set_Expression_Current_Value --
|
-- Set_Expression_Current_Value --
|
----------------------------------
|
----------------------------------
|
|
|
procedure Set_Expression_Current_Value (N : Node_Id) is
|
procedure Set_Expression_Current_Value (N : Node_Id) is
|
Cond : Node_Id;
|
Cond : Node_Id;
|
|
|
begin
|
begin
|
Cond := N;
|
Cond := N;
|
|
|
-- Loop to deal with (ignore for now) any NOT operators present. The
|
-- Loop to deal with (ignore for now) any NOT operators present. The
|
-- presence of NOT operators will be handled properly when we call
|
-- presence of NOT operators will be handled properly when we call
|
-- Get_Current_Value_Condition.
|
-- Get_Current_Value_Condition.
|
|
|
while Nkind (Cond) = N_Op_Not loop
|
while Nkind (Cond) = N_Op_Not loop
|
Cond := Right_Opnd (Cond);
|
Cond := Right_Opnd (Cond);
|
end loop;
|
end loop;
|
|
|
-- For an AND or AND THEN, recursively process operands
|
-- For an AND or AND THEN, recursively process operands
|
|
|
if Nkind (Cond) = N_Op_And or else Nkind (Cond) = N_And_Then then
|
if Nkind (Cond) = N_Op_And or else Nkind (Cond) = N_And_Then then
|
Set_Expression_Current_Value (Left_Opnd (Cond));
|
Set_Expression_Current_Value (Left_Opnd (Cond));
|
Set_Expression_Current_Value (Right_Opnd (Cond));
|
Set_Expression_Current_Value (Right_Opnd (Cond));
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Check possible relational operator
|
-- Check possible relational operator
|
|
|
if Nkind (Cond) in N_Op_Compare then
|
if Nkind (Cond) in N_Op_Compare then
|
if Compile_Time_Known_Value (Right_Opnd (Cond)) then
|
if Compile_Time_Known_Value (Right_Opnd (Cond)) then
|
Set_Entity_Current_Value (Left_Opnd (Cond));
|
Set_Entity_Current_Value (Left_Opnd (Cond));
|
elsif Compile_Time_Known_Value (Left_Opnd (Cond)) then
|
elsif Compile_Time_Known_Value (Left_Opnd (Cond)) then
|
Set_Entity_Current_Value (Right_Opnd (Cond));
|
Set_Entity_Current_Value (Right_Opnd (Cond));
|
end if;
|
end if;
|
|
|
-- Check possible boolean variable reference
|
-- Check possible boolean variable reference
|
|
|
else
|
else
|
Set_Entity_Current_Value (Cond);
|
Set_Entity_Current_Value (Cond);
|
end if;
|
end if;
|
end Set_Expression_Current_Value;
|
end Set_Expression_Current_Value;
|
|
|
-- Start of processing for Set_Current_Value_Condition
|
-- Start of processing for Set_Current_Value_Condition
|
|
|
begin
|
begin
|
Set_Expression_Current_Value (Condition (Cnode));
|
Set_Expression_Current_Value (Condition (Cnode));
|
end Set_Current_Value_Condition;
|
end Set_Current_Value_Condition;
|
|
|
--------------------------
|
--------------------------
|
-- Set_Elaboration_Flag --
|
-- Set_Elaboration_Flag --
|
--------------------------
|
--------------------------
|
|
|
procedure Set_Elaboration_Flag (N : Node_Id; Spec_Id : Entity_Id) is
|
procedure Set_Elaboration_Flag (N : Node_Id; Spec_Id : Entity_Id) is
|
Loc : constant Source_Ptr := Sloc (N);
|
Loc : constant Source_Ptr := Sloc (N);
|
Ent : constant Entity_Id := Elaboration_Entity (Spec_Id);
|
Ent : constant Entity_Id := Elaboration_Entity (Spec_Id);
|
Asn : Node_Id;
|
Asn : Node_Id;
|
|
|
begin
|
begin
|
if Present (Ent) then
|
if Present (Ent) then
|
|
|
-- Nothing to do if at the compilation unit level, because in this
|
-- Nothing to do if at the compilation unit level, because in this
|
-- case the flag is set by the binder generated elaboration routine.
|
-- case the flag is set by the binder generated elaboration routine.
|
|
|
if Nkind (Parent (N)) = N_Compilation_Unit then
|
if Nkind (Parent (N)) = N_Compilation_Unit then
|
null;
|
null;
|
|
|
-- Here we do need to generate an assignment statement
|
-- Here we do need to generate an assignment statement
|
|
|
else
|
else
|
Check_Restriction (No_Elaboration_Code, N);
|
Check_Restriction (No_Elaboration_Code, N);
|
Asn :=
|
Asn :=
|
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
Name => New_Occurrence_Of (Ent, Loc),
|
Name => New_Occurrence_Of (Ent, Loc),
|
Expression => Make_Integer_Literal (Loc, Uint_1));
|
Expression => Make_Integer_Literal (Loc, Uint_1));
|
|
|
if Nkind (Parent (N)) = N_Subunit then
|
if Nkind (Parent (N)) = N_Subunit then
|
Insert_After (Corresponding_Stub (Parent (N)), Asn);
|
Insert_After (Corresponding_Stub (Parent (N)), Asn);
|
else
|
else
|
Insert_After (N, Asn);
|
Insert_After (N, Asn);
|
end if;
|
end if;
|
|
|
Analyze (Asn);
|
Analyze (Asn);
|
|
|
-- Kill current value indication. This is necessary because the
|
-- Kill current value indication. This is necessary because the
|
-- tests of this flag are inserted out of sequence and must not
|
-- tests of this flag are inserted out of sequence and must not
|
-- pick up bogus indications of the wrong constant value.
|
-- pick up bogus indications of the wrong constant value.
|
|
|
Set_Current_Value (Ent, Empty);
|
Set_Current_Value (Ent, Empty);
|
end if;
|
end if;
|
end if;
|
end if;
|
end Set_Elaboration_Flag;
|
end Set_Elaboration_Flag;
|
|
|
----------------------------
|
----------------------------
|
-- Set_Renamed_Subprogram --
|
-- Set_Renamed_Subprogram --
|
----------------------------
|
----------------------------
|
|
|
procedure Set_Renamed_Subprogram (N : Node_Id; E : Entity_Id) is
|
procedure Set_Renamed_Subprogram (N : Node_Id; E : Entity_Id) is
|
begin
|
begin
|
-- If input node is an identifier, we can just reset it
|
-- If input node is an identifier, we can just reset it
|
|
|
if Nkind (N) = N_Identifier then
|
if Nkind (N) = N_Identifier then
|
Set_Chars (N, Chars (E));
|
Set_Chars (N, Chars (E));
|
Set_Entity (N, E);
|
Set_Entity (N, E);
|
|
|
-- Otherwise we have to do a rewrite, preserving Comes_From_Source
|
-- Otherwise we have to do a rewrite, preserving Comes_From_Source
|
|
|
else
|
else
|
declare
|
declare
|
CS : constant Boolean := Comes_From_Source (N);
|
CS : constant Boolean := Comes_From_Source (N);
|
begin
|
begin
|
Rewrite (N, Make_Identifier (Sloc (N), Chars (E)));
|
Rewrite (N, Make_Identifier (Sloc (N), Chars (E)));
|
Set_Entity (N, E);
|
Set_Entity (N, E);
|
Set_Comes_From_Source (N, CS);
|
Set_Comes_From_Source (N, CS);
|
Set_Analyzed (N, True);
|
Set_Analyzed (N, True);
|
end;
|
end;
|
end if;
|
end if;
|
end Set_Renamed_Subprogram;
|
end Set_Renamed_Subprogram;
|
|
|
----------------------------------
|
----------------------------------
|
-- Silly_Boolean_Array_Not_Test --
|
-- Silly_Boolean_Array_Not_Test --
|
----------------------------------
|
----------------------------------
|
|
|
-- This procedure implements an odd and silly test. We explicitly check
|
-- This procedure implements an odd and silly test. We explicitly check
|
-- for the case where the 'First of the component type is equal to the
|
-- for the case where the 'First of the component type is equal to the
|
-- 'Last of this component type, and if this is the case, we make sure
|
-- 'Last of this component type, and if this is the case, we make sure
|
-- that constraint error is raised. The reason is that the NOT is bound
|
-- that constraint error is raised. The reason is that the NOT is bound
|
-- to cause CE in this case, and we will not otherwise catch it.
|
-- to cause CE in this case, and we will not otherwise catch it.
|
|
|
-- No such check is required for AND and OR, since for both these cases
|
-- No such check is required for AND and OR, since for both these cases
|
-- False op False = False, and True op True = True. For the XOR case,
|
-- False op False = False, and True op True = True. For the XOR case,
|
-- see Silly_Boolean_Array_Xor_Test.
|
-- see Silly_Boolean_Array_Xor_Test.
|
|
|
-- Believe it or not, this was reported as a bug. Note that nearly always,
|
-- Believe it or not, this was reported as a bug. Note that nearly always,
|
-- the test will evaluate statically to False, so the code will be
|
-- the test will evaluate statically to False, so the code will be
|
-- statically removed, and no extra overhead caused.
|
-- statically removed, and no extra overhead caused.
|
|
|
procedure Silly_Boolean_Array_Not_Test (N : Node_Id; T : Entity_Id) is
|
procedure Silly_Boolean_Array_Not_Test (N : Node_Id; T : Entity_Id) is
|
Loc : constant Source_Ptr := Sloc (N);
|
Loc : constant Source_Ptr := Sloc (N);
|
CT : constant Entity_Id := Component_Type (T);
|
CT : constant Entity_Id := Component_Type (T);
|
|
|
begin
|
begin
|
-- The check we install is
|
-- The check we install is
|
|
|
-- constraint_error when
|
-- constraint_error when
|
-- component_type'first = component_type'last
|
-- component_type'first = component_type'last
|
-- and then array_type'Length /= 0)
|
-- and then array_type'Length /= 0)
|
|
|
-- We need the last guard because we don't want to raise CE for empty
|
-- We need the last guard because we don't want to raise CE for empty
|
-- arrays since no out of range values result. (Empty arrays with a
|
-- arrays since no out of range values result. (Empty arrays with a
|
-- component type of True .. True -- very useful -- even the ACATS
|
-- component type of True .. True -- very useful -- even the ACATS
|
-- does not test that marginal case!)
|
-- does not test that marginal case!)
|
|
|
Insert_Action (N,
|
Insert_Action (N,
|
Make_Raise_Constraint_Error (Loc,
|
Make_Raise_Constraint_Error (Loc,
|
Condition =>
|
Condition =>
|
Make_And_Then (Loc,
|
Make_And_Then (Loc,
|
Left_Opnd =>
|
Left_Opnd =>
|
Make_Op_Eq (Loc,
|
Make_Op_Eq (Loc,
|
Left_Opnd =>
|
Left_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix => New_Occurrence_Of (CT, Loc),
|
Prefix => New_Occurrence_Of (CT, Loc),
|
Attribute_Name => Name_First),
|
Attribute_Name => Name_First),
|
|
|
Right_Opnd =>
|
Right_Opnd =>
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix => New_Occurrence_Of (CT, Loc),
|
Prefix => New_Occurrence_Of (CT, Loc),
|
Attribute_Name => Name_Last)),
|
Attribute_Name => Name_Last)),
|
|
|
Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))),
|
Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))),
|
Reason => CE_Range_Check_Failed));
|
Reason => CE_Range_Check_Failed));
|
end Silly_Boolean_Array_Not_Test;
|
end Silly_Boolean_Array_Not_Test;
|
|
|
----------------------------------
|
----------------------------------
|
-- Silly_Boolean_Array_Xor_Test --
|
-- Silly_Boolean_Array_Xor_Test --
|
----------------------------------
|
----------------------------------
|
|
|
-- This procedure implements an odd and silly test. We explicitly check
|
-- This procedure implements an odd and silly test. We explicitly check
|
-- for the XOR case where the component type is True .. True, since this
|
-- for the XOR case where the component type is True .. True, since this
|
-- will raise constraint error. A special check is required since CE
|
-- will raise constraint error. A special check is required since CE
|
-- will not be generated otherwise (cf Expand_Packed_Not).
|
-- will not be generated otherwise (cf Expand_Packed_Not).
|
|
|
-- No such check is required for AND and OR, since for both these cases
|
-- No such check is required for AND and OR, since for both these cases
|
-- False op False = False, and True op True = True, and no check is
|
-- False op False = False, and True op True = True, and no check is
|
-- required for the case of False .. False, since False xor False = False.
|
-- required for the case of False .. False, since False xor False = False.
|
-- See also Silly_Boolean_Array_Not_Test
|
-- See also Silly_Boolean_Array_Not_Test
|
|
|
procedure Silly_Boolean_Array_Xor_Test (N : Node_Id; T : Entity_Id) is
|
procedure Silly_Boolean_Array_Xor_Test (N : Node_Id; T : Entity_Id) is
|
Loc : constant Source_Ptr := Sloc (N);
|
Loc : constant Source_Ptr := Sloc (N);
|
CT : constant Entity_Id := Component_Type (T);
|
CT : constant Entity_Id := Component_Type (T);
|
|
|
begin
|
begin
|
-- The check we install is
|
-- The check we install is
|
|
|
-- constraint_error when
|
-- constraint_error when
|
-- Boolean (component_type'First)
|
-- Boolean (component_type'First)
|
-- and then Boolean (component_type'Last)
|
-- and then Boolean (component_type'Last)
|
-- and then array_type'Length /= 0)
|
-- and then array_type'Length /= 0)
|
|
|
-- We need the last guard because we don't want to raise CE for empty
|
-- We need the last guard because we don't want to raise CE for empty
|
-- arrays since no out of range values result (Empty arrays with a
|
-- arrays since no out of range values result (Empty arrays with a
|
-- component type of True .. True -- very useful -- even the ACATS
|
-- component type of True .. True -- very useful -- even the ACATS
|
-- does not test that marginal case!).
|
-- does not test that marginal case!).
|
|
|
Insert_Action (N,
|
Insert_Action (N,
|
Make_Raise_Constraint_Error (Loc,
|
Make_Raise_Constraint_Error (Loc,
|
Condition =>
|
Condition =>
|
Make_And_Then (Loc,
|
Make_And_Then (Loc,
|
Left_Opnd =>
|
Left_Opnd =>
|
Make_And_Then (Loc,
|
Make_And_Then (Loc,
|
Left_Opnd =>
|
Left_Opnd =>
|
Convert_To (Standard_Boolean,
|
Convert_To (Standard_Boolean,
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix => New_Occurrence_Of (CT, Loc),
|
Prefix => New_Occurrence_Of (CT, Loc),
|
Attribute_Name => Name_First)),
|
Attribute_Name => Name_First)),
|
|
|
Right_Opnd =>
|
Right_Opnd =>
|
Convert_To (Standard_Boolean,
|
Convert_To (Standard_Boolean,
|
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
Prefix => New_Occurrence_Of (CT, Loc),
|
Prefix => New_Occurrence_Of (CT, Loc),
|
Attribute_Name => Name_Last))),
|
Attribute_Name => Name_Last))),
|
|
|
Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))),
|
Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))),
|
Reason => CE_Range_Check_Failed));
|
Reason => CE_Range_Check_Failed));
|
end Silly_Boolean_Array_Xor_Test;
|
end Silly_Boolean_Array_Xor_Test;
|
|
|
--------------------------
|
--------------------------
|
-- Target_Has_Fixed_Ops --
|
-- Target_Has_Fixed_Ops --
|
--------------------------
|
--------------------------
|
|
|
Integer_Sized_Small : Ureal;
|
Integer_Sized_Small : Ureal;
|
-- Set to 2.0 ** -(Integer'Size - 1) the first time that this function is
|
-- Set to 2.0 ** -(Integer'Size - 1) the first time that this function is
|
-- called (we don't want to compute it more than once!)
|
-- called (we don't want to compute it more than once!)
|
|
|
Long_Integer_Sized_Small : Ureal;
|
Long_Integer_Sized_Small : Ureal;
|
-- Set to 2.0 ** -(Long_Integer'Size - 1) the first time that this function
|
-- Set to 2.0 ** -(Long_Integer'Size - 1) the first time that this function
|
-- is called (we don't want to compute it more than once)
|
-- is called (we don't want to compute it more than once)
|
|
|
First_Time_For_THFO : Boolean := True;
|
First_Time_For_THFO : Boolean := True;
|
-- Set to False after first call (if Fractional_Fixed_Ops_On_Target)
|
-- Set to False after first call (if Fractional_Fixed_Ops_On_Target)
|
|
|
function Target_Has_Fixed_Ops
|
function Target_Has_Fixed_Ops
|
(Left_Typ : Entity_Id;
|
(Left_Typ : Entity_Id;
|
Right_Typ : Entity_Id;
|
Right_Typ : Entity_Id;
|
Result_Typ : Entity_Id) return Boolean
|
Result_Typ : Entity_Id) return Boolean
|
is
|
is
|
function Is_Fractional_Type (Typ : Entity_Id) return Boolean;
|
function Is_Fractional_Type (Typ : Entity_Id) return Boolean;
|
-- Return True if the given type is a fixed-point type with a small
|
-- Return True if the given type is a fixed-point type with a small
|
-- value equal to 2 ** (-(T'Object_Size - 1)) and whose values have
|
-- value equal to 2 ** (-(T'Object_Size - 1)) and whose values have
|
-- an absolute value less than 1.0. This is currently limited to
|
-- an absolute value less than 1.0. This is currently limited to
|
-- fixed-point types that map to Integer or Long_Integer.
|
-- fixed-point types that map to Integer or Long_Integer.
|
|
|
------------------------
|
------------------------
|
-- Is_Fractional_Type --
|
-- Is_Fractional_Type --
|
------------------------
|
------------------------
|
|
|
function Is_Fractional_Type (Typ : Entity_Id) return Boolean is
|
function Is_Fractional_Type (Typ : Entity_Id) return Boolean is
|
begin
|
begin
|
if Esize (Typ) = Standard_Integer_Size then
|
if Esize (Typ) = Standard_Integer_Size then
|
return Small_Value (Typ) = Integer_Sized_Small;
|
return Small_Value (Typ) = Integer_Sized_Small;
|
|
|
elsif Esize (Typ) = Standard_Long_Integer_Size then
|
elsif Esize (Typ) = Standard_Long_Integer_Size then
|
return Small_Value (Typ) = Long_Integer_Sized_Small;
|
return Small_Value (Typ) = Long_Integer_Sized_Small;
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Is_Fractional_Type;
|
end Is_Fractional_Type;
|
|
|
-- Start of processing for Target_Has_Fixed_Ops
|
-- Start of processing for Target_Has_Fixed_Ops
|
|
|
begin
|
begin
|
-- Return False if Fractional_Fixed_Ops_On_Target is false
|
-- Return False if Fractional_Fixed_Ops_On_Target is false
|
|
|
if not Fractional_Fixed_Ops_On_Target then
|
if not Fractional_Fixed_Ops_On_Target then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
-- Here the target has Fractional_Fixed_Ops, if first time, compute
|
-- Here the target has Fractional_Fixed_Ops, if first time, compute
|
-- standard constants used by Is_Fractional_Type.
|
-- standard constants used by Is_Fractional_Type.
|
|
|
if First_Time_For_THFO then
|
if First_Time_For_THFO then
|
First_Time_For_THFO := False;
|
First_Time_For_THFO := False;
|
|
|
Integer_Sized_Small :=
|
Integer_Sized_Small :=
|
UR_From_Components
|
UR_From_Components
|
(Num => Uint_1,
|
(Num => Uint_1,
|
Den => UI_From_Int (Standard_Integer_Size - 1),
|
Den => UI_From_Int (Standard_Integer_Size - 1),
|
Rbase => 2);
|
Rbase => 2);
|
|
|
Long_Integer_Sized_Small :=
|
Long_Integer_Sized_Small :=
|
UR_From_Components
|
UR_From_Components
|
(Num => Uint_1,
|
(Num => Uint_1,
|
Den => UI_From_Int (Standard_Long_Integer_Size - 1),
|
Den => UI_From_Int (Standard_Long_Integer_Size - 1),
|
Rbase => 2);
|
Rbase => 2);
|
end if;
|
end if;
|
|
|
-- Return True if target supports fixed-by-fixed multiply/divide for
|
-- Return True if target supports fixed-by-fixed multiply/divide for
|
-- fractional fixed-point types (see Is_Fractional_Type) and the operand
|
-- fractional fixed-point types (see Is_Fractional_Type) and the operand
|
-- and result types are equivalent fractional types.
|
-- and result types are equivalent fractional types.
|
|
|
return Is_Fractional_Type (Base_Type (Left_Typ))
|
return Is_Fractional_Type (Base_Type (Left_Typ))
|
and then Is_Fractional_Type (Base_Type (Right_Typ))
|
and then Is_Fractional_Type (Base_Type (Right_Typ))
|
and then Is_Fractional_Type (Base_Type (Result_Typ))
|
and then Is_Fractional_Type (Base_Type (Result_Typ))
|
and then Esize (Left_Typ) = Esize (Right_Typ)
|
and then Esize (Left_Typ) = Esize (Right_Typ)
|
and then Esize (Left_Typ) = Esize (Result_Typ);
|
and then Esize (Left_Typ) = Esize (Result_Typ);
|
end Target_Has_Fixed_Ops;
|
end Target_Has_Fixed_Ops;
|
|
|
------------------------------------------
|
------------------------------------------
|
-- Type_May_Have_Bit_Aligned_Components --
|
-- Type_May_Have_Bit_Aligned_Components --
|
------------------------------------------
|
------------------------------------------
|
|
|
function Type_May_Have_Bit_Aligned_Components
|
function Type_May_Have_Bit_Aligned_Components
|
(Typ : Entity_Id) return Boolean
|
(Typ : Entity_Id) return Boolean
|
is
|
is
|
begin
|
begin
|
-- Array type, check component type
|
-- Array type, check component type
|
|
|
if Is_Array_Type (Typ) then
|
if Is_Array_Type (Typ) then
|
return
|
return
|
Type_May_Have_Bit_Aligned_Components (Component_Type (Typ));
|
Type_May_Have_Bit_Aligned_Components (Component_Type (Typ));
|
|
|
-- Record type, check components
|
-- Record type, check components
|
|
|
elsif Is_Record_Type (Typ) then
|
elsif Is_Record_Type (Typ) then
|
declare
|
declare
|
E : Entity_Id;
|
E : Entity_Id;
|
|
|
begin
|
begin
|
E := First_Component_Or_Discriminant (Typ);
|
E := First_Component_Or_Discriminant (Typ);
|
while Present (E) loop
|
while Present (E) loop
|
if Component_May_Be_Bit_Aligned (E)
|
if Component_May_Be_Bit_Aligned (E)
|
or else Type_May_Have_Bit_Aligned_Components (Etype (E))
|
or else Type_May_Have_Bit_Aligned_Components (Etype (E))
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
|
|
Next_Component_Or_Discriminant (E);
|
Next_Component_Or_Discriminant (E);
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
end;
|
end;
|
|
|
-- Type other than array or record is always OK
|
-- Type other than array or record is always OK
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Type_May_Have_Bit_Aligned_Components;
|
end Type_May_Have_Bit_Aligned_Components;
|
|
|
----------------------------
|
----------------------------
|
-- Wrap_Cleanup_Procedure --
|
-- Wrap_Cleanup_Procedure --
|
----------------------------
|
----------------------------
|
|
|
procedure Wrap_Cleanup_Procedure (N : Node_Id) is
|
procedure Wrap_Cleanup_Procedure (N : Node_Id) is
|
Loc : constant Source_Ptr := Sloc (N);
|
Loc : constant Source_Ptr := Sloc (N);
|
Stseq : constant Node_Id := Handled_Statement_Sequence (N);
|
Stseq : constant Node_Id := Handled_Statement_Sequence (N);
|
Stmts : constant List_Id := Statements (Stseq);
|
Stmts : constant List_Id := Statements (Stseq);
|
|
|
begin
|
begin
|
if Abort_Allowed then
|
if Abort_Allowed then
|
Prepend_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
|
Prepend_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
|
Append_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer));
|
Append_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer));
|
end if;
|
end if;
|
end Wrap_Cleanup_Procedure;
|
end Wrap_Cleanup_Procedure;
|
|
|
end Exp_Util;
|
end Exp_Util;
|
|
|