-- Return the dynamic level in the normal case
- return New_Occurrence_Of
- (Get_Dynamic_Accessibility (E), Loc);
+ return New_Occurrence_Of (Get_Dynamic_Accessibility (E), Loc);
-- Initialization procedures have a special extra accessibility
-- parameter associated with the level at which the object
return New_Occurrence_Of
(Init_Proc_Level_Formal (Scope (E)), Loc);
- -- Normal object - get the level of the enclosing scope
+ -- Formal object of generic subprogram - get the level of the
+ -- subprogram
+
+ elsif Is_Formal_Object (E) and then Is_Subprogram (Scope (E)) then
+ return Make_Level_Literal (Subprogram_Access_Level (Scope (E)));
+
+ -- Normal object - get the depth of the enclosing dynamic scope
else
return Make_Level_Literal
function Has_Anonymous_Access_Discriminant (Typ : Entity_Id) return Boolean;
-- Returns True if Typ has one or more anonymous access discriminants
+ function Has_Unconstrained_Access_Discriminants
+ (Subtyp : Entity_Id) return Boolean;
+ -- Returns True if the given subtype is unconstrained and has one or more
+ -- access discriminants.
+
+ function Needs_Accessibility_Level_Temp_Or_Check
+ (Conditional_Expr : Node_Id) return Boolean;
+ -- Determine whether a conditional expression occurs in a context that
+ -- requires either an associated accessibility-level-valued temp (which
+ -- is assigned to in each arm of the conditional expression) or an
+ -- accessibility level check (which is pushed down into each arm of the
+ -- conditional expression).
+
+ function Needs_Result_Accessibility_Level
+ (Func_Id : Entity_Id) return Boolean;
+ -- Ada 2012 (AI05-0234): Return True if the function needs an implicit
+ -- parameter to identify the accessibility level of the function result
+ -- "determined by the point of call". Return False if the type of the
+ -- function result is a private type and its completion is unavailable.
+
function Prefix_With_Safe_Accessibility_Level
(N : Node_Id;
Typ : Entity_Id) return Boolean;
-- integer for use in compile-time checking. Note: Level is restricted to
-- be non-dynamic.
- function Has_Unconstrained_Access_Discriminants
- (Subtyp : Entity_Id) return Boolean;
- -- Returns True if the given subtype is unconstrained and has one or more
- -- access discriminants.
-
- function Needs_Accessibility_Level_Temp_Or_Check
- (Conditional_Expr : Node_Id) return Boolean;
- -- Determine whether a conditional expression occurs in a context that
- -- requires either an associated accessibility-level-valued temp (which
- -- is assigned to in each arm of the conditional expression) or an
- -- accessibility level check (which is pushed down into each arm of the
- -- conditional expression).
-
- function Needs_Result_Accessibility_Level
- (Func_Id : Entity_Id) return Boolean;
- -- Ada 2012 (AI05-0234): Return True if the function needs an implicit
- -- parameter to identify the accessibility level of the function result
- -- "determined by the point of call". Return False if the type of the
- -- function result is a private type and its completion is unavailable.
-
function Subprogram_Access_Level (Subp : Entity_Id) return Uint;
- -- Return the accessibility level of the view denoted by Subp
+ -- Return the accessibility level of Subp. Note that this is the level of
+ -- the innermost master of the declaration of Subp (modulo renaming) and,
+ -- in particular, is *not* the level of the entities declared within Subp.
+ -- It is used to enforce the accessibility rules for access-to-subprogram
+ -- types, results of function calls, and formal objects of generic units.
function Type_Access_Level
(Typ : Entity_Id;
Object_Addr : constant System.Address := Get_Object_Address (X);
-- Address of the raised object
- type T_Acc is access T;
-
- function To_T_Acc is
- new Ada.Unchecked_Conversion (System.Address, T_Acc);
-
-- Import the object from the occurrence
- Result : constant T_Acc := To_T_Acc (Object_Addr);
+ Result : aliased T;
+ pragma Import (Ada, Result);
+ for Result'Address use Object_Addr;
begin
- return Result;
+ return Result'Unchecked_Access;
end Get_Access_To_Object;
---------------------------------
Object_Addr : constant System.Address := Get_Object_Address (X);
-- Address of the raised object
- type T_Acc is access T'Class;
-
- function To_T_Acc is
- new Ada.Unchecked_Conversion (System.Address, T_Acc);
-
-- Import the object from the occurrence
- Result : constant T_Acc := To_T_Acc (Object_Addr);
+ Result : aliased T;
+ pragma Import (Ada, Result);
+ for Result'Address use Object_Addr;
begin
- return Result;
+ return Result'Unchecked_Access;
end Get_Access_To_Tagged_Object;
-------------------