]>
Commit | Line | Data |
---|---|---|
415dddc8 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- T B U I L D -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
bc0b26b9 | 9 | -- Copyright (C) 1992-2022, Free Software Foundation, Inc. -- |
415dddc8 RK |
10 | -- -- |
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- -- | |
b5c84c3c | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
415dddc8 RK |
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 -- | |
b5c84c3c RD |
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. -- | |
415dddc8 RK |
20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
415dddc8 RK |
23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
104f58db BD |
26 | with Atree; use Atree; |
27 | with Aspects; use Aspects; | |
28 | with Csets; use Csets; | |
29 | with Einfo; use Einfo; | |
76f9c7f4 | 30 | with Einfo.Entities; use Einfo.Entities; |
104f58db | 31 | with Einfo.Utils; use Einfo.Utils; |
104f58db BD |
32 | with Lib; use Lib; |
33 | with Nlists; use Nlists; | |
34 | with Nmake; use Nmake; | |
35 | with Opt; use Opt; | |
36 | with Restrict; use Restrict; | |
37 | with Rident; use Rident; | |
104f58db BD |
38 | with Sinfo.Utils; use Sinfo.Utils; |
39 | with Sem_Util; use Sem_Util; | |
40 | with Snames; use Snames; | |
41 | with Stand; use Stand; | |
42 | with Stringt; use Stringt; | |
43 | with Urealp; use Urealp; | |
415dddc8 RK |
44 | |
45 | package body Tbuild is | |
46 | ||
47 | ----------------------- | |
48 | -- Local Subprograms -- | |
49 | ----------------------- | |
50 | ||
51 | procedure Add_Unique_Serial_Number; | |
52 | -- Add a unique serialization to the string in the Name_Buffer. This | |
53 | -- consists of a unit specific serial number, and b/s for body/spec. | |
54 | ||
55 | ------------------------------ | |
56 | -- Add_Unique_Serial_Number -- | |
57 | ------------------------------ | |
58 | ||
baa3441d RD |
59 | Config_Serial_Number : Nat := 0; |
60 | -- Counter for use in config pragmas, see comment below | |
415dddc8 | 61 | |
baa3441d | 62 | procedure Add_Unique_Serial_Number is |
415dddc8 | 63 | begin |
baa3441d RD |
64 | -- If we are analyzing configuration pragmas, Cunit (Main_Unit) will |
65 | -- not be set yet. This happens for example when analyzing static | |
66 | -- string expressions in configuration pragmas. For this case, we | |
67 | -- just maintain a local counter, defined above and we do not need | |
68 | -- to add a b or s indication in this case. | |
415dddc8 | 69 | |
baa3441d RD |
70 | if No (Cunit (Current_Sem_Unit)) then |
71 | Config_Serial_Number := Config_Serial_Number + 1; | |
72 | Add_Nat_To_Name_Buffer (Config_Serial_Number); | |
73 | return; | |
415dddc8 | 74 | |
baa3441d | 75 | -- Normal case, within a unit |
415dddc8 | 76 | |
415dddc8 | 77 | else |
baa3441d RD |
78 | declare |
79 | Unit_Node : constant Node_Id := Unit (Cunit (Current_Sem_Unit)); | |
80 | ||
81 | begin | |
82 | Add_Nat_To_Name_Buffer (Increment_Serial_Number); | |
83 | ||
84 | -- Add either b or s, depending on whether current unit is a spec | |
85 | -- or a body. This is needed because we may generate the same name | |
86 | -- in a spec and a body otherwise. | |
87 | ||
88 | Name_Len := Name_Len + 1; | |
89 | ||
90 | if Nkind (Unit_Node) = N_Package_Declaration | |
91 | or else Nkind (Unit_Node) = N_Subprogram_Declaration | |
92 | or else Nkind (Unit_Node) in N_Generic_Declaration | |
93 | then | |
94 | Name_Buffer (Name_Len) := 's'; | |
95 | else | |
96 | Name_Buffer (Name_Len) := 'b'; | |
97 | end if; | |
98 | end; | |
415dddc8 RK |
99 | end if; |
100 | end Add_Unique_Serial_Number; | |
101 | ||
102 | ---------------- | |
103 | -- Checks_Off -- | |
104 | ---------------- | |
105 | ||
106 | function Checks_Off (N : Node_Id) return Node_Id is | |
107 | begin | |
108 | return | |
109 | Make_Unchecked_Expression (Sloc (N), | |
110 | Expression => N); | |
111 | end Checks_Off; | |
112 | ||
113 | ---------------- | |
114 | -- Convert_To -- | |
115 | ---------------- | |
116 | ||
117 | function Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id is | |
82a79441 | 118 | pragma Assert (Is_Type (Typ)); |
415dddc8 RK |
119 | Result : Node_Id; |
120 | ||
121 | begin | |
445514c0 | 122 | if Present (Etype (Expr)) and then Etype (Expr) = Typ then |
415dddc8 | 123 | return Relocate_Node (Expr); |
445514c0 | 124 | |
415dddc8 RK |
125 | else |
126 | Result := | |
127 | Make_Type_Conversion (Sloc (Expr), | |
128 | Subtype_Mark => New_Occurrence_Of (Typ, Sloc (Expr)), | |
129 | Expression => Relocate_Node (Expr)); | |
130 | ||
131 | Set_Etype (Result, Typ); | |
132 | return Result; | |
133 | end if; | |
134 | end Convert_To; | |
135 | ||
acad3c0a AC |
136 | ---------------------------- |
137 | -- Convert_To_And_Rewrite -- | |
138 | ---------------------------- | |
139 | ||
140 | procedure Convert_To_And_Rewrite (Typ : Entity_Id; Expr : Node_Id) is | |
141 | begin | |
142 | Rewrite (Expr, Convert_To (Typ, Expr)); | |
143 | end Convert_To_And_Rewrite; | |
144 | ||
fbf5a39b AC |
145 | ------------------ |
146 | -- Discard_List -- | |
147 | ------------------ | |
148 | ||
149 | procedure Discard_List (L : List_Id) is | |
150 | pragma Warnings (Off, L); | |
fbf5a39b AC |
151 | begin |
152 | null; | |
153 | end Discard_List; | |
154 | ||
155 | ------------------ | |
156 | -- Discard_Node -- | |
157 | ------------------ | |
158 | ||
159 | procedure Discard_Node (N : Node_Or_Entity_Id) is | |
160 | pragma Warnings (Off, N); | |
fbf5a39b AC |
161 | begin |
162 | null; | |
163 | end Discard_Node; | |
164 | ||
07fc65c4 GB |
165 | ------------------------------------------- |
166 | -- Make_Byte_Aligned_Attribute_Reference -- | |
167 | ------------------------------------------- | |
168 | ||
169 | function Make_Byte_Aligned_Attribute_Reference | |
170 | (Sloc : Source_Ptr; | |
171 | Prefix : Node_Id; | |
172 | Attribute_Name : Name_Id) | |
173 | return Node_Id | |
174 | is | |
175 | N : constant Node_Id := | |
176 | Make_Attribute_Reference (Sloc, | |
177 | Prefix => Prefix, | |
178 | Attribute_Name => Attribute_Name); | |
179 | ||
180 | begin | |
4a08c95c AC |
181 | pragma Assert |
182 | (Attribute_Name in Name_Address | Name_Unrestricted_Access); | |
07fc65c4 GB |
183 | Set_Must_Be_Byte_Aligned (N, True); |
184 | return N; | |
185 | end Make_Byte_Aligned_Attribute_Reference; | |
186 | ||
d32e3cee GB |
187 | ------------------------ |
188 | -- Make_Float_Literal -- | |
189 | ------------------------ | |
190 | ||
191 | function Make_Float_Literal | |
192 | (Loc : Source_Ptr; | |
193 | Radix : Uint; | |
194 | Significand : Uint; | |
195 | Exponent : Uint) return Node_Id | |
196 | is | |
197 | begin | |
198 | if Radix = 2 and then abs Significand /= 1 then | |
199 | return | |
200 | Make_Float_Literal | |
201 | (Loc, Uint_16, | |
202 | Significand * Radix**(Exponent mod 4), | |
203 | Exponent / 4); | |
204 | ||
205 | else | |
206 | declare | |
207 | N : constant Node_Id := New_Node (N_Real_Literal, Loc); | |
208 | ||
209 | begin | |
210 | Set_Realval (N, | |
211 | UR_From_Components | |
212 | (Num => abs Significand, | |
213 | Den => -Exponent, | |
214 | Rbase => UI_To_Int (Radix), | |
215 | Negative => Significand < 0)); | |
216 | return N; | |
217 | end; | |
218 | end if; | |
219 | end Make_Float_Literal; | |
220 | ||
5af638c8 AC |
221 | ------------- |
222 | -- Make_Id -- | |
223 | ------------- | |
224 | ||
225 | function Make_Id (Str : Text_Buffer) return Node_Id is | |
226 | begin | |
227 | Name_Len := 0; | |
228 | ||
229 | for J in Str'Range loop | |
230 | Name_Len := Name_Len + 1; | |
231 | Name_Buffer (Name_Len) := Fold_Lower (Str (J)); | |
232 | end loop; | |
233 | ||
234 | return | |
235 | Make_Identifier (System_Location, | |
236 | Chars => Name_Find); | |
237 | end Make_Id; | |
238 | ||
baa3441d RD |
239 | ------------------------------------- |
240 | -- Make_Implicit_Exception_Handler -- | |
241 | ------------------------------------- | |
242 | ||
243 | function Make_Implicit_Exception_Handler | |
244 | (Sloc : Source_Ptr; | |
245 | Choice_Parameter : Node_Id := Empty; | |
246 | Exception_Choices : List_Id; | |
247 | Statements : List_Id) return Node_Id | |
248 | is | |
a99ada67 RD |
249 | Handler : Node_Id; |
250 | Loc : Source_Ptr; | |
251 | ||
baa3441d | 252 | begin |
a99ada67 RD |
253 | -- Set the source location only when debugging the expanded code |
254 | ||
255 | -- When debugging the source code directly, we do not want the compiler | |
256 | -- to associate this implicit exception handler with any specific source | |
257 | -- line, because it can potentially confuse the debugger. The most | |
258 | -- damaging situation would arise when the debugger tries to insert a | |
259 | -- breakpoint at a certain line. If the code of the associated implicit | |
260 | -- exception handler is generated before the code of that line, then the | |
261 | -- debugger will end up inserting the breakpoint inside the exception | |
262 | -- handler, rather than the code the user intended to break on. As a | |
263 | -- result, it is likely that the program will not hit the breakpoint | |
264 | -- as expected. | |
265 | ||
266 | if Debug_Generated_Code then | |
267 | Loc := Sloc; | |
268 | else | |
269 | Loc := No_Location; | |
270 | end if; | |
271 | ||
272 | Handler := | |
273 | Make_Exception_Handler | |
274 | (Loc, Choice_Parameter, Exception_Choices, Statements); | |
baa3441d RD |
275 | Set_Local_Raise_Statements (Handler, No_Elist); |
276 | return Handler; | |
277 | end Make_Implicit_Exception_Handler; | |
278 | ||
415dddc8 RK |
279 | -------------------------------- |
280 | -- Make_Implicit_If_Statement -- | |
281 | -------------------------------- | |
282 | ||
283 | function Make_Implicit_If_Statement | |
284 | (Node : Node_Id; | |
285 | Condition : Node_Id; | |
286 | Then_Statements : List_Id; | |
287 | Elsif_Parts : List_Id := No_List; | |
30c20106 | 288 | Else_Statements : List_Id := No_List) return Node_Id |
415dddc8 RK |
289 | is |
290 | begin | |
291 | Check_Restriction (No_Implicit_Conditionals, Node); | |
a9d8907c | 292 | |
415dddc8 RK |
293 | return Make_If_Statement (Sloc (Node), |
294 | Condition, | |
295 | Then_Statements, | |
296 | Elsif_Parts, | |
297 | Else_Statements); | |
298 | end Make_Implicit_If_Statement; | |
299 | ||
300 | ------------------------------------- | |
301 | -- Make_Implicit_Label_Declaration -- | |
302 | ------------------------------------- | |
303 | ||
304 | function Make_Implicit_Label_Declaration | |
305 | (Loc : Source_Ptr; | |
306 | Defining_Identifier : Node_Id; | |
30c20106 | 307 | Label_Construct : Node_Id) return Node_Id |
415dddc8 RK |
308 | is |
309 | N : constant Node_Id := | |
310 | Make_Implicit_Label_Declaration (Loc, Defining_Identifier); | |
415dddc8 RK |
311 | begin |
312 | Set_Label_Construct (N, Label_Construct); | |
313 | return N; | |
314 | end Make_Implicit_Label_Declaration; | |
315 | ||
316 | ---------------------------------- | |
317 | -- Make_Implicit_Loop_Statement -- | |
318 | ---------------------------------- | |
319 | ||
320 | function Make_Implicit_Loop_Statement | |
321 | (Node : Node_Id; | |
322 | Statements : List_Id; | |
323 | Identifier : Node_Id := Empty; | |
324 | Iteration_Scheme : Node_Id := Empty; | |
325 | Has_Created_Identifier : Boolean := False; | |
30c20106 | 326 | End_Label : Node_Id := Empty) return Node_Id |
415dddc8 | 327 | is |
56adf813 AC |
328 | P : Node_Id; |
329 | Check_Restrictions : Boolean := True; | |
415dddc8 | 330 | begin |
56adf813 AC |
331 | -- Do not check restrictions if the implicit loop statement is part |
332 | -- of a dead branch: False and then ... | |
333 | -- This will occur in particular as part of the expansion of pragma | |
334 | -- Assert when assertions are disabled. | |
335 | ||
336 | P := Parent (Node); | |
337 | while Present (P) loop | |
338 | if Nkind (P) = N_And_Then then | |
339 | if Nkind (Left_Opnd (P)) = N_Identifier | |
340 | and then Entity (Left_Opnd (P)) = Standard_False | |
341 | then | |
342 | Check_Restrictions := False; | |
343 | exit; | |
344 | end if; | |
345 | ||
346 | -- Prevent the search from going too far | |
347 | ||
348 | elsif Is_Body_Or_Package_Declaration (P) then | |
349 | exit; | |
350 | end if; | |
351 | ||
352 | P := Parent (P); | |
353 | end loop; | |
354 | ||
355 | if Check_Restrictions then | |
356 | Check_Restriction (No_Implicit_Loops, Node); | |
415dddc8 | 357 | |
56adf813 AC |
358 | if Present (Iteration_Scheme) |
359 | and then Nkind (Iteration_Scheme) /= N_Iterator_Specification | |
360 | and then Present (Condition (Iteration_Scheme)) | |
361 | then | |
362 | Check_Restriction (No_Implicit_Conditionals, Node); | |
363 | end if; | |
415dddc8 RK |
364 | end if; |
365 | ||
366 | return Make_Loop_Statement (Sloc (Node), | |
367 | Identifier => Identifier, | |
368 | Iteration_Scheme => Iteration_Scheme, | |
369 | Statements => Statements, | |
370 | Has_Created_Identifier => Has_Created_Identifier, | |
371 | End_Label => End_Label); | |
372 | end Make_Implicit_Loop_Statement; | |
373 | ||
110d0820 BD |
374 | -------------------- |
375 | -- Make_Increment -- | |
376 | -------------------- | |
377 | ||
378 | function Make_Increment | |
379 | (Loc : Source_Ptr; Index : Entity_Id; Typ : Entity_Id) return Node_Id is | |
380 | begin | |
381 | return Make_Assignment_Statement (Loc, | |
382 | Name => New_Occurrence_Of (Index, Loc), | |
383 | Expression => | |
384 | Make_Attribute_Reference (Loc, | |
385 | Prefix => | |
386 | New_Occurrence_Of (Typ, Loc), | |
387 | Attribute_Name => Name_Succ, | |
388 | Expressions => New_List ( | |
389 | New_Occurrence_Of (Index, Loc)))); | |
390 | end Make_Increment; | |
391 | ||
415dddc8 RK |
392 | -------------------------- |
393 | -- Make_Integer_Literal -- | |
394 | --------------------------- | |
395 | ||
396 | function Make_Integer_Literal | |
397 | (Loc : Source_Ptr; | |
30c20106 | 398 | Intval : Int) return Node_Id |
415dddc8 RK |
399 | is |
400 | begin | |
401 | return Make_Integer_Literal (Loc, UI_From_Int (Intval)); | |
402 | end Make_Integer_Literal; | |
403 | ||
59e5fbe0 RD |
404 | -------------------------------- |
405 | -- Make_Linker_Section_Pragma -- | |
406 | -------------------------------- | |
407 | ||
408 | function Make_Linker_Section_Pragma | |
409 | (Ent : Entity_Id; | |
410 | Loc : Source_Ptr; | |
411 | Sec : String) return Node_Id | |
412 | is | |
413 | LS : Node_Id; | |
414 | ||
415 | begin | |
416 | LS := | |
417 | Make_Pragma | |
418 | (Loc, | |
419 | Name_Linker_Section, | |
420 | New_List | |
421 | (Make_Pragma_Argument_Association | |
422 | (Sloc => Loc, | |
423 | Expression => New_Occurrence_Of (Ent, Loc)), | |
424 | Make_Pragma_Argument_Association | |
425 | (Sloc => Loc, | |
426 | Expression => | |
427 | Make_String_Literal | |
428 | (Sloc => Loc, | |
429 | Strval => Sec)))); | |
430 | ||
431 | Set_Has_Gigi_Rep_Item (Ent); | |
432 | return LS; | |
433 | end Make_Linker_Section_Pragma; | |
434 | ||
c1e0259c RD |
435 | ----------------- |
436 | -- Make_Pragma -- | |
437 | ----------------- | |
438 | ||
439 | function Make_Pragma | |
440 | (Sloc : Source_Ptr; | |
441 | Chars : Name_Id; | |
7ab4d95a | 442 | Pragma_Argument_Associations : List_Id := No_List) return Node_Id |
c1e0259c RD |
443 | is |
444 | begin | |
445 | return | |
446 | Make_Pragma (Sloc, | |
c1e0259c | 447 | Pragma_Argument_Associations => Pragma_Argument_Associations, |
c1e0259c RD |
448 | Pragma_Identifier => Make_Identifier (Sloc, Chars)); |
449 | end Make_Pragma; | |
450 | ||
07fc65c4 GB |
451 | --------------------------------- |
452 | -- Make_Raise_Constraint_Error -- | |
453 | --------------------------------- | |
454 | ||
455 | function Make_Raise_Constraint_Error | |
456 | (Sloc : Source_Ptr; | |
457 | Condition : Node_Id := Empty; | |
30c20106 | 458 | Reason : RT_Exception_Code) return Node_Id |
07fc65c4 GB |
459 | is |
460 | begin | |
a2cc9797 | 461 | pragma Assert (Rkind (Reason) = CE_Reason); |
07fc65c4 GB |
462 | return |
463 | Make_Raise_Constraint_Error (Sloc, | |
464 | Condition => Condition, | |
edab6088 | 465 | Reason => UI_From_Int (RT_Exception_Code'Pos (Reason))); |
07fc65c4 GB |
466 | end Make_Raise_Constraint_Error; |
467 | ||
468 | ------------------------------ | |
469 | -- Make_Raise_Program_Error -- | |
470 | ------------------------------ | |
471 | ||
472 | function Make_Raise_Program_Error | |
473 | (Sloc : Source_Ptr; | |
474 | Condition : Node_Id := Empty; | |
30c20106 | 475 | Reason : RT_Exception_Code) return Node_Id |
07fc65c4 GB |
476 | is |
477 | begin | |
a2cc9797 | 478 | pragma Assert (Rkind (Reason) = PE_Reason); |
07fc65c4 GB |
479 | return |
480 | Make_Raise_Program_Error (Sloc, | |
481 | Condition => Condition, | |
edab6088 | 482 | Reason => UI_From_Int (RT_Exception_Code'Pos (Reason))); |
07fc65c4 GB |
483 | end Make_Raise_Program_Error; |
484 | ||
485 | ------------------------------ | |
486 | -- Make_Raise_Storage_Error -- | |
487 | ------------------------------ | |
488 | ||
489 | function Make_Raise_Storage_Error | |
490 | (Sloc : Source_Ptr; | |
491 | Condition : Node_Id := Empty; | |
30c20106 | 492 | Reason : RT_Exception_Code) return Node_Id |
07fc65c4 GB |
493 | is |
494 | begin | |
a2cc9797 | 495 | pragma Assert (Rkind (Reason) = SE_Reason); |
07fc65c4 GB |
496 | return |
497 | Make_Raise_Storage_Error (Sloc, | |
498 | Condition => Condition, | |
edab6088 | 499 | Reason => UI_From_Int (RT_Exception_Code'Pos (Reason))); |
07fc65c4 GB |
500 | end Make_Raise_Storage_Error; |
501 | ||
5af638c8 AC |
502 | ------------- |
503 | -- Make_SC -- | |
504 | ------------- | |
505 | ||
506 | function Make_SC (Pre, Sel : Node_Id) return Node_Id is | |
507 | begin | |
508 | return | |
509 | Make_Selected_Component (System_Location, | |
510 | Prefix => Pre, | |
511 | Selector_Name => Sel); | |
512 | end Make_SC; | |
513 | ||
1d571f3b AC |
514 | ------------------------- |
515 | -- Make_String_Literal -- | |
516 | ------------------------- | |
517 | ||
518 | function Make_String_Literal | |
519 | (Sloc : Source_Ptr; | |
520 | Strval : String) return Node_Id | |
521 | is | |
522 | begin | |
523 | Start_String; | |
524 | Store_String_Chars (Strval); | |
edab6088 | 525 | return Make_String_Literal (Sloc, Strval => End_String); |
1d571f3b AC |
526 | end Make_String_Literal; |
527 | ||
124e3829 RD |
528 | -------------------- |
529 | -- Make_Temporary -- | |
530 | -------------------- | |
531 | ||
ae525aa8 | 532 | function Make_Temporary |
124e3829 | 533 | (Loc : Source_Ptr; |
faf387e1 | 534 | Id : Character; |
191fcb3a | 535 | Related_Node : Node_Id := Empty) return Entity_Id |
ae525aa8 | 536 | is |
191fcb3a | 537 | Temp : constant Entity_Id := |
edab6088 | 538 | Make_Defining_Identifier (Loc, Chars => New_Internal_Name (Id)); |
ae525aa8 | 539 | begin |
ae525aa8 ES |
540 | Set_Related_Expression (Temp, Related_Node); |
541 | return Temp; | |
542 | end Make_Temporary; | |
543 | ||
415dddc8 RK |
544 | --------------------------- |
545 | -- Make_Unsuppress_Block -- | |
546 | --------------------------- | |
547 | ||
548 | -- Generates the following expansion: | |
549 | ||
550 | -- declare | |
551 | -- pragma Suppress (<check>); | |
552 | -- begin | |
553 | -- <stmts> | |
554 | -- end; | |
555 | ||
556 | function Make_Unsuppress_Block | |
557 | (Loc : Source_Ptr; | |
558 | Check : Name_Id; | |
30c20106 | 559 | Stmts : List_Id) return Node_Id |
415dddc8 RK |
560 | is |
561 | begin | |
562 | return | |
563 | Make_Block_Statement (Loc, | |
564 | Declarations => New_List ( | |
565 | Make_Pragma (Loc, | |
566 | Chars => Name_Suppress, | |
567 | Pragma_Argument_Associations => New_List ( | |
568 | Make_Pragma_Argument_Association (Loc, | |
569 | Expression => Make_Identifier (Loc, Check))))), | |
570 | ||
571 | Handled_Statement_Sequence => | |
572 | Make_Handled_Sequence_Of_Statements (Loc, | |
573 | Statements => Stmts)); | |
574 | end Make_Unsuppress_Block; | |
575 | ||
576 | -------------------------- | |
577 | -- New_Constraint_Error -- | |
578 | -------------------------- | |
579 | ||
580 | function New_Constraint_Error (Loc : Source_Ptr) return Node_Id is | |
581 | Ident_Node : Node_Id; | |
582 | Raise_Node : Node_Id; | |
583 | ||
584 | begin | |
585 | Ident_Node := New_Node (N_Identifier, Loc); | |
586 | Set_Chars (Ident_Node, Chars (Standard_Entity (S_Constraint_Error))); | |
587 | Set_Entity (Ident_Node, Standard_Entity (S_Constraint_Error)); | |
588 | Raise_Node := New_Node (N_Raise_Statement, Loc); | |
589 | Set_Name (Raise_Node, Ident_Node); | |
590 | return Raise_Node; | |
591 | end New_Constraint_Error; | |
592 | ||
593 | ----------------------- | |
594 | -- New_External_Name -- | |
595 | ----------------------- | |
596 | ||
597 | function New_External_Name | |
598 | (Related_Id : Name_Id; | |
599 | Suffix : Character := ' '; | |
600 | Suffix_Index : Int := 0; | |
30c20106 | 601 | Prefix : Character := ' ') return Name_Id |
415dddc8 RK |
602 | is |
603 | begin | |
604 | Get_Name_String (Related_Id); | |
605 | ||
606 | if Prefix /= ' ' then | |
54838d1f | 607 | pragma Assert (Is_OK_Internal_Letter (Prefix) or else Prefix = '_'); |
415dddc8 RK |
608 | |
609 | for J in reverse 1 .. Name_Len loop | |
610 | Name_Buffer (J + 1) := Name_Buffer (J); | |
611 | end loop; | |
612 | ||
613 | Name_Len := Name_Len + 1; | |
614 | Name_Buffer (1) := Prefix; | |
615 | end if; | |
616 | ||
617 | if Suffix /= ' ' then | |
618 | pragma Assert (Is_OK_Internal_Letter (Suffix)); | |
dae4faf2 | 619 | Add_Char_To_Name_Buffer (Suffix); |
415dddc8 RK |
620 | end if; |
621 | ||
622 | if Suffix_Index /= 0 then | |
623 | if Suffix_Index < 0 then | |
624 | Add_Unique_Serial_Number; | |
625 | else | |
626 | Add_Nat_To_Name_Buffer (Suffix_Index); | |
627 | end if; | |
628 | end if; | |
629 | ||
630 | return Name_Find; | |
631 | end New_External_Name; | |
632 | ||
633 | function New_External_Name | |
634 | (Related_Id : Name_Id; | |
635 | Suffix : String; | |
636 | Suffix_Index : Int := 0; | |
30c20106 | 637 | Prefix : Character := ' ') return Name_Id |
415dddc8 RK |
638 | is |
639 | begin | |
640 | Get_Name_String (Related_Id); | |
641 | ||
642 | if Prefix /= ' ' then | |
643 | pragma Assert (Is_OK_Internal_Letter (Prefix)); | |
644 | ||
645 | for J in reverse 1 .. Name_Len loop | |
646 | Name_Buffer (J + 1) := Name_Buffer (J); | |
647 | end loop; | |
648 | ||
649 | Name_Len := Name_Len + 1; | |
650 | Name_Buffer (1) := Prefix; | |
651 | end if; | |
652 | ||
653 | if Suffix /= "" then | |
654 | Name_Buffer (Name_Len + 1 .. Name_Len + Suffix'Length) := Suffix; | |
655 | Name_Len := Name_Len + Suffix'Length; | |
656 | end if; | |
657 | ||
658 | if Suffix_Index /= 0 then | |
659 | if Suffix_Index < 0 then | |
660 | Add_Unique_Serial_Number; | |
661 | else | |
662 | Add_Nat_To_Name_Buffer (Suffix_Index); | |
663 | end if; | |
664 | end if; | |
665 | ||
666 | return Name_Find; | |
667 | end New_External_Name; | |
668 | ||
669 | function New_External_Name | |
670 | (Suffix : Character; | |
30c20106 | 671 | Suffix_Index : Nat) return Name_Id |
415dddc8 RK |
672 | is |
673 | begin | |
674 | Name_Buffer (1) := Suffix; | |
675 | Name_Len := 1; | |
676 | Add_Nat_To_Name_Buffer (Suffix_Index); | |
677 | return Name_Find; | |
678 | end New_External_Name; | |
679 | ||
680 | ----------------------- | |
681 | -- New_Internal_Name -- | |
682 | ----------------------- | |
683 | ||
684 | function New_Internal_Name (Id_Char : Character) return Name_Id is | |
685 | begin | |
686 | pragma Assert (Is_OK_Internal_Letter (Id_Char)); | |
687 | Name_Buffer (1) := Id_Char; | |
688 | Name_Len := 1; | |
689 | Add_Unique_Serial_Number; | |
690 | return Name_Enter; | |
691 | end New_Internal_Name; | |
692 | ||
693 | ----------------------- | |
694 | -- New_Occurrence_Of -- | |
695 | ----------------------- | |
696 | ||
697 | function New_Occurrence_Of | |
698 | (Def_Id : Entity_Id; | |
30c20106 | 699 | Loc : Source_Ptr) return Node_Id |
415dddc8 | 700 | is |
47fb6ca8 | 701 | pragma Assert (Present (Def_Id) and then Nkind (Def_Id) in N_Entity); |
e93e5544 PT |
702 | Occurrence : constant Node_Id := |
703 | Make_Identifier (Loc, Chars (Def_Id)); | |
415dddc8 RK |
704 | |
705 | begin | |
415dddc8 RK |
706 | Set_Entity (Occurrence, Def_Id); |
707 | ||
708 | if Is_Type (Def_Id) then | |
709 | Set_Etype (Occurrence, Def_Id); | |
710 | else | |
711 | Set_Etype (Occurrence, Etype (Def_Id)); | |
712 | end if; | |
713 | ||
edab6088 RD |
714 | if Ekind (Def_Id) = E_Enumeration_Literal then |
715 | Set_Is_Static_Expression (Occurrence, True); | |
716 | end if; | |
717 | ||
415dddc8 RK |
718 | return Occurrence; |
719 | end New_Occurrence_Of; | |
720 | ||
b87971f3 AC |
721 | ----------------- |
722 | -- New_Op_Node -- | |
723 | ----------------- | |
724 | ||
725 | function New_Op_Node | |
726 | (New_Node_Kind : Node_Kind; | |
727 | New_Sloc : Source_Ptr) return Node_Id | |
728 | is | |
729 | type Name_Of_Type is array (N_Op) of Name_Id; | |
730 | Name_Of : constant Name_Of_Type := Name_Of_Type'( | |
731 | N_Op_And => Name_Op_And, | |
732 | N_Op_Or => Name_Op_Or, | |
733 | N_Op_Xor => Name_Op_Xor, | |
734 | N_Op_Eq => Name_Op_Eq, | |
735 | N_Op_Ne => Name_Op_Ne, | |
736 | N_Op_Lt => Name_Op_Lt, | |
737 | N_Op_Le => Name_Op_Le, | |
738 | N_Op_Gt => Name_Op_Gt, | |
739 | N_Op_Ge => Name_Op_Ge, | |
740 | N_Op_Add => Name_Op_Add, | |
741 | N_Op_Subtract => Name_Op_Subtract, | |
742 | N_Op_Concat => Name_Op_Concat, | |
743 | N_Op_Multiply => Name_Op_Multiply, | |
744 | N_Op_Divide => Name_Op_Divide, | |
745 | N_Op_Mod => Name_Op_Mod, | |
746 | N_Op_Rem => Name_Op_Rem, | |
747 | N_Op_Expon => Name_Op_Expon, | |
748 | N_Op_Plus => Name_Op_Add, | |
749 | N_Op_Minus => Name_Op_Subtract, | |
750 | N_Op_Abs => Name_Op_Abs, | |
751 | N_Op_Not => Name_Op_Not, | |
752 | ||
753 | -- We don't really need these shift operators, since they never | |
754 | -- appear as operators in the source, but the path of least | |
6a497607 | 755 | -- resistance is to put them in (the aggregate must be complete). |
b87971f3 AC |
756 | |
757 | N_Op_Rotate_Left => Name_Rotate_Left, | |
758 | N_Op_Rotate_Right => Name_Rotate_Right, | |
759 | N_Op_Shift_Left => Name_Shift_Left, | |
760 | N_Op_Shift_Right => Name_Shift_Right, | |
761 | N_Op_Shift_Right_Arithmetic => Name_Shift_Right_Arithmetic); | |
762 | ||
763 | Nod : constant Node_Id := New_Node (New_Node_Kind, New_Sloc); | |
69ba91ed | 764 | |
b87971f3 AC |
765 | begin |
766 | if New_Node_Kind in Name_Of'Range then | |
767 | Set_Chars (Nod, Name_Of (New_Node_Kind)); | |
768 | end if; | |
69ba91ed | 769 | |
b87971f3 AC |
770 | return Nod; |
771 | end New_Op_Node; | |
772 | ||
415dddc8 RK |
773 | ----------------------- |
774 | -- New_Suffixed_Name -- | |
775 | ----------------------- | |
776 | ||
777 | function New_Suffixed_Name | |
778 | (Related_Id : Name_Id; | |
30c20106 | 779 | Suffix : String) return Name_Id |
415dddc8 RK |
780 | is |
781 | begin | |
782 | Get_Name_String (Related_Id); | |
dae4faf2 TQ |
783 | Add_Char_To_Name_Buffer ('_'); |
784 | Add_Str_To_Name_Buffer (Suffix); | |
415dddc8 RK |
785 | return Name_Find; |
786 | end New_Suffixed_Name; | |
787 | ||
788 | ------------------- | |
789 | -- OK_Convert_To -- | |
790 | ------------------- | |
791 | ||
792 | function OK_Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id is | |
793 | Result : Node_Id; | |
415dddc8 RK |
794 | begin |
795 | Result := | |
796 | Make_Type_Conversion (Sloc (Expr), | |
797 | Subtype_Mark => New_Occurrence_Of (Typ, Sloc (Expr)), | |
798 | Expression => Relocate_Node (Expr)); | |
799 | Set_Conversion_OK (Result, True); | |
800 | Set_Etype (Result, Typ); | |
801 | return Result; | |
802 | end OK_Convert_To; | |
803 | ||
47484baa BD |
804 | -------------- |
805 | -- Sel_Comp -- | |
806 | -------------- | |
807 | ||
808 | function Sel_Comp (Pre : Node_Id; Sel : String) return Node_Id is | |
809 | begin | |
810 | return Make_Selected_Component | |
811 | (Sloc => Sloc (Pre), | |
812 | Prefix => Pre, | |
813 | Selector_Name => Make_Identifier (Sloc (Pre), Name_Find (Sel))); | |
814 | end Sel_Comp; | |
815 | ||
816 | function Sel_Comp (Pre, Sel : String; Loc : Source_Ptr) return Node_Id is | |
817 | begin | |
818 | return Sel_Comp (Make_Identifier (Loc, Name_Find (Pre)), Sel); | |
819 | end Sel_Comp; | |
820 | ||
5af638c8 | 821 | ------------- |
596b25f9 | 822 | -- Set_NOD -- |
5af638c8 AC |
823 | ------------- |
824 | ||
596b25f9 | 825 | procedure Set_NOD (Unit : Node_Id) is |
5af638c8 AC |
826 | begin |
827 | Set_Restriction_No_Dependence (Unit, Warn => False); | |
596b25f9 AC |
828 | end Set_NOD; |
829 | ||
830 | ------------- | |
831 | -- Set_NSA -- | |
832 | ------------- | |
833 | ||
834 | procedure Set_NSA (Asp : Name_Id; OK : out Boolean) is | |
835 | Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp); | |
836 | begin | |
837 | if Asp_Id = No_Aspect then | |
838 | OK := False; | |
839 | else | |
840 | OK := True; | |
841 | Set_Restriction_No_Specification_Of_Aspect (Asp_Id); | |
842 | end if; | |
843 | end Set_NSA; | |
844 | ||
845 | ------------- | |
846 | -- Set_NUA -- | |
847 | ------------- | |
848 | ||
849 | procedure Set_NUA (Attr : Name_Id; OK : out Boolean) is | |
850 | begin | |
851 | if Is_Attribute_Name (Attr) then | |
852 | OK := True; | |
853 | Set_Restriction_No_Use_Of_Attribute (Get_Attribute_Id (Attr)); | |
854 | else | |
855 | OK := False; | |
856 | end if; | |
857 | end Set_NUA; | |
858 | ||
859 | ------------- | |
860 | -- Set_NUP -- | |
861 | ------------- | |
862 | ||
863 | procedure Set_NUP (Prag : Name_Id; OK : out Boolean) is | |
864 | begin | |
865 | if Is_Pragma_Name (Prag) then | |
866 | OK := True; | |
867 | Set_Restriction_No_Use_Of_Pragma (Get_Pragma_Id (Prag)); | |
868 | else | |
869 | OK := False; | |
870 | end if; | |
871 | end Set_NUP; | |
5af638c8 | 872 | |
415dddc8 RK |
873 | -------------------------- |
874 | -- Unchecked_Convert_To -- | |
875 | -------------------------- | |
876 | ||
877 | function Unchecked_Convert_To | |
878 | (Typ : Entity_Id; | |
30c20106 | 879 | Expr : Node_Id) return Node_Id |
415dddc8 | 880 | is |
82a79441 BD |
881 | pragma Assert (Ekind (Typ) in E_Void | Type_Kind); |
882 | -- We don't really want to allow E_Void here, but existing code passes | |
883 | -- it. | |
884 | ||
405ebd74 PT |
885 | Loc : constant Source_Ptr := Sloc (Expr); |
886 | Result : Node_Id; | |
415dddc8 RK |
887 | |
888 | begin | |
889 | -- If the expression is already of the correct type, then nothing | |
82a79441 | 890 | -- to do, except for relocating the node |
415dddc8 RK |
891 | |
892 | if Present (Etype (Expr)) | |
82a79441 | 893 | and then (Base_Type (Etype (Expr)) = Typ or else Etype (Expr) = Typ) |
415dddc8 RK |
894 | then |
895 | return Relocate_Node (Expr); | |
896 | ||
82a79441 BD |
897 | -- Case where the expression is already an unchecked conversion. We |
898 | -- replace the type being converted to, to avoid creating an unchecked | |
899 | -- conversion of an unchecked conversion. Extra unchecked conversions | |
900 | -- make the .dg output less readable. We can't do this in cases | |
901 | -- involving bitfields, because the sizes might not match. The | |
902 | -- Is_Composite_Type checks avoid such cases. | |
415dddc8 RK |
903 | |
904 | elsif Nkind (Expr) = N_Unchecked_Type_Conversion | |
82a79441 BD |
905 | and then Is_Composite_Type (Etype (Expr)) |
906 | and then Is_Composite_Type (Typ) | |
415dddc8 | 907 | then |
82a79441 | 908 | Set_Subtype_Mark (Expr, New_Occurrence_Of (Typ, Loc)); |
415dddc8 RK |
909 | Result := Relocate_Node (Expr); |
910 | ||
30c20106 AC |
911 | elsif Nkind (Expr) = N_Null |
912 | and then Is_Access_Type (Typ) | |
913 | then | |
fbf5a39b AC |
914 | -- No need for a conversion |
915 | ||
916 | Result := Relocate_Node (Expr); | |
917 | ||
415dddc8 RK |
918 | -- All other cases |
919 | ||
920 | else | |
ebef9784 BD |
921 | declare |
922 | Expr_Parent : constant Node_Id := Parent (Expr); | |
923 | begin | |
924 | Result := | |
925 | Make_Unchecked_Type_Conversion (Loc, | |
926 | Subtype_Mark => New_Occurrence_Of (Typ, Loc), | |
927 | Expression => Relocate_Node (Expr)); | |
928 | Set_Parent (Result, Expr_Parent); | |
929 | end; | |
415dddc8 RK |
930 | end if; |
931 | ||
932 | Set_Etype (Result, Typ); | |
933 | return Result; | |
934 | end Unchecked_Convert_To; | |
935 | ||
936 | end Tbuild; |