annotate gcc/ada/exp_spark.adb @ 143:76e1cf5455ef

add cbc_gc test
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 19:24:05 +0900
parents 84e7813d76e9
children 1830386684a0
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 _ S P A R K --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, 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 Einfo; use Einfo;
kono
parents:
diff changeset
29 with Exp_Ch4;
kono
parents:
diff changeset
30 with Exp_Ch5; use Exp_Ch5;
kono
parents:
diff changeset
31 with Exp_Dbug; use Exp_Dbug;
kono
parents:
diff changeset
32 with Exp_Util; use Exp_Util;
kono
parents:
diff changeset
33 with Namet; use Namet;
kono
parents:
diff changeset
34 with Nlists; use Nlists;
kono
parents:
diff changeset
35 with Nmake; use Nmake;
kono
parents:
diff changeset
36 with Rtsfind; use Rtsfind;
kono
parents:
diff changeset
37 with Sem; use Sem;
kono
parents:
diff changeset
38 with Sem_Eval; use Sem_Eval;
kono
parents:
diff changeset
39 with Sem_Prag; use Sem_Prag;
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 Sinfo; use Sinfo;
kono
parents:
diff changeset
43 with Snames; use Snames;
kono
parents:
diff changeset
44 with Stand; use Stand;
kono
parents:
diff changeset
45 with Tbuild; use Tbuild;
kono
parents:
diff changeset
46 with Uintp; use Uintp;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 package body Exp_SPARK 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_SPARK_N_Attribute_Reference (N : Node_Id);
kono
parents:
diff changeset
55 -- Replace occurrences of System'To_Address by calls to
kono
parents:
diff changeset
56 -- System.Storage_Elements.To_Address
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 procedure Expand_SPARK_N_Freeze_Type (E : Entity_Id);
kono
parents:
diff changeset
59 -- Build the DIC procedure of a type when needed, if not already done
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 procedure Expand_SPARK_N_Indexed_Component (N : Node_Id);
kono
parents:
diff changeset
62 -- Insert explicit dereference if required
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 procedure Expand_SPARK_N_Loop_Statement (N : Node_Id);
kono
parents:
diff changeset
65 -- Perform loop statement-specific expansion
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 procedure Expand_SPARK_N_Object_Declaration (N : Node_Id);
kono
parents:
diff changeset
68 -- Perform object-declaration-specific expansion
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 procedure Expand_SPARK_N_Object_Renaming_Declaration (N : Node_Id);
kono
parents:
diff changeset
71 -- Perform name evaluation for a renamed object
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 procedure Expand_SPARK_N_Op_Ne (N : Node_Id);
kono
parents:
diff changeset
74 -- Rewrite operator /= based on operator = when defined explicitly
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 procedure Expand_SPARK_N_Selected_Component (N : Node_Id);
kono
parents:
diff changeset
77 -- Insert explicit dereference if required
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 ------------------
kono
parents:
diff changeset
80 -- Expand_SPARK --
kono
parents:
diff changeset
81 ------------------
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 procedure Expand_SPARK (N : Node_Id) is
kono
parents:
diff changeset
84 begin
kono
parents:
diff changeset
85 case Nkind (N) is
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 -- Qualification of entity names in formal verification mode
kono
parents:
diff changeset
88 -- is limited to the addition of a suffix for homonyms (see
kono
parents:
diff changeset
89 -- Exp_Dbug.Qualify_Entity_Name). We used to qualify entity names
kono
parents:
diff changeset
90 -- as full expansion does, but this was removed as this prevents the
kono
parents:
diff changeset
91 -- verification back-end from using a short name for debugging and
kono
parents:
diff changeset
92 -- user interaction. The verification back-end already takes care
kono
parents:
diff changeset
93 -- of qualifying names when needed.
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 when N_Block_Statement
kono
parents:
diff changeset
96 | N_Entry_Declaration
kono
parents:
diff changeset
97 | N_Package_Body
kono
parents:
diff changeset
98 | N_Package_Declaration
kono
parents:
diff changeset
99 | N_Protected_Type_Declaration
kono
parents:
diff changeset
100 | N_Subprogram_Body
kono
parents:
diff changeset
101 | N_Task_Type_Declaration
kono
parents:
diff changeset
102 =>
kono
parents:
diff changeset
103 Qualify_Entity_Names (N);
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 -- Replace occurrences of System'To_Address by calls to
kono
parents:
diff changeset
106 -- System.Storage_Elements.To_Address.
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 when N_Attribute_Reference =>
kono
parents:
diff changeset
109 Expand_SPARK_N_Attribute_Reference (N);
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 when N_Expanded_Name
kono
parents:
diff changeset
112 | N_Identifier
kono
parents:
diff changeset
113 =>
kono
parents:
diff changeset
114 Expand_SPARK_Potential_Renaming (N);
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 -- Loop iterations over arrays need to be expanded, to avoid getting
kono
parents:
diff changeset
117 -- two names referring to the same object in memory (the array and
kono
parents:
diff changeset
118 -- the iterator) in GNATprove, especially since both can be written
kono
parents:
diff changeset
119 -- (thus possibly leading to interferences due to aliasing). No such
kono
parents:
diff changeset
120 -- problem arises with quantified expressions over arrays, which are
kono
parents:
diff changeset
121 -- dealt with specially in GNATprove.
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 when N_Loop_Statement =>
kono
parents:
diff changeset
124 Expand_SPARK_N_Loop_Statement (N);
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 when N_Object_Declaration =>
kono
parents:
diff changeset
127 Expand_SPARK_N_Object_Declaration (N);
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 when N_Object_Renaming_Declaration =>
kono
parents:
diff changeset
130 Expand_SPARK_N_Object_Renaming_Declaration (N);
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 when N_Op_Ne =>
kono
parents:
diff changeset
133 Expand_SPARK_N_Op_Ne (N);
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 when N_Freeze_Entity =>
kono
parents:
diff changeset
136 if Is_Type (Entity (N)) then
kono
parents:
diff changeset
137 Expand_SPARK_N_Freeze_Type (Entity (N));
kono
parents:
diff changeset
138 end if;
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 when N_Indexed_Component =>
kono
parents:
diff changeset
141 Expand_SPARK_N_Indexed_Component (N);
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 when N_Selected_Component =>
kono
parents:
diff changeset
144 Expand_SPARK_N_Selected_Component (N);
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 -- In SPARK mode, no other constructs require expansion
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 when others =>
kono
parents:
diff changeset
149 null;
kono
parents:
diff changeset
150 end case;
kono
parents:
diff changeset
151 end Expand_SPARK;
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 --------------------------------
kono
parents:
diff changeset
154 -- Expand_SPARK_N_Freeze_Type --
kono
parents:
diff changeset
155 --------------------------------
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 procedure Expand_SPARK_N_Freeze_Type (E : Entity_Id) is
kono
parents:
diff changeset
158 begin
kono
parents:
diff changeset
159 -- When a DIC is inherited by a tagged type, it may need to be
kono
parents:
diff changeset
160 -- specialized to the descendant type, hence build a separate DIC
kono
parents:
diff changeset
161 -- procedure for it as done during regular expansion for compilation.
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 if Has_DIC (E) and then Is_Tagged_Type (E) then
kono
parents:
diff changeset
164 Build_DIC_Procedure_Body (E, For_Freeze => True);
kono
parents:
diff changeset
165 end if;
kono
parents:
diff changeset
166 end Expand_SPARK_N_Freeze_Type;
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 ----------------------------------------
kono
parents:
diff changeset
169 -- Expand_SPARK_N_Attribute_Reference --
kono
parents:
diff changeset
170 ----------------------------------------
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 procedure Expand_SPARK_N_Attribute_Reference (N : Node_Id) is
kono
parents:
diff changeset
173 Aname : constant Name_Id := Attribute_Name (N);
kono
parents:
diff changeset
174 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
kono
parents:
diff changeset
175 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
176 Typ : constant Entity_Id := Etype (N);
kono
parents:
diff changeset
177 Expr : Node_Id;
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 begin
kono
parents:
diff changeset
180 if Attr_Id = Attribute_To_Address then
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 -- Extract and convert argument to expected type for call
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 Expr :=
kono
parents:
diff changeset
185 Make_Type_Conversion (Loc,
kono
parents:
diff changeset
186 Subtype_Mark =>
kono
parents:
diff changeset
187 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
kono
parents:
diff changeset
188 Expression => Relocate_Node (First (Expressions (N))));
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 -- Replace attribute reference with call
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 Rewrite (N,
kono
parents:
diff changeset
193 Make_Function_Call (Loc,
kono
parents:
diff changeset
194 Name =>
kono
parents:
diff changeset
195 New_Occurrence_Of (RTE (RE_To_Address), Loc),
kono
parents:
diff changeset
196 Parameter_Associations => New_List (Expr)));
kono
parents:
diff changeset
197 Analyze_And_Resolve (N, Typ);
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 -- For attributes which return Universal_Integer, introduce a conversion
kono
parents:
diff changeset
200 -- to the expected type with the appropriate check flags set.
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 elsif Attr_Id = Attribute_Alignment
kono
parents:
diff changeset
203 or else Attr_Id = Attribute_Bit
kono
parents:
diff changeset
204 or else Attr_Id = Attribute_Bit_Position
kono
parents:
diff changeset
205 or else Attr_Id = Attribute_Descriptor_Size
kono
parents:
diff changeset
206 or else Attr_Id = Attribute_First_Bit
kono
parents:
diff changeset
207 or else Attr_Id = Attribute_Last_Bit
kono
parents:
diff changeset
208 or else Attr_Id = Attribute_Length
kono
parents:
diff changeset
209 or else Attr_Id = Attribute_Max_Size_In_Storage_Elements
kono
parents:
diff changeset
210 or else Attr_Id = Attribute_Pos
kono
parents:
diff changeset
211 or else Attr_Id = Attribute_Position
kono
parents:
diff changeset
212 or else Attr_Id = Attribute_Range_Length
kono
parents:
diff changeset
213 or else Attr_Id = Attribute_Object_Size
kono
parents:
diff changeset
214 or else Attr_Id = Attribute_Size
kono
parents:
diff changeset
215 or else Attr_Id = Attribute_Value_Size
kono
parents:
diff changeset
216 or else Attr_Id = Attribute_VADS_Size
kono
parents:
diff changeset
217 or else Attr_Id = Attribute_Aft
kono
parents:
diff changeset
218 or else Attr_Id = Attribute_Max_Alignment_For_Allocation
kono
parents:
diff changeset
219 then
kono
parents:
diff changeset
220 -- If the expected type is Long_Long_Integer, there will be no check
kono
parents:
diff changeset
221 -- flag as the compiler assumes attributes always fit in this type.
kono
parents:
diff changeset
222 -- Since in SPARK_Mode we do not take Storage_Error into account, we
kono
parents:
diff changeset
223 -- cannot make this assumption and need to produce a check.
kono
parents:
diff changeset
224 -- ??? It should be enough to add this check for attributes 'Length
kono
parents:
diff changeset
225 -- and 'Range_Length when the type is as big as Long_Long_Integer.
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 declare
kono
parents:
diff changeset
228 Typ : Entity_Id := Empty;
kono
parents:
diff changeset
229 begin
kono
parents:
diff changeset
230 if Attr_Id = Attribute_Range_Length then
kono
parents:
diff changeset
231 Typ := Etype (Prefix (N));
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 elsif Attr_Id = Attribute_Length then
kono
parents:
diff changeset
234 Typ := Etype (Prefix (N));
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 declare
kono
parents:
diff changeset
237 Indx : Node_Id;
kono
parents:
diff changeset
238 J : Int;
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 begin
kono
parents:
diff changeset
241 if Is_Access_Type (Typ) then
kono
parents:
diff changeset
242 Typ := Designated_Type (Typ);
kono
parents:
diff changeset
243 end if;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 if No (Expressions (N)) then
kono
parents:
diff changeset
246 J := 1;
kono
parents:
diff changeset
247 else
kono
parents:
diff changeset
248 J := UI_To_Int (Expr_Value (First (Expressions (N))));
kono
parents:
diff changeset
249 end if;
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 Indx := First_Index (Typ);
kono
parents:
diff changeset
252 while J > 1 loop
kono
parents:
diff changeset
253 Next_Index (Indx);
kono
parents:
diff changeset
254 J := J - 1;
kono
parents:
diff changeset
255 end loop;
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 Typ := Etype (Indx);
kono
parents:
diff changeset
258 end;
kono
parents:
diff changeset
259 end if;
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 Apply_Universal_Integer_Attribute_Checks (N);
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 if Present (Typ)
kono
parents:
diff changeset
264 and then RM_Size (Typ) = RM_Size (Standard_Long_Long_Integer)
kono
parents:
diff changeset
265 then
kono
parents:
diff changeset
266 Set_Do_Overflow_Check (N);
kono
parents:
diff changeset
267 end if;
kono
parents:
diff changeset
268 end;
kono
parents:
diff changeset
269 end if;
kono
parents:
diff changeset
270 end Expand_SPARK_N_Attribute_Reference;
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 -----------------------------------
kono
parents:
diff changeset
273 -- Expand_SPARK_N_Loop_Statement --
kono
parents:
diff changeset
274 -----------------------------------
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 procedure Expand_SPARK_N_Loop_Statement (N : Node_Id) is
kono
parents:
diff changeset
277 Scheme : constant Node_Id := Iteration_Scheme (N);
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 begin
kono
parents:
diff changeset
280 -- Loop iterations over arrays need to be expanded, to avoid getting
kono
parents:
diff changeset
281 -- two names referring to the same object in memory (the array and the
kono
parents:
diff changeset
282 -- iterator) in GNATprove, especially since both can be written (thus
kono
parents:
diff changeset
283 -- possibly leading to interferences due to aliasing). No such problem
kono
parents:
diff changeset
284 -- arises with quantified expressions over arrays, which are dealt with
kono
parents:
diff changeset
285 -- specially in GNATprove.
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 if Present (Scheme)
kono
parents:
diff changeset
288 and then Present (Iterator_Specification (Scheme))
kono
parents:
diff changeset
289 and then Is_Iterator_Over_Array (Iterator_Specification (Scheme))
kono
parents:
diff changeset
290 then
kono
parents:
diff changeset
291 Expand_Iterator_Loop_Over_Array (N);
kono
parents:
diff changeset
292 end if;
kono
parents:
diff changeset
293 end Expand_SPARK_N_Loop_Statement;
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 --------------------------------------
kono
parents:
diff changeset
296 -- Expand_SPARK_N_Indexed_Component --
kono
parents:
diff changeset
297 --------------------------------------
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 procedure Expand_SPARK_N_Indexed_Component (N : Node_Id) is
kono
parents:
diff changeset
300 Pref : constant Node_Id := Prefix (N);
kono
parents:
diff changeset
301 Typ : constant Entity_Id := Etype (Pref);
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 begin
kono
parents:
diff changeset
304 if Is_Access_Type (Typ) then
kono
parents:
diff changeset
305 Insert_Explicit_Dereference (Pref);
kono
parents:
diff changeset
306 Analyze_And_Resolve (Pref, Designated_Type (Typ));
kono
parents:
diff changeset
307 end if;
kono
parents:
diff changeset
308 end Expand_SPARK_N_Indexed_Component;
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 ---------------------------------------
kono
parents:
diff changeset
311 -- Expand_SPARK_N_Object_Declaration --
kono
parents:
diff changeset
312 ---------------------------------------
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 procedure Expand_SPARK_N_Object_Declaration (N : Node_Id) is
kono
parents:
diff changeset
315 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
316 Obj_Id : constant Entity_Id := Defining_Identifier (N);
kono
parents:
diff changeset
317 Typ : constant Entity_Id := Etype (Obj_Id);
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 Call : Node_Id;
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 begin
kono
parents:
diff changeset
322 -- If the object declaration denotes a variable without initialization
kono
parents:
diff changeset
323 -- whose type is subject to pragma Default_Initial_Condition, create
kono
parents:
diff changeset
324 -- and analyze a dummy call to the DIC procedure of the type in order
kono
parents:
diff changeset
325 -- to detect potential elaboration issues.
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 if Comes_From_Source (Obj_Id)
kono
parents:
diff changeset
328 and then Ekind (Obj_Id) = E_Variable
kono
parents:
diff changeset
329 and then Has_DIC (Typ)
kono
parents:
diff changeset
330 and then Present (DIC_Procedure (Typ))
kono
parents:
diff changeset
331 and then not Has_Init_Expression (N)
kono
parents:
diff changeset
332 then
kono
parents:
diff changeset
333 Call := Build_DIC_Call (Loc, Obj_Id, Typ);
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 -- Partially insert the call into the tree by setting its parent
kono
parents:
diff changeset
336 -- pointer.
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 Set_Parent (Call, N);
kono
parents:
diff changeset
339 Analyze (Call);
kono
parents:
diff changeset
340 end if;
kono
parents:
diff changeset
341 end Expand_SPARK_N_Object_Declaration;
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 ------------------------------------------------
kono
parents:
diff changeset
344 -- Expand_SPARK_N_Object_Renaming_Declaration --
kono
parents:
diff changeset
345 ------------------------------------------------
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 procedure Expand_SPARK_N_Object_Renaming_Declaration (N : Node_Id) is
kono
parents:
diff changeset
348 CFS : constant Boolean := Comes_From_Source (N);
kono
parents:
diff changeset
349 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
350 Obj_Id : constant Entity_Id := Defining_Entity (N);
kono
parents:
diff changeset
351 Nam : constant Node_Id := Name (N);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
352 Typ : constant Entity_Id := Etype (Obj_Id);
111
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 begin
kono
parents:
diff changeset
355 -- Transform a renaming of the form
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 -- Obj_Id : <subtype mark> renames <function call>;
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 -- into
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 -- Obj_Id : constant <subtype mark> := <function call>;
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 -- Invoking Evaluate_Name and ultimately Remove_Side_Effects introduces
kono
parents:
diff changeset
364 -- a temporary to capture the function result. Once potential renamings
kono
parents:
diff changeset
365 -- are rewritten for SPARK, the temporary may be leaked out into source
kono
parents:
diff changeset
366 -- constructs and lead to confusing error diagnostics. Using an object
kono
parents:
diff changeset
367 -- declaration prevents this unwanted side effect.
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 if Nkind (Nam) = N_Function_Call then
kono
parents:
diff changeset
370 Rewrite (N,
kono
parents:
diff changeset
371 Make_Object_Declaration (Loc,
kono
parents:
diff changeset
372 Defining_Identifier => Obj_Id,
kono
parents:
diff changeset
373 Constant_Present => True,
kono
parents:
diff changeset
374 Object_Definition => New_Occurrence_Of (Typ, Loc),
kono
parents:
diff changeset
375 Expression => Nam));
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 -- Inherit the original Comes_From_Source status of the renaming
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 Set_Comes_From_Source (N, CFS);
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381 -- Sever the link to the renamed function result because the entity
kono
parents:
diff changeset
382 -- will no longer alias anything.
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 Set_Renamed_Object (Obj_Id, Empty);
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 -- Remove the entity of the renaming declaration from visibility as
kono
parents:
diff changeset
387 -- the analysis of the object declaration will reintroduce it again.
kono
parents:
diff changeset
388
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
389 Remove_Entity_And_Homonym (Obj_Id);
111
kono
parents:
diff changeset
390 Analyze (N);
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 -- Otherwise unconditionally remove all side effects from the name
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 else
kono
parents:
diff changeset
395 Evaluate_Name (Nam);
kono
parents:
diff changeset
396 end if;
kono
parents:
diff changeset
397 end Expand_SPARK_N_Object_Renaming_Declaration;
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 --------------------------
kono
parents:
diff changeset
400 -- Expand_SPARK_N_Op_Ne --
kono
parents:
diff changeset
401 --------------------------
kono
parents:
diff changeset
402
kono
parents:
diff changeset
403 procedure Expand_SPARK_N_Op_Ne (N : Node_Id) is
kono
parents:
diff changeset
404 Typ : constant Entity_Id := Etype (Left_Opnd (N));
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 begin
kono
parents:
diff changeset
407 -- Case of elementary type with standard operator
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 if Is_Elementary_Type (Typ)
kono
parents:
diff changeset
410 and then Sloc (Entity (N)) = Standard_Location
kono
parents:
diff changeset
411 then
kono
parents:
diff changeset
412 null;
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 else
kono
parents:
diff changeset
415 Exp_Ch4.Expand_N_Op_Ne (N);
kono
parents:
diff changeset
416 end if;
kono
parents:
diff changeset
417 end Expand_SPARK_N_Op_Ne;
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 -------------------------------------
kono
parents:
diff changeset
420 -- Expand_SPARK_Potential_Renaming --
kono
parents:
diff changeset
421 -------------------------------------
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 procedure Expand_SPARK_Potential_Renaming (N : Node_Id) is
kono
parents:
diff changeset
424 function In_Insignificant_Pragma (Nod : Node_Id) return Boolean;
kono
parents:
diff changeset
425 -- Determine whether arbitrary node Nod appears within a significant
kono
parents:
diff changeset
426 -- pragma for SPARK.
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 -----------------------------
kono
parents:
diff changeset
429 -- In_Insignificant_Pragma --
kono
parents:
diff changeset
430 -----------------------------
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 function In_Insignificant_Pragma (Nod : Node_Id) return Boolean is
kono
parents:
diff changeset
433 Par : Node_Id;
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 begin
kono
parents:
diff changeset
436 -- Climb the parent chain looking for an enclosing pragma
kono
parents:
diff changeset
437
kono
parents:
diff changeset
438 Par := Nod;
kono
parents:
diff changeset
439 while Present (Par) loop
kono
parents:
diff changeset
440 if Nkind (Par) = N_Pragma then
kono
parents:
diff changeset
441 return not Pragma_Significant_In_SPARK (Get_Pragma_Id (Par));
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 -- Prevent the search from going too far
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 elsif Is_Body_Or_Package_Declaration (Par) then
kono
parents:
diff changeset
446 exit;
kono
parents:
diff changeset
447 end if;
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 Par := Parent (Par);
kono
parents:
diff changeset
450 end loop;
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452 return False;
kono
parents:
diff changeset
453 end In_Insignificant_Pragma;
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 -- Local variables
kono
parents:
diff changeset
456
kono
parents:
diff changeset
457 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
458 Obj_Id : constant Entity_Id := Entity (N);
kono
parents:
diff changeset
459 Typ : constant Entity_Id := Etype (N);
kono
parents:
diff changeset
460 Ren : Node_Id;
kono
parents:
diff changeset
461
kono
parents:
diff changeset
462 -- Start of processing for Expand_SPARK_Potential_Renaming
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 begin
kono
parents:
diff changeset
465 -- Replace a reference to a renaming with the actual renamed object
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 if Ekind (Obj_Id) in Object_Kind then
kono
parents:
diff changeset
468 Ren := Renamed_Object (Obj_Id);
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 if Present (Ren) then
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 -- Do not process a reference when it appears within a pragma of
kono
parents:
diff changeset
473 -- no significance to SPARK. It is assumed that the replacement
kono
parents:
diff changeset
474 -- will violate the semantics of the pragma and cause a spurious
kono
parents:
diff changeset
475 -- error.
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 if In_Insignificant_Pragma (N) then
kono
parents:
diff changeset
478 return;
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 -- Instantiations and inlining of subprograms employ "prologues"
kono
parents:
diff changeset
481 -- which map actual to formal parameters by means of renamings.
kono
parents:
diff changeset
482 -- Replace a reference to a formal by the corresponding actual
kono
parents:
diff changeset
483 -- parameter.
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 elsif Nkind (Ren) in N_Entity then
kono
parents:
diff changeset
486 Rewrite (N, New_Occurrence_Of (Ren, Loc));
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 -- Otherwise the renamed object denotes a name
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 else
kono
parents:
diff changeset
491 Rewrite (N, New_Copy_Tree (Ren, New_Sloc => Loc));
kono
parents:
diff changeset
492 Reset_Analyzed_Flags (N);
kono
parents:
diff changeset
493 end if;
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 Analyze_And_Resolve (N, Typ);
kono
parents:
diff changeset
496 end if;
kono
parents:
diff changeset
497 end if;
kono
parents:
diff changeset
498 end Expand_SPARK_Potential_Renaming;
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 ---------------------------------------
kono
parents:
diff changeset
501 -- Expand_SPARK_N_Selected_Component --
kono
parents:
diff changeset
502 ---------------------------------------
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 procedure Expand_SPARK_N_Selected_Component (N : Node_Id) is
kono
parents:
diff changeset
505 Pref : constant Node_Id := Prefix (N);
kono
parents:
diff changeset
506 Typ : constant Entity_Id := Underlying_Type (Etype (Pref));
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 begin
kono
parents:
diff changeset
509 if Present (Typ) and then Is_Access_Type (Typ) then
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 -- First set prefix type to proper access type, in case it currently
kono
parents:
diff changeset
512 -- has a private (non-access) view of this type.
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 Set_Etype (Pref, Typ);
kono
parents:
diff changeset
515
kono
parents:
diff changeset
516 Insert_Explicit_Dereference (Pref);
kono
parents:
diff changeset
517 Analyze_And_Resolve (Pref, Designated_Type (Typ));
kono
parents:
diff changeset
518
kono
parents:
diff changeset
519 if Ekind (Etype (Pref)) = E_Private_Subtype
kono
parents:
diff changeset
520 and then Is_For_Access_Subtype (Etype (Pref))
kono
parents:
diff changeset
521 then
kono
parents:
diff changeset
522 Set_Etype (Pref, Base_Type (Etype (Pref)));
kono
parents:
diff changeset
523 end if;
kono
parents:
diff changeset
524 end if;
kono
parents:
diff changeset
525 end Expand_SPARK_N_Selected_Component;
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 end Exp_SPARK;