Minor reformatting.
(Install_Null_Excluding_Check): Moved to the package specification to use it from other packages to generate the run-time check associated with the null-exclusion attribute. From-SVN: r103896
This commit is contained in:
parent
d124a2302d
commit
1525324e88
|
@ -6,7 +6,7 @@
|
||||||
-- --
|
-- --
|
||||||
-- S p e c --
|
-- S p e c --
|
||||||
-- --
|
-- --
|
||||||
-- Copyright (C) 1992-2004 Free Software Foundation, Inc. --
|
-- Copyright (C) 1992-2005 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- --
|
||||||
|
@ -159,16 +159,20 @@ package Checks is
|
||||||
OK : out Boolean;
|
OK : out Boolean;
|
||||||
Lo : out Uint;
|
Lo : out Uint;
|
||||||
Hi : out Uint);
|
Hi : out Uint);
|
||||||
-- N is a node for a subexpression. If N is of a discrete type with
|
-- N is a node for a subexpression. If N is of a discrete type with no
|
||||||
-- no error indications, and no other peculiarities (e.g. missing
|
-- error indications, and no other peculiarities (e.g. missing type
|
||||||
-- type fields), then OK is True on return, and Lo and Hi are set
|
-- fields), then OK is True on return, and Lo and Hi are set to a
|
||||||
-- to a conservative estimate of the possible range of values of N.
|
-- conservative estimate of the possible range of values of N. Thus if OK
|
||||||
-- Thus if OK is True on return, the value of the subexpression N is
|
-- is True on return, the value of the subexpression N is known to like in
|
||||||
-- known to like in the range Lo .. Hi (inclusive). If the expression
|
-- the range Lo .. Hi (inclusive). If the expression is not of a discrete
|
||||||
-- is not of a discrete type, or some kind of error condition is
|
-- type, or some kind of error condition is detected, then OK is False on
|
||||||
-- detected, then OK is False on exit, and Lo/Hi are set to No_Uint.
|
-- exit, and Lo/Hi are set to No_Uint. Thus the significance of OK being
|
||||||
-- Thus the significance of OK being False on return is that no
|
-- False on return is that no useful information is available on the range
|
||||||
-- useful information is available on the range of the expression.
|
-- of the expression.
|
||||||
|
|
||||||
|
procedure Install_Null_Excluding_Check (N : Node_Id);
|
||||||
|
-- Determines whether an access node requires a runtime access check and
|
||||||
|
-- if so inserts the appropriate run-time check.
|
||||||
|
|
||||||
-------------------------------------------------------
|
-------------------------------------------------------
|
||||||
-- Control and Optimization of Range/Overflow Checks --
|
-- Control and Optimization of Range/Overflow Checks --
|
||||||
|
@ -181,12 +185,12 @@ package Checks is
|
||||||
-- in the transitional phase where some of these checks are still done
|
-- in the transitional phase where some of these checks are still done
|
||||||
-- by the back end, but many are done by the front end.
|
-- by the back end, but many are done by the front end.
|
||||||
|
|
||||||
-- Overflow checks are similarly controlled by the Do_Overflow_Check
|
-- Overflow checks are similarly controlled by the Do_Overflow_Check flag.
|
||||||
-- flag. The difference here is that if Backend_Overflow_Checks is
|
-- The difference here is that if Backend_Overflow_Checks is is
|
||||||
-- is (Backend_Overflow_Checks_On_Target set False), then the actual
|
-- (Backend_Overflow_Checks_On_Target set False), then the actual overflow
|
||||||
-- overflow checks are generated by the front end, but if back end
|
-- checks are generated by the front end, but if back end overflow checks
|
||||||
-- overflow checks are active (Backend_Overflow_Checks_On_Target
|
-- are active (Backend_Overflow_Checks_On_Target set True), then the back
|
||||||
-- set True), then the back end does generate the checks.
|
-- end does generate the checks.
|
||||||
|
|
||||||
-- The following two routines are used to set these flags, they allow
|
-- The following two routines are used to set these flags, they allow
|
||||||
-- for the possibility of eliminating checks. Checks can be eliminated
|
-- for the possibility of eliminating checks. Checks can be eliminated
|
||||||
|
@ -266,17 +270,16 @@ package Checks is
|
||||||
|
|
||||||
-- The checks operate in one of two modes:
|
-- The checks operate in one of two modes:
|
||||||
|
|
||||||
-- If Source_Typ is Empty, then the node Expr is examined, at the
|
-- If Source_Typ is Empty, then the node Expr is examined, at the very
|
||||||
-- very least to get the source subtype. In addition for some of
|
-- least to get the source subtype. In addition for some of the checks,
|
||||||
-- the checks, the actual form of the node may be examined. For
|
-- the actual form of the node may be examined. For example, a node of
|
||||||
-- example, a node of type Integer whose actual form is an Integer
|
-- type Integer whose actual form is an Integer conversion from a type
|
||||||
-- conversion from a type with range 0 .. 3 can be determined to
|
-- with range 0 .. 3 can be determined to have a value in range 0 .. 3.
|
||||||
-- have a value in the range 0 .. 3.
|
|
||||||
|
|
||||||
-- If Source_Typ is given, then nothing can be assumed about the
|
-- If Source_Typ is given, then nothing can be assumed about the Expr,
|
||||||
-- Expr, and indeed its contents are not examined. In this case the
|
-- and indeed its contents are not examined. In this case the check is
|
||||||
-- check is based on the assumption that Expr can be an arbitrary
|
-- based on the assumption that Expr can be an arbitrary value of the
|
||||||
-- value of the given Source_Typ.
|
-- given Source_Typ.
|
||||||
|
|
||||||
-- Currently, the only case in which a Source_Typ is explicitly supplied
|
-- Currently, the only case in which a Source_Typ is explicitly supplied
|
||||||
-- is for the case of Out and In_Out parameters, where, for the conversion
|
-- is for the case of Out and In_Out parameters, where, for the conversion
|
||||||
|
@ -293,8 +296,8 @@ package Checks is
|
||||||
-- to Insert_Actions.
|
-- to Insert_Actions.
|
||||||
--
|
--
|
||||||
-- For access types, the Directly_Designated_Type is retrieved and
|
-- For access types, the Directly_Designated_Type is retrieved and
|
||||||
-- processing continues as enumerated above, with a guard against
|
-- processing continues as enumerated above, with a guard against null
|
||||||
-- null values.
|
-- values.
|
||||||
--
|
--
|
||||||
-- Note: calls to Apply_Length_Check currently never supply an explicit
|
-- Note: calls to Apply_Length_Check currently never supply an explicit
|
||||||
-- Source_Typ parameter, but Apply_Length_Check takes this parameter and
|
-- Source_Typ parameter, but Apply_Length_Check takes this parameter and
|
||||||
|
@ -305,9 +308,9 @@ package Checks is
|
||||||
(Ck_Node : Node_Id;
|
(Ck_Node : Node_Id;
|
||||||
Target_Typ : Entity_Id;
|
Target_Typ : Entity_Id;
|
||||||
Source_Typ : Entity_Id := Empty);
|
Source_Typ : Entity_Id := Empty);
|
||||||
-- For an Node of kind N_Range, constructs a range check action that
|
-- For an Node of kind N_Range, constructs a range check action that tests
|
||||||
-- tests first that the range is not null and then that the range
|
-- first that the range is not null and then that the range is contained in
|
||||||
-- is contained in the Target_Typ range.
|
-- the Target_Typ range.
|
||||||
--
|
--
|
||||||
-- For scalar types, constructs a range check action that first tests that
|
-- For scalar types, constructs a range check action that first tests that
|
||||||
-- the expression is contained in the Target_Typ range. The difference
|
-- the expression is contained in the Target_Typ range. The difference
|
||||||
|
@ -318,13 +321,13 @@ package Checks is
|
||||||
-- to check that each Expr range is properly contained in the range of
|
-- to check that each Expr range is properly contained in the range of
|
||||||
-- Target_Typ.
|
-- Target_Typ.
|
||||||
--
|
--
|
||||||
-- For a type conversion to an unconstrained array type, constructs
|
-- For a type conversion to an unconstrained array type, constructs a range
|
||||||
-- a range check action to check that the bounds of the source type
|
-- check action to check that the bounds of the source type are within the
|
||||||
-- are within the constraints imposed by the Target_Typ.
|
-- constraints imposed by the Target_Typ.
|
||||||
--
|
--
|
||||||
-- For access types, the Directly_Designated_Type is retrieved and
|
-- For access types, the Directly_Designated_Type is retrieved and
|
||||||
-- processing continues as enumerated above, with a guard against
|
-- processing continues as enumerated above, with a guard against null
|
||||||
-- null values.
|
-- values.
|
||||||
--
|
--
|
||||||
-- The source type is used by type conversions to unconstrained array
|
-- The source type is used by type conversions to unconstrained array
|
||||||
-- types to retrieve the corresponding bounds.
|
-- types to retrieve the corresponding bounds.
|
||||||
|
@ -344,10 +347,10 @@ package Checks is
|
||||||
Source_Typ : Entity_Id := Empty;
|
Source_Typ : Entity_Id := Empty;
|
||||||
Fixed_Int : Boolean := False);
|
Fixed_Int : Boolean := False);
|
||||||
-- For scalar types, determines whether an expression node should be
|
-- For scalar types, determines whether an expression node should be
|
||||||
-- flagged as needing a runtime range check. If the node requires such
|
-- flagged as needing a runtime range check. If the node requires such a
|
||||||
-- a check, the Do_Range_Check flag is turned on. The Fixed_Int flag
|
-- check, the Do_Range_Check flag is turned on. The Fixed_Int flag if set
|
||||||
-- if set causes any fixed-point values to be treated as though they
|
-- causes any fixed-point values to be treated as though they were discrete
|
||||||
-- were discrete values (i.e. the underlying integer value is used).
|
-- values (i.e. the underlying integer value is used).
|
||||||
|
|
||||||
type Check_Result is private;
|
type Check_Result is private;
|
||||||
-- Type used to return result of Range_Check call, for later use in
|
-- Type used to return result of Range_Check call, for later use in
|
||||||
|
@ -360,12 +363,11 @@ package Checks is
|
||||||
Static_Sloc : Source_Ptr;
|
Static_Sloc : Source_Ptr;
|
||||||
Flag_Node : Node_Id);
|
Flag_Node : Node_Id);
|
||||||
-- Called to append range checks as returned by a call to Range_Check.
|
-- Called to append range checks as returned by a call to Range_Check.
|
||||||
-- Stmts is a list to which either the dynamic check is appended or
|
-- Stmts is a list to which either the dynamic check is appended or the
|
||||||
-- the raise Constraint_Error statement is appended (for static checks).
|
-- raise Constraint_Error statement is appended (for static checks).
|
||||||
-- Static_Sloc is the Sloc at which the raise CE node points,
|
-- Static_Sloc is the Sloc at which the raise CE node points, Flag_Node is
|
||||||
-- Flag_Node is used as the node at which to set the Has_Dynamic_Check
|
-- used as the node at which to set the Has_Dynamic_Check flag. Checks_On
|
||||||
-- flag. Checks_On is a boolean value that says if range and index checking
|
-- is a boolean value that says if range and index checking is on or not.
|
||||||
-- is on or not.
|
|
||||||
|
|
||||||
procedure Insert_Range_Checks
|
procedure Insert_Range_Checks
|
||||||
(Checks : Check_Result;
|
(Checks : Check_Result;
|
||||||
|
@ -402,12 +404,12 @@ package Checks is
|
||||||
-- Expander Routines --
|
-- Expander Routines --
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
-- Some of the earlier processing for checks results in temporarily
|
-- Some of the earlier processing for checks results in temporarily setting
|
||||||
-- setting the Do_Range_Check flag rather than actually generating
|
-- the Do_Range_Check flag rather than actually generating checks. Now we
|
||||||
-- checks. Now we are moving the generation of such checks into the
|
-- are moving the generation of such checks into the front end for reasons
|
||||||
-- front end for reasons of efficiency and simplicity (there were
|
-- of efficiency and simplicity (there were difficutlies in handling this
|
||||||
-- difficutlies in handling this in the back end when side effects
|
-- in the back end when side effects were present in the expressions being
|
||||||
-- were present in the expressions being checked).
|
-- checked).
|
||||||
|
|
||||||
-- Probably we could eliminate the Do_Range_Check flag entirely and
|
-- Probably we could eliminate the Do_Range_Check flag entirely and
|
||||||
-- generate the checks earlier, but this is a delicate area and it
|
-- generate the checks earlier, but this is a delicate area and it
|
||||||
|
@ -419,37 +421,36 @@ package Checks is
|
||||||
(N : Node_Id;
|
(N : Node_Id;
|
||||||
Target_Type : Entity_Id;
|
Target_Type : Entity_Id;
|
||||||
Reason : RT_Exception_Code);
|
Reason : RT_Exception_Code);
|
||||||
-- This procedure is called to actually generate and insert a range
|
-- This procedure is called to actually generate and insert a range check.
|
||||||
-- check. A check is generated to ensure that the value of N lies
|
-- A check is generated to ensure that the value of N lies within the range
|
||||||
-- within the range of the target type. Note that the base type of
|
-- of the target type. Note that the base type of N may be different from
|
||||||
-- N may be different from the base type of the target type. This
|
-- the base type of the target type. This happens in the conversion case.
|
||||||
-- happens in the conversion case. The Reason parameter is the
|
-- The Reason parameter is the exception code to be used for the exception
|
||||||
-- exception code to be used for the exception if raised.
|
-- if raised.
|
||||||
--
|
--
|
||||||
-- Note on the relation of this routine to the Do_Range_Check flag.
|
-- Note on the relation of this routine to the Do_Range_Check flag. Mostly
|
||||||
-- Mostly for historical reasons, we often set the Do_Range_Check
|
-- for historical reasons, we often set the Do_Range_Check flag and then
|
||||||
-- flag and then later we call Generate_Range_Check if this flag is
|
-- later we call Generate_Range_Check if this flag is set. Most probably we
|
||||||
-- set. Most probably we could eliminate this intermediate setting
|
-- could eliminate this intermediate setting of the flag (historically the
|
||||||
-- of the flag (historically the back end dealt with range checks,
|
-- back end dealt with range checks, using this flag to indicate if a check
|
||||||
-- using this flag to indicate if a check was required, then we
|
-- was required, then we moved checks into the front end).
|
||||||
-- moved checks into the front end).
|
|
||||||
|
|
||||||
procedure Generate_Index_Checks (N : Node_Id);
|
procedure Generate_Index_Checks (N : Node_Id);
|
||||||
-- This procedure is called to generate index checks on the subscripts
|
-- This procedure is called to generate index checks on the subscripts for
|
||||||
-- for the indexed component node N. Each subscript expression is
|
-- the indexed component node N. Each subscript expression is examined, and
|
||||||
-- examined, and if the Do_Range_Check flag is set, an appropriate
|
-- if the Do_Range_Check flag is set, an appropriate index check is
|
||||||
-- index check is generated and the flag is reset.
|
-- generated and the flag is reset.
|
||||||
|
|
||||||
-- Similarly, we set the flag Do_Discriminant_Check in the semantic
|
-- Similarly, we set the flag Do_Discriminant_Check in the semantic
|
||||||
-- analysis to indicate that a discriminant check is required for a
|
-- analysis to indicate that a discriminant check is required for selected
|
||||||
-- selected component of a discriminated type. The following routine
|
-- component of a discriminated type. The following routine is called from
|
||||||
-- is called from the expander to actually generate the call.
|
-- the expander to actually generate the call.
|
||||||
|
|
||||||
procedure Generate_Discriminant_Check (N : Node_Id);
|
procedure Generate_Discriminant_Check (N : Node_Id);
|
||||||
-- N is a selected component for which a discriminant check is required
|
-- N is a selected component for which a discriminant check is required to
|
||||||
-- to make sure that the discriminants have appropriate values for the
|
-- make sure that the discriminants have appropriate values for the
|
||||||
-- selection. This is done by calling the appropriate discriminant
|
-- selection. This is done by calling the appropriate discriminant checking
|
||||||
-- checking routine for the selector.
|
-- routine for the selector.
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
-- Validity Checking --
|
-- Validity Checking --
|
||||||
|
@ -457,15 +458,15 @@ package Checks is
|
||||||
|
|
||||||
-- In (RM 13.9.1(9-11)) we have the following rules on invalid values
|
-- In (RM 13.9.1(9-11)) we have the following rules on invalid values
|
||||||
|
|
||||||
-- If the representation of a scalar object does not represent a
|
-- If the representation of a scalar object does not represent value of
|
||||||
-- value of the object's subtype (perhaps because the object was not
|
-- the object's subtype (perhaps because the object was not initialized),
|
||||||
-- initialized), the object is said to have an invalid representation.
|
-- the object is said to have an invalid representation. It is a bounded
|
||||||
-- It is a bounded error to evaluate the value of such an object. If
|
-- error to evaluate the value of such an object. If the error is
|
||||||
-- the error is detected, either Constraint_Error or Program_Error is
|
-- detected, either Constraint_Error or Program_Error is raised.
|
||||||
-- raised. Otherwise, execution continues using the invalid
|
-- Otherwise, execution continues using the invalid representation. The
|
||||||
-- representation. The rules of the language outside this subclause
|
-- rules of the language outside this subclause assume that all objects
|
||||||
-- assume that all objects have valid representations. The semantics
|
-- have valid representations. The semantics of operations on invalid
|
||||||
-- of operations on invalid representations are as follows:
|
-- representations are as follows:
|
||||||
--
|
--
|
||||||
-- 10 If the representation of the object represents a value of the
|
-- 10 If the representation of the object represents a value of the
|
||||||
-- object's type, the value of the type is used.
|
-- object's type, the value of the type is used.
|
||||||
|
@ -483,9 +484,9 @@ package Checks is
|
||||||
-- array assignments, where we don't want to do wild stores, and case
|
-- array assignments, where we don't want to do wild stores, and case
|
||||||
-- statements where we don't want to do wild jumps.
|
-- statements where we don't want to do wild jumps.
|
||||||
|
|
||||||
-- In GNAT, we control validity checking with a switch -gnatV that
|
-- In GNAT, we control validity checking with a switch -gnatV that can take
|
||||||
-- can take three parameters, n/d/f for None/Default/Full. These
|
-- three parameters, n/d/f for None/Default/Full. These modes have the
|
||||||
-- modes have the following meanings:
|
-- following meanings:
|
||||||
|
|
||||||
-- None (no validity checking)
|
-- None (no validity checking)
|
||||||
|
|
||||||
|
@ -577,12 +578,12 @@ package Checks is
|
||||||
-- are checked for validity.
|
-- are checked for validity.
|
||||||
|
|
||||||
procedure Check_Valid_Lvalue_Subscripts (Expr : Node_Id);
|
procedure Check_Valid_Lvalue_Subscripts (Expr : Node_Id);
|
||||||
-- Expr is a lvalue, i.e. an expression representing the target of
|
-- Expr is a lvalue, i.e. an expression representing the target of an
|
||||||
-- an assignment. This procedure checks for this expression involving
|
-- assignment. This procedure checks for this expression involving an
|
||||||
-- an assignment to an array value. We have to be sure that all the
|
-- assignment to an array value. We have to be sure that all the subscripts
|
||||||
-- subscripts in such a case are valid, since according to the rules
|
-- in such a case are valid, since according to the rules in (RM
|
||||||
-- in (RM 13.9.1(9-11)) such assignments are not permitted to result
|
-- 13.9.1(9-11)) such assignments are not permitted to result in erroneous
|
||||||
-- in erroneous behavior in the case of invalid subscript values.
|
-- behavior in the case of invalid subscript values.
|
||||||
|
|
||||||
procedure Ensure_Valid (Expr : Node_Id; Holes_OK : Boolean := False);
|
procedure Ensure_Valid (Expr : Node_Id; Holes_OK : Boolean := False);
|
||||||
-- Ensure that Expr represents a valid value of its type. If this type
|
-- Ensure that Expr represents a valid value of its type. If this type
|
||||||
|
@ -602,14 +603,14 @@ package Checks is
|
||||||
-- valid, raising Constraint_Error if the value is not valid.
|
-- valid, raising Constraint_Error if the value is not valid.
|
||||||
|
|
||||||
function Expr_Known_Valid (Expr : Node_Id) return Boolean;
|
function Expr_Known_Valid (Expr : Node_Id) return Boolean;
|
||||||
-- This function tests it the value of Expr is known to be valid in
|
-- This function tests it the value of Expr is known to be valid in the
|
||||||
-- the sense of RM 13.9.1(9-11). In the case of GNAT, it is only
|
-- sense of RM 13.9.1(9-11). In the case of GNAT, it is only discrete types
|
||||||
-- discrete types which are a concern, since for non-discrete types
|
-- which are a concern, since for non-discrete types we simply continue
|
||||||
-- we simply continue computation with invalid values, which does
|
-- computation with invalid values, which does not lead to erroneous
|
||||||
-- not lead to erroneous behavior. Thus Expr_Known_Valid always
|
-- behavior. Thus Expr_Known_Valid always returns True if the type of Expr
|
||||||
-- returns True if the type of Expr is non-discrete. For discrete
|
-- is non-discrete. For discrete types the value returned is True only if
|
||||||
-- types the value returned is True only if it can be determined
|
-- it can be determined that the value is Valid. Otherwise False is
|
||||||
-- that the value is Valid. Otherwise False is returned.
|
-- returned.
|
||||||
|
|
||||||
procedure Insert_Valid_Check (Expr : Node_Id);
|
procedure Insert_Valid_Check (Expr : Node_Id);
|
||||||
-- Inserts code that will check for the value of Expr being valid, in
|
-- Inserts code that will check for the value of Expr being valid, in
|
||||||
|
@ -635,12 +636,12 @@ private
|
||||||
-- responsibility of the caller to rewrite and substitute the nodes with
|
-- responsibility of the caller to rewrite and substitute the nodes with
|
||||||
-- N_Raise_Constraint_Error nodes.
|
-- N_Raise_Constraint_Error nodes.
|
||||||
--
|
--
|
||||||
-- For the non-static case a single N_Raise_Constraint_Error node
|
-- For the non-static case a single N_Raise_Constraint_Error node with a
|
||||||
-- with a non-empty Condition field is returned.
|
-- non-empty Condition field is returned.
|
||||||
--
|
--
|
||||||
-- Unused entries in Check_Result, if any, are simply set to Empty
|
-- Unused entries in Check_Result, if any, are simply set to Empty For
|
||||||
-- For external clients, the required processing on this result is
|
-- external clients, the required processing on this result is achieved
|
||||||
-- achieved using the Insert_Range_Checks routine.
|
-- using the Insert_Range_Checks routine.
|
||||||
|
|
||||||
pragma Inline (Apply_Length_Check);
|
pragma Inline (Apply_Length_Check);
|
||||||
pragma Inline (Apply_Range_Check);
|
pragma Inline (Apply_Range_Check);
|
||||||
|
|
Loading…
Reference in New Issue