1 |
706 |
jeremybenn |
------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- GNAT COMPILER COMPONENTS --
|
4 |
|
|
-- --
|
5 |
|
|
-- E X P _ P R A G --
|
6 |
|
|
-- --
|
7 |
|
|
-- B o d y --
|
8 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
|
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- --
|
13 |
|
|
-- ware Foundation; either version 3, or (at your option) any later ver- --
|
14 |
|
|
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
15 |
|
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
16 |
|
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
|
17 |
|
|
-- for more details. You should have received a copy of the GNU General --
|
18 |
|
|
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
|
19 |
|
|
-- http://www.gnu.org/licenses for a complete copy of the license. --
|
20 |
|
|
-- --
|
21 |
|
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
22 |
|
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
23 |
|
|
-- --
|
24 |
|
|
------------------------------------------------------------------------------
|
25 |
|
|
|
26 |
|
|
with Atree; use Atree;
|
27 |
|
|
with Casing; use Casing;
|
28 |
|
|
with Debug; use Debug;
|
29 |
|
|
with Einfo; use Einfo;
|
30 |
|
|
with Errout; use Errout;
|
31 |
|
|
with Exp_Ch11; use Exp_Ch11;
|
32 |
|
|
with Exp_Util; use Exp_Util;
|
33 |
|
|
with Expander; use Expander;
|
34 |
|
|
with Namet; use Namet;
|
35 |
|
|
with Nlists; use Nlists;
|
36 |
|
|
with Nmake; use Nmake;
|
37 |
|
|
with Opt; use Opt;
|
38 |
|
|
with Restrict; use Restrict;
|
39 |
|
|
with Rident; use Rident;
|
40 |
|
|
with Rtsfind; use Rtsfind;
|
41 |
|
|
with Sem; use Sem;
|
42 |
|
|
with Sem_Res; use Sem_Res;
|
43 |
|
|
with Sem_Util; use Sem_Util;
|
44 |
|
|
with Sinfo; use Sinfo;
|
45 |
|
|
with Sinput; use Sinput;
|
46 |
|
|
with Snames; use Snames;
|
47 |
|
|
with Stringt; use Stringt;
|
48 |
|
|
with Stand; use Stand;
|
49 |
|
|
with Targparm; use Targparm;
|
50 |
|
|
with Tbuild; use Tbuild;
|
51 |
|
|
with Uintp; use Uintp;
|
52 |
|
|
|
53 |
|
|
package body Exp_Prag is
|
54 |
|
|
|
55 |
|
|
-----------------------
|
56 |
|
|
-- Local Subprograms --
|
57 |
|
|
-----------------------
|
58 |
|
|
|
59 |
|
|
function Arg1 (N : Node_Id) return Node_Id;
|
60 |
|
|
function Arg2 (N : Node_Id) return Node_Id;
|
61 |
|
|
function Arg3 (N : Node_Id) return Node_Id;
|
62 |
|
|
-- Obtain specified pragma argument expression
|
63 |
|
|
|
64 |
|
|
procedure Expand_Pragma_Abort_Defer (N : Node_Id);
|
65 |
|
|
procedure Expand_Pragma_Check (N : Node_Id);
|
66 |
|
|
procedure Expand_Pragma_Common_Object (N : Node_Id);
|
67 |
|
|
procedure Expand_Pragma_Import_Or_Interface (N : Node_Id);
|
68 |
|
|
procedure Expand_Pragma_Import_Export_Exception (N : Node_Id);
|
69 |
|
|
procedure Expand_Pragma_Inspection_Point (N : Node_Id);
|
70 |
|
|
procedure Expand_Pragma_Interrupt_Priority (N : Node_Id);
|
71 |
|
|
procedure Expand_Pragma_Psect_Object (N : Node_Id);
|
72 |
|
|
procedure Expand_Pragma_Relative_Deadline (N : Node_Id);
|
73 |
|
|
|
74 |
|
|
----------
|
75 |
|
|
-- Arg1 --
|
76 |
|
|
----------
|
77 |
|
|
|
78 |
|
|
function Arg1 (N : Node_Id) return Node_Id is
|
79 |
|
|
Arg : constant Node_Id := First (Pragma_Argument_Associations (N));
|
80 |
|
|
begin
|
81 |
|
|
if Present (Arg)
|
82 |
|
|
and then Nkind (Arg) = N_Pragma_Argument_Association
|
83 |
|
|
then
|
84 |
|
|
return Expression (Arg);
|
85 |
|
|
else
|
86 |
|
|
return Arg;
|
87 |
|
|
end if;
|
88 |
|
|
end Arg1;
|
89 |
|
|
|
90 |
|
|
----------
|
91 |
|
|
-- Arg2 --
|
92 |
|
|
----------
|
93 |
|
|
|
94 |
|
|
function Arg2 (N : Node_Id) return Node_Id is
|
95 |
|
|
Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
|
96 |
|
|
|
97 |
|
|
begin
|
98 |
|
|
if No (Arg1) then
|
99 |
|
|
return Empty;
|
100 |
|
|
|
101 |
|
|
else
|
102 |
|
|
declare
|
103 |
|
|
Arg : constant Node_Id := Next (Arg1);
|
104 |
|
|
begin
|
105 |
|
|
if Present (Arg)
|
106 |
|
|
and then Nkind (Arg) = N_Pragma_Argument_Association
|
107 |
|
|
then
|
108 |
|
|
return Expression (Arg);
|
109 |
|
|
else
|
110 |
|
|
return Arg;
|
111 |
|
|
end if;
|
112 |
|
|
end;
|
113 |
|
|
end if;
|
114 |
|
|
end Arg2;
|
115 |
|
|
|
116 |
|
|
----------
|
117 |
|
|
-- Arg3 --
|
118 |
|
|
----------
|
119 |
|
|
|
120 |
|
|
function Arg3 (N : Node_Id) return Node_Id is
|
121 |
|
|
Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
|
122 |
|
|
|
123 |
|
|
begin
|
124 |
|
|
if No (Arg1) then
|
125 |
|
|
return Empty;
|
126 |
|
|
|
127 |
|
|
else
|
128 |
|
|
declare
|
129 |
|
|
Arg : Node_Id := Next (Arg1);
|
130 |
|
|
begin
|
131 |
|
|
if No (Arg) then
|
132 |
|
|
return Empty;
|
133 |
|
|
|
134 |
|
|
else
|
135 |
|
|
Next (Arg);
|
136 |
|
|
|
137 |
|
|
if Present (Arg)
|
138 |
|
|
and then Nkind (Arg) = N_Pragma_Argument_Association
|
139 |
|
|
then
|
140 |
|
|
return Expression (Arg);
|
141 |
|
|
else
|
142 |
|
|
return Arg;
|
143 |
|
|
end if;
|
144 |
|
|
end if;
|
145 |
|
|
end;
|
146 |
|
|
end if;
|
147 |
|
|
end Arg3;
|
148 |
|
|
|
149 |
|
|
---------------------
|
150 |
|
|
-- Expand_N_Pragma --
|
151 |
|
|
---------------------
|
152 |
|
|
|
153 |
|
|
procedure Expand_N_Pragma (N : Node_Id) is
|
154 |
|
|
Pname : constant Name_Id := Pragma_Name (N);
|
155 |
|
|
|
156 |
|
|
begin
|
157 |
|
|
-- Note: we may have a pragma whose Pragma_Identifier field is not a
|
158 |
|
|
-- recognized pragma, and we must ignore it at this stage.
|
159 |
|
|
|
160 |
|
|
if Is_Pragma_Name (Pname) then
|
161 |
|
|
case Get_Pragma_Id (Pname) is
|
162 |
|
|
|
163 |
|
|
-- Pragmas requiring special expander action
|
164 |
|
|
|
165 |
|
|
when Pragma_Abort_Defer =>
|
166 |
|
|
Expand_Pragma_Abort_Defer (N);
|
167 |
|
|
|
168 |
|
|
when Pragma_Check =>
|
169 |
|
|
Expand_Pragma_Check (N);
|
170 |
|
|
|
171 |
|
|
when Pragma_Common_Object =>
|
172 |
|
|
Expand_Pragma_Common_Object (N);
|
173 |
|
|
|
174 |
|
|
when Pragma_Export_Exception =>
|
175 |
|
|
Expand_Pragma_Import_Export_Exception (N);
|
176 |
|
|
|
177 |
|
|
when Pragma_Import =>
|
178 |
|
|
Expand_Pragma_Import_Or_Interface (N);
|
179 |
|
|
|
180 |
|
|
when Pragma_Import_Exception =>
|
181 |
|
|
Expand_Pragma_Import_Export_Exception (N);
|
182 |
|
|
|
183 |
|
|
when Pragma_Inspection_Point =>
|
184 |
|
|
Expand_Pragma_Inspection_Point (N);
|
185 |
|
|
|
186 |
|
|
when Pragma_Interface =>
|
187 |
|
|
Expand_Pragma_Import_Or_Interface (N);
|
188 |
|
|
|
189 |
|
|
when Pragma_Interrupt_Priority =>
|
190 |
|
|
Expand_Pragma_Interrupt_Priority (N);
|
191 |
|
|
|
192 |
|
|
when Pragma_Psect_Object =>
|
193 |
|
|
Expand_Pragma_Psect_Object (N);
|
194 |
|
|
|
195 |
|
|
when Pragma_Relative_Deadline =>
|
196 |
|
|
Expand_Pragma_Relative_Deadline (N);
|
197 |
|
|
|
198 |
|
|
-- All other pragmas need no expander action
|
199 |
|
|
|
200 |
|
|
when others => null;
|
201 |
|
|
end case;
|
202 |
|
|
end if;
|
203 |
|
|
|
204 |
|
|
end Expand_N_Pragma;
|
205 |
|
|
|
206 |
|
|
-------------------------------
|
207 |
|
|
-- Expand_Pragma_Abort_Defer --
|
208 |
|
|
-------------------------------
|
209 |
|
|
|
210 |
|
|
-- An Abort_Defer pragma appears as the first statement in a handled
|
211 |
|
|
-- statement sequence (right after the begin). It defers aborts for
|
212 |
|
|
-- the entire statement sequence, but not for any declarations or
|
213 |
|
|
-- handlers (if any) associated with this statement sequence.
|
214 |
|
|
|
215 |
|
|
-- The transformation is to transform
|
216 |
|
|
|
217 |
|
|
-- pragma Abort_Defer;
|
218 |
|
|
-- statements;
|
219 |
|
|
|
220 |
|
|
-- into
|
221 |
|
|
|
222 |
|
|
-- begin
|
223 |
|
|
-- Abort_Defer.all;
|
224 |
|
|
-- statements
|
225 |
|
|
-- exception
|
226 |
|
|
-- when all others =>
|
227 |
|
|
-- Abort_Undefer.all;
|
228 |
|
|
-- raise;
|
229 |
|
|
-- at end
|
230 |
|
|
-- Abort_Undefer_Direct;
|
231 |
|
|
-- end;
|
232 |
|
|
|
233 |
|
|
procedure Expand_Pragma_Abort_Defer (N : Node_Id) is
|
234 |
|
|
Loc : constant Source_Ptr := Sloc (N);
|
235 |
|
|
Stm : Node_Id;
|
236 |
|
|
Stms : List_Id;
|
237 |
|
|
HSS : Node_Id;
|
238 |
|
|
Blk : constant Entity_Id :=
|
239 |
|
|
New_Internal_Entity (E_Block, Current_Scope, Sloc (N), 'B');
|
240 |
|
|
|
241 |
|
|
begin
|
242 |
|
|
Stms := New_List (Build_Runtime_Call (Loc, RE_Abort_Defer));
|
243 |
|
|
|
244 |
|
|
loop
|
245 |
|
|
Stm := Remove_Next (N);
|
246 |
|
|
exit when No (Stm);
|
247 |
|
|
Append (Stm, Stms);
|
248 |
|
|
end loop;
|
249 |
|
|
|
250 |
|
|
HSS :=
|
251 |
|
|
Make_Handled_Sequence_Of_Statements (Loc,
|
252 |
|
|
Statements => Stms,
|
253 |
|
|
At_End_Proc =>
|
254 |
|
|
New_Occurrence_Of (RTE (RE_Abort_Undefer_Direct), Loc));
|
255 |
|
|
|
256 |
|
|
Rewrite (N,
|
257 |
|
|
Make_Block_Statement (Loc,
|
258 |
|
|
Handled_Statement_Sequence => HSS));
|
259 |
|
|
|
260 |
|
|
Set_Scope (Blk, Current_Scope);
|
261 |
|
|
Set_Etype (Blk, Standard_Void_Type);
|
262 |
|
|
Set_Identifier (N, New_Occurrence_Of (Blk, Sloc (N)));
|
263 |
|
|
Expand_At_End_Handler (HSS, Blk);
|
264 |
|
|
Analyze (N);
|
265 |
|
|
end Expand_Pragma_Abort_Defer;
|
266 |
|
|
|
267 |
|
|
--------------------------
|
268 |
|
|
-- Expand_Pragma_Check --
|
269 |
|
|
--------------------------
|
270 |
|
|
|
271 |
|
|
procedure Expand_Pragma_Check (N : Node_Id) is
|
272 |
|
|
Cond : constant Node_Id := Arg2 (N);
|
273 |
|
|
Nam : constant Name_Id := Chars (Arg1 (N));
|
274 |
|
|
Msg : Node_Id;
|
275 |
|
|
|
276 |
|
|
Loc : constant Source_Ptr := Sloc (First_Node (Cond));
|
277 |
|
|
-- Source location used in the case of a failed assertion. Note that
|
278 |
|
|
-- the source location of the expression is not usually the best choice
|
279 |
|
|
-- here. For example, it gets located on the last AND keyword in a
|
280 |
|
|
-- chain of boolean expressiond AND'ed together. It is best to put the
|
281 |
|
|
-- message on the first character of the assertion, which is the effect
|
282 |
|
|
-- of the First_Node call here.
|
283 |
|
|
|
284 |
|
|
begin
|
285 |
|
|
-- We already know that this check is enabled, because otherwise the
|
286 |
|
|
-- semantic pass dealt with rewriting the assertion (see Sem_Prag)
|
287 |
|
|
|
288 |
|
|
-- Since this check is enabled, we rewrite the pragma into a
|
289 |
|
|
-- corresponding if statement, and then analyze the statement
|
290 |
|
|
|
291 |
|
|
-- The normal case expansion transforms:
|
292 |
|
|
|
293 |
|
|
-- pragma Check (name, condition [,message]);
|
294 |
|
|
|
295 |
|
|
-- into
|
296 |
|
|
|
297 |
|
|
-- if not condition then
|
298 |
|
|
-- System.Assertions.Raise_Assert_Failure (Str);
|
299 |
|
|
-- end if;
|
300 |
|
|
|
301 |
|
|
-- where Str is the message if one is present, or the default of
|
302 |
|
|
-- name failed at file:line if no message is given (the "name failed
|
303 |
|
|
-- at" is omitted for name = Assertion, since it is redundant, given
|
304 |
|
|
-- that the name of the exception is Assert_Failure.)
|
305 |
|
|
|
306 |
|
|
-- An alternative expansion is used when the No_Exception_Propagation
|
307 |
|
|
-- restriction is active and there is a local Assert_Failure handler.
|
308 |
|
|
-- This is not a common combination of circumstances, but it occurs in
|
309 |
|
|
-- the context of Aunit and the zero footprint profile. In this case we
|
310 |
|
|
-- generate:
|
311 |
|
|
|
312 |
|
|
-- if not condition then
|
313 |
|
|
-- raise Assert_Failure;
|
314 |
|
|
-- end if;
|
315 |
|
|
|
316 |
|
|
-- This will then be transformed into a goto, and the local handler will
|
317 |
|
|
-- be able to handle the assert error (which would not be the case if a
|
318 |
|
|
-- call is made to the Raise_Assert_Failure procedure).
|
319 |
|
|
|
320 |
|
|
-- We also generate the direct raise if the Suppress_Exception_Locations
|
321 |
|
|
-- is active, since we don't want to generate messages in this case.
|
322 |
|
|
|
323 |
|
|
-- Note that the reason we do not always generate a direct raise is that
|
324 |
|
|
-- the form in which the procedure is called allows for more efficient
|
325 |
|
|
-- breakpointing of assertion errors.
|
326 |
|
|
|
327 |
|
|
-- Generate the appropriate if statement. Note that we consider this to
|
328 |
|
|
-- be an explicit conditional in the source, not an implicit if, so we
|
329 |
|
|
-- do not call Make_Implicit_If_Statement.
|
330 |
|
|
|
331 |
|
|
-- Case where we generate a direct raise
|
332 |
|
|
|
333 |
|
|
if ((Debug_Flag_Dot_G
|
334 |
|
|
or else Restriction_Active (No_Exception_Propagation))
|
335 |
|
|
and then Present (Find_Local_Handler (RTE (RE_Assert_Failure), N)))
|
336 |
|
|
or else (Opt.Exception_Locations_Suppressed and then No (Arg3 (N)))
|
337 |
|
|
then
|
338 |
|
|
Rewrite (N,
|
339 |
|
|
Make_If_Statement (Loc,
|
340 |
|
|
Condition =>
|
341 |
|
|
Make_Op_Not (Loc,
|
342 |
|
|
Right_Opnd => Cond),
|
343 |
|
|
Then_Statements => New_List (
|
344 |
|
|
Make_Raise_Statement (Loc,
|
345 |
|
|
Name =>
|
346 |
|
|
New_Reference_To (RTE (RE_Assert_Failure), Loc)))));
|
347 |
|
|
|
348 |
|
|
-- Case where we call the procedure
|
349 |
|
|
|
350 |
|
|
else
|
351 |
|
|
-- If we have a message given, use it
|
352 |
|
|
|
353 |
|
|
if Present (Arg3 (N)) then
|
354 |
|
|
Msg := Get_Pragma_Arg (Arg3 (N));
|
355 |
|
|
|
356 |
|
|
-- Here we have no string, so prepare one
|
357 |
|
|
|
358 |
|
|
else
|
359 |
|
|
declare
|
360 |
|
|
Msg_Loc : constant String := Build_Location_String (Loc);
|
361 |
|
|
|
362 |
|
|
begin
|
363 |
|
|
Name_Len := 0;
|
364 |
|
|
|
365 |
|
|
-- For Assert, we just use the location
|
366 |
|
|
|
367 |
|
|
if Nam = Name_Assertion then
|
368 |
|
|
null;
|
369 |
|
|
|
370 |
|
|
-- For predicate, we generate the string "predicate failed
|
371 |
|
|
-- at yyy". We prefer all lower case for predicate.
|
372 |
|
|
|
373 |
|
|
elsif Nam = Name_Predicate then
|
374 |
|
|
Add_Str_To_Name_Buffer ("predicate failed at ");
|
375 |
|
|
|
376 |
|
|
-- For special case of Precondition/Postcondition the string is
|
377 |
|
|
-- "failed xx from yy" where xx is precondition/postcondition
|
378 |
|
|
-- in all lower case. The reason for this different wording is
|
379 |
|
|
-- that the failure is not at the point of occurrence of the
|
380 |
|
|
-- pragma, unlike the other Check cases.
|
381 |
|
|
|
382 |
|
|
elsif Nam = Name_Precondition
|
383 |
|
|
or else
|
384 |
|
|
Nam = Name_Postcondition
|
385 |
|
|
then
|
386 |
|
|
Get_Name_String (Nam);
|
387 |
|
|
Insert_Str_In_Name_Buffer ("failed ", 1);
|
388 |
|
|
Add_Str_To_Name_Buffer (" from ");
|
389 |
|
|
|
390 |
|
|
-- For all other checks, the string is "xxx failed at yyy"
|
391 |
|
|
-- where xxx is the check name with current source file casing.
|
392 |
|
|
|
393 |
|
|
else
|
394 |
|
|
Get_Name_String (Nam);
|
395 |
|
|
Set_Casing (Identifier_Casing (Current_Source_File));
|
396 |
|
|
Add_Str_To_Name_Buffer (" failed at ");
|
397 |
|
|
end if;
|
398 |
|
|
|
399 |
|
|
-- In all cases, add location string
|
400 |
|
|
|
401 |
|
|
Add_Str_To_Name_Buffer (Msg_Loc);
|
402 |
|
|
|
403 |
|
|
-- Build the message
|
404 |
|
|
|
405 |
|
|
Msg := Make_String_Literal (Loc, Name_Buffer (1 .. Name_Len));
|
406 |
|
|
end;
|
407 |
|
|
end if;
|
408 |
|
|
|
409 |
|
|
-- Now rewrite as an if statement
|
410 |
|
|
|
411 |
|
|
Rewrite (N,
|
412 |
|
|
Make_If_Statement (Loc,
|
413 |
|
|
Condition =>
|
414 |
|
|
Make_Op_Not (Loc,
|
415 |
|
|
Right_Opnd => Cond),
|
416 |
|
|
Then_Statements => New_List (
|
417 |
|
|
Make_Procedure_Call_Statement (Loc,
|
418 |
|
|
Name =>
|
419 |
|
|
New_Reference_To (RTE (RE_Raise_Assert_Failure), Loc),
|
420 |
|
|
Parameter_Associations => New_List (Relocate_Node (Msg))))));
|
421 |
|
|
end if;
|
422 |
|
|
|
423 |
|
|
Analyze (N);
|
424 |
|
|
|
425 |
|
|
-- If new condition is always false, give a warning
|
426 |
|
|
|
427 |
|
|
if Warn_On_Assertion_Failure
|
428 |
|
|
and then Nkind (N) = N_Procedure_Call_Statement
|
429 |
|
|
and then Is_RTE (Entity (Name (N)), RE_Raise_Assert_Failure)
|
430 |
|
|
then
|
431 |
|
|
-- If original condition was a Standard.False, we assume that this is
|
432 |
|
|
-- indeed intended to raise assert error and no warning is required.
|
433 |
|
|
|
434 |
|
|
if Is_Entity_Name (Original_Node (Cond))
|
435 |
|
|
and then Entity (Original_Node (Cond)) = Standard_False
|
436 |
|
|
then
|
437 |
|
|
return;
|
438 |
|
|
elsif Nam = Name_Assertion then
|
439 |
|
|
Error_Msg_N ("?assertion will fail at run time", N);
|
440 |
|
|
else
|
441 |
|
|
Error_Msg_N ("?check will fail at run time", N);
|
442 |
|
|
end if;
|
443 |
|
|
end if;
|
444 |
|
|
end Expand_Pragma_Check;
|
445 |
|
|
|
446 |
|
|
---------------------------------
|
447 |
|
|
-- Expand_Pragma_Common_Object --
|
448 |
|
|
---------------------------------
|
449 |
|
|
|
450 |
|
|
-- Use a machine attribute to replicate semantic effect in DEC Ada
|
451 |
|
|
|
452 |
|
|
-- pragma Machine_Attribute (intern_name, "common_object", extern_name);
|
453 |
|
|
|
454 |
|
|
-- For now we do nothing with the size attribute ???
|
455 |
|
|
|
456 |
|
|
-- Note: Psect_Object shares this processing
|
457 |
|
|
|
458 |
|
|
procedure Expand_Pragma_Common_Object (N : Node_Id) is
|
459 |
|
|
Loc : constant Source_Ptr := Sloc (N);
|
460 |
|
|
|
461 |
|
|
Internal : constant Node_Id := Arg1 (N);
|
462 |
|
|
External : constant Node_Id := Arg2 (N);
|
463 |
|
|
|
464 |
|
|
Psect : Node_Id;
|
465 |
|
|
-- Psect value upper cased as string literal
|
466 |
|
|
|
467 |
|
|
Iloc : constant Source_Ptr := Sloc (Internal);
|
468 |
|
|
Eloc : constant Source_Ptr := Sloc (External);
|
469 |
|
|
Ploc : Source_Ptr;
|
470 |
|
|
|
471 |
|
|
begin
|
472 |
|
|
-- Acquire Psect value and fold to upper case
|
473 |
|
|
|
474 |
|
|
if Present (External) then
|
475 |
|
|
if Nkind (External) = N_String_Literal then
|
476 |
|
|
String_To_Name_Buffer (Strval (External));
|
477 |
|
|
else
|
478 |
|
|
Get_Name_String (Chars (External));
|
479 |
|
|
end if;
|
480 |
|
|
|
481 |
|
|
Set_All_Upper_Case;
|
482 |
|
|
|
483 |
|
|
Psect :=
|
484 |
|
|
Make_String_Literal (Eloc,
|
485 |
|
|
Strval => String_From_Name_Buffer);
|
486 |
|
|
|
487 |
|
|
else
|
488 |
|
|
Get_Name_String (Chars (Internal));
|
489 |
|
|
Set_All_Upper_Case;
|
490 |
|
|
Psect :=
|
491 |
|
|
Make_String_Literal (Iloc,
|
492 |
|
|
Strval => String_From_Name_Buffer);
|
493 |
|
|
end if;
|
494 |
|
|
|
495 |
|
|
Ploc := Sloc (Psect);
|
496 |
|
|
|
497 |
|
|
-- Insert the pragma
|
498 |
|
|
|
499 |
|
|
Insert_After_And_Analyze (N,
|
500 |
|
|
Make_Pragma (Loc,
|
501 |
|
|
Chars => Name_Machine_Attribute,
|
502 |
|
|
Pragma_Argument_Associations => New_List (
|
503 |
|
|
Make_Pragma_Argument_Association (Iloc,
|
504 |
|
|
Expression => New_Copy_Tree (Internal)),
|
505 |
|
|
Make_Pragma_Argument_Association (Eloc,
|
506 |
|
|
Expression =>
|
507 |
|
|
Make_String_Literal (Sloc => Ploc,
|
508 |
|
|
Strval => "common_object")),
|
509 |
|
|
Make_Pragma_Argument_Association (Ploc,
|
510 |
|
|
Expression => New_Copy_Tree (Psect)))));
|
511 |
|
|
|
512 |
|
|
end Expand_Pragma_Common_Object;
|
513 |
|
|
|
514 |
|
|
---------------------------------------
|
515 |
|
|
-- Expand_Pragma_Import_Or_Interface --
|
516 |
|
|
---------------------------------------
|
517 |
|
|
|
518 |
|
|
-- When applied to a variable, the default initialization must not be
|
519 |
|
|
-- done. As it is already done when the pragma is found, we just get rid
|
520 |
|
|
-- of the call the initialization procedure which followed the object
|
521 |
|
|
-- declaration. The call is inserted after the declaration, but validity
|
522 |
|
|
-- checks may also have been inserted and the initialization call does
|
523 |
|
|
-- not necessarily appear immediately after the object declaration.
|
524 |
|
|
|
525 |
|
|
-- We can't use the freezing mechanism for this purpose, since we
|
526 |
|
|
-- have to elaborate the initialization expression when it is first
|
527 |
|
|
-- seen (i.e. this elaboration cannot be deferred to the freeze point).
|
528 |
|
|
|
529 |
|
|
procedure Expand_Pragma_Import_Or_Interface (N : Node_Id) is
|
530 |
|
|
Def_Id : constant Entity_Id := Entity (Arg2 (N));
|
531 |
|
|
Init_Call : Node_Id;
|
532 |
|
|
|
533 |
|
|
begin
|
534 |
|
|
if Ekind (Def_Id) = E_Variable then
|
535 |
|
|
|
536 |
|
|
-- Find generated initialization call for object, if any
|
537 |
|
|
|
538 |
|
|
Init_Call := Find_Init_Call (Def_Id, Rep_Clause => N);
|
539 |
|
|
if Present (Init_Call) then
|
540 |
|
|
Remove (Init_Call);
|
541 |
|
|
end if;
|
542 |
|
|
|
543 |
|
|
-- Any default initialization expression should be removed
|
544 |
|
|
-- (e.g., null defaults for access objects, zero initialization
|
545 |
|
|
-- of packed bit arrays). Imported objects aren't allowed to
|
546 |
|
|
-- have explicit initialization, so the expression must have
|
547 |
|
|
-- been generated by the compiler.
|
548 |
|
|
|
549 |
|
|
if No (Init_Call) and then Present (Expression (Parent (Def_Id))) then
|
550 |
|
|
Set_Expression (Parent (Def_Id), Empty);
|
551 |
|
|
end if;
|
552 |
|
|
end if;
|
553 |
|
|
end Expand_Pragma_Import_Or_Interface;
|
554 |
|
|
|
555 |
|
|
-------------------------------------------
|
556 |
|
|
-- Expand_Pragma_Import_Export_Exception --
|
557 |
|
|
-------------------------------------------
|
558 |
|
|
|
559 |
|
|
-- For a VMS exception fix up the language field with "VMS"
|
560 |
|
|
-- instead of "Ada" (gigi needs this), create a constant that will be the
|
561 |
|
|
-- value of the VMS condition code and stuff the Interface_Name field
|
562 |
|
|
-- with the unexpanded name of the exception (if not already set).
|
563 |
|
|
-- For a Ada exception, just stuff the Interface_Name field
|
564 |
|
|
-- with the unexpanded name of the exception (if not already set).
|
565 |
|
|
|
566 |
|
|
procedure Expand_Pragma_Import_Export_Exception (N : Node_Id) is
|
567 |
|
|
begin
|
568 |
|
|
-- This pragma is only effective on OpenVMS systems, it was ignored
|
569 |
|
|
-- on non-VMS systems, and we need to ignore it here as well.
|
570 |
|
|
|
571 |
|
|
if not OpenVMS_On_Target then
|
572 |
|
|
return;
|
573 |
|
|
end if;
|
574 |
|
|
|
575 |
|
|
declare
|
576 |
|
|
Id : constant Entity_Id := Entity (Arg1 (N));
|
577 |
|
|
Call : constant Node_Id := Register_Exception_Call (Id);
|
578 |
|
|
Loc : constant Source_Ptr := Sloc (N);
|
579 |
|
|
|
580 |
|
|
begin
|
581 |
|
|
if Present (Call) then
|
582 |
|
|
declare
|
583 |
|
|
Excep_Internal : constant Node_Id := Make_Temporary (Loc, 'V');
|
584 |
|
|
Export_Pragma : Node_Id;
|
585 |
|
|
Excep_Alias : Node_Id;
|
586 |
|
|
Excep_Object : Node_Id;
|
587 |
|
|
Excep_Image : String_Id;
|
588 |
|
|
Exdata : List_Id;
|
589 |
|
|
Lang_Char : Node_Id;
|
590 |
|
|
Code : Node_Id;
|
591 |
|
|
|
592 |
|
|
begin
|
593 |
|
|
if Present (Interface_Name (Id)) then
|
594 |
|
|
Excep_Image := Strval (Interface_Name (Id));
|
595 |
|
|
else
|
596 |
|
|
Get_Name_String (Chars (Id));
|
597 |
|
|
Set_All_Upper_Case;
|
598 |
|
|
Excep_Image := String_From_Name_Buffer;
|
599 |
|
|
end if;
|
600 |
|
|
|
601 |
|
|
Exdata := Component_Associations (Expression (Parent (Id)));
|
602 |
|
|
|
603 |
|
|
if Is_VMS_Exception (Id) then
|
604 |
|
|
Lang_Char := Next (First (Exdata));
|
605 |
|
|
|
606 |
|
|
-- Change the one-character language designator to 'V'
|
607 |
|
|
|
608 |
|
|
Rewrite (Expression (Lang_Char),
|
609 |
|
|
Make_Character_Literal (Loc,
|
610 |
|
|
Chars => Name_uV,
|
611 |
|
|
Char_Literal_Value =>
|
612 |
|
|
UI_From_Int (Character'Pos ('V'))));
|
613 |
|
|
Analyze (Expression (Lang_Char));
|
614 |
|
|
|
615 |
|
|
if Exception_Code (Id) /= No_Uint then
|
616 |
|
|
Code :=
|
617 |
|
|
Make_Integer_Literal (Loc,
|
618 |
|
|
Intval => Exception_Code (Id));
|
619 |
|
|
|
620 |
|
|
Excep_Object :=
|
621 |
|
|
Make_Object_Declaration (Loc,
|
622 |
|
|
Defining_Identifier => Excep_Internal,
|
623 |
|
|
Object_Definition =>
|
624 |
|
|
New_Reference_To (RTE (RE_Exception_Code), Loc));
|
625 |
|
|
|
626 |
|
|
Insert_Action (N, Excep_Object);
|
627 |
|
|
Analyze (Excep_Object);
|
628 |
|
|
|
629 |
|
|
Start_String;
|
630 |
|
|
Store_String_Int
|
631 |
|
|
(UI_To_Int (Exception_Code (Id)) / 8 * 8);
|
632 |
|
|
|
633 |
|
|
Excep_Alias :=
|
634 |
|
|
Make_Pragma
|
635 |
|
|
(Loc,
|
636 |
|
|
Name_Linker_Alias,
|
637 |
|
|
New_List
|
638 |
|
|
(Make_Pragma_Argument_Association
|
639 |
|
|
(Sloc => Loc,
|
640 |
|
|
Expression =>
|
641 |
|
|
New_Reference_To (Excep_Internal, Loc)),
|
642 |
|
|
|
643 |
|
|
Make_Pragma_Argument_Association
|
644 |
|
|
(Sloc => Loc,
|
645 |
|
|
Expression =>
|
646 |
|
|
Make_String_Literal
|
647 |
|
|
(Sloc => Loc,
|
648 |
|
|
Strval => End_String))));
|
649 |
|
|
|
650 |
|
|
Insert_Action (N, Excep_Alias);
|
651 |
|
|
Analyze (Excep_Alias);
|
652 |
|
|
|
653 |
|
|
Export_Pragma :=
|
654 |
|
|
Make_Pragma
|
655 |
|
|
(Loc,
|
656 |
|
|
Name_Export,
|
657 |
|
|
New_List
|
658 |
|
|
(Make_Pragma_Argument_Association (Loc,
|
659 |
|
|
Expression => Make_Identifier (Loc, Name_C)),
|
660 |
|
|
|
661 |
|
|
Make_Pragma_Argument_Association (Loc,
|
662 |
|
|
Expression =>
|
663 |
|
|
New_Reference_To (Excep_Internal, Loc)),
|
664 |
|
|
|
665 |
|
|
Make_Pragma_Argument_Association (Loc,
|
666 |
|
|
Expression =>
|
667 |
|
|
Make_String_Literal (Loc, Excep_Image)),
|
668 |
|
|
|
669 |
|
|
Make_Pragma_Argument_Association (Loc,
|
670 |
|
|
Expression =>
|
671 |
|
|
Make_String_Literal (Loc, Excep_Image))));
|
672 |
|
|
|
673 |
|
|
Insert_Action (N, Export_Pragma);
|
674 |
|
|
Analyze (Export_Pragma);
|
675 |
|
|
|
676 |
|
|
else
|
677 |
|
|
Code :=
|
678 |
|
|
Unchecked_Convert_To (RTE (RE_Exception_Code),
|
679 |
|
|
Make_Function_Call (Loc,
|
680 |
|
|
Name =>
|
681 |
|
|
New_Reference_To (RTE (RE_Import_Value), Loc),
|
682 |
|
|
Parameter_Associations => New_List
|
683 |
|
|
(Make_String_Literal (Loc,
|
684 |
|
|
Strval => Excep_Image))));
|
685 |
|
|
end if;
|
686 |
|
|
|
687 |
|
|
Rewrite (Call,
|
688 |
|
|
Make_Procedure_Call_Statement (Loc,
|
689 |
|
|
Name => New_Reference_To
|
690 |
|
|
(RTE (RE_Register_VMS_Exception), Loc),
|
691 |
|
|
Parameter_Associations => New_List (
|
692 |
|
|
Code,
|
693 |
|
|
Unchecked_Convert_To (RTE (RE_Exception_Data_Ptr),
|
694 |
|
|
Make_Attribute_Reference (Loc,
|
695 |
|
|
Prefix => New_Occurrence_Of (Id, Loc),
|
696 |
|
|
Attribute_Name => Name_Unrestricted_Access)))));
|
697 |
|
|
|
698 |
|
|
Analyze_And_Resolve (Code, RTE (RE_Exception_Code));
|
699 |
|
|
Analyze (Call);
|
700 |
|
|
end if;
|
701 |
|
|
|
702 |
|
|
if No (Interface_Name (Id)) then
|
703 |
|
|
Set_Interface_Name (Id,
|
704 |
|
|
Make_String_Literal
|
705 |
|
|
(Sloc => Loc,
|
706 |
|
|
Strval => Excep_Image));
|
707 |
|
|
end if;
|
708 |
|
|
end;
|
709 |
|
|
end if;
|
710 |
|
|
end;
|
711 |
|
|
end Expand_Pragma_Import_Export_Exception;
|
712 |
|
|
|
713 |
|
|
------------------------------------
|
714 |
|
|
-- Expand_Pragma_Inspection_Point --
|
715 |
|
|
------------------------------------
|
716 |
|
|
|
717 |
|
|
-- If no argument is given, then we supply a default argument list that
|
718 |
|
|
-- includes all objects declared at the source level in all subprograms
|
719 |
|
|
-- that enclose the inspection point pragma.
|
720 |
|
|
|
721 |
|
|
procedure Expand_Pragma_Inspection_Point (N : Node_Id) is
|
722 |
|
|
Loc : constant Source_Ptr := Sloc (N);
|
723 |
|
|
A : List_Id;
|
724 |
|
|
Assoc : Node_Id;
|
725 |
|
|
S : Entity_Id;
|
726 |
|
|
E : Entity_Id;
|
727 |
|
|
|
728 |
|
|
begin
|
729 |
|
|
if No (Pragma_Argument_Associations (N)) then
|
730 |
|
|
A := New_List;
|
731 |
|
|
S := Current_Scope;
|
732 |
|
|
|
733 |
|
|
while S /= Standard_Standard loop
|
734 |
|
|
E := First_Entity (S);
|
735 |
|
|
while Present (E) loop
|
736 |
|
|
if Comes_From_Source (E)
|
737 |
|
|
and then Is_Object (E)
|
738 |
|
|
and then not Is_Entry_Formal (E)
|
739 |
|
|
and then Ekind (E) /= E_Component
|
740 |
|
|
and then Ekind (E) /= E_Discriminant
|
741 |
|
|
and then Ekind (E) /= E_Generic_In_Parameter
|
742 |
|
|
and then Ekind (E) /= E_Generic_In_Out_Parameter
|
743 |
|
|
then
|
744 |
|
|
Append_To (A,
|
745 |
|
|
Make_Pragma_Argument_Association (Loc,
|
746 |
|
|
Expression => New_Occurrence_Of (E, Loc)));
|
747 |
|
|
end if;
|
748 |
|
|
|
749 |
|
|
Next_Entity (E);
|
750 |
|
|
end loop;
|
751 |
|
|
|
752 |
|
|
S := Scope (S);
|
753 |
|
|
end loop;
|
754 |
|
|
|
755 |
|
|
Set_Pragma_Argument_Associations (N, A);
|
756 |
|
|
end if;
|
757 |
|
|
|
758 |
|
|
-- Expand the arguments of the pragma. Expanding an entity reference
|
759 |
|
|
-- is a noop, except in a protected operation, where a reference may
|
760 |
|
|
-- have to be transformed into a reference to the corresponding prival.
|
761 |
|
|
-- Are there other pragmas that may require this ???
|
762 |
|
|
|
763 |
|
|
Assoc := First (Pragma_Argument_Associations (N));
|
764 |
|
|
|
765 |
|
|
while Present (Assoc) loop
|
766 |
|
|
Expand (Expression (Assoc));
|
767 |
|
|
Next (Assoc);
|
768 |
|
|
end loop;
|
769 |
|
|
end Expand_Pragma_Inspection_Point;
|
770 |
|
|
|
771 |
|
|
--------------------------------------
|
772 |
|
|
-- Expand_Pragma_Interrupt_Priority --
|
773 |
|
|
--------------------------------------
|
774 |
|
|
|
775 |
|
|
-- Supply default argument if none exists (System.Interrupt_Priority'Last)
|
776 |
|
|
|
777 |
|
|
procedure Expand_Pragma_Interrupt_Priority (N : Node_Id) is
|
778 |
|
|
Loc : constant Source_Ptr := Sloc (N);
|
779 |
|
|
|
780 |
|
|
begin
|
781 |
|
|
if No (Pragma_Argument_Associations (N)) then
|
782 |
|
|
Set_Pragma_Argument_Associations (N, New_List (
|
783 |
|
|
Make_Pragma_Argument_Association (Loc,
|
784 |
|
|
Expression =>
|
785 |
|
|
Make_Attribute_Reference (Loc,
|
786 |
|
|
Prefix =>
|
787 |
|
|
New_Occurrence_Of (RTE (RE_Interrupt_Priority), Loc),
|
788 |
|
|
Attribute_Name => Name_Last))));
|
789 |
|
|
end if;
|
790 |
|
|
end Expand_Pragma_Interrupt_Priority;
|
791 |
|
|
|
792 |
|
|
--------------------------------
|
793 |
|
|
-- Expand_Pragma_Psect_Object --
|
794 |
|
|
--------------------------------
|
795 |
|
|
|
796 |
|
|
-- Convert to Common_Object, and expand the resulting pragma
|
797 |
|
|
|
798 |
|
|
procedure Expand_Pragma_Psect_Object (N : Node_Id)
|
799 |
|
|
renames Expand_Pragma_Common_Object;
|
800 |
|
|
|
801 |
|
|
-------------------------------------
|
802 |
|
|
-- Expand_Pragma_Relative_Deadline --
|
803 |
|
|
-------------------------------------
|
804 |
|
|
|
805 |
|
|
procedure Expand_Pragma_Relative_Deadline (N : Node_Id) is
|
806 |
|
|
P : constant Node_Id := Parent (N);
|
807 |
|
|
Loc : constant Source_Ptr := Sloc (N);
|
808 |
|
|
|
809 |
|
|
begin
|
810 |
|
|
-- Expand the pragma only in the case of the main subprogram. For tasks
|
811 |
|
|
-- the expansion is done in exp_ch9. Generate a call to Set_Deadline
|
812 |
|
|
-- at Clock plus the relative deadline specified in the pragma. Time
|
813 |
|
|
-- values are translated into Duration to allow for non-private
|
814 |
|
|
-- addition operation.
|
815 |
|
|
|
816 |
|
|
if Nkind (P) = N_Subprogram_Body then
|
817 |
|
|
Rewrite
|
818 |
|
|
(N,
|
819 |
|
|
Make_Procedure_Call_Statement (Loc,
|
820 |
|
|
Name => New_Reference_To (RTE (RE_Set_Deadline), Loc),
|
821 |
|
|
Parameter_Associations => New_List (
|
822 |
|
|
Unchecked_Convert_To (RTE (RO_RT_Time),
|
823 |
|
|
Make_Op_Add (Loc,
|
824 |
|
|
Left_Opnd =>
|
825 |
|
|
Make_Function_Call (Loc,
|
826 |
|
|
New_Reference_To (RTE (RO_RT_To_Duration), Loc),
|
827 |
|
|
New_List (Make_Function_Call (Loc,
|
828 |
|
|
New_Reference_To (RTE (RE_Clock), Loc)))),
|
829 |
|
|
Right_Opnd =>
|
830 |
|
|
Unchecked_Convert_To (Standard_Duration, Arg1 (N)))))));
|
831 |
|
|
|
832 |
|
|
Analyze (N);
|
833 |
|
|
end if;
|
834 |
|
|
end Expand_Pragma_Relative_Deadline;
|
835 |
|
|
|
836 |
|
|
end Exp_Prag;
|