OSDN Git Service

* Makefile.in (install-gnatlib): Remove spurious hyphen.
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ P R A G                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2004, 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 2,  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 COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 --  This unit contains the semantic processing for all pragmas, both language
28 --  and implementation defined. For most pragmas, the parser only does the
29 --  most basic job of checking the syntax, so Sem_Prag also contains the code
30 --  to complete the syntax checks. Certain pragmas are handled partially or
31 --  completely by the parser (see Par.Prag for further details).
32
33 with Atree;    use Atree;
34 with Casing;   use Casing;
35 with Csets;    use Csets;
36 with Debug;    use Debug;
37 with Einfo;    use Einfo;
38 with Elists;   use Elists;
39 with Errout;   use Errout;
40 with Exp_Dist; use Exp_Dist;
41 with Hostparm; use Hostparm;
42 with Lib;      use Lib;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet;    use Namet;
46 with Nlists;   use Nlists;
47 with Nmake;    use Nmake;
48 with Opt;      use Opt;
49 with Output;   use Output;
50 with Restrict; use Restrict;
51 with Rident;   use Rident;
52 with Rtsfind;  use Rtsfind;
53 with Sem;      use Sem;
54 with Sem_Ch3;  use Sem_Ch3;
55 with Sem_Ch8;  use Sem_Ch8;
56 with Sem_Ch13; use Sem_Ch13;
57 with Sem_Disp; use Sem_Disp;
58 with Sem_Elim; use Sem_Elim;
59 with Sem_Eval; use Sem_Eval;
60 with Sem_Intr; use Sem_Intr;
61 with Sem_Mech; use Sem_Mech;
62 with Sem_Res;  use Sem_Res;
63 with Sem_Type; use Sem_Type;
64 with Sem_Util; use Sem_Util;
65 with Sem_VFpt; use Sem_VFpt;
66 with Stand;    use Stand;
67 with Sinfo;    use Sinfo;
68 with Sinfo.CN; use Sinfo.CN;
69 with Sinput;   use Sinput;
70 with Snames;   use Snames;
71 with Stringt;  use Stringt;
72 with Stylesw;  use Stylesw;
73 with Table;
74 with Targparm; use Targparm;
75 with Tbuild;   use Tbuild;
76 with Ttypes;
77 with Uintp;    use Uintp;
78 with Urealp;   use Urealp;
79 with Validsw;  use Validsw;
80
81 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
82
83 package body Sem_Prag is
84
85    ----------------------------------------------
86    -- Common Handling of Import-Export Pragmas --
87    ----------------------------------------------
88
89    --  In the following section, a number of Import_xxx and Export_xxx
90    --  pragmas are defined by GNAT. These are compatible with the DEC
91    --  pragmas of the same name, and all have the following common
92    --  form and processing:
93
94    --  pragma Export_xxx
95    --        [Internal                 =>] LOCAL_NAME,
96    --     [, [External                 =>] EXTERNAL_SYMBOL]
97    --     [, other optional parameters   ]);
98
99    --  pragma Import_xxx
100    --        [Internal                 =>] LOCAL_NAME,
101    --     [, [External                 =>] EXTERNAL_SYMBOL]
102    --     [, other optional parameters   ]);
103
104    --   EXTERNAL_SYMBOL ::=
105    --     IDENTIFIER
106    --   | static_string_EXPRESSION
107
108    --  The internal LOCAL_NAME designates the entity that is imported or
109    --  exported, and must refer to an entity in the current declarative
110    --  part (as required by the rules for LOCAL_NAME).
111
112    --  The external linker name is designated by the External parameter
113    --  if given, or the Internal parameter if not (if there is no External
114    --  parameter, the External parameter is a copy of the Internal name).
115
116    --  If the External parameter is given as a string, then this string
117    --  is treated as an external name (exactly as though it had been given
118    --  as an External_Name parameter for a normal Import pragma).
119
120    --  If the External parameter is given as an identifier (or there is no
121    --  External parameter, so that the Internal identifier is used), then
122    --  the external name is the characters of the identifier, translated
123    --  to all upper case letters for OpenVMS versions of GNAT, and to all
124    --  lower case letters for all other versions
125
126    --  Note: the external name specified or implied by any of these special
127    --  Import_xxx or Export_xxx pragmas override an external or link name
128    --  specified in a previous Import or Export pragma.
129
130    --  Note: these and all other DEC-compatible GNAT pragmas allow full
131    --  use of named notation, following the standard rules for subprogram
132    --  calls, i.e. parameters can be given in any order if named notation
133    --  is used, and positional and named notation can be mixed, subject to
134    --  the rule that all positional parameters must appear first.
135
136    --  Note: All these pragmas are implemented exactly following the DEC
137    --  design and implementation and are intended to be fully compatible
138    --  with the use of these pragmas in the DEC Ada compiler.
139
140    --------------------------------------------
141    -- Checking for Duplicated External Names --
142    --------------------------------------------
143
144    --  It is suspicious if two separate Export pragmas use the same external
145    --  name. The following table is used to diagnose this situation so that
146    --  an appropriate warning can be issued.
147
148    --  The Node_Id stored is for the N_String_Literal node created to
149    --  hold the value of the external name. The Sloc of this node is
150    --  used to cross-reference the location of the duplication.
151
152    package Externals is new Table.Table (
153      Table_Component_Type => Node_Id,
154      Table_Index_Type     => Int,
155      Table_Low_Bound      => 0,
156      Table_Initial        => 100,
157      Table_Increment      => 100,
158      Table_Name           => "Name_Externals");
159
160    -------------------------------------
161    -- Local Subprograms and Variables --
162    -------------------------------------
163
164    function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
165    --  This routine is used for possible casing adjustment of an explicit
166    --  external name supplied as a string literal (the node N), according
167    --  to the casing requirement of Opt.External_Name_Casing. If this is
168    --  set to As_Is, then the string literal is returned unchanged, but if
169    --  it is set to Uppercase or Lowercase, then a new string literal with
170    --  appropriate casing is constructed.
171
172    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
173    --  If Def_Id refers to a renamed subprogram, then the base subprogram
174    --  (the original one, following the renaming chain) is returned.
175    --  Otherwise the entity is returned unchanged. Should be in Einfo???
176
177    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
178    --  Place semantic information on the argument of an Elaborate or
179    --  Elaborate_All pragma. Entity name for unit and its parents is
180    --  taken from item in previous with_clause that mentions the unit.
181
182    -------------------------------
183    -- Adjust_External_Name_Case --
184    -------------------------------
185
186    function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
187       CC : Char_Code;
188
189    begin
190       --  Adjust case of literal if required
191
192       if Opt.External_Name_Exp_Casing = As_Is then
193          return N;
194
195       else
196          --  Copy existing string
197
198          Start_String;
199
200          --  Set proper casing
201
202          for J in 1 .. String_Length (Strval (N)) loop
203             CC := Get_String_Char (Strval (N), J);
204
205             if Opt.External_Name_Exp_Casing = Uppercase
206               and then CC >= Get_Char_Code ('a')
207               and then CC <= Get_Char_Code ('z')
208             then
209                Store_String_Char (CC - 32);
210
211             elsif Opt.External_Name_Exp_Casing = Lowercase
212               and then CC >= Get_Char_Code ('A')
213               and then CC <= Get_Char_Code ('Z')
214             then
215                Store_String_Char (CC + 32);
216
217             else
218                Store_String_Char (CC);
219             end if;
220          end loop;
221
222          return
223            Make_String_Literal (Sloc (N),
224              Strval => End_String);
225       end if;
226    end Adjust_External_Name_Case;
227
228    --------------------
229    -- Analyze_Pragma --
230    --------------------
231
232    procedure Analyze_Pragma (N : Node_Id) is
233       Loc     : constant Source_Ptr := Sloc (N);
234       Prag_Id : Pragma_Id;
235
236       Pragma_Exit : exception;
237       --  This exception is used to exit pragma processing completely. It
238       --  is used when an error is detected, and in other situations where
239       --  it is known that no further processing is required.
240
241       Arg_Count : Nat;
242       --  Number of pragma argument associations
243
244       Arg1 : Node_Id;
245       Arg2 : Node_Id;
246       Arg3 : Node_Id;
247       Arg4 : Node_Id;
248       --  First four pragma arguments (pragma argument association nodes,
249       --  or Empty if the corresponding argument does not exist).
250
251       procedure Check_Ada_83_Warning;
252       --  Issues a warning message for the current pragma if operating in Ada
253       --  83 mode (used for language pragmas that are not a standard part of
254       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
255       --  of 95 pragma.
256
257       procedure Check_Arg_Count (Required : Nat);
258       --  Check argument count for pragma is equal to given parameter.
259       --  If not, then issue an error message and raise Pragma_Exit.
260
261       --  Note: all routines whose name is Check_Arg_Is_xxx take an
262       --  argument Arg which can either be a pragma argument association,
263       --  in which case the check is applied to the expression of the
264       --  association or an expression directly.
265
266       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
267       --  Check that an argument has the right form for an EXTERNAL_NAME
268       --  parameter of an extended import/export pragma. The rule is that
269       --  the name must be an identifier or string literal (in Ada 83 mode)
270       --  or a static string expression (in Ada 95 mode).
271
272       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
273       --  Check the specified argument Arg to make sure that it is an
274       --  identifier. If not give error and raise Pragma_Exit.
275
276       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
277       --  Check the specified argument Arg to make sure that it is an
278       --  integer literal. If not give error and raise Pragma_Exit.
279
280       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
281       --  Check the specified argument Arg to make sure that it has the
282       --  proper syntactic form for a local name and meets the semantic
283       --  requirements for a local name. The local name is analyzed as
284       --  part of the processing for this call. In addition, the local
285       --  name is required to represent an entity at the library level.
286
287       procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
288       --  Check the specified argument Arg to make sure that it has the
289       --  proper syntactic form for a local name and meets the semantic
290       --  requirements for a local name. The local name is analyzed as
291       --  part of the processing for this call.
292
293       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
294       --  Check the specified argument Arg to make sure that it is a valid
295       --  locking policy name. If not give error and raise Pragma_Exit.
296
297       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
298       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
299       --  Check the specified argument Arg to make sure that it is an
300       --  identifier whose name matches either N1 or N2 (or N3 if present).
301       --  If not then give error and raise Pragma_Exit.
302
303       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
304       --  Check the specified argument Arg to make sure that it is a valid
305       --  queuing policy name. If not give error and raise Pragma_Exit.
306
307       procedure Check_Arg_Is_Static_Expression
308         (Arg : Node_Id;
309          Typ : Entity_Id);
310       --  Check the specified argument Arg to make sure that it is a static
311       --  expression of the given type (i.e. it will be analyzed and resolved
312       --  using this type, which can be any valid argument to Resolve, e.g.
313       --  Any_Integer is OK). If not, given error and raise Pragma_Exit.
314
315       procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
316       --  Check the specified argument Arg to make sure that it is a
317       --  string literal. If not give error and raise Pragma_Exit
318
319       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
320       --  Check the specified argument Arg to make sure that it is a valid
321       --  valid task dispatching policy name. If not give error and raise
322       --  Pragma_Exit.
323
324       procedure Check_At_Least_N_Arguments (N : Nat);
325       --  Check there are at least N arguments present
326
327       procedure Check_At_Most_N_Arguments (N : Nat);
328       --  Check there are no more than N arguments present
329
330       procedure Check_Component (Comp : Node_Id);
331       --  Examine Unchecked_Union component for correct use of per-object
332       --  constrained subtypes.
333
334       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
335       --  Nam is an N_String_Literal node containing the external name set
336       --  by an Import or Export pragma (or extended Import or Export pragma).
337       --  This procedure checks for possible duplications if this is the
338       --  export case, and if found, issues an appropriate error message.
339
340       procedure Check_First_Subtype (Arg : Node_Id);
341       --  Checks that Arg, whose expression is an entity name referencing
342       --  a subtype, does not reference a type that is not a first subtype.
343
344       procedure Check_In_Main_Program;
345       --  Common checks for pragmas that appear within a main program
346       --  (Priority, Main_Storage, Time_Slice).
347
348       procedure Check_Interrupt_Or_Attach_Handler;
349       --  Common processing for first argument of pragma Interrupt_Handler
350       --  or pragma Attach_Handler.
351
352       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
353       --  Check that pragma appears in a declarative part, or in a package
354       --  specification, i.e. that it does not occur in a statement sequence
355       --  in a body.
356
357       procedure Check_No_Identifier (Arg : Node_Id);
358       --  Checks that the given argument does not have an identifier. If
359       --  an identifier is present, then an error message is issued, and
360       --  Pragma_Exit is raised.
361
362       procedure Check_No_Identifiers;
363       --  Checks that none of the arguments to the pragma has an identifier.
364       --  If any argument has an identifier, then an error message is issued,
365       --  and Pragma_Exit is raised.
366
367       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
368       --  Checks if the given argument has an identifier, and if so, requires
369       --  it to match the given identifier name. If there is a non-matching
370       --  identifier, then an error message is given and Error_Pragmas raised.
371
372       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
373       --  Checks if the given argument has an identifier, and if so, requires
374       --  it to match the given identifier name. If there is a non-matching
375       --  identifier, then an error message is given and Error_Pragmas raised.
376       --  In this version of the procedure, the identifier name is given as
377       --  a string with lower case letters.
378
379       procedure Check_Static_Constraint (Constr : Node_Id);
380       --  Constr is a constraint from an N_Subtype_Indication node from a
381       --  component constraint in an Unchecked_Union type. This routine checks
382       --  that the constraint is static as required by the restrictions for
383       --  Unchecked_Union.
384
385       procedure Check_Valid_Configuration_Pragma;
386       --  Legality checks for placement of a configuration pragma
387
388       procedure Check_Valid_Library_Unit_Pragma;
389       --  Legality checks for library unit pragmas. A special case arises for
390       --  pragmas in generic instances that come from copies of the original
391       --  library unit pragmas in the generic templates. In the case of other
392       --  than library level instantiations these can appear in contexts which
393       --  would normally be invalid (they only apply to the original template
394       --  and to library level instantiations), and they are simply ignored,
395       --  which is implemented by rewriting them as null statements.
396
397       procedure Check_Variant (Variant : Node_Id);
398       --  Check Unchecked_Union variant for lack of nested variants and
399       --  presence of at least one component.
400
401       procedure Error_Pragma (Msg : String);
402       pragma No_Return (Error_Pragma);
403       --  Outputs error message for current pragma. The message contains an %
404       --  that will be replaced with the pragma name, and the flag is placed
405       --  on the pragma itself. Pragma_Exit is then raised.
406
407       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
408       pragma No_Return (Error_Pragma_Arg);
409       --  Outputs error message for current pragma. The message may contain
410       --  a % that will be replaced with the pragma name. The parameter Arg
411       --  may either be a pragma argument association, in which case the flag
412       --  is placed on the expression of this association, or an expression,
413       --  in which case the flag is placed directly on the expression. The
414       --  message is placed using Error_Msg_N, so the message may also contain
415       --  an & insertion character which will reference the given Arg value.
416       --  After placing the message, Pragma_Exit is raised.
417
418       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
419       pragma No_Return (Error_Pragma_Arg);
420       --  Similar to above form of Error_Pragma_Arg except that two messages
421       --  are provided, the second is a continuation comment starting with \.
422
423       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
424       pragma No_Return (Error_Pragma_Arg_Ident);
425       --  Outputs error message for current pragma. The message may contain
426       --  a % that will be replaced with the pragma name. The parameter Arg
427       --  must be a pragma argument association with a non-empty identifier
428       --  (i.e. its Chars field must be set), and the error message is placed
429       --  on the identifier. The message is placed using Error_Msg_N so
430       --  the message may also contain an & insertion character which will
431       --  reference the identifier. After placing the message, Pragma_Exit
432       --  is raised.
433
434       function Find_Lib_Unit_Name return Entity_Id;
435       --  Used for a library unit pragma to find the entity to which the
436       --  library unit pragma applies, returns the entity found.
437
438       procedure Find_Program_Unit_Name (Id : Node_Id);
439       --  If the pragma is a compilation unit pragma, the id must denote the
440       --  compilation unit in the same compilation, and the pragma must appear
441       --  in the list of preceding or trailing pragmas. If it is a program
442       --  unit pragma that is not a compilation unit pragma, then the
443       --  identifier must be visible.
444
445       type Name_List is array (Natural range <>) of Name_Id;
446       type Args_List is array (Natural range <>) of Node_Id;
447       procedure Gather_Associations
448         (Names : Name_List;
449          Args  : out Args_List);
450       --  This procedure is used to gather the arguments for a pragma that
451       --  permits arbitrary ordering of parameters using the normal rules
452       --  for named and positional parameters. The Names argument is a list
453       --  of Name_Id values that corresponds to the allowed pragma argument
454       --  association identifiers in order. The result returned in Args is
455       --  a list of corresponding expressions that are the pragma arguments.
456       --  Note that this is a list of expressions, not of pragma argument
457       --  associations (Gather_Associations has completely checked all the
458       --  optional identifiers when it returns). An entry in Args is Empty
459       --  on return if the corresponding argument is not present.
460
461       function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
462       --  All the routines that check pragma arguments take either a pragma
463       --  argument association (in which case the expression of the argument
464       --  association is checked), or the expression directly. The function
465       --  Get_Pragma_Arg is a utility used to deal with these two cases. If
466       --  Arg is a pragma argument association node, then its expression is
467       --  returned, otherwise Arg is returned unchanged.
468
469       procedure GNAT_Pragma;
470       --  Called for all GNAT defined pragmas to note the use of the feature,
471       --  and also check the relevant restriction (No_Implementation_Pragmas).
472
473       function Is_Before_First_Decl
474         (Pragma_Node : Node_Id;
475          Decls       : List_Id) return Boolean;
476       --  Return True if Pragma_Node is before the first declarative item in
477       --  Decls where Decls is the list of declarative items.
478
479       function Is_Configuration_Pragma return Boolean;
480       --  Deterermines if the placement of the current pragma is appropriate
481       --  for a configuration pragma (precedes the current compilation unit)
482
483       procedure Pragma_Misplaced;
484       --  Issue fatal error message for misplaced pragma
485
486       procedure Process_Atomic_Shared_Volatile;
487       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
488       --  Shared is an obsolete Ada 83 pragma, treated as being identical
489       --  in effect to pragma Atomic.
490
491       procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
492       --  Common procesing for Convention, Interface, Import and Export.
493       --  Checks first two arguments of pragma, and sets the appropriate
494       --  convention value in the specified entity or entities. On return
495       --  C is the convention, E is the referenced entity.
496
497       procedure Process_Extended_Import_Export_Exception_Pragma
498         (Arg_Internal : Node_Id;
499          Arg_External : Node_Id;
500          Arg_Form     : Node_Id;
501          Arg_Code     : Node_Id);
502       --  Common processing for the pragmas Import/Export_Exception.
503       --  The three arguments correspond to the three named parameters of
504       --  the pragma. An argument is empty if the corresponding parameter
505       --  is not present in the pragma.
506
507       procedure Process_Extended_Import_Export_Object_Pragma
508         (Arg_Internal : Node_Id;
509          Arg_External : Node_Id;
510          Arg_Size     : Node_Id);
511       --  Common processing for the pragmass Import/Export_Object.
512       --  The three arguments correspond to the three named parameters
513       --  of the pragmas. An argument is empty if the corresponding
514       --  parameter is not present in the pragma.
515
516       procedure Process_Extended_Import_Export_Internal_Arg
517         (Arg_Internal : Node_Id := Empty);
518       --  Common processing for all extended Import and Export pragmas. The
519       --  argument is the pragma parameter for the Internal argument. If
520       --  Arg_Internal is empty or inappropriate, an error message is posted.
521       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
522       --  set to identify the referenced entity.
523
524       procedure Process_Extended_Import_Export_Subprogram_Pragma
525         (Arg_Internal                 : Node_Id;
526          Arg_External                 : Node_Id;
527          Arg_Parameter_Types          : Node_Id;
528          Arg_Result_Type              : Node_Id := Empty;
529          Arg_Mechanism                : Node_Id;
530          Arg_Result_Mechanism         : Node_Id := Empty;
531          Arg_First_Optional_Parameter : Node_Id := Empty);
532       --  Common processing for all extended Import and Export pragmas
533       --  applying to subprograms. The caller omits any arguments that do
534       --  bnot apply to the pragma in question (for example, Arg_Result_Type
535       --  can be non-Empty only in the Import_Function and Export_Function
536       --  cases). The argument names correspond to the allowed pragma
537       --  association identifiers.
538
539       procedure Process_Generic_List;
540       --  Common processing for Share_Generic and Inline_Generic
541
542       procedure Process_Import_Or_Interface;
543       --  Common processing for Import of Interface
544
545       procedure Process_Inline (Active : Boolean);
546       --  Common processing for Inline and Inline_Always. The parameter
547       --  indicates if the inline pragma is active, i.e. if it should
548       --  actually cause inlining to occur.
549
550       procedure Process_Interface_Name
551         (Subprogram_Def : Entity_Id;
552          Ext_Arg        : Node_Id;
553          Link_Arg       : Node_Id);
554       --  Given the last two arguments of pragma Import, pragma Export, or
555       --  pragma Interface_Name, performs validity checks and sets the
556       --  Interface_Name field of the given subprogram entity to the
557       --  appropriate external or link name, depending on the arguments
558       --  given. Ext_Arg is always present, but Link_Arg may be missing.
559       --  Note that Ext_Arg may represent the Link_Name if Link_Arg is
560       --  missing, and appropriate named notation is used for Ext_Arg.
561       --  If neither Ext_Arg nor Link_Arg is present, the interface name
562       --  is set to the default from the subprogram name.
563
564       procedure Process_Interrupt_Or_Attach_Handler;
565       --  Common processing for Interrupt and Attach_Handler pragmas
566
567       procedure Process_Restrictions_Or_Restriction_Warnings;
568       --  Common processing for Restrictions and Restriction_Warnings pragmas
569
570       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
571       --  Common processing for Suppress and Unsuppress. The boolean parameter
572       --  Suppress_Case is True for the Suppress case, and False for the
573       --  Unsuppress case.
574
575       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
576       --  This procedure sets the Is_Exported flag for the given entity,
577       --  checking that the entity was not previously imported. Arg is
578       --  the argument that specified the entity. A check is also made
579       --  for exporting inappropriate entities.
580
581       procedure Set_Extended_Import_Export_External_Name
582         (Internal_Ent : Entity_Id;
583          Arg_External : Node_Id);
584       --  Common processing for all extended import export pragmas. The first
585       --  argument, Internal_Ent, is the internal entity, which has already
586       --  been checked for validity by the caller. Arg_External is from the
587       --  Import or Export pragma, and may be null if no External parameter
588       --  was present. If Arg_External is present and is a non-null string
589       --  (a null string is treated as the default), then the Interface_Name
590       --  field of Internal_Ent is set appropriately.
591
592       procedure Set_Imported (E : Entity_Id);
593       --  This procedure sets the Is_Imported flag for the given entity,
594       --  checking that it is not previously exported or imported.
595
596       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
597       --  Mech is a parameter passing mechanism (see Import_Function syntax
598       --  for MECHANISM_NAME). This routine checks that the mechanism argument
599       --  has the right form, and if not issues an error message. If the
600       --  argument has the right form then the Mechanism field of Ent is
601       --  set appropriately.
602
603       procedure Set_Ravenscar_Profile (N : Node_Id);
604       --  Activate the set of configuration pragmas and restrictions that
605       --  make up the Ravenscar Profile. N is the corresponding pragma
606       --  node, which is used for error messages on any constructs
607       --  that violate the profile.
608
609       --------------------------
610       -- Check_Ada_83_Warning --
611       --------------------------
612
613       procedure Check_Ada_83_Warning is
614       begin
615          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
616             Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
617          end if;
618       end Check_Ada_83_Warning;
619
620       ---------------------
621       -- Check_Arg_Count --
622       ---------------------
623
624       procedure Check_Arg_Count (Required : Nat) is
625       begin
626          if Arg_Count /= Required then
627             Error_Pragma ("wrong number of arguments for pragma%");
628          end if;
629       end Check_Arg_Count;
630
631       --------------------------------
632       -- Check_Arg_Is_External_Name --
633       --------------------------------
634
635       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
636          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
637
638       begin
639          if Nkind (Argx) = N_Identifier then
640             return;
641
642          else
643             Analyze_And_Resolve (Argx, Standard_String);
644
645             if Is_OK_Static_Expression (Argx) then
646                return;
647
648             elsif Etype (Argx) = Any_Type then
649                raise Pragma_Exit;
650
651             --  An interesting special case, if we have a string literal and
652             --  we are in Ada 83 mode, then we allow it even though it will
653             --  not be flagged as static. This allows expected Ada 83 mode
654             --  use of external names which are string literals, even though
655             --  technically these are not static in Ada 83.
656
657             elsif Ada_Version = Ada_83
658               and then Nkind (Argx) = N_String_Literal
659             then
660                return;
661
662             --  Static expression that raises Constraint_Error. This has
663             --  already been flagged, so just exit from pragma processing.
664
665             elsif Is_Static_Expression (Argx) then
666                raise Pragma_Exit;
667
668             --  Here we have a real error (non-static expression)
669
670             else
671                Error_Msg_Name_1 := Chars (N);
672                Flag_Non_Static_Expr
673                  ("argument for pragma% must be a identifier or " &
674                   "static string expression!", Argx);
675                raise Pragma_Exit;
676             end if;
677          end if;
678       end Check_Arg_Is_External_Name;
679
680       -----------------------------
681       -- Check_Arg_Is_Identifier --
682       -----------------------------
683
684       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
685          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
686       begin
687          if Nkind (Argx) /= N_Identifier then
688             Error_Pragma_Arg
689               ("argument for pragma% must be identifier", Argx);
690          end if;
691       end Check_Arg_Is_Identifier;
692
693       ----------------------------------
694       -- Check_Arg_Is_Integer_Literal --
695       ----------------------------------
696
697       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
698          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
699       begin
700          if Nkind (Argx) /= N_Integer_Literal then
701             Error_Pragma_Arg
702               ("argument for pragma% must be integer literal", Argx);
703          end if;
704       end Check_Arg_Is_Integer_Literal;
705
706       -------------------------------------------
707       -- Check_Arg_Is_Library_Level_Local_Name --
708       -------------------------------------------
709
710       --  LOCAL_NAME ::=
711       --    DIRECT_NAME
712       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
713       --  | library_unit_NAME
714
715       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
716       begin
717          Check_Arg_Is_Local_Name (Arg);
718
719          if not Is_Library_Level_Entity (Entity (Expression (Arg)))
720            and then Comes_From_Source (N)
721          then
722             Error_Pragma_Arg
723               ("argument for pragma% must be library level entity", Arg);
724          end if;
725       end Check_Arg_Is_Library_Level_Local_Name;
726
727       -----------------------------
728       -- Check_Arg_Is_Local_Name --
729       -----------------------------
730
731       --  LOCAL_NAME ::=
732       --    DIRECT_NAME
733       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
734       --  | library_unit_NAME
735
736       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
737          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
738
739       begin
740          Analyze (Argx);
741
742          if Nkind (Argx) not in N_Direct_Name
743            and then (Nkind (Argx) /= N_Attribute_Reference
744                       or else Present (Expressions (Argx))
745                       or else Nkind (Prefix (Argx)) /= N_Identifier)
746            and then (not Is_Entity_Name (Argx)
747                       or else not Is_Compilation_Unit (Entity (Argx)))
748          then
749             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
750          end if;
751
752          if Is_Entity_Name (Argx)
753            and then Scope (Entity (Argx)) /= Current_Scope
754          then
755             Error_Pragma_Arg
756               ("pragma% argument must be in same declarative part", Arg);
757          end if;
758       end Check_Arg_Is_Local_Name;
759
760       ---------------------------------
761       -- Check_Arg_Is_Locking_Policy --
762       ---------------------------------
763
764       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
765          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
766
767       begin
768          Check_Arg_Is_Identifier (Argx);
769
770          if not Is_Locking_Policy_Name (Chars (Argx)) then
771             Error_Pragma_Arg
772               ("& is not a valid locking policy name", Argx);
773          end if;
774       end Check_Arg_Is_Locking_Policy;
775
776       -------------------------
777       -- Check_Arg_Is_One_Of --
778       -------------------------
779
780       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
781          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
782
783       begin
784          Check_Arg_Is_Identifier (Argx);
785
786          if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
787             Error_Msg_Name_2 := N1;
788             Error_Msg_Name_3 := N2;
789             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
790          end if;
791       end Check_Arg_Is_One_Of;
792
793       procedure Check_Arg_Is_One_Of
794         (Arg        : Node_Id;
795          N1, N2, N3 : Name_Id)
796       is
797          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
798
799       begin
800          Check_Arg_Is_Identifier (Argx);
801
802          if Chars (Argx) /= N1
803            and then Chars (Argx) /= N2
804            and then Chars (Argx) /= N3
805          then
806             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
807          end if;
808       end Check_Arg_Is_One_Of;
809
810       ---------------------------------
811       -- Check_Arg_Is_Queuing_Policy --
812       ---------------------------------
813
814       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
815          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
816
817       begin
818          Check_Arg_Is_Identifier (Argx);
819
820          if not Is_Queuing_Policy_Name (Chars (Argx)) then
821             Error_Pragma_Arg
822               ("& is not a valid queuing policy name", Argx);
823          end if;
824       end Check_Arg_Is_Queuing_Policy;
825
826       ------------------------------------
827       -- Check_Arg_Is_Static_Expression --
828       ------------------------------------
829
830       procedure Check_Arg_Is_Static_Expression
831         (Arg : Node_Id;
832          Typ : Entity_Id)
833       is
834          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
835
836       begin
837          Analyze_And_Resolve (Argx, Typ);
838
839          if Is_OK_Static_Expression (Argx) then
840             return;
841
842          elsif Etype (Argx) = Any_Type then
843             raise Pragma_Exit;
844
845          --  An interesting special case, if we have a string literal and
846          --  we are in Ada 83 mode, then we allow it even though it will
847          --  not be flagged as static. This allows the use of Ada 95
848          --  pragmas like Import in Ada 83 mode. They will of course be
849          --  flagged with warnings as usual, but will not cause errors.
850
851          elsif Ada_Version = Ada_83
852            and then Nkind (Argx) = N_String_Literal
853          then
854             return;
855
856          --  Static expression that raises Constraint_Error. This has
857          --  already been flagged, so just exit from pragma processing.
858
859          elsif Is_Static_Expression (Argx) then
860             raise Pragma_Exit;
861
862          --  Finally, we have a real error
863
864          else
865             Error_Msg_Name_1 := Chars (N);
866             Flag_Non_Static_Expr
867               ("argument for pragma% must be a static expression!", Argx);
868             raise Pragma_Exit;
869          end if;
870       end Check_Arg_Is_Static_Expression;
871
872       ---------------------------------
873       -- Check_Arg_Is_String_Literal --
874       ---------------------------------
875
876       procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
877          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
878
879       begin
880          if Nkind (Argx) /= N_String_Literal then
881             Error_Pragma_Arg
882               ("argument for pragma% must be string literal", Argx);
883          end if;
884
885       end Check_Arg_Is_String_Literal;
886
887       ------------------------------------------
888       -- Check_Arg_Is_Task_Dispatching_Policy --
889       ------------------------------------------
890
891       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
892          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
893
894       begin
895          Check_Arg_Is_Identifier (Argx);
896
897          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
898             Error_Pragma_Arg
899               ("& is not a valid task dispatching policy name", Argx);
900          end if;
901       end Check_Arg_Is_Task_Dispatching_Policy;
902
903       --------------------------------
904       -- Check_At_Least_N_Arguments --
905       --------------------------------
906
907       procedure Check_At_Least_N_Arguments (N : Nat) is
908       begin
909          if Arg_Count < N then
910             Error_Pragma ("too few arguments for pragma%");
911          end if;
912       end Check_At_Least_N_Arguments;
913
914       -------------------------------
915       -- Check_At_Most_N_Arguments --
916       -------------------------------
917
918       procedure Check_At_Most_N_Arguments (N : Nat) is
919          Arg : Node_Id;
920
921       begin
922          if Arg_Count > N then
923             Arg := Arg1;
924             for J in 1 .. N loop
925                Next (Arg);
926                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
927             end loop;
928          end if;
929       end Check_At_Most_N_Arguments;
930
931       ---------------------
932       -- Check_Component --
933       ---------------------
934
935       procedure Check_Component (Comp : Node_Id) is
936       begin
937          if Nkind (Comp) = N_Component_Declaration then
938             declare
939                Sindic : constant Node_Id :=
940                           Subtype_Indication (Component_Definition (Comp));
941
942             begin
943                if Nkind (Sindic) = N_Subtype_Indication then
944
945                   --  Ada 2005 (AI-216): If a component subtype is subject to
946                   --  a per-object constraint, then the component type shall
947                   --  be an Unchecked_Union.
948
949                   if Has_Per_Object_Constraint (Defining_Identifier (Comp))
950                     and then
951                       not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
952                   then
953                      Error_Msg_N ("component subtype subject to per-object" &
954                        " constraint must be an Unchecked_Union", Comp);
955                   end if;
956                end if;
957             end;
958          end if;
959       end Check_Component;
960
961       ----------------------------------
962       -- Check_Duplicated_Export_Name --
963       ----------------------------------
964
965       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
966          String_Val : constant String_Id := Strval (Nam);
967
968       begin
969          --  We are only interested in the export case, and in the case of
970          --  generics, it is the instance, not the template, that is the
971          --  problem (the template will generate a warning in any case).
972
973          if not Inside_A_Generic
974            and then (Prag_Id = Pragma_Export
975                        or else
976                      Prag_Id = Pragma_Export_Procedure
977                        or else
978                      Prag_Id = Pragma_Export_Valued_Procedure
979                        or else
980                      Prag_Id = Pragma_Export_Function)
981          then
982             for J in Externals.First .. Externals.Last loop
983                if String_Equal (String_Val, Strval (Externals.Table (J))) then
984                   Error_Msg_Sloc := Sloc (Externals.Table (J));
985                   Error_Msg_N ("external name duplicates name given#", Nam);
986                   exit;
987                end if;
988             end loop;
989
990             Externals.Append (Nam);
991          end if;
992       end Check_Duplicated_Export_Name;
993
994       -------------------------
995       -- Check_First_Subtype --
996       -------------------------
997
998       procedure Check_First_Subtype (Arg : Node_Id) is
999          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1000
1001       begin
1002          if not Is_First_Subtype (Entity (Argx)) then
1003             Error_Pragma_Arg
1004               ("pragma% cannot apply to subtype", Argx);
1005          end if;
1006       end Check_First_Subtype;
1007
1008       ---------------------------
1009       -- Check_In_Main_Program --
1010       ---------------------------
1011
1012       procedure Check_In_Main_Program is
1013          P : constant Node_Id := Parent (N);
1014
1015       begin
1016          --  Must be at in subprogram body
1017
1018          if Nkind (P) /= N_Subprogram_Body then
1019             Error_Pragma ("% pragma allowed only in subprogram");
1020
1021          --  Otherwise warn if obviously not main program
1022
1023          elsif Present (Parameter_Specifications (Specification (P)))
1024            or else not Is_Compilation_Unit (Defining_Entity (P))
1025          then
1026             Error_Msg_Name_1 := Chars (N);
1027             Error_Msg_N
1028               ("?pragma% is only effective in main program", N);
1029          end if;
1030       end Check_In_Main_Program;
1031
1032       ---------------------------------------
1033       -- Check_Interrupt_Or_Attach_Handler --
1034       ---------------------------------------
1035
1036       procedure Check_Interrupt_Or_Attach_Handler is
1037          Arg1_X : constant Node_Id := Expression (Arg1);
1038
1039       begin
1040          Analyze (Arg1_X);
1041
1042          if not Is_Entity_Name (Arg1_X) then
1043             Error_Pragma_Arg
1044               ("argument of pragma% must be entity name", Arg1);
1045
1046          elsif Prag_Id = Pragma_Interrupt_Handler then
1047             Check_Restriction (No_Dynamic_Attachment, N);
1048          end if;
1049
1050          declare
1051             Handler_Proc : Entity_Id := Empty;
1052             Proc_Scope   : Entity_Id;
1053             Found        : Boolean := False;
1054
1055          begin
1056             if not Is_Overloaded (Arg1_X) then
1057                Handler_Proc := Entity (Arg1_X);
1058
1059             else
1060                declare
1061                   It    : Interp;
1062                   Index : Interp_Index;
1063
1064                begin
1065                   Get_First_Interp (Arg1_X, Index, It);
1066                   while Present (It.Nam) loop
1067                      Handler_Proc := It.Nam;
1068
1069                      if Ekind (Handler_Proc) = E_Procedure
1070                        and then No (First_Formal (Handler_Proc))
1071                      then
1072                         if not Found then
1073                            Found := True;
1074                            Set_Entity (Arg1_X, Handler_Proc);
1075                            Set_Is_Overloaded (Arg1_X, False);
1076                         else
1077                            Error_Pragma_Arg
1078                              ("ambiguous handler name for pragma% ", Arg1);
1079                         end if;
1080                      end if;
1081
1082                      Get_Next_Interp (Index, It);
1083                   end loop;
1084
1085                   if not Found then
1086                      Error_Pragma_Arg
1087                        ("argument of pragma% must be parameterless procedure",
1088                         Arg1);
1089                   else
1090                      Handler_Proc := Entity (Arg1_X);
1091                   end if;
1092                end;
1093             end if;
1094
1095             Proc_Scope := Scope (Handler_Proc);
1096
1097             --  On AAMP only, a pragma Interrupt_Handler is supported for
1098             --  nonprotected parameterless procedures.
1099
1100             if AAMP_On_Target
1101               and then Prag_Id = Pragma_Interrupt_Handler
1102             then
1103                if Ekind (Handler_Proc) /= E_Procedure then
1104                   Error_Pragma_Arg
1105                     ("argument of pragma% must be a procedure", Arg1);
1106                end if;
1107
1108             elsif Ekind (Handler_Proc) /= E_Procedure
1109               or else Ekind (Proc_Scope) /= E_Protected_Type
1110             then
1111                Error_Pragma_Arg
1112                  ("argument of pragma% must be protected procedure", Arg1);
1113             end if;
1114
1115             if (not AAMP_On_Target or else Prag_Id = Pragma_Attach_Handler)
1116               and then Ekind (Proc_Scope) = E_Protected_Type
1117             then
1118                if Parent (N) /=
1119                     Protected_Definition (Parent (Proc_Scope))
1120                then
1121                   Error_Pragma ("pragma% must be in protected definition");
1122                end if;
1123             end if;
1124
1125             if not Is_Library_Level_Entity (Proc_Scope)
1126               or else (AAMP_On_Target
1127                         and then not Is_Library_Level_Entity (Handler_Proc))
1128             then
1129                Error_Pragma_Arg
1130                  ("pragma% requires library-level entity", Arg1);
1131             end if;
1132
1133             if Present (First_Formal (Handler_Proc)) then
1134                Error_Pragma_Arg
1135                  ("argument of pragma% must be parameterless procedure",
1136                   Arg1);
1137             end if;
1138          end;
1139       end Check_Interrupt_Or_Attach_Handler;
1140
1141       -------------------------------------------
1142       -- Check_Is_In_Decl_Part_Or_Package_Spec --
1143       -------------------------------------------
1144
1145       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1146          P : Node_Id;
1147
1148       begin
1149          P := Parent (N);
1150          loop
1151             if No (P) then
1152                exit;
1153
1154             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1155                exit;
1156
1157             elsif Nkind (P) = N_Package_Specification then
1158                return;
1159
1160             elsif Nkind (P) = N_Block_Statement then
1161                return;
1162
1163             --  Note: the following tests seem a little peculiar, because
1164             --  they test for bodies, but if we were in the statement part
1165             --  of the body, we would already have hit the handled statement
1166             --  sequence, so the only way we get here is by being in the
1167             --  declarative part of the body.
1168
1169             elsif Nkind (P) = N_Subprogram_Body
1170               or else Nkind (P) = N_Package_Body
1171               or else Nkind (P) = N_Task_Body
1172               or else Nkind (P) = N_Entry_Body
1173             then
1174                return;
1175             end if;
1176
1177             P := Parent (P);
1178          end loop;
1179
1180          Error_Pragma ("pragma% is not in declarative part or package spec");
1181       end Check_Is_In_Decl_Part_Or_Package_Spec;
1182
1183       -------------------------
1184       -- Check_No_Identifier --
1185       -------------------------
1186
1187       procedure Check_No_Identifier (Arg : Node_Id) is
1188       begin
1189          if Chars (Arg) /= No_Name then
1190             Error_Pragma_Arg_Ident
1191               ("pragma% does not permit identifier& here", Arg);
1192          end if;
1193       end Check_No_Identifier;
1194
1195       --------------------------
1196       -- Check_No_Identifiers --
1197       --------------------------
1198
1199       procedure Check_No_Identifiers is
1200          Arg_Node : Node_Id;
1201
1202       begin
1203          if Arg_Count > 0 then
1204             Arg_Node := Arg1;
1205
1206             while Present (Arg_Node) loop
1207                Check_No_Identifier (Arg_Node);
1208                Next (Arg_Node);
1209             end loop;
1210          end if;
1211       end Check_No_Identifiers;
1212
1213       -------------------------------
1214       -- Check_Optional_Identifier --
1215       -------------------------------
1216
1217       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1218       begin
1219          if Present (Arg) and then Chars (Arg) /= No_Name then
1220             if Chars (Arg) /= Id then
1221                Error_Msg_Name_1 := Chars (N);
1222                Error_Msg_Name_2 := Id;
1223                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1224                raise Pragma_Exit;
1225             end if;
1226          end if;
1227       end Check_Optional_Identifier;
1228
1229       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1230       begin
1231          Name_Buffer (1 .. Id'Length) := Id;
1232          Name_Len := Id'Length;
1233          Check_Optional_Identifier (Arg, Name_Find);
1234       end Check_Optional_Identifier;
1235
1236       -----------------------------
1237       -- Check_Static_Constraint --
1238       -----------------------------
1239
1240       --  Note: for convenience in writing this procedure, in addition to
1241       --  the officially (i.e. by spec) allowed argument which is always
1242       --  a constraint, it also allows ranges and discriminant associations.
1243       --  Above is not clear ???
1244
1245       procedure Check_Static_Constraint (Constr : Node_Id) is
1246
1247          --------------------
1248          -- Require_Static --
1249          --------------------
1250
1251          procedure Require_Static (E : Node_Id);
1252          --  Require given expression to be static expression
1253
1254          procedure Require_Static (E : Node_Id) is
1255          begin
1256             if not Is_OK_Static_Expression (E) then
1257                Flag_Non_Static_Expr
1258                  ("non-static constraint not allowed in Unchecked_Union!", E);
1259                raise Pragma_Exit;
1260             end if;
1261          end Require_Static;
1262
1263       --  Start of processing for Check_Static_Constraint
1264
1265       begin
1266          case Nkind (Constr) is
1267             when N_Discriminant_Association =>
1268                Require_Static (Expression (Constr));
1269
1270             when N_Range =>
1271                Require_Static (Low_Bound (Constr));
1272                Require_Static (High_Bound (Constr));
1273
1274             when N_Attribute_Reference =>
1275                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
1276                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1277
1278             when N_Range_Constraint =>
1279                Check_Static_Constraint (Range_Expression (Constr));
1280
1281             when N_Index_Or_Discriminant_Constraint =>
1282                declare
1283                   IDC : Entity_Id := First (Constraints (Constr));
1284                begin
1285                   while Present (IDC) loop
1286                      Check_Static_Constraint (IDC);
1287                      Next (IDC);
1288                   end loop;
1289                end;
1290
1291             when others =>
1292                null;
1293          end case;
1294       end Check_Static_Constraint;
1295
1296       --------------------------------------
1297       -- Check_Valid_Configuration_Pragma --
1298       --------------------------------------
1299
1300       --  A configuration pragma must appear in the context clause of
1301       --  a compilation unit, at the start of the list (i.e. only other
1302       --  pragmas may precede it).
1303
1304       procedure Check_Valid_Configuration_Pragma is
1305       begin
1306          if not Is_Configuration_Pragma then
1307             Error_Pragma ("incorrect placement for configuration pragma%");
1308          end if;
1309       end Check_Valid_Configuration_Pragma;
1310
1311       -------------------------------------
1312       -- Check_Valid_Library_Unit_Pragma --
1313       -------------------------------------
1314
1315       procedure Check_Valid_Library_Unit_Pragma is
1316          Plist       : List_Id;
1317          Parent_Node : Node_Id;
1318          Unit_Name   : Entity_Id;
1319          Unit_Kind   : Node_Kind;
1320          Unit_Node   : Node_Id;
1321          Sindex      : Source_File_Index;
1322
1323       begin
1324          if not Is_List_Member (N) then
1325             Pragma_Misplaced;
1326
1327          else
1328             Plist := List_Containing (N);
1329             Parent_Node := Parent (Plist);
1330
1331             if Parent_Node = Empty then
1332                Pragma_Misplaced;
1333
1334             --  Case of pragma appearing after a compilation unit. In this
1335             --  case it must have an argument with the corresponding name
1336             --  and must be part of the following pragmas of its parent.
1337
1338             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1339                if Plist /= Pragmas_After (Parent_Node) then
1340                   Pragma_Misplaced;
1341
1342                elsif Arg_Count = 0 then
1343                   Error_Pragma
1344                     ("argument required if outside compilation unit");
1345
1346                else
1347                   Check_No_Identifiers;
1348                   Check_Arg_Count (1);
1349                   Unit_Node := Unit (Parent (Parent_Node));
1350                   Unit_Kind := Nkind (Unit_Node);
1351
1352                   Analyze (Expression (Arg1));
1353
1354                   if        Unit_Kind = N_Generic_Subprogram_Declaration
1355                     or else Unit_Kind = N_Subprogram_Declaration
1356                   then
1357                      Unit_Name := Defining_Entity (Unit_Node);
1358
1359                   elsif     Unit_Kind = N_Function_Instantiation
1360                     or else Unit_Kind = N_Package_Instantiation
1361                     or else Unit_Kind = N_Procedure_Instantiation
1362                   then
1363                      Unit_Name := Defining_Entity (Unit_Node);
1364
1365                   else
1366                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
1367                   end if;
1368
1369                   if Chars (Unit_Name) /=
1370                      Chars (Entity (Expression (Arg1)))
1371                   then
1372                      Error_Pragma_Arg
1373                        ("pragma% argument is not current unit name", Arg1);
1374                   end if;
1375
1376                   if Ekind (Unit_Name) = E_Package
1377                     and then Present (Renamed_Entity (Unit_Name))
1378                   then
1379                      Error_Pragma ("pragma% not allowed for renamed package");
1380                   end if;
1381                end if;
1382
1383             --  Pragma appears other than after a compilation unit
1384
1385             else
1386                --  Here we check for the generic instantiation case and also
1387                --  for the case of processing a generic formal package. We
1388                --  detect these cases by noting that the Sloc on the node
1389                --  does not belong to the current compilation unit.
1390
1391                Sindex := Source_Index (Current_Sem_Unit);
1392
1393                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1394                   Rewrite (N, Make_Null_Statement (Loc));
1395                   return;
1396
1397                --  If before first declaration, the pragma applies to the
1398                --  enclosing unit, and the name if present must be this name.
1399
1400                elsif Is_Before_First_Decl (N, Plist) then
1401                   Unit_Node := Unit_Declaration_Node (Current_Scope);
1402                   Unit_Kind := Nkind (Unit_Node);
1403
1404                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1405                      Pragma_Misplaced;
1406
1407                   elsif Unit_Kind = N_Subprogram_Body
1408                     and then not Acts_As_Spec (Unit_Node)
1409                   then
1410                      Pragma_Misplaced;
1411
1412                   elsif Nkind (Parent_Node) = N_Package_Body then
1413                      Pragma_Misplaced;
1414
1415                   elsif Nkind (Parent_Node) = N_Package_Specification
1416                     and then Plist = Private_Declarations (Parent_Node)
1417                   then
1418                      Pragma_Misplaced;
1419
1420                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1421                           or else Nkind (Parent_Node)
1422                             = N_Generic_Subprogram_Declaration)
1423                     and then Plist = Generic_Formal_Declarations (Parent_Node)
1424                   then
1425                      Pragma_Misplaced;
1426
1427                   elsif Arg_Count > 0 then
1428                      Analyze (Expression (Arg1));
1429
1430                      if Entity (Expression (Arg1)) /= Current_Scope then
1431                         Error_Pragma_Arg
1432                           ("name in pragma% must be enclosing unit", Arg1);
1433                      end if;
1434
1435                   --  It is legal to have no argument in this context
1436
1437                   else
1438                      return;
1439                   end if;
1440
1441                --  Error if not before first declaration. This is because a
1442                --  library unit pragma argument must be the name of a library
1443                --  unit (RM 10.1.5(7)), but the only names permitted in this
1444                --  context are (RM 10.1.5(6)) names of subprogram declarations,
1445                --  generic subprogram declarations or generic instantiations.
1446
1447                else
1448                   Error_Pragma
1449                     ("pragma% misplaced, must be before first declaration");
1450                end if;
1451             end if;
1452          end if;
1453       end Check_Valid_Library_Unit_Pragma;
1454
1455       -------------------
1456       -- Check_Variant --
1457       -------------------
1458
1459       procedure Check_Variant (Variant : Node_Id) is
1460          Clist : constant Node_Id := Component_List (Variant);
1461          Comp  : Node_Id;
1462
1463       begin
1464          if Present (Variant_Part (Clist)) then
1465             Error_Msg_N
1466               ("Unchecked_Union may not have nested variants",
1467                Variant_Part (Clist));
1468          end if;
1469
1470          if not Is_Non_Empty_List (Component_Items (Clist)) then
1471             Error_Msg_N
1472               ("Unchecked_Union may not have empty component list",
1473                Variant);
1474             return;
1475          end if;
1476
1477          Comp := First (Component_Items (Clist));
1478          while Present (Comp) loop
1479
1480             Check_Component (Comp);
1481             Next (Comp);
1482
1483          end loop;
1484       end Check_Variant;
1485
1486       ------------------
1487       -- Error_Pragma --
1488       ------------------
1489
1490       procedure Error_Pragma (Msg : String) is
1491       begin
1492          Error_Msg_Name_1 := Chars (N);
1493          Error_Msg_N (Msg, N);
1494          raise Pragma_Exit;
1495       end Error_Pragma;
1496
1497       ----------------------
1498       -- Error_Pragma_Arg --
1499       ----------------------
1500
1501       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1502       begin
1503          Error_Msg_Name_1 := Chars (N);
1504          Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1505          raise Pragma_Exit;
1506       end Error_Pragma_Arg;
1507
1508       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1509       begin
1510          Error_Msg_Name_1 := Chars (N);
1511          Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1512          Error_Pragma_Arg (Msg2, Arg);
1513       end Error_Pragma_Arg;
1514
1515       ----------------------------
1516       -- Error_Pragma_Arg_Ident --
1517       ----------------------------
1518
1519       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1520       begin
1521          Error_Msg_Name_1 := Chars (N);
1522          Error_Msg_N (Msg, Arg);
1523          raise Pragma_Exit;
1524       end Error_Pragma_Arg_Ident;
1525
1526       ------------------------
1527       -- Find_Lib_Unit_Name --
1528       ------------------------
1529
1530       function Find_Lib_Unit_Name return Entity_Id is
1531       begin
1532          --  Return inner compilation unit entity, for case of nested
1533          --  categorization pragmas. This happens in generic unit.
1534
1535          if Nkind (Parent (N)) = N_Package_Specification
1536            and then Defining_Entity (Parent (N)) /= Current_Scope
1537          then
1538             return Defining_Entity (Parent (N));
1539          else
1540             return Current_Scope;
1541          end if;
1542       end Find_Lib_Unit_Name;
1543
1544       ----------------------------
1545       -- Find_Program_Unit_Name --
1546       ----------------------------
1547
1548       procedure Find_Program_Unit_Name (Id : Node_Id) is
1549          Unit_Name : Entity_Id;
1550          Unit_Kind : Node_Kind;
1551          P         : constant Node_Id := Parent (N);
1552
1553       begin
1554          if Nkind (P) = N_Compilation_Unit then
1555             Unit_Kind := Nkind (Unit (P));
1556
1557             if Unit_Kind = N_Subprogram_Declaration
1558               or else Unit_Kind = N_Package_Declaration
1559               or else Unit_Kind in N_Generic_Declaration
1560             then
1561                Unit_Name := Defining_Entity (Unit (P));
1562
1563                if Chars (Id) = Chars (Unit_Name) then
1564                   Set_Entity (Id, Unit_Name);
1565                   Set_Etype (Id, Etype (Unit_Name));
1566                else
1567                   Set_Etype (Id, Any_Type);
1568                   Error_Pragma
1569                     ("cannot find program unit referenced by pragma%");
1570                end if;
1571
1572             else
1573                Set_Etype (Id, Any_Type);
1574                Error_Pragma ("pragma% inapplicable to this unit");
1575             end if;
1576
1577          else
1578             Analyze (Id);
1579          end if;
1580
1581       end Find_Program_Unit_Name;
1582
1583       -------------------------
1584       -- Gather_Associations --
1585       -------------------------
1586
1587       procedure Gather_Associations
1588         (Names : Name_List;
1589          Args  : out Args_List)
1590       is
1591          Arg : Node_Id;
1592
1593       begin
1594          --  Initialize all parameters to Empty
1595
1596          for J in Args'Range loop
1597             Args (J) := Empty;
1598          end loop;
1599
1600          --  That's all we have to do if there are no argument associations
1601
1602          if No (Pragma_Argument_Associations (N)) then
1603             return;
1604          end if;
1605
1606          --  Otherwise first deal with any positional parameters present
1607
1608          Arg := First (Pragma_Argument_Associations (N));
1609          for Index in Args'Range loop
1610             exit when No (Arg) or else Chars (Arg) /= No_Name;
1611             Args (Index) := Expression (Arg);
1612             Next (Arg);
1613          end loop;
1614
1615          --  Positional parameters all processed, if any left, then we
1616          --  have too many positional parameters.
1617
1618          if Present (Arg) and then Chars (Arg) = No_Name then
1619             Error_Pragma_Arg
1620               ("too many positional associations for pragma%", Arg);
1621          end if;
1622
1623          --  Process named parameters if any are present
1624
1625          while Present (Arg) loop
1626             if Chars (Arg) = No_Name then
1627                Error_Pragma_Arg
1628                  ("positional association cannot follow named association",
1629                   Arg);
1630
1631             else
1632                for Index in Names'Range loop
1633                   if Names (Index) = Chars (Arg) then
1634                      if Present (Args (Index)) then
1635                         Error_Pragma_Arg
1636                           ("duplicate argument association for pragma%", Arg);
1637                      else
1638                         Args (Index) := Expression (Arg);
1639                         exit;
1640                      end if;
1641                   end if;
1642
1643                   if Index = Names'Last then
1644                      Error_Msg_Name_1 := Chars (N);
1645                      Error_Msg_N ("pragma% does not allow & argument", Arg);
1646
1647                      --  Check for possible misspelling
1648
1649                      for Index1 in Names'Range loop
1650                         if Is_Bad_Spelling_Of
1651                              (Get_Name_String (Chars (Arg)),
1652                               Get_Name_String (Names (Index1)))
1653                         then
1654                            Error_Msg_Name_1 := Names (Index1);
1655                            Error_Msg_N ("\possible misspelling of%", Arg);
1656                            exit;
1657                         end if;
1658                      end loop;
1659
1660                      raise Pragma_Exit;
1661                   end if;
1662                end loop;
1663             end if;
1664
1665             Next (Arg);
1666          end loop;
1667       end Gather_Associations;
1668
1669       --------------------
1670       -- Get_Pragma_Arg --
1671       --------------------
1672
1673       function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1674       begin
1675          if Nkind (Arg) = N_Pragma_Argument_Association then
1676             return Expression (Arg);
1677          else
1678             return Arg;
1679          end if;
1680       end Get_Pragma_Arg;
1681
1682       -----------------
1683       -- GNAT_Pragma --
1684       -----------------
1685
1686       procedure GNAT_Pragma is
1687       begin
1688          Check_Restriction (No_Implementation_Pragmas, N);
1689       end GNAT_Pragma;
1690
1691       --------------------------
1692       -- Is_Before_First_Decl --
1693       --------------------------
1694
1695       function Is_Before_First_Decl
1696         (Pragma_Node : Node_Id;
1697          Decls       : List_Id) return Boolean
1698       is
1699          Item : Node_Id := First (Decls);
1700
1701       begin
1702          --  Only other pragmas can come before this pragma
1703
1704          loop
1705             if No (Item) or else Nkind (Item) /= N_Pragma then
1706                return False;
1707
1708             elsif Item = Pragma_Node then
1709                return True;
1710             end if;
1711
1712             Next (Item);
1713          end loop;
1714       end Is_Before_First_Decl;
1715
1716       -----------------------------
1717       -- Is_Configuration_Pragma --
1718       -----------------------------
1719
1720       --  A configuration pragma must appear in the context clause of
1721       --  a compilation unit, at the start of the list (i.e. only other
1722       --  pragmas may precede it).
1723
1724       function Is_Configuration_Pragma return Boolean is
1725          Lis : constant List_Id := List_Containing (N);
1726          Par : constant Node_Id := Parent (N);
1727          Prg : Node_Id;
1728
1729       begin
1730          --  If no parent, then we are in the configuration pragma file,
1731          --  so the placement is definitely appropriate.
1732
1733          if No (Par) then
1734             return True;
1735
1736          --  Otherwise we must be in the context clause of a compilation unit
1737          --  and the only thing allowed before us in the context list is more
1738          --  configuration pragmas.
1739
1740          elsif Nkind (Par) = N_Compilation_Unit
1741            and then Context_Items (Par) = Lis
1742          then
1743             Prg := First (Lis);
1744
1745             loop
1746                if Prg = N then
1747                   return True;
1748                elsif Nkind (Prg) /= N_Pragma then
1749                   return False;
1750                end if;
1751
1752                Next (Prg);
1753             end loop;
1754
1755          else
1756             return False;
1757          end if;
1758       end Is_Configuration_Pragma;
1759
1760       ----------------------
1761       -- Pragma_Misplaced --
1762       ----------------------
1763
1764       procedure Pragma_Misplaced is
1765       begin
1766          Error_Pragma ("incorrect placement of pragma%");
1767       end Pragma_Misplaced;
1768
1769       ------------------------------------
1770       -- Process Atomic_Shared_Volatile --
1771       ------------------------------------
1772
1773       procedure Process_Atomic_Shared_Volatile is
1774          E_Id : Node_Id;
1775          E    : Entity_Id;
1776          D    : Node_Id;
1777          K    : Node_Kind;
1778          Utyp : Entity_Id;
1779
1780          procedure Set_Atomic (E : Entity_Id);
1781          --  Set given type as atomic, and if no explicit alignment was
1782          --  given, set alignment to unknown, since back end knows what
1783          --  the alignment requirements are for atomic arrays. Note that
1784          --  this step is necessary for derived types.
1785
1786          ----------------
1787          -- Set_Atomic --
1788          ----------------
1789
1790          procedure Set_Atomic (E : Entity_Id) is
1791          begin
1792             Set_Is_Atomic (E);
1793
1794             if not Has_Alignment_Clause (E) then
1795                Set_Alignment (E, Uint_0);
1796             end if;
1797          end Set_Atomic;
1798
1799       --  Start of processing for Process_Atomic_Shared_Volatile
1800
1801       begin
1802          Check_Ada_83_Warning;
1803          Check_No_Identifiers;
1804          Check_Arg_Count (1);
1805          Check_Arg_Is_Local_Name (Arg1);
1806          E_Id := Expression (Arg1);
1807
1808          if Etype (E_Id) = Any_Type then
1809             return;
1810          end if;
1811
1812          E := Entity (E_Id);
1813          D := Declaration_Node (E);
1814          K := Nkind (D);
1815
1816          if Is_Type (E) then
1817             if Rep_Item_Too_Early (E, N)
1818                  or else
1819                Rep_Item_Too_Late (E, N)
1820             then
1821                return;
1822             else
1823                Check_First_Subtype (Arg1);
1824             end if;
1825
1826             if Prag_Id /= Pragma_Volatile then
1827                Set_Atomic (E);
1828                Set_Atomic (Underlying_Type (E));
1829                Set_Atomic (Base_Type (E));
1830             end if;
1831
1832             --  Attribute belongs on the base type. If the
1833             --  view of the type is currently private, it also
1834             --  belongs on the underlying type.
1835
1836             Set_Is_Volatile (Base_Type (E));
1837             Set_Is_Volatile (Underlying_Type (E));
1838
1839             Set_Treat_As_Volatile (E);
1840             Set_Treat_As_Volatile (Underlying_Type (E));
1841
1842          elsif K = N_Object_Declaration
1843            or else (K = N_Component_Declaration
1844                      and then Original_Record_Component (E) = E)
1845          then
1846             if Rep_Item_Too_Late (E, N) then
1847                return;
1848             end if;
1849
1850             if Prag_Id /= Pragma_Volatile then
1851                Set_Is_Atomic (E);
1852
1853                --  If the object declaration has an explicit
1854                --  initialization, a temporary may have to be
1855                --  created to hold the expression, to insure
1856                --  that access to the object remain atomic.
1857
1858                if Nkind (Parent (E)) = N_Object_Declaration
1859                  and then Present (Expression (Parent (E)))
1860                then
1861                   Set_Has_Delayed_Freeze (E);
1862                end if;
1863
1864                --  An interesting improvement here. If an object of type X
1865                --  is declared atomic, and the type X is not atomic, that's
1866                --  a pity, since it may not have appropraite alignment etc.
1867                --  We can rescue this in the special case where the object
1868                --  and type are in the same unit by just setting the type
1869                --  as atomic, so that the back end will process it as atomic.
1870
1871                Utyp := Underlying_Type (Etype (E));
1872
1873                if Present (Utyp)
1874                  and then Sloc (E) > No_Location
1875                  and then Sloc (Utyp) > No_Location
1876                  and then
1877                    Get_Source_File_Index (Sloc (E)) =
1878                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1879                then
1880                   Set_Is_Atomic (Underlying_Type (Etype (E)));
1881                end if;
1882             end if;
1883
1884             Set_Is_Volatile (E);
1885             Set_Treat_As_Volatile (E);
1886
1887          else
1888             Error_Pragma_Arg
1889               ("inappropriate entity for pragma%", Arg1);
1890          end if;
1891       end Process_Atomic_Shared_Volatile;
1892
1893       ------------------------
1894       -- Process_Convention --
1895       ------------------------
1896
1897       procedure Process_Convention
1898         (C : out Convention_Id;
1899          E : out Entity_Id)
1900       is
1901          Id        : Node_Id;
1902          E1        : Entity_Id;
1903          Cname     : Name_Id;
1904          Comp_Unit : Unit_Number_Type;
1905
1906          procedure Set_Convention_From_Pragma (E : Entity_Id);
1907          --  Set convention in entity E, and also flag that the entity has a
1908          --  convention pragma. If entity is for a private or incomplete type,
1909          --  also set convention and flag on underlying type. This procedure
1910          --  also deals with the special case of C_Pass_By_Copy convention.
1911
1912          --------------------------------
1913          -- Set_Convention_From_Pragma --
1914          --------------------------------
1915
1916          procedure Set_Convention_From_Pragma (E : Entity_Id) is
1917          begin
1918             Set_Convention (E, C);
1919             Set_Has_Convention_Pragma (E);
1920
1921             if Is_Incomplete_Or_Private_Type (E) then
1922                Set_Convention            (Underlying_Type (E), C);
1923                Set_Has_Convention_Pragma (Underlying_Type (E), True);
1924             end if;
1925
1926             --  A class-wide type should inherit the convention of
1927             --  the specific root type (although this isn't specified
1928             --  clearly by the RM).
1929
1930             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1931                Set_Convention (Class_Wide_Type (E), C);
1932             end if;
1933
1934             --  If the entity is a record type, then check for special case
1935             --  of C_Pass_By_Copy, which is treated the same as C except that
1936             --  the special record flag is set. This convention is also only
1937             --  permitted on record types (see AI95-00131).
1938
1939             if Cname = Name_C_Pass_By_Copy then
1940                if Is_Record_Type (E) then
1941                   Set_C_Pass_By_Copy (Base_Type (E));
1942                elsif Is_Incomplete_Or_Private_Type (E)
1943                  and then Is_Record_Type (Underlying_Type (E))
1944                then
1945                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
1946                else
1947                   Error_Pragma_Arg
1948                     ("C_Pass_By_Copy convention allowed only for record type",
1949                      Arg2);
1950                end if;
1951             end if;
1952
1953             --  If the entity is a derived boolean type, check for the
1954             --  special case of convention C, C++, or Fortran, where we
1955             --  consider any nonzero value to represent true.
1956
1957             if Is_Discrete_Type (E)
1958               and then Root_Type (Etype (E)) = Standard_Boolean
1959               and then
1960                 (C = Convention_C
1961                    or else
1962                  C = Convention_CPP
1963                    or else
1964                  C = Convention_Fortran)
1965             then
1966                Set_Nonzero_Is_True (Base_Type (E));
1967             end if;
1968          end Set_Convention_From_Pragma;
1969
1970       --  Start of processing for Process_Convention
1971
1972       begin
1973          Check_At_Least_N_Arguments (2);
1974          Check_Arg_Is_Identifier (Arg1);
1975          Check_Optional_Identifier (Arg1, Name_Convention);
1976          Cname := Chars (Expression (Arg1));
1977
1978          --  C_Pass_By_Copy is treated as a synonym for convention C
1979          --  (this is tested again below to set the critical flag)
1980
1981          if Cname = Name_C_Pass_By_Copy then
1982             C := Convention_C;
1983
1984          --  Otherwise we must have something in the standard convention list
1985
1986          elsif Is_Convention_Name (Cname) then
1987             C := Get_Convention_Id (Chars (Expression (Arg1)));
1988
1989          --  In DEC VMS, it seems that there is an undocumented feature
1990          --  that any unrecognized convention is treated as the default,
1991          --  which for us is convention C. It does not seem so terrible
1992          --  to do this unconditionally, silently in the VMS case, and
1993          --  with a warning in the non-VMS case.
1994
1995          else
1996             if Warn_On_Export_Import and not OpenVMS_On_Target then
1997                Error_Msg_N
1998                  ("?unrecognized convention name, C assumed",
1999                   Expression (Arg1));
2000             end if;
2001
2002             C := Convention_C;
2003          end if;
2004
2005          Check_Arg_Is_Local_Name (Arg2);
2006          Check_Optional_Identifier (Arg2, Name_Entity);
2007
2008          Id := Expression (Arg2);
2009          Analyze (Id);
2010
2011          if not Is_Entity_Name (Id) then
2012             Error_Pragma_Arg ("entity name required", Arg2);
2013          end if;
2014
2015          E := Entity (Id);
2016
2017          --  Go to renamed subprogram if present, since convention applies
2018          --  to the actual renamed entity, not to the renaming entity.
2019          --  If subprogram is inherited, go to parent subprogram.
2020
2021          if Is_Subprogram (E)
2022            and then Present (Alias (E))
2023          then
2024             if Nkind (Parent (Declaration_Node (E)))
2025               = N_Subprogram_Renaming_Declaration
2026             then
2027                E := Alias (E);
2028
2029             elsif Nkind (Parent (E)) = N_Full_Type_Declaration
2030               and then Scope (E) = Scope (Alias (E))
2031             then
2032                E := Alias (E);
2033             end if;
2034          end if;
2035
2036          --  Check that we are not applying this to a specless body
2037
2038          if Is_Subprogram (E)
2039            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2040          then
2041             Error_Pragma
2042               ("pragma% requires separate spec and must come before body");
2043          end if;
2044
2045          --  Check that we are not applying this to a named constant
2046
2047          if Ekind (E) = E_Named_Integer
2048               or else
2049             Ekind (E) = E_Named_Real
2050          then
2051             Error_Msg_Name_1 := Chars (N);
2052             Error_Msg_N
2053               ("cannot apply pragma% to named constant!",
2054                Get_Pragma_Arg (Arg2));
2055             Error_Pragma_Arg
2056               ("\supply appropriate type for&!", Arg2);
2057          end if;
2058
2059          if Etype (E) = Any_Type
2060            or else Rep_Item_Too_Early (E, N)
2061          then
2062             raise Pragma_Exit;
2063          else
2064             E := Underlying_Type (E);
2065          end if;
2066
2067          if Rep_Item_Too_Late (E, N) then
2068             raise Pragma_Exit;
2069          end if;
2070
2071          if Has_Convention_Pragma (E) then
2072             Error_Pragma_Arg
2073               ("at most one Convention/Export/Import pragma is allowed", Arg2);
2074
2075          elsif Convention (E) = Convention_Protected
2076            or else Ekind (Scope (E)) = E_Protected_Type
2077          then
2078             Error_Pragma_Arg
2079               ("a protected operation cannot be given a different convention",
2080                 Arg2);
2081          end if;
2082
2083          --  For Intrinsic, a subprogram is required
2084
2085          if C = Convention_Intrinsic
2086            and then not Is_Subprogram (E)
2087            and then not Is_Generic_Subprogram (E)
2088          then
2089             Error_Pragma_Arg
2090               ("second argument of pragma% must be a subprogram", Arg2);
2091          end if;
2092
2093          --  For Stdcall, a subprogram, variable or subprogram type is required
2094
2095          if C = Convention_Stdcall
2096            and then not Is_Subprogram (E)
2097            and then not Is_Generic_Subprogram (E)
2098            and then Ekind (E) /= E_Variable
2099            and then not
2100              (Is_Access_Type (E)
2101               and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2102          then
2103             Error_Pragma_Arg
2104               ("second argument of pragma% must be subprogram (type)",
2105                Arg2);
2106          end if;
2107
2108          if not Is_Subprogram (E)
2109            and then not Is_Generic_Subprogram (E)
2110          then
2111             Set_Convention_From_Pragma (E);
2112
2113             if Is_Type (E) then
2114
2115                Check_First_Subtype (Arg2);
2116                Set_Convention_From_Pragma (Base_Type (E));
2117
2118                --  For subprograms, we must set the convention on the
2119                --  internally generated directly designated type as well.
2120
2121                if Ekind (E) = E_Access_Subprogram_Type then
2122                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
2123                end if;
2124             end if;
2125
2126          --  For the subprogram case, set proper convention for all homonyms
2127          --  in same scope and the same declarative part, i.e. the same
2128          --  compilation unit.
2129
2130          else
2131             Comp_Unit := Get_Source_Unit (E);
2132             Set_Convention_From_Pragma (E);
2133
2134             --  Treat a pragma Import as an implicit body, for GPS use.
2135
2136             if Prag_Id = Pragma_Import then
2137                   Generate_Reference (E, Id, 'b');
2138             end if;
2139
2140             E1 := E;
2141             loop
2142                E1 := Homonym (E1);
2143                exit when No (E1) or else Scope (E1) /= Current_Scope;
2144
2145                --  Note: below we are missing a check for Rep_Item_Too_Late.
2146                --  That is deliberate, we cannot chain the rep item on more
2147                --  than one Rep_Item chain, to be fixed later ???
2148
2149                if Comes_From_Source (E1)
2150                  and then Comp_Unit = Get_Source_Unit (E1)
2151                  and then Nkind (Original_Node (Parent (E1))) /=
2152                    N_Full_Type_Declaration
2153                then
2154                   Set_Convention_From_Pragma (E1);
2155
2156                   if Prag_Id = Pragma_Import then
2157                      Generate_Reference (E, Id, 'b');
2158                   end if;
2159                end if;
2160             end loop;
2161          end if;
2162       end Process_Convention;
2163
2164       -----------------------------------------------------
2165       -- Process_Extended_Import_Export_Exception_Pragma --
2166       -----------------------------------------------------
2167
2168       procedure Process_Extended_Import_Export_Exception_Pragma
2169         (Arg_Internal : Node_Id;
2170          Arg_External : Node_Id;
2171          Arg_Form     : Node_Id;
2172          Arg_Code     : Node_Id)
2173       is
2174          Def_Id   : Entity_Id;
2175          Code_Val : Uint;
2176
2177       begin
2178          GNAT_Pragma;
2179
2180          if not OpenVMS_On_Target then
2181             Error_Pragma
2182               ("?pragma% ignored (applies only to Open'V'M'S)");
2183          end if;
2184
2185          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2186          Def_Id := Entity (Arg_Internal);
2187
2188          if Ekind (Def_Id) /= E_Exception then
2189             Error_Pragma_Arg
2190               ("pragma% must refer to declared exception", Arg_Internal);
2191          end if;
2192
2193          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2194
2195          if Present (Arg_Form) then
2196             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2197          end if;
2198
2199          if Present (Arg_Form)
2200            and then Chars (Arg_Form) = Name_Ada
2201          then
2202             null;
2203          else
2204             Set_Is_VMS_Exception (Def_Id);
2205             Set_Exception_Code (Def_Id, No_Uint);
2206          end if;
2207
2208          if Present (Arg_Code) then
2209             if not Is_VMS_Exception (Def_Id) then
2210                Error_Pragma_Arg
2211                  ("Code option for pragma% not allowed for Ada case",
2212                   Arg_Code);
2213             end if;
2214
2215             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2216             Code_Val := Expr_Value (Arg_Code);
2217
2218             if not UI_Is_In_Int_Range (Code_Val) then
2219                Error_Pragma_Arg
2220                  ("Code option for pragma% must be in 32-bit range",
2221                   Arg_Code);
2222
2223             else
2224                Set_Exception_Code (Def_Id, Code_Val);
2225             end if;
2226          end if;
2227       end Process_Extended_Import_Export_Exception_Pragma;
2228
2229       -------------------------------------------------
2230       -- Process_Extended_Import_Export_Internal_Arg --
2231       -------------------------------------------------
2232
2233       procedure Process_Extended_Import_Export_Internal_Arg
2234         (Arg_Internal : Node_Id := Empty)
2235       is
2236       begin
2237          GNAT_Pragma;
2238
2239          if No (Arg_Internal) then
2240             Error_Pragma ("Internal parameter required for pragma%");
2241          end if;
2242
2243          if Nkind (Arg_Internal) = N_Identifier then
2244             null;
2245
2246          elsif Nkind (Arg_Internal) = N_Operator_Symbol
2247            and then (Prag_Id = Pragma_Import_Function
2248                        or else
2249                      Prag_Id = Pragma_Export_Function)
2250          then
2251             null;
2252
2253          else
2254             Error_Pragma_Arg
2255               ("wrong form for Internal parameter for pragma%", Arg_Internal);
2256          end if;
2257
2258          Check_Arg_Is_Local_Name (Arg_Internal);
2259       end Process_Extended_Import_Export_Internal_Arg;
2260
2261       --------------------------------------------------
2262       -- Process_Extended_Import_Export_Object_Pragma --
2263       --------------------------------------------------
2264
2265       procedure Process_Extended_Import_Export_Object_Pragma
2266         (Arg_Internal : Node_Id;
2267          Arg_External : Node_Id;
2268          Arg_Size     : Node_Id)
2269       is
2270          Def_Id : Entity_Id;
2271
2272       begin
2273          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2274          Def_Id := Entity (Arg_Internal);
2275
2276          if Ekind (Def_Id) /= E_Constant
2277            and then Ekind (Def_Id) /= E_Variable
2278          then
2279             Error_Pragma_Arg
2280               ("pragma% must designate an object", Arg_Internal);
2281          end if;
2282
2283          if Is_Psected (Def_Id) then
2284             Error_Pragma_Arg
2285               ("previous Psect_Object applies, pragma % not permitted",
2286                Arg_Internal);
2287          end if;
2288
2289          if Rep_Item_Too_Late (Def_Id, N) then
2290             raise Pragma_Exit;
2291          end if;
2292
2293          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2294
2295          if Present (Arg_Size) then
2296             Check_Arg_Is_External_Name (Arg_Size);
2297          end if;
2298
2299          --  Export_Object case
2300
2301          if Prag_Id = Pragma_Export_Object then
2302             if not Is_Library_Level_Entity (Def_Id) then
2303                Error_Pragma_Arg
2304                  ("argument for pragma% must be library level entity",
2305                   Arg_Internal);
2306             end if;
2307
2308             if Ekind (Current_Scope) = E_Generic_Package then
2309                Error_Pragma ("pragma& cannot appear in a generic unit");
2310             end if;
2311
2312             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2313                Error_Pragma_Arg
2314                  ("exported object must have compile time known size",
2315                   Arg_Internal);
2316             end if;
2317
2318             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2319                Error_Msg_N
2320                  ("?duplicate Export_Object pragma", N);
2321             else
2322                Set_Exported (Def_Id, Arg_Internal);
2323             end if;
2324
2325          --  Import_Object case
2326
2327          else
2328             if Is_Concurrent_Type (Etype (Def_Id)) then
2329                Error_Pragma_Arg
2330                  ("cannot use pragma% for task/protected object",
2331                   Arg_Internal);
2332             end if;
2333
2334             if Ekind (Def_Id) = E_Constant then
2335                Error_Pragma_Arg
2336                  ("cannot import a constant", Arg_Internal);
2337             end if;
2338
2339             if Warn_On_Export_Import
2340               and then Has_Discriminants (Etype (Def_Id))
2341             then
2342                Error_Msg_N
2343                  ("imported value must be initialized?", Arg_Internal);
2344             end if;
2345
2346             if Warn_On_Export_Import
2347               and then Is_Access_Type (Etype (Def_Id))
2348             then
2349                Error_Pragma_Arg
2350                  ("cannot import object of an access type?", Arg_Internal);
2351             end if;
2352
2353             if Warn_On_Export_Import
2354               and then Is_Imported (Def_Id)
2355             then
2356                Error_Msg_N
2357                  ("?duplicate Import_Object pragma", N);
2358
2359             --  Check for explicit initialization present. Note that an
2360             --  initialization that generated by the code generator, e.g.
2361             --  for an access type, does not count here.
2362
2363             elsif Present (Expression (Parent (Def_Id)))
2364                and then
2365                  Comes_From_Source
2366                    (Original_Node (Expression (Parent (Def_Id))))
2367             then
2368                Error_Msg_Sloc := Sloc (Def_Id);
2369                Error_Pragma_Arg
2370                  ("no initialization allowed for declaration of& #",
2371                   "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2372                   Arg1);
2373             else
2374                Set_Imported (Def_Id);
2375                Note_Possible_Modification (Arg_Internal);
2376             end if;
2377          end if;
2378       end Process_Extended_Import_Export_Object_Pragma;
2379
2380       ------------------------------------------------------
2381       -- Process_Extended_Import_Export_Subprogram_Pragma --
2382       ------------------------------------------------------
2383
2384       procedure Process_Extended_Import_Export_Subprogram_Pragma
2385         (Arg_Internal                 : Node_Id;
2386          Arg_External                 : Node_Id;
2387          Arg_Parameter_Types          : Node_Id;
2388          Arg_Result_Type              : Node_Id := Empty;
2389          Arg_Mechanism                : Node_Id;
2390          Arg_Result_Mechanism         : Node_Id := Empty;
2391          Arg_First_Optional_Parameter : Node_Id := Empty)
2392       is
2393          Ent       : Entity_Id;
2394          Def_Id    : Entity_Id;
2395          Hom_Id    : Entity_Id;
2396          Formal    : Entity_Id;
2397          Ambiguous : Boolean;
2398          Match     : Boolean;
2399          Dval      : Node_Id;
2400
2401          function Same_Base_Type
2402           (Ptype  : Node_Id;
2403            Formal : Entity_Id) return Boolean;
2404          --  Determines if Ptype references the type of Formal. Note that
2405          --  only the base types need to match according to the spec. Ptype
2406          --  here is the argument from the pragma, which is either a type
2407          --  name, or an access attribute.
2408
2409          --------------------
2410          -- Same_Base_Type --
2411          --------------------
2412
2413          function Same_Base_Type
2414            (Ptype  : Node_Id;
2415             Formal : Entity_Id) return Boolean
2416          is
2417             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2418             Pref : Node_Id;
2419
2420          begin
2421             --  Case where pragma argument is typ'Access
2422
2423             if Nkind (Ptype) = N_Attribute_Reference
2424               and then Attribute_Name (Ptype) = Name_Access
2425             then
2426                Pref := Prefix (Ptype);
2427                Find_Type (Pref);
2428
2429                if not Is_Entity_Name (Pref)
2430                  or else Entity (Pref) = Any_Type
2431                then
2432                   raise Pragma_Exit;
2433                end if;
2434
2435                --  We have a match if the corresponding argument is of an
2436                --  anonymous access type, and its designicated type matches
2437                --  the type of the prefix of the access attribute
2438
2439                return Ekind (Ftyp) = E_Anonymous_Access_Type
2440                  and then Base_Type (Entity (Pref)) =
2441                             Base_Type (Etype (Designated_Type (Ftyp)));
2442
2443             --  Case where pragma argument is a type name
2444
2445             else
2446                Find_Type (Ptype);
2447
2448                if not Is_Entity_Name (Ptype)
2449                  or else Entity (Ptype) = Any_Type
2450                then
2451                   raise Pragma_Exit;
2452                end if;
2453
2454                --  We have a match if the corresponding argument is of
2455                --  the type given in the pragma (comparing base types)
2456
2457                return Base_Type (Entity (Ptype)) = Ftyp;
2458             end if;
2459          end Same_Base_Type;
2460
2461       --  Start of processing for
2462       --  Process_Extended_Import_Export_Subprogram_Pragma
2463
2464       begin
2465          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2466          Hom_Id := Entity (Arg_Internal);
2467          Ent := Empty;
2468          Ambiguous := False;
2469
2470          --  Loop through homonyms (overloadings) of Hom_Id
2471
2472          while Present (Hom_Id) loop
2473             Def_Id := Get_Base_Subprogram (Hom_Id);
2474
2475             --  We need a subprogram in the current scope
2476
2477             if not Is_Subprogram (Def_Id)
2478               or else Scope (Def_Id) /= Current_Scope
2479             then
2480                null;
2481
2482             else
2483                Match := True;
2484
2485                --  Pragma cannot apply to subprogram body
2486
2487                if Is_Subprogram (Def_Id)
2488                  and then
2489                    Nkind (Parent
2490                      (Declaration_Node (Def_Id))) = N_Subprogram_Body
2491                then
2492                   Error_Pragma
2493                     ("pragma% requires separate spec"
2494                       & " and must come before body");
2495                end if;
2496
2497                --  Test result type if given, note that the result type
2498                --  parameter can only be present for the function cases.
2499
2500                if Present (Arg_Result_Type)
2501                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2502                then
2503                   Match := False;
2504
2505                elsif Etype (Def_Id) /= Standard_Void_Type
2506                  and then
2507                    (Chars (N) = Name_Export_Procedure
2508                       or else Chars (N) = Name_Import_Procedure)
2509                then
2510                   Match := False;
2511
2512                --  Test parameter types if given. Note that this parameter
2513                --  has not been analyzed (and must not be, since it is
2514                --  semantic nonsense), so we get it as the parser left it.
2515
2516                elsif Present (Arg_Parameter_Types) then
2517                   Check_Matching_Types : declare
2518                      Formal : Entity_Id;
2519                      Ptype  : Node_Id;
2520
2521                   begin
2522                      Formal := First_Formal (Def_Id);
2523
2524                      if Nkind (Arg_Parameter_Types) = N_Null then
2525                         if Present (Formal) then
2526                            Match := False;
2527                         end if;
2528
2529                      --  A list of one type, e.g. (List) is parsed as
2530                      --  a parenthesized expression.
2531
2532                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2533                        and then Paren_Count (Arg_Parameter_Types) = 1
2534                      then
2535                         if No (Formal)
2536                           or else Present (Next_Formal (Formal))
2537                         then
2538                            Match := False;
2539                         else
2540                            Match :=
2541                              Same_Base_Type (Arg_Parameter_Types, Formal);
2542                         end if;
2543
2544                      --  A list of more than one type is parsed as a aggregate
2545
2546                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2547                        and then Paren_Count (Arg_Parameter_Types) = 0
2548                      then
2549                         Ptype := First (Expressions (Arg_Parameter_Types));
2550                         while Present (Ptype) or else Present (Formal) loop
2551                            if No (Ptype)
2552                              or else No (Formal)
2553                              or else not Same_Base_Type (Ptype, Formal)
2554                            then
2555                               Match := False;
2556                               exit;
2557                            else
2558                               Next_Formal (Formal);
2559                               Next (Ptype);
2560                            end if;
2561                         end loop;
2562
2563                      --  Anything else is of the wrong form
2564
2565                      else
2566                         Error_Pragma_Arg
2567                           ("wrong form for Parameter_Types parameter",
2568                            Arg_Parameter_Types);
2569                      end if;
2570                   end Check_Matching_Types;
2571                end if;
2572
2573                --  Match is now False if the entry we found did not match
2574                --  either a supplied Parameter_Types or Result_Types argument
2575
2576                if Match then
2577                   if No (Ent) then
2578                      Ent := Def_Id;
2579
2580                   --  Ambiguous case, the flag Ambiguous shows if we already
2581                   --  detected this and output the initial messages.
2582
2583                   else
2584                      if not Ambiguous then
2585                         Ambiguous := True;
2586                         Error_Msg_Name_1 := Chars (N);
2587                         Error_Msg_N
2588                           ("pragma% does not uniquely identify subprogram!",
2589                            N);
2590                         Error_Msg_Sloc := Sloc (Ent);
2591                         Error_Msg_N ("matching subprogram #!", N);
2592                         Ent := Empty;
2593                      end if;
2594
2595                      Error_Msg_Sloc := Sloc (Def_Id);
2596                      Error_Msg_N ("matching subprogram #!", N);
2597                   end if;
2598                end if;
2599             end if;
2600
2601             Hom_Id := Homonym (Hom_Id);
2602          end loop;
2603
2604          --  See if we found an entry
2605
2606          if No (Ent) then
2607             if not Ambiguous then
2608                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2609                   Error_Pragma
2610                     ("pragma% cannot be given for generic subprogram");
2611
2612                else
2613                   Error_Pragma
2614                     ("pragma% does not identify local subprogram");
2615                end if;
2616             end if;
2617
2618             return;
2619          end if;
2620
2621          --  Import pragmas must be be for imported entities
2622
2623          if Prag_Id = Pragma_Import_Function
2624               or else
2625             Prag_Id = Pragma_Import_Procedure
2626               or else
2627             Prag_Id = Pragma_Import_Valued_Procedure
2628          then
2629             if not Is_Imported (Ent) then
2630                Error_Pragma
2631                  ("pragma Import or Interface must precede pragma%");
2632             end if;
2633
2634          --  Here we have the Export case which can set the entity as exported
2635
2636          --  But does not do so if the specified external name is null,
2637          --  since that is taken as a signal in DEC Ada 83 (with which
2638          --  we want to be compatible) to request no external name.
2639
2640          elsif Nkind (Arg_External) = N_String_Literal
2641            and then String_Length (Strval (Arg_External)) = 0
2642          then
2643             null;
2644
2645          --  In all other cases, set entit as exported
2646
2647          else
2648             Set_Exported (Ent, Arg_Internal);
2649          end if;
2650
2651          --  Special processing for Valued_Procedure cases
2652
2653          if Prag_Id = Pragma_Import_Valued_Procedure
2654            or else
2655             Prag_Id = Pragma_Export_Valued_Procedure
2656          then
2657             Formal := First_Formal (Ent);
2658
2659             if No (Formal) then
2660                Error_Pragma
2661                  ("at least one parameter required for pragma%");
2662
2663             elsif Ekind (Formal) /= E_Out_Parameter then
2664                Error_Pragma
2665                  ("first parameter must have mode out for pragma%");
2666
2667             else
2668                Set_Is_Valued_Procedure (Ent);
2669             end if;
2670          end if;
2671
2672          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2673
2674          --  Process Result_Mechanism argument if present. We have already
2675          --  checked that this is only allowed for the function case.
2676
2677          if Present (Arg_Result_Mechanism) then
2678             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2679          end if;
2680
2681          --  Process Mechanism parameter if present. Note that this parameter
2682          --  is not analyzed, and must not be analyzed since it is semantic
2683          --  nonsense, so we get it in exactly as the parser left it.
2684
2685          if Present (Arg_Mechanism) then
2686             declare
2687                Formal : Entity_Id;
2688                Massoc : Node_Id;
2689                Mname  : Node_Id;
2690                Choice : Node_Id;
2691
2692             begin
2693                --  A single mechanism association without a formal parameter
2694                --  name is parsed as a parenthesized expression. All other
2695                --  cases are parsed as aggregates, so we rewrite the single
2696                --  parameter case as an aggregate for consistency.
2697
2698                if Nkind (Arg_Mechanism) /= N_Aggregate
2699                  and then Paren_Count (Arg_Mechanism) = 1
2700                then
2701                   Rewrite (Arg_Mechanism,
2702                     Make_Aggregate (Sloc (Arg_Mechanism),
2703                       Expressions => New_List (
2704                         Relocate_Node (Arg_Mechanism))));
2705                end if;
2706
2707                --  Case of only mechanism name given, applies to all formals
2708
2709                if Nkind (Arg_Mechanism) /= N_Aggregate then
2710                   Formal := First_Formal (Ent);
2711                   while Present (Formal) loop
2712                      Set_Mechanism_Value (Formal, Arg_Mechanism);
2713                      Next_Formal (Formal);
2714                   end loop;
2715
2716                --  Case of list of mechanism associations given
2717
2718                else
2719                   if Null_Record_Present (Arg_Mechanism) then
2720                      Error_Pragma_Arg
2721                        ("inappropriate form for Mechanism parameter",
2722                         Arg_Mechanism);
2723                   end if;
2724
2725                   --  Deal with positional ones first
2726
2727                   Formal := First_Formal (Ent);
2728
2729                   if Present (Expressions (Arg_Mechanism)) then
2730                      Mname := First (Expressions (Arg_Mechanism));
2731
2732                      while Present (Mname) loop
2733                         if No (Formal) then
2734                            Error_Pragma_Arg
2735                              ("too many mechanism associations", Mname);
2736                         end if;
2737
2738                         Set_Mechanism_Value (Formal, Mname);
2739                         Next_Formal (Formal);
2740                         Next (Mname);
2741                      end loop;
2742                   end if;
2743
2744                   --  Deal with named entries
2745
2746                   if Present (Component_Associations (Arg_Mechanism)) then
2747                      Massoc := First (Component_Associations (Arg_Mechanism));
2748
2749                      while Present (Massoc) loop
2750                         Choice := First (Choices (Massoc));
2751
2752                         if Nkind (Choice) /= N_Identifier
2753                           or else Present (Next (Choice))
2754                         then
2755                            Error_Pragma_Arg
2756                              ("incorrect form for mechanism association",
2757                               Massoc);
2758                         end if;
2759
2760                         Formal := First_Formal (Ent);
2761                         loop
2762                            if No (Formal) then
2763                               Error_Pragma_Arg
2764                                 ("parameter name & not present", Choice);
2765                            end if;
2766
2767                            if Chars (Choice) = Chars (Formal) then
2768                               Set_Mechanism_Value
2769                                 (Formal, Expression (Massoc));
2770                               exit;
2771                            end if;
2772
2773                            Next_Formal (Formal);
2774                         end loop;
2775
2776                         Next (Massoc);
2777                      end loop;
2778                   end if;
2779                end if;
2780             end;
2781          end if;
2782
2783          --  Process First_Optional_Parameter argument if present. We have
2784          --  already checked that this is only allowed for the Import case.
2785
2786          if Present (Arg_First_Optional_Parameter) then
2787             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2788                Error_Pragma_Arg
2789                  ("first optional parameter must be formal parameter name",
2790                   Arg_First_Optional_Parameter);
2791             end if;
2792
2793             Formal := First_Formal (Ent);
2794             loop
2795                if No (Formal) then
2796                   Error_Pragma_Arg
2797                     ("specified formal parameter& not found",
2798                      Arg_First_Optional_Parameter);
2799                end if;
2800
2801                exit when Chars (Formal) =
2802                          Chars (Arg_First_Optional_Parameter);
2803
2804                Next_Formal (Formal);
2805             end loop;
2806
2807             Set_First_Optional_Parameter (Ent, Formal);
2808
2809             --  Check specified and all remaining formals have right form
2810
2811             while Present (Formal) loop
2812                if Ekind (Formal) /= E_In_Parameter then
2813                   Error_Msg_NE
2814                     ("optional formal& is not of mode in!",
2815                      Arg_First_Optional_Parameter, Formal);
2816
2817                else
2818                   Dval := Default_Value (Formal);
2819
2820                   if not Present (Dval) then
2821                      Error_Msg_NE
2822                        ("optional formal& does not have default value!",
2823                         Arg_First_Optional_Parameter, Formal);
2824
2825                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2826                      null;
2827
2828                   else
2829                      Error_Msg_FE
2830                        ("default value for optional formal& is non-static!",
2831                         Arg_First_Optional_Parameter, Formal);
2832                   end if;
2833                end if;
2834
2835                Set_Is_Optional_Parameter (Formal);
2836                Next_Formal (Formal);
2837             end loop;
2838          end if;
2839       end Process_Extended_Import_Export_Subprogram_Pragma;
2840
2841       --------------------------
2842       -- Process_Generic_List --
2843       --------------------------
2844
2845       procedure Process_Generic_List is
2846          Arg : Node_Id;
2847          Exp : Node_Id;
2848
2849       begin
2850          GNAT_Pragma;
2851          Check_No_Identifiers;
2852          Check_At_Least_N_Arguments (1);
2853
2854          Arg := Arg1;
2855          while Present (Arg) loop
2856             Exp := Expression (Arg);
2857             Analyze (Exp);
2858
2859             if not Is_Entity_Name (Exp)
2860               or else
2861                 (not Is_Generic_Instance (Entity (Exp))
2862                   and then
2863                  not Is_Generic_Unit (Entity (Exp)))
2864             then
2865                Error_Pragma_Arg
2866                  ("pragma% argument must be name of generic unit/instance",
2867                   Arg);
2868             end if;
2869
2870             Next (Arg);
2871          end loop;
2872       end Process_Generic_List;
2873
2874       ---------------------------------
2875       -- Process_Import_Or_Interface --
2876       ---------------------------------
2877
2878       procedure Process_Import_Or_Interface is
2879          C      : Convention_Id;
2880          Def_Id : Entity_Id;
2881          Hom_Id : Entity_Id;
2882
2883       begin
2884          Process_Convention (C, Def_Id);
2885          Kill_Size_Check_Code (Def_Id);
2886          Note_Possible_Modification (Expression (Arg2));
2887
2888          if Ekind (Def_Id) = E_Variable
2889               or else
2890             Ekind (Def_Id) = E_Constant
2891          then
2892             --  User initialization is not allowed for imported object, but
2893             --  the object declaration may contain a default initialization,
2894             --  that will be discarded. Note that an explicit initialization
2895             --  only counts if it comes from source, otherwise it is simply
2896             --  the code generator making an implicit initialization explicit.
2897
2898             if Present (Expression (Parent (Def_Id)))
2899                and then Comes_From_Source (Expression (Parent (Def_Id)))
2900             then
2901                Error_Msg_Sloc := Sloc (Def_Id);
2902                Error_Pragma_Arg
2903                  ("no initialization allowed for declaration of& #",
2904                   "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2905                   Arg2);
2906
2907             else
2908                Set_Imported (Def_Id);
2909                Process_Interface_Name (Def_Id, Arg3, Arg4);
2910
2911                --  Note that we do not set Is_Public here. That's because we
2912                --  only want to set if if there is no address clause, and we
2913                --  don't know that yet, so we delay that processing till
2914                --  freeze time.
2915
2916                --  pragma Import completes deferred constants
2917
2918                if Ekind (Def_Id) = E_Constant then
2919                   Set_Has_Completion (Def_Id);
2920                end if;
2921
2922                --  It is not possible to import a constant of an unconstrained
2923                --  array type (e.g. string) because there is no simple way to
2924                --  write a meaningful subtype for it.
2925
2926                if Is_Array_Type (Etype (Def_Id))
2927                  and then not Is_Constrained (Etype (Def_Id))
2928                then
2929                   Error_Msg_NE
2930                     ("imported constant& must have a constrained subtype",
2931                       N, Def_Id);
2932                end if;
2933             end if;
2934
2935          elsif Is_Subprogram (Def_Id)
2936            or else Is_Generic_Subprogram (Def_Id)
2937          then
2938             --  If the name is overloaded, pragma applies to all of the
2939             --  denoted entities in the same declarative part.
2940
2941             Hom_Id := Def_Id;
2942             while Present (Hom_Id) loop
2943                Def_Id := Get_Base_Subprogram (Hom_Id);
2944
2945                --  Ignore inherited subprograms because the pragma will
2946                --  apply to the parent operation, which is the one called.
2947
2948                if Is_Overloadable (Def_Id)
2949                  and then Present (Alias (Def_Id))
2950                then
2951                   null;
2952
2953                --  If it is not a subprogram, it must be in an outer
2954                --  scope and pragma does not apply.
2955
2956                elsif not Is_Subprogram (Def_Id)
2957                  and then not Is_Generic_Subprogram (Def_Id)
2958                then
2959                   null;
2960
2961                --  Verify that the homonym is in the same declarative
2962                --  part (not just the same scope).
2963
2964                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
2965                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
2966                then
2967                   exit;
2968
2969                else
2970                   Set_Imported (Def_Id);
2971
2972                   --  If Import intrinsic, set intrinsic flag and verify
2973                   --  that it is known as such.
2974
2975                   if C = Convention_Intrinsic then
2976                      Set_Is_Intrinsic_Subprogram (Def_Id);
2977                      Check_Intrinsic_Subprogram
2978                        (Def_Id, Expression (Arg2));
2979                   end if;
2980
2981                   --  All interfaced procedures need an external symbol
2982                   --  created for them since they are always referenced
2983                   --  from another object file.
2984
2985                   Set_Is_Public (Def_Id);
2986
2987                   --  Verify that the subprogram does not have a completion
2988                   --  through a renaming declaration. For other completions
2989                   --  the pragma appears as a too late representation.
2990
2991                   declare
2992                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
2993
2994                   begin
2995                      if Present (Decl)
2996                        and then Nkind (Decl) = N_Subprogram_Declaration
2997                        and then Present (Corresponding_Body (Decl))
2998                        and then
2999                          Nkind
3000                            (Unit_Declaration_Node
3001                              (Corresponding_Body (Decl))) =
3002                                              N_Subprogram_Renaming_Declaration
3003                      then
3004                         Error_Msg_Sloc := Sloc (Def_Id);
3005                         Error_Msg_NE ("cannot import&#," &
3006                            " already completed by a renaming",
3007                            N, Def_Id);
3008                      end if;
3009                   end;
3010
3011                   Set_Has_Completion (Def_Id);
3012                   Process_Interface_Name (Def_Id, Arg3, Arg4);
3013                end if;
3014
3015                if Is_Compilation_Unit (Hom_Id) then
3016
3017                   --  Its possible homonyms are not affected by the pragma.
3018                   --  Such homonyms might be present in the context of other
3019                   --  units being compiled.
3020
3021                   exit;
3022
3023                else
3024                   Hom_Id := Homonym (Hom_Id);
3025                end if;
3026             end loop;
3027
3028          --  When the convention is Java, we also allow Import to be given
3029          --  for packages, exceptions, and record components.
3030
3031          elsif C = Convention_Java
3032            and then
3033              (Ekind (Def_Id) = E_Package
3034                 or else Ekind (Def_Id) = E_Exception
3035                 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3036          then
3037             Set_Imported (Def_Id);
3038             Set_Is_Public (Def_Id);
3039             Process_Interface_Name (Def_Id, Arg3, Arg4);
3040
3041          else
3042             Error_Pragma_Arg
3043               ("second argument of pragma% must be object or subprogram",
3044                Arg2);
3045          end if;
3046
3047          --  If this pragma applies to a compilation unit, then the unit,
3048          --  which is a subprogram, does not require (or allow) a body.
3049          --  We also do not need to elaborate imported procedures.
3050
3051          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3052             declare
3053                Cunit : constant Node_Id := Parent (Parent (N));
3054             begin
3055                Set_Body_Required (Cunit, False);
3056             end;
3057          end if;
3058       end Process_Import_Or_Interface;
3059
3060       --------------------
3061       -- Process_Inline --
3062       --------------------
3063
3064       procedure Process_Inline (Active : Boolean) is
3065          Assoc     : Node_Id;
3066          Decl      : Node_Id;
3067          Subp_Id   : Node_Id;
3068          Subp      : Entity_Id;
3069          Applies   : Boolean;
3070          Effective : Boolean := False;
3071
3072          procedure Make_Inline (Subp : Entity_Id);
3073          --  Subp is the defining unit name of the subprogram
3074          --  declaration. Set the flag, as well as the flag in the
3075          --  corresponding body, if there is one present.
3076
3077          procedure Set_Inline_Flags (Subp : Entity_Id);
3078          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp
3079
3080          function Cannot_Inline (Subp : Entity_Id) return Boolean;
3081          --  Do not set the inline flag if body is available and contains
3082          --  exception handlers, to prevent undefined symbols at link time.
3083          --  Emit warning if front-end inlining is enabled and the pragma
3084          --  appears too late.
3085
3086          -------------------
3087          -- Cannot_Inline --
3088          -------------------
3089
3090          function Cannot_Inline (Subp : Entity_Id) return Boolean is
3091             Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3092
3093          begin
3094             if Nkind (Decl) = N_Subprogram_Body then
3095                return
3096                  Present
3097                    (Exception_Handlers (Handled_Statement_Sequence (Decl)));
3098
3099             elsif Nkind (Decl) = N_Subprogram_Declaration
3100               and then Present (Corresponding_Body (Decl))
3101             then
3102                if Front_End_Inlining
3103                  and then Analyzed (Corresponding_Body (Decl))
3104                then
3105                   Error_Msg_N ("pragma appears too late, ignored?", N);
3106                   return True;
3107
3108                --  If the subprogram is a renaming as body, the body is
3109                --  just a call to the renamed subprogram, and inlining is
3110                --  trivially possible.
3111
3112                elsif
3113                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
3114                    = N_Subprogram_Renaming_Declaration
3115                then
3116                   return False;
3117
3118                else
3119                   return
3120                     Present (Exception_Handlers
3121                       (Handled_Statement_Sequence
3122                         (Unit_Declaration_Node (Corresponding_Body (Decl)))));
3123                end if;
3124             else
3125                --  If body is not available, assume the best, the check is
3126                --  performed again when compiling enclosing package bodies.
3127
3128                return False;
3129             end if;
3130          end Cannot_Inline;
3131
3132          -----------------
3133          -- Make_Inline --
3134          -----------------
3135
3136          procedure Make_Inline (Subp : Entity_Id) is
3137             Kind       : constant Entity_Kind := Ekind (Subp);
3138             Inner_Subp : Entity_Id   := Subp;
3139
3140          begin
3141             if Etype (Subp) = Any_Type then
3142                return;
3143
3144             elsif Cannot_Inline (Subp) then
3145                Applies := True;    --  Do not treat as an error.
3146                return;
3147
3148             --  Here we have a candidate for inlining, but we must exclude
3149             --  derived operations. Otherwise we will end up trying to
3150             --  inline a phantom declaration, and the result would be to
3151             --  drag in a body which has no direct inlining associated with
3152             --  it. That would not only be inefficient but would also result
3153             --  in the backend doing cross-unit inlining in cases where it
3154             --  was definitely inappropriate to do so.
3155
3156             --  However, a simple Comes_From_Source test is insufficient,
3157             --  since we do want to allow inlining of generic instances,
3158             --  which also do not come from source. Predefined operators do
3159             --  not come from source but are not inlineable either.
3160
3161             elsif not Comes_From_Source (Subp)
3162               and then not Is_Generic_Instance (Subp)
3163               and then Scope (Subp) /= Standard_Standard
3164             then
3165                Applies := True;
3166                return;
3167
3168             --  The referenced entity must either be the enclosing entity,
3169             --  or an entity declared within the current open scope.
3170
3171             elsif Present (Scope (Subp))
3172               and then Scope (Subp) /= Current_Scope
3173               and then Subp /= Current_Scope
3174             then
3175                Error_Pragma_Arg
3176                  ("argument of% must be entity in current scope", Assoc);
3177                return;
3178             end if;
3179
3180             --  Processing for procedure, operator or function.
3181             --  If subprogram is aliased (as for an instance) indicate
3182             --  that the renamed entity (if declared in the same unit)
3183             --  is inlined.
3184
3185             if Is_Subprogram (Subp) then
3186                while Present (Alias (Inner_Subp)) loop
3187                   Inner_Subp := Alias (Inner_Subp);
3188                end loop;
3189
3190                if In_Same_Source_Unit (Subp, Inner_Subp) then
3191                   Set_Inline_Flags (Inner_Subp);
3192
3193                   Decl := Parent (Parent (Inner_Subp));
3194
3195                   if Nkind (Decl) = N_Subprogram_Declaration
3196                     and then Present (Corresponding_Body (Decl))
3197                   then
3198                      Set_Inline_Flags (Corresponding_Body (Decl));
3199                   end if;
3200                end if;
3201
3202                Applies := True;
3203
3204             --  For a generic subprogram set flag as well, for use at
3205             --  the point of instantiation, to determine whether the
3206             --  body should be generated.
3207
3208             elsif Is_Generic_Subprogram (Subp) then
3209                Set_Inline_Flags (Subp);
3210                Applies := True;
3211
3212             --  Literals are by definition inlined
3213
3214             elsif Kind = E_Enumeration_Literal then
3215                null;
3216
3217             --  Anything else is an error
3218
3219             else
3220                Error_Pragma_Arg
3221                  ("expect subprogram name for pragma%", Assoc);
3222             end if;
3223          end Make_Inline;
3224
3225          ----------------------
3226          -- Set_Inline_Flags --
3227          ----------------------
3228
3229          procedure Set_Inline_Flags (Subp : Entity_Id) is
3230          begin
3231             if Active then
3232                Set_Is_Inlined (Subp, True);
3233             end if;
3234
3235             if not Has_Pragma_Inline (Subp) then
3236                Set_Has_Pragma_Inline (Subp);
3237                Set_Next_Rep_Item (N, First_Rep_Item (Subp));
3238                Set_First_Rep_Item (Subp, N);
3239                Effective := True;
3240             end if;
3241          end Set_Inline_Flags;
3242
3243       --  Start of processing for Process_Inline
3244
3245       begin
3246          Check_No_Identifiers;
3247          Check_At_Least_N_Arguments (1);
3248
3249          if Active then
3250             Inline_Processing_Required := True;
3251          end if;
3252
3253          Assoc := Arg1;
3254          while Present (Assoc) loop
3255             Subp_Id := Expression (Assoc);
3256             Analyze (Subp_Id);
3257             Applies := False;
3258
3259             if Is_Entity_Name (Subp_Id) then
3260                Subp := Entity (Subp_Id);
3261
3262                if Subp = Any_Id then
3263                   Applies := True;
3264
3265                else
3266                   Make_Inline (Subp);
3267
3268                   while Present (Homonym (Subp))
3269                     and then Scope (Homonym (Subp)) = Current_Scope
3270                   loop
3271                      Make_Inline (Homonym (Subp));
3272                      Subp := Homonym (Subp);
3273                   end loop;
3274                end if;
3275             end if;
3276
3277             if not Applies then
3278                Error_Pragma_Arg
3279                  ("inappropriate argument for pragma%", Assoc);
3280
3281             elsif not Effective
3282               and then Warn_On_Redundant_Constructs
3283             then
3284                Error_Msg_NE ("pragma Inline for& is redundant?",
3285                  N, Entity (Subp_Id));
3286             end if;
3287
3288             Next (Assoc);
3289          end loop;
3290       end Process_Inline;
3291
3292       ----------------------------
3293       -- Process_Interface_Name --
3294       ----------------------------
3295
3296       procedure Process_Interface_Name
3297         (Subprogram_Def : Entity_Id;
3298          Ext_Arg        : Node_Id;
3299          Link_Arg       : Node_Id)
3300       is
3301          Ext_Nam    : Node_Id;
3302          Link_Nam   : Node_Id;
3303          String_Val : String_Id;
3304
3305          procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3306          --  SN is a string literal node for an interface name. This routine
3307          --  performs some minimal checks that the name is reasonable. In
3308          --  particular that no spaces or other obviously incorrect characters
3309          --  appear. This is only a warning, since any characters are allowed.
3310
3311          ----------------------------------
3312          -- Check_Form_Of_Interface_Name --
3313          ----------------------------------
3314
3315          procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3316             S  : constant String_Id := Strval (Expr_Value_S (SN));
3317             SL : constant Nat       := String_Length (S);
3318             C  : Char_Code;
3319
3320          begin
3321             if SL = 0 then
3322                Error_Msg_N ("interface name cannot be null string", SN);
3323             end if;
3324
3325             for J in 1 .. SL loop
3326                C := Get_String_Char (S, J);
3327
3328                if Warn_On_Export_Import
3329                  and then (not In_Character_Range (C)
3330                              or else Get_Character (C) = ' '
3331                              or else Get_Character (C) = ',')
3332                then
3333                   Error_Msg_N
3334                     ("?interface name contains illegal character", SN);
3335                end if;
3336             end loop;
3337          end Check_Form_Of_Interface_Name;
3338
3339       --  Start of processing for Process_Interface_Name
3340
3341       begin
3342          if No (Link_Arg) then
3343             if No (Ext_Arg) then
3344                return;
3345
3346             elsif Chars (Ext_Arg) = Name_Link_Name then
3347                Ext_Nam  := Empty;
3348                Link_Nam := Expression (Ext_Arg);
3349
3350             else
3351                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3352                Ext_Nam  := Expression (Ext_Arg);
3353                Link_Nam := Empty;
3354             end if;
3355
3356          else
3357             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
3358             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3359             Ext_Nam  := Expression (Ext_Arg);
3360             Link_Nam := Expression (Link_Arg);
3361          end if;
3362
3363          --  Check expressions for external name and link name are static
3364
3365          if Present (Ext_Nam) then
3366             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3367             Check_Form_Of_Interface_Name (Ext_Nam);
3368
3369             --  Verify that the external name is not the name of a local
3370             --  entity, which would hide the imported one and lead to
3371             --  run-time surprises. The problem can only arise for entities
3372             --  declared in a package body (otherwise the external name is
3373             --  fully qualified and won't conflict).
3374
3375             declare
3376                Nam : Name_Id;
3377                E   : Entity_Id;
3378                Par : Node_Id;
3379
3380             begin
3381                if Prag_Id = Pragma_Import then
3382                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3383                   Nam := Name_Find;
3384                   E   := Entity_Id (Get_Name_Table_Info (Nam));
3385
3386                   if Nam /= Chars (Subprogram_Def)
3387                     and then Present (E)
3388                     and then not Is_Overloadable (E)
3389                     and then Is_Immediately_Visible (E)
3390                     and then not Is_Imported (E)
3391                     and then Ekind (Scope (E)) = E_Package
3392                   then
3393                      Par := Parent (E);
3394
3395                      while Present (Par) loop
3396                         if Nkind (Par) = N_Package_Body then
3397                            Error_Msg_Sloc  := Sloc (E);
3398                            Error_Msg_NE
3399                              ("imported entity is hidden by & declared#",
3400                                  Ext_Arg, E);
3401                            exit;
3402                         end if;
3403
3404                         Par := Parent (Par);
3405                      end loop;
3406                   end if;
3407                end if;
3408             end;
3409          end if;
3410
3411          if Present (Link_Nam) then
3412             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3413             Check_Form_Of_Interface_Name (Link_Nam);
3414          end if;
3415
3416          --  If there is no link name, just set the external name
3417
3418          if No (Link_Nam) then
3419             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
3420
3421          --  For the Link_Name case, the given literal is preceded by an
3422          --  asterisk, which indicates to GCC that the given name should
3423          --  be taken literally, and in particular that no prepending of
3424          --  underlines should occur, even in systems where this is the
3425          --  normal default.
3426
3427          else
3428             Start_String;
3429             Store_String_Char (Get_Char_Code ('*'));
3430             String_Val := Strval (Expr_Value_S (Link_Nam));
3431
3432             for J in 1 .. String_Length (String_Val) loop
3433                Store_String_Char (Get_String_Char (String_Val, J));
3434             end loop;
3435
3436             Link_Nam :=
3437               Make_String_Literal (Sloc (Link_Nam), End_String);
3438          end if;
3439
3440          Set_Encoded_Interface_Name
3441            (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3442          Check_Duplicated_Export_Name (Link_Nam);
3443       end Process_Interface_Name;
3444
3445       -----------------------------------------
3446       -- Process_Interrupt_Or_Attach_Handler --
3447       -----------------------------------------
3448
3449       procedure Process_Interrupt_Or_Attach_Handler is
3450          Arg1_X       : constant Node_Id   := Expression (Arg1);
3451          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3452          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
3453
3454       begin
3455          Set_Is_Interrupt_Handler (Handler_Proc);
3456
3457          --  If the pragma is not associated with a handler procedure
3458          --  within a protected type, then it must be for a nonprotected
3459          --  procedure for the AAMP target, in which case we don't
3460          --  associate a representation item with the procedure's scope.
3461
3462          if Ekind (Proc_Scope) = E_Protected_Type then
3463             if Prag_Id = Pragma_Interrupt_Handler
3464                  or else
3465                Prag_Id = Pragma_Attach_Handler
3466             then
3467                Record_Rep_Item (Proc_Scope, N);
3468             end if;
3469          end if;
3470       end Process_Interrupt_Or_Attach_Handler;
3471
3472       --------------------------------------------------
3473       -- Process_Restrictions_Or_Restriction_Warnings --
3474       --------------------------------------------------
3475
3476       procedure Process_Restrictions_Or_Restriction_Warnings is
3477          Arg   : Node_Id;
3478          R_Id  : Restriction_Id;
3479          Id    : Name_Id;
3480          Expr  : Node_Id;
3481          Val   : Uint;
3482
3483          procedure Set_Warning (R : All_Restrictions);
3484          --  If this is a Restriction_Warnings pragma, set warning flag,
3485          --  otherwise reset the flag.
3486
3487          -----------------
3488          -- Set_Warning --
3489          -----------------
3490
3491          procedure Set_Warning (R : All_Restrictions) is
3492          begin
3493             if Prag_Id = Pragma_Restriction_Warnings then
3494                Restriction_Warnings (R) := True;
3495             else
3496                Restriction_Warnings (R) := False;
3497             end if;
3498          end Set_Warning;
3499
3500       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
3501
3502       begin
3503          Check_Ada_83_Warning;
3504          Check_At_Least_N_Arguments (1);
3505          Check_Valid_Configuration_Pragma;
3506
3507          Arg := Arg1;
3508          while Present (Arg) loop
3509             Id := Chars (Arg);
3510             Expr := Expression (Arg);
3511
3512             --  Case of no restriction identifier present
3513
3514             if Id = No_Name then
3515                if Nkind (Expr) /= N_Identifier then
3516                   Error_Pragma_Arg
3517                     ("invalid form for restriction", Arg);
3518                end if;
3519
3520                R_Id :=
3521                  Get_Restriction_Id
3522                    (Process_Restriction_Synonyms (Expr));
3523
3524                if R_Id not in All_Boolean_Restrictions then
3525                   Error_Pragma_Arg
3526                     ("invalid restriction identifier", Arg);
3527                end if;
3528
3529                if Implementation_Restriction (R_Id) then
3530                   Check_Restriction
3531                     (No_Implementation_Restrictions, Arg);
3532                end if;
3533
3534                Set_Restriction (R_Id, N);
3535                Set_Warning (R_Id);
3536
3537                --  A very special case that must be processed here:
3538                --  pragma Restrictions (No_Exceptions) turns off
3539                --  all run-time checking. This is a bit dubious in
3540                --  terms of the formal language definition, but it
3541                --  is what is intended by RM H.4(12).
3542
3543                if R_Id = No_Exceptions then
3544                   Scope_Suppress := (others => True);
3545                end if;
3546
3547             --  Case of restriction identifier present
3548
3549             else
3550                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
3551                Analyze_And_Resolve (Expr, Any_Integer);
3552
3553                if R_Id not in All_Parameter_Restrictions then
3554                   Error_Pragma_Arg
3555                     ("invalid restriction parameter identifier", Arg);
3556
3557                elsif not Is_OK_Static_Expression (Expr) then
3558                   Flag_Non_Static_Expr
3559                     ("value must be static expression!", Expr);
3560                   raise Pragma_Exit;
3561
3562                elsif not Is_Integer_Type (Etype (Expr))
3563                  or else Expr_Value (Expr) < 0
3564                then
3565                   Error_Pragma_Arg
3566                     ("value must be non-negative integer", Arg);
3567
3568                   --  Restriction pragma is active
3569
3570                else
3571                   Val := Expr_Value (Expr);
3572
3573                   if not UI_Is_In_Int_Range (Val) then
3574                      Error_Pragma_Arg
3575                        ("pragma ignored, value too large?", Arg);
3576                   else
3577                      Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
3578                      Set_Warning (R_Id);
3579                   end if;
3580                end if;
3581             end if;
3582
3583             Next (Arg);
3584          end loop;
3585       end Process_Restrictions_Or_Restriction_Warnings;
3586
3587       ---------------------------------
3588       -- Process_Suppress_Unsuppress --
3589       ---------------------------------
3590
3591       --  Note: this procedure makes entries in the check suppress data
3592       --  structures managed by Sem. See spec of package Sem for full
3593       --  details on how we handle recording of check suppression.
3594
3595       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3596          C    : Check_Id;
3597          E_Id : Node_Id;
3598          E    : Entity_Id;
3599
3600          In_Package_Spec : constant Boolean :=
3601                              (Ekind (Current_Scope) = E_Package
3602                                 or else
3603                               Ekind (Current_Scope) = E_Generic_Package)
3604                                and then not In_Package_Body (Current_Scope);
3605
3606          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3607          --  Used to suppress a single check on the given entity
3608
3609          --------------------------------
3610          -- Suppress_Unsuppress_Echeck --
3611          --------------------------------
3612
3613          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3614             ESR : constant Entity_Check_Suppress_Record :=
3615                     (Entity   => E,
3616                      Check    => C,
3617                      Suppress => Suppress_Case);
3618
3619          begin
3620             Set_Checks_May_Be_Suppressed (E);
3621
3622             if In_Package_Spec then
3623                Global_Entity_Suppress.Append (ESR);
3624             else
3625                Local_Entity_Suppress.Append (ESR);
3626             end if;
3627
3628             --  If this is a first subtype, and the base type is distinct,
3629             --  then also set the suppress flags on the base type.
3630
3631             if Is_First_Subtype (E)
3632               and then Etype (E) /= E
3633             then
3634                Suppress_Unsuppress_Echeck (Etype (E), C);
3635             end if;
3636          end Suppress_Unsuppress_Echeck;
3637
3638       --  Start of processing for Process_Suppress_Unsuppress
3639
3640       begin
3641          --  Suppress/Unsuppress can appear as a configuration pragma,
3642          --  or in a declarative part or a package spec (RM 11.5(5))
3643
3644          if not Is_Configuration_Pragma then
3645             Check_Is_In_Decl_Part_Or_Package_Spec;
3646          end if;
3647
3648          Check_At_Least_N_Arguments (1);
3649          Check_At_Most_N_Arguments (2);
3650          Check_No_Identifier (Arg1);
3651          Check_Arg_Is_Identifier (Arg1);
3652
3653          if not Is_Check_Name (Chars (Expression (Arg1))) then
3654             Error_Pragma_Arg
3655               ("argument of pragma% is not valid check name", Arg1);
3656          else
3657             C := Get_Check_Id (Chars (Expression (Arg1)));
3658          end if;
3659
3660          if Arg_Count = 1 then
3661
3662             --  Make an entry in the local scope suppress table. This is the
3663             --  table that directly shows the current value of the scope
3664             --  suppress check for any check id value.
3665
3666             if C = All_Checks then
3667                for J in Scope_Suppress'Range loop
3668                   Scope_Suppress (J) := Suppress_Case;
3669                end loop;
3670             else
3671                Scope_Suppress (C) := Suppress_Case;
3672             end if;
3673
3674             --  Also make an entry in the Local_Entity_Suppress table. See
3675             --  extended description in the package spec of Sem for details.
3676
3677             Local_Entity_Suppress.Append
3678               ((Entity   => Empty,
3679                 Check    => C,
3680                 Suppress => Suppress_Case));
3681
3682          --  Case of two arguments present, where the check is
3683          --  suppressed for a specified entity (given as the second
3684          --  argument of the pragma)
3685
3686          else
3687             Check_Optional_Identifier (Arg2, Name_On);
3688             E_Id := Expression (Arg2);
3689             Analyze (E_Id);
3690
3691             if not Is_Entity_Name (E_Id) then
3692                Error_Pragma_Arg
3693                  ("second argument of pragma% must be entity name", Arg2);
3694             end if;
3695
3696             E := Entity (E_Id);
3697
3698             if E = Any_Id then
3699                return;
3700             end if;
3701
3702             --  Enforce RM 11.5(7) which requires that for a pragma that
3703             --  appears within a package spec, the named entity must be
3704             --  within the package spec. We allow the package name itself
3705             --  to be mentioned since that makes sense, although it is not
3706             --  strictly allowed by 11.5(7).
3707
3708             if In_Package_Spec
3709               and then E /= Current_Scope
3710               and then Scope (E) /= Current_Scope
3711             then
3712                Error_Pragma_Arg
3713                  ("entity in pragma% is not in package spec ('R'M 11.5(7))",
3714                   Arg2);
3715             end if;
3716
3717             --  Loop through homonyms. As noted below, in the case of a package
3718             --  spec, only homonyms within the package spec are considered.
3719
3720             loop
3721                Suppress_Unsuppress_Echeck (E, C);
3722
3723                if Is_Generic_Instance (E)
3724                  and then Is_Subprogram (E)
3725                  and then Present (Alias (E))
3726                then
3727                   Suppress_Unsuppress_Echeck (Alias (E), C);
3728                end if;
3729
3730                --  Move to next homonym
3731
3732                E := Homonym (E);
3733                exit when No (E);
3734
3735                --  If we are within a package specification, the
3736                --  pragma only applies to homonyms in the same scope.
3737
3738                exit when In_Package_Spec
3739                  and then Scope (E) /= Current_Scope;
3740             end loop;
3741          end if;
3742       end Process_Suppress_Unsuppress;
3743
3744       ------------------
3745       -- Set_Exported --
3746       ------------------
3747
3748       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3749       begin
3750          if Is_Imported (E) then
3751             Error_Pragma_Arg
3752               ("cannot export entity& that was previously imported", Arg);
3753
3754          elsif Present (Address_Clause (E)) then
3755             Error_Pragma_Arg
3756               ("cannot export entity& that has an address clause", Arg);
3757          end if;
3758
3759          Set_Is_Exported (E);
3760
3761          --  Generate a reference for entity explicitly, because the
3762          --  identifier may be overloaded and name resolution will not
3763          --  generate one.
3764
3765          Generate_Reference (E, Arg);
3766
3767          --  Deal with exporting non-library level entity
3768
3769          if not Is_Library_Level_Entity (E) then
3770
3771             --  Not allowed at all for subprograms
3772
3773             if Is_Subprogram (E) then
3774                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3775
3776             --  Otherwise set public and statically allocated
3777
3778             else
3779                Set_Is_Public (E);
3780                Set_Is_Statically_Allocated (E);
3781
3782                --  Warn if the corresponding W flag is set and the pragma
3783                --  comes from source. The latter may not be true e.g. on
3784                --  VMS where we expand export pragmas for exception codes
3785                --  associated with imported or exported exceptions. We do
3786                --  not want to generate a warning for something that the
3787                --  user did not write.
3788
3789                if Warn_On_Export_Import
3790                  and then Comes_From_Source (Arg)
3791                then
3792                   Error_Msg_NE
3793                     ("?& has been made static as a result of Export", Arg, E);
3794                   Error_Msg_N
3795                     ("\this usage is non-standard and non-portable", Arg);
3796                end if;
3797             end if;
3798          end if;
3799
3800          if Warn_On_Export_Import and then Is_Type (E) then
3801             Error_Msg_NE
3802               ("exporting a type has no effect?", Arg, E);
3803          end if;
3804
3805          if Warn_On_Export_Import and Inside_A_Generic then
3806             Error_Msg_NE
3807               ("all instances of& will have the same external name?", Arg, E);
3808          end if;
3809       end Set_Exported;
3810
3811       ----------------------------------------------
3812       -- Set_Extended_Import_Export_External_Name --
3813       ----------------------------------------------
3814
3815       procedure Set_Extended_Import_Export_External_Name
3816         (Internal_Ent : Entity_Id;
3817          Arg_External : Node_Id)
3818       is
3819          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3820          New_Name : Node_Id;
3821
3822       begin
3823          if No (Arg_External) then
3824             return;
3825          end if;
3826
3827          Check_Arg_Is_External_Name (Arg_External);
3828
3829          if Nkind (Arg_External) = N_String_Literal then
3830             if String_Length (Strval (Arg_External)) = 0 then
3831                return;
3832             else
3833                New_Name := Adjust_External_Name_Case (Arg_External);
3834             end if;
3835
3836          elsif Nkind (Arg_External) = N_Identifier then
3837             New_Name := Get_Default_External_Name (Arg_External);
3838
3839          --  Check_Arg_Is_External_Name should let through only
3840          --  identifiers and string literals or static string
3841          --  expressions (which are folded to string literals).
3842
3843          else
3844             raise Program_Error;
3845          end if;
3846
3847          --  If we already have an external name set (by a prior normal
3848          --  Import or Export pragma), then the external names must match
3849
3850          if Present (Interface_Name (Internal_Ent)) then
3851             Check_Matching_Internal_Names : declare
3852                S1 : constant String_Id := Strval (Old_Name);
3853                S2 : constant String_Id := Strval (New_Name);
3854
3855                procedure Mismatch;
3856                --  Called if names do not match
3857
3858                --------------
3859                -- Mismatch --
3860                --------------
3861
3862                procedure Mismatch is
3863                begin
3864                   Error_Msg_Sloc := Sloc (Old_Name);
3865                   Error_Pragma_Arg
3866                     ("external name does not match that given #",
3867                      Arg_External);
3868                end Mismatch;
3869
3870             --  Start of processing for Check_Matching_Internal_Names
3871
3872             begin
3873                if String_Length (S1) /= String_Length (S2) then
3874                   Mismatch;
3875
3876                else
3877                   for J in 1 .. String_Length (S1) loop
3878                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
3879                         Mismatch;
3880                      end if;
3881                   end loop;
3882                end if;
3883             end Check_Matching_Internal_Names;
3884
3885          --  Otherwise set the given name
3886
3887          else
3888             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
3889             Check_Duplicated_Export_Name (New_Name);
3890          end if;
3891       end Set_Extended_Import_Export_External_Name;
3892
3893       ------------------
3894       -- Set_Imported --
3895       ------------------
3896
3897       procedure Set_Imported (E : Entity_Id) is
3898       begin
3899          Error_Msg_Sloc  := Sloc (E);
3900
3901          if Is_Exported (E) or else Is_Imported (E) then
3902             Error_Msg_NE ("import of& declared# not allowed", N, E);
3903
3904             if Is_Exported (E) then
3905                Error_Msg_N ("\entity was previously exported", N);
3906             else
3907                Error_Msg_N ("\entity was previously imported", N);
3908             end if;
3909
3910             Error_Pragma ("\(pragma% applies to all previous entities)");
3911
3912          else
3913             Set_Is_Imported (E);
3914
3915             --  If the entity is an object that is not at the library
3916             --  level, then it is statically allocated. We do not worry
3917             --  about objects with address clauses in this context since
3918             --  they are not really imported in the linker sense.
3919
3920             if Is_Object (E)
3921               and then not Is_Library_Level_Entity (E)
3922               and then No (Address_Clause (E))
3923             then
3924                Set_Is_Statically_Allocated (E);
3925             end if;
3926          end if;
3927       end Set_Imported;
3928
3929       -------------------------
3930       -- Set_Mechanism_Value --
3931       -------------------------
3932
3933       --  Note: the mechanism name has not been analyzed (and cannot indeed
3934       --  be analyzed, since it is semantic nonsense), so we get it in the
3935       --  exact form created by the parser.
3936
3937       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
3938          Class : Node_Id;
3939          Param : Node_Id;
3940
3941          procedure Bad_Class;
3942          --  Signal bad descriptor class name
3943
3944          procedure Bad_Mechanism;
3945          --  Signal bad mechanism name
3946
3947          ---------------
3948          -- Bad_Class --
3949          ---------------
3950
3951          procedure Bad_Class is
3952          begin
3953             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
3954          end Bad_Class;
3955
3956          -------------------------
3957          -- Bad_Mechanism_Value --
3958          -------------------------
3959
3960          procedure Bad_Mechanism is
3961          begin
3962             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
3963          end Bad_Mechanism;
3964
3965       --  Start of processing for Set_Mechanism_Value
3966
3967       begin
3968          if Mechanism (Ent) /= Default_Mechanism then
3969             Error_Msg_NE
3970               ("mechanism for & has already been set", Mech_Name, Ent);
3971          end if;
3972
3973          --  MECHANISM_NAME ::= value | reference | descriptor
3974
3975          if Nkind (Mech_Name) = N_Identifier then
3976             if Chars (Mech_Name) = Name_Value then
3977                Set_Mechanism (Ent, By_Copy);
3978                return;
3979
3980             elsif Chars (Mech_Name) = Name_Reference then
3981                Set_Mechanism (Ent, By_Reference);
3982                return;
3983
3984             elsif Chars (Mech_Name) = Name_Descriptor then
3985                Check_VMS (Mech_Name);
3986                Set_Mechanism (Ent, By_Descriptor);
3987                return;
3988
3989             elsif Chars (Mech_Name) = Name_Copy then
3990                Error_Pragma_Arg
3991                  ("bad mechanism name, Value assumed", Mech_Name);
3992
3993             else
3994                Bad_Mechanism;
3995             end if;
3996
3997          --  MECHANISM_NAME ::= descriptor (CLASS_NAME)
3998          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
3999
4000          --  Note: this form is parsed as an indexed component
4001
4002          elsif Nkind (Mech_Name) = N_Indexed_Component then
4003             Class := First (Expressions (Mech_Name));
4004
4005             if Nkind (Prefix (Mech_Name)) /= N_Identifier
4006               or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
4007               or else Present (Next (Class))
4008             then
4009                Bad_Mechanism;
4010             end if;
4011
4012          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
4013          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
4014
4015          --  Note: this form is parsed as a function call
4016
4017          elsif Nkind (Mech_Name) = N_Function_Call then
4018
4019             Param := First (Parameter_Associations (Mech_Name));
4020
4021             if Nkind (Name (Mech_Name)) /= N_Identifier
4022               or else Chars (Name (Mech_Name)) /= Name_Descriptor
4023               or else Present (Next (Param))
4024               or else No (Selector_Name (Param))
4025               or else Chars (Selector_Name (Param)) /= Name_Class
4026             then
4027                Bad_Mechanism;
4028             else
4029                Class := Explicit_Actual_Parameter (Param);
4030             end if;
4031
4032          else
4033             Bad_Mechanism;
4034          end if;
4035
4036          --  Fall through here with Class set to descriptor class name
4037
4038          Check_VMS (Mech_Name);
4039
4040          if Nkind (Class) /= N_Identifier then
4041             Bad_Class;
4042
4043          elsif Chars (Class) = Name_UBS then
4044             Set_Mechanism (Ent, By_Descriptor_UBS);
4045
4046          elsif Chars (Class) = Name_UBSB then
4047             Set_Mechanism (Ent, By_Descriptor_UBSB);
4048
4049          elsif Chars (Class) = Name_UBA then
4050             Set_Mechanism (Ent, By_Descriptor_UBA);
4051
4052          elsif Chars (Class) = Name_S then
4053             Set_Mechanism (Ent, By_Descriptor_S);
4054
4055          elsif Chars (Class) = Name_SB then
4056             Set_Mechanism (Ent, By_Descriptor_SB);
4057
4058          elsif Chars (Class) = Name_A then
4059             Set_Mechanism (Ent, By_Descriptor_A);
4060
4061          elsif Chars (Class) = Name_NCA then
4062             Set_Mechanism (Ent, By_Descriptor_NCA);
4063
4064          else
4065             Bad_Class;
4066          end if;
4067
4068       end Set_Mechanism_Value;
4069
4070       ---------------------------
4071       -- Set_Ravenscar_Profile --
4072       ---------------------------
4073
4074       --  The tasks to be done here are
4075
4076       --    Set required policies
4077
4078       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4079       --      pragma Locking_Policy (Ceiling_Locking)
4080
4081       --    Set Detect_Blocking mode
4082
4083       --    Set required restrictions (see System.Rident for detailed list)
4084
4085       procedure Set_Ravenscar_Profile (N : Node_Id) is
4086       begin
4087          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4088
4089          if Task_Dispatching_Policy /= ' '
4090            and then Task_Dispatching_Policy /= 'F'
4091          then
4092             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4093             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4094
4095          --  Set the FIFO_Within_Priorities policy, but always
4096          --  preserve System_Location since we like the error
4097          --  message with the run time name.
4098
4099          else
4100             Task_Dispatching_Policy := 'F';
4101
4102             if Task_Dispatching_Policy_Sloc /= System_Location then
4103                Task_Dispatching_Policy_Sloc := Loc;
4104             end if;
4105          end if;
4106
4107          --  pragma Locking_Policy (Ceiling_Locking)
4108
4109          if Locking_Policy /= ' '
4110            and then Locking_Policy /= 'C'
4111          then
4112             Error_Msg_Sloc := Locking_Policy_Sloc;
4113             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4114
4115          --  Set the Ceiling_Locking policy, but always preserve
4116          --  System_Location since we like the error message with the
4117          --  run time name.
4118
4119          else
4120             Locking_Policy := 'C';
4121
4122             if Locking_Policy_Sloc /= System_Location then
4123                Locking_Policy_Sloc := Loc;
4124             end if;
4125          end if;
4126
4127          --  pragma Detect_Blocking
4128
4129          Detect_Blocking := True;
4130
4131          --  Set the corresponding restrictions
4132
4133          Set_Profile_Restrictions (Ravenscar, N, Warn => False);
4134       end Set_Ravenscar_Profile;
4135
4136    --  Start of processing for Analyze_Pragma
4137
4138    begin
4139       if not Is_Pragma_Name (Chars (N)) then
4140          if Warn_On_Unrecognized_Pragma then
4141             Error_Pragma ("unrecognized pragma%!?");
4142          else
4143             raise Pragma_Exit;
4144          end if;
4145       else
4146          Prag_Id := Get_Pragma_Id (Chars (N));
4147       end if;
4148
4149       --  Preset arguments
4150
4151       Arg1 := Empty;
4152       Arg2 := Empty;
4153       Arg3 := Empty;
4154       Arg4 := Empty;
4155
4156       if Present (Pragma_Argument_Associations (N)) then
4157          Arg1 := First (Pragma_Argument_Associations (N));
4158
4159          if Present (Arg1) then
4160             Arg2 := Next (Arg1);
4161
4162             if Present (Arg2) then
4163                Arg3 := Next (Arg2);
4164
4165                if Present (Arg3) then
4166                   Arg4 := Next (Arg3);
4167                end if;
4168             end if;
4169          end if;
4170       end if;
4171
4172       --  Count number of arguments
4173
4174       declare
4175          Arg_Node : Node_Id;
4176       begin
4177          Arg_Count := 0;
4178          Arg_Node := Arg1;
4179          while Present (Arg_Node) loop
4180             Arg_Count := Arg_Count + 1;
4181             Next (Arg_Node);
4182          end loop;
4183       end;
4184
4185       --  An enumeration type defines the pragmas that are supported by the
4186       --  implementation. Get_Pragma_Id (in package Prag) transorms a name
4187       --  into the corresponding enumeration value for the following case.
4188
4189       case Prag_Id is
4190
4191          -----------------
4192          -- Abort_Defer --
4193          -----------------
4194
4195          --  pragma Abort_Defer;
4196
4197          when Pragma_Abort_Defer =>
4198             GNAT_Pragma;
4199             Check_Arg_Count (0);
4200
4201             --  The only required semantic processing is to check the
4202             --  placement. This pragma must appear at the start of the
4203             --  statement sequence of a handled sequence of statements.
4204
4205             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
4206               or else N /= First (Statements (Parent (N)))
4207             then
4208                Pragma_Misplaced;
4209             end if;
4210
4211          ------------
4212          -- Ada_83 --
4213          ------------
4214
4215          --  pragma Ada_83;
4216
4217          --  Note: this pragma also has some specific processing in Par.Prag
4218          --  because we want to set the Ada version mode during parsing.
4219
4220          when Pragma_Ada_83 =>
4221             GNAT_Pragma;
4222             Ada_Version := Ada_83;
4223             Check_Arg_Count (0);
4224
4225          ------------
4226          -- Ada_95 --
4227          ------------
4228
4229          --  pragma Ada_95;
4230
4231          --  Note: this pragma also has some specific processing in Par.Prag
4232          --  because we want to set the Ada 83 version mode during parsing.
4233
4234          when Pragma_Ada_95 =>
4235             GNAT_Pragma;
4236             Ada_Version := Ada_95;
4237             Check_Arg_Count (0);
4238
4239          ------------
4240          -- Ada_05 --
4241          ------------
4242
4243          --  pragma Ada_05;
4244
4245          --  Note: this pragma also has some specific processing in Par.Prag
4246          --  because we want to set the Ada 83 version mode during parsing.
4247
4248          when Pragma_Ada_05 =>
4249             GNAT_Pragma;
4250             Ada_Version := Ada_05;
4251             Check_Arg_Count (0);
4252
4253          ----------------------
4254          -- All_Calls_Remote --
4255          ----------------------
4256
4257          --  pragma All_Calls_Remote [(library_package_NAME)];
4258
4259          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
4260             Lib_Entity : Entity_Id;
4261
4262          begin
4263             Check_Ada_83_Warning;
4264             Check_Valid_Library_Unit_Pragma;
4265
4266             if Nkind (N) = N_Null_Statement then
4267                return;
4268             end if;
4269
4270             Lib_Entity := Find_Lib_Unit_Name;
4271
4272             --  This pragma should only apply to a RCI unit (RM E.2.3(23)).
4273
4274             if Present (Lib_Entity)
4275               and then not Debug_Flag_U
4276             then
4277                if not Is_Remote_Call_Interface (Lib_Entity) then
4278                   Error_Pragma ("pragma% only apply to rci unit");
4279
4280                --  Set flag for entity of the library unit
4281
4282                else
4283                   Set_Has_All_Calls_Remote (Lib_Entity);
4284                end if;
4285
4286             end if;
4287          end All_Calls_Remote;
4288
4289          --------------
4290          -- Annotate --
4291          --------------
4292
4293          --  pragma Annotate (IDENTIFIER {, ARG});
4294          --  ARG ::= NAME | EXPRESSION
4295
4296          when Pragma_Annotate => Annotate : begin
4297             GNAT_Pragma;
4298             Check_At_Least_N_Arguments (1);
4299             Check_Arg_Is_Identifier (Arg1);
4300
4301             declare
4302                Arg : Node_Id := Arg2;
4303                Exp : Node_Id;
4304
4305             begin
4306                while Present (Arg) loop
4307                   Exp := Expression (Arg);
4308                   Analyze (Exp);
4309
4310                   if Is_Entity_Name (Exp) then
4311                      null;
4312
4313                   elsif Nkind (Exp) = N_String_Literal then
4314                      Resolve (Exp, Standard_String);
4315
4316                   elsif Is_Overloaded (Exp) then
4317                      Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
4318
4319                   else
4320                      Resolve (Exp);
4321                   end if;
4322
4323                   Next (Arg);
4324                end loop;
4325             end;
4326          end Annotate;
4327
4328          ------------
4329          -- Assert --
4330          ------------
4331
4332          --  pragma Assert (Boolean_EXPRESSION [, static_string_EXPRESSION]);
4333
4334          when Pragma_Assert =>
4335             GNAT_Pragma;
4336             Check_No_Identifiers;
4337
4338             if Arg_Count > 1 then
4339                Check_Arg_Count (2);
4340                Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4341             end if;
4342
4343             --  If expansion is active and assertions are inactive, then
4344             --  we rewrite the Assertion as:
4345
4346             --    if False and then condition then
4347             --       null;
4348             --    end if;
4349
4350             --  The reason we do this rewriting during semantic analysis
4351             --  rather than as part of normal expansion is that we cannot
4352             --  analyze and expand the code for the boolean expression
4353             --  directly, or it may cause insertion of actions that would
4354             --  escape the attempt to suppress the assertion code.
4355
4356             if Expander_Active and not Assertions_Enabled then
4357                Rewrite (N,
4358                  Make_If_Statement (Loc,
4359                    Condition =>
4360                      Make_And_Then (Loc,
4361                        Left_Opnd  => New_Occurrence_Of (Standard_False, Loc),
4362                        Right_Opnd => Get_Pragma_Arg (Arg1)),
4363                    Then_Statements => New_List (
4364                      Make_Null_Statement (Loc))));
4365
4366                Analyze (N);
4367
4368             --  Otherwise (if assertions are enabled, or if we are not
4369             --  operating with expansion active), then we just analyze
4370             --  and resolve the expression.
4371
4372             else
4373                Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
4374             end if;
4375
4376          ---------------
4377          -- AST_Entry --
4378          ---------------
4379
4380          --  pragma AST_Entry (entry_IDENTIFIER);
4381
4382          when Pragma_AST_Entry => AST_Entry : declare
4383             Ent : Node_Id;
4384
4385          begin
4386             GNAT_Pragma;
4387             Check_VMS (N);
4388             Check_Arg_Count (1);
4389             Check_No_Identifiers;
4390             Check_Arg_Is_Local_Name (Arg1);
4391             Ent := Entity (Expression (Arg1));
4392
4393             --  Note: the implementation of the AST_Entry pragma could handle
4394             --  the entry family case fine, but for now we are consistent with
4395             --  the DEC rules, and do not allow the pragma, which of course
4396             --  has the effect of also forbidding the attribute.
4397
4398             if Ekind (Ent) /= E_Entry then
4399                Error_Pragma_Arg
4400                  ("pragma% argument must be simple entry name", Arg1);
4401
4402             elsif Is_AST_Entry (Ent) then
4403                Error_Pragma_Arg
4404                  ("duplicate % pragma for entry", Arg1);
4405
4406             elsif Has_Homonym (Ent) then
4407                Error_Pragma_Arg
4408                  ("pragma% argument cannot specify overloaded entry", Arg1);
4409
4410             else
4411                declare
4412                   FF : constant Entity_Id := First_Formal (Ent);
4413
4414                begin
4415                   if Present (FF) then
4416                      if Present (Next_Formal (FF)) then
4417                         Error_Pragma_Arg
4418                           ("entry for pragma% can have only one argument",
4419                            Arg1);
4420
4421                      elsif Parameter_Mode (FF) /= E_In_Parameter then
4422                         Error_Pragma_Arg
4423                           ("entry parameter for pragma% must have mode IN",
4424                            Arg1);
4425                      end if;
4426                   end if;
4427                end;
4428
4429                Set_Is_AST_Entry (Ent);
4430             end if;
4431          end AST_Entry;
4432
4433          ------------------
4434          -- Asynchronous --
4435          ------------------
4436
4437          --  pragma Asynchronous (LOCAL_NAME);
4438
4439          when Pragma_Asynchronous => Asynchronous : declare
4440             Nm     : Entity_Id;
4441             C_Ent  : Entity_Id;
4442             L      : List_Id;
4443             S      : Node_Id;
4444             N      : Node_Id;
4445             Formal : Entity_Id;
4446
4447             procedure Process_Async_Pragma;
4448             --  Common processing for procedure and access-to-procedure case
4449
4450             --------------------------
4451             -- Process_Async_Pragma --
4452             --------------------------
4453
4454             procedure Process_Async_Pragma is
4455             begin
4456                if not Present (L) then
4457                   Set_Is_Asynchronous (Nm);
4458                   return;
4459                end if;
4460
4461                --  The formals should be of mode IN (RM E.4.1(6))
4462
4463                S := First (L);
4464                while Present (S) loop
4465                   Formal := Defining_Identifier (S);
4466
4467                   if Nkind (Formal) = N_Defining_Identifier
4468                     and then Ekind (Formal) /= E_In_Parameter
4469                   then
4470                      Error_Pragma_Arg
4471                        ("pragma% procedure can only have IN parameter",
4472                         Arg1);
4473                   end if;
4474
4475                   Next (S);
4476                end loop;
4477
4478                Set_Is_Asynchronous (Nm);
4479             end Process_Async_Pragma;
4480
4481          --  Start of processing for pragma Asynchronous
4482
4483          begin
4484             Check_Ada_83_Warning;
4485             Check_No_Identifiers;
4486             Check_Arg_Count (1);
4487             Check_Arg_Is_Local_Name (Arg1);
4488
4489             if Debug_Flag_U then
4490                return;
4491             end if;
4492
4493             C_Ent := Cunit_Entity (Current_Sem_Unit);
4494             Analyze (Expression (Arg1));
4495             Nm := Entity (Expression (Arg1));
4496
4497             if not Is_Remote_Call_Interface (C_Ent)
4498               and then not Is_Remote_Types (C_Ent)
4499             then
4500                --  This pragma should only appear in an RCI or Remote Types
4501                --  unit (RM E.4.1(4))
4502
4503                Error_Pragma
4504                  ("pragma% not in Remote_Call_Interface or " &
4505                   "Remote_Types unit");
4506             end if;
4507
4508             if Ekind (Nm) = E_Procedure
4509               and then Nkind (Parent (Nm)) = N_Procedure_Specification
4510             then
4511                if not Is_Remote_Call_Interface (Nm) then
4512                   Error_Pragma_Arg
4513                     ("pragma% cannot be applied on non-remote procedure",
4514                      Arg1);
4515                end if;
4516
4517                L := Parameter_Specifications (Parent (Nm));
4518                Process_Async_Pragma;
4519                return;
4520
4521             elsif Ekind (Nm) = E_Function then
4522                Error_Pragma_Arg
4523                  ("pragma% cannot be applied to function", Arg1);
4524
4525             elsif Ekind (Nm) = E_Record_Type
4526               and then Present (Corresponding_Remote_Type (Nm))
4527             then
4528                --  A record type that is the Equivalent_Type for
4529                --  a remote access-to-subprogram type.
4530
4531                N := Declaration_Node (Corresponding_Remote_Type (Nm));
4532
4533                if Nkind (N) = N_Full_Type_Declaration
4534                  and then Nkind (Type_Definition (N)) =
4535                                      N_Access_Procedure_Definition
4536                then
4537                   L := Parameter_Specifications (Type_Definition (N));
4538                   Process_Async_Pragma;
4539
4540                   if Is_Asynchronous (Nm)
4541                     and then Expander_Active
4542                   then
4543                      RACW_Type_Is_Asynchronous (
4544                        Underlying_RACW_Type (Nm));
4545                   end if;
4546
4547                else
4548                   Error_Pragma_Arg
4549                     ("pragma% cannot reference access-to-function type",
4550                     Arg1);
4551                end if;
4552
4553             --  Only other possibility is Access-to-class-wide type
4554
4555             elsif Is_Access_Type (Nm)
4556               and then Is_Class_Wide_Type (Designated_Type (Nm))
4557             then
4558                Check_First_Subtype (Arg1);
4559                Set_Is_Asynchronous (Nm);
4560                if Expander_Active then
4561                   RACW_Type_Is_Asynchronous (Nm);
4562                end if;
4563
4564             else
4565                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
4566             end if;
4567          end Asynchronous;
4568
4569          ------------
4570          -- Atomic --
4571          ------------
4572
4573          --  pragma Atomic (LOCAL_NAME);
4574
4575          when Pragma_Atomic =>
4576             Process_Atomic_Shared_Volatile;
4577
4578          -----------------------
4579          -- Atomic_Components --
4580          -----------------------
4581
4582          --  pragma Atomic_Components (array_LOCAL_NAME);
4583
4584          --  This processing is shared by Volatile_Components
4585
4586          when Pragma_Atomic_Components   |
4587               Pragma_Volatile_Components =>
4588
4589          Atomic_Components : declare
4590             E_Id : Node_Id;
4591             E    : Entity_Id;
4592             D    : Node_Id;
4593             K    : Node_Kind;
4594
4595          begin
4596             Check_Ada_83_Warning;
4597             Check_No_Identifiers;
4598             Check_Arg_Count (1);
4599             Check_Arg_Is_Local_Name (Arg1);
4600             E_Id := Expression (Arg1);
4601
4602             if Etype (E_Id) = Any_Type then
4603                return;
4604             end if;
4605
4606             E := Entity (E_Id);
4607
4608             if Rep_Item_Too_Early (E, N)
4609                  or else
4610                Rep_Item_Too_Late (E, N)
4611             then
4612                return;
4613             end if;
4614
4615             D := Declaration_Node (E);
4616             K := Nkind (D);
4617
4618             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
4619               or else
4620                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4621                    and then Nkind (D) = N_Object_Declaration
4622                    and then Nkind (Object_Definition (D)) =
4623                                        N_Constrained_Array_Definition)
4624             then
4625                --  The flag is set on the object, or on the base type
4626
4627                if Nkind (D) /= N_Object_Declaration then
4628                   E := Base_Type (E);
4629                end if;
4630
4631                Set_Has_Volatile_Components (E);
4632
4633                if Prag_Id = Pragma_Atomic_Components then
4634                   Set_Has_Atomic_Components (E);
4635
4636                   if Is_Packed (E) then
4637                      Set_Is_Packed (E, False);
4638
4639                      Error_Pragma_Arg
4640                        ("?Pack canceled, cannot pack atomic components",
4641                         Arg1);
4642                   end if;
4643                end if;
4644
4645             else
4646                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
4647             end if;
4648          end Atomic_Components;
4649
4650          --------------------
4651          -- Attach_Handler --
4652          --------------------
4653
4654          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
4655
4656          when Pragma_Attach_Handler =>
4657             Check_Ada_83_Warning;
4658             Check_No_Identifiers;
4659             Check_Arg_Count (2);
4660
4661             if No_Run_Time_Mode then
4662                Error_Msg_CRT ("Attach_Handler pragma", N);
4663             else
4664                Check_Interrupt_Or_Attach_Handler;
4665
4666                --  The expression that designates the attribute may
4667                --  depend on a discriminant, and is therefore a per-
4668                --  object expression, to be expanded in the init proc.
4669                --  If expansion is enabled, perform semantic checks
4670                --  on a copy only.
4671
4672                if Expander_Active then
4673                   declare
4674                      Temp : constant Node_Id :=
4675                               New_Copy_Tree (Expression (Arg2));
4676                   begin
4677                      Set_Parent (Temp, N);
4678                      Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
4679                   end;
4680
4681                else
4682                   Analyze (Expression (Arg2));
4683                   Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
4684                end if;
4685
4686                Process_Interrupt_Or_Attach_Handler;
4687             end if;
4688
4689          --------------------
4690          -- C_Pass_By_Copy --
4691          --------------------
4692
4693          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4694
4695          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4696             Arg : Node_Id;
4697             Val : Uint;
4698
4699          begin
4700             GNAT_Pragma;
4701             Check_Valid_Configuration_Pragma;
4702             Check_Arg_Count (1);
4703             Check_Optional_Identifier (Arg1, "max_size");
4704
4705             Arg := Expression (Arg1);
4706             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4707
4708             Val := Expr_Value (Arg);
4709
4710             if Val <= 0 then
4711                Error_Pragma_Arg
4712                  ("maximum size for pragma% must be positive", Arg1);
4713
4714             elsif UI_Is_In_Int_Range (Val) then
4715                Default_C_Record_Mechanism := UI_To_Int (Val);
4716
4717             --  If a giant value is given, Int'Last will do well enough.
4718             --  If sometime someone complains that a record larger than
4719             --  two gigabytes is not copied, we will worry about it then!
4720
4721             else
4722                Default_C_Record_Mechanism := Mechanism_Type'Last;
4723             end if;
4724          end C_Pass_By_Copy;
4725
4726          -------------
4727          -- Comment --
4728          -------------
4729
4730          --  pragma Comment (static_string_EXPRESSION)
4731
4732          --  Processing for pragma Comment shares the circuitry for
4733          --  pragma Ident. The only differences are that Ident enforces
4734          --  a limit of 31 characters on its argument, and also enforces
4735          --  limitations on placement for DEC compatibility. Pragma
4736          --  Comment shares neither of these restrictions.
4737
4738          -------------------
4739          -- Common_Object --
4740          -------------------
4741
4742          --  pragma Common_Object (
4743          --        [Internal =>] LOCAL_NAME,
4744          --     [, [External =>] EXTERNAL_SYMBOL]
4745          --     [, [Size     =>] EXTERNAL_SYMBOL]);
4746
4747          --  Processing for this pragma is shared with Psect_Object
4748
4749          --------------------------
4750          -- Compile_Time_Warning --
4751          --------------------------
4752
4753          --  pragma Compile_Time_Warning
4754          --    (boolean_EXPRESSION, static_string_EXPRESSION);
4755
4756          when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare
4757             Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4758
4759          begin
4760             GNAT_Pragma;
4761             Check_Arg_Count (2);
4762             Check_No_Identifiers;
4763             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4764             Analyze_And_Resolve (Arg1x, Standard_Boolean);
4765
4766             if Compile_Time_Known_Value (Arg1x) then
4767                if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4768                   String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2)));
4769                   Add_Char_To_Name_Buffer ('?');
4770
4771                   declare
4772                      Msg : String (1 .. Name_Len) :=
4773                              Name_Buffer (1 .. Name_Len);
4774
4775                      B : Natural;
4776
4777                   begin
4778                      --  This loop looks for multiple lines separated by
4779                      --  ASCII.LF and breaks them into continuation error
4780                      --  messages marked with the usual back slash.
4781
4782                      B := 1;
4783                      for S in 2 .. Msg'Length - 1 loop
4784                         if Msg (S) = ASCII.LF then
4785                            Msg (S) := '?';
4786                            Error_Msg_N (Msg (B .. S), Arg1);
4787                            B := S;
4788                            Msg (B) := '\';
4789                         end if;
4790                      end loop;
4791
4792                      Error_Msg_N (Msg (B .. Msg'Length), Arg1);
4793                   end;
4794                end if;
4795             end if;
4796          end Compile_Time_Warning;
4797
4798          ----------------------------
4799          -- Complex_Representation --
4800          ----------------------------
4801
4802          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4803
4804          when Pragma_Complex_Representation => Complex_Representation : declare
4805             E_Id : Entity_Id;
4806             E    : Entity_Id;
4807             Ent  : Entity_Id;
4808
4809          begin
4810             GNAT_Pragma;
4811             Check_Arg_Count (1);
4812             Check_Optional_Identifier (Arg1, Name_Entity);
4813             Check_Arg_Is_Local_Name (Arg1);
4814             E_Id := Expression (Arg1);
4815
4816             if Etype (E_Id) = Any_Type then
4817                return;
4818             end if;
4819
4820             E := Entity (E_Id);
4821
4822             if not Is_Record_Type (E) then
4823                Error_Pragma_Arg
4824                  ("argument for pragma% must be record type", Arg1);
4825             end if;
4826
4827             Ent := First_Entity (E);
4828
4829             if No (Ent)
4830               or else No (Next_Entity (Ent))
4831               or else Present (Next_Entity (Next_Entity (Ent)))
4832               or else not Is_Floating_Point_Type (Etype (Ent))
4833               or else Etype (Ent) /= Etype (Next_Entity (Ent))
4834             then
4835                Error_Pragma_Arg
4836                  ("record for pragma% must have two fields of same fpt type",
4837                   Arg1);
4838
4839             else
4840                Set_Has_Complex_Representation (Base_Type (E));
4841             end if;
4842          end Complex_Representation;
4843
4844          -------------------------
4845          -- Component_Alignment --
4846          -------------------------
4847
4848          --  pragma Component_Alignment (
4849          --        [Form =>] ALIGNMENT_CHOICE
4850          --     [, [Name =>] type_LOCAL_NAME]);
4851          --
4852          --   ALIGNMENT_CHOICE ::=
4853          --     Component_Size
4854          --   | Component_Size_4
4855          --   | Storage_Unit
4856          --   | Default
4857
4858          when Pragma_Component_Alignment => Component_AlignmentP : declare
4859             Args  : Args_List (1 .. 2);
4860             Names : constant Name_List (1 .. 2) := (
4861                       Name_Form,
4862                       Name_Name);
4863
4864             Form  : Node_Id renames Args (1);
4865             Name  : Node_Id renames Args (2);
4866
4867             Atype : Component_Alignment_Kind;
4868             Typ   : Entity_Id;
4869
4870          begin
4871             GNAT_Pragma;
4872             Gather_Associations (Names, Args);
4873
4874             if No (Form) then
4875                Error_Pragma ("missing Form argument for pragma%");
4876             end if;
4877
4878             Check_Arg_Is_Identifier (Form);
4879
4880             --  Get proper alignment, note that Default = Component_Size
4881             --  on all machines we have so far, and we want to set this
4882             --  value rather than the default value to indicate that it
4883             --  has been explicitly set (and thus will not get overridden
4884             --  by the default component alignment for the current scope)
4885
4886             if Chars (Form) = Name_Component_Size then
4887                Atype := Calign_Component_Size;
4888
4889             elsif Chars (Form) = Name_Component_Size_4 then
4890                Atype := Calign_Component_Size_4;
4891
4892             elsif Chars (Form) = Name_Default then
4893                Atype := Calign_Component_Size;
4894
4895             elsif Chars (Form) = Name_Storage_Unit then
4896                Atype := Calign_Storage_Unit;
4897
4898             else
4899                Error_Pragma_Arg
4900                  ("invalid Form parameter for pragma%", Form);
4901             end if;
4902
4903             --  Case with no name, supplied, affects scope table entry
4904
4905             if No (Name) then
4906                Scope_Stack.Table
4907                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
4908
4909             --  Case of name supplied
4910
4911             else
4912                Check_Arg_Is_Local_Name (Name);
4913                Find_Type (Name);
4914                Typ := Entity (Name);
4915
4916                if Typ = Any_Type
4917                  or else Rep_Item_Too_Early (Typ, N)
4918                then
4919                   return;
4920                else
4921                   Typ := Underlying_Type (Typ);
4922                end if;
4923
4924                if not Is_Record_Type (Typ)
4925                  and then not Is_Array_Type (Typ)
4926                then
4927                   Error_Pragma_Arg
4928                     ("Name parameter of pragma% must identify record or " &
4929                      "array type", Name);
4930                end if;
4931
4932                --  An explicit Component_Alignment pragma overrides an
4933                --  implicit pragma Pack, but not an explicit one.
4934
4935                if not Has_Pragma_Pack (Base_Type (Typ)) then
4936                   Set_Is_Packed (Base_Type (Typ), False);
4937                   Set_Component_Alignment (Base_Type (Typ), Atype);
4938                end if;
4939             end if;
4940          end Component_AlignmentP;
4941
4942          ----------------
4943          -- Controlled --
4944          ----------------
4945
4946          --  pragma Controlled (first_subtype_LOCAL_NAME);
4947
4948          when Pragma_Controlled => Controlled : declare
4949             Arg : Node_Id;
4950
4951          begin
4952             Check_No_Identifiers;
4953             Check_Arg_Count (1);
4954             Check_Arg_Is_Local_Name (Arg1);
4955             Arg := Expression (Arg1);
4956
4957             if not Is_Entity_Name (Arg)
4958               or else not Is_Access_Type (Entity (Arg))
4959             then
4960                Error_Pragma_Arg ("pragma% requires access type", Arg1);
4961             else
4962                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
4963             end if;
4964          end Controlled;
4965
4966          ----------------
4967          -- Convention --
4968          ----------------
4969
4970          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
4971          --    [Entity =>] LOCAL_NAME);
4972
4973          when Pragma_Convention => Convention : declare
4974             C : Convention_Id;
4975             E : Entity_Id;
4976          begin
4977             Check_Ada_83_Warning;
4978             Check_Arg_Count (2);
4979             Process_Convention (C, E);
4980          end Convention;
4981
4982          ---------------------------
4983          -- Convention_Identifier --
4984          ---------------------------
4985
4986          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
4987          --    [Convention =>] convention_IDENTIFIER);
4988
4989          when Pragma_Convention_Identifier => Convention_Identifier : declare
4990             Idnam : Name_Id;
4991             Cname : Name_Id;
4992
4993          begin
4994             GNAT_Pragma;
4995             Check_Arg_Count (2);
4996             Check_Optional_Identifier (Arg1, Name_Name);
4997             Check_Optional_Identifier (Arg2, Name_Convention);
4998             Check_Arg_Is_Identifier (Arg1);
4999             Check_Arg_Is_Identifier (Arg1);
5000             Idnam := Chars (Expression (Arg1));
5001             Cname := Chars (Expression (Arg2));
5002
5003             if Is_Convention_Name (Cname) then
5004                Record_Convention_Identifier
5005                  (Idnam, Get_Convention_Id (Cname));
5006             else
5007                Error_Pragma_Arg
5008                  ("second arg for % pragma must be convention", Arg2);
5009             end if;
5010          end Convention_Identifier;
5011
5012          ---------------
5013          -- CPP_Class --
5014          ---------------
5015
5016          --  pragma CPP_Class ([Entity =>] local_NAME)
5017
5018          when Pragma_CPP_Class => CPP_Class : declare
5019             Arg         : Node_Id;
5020             Typ         : Entity_Id;
5021             Default_DTC : Entity_Id := Empty;
5022             VTP_Type    : constant Entity_Id  := RTE (RE_Vtable_Ptr);
5023             C           : Entity_Id;
5024             Tag_C       : Entity_Id;
5025
5026          begin
5027             GNAT_Pragma;
5028             Check_Arg_Count (1);
5029             Check_Optional_Identifier (Arg1, Name_Entity);
5030             Check_Arg_Is_Local_Name (Arg1);
5031
5032             Arg := Expression (Arg1);
5033             Analyze (Arg);
5034
5035             if Etype (Arg) = Any_Type then
5036                return;
5037             end if;
5038
5039             if not Is_Entity_Name (Arg)
5040               or else not Is_Type (Entity (Arg))
5041             then
5042                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
5043             end if;
5044
5045             Typ := Entity (Arg);
5046
5047             if not Is_Record_Type (Typ) then
5048                Error_Pragma_Arg ("pragma% applicable to a record, "
5049                  & "tagged record or record extension", Arg1);
5050             end if;
5051
5052             Default_DTC := First_Component (Typ);
5053             while Present (Default_DTC)
5054               and then Etype (Default_DTC) /= VTP_Type
5055             loop
5056                Next_Component (Default_DTC);
5057             end loop;
5058
5059             --  Case of non tagged type
5060
5061             if not Is_Tagged_Type (Typ) then
5062                Set_Is_CPP_Class (Typ);
5063
5064                if Present (Default_DTC) then
5065                   Error_Pragma_Arg
5066                     ("only tagged records can contain vtable pointers", Arg1);
5067                end if;
5068
5069             --  Case of tagged type with no vtable ptr
5070
5071             --  What is test for Typ = Root_Typ (Typ) about here ???
5072
5073             elsif Is_Tagged_Type (Typ)
5074               and then Typ = Root_Type (Typ)
5075               and then No (Default_DTC)
5076             then
5077                Error_Pragma_Arg
5078                  ("a cpp_class must contain a vtable pointer", Arg1);
5079
5080             --  Tagged type that has a vtable ptr
5081
5082             elsif Present (Default_DTC) then
5083                Set_Is_CPP_Class (Typ);
5084                Set_Is_Limited_Record (Typ);
5085                Set_Is_Tag (Default_DTC);
5086                Set_DT_Entry_Count (Default_DTC, No_Uint);
5087
5088                --  Since a CPP type has no direct link to its associated tag
5089                --  most tags checks cannot be performed
5090
5091                Set_Kill_Tag_Checks (Typ);
5092                Set_Kill_Tag_Checks (Class_Wide_Type (Typ));
5093
5094                --  Get rid of the _tag component when there was one.
5095                --  It is only useful for regular tagged types
5096
5097                if Expander_Active and then Typ = Root_Type (Typ) then
5098
5099                   Tag_C := Tag_Component (Typ);
5100                   C := First_Entity (Typ);
5101
5102                   if C = Tag_C then
5103                      Set_First_Entity (Typ, Next_Entity (Tag_C));
5104
5105                   else
5106                      while Next_Entity (C) /= Tag_C loop
5107                         Next_Entity (C);
5108                      end loop;
5109
5110                      Set_Next_Entity (C, Next_Entity (Tag_C));
5111                   end if;
5112                end if;
5113             end if;
5114          end CPP_Class;
5115
5116          ---------------------
5117          -- CPP_Constructor --
5118          ---------------------
5119
5120          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
5121
5122          when Pragma_CPP_Constructor => CPP_Constructor : declare
5123             Id     : Entity_Id;
5124             Def_Id : Entity_Id;
5125
5126          begin
5127             GNAT_Pragma;
5128             Check_Arg_Count (1);
5129             Check_Optional_Identifier (Arg1, Name_Entity);
5130             Check_Arg_Is_Local_Name (Arg1);
5131
5132             Id := Expression (Arg1);
5133             Find_Program_Unit_Name (Id);
5134
5135             --  If we did not find the name, we are done
5136
5137             if Etype (Id) = Any_Type then
5138                return;
5139             end if;
5140
5141             Def_Id := Entity (Id);
5142
5143             if Ekind (Def_Id) = E_Function
5144               and then Is_Class_Wide_Type (Etype (Def_Id))
5145               and then Is_CPP_Class (Etype (Etype (Def_Id)))
5146             then
5147                --  What the heck is this??? this pragma allows only 1 arg
5148
5149                if Arg_Count >= 2 then
5150                   Check_At_Most_N_Arguments (3);
5151                   Process_Interface_Name (Def_Id, Arg2, Arg3);
5152                end if;
5153
5154                if No (Parameter_Specifications (Parent (Def_Id))) then
5155                   Set_Has_Completion (Def_Id);
5156                   Set_Is_Constructor (Def_Id);
5157                else
5158                   Error_Pragma_Arg
5159                     ("non-default constructors not implemented", Arg1);
5160                end if;
5161
5162             else
5163                Error_Pragma_Arg
5164                  ("pragma% requires function returning a 'C'P'P_Class type",
5165                    Arg1);
5166             end if;
5167          end CPP_Constructor;
5168
5169          -----------------
5170          -- CPP_Virtual --
5171          -----------------
5172
5173          --  pragma CPP_Virtual
5174          --      [Entity =>]       LOCAL_NAME
5175          --    [ [Vtable_Ptr =>]   LOCAL_NAME,
5176          --      [Position =>]     static_integer_EXPRESSION]);
5177
5178          when Pragma_CPP_Virtual => CPP_Virtual : declare
5179             Arg      : Node_Id;
5180             Typ      : Entity_Id;
5181             Subp     : Entity_Id;
5182             VTP_Type : constant Entity_Id  := RTE (RE_Vtable_Ptr);
5183             DTC      : Entity_Id;
5184             V        : Uint;
5185
5186          begin
5187             GNAT_Pragma;
5188
5189             if Arg_Count = 3 then
5190                Check_Optional_Identifier (Arg2, "vtable_ptr");
5191
5192                --  We allow Entry_Count as well as Position for the third
5193                --  parameter for back compatibility with versions of GNAT
5194                --  before version 3.12. The documentation has always said
5195                --  Position, but the code up to 3.12 said Entry_Count.
5196
5197                if Chars (Arg3) /= Name_Position then
5198                   Check_Optional_Identifier (Arg3, "entry_count");
5199                end if;
5200
5201             else
5202                Check_Arg_Count (1);
5203             end if;
5204
5205             Check_Optional_Identifier (Arg1, Name_Entity);
5206             Check_Arg_Is_Local_Name (Arg1);
5207
5208             --  First argument must be a subprogram name
5209
5210             Arg := Expression (Arg1);
5211             Find_Program_Unit_Name (Arg);
5212
5213             if Etype (Arg) = Any_Type then
5214                return;
5215             else
5216                Subp := Entity (Arg);
5217             end if;
5218
5219             if not (Is_Subprogram (Subp)
5220                      and then Is_Dispatching_Operation (Subp))
5221             then
5222                Error_Pragma_Arg
5223                  ("pragma% must reference a primitive operation", Arg1);
5224             end if;
5225
5226             Typ := Find_Dispatching_Type (Subp);
5227
5228             --  If only one Argument defaults are :
5229             --    . DTC_Entity is the default Vtable pointer
5230             --    . DT_Position will be set at the freezing point
5231
5232             if Arg_Count = 1 then
5233                Set_DTC_Entity (Subp, Tag_Component (Typ));
5234                return;
5235             end if;
5236
5237             --  Second argument is a component name of type Vtable_Ptr
5238
5239             Arg := Expression (Arg2);
5240
5241             if Nkind (Arg) /= N_Identifier then
5242                Error_Msg_NE ("must be a& component name", Arg, Typ);
5243                raise Pragma_Exit;
5244             end if;
5245
5246             DTC := First_Component (Typ);
5247             while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5248                Next_Component (DTC);
5249             end loop;
5250
5251             if No (DTC) then
5252                Error_Msg_NE ("must be a& component name", Arg, Typ);
5253                raise Pragma_Exit;
5254
5255             elsif Etype (DTC) /= VTP_Type then
5256                Wrong_Type (Arg, VTP_Type);
5257                return;
5258             end if;
5259
5260             --  Third argument is an integer (DT_Position)
5261
5262             Arg := Expression (Arg3);
5263             Analyze_And_Resolve (Arg, Any_Integer);
5264
5265             if not Is_Static_Expression (Arg) then
5266                Flag_Non_Static_Expr
5267                  ("third argument of pragma CPP_Virtual must be static!",
5268                   Arg3);
5269                raise Pragma_Exit;
5270
5271             else
5272                V := Expr_Value (Expression (Arg3));
5273
5274                if V <= 0 then
5275                   Error_Pragma_Arg
5276                     ("third argument of pragma% must be positive",
5277                      Arg3);
5278
5279                else
5280                   Set_DTC_Entity (Subp, DTC);
5281                   Set_DT_Position (Subp, V);
5282                end if;
5283             end if;
5284          end CPP_Virtual;
5285
5286          ----------------
5287          -- CPP_Vtable --
5288          ----------------
5289
5290          --  pragma CPP_Vtable (
5291          --    [Entity =>]       LOCAL_NAME
5292          --    [Vtable_Ptr =>]   LOCAL_NAME,
5293          --    [Entry_Count =>]  static_integer_EXPRESSION);
5294
5295          when Pragma_CPP_Vtable => CPP_Vtable : declare
5296             Arg      : Node_Id;
5297             Typ      : Entity_Id;
5298             VTP_Type : constant Entity_Id  := RTE (RE_Vtable_Ptr);
5299             DTC      : Entity_Id;
5300             V        : Uint;
5301             Elmt     : Elmt_Id;
5302
5303          begin
5304             GNAT_Pragma;
5305             Check_Arg_Count (3);
5306             Check_Optional_Identifier (Arg1, Name_Entity);
5307             Check_Optional_Identifier (Arg2, "vtable_ptr");
5308             Check_Optional_Identifier (Arg3, "entry_count");
5309             Check_Arg_Is_Local_Name (Arg1);
5310
5311             --  First argument is a record type name
5312
5313             Arg := Expression (Arg1);
5314             Analyze (Arg);
5315
5316             if Etype (Arg) = Any_Type then
5317                return;
5318             else
5319                Typ := Entity (Arg);
5320             end if;
5321
5322             if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
5323                Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
5324             end if;
5325
5326             --  Second argument is a component name of type Vtable_Ptr
5327
5328             Arg := Expression (Arg2);
5329
5330             if Nkind (Arg) /= N_Identifier then
5331                Error_Msg_NE ("must be a& component name", Arg, Typ);
5332                raise Pragma_Exit;
5333             end if;
5334
5335             DTC := First_Component (Typ);
5336             while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5337                Next_Component (DTC);
5338             end loop;
5339
5340             if No (DTC) then
5341                Error_Msg_NE ("must be a& component name", Arg, Typ);
5342                raise Pragma_Exit;
5343
5344             elsif Etype (DTC) /= VTP_Type then
5345                Wrong_Type (DTC, VTP_Type);
5346                return;
5347
5348             --  If it is the first pragma Vtable, This becomes the default tag
5349
5350             elsif (not Is_Tag (DTC))
5351               and then DT_Entry_Count (Tag_Component (Typ)) = No_Uint
5352             then
5353                Set_Is_Tag (Tag_Component (Typ), False);
5354                Set_Is_Tag (DTC, True);
5355                Set_DT_Entry_Count (DTC, No_Uint);
5356             end if;
5357
5358             --  Those pragmas must appear before any primitive operation
5359             --  definition (except inherited ones) otherwise the default
5360             --  may be wrong
5361
5362             Elmt := First_Elmt (Primitive_Operations (Typ));
5363             while Present (Elmt) loop
5364                if No (Alias (Node (Elmt))) then
5365                   Error_Msg_Sloc := Sloc (Node (Elmt));
5366                   Error_Pragma
5367                     ("pragma% must appear before this primitive operation");
5368                end if;
5369
5370                Next_Elmt (Elmt);
5371             end loop;
5372
5373             --  Third argument is an integer (DT_Entry_Count)
5374
5375             Arg := Expression (Arg3);
5376             Analyze_And_Resolve (Arg, Any_Integer);
5377
5378             if not Is_Static_Expression (Arg) then
5379                Flag_Non_Static_Expr
5380                  ("entry count for pragma CPP_Vtable must be a static " &
5381                   "expression!", Arg3);
5382                raise Pragma_Exit;
5383
5384             else
5385                V := Expr_Value (Expression (Arg3));
5386
5387                if V <= 0 then
5388                   Error_Pragma_Arg
5389                     ("entry count for pragma% must be positive", Arg3);
5390                else
5391                   Set_DT_Entry_Count (DTC, V);
5392                end if;
5393             end if;
5394          end CPP_Vtable;
5395
5396          -----------
5397          -- Debug --
5398          -----------
5399
5400          --  pragma Debug (PROCEDURE_CALL_STATEMENT);
5401
5402          when Pragma_Debug => Debug : begin
5403             GNAT_Pragma;
5404
5405             --  Rewrite into a conditional with a static condition
5406
5407             Rewrite (N, Make_Implicit_If_Statement (N,
5408               Condition => New_Occurrence_Of (Boolean_Literals (
5409                 Assertions_Enabled and Expander_Active), Loc),
5410               Then_Statements => New_List (
5411                 Relocate_Node (Debug_Statement (N)))));
5412             Analyze (N);
5413          end Debug;
5414
5415          ---------------------
5416          -- Detect_Blocking --
5417          ---------------------
5418
5419          --  pragma Detect_Blocking;
5420
5421          when Pragma_Detect_Blocking =>
5422             GNAT_Pragma;
5423             Check_Arg_Count (0);
5424             Check_Valid_Configuration_Pragma;
5425             Detect_Blocking := True;
5426
5427          -------------------
5428          -- Discard_Names --
5429          -------------------
5430
5431          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
5432
5433          when Pragma_Discard_Names => Discard_Names : declare
5434             E_Id : Entity_Id;
5435             E    : Entity_Id;
5436
5437          begin
5438             Check_Ada_83_Warning;
5439
5440             --  Deal with configuration pragma case
5441
5442             if Arg_Count = 0 and then Is_Configuration_Pragma then
5443                Global_Discard_Names := True;
5444                return;
5445
5446             --  Otherwise, check correct appropriate context
5447
5448             else
5449                Check_Is_In_Decl_Part_Or_Package_Spec;
5450
5451                if Arg_Count = 0 then
5452
5453                   --  If there is no parameter, then from now on this pragma
5454                   --  applies to any enumeration, exception or tagged type
5455                   --  defined in the current declarative part.
5456
5457                   Set_Discard_Names (Current_Scope);
5458                   return;
5459
5460                else
5461                   Check_Arg_Count (1);
5462                   Check_Optional_Identifier (Arg1, Name_On);
5463                   Check_Arg_Is_Local_Name (Arg1);
5464                   E_Id := Expression (Arg1);
5465
5466                   if Etype (E_Id) = Any_Type then
5467                      return;
5468                   else
5469                      E := Entity (E_Id);
5470                   end if;
5471
5472                   if (Is_First_Subtype (E)
5473                        and then (Is_Enumeration_Type (E)
5474                                   or else Is_Tagged_Type (E)))
5475                     or else Ekind (E) = E_Exception
5476                   then
5477                      Set_Discard_Names (E);
5478                   else
5479                      Error_Pragma_Arg
5480                        ("inappropriate entity for pragma%", Arg1);
5481                   end if;
5482                end if;
5483             end if;
5484          end Discard_Names;
5485
5486          ---------------
5487          -- Elaborate --
5488          ---------------
5489
5490          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5491
5492          when Pragma_Elaborate => Elaborate : declare
5493             Plist       : List_Id;
5494             Parent_Node : Node_Id;
5495             Arg         : Node_Id;
5496             Citem       : Node_Id;
5497
5498          begin
5499             --  Pragma must be in context items list of a compilation unit
5500
5501             if not Is_List_Member (N) then
5502                Pragma_Misplaced;
5503                return;
5504
5505             else
5506                Plist := List_Containing (N);
5507                Parent_Node := Parent (Plist);
5508
5509                if Parent_Node = Empty
5510                  or else Nkind (Parent_Node) /= N_Compilation_Unit
5511                  or else Context_Items (Parent_Node) /= Plist
5512                then
5513                   Pragma_Misplaced;
5514                   return;
5515                end if;
5516             end if;
5517
5518             --  Must be at least one argument
5519
5520             if Arg_Count = 0 then
5521                Error_Pragma ("pragma% requires at least one argument");
5522             end if;
5523
5524             --  In Ada 83 mode, there can be no items following it in the
5525             --  context list except other pragmas and implicit with clauses
5526             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5527             --  placement rule does not apply.
5528
5529             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5530                Citem := Next (N);
5531
5532                while Present (Citem) loop
5533                   if Nkind (Citem) = N_Pragma
5534                     or else (Nkind (Citem) = N_With_Clause
5535                               and then Implicit_With (Citem))
5536                   then
5537                      null;
5538                   else
5539                      Error_Pragma
5540                        ("(Ada 83) pragma% must be at end of context clause");
5541                   end if;
5542
5543                   Next (Citem);
5544                end loop;
5545             end if;
5546
5547             --  Finally, the arguments must all be units mentioned in a with
5548             --  clause in the same context clause. Note we already checked
5549             --  (in Par.Prag) that the arguments are either identifiers or
5550
5551             Arg := Arg1;
5552             Outer : while Present (Arg) loop
5553                Citem := First (Plist);
5554
5555                Inner : while Citem /= N loop
5556                   if Nkind (Citem) = N_With_Clause
5557                     and then Same_Name (Name (Citem), Expression (Arg))
5558                   then
5559                      Set_Elaborate_Present (Citem, True);
5560                      Set_Unit_Name (Expression (Arg), Name (Citem));
5561                      Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5562                      exit Inner;
5563                   end if;
5564
5565                   Next (Citem);
5566                end loop Inner;
5567
5568                if Citem = N then
5569                   Error_Pragma_Arg
5570                     ("argument of pragma% is not with'ed unit", Arg);
5571                end if;
5572
5573                Next (Arg);
5574             end loop Outer;
5575
5576             --  Give a warning if operating in static mode with -gnatwl
5577             --  (elaboration warnings eanbled) switch set.
5578
5579             if Elab_Warnings and not Dynamic_Elaboration_Checks then
5580                Error_Msg_N
5581                  ("?use of pragma Elaborate may not be safe", N);
5582                Error_Msg_N
5583                  ("?use pragma Elaborate_All instead if possible", N);
5584             end if;
5585          end Elaborate;
5586
5587          -------------------
5588          -- Elaborate_All --
5589          -------------------
5590
5591          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5592
5593          when Pragma_Elaborate_All => Elaborate_All : declare
5594             Plist       : List_Id;
5595             Parent_Node : Node_Id;
5596             Arg         : Node_Id;
5597             Citem       : Node_Id;
5598
5599          begin
5600             Check_Ada_83_Warning;
5601
5602             --  Pragma must be in context items list of a compilation unit
5603
5604             if not Is_List_Member (N) then
5605                Pragma_Misplaced;
5606                return;
5607
5608             else
5609                Plist := List_Containing (N);
5610                Parent_Node := Parent (Plist);
5611
5612                if Parent_Node = Empty
5613                  or else Nkind (Parent_Node) /= N_Compilation_Unit
5614                  or else Context_Items (Parent_Node) /= Plist
5615                then
5616                   Pragma_Misplaced;
5617                   return;
5618                end if;
5619             end if;
5620
5621             --  Must be at least one argument
5622
5623             if Arg_Count = 0 then
5624                Error_Pragma ("pragma% requires at least one argument");
5625             end if;
5626
5627             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
5628             --  have to appear at the end of the context clause, but may
5629             --  appear mixed in with other items, even in Ada 83 mode.
5630
5631             --  Final check: the arguments must all be units mentioned in
5632             --  a with clause in the same context clause. Note that we
5633             --  already checked (in Par.Prag) that all the arguments are
5634             --  either identifiers or selected components.
5635
5636             Arg := Arg1;
5637             Outr : while Present (Arg) loop
5638                Citem := First (Plist);
5639
5640                Innr : while Citem /= N loop
5641                   if Nkind (Citem) = N_With_Clause
5642                     and then Same_Name (Name (Citem), Expression (Arg))
5643                   then
5644                      Set_Elaborate_All_Present (Citem, True);
5645                      Set_Unit_Name (Expression (Arg), Name (Citem));
5646                      Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5647                      exit Innr;
5648                   end if;
5649
5650                   Next (Citem);
5651                end loop Innr;
5652
5653                if Citem = N then
5654                   Set_Error_Posted (N);
5655                   Error_Pragma_Arg
5656                     ("argument of pragma% is not with'ed unit", Arg);
5657                end if;
5658
5659                Next (Arg);
5660             end loop Outr;
5661          end Elaborate_All;
5662
5663          --------------------
5664          -- Elaborate_Body --
5665          --------------------
5666
5667          --  pragma Elaborate_Body [( library_unit_NAME )];
5668
5669          when Pragma_Elaborate_Body => Elaborate_Body : declare
5670             Cunit_Node : Node_Id;
5671             Cunit_Ent  : Entity_Id;
5672
5673          begin
5674             Check_Ada_83_Warning;
5675             Check_Valid_Library_Unit_Pragma;
5676
5677             if Nkind (N) = N_Null_Statement then
5678                return;
5679             end if;
5680
5681             Cunit_Node := Cunit (Current_Sem_Unit);
5682             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
5683
5684             if Nkind (Unit (Cunit_Node)) = N_Package_Body
5685                  or else
5686                Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
5687             then
5688                Error_Pragma ("pragma% must refer to a spec, not a body");
5689             else
5690                Set_Body_Required (Cunit_Node, True);
5691                Set_Has_Pragma_Elaborate_Body     (Cunit_Ent);
5692
5693                --  If we are in dynamic elaboration mode, then we suppress
5694                --  elaboration warnings for the unit, since it is definitely
5695                --  fine NOT to do dynamic checks at the first level (and such
5696                --  checks will be suppressed because no elaboration boolean
5697                --  is created for Elaborate_Body packages).
5698
5699                --  But in the static model of elaboration, Elaborate_Body is
5700                --  definitely NOT good enough to ensure elaboration safety on
5701                --  its own, since the body may WITH other units that are not
5702                --  safe from an elaboration point of view, so a client must
5703                --  still do an Elaborate_All on such units.
5704
5705                --  Debug flag -gnatdD restores the old behavior of 3.13,
5706                --  where Elaborate_Body always suppressed elab warnings.
5707
5708                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
5709                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
5710                end if;
5711             end if;
5712          end Elaborate_Body;
5713
5714          ------------------------
5715          -- Elaboration_Checks --
5716          ------------------------
5717
5718          --  pragma Elaboration_Checks (Static | Dynamic);
5719
5720          when Pragma_Elaboration_Checks =>
5721             GNAT_Pragma;
5722             Check_Arg_Count (1);
5723             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
5724             Dynamic_Elaboration_Checks :=
5725               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
5726
5727          ---------------
5728          -- Eliminate --
5729          ---------------
5730
5731          --  pragma Eliminate (
5732          --      [Unit_Name       =>]  IDENTIFIER |
5733          --                            SELECTED_COMPONENT
5734          --    [,[Entity          =>]  IDENTIFIER |
5735          --                            SELECTED_COMPONENT |
5736          --                            STRING_LITERAL]
5737          --    [,]OVERLOADING_RESOLUTION);
5738
5739          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
5740          --                             SOURCE_LOCATION
5741
5742          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
5743          --                                        FUNCTION_PROFILE
5744
5745          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
5746
5747          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
5748          --                       Result_Type => result_SUBTYPE_NAME]
5749
5750          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
5751          --  SUBTYPE_NAME    ::= STRING_LITERAL
5752
5753          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
5754          --  SOURCE_TRACE    ::= STRING_LITERAL
5755
5756          when Pragma_Eliminate => Eliminate : declare
5757             Args  : Args_List (1 .. 5);
5758             Names : constant Name_List (1 .. 5) := (
5759                       Name_Unit_Name,
5760                       Name_Entity,
5761                       Name_Parameter_Types,
5762                       Name_Result_Type,
5763                       Name_Source_Location);
5764
5765             Unit_Name       : Node_Id renames Args (1);
5766             Entity          : Node_Id renames Args (2);
5767             Parameter_Types : Node_Id renames Args (3);
5768             Result_Type     : Node_Id renames Args (4);
5769             Source_Location : Node_Id renames Args (5);
5770
5771          begin
5772             GNAT_Pragma;
5773             Check_Valid_Configuration_Pragma;
5774             Gather_Associations (Names, Args);
5775
5776             if No (Unit_Name) then
5777                Error_Pragma ("missing Unit_Name argument for pragma%");
5778             end if;
5779
5780             if No (Entity)
5781               and then (Present (Parameter_Types)
5782                           or else
5783                         Present (Result_Type)
5784                           or else
5785                         Present (Source_Location))
5786             then
5787                Error_Pragma ("missing Entity argument for pragma%");
5788             end if;
5789
5790             if (Present (Parameter_Types)
5791                        or else
5792                 Present (Result_Type))
5793               and then
5794                 Present (Source_Location)
5795             then
5796                Error_Pragma
5797                  ("parameter profile and source location can not " &
5798                   "be used together in pragma%");
5799             end if;
5800
5801             Process_Eliminate_Pragma
5802               (N,
5803                Unit_Name,
5804                Entity,
5805                Parameter_Types,
5806                Result_Type,
5807                Source_Location);
5808          end Eliminate;
5809
5810          -------------------------
5811          -- Explicit_Overriding --
5812          -------------------------
5813
5814          when Pragma_Explicit_Overriding =>
5815             Check_Valid_Configuration_Pragma;
5816             Check_Arg_Count (0);
5817             Explicit_Overriding := True;
5818
5819          ------------
5820          -- Export --
5821          ------------
5822
5823          --  pragma Export (
5824          --    [   Convention    =>] convention_IDENTIFIER,
5825          --    [   Entity        =>] local_NAME
5826          --    [, [External_Name =>] static_string_EXPRESSION ]
5827          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
5828
5829          when Pragma_Export => Export : declare
5830             C      : Convention_Id;
5831             Def_Id : Entity_Id;
5832
5833          begin
5834             Check_Ada_83_Warning;
5835             Check_At_Least_N_Arguments (2);
5836             Check_At_Most_N_Arguments  (4);
5837             Process_Convention (C, Def_Id);
5838
5839             if Ekind (Def_Id) /= E_Constant then
5840                Note_Possible_Modification (Expression (Arg2));
5841             end if;
5842
5843             Process_Interface_Name (Def_Id, Arg3, Arg4);
5844             Set_Exported (Def_Id, Arg2);
5845          end Export;
5846
5847          ----------------------
5848          -- Export_Exception --
5849          ----------------------
5850
5851          --  pragma Export_Exception (
5852          --        [Internal         =>] LOCAL_NAME,
5853          --     [, [External         =>] EXTERNAL_SYMBOL,]
5854          --     [, [Form     =>] Ada | VMS]
5855          --     [, [Code     =>] static_integer_EXPRESSION]);
5856
5857          when Pragma_Export_Exception => Export_Exception : declare
5858             Args  : Args_List (1 .. 4);
5859             Names : constant Name_List (1 .. 4) := (
5860                       Name_Internal,
5861                       Name_External,
5862                       Name_Form,
5863                       Name_Code);
5864
5865             Internal : Node_Id renames Args (1);
5866             External : Node_Id renames Args (2);
5867             Form     : Node_Id renames Args (3);
5868             Code     : Node_Id renames Args (4);
5869
5870          begin
5871             if Inside_A_Generic then
5872                Error_Pragma ("pragma% cannot be used for generic entities");
5873             end if;
5874
5875             Gather_Associations (Names, Args);
5876             Process_Extended_Import_Export_Exception_Pragma (
5877               Arg_Internal => Internal,
5878               Arg_External => External,
5879               Arg_Form     => Form,
5880               Arg_Code     => Code);
5881
5882             if not Is_VMS_Exception (Entity (Internal)) then
5883                Set_Exported (Entity (Internal), Internal);
5884             end if;
5885          end Export_Exception;
5886
5887          ---------------------
5888          -- Export_Function --
5889          ---------------------
5890
5891          --  pragma Export_Function (
5892          --        [Internal         =>] LOCAL_NAME,
5893          --     [, [External         =>] EXTERNAL_SYMBOL,]
5894          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
5895          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
5896          --     [, [Mechanism        =>] MECHANISM]
5897          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
5898
5899          --  EXTERNAL_SYMBOL ::=
5900          --    IDENTIFIER
5901          --  | static_string_EXPRESSION
5902
5903          --  PARAMETER_TYPES ::=
5904          --    null
5905          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5906
5907          --  TYPE_DESIGNATOR ::=
5908          --    subtype_NAME
5909          --  | subtype_Name ' Access
5910
5911          --  MECHANISM ::=
5912          --    MECHANISM_NAME
5913          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5914
5915          --  MECHANISM_ASSOCIATION ::=
5916          --    [formal_parameter_NAME =>] MECHANISM_NAME
5917
5918          --  MECHANISM_NAME ::=
5919          --    Value
5920          --  | Reference
5921          --  | Descriptor [([Class =>] CLASS_NAME)]
5922
5923          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5924
5925          when Pragma_Export_Function => Export_Function : declare
5926             Args  : Args_List (1 .. 6);
5927             Names : constant Name_List (1 .. 6) := (
5928                       Name_Internal,
5929                       Name_External,
5930                       Name_Parameter_Types,
5931                       Name_Result_Type,
5932                       Name_Mechanism,
5933                       Name_Result_Mechanism);
5934
5935             Internal         : Node_Id renames Args (1);
5936             External         : Node_Id renames Args (2);
5937             Parameter_Types  : Node_Id renames Args (3);
5938             Result_Type      : Node_Id renames Args (4);
5939             Mechanism        : Node_Id renames Args (5);
5940             Result_Mechanism : Node_Id renames Args (6);
5941
5942          begin
5943             GNAT_Pragma;
5944             Gather_Associations (Names, Args);
5945             Process_Extended_Import_Export_Subprogram_Pragma (
5946               Arg_Internal         => Internal,
5947               Arg_External         => External,
5948               Arg_Parameter_Types  => Parameter_Types,
5949               Arg_Result_Type      => Result_Type,
5950               Arg_Mechanism        => Mechanism,
5951               Arg_Result_Mechanism => Result_Mechanism);
5952          end Export_Function;
5953
5954          -------------------
5955          -- Export_Object --
5956          -------------------
5957
5958          --  pragma Export_Object (
5959          --        [Internal =>] LOCAL_NAME,
5960          --     [, [External =>] EXTERNAL_SYMBOL]
5961          --     [, [Size     =>] EXTERNAL_SYMBOL]);
5962
5963          --  EXTERNAL_SYMBOL ::=
5964          --    IDENTIFIER
5965          --  | static_string_EXPRESSION
5966
5967          --  PARAMETER_TYPES ::=
5968          --    null
5969          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5970
5971          --  TYPE_DESIGNATOR ::=
5972          --    subtype_NAME
5973          --  | subtype_Name ' Access
5974
5975          --  MECHANISM ::=
5976          --    MECHANISM_NAME
5977          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5978
5979          --  MECHANISM_ASSOCIATION ::=
5980          --    [formal_parameter_NAME =>] MECHANISM_NAME
5981
5982          --  MECHANISM_NAME ::=
5983          --    Value
5984          --  | Reference
5985          --  | Descriptor [([Class =>] CLASS_NAME)]
5986
5987          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5988
5989          when Pragma_Export_Object => Export_Object : declare
5990             Args  : Args_List (1 .. 3);
5991             Names : constant Name_List (1 .. 3) := (
5992                       Name_Internal,
5993                       Name_External,
5994                       Name_Size);
5995
5996             Internal : Node_Id renames Args (1);
5997             External : Node_Id renames Args (2);
5998             Size     : Node_Id renames Args (3);
5999
6000          begin
6001             GNAT_Pragma;
6002             Gather_Associations (Names, Args);
6003             Process_Extended_Import_Export_Object_Pragma (
6004               Arg_Internal => Internal,
6005               Arg_External => External,
6006               Arg_Size     => Size);
6007          end Export_Object;
6008
6009          ----------------------
6010          -- Export_Procedure --
6011          ----------------------
6012
6013          --  pragma Export_Procedure (
6014          --        [Internal         =>] LOCAL_NAME,
6015          --     [, [External         =>] EXTERNAL_SYMBOL,]
6016          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
6017          --     [, [Mechanism        =>] MECHANISM]);
6018
6019          --  EXTERNAL_SYMBOL ::=
6020          --    IDENTIFIER
6021          --  | static_string_EXPRESSION
6022
6023          --  PARAMETER_TYPES ::=
6024          --    null
6025          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6026
6027          --  TYPE_DESIGNATOR ::=
6028          --    subtype_NAME
6029          --  | subtype_Name ' Access
6030
6031          --  MECHANISM ::=
6032          --    MECHANISM_NAME
6033          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6034
6035          --  MECHANISM_ASSOCIATION ::=
6036          --    [formal_parameter_NAME =>] MECHANISM_NAME
6037
6038          --  MECHANISM_NAME ::=
6039          --    Value
6040          --  | Reference
6041          --  | Descriptor [([Class =>] CLASS_NAME)]
6042
6043          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6044
6045          when Pragma_Export_Procedure => Export_Procedure : declare
6046             Args  : Args_List (1 .. 4);
6047             Names : constant Name_List (1 .. 4) := (
6048                       Name_Internal,
6049                       Name_External,
6050                       Name_Parameter_Types,
6051                       Name_Mechanism);
6052
6053             Internal        : Node_Id renames Args (1);
6054             External        : Node_Id renames Args (2);
6055             Parameter_Types : Node_Id renames Args (3);
6056             Mechanism       : Node_Id renames Args (4);
6057
6058          begin
6059             GNAT_Pragma;
6060             Gather_Associations (Names, Args);
6061             Process_Extended_Import_Export_Subprogram_Pragma (
6062               Arg_Internal        => Internal,
6063               Arg_External        => External,
6064               Arg_Parameter_Types => Parameter_Types,
6065               Arg_Mechanism       => Mechanism);
6066          end Export_Procedure;
6067
6068          ------------------
6069          -- Export_Value --
6070          ------------------
6071
6072          --  pragma Export_Value (
6073          --     [Value     =>] static_integer_EXPRESSION,
6074          --     [Link_Name =>] static_string_EXPRESSION);
6075
6076          when Pragma_Export_Value =>
6077             GNAT_Pragma;
6078             Check_Arg_Count (2);
6079
6080             Check_Optional_Identifier (Arg1, Name_Value);
6081             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6082
6083             Check_Optional_Identifier (Arg2, Name_Link_Name);
6084             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6085
6086          -----------------------------
6087          -- Export_Valued_Procedure --
6088          -----------------------------
6089
6090          --  pragma Export_Valued_Procedure (
6091          --        [Internal         =>] LOCAL_NAME,
6092          --     [, [External         =>] EXTERNAL_SYMBOL,]
6093          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
6094          --     [, [Mechanism        =>] MECHANISM]);
6095
6096          --  EXTERNAL_SYMBOL ::=
6097          --    IDENTIFIER
6098          --  | static_string_EXPRESSION
6099
6100          --  PARAMETER_TYPES ::=
6101          --    null
6102          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6103
6104          --  TYPE_DESIGNATOR ::=
6105          --    subtype_NAME
6106          --  | subtype_Name ' Access
6107
6108          --  MECHANISM ::=
6109          --    MECHANISM_NAME
6110          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6111
6112          --  MECHANISM_ASSOCIATION ::=
6113          --    [formal_parameter_NAME =>] MECHANISM_NAME
6114
6115          --  MECHANISM_NAME ::=
6116          --    Value
6117          --  | Reference
6118          --  | Descriptor [([Class =>] CLASS_NAME)]
6119
6120          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6121
6122          when Pragma_Export_Valued_Procedure =>
6123          Export_Valued_Procedure : declare
6124             Args  : Args_List (1 .. 4);
6125             Names : constant Name_List (1 .. 4) := (
6126                       Name_Internal,
6127                       Name_External,
6128                       Name_Parameter_Types,
6129                       Name_Mechanism);
6130
6131             Internal        : Node_Id renames Args (1);
6132             External        : Node_Id renames Args (2);
6133             Parameter_Types : Node_Id renames Args (3);
6134             Mechanism       : Node_Id renames Args (4);
6135
6136          begin
6137             GNAT_Pragma;
6138             Gather_Associations (Names, Args);
6139             Process_Extended_Import_Export_Subprogram_Pragma (
6140               Arg_Internal        => Internal,
6141               Arg_External        => External,
6142               Arg_Parameter_Types => Parameter_Types,
6143               Arg_Mechanism       => Mechanism);
6144          end Export_Valued_Procedure;
6145
6146          -------------------
6147          -- Extend_System --
6148          -------------------
6149
6150          --  pragma Extend_System ([Name =>] Identifier);
6151
6152          when Pragma_Extend_System => Extend_System : declare
6153          begin
6154             GNAT_Pragma;
6155             Check_Valid_Configuration_Pragma;
6156             Check_Arg_Count (1);
6157             Check_Optional_Identifier (Arg1, Name_Name);
6158             Check_Arg_Is_Identifier (Arg1);
6159
6160             Get_Name_String (Chars (Expression (Arg1)));
6161
6162             if Name_Len > 4
6163               and then Name_Buffer (1 .. 4) = "aux_"
6164             then
6165                if Present (System_Extend_Pragma_Arg) then
6166                   if Chars (Expression (Arg1)) =
6167                      Chars (Expression (System_Extend_Pragma_Arg))
6168                   then
6169                      null;
6170                   else
6171                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
6172                      Error_Pragma ("pragma% conflicts with that at#");
6173                   end if;
6174
6175                else
6176                   System_Extend_Pragma_Arg := Arg1;
6177
6178                   if not GNAT_Mode then
6179                      System_Extend_Unit := Arg1;
6180                   end if;
6181                end if;
6182             else
6183                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
6184             end if;
6185          end Extend_System;
6186
6187          ------------------------
6188          -- Extensions_Allowed --
6189          ------------------------
6190
6191          --  pragma Extensions_Allowed (ON | OFF);
6192
6193          when Pragma_Extensions_Allowed =>
6194             GNAT_Pragma;
6195             Check_Arg_Count (1);
6196             Check_No_Identifiers;
6197             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6198
6199             if Chars (Expression (Arg1)) = Name_On then
6200                Extensions_Allowed := True;
6201                Ada_Version := Ada_Version_Type'Last;
6202             else
6203                Extensions_Allowed := False;
6204                Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95);
6205             end if;
6206
6207          --------------
6208          -- External --
6209          --------------
6210
6211          --  pragma External (
6212          --    [   Convention    =>] convention_IDENTIFIER,
6213          --    [   Entity        =>] local_NAME
6214          --    [, [External_Name =>] static_string_EXPRESSION ]
6215          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
6216
6217          when Pragma_External => External : declare
6218             C      : Convention_Id;
6219             Def_Id : Entity_Id;
6220
6221          begin
6222             GNAT_Pragma;
6223             Check_At_Least_N_Arguments (2);
6224             Check_At_Most_N_Arguments  (4);
6225             Process_Convention (C, Def_Id);
6226             Note_Possible_Modification (Expression (Arg2));
6227             Process_Interface_Name (Def_Id, Arg3, Arg4);
6228             Set_Exported (Def_Id, Arg2);
6229          end External;
6230
6231          --------------------------
6232          -- External_Name_Casing --
6233          --------------------------
6234
6235          --  pragma External_Name_Casing (
6236          --    UPPERCASE | LOWERCASE
6237          --    [, AS_IS | UPPERCASE | LOWERCASE]);
6238
6239          when Pragma_External_Name_Casing => External_Name_Casing : declare
6240          begin
6241             GNAT_Pragma;
6242             Check_No_Identifiers;
6243
6244             if Arg_Count = 2 then
6245                Check_Arg_Is_One_Of
6246                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
6247
6248                case Chars (Get_Pragma_Arg (Arg2)) is
6249                   when Name_As_Is     =>
6250                      Opt.External_Name_Exp_Casing := As_Is;
6251
6252                   when Name_Uppercase =>
6253                      Opt.External_Name_Exp_Casing := Uppercase;
6254
6255                   when Name_Lowercase =>
6256                      Opt.External_Name_Exp_Casing := Lowercase;
6257
6258                   when others =>
6259                      null;
6260                end case;
6261
6262             else
6263                Check_Arg_Count (1);
6264             end if;
6265
6266             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
6267
6268             case Chars (Get_Pragma_Arg (Arg1)) is
6269                when Name_Uppercase =>
6270                   Opt.External_Name_Imp_Casing := Uppercase;
6271
6272                when Name_Lowercase =>
6273                   Opt.External_Name_Imp_Casing := Lowercase;
6274
6275                when others =>
6276                   null;
6277             end case;
6278          end External_Name_Casing;
6279
6280          ---------------------------
6281          -- Finalize_Storage_Only --
6282          ---------------------------
6283
6284          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
6285
6286          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
6287             Assoc   : constant Node_Id := Arg1;
6288             Type_Id : constant Node_Id := Expression (Assoc);
6289             Typ     : Entity_Id;
6290
6291          begin
6292             Check_No_Identifiers;
6293             Check_Arg_Count (1);
6294             Check_Arg_Is_Local_Name (Arg1);
6295
6296             Find_Type (Type_Id);
6297             Typ := Entity (Type_Id);
6298
6299             if Typ = Any_Type
6300               or else Rep_Item_Too_Early (Typ, N)
6301             then
6302                return;
6303             else
6304                Typ := Underlying_Type (Typ);
6305             end if;
6306
6307             if not Is_Controlled (Typ) then
6308                Error_Pragma ("pragma% must specify controlled type");
6309             end if;
6310
6311             Check_First_Subtype (Arg1);
6312
6313             if Finalize_Storage_Only (Typ) then
6314                Error_Pragma ("duplicate pragma%, only one allowed");
6315
6316             elsif not Rep_Item_Too_Late (Typ, N) then
6317                Set_Finalize_Storage_Only (Base_Type (Typ), True);
6318             end if;
6319          end Finalize_Storage;
6320
6321          --------------------------
6322          -- Float_Representation --
6323          --------------------------
6324
6325          --  pragma Float_Representation (VAX_Float | IEEE_Float);
6326
6327          when Pragma_Float_Representation => Float_Representation : declare
6328             Argx : Node_Id;
6329             Digs : Nat;
6330             Ent  : Entity_Id;
6331
6332          begin
6333             GNAT_Pragma;
6334
6335             if Arg_Count = 1 then
6336                Check_Valid_Configuration_Pragma;
6337             else
6338                Check_Arg_Count (2);
6339                Check_Optional_Identifier (Arg2, Name_Entity);
6340                Check_Arg_Is_Local_Name (Arg2);
6341             end if;
6342
6343             Check_No_Identifier (Arg1);
6344             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
6345
6346             if not OpenVMS_On_Target then
6347                if Chars (Expression (Arg1)) = Name_VAX_Float then
6348                   Error_Pragma
6349                     ("?pragma% ignored (applies only to Open'V'M'S)");
6350                end if;
6351
6352                return;
6353             end if;
6354
6355             --  One argument case
6356
6357             if Arg_Count = 1 then
6358
6359                if Chars (Expression (Arg1)) = Name_VAX_Float then
6360
6361                   if Opt.Float_Format = 'I' then
6362                      Error_Pragma ("'I'E'E'E format previously specified");
6363                   end if;
6364
6365                   Opt.Float_Format := 'V';
6366
6367                else
6368                   if Opt.Float_Format = 'V' then
6369                      Error_Pragma ("'V'A'X format previously specified");
6370                   end if;
6371
6372                   Opt.Float_Format := 'I';
6373                end if;
6374
6375                Set_Standard_Fpt_Formats;
6376
6377             --  Two argument case
6378
6379             else
6380                Argx := Get_Pragma_Arg (Arg2);
6381
6382                if not Is_Entity_Name (Argx)
6383                  or else not Is_Floating_Point_Type (Entity (Argx))
6384                then
6385                   Error_Pragma_Arg
6386                     ("second argument of% pragma must be floating-point type",
6387                      Arg2);
6388                end if;
6389
6390                Ent  := Entity (Argx);
6391                Digs := UI_To_Int (Digits_Value (Ent));
6392
6393                --  Two arguments, VAX_Float case
6394
6395                if Chars (Expression (Arg1)) = Name_VAX_Float then
6396
6397                   case Digs is
6398                      when  6 => Set_F_Float (Ent);
6399                      when  9 => Set_D_Float (Ent);
6400                      when 15 => Set_G_Float (Ent);
6401
6402                      when others =>
6403                         Error_Pragma_Arg
6404                           ("wrong digits value, must be 6,9 or 15", Arg2);
6405                   end case;
6406
6407                --  Two arguments, IEEE_Float case
6408
6409                else
6410                   case Digs is
6411                      when  6 => Set_IEEE_Short (Ent);
6412                      when 15 => Set_IEEE_Long  (Ent);
6413
6414                      when others =>
6415                         Error_Pragma_Arg
6416                           ("wrong digits value, must be 6 or 15", Arg2);
6417                   end case;
6418                end if;
6419             end if;
6420          end Float_Representation;
6421
6422          -----------
6423          -- Ident --
6424          -----------
6425
6426          --  pragma Ident (static_string_EXPRESSION)
6427
6428          --  Note: pragma Comment shares this processing. Pragma Comment
6429          --  is identical to Ident, except that the restriction of the
6430          --  argument to 31 characters and the placement restrictions
6431          --  are not enforced for pragma Comment.
6432
6433          when Pragma_Ident | Pragma_Comment => Ident : declare
6434             Str : Node_Id;
6435
6436          begin
6437             GNAT_Pragma;
6438             Check_Arg_Count (1);
6439             Check_No_Identifiers;
6440             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6441
6442             --  For pragma Ident, preserve DEC compatibility by requiring
6443             --  the pragma to appear in a declarative part or package spec.
6444
6445             if Prag_Id = Pragma_Ident then
6446                Check_Is_In_Decl_Part_Or_Package_Spec;
6447             end if;
6448
6449             Str := Expr_Value_S (Expression (Arg1));
6450
6451             declare
6452                CS : Node_Id;
6453                GP : Node_Id;
6454
6455             begin
6456                GP := Parent (Parent (N));
6457
6458                if Nkind (GP) = N_Package_Declaration
6459                     or else
6460                   Nkind (GP) = N_Generic_Package_Declaration
6461                then
6462                   GP := Parent (GP);
6463                end if;
6464
6465                --  If we have a compilation unit, then record the ident
6466                --  value, checking for improper duplication.
6467
6468                if Nkind (GP) = N_Compilation_Unit then
6469                   CS := Ident_String (Current_Sem_Unit);
6470
6471                   if Present (CS) then
6472
6473                      --  For Ident, we do not permit multiple instances
6474
6475                      if Prag_Id = Pragma_Ident then
6476                         Error_Pragma ("duplicate% pragma not permitted");
6477
6478                      --  For Comment, we concatenate the string, unless we
6479                      --  want to preserve the tree structure for ASIS.
6480
6481                      elsif not ASIS_Mode then
6482                         Start_String (Strval (CS));
6483                         Store_String_Char (' ');
6484                         Store_String_Chars (Strval (Str));
6485                         Set_Strval (CS, End_String);
6486                      end if;
6487
6488                   else
6489                      --  In VMS, the effect of IDENT is achieved by passing
6490                      --  IDENTIFICATION=name as a --for-linker switch.
6491
6492                      if OpenVMS_On_Target then
6493                         Start_String;
6494                         Store_String_Chars
6495                           ("--for-linker=IDENTIFICATION=");
6496                         String_To_Name_Buffer (Strval (Str));
6497                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
6498
6499                         --  Only the last processed IDENT is saved. The main
6500                         --  purpose is so an IDENT associated with a main
6501                         --  procedure will be used in preference to an IDENT
6502                         --  associated with a with'd package.
6503
6504                         Replace_Linker_Option_String
6505                           (End_String, "--for-linker=IDENTIFICATION=");
6506                      end if;
6507
6508                      Set_Ident_String (Current_Sem_Unit, Str);
6509                   end if;
6510
6511                --  For subunits, we just ignore the Ident, since in GNAT
6512                --  these are not separate object files, and hence not
6513                --  separate units in the unit table.
6514
6515                elsif Nkind (GP) = N_Subunit then
6516                   null;
6517
6518                --  Otherwise we have a misplaced pragma Ident, but we ignore
6519                --  this if we are in an instantiation, since it comes from
6520                --  a generic, and has no relevance to the instantiation.
6521
6522                elsif Prag_Id = Pragma_Ident then
6523                   if Instantiation_Location (Loc) = No_Location then
6524                      Error_Pragma ("pragma% only allowed at outer level");
6525                   end if;
6526                end if;
6527             end;
6528          end Ident;
6529
6530          ------------
6531          -- Import --
6532          ------------
6533
6534          --  pragma Import (
6535          --    [   Convention    =>] convention_IDENTIFIER,
6536          --    [   Entity        =>] local_NAME
6537          --    [, [External_Name =>] static_string_EXPRESSION ]
6538          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
6539
6540          when Pragma_Import =>
6541             Check_Ada_83_Warning;
6542             Check_At_Least_N_Arguments (2);
6543             Check_At_Most_N_Arguments  (4);
6544             Process_Import_Or_Interface;
6545
6546          ----------------------
6547          -- Import_Exception --
6548          ----------------------
6549
6550          --  pragma Import_Exception (
6551          --        [Internal         =>] LOCAL_NAME,
6552          --     [, [External         =>] EXTERNAL_SYMBOL,]
6553          --     [, [Form     =>] Ada | VMS]
6554          --     [, [Code     =>] static_integer_EXPRESSION]);
6555
6556          when Pragma_Import_Exception => Import_Exception : declare
6557             Args  : Args_List (1 .. 4);
6558             Names : constant Name_List (1 .. 4) := (
6559                       Name_Internal,
6560                       Name_External,
6561                       Name_Form,
6562                       Name_Code);
6563
6564             Internal : Node_Id renames Args (1);
6565             External : Node_Id renames Args (2);
6566             Form     : Node_Id renames Args (3);
6567             Code     : Node_Id renames Args (4);
6568
6569          begin
6570             Gather_Associations (Names, Args);
6571
6572             if Present (External) and then Present (Code) then
6573                Error_Pragma
6574                  ("cannot give both External and Code options for pragma%");
6575             end if;
6576
6577             Process_Extended_Import_Export_Exception_Pragma (
6578               Arg_Internal => Internal,
6579               Arg_External => External,
6580               Arg_Form     => Form,
6581               Arg_Code     => Code);
6582
6583             if not Is_VMS_Exception (Entity (Internal)) then
6584                Set_Imported (Entity (Internal));
6585             end if;
6586          end Import_Exception;
6587
6588          ---------------------
6589          -- Import_Function --
6590          ---------------------
6591
6592          --  pragma Import_Function (
6593          --        [Internal                 =>] LOCAL_NAME,
6594          --     [, [External                 =>] EXTERNAL_SYMBOL]
6595          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
6596          --     [, [Result_Type              =>] SUBTYPE_MARK]
6597          --     [, [Mechanism                =>] MECHANISM]
6598          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
6599          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
6600
6601          --  EXTERNAL_SYMBOL ::=
6602          --    IDENTIFIER
6603          --  | static_string_EXPRESSION
6604
6605          --  PARAMETER_TYPES ::=
6606          --    null
6607          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6608
6609          --  TYPE_DESIGNATOR ::=
6610          --    subtype_NAME
6611          --  | subtype_Name ' Access
6612
6613          --  MECHANISM ::=
6614          --    MECHANISM_NAME
6615          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6616
6617          --  MECHANISM_ASSOCIATION ::=
6618          --    [formal_parameter_NAME =>] MECHANISM_NAME
6619
6620          --  MECHANISM_NAME ::=
6621          --    Value
6622          --  | Reference
6623          --  | Descriptor [([Class =>] CLASS_NAME)]
6624
6625          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6626
6627          when Pragma_Import_Function => Import_Function : declare
6628             Args  : Args_List (1 .. 7);
6629             Names : constant Name_List (1 .. 7) := (
6630                       Name_Internal,
6631                       Name_External,
6632                       Name_Parameter_Types,
6633                       Name_Result_Type,
6634                       Name_Mechanism,
6635                       Name_Result_Mechanism,
6636                       Name_First_Optional_Parameter);
6637
6638             Internal                 : Node_Id renames Args (1);
6639             External                 : Node_Id renames Args (2);
6640             Parameter_Types          : Node_Id renames Args (3);
6641             Result_Type              : Node_Id renames Args (4);
6642             Mechanism                : Node_Id renames Args (5);
6643             Result_Mechanism         : Node_Id renames Args (6);
6644             First_Optional_Parameter : Node_Id renames Args (7);
6645
6646          begin
6647             GNAT_Pragma;
6648             Gather_Associations (Names, Args);
6649             Process_Extended_Import_Export_Subprogram_Pragma (
6650               Arg_Internal                 => Internal,
6651               Arg_External                 => External,
6652               Arg_Parameter_Types          => Parameter_Types,
6653               Arg_Result_Type              => Result_Type,
6654               Arg_Mechanism                => Mechanism,
6655               Arg_Result_Mechanism         => Result_Mechanism,
6656               Arg_First_Optional_Parameter => First_Optional_Parameter);
6657          end Import_Function;
6658
6659          -------------------
6660          -- Import_Object --
6661          -------------------
6662
6663          --  pragma Import_Object (
6664          --        [Internal =>] LOCAL_NAME,
6665          --     [, [External =>] EXTERNAL_SYMBOL]
6666          --     [, [Size     =>] EXTERNAL_SYMBOL]);
6667
6668          --  EXTERNAL_SYMBOL ::=
6669          --    IDENTIFIER
6670          --  | static_string_EXPRESSION
6671
6672          when Pragma_Import_Object => Import_Object : declare
6673             Args  : Args_List (1 .. 3);
6674             Names : constant Name_List (1 .. 3) := (
6675                       Name_Internal,
6676                       Name_External,
6677                       Name_Size);
6678
6679             Internal : Node_Id renames Args (1);
6680             External : Node_Id renames Args (2);
6681             Size     : Node_Id renames Args (3);
6682
6683          begin
6684             GNAT_Pragma;
6685             Gather_Associations (Names, Args);
6686             Process_Extended_Import_Export_Object_Pragma (
6687               Arg_Internal => Internal,
6688               Arg_External => External,
6689               Arg_Size     => Size);
6690          end Import_Object;
6691
6692          ----------------------
6693          -- Import_Procedure --
6694          ----------------------
6695
6696          --  pragma Import_Procedure (
6697          --        [Internal                 =>] LOCAL_NAME,
6698          --     [, [External                 =>] EXTERNAL_SYMBOL]
6699          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
6700          --     [, [Mechanism                =>] MECHANISM]
6701          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
6702
6703          --  EXTERNAL_SYMBOL ::=
6704          --    IDENTIFIER
6705          --  | static_string_EXPRESSION
6706
6707          --  PARAMETER_TYPES ::=
6708          --    null
6709          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6710
6711          --  TYPE_DESIGNATOR ::=
6712          --    subtype_NAME
6713          --  | subtype_Name ' Access
6714
6715          --  MECHANISM ::=
6716          --    MECHANISM_NAME
6717          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6718
6719          --  MECHANISM_ASSOCIATION ::=
6720          --    [formal_parameter_NAME =>] MECHANISM_NAME
6721
6722          --  MECHANISM_NAME ::=
6723          --    Value
6724          --  | Reference
6725          --  | Descriptor [([Class =>] CLASS_NAME)]
6726
6727          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6728
6729          when Pragma_Import_Procedure => Import_Procedure : declare
6730             Args  : Args_List (1 .. 5);
6731             Names : constant Name_List (1 .. 5) := (
6732                       Name_Internal,
6733                       Name_External,
6734                       Name_Parameter_Types,
6735                       Name_Mechanism,
6736                       Name_First_Optional_Parameter);
6737
6738             Internal                 : Node_Id renames Args (1);
6739             External                 : Node_Id renames Args (2);
6740             Parameter_Types          : Node_Id renames Args (3);
6741             Mechanism                : Node_Id renames Args (4);
6742             First_Optional_Parameter : Node_Id renames Args (5);
6743
6744          begin
6745             GNAT_Pragma;
6746             Gather_Associations (Names, Args);
6747             Process_Extended_Import_Export_Subprogram_Pragma (
6748               Arg_Internal                 => Internal,
6749               Arg_External                 => External,
6750               Arg_Parameter_Types          => Parameter_Types,
6751               Arg_Mechanism                => Mechanism,
6752               Arg_First_Optional_Parameter => First_Optional_Parameter);
6753          end Import_Procedure;
6754
6755          -----------------------------
6756          -- Import_Valued_Procedure --
6757          -----------------------------
6758
6759          --  pragma Import_Valued_Procedure (
6760          --        [Internal                 =>] LOCAL_NAME,
6761          --     [, [External                 =>] EXTERNAL_SYMBOL]
6762          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
6763          --     [, [Mechanism                =>] MECHANISM]
6764          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
6765
6766          --  EXTERNAL_SYMBOL ::=
6767          --    IDENTIFIER
6768          --  | static_string_EXPRESSION
6769
6770          --  PARAMETER_TYPES ::=
6771          --    null
6772          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6773
6774          --  TYPE_DESIGNATOR ::=
6775          --    subtype_NAME
6776          --  | subtype_Name ' Access
6777
6778          --  MECHANISM ::=
6779          --    MECHANISM_NAME
6780          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6781
6782          --  MECHANISM_ASSOCIATION ::=
6783          --    [formal_parameter_NAME =>] MECHANISM_NAME
6784
6785          --  MECHANISM_NAME ::=
6786          --    Value
6787          --  | Reference
6788          --  | Descriptor [([Class =>] CLASS_NAME)]
6789
6790          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6791
6792          when Pragma_Import_Valued_Procedure =>
6793          Import_Valued_Procedure : declare
6794             Args  : Args_List (1 .. 5);
6795             Names : constant Name_List (1 .. 5) := (
6796                       Name_Internal,
6797                       Name_External,
6798                       Name_Parameter_Types,
6799                       Name_Mechanism,
6800                       Name_First_Optional_Parameter);
6801
6802             Internal                 : Node_Id renames Args (1);
6803             External                 : Node_Id renames Args (2);
6804             Parameter_Types          : Node_Id renames Args (3);
6805             Mechanism                : Node_Id renames Args (4);
6806             First_Optional_Parameter : Node_Id renames Args (5);
6807
6808          begin
6809             GNAT_Pragma;
6810             Gather_Associations (Names, Args);
6811             Process_Extended_Import_Export_Subprogram_Pragma (
6812               Arg_Internal                 => Internal,
6813               Arg_External                 => External,
6814               Arg_Parameter_Types          => Parameter_Types,
6815               Arg_Mechanism                => Mechanism,
6816               Arg_First_Optional_Parameter => First_Optional_Parameter);
6817          end Import_Valued_Procedure;
6818
6819          ------------------------
6820          -- Initialize_Scalars --
6821          ------------------------
6822
6823          --  pragma Initialize_Scalars;
6824
6825          when Pragma_Initialize_Scalars =>
6826             GNAT_Pragma;
6827             Check_Arg_Count (0);
6828             Check_Valid_Configuration_Pragma;
6829             Check_Restriction (No_Initialize_Scalars, N);
6830
6831             if not Restriction_Active (No_Initialize_Scalars) then
6832                Init_Or_Norm_Scalars := True;
6833                Initialize_Scalars := True;
6834             end if;
6835
6836          ------------
6837          -- Inline --
6838          ------------
6839
6840          --  pragma Inline ( NAME {, NAME} );
6841
6842          when Pragma_Inline =>
6843
6844             --  Pragma is active if inlining option is active
6845
6846             Process_Inline (Inline_Active);
6847
6848          -------------------
6849          -- Inline_Always --
6850          -------------------
6851
6852          --  pragma Inline_Always ( NAME {, NAME} );
6853
6854          when Pragma_Inline_Always =>
6855             Process_Inline (True);
6856
6857          --------------------
6858          -- Inline_Generic --
6859          --------------------
6860
6861          --  pragma Inline_Generic (NAME {, NAME});
6862
6863          when Pragma_Inline_Generic =>
6864             Process_Generic_List;
6865
6866          ----------------------
6867          -- Inspection_Point --
6868          ----------------------
6869
6870          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
6871
6872          when Pragma_Inspection_Point => Inspection_Point : declare
6873             Arg : Node_Id;
6874             Exp : Node_Id;
6875
6876          begin
6877             if Arg_Count > 0 then
6878                Arg := Arg1;
6879                loop
6880                   Exp := Expression (Arg);
6881                   Analyze (Exp);
6882
6883                   if not Is_Entity_Name (Exp)
6884                     or else not Is_Object (Entity (Exp))
6885                   then
6886                      Error_Pragma_Arg ("object name required", Arg);
6887                   end if;
6888
6889                   Next (Arg);
6890                   exit when No (Arg);
6891                end loop;
6892             end if;
6893          end Inspection_Point;
6894
6895          ---------------
6896          -- Interface --
6897          ---------------
6898
6899          --  pragma Interface (
6900          --    convention_IDENTIFIER,
6901          --    local_NAME );
6902
6903          when Pragma_Interface =>
6904             GNAT_Pragma;
6905             Check_Arg_Count (2);
6906             Check_No_Identifiers;
6907             Process_Import_Or_Interface;
6908
6909          --------------------
6910          -- Interface_Name --
6911          --------------------
6912
6913          --  pragma Interface_Name (
6914          --    [  Entity        =>] local_NAME
6915          --    [,[External_Name =>] static_string_EXPRESSION ]
6916          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
6917
6918          when Pragma_Interface_Name => Interface_Name : declare
6919             Id     : Node_Id;
6920             Def_Id : Entity_Id;
6921             Hom_Id : Entity_Id;
6922             Found  : Boolean;
6923
6924          begin
6925             GNAT_Pragma;
6926             Check_At_Least_N_Arguments (2);
6927             Check_At_Most_N_Arguments  (3);
6928             Id := Expression (Arg1);
6929             Analyze (Id);
6930
6931             if not Is_Entity_Name (Id) then
6932                Error_Pragma_Arg
6933                  ("first argument for pragma% must be entity name", Arg1);
6934             elsif Etype (Id) = Any_Type then
6935                return;
6936             else
6937                Def_Id := Entity (Id);
6938             end if;
6939
6940             --  Special DEC-compatible processing for the object case,
6941             --  forces object to be imported.
6942
6943             if Ekind (Def_Id) = E_Variable then
6944                Kill_Size_Check_Code (Def_Id);
6945                Note_Possible_Modification (Id);
6946
6947                --  Initialization is not allowed for imported variable
6948
6949                if Present (Expression (Parent (Def_Id)))
6950                  and then Comes_From_Source (Expression (Parent (Def_Id)))
6951                then
6952                   Error_Msg_Sloc := Sloc (Def_Id);
6953                   Error_Pragma_Arg
6954                     ("no initialization allowed for declaration of& #",
6955                      Arg2);
6956
6957                else
6958                   --  For compatibility, support VADS usage of providing both
6959                   --  pragmas Interface and Interface_Name to obtain the effect
6960                   --  of a single Import pragma.
6961
6962                   if Is_Imported (Def_Id)
6963                     and then Present (First_Rep_Item (Def_Id))
6964                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
6965                     and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
6966                   then
6967                      null;
6968                   else
6969                      Set_Imported (Def_Id);
6970                   end if;
6971
6972                   Set_Is_Public (Def_Id);
6973                   Process_Interface_Name (Def_Id, Arg2, Arg3);
6974                end if;
6975
6976             --  Otherwise must be subprogram
6977
6978             elsif not Is_Subprogram (Def_Id) then
6979                Error_Pragma_Arg
6980                  ("argument of pragma% is not subprogram", Arg1);
6981
6982             else
6983                Check_At_Most_N_Arguments (3);
6984                Hom_Id := Def_Id;
6985                Found := False;
6986
6987                --  Loop through homonyms
6988
6989                loop
6990                   Def_Id := Get_Base_Subprogram (Hom_Id);
6991
6992                   if Is_Imported (Def_Id) then
6993                      Process_Interface_Name (Def_Id, Arg2, Arg3);
6994                      Found := True;
6995                   end if;
6996
6997                   Hom_Id := Homonym (Hom_Id);
6998
6999                   exit when No (Hom_Id)
7000                     or else Scope (Hom_Id) /= Current_Scope;
7001                end loop;
7002
7003                if not Found then
7004                   Error_Pragma_Arg
7005                     ("argument of pragma% is not imported subprogram",
7006                      Arg1);
7007                end if;
7008             end if;
7009          end Interface_Name;
7010
7011          -----------------------
7012          -- Interrupt_Handler --
7013          -----------------------
7014
7015          --  pragma Interrupt_Handler (handler_NAME);
7016
7017          when Pragma_Interrupt_Handler =>
7018             Check_Ada_83_Warning;
7019             Check_Arg_Count (1);
7020             Check_No_Identifiers;
7021
7022             if No_Run_Time_Mode then
7023                Error_Msg_CRT ("Interrupt_Handler pragma", N);
7024             else
7025                Check_Interrupt_Or_Attach_Handler;
7026                Process_Interrupt_Or_Attach_Handler;
7027             end if;
7028
7029          ------------------------
7030          -- Interrupt_Priority --
7031          ------------------------
7032
7033          --  pragma Interrupt_Priority [(EXPRESSION)];
7034
7035          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
7036             P   : constant Node_Id := Parent (N);
7037             Arg : Node_Id;
7038
7039          begin
7040             Check_Ada_83_Warning;
7041
7042             if Arg_Count /= 0 then
7043                Arg := Expression (Arg1);
7044                Check_Arg_Count (1);
7045                Check_No_Identifiers;
7046
7047                --  The expression must be analyzed in the special manner
7048                --  described in "Handling of Default and Per-Object
7049                --  Expressions" in sem.ads.
7050
7051                Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
7052             end if;
7053
7054             if Nkind (P) /= N_Task_Definition
7055               and then Nkind (P) /= N_Protected_Definition
7056             then
7057                Pragma_Misplaced;
7058                return;
7059
7060             elsif Has_Priority_Pragma (P) then
7061                Error_Pragma ("duplicate pragma% not allowed");
7062
7063             else
7064                Set_Has_Priority_Pragma (P, True);
7065                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7066             end if;
7067          end Interrupt_Priority;
7068
7069          ---------------------
7070          -- Interrupt_State --
7071          ---------------------
7072
7073          --  pragma Interrupt_State (
7074          --    [Name  =>] INTERRUPT_ID,
7075          --    [State =>] INTERRUPT_STATE);
7076
7077          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
7078          --  INTERRUPT_STATE => System | Runtime | User
7079
7080          --  Note: if the interrupt id is given as an identifier, then
7081          --  it must be one of the identifiers in Ada.Interrupts.Names.
7082          --  Otherwise it is given as a static integer expression which
7083          --  must be in the range of Ada.Interrupts.Interrupt_ID.
7084
7085          when Pragma_Interrupt_State => Interrupt_State : declare
7086
7087             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
7088             --  This is the entity Ada.Interrupts.Interrupt_ID;
7089
7090             State_Type : Character;
7091             --  Set to 's'/'r'/'u' for System/Runtime/User
7092
7093             IST_Num : Pos;
7094             --  Index to entry in Interrupt_States table
7095
7096             Int_Val : Uint;
7097             --  Value of interrupt
7098
7099             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
7100             --  The first argument to the pragma
7101
7102             Int_Ent : Entity_Id;
7103             --  Interrupt entity in Ada.Interrupts.Names
7104
7105          begin
7106             GNAT_Pragma;
7107             Check_Arg_Count (2);
7108
7109             Check_Optional_Identifier (Arg1, Name_Name);
7110             Check_Optional_Identifier (Arg2, "state");
7111             Check_Arg_Is_Identifier (Arg2);
7112
7113             --  First argument is identifier
7114
7115             if Nkind (Arg1X) = N_Identifier then
7116
7117                --  Search list of names in Ada.Interrupts.Names
7118
7119                Int_Ent := First_Entity (RTE (RE_Names));
7120                loop
7121                   if No (Int_Ent) then
7122                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
7123
7124                   elsif Chars (Int_Ent) = Chars (Arg1X) then
7125                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
7126                      exit;
7127                   end if;
7128
7129                   Next_Entity (Int_Ent);
7130                end loop;
7131
7132             --  First argument is not an identifier, so it must be a
7133             --  static expression of type Ada.Interrupts.Interrupt_ID.
7134
7135             else
7136                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7137                Int_Val := Expr_Value (Arg1X);
7138
7139                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
7140                     or else
7141                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
7142                then
7143                   Error_Pragma_Arg
7144                     ("value not in range of type " &
7145                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
7146                end if;
7147             end if;
7148
7149             --  Check OK state
7150
7151             case Chars (Get_Pragma_Arg (Arg2)) is
7152                when Name_Runtime => State_Type := 'r';
7153                when Name_System  => State_Type := 's';
7154                when Name_User    => State_Type := 'u';
7155
7156                when others =>
7157                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
7158             end case;
7159
7160             --  Check if entry is already stored
7161
7162             IST_Num := Interrupt_States.First;
7163             loop
7164                --  If entry not found, add it
7165
7166                if IST_Num > Interrupt_States.Last then
7167                   Interrupt_States.Append
7168                     ((Interrupt_Number => UI_To_Int (Int_Val),
7169                       Interrupt_State  => State_Type,
7170                       Pragma_Loc       => Loc));
7171                   exit;
7172
7173                --  Case of entry for the same entry
7174
7175                elsif Int_Val = Interrupt_States.Table (IST_Num).
7176                                                            Interrupt_Number
7177                then
7178                   --  If state matches, done, no need to make redundant entry
7179
7180                   exit when
7181                     State_Type = Interrupt_States.Table (IST_Num).
7182                                                            Interrupt_State;
7183
7184                   --  Otherwise if state does not match, error
7185
7186                   Error_Msg_Sloc :=
7187                     Interrupt_States.Table (IST_Num).Pragma_Loc;
7188                   Error_Pragma_Arg
7189                     ("state conflicts with that given at #", Arg2);
7190                   exit;
7191                end if;
7192
7193                IST_Num := IST_Num + 1;
7194             end loop;
7195          end Interrupt_State;
7196
7197          ----------------------
7198          -- Java_Constructor --
7199          ----------------------
7200
7201          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
7202
7203          when Pragma_Java_Constructor => Java_Constructor : declare
7204             Id     : Entity_Id;
7205             Def_Id : Entity_Id;
7206             Hom_Id : Entity_Id;
7207
7208          begin
7209             GNAT_Pragma;
7210             Check_Arg_Count (1);
7211             Check_Optional_Identifier (Arg1, Name_Entity);
7212             Check_Arg_Is_Local_Name (Arg1);
7213
7214             Id := Expression (Arg1);
7215             Find_Program_Unit_Name (Id);
7216
7217             --  If we did not find the name, we are done
7218
7219             if Etype (Id) = Any_Type then
7220                return;
7221             end if;
7222
7223             Hom_Id := Entity (Id);
7224
7225             --  Loop through homonyms
7226
7227             loop
7228                Def_Id := Get_Base_Subprogram (Hom_Id);
7229
7230                --  The constructor is required to be a function returning
7231                --  an access type whose designated type has convention Java.
7232
7233                if Ekind (Def_Id) = E_Function
7234                  and then Ekind (Etype (Def_Id)) in Access_Kind
7235                  and then
7236                    (Atree.Convention
7237                       (Designated_Type (Etype (Def_Id))) = Convention_Java
7238                    or else
7239                      Atree.Convention
7240                       (Root_Type (Designated_Type (Etype (Def_Id))))
7241                         = Convention_Java)
7242                then
7243                   Set_Is_Constructor (Def_Id);
7244                   Set_Convention     (Def_Id, Convention_Java);
7245
7246                else
7247                   Error_Pragma_Arg
7248                     ("pragma% requires function returning a 'Java access type",
7249                       Arg1);
7250                end if;
7251
7252                Hom_Id := Homonym (Hom_Id);
7253
7254                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
7255             end loop;
7256          end Java_Constructor;
7257
7258          ----------------------
7259          -- Java_Interface --
7260          ----------------------
7261
7262          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
7263
7264          when Pragma_Java_Interface => Java_Interface : declare
7265             Arg : Node_Id;
7266             Typ : Entity_Id;
7267
7268          begin
7269             GNAT_Pragma;
7270             Check_Arg_Count (1);
7271             Check_Optional_Identifier (Arg1, Name_Entity);
7272             Check_Arg_Is_Local_Name (Arg1);
7273
7274             Arg := Expression (Arg1);
7275             Analyze (Arg);
7276
7277             if Etype (Arg) = Any_Type then
7278                return;
7279             end if;
7280
7281             if not Is_Entity_Name (Arg)
7282               or else not Is_Type (Entity (Arg))
7283             then
7284                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7285             end if;
7286
7287             Typ := Underlying_Type (Entity (Arg));
7288
7289             --  For now we simply check some of the semantic constraints
7290             --  on the type. This currently leaves out some restrictions
7291             --  on interface types, namely that the parent type must be
7292             --  java.lang.Object.Typ and that all primitives of the type
7293             --  should be declared abstract. ???
7294
7295             if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
7296                Error_Pragma_Arg ("pragma% requires an abstract "
7297                  & "tagged type", Arg1);
7298
7299             elsif not Has_Discriminants (Typ)
7300               or else Ekind (Etype (First_Discriminant (Typ)))
7301                         /= E_Anonymous_Access_Type
7302               or else
7303                 not Is_Class_Wide_Type
7304                       (Designated_Type (Etype (First_Discriminant (Typ))))
7305             then
7306                Error_Pragma_Arg
7307                  ("type must have a class-wide access discriminant", Arg1);
7308             end if;
7309          end Java_Interface;
7310
7311          ----------------
7312          -- Keep_Names --
7313          ----------------
7314
7315          --  pragma Keep_Names ([On => ] local_NAME);
7316
7317          when Pragma_Keep_Names => Keep_Names : declare
7318             Arg : Node_Id;
7319
7320          begin
7321             GNAT_Pragma;
7322             Check_Arg_Count (1);
7323             Check_Optional_Identifier (Arg1, Name_On);
7324             Check_Arg_Is_Local_Name (Arg1);
7325
7326             Arg := Expression (Arg1);
7327             Analyze (Arg);
7328
7329             if Etype (Arg) = Any_Type then
7330                return;
7331             end if;
7332
7333             if not Is_Entity_Name (Arg)
7334               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
7335             then
7336                Error_Pragma_Arg
7337                  ("pragma% requires a local enumeration type", Arg1);
7338             end if;
7339
7340             Set_Discard_Names (Entity (Arg), False);
7341          end Keep_Names;
7342
7343          -------------
7344          -- License --
7345          -------------
7346
7347          --  pragma License (RESTRICTED | UNRESRICTED | GPL | MODIFIED_GPL);
7348
7349          when Pragma_License =>
7350             GNAT_Pragma;
7351             Check_Arg_Count (1);
7352             Check_No_Identifiers;
7353             Check_Valid_Configuration_Pragma;
7354             Check_Arg_Is_Identifier (Arg1);
7355
7356             declare
7357                Sind : constant Source_File_Index :=
7358                         Source_Index (Current_Sem_Unit);
7359
7360             begin
7361                case Chars (Get_Pragma_Arg (Arg1)) is
7362                   when Name_GPL =>
7363                      Set_License (Sind, GPL);
7364
7365                   when Name_Modified_GPL =>
7366                      Set_License (Sind, Modified_GPL);
7367
7368                   when Name_Restricted =>
7369                      Set_License (Sind, Restricted);
7370
7371                   when Name_Unrestricted =>
7372                      Set_License (Sind, Unrestricted);
7373
7374                   when others =>
7375                      Error_Pragma_Arg ("invalid license name", Arg1);
7376                end case;
7377             end;
7378
7379          ---------------
7380          -- Link_With --
7381          ---------------
7382
7383          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
7384
7385          when Pragma_Link_With => Link_With : declare
7386             Arg : Node_Id;
7387
7388          begin
7389             GNAT_Pragma;
7390
7391             if Operating_Mode = Generate_Code
7392               and then In_Extended_Main_Source_Unit (N)
7393             then
7394                Check_At_Least_N_Arguments (1);
7395                Check_No_Identifiers;
7396                Check_Is_In_Decl_Part_Or_Package_Spec;
7397                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7398                Start_String;
7399
7400                Arg := Arg1;
7401                while Present (Arg) loop
7402                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
7403
7404                   --  Store argument, converting sequences of spaces
7405                   --  to a single null character (this is one of the
7406                   --  differences in processing between Link_With
7407                   --  and Linker_Options).
7408
7409                   declare
7410                      C : constant Char_Code := Get_Char_Code (' ');
7411                      S : constant String_Id :=
7412                            Strval (Expr_Value_S (Expression (Arg)));
7413                      L : constant Nat := String_Length (S);
7414                      F : Nat := 1;
7415
7416                      procedure Skip_Spaces;
7417                      --  Advance F past any spaces
7418
7419                      procedure Skip_Spaces is
7420                      begin
7421                         while F <= L and then Get_String_Char (S, F) = C loop
7422                            F := F + 1;
7423                         end loop;
7424                      end Skip_Spaces;
7425
7426                   begin
7427                      Skip_Spaces; -- skip leading spaces
7428
7429                      --  Loop through characters, changing any embedded
7430                      --  sequence of spaces to a single null character
7431                      --  (this is how Link_With/Linker_Options differ)
7432
7433                      while F <= L loop
7434                         if Get_String_Char (S, F) = C then
7435                            Skip_Spaces;
7436                            exit when F > L;
7437                            Store_String_Char (ASCII.NUL);
7438
7439                         else
7440                            Store_String_Char (Get_String_Char (S, F));
7441                            F := F + 1;
7442                         end if;
7443                      end loop;
7444                   end;
7445
7446                   Arg := Next (Arg);
7447
7448                   if Present (Arg) then
7449                      Store_String_Char (ASCII.NUL);
7450                   end if;
7451                end loop;
7452
7453                Store_Linker_Option_String (End_String);
7454             end if;
7455          end Link_With;
7456
7457          ------------------
7458          -- Linker_Alias --
7459          ------------------
7460
7461          --  pragma Linker_Alias (
7462          --      [Entity =>]  LOCAL_NAME
7463          --      [Alias  =>]  static_string_EXPRESSION);
7464
7465          when Pragma_Linker_Alias =>
7466             GNAT_Pragma;
7467             Check_Arg_Count (2);
7468             Check_Optional_Identifier (Arg1, Name_Entity);
7469             Check_Optional_Identifier (Arg2, "alias");
7470             Check_Arg_Is_Library_Level_Local_Name (Arg1);
7471             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7472
7473             --  The only processing required is to link this item on to the
7474             --  list of rep items for the given entity. This is accomplished
7475             --  by the call to Rep_Item_Too_Late (when no error is detected
7476             --  and False is returned).
7477
7478             if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7479                return;
7480             else
7481                Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7482             end if;
7483
7484          --------------------
7485          -- Linker_Options --
7486          --------------------
7487
7488          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
7489
7490          when Pragma_Linker_Options => Linker_Options : declare
7491             Arg : Node_Id;
7492
7493          begin
7494             Check_Ada_83_Warning;
7495             Check_No_Identifiers;
7496             Check_Arg_Count (1);
7497             Check_Is_In_Decl_Part_Or_Package_Spec;
7498
7499             if Operating_Mode = Generate_Code
7500               and then In_Extended_Main_Source_Unit (N)
7501             then
7502                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7503                Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7504
7505                Arg := Arg2;
7506                while Present (Arg) loop
7507                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
7508                   Store_String_Char (ASCII.NUL);
7509                   Store_String_Chars
7510                     (Strval (Expr_Value_S (Expression (Arg))));
7511                   Arg := Next (Arg);
7512                end loop;
7513
7514                Store_Linker_Option_String (End_String);
7515             end if;
7516          end Linker_Options;
7517
7518          --------------------
7519          -- Linker_Section --
7520          --------------------
7521
7522          --  pragma Linker_Section (
7523          --      [Entity  =>]  LOCAL_NAME
7524          --      [Section =>]  static_string_EXPRESSION);
7525
7526          when Pragma_Linker_Section =>
7527             GNAT_Pragma;
7528             Check_Arg_Count (2);
7529             Check_Optional_Identifier (Arg1, Name_Entity);
7530             Check_Optional_Identifier (Arg2, Name_Section);
7531             Check_Arg_Is_Library_Level_Local_Name (Arg1);
7532             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7533
7534             --  The only processing required is to link this item on to the
7535             --  list of rep items for the given entity. This is accomplished
7536             --  by the call to Rep_Item_Too_Late (when no error is detected
7537             --  and False is returned).
7538
7539             if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7540                return;
7541             else
7542                Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7543             end if;
7544
7545          ----------
7546          -- List --
7547          ----------
7548
7549          --  pragma List (On | Off)
7550
7551          --  There is nothing to do here, since we did all the processing
7552          --  for this pragma in Par.Prag (so that it works properly even in
7553          --  syntax only mode)
7554
7555          when Pragma_List =>
7556             null;
7557
7558          --------------------
7559          -- Locking_Policy --
7560          --------------------
7561
7562          --  pragma Locking_Policy (policy_IDENTIFIER);
7563
7564          when Pragma_Locking_Policy => declare
7565             LP : Character;
7566
7567          begin
7568             Check_Ada_83_Warning;
7569             Check_Arg_Count (1);
7570             Check_No_Identifiers;
7571             Check_Arg_Is_Locking_Policy (Arg1);
7572             Check_Valid_Configuration_Pragma;
7573             Get_Name_String (Chars (Expression (Arg1)));
7574             LP := Fold_Upper (Name_Buffer (1));
7575
7576             if Locking_Policy /= ' '
7577               and then Locking_Policy /= LP
7578             then
7579                Error_Msg_Sloc := Locking_Policy_Sloc;
7580                Error_Pragma ("locking policy incompatible with policy#");
7581
7582             --  Set new policy, but always preserve System_Location since
7583             --  we like the error message with the run time name.
7584
7585             else
7586                Locking_Policy := LP;
7587
7588                if Locking_Policy_Sloc /= System_Location then
7589                   Locking_Policy_Sloc := Loc;
7590                end if;
7591             end if;
7592          end;
7593
7594          ----------------
7595          -- Long_Float --
7596          ----------------
7597
7598          --  pragma Long_Float (D_Float | G_Float);
7599
7600          when Pragma_Long_Float =>
7601             GNAT_Pragma;
7602             Check_Valid_Configuration_Pragma;
7603             Check_Arg_Count (1);
7604             Check_No_Identifier (Arg1);
7605             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
7606
7607             if not OpenVMS_On_Target then
7608                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
7609             end if;
7610
7611             --  D_Float case
7612
7613             if Chars (Expression (Arg1)) = Name_D_Float then
7614                if Opt.Float_Format_Long = 'G' then
7615                   Error_Pragma ("G_Float previously specified");
7616                end if;
7617
7618                Opt.Float_Format_Long := 'D';
7619
7620             --  G_Float case (this is the default, does not need overriding)
7621
7622             else
7623                if Opt.Float_Format_Long = 'D' then
7624                   Error_Pragma ("D_Float previously specified");
7625                end if;
7626
7627                Opt.Float_Format_Long := 'G';
7628             end if;
7629
7630             Set_Standard_Fpt_Formats;
7631
7632          -----------------------
7633          -- Machine_Attribute --
7634          -----------------------
7635
7636          --  pragma Machine_Attribute (
7637          --    [Entity         =>] LOCAL_NAME,
7638          --    [Attribute_Name =>] static_string_EXPRESSION
7639          --  [,[Info           =>] static_string_EXPRESSION] );
7640
7641          when Pragma_Machine_Attribute => Machine_Attribute : declare
7642             Def_Id : Entity_Id;
7643
7644          begin
7645             GNAT_Pragma;
7646
7647             if Arg_Count = 3 then
7648                Check_Optional_Identifier (Arg3, "info");
7649                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7650             else
7651                Check_Arg_Count (2);
7652             end if;
7653
7654             Check_Arg_Is_Local_Name (Arg1);
7655             Check_Optional_Identifier (Arg2, "attribute_name");
7656             Check_Optional_Identifier (Arg1, Name_Entity);
7657             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7658             Def_Id := Entity (Expression (Arg1));
7659
7660             if Is_Access_Type (Def_Id) then
7661                Def_Id := Designated_Type (Def_Id);
7662             end if;
7663
7664             if Rep_Item_Too_Early (Def_Id, N) then
7665                return;
7666             end if;
7667
7668             Def_Id := Underlying_Type (Def_Id);
7669
7670             --  The only processing required is to link this item on to the
7671             --  list of rep items for the given entity. This is accomplished
7672             --  by the call to Rep_Item_Too_Late (when no error is detected
7673             --  and False is returned).
7674
7675             if Rep_Item_Too_Late (Def_Id, N) then
7676                return;
7677             else
7678                Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7679             end if;
7680          end Machine_Attribute;
7681
7682          ----------
7683          -- Main --
7684          ----------
7685
7686          --  pragma Main_Storage
7687          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7688
7689          --  MAIN_STORAGE_OPTION ::=
7690          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7691          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7692
7693          when Pragma_Main => Main : declare
7694             Args  : Args_List (1 .. 3);
7695             Names : constant Name_List (1 .. 3) := (
7696                       Name_Stack_Size,
7697                       Name_Task_Stack_Size_Default,
7698                       Name_Time_Slicing_Enabled);
7699
7700             Nod : Node_Id;
7701
7702          begin
7703             GNAT_Pragma;
7704             Gather_Associations (Names, Args);
7705
7706             for J in 1 .. 2 loop
7707                if Present (Args (J)) then
7708                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7709                end if;
7710             end loop;
7711
7712             if Present (Args (3)) then
7713                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
7714             end if;
7715
7716             Nod := Next (N);
7717             while Present (Nod) loop
7718                if Nkind (Nod) = N_Pragma
7719                  and then Chars (Nod) = Name_Main
7720                then
7721                   Error_Msg_Name_1 := Chars (N);
7722                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
7723                end if;
7724
7725                Next (Nod);
7726             end loop;
7727          end Main;
7728
7729          ------------------
7730          -- Main_Storage --
7731          ------------------
7732
7733          --  pragma Main_Storage
7734          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7735
7736          --  MAIN_STORAGE_OPTION ::=
7737          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7738          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7739
7740          when Pragma_Main_Storage => Main_Storage : declare
7741             Args  : Args_List (1 .. 2);
7742             Names : constant Name_List (1 .. 2) := (
7743                       Name_Working_Storage,
7744                       Name_Top_Guard);
7745
7746             Nod : Node_Id;
7747
7748          begin
7749             GNAT_Pragma;
7750             Gather_Associations (Names, Args);
7751
7752             for J in 1 .. 2 loop
7753                if Present (Args (J)) then
7754                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7755                end if;
7756             end loop;
7757
7758             Check_In_Main_Program;
7759
7760             Nod := Next (N);
7761             while Present (Nod) loop
7762                if Nkind (Nod) = N_Pragma
7763                  and then Chars (Nod) = Name_Main_Storage
7764                then
7765                   Error_Msg_Name_1 := Chars (N);
7766                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
7767                end if;
7768
7769                Next (Nod);
7770             end loop;
7771          end Main_Storage;
7772
7773          -----------------
7774          -- Memory_Size --
7775          -----------------
7776
7777          --  pragma Memory_Size (NUMERIC_LITERAL)
7778
7779          when Pragma_Memory_Size =>
7780             GNAT_Pragma;
7781
7782             --  Memory size is simply ignored
7783
7784             Check_No_Identifiers;
7785             Check_Arg_Count (1);
7786             Check_Arg_Is_Integer_Literal (Arg1);
7787
7788          ---------------
7789          -- No_Return --
7790          ---------------
7791
7792          --  pragma No_Return (procedure_LOCAL_NAME);
7793
7794          when Pragma_No_Return => No_Return : declare
7795             Id    : Node_Id;
7796             E     : Entity_Id;
7797             Found : Boolean;
7798
7799          begin
7800             GNAT_Pragma;
7801             Check_Arg_Count (1);
7802             Check_No_Identifiers;
7803             Check_Arg_Is_Local_Name (Arg1);
7804             Id := Expression (Arg1);
7805             Analyze (Id);
7806
7807             if not Is_Entity_Name (Id) then
7808                Error_Pragma_Arg ("entity name required", Arg1);
7809             end if;
7810
7811             if Etype (Id) = Any_Type then
7812                raise Pragma_Exit;
7813             end if;
7814
7815             E := Entity (Id);
7816
7817             Found := False;
7818             while Present (E)
7819               and then Scope (E) = Current_Scope
7820             loop
7821                if Ekind (E) = E_Procedure
7822                  or else Ekind (E) = E_Generic_Procedure
7823                then
7824                   Set_No_Return (E);
7825                   Found := True;
7826                end if;
7827
7828                E := Homonym (E);
7829             end loop;
7830
7831             if not Found then
7832                Error_Pragma ("no procedures found for pragma%");
7833             end if;
7834          end No_Return;
7835
7836          ------------------------
7837          -- No_Strict_Aliasing --
7838          ------------------------
7839
7840          when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
7841             E_Id : Entity_Id;
7842
7843          begin
7844             GNAT_Pragma;
7845             Check_At_Most_N_Arguments (1);
7846
7847             if Arg_Count = 0 then
7848                Check_Valid_Configuration_Pragma;
7849                Opt.No_Strict_Aliasing := True;
7850
7851             else
7852                Check_Optional_Identifier (Arg2, Name_Entity);
7853                Check_Arg_Is_Local_Name (Arg1);
7854                E_Id := Entity (Expression (Arg1));
7855
7856                if E_Id = Any_Type then
7857                   return;
7858                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
7859                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
7860                end if;
7861
7862                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
7863             end if;
7864          end No_Strict_Alias;
7865
7866          -----------------
7867          -- Obsolescent --
7868          -----------------
7869
7870          --  pragma Obsolescent [(static_string_EXPRESSION)];
7871
7872          when Pragma_Obsolescent => Obsolescent : declare
7873          begin
7874             GNAT_Pragma;
7875             Check_At_Most_N_Arguments (1);
7876             Check_No_Identifiers;
7877
7878             if Arg_Count = 1 then
7879                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7880             end if;
7881
7882             if No (Prev (N))
7883               or else (Nkind (Prev (N))) /= N_Subprogram_Declaration
7884             then
7885                Error_Pragma
7886                  ("pragma% misplaced, must immediately " &
7887                   "follow subprogram spec");
7888             end if;
7889          end Obsolescent;
7890
7891          -----------------
7892          -- No_Run_Time --
7893          -----------------
7894
7895          --  pragma No_Run_Time
7896
7897          --  Note: this pragma is retained for backwards compatibiltiy.
7898          --  See body of Rtsfind for full details on its handling.
7899
7900          when Pragma_No_Run_Time =>
7901             GNAT_Pragma;
7902             Check_Valid_Configuration_Pragma;
7903             Check_Arg_Count (0);
7904
7905             No_Run_Time_Mode           := True;
7906             Configurable_Run_Time_Mode := True;
7907
7908             declare
7909                Word32 : constant Boolean := Ttypes.System_Word_Size = 32;
7910             begin
7911                if Word32 then
7912                   Duration_32_Bits_On_Target := True;
7913                end if;
7914             end;
7915
7916             Set_Restriction (No_Finalization, N);
7917             Set_Restriction (No_Exception_Handlers, N);
7918             Set_Restriction (Max_Tasks, N, 0);
7919             Set_Restriction (No_Tasking, N);
7920
7921          -----------------------
7922          -- Normalize_Scalars --
7923          -----------------------
7924
7925          --  pragma Normalize_Scalars;
7926
7927          when Pragma_Normalize_Scalars =>
7928             Check_Ada_83_Warning;
7929             Check_Arg_Count (0);
7930             Check_Valid_Configuration_Pragma;
7931             Normalize_Scalars := True;
7932             Init_Or_Norm_Scalars := True;
7933
7934          --------------
7935          -- Optimize --
7936          --------------
7937
7938          --  pragma Optimize (Time | Space);
7939
7940          --  The actual check for optimize is done in Gigi. Note that this
7941          --  pragma does not actually change the optimization setting, it
7942          --  simply checks that it is consistent with the pragma.
7943
7944          when Pragma_Optimize =>
7945             Check_No_Identifiers;
7946             Check_Arg_Count (1);
7947             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
7948
7949          -------------------------
7950          -- Optional_Overriding --
7951          -------------------------
7952
7953          --  These pragmas are treated as part of the previous subprogram
7954          --  declaration, and analyzed immediately after it (see sem_ch6,
7955          --  Check_Overriding_Operation). If the pragma has not been analyzed
7956          --  yet, it appears in the wrong place.
7957
7958          when Pragma_Optional_Overriding =>
7959             Error_Msg_N ("pragma must appear immediately after subprogram", N);
7960
7961          ----------------
7962          -- Overriding --
7963          ----------------
7964
7965          when Pragma_Overriding =>
7966             Error_Msg_N ("pragma must appear immediately after subprogram", N);
7967
7968          ----------
7969          -- Pack --
7970          ----------
7971
7972          --  pragma Pack (first_subtype_LOCAL_NAME);
7973
7974          when Pragma_Pack => Pack : declare
7975             Assoc   : constant Node_Id := Arg1;
7976             Type_Id : Node_Id;
7977             Typ     : Entity_Id;
7978
7979          begin
7980             Check_No_Identifiers;
7981             Check_Arg_Count (1);
7982             Check_Arg_Is_Local_Name (Arg1);
7983
7984             Type_Id := Expression (Assoc);
7985             Find_Type (Type_Id);
7986             Typ := Entity (Type_Id);
7987
7988             if Typ = Any_Type
7989               or else Rep_Item_Too_Early (Typ, N)
7990             then
7991                return;
7992             else
7993                Typ := Underlying_Type (Typ);
7994             end if;
7995
7996             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
7997                Error_Pragma ("pragma% must specify array or record type");
7998             end if;
7999
8000             Check_First_Subtype (Arg1);
8001
8002             if Has_Pragma_Pack (Typ) then
8003                Error_Pragma ("duplicate pragma%, only one allowed");
8004
8005             --  Array type. We set the Has_Pragma_Pack flag, and Is_Packed,
8006             --  but not Has_Non_Standard_Rep, because we don't actually know
8007             --  till freeze time if the array can have packed representation.
8008             --  That's because in the general case we do not know enough about
8009             --  the component type until it in turn is frozen, which certainly
8010             --  happens before the array type is frozen, but not necessarily
8011             --  till that point (i.e. right now it may be unfrozen).
8012
8013             elsif Is_Array_Type (Typ) then
8014                if Has_Aliased_Components (Base_Type (Typ)) then
8015                   Error_Pragma
8016                     ("pragma% ignored, cannot pack aliased components?");
8017
8018                elsif Has_Atomic_Components (Typ)
8019                  or else Is_Atomic (Component_Type (Typ))
8020                then
8021                   Error_Pragma
8022                     ("?pragma% ignored, cannot pack atomic components");
8023
8024                elsif not Rep_Item_Too_Late (Typ, N) then
8025                   Set_Is_Packed            (Base_Type (Typ));
8026                   Set_Has_Pragma_Pack      (Base_Type (Typ));
8027                   Set_Has_Non_Standard_Rep (Base_Type (Typ));
8028                end if;
8029
8030             --  Record type. For record types, the pack is always effective
8031
8032             else pragma Assert (Is_Record_Type (Typ));
8033                if not Rep_Item_Too_Late (Typ, N) then
8034                   Set_Has_Pragma_Pack      (Base_Type (Typ));
8035                   Set_Is_Packed            (Base_Type (Typ));
8036                   Set_Has_Non_Standard_Rep (Base_Type (Typ));
8037                end if;
8038             end if;
8039          end Pack;
8040
8041          ----------
8042          -- Page --
8043          ----------
8044
8045          --  pragma Page;
8046
8047          --  There is nothing to do here, since we did all the processing
8048          --  for this pragma in Par.Prag (so that it works properly even in
8049          --  syntax only mode)
8050
8051          when Pragma_Page =>
8052             null;
8053
8054          -------------
8055          -- Passive --
8056          -------------
8057
8058          --  pragma Passive [(PASSIVE_FORM)];
8059
8060          --   PASSIVE_FORM ::= Semaphore | No
8061
8062          when Pragma_Passive =>
8063             GNAT_Pragma;
8064
8065             if Nkind (Parent (N)) /= N_Task_Definition then
8066                Error_Pragma ("pragma% must be within task definition");
8067             end if;
8068
8069             if Arg_Count /= 0 then
8070                Check_Arg_Count (1);
8071                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
8072             end if;
8073
8074          -------------
8075          -- Polling --
8076          -------------
8077
8078          --  pragma Polling (ON | OFF);
8079
8080          when Pragma_Polling =>
8081             GNAT_Pragma;
8082             Check_Arg_Count (1);
8083             Check_No_Identifiers;
8084             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8085             Polling_Required := (Chars (Expression (Arg1)) = Name_On);
8086
8087          ---------------------
8088          -- Persistent_Data --
8089          ---------------------
8090
8091          when Pragma_Persistent_Data => declare
8092             Ent : Entity_Id;
8093
8094          begin
8095             --  Register the pragma as applying to the compilation unit.
8096             --  Individual Persistent_Object pragmas for relevant objects
8097             --  are generated the end of the compilation.
8098
8099             GNAT_Pragma;
8100             Check_Valid_Configuration_Pragma;
8101             Check_Arg_Count (0);
8102             Ent := Find_Lib_Unit_Name;
8103             Set_Is_Preelaborated (Ent);
8104          end;
8105
8106          -----------------------
8107          -- Persistent_Object --
8108          -----------------------
8109
8110          when Pragma_Persistent_Object => declare
8111             Decl : Node_Id;
8112             Ent  : Entity_Id;
8113             MA   : Node_Id;
8114             Str  : String_Id;
8115
8116          begin
8117             GNAT_Pragma;
8118             Check_Arg_Count (1);
8119             Check_Arg_Is_Library_Level_Local_Name (Arg1);
8120
8121             if not Is_Entity_Name (Expression (Arg1))
8122               or else
8123                (Ekind (Entity (Expression (Arg1))) /= E_Variable
8124                  and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
8125             then
8126                Error_Pragma_Arg ("pragma only applies to objects", Arg1);
8127             end if;
8128
8129             Ent := Entity (Expression (Arg1));
8130             Decl := Parent (Ent);
8131
8132             if Nkind (Decl) /= N_Object_Declaration then
8133                return;
8134             end if;
8135
8136             --  Placement of the object depends on whether there is
8137             --  an initial value or none. If the No_Initialization flag
8138             --  is set, the initialization has been transformed into
8139             --  assignments, which is disallowed elaboration code.
8140
8141             if No_Initialization (Decl) then
8142                Error_Msg_N
8143                  ("initialization for persistent object"
8144                    &  "must be static expression", Decl);
8145                return;
8146             end if;
8147
8148             if No (Expression (Decl)) then
8149                Start_String;
8150                Store_String_Chars ("section ("".persistent.bss"")");
8151                Str := End_String;
8152
8153             else
8154                if not Is_OK_Static_Expression (Expression (Decl)) then
8155                   Flag_Non_Static_Expr
8156                     ("initialization for persistent object"
8157                       &  "must be static expression!", Expression (Decl));
8158                   return;
8159                end if;
8160
8161                Start_String;
8162                Store_String_Chars ("section ("".persistent.data"")");
8163                Str := End_String;
8164             end if;
8165
8166             MA :=
8167                Make_Pragma
8168                  (Sloc (N),
8169                   Name_Machine_Attribute,
8170                   New_List
8171                     (Make_Pragma_Argument_Association
8172                        (Sloc => Sloc (Arg1),
8173                         Expression => New_Occurrence_Of (Ent, Sloc (Ent))),
8174                      Make_Pragma_Argument_Association
8175                        (Sloc => Sloc (Arg1),
8176                         Expression =>
8177                           Make_String_Literal
8178                             (Sloc => Sloc (Arg1),
8179                              Strval => Str))));
8180
8181             Insert_After (N, MA);
8182             Analyze (MA);
8183             Set_Has_Gigi_Rep_Item (Ent);
8184          end;
8185
8186          ------------------
8187          -- Preelaborate --
8188          ------------------
8189
8190          --  pragma Preelaborate [(library_unit_NAME)];
8191
8192          --  Set the flag Is_Preelaborated of program unit name entity
8193
8194          when Pragma_Preelaborate => Preelaborate : declare
8195             Pa  : constant Node_Id   := Parent (N);
8196             Pk  : constant Node_Kind := Nkind (Pa);
8197             Ent : Entity_Id;
8198
8199          begin
8200             Check_Ada_83_Warning;
8201             Check_Valid_Library_Unit_Pragma;
8202
8203             if Nkind (N) = N_Null_Statement then
8204                return;
8205             end if;
8206
8207             Ent := Find_Lib_Unit_Name;
8208
8209             --  This filters out pragmas inside generic parent then
8210             --  show up inside instantiation
8211
8212             if Present (Ent)
8213               and then not (Pk = N_Package_Specification
8214                              and then Present (Generic_Parent (Pa)))
8215             then
8216                if not Debug_Flag_U then
8217                   Set_Is_Preelaborated (Ent);
8218                   Set_Suppress_Elaboration_Warnings (Ent);
8219                end if;
8220             end if;
8221          end Preelaborate;
8222
8223          --------------
8224          -- Priority --
8225          --------------
8226
8227          --  pragma Priority (EXPRESSION);
8228
8229          when Pragma_Priority => Priority : declare
8230             P   : constant Node_Id := Parent (N);
8231             Arg : Node_Id;
8232
8233          begin
8234             Check_No_Identifiers;
8235             Check_Arg_Count (1);
8236
8237             --  Subprogram case
8238
8239             if Nkind (P) = N_Subprogram_Body then
8240                Check_In_Main_Program;
8241
8242                Arg := Expression (Arg1);
8243                Analyze_And_Resolve (Arg, Standard_Integer);
8244
8245                --  Must be static
8246
8247                if not Is_Static_Expression (Arg) then
8248                   Flag_Non_Static_Expr
8249                     ("main subprogram priority is not static!", Arg);
8250                   raise Pragma_Exit;
8251
8252                --  If constraint error, then we already signalled an error
8253
8254                elsif Raises_Constraint_Error (Arg) then
8255                   null;
8256
8257                --  Otherwise check in range
8258
8259                else
8260                   declare
8261                      Val : constant Uint := Expr_Value (Arg);
8262
8263                   begin
8264                      if Val < 0
8265                        or else Val > Expr_Value (Expression
8266                                        (Parent (RTE (RE_Max_Priority))))
8267                      then
8268                         Error_Pragma_Arg
8269                           ("main subprogram priority is out of range", Arg1);
8270                      end if;
8271                   end;
8272                end if;
8273
8274                Set_Main_Priority
8275                  (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8276
8277             --  Task or Protected, must be of type Integer
8278
8279             elsif Nkind (P) = N_Protected_Definition
8280                     or else
8281                   Nkind (P) = N_Task_Definition
8282             then
8283                Arg := Expression (Arg1);
8284
8285                --  The expression must be analyzed in the special manner
8286                --  described in "Handling of Default and Per-Object
8287                --  Expressions" in sem.ads.
8288
8289                Analyze_Per_Use_Expression (Arg, Standard_Integer);
8290
8291                if not Is_Static_Expression (Arg) then
8292                   Check_Restriction (Static_Priorities, Arg);
8293                end if;
8294
8295             --  Anything else is incorrect
8296
8297             else
8298                Pragma_Misplaced;
8299             end if;
8300
8301             if Has_Priority_Pragma (P) then
8302                Error_Pragma ("duplicate pragma% not allowed");
8303             else
8304                Set_Has_Priority_Pragma (P, True);
8305
8306                if Nkind (P) = N_Protected_Definition
8307                     or else
8308                   Nkind (P) = N_Task_Definition
8309                then
8310                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8311                   --  exp_ch9 should use this ???
8312                end if;
8313             end if;
8314          end Priority;
8315
8316          -------------
8317          -- Profile --
8318          -------------
8319
8320          --  pragma Profile (profile_IDENTIFIER);
8321
8322          --  profile_IDENTIFIER => Protected | Ravenscar
8323
8324          when Pragma_Profile =>
8325             Check_Arg_Count (1);
8326             Check_Valid_Configuration_Pragma;
8327             Check_No_Identifiers;
8328
8329             declare
8330                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8331             begin
8332                if Chars (Argx) = Name_Ravenscar then
8333                   Set_Ravenscar_Profile (N);
8334
8335                elsif Chars (Argx) = Name_Restricted then
8336                   Set_Profile_Restrictions (Restricted, N, Warn => False);
8337                else
8338                   Error_Pragma_Arg ("& is not a valid profile", Argx);
8339                end if;
8340             end;
8341
8342          ----------------------
8343          -- Profile_Warnings --
8344          ----------------------
8345
8346          --  pragma Profile_Warnings (profile_IDENTIFIER);
8347
8348          --  profile_IDENTIFIER => Protected | Ravenscar
8349
8350          when Pragma_Profile_Warnings =>
8351             GNAT_Pragma;
8352             Check_Arg_Count (1);
8353             Check_Valid_Configuration_Pragma;
8354             Check_No_Identifiers;
8355
8356             declare
8357                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8358             begin
8359                if Chars (Argx) = Name_Ravenscar then
8360                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
8361
8362                elsif Chars (Argx) = Name_Restricted then
8363                   Set_Profile_Restrictions (Restricted, N, Warn => True);
8364                else
8365                   Error_Pragma_Arg ("& is not a valid profile", Argx);
8366                end if;
8367             end;
8368
8369          --------------------------
8370          -- Propagate_Exceptions --
8371          --------------------------
8372
8373          --  pragma Propagate_Exceptions;
8374
8375          when Pragma_Propagate_Exceptions =>
8376             GNAT_Pragma;
8377             Check_Arg_Count (0);
8378
8379             if In_Extended_Main_Source_Unit (N) then
8380                Propagate_Exceptions := True;
8381             end if;
8382
8383          ------------------
8384          -- Psect_Object --
8385          ------------------
8386
8387          --  pragma Psect_Object (
8388          --        [Internal =>] LOCAL_NAME,
8389          --     [, [External =>] EXTERNAL_SYMBOL]
8390          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8391
8392          when Pragma_Psect_Object | Pragma_Common_Object =>
8393          Psect_Object : declare
8394             Args  : Args_List (1 .. 3);
8395             Names : constant Name_List (1 .. 3) := (
8396                       Name_Internal,
8397                       Name_External,
8398                       Name_Size);
8399
8400             Internal : Node_Id renames Args (1);
8401             External : Node_Id renames Args (2);
8402             Size     : Node_Id renames Args (3);
8403
8404             R_Internal : Node_Id;
8405             R_External : Node_Id;
8406
8407             MA       : Node_Id;
8408             Str      : String_Id;
8409
8410             Def_Id   : Entity_Id;
8411
8412             procedure Check_Too_Long (Arg : Node_Id);
8413             --  Posts message if the argument is an identifier with more
8414             --  than 31 characters, or a string literal with more than
8415             --  31 characters, and we are operating under VMS
8416
8417             --------------------
8418             -- Check_Too_Long --
8419             --------------------
8420
8421             procedure Check_Too_Long (Arg : Node_Id) is
8422                X : constant Node_Id := Original_Node (Arg);
8423
8424             begin
8425                if Nkind (X) /= N_String_Literal
8426                     and then
8427                   Nkind (X) /= N_Identifier
8428                then
8429                   Error_Pragma_Arg
8430                     ("inappropriate argument for pragma %", Arg);
8431                end if;
8432
8433                if OpenVMS_On_Target then
8434                   if (Nkind (X) = N_String_Literal
8435                        and then String_Length (Strval (X)) > 31)
8436                     or else
8437                      (Nkind (X) = N_Identifier
8438                        and then Length_Of_Name (Chars (X)) > 31)
8439                   then
8440                      Error_Pragma_Arg
8441                        ("argument for pragma % is longer than 31 characters",
8442                         Arg);
8443                   end if;
8444                end if;
8445             end Check_Too_Long;
8446
8447          --  Start of processing for Common_Object/Psect_Object
8448
8449          begin
8450             GNAT_Pragma;
8451             Gather_Associations (Names, Args);
8452             Process_Extended_Import_Export_Internal_Arg (Internal);
8453
8454             R_Internal := Relocate_Node (Internal);
8455
8456             Def_Id := Entity (R_Internal);
8457
8458             if Ekind (Def_Id) /= E_Constant
8459               and then Ekind (Def_Id) /= E_Variable
8460             then
8461                Error_Pragma_Arg
8462                  ("pragma% must designate an object", Internal);
8463             end if;
8464
8465             Check_Too_Long (R_Internal);
8466
8467             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
8468                Error_Pragma_Arg
8469                  ("cannot use pragma% for imported/exported object",
8470                   R_Internal);
8471             end if;
8472
8473             if Is_Concurrent_Type (Etype (R_Internal)) then
8474                Error_Pragma_Arg
8475                  ("cannot specify pragma % for task/protected object",
8476                   R_Internal);
8477             end if;
8478
8479             if Is_Psected (Def_Id) then
8480                Error_Msg_N ("?duplicate Psect_Object pragma", N);
8481             else
8482                Set_Is_Psected (Def_Id);
8483             end if;
8484
8485             if Ekind (Def_Id) = E_Constant then
8486                Error_Pragma_Arg
8487                  ("cannot specify pragma % for a constant", R_Internal);
8488             end if;
8489
8490             if Is_Record_Type (Etype (R_Internal)) then
8491                declare
8492                   Ent  : Entity_Id;
8493                   Decl : Entity_Id;
8494
8495                begin
8496                   Ent := First_Entity (Etype (R_Internal));
8497                   while Present (Ent) loop
8498                      Decl := Declaration_Node (Ent);
8499
8500                      if Ekind (Ent) = E_Component
8501                        and then Nkind (Decl) = N_Component_Declaration
8502                        and then Present (Expression (Decl))
8503                        and then Warn_On_Export_Import
8504                      then
8505                         Error_Msg_N
8506                           ("?object for pragma % has defaults", R_Internal);
8507                         exit;
8508
8509                      else
8510                         Next_Entity (Ent);
8511                      end if;
8512                   end loop;
8513                end;
8514             end if;
8515
8516             if Present (Size) then
8517                Check_Too_Long (Size);
8518             end if;
8519
8520             --  Make Psect case-insensitive.
8521
8522             if Present (External) then
8523                Check_Too_Long (External);
8524
8525                if Nkind (External) = N_String_Literal then
8526                   String_To_Name_Buffer (Strval (External));
8527                else
8528                   Get_Name_String (Chars (External));
8529                end if;
8530
8531                Set_All_Upper_Case;
8532                Start_String;
8533                Store_String_Chars (Name_Buffer (1 .. Name_Len));
8534                Str := End_String;
8535                R_External := Make_String_Literal
8536                  (Sloc => Sloc (External), Strval => Str);
8537             else
8538                Get_Name_String (Chars (Internal));
8539                Set_All_Upper_Case;
8540                Start_String;
8541                Store_String_Chars (Name_Buffer (1 .. Name_Len));
8542                Str := End_String;
8543                R_External := Make_String_Literal
8544                  (Sloc => Sloc (Internal), Strval => Str);
8545             end if;
8546
8547             --  Transform into pragma Linker_Section, add attributes to
8548             --  match what DEC Ada does. Ignore size for now?
8549
8550             Rewrite (N,
8551                Make_Pragma
8552                  (Sloc (N),
8553                   Name_Linker_Section,
8554                   New_List
8555                     (Make_Pragma_Argument_Association
8556                        (Sloc => Sloc (R_Internal),
8557                         Expression => R_Internal),
8558                      Make_Pragma_Argument_Association
8559                        (Sloc => Sloc (R_External),
8560                         Expression => R_External))));
8561
8562             Analyze (N);
8563
8564             --  Add Machine_Attribute of "overlaid", so the section overlays
8565             --  other sections of the same name.
8566
8567             Start_String;
8568             Store_String_Chars ("overlaid");
8569             Str := End_String;
8570
8571             MA :=
8572                Make_Pragma
8573                  (Sloc (N),
8574                   Name_Machine_Attribute,
8575                   New_List
8576                     (Make_Pragma_Argument_Association
8577                        (Sloc => Sloc (R_Internal),
8578                         Expression => R_Internal),
8579                      Make_Pragma_Argument_Association
8580                        (Sloc => Sloc (R_External),
8581                         Expression =>
8582                           Make_String_Literal
8583                             (Sloc => Sloc (R_External),
8584                              Strval => Str))));
8585             Analyze (MA);
8586
8587             --  Add Machine_Attribute of "global", so the section is visible
8588             --  everywhere
8589
8590             Start_String;
8591             Store_String_Chars ("global");
8592             Str := End_String;
8593
8594             MA :=
8595                Make_Pragma
8596                  (Sloc (N),
8597                   Name_Machine_Attribute,
8598                   New_List
8599                     (Make_Pragma_Argument_Association
8600                        (Sloc => Sloc (R_Internal),
8601                         Expression => R_Internal),
8602
8603                      Make_Pragma_Argument_Association
8604                        (Sloc => Sloc (R_External),
8605                         Expression =>
8606                           Make_String_Literal
8607                             (Sloc => Sloc (R_External),
8608                              Strval => Str))));
8609             Analyze (MA);
8610
8611             --  Add Machine_Attribute of "initialize", so the section is
8612             --  demand zeroed.
8613
8614             Start_String;
8615             Store_String_Chars ("initialize");
8616             Str := End_String;
8617
8618             MA :=
8619                Make_Pragma
8620                  (Sloc (N),
8621                   Name_Machine_Attribute,
8622                   New_List
8623                     (Make_Pragma_Argument_Association
8624                        (Sloc => Sloc (R_Internal),
8625                         Expression => R_Internal),
8626
8627                      Make_Pragma_Argument_Association
8628                        (Sloc => Sloc (R_External),
8629                         Expression =>
8630                           Make_String_Literal
8631                             (Sloc => Sloc (R_External),
8632                              Strval => Str))));
8633             Analyze (MA);
8634          end Psect_Object;
8635
8636          ----------
8637          -- Pure --
8638          ----------
8639
8640          --  pragma Pure [(library_unit_NAME)];
8641
8642          when Pragma_Pure => Pure : declare
8643             Ent : Entity_Id;
8644          begin
8645             Check_Ada_83_Warning;
8646             Check_Valid_Library_Unit_Pragma;
8647
8648             if Nkind (N) = N_Null_Statement then
8649                return;
8650             end if;
8651
8652             Ent := Find_Lib_Unit_Name;
8653             Set_Is_Pure (Ent);
8654             Set_Suppress_Elaboration_Warnings (Ent);
8655          end Pure;
8656
8657          -------------------
8658          -- Pure_Function --
8659          -------------------
8660
8661          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
8662
8663          when Pragma_Pure_Function => Pure_Function : declare
8664             E_Id      : Node_Id;
8665             E         : Entity_Id;
8666             Def_Id    : Entity_Id;
8667             Effective : Boolean := False;
8668
8669          begin
8670             GNAT_Pragma;
8671             Check_Arg_Count (1);
8672             Check_Optional_Identifier (Arg1, Name_Entity);
8673             Check_Arg_Is_Local_Name (Arg1);
8674             E_Id := Expression (Arg1);
8675
8676             if Error_Posted (E_Id) then
8677                return;
8678             end if;
8679
8680             --  Loop through homonyms (overloadings) of referenced entity
8681
8682             E := Entity (E_Id);
8683
8684             if Present (E) then
8685                loop
8686                   Def_Id := Get_Base_Subprogram (E);
8687
8688                   if Ekind (Def_Id) /= E_Function
8689                     and then Ekind (Def_Id) /= E_Generic_Function
8690                     and then Ekind (Def_Id) /= E_Operator
8691                   then
8692                      Error_Pragma_Arg
8693                        ("pragma% requires a function name", Arg1);
8694                   end if;
8695
8696                   Set_Is_Pure (Def_Id);
8697
8698                   if not Has_Pragma_Pure_Function (Def_Id) then
8699                      Set_Has_Pragma_Pure_Function (Def_Id);
8700                      Effective := True;
8701                   end if;
8702
8703                   E := Homonym (E);
8704                   exit when No (E) or else Scope (E) /= Current_Scope;
8705                end loop;
8706
8707                if not Effective
8708                  and then Warn_On_Redundant_Constructs
8709                then
8710                   Error_Msg_NE ("pragma Pure_Function on& is redundant?",
8711                     N, Entity (E_Id));
8712                end if;
8713             end if;
8714          end Pure_Function;
8715
8716          --------------------
8717          -- Queuing_Policy --
8718          --------------------
8719
8720          --  pragma Queuing_Policy (policy_IDENTIFIER);
8721
8722          when Pragma_Queuing_Policy => declare
8723             QP : Character;
8724
8725          begin
8726             Check_Ada_83_Warning;
8727             Check_Arg_Count (1);
8728             Check_No_Identifiers;
8729             Check_Arg_Is_Queuing_Policy (Arg1);
8730             Check_Valid_Configuration_Pragma;
8731             Get_Name_String (Chars (Expression (Arg1)));
8732             QP := Fold_Upper (Name_Buffer (1));
8733
8734             if Queuing_Policy /= ' '
8735               and then Queuing_Policy /= QP
8736             then
8737                Error_Msg_Sloc := Queuing_Policy_Sloc;
8738                Error_Pragma ("queuing policy incompatible with policy#");
8739
8740             --  Set new policy, but always preserve System_Location since
8741             --  we like the error message with the run time name.
8742
8743             else
8744                Queuing_Policy := QP;
8745
8746                if Queuing_Policy_Sloc /= System_Location then
8747                   Queuing_Policy_Sloc := Loc;
8748                end if;
8749             end if;
8750          end;
8751
8752          ---------------------------
8753          -- Remote_Call_Interface --
8754          ---------------------------
8755
8756          --  pragma Remote_Call_Interface [(library_unit_NAME)];
8757
8758          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
8759             Cunit_Node : Node_Id;
8760             Cunit_Ent  : Entity_Id;
8761             K          : Node_Kind;
8762
8763          begin
8764             Check_Ada_83_Warning;
8765             Check_Valid_Library_Unit_Pragma;
8766
8767             if Nkind (N) = N_Null_Statement then
8768                return;
8769             end if;
8770
8771             Cunit_Node := Cunit (Current_Sem_Unit);
8772             K          := Nkind (Unit (Cunit_Node));
8773             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
8774
8775             if K = N_Package_Declaration
8776               or else K = N_Generic_Package_Declaration
8777               or else K = N_Subprogram_Declaration
8778               or else K = N_Generic_Subprogram_Declaration
8779               or else (K = N_Subprogram_Body
8780                          and then Acts_As_Spec (Unit (Cunit_Node)))
8781             then
8782                null;
8783             else
8784                Error_Pragma (
8785                  "pragma% must apply to package or subprogram declaration");
8786             end if;
8787
8788             Set_Is_Remote_Call_Interface (Cunit_Ent);
8789          end Remote_Call_Interface;
8790
8791          ------------------
8792          -- Remote_Types --
8793          ------------------
8794
8795          --  pragma Remote_Types [(library_unit_NAME)];
8796
8797          when Pragma_Remote_Types => Remote_Types : declare
8798             Cunit_Node : Node_Id;
8799             Cunit_Ent  : Entity_Id;
8800
8801          begin
8802             Check_Ada_83_Warning;
8803             Check_Valid_Library_Unit_Pragma;
8804
8805             if Nkind (N) = N_Null_Statement then
8806                return;
8807             end if;
8808
8809             Cunit_Node := Cunit (Current_Sem_Unit);
8810             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
8811
8812             if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8813               and then
8814               Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8815             then
8816                Error_Pragma (
8817                  "pragma% can only apply to a package declaration");
8818             end if;
8819
8820             Set_Is_Remote_Types (Cunit_Ent);
8821          end Remote_Types;
8822
8823          ---------------
8824          -- Ravenscar --
8825          ---------------
8826
8827          --  pragma Ravenscar;
8828
8829          when Pragma_Ravenscar =>
8830             GNAT_Pragma;
8831             Check_Arg_Count (0);
8832             Check_Valid_Configuration_Pragma;
8833             Set_Ravenscar_Profile (N);
8834
8835             if Warn_On_Obsolescent_Feature then
8836                Error_Msg_N
8837                  ("pragma Ravenscar is an obsolescent feature?", N);
8838                Error_Msg_N
8839                  ("|use pragma Profile (Ravenscar) instead", N);
8840             end if;
8841
8842          -------------------------
8843          -- Restricted_Run_Time --
8844          -------------------------
8845
8846          --  pragma Restricted_Run_Time;
8847
8848          when Pragma_Restricted_Run_Time =>
8849             GNAT_Pragma;
8850             Check_Arg_Count (0);
8851             Check_Valid_Configuration_Pragma;
8852             Set_Profile_Restrictions (Restricted, N, Warn => False);
8853
8854             if Warn_On_Obsolescent_Feature then
8855                Error_Msg_N
8856                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
8857                Error_Msg_N
8858                  ("|use pragma Profile (Restricted) instead", N);
8859             end if;
8860
8861          ------------------
8862          -- Restrictions --
8863          ------------------
8864
8865          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
8866
8867          --  RESTRICTION ::=
8868          --    restriction_IDENTIFIER
8869          --  | restriction_parameter_IDENTIFIER => EXPRESSION
8870
8871          when Pragma_Restrictions =>
8872             Process_Restrictions_Or_Restriction_Warnings;
8873
8874          --------------------------
8875          -- Restriction_Warnings --
8876          --------------------------
8877
8878          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
8879
8880          --  RESTRICTION ::=
8881          --    restriction_IDENTIFIER
8882          --  | restriction_parameter_IDENTIFIER => EXPRESSION
8883
8884          when Pragma_Restriction_Warnings =>
8885             Process_Restrictions_Or_Restriction_Warnings;
8886
8887          ----------------
8888          -- Reviewable --
8889          ----------------
8890
8891          --  pragma Reviewable;
8892
8893          when Pragma_Reviewable =>
8894             Check_Ada_83_Warning;
8895             Check_Arg_Count (0);
8896
8897          -------------------
8898          -- Share_Generic --
8899          -------------------
8900
8901          --  pragma Share_Generic (NAME {, NAME});
8902
8903          when Pragma_Share_Generic =>
8904             GNAT_Pragma;
8905             Process_Generic_List;
8906
8907          ------------
8908          -- Shared --
8909          ------------
8910
8911          --  pragma Shared (LOCAL_NAME);
8912
8913          when Pragma_Shared =>
8914             GNAT_Pragma;
8915             Process_Atomic_Shared_Volatile;
8916
8917          --------------------
8918          -- Shared_Passive --
8919          --------------------
8920
8921          --  pragma Shared_Passive [(library_unit_NAME)];
8922
8923          --  Set the flag Is_Shared_Passive of program unit name entity
8924
8925          when Pragma_Shared_Passive => Shared_Passive : declare
8926             Cunit_Node : Node_Id;
8927             Cunit_Ent  : Entity_Id;
8928
8929          begin
8930             Check_Ada_83_Warning;
8931             Check_Valid_Library_Unit_Pragma;
8932
8933             if Nkind (N) = N_Null_Statement then
8934                return;
8935             end if;
8936
8937             Cunit_Node := Cunit (Current_Sem_Unit);
8938             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
8939
8940             if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8941               and then
8942               Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8943             then
8944                Error_Pragma (
8945                  "pragma% can only apply to a package declaration");
8946             end if;
8947
8948             Set_Is_Shared_Passive (Cunit_Ent);
8949          end Shared_Passive;
8950
8951          ----------------------
8952          -- Source_File_Name --
8953          ----------------------
8954
8955          --  There are five forms for this pragma:
8956
8957          --  pragma Source_File_Name (
8958          --    [UNIT_NAME      =>] unit_NAME,
8959          --     BODY_FILE_NAME =>  STRING_LITERAL
8960          --    [, [INDEX =>] INTEGER_LITERAL]);
8961
8962          --  pragma Source_File_Name (
8963          --    [UNIT_NAME      =>] unit_NAME,
8964          --     SPEC_FILE_NAME =>  STRING_LITERAL
8965          --    [, [INDEX =>] INTEGER_LITERAL]);
8966
8967          --  pragma Source_File_Name (
8968          --     BODY_FILE_NAME  => STRING_LITERAL
8969          --  [, DOT_REPLACEMENT => STRING_LITERAL]
8970          --  [, CASING          => CASING_SPEC]);
8971
8972          --  pragma Source_File_Name (
8973          --     SPEC_FILE_NAME  => STRING_LITERAL
8974          --  [, DOT_REPLACEMENT => STRING_LITERAL]
8975          --  [, CASING          => CASING_SPEC]);
8976
8977          --  pragma Source_File_Name (
8978          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
8979          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
8980          --  [, CASING             => CASING_SPEC]);
8981
8982          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
8983
8984          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
8985          --  Source_File_Name (SFN), however their usage is exclusive:
8986          --  SFN can only be used when no project file is used, while
8987          --  SFNP can only be used when a project file is used.
8988
8989          --  No processing here. Processing was completed during parsing,
8990          --  since we need to have file names set as early as possible.
8991          --  Units are loaded well before semantic processing starts.
8992
8993          --  The only processing we defer to this point is the check
8994          --  for correct placement.
8995
8996          when Pragma_Source_File_Name =>
8997             GNAT_Pragma;
8998             Check_Valid_Configuration_Pragma;
8999
9000          ------------------------------
9001          -- Source_File_Name_Project --
9002          ------------------------------
9003
9004          --  See Source_File_Name for syntax
9005
9006          --  No processing here. Processing was completed during parsing,
9007          --  since we need to have file names set as early as possible.
9008          --  Units are loaded well before semantic processing starts.
9009
9010          --  The only processing we defer to this point is the check
9011          --  for correct placement.
9012
9013          when Pragma_Source_File_Name_Project =>
9014             GNAT_Pragma;
9015             Check_Valid_Configuration_Pragma;
9016
9017             --  Check that a pragma Source_File_Name_Project is used only
9018             --  in a configuration pragmas file.
9019
9020             --  Pragmas Source_File_Name_Project should only be generated
9021             --  by the Project Manager in configuration pragmas files.
9022
9023             --  This is really an ugly test. It seems to depend on some
9024             --  accidental and undocumented property. At the very least
9025             --  it needs to be documented, but it would be better to have
9026             --  a clean way of testing if we are in a configuration file???
9027
9028             if Present (Parent (N)) then
9029                Error_Pragma
9030                  ("pragma% can only appear in a configuration pragmas file");
9031             end if;
9032
9033          ----------------------
9034          -- Source_Reference --
9035          ----------------------
9036
9037          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
9038
9039          --  Nothing to do, all processing completed in Par.Prag, since we
9040          --  need the information for possible parser messages that are output
9041
9042          when Pragma_Source_Reference =>
9043             GNAT_Pragma;
9044
9045          ------------------
9046          -- Storage_Size --
9047          ------------------
9048
9049          --  pragma Storage_Size (EXPRESSION);
9050
9051          when Pragma_Storage_Size => Storage_Size : declare
9052             P   : constant Node_Id := Parent (N);
9053             Arg : Node_Id;
9054
9055          begin
9056             Check_No_Identifiers;
9057             Check_Arg_Count (1);
9058
9059             --  The expression must be analyzed in the special manner
9060             --  described in "Handling of Default Expressions" in sem.ads.
9061
9062             --  Set In_Default_Expression for per-object case ???
9063
9064             Arg := Expression (Arg1);
9065             Analyze_Per_Use_Expression (Arg, Any_Integer);
9066
9067             if not Is_Static_Expression (Arg) then
9068                Check_Restriction (Static_Storage_Size, Arg);
9069             end if;
9070
9071             if Nkind (P) /= N_Task_Definition then
9072                Pragma_Misplaced;
9073                return;
9074
9075             else
9076                if Has_Storage_Size_Pragma (P) then
9077                   Error_Pragma ("duplicate pragma% not allowed");
9078                else
9079                   Set_Has_Storage_Size_Pragma (P, True);
9080                end if;
9081
9082                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9083                --  ???  exp_ch9 should use this!
9084             end if;
9085          end Storage_Size;
9086
9087          ------------------
9088          -- Storage_Unit --
9089          ------------------
9090
9091          --  pragma Storage_Unit (NUMERIC_LITERAL);
9092
9093          --  Only permitted argument is System'Storage_Unit value
9094
9095          when Pragma_Storage_Unit =>
9096             Check_No_Identifiers;
9097             Check_Arg_Count (1);
9098             Check_Arg_Is_Integer_Literal (Arg1);
9099
9100             if Intval (Expression (Arg1)) /=
9101               UI_From_Int (Ttypes.System_Storage_Unit)
9102             then
9103                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
9104                Error_Pragma_Arg
9105                  ("the only allowed argument for pragma% is ^", Arg1);
9106             end if;
9107
9108          --------------------
9109          -- Stream_Convert --
9110          --------------------
9111
9112          --  pragma Stream_Convert (
9113          --    [Entity =>] type_LOCAL_NAME,
9114          --    [Read   =>] function_NAME,
9115          --    [Write  =>] function NAME);
9116
9117          when Pragma_Stream_Convert => Stream_Convert : declare
9118
9119             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
9120             --  Check that the given argument is the name of a local
9121             --  function of one argument that is not overloaded earlier
9122             --  in the current local scope. A check is also made that the
9123             --  argument is a function with one parameter.
9124
9125             --------------------------------------
9126             -- Check_OK_Stream_Convert_Function --
9127             --------------------------------------
9128
9129             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
9130                Ent : Entity_Id;
9131
9132             begin
9133                Check_Arg_Is_Local_Name (Arg);
9134                Ent := Entity (Expression (Arg));
9135
9136                if Has_Homonym (Ent) then
9137                   Error_Pragma_Arg
9138                     ("argument for pragma% may not be overloaded", Arg);
9139                end if;
9140
9141                if Ekind (Ent) /= E_Function
9142                  or else No (First_Formal (Ent))
9143                  or else Present (Next_Formal (First_Formal (Ent)))
9144                then
9145                   Error_Pragma_Arg
9146                     ("argument for pragma% must be" &
9147                      " function of one argument", Arg);
9148                end if;
9149             end Check_OK_Stream_Convert_Function;
9150
9151          --  Start of procecessing for Stream_Convert
9152
9153          begin
9154             GNAT_Pragma;
9155             Check_Arg_Count (3);
9156             Check_Optional_Identifier (Arg1, Name_Entity);
9157             Check_Optional_Identifier (Arg2, Name_Read);
9158             Check_Optional_Identifier (Arg3, Name_Write);
9159             Check_Arg_Is_Local_Name (Arg1);
9160             Check_OK_Stream_Convert_Function (Arg2);
9161             Check_OK_Stream_Convert_Function (Arg3);
9162
9163             declare
9164                Typ   : constant Entity_Id :=
9165                          Underlying_Type (Entity (Expression (Arg1)));
9166                Read  : constant Entity_Id := Entity (Expression (Arg2));
9167                Write : constant Entity_Id := Entity (Expression (Arg3));
9168
9169             begin
9170                if Etype (Typ) = Any_Type
9171                     or else
9172                   Etype (Read) = Any_Type
9173                     or else
9174                   Etype (Write) = Any_Type
9175                then
9176                   return;
9177                end if;
9178
9179                Check_First_Subtype (Arg1);
9180
9181                if Rep_Item_Too_Early (Typ, N)
9182                     or else
9183                   Rep_Item_Too_Late (Typ, N)
9184                then
9185                   return;
9186                end if;
9187
9188                if Underlying_Type (Etype (Read)) /= Typ then
9189                   Error_Pragma_Arg
9190                     ("incorrect return type for function&", Arg2);
9191                end if;
9192
9193                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
9194                   Error_Pragma_Arg
9195                     ("incorrect parameter type for function&", Arg3);
9196                end if;
9197
9198                if Underlying_Type (Etype (First_Formal (Read))) /=
9199                   Underlying_Type (Etype (Write))
9200                then
9201                   Error_Pragma_Arg
9202                     ("result type of & does not match Read parameter type",
9203                      Arg3);
9204                end if;
9205             end;
9206          end Stream_Convert;
9207
9208          -------------------------
9209          -- Style_Checks (GNAT) --
9210          -------------------------
9211
9212          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9213
9214          --  This is processed by the parser since some of the style
9215          --  checks take place during source scanning and parsing. This
9216          --  means that we don't need to issue error messages here.
9217
9218          when Pragma_Style_Checks => Style_Checks : declare
9219             A  : constant Node_Id   := Expression (Arg1);
9220             S  : String_Id;
9221             C  : Char_Code;
9222
9223          begin
9224             GNAT_Pragma;
9225             Check_No_Identifiers;
9226
9227             --  Two argument form
9228
9229             if Arg_Count = 2 then
9230                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9231
9232                declare
9233                   E_Id : Node_Id;
9234                   E    : Entity_Id;
9235
9236                begin
9237                   E_Id := Expression (Arg2);
9238                   Analyze (E_Id);
9239
9240                   if not Is_Entity_Name (E_Id) then
9241                      Error_Pragma_Arg
9242                        ("second argument of pragma% must be entity name",
9243                         Arg2);
9244                   end if;
9245
9246                   E := Entity (E_Id);
9247
9248                   if E = Any_Id then
9249                      return;
9250                   else
9251                      loop
9252                         Set_Suppress_Style_Checks (E,
9253                           (Chars (Expression (Arg1)) = Name_Off));
9254                         exit when No (Homonym (E));
9255                         E := Homonym (E);
9256                      end loop;
9257                   end if;
9258                end;
9259
9260             --  One argument form
9261
9262             else
9263                Check_Arg_Count (1);
9264
9265                if Nkind (A) = N_String_Literal then
9266                   S   := Strval (A);
9267
9268                   declare
9269                      Slen    : constant Natural := Natural (String_Length (S));
9270                      Options : String (1 .. Slen);
9271                      J       : Natural;
9272
9273                   begin
9274                      J := 1;
9275                      loop
9276                         C := Get_String_Char (S, Int (J));
9277                         exit when not In_Character_Range (C);
9278                         Options (J) := Get_Character (C);
9279
9280                         if J = Slen then
9281                            Set_Style_Check_Options (Options);
9282                            exit;
9283                         else
9284                            J := J + 1;
9285                         end if;
9286                      end loop;
9287                   end;
9288
9289                elsif Nkind (A) = N_Identifier then
9290
9291                   if Chars (A) = Name_All_Checks then
9292                      Set_Default_Style_Check_Options;
9293
9294                   elsif Chars (A) = Name_On then
9295                      Style_Check := True;
9296
9297                   elsif Chars (A) = Name_Off then
9298                      Style_Check := False;
9299
9300                   end if;
9301                end if;
9302             end if;
9303          end Style_Checks;
9304
9305          --------------
9306          -- Subtitle --
9307          --------------
9308
9309          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
9310
9311          when Pragma_Subtitle =>
9312             GNAT_Pragma;
9313             Check_Arg_Count (1);
9314             Check_Optional_Identifier (Arg1, Name_Subtitle);
9315             Check_Arg_Is_String_Literal (Arg1);
9316
9317          --------------
9318          -- Suppress --
9319          --------------
9320
9321          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
9322
9323          when Pragma_Suppress =>
9324             Process_Suppress_Unsuppress (True);
9325
9326          ------------------
9327          -- Suppress_All --
9328          ------------------
9329
9330          --  pragma Suppress_All;
9331
9332          --  The only check made here is that the pragma appears in the
9333          --  proper place, i.e. following a compilation unit. If indeed
9334          --  it appears in this context, then the parser has already
9335          --  inserted an equivalent pragma Suppress (All_Checks) to get
9336          --  the required effect.
9337
9338          when Pragma_Suppress_All =>
9339             GNAT_Pragma;
9340             Check_Arg_Count (0);
9341
9342             if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9343               or else not Is_List_Member (N)
9344               or else List_Containing (N) /= Pragmas_After (Parent (N))
9345             then
9346                Error_Pragma
9347                  ("misplaced pragma%, must follow compilation unit");
9348             end if;
9349
9350          -------------------------
9351          -- Suppress_Debug_Info --
9352          -------------------------
9353
9354          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
9355
9356          when Pragma_Suppress_Debug_Info =>
9357             GNAT_Pragma;
9358             Check_Arg_Count (1);
9359             Check_Arg_Is_Local_Name (Arg1);
9360             Check_Optional_Identifier (Arg1, Name_Entity);
9361             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
9362
9363          ----------------------------------
9364          -- Suppress_Exception_Locations --
9365          ----------------------------------
9366
9367          --  pragma Suppress_Exception_Locations;
9368
9369          when Pragma_Suppress_Exception_Locations =>
9370             GNAT_Pragma;
9371             Check_Arg_Count (0);
9372             Check_Valid_Configuration_Pragma;
9373             Exception_Locations_Suppressed := True;
9374
9375          -----------------------------
9376          -- Suppress_Initialization --
9377          -----------------------------
9378
9379          --  pragma Suppress_Initialization ([Entity =>] type_Name);
9380
9381          when Pragma_Suppress_Initialization => Suppress_Init : declare
9382             E_Id : Node_Id;
9383             E    : Entity_Id;
9384
9385          begin
9386             GNAT_Pragma;
9387             Check_Arg_Count (1);
9388             Check_Optional_Identifier (Arg1, Name_Entity);
9389             Check_Arg_Is_Local_Name (Arg1);
9390
9391             E_Id := Expression (Arg1);
9392
9393             if Etype (E_Id) = Any_Type then
9394                return;
9395             end if;
9396
9397             E := Entity (E_Id);
9398
9399             if Is_Type (E) then
9400                if Is_Incomplete_Or_Private_Type (E) then
9401                   if No (Full_View (Base_Type (E))) then
9402                      Error_Pragma_Arg
9403                        ("argument of pragma% cannot be an incomplete type",
9404                          Arg1);
9405                   else
9406                      Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
9407                   end if;
9408                else
9409                   Set_Suppress_Init_Proc (Base_Type (E));
9410                end if;
9411
9412             else
9413                Error_Pragma_Arg
9414                  ("pragma% requires argument that is a type name", Arg1);
9415             end if;
9416          end Suppress_Init;
9417
9418          -----------------
9419          -- System_Name --
9420          -----------------
9421
9422          --  pragma System_Name (DIRECT_NAME);
9423
9424          --  Syntax check: one argument, which must be the identifier GNAT
9425          --  or the identifier GCC, no other identifiers are acceptable.
9426
9427          when Pragma_System_Name =>
9428             Check_No_Identifiers;
9429             Check_Arg_Count (1);
9430             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
9431
9432          -----------------------------
9433          -- Task_Dispatching_Policy --
9434          -----------------------------
9435
9436          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
9437
9438          when Pragma_Task_Dispatching_Policy => declare
9439             DP : Character;
9440
9441          begin
9442             Check_Ada_83_Warning;
9443             Check_Arg_Count (1);
9444             Check_No_Identifiers;
9445             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9446             Check_Valid_Configuration_Pragma;
9447             Get_Name_String (Chars (Expression (Arg1)));
9448             DP := Fold_Upper (Name_Buffer (1));
9449
9450             if Task_Dispatching_Policy /= ' '
9451               and then Task_Dispatching_Policy /= DP
9452             then
9453                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9454                Error_Pragma
9455                  ("task dispatching policy incompatible with policy#");
9456
9457             --  Set new policy, but always preserve System_Location since
9458             --  we like the error message with the run time name.
9459
9460             else
9461                Task_Dispatching_Policy := DP;
9462
9463                if Task_Dispatching_Policy_Sloc /= System_Location then
9464                   Task_Dispatching_Policy_Sloc := Loc;
9465                end if;
9466             end if;
9467          end;
9468
9469          --------------
9470          -- Task_Info --
9471          --------------
9472
9473          --  pragma Task_Info (EXPRESSION);
9474
9475          when Pragma_Task_Info => Task_Info : declare
9476             P : constant Node_Id := Parent (N);
9477
9478          begin
9479             GNAT_Pragma;
9480
9481             if Nkind (P) /= N_Task_Definition then
9482                Error_Pragma ("pragma% must appear in task definition");
9483             end if;
9484
9485             Check_No_Identifiers;
9486             Check_Arg_Count (1);
9487
9488             Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
9489
9490             if Etype (Expression (Arg1)) = Any_Type then
9491                return;
9492             end if;
9493
9494             if Has_Task_Info_Pragma (P) then
9495                Error_Pragma ("duplicate pragma% not allowed");
9496             else
9497                Set_Has_Task_Info_Pragma (P, True);
9498             end if;
9499          end Task_Info;
9500
9501          ---------------
9502          -- Task_Name --
9503          ---------------
9504
9505          --  pragma Task_Name (string_EXPRESSION);
9506
9507          when Pragma_Task_Name => Task_Name : declare
9508          --  pragma Priority (EXPRESSION);
9509
9510             P   : constant Node_Id := Parent (N);
9511             Arg : Node_Id;
9512
9513          begin
9514             Check_No_Identifiers;
9515             Check_Arg_Count (1);
9516
9517             Arg := Expression (Arg1);
9518             Analyze_And_Resolve (Arg, Standard_String);
9519
9520             if Nkind (P) /= N_Task_Definition then
9521                Pragma_Misplaced;
9522             end if;
9523
9524             if Has_Task_Name_Pragma (P) then
9525                Error_Pragma ("duplicate pragma% not allowed");
9526             else
9527                Set_Has_Task_Name_Pragma (P, True);
9528                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9529             end if;
9530          end Task_Name;
9531
9532          ------------------
9533          -- Task_Storage --
9534          ------------------
9535
9536          --  pragma Task_Storage (
9537          --     [Task_Type =>] LOCAL_NAME,
9538          --     [Top_Guard =>] static_integer_EXPRESSION);
9539
9540          when Pragma_Task_Storage => Task_Storage : declare
9541             Args  : Args_List (1 .. 2);
9542             Names : constant Name_List (1 .. 2) := (
9543                       Name_Task_Type,
9544                       Name_Top_Guard);
9545
9546             Task_Type : Node_Id renames Args (1);
9547             Top_Guard : Node_Id renames Args (2);
9548
9549             Ent : Entity_Id;
9550
9551          begin
9552             GNAT_Pragma;
9553             Gather_Associations (Names, Args);
9554
9555             if No (Task_Type) then
9556                Error_Pragma
9557                  ("missing task_type argument for pragma%");
9558             end if;
9559
9560             Check_Arg_Is_Local_Name (Task_Type);
9561
9562             Ent := Entity (Task_Type);
9563
9564             if not Is_Task_Type (Ent) then
9565                Error_Pragma_Arg
9566                  ("argument for pragma% must be task type", Task_Type);
9567             end if;
9568
9569             if No (Top_Guard) then
9570                Error_Pragma_Arg
9571                  ("pragma% takes two arguments", Task_Type);
9572             else
9573                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
9574             end if;
9575
9576             Check_First_Subtype (Task_Type);
9577
9578             if Rep_Item_Too_Late (Ent, N) then
9579                raise Pragma_Exit;
9580             end if;
9581          end Task_Storage;
9582
9583          -----------------
9584          -- Thread_Body --
9585          -----------------
9586
9587          --  pragma Thread_Body
9588          --    (  [Entity =>]               LOCAL_NAME
9589          --     [,[Secondary_Stack_Size =>] static_integer_EXPRESSION]);
9590
9591          when Pragma_Thread_Body => Thread_Body : declare
9592             Id : Node_Id;
9593             SS : Node_Id;
9594             E  : Entity_Id;
9595
9596          begin
9597             GNAT_Pragma;
9598             Check_At_Least_N_Arguments (1);
9599             Check_At_Most_N_Arguments (2);
9600             Check_Optional_Identifier (Arg1, Name_Entity);
9601             Check_Arg_Is_Local_Name (Arg1);
9602
9603             Id := Expression (Arg1);
9604
9605             if not Is_Entity_Name (Id)
9606               or else not Is_Subprogram (Entity (Id))
9607             then
9608                Error_Pragma_Arg ("subprogram name required", Arg1);
9609             end if;
9610
9611             E := Entity (Id);
9612
9613             --  Go to renamed subprogram if present, since Thread_Body applies
9614             --  to the actual renamed entity, not to the renaming entity.
9615
9616             if Present (Alias (E))
9617               and then Nkind (Parent (Declaration_Node (E))) =
9618                          N_Subprogram_Renaming_Declaration
9619             then
9620                E := Alias (E);
9621             end if;
9622
9623             --  Various error checks
9624
9625             if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then
9626                Error_Pragma
9627                  ("pragma% requires separate spec and must come before body");
9628
9629             elsif Rep_Item_Too_Early (E, N)
9630                  or else
9631                Rep_Item_Too_Late (E, N)
9632             then
9633                raise Pragma_Exit;
9634
9635             elsif Is_Thread_Body (E) then
9636                Error_Pragma_Arg
9637                  ("only one thread body pragma allowed", Arg1);
9638
9639             elsif Present (Homonym (E))
9640               and then Scope (Homonym (E)) = Current_Scope
9641             then
9642                Error_Pragma_Arg
9643                  ("thread body subprogram must not be overloaded", Arg1);
9644             end if;
9645
9646             Set_Is_Thread_Body (E);
9647
9648             --  Deal with secondary stack argument
9649
9650             if Arg_Count = 2 then
9651                Check_Optional_Identifier (Arg2, Name_Secondary_Stack_Size);
9652                SS := Expression (Arg2);
9653                Analyze_And_Resolve (SS, Any_Integer);
9654             end if;
9655          end Thread_Body;
9656
9657          ----------------
9658          -- Time_Slice --
9659          ----------------
9660
9661          --  pragma Time_Slice (static_duration_EXPRESSION);
9662
9663          when Pragma_Time_Slice => Time_Slice : declare
9664             Val : Ureal;
9665             Nod : Node_Id;
9666
9667          begin
9668             GNAT_Pragma;
9669             Check_Arg_Count (1);
9670             Check_No_Identifiers;
9671             Check_In_Main_Program;
9672             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
9673
9674             if not Error_Posted (Arg1) then
9675                Nod := Next (N);
9676                while Present (Nod) loop
9677                   if Nkind (Nod) = N_Pragma
9678                     and then Chars (Nod) = Name_Time_Slice
9679                   then
9680                      Error_Msg_Name_1 := Chars (N);
9681                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
9682                   end if;
9683
9684                   Next (Nod);
9685                end loop;
9686             end if;
9687
9688             --  Process only if in main unit
9689
9690             if Get_Source_Unit (Loc) = Main_Unit then
9691                Opt.Time_Slice_Set := True;
9692                Val := Expr_Value_R (Expression (Arg1));
9693
9694                if Val <= Ureal_0 then
9695                   Opt.Time_Slice_Value := 0;
9696
9697                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
9698                   Opt.Time_Slice_Value := 1_000_000_000;
9699
9700                else
9701                   Opt.Time_Slice_Value :=
9702                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
9703                end if;
9704             end if;
9705          end Time_Slice;
9706
9707          -----------
9708          -- Title --
9709          -----------
9710
9711          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
9712
9713          --   TITLING_OPTION ::=
9714          --     [Title =>] STRING_LITERAL
9715          --   | [Subtitle =>] STRING_LITERAL
9716
9717          when Pragma_Title => Title : declare
9718             Args  : Args_List (1 .. 2);
9719             Names : constant Name_List (1 .. 2) := (
9720                       Name_Title,
9721                       Name_Subtitle);
9722
9723          begin
9724             GNAT_Pragma;
9725             Gather_Associations (Names, Args);
9726
9727             for J in 1 .. 2 loop
9728                if Present (Args (J)) then
9729                   Check_Arg_Is_String_Literal (Args (J));
9730                end if;
9731             end loop;
9732          end Title;
9733
9734          ---------------------
9735          -- Unchecked_Union --
9736          ---------------------
9737
9738          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
9739
9740          when Pragma_Unchecked_Union => Unchecked_Union : declare
9741             Assoc   : constant Node_Id := Arg1;
9742             Type_Id : constant Node_Id := Expression (Assoc);
9743             Typ     : Entity_Id;
9744             Discr   : Entity_Id;
9745             Tdef    : Node_Id;
9746             Clist   : Node_Id;
9747             Vpart   : Node_Id;
9748             Comp    : Node_Id;
9749             Variant : Node_Id;
9750
9751          begin
9752             GNAT_Pragma;
9753             Check_No_Identifiers;
9754             Check_Arg_Count (1);
9755             Check_Arg_Is_Local_Name (Arg1);
9756
9757             Find_Type (Type_Id);
9758             Typ := Entity (Type_Id);
9759
9760             if Typ = Any_Type
9761               or else Rep_Item_Too_Early (Typ, N)
9762             then
9763                return;
9764             else
9765                Typ := Underlying_Type (Typ);
9766             end if;
9767
9768             if Rep_Item_Too_Late (Typ, N) then
9769                return;
9770             end if;
9771
9772             Check_First_Subtype (Arg1);
9773
9774             --  Note remaining cases are references to a type in the current
9775             --  declarative part. If we find an error, we post the error on
9776             --  the relevant type declaration at an appropriate point.
9777
9778             if not Is_Record_Type (Typ) then
9779                Error_Msg_N ("Unchecked_Union must be record type", Typ);
9780                return;
9781
9782             elsif Is_Tagged_Type (Typ) then
9783                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
9784                return;
9785
9786             elsif Is_Limited_Type (Typ) then
9787                Error_Msg_N
9788                  ("Unchecked_Union must not be limited record type", Typ);
9789                Explain_Limited_Type (Typ, Typ);
9790                return;
9791
9792             else
9793                if not Has_Discriminants (Typ) then
9794                   Error_Msg_N
9795                     ("Unchecked_Union must have one discriminant", Typ);
9796                   return;
9797                end if;
9798
9799                Discr := First_Discriminant (Typ);
9800
9801                if Present (Next_Discriminant (Discr)) then
9802                   Error_Msg_N
9803                     ("Unchecked_Union must have exactly one discriminant",
9804                      Next_Discriminant (Discr));
9805                   return;
9806                end if;
9807
9808                if No (Discriminant_Default_Value (Discr)) then
9809                   Error_Msg_N
9810                     ("Unchecked_Union discriminant must have default value",
9811                      Discr);
9812                end if;
9813
9814                Tdef  := Type_Definition (Declaration_Node (Typ));
9815                Clist := Component_List (Tdef);
9816
9817                Comp := First (Component_Items (Clist));
9818                while Present (Comp) loop
9819
9820                   Check_Component (Comp);
9821                   Next (Comp);
9822
9823                end loop;
9824
9825                if No (Clist) or else No (Variant_Part (Clist)) then
9826                   Error_Msg_N
9827                     ("Unchecked_Union must have variant part",
9828                      Tdef);
9829                   return;
9830                end if;
9831
9832                Vpart := Variant_Part (Clist);
9833                Variant := First (Variants (Vpart));
9834                while Present (Variant) loop
9835
9836                   Check_Variant (Variant);
9837                   Next (Variant);
9838
9839                end loop;
9840             end if;
9841
9842             Set_Is_Unchecked_Union  (Typ, True);
9843             Set_Convention          (Typ, Convention_C);
9844
9845             Set_Has_Unchecked_Union (Base_Type (Typ), True);
9846             Set_Is_Unchecked_Union  (Base_Type (Typ), True);
9847          end Unchecked_Union;
9848
9849          ------------------------
9850          -- Unimplemented_Unit --
9851          ------------------------
9852
9853          --  pragma Unimplemented_Unit;
9854
9855          --  Note: this only gives an error if we are generating code,
9856          --  or if we are in a generic library unit (where the pragma
9857          --  appears in the body, not in the spec).
9858
9859          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
9860             Cunitent : constant Entity_Id :=
9861                          Cunit_Entity (Get_Source_Unit (Loc));
9862             Ent_Kind : constant Entity_Kind :=
9863                          Ekind (Cunitent);
9864
9865          begin
9866             GNAT_Pragma;
9867             Check_Arg_Count (0);
9868
9869             if Operating_Mode = Generate_Code
9870               or else Ent_Kind = E_Generic_Function
9871               or else Ent_Kind = E_Generic_Procedure
9872               or else Ent_Kind = E_Generic_Package
9873             then
9874                Get_Name_String (Chars (Cunitent));
9875                Set_Casing (Mixed_Case);
9876                Write_Str (Name_Buffer (1 .. Name_Len));
9877                Write_Str (" is not implemented");
9878                Write_Eol;
9879                raise Unrecoverable_Error;
9880             end if;
9881          end Unimplemented_Unit;
9882
9883          --------------------
9884          -- Universal_Data --
9885          --------------------
9886
9887          --  pragma Universal_Data [(library_unit_NAME)];
9888
9889          when Pragma_Universal_Data =>
9890             GNAT_Pragma;
9891
9892             --  If this is a configuration pragma, then set the universal
9893             --  addressing option, otherwise confirm that the pragma
9894             --  satisfies the requirements of library unit pragma placement
9895             --  and leave it to the GNAAMP back end to detect the pragma
9896             --  (avoids transitive setting of the option due to withed units).
9897
9898             if Is_Configuration_Pragma then
9899                Universal_Addressing_On_AAMP := True;
9900             else
9901                Check_Valid_Library_Unit_Pragma;
9902             end if;
9903
9904             if not AAMP_On_Target then
9905                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
9906             end if;
9907
9908          ------------------
9909          -- Unreferenced --
9910          ------------------
9911
9912          --  pragma Unreferenced (local_Name {, local_Name});
9913
9914          when Pragma_Unreferenced => Unreferenced : declare
9915             Arg_Node : Node_Id;
9916             Arg_Expr : Node_Id;
9917             Arg_Ent  : Entity_Id;
9918
9919          begin
9920             GNAT_Pragma;
9921             Check_At_Least_N_Arguments (1);
9922
9923             Arg_Node := Arg1;
9924
9925             while Present (Arg_Node) loop
9926                Check_No_Identifier (Arg_Node);
9927
9928                --  Note that the analyze call done by Check_Arg_Is_Local_Name
9929                --  will in fact generate a reference, so that the entity will
9930                --  have a reference, which will inhibit any warnings about it
9931                --  not being referenced, and also properly show up in the ali
9932                --  file as a reference. But this reference is recorded before
9933                --  the Has_Pragma_Unreferenced flag is set, so that no warning
9934                --  is generated for this reference.
9935
9936                Check_Arg_Is_Local_Name (Arg_Node);
9937                Arg_Expr := Get_Pragma_Arg (Arg_Node);
9938
9939                if Is_Entity_Name (Arg_Expr) then
9940                   Arg_Ent := Entity (Arg_Expr);
9941
9942                   --  If the entity is overloaded, the pragma applies to the
9943                   --  most recent overloading, as documented. In this case,
9944                   --  name resolution does not generate a reference, so it
9945                   --  must be done here explicitly.
9946
9947                   if Is_Overloaded (Arg_Expr) then
9948                      Generate_Reference (Arg_Ent, N);
9949                   end if;
9950
9951                   Set_Has_Pragma_Unreferenced (Arg_Ent);
9952                end if;
9953
9954                Next (Arg_Node);
9955             end loop;
9956          end Unreferenced;
9957
9958          ------------------------------
9959          -- Unreserve_All_Interrupts --
9960          ------------------------------
9961
9962          --  pragma Unreserve_All_Interrupts;
9963
9964          when Pragma_Unreserve_All_Interrupts =>
9965             GNAT_Pragma;
9966             Check_Arg_Count (0);
9967
9968             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
9969                Unreserve_All_Interrupts := True;
9970             end if;
9971
9972          ----------------
9973          -- Unsuppress --
9974          ----------------
9975
9976          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
9977
9978          when Pragma_Unsuppress =>
9979             GNAT_Pragma;
9980             Process_Suppress_Unsuppress (False);
9981
9982          -------------------
9983          -- Use_VADS_Size --
9984          -------------------
9985
9986          --  pragma Use_VADS_Size;
9987
9988          when Pragma_Use_VADS_Size =>
9989             GNAT_Pragma;
9990             Check_Arg_Count (0);
9991             Check_Valid_Configuration_Pragma;
9992             Use_VADS_Size := True;
9993
9994          ---------------------
9995          -- Validity_Checks --
9996          ---------------------
9997
9998          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9999
10000          when Pragma_Validity_Checks => Validity_Checks : declare
10001             A  : constant Node_Id   := Expression (Arg1);
10002             S  : String_Id;
10003             C  : Char_Code;
10004
10005          begin
10006             GNAT_Pragma;
10007             Check_Arg_Count (1);
10008             Check_No_Identifiers;
10009
10010             if Nkind (A) = N_String_Literal then
10011                S   := Strval (A);
10012
10013                declare
10014                   Slen    : constant Natural := Natural (String_Length (S));
10015                   Options : String (1 .. Slen);
10016                   J       : Natural;
10017
10018                begin
10019                   J := 1;
10020                   loop
10021                      C := Get_String_Char (S, Int (J));
10022                      exit when not In_Character_Range (C);
10023                      Options (J) := Get_Character (C);
10024
10025                      if J = Slen then
10026                         Set_Validity_Check_Options (Options);
10027                         exit;
10028                      else
10029                         J := J + 1;
10030                      end if;
10031                   end loop;
10032                end;
10033
10034             elsif Nkind (A) = N_Identifier then
10035
10036                if Chars (A) = Name_All_Checks then
10037                   Set_Validity_Check_Options ("a");
10038
10039                elsif Chars (A) = Name_On then
10040                   Validity_Checks_On := True;
10041
10042                elsif Chars (A) = Name_Off then
10043                   Validity_Checks_On := False;
10044
10045                end if;
10046             end if;
10047          end Validity_Checks;
10048
10049          --------------
10050          -- Volatile --
10051          --------------
10052
10053          --  pragma Volatile (LOCAL_NAME);
10054
10055          when Pragma_Volatile =>
10056             Process_Atomic_Shared_Volatile;
10057
10058          -------------------------
10059          -- Volatile_Components --
10060          -------------------------
10061
10062          --  pragma Volatile_Components (array_LOCAL_NAME);
10063
10064          --  Volatile is handled by the same circuit as Atomic_Components
10065
10066          --------------
10067          -- Warnings --
10068          --------------
10069
10070          --  pragma Warnings (On | Off, [LOCAL_NAME])
10071
10072          when Pragma_Warnings => Warnings : begin
10073             GNAT_Pragma;
10074             Check_At_Least_N_Arguments (1);
10075             Check_At_Most_N_Arguments (2);
10076             Check_No_Identifiers;
10077
10078             --  One argument case was processed by parser in Par.Prag
10079
10080             if Arg_Count /= 1 then
10081                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10082                Check_Arg_Count (2);
10083
10084                declare
10085                   E_Id : Node_Id;
10086                   E    : Entity_Id;
10087
10088                begin
10089                   E_Id := Expression (Arg2);
10090                   Analyze (E_Id);
10091
10092                   --  In the expansion of an inlined body, a reference to
10093                   --  the formal may be wrapped in a conversion if the actual
10094                   --  is a conversion. Retrieve the real entity name.
10095
10096                   if (In_Instance_Body
10097                        or else In_Inlined_Body)
10098                     and then Nkind (E_Id) = N_Unchecked_Type_Conversion
10099                   then
10100                      E_Id := Expression (E_Id);
10101                   end if;
10102
10103                   if not Is_Entity_Name (E_Id) then
10104                      Error_Pragma_Arg
10105                        ("second argument of pragma% must be entity name",
10106                         Arg2);
10107                   end if;
10108
10109                   E := Entity (E_Id);
10110
10111                   if E = Any_Id then
10112                      return;
10113                   else
10114                      loop
10115                         Set_Warnings_Off (E,
10116                           (Chars (Expression (Arg1)) = Name_Off));
10117
10118                         if Is_Enumeration_Type (E) then
10119                            declare
10120                               Lit : Entity_Id := First_Literal (E);
10121
10122                            begin
10123                               while Present (Lit) loop
10124                                  Set_Warnings_Off (Lit);
10125                                  Next_Literal (Lit);
10126                               end loop;
10127                            end;
10128                         end if;
10129
10130                         exit when No (Homonym (E));
10131                         E := Homonym (E);
10132                      end loop;
10133                   end if;
10134                end;
10135             end if;
10136          end Warnings;
10137
10138          -------------------
10139          -- Weak_External --
10140          -------------------
10141
10142          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
10143
10144          when Pragma_Weak_External => Weak_External : declare
10145             Ent : Entity_Id;
10146
10147          begin
10148             GNAT_Pragma;
10149             Check_Arg_Count (1);
10150             Check_Optional_Identifier (Arg1, Name_Entity);
10151             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10152             Ent := Entity (Expression (Arg1));
10153
10154             if Rep_Item_Too_Early (Ent, N) then
10155                return;
10156             else
10157                Ent := Underlying_Type (Ent);
10158             end if;
10159
10160             --  The only processing required is to link this item on to the
10161             --  list of rep items for the given entity. This is accomplished
10162             --  by the call to Rep_Item_Too_Late (when no error is detected
10163             --  and False is returned).
10164
10165             if Rep_Item_Too_Late (Ent, N) then
10166                return;
10167             else
10168                Set_Has_Gigi_Rep_Item (Ent);
10169             end if;
10170          end Weak_External;
10171
10172          --------------------
10173          -- Unknown_Pragma --
10174          --------------------
10175
10176          --  Should be impossible, since the case of an unknown pragma is
10177          --  separately processed before the case statement is entered.
10178
10179          when Unknown_Pragma =>
10180             raise Program_Error;
10181       end case;
10182
10183    exception
10184       when Pragma_Exit => null;
10185    end Analyze_Pragma;
10186
10187    ---------------------------------
10188    -- Delay_Config_Pragma_Analyze --
10189    ---------------------------------
10190
10191    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
10192    begin
10193       return Chars (N) = Name_Interrupt_State;
10194    end Delay_Config_Pragma_Analyze;
10195
10196    -------------------------
10197    -- Get_Base_Subprogram --
10198    -------------------------
10199
10200    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
10201       Result : Entity_Id;
10202
10203    begin
10204       Result := Def_Id;
10205
10206       --  Follow subprogram renaming chain
10207
10208       while Is_Subprogram (Result)
10209         and then
10210           (Is_Generic_Instance (Result)
10211             or else Nkind (Parent (Declaration_Node (Result))) =
10212                     N_Subprogram_Renaming_Declaration)
10213         and then Present (Alias (Result))
10214       loop
10215          Result := Alias (Result);
10216       end loop;
10217
10218       return Result;
10219    end Get_Base_Subprogram;
10220
10221    -----------------------------
10222    -- Is_Config_Static_String --
10223    -----------------------------
10224
10225    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
10226
10227       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
10228       --  This is an internal recursive function that is just like the
10229       --  outer function except that it adds the string to the name buffer
10230       --  rather than placing the string in the name buffer.
10231
10232       ------------------------------
10233       -- Add_Config_Static_String --
10234       ------------------------------
10235
10236       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
10237          N : Node_Id;
10238          C : Char_Code;
10239
10240       begin
10241          N := Arg;
10242
10243          if Nkind (N) = N_Op_Concat then
10244             if Add_Config_Static_String (Left_Opnd (N)) then
10245                N := Right_Opnd (N);
10246             else
10247                return False;
10248             end if;
10249          end if;
10250
10251          if Nkind (N) /= N_String_Literal then
10252             Error_Msg_N ("string literal expected for pragma argument", N);
10253             return False;
10254
10255          else
10256             for J in 1 .. String_Length (Strval (N)) loop
10257                C := Get_String_Char (Strval (N), J);
10258
10259                if not In_Character_Range (C) then
10260                   Error_Msg
10261                     ("string literal contains invalid wide character",
10262                      Sloc (N) + 1 + Source_Ptr (J));
10263                   return False;
10264                end if;
10265
10266                Add_Char_To_Name_Buffer (Get_Character (C));
10267             end loop;
10268          end if;
10269
10270          return True;
10271       end Add_Config_Static_String;
10272
10273    --  Start of prorcessing for Is_Config_Static_String
10274
10275    begin
10276
10277       Name_Len := 0;
10278       return Add_Config_Static_String (Arg);
10279    end Is_Config_Static_String;
10280
10281    -----------------------------------------
10282    -- Is_Non_Significant_Pragma_Reference --
10283    -----------------------------------------
10284
10285    --  This function makes use of the following static table which indicates
10286    --  whether a given pragma is significant. A value of -1 in this table
10287    --  indicates that the reference is significant. A value of zero indicates
10288    --  than appearence as any argument is insignificant, a positive value
10289    --  indicates that appearence in that parameter position is significant.
10290
10291    Sig_Flags : constant array (Pragma_Id) of Int :=
10292
10293      (Pragma_AST_Entry                    => -1,
10294       Pragma_Abort_Defer                  => -1,
10295       Pragma_Ada_83                       => -1,
10296       Pragma_Ada_95                       => -1,
10297       Pragma_Ada_05                       => -1,
10298       Pragma_All_Calls_Remote             => -1,
10299       Pragma_Annotate                     => -1,
10300       Pragma_Assert                       => -1,
10301       Pragma_Asynchronous                 => -1,
10302       Pragma_Atomic                       =>  0,
10303       Pragma_Atomic_Components            =>  0,
10304       Pragma_Attach_Handler               => -1,
10305       Pragma_CPP_Class                    =>  0,
10306       Pragma_CPP_Constructor              =>  0,
10307       Pragma_CPP_Virtual                  =>  0,
10308       Pragma_CPP_Vtable                   =>  0,
10309       Pragma_C_Pass_By_Copy               =>  0,
10310       Pragma_Comment                      =>  0,
10311       Pragma_Common_Object                => -1,
10312       Pragma_Compile_Time_Warning         => -1,
10313       Pragma_Complex_Representation       =>  0,
10314       Pragma_Component_Alignment          => -1,
10315       Pragma_Controlled                   =>  0,
10316       Pragma_Convention                   =>  0,
10317       Pragma_Convention_Identifier        =>  0,
10318       Pragma_Debug                        => -1,
10319       Pragma_Detect_Blocking              => -1,
10320       Pragma_Discard_Names                =>  0,
10321       Pragma_Elaborate                    => -1,
10322       Pragma_Elaborate_All                => -1,
10323       Pragma_Elaborate_Body               => -1,
10324       Pragma_Elaboration_Checks           => -1,
10325       Pragma_Eliminate                    => -1,
10326       Pragma_Explicit_Overriding          => -1,
10327       Pragma_Export                       => -1,
10328       Pragma_Export_Exception             => -1,
10329       Pragma_Export_Function              => -1,
10330       Pragma_Export_Object                => -1,
10331       Pragma_Export_Procedure             => -1,
10332       Pragma_Export_Value                 => -1,
10333       Pragma_Export_Valued_Procedure      => -1,
10334       Pragma_Extend_System                => -1,
10335       Pragma_Extensions_Allowed           => -1,
10336       Pragma_External                     => -1,
10337       Pragma_External_Name_Casing         => -1,
10338       Pragma_Finalize_Storage_Only        =>  0,
10339       Pragma_Float_Representation         =>  0,
10340       Pragma_Ident                        => -1,
10341       Pragma_Import                       => +2,
10342       Pragma_Import_Exception             =>  0,
10343       Pragma_Import_Function              =>  0,
10344       Pragma_Import_Object                =>  0,
10345       Pragma_Import_Procedure             =>  0,
10346       Pragma_Import_Valued_Procedure      =>  0,
10347       Pragma_Initialize_Scalars           => -1,
10348       Pragma_Inline                       =>  0,
10349       Pragma_Inline_Always                =>  0,
10350       Pragma_Inline_Generic               =>  0,
10351       Pragma_Inspection_Point             => -1,
10352       Pragma_Interface                    => +2,
10353       Pragma_Interface_Name               => +2,
10354       Pragma_Interrupt_Handler            => -1,
10355       Pragma_Interrupt_Priority           => -1,
10356       Pragma_Interrupt_State              => -1,
10357       Pragma_Java_Constructor             => -1,
10358       Pragma_Java_Interface               => -1,
10359       Pragma_Keep_Names                   =>  0,
10360       Pragma_License                      => -1,
10361       Pragma_Link_With                    => -1,
10362       Pragma_Linker_Alias                 => -1,
10363       Pragma_Linker_Options               => -1,
10364       Pragma_Linker_Section               => -1,
10365       Pragma_List                         => -1,
10366       Pragma_Locking_Policy               => -1,
10367       Pragma_Long_Float                   => -1,
10368       Pragma_Machine_Attribute            => -1,
10369       Pragma_Main                         => -1,
10370       Pragma_Main_Storage                 => -1,
10371       Pragma_Memory_Size                  => -1,
10372       Pragma_No_Return                    =>  0,
10373       Pragma_No_Run_Time                  => -1,
10374       Pragma_No_Strict_Aliasing           => -1,
10375       Pragma_Normalize_Scalars            => -1,
10376       Pragma_Obsolescent                  =>  0,
10377       Pragma_Optimize                     => -1,
10378       Pragma_Optional_Overriding          => -1,
10379       Pragma_Overriding                   => -1,
10380       Pragma_Pack                         =>  0,
10381       Pragma_Page                         => -1,
10382       Pragma_Passive                      => -1,
10383       Pragma_Polling                      => -1,
10384       Pragma_Persistent_Data              => -1,
10385       Pragma_Persistent_Object            => -1,
10386       Pragma_Preelaborate                 => -1,
10387       Pragma_Priority                     => -1,
10388       Pragma_Profile                      =>  0,
10389       Pragma_Profile_Warnings             =>  0,
10390       Pragma_Propagate_Exceptions         => -1,
10391       Pragma_Psect_Object                 => -1,
10392       Pragma_Pure                         =>  0,
10393       Pragma_Pure_Function                =>  0,
10394       Pragma_Queuing_Policy               => -1,
10395       Pragma_Ravenscar                    => -1,
10396       Pragma_Remote_Call_Interface        => -1,
10397       Pragma_Remote_Types                 => -1,
10398       Pragma_Restricted_Run_Time          => -1,
10399       Pragma_Restriction_Warnings         => -1,
10400       Pragma_Restrictions                 => -1,
10401       Pragma_Reviewable                   => -1,
10402       Pragma_Share_Generic                => -1,
10403       Pragma_Shared                       => -1,
10404       Pragma_Shared_Passive               => -1,
10405       Pragma_Source_File_Name             => -1,
10406       Pragma_Source_File_Name_Project     => -1,
10407       Pragma_Source_Reference             => -1,
10408       Pragma_Storage_Size                 => -1,
10409       Pragma_Storage_Unit                 => -1,
10410       Pragma_Stream_Convert               => -1,
10411       Pragma_Style_Checks                 => -1,
10412       Pragma_Subtitle                     => -1,
10413       Pragma_Suppress                     =>  0,
10414       Pragma_Suppress_Exception_Locations =>  0,
10415       Pragma_Suppress_All                 => -1,
10416       Pragma_Suppress_Debug_Info          =>  0,
10417       Pragma_Suppress_Initialization      =>  0,
10418       Pragma_System_Name                  => -1,
10419       Pragma_Task_Dispatching_Policy      => -1,
10420       Pragma_Task_Info                    => -1,
10421       Pragma_Task_Name                    => -1,
10422       Pragma_Task_Storage                 =>  0,
10423       Pragma_Thread_Body                  => +2,
10424       Pragma_Time_Slice                   => -1,
10425       Pragma_Title                        => -1,
10426       Pragma_Unchecked_Union              =>  0,
10427       Pragma_Unimplemented_Unit           => -1,
10428       Pragma_Universal_Data               => -1,
10429       Pragma_Unreferenced                 => -1,
10430       Pragma_Unreserve_All_Interrupts     => -1,
10431       Pragma_Unsuppress                   =>  0,
10432       Pragma_Use_VADS_Size                => -1,
10433       Pragma_Validity_Checks              => -1,
10434       Pragma_Volatile                     =>  0,
10435       Pragma_Volatile_Components          =>  0,
10436       Pragma_Warnings                     => -1,
10437       Pragma_Weak_External                =>  0,
10438       Unknown_Pragma                      =>  0);
10439
10440    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
10441       P : Node_Id;
10442       C : Int;
10443       A : Node_Id;
10444
10445    begin
10446       P := Parent (N);
10447
10448       if Nkind (P) /= N_Pragma_Argument_Association then
10449          return False;
10450
10451       else
10452          C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
10453
10454          case C is
10455             when -1 =>
10456                return False;
10457
10458             when 0 =>
10459                return True;
10460
10461             when others =>
10462                A := First (Pragma_Argument_Associations (Parent (P)));
10463                for J in 1 .. C - 1 loop
10464                   if No (A) then
10465                      return False;
10466                   end if;
10467
10468                   Next (A);
10469                end loop;
10470
10471                return A = P;
10472          end case;
10473       end if;
10474    end Is_Non_Significant_Pragma_Reference;
10475
10476    ------------------------------
10477    -- Is_Pragma_String_Literal --
10478    ------------------------------
10479
10480    --  This function returns true if the corresponding pragma argument is
10481    --  a static string expression. These are the only cases in which string
10482    --  literals can appear as pragma arguments. We also allow a string
10483    --  literal as the first argument to pragma Assert (although it will
10484    --  of course always generate a type error).
10485
10486    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
10487       Pragn : constant Node_Id := Parent (Par);
10488       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
10489       Pname : constant Name_Id := Chars (Pragn);
10490       Argn  : Natural;
10491       N     : Node_Id;
10492
10493    begin
10494       Argn := 1;
10495       N := First (Assoc);
10496       loop
10497          exit when N = Par;
10498          Argn := Argn + 1;
10499          Next (N);
10500       end loop;
10501
10502       if Pname = Name_Assert then
10503          return True;
10504
10505       elsif Pname = Name_Export then
10506          return Argn > 2;
10507
10508       elsif Pname = Name_Ident then
10509          return Argn = 1;
10510
10511       elsif Pname = Name_Import then
10512          return Argn > 2;
10513
10514       elsif Pname = Name_Interface_Name then
10515          return Argn > 1;
10516
10517       elsif Pname = Name_Linker_Alias then
10518          return Argn = 2;
10519
10520       elsif Pname = Name_Linker_Section then
10521          return Argn = 2;
10522
10523       elsif Pname = Name_Machine_Attribute then
10524          return Argn = 2;
10525
10526       elsif Pname = Name_Source_File_Name then
10527          return True;
10528
10529       elsif Pname = Name_Source_Reference then
10530          return Argn = 2;
10531
10532       elsif Pname = Name_Title then
10533          return True;
10534
10535       elsif Pname = Name_Subtitle then
10536          return True;
10537
10538       else
10539          return False;
10540       end if;
10541    end Is_Pragma_String_Literal;
10542
10543    --------------------------------------
10544    -- Process_Compilation_Unit_Pragmas --
10545    --------------------------------------
10546
10547    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
10548    begin
10549       --  A special check for pragma Suppress_All. This is a strange DEC
10550       --  pragma, strange because it comes at the end of the unit. If we
10551       --  have a pragma Suppress_All in the Pragmas_After of the current
10552       --  unit, then we insert a pragma Suppress (All_Checks) at the start
10553       --  of the context clause to ensure the correct processing.
10554
10555       declare
10556          PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
10557          P  : Node_Id;
10558
10559       begin
10560          if Present (PA) then
10561             P := First (PA);
10562             while Present (P) loop
10563                if Chars (P) = Name_Suppress_All then
10564                   Prepend_To (Context_Items (N),
10565                     Make_Pragma (Sloc (P),
10566                       Chars => Name_Suppress,
10567                       Pragma_Argument_Associations => New_List (
10568                         Make_Pragma_Argument_Association (Sloc (P),
10569                           Expression =>
10570                             Make_Identifier (Sloc (P),
10571                               Chars => Name_All_Checks)))));
10572                   exit;
10573                end if;
10574
10575                Next (P);
10576             end loop;
10577          end if;
10578       end;
10579    end Process_Compilation_Unit_Pragmas;
10580
10581    --------------------------------
10582    -- Set_Encoded_Interface_Name --
10583    --------------------------------
10584
10585    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
10586       Str : constant String_Id := Strval (S);
10587       Len : constant Int       := String_Length (Str);
10588       CC  : Char_Code;
10589       C   : Character;
10590       J   : Int;
10591
10592       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
10593
10594       procedure Encode;
10595       --  Stores encoded value of character code CC. The encoding we
10596       --  use an underscore followed by four lower case hex digits.
10597
10598       ------------
10599       -- Encode --
10600       ------------
10601
10602       procedure Encode is
10603       begin
10604          Store_String_Char (Get_Char_Code ('_'));
10605          Store_String_Char
10606            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
10607          Store_String_Char
10608            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
10609          Store_String_Char
10610            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
10611          Store_String_Char
10612            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
10613       end Encode;
10614
10615    --  Start of processing for Set_Encoded_Interface_Name
10616
10617    begin
10618       --  If first character is asterisk, this is a link name, and we
10619       --  leave it completely unmodified. We also ignore null strings
10620       --  (the latter case happens only in error cases) and no encoding
10621       --  should occur for Java interface names.
10622
10623       if Len = 0
10624         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
10625         or else Java_VM
10626       then
10627          Set_Interface_Name (E, S);
10628
10629       else
10630          J := 1;
10631          loop
10632             CC := Get_String_Char (Str, J);
10633
10634             exit when not In_Character_Range (CC);
10635
10636             C := Get_Character (CC);
10637
10638             exit when C /= '_' and then C /= '$'
10639               and then C not in '0' .. '9'
10640               and then C not in 'a' .. 'z'
10641               and then C not in 'A' .. 'Z';
10642
10643             if J = Len then
10644                Set_Interface_Name (E, S);
10645                return;
10646
10647             else
10648                J := J + 1;
10649             end if;
10650          end loop;
10651
10652          --  Here we need to encode. The encoding we use as follows:
10653          --     three underscores  + four hex digits (lower case)
10654
10655          Start_String;
10656
10657          for J in 1 .. String_Length (Str) loop
10658             CC := Get_String_Char (Str, J);
10659
10660             if not In_Character_Range (CC) then
10661                Encode;
10662             else
10663                C := Get_Character (CC);
10664
10665                if C = '_' or else C = '$'
10666                  or else C in '0' .. '9'
10667                  or else C in 'a' .. 'z'
10668                  or else C in 'A' .. 'Z'
10669                then
10670                   Store_String_Char (CC);
10671                else
10672                   Encode;
10673                end if;
10674             end if;
10675          end loop;
10676
10677          Set_Interface_Name (E,
10678            Make_String_Literal (Sloc (S),
10679              Strval => End_String));
10680       end if;
10681    end Set_Encoded_Interface_Name;
10682
10683    -------------------
10684    -- Set_Unit_Name --
10685    -------------------
10686
10687    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
10688       Pref : Node_Id;
10689       Scop : Entity_Id;
10690
10691    begin
10692       if Nkind (N) = N_Identifier
10693         and then Nkind (With_Item) = N_Identifier
10694       then
10695          Set_Entity (N, Entity (With_Item));
10696
10697       elsif Nkind (N) = N_Selected_Component then
10698          Change_Selected_Component_To_Expanded_Name (N);
10699          Set_Entity (N, Entity (With_Item));
10700          Set_Entity (Selector_Name (N), Entity (N));
10701
10702          Pref := Prefix (N);
10703          Scop := Scope (Entity (N));
10704          while Nkind (Pref) = N_Selected_Component loop
10705             Change_Selected_Component_To_Expanded_Name (Pref);
10706             Set_Entity (Selector_Name (Pref), Scop);
10707             Set_Entity (Pref, Scop);
10708             Pref := Prefix (Pref);
10709             Scop := Scope (Scop);
10710          end loop;
10711
10712          Set_Entity (Pref, Scop);
10713       end if;
10714    end Set_Unit_Name;
10715 end Sem_Prag;