Commit 3b26fe82 by Hristian Kirtchev Committed by Pierre-Marie de Rodat

[Ada] In-place initialization for Initialize_Scalars

This patch cleans up the implementation of routine Get_Simple_Init_Val. It also
eliminates potentially large and unnecessary tree replications in the context
of object default initialization.

No change in behavior, no test needed.

2018-05-22  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

	* exp_ch3.adb (Build_Array_Init_Proc): Update the call to
	Needs_Simple_Initialization.
	(Build_Init_Statements): Update the call to Get_Simple_Init_Val.
	(Check_Subtype_Bounds): Renamed to Extract_Subtype_Bounds. Update the
	profile and comment on usage.
	(Default_Initialize_Object): Do not use New_Copy_Tree to set the proper
	Sloc of a value obtained from aspect Default_Value because this could
	potentially replicate large trees. The proper Sloc is now set in
	Get_Simple_Init_Val.
	(Get_Simple_Init_Val): Reorganized by breaking the various cases into
	separate routines. Eliminate the use of global variables.
	(Init_Component): Update the call to Get_Simple_Init_Val.
	(Needs_Simple_Initialization): Update the parameter profile and all
	uses of T.
	(Simple_Init_Defaulted_Type): Copy the value of aspect Default_Value
	and set the proper Sloc.
	* exp_ch3.ads (Get_Simple_Init_Val): Update the parameter profile and
	comment on usage.
	(Needs_Simple_Initialization): Update the parameter profile.

From-SVN: r260526
parent 59ec5d9b
2018-05-22 Hristian Kirtchev <kirtchev@adacore.com>
* exp_ch3.adb (Build_Array_Init_Proc): Update the call to
Needs_Simple_Initialization.
(Build_Init_Statements): Update the call to Get_Simple_Init_Val.
(Check_Subtype_Bounds): Renamed to Extract_Subtype_Bounds. Update the
profile and comment on usage.
(Default_Initialize_Object): Do not use New_Copy_Tree to set the proper
Sloc of a value obtained from aspect Default_Value because this could
potentially replicate large trees. The proper Sloc is now set in
Get_Simple_Init_Val.
(Get_Simple_Init_Val): Reorganized by breaking the various cases into
separate routines. Eliminate the use of global variables.
(Init_Component): Update the call to Get_Simple_Init_Val.
(Needs_Simple_Initialization): Update the parameter profile and all
uses of T.
(Simple_Init_Defaulted_Type): Copy the value of aspect Default_Value
and set the proper Sloc.
* exp_ch3.ads (Get_Simple_Init_Val): Update the parameter profile and
comment on usage.
(Needs_Simple_Initialization): Update the parameter profile.
2018-05-22 Patrick Bernardi <bernardi@adacore.com> 2018-05-22 Patrick Bernardi <bernardi@adacore.com>
* sem_ch3.adb (Build_Discriminant_Constraints): Raise an error if the * sem_ch3.adb (Build_Discriminant_Constraints): Raise an error if the
......
...@@ -91,6 +91,26 @@ package Exp_Ch3 is ...@@ -91,6 +91,26 @@ package Exp_Ch3 is
-- want Gigi to see the node. This function can't delete the node itself -- want Gigi to see the node. This function can't delete the node itself
-- since it would confuse any remaining processing of the freeze node. -- since it would confuse any remaining processing of the freeze node.
function Get_Simple_Init_Val
(Typ : Entity_Id;
N : Node_Id;
Size : Uint := No_Uint) return Node_Id;
-- Build an expression which represents the required initial value of type
-- Typ for which predicate Needs_Simple_Initialization is True. N is a node
-- whose source location used in the construction of the expression. Size
-- is utilized as follows:
--
-- * If the size of the object to be initialized it is known, it should
-- be passed to the routine.
--
-- * If the size is unknown or is zero, then the Esize of Typ is used as
-- an estimate of the size.
--
-- The object size is needed to prepare a known invalid value for use by
-- Normalize_Scalars. A call to this routine where Typ denotes a scalar
-- type is only valid when Normalize_Scalars or Initialize_Scalars is
-- active, or if N is the node for a 'Invalid_Value attribute node.
procedure Init_Secondary_Tags procedure Init_Secondary_Tags
(Typ : Entity_Id; (Typ : Entity_Id;
Target : Node_Id; Target : Node_Id;
...@@ -115,7 +135,7 @@ package Exp_Ch3 is ...@@ -115,7 +135,7 @@ package Exp_Ch3 is
-- see Check_Address_Clause. -- see Check_Address_Clause.
function Needs_Simple_Initialization function Needs_Simple_Initialization
(T : Entity_Id; (Typ : Entity_Id;
Consider_IS : Boolean := True) return Boolean; Consider_IS : Boolean := True) return Boolean;
-- Certain types need initialization even though there is no specific -- Certain types need initialization even though there is no specific
-- initialization routine: -- initialization routine:
...@@ -127,20 +147,4 @@ package Exp_Ch3 is ...@@ -127,20 +147,4 @@ package Exp_Ch3 is
-- set to False, but if Consider_IS is set to True, then the cases above -- set to False, but if Consider_IS is set to True, then the cases above
-- mentioning Normalize_Scalars also apply for Initialize_Scalars mode. -- mentioning Normalize_Scalars also apply for Initialize_Scalars mode.
function Get_Simple_Init_Val
(T : Entity_Id;
N : Node_Id;
Size : Uint := No_Uint) return Node_Id;
-- For a type which Needs_Simple_Initialization (see above), prepares the
-- tree for an expression representing the required initial value. N is a
-- node whose source location used in constructing this tree which is
-- returned as the result of the call. The Size parameter indicates the
-- target size of the object if it is known (indicated by a value that is
-- not No_Uint and is greater than zero). If Size is not given (Size set to
-- No_Uint, or non-positive), then the Esize of T is used as an estimate of
-- the Size. The object size is needed to prepare a known invalid value for
-- use by Normalize_Scalars. A call to this routine where T is a scalar
-- type is only valid if we are in Normalize_Scalars or Initialize_Scalars
-- mode, or if N is the node for a 'Invalid_Value attribute node.
end Exp_Ch3; end Exp_Ch3;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment