annotate gcc/ada/exp_ch2.adb @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- E X P _ C H 2 --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 with Atree; use Atree;
kono
parents:
diff changeset
27 with Checks; use Checks;
kono
parents:
diff changeset
28 with Debug; use Debug;
kono
parents:
diff changeset
29 with Einfo; use Einfo;
kono
parents:
diff changeset
30 with Elists; use Elists;
kono
parents:
diff changeset
31 with Exp_Smem; use Exp_Smem;
kono
parents:
diff changeset
32 with Exp_Tss; use Exp_Tss;
kono
parents:
diff changeset
33 with Exp_Util; use Exp_Util;
kono
parents:
diff changeset
34 with Namet; use Namet;
kono
parents:
diff changeset
35 with Nmake; use Nmake;
kono
parents:
diff changeset
36 with Opt; use Opt;
kono
parents:
diff changeset
37 with Output; use Output;
kono
parents:
diff changeset
38 with Sem; use Sem;
kono
parents:
diff changeset
39 with Sem_Eval; use Sem_Eval;
kono
parents:
diff changeset
40 with Sem_Res; use Sem_Res;
kono
parents:
diff changeset
41 with Sem_Util; use Sem_Util;
kono
parents:
diff changeset
42 with Sem_Warn; use Sem_Warn;
kono
parents:
diff changeset
43 with Sinfo; use Sinfo;
kono
parents:
diff changeset
44 with Sinput; use Sinput;
kono
parents:
diff changeset
45 with Snames; use Snames;
kono
parents:
diff changeset
46 with Tbuild; use Tbuild;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 package body Exp_Ch2 is
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 -----------------------
kono
parents:
diff changeset
51 -- Local Subprograms --
kono
parents:
diff changeset
52 -----------------------
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 procedure Expand_Current_Value (N : Node_Id);
kono
parents:
diff changeset
55 -- N is a node for a variable whose Current_Value field is set. If N is
kono
parents:
diff changeset
56 -- node is for a discrete type, replaces node with a copy of the referenced
kono
parents:
diff changeset
57 -- value. This provides a limited form of value propagation for variables
kono
parents:
diff changeset
58 -- which are initialized or assigned not been further modified at the time
kono
parents:
diff changeset
59 -- of reference. The call has no effect if the Current_Value refers to a
kono
parents:
diff changeset
60 -- conditional with condition other than equality.
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 procedure Expand_Discriminant (N : Node_Id);
kono
parents:
diff changeset
63 -- An occurrence of a discriminant within a discriminated type is replaced
kono
parents:
diff changeset
64 -- with the corresponding discriminal, that is to say the formal parameter
kono
parents:
diff changeset
65 -- of the initialization procedure for the type that is associated with
kono
parents:
diff changeset
66 -- that particular discriminant. This replacement is not performed for
kono
parents:
diff changeset
67 -- discriminants of records that appear in constraints of component of the
kono
parents:
diff changeset
68 -- record, because Gigi uses the discriminant name to retrieve its value.
kono
parents:
diff changeset
69 -- In the other hand, it has to be performed for default expressions of
kono
parents:
diff changeset
70 -- components because they are used in the record init procedure. See Einfo
kono
parents:
diff changeset
71 -- for more details, and Exp_Ch3, Exp_Ch9 for examples of use. For
kono
parents:
diff changeset
72 -- discriminants of tasks and protected types, the transformation is more
kono
parents:
diff changeset
73 -- complex when it occurs within a default expression for an entry or
kono
parents:
diff changeset
74 -- protected operation. The corresponding default_expression_function has
kono
parents:
diff changeset
75 -- an additional parameter which is the target of an entry call, and the
kono
parents:
diff changeset
76 -- discriminant of the task must be replaced with a reference to the
kono
parents:
diff changeset
77 -- discriminant of that formal parameter.
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 procedure Expand_Entity_Reference (N : Node_Id);
kono
parents:
diff changeset
80 -- Common processing for expansion of identifiers and expanded names
kono
parents:
diff changeset
81 -- Dispatches to specific expansion procedures.
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 procedure Expand_Entry_Index_Parameter (N : Node_Id);
kono
parents:
diff changeset
84 -- A reference to the identifier in the entry index specification of an
kono
parents:
diff changeset
85 -- entry body is modified to a reference to a constant definition equal to
kono
parents:
diff changeset
86 -- the index of the entry family member being called. This constant is
kono
parents:
diff changeset
87 -- calculated as part of the elaboration of the expanded code for the body,
kono
parents:
diff changeset
88 -- and is calculated from the object-wide entry index returned by Next_
kono
parents:
diff changeset
89 -- Entry_Call.
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 procedure Expand_Entry_Parameter (N : Node_Id);
kono
parents:
diff changeset
92 -- A reference to an entry parameter is modified to be a reference to the
kono
parents:
diff changeset
93 -- corresponding component of the entry parameter record that is passed by
kono
parents:
diff changeset
94 -- the runtime to the accept body procedure.
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 procedure Expand_Formal (N : Node_Id);
kono
parents:
diff changeset
97 -- A reference to a formal parameter of a protected subprogram is expanded
kono
parents:
diff changeset
98 -- into the corresponding formal of the unprotected procedure used to
kono
parents:
diff changeset
99 -- represent the operation within the protected object. In other cases
kono
parents:
diff changeset
100 -- Expand_Formal is a no-op.
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 procedure Expand_Protected_Component (N : Node_Id);
kono
parents:
diff changeset
103 -- A reference to a private component of a protected type is expanded into
kono
parents:
diff changeset
104 -- a reference to the corresponding prival in the current protected entry
kono
parents:
diff changeset
105 -- or subprogram.
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 procedure Expand_Renaming (N : Node_Id);
kono
parents:
diff changeset
108 -- For renamings, just replace the identifier by the corresponding
kono
parents:
diff changeset
109 -- named expression. Note that this has been evaluated (see routine
kono
parents:
diff changeset
110 -- Exp_Ch8.Expand_N_Object_Renaming.Evaluate_Name) so this gives
kono
parents:
diff changeset
111 -- the correct renaming semantics.
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 --------------------------
kono
parents:
diff changeset
114 -- Expand_Current_Value --
kono
parents:
diff changeset
115 --------------------------
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 procedure Expand_Current_Value (N : Node_Id) is
kono
parents:
diff changeset
118 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
119 E : constant Entity_Id := Entity (N);
kono
parents:
diff changeset
120 CV : constant Node_Id := Current_Value (E);
kono
parents:
diff changeset
121 T : constant Entity_Id := Etype (N);
kono
parents:
diff changeset
122 Val : Node_Id;
kono
parents:
diff changeset
123 Op : Node_Kind;
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 -- Start of processing for Expand_Current_Value
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 begin
kono
parents:
diff changeset
128 if True
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 -- No replacement if value raises constraint error
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 and then Nkind (CV) /= N_Raise_Constraint_Error
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 -- Do this only for discrete types
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 and then Is_Discrete_Type (T)
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 -- Do not replace biased types, since it is problematic to
kono
parents:
diff changeset
139 -- consistently generate a sensible constant value in this case.
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 and then not Has_Biased_Representation (T)
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 -- Do not replace lvalues
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 and then not May_Be_Lvalue (N)
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 -- Check that entity is suitable for replacement
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 and then OK_To_Do_Constant_Replacement (E)
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 -- Do not replace occurrences in pragmas (where names typically
kono
parents:
diff changeset
152 -- appear not as values, but as simply names. If there are cases
kono
parents:
diff changeset
153 -- where values are required, it is only a very minor efficiency
kono
parents:
diff changeset
154 -- issue that they do not get replaced when they could be).
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 and then Nkind (Parent (N)) /= N_Pragma_Argument_Association
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 -- Do not replace the prefixes of attribute references, since this
kono
parents:
diff changeset
159 -- causes trouble with cases like 4'Size. Also for Name_Asm_Input and
kono
parents:
diff changeset
160 -- Name_Asm_Output, don't do replacement anywhere, since we can have
kono
parents:
diff changeset
161 -- lvalue references in the arguments.
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 and then not (Nkind (Parent (N)) = N_Attribute_Reference
kono
parents:
diff changeset
164 and then
kono
parents:
diff changeset
165 (Nam_In (Attribute_Name (Parent (N)),
kono
parents:
diff changeset
166 Name_Asm_Input,
kono
parents:
diff changeset
167 Name_Asm_Output)
kono
parents:
diff changeset
168 or else Prefix (Parent (N)) = N))
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 then
kono
parents:
diff changeset
171 -- Case of Current_Value is a compile time known value
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 if Nkind (CV) in N_Subexpr then
kono
parents:
diff changeset
174 Val := CV;
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 -- Case of Current_Value is an if expression reference
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 else
kono
parents:
diff changeset
179 Get_Current_Value_Condition (N, Op, Val);
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 if Op /= N_Op_Eq then
kono
parents:
diff changeset
182 return;
kono
parents:
diff changeset
183 end if;
kono
parents:
diff changeset
184 end if;
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 -- If constant value is an occurrence of an enumeration literal,
kono
parents:
diff changeset
187 -- then we just make another occurrence of the same literal.
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 if Is_Entity_Name (Val)
kono
parents:
diff changeset
190 and then Ekind (Entity (Val)) = E_Enumeration_Literal
kono
parents:
diff changeset
191 then
kono
parents:
diff changeset
192 Rewrite (N,
kono
parents:
diff changeset
193 Unchecked_Convert_To (T,
kono
parents:
diff changeset
194 New_Occurrence_Of (Entity (Val), Loc)));
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 -- If constant is of a character type, just make an appropriate
kono
parents:
diff changeset
197 -- character literal, which will get the proper type.
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 elsif Is_Character_Type (T) then
kono
parents:
diff changeset
200 Rewrite (N,
kono
parents:
diff changeset
201 Make_Character_Literal (Loc,
kono
parents:
diff changeset
202 Chars => Chars (Val),
kono
parents:
diff changeset
203 Char_Literal_Value => Expr_Rep_Value (Val)));
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 -- If constant is of an integer type, just make an appropriate
kono
parents:
diff changeset
206 -- integer literal, which will get the proper type.
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 elsif Is_Integer_Type (T) then
kono
parents:
diff changeset
209 Rewrite (N,
kono
parents:
diff changeset
210 Make_Integer_Literal (Loc,
kono
parents:
diff changeset
211 Intval => Expr_Rep_Value (Val)));
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 -- Otherwise do unchecked conversion of value to right type
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 else
kono
parents:
diff changeset
216 Rewrite (N,
kono
parents:
diff changeset
217 Unchecked_Convert_To (T,
kono
parents:
diff changeset
218 Make_Integer_Literal (Loc,
kono
parents:
diff changeset
219 Intval => Expr_Rep_Value (Val))));
kono
parents:
diff changeset
220 end if;
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 Analyze_And_Resolve (N, T);
kono
parents:
diff changeset
223 Set_Is_Static_Expression (N, False);
kono
parents:
diff changeset
224 end if;
kono
parents:
diff changeset
225 end Expand_Current_Value;
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 -------------------------
kono
parents:
diff changeset
228 -- Expand_Discriminant --
kono
parents:
diff changeset
229 -------------------------
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 procedure Expand_Discriminant (N : Node_Id) is
kono
parents:
diff changeset
232 Scop : constant Entity_Id := Scope (Entity (N));
kono
parents:
diff changeset
233 P : Node_Id := N;
kono
parents:
diff changeset
234 Parent_P : Node_Id := Parent (P);
kono
parents:
diff changeset
235 In_Entry : Boolean := False;
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 begin
kono
parents:
diff changeset
238 -- The Incomplete_Or_Private_Kind happens while resolving the
kono
parents:
diff changeset
239 -- discriminant constraint involved in a derived full type,
kono
parents:
diff changeset
240 -- such as:
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 -- type D is private;
kono
parents:
diff changeset
243 -- type D(C : ...) is new T(C);
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 if Ekind (Scop) = E_Record_Type
kono
parents:
diff changeset
246 or Ekind (Scop) in Incomplete_Or_Private_Kind
kono
parents:
diff changeset
247 then
kono
parents:
diff changeset
248 -- Find the origin by walking up the tree till the component
kono
parents:
diff changeset
249 -- declaration
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 while Present (Parent_P)
kono
parents:
diff changeset
252 and then Nkind (Parent_P) /= N_Component_Declaration
kono
parents:
diff changeset
253 loop
kono
parents:
diff changeset
254 P := Parent_P;
kono
parents:
diff changeset
255 Parent_P := Parent (P);
kono
parents:
diff changeset
256 end loop;
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 -- If the discriminant reference was part of the default expression
kono
parents:
diff changeset
259 -- it has to be "discriminalized"
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 if Present (Parent_P) and then P = Expression (Parent_P) then
kono
parents:
diff changeset
262 Set_Entity (N, Discriminal (Entity (N)));
kono
parents:
diff changeset
263 end if;
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 elsif Is_Concurrent_Type (Scop) then
kono
parents:
diff changeset
266 while Present (Parent_P)
kono
parents:
diff changeset
267 and then Nkind (Parent_P) /= N_Subprogram_Body
kono
parents:
diff changeset
268 loop
kono
parents:
diff changeset
269 P := Parent_P;
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 if Nkind (P) = N_Entry_Declaration then
kono
parents:
diff changeset
272 In_Entry := True;
kono
parents:
diff changeset
273 end if;
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 Parent_P := Parent (Parent_P);
kono
parents:
diff changeset
276 end loop;
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 -- If the discriminant occurs within the default expression for a
kono
parents:
diff changeset
279 -- formal of an entry or protected operation, replace it with a
kono
parents:
diff changeset
280 -- reference to the discriminant of the formal of the enclosing
kono
parents:
diff changeset
281 -- operation.
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 if Present (Parent_P)
kono
parents:
diff changeset
284 and then Present (Corresponding_Spec (Parent_P))
kono
parents:
diff changeset
285 then
kono
parents:
diff changeset
286 declare
kono
parents:
diff changeset
287 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
288 D_Fun : constant Entity_Id := Corresponding_Spec (Parent_P);
kono
parents:
diff changeset
289 Formal : constant Entity_Id := First_Formal (D_Fun);
kono
parents:
diff changeset
290 New_N : Node_Id;
kono
parents:
diff changeset
291 Disc : Entity_Id;
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 begin
kono
parents:
diff changeset
294 -- Verify that we are within the body of an entry or protected
kono
parents:
diff changeset
295 -- operation. Its first formal parameter is the synchronized
kono
parents:
diff changeset
296 -- type itself.
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 if Present (Formal)
kono
parents:
diff changeset
299 and then Etype (Formal) = Scope (Entity (N))
kono
parents:
diff changeset
300 then
kono
parents:
diff changeset
301 Disc := CR_Discriminant (Entity (N));
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 New_N :=
kono
parents:
diff changeset
304 Make_Selected_Component (Loc,
kono
parents:
diff changeset
305 Prefix => New_Occurrence_Of (Formal, Loc),
kono
parents:
diff changeset
306 Selector_Name => New_Occurrence_Of (Disc, Loc));
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 Set_Etype (New_N, Etype (N));
kono
parents:
diff changeset
309 Rewrite (N, New_N);
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 else
kono
parents:
diff changeset
312 Set_Entity (N, Discriminal (Entity (N)));
kono
parents:
diff changeset
313 end if;
kono
parents:
diff changeset
314 end;
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 elsif Nkind (Parent (N)) = N_Range
kono
parents:
diff changeset
317 and then In_Entry
kono
parents:
diff changeset
318 then
kono
parents:
diff changeset
319 Set_Entity (N, CR_Discriminant (Entity (N)));
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 -- Finally, if the entity is the discriminant of the original
kono
parents:
diff changeset
322 -- type declaration, and we are within the initialization
kono
parents:
diff changeset
323 -- procedure for a task, the designated entity is the
kono
parents:
diff changeset
324 -- discriminal of the task body. This can happen when the
kono
parents:
diff changeset
325 -- argument of pragma Task_Name mentions a discriminant,
kono
parents:
diff changeset
326 -- because the pragma is analyzed in the task declaration
kono
parents:
diff changeset
327 -- but is expanded in the call to Create_Task in the init_proc.
kono
parents:
diff changeset
328
kono
parents:
diff changeset
329 elsif Within_Init_Proc then
kono
parents:
diff changeset
330 Set_Entity (N, Discriminal (CR_Discriminant (Entity (N))));
kono
parents:
diff changeset
331 else
kono
parents:
diff changeset
332 Set_Entity (N, Discriminal (Entity (N)));
kono
parents:
diff changeset
333 end if;
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 else
kono
parents:
diff changeset
336 Set_Entity (N, Discriminal (Entity (N)));
kono
parents:
diff changeset
337 end if;
kono
parents:
diff changeset
338 end Expand_Discriminant;
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 -----------------------------
kono
parents:
diff changeset
341 -- Expand_Entity_Reference --
kono
parents:
diff changeset
342 -----------------------------
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 procedure Expand_Entity_Reference (N : Node_Id) is
kono
parents:
diff changeset
345 E : constant Entity_Id := Entity (N);
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 begin
kono
parents:
diff changeset
348 -- Defend against errors
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 if No (E) then
kono
parents:
diff changeset
351 Check_Error_Detected;
kono
parents:
diff changeset
352 return;
kono
parents:
diff changeset
353 end if;
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 if Ekind (E) = E_Discriminant then
kono
parents:
diff changeset
356 Expand_Discriminant (N);
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 elsif Is_Entry_Formal (E) then
kono
parents:
diff changeset
359 Expand_Entry_Parameter (N);
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 elsif Is_Protected_Component (E) then
kono
parents:
diff changeset
362 if No_Run_Time_Mode then
kono
parents:
diff changeset
363 return;
kono
parents:
diff changeset
364 else
kono
parents:
diff changeset
365 Expand_Protected_Component (N);
kono
parents:
diff changeset
366 end if;
kono
parents:
diff changeset
367
kono
parents:
diff changeset
368 elsif Ekind (E) = E_Entry_Index_Parameter then
kono
parents:
diff changeset
369 Expand_Entry_Index_Parameter (N);
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 elsif Is_Formal (E) then
kono
parents:
diff changeset
372 Expand_Formal (N);
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 elsif Is_Renaming_Of_Object (E) then
kono
parents:
diff changeset
375 Expand_Renaming (N);
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 elsif Ekind (E) = E_Variable
kono
parents:
diff changeset
378 and then Is_Shared_Passive (E)
kono
parents:
diff changeset
379 then
kono
parents:
diff changeset
380 Expand_Shared_Passive_Variable (N);
kono
parents:
diff changeset
381 end if;
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 -- Test code for implementing the pragma Reviewable requirement of
kono
parents:
diff changeset
384 -- classifying reads of scalars as referencing potentially uninitialized
kono
parents:
diff changeset
385 -- objects or not.
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 if Debug_Flag_XX
kono
parents:
diff changeset
388 and then Is_Scalar_Type (Etype (N))
kono
parents:
diff changeset
389 and then (Is_Assignable (E) or else Is_Constant_Object (E))
kono
parents:
diff changeset
390 and then Comes_From_Source (N)
kono
parents:
diff changeset
391 and then Is_LHS (N) = No
kono
parents:
diff changeset
392 and then not Is_Actual_Out_Parameter (N)
kono
parents:
diff changeset
393 and then (Nkind (Parent (N)) /= N_Attribute_Reference
kono
parents:
diff changeset
394 or else Attribute_Name (Parent (N)) /= Name_Valid)
kono
parents:
diff changeset
395 then
kono
parents:
diff changeset
396 Write_Location (Sloc (N));
kono
parents:
diff changeset
397 Write_Str (": Read from scalar """);
kono
parents:
diff changeset
398 Write_Name (Chars (N));
kono
parents:
diff changeset
399 Write_Str ("""");
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 if Is_Known_Valid (E) then
kono
parents:
diff changeset
402 Write_Str (", Is_Known_Valid");
kono
parents:
diff changeset
403 end if;
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 Write_Eol;
kono
parents:
diff changeset
406 end if;
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 -- Set Atomic_Sync_Required if necessary for atomic variable. Note that
kono
parents:
diff changeset
409 -- this processing does NOT apply to Volatile_Full_Access variables.
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 if Nkind_In (N, N_Identifier, N_Expanded_Name)
kono
parents:
diff changeset
412 and then Ekind (E) = E_Variable
kono
parents:
diff changeset
413 and then (Is_Atomic (E) or else Is_Atomic (Etype (E)))
kono
parents:
diff changeset
414 then
kono
parents:
diff changeset
415 declare
kono
parents:
diff changeset
416 Set : Boolean;
kono
parents:
diff changeset
417
kono
parents:
diff changeset
418 begin
kono
parents:
diff changeset
419 -- If variable is atomic, but type is not, setting depends on
kono
parents:
diff changeset
420 -- disable/enable state for the variable.
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 if Is_Atomic (E) and then not Is_Atomic (Etype (E)) then
kono
parents:
diff changeset
423 Set := not Atomic_Synchronization_Disabled (E);
kono
parents:
diff changeset
424
kono
parents:
diff changeset
425 -- If variable is not atomic, but its type is atomic, setting
kono
parents:
diff changeset
426 -- depends on disable/enable state for the type.
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 elsif not Is_Atomic (E) and then Is_Atomic (Etype (E)) then
kono
parents:
diff changeset
429 Set := not Atomic_Synchronization_Disabled (Etype (E));
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 -- Else both variable and type are atomic (see outer if), and we
kono
parents:
diff changeset
432 -- disable if either variable or its type have sync disabled.
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 else
kono
parents:
diff changeset
435 Set := (not Atomic_Synchronization_Disabled (E))
kono
parents:
diff changeset
436 and then
kono
parents:
diff changeset
437 (not Atomic_Synchronization_Disabled (Etype (E)));
kono
parents:
diff changeset
438 end if;
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 -- Set flag if required
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 if Set then
kono
parents:
diff changeset
443 Activate_Atomic_Synchronization (N);
kono
parents:
diff changeset
444 end if;
kono
parents:
diff changeset
445 end;
kono
parents:
diff changeset
446 end if;
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 -- Interpret possible Current_Value for variable case
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 if Is_Assignable (E)
kono
parents:
diff changeset
451 and then Present (Current_Value (E))
kono
parents:
diff changeset
452 then
kono
parents:
diff changeset
453 Expand_Current_Value (N);
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 -- We do want to warn for the case of a boolean variable (not a
kono
parents:
diff changeset
456 -- boolean constant) whose value is known at compile time.
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 if Is_Boolean_Type (Etype (N)) then
kono
parents:
diff changeset
459 Warn_On_Known_Condition (N);
kono
parents:
diff changeset
460 end if;
kono
parents:
diff changeset
461
kono
parents:
diff changeset
462 -- Don't mess with Current_Value for compile time known values. Not
kono
parents:
diff changeset
463 -- only is it unnecessary, but we could disturb an indication of a
kono
parents:
diff changeset
464 -- static value, which could cause semantic trouble.
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 elsif Compile_Time_Known_Value (N) then
kono
parents:
diff changeset
467 null;
kono
parents:
diff changeset
468
kono
parents:
diff changeset
469 -- Interpret possible Current_Value for constant case
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 elsif Is_Constant_Object (E)
kono
parents:
diff changeset
472 and then Present (Current_Value (E))
kono
parents:
diff changeset
473 then
kono
parents:
diff changeset
474 Expand_Current_Value (N);
kono
parents:
diff changeset
475 end if;
kono
parents:
diff changeset
476 end Expand_Entity_Reference;
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 ----------------------------------
kono
parents:
diff changeset
479 -- Expand_Entry_Index_Parameter --
kono
parents:
diff changeset
480 ----------------------------------
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 procedure Expand_Entry_Index_Parameter (N : Node_Id) is
kono
parents:
diff changeset
483 Index_Con : constant Entity_Id := Entry_Index_Constant (Entity (N));
kono
parents:
diff changeset
484 begin
kono
parents:
diff changeset
485 Set_Entity (N, Index_Con);
kono
parents:
diff changeset
486 Set_Etype (N, Etype (Index_Con));
kono
parents:
diff changeset
487 end Expand_Entry_Index_Parameter;
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 ----------------------------
kono
parents:
diff changeset
490 -- Expand_Entry_Parameter --
kono
parents:
diff changeset
491 ----------------------------
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 procedure Expand_Entry_Parameter (N : Node_Id) is
kono
parents:
diff changeset
494 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
495 Ent_Formal : constant Entity_Id := Entity (N);
kono
parents:
diff changeset
496 Ent_Spec : constant Entity_Id := Scope (Ent_Formal);
kono
parents:
diff changeset
497 Parm_Type : constant Entity_Id := Entry_Parameters_Type (Ent_Spec);
kono
parents:
diff changeset
498 Acc_Stack : constant Elist_Id := Accept_Address (Ent_Spec);
kono
parents:
diff changeset
499 Addr_Ent : constant Entity_Id := Node (Last_Elmt (Acc_Stack));
kono
parents:
diff changeset
500 P_Comp_Ref : Entity_Id;
kono
parents:
diff changeset
501
kono
parents:
diff changeset
502 function In_Assignment_Context (N : Node_Id) return Boolean;
kono
parents:
diff changeset
503 -- Check whether this is a context in which the entry formal may be
kono
parents:
diff changeset
504 -- assigned to.
kono
parents:
diff changeset
505
kono
parents:
diff changeset
506 ---------------------------
kono
parents:
diff changeset
507 -- In_Assignment_Context --
kono
parents:
diff changeset
508 ---------------------------
kono
parents:
diff changeset
509
kono
parents:
diff changeset
510 function In_Assignment_Context (N : Node_Id) return Boolean is
kono
parents:
diff changeset
511 begin
kono
parents:
diff changeset
512 -- Case of use in a call
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 -- ??? passing a formal as actual for a mode IN formal is
kono
parents:
diff changeset
515 -- considered as an assignment?
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 if Nkind_In (Parent (N), N_Procedure_Call_Statement,
kono
parents:
diff changeset
518 N_Entry_Call_Statement)
kono
parents:
diff changeset
519 or else (Nkind (Parent (N)) = N_Assignment_Statement
kono
parents:
diff changeset
520 and then N = Name (Parent (N)))
kono
parents:
diff changeset
521 then
kono
parents:
diff changeset
522 return True;
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 -- Case of a parameter association: climb up to enclosing call
kono
parents:
diff changeset
525
kono
parents:
diff changeset
526 elsif Nkind (Parent (N)) = N_Parameter_Association then
kono
parents:
diff changeset
527 return In_Assignment_Context (Parent (N));
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 -- Case of a selected component, indexed component or slice prefix:
kono
parents:
diff changeset
530 -- climb up the tree, unless the prefix is of an access type (in
kono
parents:
diff changeset
531 -- which case there is an implicit dereference, and the formal itself
kono
parents:
diff changeset
532 -- is not being assigned to).
kono
parents:
diff changeset
533
kono
parents:
diff changeset
534 elsif Nkind_In (Parent (N), N_Selected_Component,
kono
parents:
diff changeset
535 N_Indexed_Component,
kono
parents:
diff changeset
536 N_Slice)
kono
parents:
diff changeset
537 and then N = Prefix (Parent (N))
kono
parents:
diff changeset
538 and then not Is_Access_Type (Etype (N))
kono
parents:
diff changeset
539 and then In_Assignment_Context (Parent (N))
kono
parents:
diff changeset
540 then
kono
parents:
diff changeset
541 return True;
kono
parents:
diff changeset
542
kono
parents:
diff changeset
543 else
kono
parents:
diff changeset
544 return False;
kono
parents:
diff changeset
545 end if;
kono
parents:
diff changeset
546 end In_Assignment_Context;
kono
parents:
diff changeset
547
kono
parents:
diff changeset
548 -- Start of processing for Expand_Entry_Parameter
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 begin
kono
parents:
diff changeset
551 if Is_Task_Type (Scope (Ent_Spec))
kono
parents:
diff changeset
552 and then Comes_From_Source (Ent_Formal)
kono
parents:
diff changeset
553 then
kono
parents:
diff changeset
554 -- Before replacing the formal with the local renaming that is used
kono
parents:
diff changeset
555 -- in the accept block, note if this is an assignment context, and
kono
parents:
diff changeset
556 -- note the modification to avoid spurious warnings, because the
kono
parents:
diff changeset
557 -- original entity is not used further. If formal is unconstrained,
kono
parents:
diff changeset
558 -- we also generate an extra parameter to hold the Constrained
kono
parents:
diff changeset
559 -- attribute of the actual. No renaming is generated for this flag.
kono
parents:
diff changeset
560
kono
parents:
diff changeset
561 -- Calling Note_Possible_Modification in the expander is dubious,
kono
parents:
diff changeset
562 -- because this generates a cross-reference entry, and should be
kono
parents:
diff changeset
563 -- done during semantic processing so it is called in -gnatc mode???
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 if Ekind (Entity (N)) /= E_In_Parameter
kono
parents:
diff changeset
566 and then In_Assignment_Context (N)
kono
parents:
diff changeset
567 then
kono
parents:
diff changeset
568 Note_Possible_Modification (N, Sure => True);
kono
parents:
diff changeset
569 end if;
kono
parents:
diff changeset
570 end if;
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 -- What we need is a reference to the corresponding component of the
kono
parents:
diff changeset
573 -- parameter record object. The Accept_Address field of the entry entity
kono
parents:
diff changeset
574 -- references the address variable that contains the address of the
kono
parents:
diff changeset
575 -- accept parameters record. We first have to do an unchecked conversion
kono
parents:
diff changeset
576 -- to turn this into a pointer to the parameter record and then we
kono
parents:
diff changeset
577 -- select the required parameter field.
kono
parents:
diff changeset
578
kono
parents:
diff changeset
579 -- The same processing applies to protected entries, where the Accept_
kono
parents:
diff changeset
580 -- Address is also the address of the Parameters record.
kono
parents:
diff changeset
581
kono
parents:
diff changeset
582 P_Comp_Ref :=
kono
parents:
diff changeset
583 Make_Selected_Component (Loc,
kono
parents:
diff changeset
584 Prefix =>
kono
parents:
diff changeset
585 Make_Explicit_Dereference (Loc,
kono
parents:
diff changeset
586 Unchecked_Convert_To (Parm_Type,
kono
parents:
diff changeset
587 New_Occurrence_Of (Addr_Ent, Loc))),
kono
parents:
diff changeset
588 Selector_Name =>
kono
parents:
diff changeset
589 New_Occurrence_Of (Entry_Component (Ent_Formal), Loc));
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 -- For all types of parameters, the constructed parameter record object
kono
parents:
diff changeset
592 -- contains a pointer to the parameter. Thus we must dereference them to
kono
parents:
diff changeset
593 -- access them (this will often be redundant, since the dereference is
kono
parents:
diff changeset
594 -- implicit, but no harm is done by making it explicit).
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596 Rewrite (N,
kono
parents:
diff changeset
597 Make_Explicit_Dereference (Loc, P_Comp_Ref));
kono
parents:
diff changeset
598
kono
parents:
diff changeset
599 Analyze (N);
kono
parents:
diff changeset
600 end Expand_Entry_Parameter;
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 -------------------
kono
parents:
diff changeset
603 -- Expand_Formal --
kono
parents:
diff changeset
604 -------------------
kono
parents:
diff changeset
605
kono
parents:
diff changeset
606 procedure Expand_Formal (N : Node_Id) is
kono
parents:
diff changeset
607 E : constant Entity_Id := Entity (N);
kono
parents:
diff changeset
608 Scop : constant Entity_Id := Scope (E);
kono
parents:
diff changeset
609
kono
parents:
diff changeset
610 begin
kono
parents:
diff changeset
611 -- Check whether the subprogram of which this is a formal is
kono
parents:
diff changeset
612 -- a protected operation. The initialization procedure for
kono
parents:
diff changeset
613 -- the corresponding record type is not itself a protected operation.
kono
parents:
diff changeset
614
kono
parents:
diff changeset
615 if Is_Protected_Type (Scope (Scop))
kono
parents:
diff changeset
616 and then not Is_Init_Proc (Scop)
kono
parents:
diff changeset
617 and then Present (Protected_Formal (E))
kono
parents:
diff changeset
618 then
kono
parents:
diff changeset
619 Set_Entity (N, Protected_Formal (E));
kono
parents:
diff changeset
620 end if;
kono
parents:
diff changeset
621 end Expand_Formal;
kono
parents:
diff changeset
622
kono
parents:
diff changeset
623 ----------------------------
kono
parents:
diff changeset
624 -- Expand_N_Expanded_Name --
kono
parents:
diff changeset
625 ----------------------------
kono
parents:
diff changeset
626
kono
parents:
diff changeset
627 procedure Expand_N_Expanded_Name (N : Node_Id) is
kono
parents:
diff changeset
628 begin
kono
parents:
diff changeset
629 Expand_Entity_Reference (N);
kono
parents:
diff changeset
630 end Expand_N_Expanded_Name;
kono
parents:
diff changeset
631
kono
parents:
diff changeset
632 -------------------------
kono
parents:
diff changeset
633 -- Expand_N_Identifier --
kono
parents:
diff changeset
634 -------------------------
kono
parents:
diff changeset
635
kono
parents:
diff changeset
636 procedure Expand_N_Identifier (N : Node_Id) is
kono
parents:
diff changeset
637 begin
kono
parents:
diff changeset
638 Expand_Entity_Reference (N);
kono
parents:
diff changeset
639 end Expand_N_Identifier;
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 ---------------------------
kono
parents:
diff changeset
642 -- Expand_N_Real_Literal --
kono
parents:
diff changeset
643 ---------------------------
kono
parents:
diff changeset
644
kono
parents:
diff changeset
645 procedure Expand_N_Real_Literal (N : Node_Id) is
kono
parents:
diff changeset
646 pragma Unreferenced (N);
kono
parents:
diff changeset
647
kono
parents:
diff changeset
648 begin
kono
parents:
diff changeset
649 -- Historically, this routine existed because there were expansion
kono
parents:
diff changeset
650 -- requirements for Vax real literals, but now Vax real literals
kono
parents:
diff changeset
651 -- are now handled by gigi, so this routine no longer does anything.
kono
parents:
diff changeset
652
kono
parents:
diff changeset
653 null;
kono
parents:
diff changeset
654 end Expand_N_Real_Literal;
kono
parents:
diff changeset
655
kono
parents:
diff changeset
656 --------------------------------
kono
parents:
diff changeset
657 -- Expand_Protected_Component --
kono
parents:
diff changeset
658 --------------------------------
kono
parents:
diff changeset
659
kono
parents:
diff changeset
660 procedure Expand_Protected_Component (N : Node_Id) is
kono
parents:
diff changeset
661
kono
parents:
diff changeset
662 function Inside_Eliminated_Body return Boolean;
kono
parents:
diff changeset
663 -- Determine whether the current entity is inside a subprogram or an
kono
parents:
diff changeset
664 -- entry which has been marked as eliminated.
kono
parents:
diff changeset
665
kono
parents:
diff changeset
666 ----------------------------
kono
parents:
diff changeset
667 -- Inside_Eliminated_Body --
kono
parents:
diff changeset
668 ----------------------------
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 function Inside_Eliminated_Body return Boolean is
kono
parents:
diff changeset
671 S : Entity_Id := Current_Scope;
kono
parents:
diff changeset
672
kono
parents:
diff changeset
673 begin
kono
parents:
diff changeset
674 while Present (S) loop
kono
parents:
diff changeset
675 if (Ekind (S) = E_Entry
kono
parents:
diff changeset
676 or else Ekind (S) = E_Entry_Family
kono
parents:
diff changeset
677 or else Ekind (S) = E_Function
kono
parents:
diff changeset
678 or else Ekind (S) = E_Procedure)
kono
parents:
diff changeset
679 and then Is_Eliminated (S)
kono
parents:
diff changeset
680 then
kono
parents:
diff changeset
681 return True;
kono
parents:
diff changeset
682 end if;
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 S := Scope (S);
kono
parents:
diff changeset
685 end loop;
kono
parents:
diff changeset
686
kono
parents:
diff changeset
687 return False;
kono
parents:
diff changeset
688 end Inside_Eliminated_Body;
kono
parents:
diff changeset
689
kono
parents:
diff changeset
690 -- Start of processing for Expand_Protected_Component
kono
parents:
diff changeset
691
kono
parents:
diff changeset
692 begin
kono
parents:
diff changeset
693 -- Eliminated bodies are not expanded and thus do not need privals
kono
parents:
diff changeset
694
kono
parents:
diff changeset
695 if not Inside_Eliminated_Body then
kono
parents:
diff changeset
696 declare
kono
parents:
diff changeset
697 Priv : constant Entity_Id := Prival (Entity (N));
kono
parents:
diff changeset
698 begin
kono
parents:
diff changeset
699 Set_Entity (N, Priv);
kono
parents:
diff changeset
700 Set_Etype (N, Etype (Priv));
kono
parents:
diff changeset
701 end;
kono
parents:
diff changeset
702 end if;
kono
parents:
diff changeset
703 end Expand_Protected_Component;
kono
parents:
diff changeset
704
kono
parents:
diff changeset
705 ---------------------
kono
parents:
diff changeset
706 -- Expand_Renaming --
kono
parents:
diff changeset
707 ---------------------
kono
parents:
diff changeset
708
kono
parents:
diff changeset
709 procedure Expand_Renaming (N : Node_Id) is
kono
parents:
diff changeset
710 E : constant Entity_Id := Entity (N);
kono
parents:
diff changeset
711 T : constant Entity_Id := Etype (N);
kono
parents:
diff changeset
712
kono
parents:
diff changeset
713 begin
kono
parents:
diff changeset
714 Rewrite (N, New_Copy_Tree (Renamed_Object (E)));
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 -- We mark the copy as unanalyzed, so that it is sure to be reanalyzed
kono
parents:
diff changeset
717 -- at the top level. This is needed in the packed case since we
kono
parents:
diff changeset
718 -- specifically avoided expanding packed array references when the
kono
parents:
diff changeset
719 -- renaming declaration was analyzed.
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 Reset_Analyzed_Flags (N);
kono
parents:
diff changeset
722 Analyze_And_Resolve (N, T);
kono
parents:
diff changeset
723 end Expand_Renaming;
kono
parents:
diff changeset
724
kono
parents:
diff changeset
725 ------------------
kono
parents:
diff changeset
726 -- Param_Entity --
kono
parents:
diff changeset
727 ------------------
kono
parents:
diff changeset
728
kono
parents:
diff changeset
729 -- This would be trivial, simply a test for an identifier that was a
kono
parents:
diff changeset
730 -- reference to a formal, if it were not for the fact that a previous call
kono
parents:
diff changeset
731 -- to Expand_Entry_Parameter will have modified the reference to the
kono
parents:
diff changeset
732 -- identifier. A formal of a protected entity is rewritten as
kono
parents:
diff changeset
733
kono
parents:
diff changeset
734 -- typ!(recobj).rec.all'Constrained
kono
parents:
diff changeset
735
kono
parents:
diff changeset
736 -- where rec is a selector whose Entry_Formal link points to the formal
kono
parents:
diff changeset
737
kono
parents:
diff changeset
738 -- If the type of the entry parameter has a representation clause, then an
kono
parents:
diff changeset
739 -- extra temp is involved (see below).
kono
parents:
diff changeset
740
kono
parents:
diff changeset
741 -- For a formal of a task entity, the formal is rewritten as a local
kono
parents:
diff changeset
742 -- renaming.
kono
parents:
diff changeset
743
kono
parents:
diff changeset
744 -- In addition, a formal that is marked volatile because it is aliased
kono
parents:
diff changeset
745 -- through an address clause is rewritten as dereference as well.
kono
parents:
diff changeset
746
kono
parents:
diff changeset
747 function Param_Entity (N : Node_Id) return Entity_Id is
kono
parents:
diff changeset
748 Renamed_Obj : Node_Id;
kono
parents:
diff changeset
749
kono
parents:
diff changeset
750 begin
kono
parents:
diff changeset
751 -- Simple reference case
kono
parents:
diff changeset
752
kono
parents:
diff changeset
753 if Nkind_In (N, N_Identifier, N_Expanded_Name) then
kono
parents:
diff changeset
754 if Is_Formal (Entity (N)) then
kono
parents:
diff changeset
755 return Entity (N);
kono
parents:
diff changeset
756
kono
parents:
diff changeset
757 -- Handle renamings of formal parameters and formals of tasks that
kono
parents:
diff changeset
758 -- are rewritten as renamings.
kono
parents:
diff changeset
759
kono
parents:
diff changeset
760 elsif Nkind (Parent (Entity (N))) = N_Object_Renaming_Declaration then
kono
parents:
diff changeset
761 Renamed_Obj := Get_Referenced_Object (Renamed_Object (Entity (N)));
kono
parents:
diff changeset
762
kono
parents:
diff changeset
763 if Is_Entity_Name (Renamed_Obj)
kono
parents:
diff changeset
764 and then Is_Formal (Entity (Renamed_Obj))
kono
parents:
diff changeset
765 then
kono
parents:
diff changeset
766 return Entity (Renamed_Obj);
kono
parents:
diff changeset
767
kono
parents:
diff changeset
768 elsif
kono
parents:
diff changeset
769 Nkind (Parent (Parent (Entity (N)))) = N_Accept_Statement
kono
parents:
diff changeset
770 then
kono
parents:
diff changeset
771 return Entity (N);
kono
parents:
diff changeset
772 end if;
kono
parents:
diff changeset
773 end if;
kono
parents:
diff changeset
774
kono
parents:
diff changeset
775 else
kono
parents:
diff changeset
776 if Nkind (N) = N_Explicit_Dereference then
kono
parents:
diff changeset
777 declare
kono
parents:
diff changeset
778 P : Node_Id := Prefix (N);
kono
parents:
diff changeset
779 S : Node_Id;
kono
parents:
diff changeset
780 E : Entity_Id;
kono
parents:
diff changeset
781 Decl : Node_Id;
kono
parents:
diff changeset
782
kono
parents:
diff changeset
783 begin
kono
parents:
diff changeset
784 -- If the type of an entry parameter has a representation
kono
parents:
diff changeset
785 -- clause, then the prefix is not a selected component, but
kono
parents:
diff changeset
786 -- instead a reference to a temp pointing at the selected
kono
parents:
diff changeset
787 -- component. In this case, set P to be the initial value of
kono
parents:
diff changeset
788 -- that temp.
kono
parents:
diff changeset
789
kono
parents:
diff changeset
790 if Nkind (P) = N_Identifier then
kono
parents:
diff changeset
791 E := Entity (P);
kono
parents:
diff changeset
792
kono
parents:
diff changeset
793 if Ekind (E) = E_Constant then
kono
parents:
diff changeset
794 Decl := Parent (E);
kono
parents:
diff changeset
795
kono
parents:
diff changeset
796 if Nkind (Decl) = N_Object_Declaration then
kono
parents:
diff changeset
797 P := Expression (Decl);
kono
parents:
diff changeset
798 end if;
kono
parents:
diff changeset
799 end if;
kono
parents:
diff changeset
800 end if;
kono
parents:
diff changeset
801
kono
parents:
diff changeset
802 if Nkind (P) = N_Selected_Component then
kono
parents:
diff changeset
803 S := Selector_Name (P);
kono
parents:
diff changeset
804
kono
parents:
diff changeset
805 if Present (Entry_Formal (Entity (S))) then
kono
parents:
diff changeset
806 return Entry_Formal (Entity (S));
kono
parents:
diff changeset
807 end if;
kono
parents:
diff changeset
808
kono
parents:
diff changeset
809 elsif Nkind (Original_Node (N)) = N_Identifier then
kono
parents:
diff changeset
810 return Param_Entity (Original_Node (N));
kono
parents:
diff changeset
811 end if;
kono
parents:
diff changeset
812 end;
kono
parents:
diff changeset
813 end if;
kono
parents:
diff changeset
814 end if;
kono
parents:
diff changeset
815
kono
parents:
diff changeset
816 return (Empty);
kono
parents:
diff changeset
817 end Param_Entity;
kono
parents:
diff changeset
818
kono
parents:
diff changeset
819 end Exp_Ch2;