OSDN Git Service

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