OSDN Git Service

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