[Ada] Simplify processing of 'Valid_Scalars on array types

2020-06-19  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* exp_attr.adb (Expand_N_Attribute_Reference): Do not call
	Scalar_Part_Present on the array component's type.
	(Build_Array_VS_Func): Remove Comp_Typ parameter, because it can
	be easily computed from the Array_Top parameter *and redundant
	parameters are confusing and error-prone).
This commit is contained in:
Piotr Trojanek 2020-04-27 11:14:31 +02:00 committed by Pierre-Marie de Rodat
parent 66bd7af5cc
commit a4dafb8b92
1 changed files with 17 additions and 25 deletions

View File

@ -79,8 +79,7 @@ package body Exp_Attr is
function Build_Array_VS_Func function Build_Array_VS_Func
(Attr : Node_Id; (Attr : Node_Id;
Formal_Typ : Entity_Id; Formal_Typ : Entity_Id;
Array_Typ : Entity_Id; Array_Typ : Entity_Id) return Entity_Id;
Comp_Typ : Entity_Id) return Entity_Id;
-- Validate the components of an array type by means of a function. Return -- Validate the components of an array type by means of a function. Return
-- the entity of the validation function. The parameters are as follows: -- the entity of the validation function. The parameters are as follows:
-- --
@ -91,8 +90,6 @@ package body Exp_Attr is
-- parameter. -- parameter.
-- --
-- * Array_Typ - the array type whose components are to be validated -- * Array_Typ - the array type whose components are to be validated
--
-- * Comp_Typ - the component type of the array
function Build_Disp_Get_Task_Id_Call (Actual : Node_Id) return Node_Id; function Build_Disp_Get_Task_Id_Call (Actual : Node_Id) return Node_Id;
-- Build a call to Disp_Get_Task_Id, passing Actual as actual parameter -- Build a call to Disp_Get_Task_Id, passing Actual as actual parameter
@ -237,10 +234,11 @@ package body Exp_Attr is
function Build_Array_VS_Func function Build_Array_VS_Func
(Attr : Node_Id; (Attr : Node_Id;
Formal_Typ : Entity_Id; Formal_Typ : Entity_Id;
Array_Typ : Entity_Id; Array_Typ : Entity_Id) return Entity_Id
Comp_Typ : Entity_Id) return Entity_Id
is is
Loc : constant Source_Ptr := Sloc (Attr); Loc : constant Source_Ptr := Sloc (Attr);
Comp_Typ : constant Entity_Id :=
Validated_View (Component_Type (Array_Typ));
function Validate_Component function Validate_Component
(Obj_Id : Entity_Id; (Obj_Id : Entity_Id;
@ -7088,9 +7086,8 @@ package body Exp_Attr is
------------------- -------------------
when Attribute_Valid_Scalars => Valid_Scalars : declare when Attribute_Valid_Scalars => Valid_Scalars : declare
Val_Typ : constant Entity_Id := Validated_View (Ptyp); Val_Typ : constant Entity_Id := Validated_View (Ptyp);
Comp_Typ : Entity_Id; Expr : Node_Id;
Expr : Node_Id;
begin begin
-- Assume that the prefix does not need validation -- Assume that the prefix does not need validation
@ -7130,21 +7127,16 @@ package body Exp_Attr is
-- dimensions of the array while checking individual components. -- dimensions of the array while checking individual components.
elsif Is_Array_Type (Val_Typ) then elsif Is_Array_Type (Val_Typ) then
Comp_Typ := Validated_View (Component_Type (Val_Typ)); Expr :=
Make_Function_Call (Loc,
if Scalar_Part_Present (Comp_Typ) then Name =>
Expr := New_Occurrence_Of
Make_Function_Call (Loc, (Build_Array_VS_Func
Name => (Attr => N,
New_Occurrence_Of Formal_Typ => Ptyp,
(Build_Array_VS_Func Array_Typ => Val_Typ),
(Attr => N, Loc),
Formal_Typ => Ptyp, Parameter_Associations => New_List (Pref));
Array_Typ => Val_Typ,
Comp_Typ => Comp_Typ),
Loc),
Parameter_Associations => New_List (Pref));
end if;
-- Validate the scalar components, discriminants of a record type by -- Validate the scalar components, discriminants of a record type by
-- examining the structure of a record type. -- examining the structure of a record type.