OSDN Git Service

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