OSDN Git Service

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