OSDN Git Service

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