OSDN Git Service

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