OSDN Git Service

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