OSDN Git Service

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