OSDN Git Service

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