OSDN Git Service

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