OSDN Git Service

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