1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Einfo
; use Einfo
;
28 with Exp_Attr
; use Exp_Attr
;
29 with Exp_Ch4
; use Exp_Ch4
;
30 with Exp_Ch6
; use Exp_Ch6
;
31 with Exp_Dbug
; use Exp_Dbug
;
32 with Exp_Util
; use Exp_Util
;
33 with Nlists
; use Nlists
;
34 with Rtsfind
; use Rtsfind
;
35 with Sem_Aux
; use Sem_Aux
;
36 with Sem_Res
; use Sem_Res
;
37 with Sem_Util
; use Sem_Util
;
38 with Sinfo
; use Sinfo
;
39 with Snames
; use Snames
;
40 with Stand
; use Stand
;
41 with Tbuild
; use Tbuild
;
43 package body Exp_Alfa
is
45 -----------------------
46 -- Local Subprograms --
47 -----------------------
49 procedure Expand_Alfa_Call
(N
: Node_Id
);
50 -- This procedure contains common processing for function and procedure
52 -- * expansion of actuals to introduce necessary temporaries
53 -- * replacement of renaming by subprogram renamed
55 procedure Expand_Alfa_N_Attribute_Reference
(N
: Node_Id
);
56 -- Expand attributes 'Old and 'Result only
58 procedure Expand_Alfa_N_In
(N
: Node_Id
);
59 -- Expand set membership into individual ones
61 procedure Expand_Alfa_N_Object_Renaming_Declaration
(N
: Node_Id
);
62 -- Perform name evaluation for a renamed object
64 procedure Expand_Alfa_N_Simple_Return_Statement
(N
: Node_Id
);
65 -- Insert conversion on function return if necessary
67 procedure Expand_Alfa_Simple_Function_Return
(N
: Node_Id
);
68 -- Expand simple return from function
70 procedure Expand_Potential_Renaming
(N
: Node_Id
);
71 -- N denotes a N_Identifier or N_Expanded_Name. If N references a renaming,
72 -- replace N with the renamed object.
78 procedure Expand_Alfa
(N
: Node_Id
) is
81 when N_Attribute_Reference
=>
82 Expand_Alfa_N_Attribute_Reference
(N
);
84 when N_Block_Statement |
86 N_Package_Declaration |
88 Qualify_Entity_Names
(N
);
90 when N_Subprogram_Call
=>
93 when N_Expanded_Name |
95 Expand_Potential_Renaming
(N
);
103 when N_Object_Renaming_Declaration
=>
104 Expand_Alfa_N_Object_Renaming_Declaration
(N
);
106 when N_Simple_Return_Statement
=>
107 Expand_Alfa_N_Simple_Return_Statement
(N
);
114 ----------------------
115 -- Expand_Alfa_Call --
116 ----------------------
118 procedure Expand_Alfa_Call
(N
: Node_Id
) is
119 Call_Node
: constant Node_Id
:= N
;
120 Parent_Subp
: Entity_Id
;
124 -- Ignore if previous error
126 if Nkind
(Call_Node
) in N_Has_Etype
127 and then Etype
(Call_Node
) = Any_Type
132 -- Call using access to subprogram with explicit dereference
134 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
135 Subp
:= Etype
(Name
(Call_Node
));
136 Parent_Subp
:= Empty
;
138 -- Case of call to simple entry, where the Name is a selected component
139 -- whose prefix is the task, and whose selector name is the entry name
141 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
142 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
143 Parent_Subp
:= Empty
;
145 -- Case of call to member of entry family, where Name is an indexed
146 -- component, with the prefix being a selected component giving the
147 -- task and entry family name, and the index being the entry index.
149 elsif Nkind
(Name
(Call_Node
)) = N_Indexed_Component
then
150 Subp
:= Entity
(Selector_Name
(Prefix
(Name
(Call_Node
))));
151 Parent_Subp
:= Empty
;
156 Subp
:= Entity
(Name
(Call_Node
));
157 Parent_Subp
:= Alias
(Subp
);
160 -- Various expansion activities for actuals are carried out
162 Expand_Actuals
(N
, Subp
);
164 -- If the subprogram is a renaming, replace it in the call with the name
165 -- of the actual subprogram being called.
167 if Present
(Parent_Subp
) then
168 Parent_Subp
:= Ultimate_Alias
(Parent_Subp
);
170 -- The below setting of Entity is suspect, see F109-018 discussion???
172 Set_Entity
(Name
(Call_Node
), Parent_Subp
);
174 end Expand_Alfa_Call
;
176 ---------------------------------------
177 -- Expand_Alfa_N_Attribute_Reference --
178 ---------------------------------------
180 procedure Expand_Alfa_N_Attribute_Reference
(N
: Node_Id
) is
181 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attribute_Name
(N
));
187 Expand_N_Attribute_Reference
(N
);
192 end Expand_Alfa_N_Attribute_Reference
;
194 ----------------------
195 -- Expand_Alfa_N_In --
196 ----------------------
198 procedure Expand_Alfa_N_In
(N
: Node_Id
) is
200 if Present
(Alternatives
(N
)) then
201 Expand_Set_Membership
(N
);
203 end Expand_Alfa_N_In
;
205 -----------------------------------------------
206 -- Expand_Alfa_N_Object_Renaming_Declaration --
207 -----------------------------------------------
209 procedure Expand_Alfa_N_Object_Renaming_Declaration
(N
: Node_Id
) is
211 -- Unconditionally remove all side effects from the name
213 Evaluate_Name
(Name
(N
));
214 end Expand_Alfa_N_Object_Renaming_Declaration
;
216 -------------------------------------------
217 -- Expand_Alfa_N_Simple_Return_Statement --
218 -------------------------------------------
220 procedure Expand_Alfa_N_Simple_Return_Statement
(N
: Node_Id
) is
222 -- Defend against previous errors (i.e. the return statement calls a
223 -- function that is not available in configurable runtime).
225 if Present
(Expression
(N
))
226 and then Nkind
(Expression
(N
)) = N_Empty
231 -- Distinguish the function and non-function cases:
233 case Ekind
(Return_Applies_To
(Return_Statement_Entity
(N
))) is
236 E_Generic_Function
=>
237 Expand_Alfa_Simple_Function_Return
(N
);
240 E_Generic_Procedure |
243 E_Return_Statement
=>
251 when RE_Not_Available
=>
253 end Expand_Alfa_N_Simple_Return_Statement
;
255 ----------------------------------------
256 -- Expand_Alfa_Simple_Function_Return --
257 ----------------------------------------
259 procedure Expand_Alfa_Simple_Function_Return
(N
: Node_Id
) is
260 Scope_Id
: constant Entity_Id
:=
261 Return_Applies_To
(Return_Statement_Entity
(N
));
262 -- The function we are returning from
264 R_Type
: constant Entity_Id
:= Etype
(Scope_Id
);
265 -- The result type of the function
267 Exp
: constant Node_Id
:= Expression
(N
);
268 pragma Assert
(Present
(Exp
));
270 Exptyp
: constant Entity_Id
:= Etype
(Exp
);
271 -- The type of the expression (not necessarily the same as R_Type)
274 -- Check the result expression of a scalar function against the subtype
275 -- of the function by inserting a conversion. This conversion must
276 -- eventually be performed for other classes of types, but for now it's
277 -- only done for scalars.
280 if Is_Scalar_Type
(Exptyp
) then
281 Rewrite
(Exp
, Convert_To
(R_Type
, Exp
));
283 -- The expression is resolved to ensure that the conversion gets
284 -- expanded to generate a possible constraint check.
286 Analyze_And_Resolve
(Exp
, R_Type
);
288 end Expand_Alfa_Simple_Function_Return
;
290 -------------------------------
291 -- Expand_Potential_Renaming --
292 -------------------------------
294 procedure Expand_Potential_Renaming
(N
: Node_Id
) is
295 E
: constant Entity_Id
:= Entity
(N
);
296 T
: constant Entity_Id
:= Etype
(N
);
299 -- Replace a reference to a renaming with the actual renamed object
301 if Ekind
(E
) in Object_Kind
and then Present
(Renamed_Object
(E
)) then
302 Rewrite
(N
, New_Copy_Tree
(Renamed_Object
(E
)));
303 Reset_Analyzed_Flags
(N
);
304 Analyze_And_Resolve
(N
, T
);
306 end Expand_Potential_Renaming
;