OSDN Git Service

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