OSDN Git Service

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