OSDN Git Service

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