OSDN Git Service

2010-10-08 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ P R A G                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2010, 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 3,  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 COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 --  This unit contains the semantic processing for all pragmas, both language
27 --  and implementation defined. For most pragmas, the parser only does the
28 --  most basic job of checking the syntax, so Sem_Prag also contains the code
29 --  to complete the syntax checks. Certain pragmas are handled partially or
30 --  completely by the parser (see Par.Prag for further details).
31
32 with Atree;    use Atree;
33 with Casing;   use Casing;
34 with Checks;   use Checks;
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 Exp_Ch7;  use Exp_Ch7;
41 with Exp_Dist; use Exp_Dist;
42 with Lib;      use Lib;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists;   use Nlists;
47 with Nmake;    use Nmake;
48 with Opt;      use Opt;
49 with Output;   use Output;
50 with Par_SCO;  use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident;   use Rident;
53 with Rtsfind;  use Rtsfind;
54 with Sem;      use Sem;
55 with Sem_Aux;  use Sem_Aux;
56 with Sem_Ch3;  use Sem_Ch3;
57 with Sem_Ch6;  use Sem_Ch6;
58 with Sem_Ch8;  use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Dist; use Sem_Dist;
62 with Sem_Elim; use Sem_Elim;
63 with Sem_Eval; use Sem_Eval;
64 with Sem_Intr; use Sem_Intr;
65 with Sem_Mech; use Sem_Mech;
66 with Sem_Res;  use Sem_Res;
67 with Sem_Type; use Sem_Type;
68 with Sem_Util; use Sem_Util;
69 with Sem_VFpt; use Sem_VFpt;
70 with Sem_Warn; use Sem_Warn;
71 with Stand;    use Stand;
72 with Sinfo;    use Sinfo;
73 with Sinfo.CN; use Sinfo.CN;
74 with Sinput;   use Sinput;
75 with Snames;   use Snames;
76 with Stringt;  use Stringt;
77 with Stylesw;  use Stylesw;
78 with Table;
79 with Targparm; use Targparm;
80 with Tbuild;   use Tbuild;
81 with Ttypes;
82 with Uintp;    use Uintp;
83 with Uname;    use Uname;
84 with Urealp;   use Urealp;
85 with Validsw;  use Validsw;
86
87 package body Sem_Prag is
88
89    ----------------------------------------------
90    -- Common Handling of Import-Export Pragmas --
91    ----------------------------------------------
92
93    --  In the following section, a number of Import_xxx and Export_xxx
94    --  pragmas are defined by GNAT. These are compatible with the DEC
95    --  pragmas of the same name, and all have the following common
96    --  form and processing:
97
98    --  pragma Export_xxx
99    --        [Internal                 =>] LOCAL_NAME
100    --     [, [External                 =>] EXTERNAL_SYMBOL]
101    --     [, other optional parameters   ]);
102
103    --  pragma Import_xxx
104    --        [Internal                 =>] LOCAL_NAME
105    --     [, [External                 =>] EXTERNAL_SYMBOL]
106    --     [, other optional parameters   ]);
107
108    --   EXTERNAL_SYMBOL ::=
109    --     IDENTIFIER
110    --   | static_string_EXPRESSION
111
112    --  The internal LOCAL_NAME designates the entity that is imported or
113    --  exported, and must refer to an entity in the current declarative
114    --  part (as required by the rules for LOCAL_NAME).
115
116    --  The external linker name is designated by the External parameter if
117    --  given, or the Internal parameter if not (if there is no External
118    --  parameter, the External parameter is a copy of the Internal name).
119
120    --  If the External parameter is given as a string, then this string is
121    --  treated as an external name (exactly as though it had been given as an
122    --  External_Name parameter for a normal Import pragma).
123
124    --  If the External parameter is given as an identifier (or there is no
125    --  External parameter, so that the Internal identifier is used), then
126    --  the external name is the characters of the identifier, translated
127    --  to all upper case letters for OpenVMS versions of GNAT, and to all
128    --  lower case letters for all other versions
129
130    --  Note: the external name specified or implied by any of these special
131    --  Import_xxx or Export_xxx pragmas override an external or link name
132    --  specified in a previous Import or Export pragma.
133
134    --  Note: these and all other DEC-compatible GNAT pragmas allow full use of
135    --  named notation, following the standard rules for subprogram calls, i.e.
136    --  parameters can be given in any order if named notation is used, and
137    --  positional and named notation can be mixed, subject to the rule that all
138    --  positional parameters must appear first.
139
140    --  Note: All these pragmas are implemented exactly following the DEC design
141    --  and implementation and are intended to be fully compatible with the use
142    --  of these pragmas in the DEC Ada compiler.
143
144    --------------------------------------------
145    -- Checking for Duplicated External Names --
146    --------------------------------------------
147
148    --  It is suspicious if two separate Export pragmas use the same external
149    --  name. The following table is used to diagnose this situation so that
150    --  an appropriate warning can be issued.
151
152    --  The Node_Id stored is for the N_String_Literal node created to hold
153    --  the value of the external name. The Sloc of this node is used to
154    --  cross-reference the location of the duplication.
155
156    package Externals is new Table.Table (
157      Table_Component_Type => Node_Id,
158      Table_Index_Type     => Int,
159      Table_Low_Bound      => 0,
160      Table_Initial        => 100,
161      Table_Increment      => 100,
162      Table_Name           => "Name_Externals");
163
164    -------------------------------------
165    -- Local Subprograms and Variables --
166    -------------------------------------
167
168    function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
169    --  This routine is used for possible casing adjustment of an explicit
170    --  external name supplied as a string literal (the node N), according to
171    --  the casing requirement of Opt.External_Name_Casing. If this is set to
172    --  As_Is, then the string literal is returned unchanged, but if it is set
173    --  to Uppercase or Lowercase, then a new string literal with appropriate
174    --  casing is constructed.
175
176    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
177    --  If Def_Id refers to a renamed subprogram, then the base subprogram (the
178    --  original one, following the renaming chain) is returned. Otherwise the
179    --  entity is returned unchanged. Should be in Einfo???
180
181    function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
182    --  All the routines that check pragma arguments take either a pragma
183    --  argument association (in which case the expression of the argument
184    --  association is checked), or the expression directly. The function
185    --  Get_Pragma_Arg is a utility used to deal with these two cases. If Arg
186    --  is a pragma argument association node, then its expression is returned,
187    --  otherwise Arg is returned unchanged.
188
189    procedure rv;
190    --  This is a dummy function called by the processing for pragma Reviewable.
191    --  It is there for assisting front end debugging. By placing a Reviewable
192    --  pragma in the source program, a breakpoint on rv catches this place in
193    --  the source, allowing convenient stepping to the point of interest.
194
195    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196    --  Place semantic information on the argument of an Elaborate/Elaborate_All
197    --  pragma. Entity name for unit and its parents is taken from item in
198    --  previous with_clause that mentions the unit.
199
200    -------------------------------
201    -- Adjust_External_Name_Case --
202    -------------------------------
203
204    function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
205       CC : Char_Code;
206
207    begin
208       --  Adjust case of literal if required
209
210       if Opt.External_Name_Exp_Casing = As_Is then
211          return N;
212
213       else
214          --  Copy existing string
215
216          Start_String;
217
218          --  Set proper casing
219
220          for J in 1 .. String_Length (Strval (N)) loop
221             CC := Get_String_Char (Strval (N), J);
222
223             if Opt.External_Name_Exp_Casing = Uppercase
224               and then CC >= Get_Char_Code ('a')
225               and then CC <= Get_Char_Code ('z')
226             then
227                Store_String_Char (CC - 32);
228
229             elsif Opt.External_Name_Exp_Casing = Lowercase
230               and then CC >= Get_Char_Code ('A')
231               and then CC <= Get_Char_Code ('Z')
232             then
233                Store_String_Char (CC + 32);
234
235             else
236                Store_String_Char (CC);
237             end if;
238          end loop;
239
240          return
241            Make_String_Literal (Sloc (N),
242              Strval => End_String);
243       end if;
244    end Adjust_External_Name_Case;
245
246    ------------------------------
247    -- Analyze_PPC_In_Decl_Part --
248    ------------------------------
249
250    procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251       Arg1 : constant Node_Id :=
252                First (Pragma_Argument_Associations (N));
253       Arg2 : constant Node_Id := Next (Arg1);
254
255    begin
256       --  Install formals and push subprogram spec onto scope stack so that we
257       --  can see the formals from the pragma.
258
259       Install_Formals (S);
260       Push_Scope (S);
261
262       --  Preanalyze the boolean expression, we treat this as a spec expression
263       --  (i.e. similar to a default expression).
264
265       Preanalyze_Spec_Expression
266         (Get_Pragma_Arg (Arg1), Standard_Boolean);
267
268       --  If there is a message argument, analyze it the same way
269
270       if Present (Arg2) then
271          Preanalyze_Spec_Expression
272            (Get_Pragma_Arg (Arg2), Standard_String);
273       end if;
274
275       --  Remove the subprogram from the scope stack now that the pre-analysis
276       --  of the precondition/postcondition is done.
277
278       End_Scope;
279    end Analyze_PPC_In_Decl_Part;
280
281    --------------------
282    -- Analyze_Pragma --
283    --------------------
284
285    procedure Analyze_Pragma (N : Node_Id) is
286       Loc     : constant Source_Ptr := Sloc (N);
287       Pname   : constant Name_Id    := Pragma_Name (N);
288       Prag_Id : Pragma_Id;
289
290       Pragma_Exit : exception;
291       --  This exception is used to exit pragma processing completely. It is
292       --  used when an error is detected, and no further processing is
293       --  required. It is also used if an earlier error has left the tree in
294       --  a state where the pragma should not be processed.
295
296       Arg_Count : Nat;
297       --  Number of pragma argument associations
298
299       Arg1 : Node_Id;
300       Arg2 : Node_Id;
301       Arg3 : Node_Id;
302       Arg4 : Node_Id;
303       --  First four pragma arguments (pragma argument association nodes, or
304       --  Empty if the corresponding argument does not exist).
305
306       type Name_List is array (Natural range <>) of Name_Id;
307       type Args_List is array (Natural range <>) of Node_Id;
308       --  Types used for arguments to Check_Arg_Order and Gather_Associations
309
310       procedure Ada_2005_Pragma;
311       --  Called for pragmas defined in Ada 2005, that are not in Ada 95. In
312       --  Ada 95 mode, these are implementation defined pragmas, so should be
313       --  caught by the No_Implementation_Pragmas restriction.
314
315       procedure Ada_2012_Pragma;
316       --  Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
317       --  In Ada 95 or 05 mode, these are implementation defined pragmas, so
318       --  should be caught by the No_Implementation_Pragmas restriction.
319
320       procedure Check_Ada_83_Warning;
321       --  Issues a warning message for the current pragma if operating in Ada
322       --  83 mode (used for language pragmas that are not a standard part of
323       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
324       --  of 95 pragma.
325
326       procedure Check_Arg_Count (Required : Nat);
327       --  Check argument count for pragma is equal to given parameter. If not,
328       --  then issue an error message and raise Pragma_Exit.
329
330       --  Note: all routines whose name is Check_Arg_Is_xxx take an argument
331       --  Arg which can either be a pragma argument association, in which case
332       --  the check is applied to the expression of the association or an
333       --  expression directly.
334
335       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
336       --  Check that an argument has the right form for an EXTERNAL_NAME
337       --  parameter of an extended import/export pragma. The rule is that the
338       --  name must be an identifier or string literal (in Ada 83 mode) or a
339       --  static string expression (in Ada 95 mode).
340
341       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
342       --  Check the specified argument Arg to make sure that it is an
343       --  identifier. If not give error and raise Pragma_Exit.
344
345       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
346       --  Check the specified argument Arg to make sure that it is an integer
347       --  literal. If not give error and raise Pragma_Exit.
348
349       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
350       --  Check the specified argument Arg to make sure that it has the proper
351       --  syntactic form for a local name and meets the semantic requirements
352       --  for a local name. The local name is analyzed as part of the
353       --  processing for this call. In addition, the local name is required
354       --  to represent an entity at the library level.
355
356       procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
357       --  Check the specified argument Arg to make sure that it has the proper
358       --  syntactic form for a local name and meets the semantic requirements
359       --  for a local name. The local name is analyzed as part of the
360       --  processing for this call.
361
362       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
363       --  Check the specified argument Arg to make sure that it is a valid
364       --  locking policy name. If not give error and raise Pragma_Exit.
365
366       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
367       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
368       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
369       --  Check the specified argument Arg to make sure that it is an
370       --  identifier whose name matches either N1 or N2 (or N3 if present).
371       --  If not then give error and raise Pragma_Exit.
372
373       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
374       --  Check the specified argument Arg to make sure that it is a valid
375       --  queuing policy name. If not give error and raise Pragma_Exit.
376
377       procedure Check_Arg_Is_Static_Expression
378         (Arg : Node_Id;
379          Typ : Entity_Id := Empty);
380       --  Check the specified argument Arg to make sure that it is a static
381       --  expression of the given type (i.e. it will be analyzed and resolved
382       --  using this type, which can be any valid argument to Resolve, e.g.
383       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
384       --  Typ is left Empty, then any static expression is allowed.
385
386       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
387       --  Check the specified argument Arg to make sure that it is a valid task
388       --  dispatching policy name. If not give error and raise Pragma_Exit.
389
390       procedure Check_Arg_Order (Names : Name_List);
391       --  Checks for an instance of two arguments with identifiers for the
392       --  current pragma which are not in the sequence indicated by Names,
393       --  and if so, generates a fatal message about bad order of arguments.
394
395       procedure Check_At_Least_N_Arguments (N : Nat);
396       --  Check there are at least N arguments present
397
398       procedure Check_At_Most_N_Arguments (N : Nat);
399       --  Check there are no more than N arguments present
400
401       procedure Check_Component
402         (Comp            : Node_Id;
403          UU_Typ          : Entity_Id;
404          In_Variant_Part : Boolean := False);
405       --  Examine an Unchecked_Union component for correct use of per-object
406       --  constrained subtypes, and for restrictions on finalizable components.
407       --  UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
408       --  should be set when Comp comes from a record variant.
409
410       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
411       --  Nam is an N_String_Literal node containing the external name set by
412       --  an Import or Export pragma (or extended Import or Export pragma).
413       --  This procedure checks for possible duplications if this is the export
414       --  case, and if found, issues an appropriate error message.
415
416       procedure Check_First_Subtype (Arg : Node_Id);
417       --  Checks that Arg, whose expression is an entity name referencing a
418       --  subtype, does not reference a type that is not a first subtype.
419
420       procedure Check_In_Main_Program;
421       --  Common checks for pragmas that appear within a main program
422       --  (Priority, Main_Storage, Time_Slice, Relative_Deadline).
423
424       procedure Check_Interrupt_Or_Attach_Handler;
425       --  Common processing for first argument of pragma Interrupt_Handler or
426       --  pragma Attach_Handler.
427
428       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
429       --  Check that pragma appears in a declarative part, or in a package
430       --  specification, i.e. that it does not occur in a statement sequence
431       --  in a body.
432
433       procedure Check_No_Identifier (Arg : Node_Id);
434       --  Checks that the given argument does not have an identifier. If
435       --  an identifier is present, then an error message is issued, and
436       --  Pragma_Exit is raised.
437
438       procedure Check_No_Identifiers;
439       --  Checks that none of the arguments to the pragma has an identifier.
440       --  If any argument has an identifier, then an error message is issued,
441       --  and Pragma_Exit is raised.
442
443       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
444       --  Checks if the given argument has an identifier, and if so, requires
445       --  it to match the given identifier name. If there is a non-matching
446       --  identifier, then an error message is given and Error_Pragmas raised.
447
448       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
449       --  Checks if the given argument has an identifier, and if so, requires
450       --  it to match the given identifier name. If there is a non-matching
451       --  identifier, then an error message is given and Error_Pragmas raised.
452       --  In this version of the procedure, the identifier name is given as
453       --  a string with lower case letters.
454
455       procedure Check_Precondition_Postcondition (In_Body : out Boolean);
456       --  Called to process a precondition or postcondition pragma. There are
457       --  three cases:
458       --
459       --    The pragma appears after a subprogram spec
460       --
461       --      If the corresponding check is not enabled, the pragma is analyzed
462       --      but otherwise ignored and control returns with In_Body set False.
463       --
464       --      If the check is enabled, then the first step is to analyze the
465       --      pragma, but this is skipped if the subprogram spec appears within
466       --      a package specification (because this is the case where we delay
467       --      analysis till the end of the spec). Then (whether or not it was
468       --      analyzed), the pragma is chained to the subprogram in question
469       --      (using Spec_PPC_List and Next_Pragma) and control returns to the
470       --      caller with In_Body set False.
471       --
472       --    The pragma appears at the start of subprogram body declarations
473       --
474       --      In this case an immediate return to the caller is made with
475       --      In_Body set True, and the pragma is NOT analyzed.
476       --
477       --    In all other cases, an error message for bad placement is given
478
479       procedure Check_Static_Constraint (Constr : Node_Id);
480       --  Constr is a constraint from an N_Subtype_Indication node from a
481       --  component constraint in an Unchecked_Union type. This routine checks
482       --  that the constraint is static as required by the restrictions for
483       --  Unchecked_Union.
484
485       procedure Check_Valid_Configuration_Pragma;
486       --  Legality checks for placement of a configuration pragma
487
488       procedure Check_Valid_Library_Unit_Pragma;
489       --  Legality checks for library unit pragmas. A special case arises for
490       --  pragmas in generic instances that come from copies of the original
491       --  library unit pragmas in the generic templates. In the case of other
492       --  than library level instantiations these can appear in contexts which
493       --  would normally be invalid (they only apply to the original template
494       --  and to library level instantiations), and they are simply ignored,
495       --  which is implemented by rewriting them as null statements.
496
497       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
498       --  Check an Unchecked_Union variant for lack of nested variants and
499       --  presence of at least one component. UU_Typ is the related Unchecked_
500       --  Union type.
501
502       procedure Error_Pragma (Msg : String);
503       pragma No_Return (Error_Pragma);
504       --  Outputs error message for current pragma. The message contains a %
505       --  that will be replaced with the pragma name, and the flag is placed
506       --  on the pragma itself. Pragma_Exit is then raised.
507
508       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
509       pragma No_Return (Error_Pragma_Arg);
510       --  Outputs error message for current pragma. The message may contain
511       --  a % that will be replaced with the pragma name. The parameter Arg
512       --  may either be a pragma argument association, in which case the flag
513       --  is placed on the expression of this association, or an expression,
514       --  in which case the flag is placed directly on the expression. The
515       --  message is placed using Error_Msg_N, so the message may also contain
516       --  an & insertion character which will reference the given Arg value.
517       --  After placing the message, Pragma_Exit is raised.
518
519       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
520       pragma No_Return (Error_Pragma_Arg);
521       --  Similar to above form of Error_Pragma_Arg except that two messages
522       --  are provided, the second is a continuation comment starting with \.
523
524       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
525       pragma No_Return (Error_Pragma_Arg_Ident);
526       --  Outputs error message for current pragma. The message may contain
527       --  a % that will be replaced with the pragma name. The parameter Arg
528       --  must be a pragma argument association with a non-empty identifier
529       --  (i.e. its Chars field must be set), and the error message is placed
530       --  on the identifier. The message is placed using Error_Msg_N so
531       --  the message may also contain an & insertion character which will
532       --  reference the identifier. After placing the message, Pragma_Exit
533       --  is raised.
534
535       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
536       pragma No_Return (Error_Pragma_Ref);
537       --  Outputs error message for current pragma. The message may contain
538       --  a % that will be replaced with the pragma name. The parameter Ref
539       --  must be an entity whose name can be referenced by & and sloc by #.
540       --  After placing the message, Pragma_Exit is raised.
541
542       function Find_Lib_Unit_Name return Entity_Id;
543       --  Used for a library unit pragma to find the entity to which the
544       --  library unit pragma applies, returns the entity found.
545
546       procedure Find_Program_Unit_Name (Id : Node_Id);
547       --  If the pragma is a compilation unit pragma, the id must denote the
548       --  compilation unit in the same compilation, and the pragma must appear
549       --  in the list of preceding or trailing pragmas. If it is a program
550       --  unit pragma that is not a compilation unit pragma, then the
551       --  identifier must be visible.
552
553       function Find_Unique_Parameterless_Procedure
554         (Name : Entity_Id;
555          Arg  : Node_Id) return Entity_Id;
556       --  Used for a procedure pragma to find the unique parameterless
557       --  procedure identified by Name, returns it if it exists, otherwise
558       --  errors out and uses Arg as the pragma argument for the message.
559
560       procedure Gather_Associations
561         (Names : Name_List;
562          Args  : out Args_List);
563       --  This procedure is used to gather the arguments for a pragma that
564       --  permits arbitrary ordering of parameters using the normal rules
565       --  for named and positional parameters. The Names argument is a list
566       --  of Name_Id values that corresponds to the allowed pragma argument
567       --  association identifiers in order. The result returned in Args is
568       --  a list of corresponding expressions that are the pragma arguments.
569       --  Note that this is a list of expressions, not of pragma argument
570       --  associations (Gather_Associations has completely checked all the
571       --  optional identifiers when it returns). An entry in Args is Empty
572       --  on return if the corresponding argument is not present.
573
574       procedure GNAT_Pragma;
575       --  Called for all GNAT defined pragmas to check the relevant restriction
576       --  (No_Implementation_Pragmas).
577
578       function Is_Before_First_Decl
579         (Pragma_Node : Node_Id;
580          Decls       : List_Id) return Boolean;
581       --  Return True if Pragma_Node is before the first declarative item in
582       --  Decls where Decls is the list of declarative items.
583
584       function Is_Configuration_Pragma return Boolean;
585       --  Determines if the placement of the current pragma is appropriate
586       --  for a configuration pragma.
587
588       function Is_In_Context_Clause return Boolean;
589       --  Returns True if pragma appears within the context clause of a unit,
590       --  and False for any other placement (does not generate any messages).
591
592       function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
593       --  Analyzes the argument, and determines if it is a static string
594       --  expression, returns True if so, False if non-static or not String.
595
596       procedure Pragma_Misplaced;
597       pragma No_Return (Pragma_Misplaced);
598       --  Issue fatal error message for misplaced pragma
599
600       procedure Process_Atomic_Shared_Volatile;
601       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
602       --  Shared is an obsolete Ada 83 pragma, treated as being identical
603       --  in effect to pragma Atomic.
604
605       procedure Process_Compile_Time_Warning_Or_Error;
606       --  Common processing for Compile_Time_Error and Compile_Time_Warning
607
608       procedure Process_Convention
609         (C   : out Convention_Id;
610          Ent : out Entity_Id);
611       --  Common processing for Convention, Interface, Import and Export.
612       --  Checks first two arguments of pragma, and sets the appropriate
613       --  convention value in the specified entity or entities. On return
614       --  C is the convention, Ent is the referenced entity.
615
616       procedure Process_Extended_Import_Export_Exception_Pragma
617         (Arg_Internal : Node_Id;
618          Arg_External : Node_Id;
619          Arg_Form     : Node_Id;
620          Arg_Code     : Node_Id);
621       --  Common processing for the pragmas Import/Export_Exception. The three
622       --  arguments correspond to the three named parameters of the pragma. An
623       --  argument is empty if the corresponding parameter is not present in
624       --  the pragma.
625
626       procedure Process_Extended_Import_Export_Object_Pragma
627         (Arg_Internal : Node_Id;
628          Arg_External : Node_Id;
629          Arg_Size     : Node_Id);
630       --  Common processing for the pragmas Import/Export_Object. The three
631       --  arguments correspond to the three named parameters of the pragmas. An
632       --  argument is empty if the corresponding parameter is not present in
633       --  the pragma.
634
635       procedure Process_Extended_Import_Export_Internal_Arg
636         (Arg_Internal : Node_Id := Empty);
637       --  Common processing for all extended Import and Export pragmas. The
638       --  argument is the pragma parameter for the Internal argument. If
639       --  Arg_Internal is empty or inappropriate, an error message is posted.
640       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
641       --  set to identify the referenced entity.
642
643       procedure Process_Extended_Import_Export_Subprogram_Pragma
644         (Arg_Internal                 : Node_Id;
645          Arg_External                 : Node_Id;
646          Arg_Parameter_Types          : Node_Id;
647          Arg_Result_Type              : Node_Id := Empty;
648          Arg_Mechanism                : Node_Id;
649          Arg_Result_Mechanism         : Node_Id := Empty;
650          Arg_First_Optional_Parameter : Node_Id := Empty);
651       --  Common processing for all extended Import and Export pragmas applying
652       --  to subprograms. The caller omits any arguments that do not apply to
653       --  the pragma in question (for example, Arg_Result_Type can be non-Empty
654       --  only in the Import_Function and Export_Function cases). The argument
655       --  names correspond to the allowed pragma association identifiers.
656
657       procedure Process_Generic_List;
658       --  Common processing for Share_Generic and Inline_Generic
659
660       procedure Process_Import_Or_Interface;
661       --  Common processing for Import of Interface
662
663       procedure Process_Inline (Active : Boolean);
664       --  Common processing for Inline and Inline_Always. The parameter
665       --  indicates if the inline pragma is active, i.e. if it should actually
666       --  cause inlining to occur.
667
668       procedure Process_Interface_Name
669         (Subprogram_Def : Entity_Id;
670          Ext_Arg        : Node_Id;
671          Link_Arg       : Node_Id);
672       --  Given the last two arguments of pragma Import, pragma Export, or
673       --  pragma Interface_Name, performs validity checks and sets the
674       --  Interface_Name field of the given subprogram entity to the
675       --  appropriate external or link name, depending on the arguments given.
676       --  Ext_Arg is always present, but Link_Arg may be missing. Note that
677       --  Ext_Arg may represent the Link_Name if Link_Arg is missing, and
678       --  appropriate named notation is used for Ext_Arg. If neither Ext_Arg
679       --  nor Link_Arg is present, the interface name is set to the default
680       --  from the subprogram name.
681
682       procedure Process_Interrupt_Or_Attach_Handler;
683       --  Common processing for Interrupt and Attach_Handler pragmas
684
685       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
686       --  Common processing for Restrictions and Restriction_Warnings pragmas.
687       --  Warn is True for Restriction_Warnings, or for Restrictions if the
688       --  flag Treat_Restrictions_As_Warnings is set, and False if this flag
689       --  is not set in the Restrictions case.
690
691       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
692       --  Common processing for Suppress and Unsuppress. The boolean parameter
693       --  Suppress_Case is True for the Suppress case, and False for the
694       --  Unsuppress case.
695
696       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
697       --  This procedure sets the Is_Exported flag for the given entity,
698       --  checking that the entity was not previously imported. Arg is
699       --  the argument that specified the entity. A check is also made
700       --  for exporting inappropriate entities.
701
702       procedure Set_Extended_Import_Export_External_Name
703         (Internal_Ent : Entity_Id;
704          Arg_External : Node_Id);
705       --  Common processing for all extended import export pragmas. The first
706       --  argument, Internal_Ent, is the internal entity, which has already
707       --  been checked for validity by the caller. Arg_External is from the
708       --  Import or Export pragma, and may be null if no External parameter
709       --  was present. If Arg_External is present and is a non-null string
710       --  (a null string is treated as the default), then the Interface_Name
711       --  field of Internal_Ent is set appropriately.
712
713       procedure Set_Imported (E : Entity_Id);
714       --  This procedure sets the Is_Imported flag for the given entity,
715       --  checking that it is not previously exported or imported.
716
717       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
718       --  Mech is a parameter passing mechanism (see Import_Function syntax
719       --  for MECHANISM_NAME). This routine checks that the mechanism argument
720       --  has the right form, and if not issues an error message. If the
721       --  argument has the right form then the Mechanism field of Ent is
722       --  set appropriately.
723
724       procedure Set_Ravenscar_Profile (N : Node_Id);
725       --  Activate the set of configuration pragmas and restrictions that make
726       --  up the Ravenscar Profile. N is the corresponding pragma node, which
727       --  is used for error messages on any constructs that violate the
728       --  profile.
729
730       ---------------------
731       -- Ada_2005_Pragma --
732       ---------------------
733
734       procedure Ada_2005_Pragma is
735       begin
736          if Ada_Version <= Ada_95 then
737             Check_Restriction (No_Implementation_Pragmas, N);
738          end if;
739       end Ada_2005_Pragma;
740
741       ---------------------
742       -- Ada_2012_Pragma --
743       ---------------------
744
745       procedure Ada_2012_Pragma is
746       begin
747          if Ada_Version <= Ada_05 then
748             Check_Restriction (No_Implementation_Pragmas, N);
749          end if;
750       end Ada_2012_Pragma;
751
752       --------------------------
753       -- Check_Ada_83_Warning --
754       --------------------------
755
756       procedure Check_Ada_83_Warning is
757       begin
758          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
759             Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
760          end if;
761       end Check_Ada_83_Warning;
762
763       ---------------------
764       -- Check_Arg_Count --
765       ---------------------
766
767       procedure Check_Arg_Count (Required : Nat) is
768       begin
769          if Arg_Count /= Required then
770             Error_Pragma ("wrong number of arguments for pragma%");
771          end if;
772       end Check_Arg_Count;
773
774       --------------------------------
775       -- Check_Arg_Is_External_Name --
776       --------------------------------
777
778       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
779          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
780
781       begin
782          if Nkind (Argx) = N_Identifier then
783             return;
784
785          else
786             Analyze_And_Resolve (Argx, Standard_String);
787
788             if Is_OK_Static_Expression (Argx) then
789                return;
790
791             elsif Etype (Argx) = Any_Type then
792                raise Pragma_Exit;
793
794             --  An interesting special case, if we have a string literal and
795             --  we are in Ada 83 mode, then we allow it even though it will
796             --  not be flagged as static. This allows expected Ada 83 mode
797             --  use of external names which are string literals, even though
798             --  technically these are not static in Ada 83.
799
800             elsif Ada_Version = Ada_83
801               and then Nkind (Argx) = N_String_Literal
802             then
803                return;
804
805             --  Static expression that raises Constraint_Error. This has
806             --  already been flagged, so just exit from pragma processing.
807
808             elsif Is_Static_Expression (Argx) then
809                raise Pragma_Exit;
810
811             --  Here we have a real error (non-static expression)
812
813             else
814                Error_Msg_Name_1 := Pname;
815                Flag_Non_Static_Expr
816                  ("argument for pragma% must be a identifier or " &
817                   "static string expression!", Argx);
818                raise Pragma_Exit;
819             end if;
820          end if;
821       end Check_Arg_Is_External_Name;
822
823       -----------------------------
824       -- Check_Arg_Is_Identifier --
825       -----------------------------
826
827       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
828          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
829       begin
830          if Nkind (Argx) /= N_Identifier then
831             Error_Pragma_Arg
832               ("argument for pragma% must be identifier", Argx);
833          end if;
834       end Check_Arg_Is_Identifier;
835
836       ----------------------------------
837       -- Check_Arg_Is_Integer_Literal --
838       ----------------------------------
839
840       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
841          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
842       begin
843          if Nkind (Argx) /= N_Integer_Literal then
844             Error_Pragma_Arg
845               ("argument for pragma% must be integer literal", Argx);
846          end if;
847       end Check_Arg_Is_Integer_Literal;
848
849       -------------------------------------------
850       -- Check_Arg_Is_Library_Level_Local_Name --
851       -------------------------------------------
852
853       --  LOCAL_NAME ::=
854       --    DIRECT_NAME
855       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
856       --  | library_unit_NAME
857
858       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
859       begin
860          Check_Arg_Is_Local_Name (Arg);
861
862          if not Is_Library_Level_Entity (Entity (Expression (Arg)))
863            and then Comes_From_Source (N)
864          then
865             Error_Pragma_Arg
866               ("argument for pragma% must be library level entity", Arg);
867          end if;
868       end Check_Arg_Is_Library_Level_Local_Name;
869
870       -----------------------------
871       -- Check_Arg_Is_Local_Name --
872       -----------------------------
873
874       --  LOCAL_NAME ::=
875       --    DIRECT_NAME
876       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
877       --  | library_unit_NAME
878
879       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
880          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
881
882       begin
883          Analyze (Argx);
884
885          if Nkind (Argx) not in N_Direct_Name
886            and then (Nkind (Argx) /= N_Attribute_Reference
887                       or else Present (Expressions (Argx))
888                       or else Nkind (Prefix (Argx)) /= N_Identifier)
889            and then (not Is_Entity_Name (Argx)
890                       or else not Is_Compilation_Unit (Entity (Argx)))
891          then
892             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
893          end if;
894
895          if Is_Entity_Name (Argx)
896            and then Scope (Entity (Argx)) /= Current_Scope
897          then
898             Error_Pragma_Arg
899               ("pragma% argument must be in same declarative part", Arg);
900          end if;
901       end Check_Arg_Is_Local_Name;
902
903       ---------------------------------
904       -- Check_Arg_Is_Locking_Policy --
905       ---------------------------------
906
907       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
908          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
909
910       begin
911          Check_Arg_Is_Identifier (Argx);
912
913          if not Is_Locking_Policy_Name (Chars (Argx)) then
914             Error_Pragma_Arg
915               ("& is not a valid locking policy name", Argx);
916          end if;
917       end Check_Arg_Is_Locking_Policy;
918
919       -------------------------
920       -- Check_Arg_Is_One_Of --
921       -------------------------
922
923       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
924          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
925
926       begin
927          Check_Arg_Is_Identifier (Argx);
928
929          if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
930             Error_Msg_Name_2 := N1;
931             Error_Msg_Name_3 := N2;
932             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
933          end if;
934       end Check_Arg_Is_One_Of;
935
936       procedure Check_Arg_Is_One_Of
937         (Arg        : Node_Id;
938          N1, N2, N3 : Name_Id)
939       is
940          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
941
942       begin
943          Check_Arg_Is_Identifier (Argx);
944
945          if Chars (Argx) /= N1
946            and then Chars (Argx) /= N2
947            and then Chars (Argx) /= N3
948          then
949             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
950          end if;
951       end Check_Arg_Is_One_Of;
952
953       procedure Check_Arg_Is_One_Of
954         (Arg            : Node_Id;
955          N1, N2, N3, N4 : Name_Id)
956       is
957          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
958
959       begin
960          Check_Arg_Is_Identifier (Argx);
961
962          if Chars (Argx) /= N1
963            and then Chars (Argx) /= N2
964            and then Chars (Argx) /= N3
965            and then Chars (Argx) /= N4
966          then
967             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
968          end if;
969       end Check_Arg_Is_One_Of;
970
971       ---------------------------------
972       -- Check_Arg_Is_Queuing_Policy --
973       ---------------------------------
974
975       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
976          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
977
978       begin
979          Check_Arg_Is_Identifier (Argx);
980
981          if not Is_Queuing_Policy_Name (Chars (Argx)) then
982             Error_Pragma_Arg
983               ("& is not a valid queuing policy name", Argx);
984          end if;
985       end Check_Arg_Is_Queuing_Policy;
986
987       ------------------------------------
988       -- Check_Arg_Is_Static_Expression --
989       ------------------------------------
990
991       procedure Check_Arg_Is_Static_Expression
992         (Arg : Node_Id;
993          Typ : Entity_Id := Empty)
994       is
995          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
996
997       begin
998          if Present (Typ) then
999             Analyze_And_Resolve (Argx, Typ);
1000          else
1001             Analyze_And_Resolve (Argx);
1002          end if;
1003
1004          if Is_OK_Static_Expression (Argx) then
1005             return;
1006
1007          elsif Etype (Argx) = Any_Type then
1008             raise Pragma_Exit;
1009
1010          --  An interesting special case, if we have a string literal and we
1011          --  are in Ada 83 mode, then we allow it even though it will not be
1012          --  flagged as static. This allows the use of Ada 95 pragmas like
1013          --  Import in Ada 83 mode. They will of course be flagged with
1014          --  warnings as usual, but will not cause errors.
1015
1016          elsif Ada_Version = Ada_83
1017            and then Nkind (Argx) = N_String_Literal
1018          then
1019             return;
1020
1021          --  Static expression that raises Constraint_Error. This has already
1022          --  been flagged, so just exit from pragma processing.
1023
1024          elsif Is_Static_Expression (Argx) then
1025             raise Pragma_Exit;
1026
1027          --  Finally, we have a real error
1028
1029          else
1030             Error_Msg_Name_1 := Pname;
1031             Flag_Non_Static_Expr
1032               ("argument for pragma% must be a static expression!", Argx);
1033             raise Pragma_Exit;
1034          end if;
1035       end Check_Arg_Is_Static_Expression;
1036
1037       ------------------------------------------
1038       -- Check_Arg_Is_Task_Dispatching_Policy --
1039       ------------------------------------------
1040
1041       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1042          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1043
1044       begin
1045          Check_Arg_Is_Identifier (Argx);
1046
1047          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1048             Error_Pragma_Arg
1049               ("& is not a valid task dispatching policy name", Argx);
1050          end if;
1051       end Check_Arg_Is_Task_Dispatching_Policy;
1052
1053       ---------------------
1054       -- Check_Arg_Order --
1055       ---------------------
1056
1057       procedure Check_Arg_Order (Names : Name_List) is
1058          Arg : Node_Id;
1059
1060          Highest_So_Far : Natural := 0;
1061          --  Highest index in Names seen do far
1062
1063       begin
1064          Arg := Arg1;
1065          for J in 1 .. Arg_Count loop
1066             if Chars (Arg) /= No_Name then
1067                for K in Names'Range loop
1068                   if Chars (Arg) = Names (K) then
1069                      if K < Highest_So_Far then
1070                         Error_Msg_Name_1 := Pname;
1071                         Error_Msg_N
1072                           ("parameters out of order for pragma%", Arg);
1073                         Error_Msg_Name_1 := Names (K);
1074                         Error_Msg_Name_2 := Names (Highest_So_Far);
1075                         Error_Msg_N ("\% must appear before %", Arg);
1076                         raise Pragma_Exit;
1077
1078                      else
1079                         Highest_So_Far := K;
1080                      end if;
1081                   end if;
1082                end loop;
1083             end if;
1084
1085             Arg := Next (Arg);
1086          end loop;
1087       end Check_Arg_Order;
1088
1089       --------------------------------
1090       -- Check_At_Least_N_Arguments --
1091       --------------------------------
1092
1093       procedure Check_At_Least_N_Arguments (N : Nat) is
1094       begin
1095          if Arg_Count < N then
1096             Error_Pragma ("too few arguments for pragma%");
1097          end if;
1098       end Check_At_Least_N_Arguments;
1099
1100       -------------------------------
1101       -- Check_At_Most_N_Arguments --
1102       -------------------------------
1103
1104       procedure Check_At_Most_N_Arguments (N : Nat) is
1105          Arg : Node_Id;
1106       begin
1107          if Arg_Count > N then
1108             Arg := Arg1;
1109             for J in 1 .. N loop
1110                Next (Arg);
1111                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1112             end loop;
1113          end if;
1114       end Check_At_Most_N_Arguments;
1115
1116       ---------------------
1117       -- Check_Component --
1118       ---------------------
1119
1120       procedure Check_Component
1121         (Comp            : Node_Id;
1122          UU_Typ          : Entity_Id;
1123          In_Variant_Part : Boolean := False)
1124       is
1125          Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1126          Sindic  : constant Node_Id :=
1127                      Subtype_Indication (Component_Definition (Comp));
1128          Typ     : constant Entity_Id := Etype (Comp_Id);
1129
1130          function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1131          --  Determine whether entity Id appears inside a generic body
1132
1133          -------------------------
1134          -- Inside_Generic_Body --
1135          -------------------------
1136
1137          function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1138             S : Entity_Id := Id;
1139
1140          begin
1141             while Present (S)
1142               and then S /= Standard_Standard
1143             loop
1144                if Ekind (S) = E_Generic_Package
1145                  and then In_Package_Body (S)
1146                then
1147                   return True;
1148                end if;
1149
1150                S := Scope (S);
1151             end loop;
1152
1153             return False;
1154          end Inside_Generic_Body;
1155
1156       --  Start of processing for Check_Component
1157
1158       begin
1159          --  Ada 2005 (AI-216): If a component subtype is subject to a per-
1160          --  object constraint, then the component type shall be an Unchecked_
1161          --  Union.
1162
1163          if Nkind (Sindic) = N_Subtype_Indication
1164            and then Has_Per_Object_Constraint (Comp_Id)
1165            and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1166          then
1167             Error_Msg_N
1168               ("component subtype subject to per-object constraint " &
1169                "must be an Unchecked_Union", Comp);
1170
1171          --  Ada 2012 (AI05-0026): For an unchecked union type declared within
1172          --  the body of a generic unit, or within the body of any of its
1173          --  descendant library units, no part of the type of a component
1174          --  declared in a variant_part of the unchecked union type shall be of
1175          --  a formal private type or formal private extension declared within
1176          --  the formal part of the generic unit.
1177
1178          elsif Ada_Version >= Ada_2012
1179            and then Inside_Generic_Body (UU_Typ)
1180            and then In_Variant_Part
1181            and then Is_Private_Type (Typ)
1182            and then Is_Generic_Type (Typ)
1183          then
1184             Error_Msg_N
1185               ("component of Unchecked_Union cannot be of generic type", Comp);
1186
1187          elsif Needs_Finalization (Typ) then
1188             Error_Msg_N
1189               ("component of Unchecked_Union cannot be controlled", Comp);
1190
1191          elsif Has_Task (Typ) then
1192             Error_Msg_N
1193               ("component of Unchecked_Union cannot have tasks", Comp);
1194          end if;
1195       end Check_Component;
1196
1197       ----------------------------------
1198       -- Check_Duplicated_Export_Name --
1199       ----------------------------------
1200
1201       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1202          String_Val : constant String_Id := Strval (Nam);
1203
1204       begin
1205          --  We are only interested in the export case, and in the case of
1206          --  generics, it is the instance, not the template, that is the
1207          --  problem (the template will generate a warning in any case).
1208
1209          if not Inside_A_Generic
1210            and then (Prag_Id = Pragma_Export
1211                        or else
1212                      Prag_Id = Pragma_Export_Procedure
1213                        or else
1214                      Prag_Id = Pragma_Export_Valued_Procedure
1215                        or else
1216                      Prag_Id = Pragma_Export_Function)
1217          then
1218             for J in Externals.First .. Externals.Last loop
1219                if String_Equal (String_Val, Strval (Externals.Table (J))) then
1220                   Error_Msg_Sloc := Sloc (Externals.Table (J));
1221                   Error_Msg_N ("external name duplicates name given#", Nam);
1222                   exit;
1223                end if;
1224             end loop;
1225
1226             Externals.Append (Nam);
1227          end if;
1228       end Check_Duplicated_Export_Name;
1229
1230       -------------------------
1231       -- Check_First_Subtype --
1232       -------------------------
1233
1234       procedure Check_First_Subtype (Arg : Node_Id) is
1235          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1236       begin
1237          if not Is_First_Subtype (Entity (Argx)) then
1238             Error_Pragma_Arg
1239               ("pragma% cannot apply to subtype", Argx);
1240          end if;
1241       end Check_First_Subtype;
1242
1243       ---------------------------
1244       -- Check_In_Main_Program --
1245       ---------------------------
1246
1247       procedure Check_In_Main_Program is
1248          P : constant Node_Id := Parent (N);
1249
1250       begin
1251          --  Must be at in subprogram body
1252
1253          if Nkind (P) /= N_Subprogram_Body then
1254             Error_Pragma ("% pragma allowed only in subprogram");
1255
1256          --  Otherwise warn if obviously not main program
1257
1258          elsif Present (Parameter_Specifications (Specification (P)))
1259            or else not Is_Compilation_Unit (Defining_Entity (P))
1260          then
1261             Error_Msg_Name_1 := Pname;
1262             Error_Msg_N
1263               ("?pragma% is only effective in main program", N);
1264          end if;
1265       end Check_In_Main_Program;
1266
1267       ---------------------------------------
1268       -- Check_Interrupt_Or_Attach_Handler --
1269       ---------------------------------------
1270
1271       procedure Check_Interrupt_Or_Attach_Handler is
1272          Arg1_X : constant Node_Id := Expression (Arg1);
1273          Handler_Proc, Proc_Scope : Entity_Id;
1274
1275       begin
1276          Analyze (Arg1_X);
1277
1278          if Prag_Id = Pragma_Interrupt_Handler then
1279             Check_Restriction (No_Dynamic_Attachment, N);
1280          end if;
1281
1282          Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1283          Proc_Scope := Scope (Handler_Proc);
1284
1285          --  On AAMP only, a pragma Interrupt_Handler is supported for
1286          --  nonprotected parameterless procedures.
1287
1288          if not AAMP_On_Target
1289            or else Prag_Id = Pragma_Attach_Handler
1290          then
1291             if Ekind (Proc_Scope) /= E_Protected_Type then
1292                Error_Pragma_Arg
1293                  ("argument of pragma% must be protected procedure", Arg1);
1294             end if;
1295
1296             if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1297                Error_Pragma ("pragma% must be in protected definition");
1298             end if;
1299          end if;
1300
1301          if not Is_Library_Level_Entity (Proc_Scope)
1302            or else (AAMP_On_Target
1303                      and then not Is_Library_Level_Entity (Handler_Proc))
1304          then
1305             Error_Pragma_Arg
1306               ("argument for pragma% must be library level entity", Arg1);
1307          end if;
1308       end Check_Interrupt_Or_Attach_Handler;
1309
1310       -------------------------------------------
1311       -- Check_Is_In_Decl_Part_Or_Package_Spec --
1312       -------------------------------------------
1313
1314       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1315          P : Node_Id;
1316
1317       begin
1318          P := Parent (N);
1319          loop
1320             if No (P) then
1321                exit;
1322
1323             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1324                exit;
1325
1326             elsif Nkind_In (P, N_Package_Specification,
1327                                N_Block_Statement)
1328             then
1329                return;
1330
1331             --  Note: the following tests seem a little peculiar, because
1332             --  they test for bodies, but if we were in the statement part
1333             --  of the body, we would already have hit the handled statement
1334             --  sequence, so the only way we get here is by being in the
1335             --  declarative part of the body.
1336
1337             elsif Nkind_In (P, N_Subprogram_Body,
1338                                N_Package_Body,
1339                                N_Task_Body,
1340                                N_Entry_Body)
1341             then
1342                return;
1343             end if;
1344
1345             P := Parent (P);
1346          end loop;
1347
1348          Error_Pragma ("pragma% is not in declarative part or package spec");
1349       end Check_Is_In_Decl_Part_Or_Package_Spec;
1350
1351       -------------------------
1352       -- Check_No_Identifier --
1353       -------------------------
1354
1355       procedure Check_No_Identifier (Arg : Node_Id) is
1356       begin
1357          if Chars (Arg) /= No_Name then
1358             Error_Pragma_Arg_Ident
1359               ("pragma% does not permit identifier& here", Arg);
1360          end if;
1361       end Check_No_Identifier;
1362
1363       --------------------------
1364       -- Check_No_Identifiers --
1365       --------------------------
1366
1367       procedure Check_No_Identifiers is
1368          Arg_Node : Node_Id;
1369       begin
1370          if Arg_Count > 0 then
1371             Arg_Node := Arg1;
1372             while Present (Arg_Node) loop
1373                Check_No_Identifier (Arg_Node);
1374                Next (Arg_Node);
1375             end loop;
1376          end if;
1377       end Check_No_Identifiers;
1378
1379       -------------------------------
1380       -- Check_Optional_Identifier --
1381       -------------------------------
1382
1383       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1384       begin
1385          if Present (Arg) and then Chars (Arg) /= No_Name then
1386             if Chars (Arg) /= Id then
1387                Error_Msg_Name_1 := Pname;
1388                Error_Msg_Name_2 := Id;
1389                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1390                raise Pragma_Exit;
1391             end if;
1392          end if;
1393       end Check_Optional_Identifier;
1394
1395       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1396       begin
1397          Name_Buffer (1 .. Id'Length) := Id;
1398          Name_Len := Id'Length;
1399          Check_Optional_Identifier (Arg, Name_Find);
1400       end Check_Optional_Identifier;
1401
1402       --------------------------------------
1403       -- Check_Precondition_Postcondition --
1404       --------------------------------------
1405
1406       procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1407          P  : Node_Id;
1408          PO : Node_Id;
1409
1410          procedure Chain_PPC (PO : Node_Id);
1411          --  If PO is a subprogram declaration node (or a generic subprogram
1412          --  declaration node), then the precondition/postcondition applies
1413          --  to this subprogram and the processing for the pragma is completed.
1414          --  Otherwise the pragma is misplaced.
1415
1416          ---------------
1417          -- Chain_PPC --
1418          ---------------
1419
1420          procedure Chain_PPC (PO : Node_Id) is
1421             S : Node_Id;
1422
1423          begin
1424             if not Nkind_In (PO, N_Subprogram_Declaration,
1425                                  N_Generic_Subprogram_Declaration)
1426             then
1427                Pragma_Misplaced;
1428             end if;
1429
1430             --  Here if we have subprogram or generic subprogram declaration
1431
1432             S := Defining_Unit_Name (Specification (PO));
1433
1434             --  Analyze the pragma unless it appears within a package spec,
1435             --  which is the case where we delay the analysis of the PPC until
1436             --  the end of the package declarations (for details, see
1437             --  Analyze_Package_Specification.Analyze_PPCs).
1438
1439             if not Is_Package_Or_Generic_Package (Scope (S)) then
1440                Analyze_PPC_In_Decl_Part (N, S);
1441             end if;
1442
1443             --  Chain spec PPC pragma to list for subprogram
1444
1445             Set_Next_Pragma (N, Spec_PPC_List (S));
1446             Set_Spec_PPC_List (S, N);
1447
1448             --  Return indicating spec case
1449
1450             In_Body := False;
1451             return;
1452          end Chain_PPC;
1453
1454          --  Start of processing for Check_Precondition_Postcondition
1455
1456       begin
1457          if not Is_List_Member (N) then
1458             Pragma_Misplaced;
1459          end if;
1460
1461          --  Record if pragma is enabled
1462
1463          if Check_Enabled (Pname) then
1464             Set_Pragma_Enabled (N);
1465             Set_SCO_Pragma_Enabled (Loc);
1466          end if;
1467
1468          --  If we are within an inlined body, the legality of the pragma
1469          --  has been checked already.
1470
1471          if In_Inlined_Body then
1472             In_Body := True;
1473             return;
1474          end if;
1475
1476          --  Search prior declarations
1477
1478          P := N;
1479          while Present (Prev (P)) loop
1480             P := Prev (P);
1481
1482             --  If the previous node is a generic subprogram, do not go to to
1483             --  the original node, which is the unanalyzed tree: we need to
1484             --  attach the pre/postconditions to the analyzed version at this
1485             --  point. They get propagated to the original tree when analyzing
1486             --  the corresponding body.
1487
1488             if Nkind (P) not in N_Generic_Declaration then
1489                PO := Original_Node (P);
1490             else
1491                PO := P;
1492             end if;
1493
1494             --  Skip past prior pragma
1495
1496             if Nkind (PO) = N_Pragma then
1497                null;
1498
1499             --  Skip stuff not coming from source
1500
1501             elsif not Comes_From_Source (PO) then
1502                null;
1503
1504             --  Only remaining possibility is subprogram declaration
1505
1506             else
1507                Chain_PPC (PO);
1508                return;
1509             end if;
1510          end loop;
1511
1512          --  If we fall through loop, pragma is at start of list, so see if it
1513          --  is at the start of declarations of a subprogram body.
1514
1515          if Nkind (Parent (N)) = N_Subprogram_Body
1516            and then List_Containing (N) = Declarations (Parent (N))
1517          then
1518             if Operating_Mode /= Generate_Code
1519               or else Inside_A_Generic
1520             then
1521
1522                --  Analyze expression in pragma, for correctness
1523                --  and for ASIS use.
1524
1525                Preanalyze_Spec_Expression
1526                  (Get_Pragma_Arg (Arg1), Standard_Boolean);
1527             end if;
1528
1529             In_Body := True;
1530             return;
1531
1532          --  See if it is in the pragmas after a library level subprogram
1533
1534          elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1535             Chain_PPC (Unit (Parent (Parent (N))));
1536             return;
1537          end if;
1538
1539          --  If we fall through, pragma was misplaced
1540
1541          Pragma_Misplaced;
1542       end Check_Precondition_Postcondition;
1543
1544       -----------------------------
1545       -- Check_Static_Constraint --
1546       -----------------------------
1547
1548       --  Note: for convenience in writing this procedure, in addition to
1549       --  the officially (i.e. by spec) allowed argument which is always a
1550       --  constraint, it also allows ranges and discriminant associations.
1551       --  Above is not clear ???
1552
1553       procedure Check_Static_Constraint (Constr : Node_Id) is
1554
1555          procedure Require_Static (E : Node_Id);
1556          --  Require given expression to be static expression
1557
1558          --------------------
1559          -- Require_Static --
1560          --------------------
1561
1562          procedure Require_Static (E : Node_Id) is
1563          begin
1564             if not Is_OK_Static_Expression (E) then
1565                Flag_Non_Static_Expr
1566                  ("non-static constraint not allowed in Unchecked_Union!", E);
1567                raise Pragma_Exit;
1568             end if;
1569          end Require_Static;
1570
1571       --  Start of processing for Check_Static_Constraint
1572
1573       begin
1574          case Nkind (Constr) is
1575             when N_Discriminant_Association =>
1576                Require_Static (Expression (Constr));
1577
1578             when N_Range =>
1579                Require_Static (Low_Bound (Constr));
1580                Require_Static (High_Bound (Constr));
1581
1582             when N_Attribute_Reference =>
1583                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
1584                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1585
1586             when N_Range_Constraint =>
1587                Check_Static_Constraint (Range_Expression (Constr));
1588
1589             when N_Index_Or_Discriminant_Constraint =>
1590                declare
1591                   IDC : Entity_Id;
1592                begin
1593                   IDC := First (Constraints (Constr));
1594                   while Present (IDC) loop
1595                      Check_Static_Constraint (IDC);
1596                      Next (IDC);
1597                   end loop;
1598                end;
1599
1600             when others =>
1601                null;
1602          end case;
1603       end Check_Static_Constraint;
1604
1605       --------------------------------------
1606       -- Check_Valid_Configuration_Pragma --
1607       --------------------------------------
1608
1609       --  A configuration pragma must appear in the context clause of a
1610       --  compilation unit, and only other pragmas may precede it. Note that
1611       --  the test also allows use in a configuration pragma file.
1612
1613       procedure Check_Valid_Configuration_Pragma is
1614       begin
1615          if not Is_Configuration_Pragma then
1616             Error_Pragma ("incorrect placement for configuration pragma%");
1617          end if;
1618       end Check_Valid_Configuration_Pragma;
1619
1620       -------------------------------------
1621       -- Check_Valid_Library_Unit_Pragma --
1622       -------------------------------------
1623
1624       procedure Check_Valid_Library_Unit_Pragma is
1625          Plist       : List_Id;
1626          Parent_Node : Node_Id;
1627          Unit_Name   : Entity_Id;
1628          Unit_Kind   : Node_Kind;
1629          Unit_Node   : Node_Id;
1630          Sindex      : Source_File_Index;
1631
1632       begin
1633          if not Is_List_Member (N) then
1634             Pragma_Misplaced;
1635
1636          else
1637             Plist := List_Containing (N);
1638             Parent_Node := Parent (Plist);
1639
1640             if Parent_Node = Empty then
1641                Pragma_Misplaced;
1642
1643             --  Case of pragma appearing after a compilation unit. In this case
1644             --  it must have an argument with the corresponding name and must
1645             --  be part of the following pragmas of its parent.
1646
1647             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1648                if Plist /= Pragmas_After (Parent_Node) then
1649                   Pragma_Misplaced;
1650
1651                elsif Arg_Count = 0 then
1652                   Error_Pragma
1653                     ("argument required if outside compilation unit");
1654
1655                else
1656                   Check_No_Identifiers;
1657                   Check_Arg_Count (1);
1658                   Unit_Node := Unit (Parent (Parent_Node));
1659                   Unit_Kind := Nkind (Unit_Node);
1660
1661                   Analyze (Expression (Arg1));
1662
1663                   if Unit_Kind = N_Generic_Subprogram_Declaration
1664                     or else Unit_Kind = N_Subprogram_Declaration
1665                   then
1666                      Unit_Name := Defining_Entity (Unit_Node);
1667
1668                   elsif Unit_Kind in N_Generic_Instantiation then
1669                      Unit_Name := Defining_Entity (Unit_Node);
1670
1671                   else
1672                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
1673                   end if;
1674
1675                   if Chars (Unit_Name) /=
1676                      Chars (Entity (Expression (Arg1)))
1677                   then
1678                      Error_Pragma_Arg
1679                        ("pragma% argument is not current unit name", Arg1);
1680                   end if;
1681
1682                   if Ekind (Unit_Name) = E_Package
1683                     and then Present (Renamed_Entity (Unit_Name))
1684                   then
1685                      Error_Pragma ("pragma% not allowed for renamed package");
1686                   end if;
1687                end if;
1688
1689             --  Pragma appears other than after a compilation unit
1690
1691             else
1692                --  Here we check for the generic instantiation case and also
1693                --  for the case of processing a generic formal package. We
1694                --  detect these cases by noting that the Sloc on the node
1695                --  does not belong to the current compilation unit.
1696
1697                Sindex := Source_Index (Current_Sem_Unit);
1698
1699                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1700                   Rewrite (N, Make_Null_Statement (Loc));
1701                   return;
1702
1703                --  If before first declaration, the pragma applies to the
1704                --  enclosing unit, and the name if present must be this name.
1705
1706                elsif Is_Before_First_Decl (N, Plist) then
1707                   Unit_Node := Unit_Declaration_Node (Current_Scope);
1708                   Unit_Kind := Nkind (Unit_Node);
1709
1710                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1711                      Pragma_Misplaced;
1712
1713                   elsif Unit_Kind = N_Subprogram_Body
1714                     and then not Acts_As_Spec (Unit_Node)
1715                   then
1716                      Pragma_Misplaced;
1717
1718                   elsif Nkind (Parent_Node) = N_Package_Body then
1719                      Pragma_Misplaced;
1720
1721                   elsif Nkind (Parent_Node) = N_Package_Specification
1722                     and then Plist = Private_Declarations (Parent_Node)
1723                   then
1724                      Pragma_Misplaced;
1725
1726                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1727                            or else Nkind (Parent_Node) =
1728                                              N_Generic_Subprogram_Declaration)
1729                     and then Plist = Generic_Formal_Declarations (Parent_Node)
1730                   then
1731                      Pragma_Misplaced;
1732
1733                   elsif Arg_Count > 0 then
1734                      Analyze (Expression (Arg1));
1735
1736                      if Entity (Expression (Arg1)) /= Current_Scope then
1737                         Error_Pragma_Arg
1738                           ("name in pragma% must be enclosing unit", Arg1);
1739                      end if;
1740
1741                   --  It is legal to have no argument in this context
1742
1743                   else
1744                      return;
1745                   end if;
1746
1747                --  Error if not before first declaration. This is because a
1748                --  library unit pragma argument must be the name of a library
1749                --  unit (RM 10.1.5(7)), but the only names permitted in this
1750                --  context are (RM 10.1.5(6)) names of subprogram declarations,
1751                --  generic subprogram declarations or generic instantiations.
1752
1753                else
1754                   Error_Pragma
1755                     ("pragma% misplaced, must be before first declaration");
1756                end if;
1757             end if;
1758          end if;
1759       end Check_Valid_Library_Unit_Pragma;
1760
1761       -------------------
1762       -- Check_Variant --
1763       -------------------
1764
1765       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
1766          Clist : constant Node_Id := Component_List (Variant);
1767          Comp  : Node_Id;
1768
1769       begin
1770          if not Is_Non_Empty_List (Component_Items (Clist)) then
1771             Error_Msg_N
1772               ("Unchecked_Union may not have empty component list",
1773                Variant);
1774             return;
1775          end if;
1776
1777          Comp := First (Component_Items (Clist));
1778          while Present (Comp) loop
1779             Check_Component (Comp, UU_Typ, In_Variant_Part => True);
1780             Next (Comp);
1781          end loop;
1782       end Check_Variant;
1783
1784       ------------------
1785       -- Error_Pragma --
1786       ------------------
1787
1788       procedure Error_Pragma (Msg : String) is
1789       begin
1790          Error_Msg_Name_1 := Pname;
1791          Error_Msg_N (Msg, N);
1792          raise Pragma_Exit;
1793       end Error_Pragma;
1794
1795       ----------------------
1796       -- Error_Pragma_Arg --
1797       ----------------------
1798
1799       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1800       begin
1801          Error_Msg_Name_1 := Pname;
1802          Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1803          raise Pragma_Exit;
1804       end Error_Pragma_Arg;
1805
1806       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1807       begin
1808          Error_Msg_Name_1 := Pname;
1809          Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1810          Error_Pragma_Arg (Msg2, Arg);
1811       end Error_Pragma_Arg;
1812
1813       ----------------------------
1814       -- Error_Pragma_Arg_Ident --
1815       ----------------------------
1816
1817       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1818       begin
1819          Error_Msg_Name_1 := Pname;
1820          Error_Msg_N (Msg, Arg);
1821          raise Pragma_Exit;
1822       end Error_Pragma_Arg_Ident;
1823
1824       ----------------------
1825       -- Error_Pragma_Ref --
1826       ----------------------
1827
1828       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1829       begin
1830          Error_Msg_Name_1 := Pname;
1831          Error_Msg_Sloc   := Sloc (Ref);
1832          Error_Msg_NE (Msg, N, Ref);
1833          raise Pragma_Exit;
1834       end Error_Pragma_Ref;
1835
1836       ------------------------
1837       -- Find_Lib_Unit_Name --
1838       ------------------------
1839
1840       function Find_Lib_Unit_Name return Entity_Id is
1841       begin
1842          --  Return inner compilation unit entity, for case of nested
1843          --  categorization pragmas. This happens in generic unit.
1844
1845          if Nkind (Parent (N)) = N_Package_Specification
1846            and then Defining_Entity (Parent (N)) /= Current_Scope
1847          then
1848             return Defining_Entity (Parent (N));
1849          else
1850             return Current_Scope;
1851          end if;
1852       end Find_Lib_Unit_Name;
1853
1854       ----------------------------
1855       -- Find_Program_Unit_Name --
1856       ----------------------------
1857
1858       procedure Find_Program_Unit_Name (Id : Node_Id) is
1859          Unit_Name : Entity_Id;
1860          Unit_Kind : Node_Kind;
1861          P         : constant Node_Id := Parent (N);
1862
1863       begin
1864          if Nkind (P) = N_Compilation_Unit then
1865             Unit_Kind := Nkind (Unit (P));
1866
1867             if Unit_Kind = N_Subprogram_Declaration
1868               or else Unit_Kind = N_Package_Declaration
1869               or else Unit_Kind in N_Generic_Declaration
1870             then
1871                Unit_Name := Defining_Entity (Unit (P));
1872
1873                if Chars (Id) = Chars (Unit_Name) then
1874                   Set_Entity (Id, Unit_Name);
1875                   Set_Etype (Id, Etype (Unit_Name));
1876                else
1877                   Set_Etype (Id, Any_Type);
1878                   Error_Pragma
1879                     ("cannot find program unit referenced by pragma%");
1880                end if;
1881
1882             else
1883                Set_Etype (Id, Any_Type);
1884                Error_Pragma ("pragma% inapplicable to this unit");
1885             end if;
1886
1887          else
1888             Analyze (Id);
1889          end if;
1890       end Find_Program_Unit_Name;
1891
1892       -----------------------------------------
1893       -- Find_Unique_Parameterless_Procedure --
1894       -----------------------------------------
1895
1896       function Find_Unique_Parameterless_Procedure
1897         (Name : Entity_Id;
1898          Arg  : Node_Id) return Entity_Id
1899       is
1900          Proc : Entity_Id := Empty;
1901
1902       begin
1903          --  The body of this procedure needs some comments ???
1904
1905          if not Is_Entity_Name (Name) then
1906             Error_Pragma_Arg
1907               ("argument of pragma% must be entity name", Arg);
1908
1909          elsif not Is_Overloaded (Name) then
1910             Proc := Entity (Name);
1911
1912             if Ekind (Proc) /= E_Procedure
1913               or else Present (First_Formal (Proc))
1914             then
1915                Error_Pragma_Arg
1916                  ("argument of pragma% must be parameterless procedure", Arg);
1917             end if;
1918
1919          else
1920             declare
1921                Found : Boolean := False;
1922                It    : Interp;
1923                Index : Interp_Index;
1924
1925             begin
1926                Get_First_Interp (Name, Index, It);
1927                while Present (It.Nam) loop
1928                   Proc := It.Nam;
1929
1930                   if Ekind (Proc) = E_Procedure
1931                     and then No (First_Formal (Proc))
1932                   then
1933                      if not Found then
1934                         Found := True;
1935                         Set_Entity (Name, Proc);
1936                         Set_Is_Overloaded (Name, False);
1937                      else
1938                         Error_Pragma_Arg
1939                           ("ambiguous handler name for pragma% ", Arg);
1940                      end if;
1941                   end if;
1942
1943                   Get_Next_Interp (Index, It);
1944                end loop;
1945
1946                if not Found then
1947                   Error_Pragma_Arg
1948                     ("argument of pragma% must be parameterless procedure",
1949                      Arg);
1950                else
1951                   Proc := Entity (Name);
1952                end if;
1953             end;
1954          end if;
1955
1956          return Proc;
1957       end Find_Unique_Parameterless_Procedure;
1958
1959       -------------------------
1960       -- Gather_Associations --
1961       -------------------------
1962
1963       procedure Gather_Associations
1964         (Names : Name_List;
1965          Args  : out Args_List)
1966       is
1967          Arg : Node_Id;
1968
1969       begin
1970          --  Initialize all parameters to Empty
1971
1972          for J in Args'Range loop
1973             Args (J) := Empty;
1974          end loop;
1975
1976          --  That's all we have to do if there are no argument associations
1977
1978          if No (Pragma_Argument_Associations (N)) then
1979             return;
1980          end if;
1981
1982          --  Otherwise first deal with any positional parameters present
1983
1984          Arg := First (Pragma_Argument_Associations (N));
1985          for Index in Args'Range loop
1986             exit when No (Arg) or else Chars (Arg) /= No_Name;
1987             Args (Index) := Expression (Arg);
1988             Next (Arg);
1989          end loop;
1990
1991          --  Positional parameters all processed, if any left, then we
1992          --  have too many positional parameters.
1993
1994          if Present (Arg) and then Chars (Arg) = No_Name then
1995             Error_Pragma_Arg
1996               ("too many positional associations for pragma%", Arg);
1997          end if;
1998
1999          --  Process named parameters if any are present
2000
2001          while Present (Arg) loop
2002             if Chars (Arg) = No_Name then
2003                Error_Pragma_Arg
2004                  ("positional association cannot follow named association",
2005                   Arg);
2006
2007             else
2008                for Index in Names'Range loop
2009                   if Names (Index) = Chars (Arg) then
2010                      if Present (Args (Index)) then
2011                         Error_Pragma_Arg
2012                           ("duplicate argument association for pragma%", Arg);
2013                      else
2014                         Args (Index) := Expression (Arg);
2015                         exit;
2016                      end if;
2017                   end if;
2018
2019                   if Index = Names'Last then
2020                      Error_Msg_Name_1 := Pname;
2021                      Error_Msg_N ("pragma% does not allow & argument", Arg);
2022
2023                      --  Check for possible misspelling
2024
2025                      for Index1 in Names'Range loop
2026                         if Is_Bad_Spelling_Of
2027                              (Chars (Arg), Names (Index1))
2028                         then
2029                            Error_Msg_Name_1 := Names (Index1);
2030                            Error_Msg_N -- CODEFIX
2031                              ("\possible misspelling of%", Arg);
2032                            exit;
2033                         end if;
2034                      end loop;
2035
2036                      raise Pragma_Exit;
2037                   end if;
2038                end loop;
2039             end if;
2040
2041             Next (Arg);
2042          end loop;
2043       end Gather_Associations;
2044
2045       -----------------
2046       -- GNAT_Pragma --
2047       -----------------
2048
2049       procedure GNAT_Pragma is
2050       begin
2051          Check_Restriction (No_Implementation_Pragmas, N);
2052       end GNAT_Pragma;
2053
2054       --------------------------
2055       -- Is_Before_First_Decl --
2056       --------------------------
2057
2058       function Is_Before_First_Decl
2059         (Pragma_Node : Node_Id;
2060          Decls       : List_Id) return Boolean
2061       is
2062          Item : Node_Id := First (Decls);
2063
2064       begin
2065          --  Only other pragmas can come before this pragma
2066
2067          loop
2068             if No (Item) or else Nkind (Item) /= N_Pragma then
2069                return False;
2070
2071             elsif Item = Pragma_Node then
2072                return True;
2073             end if;
2074
2075             Next (Item);
2076          end loop;
2077       end Is_Before_First_Decl;
2078
2079       -----------------------------
2080       -- Is_Configuration_Pragma --
2081       -----------------------------
2082
2083       --  A configuration pragma must appear in the context clause of a
2084       --  compilation unit, and only other pragmas may precede it. Note that
2085       --  the test below also permits use in a configuration pragma file.
2086
2087       function Is_Configuration_Pragma return Boolean is
2088          Lis : constant List_Id := List_Containing (N);
2089          Par : constant Node_Id := Parent (N);
2090          Prg : Node_Id;
2091
2092       begin
2093          --  If no parent, then we are in the configuration pragma file,
2094          --  so the placement is definitely appropriate.
2095
2096          if No (Par) then
2097             return True;
2098
2099          --  Otherwise we must be in the context clause of a compilation unit
2100          --  and the only thing allowed before us in the context list is more
2101          --  configuration pragmas.
2102
2103          elsif Nkind (Par) = N_Compilation_Unit
2104            and then Context_Items (Par) = Lis
2105          then
2106             Prg := First (Lis);
2107
2108             loop
2109                if Prg = N then
2110                   return True;
2111                elsif Nkind (Prg) /= N_Pragma then
2112                   return False;
2113                end if;
2114
2115                Next (Prg);
2116             end loop;
2117
2118          else
2119             return False;
2120          end if;
2121       end Is_Configuration_Pragma;
2122
2123       --------------------------
2124       -- Is_In_Context_Clause --
2125       --------------------------
2126
2127       function Is_In_Context_Clause return Boolean is
2128          Plist       : List_Id;
2129          Parent_Node : Node_Id;
2130
2131       begin
2132          if not Is_List_Member (N) then
2133             return False;
2134
2135          else
2136             Plist := List_Containing (N);
2137             Parent_Node := Parent (Plist);
2138
2139             if Parent_Node = Empty
2140               or else Nkind (Parent_Node) /= N_Compilation_Unit
2141               or else Context_Items (Parent_Node) /= Plist
2142             then
2143                return False;
2144             end if;
2145          end if;
2146
2147          return True;
2148       end Is_In_Context_Clause;
2149
2150       ---------------------------------
2151       -- Is_Static_String_Expression --
2152       ---------------------------------
2153
2154       function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2155          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2156
2157       begin
2158          Analyze_And_Resolve (Argx);
2159          return Is_OK_Static_Expression (Argx)
2160            and then Nkind (Argx) = N_String_Literal;
2161       end Is_Static_String_Expression;
2162
2163       ----------------------
2164       -- Pragma_Misplaced --
2165       ----------------------
2166
2167       procedure Pragma_Misplaced is
2168       begin
2169          Error_Pragma ("incorrect placement of pragma%");
2170       end Pragma_Misplaced;
2171
2172       ------------------------------------
2173       -- Process Atomic_Shared_Volatile --
2174       ------------------------------------
2175
2176       procedure Process_Atomic_Shared_Volatile is
2177          E_Id : Node_Id;
2178          E    : Entity_Id;
2179          D    : Node_Id;
2180          K    : Node_Kind;
2181          Utyp : Entity_Id;
2182
2183          procedure Set_Atomic (E : Entity_Id);
2184          --  Set given type as atomic, and if no explicit alignment was given,
2185          --  set alignment to unknown, since back end knows what the alignment
2186          --  requirements are for atomic arrays. Note: this step is necessary
2187          --  for derived types.
2188
2189          ----------------
2190          -- Set_Atomic --
2191          ----------------
2192
2193          procedure Set_Atomic (E : Entity_Id) is
2194          begin
2195             Set_Is_Atomic (E);
2196
2197             if not Has_Alignment_Clause (E) then
2198                Set_Alignment (E, Uint_0);
2199             end if;
2200          end Set_Atomic;
2201
2202       --  Start of processing for Process_Atomic_Shared_Volatile
2203
2204       begin
2205          Check_Ada_83_Warning;
2206          Check_No_Identifiers;
2207          Check_Arg_Count (1);
2208          Check_Arg_Is_Local_Name (Arg1);
2209          E_Id := Expression (Arg1);
2210
2211          if Etype (E_Id) = Any_Type then
2212             return;
2213          end if;
2214
2215          E := Entity (E_Id);
2216          D := Declaration_Node (E);
2217          K := Nkind (D);
2218
2219          if Is_Type (E) then
2220             if Rep_Item_Too_Early (E, N)
2221                  or else
2222                Rep_Item_Too_Late (E, N)
2223             then
2224                return;
2225             else
2226                Check_First_Subtype (Arg1);
2227             end if;
2228
2229             if Prag_Id /= Pragma_Volatile then
2230                Set_Atomic (E);
2231                Set_Atomic (Underlying_Type (E));
2232                Set_Atomic (Base_Type (E));
2233             end if;
2234
2235             --  Attribute belongs on the base type. If the view of the type is
2236             --  currently private, it also belongs on the underlying type.
2237
2238             Set_Is_Volatile (Base_Type (E));
2239             Set_Is_Volatile (Underlying_Type (E));
2240
2241             Set_Treat_As_Volatile (E);
2242             Set_Treat_As_Volatile (Underlying_Type (E));
2243
2244          elsif K = N_Object_Declaration
2245            or else (K = N_Component_Declaration
2246                      and then Original_Record_Component (E) = E)
2247          then
2248             if Rep_Item_Too_Late (E, N) then
2249                return;
2250             end if;
2251
2252             if Prag_Id /= Pragma_Volatile then
2253                Set_Is_Atomic (E);
2254
2255                --  If the object declaration has an explicit initialization, a
2256                --  temporary may have to be created to hold the expression, to
2257                --  ensure that access to the object remain atomic.
2258
2259                if Nkind (Parent (E)) = N_Object_Declaration
2260                  and then Present (Expression (Parent (E)))
2261                then
2262                   Set_Has_Delayed_Freeze (E);
2263                end if;
2264
2265                --  An interesting improvement here. If an object of type X is
2266                --  declared atomic, and the type X is not atomic, that's a
2267                --  pity, since it may not have appropriate alignment etc. We
2268                --  can rescue this in the special case where the object and
2269                --  type are in the same unit by just setting the type as
2270                --  atomic, so that the back end will process it as atomic.
2271
2272                Utyp := Underlying_Type (Etype (E));
2273
2274                if Present (Utyp)
2275                  and then Sloc (E) > No_Location
2276                  and then Sloc (Utyp) > No_Location
2277                  and then
2278                    Get_Source_File_Index (Sloc (E)) =
2279                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2280                then
2281                   Set_Is_Atomic (Underlying_Type (Etype (E)));
2282                end if;
2283             end if;
2284
2285             Set_Is_Volatile (E);
2286             Set_Treat_As_Volatile (E);
2287
2288          else
2289             Error_Pragma_Arg
2290               ("inappropriate entity for pragma%", Arg1);
2291          end if;
2292       end Process_Atomic_Shared_Volatile;
2293
2294       -------------------------------------------
2295       -- Process_Compile_Time_Warning_Or_Error --
2296       -------------------------------------------
2297
2298       procedure Process_Compile_Time_Warning_Or_Error is
2299          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2300
2301       begin
2302          Check_Arg_Count (2);
2303          Check_No_Identifiers;
2304          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2305          Analyze_And_Resolve (Arg1x, Standard_Boolean);
2306
2307          if Compile_Time_Known_Value (Arg1x) then
2308             if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2309                declare
2310                   Str   : constant String_Id :=
2311                             Strval (Get_Pragma_Arg (Arg2));
2312                   Len   : constant Int := String_Length (Str);
2313                   Cont  : Boolean;
2314                   Ptr   : Nat;
2315                   CC    : Char_Code;
2316                   C     : Character;
2317                   Cent  : constant Entity_Id :=
2318                             Cunit_Entity (Current_Sem_Unit);
2319
2320                   Force : constant Boolean :=
2321                             Prag_Id = Pragma_Compile_Time_Warning
2322                               and then
2323                                 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2324                               and then (Ekind (Cent) /= E_Package
2325                                           or else not In_Private_Part (Cent));
2326                   --  Set True if this is the warning case, and we are in the
2327                   --  visible part of a package spec, or in a subprogram spec,
2328                   --  in which case we want to force the client to see the
2329                   --  warning, even though it is not in the main unit.
2330
2331                begin
2332                   --  Loop through segments of message separated by line feeds.
2333                   --  We output these segments as separate messages with
2334                   --  continuation marks for all but the first.
2335
2336                   Cont := False;
2337                   Ptr := 1;
2338                   loop
2339                      Error_Msg_Strlen := 0;
2340
2341                      --  Loop to copy characters from argument to error message
2342                      --  string buffer.
2343
2344                      loop
2345                         exit when Ptr > Len;
2346                         CC := Get_String_Char (Str, Ptr);
2347                         Ptr := Ptr + 1;
2348
2349                         --  Ignore wide chars ??? else store character
2350
2351                         if In_Character_Range (CC) then
2352                            C := Get_Character (CC);
2353                            exit when C = ASCII.LF;
2354                            Error_Msg_Strlen := Error_Msg_Strlen + 1;
2355                            Error_Msg_String (Error_Msg_Strlen) := C;
2356                         end if;
2357                      end loop;
2358
2359                      --  Here with one line ready to go
2360
2361                      Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2362
2363                      --  If this is a warning in a spec, then we want clients
2364                      --  to see the warning, so mark the message with the
2365                      --  special sequence !! to force the warning. In the case
2366                      --  of a package spec, we do not force this if we are in
2367                      --  the private part of the spec.
2368
2369                      if Force then
2370                         if Cont = False then
2371                            Error_Msg_N ("<~!!", Arg1);
2372                            Cont := True;
2373                         else
2374                            Error_Msg_N ("\<~!!", Arg1);
2375                         end if;
2376
2377                      --  Error, rather than warning, or in a body, so we do not
2378                      --  need to force visibility for client (error will be
2379                      --  output in any case, and this is the situation in which
2380                      --  we do not want a client to get a warning, since the
2381                      --  warning is in the body or the spec private part.
2382
2383                      else
2384                         if Cont = False then
2385                            Error_Msg_N ("<~", Arg1);
2386                            Cont := True;
2387                         else
2388                            Error_Msg_N ("\<~", Arg1);
2389                         end if;
2390                      end if;
2391
2392                      exit when Ptr > Len;
2393                   end loop;
2394                end;
2395             end if;
2396          end if;
2397       end Process_Compile_Time_Warning_Or_Error;
2398
2399       ------------------------
2400       -- Process_Convention --
2401       ------------------------
2402
2403       procedure Process_Convention
2404         (C   : out Convention_Id;
2405          Ent : out Entity_Id)
2406       is
2407          Id        : Node_Id;
2408          E         : Entity_Id;
2409          E1        : Entity_Id;
2410          Cname     : Name_Id;
2411          Comp_Unit : Unit_Number_Type;
2412
2413          procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2414          --  Called if we have more than one Export/Import/Convention pragma.
2415          --  This is generally illegal, but we have a special case of allowing
2416          --  Import and Interface to coexist if they specify the convention in
2417          --  a consistent manner. We are allowed to do this, since Interface is
2418          --  an implementation defined pragma, and we choose to do it since we
2419          --  know Rational allows this combination. S is the entity id of the
2420          --  subprogram in question. This procedure also sets the special flag
2421          --  Import_Interface_Present in both pragmas in the case where we do
2422          --  have matching Import and Interface pragmas.
2423
2424          procedure Set_Convention_From_Pragma (E : Entity_Id);
2425          --  Set convention in entity E, and also flag that the entity has a
2426          --  convention pragma. If entity is for a private or incomplete type,
2427          --  also set convention and flag on underlying type. This procedure
2428          --  also deals with the special case of C_Pass_By_Copy convention.
2429
2430          -------------------------------
2431          -- Diagnose_Multiple_Pragmas --
2432          -------------------------------
2433
2434          procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2435             Pdec : constant Node_Id := Declaration_Node (S);
2436             Decl : Node_Id;
2437             Err  : Boolean;
2438
2439             function Same_Convention (Decl : Node_Id) return Boolean;
2440             --  Decl is a pragma node. This function returns True if this
2441             --  pragma has a first argument that is an identifier with a
2442             --  Chars field corresponding to the Convention_Id C.
2443
2444             function Same_Name (Decl : Node_Id) return Boolean;
2445             --  Decl is a pragma node. This function returns True if this
2446             --  pragma has a second argument that is an identifier with a
2447             --  Chars field that matches the Chars of the current subprogram.
2448
2449             ---------------------
2450             -- Same_Convention --
2451             ---------------------
2452
2453             function Same_Convention (Decl : Node_Id) return Boolean is
2454                Arg1 : constant Node_Id :=
2455                         First (Pragma_Argument_Associations (Decl));
2456
2457             begin
2458                if Present (Arg1) then
2459                   declare
2460                      Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2461                   begin
2462                      if Nkind (Arg) = N_Identifier
2463                        and then Is_Convention_Name (Chars (Arg))
2464                        and then Get_Convention_Id (Chars (Arg)) = C
2465                      then
2466                         return True;
2467                      end if;
2468                   end;
2469                end if;
2470
2471                return False;
2472             end Same_Convention;
2473
2474             ---------------
2475             -- Same_Name --
2476             ---------------
2477
2478             function Same_Name (Decl : Node_Id) return Boolean is
2479                Arg1 : constant Node_Id :=
2480                         First (Pragma_Argument_Associations (Decl));
2481                Arg2 : Node_Id;
2482
2483             begin
2484                if No (Arg1) then
2485                   return False;
2486                end if;
2487
2488                Arg2 := Next (Arg1);
2489
2490                if No (Arg2) then
2491                   return False;
2492                end if;
2493
2494                declare
2495                   Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2496                begin
2497                   if Nkind (Arg) = N_Identifier
2498                     and then Chars (Arg) = Chars (S)
2499                   then
2500                      return True;
2501                   end if;
2502                end;
2503
2504                return False;
2505             end Same_Name;
2506
2507          --  Start of processing for Diagnose_Multiple_Pragmas
2508
2509          begin
2510             Err := True;
2511
2512             --  Definitely give message if we have Convention/Export here
2513
2514             if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2515                null;
2516
2517                --  If we have an Import or Export, scan back from pragma to
2518                --  find any previous pragma applying to the same procedure.
2519                --  The scan will be terminated by the start of the list, or
2520                --  hitting the subprogram declaration. This won't allow one
2521                --  pragma to appear in the public part and one in the private
2522                --  part, but that seems very unlikely in practice.
2523
2524             else
2525                Decl := Prev (N);
2526                while Present (Decl) and then Decl /= Pdec loop
2527
2528                   --  Look for pragma with same name as us
2529
2530                   if Nkind (Decl) = N_Pragma
2531                     and then Same_Name (Decl)
2532                   then
2533                      --  Give error if same as our pragma or Export/Convention
2534
2535                      if Pragma_Name (Decl) = Name_Export
2536                           or else
2537                         Pragma_Name (Decl) = Name_Convention
2538                           or else
2539                         Pragma_Name (Decl) = Pragma_Name (N)
2540                      then
2541                         exit;
2542
2543                      --  Case of Import/Interface or the other way round
2544
2545                      elsif Pragma_Name (Decl) = Name_Interface
2546                              or else
2547                            Pragma_Name (Decl) = Name_Import
2548                      then
2549                         --  Here we know that we have Import and Interface. It
2550                         --  doesn't matter which way round they are. See if
2551                         --  they specify the same convention. If so, all OK,
2552                         --  and set special flags to stop other messages
2553
2554                         if Same_Convention (Decl) then
2555                            Set_Import_Interface_Present (N);
2556                            Set_Import_Interface_Present (Decl);
2557                            Err := False;
2558
2559                         --  If different conventions, special message
2560
2561                         else
2562                            Error_Msg_Sloc := Sloc (Decl);
2563                            Error_Pragma_Arg
2564                              ("convention differs from that given#", Arg1);
2565                            return;
2566                         end if;
2567                      end if;
2568                   end if;
2569
2570                   Next (Decl);
2571                end loop;
2572             end if;
2573
2574             --  Give message if needed if we fall through those tests
2575
2576             if Err then
2577                Error_Pragma_Arg
2578                  ("at most one Convention/Export/Import pragma is allowed",
2579                   Arg2);
2580             end if;
2581          end Diagnose_Multiple_Pragmas;
2582
2583          --------------------------------
2584          -- Set_Convention_From_Pragma --
2585          --------------------------------
2586
2587          procedure Set_Convention_From_Pragma (E : Entity_Id) is
2588          begin
2589             --  Ada 2005 (AI-430): Check invalid attempt to change convention
2590             --  for an overridden dispatching operation. Technically this is
2591             --  an amendment and should only be done in Ada 2005 mode. However,
2592             --  this is clearly a mistake, since the problem that is addressed
2593             --  by this AI is that there is a clear gap in the RM!
2594
2595             if Is_Dispatching_Operation (E)
2596               and then Present (Overridden_Operation (E))
2597               and then C /= Convention (Overridden_Operation (E))
2598             then
2599                Error_Pragma_Arg
2600                  ("cannot change convention for " &
2601                   "overridden dispatching operation",
2602                   Arg1);
2603             end if;
2604
2605             --  Set the convention
2606
2607             Set_Convention (E, C);
2608             Set_Has_Convention_Pragma (E);
2609
2610             if Is_Incomplete_Or_Private_Type (E) then
2611                Set_Convention            (Underlying_Type (E), C);
2612                Set_Has_Convention_Pragma (Underlying_Type (E), True);
2613             end if;
2614
2615             --  A class-wide type should inherit the convention of the specific
2616             --  root type (although this isn't specified clearly by the RM).
2617
2618             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2619                Set_Convention (Class_Wide_Type (E), C);
2620             end if;
2621
2622             --  If the entity is a record type, then check for special case of
2623             --  C_Pass_By_Copy, which is treated the same as C except that the
2624             --  special record flag is set. This convention is only permitted
2625             --  on record types (see AI95-00131).
2626
2627             if Cname = Name_C_Pass_By_Copy then
2628                if Is_Record_Type (E) then
2629                   Set_C_Pass_By_Copy (Base_Type (E));
2630                elsif Is_Incomplete_Or_Private_Type (E)
2631                  and then Is_Record_Type (Underlying_Type (E))
2632                then
2633                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2634                else
2635                   Error_Pragma_Arg
2636                     ("C_Pass_By_Copy convention allowed only for record type",
2637                      Arg2);
2638                end if;
2639             end if;
2640
2641             --  If the entity is a derived boolean type, check for the special
2642             --  case of convention C, C++, or Fortran, where we consider any
2643             --  nonzero value to represent true.
2644
2645             if Is_Discrete_Type (E)
2646               and then Root_Type (Etype (E)) = Standard_Boolean
2647               and then
2648                 (C = Convention_C
2649                    or else
2650                  C = Convention_CPP
2651                    or else
2652                  C = Convention_Fortran)
2653             then
2654                Set_Nonzero_Is_True (Base_Type (E));
2655             end if;
2656          end Set_Convention_From_Pragma;
2657
2658       --  Start of processing for Process_Convention
2659
2660       begin
2661          Check_At_Least_N_Arguments (2);
2662          Check_Optional_Identifier (Arg1, Name_Convention);
2663          Check_Arg_Is_Identifier (Arg1);
2664          Cname := Chars (Expression (Arg1));
2665
2666          --  C_Pass_By_Copy is treated as a synonym for convention C (this is
2667          --  tested again below to set the critical flag).
2668          if Cname = Name_C_Pass_By_Copy then
2669             C := Convention_C;
2670
2671          --  Otherwise we must have something in the standard convention list
2672
2673          elsif Is_Convention_Name (Cname) then
2674             C := Get_Convention_Id (Chars (Expression (Arg1)));
2675
2676          --  In DEC VMS, it seems that there is an undocumented feature that
2677          --  any unrecognized convention is treated as the default, which for
2678          --  us is convention C. It does not seem so terrible to do this
2679          --  unconditionally, silently in the VMS case, and with a warning
2680          --  in the non-VMS case.
2681
2682          else
2683             if Warn_On_Export_Import and not OpenVMS_On_Target then
2684                Error_Msg_N
2685                  ("?unrecognized convention name, C assumed",
2686                   Expression (Arg1));
2687             end if;
2688
2689             C := Convention_C;
2690          end if;
2691
2692          Check_Optional_Identifier (Arg2, Name_Entity);
2693          Check_Arg_Is_Local_Name (Arg2);
2694
2695          Id := Expression (Arg2);
2696          Analyze (Id);
2697
2698          if not Is_Entity_Name (Id) then
2699             Error_Pragma_Arg ("entity name required", Arg2);
2700          end if;
2701
2702          E := Entity (Id);
2703
2704          --  Set entity to return
2705
2706          Ent := E;
2707
2708          --  Go to renamed subprogram if present, since convention applies to
2709          --  the actual renamed entity, not to the renaming entity. If the
2710          --  subprogram is inherited, go to parent subprogram.
2711
2712          if Is_Subprogram (E)
2713            and then Present (Alias (E))
2714          then
2715             if Nkind (Parent (Declaration_Node (E))) =
2716                                        N_Subprogram_Renaming_Declaration
2717             then
2718                if Scope (E) /= Scope (Alias (E)) then
2719                   Error_Pragma_Ref
2720                     ("cannot apply pragma% to non-local entity&#", E);
2721                end if;
2722
2723                E := Alias (E);
2724
2725             elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2726                                         N_Private_Extension_Declaration)
2727               and then Scope (E) = Scope (Alias (E))
2728             then
2729                E := Alias (E);
2730
2731                --  Return the parent subprogram the entity was inherited from
2732
2733                Ent := E;
2734             end if;
2735          end if;
2736
2737          --  Check that we are not applying this to a specless body
2738
2739          if Is_Subprogram (E)
2740            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2741          then
2742             Error_Pragma
2743               ("pragma% requires separate spec and must come before body");
2744          end if;
2745
2746          --  Check that we are not applying this to a named constant
2747
2748          if Ekind_In (E, E_Named_Integer, E_Named_Real) then
2749             Error_Msg_Name_1 := Pname;
2750             Error_Msg_N
2751               ("cannot apply pragma% to named constant!",
2752                Get_Pragma_Arg (Arg2));
2753             Error_Pragma_Arg
2754               ("\supply appropriate type for&!", Arg2);
2755          end if;
2756
2757          if Ekind (E) = E_Enumeration_Literal then
2758             Error_Pragma ("enumeration literal not allowed for pragma%");
2759          end if;
2760
2761          --  Check for rep item appearing too early or too late
2762
2763          if Etype (E) = Any_Type
2764            or else Rep_Item_Too_Early (E, N)
2765          then
2766             raise Pragma_Exit;
2767          else
2768             E := Underlying_Type (E);
2769          end if;
2770
2771          if Rep_Item_Too_Late (E, N) then
2772             raise Pragma_Exit;
2773          end if;
2774
2775          if Has_Convention_Pragma (E) then
2776             Diagnose_Multiple_Pragmas (E);
2777
2778          elsif Convention (E) = Convention_Protected
2779            or else Ekind (Scope (E)) = E_Protected_Type
2780          then
2781             Error_Pragma_Arg
2782               ("a protected operation cannot be given a different convention",
2783                 Arg2);
2784          end if;
2785
2786          --  For Intrinsic, a subprogram is required
2787
2788          if C = Convention_Intrinsic
2789            and then not Is_Subprogram (E)
2790            and then not Is_Generic_Subprogram (E)
2791          then
2792             Error_Pragma_Arg
2793               ("second argument of pragma% must be a subprogram", Arg2);
2794          end if;
2795
2796          --  For Stdcall, a subprogram, variable or subprogram type is required
2797
2798          if C = Convention_Stdcall
2799            and then not Is_Subprogram (E)
2800            and then not Is_Generic_Subprogram (E)
2801            and then Ekind (E) /= E_Variable
2802            and then not
2803              (Is_Access_Type (E)
2804                and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2805          then
2806             Error_Pragma_Arg
2807               ("second argument of pragma% must be subprogram (type)",
2808                Arg2);
2809          end if;
2810
2811          if not Is_Subprogram (E)
2812            and then not Is_Generic_Subprogram (E)
2813          then
2814             Set_Convention_From_Pragma (E);
2815
2816             if Is_Type (E) then
2817                Check_First_Subtype (Arg2);
2818                Set_Convention_From_Pragma (Base_Type (E));
2819
2820                --  For subprograms, we must set the convention on the
2821                --  internally generated directly designated type as well.
2822
2823                if Ekind (E) = E_Access_Subprogram_Type then
2824                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
2825                end if;
2826             end if;
2827
2828          --  For the subprogram case, set proper convention for all homonyms
2829          --  in same scope and the same declarative part, i.e. the same
2830          --  compilation unit.
2831
2832          else
2833             Comp_Unit := Get_Source_Unit (E);
2834             Set_Convention_From_Pragma (E);
2835
2836             --  Treat a pragma Import as an implicit body, for GPS use
2837
2838             if Prag_Id = Pragma_Import then
2839                Generate_Reference (E, Id, 'b');
2840             end if;
2841
2842             --  Loop through the homonyms of the pragma argument's entity
2843
2844             E1 := Ent;
2845             loop
2846                E1 := Homonym (E1);
2847                exit when No (E1) or else Scope (E1) /= Current_Scope;
2848
2849                --  Do not set the pragma on inherited operations or on formal
2850                --  subprograms.
2851
2852                if Comes_From_Source (E1)
2853                  and then Comp_Unit = Get_Source_Unit (E1)
2854                  and then not Is_Formal_Subprogram (E1)
2855                  and then Nkind (Original_Node (Parent (E1))) /=
2856                                                     N_Full_Type_Declaration
2857                then
2858                   if Present (Alias (E1))
2859                     and then Scope (E1) /= Scope (Alias (E1))
2860                   then
2861                      Error_Pragma_Ref
2862                        ("cannot apply pragma% to non-local entity& declared#",
2863                         E1);
2864                   end if;
2865
2866                   Set_Convention_From_Pragma (E1);
2867
2868                   if Prag_Id = Pragma_Import then
2869                      Generate_Reference (E1, Id, 'b');
2870                   end if;
2871                end if;
2872             end loop;
2873          end if;
2874       end Process_Convention;
2875
2876       -----------------------------------------------------
2877       -- Process_Extended_Import_Export_Exception_Pragma --
2878       -----------------------------------------------------
2879
2880       procedure Process_Extended_Import_Export_Exception_Pragma
2881         (Arg_Internal : Node_Id;
2882          Arg_External : Node_Id;
2883          Arg_Form     : Node_Id;
2884          Arg_Code     : Node_Id)
2885       is
2886          Def_Id   : Entity_Id;
2887          Code_Val : Uint;
2888
2889       begin
2890          if not OpenVMS_On_Target then
2891             Error_Pragma
2892               ("?pragma% ignored (applies only to Open'V'M'S)");
2893          end if;
2894
2895          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2896          Def_Id := Entity (Arg_Internal);
2897
2898          if Ekind (Def_Id) /= E_Exception then
2899             Error_Pragma_Arg
2900               ("pragma% must refer to declared exception", Arg_Internal);
2901          end if;
2902
2903          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2904
2905          if Present (Arg_Form) then
2906             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2907          end if;
2908
2909          if Present (Arg_Form)
2910            and then Chars (Arg_Form) = Name_Ada
2911          then
2912             null;
2913          else
2914             Set_Is_VMS_Exception (Def_Id);
2915             Set_Exception_Code (Def_Id, No_Uint);
2916          end if;
2917
2918          if Present (Arg_Code) then
2919             if not Is_VMS_Exception (Def_Id) then
2920                Error_Pragma_Arg
2921                  ("Code option for pragma% not allowed for Ada case",
2922                   Arg_Code);
2923             end if;
2924
2925             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2926             Code_Val := Expr_Value (Arg_Code);
2927
2928             if not UI_Is_In_Int_Range (Code_Val) then
2929                Error_Pragma_Arg
2930                  ("Code option for pragma% must be in 32-bit range",
2931                   Arg_Code);
2932
2933             else
2934                Set_Exception_Code (Def_Id, Code_Val);
2935             end if;
2936          end if;
2937       end Process_Extended_Import_Export_Exception_Pragma;
2938
2939       -------------------------------------------------
2940       -- Process_Extended_Import_Export_Internal_Arg --
2941       -------------------------------------------------
2942
2943       procedure Process_Extended_Import_Export_Internal_Arg
2944         (Arg_Internal : Node_Id := Empty)
2945       is
2946       begin
2947          if No (Arg_Internal) then
2948             Error_Pragma ("Internal parameter required for pragma%");
2949          end if;
2950
2951          if Nkind (Arg_Internal) = N_Identifier then
2952             null;
2953
2954          elsif Nkind (Arg_Internal) = N_Operator_Symbol
2955            and then (Prag_Id = Pragma_Import_Function
2956                        or else
2957                      Prag_Id = Pragma_Export_Function)
2958          then
2959             null;
2960
2961          else
2962             Error_Pragma_Arg
2963               ("wrong form for Internal parameter for pragma%", Arg_Internal);
2964          end if;
2965
2966          Check_Arg_Is_Local_Name (Arg_Internal);
2967       end Process_Extended_Import_Export_Internal_Arg;
2968
2969       --------------------------------------------------
2970       -- Process_Extended_Import_Export_Object_Pragma --
2971       --------------------------------------------------
2972
2973       procedure Process_Extended_Import_Export_Object_Pragma
2974         (Arg_Internal : Node_Id;
2975          Arg_External : Node_Id;
2976          Arg_Size     : Node_Id)
2977       is
2978          Def_Id : Entity_Id;
2979
2980       begin
2981          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2982          Def_Id := Entity (Arg_Internal);
2983
2984          if not Ekind_In (Def_Id, E_Constant, E_Variable) then
2985             Error_Pragma_Arg
2986               ("pragma% must designate an object", Arg_Internal);
2987          end if;
2988
2989          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2990               or else
2991             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2992          then
2993             Error_Pragma_Arg
2994               ("previous Common/Psect_Object applies, pragma % not permitted",
2995                Arg_Internal);
2996          end if;
2997
2998          if Rep_Item_Too_Late (Def_Id, N) then
2999             raise Pragma_Exit;
3000          end if;
3001
3002          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3003
3004          if Present (Arg_Size) then
3005             Check_Arg_Is_External_Name (Arg_Size);
3006          end if;
3007
3008          --  Export_Object case
3009
3010          if Prag_Id = Pragma_Export_Object then
3011             if not Is_Library_Level_Entity (Def_Id) then
3012                Error_Pragma_Arg
3013                  ("argument for pragma% must be library level entity",
3014                   Arg_Internal);
3015             end if;
3016
3017             if Ekind (Current_Scope) = E_Generic_Package then
3018                Error_Pragma ("pragma& cannot appear in a generic unit");
3019             end if;
3020
3021             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3022                Error_Pragma_Arg
3023                  ("exported object must have compile time known size",
3024                   Arg_Internal);
3025             end if;
3026
3027             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3028                Error_Msg_N ("?duplicate Export_Object pragma", N);
3029             else
3030                Set_Exported (Def_Id, Arg_Internal);
3031             end if;
3032
3033          --  Import_Object case
3034
3035          else
3036             if Is_Concurrent_Type (Etype (Def_Id)) then
3037                Error_Pragma_Arg
3038                  ("cannot use pragma% for task/protected object",
3039                   Arg_Internal);
3040             end if;
3041
3042             if Ekind (Def_Id) = E_Constant then
3043                Error_Pragma_Arg
3044                  ("cannot import a constant", Arg_Internal);
3045             end if;
3046
3047             if Warn_On_Export_Import
3048               and then Has_Discriminants (Etype (Def_Id))
3049             then
3050                Error_Msg_N
3051                  ("imported value must be initialized?", Arg_Internal);
3052             end if;
3053
3054             if Warn_On_Export_Import
3055               and then Is_Access_Type (Etype (Def_Id))
3056             then
3057                Error_Pragma_Arg
3058                  ("cannot import object of an access type?", Arg_Internal);
3059             end if;
3060
3061             if Warn_On_Export_Import
3062               and then Is_Imported (Def_Id)
3063             then
3064                Error_Msg_N
3065                  ("?duplicate Import_Object pragma", N);
3066
3067             --  Check for explicit initialization present. Note that an
3068             --  initialization generated by the code generator, e.g. for an
3069             --  access type, does not count here.
3070
3071             elsif Present (Expression (Parent (Def_Id)))
3072                and then
3073                  Comes_From_Source
3074                    (Original_Node (Expression (Parent (Def_Id))))
3075             then
3076                Error_Msg_Sloc := Sloc (Def_Id);
3077                Error_Pragma_Arg
3078                  ("imported entities cannot be initialized (RM B.1(24))",
3079                   "\no initialization allowed for & declared#", Arg1);
3080             else
3081                Set_Imported (Def_Id);
3082                Note_Possible_Modification (Arg_Internal, Sure => False);
3083             end if;
3084          end if;
3085       end Process_Extended_Import_Export_Object_Pragma;
3086
3087       ------------------------------------------------------
3088       -- Process_Extended_Import_Export_Subprogram_Pragma --
3089       ------------------------------------------------------
3090
3091       procedure Process_Extended_Import_Export_Subprogram_Pragma
3092         (Arg_Internal                 : Node_Id;
3093          Arg_External                 : Node_Id;
3094          Arg_Parameter_Types          : Node_Id;
3095          Arg_Result_Type              : Node_Id := Empty;
3096          Arg_Mechanism                : Node_Id;
3097          Arg_Result_Mechanism         : Node_Id := Empty;
3098          Arg_First_Optional_Parameter : Node_Id := Empty)
3099       is
3100          Ent       : Entity_Id;
3101          Def_Id    : Entity_Id;
3102          Hom_Id    : Entity_Id;
3103          Formal    : Entity_Id;
3104          Ambiguous : Boolean;
3105          Match     : Boolean;
3106          Dval      : Node_Id;
3107
3108          function Same_Base_Type
3109           (Ptype  : Node_Id;
3110            Formal : Entity_Id) return Boolean;
3111          --  Determines if Ptype references the type of Formal. Note that only
3112          --  the base types need to match according to the spec. Ptype here is
3113          --  the argument from the pragma, which is either a type name, or an
3114          --  access attribute.
3115
3116          --------------------
3117          -- Same_Base_Type --
3118          --------------------
3119
3120          function Same_Base_Type
3121            (Ptype  : Node_Id;
3122             Formal : Entity_Id) return Boolean
3123          is
3124             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3125             Pref : Node_Id;
3126
3127          begin
3128             --  Case where pragma argument is typ'Access
3129
3130             if Nkind (Ptype) = N_Attribute_Reference
3131               and then Attribute_Name (Ptype) = Name_Access
3132             then
3133                Pref := Prefix (Ptype);
3134                Find_Type (Pref);
3135
3136                if not Is_Entity_Name (Pref)
3137                  or else Entity (Pref) = Any_Type
3138                then
3139                   raise Pragma_Exit;
3140                end if;
3141
3142                --  We have a match if the corresponding argument is of an
3143                --  anonymous access type, and its designated type matches the
3144                --  type of the prefix of the access attribute
3145
3146                return Ekind (Ftyp) = E_Anonymous_Access_Type
3147                  and then Base_Type (Entity (Pref)) =
3148                             Base_Type (Etype (Designated_Type (Ftyp)));
3149
3150             --  Case where pragma argument is a type name
3151
3152             else
3153                Find_Type (Ptype);
3154
3155                if not Is_Entity_Name (Ptype)
3156                  or else Entity (Ptype) = Any_Type
3157                then
3158                   raise Pragma_Exit;
3159                end if;
3160
3161                --  We have a match if the corresponding argument is of the type
3162                --  given in the pragma (comparing base types)
3163
3164                return Base_Type (Entity (Ptype)) = Ftyp;
3165             end if;
3166          end Same_Base_Type;
3167
3168       --  Start of processing for
3169       --  Process_Extended_Import_Export_Subprogram_Pragma
3170
3171       begin
3172          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3173          Ent := Empty;
3174          Ambiguous := False;
3175
3176          --  Loop through homonyms (overloadings) of the entity
3177
3178          Hom_Id := Entity (Arg_Internal);
3179          while Present (Hom_Id) loop
3180             Def_Id := Get_Base_Subprogram (Hom_Id);
3181
3182             --  We need a subprogram in the current scope
3183
3184             if not Is_Subprogram (Def_Id)
3185               or else Scope (Def_Id) /= Current_Scope
3186             then
3187                null;
3188
3189             else
3190                Match := True;
3191
3192                --  Pragma cannot apply to subprogram body
3193
3194                if Is_Subprogram (Def_Id)
3195                  and then Nkind (Parent (Declaration_Node (Def_Id))) =
3196                                                              N_Subprogram_Body
3197                then
3198                   Error_Pragma
3199                     ("pragma% requires separate spec"
3200                       & " and must come before body");
3201                end if;
3202
3203                --  Test result type if given, note that the result type
3204                --  parameter can only be present for the function cases.
3205
3206                if Present (Arg_Result_Type)
3207                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3208                then
3209                   Match := False;
3210
3211                elsif Etype (Def_Id) /= Standard_Void_Type
3212                  and then
3213                    (Pname = Name_Export_Procedure
3214                       or else
3215                     Pname = Name_Import_Procedure)
3216                then
3217                   Match := False;
3218
3219                --  Test parameter types if given. Note that this parameter
3220                --  has not been analyzed (and must not be, since it is
3221                --  semantic nonsense), so we get it as the parser left it.
3222
3223                elsif Present (Arg_Parameter_Types) then
3224                   Check_Matching_Types : declare
3225                      Formal : Entity_Id;
3226                      Ptype  : Node_Id;
3227
3228                   begin
3229                      Formal := First_Formal (Def_Id);
3230
3231                      if Nkind (Arg_Parameter_Types) = N_Null then
3232                         if Present (Formal) then
3233                            Match := False;
3234                         end if;
3235
3236                      --  A list of one type, e.g. (List) is parsed as
3237                      --  a parenthesized expression.
3238
3239                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3240                        and then Paren_Count (Arg_Parameter_Types) = 1
3241                      then
3242                         if No (Formal)
3243                           or else Present (Next_Formal (Formal))
3244                         then
3245                            Match := False;
3246                         else
3247                            Match :=
3248                              Same_Base_Type (Arg_Parameter_Types, Formal);
3249                         end if;
3250
3251                      --  A list of more than one type is parsed as a aggregate
3252
3253                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3254                        and then Paren_Count (Arg_Parameter_Types) = 0
3255                      then
3256                         Ptype := First (Expressions (Arg_Parameter_Types));
3257                         while Present (Ptype) or else Present (Formal) loop
3258                            if No (Ptype)
3259                              or else No (Formal)
3260                              or else not Same_Base_Type (Ptype, Formal)
3261                            then
3262                               Match := False;
3263                               exit;
3264                            else
3265                               Next_Formal (Formal);
3266                               Next (Ptype);
3267                            end if;
3268                         end loop;
3269
3270                      --  Anything else is of the wrong form
3271
3272                      else
3273                         Error_Pragma_Arg
3274                           ("wrong form for Parameter_Types parameter",
3275                            Arg_Parameter_Types);
3276                      end if;
3277                   end Check_Matching_Types;
3278                end if;
3279
3280                --  Match is now False if the entry we found did not match
3281                --  either a supplied Parameter_Types or Result_Types argument
3282
3283                if Match then
3284                   if No (Ent) then
3285                      Ent := Def_Id;
3286
3287                   --  Ambiguous case, the flag Ambiguous shows if we already
3288                   --  detected this and output the initial messages.
3289
3290                   else
3291                      if not Ambiguous then
3292                         Ambiguous := True;
3293                         Error_Msg_Name_1 := Pname;
3294                         Error_Msg_N
3295                           ("pragma% does not uniquely identify subprogram!",
3296                            N);
3297                         Error_Msg_Sloc := Sloc (Ent);
3298                         Error_Msg_N ("matching subprogram #!", N);
3299                         Ent := Empty;
3300                      end if;
3301
3302                      Error_Msg_Sloc := Sloc (Def_Id);
3303                      Error_Msg_N ("matching subprogram #!", N);
3304                   end if;
3305                end if;
3306             end if;
3307
3308             Hom_Id := Homonym (Hom_Id);
3309          end loop;
3310
3311          --  See if we found an entry
3312
3313          if No (Ent) then
3314             if not Ambiguous then
3315                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3316                   Error_Pragma
3317                     ("pragma% cannot be given for generic subprogram");
3318                else
3319                   Error_Pragma
3320                     ("pragma% does not identify local subprogram");
3321                end if;
3322             end if;
3323
3324             return;
3325          end if;
3326
3327          --  Import pragmas must be for imported entities
3328
3329          if Prag_Id = Pragma_Import_Function
3330               or else
3331             Prag_Id = Pragma_Import_Procedure
3332               or else
3333             Prag_Id = Pragma_Import_Valued_Procedure
3334          then
3335             if not Is_Imported (Ent) then
3336                Error_Pragma
3337                  ("pragma Import or Interface must precede pragma%");
3338             end if;
3339
3340          --  Here we have the Export case which can set the entity as exported
3341
3342          --  But does not do so if the specified external name is null, since
3343          --  that is taken as a signal in DEC Ada 83 (with which we want to be
3344          --  compatible) to request no external name.
3345
3346          elsif Nkind (Arg_External) = N_String_Literal
3347            and then String_Length (Strval (Arg_External)) = 0
3348          then
3349             null;
3350
3351          --  In all other cases, set entity as exported
3352
3353          else
3354             Set_Exported (Ent, Arg_Internal);
3355          end if;
3356
3357          --  Special processing for Valued_Procedure cases
3358
3359          if Prag_Id = Pragma_Import_Valued_Procedure
3360            or else
3361             Prag_Id = Pragma_Export_Valued_Procedure
3362          then
3363             Formal := First_Formal (Ent);
3364
3365             if No (Formal) then
3366                Error_Pragma ("at least one parameter required for pragma%");
3367
3368             elsif Ekind (Formal) /= E_Out_Parameter then
3369                Error_Pragma ("first parameter must have mode out for pragma%");
3370
3371             else
3372                Set_Is_Valued_Procedure (Ent);
3373             end if;
3374          end if;
3375
3376          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3377
3378          --  Process Result_Mechanism argument if present. We have already
3379          --  checked that this is only allowed for the function case.
3380
3381          if Present (Arg_Result_Mechanism) then
3382             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3383          end if;
3384
3385          --  Process Mechanism parameter if present. Note that this parameter
3386          --  is not analyzed, and must not be analyzed since it is semantic
3387          --  nonsense, so we get it in exactly as the parser left it.
3388
3389          if Present (Arg_Mechanism) then
3390             declare
3391                Formal : Entity_Id;
3392                Massoc : Node_Id;
3393                Mname  : Node_Id;
3394                Choice : Node_Id;
3395
3396             begin
3397                --  A single mechanism association without a formal parameter
3398                --  name is parsed as a parenthesized expression. All other
3399                --  cases are parsed as aggregates, so we rewrite the single
3400                --  parameter case as an aggregate for consistency.
3401
3402                if Nkind (Arg_Mechanism) /= N_Aggregate
3403                  and then Paren_Count (Arg_Mechanism) = 1
3404                then
3405                   Rewrite (Arg_Mechanism,
3406                     Make_Aggregate (Sloc (Arg_Mechanism),
3407                       Expressions => New_List (
3408                         Relocate_Node (Arg_Mechanism))));
3409                end if;
3410
3411                --  Case of only mechanism name given, applies to all formals
3412
3413                if Nkind (Arg_Mechanism) /= N_Aggregate then
3414                   Formal := First_Formal (Ent);
3415                   while Present (Formal) loop
3416                      Set_Mechanism_Value (Formal, Arg_Mechanism);
3417                      Next_Formal (Formal);
3418                   end loop;
3419
3420                --  Case of list of mechanism associations given
3421
3422                else
3423                   if Null_Record_Present (Arg_Mechanism) then
3424                      Error_Pragma_Arg
3425                        ("inappropriate form for Mechanism parameter",
3426                         Arg_Mechanism);
3427                   end if;
3428
3429                   --  Deal with positional ones first
3430
3431                   Formal := First_Formal (Ent);
3432
3433                   if Present (Expressions (Arg_Mechanism)) then
3434                      Mname := First (Expressions (Arg_Mechanism));
3435                      while Present (Mname) loop
3436                         if No (Formal) then
3437                            Error_Pragma_Arg
3438                              ("too many mechanism associations", Mname);
3439                         end if;
3440
3441                         Set_Mechanism_Value (Formal, Mname);
3442                         Next_Formal (Formal);
3443                         Next (Mname);
3444                      end loop;
3445                   end if;
3446
3447                   --  Deal with named entries
3448
3449                   if Present (Component_Associations (Arg_Mechanism)) then
3450                      Massoc := First (Component_Associations (Arg_Mechanism));
3451                      while Present (Massoc) loop
3452                         Choice := First (Choices (Massoc));
3453
3454                         if Nkind (Choice) /= N_Identifier
3455                           or else Present (Next (Choice))
3456                         then
3457                            Error_Pragma_Arg
3458                              ("incorrect form for mechanism association",
3459                               Massoc);
3460                         end if;
3461
3462                         Formal := First_Formal (Ent);
3463                         loop
3464                            if No (Formal) then
3465                               Error_Pragma_Arg
3466                                 ("parameter name & not present", Choice);
3467                            end if;
3468
3469                            if Chars (Choice) = Chars (Formal) then
3470                               Set_Mechanism_Value
3471                                 (Formal, Expression (Massoc));
3472
3473                               --  Set entity on identifier for ASIS
3474
3475                               Set_Entity (Choice, Formal);
3476
3477                               exit;
3478                            end if;
3479
3480                            Next_Formal (Formal);
3481                         end loop;
3482
3483                         Next (Massoc);
3484                      end loop;
3485                   end if;
3486                end if;
3487             end;
3488          end if;
3489
3490          --  Process First_Optional_Parameter argument if present. We have
3491          --  already checked that this is only allowed for the Import case.
3492
3493          if Present (Arg_First_Optional_Parameter) then
3494             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3495                Error_Pragma_Arg
3496                  ("first optional parameter must be formal parameter name",
3497                   Arg_First_Optional_Parameter);
3498             end if;
3499
3500             Formal := First_Formal (Ent);
3501             loop
3502                if No (Formal) then
3503                   Error_Pragma_Arg
3504                     ("specified formal parameter& not found",
3505                      Arg_First_Optional_Parameter);
3506                end if;
3507
3508                exit when Chars (Formal) =
3509                          Chars (Arg_First_Optional_Parameter);
3510
3511                Next_Formal (Formal);
3512             end loop;
3513
3514             Set_First_Optional_Parameter (Ent, Formal);
3515
3516             --  Check specified and all remaining formals have right form
3517
3518             while Present (Formal) loop
3519                if Ekind (Formal) /= E_In_Parameter then
3520                   Error_Msg_NE
3521                     ("optional formal& is not of mode in!",
3522                      Arg_First_Optional_Parameter, Formal);
3523
3524                else
3525                   Dval := Default_Value (Formal);
3526
3527                   if No (Dval) then
3528                      Error_Msg_NE
3529                        ("optional formal& does not have default value!",
3530                         Arg_First_Optional_Parameter, Formal);
3531
3532                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3533                      null;
3534
3535                   else
3536                      Error_Msg_FE
3537                        ("default value for optional formal& is non-static!",
3538                         Arg_First_Optional_Parameter, Formal);
3539                   end if;
3540                end if;
3541
3542                Set_Is_Optional_Parameter (Formal);
3543                Next_Formal (Formal);
3544             end loop;
3545          end if;
3546       end Process_Extended_Import_Export_Subprogram_Pragma;
3547
3548       --------------------------
3549       -- Process_Generic_List --
3550       --------------------------
3551
3552       procedure Process_Generic_List is
3553          Arg : Node_Id;
3554          Exp : Node_Id;
3555
3556       begin
3557          Check_No_Identifiers;
3558          Check_At_Least_N_Arguments (1);
3559
3560          Arg := Arg1;
3561          while Present (Arg) loop
3562             Exp := Expression (Arg);
3563             Analyze (Exp);
3564
3565             if not Is_Entity_Name (Exp)
3566               or else
3567                 (not Is_Generic_Instance (Entity (Exp))
3568                   and then
3569                  not Is_Generic_Unit (Entity (Exp)))
3570             then
3571                Error_Pragma_Arg
3572                  ("pragma% argument must be name of generic unit/instance",
3573                   Arg);
3574             end if;
3575
3576             Next (Arg);
3577          end loop;
3578       end Process_Generic_List;
3579
3580       ---------------------------------
3581       -- Process_Import_Or_Interface --
3582       ---------------------------------
3583
3584       procedure Process_Import_Or_Interface is
3585          C      : Convention_Id;
3586          Def_Id : Entity_Id;
3587          Hom_Id : Entity_Id;
3588
3589       begin
3590          Process_Convention (C, Def_Id);
3591          Kill_Size_Check_Code (Def_Id);
3592          Note_Possible_Modification (Expression (Arg2), Sure => False);
3593
3594          if Ekind_In (Def_Id, E_Variable, E_Constant) then
3595
3596             --  We do not permit Import to apply to a renaming declaration
3597
3598             if Present (Renamed_Object (Def_Id)) then
3599                Error_Pragma_Arg
3600                  ("pragma% not allowed for object renaming", Arg2);
3601
3602             --  User initialization is not allowed for imported object, but
3603             --  the object declaration may contain a default initialization,
3604             --  that will be discarded. Note that an explicit initialization
3605             --  only counts if it comes from source, otherwise it is simply
3606             --  the code generator making an implicit initialization explicit.
3607
3608             elsif Present (Expression (Parent (Def_Id)))
3609               and then Comes_From_Source (Expression (Parent (Def_Id)))
3610             then
3611                Error_Msg_Sloc := Sloc (Def_Id);
3612                Error_Pragma_Arg
3613                  ("no initialization allowed for declaration of& #",
3614                   "\imported entities cannot be initialized (RM B.1(24))",
3615                   Arg2);
3616
3617             else
3618                Set_Imported (Def_Id);
3619                Process_Interface_Name (Def_Id, Arg3, Arg4);
3620
3621                --  Note that we do not set Is_Public here. That's because we
3622                --  only want to set it if there is no address clause, and we
3623                --  don't know that yet, so we delay that processing till
3624                --  freeze time.
3625
3626                --  pragma Import completes deferred constants
3627
3628                if Ekind (Def_Id) = E_Constant then
3629                   Set_Has_Completion (Def_Id);
3630                end if;
3631
3632                --  It is not possible to import a constant of an unconstrained
3633                --  array type (e.g. string) because there is no simple way to
3634                --  write a meaningful subtype for it.
3635
3636                if Is_Array_Type (Etype (Def_Id))
3637                  and then not Is_Constrained (Etype (Def_Id))
3638                then
3639                   Error_Msg_NE
3640                     ("imported constant& must have a constrained subtype",
3641                       N, Def_Id);
3642                end if;
3643             end if;
3644
3645          elsif Is_Subprogram (Def_Id)
3646            or else Is_Generic_Subprogram (Def_Id)
3647          then
3648             --  If the name is overloaded, pragma applies to all of the
3649             --  denoted entities in the same declarative part.
3650
3651             Hom_Id := Def_Id;
3652             while Present (Hom_Id) loop
3653                Def_Id := Get_Base_Subprogram (Hom_Id);
3654
3655                --  Ignore inherited subprograms because the pragma will
3656                --  apply to the parent operation, which is the one called.
3657
3658                if Is_Overloadable (Def_Id)
3659                  and then Present (Alias (Def_Id))
3660                then
3661                   null;
3662
3663                --  If it is not a subprogram, it must be in an outer scope and
3664                --  pragma does not apply.
3665
3666                elsif not Is_Subprogram (Def_Id)
3667                  and then not Is_Generic_Subprogram (Def_Id)
3668                then
3669                   null;
3670
3671                --  Verify that the homonym is in the same declarative part (not
3672                --  just the same scope).
3673
3674                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3675                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3676                then
3677                   exit;
3678
3679                else
3680                   Set_Imported (Def_Id);
3681
3682                   --  Reject an Import applied to an abstract subprogram
3683
3684                   if Is_Subprogram (Def_Id)
3685                     and then Is_Abstract_Subprogram (Def_Id)
3686                   then
3687                      Error_Msg_Sloc := Sloc (Def_Id);
3688                      Error_Msg_NE
3689                        ("cannot import abstract subprogram& declared#",
3690                         Arg2, Def_Id);
3691                   end if;
3692
3693                   --  Special processing for Convention_Intrinsic
3694
3695                   if C = Convention_Intrinsic then
3696
3697                      --  Link_Name argument not allowed for intrinsic
3698
3699                      if Present (Arg3)
3700                        and then Chars (Arg3) = Name_Link_Name
3701                      then
3702                         Arg4 := Arg3;
3703                      end if;
3704
3705                      if Present (Arg4) then
3706                         Error_Pragma_Arg
3707                           ("Link_Name argument not allowed for " &
3708                            "Import Intrinsic",
3709                            Arg4);
3710                      end if;
3711
3712                      Set_Is_Intrinsic_Subprogram (Def_Id);
3713
3714                      --  If no external name is present, then check that this
3715                      --  is a valid intrinsic subprogram. If an external name
3716                      --  is present, then this is handled by the back end.
3717
3718                      if No (Arg3) then
3719                         Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3720                      end if;
3721                   end if;
3722
3723                   --  All interfaced procedures need an external symbol created
3724                   --  for them since they are always referenced from another
3725                   --  object file.
3726
3727                   Set_Is_Public (Def_Id);
3728
3729                   --  Verify that the subprogram does not have a completion
3730                   --  through a renaming declaration. For other completions the
3731                   --  pragma appears as a too late representation.
3732
3733                   declare
3734                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3735
3736                   begin
3737                      if Present (Decl)
3738                        and then Nkind (Decl) = N_Subprogram_Declaration
3739                        and then Present (Corresponding_Body (Decl))
3740                        and then Nkind (Unit_Declaration_Node
3741                                         (Corresponding_Body (Decl))) =
3742                                              N_Subprogram_Renaming_Declaration
3743                      then
3744                         Error_Msg_Sloc := Sloc (Def_Id);
3745                         Error_Msg_NE
3746                           ("cannot import&, renaming already provided for " &
3747                            "declaration #", N, Def_Id);
3748                      end if;
3749                   end;
3750
3751                   Set_Has_Completion (Def_Id);
3752                   Process_Interface_Name (Def_Id, Arg3, Arg4);
3753                end if;
3754
3755                if Is_Compilation_Unit (Hom_Id) then
3756
3757                   --  Its possible homonyms are not affected by the pragma.
3758                   --  Such homonyms might be present in the context of other
3759                   --  units being compiled.
3760
3761                   exit;
3762
3763                else
3764                   Hom_Id := Homonym (Hom_Id);
3765                end if;
3766             end loop;
3767
3768          --  When the convention is Java or CIL, we also allow Import to be
3769          --  given for packages, generic packages, exceptions, record
3770          --  components, and access to subprograms.
3771
3772          elsif (C = Convention_Java or else C = Convention_CIL)
3773            and then
3774              (Is_Package_Or_Generic_Package (Def_Id)
3775                or else Ekind (Def_Id) = E_Exception
3776                or else Ekind (Def_Id) = E_Access_Subprogram_Type
3777                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3778          then
3779             Set_Imported (Def_Id);
3780             Set_Is_Public (Def_Id);
3781             Process_Interface_Name (Def_Id, Arg3, Arg4);
3782
3783          --  Import a CPP class
3784
3785          elsif Is_Record_Type (Def_Id)
3786            and then C = Convention_CPP
3787          then
3788             --  Types treated as CPP classes are treated as limited, but we
3789             --  don't require them to be declared this way. A warning is
3790             --  issued to encourage the user to declare them as limited.
3791             --  This is not an error, for compatibility reasons, because
3792             --  these types have been supported this way for some time.
3793
3794             if not Is_Limited_Type (Def_Id) then
3795                Error_Msg_N
3796                  ("imported 'C'P'P type should be " &
3797                     "explicitly declared limited?",
3798                   Get_Pragma_Arg (Arg2));
3799                Error_Msg_N
3800                  ("\type will be considered limited",
3801                   Get_Pragma_Arg (Arg2));
3802             end if;
3803
3804             Set_Is_CPP_Class (Def_Id);
3805             Set_Is_Limited_Record (Def_Id);
3806
3807             --  Imported CPP types must not have discriminants (because C++
3808             --  classes do not have discriminants).
3809
3810             if Has_Discriminants (Def_Id) then
3811                Error_Msg_N
3812                  ("imported 'C'P'P type cannot have discriminants",
3813                   First (Discriminant_Specifications
3814                           (Declaration_Node (Def_Id))));
3815             end if;
3816
3817             --  Components of imported CPP types must not have default
3818             --  expressions because the constructor (if any) is on the
3819             --  C++ side.
3820
3821             declare
3822                Tdef  : constant Node_Id :=
3823                          Type_Definition (Declaration_Node (Def_Id));
3824                Clist : Node_Id;
3825                Comp  : Node_Id;
3826
3827             begin
3828                if Nkind (Tdef) = N_Record_Definition then
3829                   Clist := Component_List (Tdef);
3830
3831                else
3832                   pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
3833                   Clist := Component_List (Record_Extension_Part (Tdef));
3834                end if;
3835
3836                if Present (Clist) then
3837                   Comp := First (Component_Items (Clist));
3838                   while Present (Comp) loop
3839                      if Present (Expression (Comp)) then
3840                         Error_Msg_N
3841                           ("component of imported 'C'P'P type cannot have" &
3842                            " default expression", Expression (Comp));
3843                      end if;
3844
3845                      Next (Comp);
3846                   end loop;
3847                end if;
3848             end;
3849
3850          else
3851             Error_Pragma_Arg
3852               ("second argument of pragma% must be object or subprogram",
3853                Arg2);
3854          end if;
3855
3856          --  If this pragma applies to a compilation unit, then the unit, which
3857          --  is a subprogram, does not require (or allow) a body. We also do
3858          --  not need to elaborate imported procedures.
3859
3860          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3861             declare
3862                Cunit : constant Node_Id := Parent (Parent (N));
3863             begin
3864                Set_Body_Required (Cunit, False);
3865             end;
3866          end if;
3867       end Process_Import_Or_Interface;
3868
3869       --------------------
3870       -- Process_Inline --
3871       --------------------
3872
3873       procedure Process_Inline (Active : Boolean) is
3874          Assoc     : Node_Id;
3875          Decl      : Node_Id;
3876          Subp_Id   : Node_Id;
3877          Subp      : Entity_Id;
3878          Applies   : Boolean;
3879          Effective : Boolean := False;
3880
3881          procedure Make_Inline (Subp : Entity_Id);
3882          --  Subp is the defining unit name of the subprogram declaration. Set
3883          --  the flag, as well as the flag in the corresponding body, if there
3884          --  is one present.
3885
3886          procedure Set_Inline_Flags (Subp : Entity_Id);
3887          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3888          --  Has_Pragma_Inline_Always for the Inline_Always case.
3889
3890          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3891          --  Returns True if it can be determined at this stage that inlining
3892          --  is not possible, for example if the body is available and contains
3893          --  exception handlers, we prevent inlining, since otherwise we can
3894          --  get undefined symbols at link time. This function also emits a
3895          --  warning if front-end inlining is enabled and the pragma appears
3896          --  too late.
3897          --
3898          --  ??? is business with link symbols still valid, or does it relate
3899          --  to front end ZCX which is being phased out ???
3900
3901          ---------------------------
3902          -- Inlining_Not_Possible --
3903          ---------------------------
3904
3905          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3906             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
3907             Stats : Node_Id;
3908
3909          begin
3910             if Nkind (Decl) = N_Subprogram_Body then
3911                Stats := Handled_Statement_Sequence (Decl);
3912                return Present (Exception_Handlers (Stats))
3913                  or else Present (At_End_Proc (Stats));
3914
3915             elsif Nkind (Decl) = N_Subprogram_Declaration
3916               and then Present (Corresponding_Body (Decl))
3917             then
3918                if Front_End_Inlining
3919                  and then Analyzed (Corresponding_Body (Decl))
3920                then
3921                   Error_Msg_N ("pragma appears too late, ignored?", N);
3922                   return True;
3923
3924                --  If the subprogram is a renaming as body, the body is just a
3925                --  call to the renamed subprogram, and inlining is trivially
3926                --  possible.
3927
3928                elsif
3929                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3930                                              N_Subprogram_Renaming_Declaration
3931                then
3932                   return False;
3933
3934                else
3935                   Stats :=
3936                     Handled_Statement_Sequence
3937                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
3938
3939                   return
3940                     Present (Exception_Handlers (Stats))
3941                       or else Present (At_End_Proc (Stats));
3942                end if;
3943
3944             else
3945                --  If body is not available, assume the best, the check is
3946                --  performed again when compiling enclosing package bodies.
3947
3948                return False;
3949             end if;
3950          end Inlining_Not_Possible;
3951
3952          -----------------
3953          -- Make_Inline --
3954          -----------------
3955
3956          procedure Make_Inline (Subp : Entity_Id) is
3957             Kind       : constant Entity_Kind := Ekind (Subp);
3958             Inner_Subp : Entity_Id   := Subp;
3959
3960          begin
3961             --  Ignore if bad type, avoid cascaded error
3962
3963             if Etype (Subp) = Any_Type then
3964                Applies := True;
3965                return;
3966
3967             --  Ignore if all inlining is suppressed
3968
3969             elsif Suppress_All_Inlining then
3970                Applies := True;
3971                return;
3972
3973             --  If inlining is not possible, for now do not treat as an error
3974
3975             elsif Inlining_Not_Possible (Subp) then
3976                Applies := True;
3977                return;
3978
3979             --  Here we have a candidate for inlining, but we must exclude
3980             --  derived operations. Otherwise we would end up trying to inline
3981             --  a phantom declaration, and the result would be to drag in a
3982             --  body which has no direct inlining associated with it. That
3983             --  would not only be inefficient but would also result in the
3984             --  backend doing cross-unit inlining in cases where it was
3985             --  definitely inappropriate to do so.
3986
3987             --  However, a simple Comes_From_Source test is insufficient, since
3988             --  we do want to allow inlining of generic instances which also do
3989             --  not come from source. We also need to recognize specs generated
3990             --  by the front-end for bodies that carry the pragma. Finally,
3991             --  predefined operators do not come from source but are not
3992             --  inlineable either.
3993
3994             elsif Is_Generic_Instance (Subp)
3995               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3996             then
3997                null;
3998
3999             elsif not Comes_From_Source (Subp)
4000               and then Scope (Subp) /= Standard_Standard
4001             then
4002                Applies := True;
4003                return;
4004             end if;
4005
4006             --  The referenced entity must either be the enclosing entity, or
4007             --  an entity declared within the current open scope.
4008
4009             if Present (Scope (Subp))
4010               and then Scope (Subp) /= Current_Scope
4011               and then Subp /= Current_Scope
4012             then
4013                Error_Pragma_Arg
4014                  ("argument of% must be entity in current scope", Assoc);
4015                return;
4016             end if;
4017
4018             --  Processing for procedure, operator or function. If subprogram
4019             --  is aliased (as for an instance) indicate that the renamed
4020             --  entity (if declared in the same unit) is inlined.
4021
4022             if Is_Subprogram (Subp) then
4023                Inner_Subp := Ultimate_Alias (Inner_Subp);
4024
4025                if In_Same_Source_Unit (Subp, Inner_Subp) then
4026                   Set_Inline_Flags (Inner_Subp);
4027
4028                   Decl := Parent (Parent (Inner_Subp));
4029
4030                   if Nkind (Decl) = N_Subprogram_Declaration
4031                     and then Present (Corresponding_Body (Decl))
4032                   then
4033                      Set_Inline_Flags (Corresponding_Body (Decl));
4034
4035                   elsif Is_Generic_Instance (Subp) then
4036
4037                      --  Indicate that the body needs to be created for
4038                      --  inlining subsequent calls. The instantiation node
4039                      --  follows the declaration of the wrapper package
4040                      --  created for it.
4041
4042                      if Scope (Subp) /= Standard_Standard
4043                        and then
4044                          Need_Subprogram_Instance_Body
4045                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4046                               Subp)
4047                      then
4048                         null;
4049                      end if;
4050                   end if;
4051                end if;
4052
4053                Applies := True;
4054
4055             --  For a generic subprogram set flag as well, for use at the point
4056             --  of instantiation, to determine whether the body should be
4057             --  generated.
4058
4059             elsif Is_Generic_Subprogram (Subp) then
4060                Set_Inline_Flags (Subp);
4061                Applies := True;
4062
4063             --  Literals are by definition inlined
4064
4065             elsif Kind = E_Enumeration_Literal then
4066                null;
4067
4068             --  Anything else is an error
4069
4070             else
4071                Error_Pragma_Arg
4072                  ("expect subprogram name for pragma%", Assoc);
4073             end if;
4074          end Make_Inline;
4075
4076          ----------------------
4077          -- Set_Inline_Flags --
4078          ----------------------
4079
4080          procedure Set_Inline_Flags (Subp : Entity_Id) is
4081          begin
4082             if Active then
4083                Set_Is_Inlined (Subp, True);
4084             end if;
4085
4086             if not Has_Pragma_Inline (Subp) then
4087                Set_Has_Pragma_Inline (Subp);
4088                Effective := True;
4089             end if;
4090
4091             if Prag_Id = Pragma_Inline_Always then
4092                Set_Has_Pragma_Inline_Always (Subp);
4093             end if;
4094          end Set_Inline_Flags;
4095
4096       --  Start of processing for Process_Inline
4097
4098       begin
4099          Check_No_Identifiers;
4100          Check_At_Least_N_Arguments (1);
4101
4102          if Active then
4103             Inline_Processing_Required := True;
4104          end if;
4105
4106          Assoc := Arg1;
4107          while Present (Assoc) loop
4108             Subp_Id := Expression (Assoc);
4109             Analyze (Subp_Id);
4110             Applies := False;
4111
4112             if Is_Entity_Name (Subp_Id) then
4113                Subp := Entity (Subp_Id);
4114
4115                if Subp = Any_Id then
4116
4117                   --  If previous error, avoid cascaded errors
4118
4119                   Applies := True;
4120                   Effective := True;
4121
4122                else
4123                   Make_Inline (Subp);
4124
4125                   while Present (Homonym (Subp))
4126                     and then Scope (Homonym (Subp)) = Current_Scope
4127                   loop
4128                      Make_Inline (Homonym (Subp));
4129                      Subp := Homonym (Subp);
4130                   end loop;
4131                end if;
4132             end if;
4133
4134             if not Applies then
4135                Error_Pragma_Arg
4136                  ("inappropriate argument for pragma%", Assoc);
4137
4138             elsif not Effective
4139               and then Warn_On_Redundant_Constructs
4140               and then not Suppress_All_Inlining
4141             then
4142                if Inlining_Not_Possible (Subp) then
4143                   Error_Msg_NE
4144                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4145                else
4146                   Error_Msg_NE
4147                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4148                end if;
4149             end if;
4150
4151             Next (Assoc);
4152          end loop;
4153       end Process_Inline;
4154
4155       ----------------------------
4156       -- Process_Interface_Name --
4157       ----------------------------
4158
4159       procedure Process_Interface_Name
4160         (Subprogram_Def : Entity_Id;
4161          Ext_Arg        : Node_Id;
4162          Link_Arg       : Node_Id)
4163       is
4164          Ext_Nam    : Node_Id;
4165          Link_Nam   : Node_Id;
4166          String_Val : String_Id;
4167
4168          procedure Check_Form_Of_Interface_Name
4169            (SN            : Node_Id;
4170             Ext_Name_Case : Boolean);
4171          --  SN is a string literal node for an interface name. This routine
4172          --  performs some minimal checks that the name is reasonable. In
4173          --  particular that no spaces or other obviously incorrect characters
4174          --  appear. This is only a warning, since any characters are allowed.
4175          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
4176
4177          ----------------------------------
4178          -- Check_Form_Of_Interface_Name --
4179          ----------------------------------
4180
4181          procedure Check_Form_Of_Interface_Name
4182            (SN            : Node_Id;
4183             Ext_Name_Case : Boolean)
4184          is
4185             S  : constant String_Id := Strval (Expr_Value_S (SN));
4186             SL : constant Nat       := String_Length (S);
4187             C  : Char_Code;
4188
4189          begin
4190             if SL = 0 then
4191                Error_Msg_N ("interface name cannot be null string", SN);
4192             end if;
4193
4194             for J in 1 .. SL loop
4195                C := Get_String_Char (S, J);
4196
4197                --  Look for dubious character and issue unconditional warning.
4198                --  Definitely dubious if not in character range.
4199
4200                if not In_Character_Range (C)
4201
4202                   --  For all cases except CLI target,
4203                   --  commas, spaces and slashes are dubious (in CLI, we use
4204                   --  commas and backslashes in external names to specify
4205                   --  assembly version and public key, while slashes and spaces
4206                   --  can be used in names to mark nested classes and
4207                   --  valuetypes).
4208
4209                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4210                              and then (Get_Character (C) = ','
4211                                          or else
4212                                        Get_Character (C) = '\'))
4213                  or else (VM_Target /= CLI_Target
4214                             and then (Get_Character (C) = ' '
4215                                         or else
4216                                       Get_Character (C) = '/'))
4217                then
4218                   Error_Msg
4219                     ("?interface name contains illegal character",
4220                      Sloc (SN) + Source_Ptr (J));
4221                end if;
4222             end loop;
4223          end Check_Form_Of_Interface_Name;
4224
4225       --  Start of processing for Process_Interface_Name
4226
4227       begin
4228          if No (Link_Arg) then
4229             if No (Ext_Arg) then
4230                if VM_Target = CLI_Target
4231                  and then Ekind (Subprogram_Def) = E_Package
4232                  and then Nkind (Parent (Subprogram_Def)) =
4233                                                  N_Package_Specification
4234                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
4235                then
4236                   Set_Interface_Name
4237                      (Subprogram_Def,
4238                       Interface_Name
4239                         (Generic_Parent (Parent (Subprogram_Def))));
4240                end if;
4241
4242                return;
4243
4244             elsif Chars (Ext_Arg) = Name_Link_Name then
4245                Ext_Nam  := Empty;
4246                Link_Nam := Expression (Ext_Arg);
4247
4248             else
4249                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4250                Ext_Nam  := Expression (Ext_Arg);
4251                Link_Nam := Empty;
4252             end if;
4253
4254          else
4255             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
4256             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4257             Ext_Nam  := Expression (Ext_Arg);
4258             Link_Nam := Expression (Link_Arg);
4259          end if;
4260
4261          --  Check expressions for external name and link name are static
4262
4263          if Present (Ext_Nam) then
4264             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4265             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4266
4267             --  Verify that external name is not the name of a local entity,
4268             --  which would hide the imported one and could lead to run-time
4269             --  surprises. The problem can only arise for entities declared in
4270             --  a package body (otherwise the external name is fully qualified
4271             --  and will not conflict).
4272
4273             declare
4274                Nam : Name_Id;
4275                E   : Entity_Id;
4276                Par : Node_Id;
4277
4278             begin
4279                if Prag_Id = Pragma_Import then
4280                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4281                   Nam := Name_Find;
4282                   E   := Entity_Id (Get_Name_Table_Info (Nam));
4283
4284                   if Nam /= Chars (Subprogram_Def)
4285                     and then Present (E)
4286                     and then not Is_Overloadable (E)
4287                     and then Is_Immediately_Visible (E)
4288                     and then not Is_Imported (E)
4289                     and then Ekind (Scope (E)) = E_Package
4290                   then
4291                      Par := Parent (E);
4292                      while Present (Par) loop
4293                         if Nkind (Par) = N_Package_Body then
4294                            Error_Msg_Sloc := Sloc (E);
4295                            Error_Msg_NE
4296                              ("imported entity is hidden by & declared#",
4297                               Ext_Arg, E);
4298                            exit;
4299                         end if;
4300
4301                         Par := Parent (Par);
4302                      end loop;
4303                   end if;
4304                end if;
4305             end;
4306          end if;
4307
4308          if Present (Link_Nam) then
4309             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4310             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4311          end if;
4312
4313          --  If there is no link name, just set the external name
4314
4315          if No (Link_Nam) then
4316             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4317
4318          --  For the Link_Name case, the given literal is preceded by an
4319          --  asterisk, which indicates to GCC that the given name should be
4320          --  taken literally, and in particular that no prepending of
4321          --  underlines should occur, even in systems where this is the
4322          --  normal default.
4323
4324          else
4325             Start_String;
4326
4327             if VM_Target = No_VM then
4328                Store_String_Char (Get_Char_Code ('*'));
4329             end if;
4330
4331             String_Val := Strval (Expr_Value_S (Link_Nam));
4332             Store_String_Chars (String_Val);
4333             Link_Nam :=
4334               Make_String_Literal (Sloc (Link_Nam),
4335                 Strval => End_String);
4336          end if;
4337
4338          Set_Encoded_Interface_Name
4339            (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4340
4341          --  We allow duplicated export names in CIL, as they are always
4342          --  enclosed in a namespace that differentiates them, and overloaded
4343          --  entities are supported by the VM.
4344
4345          if Convention (Subprogram_Def) /= Convention_CIL then
4346             Check_Duplicated_Export_Name (Link_Nam);
4347          end if;
4348       end Process_Interface_Name;
4349
4350       -----------------------------------------
4351       -- Process_Interrupt_Or_Attach_Handler --
4352       -----------------------------------------
4353
4354       procedure Process_Interrupt_Or_Attach_Handler is
4355          Arg1_X       : constant Node_Id   := Expression (Arg1);
4356          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4357          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
4358
4359       begin
4360          Set_Is_Interrupt_Handler (Handler_Proc);
4361
4362          --  If the pragma is not associated with a handler procedure within a
4363          --  protected type, then it must be for a nonprotected procedure for
4364          --  the AAMP target, in which case we don't associate a representation
4365          --  item with the procedure's scope.
4366
4367          if Ekind (Proc_Scope) = E_Protected_Type then
4368             if Prag_Id = Pragma_Interrupt_Handler
4369                  or else
4370                Prag_Id = Pragma_Attach_Handler
4371             then
4372                Record_Rep_Item (Proc_Scope, N);
4373             end if;
4374          end if;
4375       end Process_Interrupt_Or_Attach_Handler;
4376
4377       --------------------------------------------------
4378       -- Process_Restrictions_Or_Restriction_Warnings --
4379       --------------------------------------------------
4380
4381       --  Note: some of the simple identifier cases were handled in par-prag,
4382       --  but it is harmless (and more straightforward) to simply handle all
4383       --  cases here, even if it means we repeat a bit of work in some cases.
4384
4385       procedure Process_Restrictions_Or_Restriction_Warnings
4386         (Warn : Boolean)
4387       is
4388          Arg   : Node_Id;
4389          R_Id  : Restriction_Id;
4390          Id    : Name_Id;
4391          Expr  : Node_Id;
4392          Val   : Uint;
4393
4394          procedure Check_Unit_Name (N : Node_Id);
4395          --  Checks unit name parameter for No_Dependence. Returns if it has
4396          --  an appropriate form, otherwise raises pragma argument error.
4397
4398          ---------------------
4399          -- Check_Unit_Name --
4400          ---------------------
4401
4402          procedure Check_Unit_Name (N : Node_Id) is
4403          begin
4404             if Nkind (N) = N_Selected_Component then
4405                Check_Unit_Name (Prefix (N));
4406                Check_Unit_Name (Selector_Name (N));
4407
4408             elsif Nkind (N) = N_Identifier then
4409                return;
4410
4411             else
4412                Error_Pragma_Arg
4413                  ("wrong form for unit name for No_Dependence", N);
4414             end if;
4415          end Check_Unit_Name;
4416
4417       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
4418
4419       begin
4420          Check_Ada_83_Warning;
4421          Check_At_Least_N_Arguments (1);
4422          Check_Valid_Configuration_Pragma;
4423
4424          Arg := Arg1;
4425          while Present (Arg) loop
4426             Id := Chars (Arg);
4427             Expr := Expression (Arg);
4428
4429             --  Case of no restriction identifier present
4430
4431             if Id = No_Name then
4432                if Nkind (Expr) /= N_Identifier then
4433                   Error_Pragma_Arg
4434                     ("invalid form for restriction", Arg);
4435                end if;
4436
4437                R_Id :=
4438                  Get_Restriction_Id
4439                    (Process_Restriction_Synonyms (Expr));
4440
4441                if R_Id not in All_Boolean_Restrictions then
4442                   Error_Msg_Name_1 := Pname;
4443                   Error_Msg_N
4444                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4445
4446                   --  Check for possible misspelling
4447
4448                   for J in Restriction_Id loop
4449                      declare
4450                         Rnm : constant String := Restriction_Id'Image (J);
4451
4452                      begin
4453                         Name_Buffer (1 .. Rnm'Length) := Rnm;
4454                         Name_Len := Rnm'Length;
4455                         Set_Casing (All_Lower_Case);
4456
4457                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4458                            Set_Casing
4459                              (Identifier_Casing (Current_Source_File));
4460                            Error_Msg_String (1 .. Rnm'Length) :=
4461                              Name_Buffer (1 .. Name_Len);
4462                            Error_Msg_Strlen := Rnm'Length;
4463                            Error_Msg_N -- CODEFIX
4464                              ("\possible misspelling of ""~""",
4465                               Get_Pragma_Arg (Arg));
4466                            exit;
4467                         end if;
4468                      end;
4469                   end loop;
4470
4471                   raise Pragma_Exit;
4472                end if;
4473
4474                if Implementation_Restriction (R_Id) then
4475                   Check_Restriction (No_Implementation_Restrictions, Arg);
4476                end if;
4477
4478                --  If this is a warning, then set the warning unless we already
4479                --  have a real restriction active (we never want a warning to
4480                --  override a real restriction).
4481
4482                if Warn then
4483                   if not Restriction_Active (R_Id) then
4484                      Set_Restriction (R_Id, N);
4485                      Restriction_Warnings (R_Id) := True;
4486                   end if;
4487
4488                --  If real restriction case, then set it and make sure that the
4489                --  restriction warning flag is off, since a real restriction
4490                --  always overrides a warning.
4491
4492                else
4493                   Set_Restriction (R_Id, N);
4494                   Restriction_Warnings (R_Id) := False;
4495                end if;
4496
4497                --  Check for obsolescent restrictions in Ada 2005 mode
4498
4499                if not Warn
4500                  and then Ada_Version >= Ada_2005
4501                  and then (R_Id = No_Asynchronous_Control
4502                             or else
4503                            R_Id = No_Unchecked_Deallocation
4504                             or else
4505                            R_Id = No_Unchecked_Conversion)
4506                then
4507                   Check_Restriction (No_Obsolescent_Features, N);
4508                end if;
4509
4510                --  A very special case that must be processed here: pragma
4511                --  Restrictions (No_Exceptions) turns off all run-time
4512                --  checking. This is a bit dubious in terms of the formal
4513                --  language definition, but it is what is intended by RM
4514                --  H.4(12). Restriction_Warnings never affects generated code
4515                --  so this is done only in the real restriction case.
4516
4517                if R_Id = No_Exceptions and then not Warn then
4518                   Scope_Suppress := (others => True);
4519                end if;
4520
4521             --  Case of No_Dependence => unit-name. Note that the parser
4522             --  already made the necessary entry in the No_Dependence table.
4523
4524             elsif Id = Name_No_Dependence then
4525                Check_Unit_Name (Expr);
4526
4527             --  All other cases of restriction identifier present
4528
4529             else
4530                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4531                Analyze_And_Resolve (Expr, Any_Integer);
4532
4533                if R_Id not in All_Parameter_Restrictions then
4534                   Error_Pragma_Arg
4535                     ("invalid restriction parameter identifier", Arg);
4536
4537                elsif not Is_OK_Static_Expression (Expr) then
4538                   Flag_Non_Static_Expr
4539                     ("value must be static expression!", Expr);
4540                   raise Pragma_Exit;
4541
4542                elsif not Is_Integer_Type (Etype (Expr))
4543                  or else Expr_Value (Expr) < 0
4544                then
4545                   Error_Pragma_Arg
4546                     ("value must be non-negative integer", Arg);
4547                end if;
4548
4549                --  Restriction pragma is active
4550
4551                Val := Expr_Value (Expr);
4552
4553                if not UI_Is_In_Int_Range (Val) then
4554                   Error_Pragma_Arg
4555                     ("pragma ignored, value too large?", Arg);
4556                end if;
4557
4558                --  Warning case. If the real restriction is active, then we
4559                --  ignore the request, since warning never overrides a real
4560                --  restriction. Otherwise we set the proper warning. Note that
4561                --  this circuit sets the warning again if it is already set,
4562                --  which is what we want, since the constant may have changed.
4563
4564                if Warn then
4565                   if not Restriction_Active (R_Id) then
4566                      Set_Restriction
4567                        (R_Id, N, Integer (UI_To_Int (Val)));
4568                      Restriction_Warnings (R_Id) := True;
4569                   end if;
4570
4571                --  Real restriction case, set restriction and make sure warning
4572                --  flag is off since real restriction always overrides warning.
4573
4574                else
4575                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4576                   Restriction_Warnings (R_Id) := False;
4577                end if;
4578             end if;
4579
4580             Next (Arg);
4581          end loop;
4582       end Process_Restrictions_Or_Restriction_Warnings;
4583
4584       ---------------------------------
4585       -- Process_Suppress_Unsuppress --
4586       ---------------------------------
4587
4588       --  Note: this procedure makes entries in the check suppress data
4589       --  structures managed by Sem. See spec of package Sem for full
4590       --  details on how we handle recording of check suppression.
4591
4592       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4593          C    : Check_Id;
4594          E_Id : Node_Id;
4595          E    : Entity_Id;
4596
4597          In_Package_Spec : constant Boolean :=
4598                              Is_Package_Or_Generic_Package (Current_Scope)
4599                                and then not In_Package_Body (Current_Scope);
4600
4601          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4602          --  Used to suppress a single check on the given entity
4603
4604          --------------------------------
4605          -- Suppress_Unsuppress_Echeck --
4606          --------------------------------
4607
4608          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4609          begin
4610             Set_Checks_May_Be_Suppressed (E);
4611
4612             if In_Package_Spec then
4613                Push_Global_Suppress_Stack_Entry
4614                  (Entity   => E,
4615                   Check    => C,
4616                   Suppress => Suppress_Case);
4617
4618             else
4619                Push_Local_Suppress_Stack_Entry
4620                  (Entity   => E,
4621                   Check    => C,
4622                   Suppress => Suppress_Case);
4623             end if;
4624
4625             --  If this is a first subtype, and the base type is distinct,
4626             --  then also set the suppress flags on the base type.
4627
4628             if Is_First_Subtype (E)
4629               and then Etype (E) /= E
4630             then
4631                Suppress_Unsuppress_Echeck (Etype (E), C);
4632             end if;
4633          end Suppress_Unsuppress_Echeck;
4634
4635       --  Start of processing for Process_Suppress_Unsuppress
4636
4637       begin
4638          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
4639          --  declarative part or a package spec (RM 11.5(5)).
4640
4641          if not Is_Configuration_Pragma then
4642             Check_Is_In_Decl_Part_Or_Package_Spec;
4643          end if;
4644
4645          Check_At_Least_N_Arguments (1);
4646          Check_At_Most_N_Arguments (2);
4647          Check_No_Identifier (Arg1);
4648          Check_Arg_Is_Identifier (Arg1);
4649
4650          C := Get_Check_Id (Chars (Expression (Arg1)));
4651
4652          if C = No_Check_Id then
4653             Error_Pragma_Arg
4654               ("argument of pragma% is not valid check name", Arg1);
4655          end if;
4656
4657          if not Suppress_Case
4658            and then (C = All_Checks or else C = Overflow_Check)
4659          then
4660             Opt.Overflow_Checks_Unsuppressed := True;
4661          end if;
4662
4663          if Arg_Count = 1 then
4664
4665             --  Make an entry in the local scope suppress table. This is the
4666             --  table that directly shows the current value of the scope
4667             --  suppress check for any check id value.
4668
4669             if C = All_Checks then
4670
4671                --  For All_Checks, we set all specific predefined checks with
4672                --  the exception of Elaboration_Check, which is handled
4673                --  specially because of not wanting All_Checks to have the
4674                --  effect of deactivating static elaboration order processing.
4675
4676                for J in Scope_Suppress'Range loop
4677                   if J /= Elaboration_Check then
4678                      Scope_Suppress (J) := Suppress_Case;
4679                   end if;
4680                end loop;
4681
4682             --  If not All_Checks, and predefined check, then set appropriate
4683             --  scope entry. Note that we will set Elaboration_Check if this
4684             --  is explicitly specified.
4685
4686             elsif C in Predefined_Check_Id then
4687                Scope_Suppress (C) := Suppress_Case;
4688             end if;
4689
4690             --  Also make an entry in the Local_Entity_Suppress table
4691
4692             Push_Local_Suppress_Stack_Entry
4693               (Entity   => Empty,
4694                Check    => C,
4695                Suppress => Suppress_Case);
4696
4697          --  Case of two arguments present, where the check is suppressed for
4698          --  a specified entity (given as the second argument of the pragma)
4699
4700          else
4701             --  This is obsolescent in Ada 2005 mode
4702
4703             if Ada_Version >= Ada_2005 then
4704                Check_Restriction (No_Obsolescent_Features, Arg2);
4705             end if;
4706
4707             Check_Optional_Identifier (Arg2, Name_On);
4708             E_Id := Expression (Arg2);
4709             Analyze (E_Id);
4710
4711             if not Is_Entity_Name (E_Id) then
4712                Error_Pragma_Arg
4713                  ("second argument of pragma% must be entity name", Arg2);
4714             end if;
4715
4716             E := Entity (E_Id);
4717
4718             if E = Any_Id then
4719                return;
4720             end if;
4721
4722             --  Enforce RM 11.5(7) which requires that for a pragma that
4723             --  appears within a package spec, the named entity must be
4724             --  within the package spec. We allow the package name itself
4725             --  to be mentioned since that makes sense, although it is not
4726             --  strictly allowed by 11.5(7).
4727
4728             if In_Package_Spec
4729               and then E /= Current_Scope
4730               and then Scope (E) /= Current_Scope
4731             then
4732                Error_Pragma_Arg
4733                  ("entity in pragma% is not in package spec (RM 11.5(7))",
4734                   Arg2);
4735             end if;
4736
4737             --  Loop through homonyms. As noted below, in the case of a package
4738             --  spec, only homonyms within the package spec are considered.
4739
4740             loop
4741                Suppress_Unsuppress_Echeck (E, C);
4742
4743                if Is_Generic_Instance (E)
4744                  and then Is_Subprogram (E)
4745                  and then Present (Alias (E))
4746                then
4747                   Suppress_Unsuppress_Echeck (Alias (E), C);
4748                end if;
4749
4750                --  Move to next homonym
4751
4752                E := Homonym (E);
4753                exit when No (E);
4754
4755                --  If we are within a package specification, the pragma only
4756                --  applies to homonyms in the same scope.
4757
4758                exit when In_Package_Spec
4759                  and then Scope (E) /= Current_Scope;
4760             end loop;
4761          end if;
4762       end Process_Suppress_Unsuppress;
4763
4764       ------------------
4765       -- Set_Exported --
4766       ------------------
4767
4768       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4769       begin
4770          if Is_Imported (E) then
4771             Error_Pragma_Arg
4772               ("cannot export entity& that was previously imported", Arg);
4773
4774          elsif Present (Address_Clause (E)) then
4775             Error_Pragma_Arg
4776               ("cannot export entity& that has an address clause", Arg);
4777          end if;
4778
4779          Set_Is_Exported (E);
4780
4781          --  Generate a reference for entity explicitly, because the
4782          --  identifier may be overloaded and name resolution will not
4783          --  generate one.
4784
4785          Generate_Reference (E, Arg);
4786
4787          --  Deal with exporting non-library level entity
4788
4789          if not Is_Library_Level_Entity (E) then
4790
4791             --  Not allowed at all for subprograms
4792
4793             if Is_Subprogram (E) then
4794                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4795
4796             --  Otherwise set public and statically allocated
4797
4798             else
4799                Set_Is_Public (E);
4800                Set_Is_Statically_Allocated (E);
4801
4802                --  Warn if the corresponding W flag is set and the pragma comes
4803                --  from source. The latter may not be true e.g. on VMS where we
4804                --  expand export pragmas for exception codes associated with
4805                --  imported or exported exceptions. We do not want to generate
4806                --  a warning for something that the user did not write.
4807
4808                if Warn_On_Export_Import
4809                  and then Comes_From_Source (Arg)
4810                then
4811                   Error_Msg_NE
4812                     ("?& has been made static as a result of Export", Arg, E);
4813                   Error_Msg_N
4814                     ("\this usage is non-standard and non-portable", Arg);
4815                end if;
4816             end if;
4817          end if;
4818
4819          if Warn_On_Export_Import and then Is_Type (E) then
4820             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
4821          end if;
4822
4823          if Warn_On_Export_Import and Inside_A_Generic then
4824             Error_Msg_NE
4825               ("all instances of& will have the same external name?", Arg, E);
4826          end if;
4827       end Set_Exported;
4828
4829       ----------------------------------------------
4830       -- Set_Extended_Import_Export_External_Name --
4831       ----------------------------------------------
4832
4833       procedure Set_Extended_Import_Export_External_Name
4834         (Internal_Ent : Entity_Id;
4835          Arg_External : Node_Id)
4836       is
4837          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4838          New_Name : Node_Id;
4839
4840       begin
4841          if No (Arg_External) then
4842             return;
4843          end if;
4844
4845          Check_Arg_Is_External_Name (Arg_External);
4846
4847          if Nkind (Arg_External) = N_String_Literal then
4848             if String_Length (Strval (Arg_External)) = 0 then
4849                return;
4850             else
4851                New_Name := Adjust_External_Name_Case (Arg_External);
4852             end if;
4853
4854          elsif Nkind (Arg_External) = N_Identifier then
4855             New_Name := Get_Default_External_Name (Arg_External);
4856
4857          --  Check_Arg_Is_External_Name should let through only identifiers and
4858          --  string literals or static string expressions (which are folded to
4859          --  string literals).
4860
4861          else
4862             raise Program_Error;
4863          end if;
4864
4865          --  If we already have an external name set (by a prior normal Import
4866          --  or Export pragma), then the external names must match
4867
4868          if Present (Interface_Name (Internal_Ent)) then
4869             Check_Matching_Internal_Names : declare
4870                S1 : constant String_Id := Strval (Old_Name);
4871                S2 : constant String_Id := Strval (New_Name);
4872
4873                procedure Mismatch;
4874                --  Called if names do not match
4875
4876                --------------
4877                -- Mismatch --
4878                --------------
4879
4880                procedure Mismatch is
4881                begin
4882                   Error_Msg_Sloc := Sloc (Old_Name);
4883                   Error_Pragma_Arg
4884                     ("external name does not match that given #",
4885                      Arg_External);
4886                end Mismatch;
4887
4888             --  Start of processing for Check_Matching_Internal_Names
4889
4890             begin
4891                if String_Length (S1) /= String_Length (S2) then
4892                   Mismatch;
4893
4894                else
4895                   for J in 1 .. String_Length (S1) loop
4896                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4897                         Mismatch;
4898                      end if;
4899                   end loop;
4900                end if;
4901             end Check_Matching_Internal_Names;
4902
4903          --  Otherwise set the given name
4904
4905          else
4906             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4907             Check_Duplicated_Export_Name (New_Name);
4908          end if;
4909       end Set_Extended_Import_Export_External_Name;
4910
4911       ------------------
4912       -- Set_Imported --
4913       ------------------
4914
4915       procedure Set_Imported (E : Entity_Id) is
4916       begin
4917          --  Error message if already imported or exported
4918
4919          if Is_Exported (E) or else Is_Imported (E) then
4920
4921             --  Error if being set Exported twice
4922
4923             if Is_Exported (E) then
4924                Error_Msg_NE ("entity& was previously exported", N, E);
4925
4926             --  OK if Import/Interface case
4927
4928             elsif Import_Interface_Present (N) then
4929                goto OK;
4930
4931             --  Error if being set Imported twice
4932
4933             else
4934                Error_Msg_NE ("entity& was previously imported", N, E);
4935             end if;
4936
4937             Error_Msg_Name_1 := Pname;
4938             Error_Msg_N
4939               ("\(pragma% applies to all previous entities)", N);
4940
4941             Error_Msg_Sloc  := Sloc (E);
4942             Error_Msg_NE ("\import not allowed for& declared#", N, E);
4943
4944          --  Here if not previously imported or exported, OK to import
4945
4946          else
4947             Set_Is_Imported (E);
4948
4949             --  If the entity is an object that is not at the library level,
4950             --  then it is statically allocated. We do not worry about objects
4951             --  with address clauses in this context since they are not really
4952             --  imported in the linker sense.
4953
4954             if Is_Object (E)
4955               and then not Is_Library_Level_Entity (E)
4956               and then No (Address_Clause (E))
4957             then
4958                Set_Is_Statically_Allocated (E);
4959             end if;
4960          end if;
4961
4962          <<OK>> null;
4963       end Set_Imported;
4964
4965       -------------------------
4966       -- Set_Mechanism_Value --
4967       -------------------------
4968
4969       --  Note: the mechanism name has not been analyzed (and cannot indeed be
4970       --  analyzed, since it is semantic nonsense), so we get it in the exact
4971       --  form created by the parser.
4972
4973       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4974          Class        : Node_Id;
4975          Param        : Node_Id;
4976          Mech_Name_Id : Name_Id;
4977
4978          procedure Bad_Class;
4979          --  Signal bad descriptor class name
4980
4981          procedure Bad_Mechanism;
4982          --  Signal bad mechanism name
4983
4984          ---------------
4985          -- Bad_Class --
4986          ---------------
4987
4988          procedure Bad_Class is
4989          begin
4990             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4991          end Bad_Class;
4992
4993          -------------------------
4994          -- Bad_Mechanism_Value --
4995          -------------------------
4996
4997          procedure Bad_Mechanism is
4998          begin
4999             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5000          end Bad_Mechanism;
5001
5002       --  Start of processing for Set_Mechanism_Value
5003
5004       begin
5005          if Mechanism (Ent) /= Default_Mechanism then
5006             Error_Msg_NE
5007               ("mechanism for & has already been set", Mech_Name, Ent);
5008          end if;
5009
5010          --  MECHANISM_NAME ::= value | reference | descriptor |
5011          --                     short_descriptor
5012
5013          if Nkind (Mech_Name) = N_Identifier then
5014             if Chars (Mech_Name) = Name_Value then
5015                Set_Mechanism (Ent, By_Copy);
5016                return;
5017
5018             elsif Chars (Mech_Name) = Name_Reference then
5019                Set_Mechanism (Ent, By_Reference);
5020                return;
5021
5022             elsif Chars (Mech_Name) = Name_Descriptor then
5023                Check_VMS (Mech_Name);
5024
5025                --  Descriptor => Short_Descriptor if pragma was given
5026
5027                if Short_Descriptors then
5028                   Set_Mechanism (Ent, By_Short_Descriptor);
5029                else
5030                   Set_Mechanism (Ent, By_Descriptor);
5031                end if;
5032
5033                return;
5034
5035             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5036                Check_VMS (Mech_Name);
5037                Set_Mechanism (Ent, By_Short_Descriptor);
5038                return;
5039
5040             elsif Chars (Mech_Name) = Name_Copy then
5041                Error_Pragma_Arg
5042                  ("bad mechanism name, Value assumed", Mech_Name);
5043
5044             else
5045                Bad_Mechanism;
5046             end if;
5047
5048          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5049          --                     short_descriptor (CLASS_NAME)
5050          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5051
5052          --  Note: this form is parsed as an indexed component
5053
5054          elsif Nkind (Mech_Name) = N_Indexed_Component then
5055             Class := First (Expressions (Mech_Name));
5056
5057             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5058              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5059                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5060              or else Present (Next (Class))
5061             then
5062                Bad_Mechanism;
5063             else
5064                Mech_Name_Id := Chars (Prefix (Mech_Name));
5065
5066                --  Change Descriptor => Short_Descriptor if pragma was given
5067
5068                if Mech_Name_Id = Name_Descriptor
5069                  and then Short_Descriptors
5070                then
5071                   Mech_Name_Id := Name_Short_Descriptor;
5072                end if;
5073             end if;
5074
5075          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5076          --                     short_descriptor (Class => CLASS_NAME)
5077          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5078
5079          --  Note: this form is parsed as a function call
5080
5081          elsif Nkind (Mech_Name) = N_Function_Call then
5082             Param := First (Parameter_Associations (Mech_Name));
5083
5084             if Nkind (Name (Mech_Name)) /= N_Identifier
5085               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5086                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5087               or else Present (Next (Param))
5088               or else No (Selector_Name (Param))
5089               or else Chars (Selector_Name (Param)) /= Name_Class
5090             then
5091                Bad_Mechanism;
5092             else
5093                Class := Explicit_Actual_Parameter (Param);
5094                Mech_Name_Id := Chars (Name (Mech_Name));
5095             end if;
5096
5097          else
5098             Bad_Mechanism;
5099          end if;
5100
5101          --  Fall through here with Class set to descriptor class name
5102
5103          Check_VMS (Mech_Name);
5104
5105          if Nkind (Class) /= N_Identifier then
5106             Bad_Class;
5107
5108          elsif Mech_Name_Id = Name_Descriptor
5109            and then Chars (Class) = Name_UBS
5110          then
5111             Set_Mechanism (Ent, By_Descriptor_UBS);
5112
5113          elsif Mech_Name_Id = Name_Descriptor
5114            and then Chars (Class) = Name_UBSB
5115          then
5116             Set_Mechanism (Ent, By_Descriptor_UBSB);
5117
5118          elsif Mech_Name_Id = Name_Descriptor
5119            and then Chars (Class) = Name_UBA
5120          then
5121             Set_Mechanism (Ent, By_Descriptor_UBA);
5122
5123          elsif Mech_Name_Id = Name_Descriptor
5124            and then Chars (Class) = Name_S
5125          then
5126             Set_Mechanism (Ent, By_Descriptor_S);
5127
5128          elsif Mech_Name_Id = Name_Descriptor
5129            and then Chars (Class) = Name_SB
5130          then
5131             Set_Mechanism (Ent, By_Descriptor_SB);
5132
5133          elsif Mech_Name_Id = Name_Descriptor
5134            and then Chars (Class) = Name_A
5135          then
5136             Set_Mechanism (Ent, By_Descriptor_A);
5137
5138          elsif Mech_Name_Id = Name_Descriptor
5139            and then Chars (Class) = Name_NCA
5140          then
5141             Set_Mechanism (Ent, By_Descriptor_NCA);
5142
5143          elsif Mech_Name_Id = Name_Short_Descriptor
5144            and then Chars (Class) = Name_UBS
5145          then
5146             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5147
5148          elsif Mech_Name_Id = Name_Short_Descriptor
5149            and then Chars (Class) = Name_UBSB
5150          then
5151             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5152
5153          elsif Mech_Name_Id = Name_Short_Descriptor
5154            and then Chars (Class) = Name_UBA
5155          then
5156             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5157
5158          elsif Mech_Name_Id = Name_Short_Descriptor
5159            and then Chars (Class) = Name_S
5160          then
5161             Set_Mechanism (Ent, By_Short_Descriptor_S);
5162
5163          elsif Mech_Name_Id = Name_Short_Descriptor
5164            and then Chars (Class) = Name_SB
5165          then
5166             Set_Mechanism (Ent, By_Short_Descriptor_SB);
5167
5168          elsif Mech_Name_Id = Name_Short_Descriptor
5169            and then Chars (Class) = Name_A
5170          then
5171             Set_Mechanism (Ent, By_Short_Descriptor_A);
5172
5173          elsif Mech_Name_Id = Name_Short_Descriptor
5174            and then Chars (Class) = Name_NCA
5175          then
5176             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5177
5178          else
5179             Bad_Class;
5180          end if;
5181       end Set_Mechanism_Value;
5182
5183       ---------------------------
5184       -- Set_Ravenscar_Profile --
5185       ---------------------------
5186
5187       --  The tasks to be done here are
5188
5189       --    Set required policies
5190
5191       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5192       --      pragma Locking_Policy (Ceiling_Locking)
5193
5194       --    Set Detect_Blocking mode
5195
5196       --    Set required restrictions (see System.Rident for detailed list)
5197
5198       procedure Set_Ravenscar_Profile (N : Node_Id) is
5199       begin
5200          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5201
5202          if Task_Dispatching_Policy /= ' '
5203            and then Task_Dispatching_Policy /= 'F'
5204          then
5205             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5206             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5207
5208          --  Set the FIFO_Within_Priorities policy, but always preserve
5209          --  System_Location since we like the error message with the run time
5210          --  name.
5211
5212          else
5213             Task_Dispatching_Policy := 'F';
5214
5215             if Task_Dispatching_Policy_Sloc /= System_Location then
5216                Task_Dispatching_Policy_Sloc := Loc;
5217             end if;
5218          end if;
5219
5220          --  pragma Locking_Policy (Ceiling_Locking)
5221
5222          if Locking_Policy /= ' '
5223            and then Locking_Policy /= 'C'
5224          then
5225             Error_Msg_Sloc := Locking_Policy_Sloc;
5226             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5227
5228          --  Set the Ceiling_Locking policy, but preserve System_Location since
5229          --  we like the error message with the run time name.
5230
5231          else
5232             Locking_Policy := 'C';
5233
5234             if Locking_Policy_Sloc /= System_Location then
5235                Locking_Policy_Sloc := Loc;
5236             end if;
5237          end if;
5238
5239          --  pragma Detect_Blocking
5240
5241          Detect_Blocking := True;
5242
5243          --  Set the corresponding restrictions
5244
5245          Set_Profile_Restrictions
5246            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5247       end Set_Ravenscar_Profile;
5248
5249    --  Start of processing for Analyze_Pragma
5250
5251    begin
5252       --  Deal with unrecognized pragma
5253
5254       if not Is_Pragma_Name (Pname) then
5255          if Warn_On_Unrecognized_Pragma then
5256             Error_Msg_Name_1 := Pname;
5257             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5258
5259             for PN in First_Pragma_Name .. Last_Pragma_Name loop
5260                if Is_Bad_Spelling_Of (Pname, PN) then
5261                   Error_Msg_Name_1 := PN;
5262                   Error_Msg_N -- CODEFIX
5263                     ("\?possible misspelling of %!", Pragma_Identifier (N));
5264                   exit;
5265                end if;
5266             end loop;
5267          end if;
5268
5269          return;
5270       end if;
5271
5272       --  Here to start processing for recognized pragma
5273
5274       Prag_Id := Get_Pragma_Id (Pname);
5275
5276       --  Preset arguments
5277
5278       Arg1 := Empty;
5279       Arg2 := Empty;
5280       Arg3 := Empty;
5281       Arg4 := Empty;
5282
5283       if Present (Pragma_Argument_Associations (N)) then
5284          Arg1 := First (Pragma_Argument_Associations (N));
5285
5286          if Present (Arg1) then
5287             Arg2 := Next (Arg1);
5288
5289             if Present (Arg2) then
5290                Arg3 := Next (Arg2);
5291
5292                if Present (Arg3) then
5293                   Arg4 := Next (Arg3);
5294                end if;
5295             end if;
5296          end if;
5297       end if;
5298
5299       --  Count number of arguments
5300
5301       declare
5302          Arg_Node : Node_Id;
5303       begin
5304          Arg_Count := 0;
5305          Arg_Node := Arg1;
5306          while Present (Arg_Node) loop
5307             Arg_Count := Arg_Count + 1;
5308             Next (Arg_Node);
5309          end loop;
5310       end;
5311
5312       --  An enumeration type defines the pragmas that are supported by the
5313       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
5314       --  into the corresponding enumeration value for the following case.
5315
5316       case Prag_Id is
5317
5318          -----------------
5319          -- Abort_Defer --
5320          -----------------
5321
5322          --  pragma Abort_Defer;
5323
5324          when Pragma_Abort_Defer =>
5325             GNAT_Pragma;
5326             Check_Arg_Count (0);
5327
5328             --  The only required semantic processing is to check the
5329             --  placement. This pragma must appear at the start of the
5330             --  statement sequence of a handled sequence of statements.
5331
5332             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5333               or else N /= First (Statements (Parent (N)))
5334             then
5335                Pragma_Misplaced;
5336             end if;
5337
5338          ------------
5339          -- Ada_83 --
5340          ------------
5341
5342          --  pragma Ada_83;
5343
5344          --  Note: this pragma also has some specific processing in Par.Prag
5345          --  because we want to set the Ada version mode during parsing.
5346
5347          when Pragma_Ada_83 =>
5348             GNAT_Pragma;
5349             Check_Arg_Count (0);
5350
5351             --  We really should check unconditionally for proper configuration
5352             --  pragma placement, since we really don't want mixed Ada modes
5353             --  within a single unit, and the GNAT reference manual has always
5354             --  said this was a configuration pragma, but we did not check and
5355             --  are hesitant to add the check now.
5356
5357             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5358             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5359             --  or Ada 2012 mode.
5360
5361             if Ada_Version >= Ada_05 then
5362                Check_Valid_Configuration_Pragma;
5363             end if;
5364
5365             --  Now set Ada 83 mode
5366
5367             Ada_Version := Ada_83;
5368             Ada_Version_Explicit := Ada_Version;
5369
5370          ------------
5371          -- Ada_95 --
5372          ------------
5373
5374          --  pragma Ada_95;
5375
5376          --  Note: this pragma also has some specific processing in Par.Prag
5377          --  because we want to set the Ada 83 version mode during parsing.
5378
5379          when Pragma_Ada_95 =>
5380             GNAT_Pragma;
5381             Check_Arg_Count (0);
5382
5383             --  We really should check unconditionally for proper configuration
5384             --  pragma placement, since we really don't want mixed Ada modes
5385             --  within a single unit, and the GNAT reference manual has always
5386             --  said this was a configuration pragma, but we did not check and
5387             --  are hesitant to add the check now.
5388
5389             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
5390             --  or Ada 95, so we must check if we are in Ada 2005 mode.
5391
5392             if Ada_Version >= Ada_05 then
5393                Check_Valid_Configuration_Pragma;
5394             end if;
5395
5396             --  Now set Ada 95 mode
5397
5398             Ada_Version := Ada_95;
5399             Ada_Version_Explicit := Ada_Version;
5400
5401          ---------------------
5402          -- Ada_05/Ada_2005 --
5403          ---------------------
5404
5405          --  pragma Ada_05;
5406          --  pragma Ada_05 (LOCAL_NAME);
5407
5408          --  pragma Ada_2005;
5409          --  pragma Ada_2005 (LOCAL_NAME):
5410
5411          --  Note: these pragmas also have some specific processing in Par.Prag
5412          --  because we want to set the Ada 2005 version mode during parsing.
5413
5414          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5415             E_Id : Node_Id;
5416
5417          begin
5418             GNAT_Pragma;
5419
5420             if Arg_Count = 1 then
5421                Check_Arg_Is_Local_Name (Arg1);
5422                E_Id := Expression (Arg1);
5423
5424                if Etype (E_Id) = Any_Type then
5425                   return;
5426                end if;
5427
5428                Set_Is_Ada_2005_Only (Entity (E_Id));
5429
5430             else
5431                Check_Arg_Count (0);
5432
5433                --  For Ada_2005 we unconditionally enforce the documented
5434                --  configuration pragma placement, since we do not want to
5435                --  tolerate mixed modes in a unit involving Ada 2005. That
5436                --  would cause real difficulties for those cases where there
5437                --  are incompatibilities between Ada 95 and Ada 2005.
5438
5439                Check_Valid_Configuration_Pragma;
5440
5441                --  Now set Ada 2005 mode
5442
5443                Ada_Version := Ada_05;
5444                Ada_Version_Explicit := Ada_05;
5445             end if;
5446          end;
5447
5448          ---------------------
5449          -- Ada_12/Ada_2012 --
5450          ---------------------
5451
5452          --  pragma Ada_12;
5453          --  pragma Ada_12 (LOCAL_NAME);
5454
5455          --  pragma Ada_2012;
5456          --  pragma Ada_2012 (LOCAL_NAME):
5457
5458          --  Note: these pragmas also have some specific processing in Par.Prag
5459          --  because we want to set the Ada 2012 version mode during parsing.
5460
5461          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5462             E_Id : Node_Id;
5463
5464          begin
5465             GNAT_Pragma;
5466
5467             if Arg_Count = 1 then
5468                Check_Arg_Is_Local_Name (Arg1);
5469                E_Id := Expression (Arg1);
5470
5471                if Etype (E_Id) = Any_Type then
5472                   return;
5473                end if;
5474
5475                Set_Is_Ada_2012_Only (Entity (E_Id));
5476
5477             else
5478                Check_Arg_Count (0);
5479
5480                --  For Ada_2012 we unconditionally enforce the documented
5481                --  configuration pragma placement, since we do not want to
5482                --  tolerate mixed modes in a unit involving Ada 2012. That
5483                --  would cause real difficulties for those cases where there
5484                --  are incompatibilities between Ada 95 and Ada 2012. We could
5485                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5486
5487                Check_Valid_Configuration_Pragma;
5488
5489                --  Now set Ada 2012 mode
5490
5491                Ada_Version := Ada_12;
5492                Ada_Version_Explicit := Ada_12;
5493             end if;
5494          end;
5495
5496          ----------------------
5497          -- All_Calls_Remote --
5498          ----------------------
5499
5500          --  pragma All_Calls_Remote [(library_package_NAME)];
5501
5502          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5503             Lib_Entity : Entity_Id;
5504
5505          begin
5506             Check_Ada_83_Warning;
5507             Check_Valid_Library_Unit_Pragma;
5508
5509             if Nkind (N) = N_Null_Statement then
5510                return;
5511             end if;
5512
5513             Lib_Entity := Find_Lib_Unit_Name;
5514
5515             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
5516
5517             if Present (Lib_Entity)
5518               and then not Debug_Flag_U
5519             then
5520                if not Is_Remote_Call_Interface (Lib_Entity) then
5521                   Error_Pragma ("pragma% only apply to rci unit");
5522
5523                --  Set flag for entity of the library unit
5524
5525                else
5526                   Set_Has_All_Calls_Remote (Lib_Entity);
5527                end if;
5528
5529             end if;
5530          end All_Calls_Remote;
5531
5532          --------------
5533          -- Annotate --
5534          --------------
5535
5536          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5537          --  ARG ::= NAME | EXPRESSION
5538
5539          --  The first two arguments are by convention intended to refer to an
5540          --  external tool and a tool-specific function. These arguments are
5541          --  not analyzed.
5542
5543          when Pragma_Annotate => Annotate : begin
5544             GNAT_Pragma;
5545             Check_At_Least_N_Arguments (1);
5546             Check_Arg_Is_Identifier (Arg1);
5547             Check_No_Identifiers;
5548             Store_Note (N);
5549
5550             declare
5551                Arg : Node_Id;
5552                Exp : Node_Id;
5553
5554             begin
5555                --  Second unanalyzed parameter is optional
5556
5557                if No (Arg2) then
5558                   null;
5559                else
5560                   Arg := Next (Arg2);
5561                   while Present (Arg) loop
5562                      Exp := Expression (Arg);
5563                      Analyze (Exp);
5564
5565                      if Is_Entity_Name (Exp) then
5566                         null;
5567
5568                      --  For string literals, we assume Standard_String as the
5569                      --  type, unless the string contains wide or wide_wide
5570                      --  characters.
5571
5572                      elsif Nkind (Exp) = N_String_Literal then
5573                         if Has_Wide_Wide_Character (Exp) then
5574                            Resolve (Exp, Standard_Wide_Wide_String);
5575                         elsif Has_Wide_Character (Exp) then
5576                            Resolve (Exp, Standard_Wide_String);
5577                         else
5578                            Resolve (Exp, Standard_String);
5579                         end if;
5580
5581                      elsif Is_Overloaded (Exp) then
5582                            Error_Pragma_Arg
5583                              ("ambiguous argument for pragma%", Exp);
5584
5585                      else
5586                         Resolve (Exp);
5587                      end if;
5588
5589                      Next (Arg);
5590                   end loop;
5591                end if;
5592             end;
5593          end Annotate;
5594
5595          ------------
5596          -- Assert --
5597          ------------
5598
5599          --  pragma Assert ([Check =>] Boolean_EXPRESSION
5600          --                 [, [Message =>] Static_String_EXPRESSION]);
5601
5602          when Pragma_Assert => Assert : declare
5603             Expr : Node_Id;
5604             Newa : List_Id;
5605
5606          begin
5607             Ada_2005_Pragma;
5608             Check_At_Least_N_Arguments (1);
5609             Check_At_Most_N_Arguments (2);
5610             Check_Arg_Order ((Name_Check, Name_Message));
5611             Check_Optional_Identifier (Arg1, Name_Check);
5612
5613             --  We treat pragma Assert as equivalent to:
5614
5615             --    pragma Check (Assertion, condition [, msg]);
5616
5617             --  So rewrite pragma in this manner, and analyze the result
5618
5619             Expr := Get_Pragma_Arg (Arg1);
5620             Newa := New_List (
5621               Make_Pragma_Argument_Association (Loc,
5622                 Expression =>
5623                   Make_Identifier (Loc,
5624                     Chars => Name_Assertion)),
5625
5626               Make_Pragma_Argument_Association (Sloc (Expr),
5627                 Expression => Expr));
5628
5629             if Arg_Count > 1 then
5630                Check_Optional_Identifier (Arg2, Name_Message);
5631                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5632                Append_To (Newa, Relocate_Node (Arg2));
5633             end if;
5634
5635             Rewrite (N,
5636               Make_Pragma (Loc,
5637                 Chars => Name_Check,
5638                 Pragma_Argument_Associations => Newa));
5639             Analyze (N);
5640          end Assert;
5641
5642          ----------------------
5643          -- Assertion_Policy --
5644          ----------------------
5645
5646          --  pragma Assertion_Policy (Check | Ignore)
5647
5648          when Pragma_Assertion_Policy => Assertion_Policy : declare
5649             Policy : Node_Id;
5650
5651          begin
5652             Ada_2005_Pragma;
5653             Check_Valid_Configuration_Pragma;
5654             Check_Arg_Count (1);
5655             Check_No_Identifiers;
5656             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5657
5658             --  We treat pragma Assertion_Policy as equivalent to:
5659
5660             --    pragma Check_Policy (Assertion, policy)
5661
5662             --  So rewrite the pragma in that manner and link on to the chain
5663             --  of Check_Policy pragmas, marking the pragma as analyzed.
5664
5665             Policy := Get_Pragma_Arg (Arg1);
5666
5667             Rewrite (N,
5668               Make_Pragma (Loc,
5669                 Chars => Name_Check_Policy,
5670
5671                 Pragma_Argument_Associations => New_List (
5672                   Make_Pragma_Argument_Association (Loc,
5673                     Expression =>
5674                       Make_Identifier (Loc,
5675                         Chars => Name_Assertion)),
5676
5677                   Make_Pragma_Argument_Association (Loc,
5678                     Expression =>
5679                       Make_Identifier (Sloc (Policy),
5680                         Chars => Chars (Policy))))));
5681
5682             Set_Analyzed (N);
5683             Set_Next_Pragma (N, Opt.Check_Policy_List);
5684             Opt.Check_Policy_List := N;
5685          end Assertion_Policy;
5686
5687          ------------------------------
5688          -- Assume_No_Invalid_Values --
5689          ------------------------------
5690
5691          --  pragma Assume_No_Invalid_Values (On | Off);
5692
5693          when Pragma_Assume_No_Invalid_Values =>
5694             GNAT_Pragma;
5695             Check_Valid_Configuration_Pragma;
5696             Check_Arg_Count (1);
5697             Check_No_Identifiers;
5698             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5699
5700             if Chars (Expression (Arg1)) = Name_On then
5701                Assume_No_Invalid_Values := True;
5702             else
5703                Assume_No_Invalid_Values := False;
5704             end if;
5705
5706          ---------------
5707          -- AST_Entry --
5708          ---------------
5709
5710          --  pragma AST_Entry (entry_IDENTIFIER);
5711
5712          when Pragma_AST_Entry => AST_Entry : declare
5713             Ent : Node_Id;
5714
5715          begin
5716             GNAT_Pragma;
5717             Check_VMS (N);
5718             Check_Arg_Count (1);
5719             Check_No_Identifiers;
5720             Check_Arg_Is_Local_Name (Arg1);
5721             Ent := Entity (Expression (Arg1));
5722
5723             --  Note: the implementation of the AST_Entry pragma could handle
5724             --  the entry family case fine, but for now we are consistent with
5725             --  the DEC rules, and do not allow the pragma, which of course
5726             --  has the effect of also forbidding the attribute.
5727
5728             if Ekind (Ent) /= E_Entry then
5729                Error_Pragma_Arg
5730                  ("pragma% argument must be simple entry name", Arg1);
5731
5732             elsif Is_AST_Entry (Ent) then
5733                Error_Pragma_Arg
5734                  ("duplicate % pragma for entry", Arg1);
5735
5736             elsif Has_Homonym (Ent) then
5737                Error_Pragma_Arg
5738                  ("pragma% argument cannot specify overloaded entry", Arg1);
5739
5740             else
5741                declare
5742                   FF : constant Entity_Id := First_Formal (Ent);
5743
5744                begin
5745                   if Present (FF) then
5746                      if Present (Next_Formal (FF)) then
5747                         Error_Pragma_Arg
5748                           ("entry for pragma% can have only one argument",
5749                            Arg1);
5750
5751                      elsif Parameter_Mode (FF) /= E_In_Parameter then
5752                         Error_Pragma_Arg
5753                           ("entry parameter for pragma% must have mode IN",
5754                            Arg1);
5755                      end if;
5756                   end if;
5757                end;
5758
5759                Set_Is_AST_Entry (Ent);
5760             end if;
5761          end AST_Entry;
5762
5763          ------------------
5764          -- Asynchronous --
5765          ------------------
5766
5767          --  pragma Asynchronous (LOCAL_NAME);
5768
5769          when Pragma_Asynchronous => Asynchronous : declare
5770             Nm     : Entity_Id;
5771             C_Ent  : Entity_Id;
5772             L      : List_Id;
5773             S      : Node_Id;
5774             N      : Node_Id;
5775             Formal : Entity_Id;
5776
5777             procedure Process_Async_Pragma;
5778             --  Common processing for procedure and access-to-procedure case
5779
5780             --------------------------
5781             -- Process_Async_Pragma --
5782             --------------------------
5783
5784             procedure Process_Async_Pragma is
5785             begin
5786                if No (L) then
5787                   Set_Is_Asynchronous (Nm);
5788                   return;
5789                end if;
5790
5791                --  The formals should be of mode IN (RM E.4.1(6))
5792
5793                S := First (L);
5794                while Present (S) loop
5795                   Formal := Defining_Identifier (S);
5796
5797                   if Nkind (Formal) = N_Defining_Identifier
5798                     and then Ekind (Formal) /= E_In_Parameter
5799                   then
5800                      Error_Pragma_Arg
5801                        ("pragma% procedure can only have IN parameter",
5802                         Arg1);
5803                   end if;
5804
5805                   Next (S);
5806                end loop;
5807
5808                Set_Is_Asynchronous (Nm);
5809             end Process_Async_Pragma;
5810
5811          --  Start of processing for pragma Asynchronous
5812
5813          begin
5814             Check_Ada_83_Warning;
5815             Check_No_Identifiers;
5816             Check_Arg_Count (1);
5817             Check_Arg_Is_Local_Name (Arg1);
5818
5819             if Debug_Flag_U then
5820                return;
5821             end if;
5822
5823             C_Ent := Cunit_Entity (Current_Sem_Unit);
5824             Analyze (Expression (Arg1));
5825             Nm := Entity (Expression (Arg1));
5826
5827             if not Is_Remote_Call_Interface (C_Ent)
5828               and then not Is_Remote_Types (C_Ent)
5829             then
5830                --  This pragma should only appear in an RCI or Remote Types
5831                --  unit (RM E.4.1(4)).
5832
5833                Error_Pragma
5834                  ("pragma% not in Remote_Call_Interface or " &
5835                   "Remote_Types unit");
5836             end if;
5837
5838             if Ekind (Nm) = E_Procedure
5839               and then Nkind (Parent (Nm)) = N_Procedure_Specification
5840             then
5841                if not Is_Remote_Call_Interface (Nm) then
5842                   Error_Pragma_Arg
5843                     ("pragma% cannot be applied on non-remote procedure",
5844                      Arg1);
5845                end if;
5846
5847                L := Parameter_Specifications (Parent (Nm));
5848                Process_Async_Pragma;
5849                return;
5850
5851             elsif Ekind (Nm) = E_Function then
5852                Error_Pragma_Arg
5853                  ("pragma% cannot be applied to function", Arg1);
5854
5855             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5856
5857                   if Is_Record_Type (Nm) then
5858
5859                   --  A record type that is the Equivalent_Type for a remote
5860                   --  access-to-subprogram type.
5861
5862                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
5863
5864                   else
5865                      --  A non-expanded RAS type (distribution is not enabled)
5866
5867                      N := Declaration_Node (Nm);
5868                   end if;
5869
5870                if Nkind (N) = N_Full_Type_Declaration
5871                  and then Nkind (Type_Definition (N)) =
5872                                      N_Access_Procedure_Definition
5873                then
5874                   L := Parameter_Specifications (Type_Definition (N));
5875                   Process_Async_Pragma;
5876
5877                   if Is_Asynchronous (Nm)
5878                     and then Expander_Active
5879                     and then Get_PCS_Name /= Name_No_DSA
5880                   then
5881                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5882                   end if;
5883
5884                else
5885                   Error_Pragma_Arg
5886                     ("pragma% cannot reference access-to-function type",
5887                     Arg1);
5888                end if;
5889
5890             --  Only other possibility is Access-to-class-wide type
5891
5892             elsif Is_Access_Type (Nm)
5893               and then Is_Class_Wide_Type (Designated_Type (Nm))
5894             then
5895                Check_First_Subtype (Arg1);
5896                Set_Is_Asynchronous (Nm);
5897                if Expander_Active then
5898                   RACW_Type_Is_Asynchronous (Nm);
5899                end if;
5900
5901             else
5902                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5903             end if;
5904          end Asynchronous;
5905
5906          ------------
5907          -- Atomic --
5908          ------------
5909
5910          --  pragma Atomic (LOCAL_NAME);
5911
5912          when Pragma_Atomic =>
5913             Process_Atomic_Shared_Volatile;
5914
5915          -----------------------
5916          -- Atomic_Components --
5917          -----------------------
5918
5919          --  pragma Atomic_Components (array_LOCAL_NAME);
5920
5921          --  This processing is shared by Volatile_Components
5922
5923          when Pragma_Atomic_Components   |
5924               Pragma_Volatile_Components =>
5925
5926          Atomic_Components : declare
5927             E_Id : Node_Id;
5928             E    : Entity_Id;
5929             D    : Node_Id;
5930             K    : Node_Kind;
5931
5932          begin
5933             Check_Ada_83_Warning;
5934             Check_No_Identifiers;
5935             Check_Arg_Count (1);
5936             Check_Arg_Is_Local_Name (Arg1);
5937             E_Id := Expression (Arg1);
5938
5939             if Etype (E_Id) = Any_Type then
5940                return;
5941             end if;
5942
5943             E := Entity (E_Id);
5944
5945             if Rep_Item_Too_Early (E, N)
5946                  or else
5947                Rep_Item_Too_Late (E, N)
5948             then
5949                return;
5950             end if;
5951
5952             D := Declaration_Node (E);
5953             K := Nkind (D);
5954
5955             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5956               or else
5957                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5958                    and then Nkind (D) = N_Object_Declaration
5959                    and then Nkind (Object_Definition (D)) =
5960                                        N_Constrained_Array_Definition)
5961             then
5962                --  The flag is set on the object, or on the base type
5963
5964                if Nkind (D) /= N_Object_Declaration then
5965                   E := Base_Type (E);
5966                end if;
5967
5968                Set_Has_Volatile_Components (E);
5969
5970                if Prag_Id = Pragma_Atomic_Components then
5971                   Set_Has_Atomic_Components (E);
5972                end if;
5973
5974             else
5975                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5976             end if;
5977          end Atomic_Components;
5978
5979          --------------------
5980          -- Attach_Handler --
5981          --------------------
5982
5983          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
5984
5985          when Pragma_Attach_Handler =>
5986             Check_Ada_83_Warning;
5987             Check_No_Identifiers;
5988             Check_Arg_Count (2);
5989
5990             if No_Run_Time_Mode then
5991                Error_Msg_CRT ("Attach_Handler pragma", N);
5992             else
5993                Check_Interrupt_Or_Attach_Handler;
5994
5995                --  The expression that designates the attribute may
5996                --  depend on a discriminant, and is therefore a per-
5997                --  object expression, to be expanded in the init proc.
5998                --  If expansion is enabled, perform semantic checks
5999                --  on a copy only.
6000
6001                if Expander_Active then
6002                   declare
6003                      Temp : constant Node_Id :=
6004                               New_Copy_Tree (Expression (Arg2));
6005                   begin
6006                      Set_Parent (Temp, N);
6007                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6008                   end;
6009
6010                else
6011                   Analyze (Expression (Arg2));
6012                   Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
6013                end if;
6014
6015                Process_Interrupt_Or_Attach_Handler;
6016             end if;
6017
6018          --------------------
6019          -- C_Pass_By_Copy --
6020          --------------------
6021
6022          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6023
6024          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6025             Arg : Node_Id;
6026             Val : Uint;
6027
6028          begin
6029             GNAT_Pragma;
6030             Check_Valid_Configuration_Pragma;
6031             Check_Arg_Count (1);
6032             Check_Optional_Identifier (Arg1, "max_size");
6033
6034             Arg := Expression (Arg1);
6035             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6036
6037             Val := Expr_Value (Arg);
6038
6039             if Val <= 0 then
6040                Error_Pragma_Arg
6041                  ("maximum size for pragma% must be positive", Arg1);
6042
6043             elsif UI_Is_In_Int_Range (Val) then
6044                Default_C_Record_Mechanism := UI_To_Int (Val);
6045
6046             --  If a giant value is given, Int'Last will do well enough.
6047             --  If sometime someone complains that a record larger than
6048             --  two gigabytes is not copied, we will worry about it then!
6049
6050             else
6051                Default_C_Record_Mechanism := Mechanism_Type'Last;
6052             end if;
6053          end C_Pass_By_Copy;
6054
6055          -----------
6056          -- Check --
6057          -----------
6058
6059          --  pragma Check ([Name    =>] Identifier,
6060          --                [Check   =>] Boolean_Expression
6061          --              [,[Message =>] String_Expression]);
6062
6063          when Pragma_Check => Check : declare
6064             Expr : Node_Id;
6065             Eloc : Source_Ptr;
6066
6067             Check_On : Boolean;
6068             --  Set True if category of assertions referenced by Name enabled
6069
6070          begin
6071             GNAT_Pragma;
6072             Check_At_Least_N_Arguments (2);
6073             Check_At_Most_N_Arguments (3);
6074             Check_Optional_Identifier (Arg1, Name_Name);
6075             Check_Optional_Identifier (Arg2, Name_Check);
6076
6077             if Arg_Count = 3 then
6078                Check_Optional_Identifier (Arg3, Name_Message);
6079                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6080             end if;
6081
6082             Check_Arg_Is_Identifier (Arg1);
6083
6084             --  Indicate if pragma is enabled. The Original_Node reference here
6085             --  is to deal with pragma Assert rewritten as a Check pragma.
6086
6087             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6088
6089             if Check_On then
6090                Set_Pragma_Enabled (N);
6091                Set_Pragma_Enabled (Original_Node (N));
6092                Set_SCO_Pragma_Enabled (Loc);
6093             end if;
6094
6095             --  If expansion is active and the check is not enabled then we
6096             --  rewrite the Check as:
6097
6098             --    if False and then condition then
6099             --       null;
6100             --    end if;
6101
6102             --  The reason we do this rewriting during semantic analysis rather
6103             --  than as part of normal expansion is that we cannot analyze and
6104             --  expand the code for the boolean expression directly, or it may
6105             --  cause insertion of actions that would escape the attempt to
6106             --  suppress the check code.
6107
6108             --  Note that the Sloc for the if statement corresponds to the
6109             --  argument condition, not the pragma itself. The reason for this
6110             --  is that we may generate a warning if the condition is False at
6111             --  compile time, and we do not want to delete this warning when we
6112             --  delete the if statement.
6113
6114             Expr := Expression (Arg2);
6115
6116             if Expander_Active and then not Check_On then
6117                Eloc := Sloc (Expr);
6118
6119                Rewrite (N,
6120                  Make_If_Statement (Eloc,
6121                    Condition =>
6122                      Make_And_Then (Eloc,
6123                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
6124                        Right_Opnd => Expr),
6125                    Then_Statements => New_List (
6126                      Make_Null_Statement (Eloc))));
6127
6128                Analyze (N);
6129
6130             --  Check is active
6131
6132             else
6133                Analyze_And_Resolve (Expr, Any_Boolean);
6134             end if;
6135          end Check;
6136
6137          ----------------
6138          -- Check_Name --
6139          ----------------
6140
6141          --  pragma Check_Name (check_IDENTIFIER);
6142
6143          when Pragma_Check_Name =>
6144             Check_No_Identifiers;
6145             GNAT_Pragma;
6146             Check_Valid_Configuration_Pragma;
6147             Check_Arg_Count (1);
6148             Check_Arg_Is_Identifier (Arg1);
6149
6150             declare
6151                Nam : constant Name_Id := Chars (Expression (Arg1));
6152
6153             begin
6154                for J in Check_Names.First .. Check_Names.Last loop
6155                   if Check_Names.Table (J) = Nam then
6156                      return;
6157                   end if;
6158                end loop;
6159
6160                Check_Names.Append (Nam);
6161             end;
6162
6163          ------------------
6164          -- Check_Policy --
6165          ------------------
6166
6167          --  pragma Check_Policy (
6168          --    [Name   =>] IDENTIFIER,
6169          --    [Policy =>] POLICY_IDENTIFIER);
6170
6171          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6172
6173          --  Note: this is a configuration pragma, but it is allowed to appear
6174          --  anywhere else.
6175
6176          when Pragma_Check_Policy =>
6177             GNAT_Pragma;
6178             Check_Arg_Count (2);
6179             Check_Optional_Identifier (Arg1, Name_Name);
6180             Check_Optional_Identifier (Arg2, Name_Policy);
6181             Check_Arg_Is_One_Of
6182               (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6183
6184             --  A Check_Policy pragma can appear either as a configuration
6185             --  pragma, or in a declarative part or a package spec (see RM
6186             --  11.5(5) for rules for Suppress/Unsuppress which are also
6187             --  followed for Check_Policy).
6188
6189             if not Is_Configuration_Pragma then
6190                Check_Is_In_Decl_Part_Or_Package_Spec;
6191             end if;
6192
6193             Set_Next_Pragma (N, Opt.Check_Policy_List);
6194             Opt.Check_Policy_List := N;
6195
6196          ---------------------
6197          -- CIL_Constructor --
6198          ---------------------
6199
6200          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6201
6202          --  Processing for this pragma is shared with Java_Constructor
6203
6204          -------------
6205          -- Comment --
6206          -------------
6207
6208          --  pragma Comment (static_string_EXPRESSION)
6209
6210          --  Processing for pragma Comment shares the circuitry for pragma
6211          --  Ident. The only differences are that Ident enforces a limit of 31
6212          --  characters on its argument, and also enforces limitations on
6213          --  placement for DEC compatibility. Pragma Comment shares neither of
6214          --  these restrictions.
6215
6216          -------------------
6217          -- Common_Object --
6218          -------------------
6219
6220          --  pragma Common_Object (
6221          --        [Internal =>] LOCAL_NAME
6222          --     [, [External =>] EXTERNAL_SYMBOL]
6223          --     [, [Size     =>] EXTERNAL_SYMBOL]);
6224
6225          --  Processing for this pragma is shared with Psect_Object
6226
6227          ------------------------
6228          -- Compile_Time_Error --
6229          ------------------------
6230
6231          --  pragma Compile_Time_Error
6232          --    (boolean_EXPRESSION, static_string_EXPRESSION);
6233
6234          when Pragma_Compile_Time_Error =>
6235             GNAT_Pragma;
6236             Process_Compile_Time_Warning_Or_Error;
6237
6238          --------------------------
6239          -- Compile_Time_Warning --
6240          --------------------------
6241
6242          --  pragma Compile_Time_Warning
6243          --    (boolean_EXPRESSION, static_string_EXPRESSION);
6244
6245          when Pragma_Compile_Time_Warning =>
6246             GNAT_Pragma;
6247             Process_Compile_Time_Warning_Or_Error;
6248
6249          -------------------
6250          -- Compiler_Unit --
6251          -------------------
6252
6253          when Pragma_Compiler_Unit =>
6254             GNAT_Pragma;
6255             Check_Arg_Count (0);
6256             Set_Is_Compiler_Unit (Get_Source_Unit (N));
6257
6258          -----------------------------
6259          -- Complete_Representation --
6260          -----------------------------
6261
6262          --  pragma Complete_Representation;
6263
6264          when Pragma_Complete_Representation =>
6265             GNAT_Pragma;
6266             Check_Arg_Count (0);
6267
6268             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6269                Error_Pragma
6270                  ("pragma & must appear within record representation clause");
6271             end if;
6272
6273          ----------------------------
6274          -- Complex_Representation --
6275          ----------------------------
6276
6277          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6278
6279          when Pragma_Complex_Representation => Complex_Representation : declare
6280             E_Id : Entity_Id;
6281             E    : Entity_Id;
6282             Ent  : Entity_Id;
6283
6284          begin
6285             GNAT_Pragma;
6286             Check_Arg_Count (1);
6287             Check_Optional_Identifier (Arg1, Name_Entity);
6288             Check_Arg_Is_Local_Name (Arg1);
6289             E_Id := Expression (Arg1);
6290
6291             if Etype (E_Id) = Any_Type then
6292                return;
6293             end if;
6294
6295             E := Entity (E_Id);
6296
6297             if not Is_Record_Type (E) then
6298                Error_Pragma_Arg
6299                  ("argument for pragma% must be record type", Arg1);
6300             end if;
6301
6302             Ent := First_Entity (E);
6303
6304             if No (Ent)
6305               or else No (Next_Entity (Ent))
6306               or else Present (Next_Entity (Next_Entity (Ent)))
6307               or else not Is_Floating_Point_Type (Etype (Ent))
6308               or else Etype (Ent) /= Etype (Next_Entity (Ent))
6309             then
6310                Error_Pragma_Arg
6311                  ("record for pragma% must have two fields of the same "
6312                   & "floating-point type", Arg1);
6313
6314             else
6315                Set_Has_Complex_Representation (Base_Type (E));
6316
6317                --  We need to treat the type has having a non-standard
6318                --  representation, for back-end purposes, even though in
6319                --  general a complex will have the default representation
6320                --  of a record with two real components.
6321
6322                Set_Has_Non_Standard_Rep (Base_Type (E));
6323             end if;
6324          end Complex_Representation;
6325
6326          -------------------------
6327          -- Component_Alignment --
6328          -------------------------
6329
6330          --  pragma Component_Alignment (
6331          --        [Form =>] ALIGNMENT_CHOICE
6332          --     [, [Name =>] type_LOCAL_NAME]);
6333          --
6334          --   ALIGNMENT_CHOICE ::=
6335          --     Component_Size
6336          --   | Component_Size_4
6337          --   | Storage_Unit
6338          --   | Default
6339
6340          when Pragma_Component_Alignment => Component_AlignmentP : declare
6341             Args  : Args_List (1 .. 2);
6342             Names : constant Name_List (1 .. 2) := (
6343                       Name_Form,
6344                       Name_Name);
6345
6346             Form  : Node_Id renames Args (1);
6347             Name  : Node_Id renames Args (2);
6348
6349             Atype : Component_Alignment_Kind;
6350             Typ   : Entity_Id;
6351
6352          begin
6353             GNAT_Pragma;
6354             Gather_Associations (Names, Args);
6355
6356             if No (Form) then
6357                Error_Pragma ("missing Form argument for pragma%");
6358             end if;
6359
6360             Check_Arg_Is_Identifier (Form);
6361
6362             --  Get proper alignment, note that Default = Component_Size on all
6363             --  machines we have so far, and we want to set this value rather
6364             --  than the default value to indicate that it has been explicitly
6365             --  set (and thus will not get overridden by the default component
6366             --  alignment for the current scope)
6367
6368             if Chars (Form) = Name_Component_Size then
6369                Atype := Calign_Component_Size;
6370
6371             elsif Chars (Form) = Name_Component_Size_4 then
6372                Atype := Calign_Component_Size_4;
6373
6374             elsif Chars (Form) = Name_Default then
6375                Atype := Calign_Component_Size;
6376
6377             elsif Chars (Form) = Name_Storage_Unit then
6378                Atype := Calign_Storage_Unit;
6379
6380             else
6381                Error_Pragma_Arg
6382                  ("invalid Form parameter for pragma%", Form);
6383             end if;
6384
6385             --  Case with no name, supplied, affects scope table entry
6386
6387             if No (Name) then
6388                Scope_Stack.Table
6389                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
6390
6391             --  Case of name supplied
6392
6393             else
6394                Check_Arg_Is_Local_Name (Name);
6395                Find_Type (Name);
6396                Typ := Entity (Name);
6397
6398                if Typ = Any_Type
6399                  or else Rep_Item_Too_Early (Typ, N)
6400                then
6401                   return;
6402                else
6403                   Typ := Underlying_Type (Typ);
6404                end if;
6405
6406                if not Is_Record_Type (Typ)
6407                  and then not Is_Array_Type (Typ)
6408                then
6409                   Error_Pragma_Arg
6410                     ("Name parameter of pragma% must identify record or " &
6411                      "array type", Name);
6412                end if;
6413
6414                --  An explicit Component_Alignment pragma overrides an
6415                --  implicit pragma Pack, but not an explicit one.
6416
6417                if not Has_Pragma_Pack (Base_Type (Typ)) then
6418                   Set_Is_Packed (Base_Type (Typ), False);
6419                   Set_Component_Alignment (Base_Type (Typ), Atype);
6420                end if;
6421             end if;
6422          end Component_AlignmentP;
6423
6424          ----------------
6425          -- Controlled --
6426          ----------------
6427
6428          --  pragma Controlled (first_subtype_LOCAL_NAME);
6429
6430          when Pragma_Controlled => Controlled : declare
6431             Arg : Node_Id;
6432
6433          begin
6434             Check_No_Identifiers;
6435             Check_Arg_Count (1);
6436             Check_Arg_Is_Local_Name (Arg1);
6437             Arg := Expression (Arg1);
6438
6439             if not Is_Entity_Name (Arg)
6440               or else not Is_Access_Type (Entity (Arg))
6441             then
6442                Error_Pragma_Arg ("pragma% requires access type", Arg1);
6443             else
6444                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6445             end if;
6446          end Controlled;
6447
6448          ----------------
6449          -- Convention --
6450          ----------------
6451
6452          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
6453          --    [Entity =>] LOCAL_NAME);
6454
6455          when Pragma_Convention => Convention : declare
6456             C : Convention_Id;
6457             E : Entity_Id;
6458             pragma Warnings (Off, C);
6459             pragma Warnings (Off, E);
6460          begin
6461             Check_Arg_Order ((Name_Convention, Name_Entity));
6462             Check_Ada_83_Warning;
6463             Check_Arg_Count (2);
6464             Process_Convention (C, E);
6465          end Convention;
6466
6467          ---------------------------
6468          -- Convention_Identifier --
6469          ---------------------------
6470
6471          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
6472          --    [Convention =>] convention_IDENTIFIER);
6473
6474          when Pragma_Convention_Identifier => Convention_Identifier : declare
6475             Idnam : Name_Id;
6476             Cname : Name_Id;
6477
6478          begin
6479             GNAT_Pragma;
6480             Check_Arg_Order ((Name_Name, Name_Convention));
6481             Check_Arg_Count (2);
6482             Check_Optional_Identifier (Arg1, Name_Name);
6483             Check_Optional_Identifier (Arg2, Name_Convention);
6484             Check_Arg_Is_Identifier (Arg1);
6485             Check_Arg_Is_Identifier (Arg2);
6486             Idnam := Chars (Expression (Arg1));
6487             Cname := Chars (Expression (Arg2));
6488
6489             if Is_Convention_Name (Cname) then
6490                Record_Convention_Identifier
6491                  (Idnam, Get_Convention_Id (Cname));
6492             else
6493                Error_Pragma_Arg
6494                  ("second arg for % pragma must be convention", Arg2);
6495             end if;
6496          end Convention_Identifier;
6497
6498          ---------------
6499          -- CPP_Class --
6500          ---------------
6501
6502          --  pragma CPP_Class ([Entity =>] local_NAME)
6503
6504          when Pragma_CPP_Class => CPP_Class : declare
6505             Arg : Node_Id;
6506             Typ : Entity_Id;
6507
6508          begin
6509             if Warn_On_Obsolescent_Feature then
6510                Error_Msg_N
6511                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6512                   " by pragma import?", N);
6513             end if;
6514
6515             GNAT_Pragma;
6516             Check_Arg_Count (1);
6517             Check_Optional_Identifier (Arg1, Name_Entity);
6518             Check_Arg_Is_Local_Name (Arg1);
6519
6520             Arg := Expression (Arg1);
6521             Analyze (Arg);
6522
6523             if Etype (Arg) = Any_Type then
6524                return;
6525             end if;
6526
6527             if not Is_Entity_Name (Arg)
6528               or else not Is_Type (Entity (Arg))
6529             then
6530                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6531             end if;
6532
6533             Typ := Entity (Arg);
6534
6535             if not Is_Tagged_Type (Typ) then
6536                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6537             end if;
6538
6539             --  Types treated as CPP classes are treated as limited, but we
6540             --  don't require them to be declared this way. A warning is issued
6541             --  to encourage the user to declare them as limited. This is not
6542             --  an error, for compatibility reasons, because these types have
6543             --  been supported this way for some time.
6544
6545             if not Is_Limited_Type (Typ) then
6546                Error_Msg_N
6547                  ("imported 'C'P'P type should be " &
6548                     "explicitly declared limited?",
6549                   Get_Pragma_Arg (Arg1));
6550                Error_Msg_N
6551                  ("\type will be considered limited",
6552                   Get_Pragma_Arg (Arg1));
6553             end if;
6554
6555             Set_Is_CPP_Class      (Typ);
6556             Set_Is_Limited_Record (Typ);
6557             Set_Convention        (Typ, Convention_CPP);
6558
6559             --  Imported CPP types must not have discriminants (because C++
6560             --  classes do not have discriminants).
6561
6562             if Has_Discriminants (Typ) then
6563                Error_Msg_N
6564                  ("imported 'C'P'P type cannot have discriminants",
6565                   First (Discriminant_Specifications
6566                           (Declaration_Node (Typ))));
6567             end if;
6568
6569             --  Components of imported CPP types must not have default
6570             --  expressions because the constructor (if any) is in the
6571             --  C++ side.
6572
6573             if Is_Incomplete_Or_Private_Type (Typ)
6574               and then No (Underlying_Type (Typ))
6575             then
6576                --  It should be an error to apply pragma CPP to a private
6577                --  type if the underlying type is not visible (as it is
6578                --  for any representation item). For now, for backward
6579                --  compatibility we do nothing but we cannot check components
6580                --  because they are not available at this stage. All this code
6581                --  will be removed when we cleanup this obsolete GNAT pragma???
6582
6583                null;
6584
6585             else
6586                declare
6587                   Tdef  : constant Node_Id :=
6588                             Type_Definition (Declaration_Node (Typ));
6589                   Clist : Node_Id;
6590                   Comp  : Node_Id;
6591
6592                begin
6593                   if Nkind (Tdef) = N_Record_Definition then
6594                      Clist := Component_List (Tdef);
6595                   else
6596                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6597                      Clist := Component_List (Record_Extension_Part (Tdef));
6598                   end if;
6599
6600                   if Present (Clist) then
6601                      Comp := First (Component_Items (Clist));
6602                      while Present (Comp) loop
6603                         if Present (Expression (Comp)) then
6604                            Error_Msg_N
6605                              ("component of imported 'C'P'P type cannot have" &
6606                               " default expression", Expression (Comp));
6607                         end if;
6608
6609                         Next (Comp);
6610                      end loop;
6611                   end if;
6612                end;
6613             end if;
6614          end CPP_Class;
6615
6616          ---------------------
6617          -- CPP_Constructor --
6618          ---------------------
6619
6620          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6621          --    [, [External_Name =>] static_string_EXPRESSION ]
6622          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
6623
6624          when Pragma_CPP_Constructor => CPP_Constructor : declare
6625             Elmt    : Elmt_Id;
6626             Id      : Entity_Id;
6627             Def_Id  : Entity_Id;
6628             Tag_Typ : Entity_Id;
6629
6630          begin
6631             GNAT_Pragma;
6632             Check_At_Least_N_Arguments (1);
6633             Check_At_Most_N_Arguments (3);
6634             Check_Optional_Identifier (Arg1, Name_Entity);
6635             Check_Arg_Is_Local_Name (Arg1);
6636
6637             Id := Expression (Arg1);
6638             Find_Program_Unit_Name (Id);
6639
6640             --  If we did not find the name, we are done
6641
6642             if Etype (Id) = Any_Type then
6643                return;
6644             end if;
6645
6646             Def_Id := Entity (Id);
6647
6648             --  Check if already defined as constructor
6649
6650             if Is_Constructor (Def_Id) then
6651                Error_Msg_N
6652                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
6653                return;
6654             end if;
6655
6656             if Ekind (Def_Id) = E_Function
6657               and then (Is_CPP_Class (Etype (Def_Id))
6658                          or else (Is_Class_Wide_Type (Etype (Def_Id))
6659                                    and then
6660                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
6661             then
6662                if Arg_Count >= 2 then
6663                   Set_Imported (Def_Id);
6664                   Set_Is_Public (Def_Id);
6665                   Process_Interface_Name (Def_Id, Arg2, Arg3);
6666                end if;
6667
6668                Set_Has_Completion (Def_Id);
6669                Set_Is_Constructor (Def_Id);
6670
6671                --  Imported C++ constructors are not dispatching primitives
6672                --  because in C++ they don't have a dispatch table slot.
6673                --  However, in Ada the constructor has the profile of a
6674                --  function that returns a tagged type and therefore it has
6675                --  been treated as a primitive operation during semantic
6676                --  analysis. We now remove it from the list of primitive
6677                --  operations of the type.
6678
6679                if Is_Tagged_Type (Etype (Def_Id))
6680                  and then not Is_Class_Wide_Type (Etype (Def_Id))
6681                then
6682                   pragma Assert (Is_Dispatching_Operation (Def_Id));
6683                   Tag_Typ := Etype (Def_Id);
6684
6685                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
6686                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
6687                      Next_Elmt (Elmt);
6688                   end loop;
6689
6690                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
6691                   Set_Is_Dispatching_Operation (Def_Id, False);
6692                end if;
6693
6694                --  For backward compatibility, if the constructor returns a
6695                --  class wide type, and we internally change the return type to
6696                --  the corresponding root type.
6697
6698                if Is_Class_Wide_Type (Etype (Def_Id)) then
6699                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
6700                end if;
6701             else
6702                Error_Pragma_Arg
6703                  ("pragma% requires function returning a 'C'P'P_Class type",
6704                    Arg1);
6705             end if;
6706          end CPP_Constructor;
6707
6708          -----------------
6709          -- CPP_Virtual --
6710          -----------------
6711
6712          when Pragma_CPP_Virtual => CPP_Virtual : declare
6713          begin
6714             GNAT_Pragma;
6715
6716             if Warn_On_Obsolescent_Feature then
6717                Error_Msg_N
6718                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6719                   "no effect?", N);
6720             end if;
6721          end CPP_Virtual;
6722
6723          ----------------
6724          -- CPP_Vtable --
6725          ----------------
6726
6727          when Pragma_CPP_Vtable => CPP_Vtable : declare
6728          begin
6729             GNAT_Pragma;
6730
6731             if Warn_On_Obsolescent_Feature then
6732                Error_Msg_N
6733                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6734                   "no effect?", N);
6735             end if;
6736          end CPP_Vtable;
6737
6738          -----------
6739          -- Debug --
6740          -----------
6741
6742          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6743
6744          when Pragma_Debug => Debug : declare
6745                Cond : Node_Id;
6746
6747          begin
6748             GNAT_Pragma;
6749
6750             Cond :=
6751               New_Occurrence_Of
6752                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6753                  Loc);
6754
6755             if Arg_Count = 2 then
6756                Cond :=
6757                  Make_And_Then (Loc,
6758                    Left_Opnd   => Relocate_Node (Cond),
6759                    Right_Opnd  => Expression (Arg1));
6760             end if;
6761
6762             --  Rewrite into a conditional with an appropriate condition. We
6763             --  wrap the procedure call in a block so that overhead from e.g.
6764             --  use of the secondary stack does not generate execution overhead
6765             --  for suppressed conditions.
6766
6767             Rewrite (N, Make_Implicit_If_Statement (N,
6768               Condition => Cond,
6769                  Then_Statements => New_List (
6770                    Make_Block_Statement (Loc,
6771                      Handled_Statement_Sequence =>
6772                        Make_Handled_Sequence_Of_Statements (Loc,
6773                          Statements => New_List (
6774                            Relocate_Node (Debug_Statement (N))))))));
6775             Analyze (N);
6776          end Debug;
6777
6778          ------------------
6779          -- Debug_Policy --
6780          ------------------
6781
6782          --  pragma Debug_Policy (Check | Ignore)
6783
6784          when Pragma_Debug_Policy =>
6785             GNAT_Pragma;
6786             Check_Arg_Count (1);
6787             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6788             Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6789
6790          ---------------------
6791          -- Detect_Blocking --
6792          ---------------------
6793
6794          --  pragma Detect_Blocking;
6795
6796          when Pragma_Detect_Blocking =>
6797             Ada_2005_Pragma;
6798             Check_Arg_Count (0);
6799             Check_Valid_Configuration_Pragma;
6800             Detect_Blocking := True;
6801
6802          ---------------
6803          -- Dimension --
6804          ---------------
6805
6806          when Pragma_Dimension =>
6807             GNAT_Pragma;
6808             Check_Arg_Count (4);
6809             Check_No_Identifiers;
6810             Check_Arg_Is_Local_Name (Arg1);
6811
6812             if not Is_Type (Arg1) then
6813                Error_Pragma ("first argument for pragma% must be subtype");
6814             end if;
6815
6816             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
6817             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
6818             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
6819
6820          -------------------
6821          -- Discard_Names --
6822          -------------------
6823
6824          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
6825
6826          when Pragma_Discard_Names => Discard_Names : declare
6827             E    : Entity_Id;
6828             E_Id : Entity_Id;
6829
6830          begin
6831             Check_Ada_83_Warning;
6832
6833             --  Deal with configuration pragma case
6834
6835             if Arg_Count = 0 and then Is_Configuration_Pragma then
6836                Global_Discard_Names := True;
6837                return;
6838
6839             --  Otherwise, check correct appropriate context
6840
6841             else
6842                Check_Is_In_Decl_Part_Or_Package_Spec;
6843
6844                if Arg_Count = 0 then
6845
6846                   --  If there is no parameter, then from now on this pragma
6847                   --  applies to any enumeration, exception or tagged type
6848                   --  defined in the current declarative part, and recursively
6849                   --  to any nested scope.
6850
6851                   Set_Discard_Names (Current_Scope);
6852                   return;
6853
6854                else
6855                   Check_Arg_Count (1);
6856                   Check_Optional_Identifier (Arg1, Name_On);
6857                   Check_Arg_Is_Local_Name (Arg1);
6858
6859                   E_Id := Expression (Arg1);
6860
6861                   if Etype (E_Id) = Any_Type then
6862                      return;
6863                   else
6864                      E := Entity (E_Id);
6865                   end if;
6866
6867                   if (Is_First_Subtype (E)
6868                       and then
6869                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6870                     or else Ekind (E) = E_Exception
6871                   then
6872                      Set_Discard_Names (E);
6873                   else
6874                      Error_Pragma_Arg
6875                        ("inappropriate entity for pragma%", Arg1);
6876                   end if;
6877
6878                end if;
6879             end if;
6880          end Discard_Names;
6881
6882          ---------------
6883          -- Elaborate --
6884          ---------------
6885
6886          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6887
6888          when Pragma_Elaborate => Elaborate : declare
6889             Arg   : Node_Id;
6890             Citem : Node_Id;
6891
6892          begin
6893             --  Pragma must be in context items list of a compilation unit
6894
6895             if not Is_In_Context_Clause then
6896                Pragma_Misplaced;
6897             end if;
6898
6899             --  Must be at least one argument
6900
6901             if Arg_Count = 0 then
6902                Error_Pragma ("pragma% requires at least one argument");
6903             end if;
6904
6905             --  In Ada 83 mode, there can be no items following it in the
6906             --  context list except other pragmas and implicit with clauses
6907             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6908             --  placement rule does not apply.
6909
6910             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6911                Citem := Next (N);
6912                while Present (Citem) loop
6913                   if Nkind (Citem) = N_Pragma
6914                     or else (Nkind (Citem) = N_With_Clause
6915                               and then Implicit_With (Citem))
6916                   then
6917                      null;
6918                   else
6919                      Error_Pragma
6920                        ("(Ada 83) pragma% must be at end of context clause");
6921                   end if;
6922
6923                   Next (Citem);
6924                end loop;
6925             end if;
6926
6927             --  Finally, the arguments must all be units mentioned in a with
6928             --  clause in the same context clause. Note we already checked (in
6929             --  Par.Prag) that the arguments are all identifiers or selected
6930             --  components.
6931
6932             Arg := Arg1;
6933             Outer : while Present (Arg) loop
6934                Citem := First (List_Containing (N));
6935                Inner : while Citem /= N loop
6936                   if Nkind (Citem) = N_With_Clause
6937                     and then Same_Name (Name (Citem), Expression (Arg))
6938                   then
6939                      Set_Elaborate_Present (Citem, True);
6940                      Set_Unit_Name (Expression (Arg), Name (Citem));
6941
6942                      --  With the pragma present, elaboration calls on
6943                      --  subprograms from the named unit need no further
6944                      --  checks, as long as the pragma appears in the current
6945                      --  compilation unit. If the pragma appears in some unit
6946                      --  in the context, there might still be a need for an
6947                      --  Elaborate_All_Desirable from the current compilation
6948                      --  to the named unit, so we keep the check enabled.
6949
6950                      if In_Extended_Main_Source_Unit (N) then
6951                         Set_Suppress_Elaboration_Warnings
6952                           (Entity (Name (Citem)));
6953                      end if;
6954
6955                      exit Inner;
6956                   end if;
6957
6958                   Next (Citem);
6959                end loop Inner;
6960
6961                if Citem = N then
6962                   Error_Pragma_Arg
6963                     ("argument of pragma% is not with'ed unit", Arg);
6964                end if;
6965
6966                Next (Arg);
6967             end loop Outer;
6968
6969             --  Give a warning if operating in static mode with -gnatwl
6970             --  (elaboration warnings enabled) switch set.
6971
6972             if Elab_Warnings and not Dynamic_Elaboration_Checks then
6973                Error_Msg_N
6974                  ("?use of pragma Elaborate may not be safe", N);
6975                Error_Msg_N
6976                  ("?use pragma Elaborate_All instead if possible", N);
6977             end if;
6978          end Elaborate;
6979
6980          -------------------
6981          -- Elaborate_All --
6982          -------------------
6983
6984          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6985
6986          when Pragma_Elaborate_All => Elaborate_All : declare
6987             Arg   : Node_Id;
6988             Citem : Node_Id;
6989
6990          begin
6991             Check_Ada_83_Warning;
6992
6993             --  Pragma must be in context items list of a compilation unit
6994
6995             if not Is_In_Context_Clause then
6996                Pragma_Misplaced;
6997             end if;
6998
6999             --  Must be at least one argument
7000
7001             if Arg_Count = 0 then
7002                Error_Pragma ("pragma% requires at least one argument");
7003             end if;
7004
7005             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
7006             --  have to appear at the end of the context clause, but may
7007             --  appear mixed in with other items, even in Ada 83 mode.
7008
7009             --  Final check: the arguments must all be units mentioned in
7010             --  a with clause in the same context clause. Note that we
7011             --  already checked (in Par.Prag) that all the arguments are
7012             --  either identifiers or selected components.
7013
7014             Arg := Arg1;
7015             Outr : while Present (Arg) loop
7016                Citem := First (List_Containing (N));
7017                Innr : while Citem /= N loop
7018                   if Nkind (Citem) = N_With_Clause
7019                     and then Same_Name (Name (Citem), Expression (Arg))
7020                   then
7021                      Set_Elaborate_All_Present (Citem, True);
7022                      Set_Unit_Name (Expression (Arg), Name (Citem));
7023
7024                      --  Suppress warnings and elaboration checks on the named
7025                      --  unit if the pragma is in the current compilation, as
7026                      --  for pragma Elaborate.
7027
7028                      if In_Extended_Main_Source_Unit (N) then
7029                         Set_Suppress_Elaboration_Warnings
7030                           (Entity (Name (Citem)));
7031                      end if;
7032                      exit Innr;
7033                   end if;
7034
7035                   Next (Citem);
7036                end loop Innr;
7037
7038                if Citem = N then
7039                   Set_Error_Posted (N);
7040                   Error_Pragma_Arg
7041                     ("argument of pragma% is not with'ed unit", Arg);
7042                end if;
7043
7044                Next (Arg);
7045             end loop Outr;
7046          end Elaborate_All;
7047
7048          --------------------
7049          -- Elaborate_Body --
7050          --------------------
7051
7052          --  pragma Elaborate_Body [( library_unit_NAME )];
7053
7054          when Pragma_Elaborate_Body => Elaborate_Body : declare
7055             Cunit_Node : Node_Id;
7056             Cunit_Ent  : Entity_Id;
7057
7058          begin
7059             Check_Ada_83_Warning;
7060             Check_Valid_Library_Unit_Pragma;
7061
7062             if Nkind (N) = N_Null_Statement then
7063                return;
7064             end if;
7065
7066             Cunit_Node := Cunit (Current_Sem_Unit);
7067             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
7068
7069             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7070                                             N_Subprogram_Body)
7071             then
7072                Error_Pragma ("pragma% must refer to a spec, not a body");
7073             else
7074                Set_Body_Required (Cunit_Node, True);
7075                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7076
7077                --  If we are in dynamic elaboration mode, then we suppress
7078                --  elaboration warnings for the unit, since it is definitely
7079                --  fine NOT to do dynamic checks at the first level (and such
7080                --  checks will be suppressed because no elaboration boolean
7081                --  is created for Elaborate_Body packages).
7082
7083                --  But in the static model of elaboration, Elaborate_Body is
7084                --  definitely NOT good enough to ensure elaboration safety on
7085                --  its own, since the body may WITH other units that are not
7086                --  safe from an elaboration point of view, so a client must
7087                --  still do an Elaborate_All on such units.
7088
7089                --  Debug flag -gnatdD restores the old behavior of 3.13, where
7090                --  Elaborate_Body always suppressed elab warnings.
7091
7092                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7093                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7094                end if;
7095             end if;
7096          end Elaborate_Body;
7097
7098          ------------------------
7099          -- Elaboration_Checks --
7100          ------------------------
7101
7102          --  pragma Elaboration_Checks (Static | Dynamic);
7103
7104          when Pragma_Elaboration_Checks =>
7105             GNAT_Pragma;
7106             Check_Arg_Count (1);
7107             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7108             Dynamic_Elaboration_Checks :=
7109               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7110
7111          ---------------
7112          -- Eliminate --
7113          ---------------
7114
7115          --  pragma Eliminate (
7116          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
7117          --    [,[Entity     =>] IDENTIFIER |
7118          --                      SELECTED_COMPONENT |
7119          --                      STRING_LITERAL]
7120          --    [,                OVERLOADING_RESOLUTION]);
7121
7122          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7123          --                             SOURCE_LOCATION
7124
7125          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7126          --                                        FUNCTION_PROFILE
7127
7128          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7129
7130          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7131          --                       Result_Type => result_SUBTYPE_NAME]
7132
7133          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7134          --  SUBTYPE_NAME    ::= STRING_LITERAL
7135
7136          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7137          --  SOURCE_TRACE    ::= STRING_LITERAL
7138
7139          when Pragma_Eliminate => Eliminate : declare
7140             Args  : Args_List (1 .. 5);
7141             Names : constant Name_List (1 .. 5) := (
7142                       Name_Unit_Name,
7143                       Name_Entity,
7144                       Name_Parameter_Types,
7145                       Name_Result_Type,
7146                       Name_Source_Location);
7147
7148             Unit_Name       : Node_Id renames Args (1);
7149             Entity          : Node_Id renames Args (2);
7150             Parameter_Types : Node_Id renames Args (3);
7151             Result_Type     : Node_Id renames Args (4);
7152             Source_Location : Node_Id renames Args (5);
7153
7154          begin
7155             GNAT_Pragma;
7156             Check_Valid_Configuration_Pragma;
7157             Gather_Associations (Names, Args);
7158
7159             if No (Unit_Name) then
7160                Error_Pragma ("missing Unit_Name argument for pragma%");
7161             end if;
7162
7163             if No (Entity)
7164               and then (Present (Parameter_Types)
7165                           or else
7166                         Present (Result_Type)
7167                           or else
7168                         Present (Source_Location))
7169             then
7170                Error_Pragma ("missing Entity argument for pragma%");
7171             end if;
7172
7173             if (Present (Parameter_Types)
7174                        or else
7175                 Present (Result_Type))
7176               and then
7177                 Present (Source_Location)
7178             then
7179                Error_Pragma
7180                  ("parameter profile and source location cannot " &
7181                   "be used together in pragma%");
7182             end if;
7183
7184             Process_Eliminate_Pragma
7185               (N,
7186                Unit_Name,
7187                Entity,
7188                Parameter_Types,
7189                Result_Type,
7190                Source_Location);
7191          end Eliminate;
7192
7193          ------------
7194          -- Export --
7195          ------------
7196
7197          --  pragma Export (
7198          --    [   Convention    =>] convention_IDENTIFIER,
7199          --    [   Entity        =>] local_NAME
7200          --    [, [External_Name =>] static_string_EXPRESSION ]
7201          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7202
7203          when Pragma_Export => Export : declare
7204             C      : Convention_Id;
7205             Def_Id : Entity_Id;
7206
7207             pragma Warnings (Off, C);
7208
7209          begin
7210             Check_Ada_83_Warning;
7211             Check_Arg_Order
7212               ((Name_Convention,
7213                 Name_Entity,
7214                 Name_External_Name,
7215                 Name_Link_Name));
7216             Check_At_Least_N_Arguments (2);
7217             Check_At_Most_N_Arguments  (4);
7218             Process_Convention (C, Def_Id);
7219
7220             if Ekind (Def_Id) /= E_Constant then
7221                Note_Possible_Modification (Expression (Arg2), Sure => False);
7222             end if;
7223
7224             Process_Interface_Name (Def_Id, Arg3, Arg4);
7225             Set_Exported (Def_Id, Arg2);
7226
7227             --  If the entity is a deferred constant, propagate the information
7228             --  to the full view, because gigi elaborates the full view only.
7229
7230             if Ekind (Def_Id) = E_Constant
7231               and then Present (Full_View (Def_Id))
7232             then
7233                declare
7234                   Id2 : constant Entity_Id := Full_View (Def_Id);
7235                begin
7236                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
7237                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
7238                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7239                end;
7240             end if;
7241          end Export;
7242
7243          ----------------------
7244          -- Export_Exception --
7245          ----------------------
7246
7247          --  pragma Export_Exception (
7248          --        [Internal         =>] LOCAL_NAME
7249          --     [, [External         =>] EXTERNAL_SYMBOL]
7250          --     [, [Form     =>] Ada | VMS]
7251          --     [, [Code     =>] static_integer_EXPRESSION]);
7252
7253          when Pragma_Export_Exception => Export_Exception : declare
7254             Args  : Args_List (1 .. 4);
7255             Names : constant Name_List (1 .. 4) := (
7256                       Name_Internal,
7257                       Name_External,
7258                       Name_Form,
7259                       Name_Code);
7260
7261             Internal : Node_Id renames Args (1);
7262             External : Node_Id renames Args (2);
7263             Form     : Node_Id renames Args (3);
7264             Code     : Node_Id renames Args (4);
7265
7266          begin
7267             GNAT_Pragma;
7268
7269             if Inside_A_Generic then
7270                Error_Pragma ("pragma% cannot be used for generic entities");
7271             end if;
7272
7273             Gather_Associations (Names, Args);
7274             Process_Extended_Import_Export_Exception_Pragma (
7275               Arg_Internal => Internal,
7276               Arg_External => External,
7277               Arg_Form     => Form,
7278               Arg_Code     => Code);
7279
7280             if not Is_VMS_Exception (Entity (Internal)) then
7281                Set_Exported (Entity (Internal), Internal);
7282             end if;
7283          end Export_Exception;
7284
7285          ---------------------
7286          -- Export_Function --
7287          ---------------------
7288
7289          --  pragma Export_Function (
7290          --        [Internal         =>] LOCAL_NAME
7291          --     [, [External         =>] EXTERNAL_SYMBOL]
7292          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
7293          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
7294          --     [, [Mechanism        =>] MECHANISM]
7295          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
7296
7297          --  EXTERNAL_SYMBOL ::=
7298          --    IDENTIFIER
7299          --  | static_string_EXPRESSION
7300
7301          --  PARAMETER_TYPES ::=
7302          --    null
7303          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7304
7305          --  TYPE_DESIGNATOR ::=
7306          --    subtype_NAME
7307          --  | subtype_Name ' Access
7308
7309          --  MECHANISM ::=
7310          --    MECHANISM_NAME
7311          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7312
7313          --  MECHANISM_ASSOCIATION ::=
7314          --    [formal_parameter_NAME =>] MECHANISM_NAME
7315
7316          --  MECHANISM_NAME ::=
7317          --    Value
7318          --  | Reference
7319          --  | Descriptor [([Class =>] CLASS_NAME)]
7320
7321          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7322
7323          when Pragma_Export_Function => Export_Function : declare
7324             Args  : Args_List (1 .. 6);
7325             Names : constant Name_List (1 .. 6) := (
7326                       Name_Internal,
7327                       Name_External,
7328                       Name_Parameter_Types,
7329                       Name_Result_Type,
7330                       Name_Mechanism,
7331                       Name_Result_Mechanism);
7332
7333             Internal         : Node_Id renames Args (1);
7334             External         : Node_Id renames Args (2);
7335             Parameter_Types  : Node_Id renames Args (3);
7336             Result_Type      : Node_Id renames Args (4);
7337             Mechanism        : Node_Id renames Args (5);
7338             Result_Mechanism : Node_Id renames Args (6);
7339
7340          begin
7341             GNAT_Pragma;
7342             Gather_Associations (Names, Args);
7343             Process_Extended_Import_Export_Subprogram_Pragma (
7344               Arg_Internal         => Internal,
7345               Arg_External         => External,
7346               Arg_Parameter_Types  => Parameter_Types,
7347               Arg_Result_Type      => Result_Type,
7348               Arg_Mechanism        => Mechanism,
7349               Arg_Result_Mechanism => Result_Mechanism);
7350          end Export_Function;
7351
7352          -------------------
7353          -- Export_Object --
7354          -------------------
7355
7356          --  pragma Export_Object (
7357          --        [Internal =>] LOCAL_NAME
7358          --     [, [External =>] EXTERNAL_SYMBOL]
7359          --     [, [Size     =>] EXTERNAL_SYMBOL]);
7360
7361          --  EXTERNAL_SYMBOL ::=
7362          --    IDENTIFIER
7363          --  | static_string_EXPRESSION
7364
7365          --  PARAMETER_TYPES ::=
7366          --    null
7367          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7368
7369          --  TYPE_DESIGNATOR ::=
7370          --    subtype_NAME
7371          --  | subtype_Name ' Access
7372
7373          --  MECHANISM ::=
7374          --    MECHANISM_NAME
7375          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7376
7377          --  MECHANISM_ASSOCIATION ::=
7378          --    [formal_parameter_NAME =>] MECHANISM_NAME
7379
7380          --  MECHANISM_NAME ::=
7381          --    Value
7382          --  | Reference
7383          --  | Descriptor [([Class =>] CLASS_NAME)]
7384
7385          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7386
7387          when Pragma_Export_Object => Export_Object : declare
7388             Args  : Args_List (1 .. 3);
7389             Names : constant Name_List (1 .. 3) := (
7390                       Name_Internal,
7391                       Name_External,
7392                       Name_Size);
7393
7394             Internal : Node_Id renames Args (1);
7395             External : Node_Id renames Args (2);
7396             Size     : Node_Id renames Args (3);
7397
7398          begin
7399             GNAT_Pragma;
7400             Gather_Associations (Names, Args);
7401             Process_Extended_Import_Export_Object_Pragma (
7402               Arg_Internal => Internal,
7403               Arg_External => External,
7404               Arg_Size     => Size);
7405          end Export_Object;
7406
7407          ----------------------
7408          -- Export_Procedure --
7409          ----------------------
7410
7411          --  pragma Export_Procedure (
7412          --        [Internal         =>] LOCAL_NAME
7413          --     [, [External         =>] EXTERNAL_SYMBOL]
7414          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
7415          --     [, [Mechanism        =>] MECHANISM]);
7416
7417          --  EXTERNAL_SYMBOL ::=
7418          --    IDENTIFIER
7419          --  | static_string_EXPRESSION
7420
7421          --  PARAMETER_TYPES ::=
7422          --    null
7423          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7424
7425          --  TYPE_DESIGNATOR ::=
7426          --    subtype_NAME
7427          --  | subtype_Name ' Access
7428
7429          --  MECHANISM ::=
7430          --    MECHANISM_NAME
7431          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7432
7433          --  MECHANISM_ASSOCIATION ::=
7434          --    [formal_parameter_NAME =>] MECHANISM_NAME
7435
7436          --  MECHANISM_NAME ::=
7437          --    Value
7438          --  | Reference
7439          --  | Descriptor [([Class =>] CLASS_NAME)]
7440
7441          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7442
7443          when Pragma_Export_Procedure => Export_Procedure : declare
7444             Args  : Args_List (1 .. 4);
7445             Names : constant Name_List (1 .. 4) := (
7446                       Name_Internal,
7447                       Name_External,
7448                       Name_Parameter_Types,
7449                       Name_Mechanism);
7450
7451             Internal        : Node_Id renames Args (1);
7452             External        : Node_Id renames Args (2);
7453             Parameter_Types : Node_Id renames Args (3);
7454             Mechanism       : Node_Id renames Args (4);
7455
7456          begin
7457             GNAT_Pragma;
7458             Gather_Associations (Names, Args);
7459             Process_Extended_Import_Export_Subprogram_Pragma (
7460               Arg_Internal        => Internal,
7461               Arg_External        => External,
7462               Arg_Parameter_Types => Parameter_Types,
7463               Arg_Mechanism       => Mechanism);
7464          end Export_Procedure;
7465
7466          ------------------
7467          -- Export_Value --
7468          ------------------
7469
7470          --  pragma Export_Value (
7471          --     [Value     =>] static_integer_EXPRESSION,
7472          --     [Link_Name =>] static_string_EXPRESSION);
7473
7474          when Pragma_Export_Value =>
7475             GNAT_Pragma;
7476             Check_Arg_Order ((Name_Value, Name_Link_Name));
7477             Check_Arg_Count (2);
7478
7479             Check_Optional_Identifier (Arg1, Name_Value);
7480             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7481
7482             Check_Optional_Identifier (Arg2, Name_Link_Name);
7483             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7484
7485          -----------------------------
7486          -- Export_Valued_Procedure --
7487          -----------------------------
7488
7489          --  pragma Export_Valued_Procedure (
7490          --        [Internal         =>] LOCAL_NAME
7491          --     [, [External         =>] EXTERNAL_SYMBOL,]
7492          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
7493          --     [, [Mechanism        =>] MECHANISM]);
7494
7495          --  EXTERNAL_SYMBOL ::=
7496          --    IDENTIFIER
7497          --  | static_string_EXPRESSION
7498
7499          --  PARAMETER_TYPES ::=
7500          --    null
7501          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7502
7503          --  TYPE_DESIGNATOR ::=
7504          --    subtype_NAME
7505          --  | subtype_Name ' Access
7506
7507          --  MECHANISM ::=
7508          --    MECHANISM_NAME
7509          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7510
7511          --  MECHANISM_ASSOCIATION ::=
7512          --    [formal_parameter_NAME =>] MECHANISM_NAME
7513
7514          --  MECHANISM_NAME ::=
7515          --    Value
7516          --  | Reference
7517          --  | Descriptor [([Class =>] CLASS_NAME)]
7518
7519          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7520
7521          when Pragma_Export_Valued_Procedure =>
7522          Export_Valued_Procedure : declare
7523             Args  : Args_List (1 .. 4);
7524             Names : constant Name_List (1 .. 4) := (
7525                       Name_Internal,
7526                       Name_External,
7527                       Name_Parameter_Types,
7528                       Name_Mechanism);
7529
7530             Internal        : Node_Id renames Args (1);
7531             External        : Node_Id renames Args (2);
7532             Parameter_Types : Node_Id renames Args (3);
7533             Mechanism       : Node_Id renames Args (4);
7534
7535          begin
7536             GNAT_Pragma;
7537             Gather_Associations (Names, Args);
7538             Process_Extended_Import_Export_Subprogram_Pragma (
7539               Arg_Internal        => Internal,
7540               Arg_External        => External,
7541               Arg_Parameter_Types => Parameter_Types,
7542               Arg_Mechanism       => Mechanism);
7543          end Export_Valued_Procedure;
7544
7545          -------------------
7546          -- Extend_System --
7547          -------------------
7548
7549          --  pragma Extend_System ([Name =>] Identifier);
7550
7551          when Pragma_Extend_System => Extend_System : declare
7552          begin
7553             GNAT_Pragma;
7554             Check_Valid_Configuration_Pragma;
7555             Check_Arg_Count (1);
7556             Check_Optional_Identifier (Arg1, Name_Name);
7557             Check_Arg_Is_Identifier (Arg1);
7558
7559             Get_Name_String (Chars (Expression (Arg1)));
7560
7561             if Name_Len > 4
7562               and then Name_Buffer (1 .. 4) = "aux_"
7563             then
7564                if Present (System_Extend_Pragma_Arg) then
7565                   if Chars (Expression (Arg1)) =
7566                      Chars (Expression (System_Extend_Pragma_Arg))
7567                   then
7568                      null;
7569                   else
7570                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7571                      Error_Pragma ("pragma% conflicts with that #");
7572                   end if;
7573
7574                else
7575                   System_Extend_Pragma_Arg := Arg1;
7576
7577                   if not GNAT_Mode then
7578                      System_Extend_Unit := Arg1;
7579                   end if;
7580                end if;
7581             else
7582                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7583             end if;
7584          end Extend_System;
7585
7586          ------------------------
7587          -- Extensions_Allowed --
7588          ------------------------
7589
7590          --  pragma Extensions_Allowed (ON | OFF);
7591
7592          when Pragma_Extensions_Allowed =>
7593             GNAT_Pragma;
7594             Check_Arg_Count (1);
7595             Check_No_Identifiers;
7596             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7597
7598             if Chars (Expression (Arg1)) = Name_On then
7599                Extensions_Allowed := True;
7600                Ada_Version := Ada_Version_Type'Last;
7601
7602             else
7603                Extensions_Allowed := False;
7604                Ada_Version := Ada_Version_Explicit;
7605             end if;
7606
7607          --------------
7608          -- External --
7609          --------------
7610
7611          --  pragma External (
7612          --    [   Convention    =>] convention_IDENTIFIER,
7613          --    [   Entity        =>] local_NAME
7614          --    [, [External_Name =>] static_string_EXPRESSION ]
7615          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7616
7617          when Pragma_External => External : declare
7618                Def_Id : Entity_Id;
7619
7620                C : Convention_Id;
7621                pragma Warnings (Off, C);
7622
7623          begin
7624             GNAT_Pragma;
7625             Check_Arg_Order
7626               ((Name_Convention,
7627                 Name_Entity,
7628                 Name_External_Name,
7629                 Name_Link_Name));
7630             Check_At_Least_N_Arguments (2);
7631             Check_At_Most_N_Arguments  (4);
7632             Process_Convention (C, Def_Id);
7633             Note_Possible_Modification (Expression (Arg2), Sure => False);
7634             Process_Interface_Name (Def_Id, Arg3, Arg4);
7635             Set_Exported (Def_Id, Arg2);
7636          end External;
7637
7638          --------------------------
7639          -- External_Name_Casing --
7640          --------------------------
7641
7642          --  pragma External_Name_Casing (
7643          --    UPPERCASE | LOWERCASE
7644          --    [, AS_IS | UPPERCASE | LOWERCASE]);
7645
7646          when Pragma_External_Name_Casing => External_Name_Casing : declare
7647          begin
7648             GNAT_Pragma;
7649             Check_No_Identifiers;
7650
7651             if Arg_Count = 2 then
7652                Check_Arg_Is_One_Of
7653                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7654
7655                case Chars (Get_Pragma_Arg (Arg2)) is
7656                   when Name_As_Is     =>
7657                      Opt.External_Name_Exp_Casing := As_Is;
7658
7659                   when Name_Uppercase =>
7660                      Opt.External_Name_Exp_Casing := Uppercase;
7661
7662                   when Name_Lowercase =>
7663                      Opt.External_Name_Exp_Casing := Lowercase;
7664
7665                   when others =>
7666                      null;
7667                end case;
7668
7669             else
7670                Check_Arg_Count (1);
7671             end if;
7672
7673             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7674
7675             case Chars (Get_Pragma_Arg (Arg1)) is
7676                when Name_Uppercase =>
7677                   Opt.External_Name_Imp_Casing := Uppercase;
7678
7679                when Name_Lowercase =>
7680                   Opt.External_Name_Imp_Casing := Lowercase;
7681
7682                when others =>
7683                   null;
7684             end case;
7685          end External_Name_Casing;
7686
7687          --------------------------
7688          -- Favor_Top_Level --
7689          --------------------------
7690
7691          --  pragma Favor_Top_Level (type_NAME);
7692
7693          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7694                Named_Entity : Entity_Id;
7695
7696          begin
7697             GNAT_Pragma;
7698             Check_No_Identifiers;
7699             Check_Arg_Count (1);
7700             Check_Arg_Is_Local_Name (Arg1);
7701             Named_Entity := Entity (Expression (Arg1));
7702
7703             --  If it's an access-to-subprogram type (in particular, not a
7704             --  subtype), set the flag on that type.
7705
7706             if Is_Access_Subprogram_Type (Named_Entity) then
7707                Set_Can_Use_Internal_Rep (Named_Entity, False);
7708
7709             --  Otherwise it's an error (name denotes the wrong sort of entity)
7710
7711             else
7712                Error_Pragma_Arg
7713                  ("access-to-subprogram type expected", Expression (Arg1));
7714             end if;
7715          end Favor_Top_Level;
7716
7717          ---------------
7718          -- Fast_Math --
7719          ---------------
7720
7721          --  pragma Fast_Math;
7722
7723          when Pragma_Fast_Math =>
7724             GNAT_Pragma;
7725             Check_No_Identifiers;
7726             Check_Valid_Configuration_Pragma;
7727             Fast_Math := True;
7728
7729          ---------------------------
7730          -- Finalize_Storage_Only --
7731          ---------------------------
7732
7733          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7734
7735          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7736             Assoc   : constant Node_Id := Arg1;
7737             Type_Id : constant Node_Id := Expression (Assoc);
7738             Typ     : Entity_Id;
7739
7740          begin
7741             GNAT_Pragma;
7742             Check_No_Identifiers;
7743             Check_Arg_Count (1);
7744             Check_Arg_Is_Local_Name (Arg1);
7745
7746             Find_Type (Type_Id);
7747             Typ := Entity (Type_Id);
7748
7749             if Typ = Any_Type
7750               or else Rep_Item_Too_Early (Typ, N)
7751             then
7752                return;
7753             else
7754                Typ := Underlying_Type (Typ);
7755             end if;
7756
7757             if not Is_Controlled (Typ) then
7758                Error_Pragma ("pragma% must specify controlled type");
7759             end if;
7760
7761             Check_First_Subtype (Arg1);
7762
7763             if Finalize_Storage_Only (Typ) then
7764                Error_Pragma ("duplicate pragma%, only one allowed");
7765
7766             elsif not Rep_Item_Too_Late (Typ, N) then
7767                Set_Finalize_Storage_Only (Base_Type (Typ), True);
7768             end if;
7769          end Finalize_Storage;
7770
7771          --------------------------
7772          -- Float_Representation --
7773          --------------------------
7774
7775          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7776
7777          --  FLOAT_REP ::= VAX_Float | IEEE_Float
7778
7779          when Pragma_Float_Representation => Float_Representation : declare
7780             Argx : Node_Id;
7781             Digs : Nat;
7782             Ent  : Entity_Id;
7783
7784          begin
7785             GNAT_Pragma;
7786
7787             if Arg_Count = 1 then
7788                Check_Valid_Configuration_Pragma;
7789             else
7790                Check_Arg_Count (2);
7791                Check_Optional_Identifier (Arg2, Name_Entity);
7792                Check_Arg_Is_Local_Name (Arg2);
7793             end if;
7794
7795             Check_No_Identifier (Arg1);
7796             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7797
7798             if not OpenVMS_On_Target then
7799                if Chars (Expression (Arg1)) = Name_VAX_Float then
7800                   Error_Pragma
7801                     ("?pragma% ignored (applies only to Open'V'M'S)");
7802                end if;
7803
7804                return;
7805             end if;
7806
7807             --  One argument case
7808
7809             if Arg_Count = 1 then
7810                if Chars (Expression (Arg1)) = Name_VAX_Float then
7811                   if Opt.Float_Format = 'I' then
7812                      Error_Pragma ("'I'E'E'E format previously specified");
7813                   end if;
7814
7815                   Opt.Float_Format := 'V';
7816
7817                else
7818                   if Opt.Float_Format = 'V' then
7819                      Error_Pragma ("'V'A'X format previously specified");
7820                   end if;
7821
7822                   Opt.Float_Format := 'I';
7823                end if;
7824
7825                Set_Standard_Fpt_Formats;
7826
7827             --  Two argument case
7828
7829             else
7830                Argx := Get_Pragma_Arg (Arg2);
7831
7832                if not Is_Entity_Name (Argx)
7833                  or else not Is_Floating_Point_Type (Entity (Argx))
7834                then
7835                   Error_Pragma_Arg
7836                     ("second argument of% pragma must be floating-point type",
7837                      Arg2);
7838                end if;
7839
7840                Ent  := Entity (Argx);
7841                Digs := UI_To_Int (Digits_Value (Ent));
7842
7843                --  Two arguments, VAX_Float case
7844
7845                if Chars (Expression (Arg1)) = Name_VAX_Float then
7846                   case Digs is
7847                      when  6 => Set_F_Float (Ent);
7848                      when  9 => Set_D_Float (Ent);
7849                      when 15 => Set_G_Float (Ent);
7850
7851                      when others =>
7852                         Error_Pragma_Arg
7853                           ("wrong digits value, must be 6,9 or 15", Arg2);
7854                   end case;
7855
7856                --  Two arguments, IEEE_Float case
7857
7858                else
7859                   case Digs is
7860                      when  6 => Set_IEEE_Short (Ent);
7861                      when 15 => Set_IEEE_Long  (Ent);
7862
7863                      when others =>
7864                         Error_Pragma_Arg
7865                           ("wrong digits value, must be 6 or 15", Arg2);
7866                   end case;
7867                end if;
7868             end if;
7869          end Float_Representation;
7870
7871          -----------
7872          -- Ident --
7873          -----------
7874
7875          --  pragma Ident (static_string_EXPRESSION)
7876
7877          --  Note: pragma Comment shares this processing. Pragma Comment is
7878          --  identical to Ident, except that the restriction of the argument to
7879          --  31 characters and the placement restrictions are not enforced for
7880          --  pragma Comment.
7881
7882          when Pragma_Ident | Pragma_Comment => Ident : declare
7883             Str : Node_Id;
7884
7885          begin
7886             GNAT_Pragma;
7887             Check_Arg_Count (1);
7888             Check_No_Identifiers;
7889             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7890             Store_Note (N);
7891
7892             --  For pragma Ident, preserve DEC compatibility by requiring the
7893             --  pragma to appear in a declarative part or package spec.
7894
7895             if Prag_Id = Pragma_Ident then
7896                Check_Is_In_Decl_Part_Or_Package_Spec;
7897             end if;
7898
7899             Str := Expr_Value_S (Expression (Arg1));
7900
7901             declare
7902                CS : Node_Id;
7903                GP : Node_Id;
7904
7905             begin
7906                GP := Parent (Parent (N));
7907
7908                if Nkind_In (GP, N_Package_Declaration,
7909                                 N_Generic_Package_Declaration)
7910                then
7911                   GP := Parent (GP);
7912                end if;
7913
7914                --  If we have a compilation unit, then record the ident value,
7915                --  checking for improper duplication.
7916
7917                if Nkind (GP) = N_Compilation_Unit then
7918                   CS := Ident_String (Current_Sem_Unit);
7919
7920                   if Present (CS) then
7921
7922                      --  For Ident, we do not permit multiple instances
7923
7924                      if Prag_Id = Pragma_Ident then
7925                         Error_Pragma ("duplicate% pragma not permitted");
7926
7927                      --  For Comment, we concatenate the string, unless we want
7928                      --  to preserve the tree structure for ASIS.
7929
7930                      elsif not ASIS_Mode then
7931                         Start_String (Strval (CS));
7932                         Store_String_Char (' ');
7933                         Store_String_Chars (Strval (Str));
7934                         Set_Strval (CS, End_String);
7935                      end if;
7936
7937                   else
7938                      --  In VMS, the effect of IDENT is achieved by passing
7939                      --  --identification=name as a --for-linker switch.
7940
7941                      if OpenVMS_On_Target then
7942                         Start_String;
7943                         Store_String_Chars
7944                           ("--for-linker=--identification=");
7945                         String_To_Name_Buffer (Strval (Str));
7946                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
7947
7948                         --  Only the last processed IDENT is saved. The main
7949                         --  purpose is so an IDENT associated with a main
7950                         --  procedure will be used in preference to an IDENT
7951                         --  associated with a with'd package.
7952
7953                         Replace_Linker_Option_String
7954                           (End_String, "--for-linker=--identification=");
7955                      end if;
7956
7957                      Set_Ident_String (Current_Sem_Unit, Str);
7958                   end if;
7959
7960                --  For subunits, we just ignore the Ident, since in GNAT these
7961                --  are not separate object files, and hence not separate units
7962                --  in the unit table.
7963
7964                elsif Nkind (GP) = N_Subunit then
7965                   null;
7966
7967                --  Otherwise we have a misplaced pragma Ident, but we ignore
7968                --  this if we are in an instantiation, since it comes from
7969                --  a generic, and has no relevance to the instantiation.
7970
7971                elsif Prag_Id = Pragma_Ident then
7972                   if Instantiation_Location (Loc) = No_Location then
7973                      Error_Pragma ("pragma% only allowed at outer level");
7974                   end if;
7975                end if;
7976             end;
7977          end Ident;
7978
7979          -----------------
7980          -- Implemented --
7981          -----------------
7982
7983          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
7984          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
7985
7986          when Pragma_Implemented => Implemented : declare
7987             Proc_Id : Entity_Id;
7988             Typ     : Entity_Id;
7989
7990          begin
7991             Ada_2012_Pragma;
7992             Check_Arg_Count (2);
7993             Check_No_Identifiers;
7994             Check_Arg_Is_Identifier (Arg1);
7995             Check_Arg_Is_Local_Name (Arg1);
7996             Check_Arg_Is_One_Of
7997               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
7998
7999             --  Extract the name of the local procedure
8000
8001             Proc_Id := Entity (Expression (Arg1));
8002
8003             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8004             --  primitive procedure of a synchronized tagged type.
8005
8006             if Ekind (Proc_Id) = E_Procedure
8007               and then Is_Primitive (Proc_Id)
8008               and then Present (First_Formal (Proc_Id))
8009             then
8010                Typ := Etype (First_Formal (Proc_Id));
8011
8012                if Is_Tagged_Type (Typ)
8013                  and then
8014
8015                   --  Check for a protected, a synchronized or a task interface
8016
8017                    ((Is_Interface (Typ)
8018                        and then Is_Synchronized_Interface (Typ))
8019
8020                   --  Check for a protected type or a task type that implements
8021                   --  an interface.
8022
8023                    or else
8024                     (Is_Concurrent_Record_Type (Typ)
8025                        and then Present (Interfaces (Typ)))
8026
8027                   --  Check for a private record extension with keyword
8028                   --  "synchronized".
8029
8030                    or else
8031                     (Ekind_In (Typ, E_Record_Type_With_Private,
8032                                     E_Record_Subtype_With_Private)
8033                        and then Synchronized_Present (Parent (Typ))))
8034                then
8035                   null;
8036                else
8037                   Error_Pragma_Arg
8038                     ("controlling formal must be of synchronized " &
8039                      "tagged type", Arg1);
8040                   return;
8041                end if;
8042
8043             --  Procedures declared inside a protected type must be accepted
8044
8045             elsif Ekind (Proc_Id) = E_Procedure
8046               and then Is_Protected_Type (Scope (Proc_Id))
8047             then
8048                null;
8049
8050             --  The first argument is not a primitive procedure
8051
8052             else
8053                Error_Pragma_Arg
8054                  ("pragma % must be applied to a primitive procedure", Arg1);
8055                return;
8056             end if;
8057
8058             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8059             --  By_Protected_Procedure to the primitive procedure of a task
8060             --  interface.
8061
8062             if Chars (Arg2) = Name_By_Protected_Procedure
8063               and then Is_Interface (Typ)
8064               and then Is_Task_Interface (Typ)
8065             then
8066                Error_Pragma_Arg
8067                  ("implementation kind By_Protected_Procedure cannot be " &
8068                   "applied to a task interface primitive", Arg2);
8069                return;
8070             end if;
8071
8072             Record_Rep_Item (Proc_Id, N);
8073          end Implemented;
8074
8075          ----------------------
8076          -- Implicit_Packing --
8077          ----------------------
8078
8079          --  pragma Implicit_Packing;
8080
8081          when Pragma_Implicit_Packing =>
8082             GNAT_Pragma;
8083             Check_Arg_Count (0);
8084             Implicit_Packing := True;
8085
8086          ------------
8087          -- Import --
8088          ------------
8089
8090          --  pragma Import (
8091          --       [Convention    =>] convention_IDENTIFIER,
8092          --       [Entity        =>] local_NAME
8093          --    [, [External_Name =>] static_string_EXPRESSION ]
8094          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8095
8096          when Pragma_Import =>
8097             Check_Ada_83_Warning;
8098             Check_Arg_Order
8099               ((Name_Convention,
8100                 Name_Entity,
8101                 Name_External_Name,
8102                 Name_Link_Name));
8103             Check_At_Least_N_Arguments (2);
8104             Check_At_Most_N_Arguments  (4);
8105             Process_Import_Or_Interface;
8106
8107          ----------------------
8108          -- Import_Exception --
8109          ----------------------
8110
8111          --  pragma Import_Exception (
8112          --        [Internal         =>] LOCAL_NAME
8113          --     [, [External         =>] EXTERNAL_SYMBOL]
8114          --     [, [Form     =>] Ada | VMS]
8115          --     [, [Code     =>] static_integer_EXPRESSION]);
8116
8117          when Pragma_Import_Exception => Import_Exception : declare
8118             Args  : Args_List (1 .. 4);
8119             Names : constant Name_List (1 .. 4) := (
8120                       Name_Internal,
8121                       Name_External,
8122                       Name_Form,
8123                       Name_Code);
8124
8125             Internal : Node_Id renames Args (1);
8126             External : Node_Id renames Args (2);
8127             Form     : Node_Id renames Args (3);
8128             Code     : Node_Id renames Args (4);
8129
8130          begin
8131             GNAT_Pragma;
8132             Gather_Associations (Names, Args);
8133
8134             if Present (External) and then Present (Code) then
8135                Error_Pragma
8136                  ("cannot give both External and Code options for pragma%");
8137             end if;
8138
8139             Process_Extended_Import_Export_Exception_Pragma (
8140               Arg_Internal => Internal,
8141               Arg_External => External,
8142               Arg_Form     => Form,
8143               Arg_Code     => Code);
8144
8145             if not Is_VMS_Exception (Entity (Internal)) then
8146                Set_Imported (Entity (Internal));
8147             end if;
8148          end Import_Exception;
8149
8150          ---------------------
8151          -- Import_Function --
8152          ---------------------
8153
8154          --  pragma Import_Function (
8155          --        [Internal                 =>] LOCAL_NAME,
8156          --     [, [External                 =>] EXTERNAL_SYMBOL]
8157          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
8158          --     [, [Result_Type              =>] SUBTYPE_MARK]
8159          --     [, [Mechanism                =>] MECHANISM]
8160          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
8161          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
8162
8163          --  EXTERNAL_SYMBOL ::=
8164          --    IDENTIFIER
8165          --  | static_string_EXPRESSION
8166
8167          --  PARAMETER_TYPES ::=
8168          --    null
8169          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8170
8171          --  TYPE_DESIGNATOR ::=
8172          --    subtype_NAME
8173          --  | subtype_Name ' Access
8174
8175          --  MECHANISM ::=
8176          --    MECHANISM_NAME
8177          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8178
8179          --  MECHANISM_ASSOCIATION ::=
8180          --    [formal_parameter_NAME =>] MECHANISM_NAME
8181
8182          --  MECHANISM_NAME ::=
8183          --    Value
8184          --  | Reference
8185          --  | Descriptor [([Class =>] CLASS_NAME)]
8186
8187          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8188
8189          when Pragma_Import_Function => Import_Function : declare
8190             Args  : Args_List (1 .. 7);
8191             Names : constant Name_List (1 .. 7) := (
8192                       Name_Internal,
8193                       Name_External,
8194                       Name_Parameter_Types,
8195                       Name_Result_Type,
8196                       Name_Mechanism,
8197                       Name_Result_Mechanism,
8198                       Name_First_Optional_Parameter);
8199
8200             Internal                 : Node_Id renames Args (1);
8201             External                 : Node_Id renames Args (2);
8202             Parameter_Types          : Node_Id renames Args (3);
8203             Result_Type              : Node_Id renames Args (4);
8204             Mechanism                : Node_Id renames Args (5);
8205             Result_Mechanism         : Node_Id renames Args (6);
8206             First_Optional_Parameter : Node_Id renames Args (7);
8207
8208          begin
8209             GNAT_Pragma;
8210             Gather_Associations (Names, Args);
8211             Process_Extended_Import_Export_Subprogram_Pragma (
8212               Arg_Internal                 => Internal,
8213               Arg_External                 => External,
8214               Arg_Parameter_Types          => Parameter_Types,
8215               Arg_Result_Type              => Result_Type,
8216               Arg_Mechanism                => Mechanism,
8217               Arg_Result_Mechanism         => Result_Mechanism,
8218               Arg_First_Optional_Parameter => First_Optional_Parameter);
8219          end Import_Function;
8220
8221          -------------------
8222          -- Import_Object --
8223          -------------------
8224
8225          --  pragma Import_Object (
8226          --        [Internal =>] LOCAL_NAME
8227          --     [, [External =>] EXTERNAL_SYMBOL]
8228          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8229
8230          --  EXTERNAL_SYMBOL ::=
8231          --    IDENTIFIER
8232          --  | static_string_EXPRESSION
8233
8234          when Pragma_Import_Object => Import_Object : declare
8235             Args  : Args_List (1 .. 3);
8236             Names : constant Name_List (1 .. 3) := (
8237                       Name_Internal,
8238                       Name_External,
8239                       Name_Size);
8240
8241             Internal : Node_Id renames Args (1);
8242             External : Node_Id renames Args (2);
8243             Size     : Node_Id renames Args (3);
8244
8245          begin
8246             GNAT_Pragma;
8247             Gather_Associations (Names, Args);
8248             Process_Extended_Import_Export_Object_Pragma (
8249               Arg_Internal => Internal,
8250               Arg_External => External,
8251               Arg_Size     => Size);
8252          end Import_Object;
8253
8254          ----------------------
8255          -- Import_Procedure --
8256          ----------------------
8257
8258          --  pragma Import_Procedure (
8259          --        [Internal                 =>] LOCAL_NAME
8260          --     [, [External                 =>] EXTERNAL_SYMBOL]
8261          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
8262          --     [, [Mechanism                =>] MECHANISM]
8263          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
8264
8265          --  EXTERNAL_SYMBOL ::=
8266          --    IDENTIFIER
8267          --  | static_string_EXPRESSION
8268
8269          --  PARAMETER_TYPES ::=
8270          --    null
8271          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8272
8273          --  TYPE_DESIGNATOR ::=
8274          --    subtype_NAME
8275          --  | subtype_Name ' Access
8276
8277          --  MECHANISM ::=
8278          --    MECHANISM_NAME
8279          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8280
8281          --  MECHANISM_ASSOCIATION ::=
8282          --    [formal_parameter_NAME =>] MECHANISM_NAME
8283
8284          --  MECHANISM_NAME ::=
8285          --    Value
8286          --  | Reference
8287          --  | Descriptor [([Class =>] CLASS_NAME)]
8288
8289          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8290
8291          when Pragma_Import_Procedure => Import_Procedure : declare
8292             Args  : Args_List (1 .. 5);
8293             Names : constant Name_List (1 .. 5) := (
8294                       Name_Internal,
8295                       Name_External,
8296                       Name_Parameter_Types,
8297                       Name_Mechanism,
8298                       Name_First_Optional_Parameter);
8299
8300             Internal                 : Node_Id renames Args (1);
8301             External                 : Node_Id renames Args (2);
8302             Parameter_Types          : Node_Id renames Args (3);
8303             Mechanism                : Node_Id renames Args (4);
8304             First_Optional_Parameter : Node_Id renames Args (5);
8305
8306          begin
8307             GNAT_Pragma;
8308             Gather_Associations (Names, Args);
8309             Process_Extended_Import_Export_Subprogram_Pragma (
8310               Arg_Internal                 => Internal,
8311               Arg_External                 => External,
8312               Arg_Parameter_Types          => Parameter_Types,
8313               Arg_Mechanism                => Mechanism,
8314               Arg_First_Optional_Parameter => First_Optional_Parameter);
8315          end Import_Procedure;
8316
8317          -----------------------------
8318          -- Import_Valued_Procedure --
8319          -----------------------------
8320
8321          --  pragma Import_Valued_Procedure (
8322          --        [Internal                 =>] LOCAL_NAME
8323          --     [, [External                 =>] EXTERNAL_SYMBOL]
8324          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
8325          --     [, [Mechanism                =>] MECHANISM]
8326          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
8327
8328          --  EXTERNAL_SYMBOL ::=
8329          --    IDENTIFIER
8330          --  | static_string_EXPRESSION
8331
8332          --  PARAMETER_TYPES ::=
8333          --    null
8334          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8335
8336          --  TYPE_DESIGNATOR ::=
8337          --    subtype_NAME
8338          --  | subtype_Name ' Access
8339
8340          --  MECHANISM ::=
8341          --    MECHANISM_NAME
8342          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8343
8344          --  MECHANISM_ASSOCIATION ::=
8345          --    [formal_parameter_NAME =>] MECHANISM_NAME
8346
8347          --  MECHANISM_NAME ::=
8348          --    Value
8349          --  | Reference
8350          --  | Descriptor [([Class =>] CLASS_NAME)]
8351
8352          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8353
8354          when Pragma_Import_Valued_Procedure =>
8355          Import_Valued_Procedure : declare
8356             Args  : Args_List (1 .. 5);
8357             Names : constant Name_List (1 .. 5) := (
8358                       Name_Internal,
8359                       Name_External,
8360                       Name_Parameter_Types,
8361                       Name_Mechanism,
8362                       Name_First_Optional_Parameter);
8363
8364             Internal                 : Node_Id renames Args (1);
8365             External                 : Node_Id renames Args (2);
8366             Parameter_Types          : Node_Id renames Args (3);
8367             Mechanism                : Node_Id renames Args (4);
8368             First_Optional_Parameter : Node_Id renames Args (5);
8369
8370          begin
8371             GNAT_Pragma;
8372             Gather_Associations (Names, Args);
8373             Process_Extended_Import_Export_Subprogram_Pragma (
8374               Arg_Internal                 => Internal,
8375               Arg_External                 => External,
8376               Arg_Parameter_Types          => Parameter_Types,
8377               Arg_Mechanism                => Mechanism,
8378               Arg_First_Optional_Parameter => First_Optional_Parameter);
8379          end Import_Valued_Procedure;
8380
8381          -----------------
8382          -- Independent --
8383          -----------------
8384
8385          --  pragma Independent (LOCAL_NAME);
8386
8387          when Pragma_Independent => Independent : declare
8388             E_Id : Node_Id;
8389             E    : Entity_Id;
8390             D    : Node_Id;
8391             K    : Node_Kind;
8392
8393          begin
8394             Check_Ada_83_Warning;
8395             Ada_2012_Pragma;
8396             Check_No_Identifiers;
8397             Check_Arg_Count (1);
8398             Check_Arg_Is_Local_Name (Arg1);
8399             E_Id := Expression (Arg1);
8400
8401             if Etype (E_Id) = Any_Type then
8402                return;
8403             end if;
8404
8405             E := Entity (E_Id);
8406             D := Declaration_Node (E);
8407             K := Nkind (D);
8408
8409             if Is_Type (E) then
8410                if Rep_Item_Too_Early (E, N)
8411                     or else
8412                   Rep_Item_Too_Late (E, N)
8413                then
8414                   return;
8415                else
8416                   Check_First_Subtype (Arg1);
8417                end if;
8418
8419             elsif K = N_Object_Declaration
8420               or else (K = N_Component_Declaration
8421                        and then Original_Record_Component (E) = E)
8422             then
8423                if Rep_Item_Too_Late (E, N) then
8424                   return;
8425                end if;
8426
8427             else
8428                Error_Pragma_Arg
8429                  ("inappropriate entity for pragma%", Arg1);
8430             end if;
8431
8432             Independence_Checks.Append ((N, E));
8433          end Independent;
8434
8435          ----------------------------
8436          -- Independent_Components --
8437          ----------------------------
8438
8439          --  pragma Atomic_Components (array_LOCAL_NAME);
8440
8441          --  This processing is shared by Volatile_Components
8442
8443          when Pragma_Independent_Components => Independent_Components : declare
8444             E_Id : Node_Id;
8445             E    : Entity_Id;
8446             D    : Node_Id;
8447             K    : Node_Kind;
8448
8449          begin
8450             Check_Ada_83_Warning;
8451             Ada_2012_Pragma;
8452             Check_No_Identifiers;
8453             Check_Arg_Count (1);
8454             Check_Arg_Is_Local_Name (Arg1);
8455             E_Id := Expression (Arg1);
8456
8457             if Etype (E_Id) = Any_Type then
8458                return;
8459             end if;
8460
8461             E := Entity (E_Id);
8462
8463             if Rep_Item_Too_Early (E, N)
8464                  or else
8465                Rep_Item_Too_Late (E, N)
8466             then
8467                return;
8468             end if;
8469
8470             D := Declaration_Node (E);
8471             K := Nkind (D);
8472
8473             if (K = N_Full_Type_Declaration
8474                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
8475               or else
8476                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8477                    and then Nkind (D) = N_Object_Declaration
8478                    and then Nkind (Object_Definition (D)) =
8479                                        N_Constrained_Array_Definition)
8480             then
8481                Independence_Checks.Append ((N, E));
8482
8483             else
8484                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
8485             end if;
8486          end Independent_Components;
8487
8488          ------------------------
8489          -- Initialize_Scalars --
8490          ------------------------
8491
8492          --  pragma Initialize_Scalars;
8493
8494          when Pragma_Initialize_Scalars =>
8495             GNAT_Pragma;
8496             Check_Arg_Count (0);
8497             Check_Valid_Configuration_Pragma;
8498             Check_Restriction (No_Initialize_Scalars, N);
8499
8500             --  Initialize_Scalars creates false positives in CodePeer,
8501             --  so ignore this pragma in this mode.
8502
8503             if not Restriction_Active (No_Initialize_Scalars)
8504               and then not CodePeer_Mode
8505             then
8506                Init_Or_Norm_Scalars := True;
8507                Initialize_Scalars := True;
8508             end if;
8509
8510          ------------
8511          -- Inline --
8512          ------------
8513
8514          --  pragma Inline ( NAME {, NAME} );
8515
8516          when Pragma_Inline =>
8517
8518             --  Pragma is active if inlining option is active
8519
8520             Process_Inline (Inline_Active);
8521
8522          -------------------
8523          -- Inline_Always --
8524          -------------------
8525
8526          --  pragma Inline_Always ( NAME {, NAME} );
8527
8528          when Pragma_Inline_Always =>
8529             GNAT_Pragma;
8530
8531             --  Pragma always active unless in CodePeer mode, since this causes
8532             --  walk order issues.
8533
8534             if not CodePeer_Mode then
8535                Process_Inline (True);
8536             end if;
8537
8538          --------------------
8539          -- Inline_Generic --
8540          --------------------
8541
8542          --  pragma Inline_Generic (NAME {, NAME});
8543
8544          when Pragma_Inline_Generic =>
8545             GNAT_Pragma;
8546             Process_Generic_List;
8547
8548          ----------------------
8549          -- Inspection_Point --
8550          ----------------------
8551
8552          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
8553
8554          when Pragma_Inspection_Point => Inspection_Point : declare
8555             Arg : Node_Id;
8556             Exp : Node_Id;
8557
8558          begin
8559             if Arg_Count > 0 then
8560                Arg := Arg1;
8561                loop
8562                   Exp := Expression (Arg);
8563                   Analyze (Exp);
8564
8565                   if not Is_Entity_Name (Exp)
8566                     or else not Is_Object (Entity (Exp))
8567                   then
8568                      Error_Pragma_Arg ("object name required", Arg);
8569                   end if;
8570
8571                   Next (Arg);
8572                   exit when No (Arg);
8573                end loop;
8574             end if;
8575          end Inspection_Point;
8576
8577          ---------------
8578          -- Interface --
8579          ---------------
8580
8581          --  pragma Interface (
8582          --    [   Convention    =>] convention_IDENTIFIER,
8583          --    [   Entity        =>] local_NAME
8584          --    [, [External_Name =>] static_string_EXPRESSION ]
8585          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8586
8587          when Pragma_Interface =>
8588             GNAT_Pragma;
8589             Check_Arg_Order
8590               ((Name_Convention,
8591                 Name_Entity,
8592                 Name_External_Name,
8593                 Name_Link_Name));
8594             Check_At_Least_N_Arguments (2);
8595             Check_At_Most_N_Arguments  (4);
8596             Process_Import_Or_Interface;
8597
8598             --  In Ada 2005, the permission to use Interface (a reserved word)
8599             --  as a pragma name is considered an obsolescent feature.
8600
8601             if Ada_Version >= Ada_2005 then
8602                Check_Restriction
8603                  (No_Obsolescent_Features, Pragma_Identifier (N));
8604             end if;
8605
8606          --------------------
8607          -- Interface_Name --
8608          --------------------
8609
8610          --  pragma Interface_Name (
8611          --    [  Entity        =>] local_NAME
8612          --    [,[External_Name =>] static_string_EXPRESSION ]
8613          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
8614
8615          when Pragma_Interface_Name => Interface_Name : declare
8616             Id     : Node_Id;
8617             Def_Id : Entity_Id;
8618             Hom_Id : Entity_Id;
8619             Found  : Boolean;
8620
8621          begin
8622             GNAT_Pragma;
8623             Check_Arg_Order
8624               ((Name_Entity, Name_External_Name, Name_Link_Name));
8625             Check_At_Least_N_Arguments (2);
8626             Check_At_Most_N_Arguments  (3);
8627             Id := Expression (Arg1);
8628             Analyze (Id);
8629
8630             if not Is_Entity_Name (Id) then
8631                Error_Pragma_Arg
8632                  ("first argument for pragma% must be entity name", Arg1);
8633             elsif Etype (Id) = Any_Type then
8634                return;
8635             else
8636                Def_Id := Entity (Id);
8637             end if;
8638
8639             --  Special DEC-compatible processing for the object case, forces
8640             --  object to be imported.
8641
8642             if Ekind (Def_Id) = E_Variable then
8643                Kill_Size_Check_Code (Def_Id);
8644                Note_Possible_Modification (Id, Sure => False);
8645
8646                --  Initialization is not allowed for imported variable
8647
8648                if Present (Expression (Parent (Def_Id)))
8649                  and then Comes_From_Source (Expression (Parent (Def_Id)))
8650                then
8651                   Error_Msg_Sloc := Sloc (Def_Id);
8652                   Error_Pragma_Arg
8653                     ("no initialization allowed for declaration of& #",
8654                      Arg2);
8655
8656                else
8657                   --  For compatibility, support VADS usage of providing both
8658                   --  pragmas Interface and Interface_Name to obtain the effect
8659                   --  of a single Import pragma.
8660
8661                   if Is_Imported (Def_Id)
8662                     and then Present (First_Rep_Item (Def_Id))
8663                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8664                     and then
8665                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8666                   then
8667                      null;
8668                   else
8669                      Set_Imported (Def_Id);
8670                   end if;
8671
8672                   Set_Is_Public (Def_Id);
8673                   Process_Interface_Name (Def_Id, Arg2, Arg3);
8674                end if;
8675
8676             --  Otherwise must be subprogram
8677
8678             elsif not Is_Subprogram (Def_Id) then
8679                Error_Pragma_Arg
8680                  ("argument of pragma% is not subprogram", Arg1);
8681
8682             else
8683                Check_At_Most_N_Arguments (3);
8684                Hom_Id := Def_Id;
8685                Found := False;
8686
8687                --  Loop through homonyms
8688
8689                loop
8690                   Def_Id := Get_Base_Subprogram (Hom_Id);
8691
8692                   if Is_Imported (Def_Id) then
8693                      Process_Interface_Name (Def_Id, Arg2, Arg3);
8694                      Found := True;
8695                   end if;
8696
8697                   Hom_Id := Homonym (Hom_Id);
8698
8699                   exit when No (Hom_Id)
8700                     or else Scope (Hom_Id) /= Current_Scope;
8701                end loop;
8702
8703                if not Found then
8704                   Error_Pragma_Arg
8705                     ("argument of pragma% is not imported subprogram",
8706                      Arg1);
8707                end if;
8708             end if;
8709          end Interface_Name;
8710
8711          -----------------------
8712          -- Interrupt_Handler --
8713          -----------------------
8714
8715          --  pragma Interrupt_Handler (handler_NAME);
8716
8717          when Pragma_Interrupt_Handler =>
8718             Check_Ada_83_Warning;
8719             Check_Arg_Count (1);
8720             Check_No_Identifiers;
8721
8722             if No_Run_Time_Mode then
8723                Error_Msg_CRT ("Interrupt_Handler pragma", N);
8724             else
8725                Check_Interrupt_Or_Attach_Handler;
8726                Process_Interrupt_Or_Attach_Handler;
8727             end if;
8728
8729          ------------------------
8730          -- Interrupt_Priority --
8731          ------------------------
8732
8733          --  pragma Interrupt_Priority [(EXPRESSION)];
8734
8735          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8736             P   : constant Node_Id := Parent (N);
8737             Arg : Node_Id;
8738
8739          begin
8740             Check_Ada_83_Warning;
8741
8742             if Arg_Count /= 0 then
8743                Arg := Expression (Arg1);
8744                Check_Arg_Count (1);
8745                Check_No_Identifiers;
8746
8747                --  The expression must be analyzed in the special manner
8748                --  described in "Handling of Default and Per-Object
8749                --  Expressions" in sem.ads.
8750
8751                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8752             end if;
8753
8754             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8755                Pragma_Misplaced;
8756                return;
8757
8758             elsif Has_Priority_Pragma (P) then
8759                Error_Pragma ("duplicate pragma% not allowed");
8760
8761             else
8762                Set_Has_Priority_Pragma (P, True);
8763                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8764             end if;
8765          end Interrupt_Priority;
8766
8767          ---------------------
8768          -- Interrupt_State --
8769          ---------------------
8770
8771          --  pragma Interrupt_State (
8772          --    [Name  =>] INTERRUPT_ID,
8773          --    [State =>] INTERRUPT_STATE);
8774
8775          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8776          --  INTERRUPT_STATE => System | Runtime | User
8777
8778          --  Note: if the interrupt id is given as an identifier, then it must
8779          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8780          --  given as a static integer expression which must be in the range of
8781          --  Ada.Interrupts.Interrupt_ID.
8782
8783          when Pragma_Interrupt_State => Interrupt_State : declare
8784
8785             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8786             --  This is the entity Ada.Interrupts.Interrupt_ID;
8787
8788             State_Type : Character;
8789             --  Set to 's'/'r'/'u' for System/Runtime/User
8790
8791             IST_Num : Pos;
8792             --  Index to entry in Interrupt_States table
8793
8794             Int_Val : Uint;
8795             --  Value of interrupt
8796
8797             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8798             --  The first argument to the pragma
8799
8800             Int_Ent : Entity_Id;
8801             --  Interrupt entity in Ada.Interrupts.Names
8802
8803          begin
8804             GNAT_Pragma;
8805             Check_Arg_Order ((Name_Name, Name_State));
8806             Check_Arg_Count (2);
8807
8808             Check_Optional_Identifier (Arg1, Name_Name);
8809             Check_Optional_Identifier (Arg2, Name_State);
8810             Check_Arg_Is_Identifier (Arg2);
8811
8812             --  First argument is identifier
8813
8814             if Nkind (Arg1X) = N_Identifier then
8815
8816                --  Search list of names in Ada.Interrupts.Names
8817
8818                Int_Ent := First_Entity (RTE (RE_Names));
8819                loop
8820                   if No (Int_Ent) then
8821                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
8822
8823                   elsif Chars (Int_Ent) = Chars (Arg1X) then
8824                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
8825                      exit;
8826                   end if;
8827
8828                   Next_Entity (Int_Ent);
8829                end loop;
8830
8831             --  First argument is not an identifier, so it must be a static
8832             --  expression of type Ada.Interrupts.Interrupt_ID.
8833
8834             else
8835                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8836                Int_Val := Expr_Value (Arg1X);
8837
8838                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8839                     or else
8840                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8841                then
8842                   Error_Pragma_Arg
8843                     ("value not in range of type " &
8844                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8845                end if;
8846             end if;
8847
8848             --  Check OK state
8849
8850             case Chars (Get_Pragma_Arg (Arg2)) is
8851                when Name_Runtime => State_Type := 'r';
8852                when Name_System  => State_Type := 's';
8853                when Name_User    => State_Type := 'u';
8854
8855                when others =>
8856                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
8857             end case;
8858
8859             --  Check if entry is already stored
8860
8861             IST_Num := Interrupt_States.First;
8862             loop
8863                --  If entry not found, add it
8864
8865                if IST_Num > Interrupt_States.Last then
8866                   Interrupt_States.Append
8867                     ((Interrupt_Number => UI_To_Int (Int_Val),
8868                       Interrupt_State  => State_Type,
8869                       Pragma_Loc       => Loc));
8870                   exit;
8871
8872                --  Case of entry for the same entry
8873
8874                elsif Int_Val = Interrupt_States.Table (IST_Num).
8875                                                            Interrupt_Number
8876                then
8877                   --  If state matches, done, no need to make redundant entry
8878
8879                   exit when
8880                     State_Type = Interrupt_States.Table (IST_Num).
8881                                                            Interrupt_State;
8882
8883                   --  Otherwise if state does not match, error
8884
8885                   Error_Msg_Sloc :=
8886                     Interrupt_States.Table (IST_Num).Pragma_Loc;
8887                   Error_Pragma_Arg
8888                     ("state conflicts with that given #", Arg2);
8889                   exit;
8890                end if;
8891
8892                IST_Num := IST_Num + 1;
8893             end loop;
8894          end Interrupt_State;
8895
8896          ----------------------
8897          -- Java_Constructor --
8898          ----------------------
8899
8900          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8901
8902          --  Also handles pragma CIL_Constructor
8903
8904          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8905          Java_Constructor : declare
8906             Convention : Convention_Id;
8907             Def_Id     : Entity_Id;
8908             Hom_Id     : Entity_Id;
8909             Id         : Entity_Id;
8910
8911          begin
8912             GNAT_Pragma;
8913             Check_Arg_Count (1);
8914             Check_Optional_Identifier (Arg1, Name_Entity);
8915             Check_Arg_Is_Local_Name (Arg1);
8916
8917             Id := Expression (Arg1);
8918             Find_Program_Unit_Name (Id);
8919
8920             --  If we did not find the name, we are done
8921
8922             if Etype (Id) = Any_Type then
8923                return;
8924             end if;
8925
8926             --  Check wrong use of pragma in wrong VM target
8927
8928             if VM_Target = No_VM then
8929                return;
8930
8931             elsif VM_Target = CLI_Target
8932               and then Prag_Id = Pragma_Java_Constructor
8933             then
8934                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
8935
8936             elsif VM_Target = JVM_Target
8937               and then Prag_Id = Pragma_CIL_Constructor
8938             then
8939                Error_Pragma ("must use pragma 'Java_'Constructor");
8940             end if;
8941
8942             case Prag_Id is
8943                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
8944                when Pragma_Java_Constructor => Convention := Convention_Java;
8945                when others                  => null;
8946             end case;
8947
8948             Hom_Id := Entity (Id);
8949
8950             --  Loop through homonyms
8951
8952             loop
8953                Def_Id := Get_Base_Subprogram (Hom_Id);
8954
8955                --  The constructor is required to be a function
8956
8957                if Ekind (Def_Id) /= E_Function then
8958                   if VM_Target = JVM_Target then
8959                      Error_Pragma_Arg
8960                        ("pragma% requires function returning a " &
8961                         "'Java access type", Def_Id);
8962                   else
8963                      Error_Pragma_Arg
8964                        ("pragma% requires function returning a " &
8965                         "'C'I'L access type", Def_Id);
8966                   end if;
8967                end if;
8968
8969                --  Check arguments: For tagged type the first formal must be
8970                --  named "this" and its type must be a named access type
8971                --  designating a class-wide tagged type that has convention
8972                --  CIL/Java. The first formal must also have a null default
8973                --  value. For example:
8974
8975                --      type Typ is tagged ...
8976                --      type Ref is access all Typ;
8977                --      pragma Convention (CIL, Typ);
8978
8979                --      function New_Typ (This : Ref) return Ref;
8980                --      function New_Typ (This : Ref; I : Integer) return Ref;
8981                --      pragma Cil_Constructor (New_Typ);
8982
8983                --  Reason: The first formal must NOT be a primitive of the
8984                --  tagged type.
8985
8986                --  This rule also applies to constructors of delegates used
8987                --  to interface with standard target libraries. For example:
8988
8989                --      type Delegate is access procedure ...
8990                --      pragma Import (CIL, Delegate, ...);
8991
8992                --      function new_Delegate
8993                --        (This : Delegate := null; ... ) return Delegate;
8994
8995                --  For value-types this rule does not apply.
8996
8997                if not Is_Value_Type (Etype (Def_Id)) then
8998                   if No (First_Formal (Def_Id)) then
8999                      Error_Msg_Name_1 := Pname;
9000                      Error_Msg_N
9001                        ("first formal of % function must be named `this`",
9002                         Def_Id);
9003
9004                   elsif Get_Name_String (Chars (First_Formal (Def_Id)))
9005                           /= "this"
9006                   then
9007                      Error_Msg_Name_1 := Pname;
9008                      Error_Msg_N
9009                        ("first formal of % function must be named `this`",
9010                         Parent (First_Formal (Def_Id)));
9011
9012                   elsif not Is_Access_Type (Etype (First_Formal (Def_Id))) then
9013                      Error_Msg_Name_1 := Pname;
9014                      Error_Msg_N
9015                        ("first formal of % function must be an access type",
9016                         Parameter_Type (Parent (First_Formal (Def_Id))));
9017
9018                   --  For delegates the type of the first formal must be a
9019                   --  named access-to-subprogram type (see previous example)
9020
9021                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9022                     and then Ekind (Etype (First_Formal (Def_Id)))
9023                                /= E_Access_Subprogram_Type
9024                   then
9025                      Error_Msg_Name_1 := Pname;
9026                      Error_Msg_N
9027                        ("first formal of % function must be a named access" &
9028                         " to subprogram type",
9029                         Parameter_Type (Parent (First_Formal (Def_Id))));
9030
9031                   --  Warning: We should reject anonymous access types because
9032                   --  the constructor must not be handled as a primitive of the
9033                   --  tagged type. We temporarily allow it because this profile
9034                   --  is currently generated by cil2ada???
9035
9036                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9037                     and then not Ekind_In (Etype (First_Formal (Def_Id)),
9038                                    E_Access_Type,
9039                                    E_General_Access_Type,
9040                                    E_Anonymous_Access_Type)
9041                   then
9042                      Error_Msg_Name_1 := Pname;
9043                      Error_Msg_N
9044                        ("first formal of % function must be a named access" &
9045                         " type",
9046                         Parameter_Type (Parent (First_Formal (Def_Id))));
9047
9048                   elsif Atree.Convention
9049                          (Designated_Type (Etype (First_Formal (Def_Id))))
9050                            /= Convention
9051                   then
9052                      Error_Msg_Name_1 := Pname;
9053
9054                      if Convention = Convention_Java then
9055                         Error_Msg_N
9056                           ("pragma% requires convention 'Cil in designated" &
9057                            " type",
9058                            Parameter_Type (Parent (First_Formal (Def_Id))));
9059                      else
9060                         Error_Msg_N
9061                           ("pragma% requires convention 'Java in designated" &
9062                            " type",
9063                            Parameter_Type (Parent (First_Formal (Def_Id))));
9064                      end if;
9065
9066                   elsif No (Expression (Parent (First_Formal (Def_Id))))
9067                     or else
9068                       Nkind (Expression (Parent (First_Formal (Def_Id)))) /=
9069                         N_Null
9070                   then
9071                      Error_Msg_Name_1 := Pname;
9072                      Error_Msg_N
9073                        ("pragma% requires first formal with default `null`",
9074                         Parameter_Type (Parent (First_Formal (Def_Id))));
9075                   end if;
9076                end if;
9077
9078                --  Check result type: the constructor must be a function
9079                --  returning:
9080                --   * a value type (only allowed in the CIL compiler)
9081                --   * an access-to-subprogram type with convention Java/CIL
9082                --   * an access-type designating a type that has convention
9083                --     Java/CIL.
9084
9085                if Is_Value_Type (Etype (Def_Id)) then
9086                   null;
9087
9088                --  Access-to-subprogram type with convention Java/CIL
9089
9090                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9091                   if Atree.Convention (Etype (Def_Id)) /= Convention then
9092                      if Convention = Convention_Java then
9093                         Error_Pragma_Arg
9094                           ("pragma% requires function returning a " &
9095                            "'Java access type", Arg1);
9096                      else
9097                         pragma Assert (Convention = Convention_CIL);
9098                         Error_Pragma_Arg
9099                           ("pragma% requires function returning a " &
9100                            "'C'I'L access type", Arg1);
9101                      end if;
9102                   end if;
9103
9104                elsif Ekind (Etype (Def_Id)) in Access_Kind then
9105                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
9106                                                    E_General_Access_Type)
9107                     or else
9108                       Atree.Convention
9109                         (Designated_Type (Etype (Def_Id))) /= Convention
9110                   then
9111                      Error_Msg_Name_1 := Pname;
9112
9113                      if Convention = Convention_Java then
9114                         Error_Pragma_Arg
9115                           ("pragma% requires function returning a named" &
9116                            "'Java access type", Arg1);
9117                      else
9118                         Error_Pragma_Arg
9119                           ("pragma% requires function returning a named" &
9120                            "'C'I'L access type", Arg1);
9121                      end if;
9122                   end if;
9123                end if;
9124
9125                Set_Is_Constructor (Def_Id);
9126                Set_Convention     (Def_Id, Convention);
9127                Set_Is_Imported    (Def_Id);
9128
9129                Hom_Id := Homonym (Hom_Id);
9130
9131                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9132             end loop;
9133          end Java_Constructor;
9134
9135          ----------------------
9136          -- Java_Interface --
9137          ----------------------
9138
9139          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
9140
9141          when Pragma_Java_Interface => Java_Interface : declare
9142             Arg : Node_Id;
9143             Typ : Entity_Id;
9144
9145          begin
9146             GNAT_Pragma;
9147             Check_Arg_Count (1);
9148             Check_Optional_Identifier (Arg1, Name_Entity);
9149             Check_Arg_Is_Local_Name (Arg1);
9150
9151             Arg := Expression (Arg1);
9152             Analyze (Arg);
9153
9154             if Etype (Arg) = Any_Type then
9155                return;
9156             end if;
9157
9158             if not Is_Entity_Name (Arg)
9159               or else not Is_Type (Entity (Arg))
9160             then
9161                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9162             end if;
9163
9164             Typ := Underlying_Type (Entity (Arg));
9165
9166             --  For now simply check some of the semantic constraints on the
9167             --  type. This currently leaves out some restrictions on interface
9168             --  types, namely that the parent type must be java.lang.Object.Typ
9169             --  and that all primitives of the type should be declared
9170             --  abstract. ???
9171
9172             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9173                Error_Pragma_Arg ("pragma% requires an abstract "
9174                  & "tagged type", Arg1);
9175
9176             elsif not Has_Discriminants (Typ)
9177               or else Ekind (Etype (First_Discriminant (Typ)))
9178                         /= E_Anonymous_Access_Type
9179               or else
9180                 not Is_Class_Wide_Type
9181                       (Designated_Type (Etype (First_Discriminant (Typ))))
9182             then
9183                Error_Pragma_Arg
9184                  ("type must have a class-wide access discriminant", Arg1);
9185             end if;
9186          end Java_Interface;
9187
9188          ----------------
9189          -- Keep_Names --
9190          ----------------
9191
9192          --  pragma Keep_Names ([On => ] local_NAME);
9193
9194          when Pragma_Keep_Names => Keep_Names : declare
9195             Arg : Node_Id;
9196
9197          begin
9198             GNAT_Pragma;
9199             Check_Arg_Count (1);
9200             Check_Optional_Identifier (Arg1, Name_On);
9201             Check_Arg_Is_Local_Name (Arg1);
9202
9203             Arg := Expression (Arg1);
9204             Analyze (Arg);
9205
9206             if Etype (Arg) = Any_Type then
9207                return;
9208             end if;
9209
9210             if not Is_Entity_Name (Arg)
9211               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9212             then
9213                Error_Pragma_Arg
9214                  ("pragma% requires a local enumeration type", Arg1);
9215             end if;
9216
9217             Set_Discard_Names (Entity (Arg), False);
9218          end Keep_Names;
9219
9220          -------------
9221          -- License --
9222          -------------
9223
9224          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9225
9226          when Pragma_License =>
9227             GNAT_Pragma;
9228             Check_Arg_Count (1);
9229             Check_No_Identifiers;
9230             Check_Valid_Configuration_Pragma;
9231             Check_Arg_Is_Identifier (Arg1);
9232
9233             declare
9234                Sind : constant Source_File_Index :=
9235                         Source_Index (Current_Sem_Unit);
9236
9237             begin
9238                case Chars (Get_Pragma_Arg (Arg1)) is
9239                   when Name_GPL =>
9240                      Set_License (Sind, GPL);
9241
9242                   when Name_Modified_GPL =>
9243                      Set_License (Sind, Modified_GPL);
9244
9245                   when Name_Restricted =>
9246                      Set_License (Sind, Restricted);
9247
9248                   when Name_Unrestricted =>
9249                      Set_License (Sind, Unrestricted);
9250
9251                   when others =>
9252                      Error_Pragma_Arg ("invalid license name", Arg1);
9253                end case;
9254             end;
9255
9256          ---------------
9257          -- Link_With --
9258          ---------------
9259
9260          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9261
9262          when Pragma_Link_With => Link_With : declare
9263             Arg : Node_Id;
9264
9265          begin
9266             GNAT_Pragma;
9267
9268             if Operating_Mode = Generate_Code
9269               and then In_Extended_Main_Source_Unit (N)
9270             then
9271                Check_At_Least_N_Arguments (1);
9272                Check_No_Identifiers;
9273                Check_Is_In_Decl_Part_Or_Package_Spec;
9274                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9275                Start_String;
9276
9277                Arg := Arg1;
9278                while Present (Arg) loop
9279                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
9280
9281                   --  Store argument, converting sequences of spaces to a
9282                   --  single null character (this is one of the differences
9283                   --  in processing between Link_With and Linker_Options).
9284
9285                   Arg_Store : declare
9286                      C : constant Char_Code := Get_Char_Code (' ');
9287                      S : constant String_Id :=
9288                            Strval (Expr_Value_S (Expression (Arg)));
9289                      L : constant Nat := String_Length (S);
9290                      F : Nat := 1;
9291
9292                      procedure Skip_Spaces;
9293                      --  Advance F past any spaces
9294
9295                      -----------------
9296                      -- Skip_Spaces --
9297                      -----------------
9298
9299                      procedure Skip_Spaces is
9300                      begin
9301                         while F <= L and then Get_String_Char (S, F) = C loop
9302                            F := F + 1;
9303                         end loop;
9304                      end Skip_Spaces;
9305
9306                   --  Start of processing for Arg_Store
9307
9308                   begin
9309                      Skip_Spaces; -- skip leading spaces
9310
9311                      --  Loop through characters, changing any embedded
9312                      --  sequence of spaces to a single null character (this
9313                      --  is how Link_With/Linker_Options differ)
9314
9315                      while F <= L loop
9316                         if Get_String_Char (S, F) = C then
9317                            Skip_Spaces;
9318                            exit when F > L;
9319                            Store_String_Char (ASCII.NUL);
9320
9321                         else
9322                            Store_String_Char (Get_String_Char (S, F));
9323                            F := F + 1;
9324                         end if;
9325                      end loop;
9326                   end Arg_Store;
9327
9328                   Arg := Next (Arg);
9329
9330                   if Present (Arg) then
9331                      Store_String_Char (ASCII.NUL);
9332                   end if;
9333                end loop;
9334
9335                Store_Linker_Option_String (End_String);
9336             end if;
9337          end Link_With;
9338
9339          ------------------
9340          -- Linker_Alias --
9341          ------------------
9342
9343          --  pragma Linker_Alias (
9344          --      [Entity =>]  LOCAL_NAME
9345          --      [Target =>]  static_string_EXPRESSION);
9346
9347          when Pragma_Linker_Alias =>
9348             GNAT_Pragma;
9349             Check_Arg_Order ((Name_Entity, Name_Target));
9350             Check_Arg_Count (2);
9351             Check_Optional_Identifier (Arg1, Name_Entity);
9352             Check_Optional_Identifier (Arg2, Name_Target);
9353             Check_Arg_Is_Library_Level_Local_Name (Arg1);
9354             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9355
9356             --  The only processing required is to link this item on to the
9357             --  list of rep items for the given entity. This is accomplished
9358             --  by the call to Rep_Item_Too_Late (when no error is detected
9359             --  and False is returned).
9360
9361             if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
9362                return;
9363             else
9364                Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9365             end if;
9366
9367          ------------------------
9368          -- Linker_Constructor --
9369          ------------------------
9370
9371          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
9372
9373          --  Code is shared with Linker_Destructor
9374
9375          -----------------------
9376          -- Linker_Destructor --
9377          -----------------------
9378
9379          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
9380
9381          when Pragma_Linker_Constructor |
9382               Pragma_Linker_Destructor =>
9383          Linker_Constructor : declare
9384             Arg1_X : Node_Id;
9385             Proc   : Entity_Id;
9386
9387          begin
9388             GNAT_Pragma;
9389             Check_Arg_Count (1);
9390             Check_No_Identifiers;
9391             Check_Arg_Is_Local_Name (Arg1);
9392             Arg1_X := Expression (Arg1);
9393             Analyze (Arg1_X);
9394             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
9395
9396             if not Is_Library_Level_Entity (Proc) then
9397                Error_Pragma_Arg
9398                 ("argument for pragma% must be library level entity", Arg1);
9399             end if;
9400
9401             --  The only processing required is to link this item on to the
9402             --  list of rep items for the given entity. This is accomplished
9403             --  by the call to Rep_Item_Too_Late (when no error is detected
9404             --  and False is returned).
9405
9406             if Rep_Item_Too_Late (Proc, N) then
9407                return;
9408             else
9409                Set_Has_Gigi_Rep_Item (Proc);
9410             end if;
9411          end Linker_Constructor;
9412
9413          --------------------
9414          -- Linker_Options --
9415          --------------------
9416
9417          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
9418
9419          when Pragma_Linker_Options => Linker_Options : declare
9420             Arg : Node_Id;
9421
9422          begin
9423             Check_Ada_83_Warning;
9424             Check_No_Identifiers;
9425             Check_Arg_Count (1);
9426             Check_Is_In_Decl_Part_Or_Package_Spec;
9427             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9428             Start_String (Strval (Expr_Value_S (Expression (Arg1))));
9429
9430             Arg := Arg2;
9431             while Present (Arg) loop
9432                Check_Arg_Is_Static_Expression (Arg, Standard_String);
9433                Store_String_Char (ASCII.NUL);
9434                Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
9435                Arg := Next (Arg);
9436             end loop;
9437
9438             if Operating_Mode = Generate_Code
9439               and then In_Extended_Main_Source_Unit (N)
9440             then
9441                Store_Linker_Option_String (End_String);
9442             end if;
9443          end Linker_Options;
9444
9445          --------------------
9446          -- Linker_Section --
9447          --------------------
9448
9449          --  pragma Linker_Section (
9450          --      [Entity  =>]  LOCAL_NAME
9451          --      [Section =>]  static_string_EXPRESSION);
9452
9453          when Pragma_Linker_Section =>
9454             GNAT_Pragma;
9455             Check_Arg_Order ((Name_Entity, Name_Section));
9456             Check_Arg_Count (2);
9457             Check_Optional_Identifier (Arg1, Name_Entity);
9458             Check_Optional_Identifier (Arg2, Name_Section);
9459             Check_Arg_Is_Library_Level_Local_Name (Arg1);
9460             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9461
9462             --  This pragma applies only to objects
9463
9464             if not Is_Object (Entity (Expression (Arg1))) then
9465                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
9466             end if;
9467
9468             --  The only processing required is to link this item on to the
9469             --  list of rep items for the given entity. This is accomplished
9470             --  by the call to Rep_Item_Too_Late (when no error is detected
9471             --  and False is returned).
9472
9473             if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
9474                return;
9475             else
9476                Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9477             end if;
9478
9479          ----------
9480          -- List --
9481          ----------
9482
9483          --  pragma List (On | Off)
9484
9485          --  There is nothing to do here, since we did all the processing for
9486          --  this pragma in Par.Prag (so that it works properly even in syntax
9487          --  only mode).
9488
9489          when Pragma_List =>
9490             null;
9491
9492          --------------------
9493          -- Locking_Policy --
9494          --------------------
9495
9496          --  pragma Locking_Policy (policy_IDENTIFIER);
9497
9498          when Pragma_Locking_Policy => declare
9499             LP : Character;
9500
9501          begin
9502             Check_Ada_83_Warning;
9503             Check_Arg_Count (1);
9504             Check_No_Identifiers;
9505             Check_Arg_Is_Locking_Policy (Arg1);
9506             Check_Valid_Configuration_Pragma;
9507             Get_Name_String (Chars (Expression (Arg1)));
9508             LP := Fold_Upper (Name_Buffer (1));
9509
9510             if Locking_Policy /= ' '
9511               and then Locking_Policy /= LP
9512             then
9513                Error_Msg_Sloc := Locking_Policy_Sloc;
9514                Error_Pragma ("locking policy incompatible with policy#");
9515
9516             --  Set new policy, but always preserve System_Location since we
9517             --  like the error message with the run time name.
9518
9519             else
9520                Locking_Policy := LP;
9521
9522                if Locking_Policy_Sloc /= System_Location then
9523                   Locking_Policy_Sloc := Loc;
9524                end if;
9525             end if;
9526          end;
9527
9528          ----------------
9529          -- Long_Float --
9530          ----------------
9531
9532          --  pragma Long_Float (D_Float | G_Float);
9533
9534          when Pragma_Long_Float =>
9535             GNAT_Pragma;
9536             Check_Valid_Configuration_Pragma;
9537             Check_Arg_Count (1);
9538             Check_No_Identifier (Arg1);
9539             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
9540
9541             if not OpenVMS_On_Target then
9542                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
9543             end if;
9544
9545             --  D_Float case
9546
9547             if Chars (Expression (Arg1)) = Name_D_Float then
9548                if Opt.Float_Format_Long = 'G' then
9549                   Error_Pragma ("G_Float previously specified");
9550                end if;
9551
9552                Opt.Float_Format_Long := 'D';
9553
9554             --  G_Float case (this is the default, does not need overriding)
9555
9556             else
9557                if Opt.Float_Format_Long = 'D' then
9558                   Error_Pragma ("D_Float previously specified");
9559                end if;
9560
9561                Opt.Float_Format_Long := 'G';
9562             end if;
9563
9564             Set_Standard_Fpt_Formats;
9565
9566          -----------------------
9567          -- Machine_Attribute --
9568          -----------------------
9569
9570          --  pragma Machine_Attribute (
9571          --       [Entity         =>] LOCAL_NAME,
9572          --       [Attribute_Name =>] static_string_EXPRESSION
9573          --    [, [Info           =>] static_EXPRESSION] );
9574
9575          when Pragma_Machine_Attribute => Machine_Attribute : declare
9576             Def_Id : Entity_Id;
9577
9578          begin
9579             GNAT_Pragma;
9580             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
9581
9582             if Arg_Count = 3 then
9583                Check_Optional_Identifier (Arg3, Name_Info);
9584                Check_Arg_Is_Static_Expression (Arg3);
9585             else
9586                Check_Arg_Count (2);
9587             end if;
9588
9589             Check_Optional_Identifier (Arg1, Name_Entity);
9590             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
9591             Check_Arg_Is_Local_Name (Arg1);
9592             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9593             Def_Id := Entity (Expression (Arg1));
9594
9595             if Is_Access_Type (Def_Id) then
9596                Def_Id := Designated_Type (Def_Id);
9597             end if;
9598
9599             if Rep_Item_Too_Early (Def_Id, N) then
9600                return;
9601             end if;
9602
9603             Def_Id := Underlying_Type (Def_Id);
9604
9605             --  The only processing required is to link this item on to the
9606             --  list of rep items for the given entity. This is accomplished
9607             --  by the call to Rep_Item_Too_Late (when no error is detected
9608             --  and False is returned).
9609
9610             if Rep_Item_Too_Late (Def_Id, N) then
9611                return;
9612             else
9613                Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9614             end if;
9615          end Machine_Attribute;
9616
9617          ----------
9618          -- Main --
9619          ----------
9620
9621          --  pragma Main
9622          --   (MAIN_OPTION [, MAIN_OPTION]);
9623
9624          --  MAIN_OPTION ::=
9625          --    [STACK_SIZE              =>] static_integer_EXPRESSION
9626          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
9627          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
9628
9629          when Pragma_Main => Main : declare
9630             Args  : Args_List (1 .. 3);
9631             Names : constant Name_List (1 .. 3) := (
9632                       Name_Stack_Size,
9633                       Name_Task_Stack_Size_Default,
9634                       Name_Time_Slicing_Enabled);
9635
9636             Nod : Node_Id;
9637
9638          begin
9639             GNAT_Pragma;
9640             Gather_Associations (Names, Args);
9641
9642             for J in 1 .. 2 loop
9643                if Present (Args (J)) then
9644                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9645                end if;
9646             end loop;
9647
9648             if Present (Args (3)) then
9649                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
9650             end if;
9651
9652             Nod := Next (N);
9653             while Present (Nod) loop
9654                if Nkind (Nod) = N_Pragma
9655                  and then Pragma_Name (Nod) = Name_Main
9656                then
9657                   Error_Msg_Name_1 := Pname;
9658                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
9659                end if;
9660
9661                Next (Nod);
9662             end loop;
9663          end Main;
9664
9665          ------------------
9666          -- Main_Storage --
9667          ------------------
9668
9669          --  pragma Main_Storage
9670          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
9671
9672          --  MAIN_STORAGE_OPTION ::=
9673          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
9674          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
9675
9676          when Pragma_Main_Storage => Main_Storage : declare
9677             Args  : Args_List (1 .. 2);
9678             Names : constant Name_List (1 .. 2) := (
9679                       Name_Working_Storage,
9680                       Name_Top_Guard);
9681
9682             Nod : Node_Id;
9683
9684          begin
9685             GNAT_Pragma;
9686             Gather_Associations (Names, Args);
9687
9688             for J in 1 .. 2 loop
9689                if Present (Args (J)) then
9690                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9691                end if;
9692             end loop;
9693
9694             Check_In_Main_Program;
9695
9696             Nod := Next (N);
9697             while Present (Nod) loop
9698                if Nkind (Nod) = N_Pragma
9699                  and then Pragma_Name (Nod) = Name_Main_Storage
9700                then
9701                   Error_Msg_Name_1 := Pname;
9702                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
9703                end if;
9704
9705                Next (Nod);
9706             end loop;
9707          end Main_Storage;
9708
9709          -----------------
9710          -- Memory_Size --
9711          -----------------
9712
9713          --  pragma Memory_Size (NUMERIC_LITERAL)
9714
9715          when Pragma_Memory_Size =>
9716             GNAT_Pragma;
9717
9718             --  Memory size is simply ignored
9719
9720             Check_No_Identifiers;
9721             Check_Arg_Count (1);
9722             Check_Arg_Is_Integer_Literal (Arg1);
9723
9724          -------------
9725          -- No_Body --
9726          -------------
9727
9728          --  pragma No_Body;
9729
9730          --  The only correct use of this pragma is on its own in a file, in
9731          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
9732          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
9733          --  check for a file containing nothing but a No_Body pragma). If we
9734          --  attempt to process it during normal semantics processing, it means
9735          --  it was misplaced.
9736
9737          when Pragma_No_Body =>
9738             GNAT_Pragma;
9739             Pragma_Misplaced;
9740
9741          ---------------
9742          -- No_Return --
9743          ---------------
9744
9745          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
9746
9747          when Pragma_No_Return => No_Return : declare
9748             Id    : Node_Id;
9749             E     : Entity_Id;
9750             Found : Boolean;
9751             Arg   : Node_Id;
9752
9753          begin
9754             Ada_2005_Pragma;
9755             Check_At_Least_N_Arguments (1);
9756
9757             --  Loop through arguments of pragma
9758
9759             Arg := Arg1;
9760             while Present (Arg) loop
9761                Check_Arg_Is_Local_Name (Arg);
9762                Id := Expression (Arg);
9763                Analyze (Id);
9764
9765                if not Is_Entity_Name (Id) then
9766                   Error_Pragma_Arg ("entity name required", Arg);
9767                end if;
9768
9769                if Etype (Id) = Any_Type then
9770                   raise Pragma_Exit;
9771                end if;
9772
9773                --  Loop to find matching procedures
9774
9775                E := Entity (Id);
9776                Found := False;
9777                while Present (E)
9778                  and then Scope (E) = Current_Scope
9779                loop
9780                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
9781                      Set_No_Return (E);
9782
9783                      --  Set flag on any alias as well
9784
9785                      if Is_Overloadable (E) and then Present (Alias (E)) then
9786                         Set_No_Return (Alias (E));
9787                      end if;
9788
9789                      Found := True;
9790                   end if;
9791
9792                   E := Homonym (E);
9793                end loop;
9794
9795                if not Found then
9796                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
9797                end if;
9798
9799                Next (Arg);
9800             end loop;
9801          end No_Return;
9802
9803          -----------------
9804          -- No_Run_Time --
9805          -----------------
9806
9807          --  pragma No_Run_Time;
9808
9809          --  Note: this pragma is retained for backwards compatibility. See
9810          --  body of Rtsfind for full details on its handling.
9811
9812          when Pragma_No_Run_Time =>
9813             GNAT_Pragma;
9814             Check_Valid_Configuration_Pragma;
9815             Check_Arg_Count (0);
9816
9817             No_Run_Time_Mode           := True;
9818             Configurable_Run_Time_Mode := True;
9819
9820             --  Set Duration to 32 bits if word size is 32
9821
9822             if Ttypes.System_Word_Size = 32 then
9823                Duration_32_Bits_On_Target := True;
9824             end if;
9825
9826             --  Set appropriate restrictions
9827
9828             Set_Restriction (No_Finalization, N);
9829             Set_Restriction (No_Exception_Handlers, N);
9830             Set_Restriction (Max_Tasks, N, 0);
9831             Set_Restriction (No_Tasking, N);
9832
9833          ------------------------
9834          -- No_Strict_Aliasing --
9835          ------------------------
9836
9837          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9838
9839          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9840             E_Id : Entity_Id;
9841
9842          begin
9843             GNAT_Pragma;
9844             Check_At_Most_N_Arguments (1);
9845
9846             if Arg_Count = 0 then
9847                Check_Valid_Configuration_Pragma;
9848                Opt.No_Strict_Aliasing := True;
9849
9850             else
9851                Check_Optional_Identifier (Arg2, Name_Entity);
9852                Check_Arg_Is_Local_Name (Arg1);
9853                E_Id := Entity (Expression (Arg1));
9854
9855                if E_Id = Any_Type then
9856                   return;
9857                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9858                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
9859                end if;
9860
9861                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9862             end if;
9863          end No_Strict_Aliasing;
9864
9865          -----------------------
9866          -- Normalize_Scalars --
9867          -----------------------
9868
9869          --  pragma Normalize_Scalars;
9870
9871          when Pragma_Normalize_Scalars =>
9872             Check_Ada_83_Warning;
9873             Check_Arg_Count (0);
9874             Check_Valid_Configuration_Pragma;
9875
9876             --  Normalize_Scalars creates false positives in CodePeer, so
9877             --  ignore this pragma in this mode.
9878
9879             if not CodePeer_Mode then
9880                Normalize_Scalars := True;
9881                Init_Or_Norm_Scalars := True;
9882             end if;
9883
9884          -----------------
9885          -- Obsolescent --
9886          -----------------
9887
9888          --  pragma Obsolescent;
9889
9890          --  pragma Obsolescent (
9891          --    [Message =>] static_string_EXPRESSION
9892          --  [,[Version =>] Ada_05]]);
9893
9894          --  pragma Obsolescent (
9895          --    [Entity  =>] NAME
9896          --  [,[Message =>] static_string_EXPRESSION
9897          --  [,[Version =>] Ada_05]] );
9898
9899          when Pragma_Obsolescent => Obsolescent : declare
9900             Ename : Node_Id;
9901             Decl  : Node_Id;
9902
9903             procedure Set_Obsolescent (E : Entity_Id);
9904             --  Given an entity Ent, mark it as obsolescent if appropriate
9905
9906             ---------------------
9907             -- Set_Obsolescent --
9908             ---------------------
9909
9910             procedure Set_Obsolescent (E : Entity_Id) is
9911                Active : Boolean;
9912                Ent    : Entity_Id;
9913                S      : String_Id;
9914
9915             begin
9916                Active := True;
9917                Ent    := E;
9918
9919                --  Entity name was given
9920
9921                if Present (Ename) then
9922
9923                   --  If entity name matches, we are fine. Save entity in
9924                   --  pragma argument, for ASIS use.
9925
9926                   if Chars (Ename) = Chars (Ent) then
9927                      Set_Entity (Ename, Ent);
9928                      Generate_Reference (Ent, Ename);
9929
9930                   --  If entity name does not match, only possibility is an
9931                   --  enumeration literal from an enumeration type declaration.
9932
9933                   elsif Ekind (Ent) /= E_Enumeration_Type then
9934                      Error_Pragma
9935                        ("pragma % entity name does not match declaration");
9936
9937                   else
9938                      Ent := First_Literal (E);
9939                      loop
9940                         if No (Ent) then
9941                            Error_Pragma
9942                              ("pragma % entity name does not match any " &
9943                               "enumeration literal");
9944
9945                         elsif Chars (Ent) = Chars (Ename) then
9946                            Set_Entity (Ename, Ent);
9947                            Generate_Reference (Ent, Ename);
9948                            exit;
9949
9950                         else
9951                            Ent := Next_Literal (Ent);
9952                         end if;
9953                      end loop;
9954                   end if;
9955                end if;
9956
9957                --  Ent points to entity to be marked
9958
9959                if Arg_Count >= 1 then
9960
9961                   --  Deal with static string argument
9962
9963                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9964                   S := Strval (Expression (Arg1));
9965
9966                   for J in 1 .. String_Length (S) loop
9967                      if not In_Character_Range (Get_String_Char (S, J)) then
9968                         Error_Pragma_Arg
9969                           ("pragma% argument does not allow wide characters",
9970                            Arg1);
9971                      end if;
9972                   end loop;
9973
9974                   Obsolescent_Warnings.Append
9975                     ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9976
9977                   --  Check for Ada_05 parameter
9978
9979                   if Arg_Count /= 1 then
9980                      Check_Arg_Count (2);
9981
9982                      declare
9983                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9984
9985                      begin
9986                         Check_Arg_Is_Identifier (Argx);
9987
9988                         if Chars (Argx) /= Name_Ada_05 then
9989                            Error_Msg_Name_2 := Name_Ada_05;
9990                            Error_Pragma_Arg
9991                              ("only allowed argument for pragma% is %", Argx);
9992                         end if;
9993
9994                         if Ada_Version_Explicit < Ada_05
9995                           or else not Warn_On_Ada_2005_Compatibility
9996                         then
9997                            Active := False;
9998                         end if;
9999                      end;
10000                   end if;
10001                end if;
10002
10003                --  Set flag if pragma active
10004
10005                if Active then
10006                   Set_Is_Obsolescent (Ent);
10007                end if;
10008
10009                return;
10010             end Set_Obsolescent;
10011
10012          --  Start of processing for pragma Obsolescent
10013
10014          begin
10015             GNAT_Pragma;
10016
10017             Check_At_Most_N_Arguments (3);
10018
10019             --  See if first argument specifies an entity name
10020
10021             if Arg_Count >= 1
10022               and then
10023                 (Chars (Arg1) = Name_Entity
10024                    or else
10025                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10026                                                       N_Identifier,
10027                                                       N_Operator_Symbol))
10028             then
10029                Ename := Get_Pragma_Arg (Arg1);
10030
10031                --  Eliminate first argument, so we can share processing
10032
10033                Arg1 := Arg2;
10034                Arg2 := Arg3;
10035                Arg_Count := Arg_Count - 1;
10036
10037             --  No Entity name argument given
10038
10039             else
10040                Ename := Empty;
10041             end if;
10042
10043             if Arg_Count >= 1 then
10044                Check_Optional_Identifier (Arg1, Name_Message);
10045
10046                if Arg_Count = 2 then
10047                   Check_Optional_Identifier (Arg2, Name_Version);
10048                end if;
10049             end if;
10050
10051             --  Get immediately preceding declaration
10052
10053             Decl := Prev (N);
10054             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10055                Prev (Decl);
10056             end loop;
10057
10058             --  Cases where we do not follow anything other than another pragma
10059
10060             if No (Decl) then
10061
10062                --  First case: library level compilation unit declaration with
10063                --  the pragma immediately following the declaration.
10064
10065                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10066                   Set_Obsolescent
10067                     (Defining_Entity (Unit (Parent (Parent (N)))));
10068                   return;
10069
10070                --  Case 2: library unit placement for package
10071
10072                else
10073                   declare
10074                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
10075                   begin
10076                      if Is_Package_Or_Generic_Package (Ent) then
10077                         Set_Obsolescent (Ent);
10078                         return;
10079                      end if;
10080                   end;
10081                end if;
10082
10083             --  Cases where we must follow a declaration
10084
10085             else
10086                if         Nkind (Decl) not in N_Declaration
10087                  and then Nkind (Decl) not in N_Later_Decl_Item
10088                  and then Nkind (Decl) not in N_Generic_Declaration
10089                  and then Nkind (Decl) not in N_Renaming_Declaration
10090                then
10091                   Error_Pragma
10092                     ("pragma% misplaced, "
10093                      & "must immediately follow a declaration");
10094
10095                else
10096                   Set_Obsolescent (Defining_Entity (Decl));
10097                   return;
10098                end if;
10099             end if;
10100          end Obsolescent;
10101
10102          --------------
10103          -- Optimize --
10104          --------------
10105
10106          --  pragma Optimize (Time | Space | Off);
10107
10108          --  The actual check for optimize is done in Gigi. Note that this
10109          --  pragma does not actually change the optimization setting, it
10110          --  simply checks that it is consistent with the pragma.
10111
10112          when Pragma_Optimize =>
10113             Check_No_Identifiers;
10114             Check_Arg_Count (1);
10115             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10116
10117          ------------------------
10118          -- Optimize_Alignment --
10119          ------------------------
10120
10121          --  pragma Optimize_Alignment (Time | Space | Off);
10122
10123          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10124             GNAT_Pragma;
10125             Check_No_Identifiers;
10126             Check_Arg_Count (1);
10127             Check_Valid_Configuration_Pragma;
10128
10129             declare
10130                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10131             begin
10132                case Nam is
10133                   when Name_Time =>
10134                      Opt.Optimize_Alignment := 'T';
10135                   when Name_Space =>
10136                      Opt.Optimize_Alignment := 'S';
10137                   when Name_Off =>
10138                      Opt.Optimize_Alignment := 'O';
10139                   when others =>
10140                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10141                end case;
10142             end;
10143
10144             --  Set indication that mode is set locally. If we are in fact in a
10145             --  configuration pragma file, this setting is harmless since the
10146             --  switch will get reset anyway at the start of each unit.
10147
10148             Optimize_Alignment_Local := True;
10149          end Optimize_Alignment;
10150
10151          -------------
10152          -- Ordered --
10153          -------------
10154
10155          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10156
10157          when Pragma_Ordered => Ordered : declare
10158             Assoc   : constant Node_Id := Arg1;
10159             Type_Id : Node_Id;
10160             Typ     : Entity_Id;
10161
10162          begin
10163             GNAT_Pragma;
10164             Check_No_Identifiers;
10165             Check_Arg_Count (1);
10166             Check_Arg_Is_Local_Name (Arg1);
10167
10168             Type_Id := Expression (Assoc);
10169             Find_Type (Type_Id);
10170             Typ := Entity (Type_Id);
10171
10172             if Typ = Any_Type then
10173                return;
10174             else
10175                Typ := Underlying_Type (Typ);
10176             end if;
10177
10178             if not Is_Enumeration_Type (Typ) then
10179                Error_Pragma ("pragma% must specify enumeration type");
10180             end if;
10181
10182             Check_First_Subtype (Arg1);
10183             Set_Has_Pragma_Ordered (Base_Type (Typ));
10184          end Ordered;
10185
10186          ----------
10187          -- Pack --
10188          ----------
10189
10190          --  pragma Pack (first_subtype_LOCAL_NAME);
10191
10192          when Pragma_Pack => Pack : declare
10193             Assoc   : constant Node_Id := Arg1;
10194             Type_Id : Node_Id;
10195             Typ     : Entity_Id;
10196             Ctyp    : Entity_Id;
10197             Ignore  : Boolean := False;
10198
10199          begin
10200             Check_No_Identifiers;
10201             Check_Arg_Count (1);
10202             Check_Arg_Is_Local_Name (Arg1);
10203
10204             Type_Id := Expression (Assoc);
10205             Find_Type (Type_Id);
10206             Typ := Entity (Type_Id);
10207
10208             if Typ = Any_Type
10209               or else Rep_Item_Too_Early (Typ, N)
10210             then
10211                return;
10212             else
10213                Typ := Underlying_Type (Typ);
10214             end if;
10215
10216             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10217                Error_Pragma ("pragma% must specify array or record type");
10218             end if;
10219
10220             Check_First_Subtype (Arg1);
10221
10222             if Has_Pragma_Pack (Typ) then
10223                Error_Pragma ("duplicate pragma%, only one allowed");
10224
10225             --  Array type
10226
10227             elsif Is_Array_Type (Typ) then
10228                Ctyp := Component_Type (Typ);
10229
10230                --  Ignore pack that does nothing
10231
10232                if Known_Static_Esize (Ctyp)
10233                  and then Known_Static_RM_Size (Ctyp)
10234                  and then Esize (Ctyp) = RM_Size (Ctyp)
10235                  and then Addressable (Esize (Ctyp))
10236                then
10237                   Ignore := True;
10238                end if;
10239
10240                --  Process OK pragma Pack. Note that if there is a separate
10241                --  component clause present, the Pack will be cancelled. This
10242                --  processing is in Freeze.
10243
10244                if not Rep_Item_Too_Late (Typ, N) then
10245
10246                   --  In the context of static code analysis, we do not need
10247                   --  complex front-end expansions related to pragma Pack,
10248                   --  so disable handling of pragma Pack in this case.
10249
10250                   if CodePeer_Mode then
10251                      null;
10252
10253                   --  For normal non-VM target, do the packing
10254
10255                   elsif VM_Target = No_VM then
10256                      if not Ignore then
10257                         Set_Is_Packed            (Base_Type (Typ));
10258                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
10259                      end if;
10260
10261                      Set_Has_Pragma_Pack (Base_Type (Typ));
10262
10263                   --  If we ignore the pack for VM_Targets, then warn about
10264                   --  this, except suppress the warning in GNAT mode.
10265
10266                   elsif not GNAT_Mode then
10267                      Error_Pragma
10268                        ("?pragma% ignored in this configuration");
10269                   end if;
10270                end if;
10271
10272             --  For record types, the pack is always effective
10273
10274             else pragma Assert (Is_Record_Type (Typ));
10275                if not Rep_Item_Too_Late (Typ, N) then
10276                   if VM_Target = No_VM then
10277                      Set_Is_Packed            (Base_Type (Typ));
10278                      Set_Has_Pragma_Pack      (Base_Type (Typ));
10279                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
10280
10281                   elsif not GNAT_Mode then
10282                      Error_Pragma ("?pragma% ignored in this configuration");
10283                   end if;
10284                end if;
10285             end if;
10286          end Pack;
10287
10288          ----------
10289          -- Page --
10290          ----------
10291
10292          --  pragma Page;
10293
10294          --  There is nothing to do here, since we did all the processing for
10295          --  this pragma in Par.Prag (so that it works properly even in syntax
10296          --  only mode).
10297
10298          when Pragma_Page =>
10299             null;
10300
10301          -------------
10302          -- Passive --
10303          -------------
10304
10305          --  pragma Passive [(PASSIVE_FORM)];
10306
10307          --   PASSIVE_FORM ::= Semaphore | No
10308
10309          when Pragma_Passive =>
10310             GNAT_Pragma;
10311
10312             if Nkind (Parent (N)) /= N_Task_Definition then
10313                Error_Pragma ("pragma% must be within task definition");
10314             end if;
10315
10316             if Arg_Count /= 0 then
10317                Check_Arg_Count (1);
10318                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
10319             end if;
10320
10321          ----------------------------------
10322          -- Preelaborable_Initialization --
10323          ----------------------------------
10324
10325          --  pragma Preelaborable_Initialization (DIRECT_NAME);
10326
10327          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
10328             Ent : Entity_Id;
10329
10330          begin
10331             Ada_2005_Pragma;
10332             Check_Arg_Count (1);
10333             Check_No_Identifiers;
10334             Check_Arg_Is_Identifier (Arg1);
10335             Check_Arg_Is_Local_Name (Arg1);
10336             Check_First_Subtype (Arg1);
10337             Ent := Entity (Expression (Arg1));
10338
10339             if not Is_Private_Type (Ent)
10340               and then not Is_Protected_Type (Ent)
10341             then
10342                Error_Pragma_Arg
10343                  ("pragma % can only be applied to private or protected type",
10344                   Arg1);
10345             end if;
10346
10347             --  Give an error if the pragma is applied to a protected type that
10348             --  does not qualify (due to having entries, or due to components
10349             --  that do not qualify).
10350
10351             if Is_Protected_Type (Ent)
10352               and then not Has_Preelaborable_Initialization (Ent)
10353             then
10354                Error_Msg_N
10355                  ("protected type & does not have preelaborable " &
10356                   "initialization", Ent);
10357
10358             --  Otherwise mark the type as definitely having preelaborable
10359             --  initialization.
10360
10361             else
10362                Set_Known_To_Have_Preelab_Init (Ent);
10363             end if;
10364
10365             if Has_Pragma_Preelab_Init (Ent)
10366               and then Warn_On_Redundant_Constructs
10367             then
10368                Error_Pragma ("?duplicate pragma%!");
10369             else
10370                Set_Has_Pragma_Preelab_Init (Ent);
10371             end if;
10372          end Preelab_Init;
10373
10374          --------------------
10375          -- Persistent_BSS --
10376          --------------------
10377
10378          when Pragma_Persistent_BSS => Persistent_BSS :  declare
10379             Decl : Node_Id;
10380             Ent  : Entity_Id;
10381             Prag : Node_Id;
10382
10383          begin
10384             GNAT_Pragma;
10385             Check_At_Most_N_Arguments (1);
10386
10387             --  Case of application to specific object (one argument)
10388
10389             if Arg_Count = 1 then
10390                Check_Arg_Is_Library_Level_Local_Name (Arg1);
10391
10392                if not Is_Entity_Name (Expression (Arg1))
10393                  or else
10394                   (Ekind (Entity (Expression (Arg1))) /= E_Variable
10395                     and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
10396                then
10397                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
10398                end if;
10399
10400                Ent := Entity (Expression (Arg1));
10401                Decl := Parent (Ent);
10402
10403                if Rep_Item_Too_Late (Ent, N) then
10404                   return;
10405                end if;
10406
10407                if Present (Expression (Decl)) then
10408                   Error_Pragma_Arg
10409                     ("object for pragma% cannot have initialization", Arg1);
10410                end if;
10411
10412                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
10413                   Error_Pragma_Arg
10414                     ("object type for pragma% is not potentially persistent",
10415                      Arg1);
10416                end if;
10417
10418                Prag :=
10419                  Make_Linker_Section_Pragma
10420                    (Ent, Sloc (N), ".persistent.bss");
10421                Insert_After (N, Prag);
10422                Analyze (Prag);
10423
10424             --  Case of use as configuration pragma with no arguments
10425
10426             else
10427                Check_Valid_Configuration_Pragma;
10428                Persistent_BSS_Mode := True;
10429             end if;
10430          end Persistent_BSS;
10431
10432          -------------
10433          -- Polling --
10434          -------------
10435
10436          --  pragma Polling (ON | OFF);
10437
10438          when Pragma_Polling =>
10439             GNAT_Pragma;
10440             Check_Arg_Count (1);
10441             Check_No_Identifiers;
10442             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10443             Polling_Required := (Chars (Expression (Arg1)) = Name_On);
10444
10445          -------------------
10446          -- Postcondition --
10447          -------------------
10448
10449          --  pragma Postcondition ([Check   =>] Boolean_Expression
10450          --                      [,[Message =>] String_Expression]);
10451
10452          when Pragma_Postcondition => Postcondition : declare
10453             In_Body : Boolean;
10454             pragma Warnings (Off, In_Body);
10455
10456          begin
10457             GNAT_Pragma;
10458             Check_At_Least_N_Arguments (1);
10459             Check_At_Most_N_Arguments (2);
10460             Check_Optional_Identifier (Arg1, Name_Check);
10461
10462             --  All we need to do here is call the common check procedure,
10463             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
10464
10465             Check_Precondition_Postcondition (In_Body);
10466          end Postcondition;
10467
10468          ------------------
10469          -- Precondition --
10470          ------------------
10471
10472          --  pragma Precondition ([Check   =>] Boolean_Expression
10473          --                     [,[Message =>] String_Expression]);
10474
10475          when Pragma_Precondition => Precondition : declare
10476             In_Body : Boolean;
10477
10478          begin
10479             GNAT_Pragma;
10480             Check_At_Least_N_Arguments (1);
10481             Check_At_Most_N_Arguments (2);
10482             Check_Optional_Identifier (Arg1, Name_Check);
10483
10484             Check_Precondition_Postcondition (In_Body);
10485
10486             --  If in spec, nothing more to do. If in body, then we convert the
10487             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
10488             --  this whether or not precondition checks are enabled. That works
10489             --  fine since pragma Check will do this check, and will also
10490             --  analyze the condition itself in the proper context.
10491
10492             if In_Body then
10493                if Arg_Count = 2 then
10494                   Check_Optional_Identifier (Arg3, Name_Message);
10495                   Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
10496                end if;
10497
10498                Rewrite (N,
10499                  Make_Pragma (Loc,
10500                    Chars => Name_Check,
10501                    Pragma_Argument_Associations => New_List (
10502                      Make_Pragma_Argument_Association (Loc,
10503                        Expression =>
10504                          Make_Identifier (Loc,
10505                            Chars => Name_Precondition)),
10506
10507                      Make_Pragma_Argument_Association (Sloc (Arg1),
10508                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
10509
10510                if Arg_Count = 2 then
10511                   Append_To (Pragma_Argument_Associations (N),
10512                     Make_Pragma_Argument_Association (Sloc (Arg2),
10513                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
10514                end if;
10515
10516                Analyze (N);
10517             end if;
10518          end Precondition;
10519
10520          ------------------
10521          -- Preelaborate --
10522          ------------------
10523
10524          --  pragma Preelaborate [(library_unit_NAME)];
10525
10526          --  Set the flag Is_Preelaborated of program unit name entity
10527
10528          when Pragma_Preelaborate => Preelaborate : declare
10529             Pa  : constant Node_Id   := Parent (N);
10530             Pk  : constant Node_Kind := Nkind (Pa);
10531             Ent : Entity_Id;
10532
10533          begin
10534             Check_Ada_83_Warning;
10535             Check_Valid_Library_Unit_Pragma;
10536
10537             if Nkind (N) = N_Null_Statement then
10538                return;
10539             end if;
10540
10541             Ent := Find_Lib_Unit_Name;
10542
10543             --  This filters out pragmas inside generic parent then
10544             --  show up inside instantiation
10545
10546             if Present (Ent)
10547               and then not (Pk = N_Package_Specification
10548                               and then Present (Generic_Parent (Pa)))
10549             then
10550                if not Debug_Flag_U then
10551                   Set_Is_Preelaborated (Ent);
10552                   Set_Suppress_Elaboration_Warnings (Ent);
10553                end if;
10554             end if;
10555          end Preelaborate;
10556
10557          ---------------------
10558          -- Preelaborate_05 --
10559          ---------------------
10560
10561          --  pragma Preelaborate_05 [(library_unit_NAME)];
10562
10563          --  This pragma is useable only in GNAT_Mode, where it is used like
10564          --  pragma Preelaborate but it is only effective in Ada 2005 mode
10565          --  (otherwise it is ignored). This is used to implement AI-362 which
10566          --  recategorizes some run-time packages in Ada 2005 mode.
10567
10568          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
10569             Ent : Entity_Id;
10570
10571          begin
10572             GNAT_Pragma;
10573             Check_Valid_Library_Unit_Pragma;
10574
10575             if not GNAT_Mode then
10576                Error_Pragma ("pragma% only available in GNAT mode");
10577             end if;
10578
10579             if Nkind (N) = N_Null_Statement then
10580                return;
10581             end if;
10582
10583             --  This is one of the few cases where we need to test the value of
10584             --  Ada_Version_Explicit rather than Ada_Version (which is always
10585             --  set to Ada_12 in a predefined unit), we need to know the
10586             --  explicit version set to know if this pragma is active.
10587
10588             if Ada_Version_Explicit >= Ada_05 then
10589                Ent := Find_Lib_Unit_Name;
10590                Set_Is_Preelaborated (Ent);
10591                Set_Suppress_Elaboration_Warnings (Ent);
10592             end if;
10593          end Preelaborate_05;
10594
10595          --------------
10596          -- Priority --
10597          --------------
10598
10599          --  pragma Priority (EXPRESSION);
10600
10601          when Pragma_Priority => Priority : declare
10602             P   : constant Node_Id := Parent (N);
10603             Arg : Node_Id;
10604
10605          begin
10606             Check_No_Identifiers;
10607             Check_Arg_Count (1);
10608
10609             --  Subprogram case
10610
10611             if Nkind (P) = N_Subprogram_Body then
10612                Check_In_Main_Program;
10613
10614                Arg := Expression (Arg1);
10615                Analyze_And_Resolve (Arg, Standard_Integer);
10616
10617                --  Must be static
10618
10619                if not Is_Static_Expression (Arg) then
10620                   Flag_Non_Static_Expr
10621                     ("main subprogram priority is not static!", Arg);
10622                   raise Pragma_Exit;
10623
10624                --  If constraint error, then we already signalled an error
10625
10626                elsif Raises_Constraint_Error (Arg) then
10627                   null;
10628
10629                --  Otherwise check in range
10630
10631                else
10632                   declare
10633                      Val : constant Uint := Expr_Value (Arg);
10634
10635                   begin
10636                      if Val < 0
10637                        or else Val > Expr_Value (Expression
10638                                        (Parent (RTE (RE_Max_Priority))))
10639                      then
10640                         Error_Pragma_Arg
10641                           ("main subprogram priority is out of range", Arg1);
10642                      end if;
10643                   end;
10644                end if;
10645
10646                Set_Main_Priority
10647                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
10648
10649                --  Load an arbitrary entity from System.Tasking to make sure
10650                --  this package is implicitly with'ed, since we need to have
10651                --  the tasking run-time active for the pragma Priority to have
10652                --  any effect.
10653
10654                declare
10655                   Discard : Entity_Id;
10656                   pragma Warnings (Off, Discard);
10657                begin
10658                   Discard := RTE (RE_Task_List);
10659                end;
10660
10661             --  Task or Protected, must be of type Integer
10662
10663             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10664                Arg := Expression (Arg1);
10665
10666                --  The expression must be analyzed in the special manner
10667                --  described in "Handling of Default and Per-Object
10668                --  Expressions" in sem.ads.
10669
10670                Preanalyze_Spec_Expression (Arg, Standard_Integer);
10671
10672                if not Is_Static_Expression (Arg) then
10673                   Check_Restriction (Static_Priorities, Arg);
10674                end if;
10675
10676             --  Anything else is incorrect
10677
10678             else
10679                Pragma_Misplaced;
10680             end if;
10681
10682             if Has_Priority_Pragma (P) then
10683                Error_Pragma ("duplicate pragma% not allowed");
10684             else
10685                Set_Has_Priority_Pragma (P, True);
10686
10687                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10688                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10689                   --  exp_ch9 should use this ???
10690                end if;
10691             end if;
10692          end Priority;
10693
10694          -----------------------------------
10695          -- Priority_Specific_Dispatching --
10696          -----------------------------------
10697
10698          --  pragma Priority_Specific_Dispatching (
10699          --    policy_IDENTIFIER,
10700          --    first_priority_EXPRESSION,
10701          --    last_priority_EXPRESSION);
10702
10703          when Pragma_Priority_Specific_Dispatching =>
10704          Priority_Specific_Dispatching : declare
10705             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
10706             --  This is the entity System.Any_Priority;
10707
10708             DP          : Character;
10709             Lower_Bound : Node_Id;
10710             Upper_Bound : Node_Id;
10711             Lower_Val   : Uint;
10712             Upper_Val   : Uint;
10713
10714          begin
10715             Ada_2005_Pragma;
10716             Check_Arg_Count (3);
10717             Check_No_Identifiers;
10718             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
10719             Check_Valid_Configuration_Pragma;
10720             Get_Name_String (Chars (Expression (Arg1)));
10721             DP := Fold_Upper (Name_Buffer (1));
10722
10723             Lower_Bound := Expression (Arg2);
10724             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
10725             Lower_Val := Expr_Value (Lower_Bound);
10726
10727             Upper_Bound := Expression (Arg3);
10728             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
10729             Upper_Val := Expr_Value (Upper_Bound);
10730
10731             --  It is not allowed to use Task_Dispatching_Policy and
10732             --  Priority_Specific_Dispatching in the same partition.
10733
10734             if Task_Dispatching_Policy /= ' ' then
10735                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10736                Error_Pragma
10737                  ("pragma% incompatible with Task_Dispatching_Policy#");
10738
10739             --  Check lower bound in range
10740
10741             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10742                     or else
10743                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
10744             then
10745                Error_Pragma_Arg
10746                  ("first_priority is out of range", Arg2);
10747
10748             --  Check upper bound in range
10749
10750             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10751                     or else
10752                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
10753             then
10754                Error_Pragma_Arg
10755                  ("last_priority is out of range", Arg3);
10756
10757             --  Check that the priority range is valid
10758
10759             elsif Lower_Val > Upper_Val then
10760                Error_Pragma
10761                  ("last_priority_expression must be greater than" &
10762                   " or equal to first_priority_expression");
10763
10764             --  Store the new policy, but always preserve System_Location since
10765             --  we like the error message with the run-time name.
10766
10767             else
10768                --  Check overlapping in the priority ranges specified in other
10769                --  Priority_Specific_Dispatching pragmas within the same
10770                --  partition. We can only check those we know about!
10771
10772                for J in
10773                   Specific_Dispatching.First .. Specific_Dispatching.Last
10774                loop
10775                   if Specific_Dispatching.Table (J).First_Priority in
10776                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10777                   or else Specific_Dispatching.Table (J).Last_Priority in
10778                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10779                   then
10780                      Error_Msg_Sloc :=
10781                        Specific_Dispatching.Table (J).Pragma_Loc;
10782                         Error_Pragma
10783                           ("priority range overlaps with "
10784                            & "Priority_Specific_Dispatching#");
10785                   end if;
10786                end loop;
10787
10788                --  The use of Priority_Specific_Dispatching is incompatible
10789                --  with Task_Dispatching_Policy.
10790
10791                if Task_Dispatching_Policy /= ' ' then
10792                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10793                      Error_Pragma
10794                        ("Priority_Specific_Dispatching incompatible "
10795                         & "with Task_Dispatching_Policy#");
10796                end if;
10797
10798                --  The use of Priority_Specific_Dispatching forces ceiling
10799                --  locking policy.
10800
10801                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
10802                   Error_Msg_Sloc := Locking_Policy_Sloc;
10803                      Error_Pragma
10804                        ("Priority_Specific_Dispatching incompatible "
10805                         & "with Locking_Policy#");
10806
10807                --  Set the Ceiling_Locking policy, but preserve System_Location
10808                --  since we like the error message with the run time name.
10809
10810                else
10811                   Locking_Policy := 'C';
10812
10813                   if Locking_Policy_Sloc /= System_Location then
10814                      Locking_Policy_Sloc := Loc;
10815                   end if;
10816                end if;
10817
10818                --  Add entry in the table
10819
10820                Specific_Dispatching.Append
10821                     ((Dispatching_Policy => DP,
10822                       First_Priority     => UI_To_Int (Lower_Val),
10823                       Last_Priority      => UI_To_Int (Upper_Val),
10824                       Pragma_Loc         => Loc));
10825             end if;
10826          end Priority_Specific_Dispatching;
10827
10828          -------------
10829          -- Profile --
10830          -------------
10831
10832          --  pragma Profile (profile_IDENTIFIER);
10833
10834          --  profile_IDENTIFIER => Restricted | Ravenscar
10835
10836          when Pragma_Profile =>
10837             Ada_2005_Pragma;
10838             Check_Arg_Count (1);
10839             Check_Valid_Configuration_Pragma;
10840             Check_No_Identifiers;
10841
10842             declare
10843                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10844             begin
10845                if Chars (Argx) = Name_Ravenscar then
10846                   Set_Ravenscar_Profile (N);
10847                elsif Chars (Argx) = Name_Restricted then
10848                   Set_Profile_Restrictions
10849                     (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10850                else
10851                   Error_Pragma_Arg ("& is not a valid profile", Argx);
10852                end if;
10853             end;
10854
10855          ----------------------
10856          -- Profile_Warnings --
10857          ----------------------
10858
10859          --  pragma Profile_Warnings (profile_IDENTIFIER);
10860
10861          --  profile_IDENTIFIER => Restricted | Ravenscar
10862
10863          when Pragma_Profile_Warnings =>
10864             GNAT_Pragma;
10865             Check_Arg_Count (1);
10866             Check_Valid_Configuration_Pragma;
10867             Check_No_Identifiers;
10868
10869             declare
10870                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10871             begin
10872                if Chars (Argx) = Name_Ravenscar then
10873                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
10874                elsif Chars (Argx) = Name_Restricted then
10875                   Set_Profile_Restrictions (Restricted, N, Warn => True);
10876                else
10877                   Error_Pragma_Arg ("& is not a valid profile", Argx);
10878                end if;
10879             end;
10880
10881          --------------------------
10882          -- Propagate_Exceptions --
10883          --------------------------
10884
10885          --  pragma Propagate_Exceptions;
10886
10887          --  Note: this pragma is obsolete and has no effect
10888
10889          when Pragma_Propagate_Exceptions =>
10890             GNAT_Pragma;
10891             Check_Arg_Count (0);
10892
10893             if In_Extended_Main_Source_Unit (N) then
10894                Propagate_Exceptions := True;
10895             end if;
10896
10897          ------------------
10898          -- Psect_Object --
10899          ------------------
10900
10901          --  pragma Psect_Object (
10902          --        [Internal =>] LOCAL_NAME,
10903          --     [, [External =>] EXTERNAL_SYMBOL]
10904          --     [, [Size     =>] EXTERNAL_SYMBOL]);
10905
10906          when Pragma_Psect_Object | Pragma_Common_Object =>
10907          Psect_Object : declare
10908             Args  : Args_List (1 .. 3);
10909             Names : constant Name_List (1 .. 3) := (
10910                       Name_Internal,
10911                       Name_External,
10912                       Name_Size);
10913
10914             Internal : Node_Id renames Args (1);
10915             External : Node_Id renames Args (2);
10916             Size     : Node_Id renames Args (3);
10917
10918             Def_Id : Entity_Id;
10919
10920             procedure Check_Too_Long (Arg : Node_Id);
10921             --  Posts message if the argument is an identifier with more
10922             --  than 31 characters, or a string literal with more than
10923             --  31 characters, and we are operating under VMS
10924
10925             --------------------
10926             -- Check_Too_Long --
10927             --------------------
10928
10929             procedure Check_Too_Long (Arg : Node_Id) is
10930                X : constant Node_Id := Original_Node (Arg);
10931
10932             begin
10933                if not Nkind_In (X, N_String_Literal, N_Identifier) then
10934                   Error_Pragma_Arg
10935                     ("inappropriate argument for pragma %", Arg);
10936                end if;
10937
10938                if OpenVMS_On_Target then
10939                   if (Nkind (X) = N_String_Literal
10940                        and then String_Length (Strval (X)) > 31)
10941                     or else
10942                      (Nkind (X) = N_Identifier
10943                        and then Length_Of_Name (Chars (X)) > 31)
10944                   then
10945                      Error_Pragma_Arg
10946                        ("argument for pragma % is longer than 31 characters",
10947                         Arg);
10948                   end if;
10949                end if;
10950             end Check_Too_Long;
10951
10952          --  Start of processing for Common_Object/Psect_Object
10953
10954          begin
10955             GNAT_Pragma;
10956             Gather_Associations (Names, Args);
10957             Process_Extended_Import_Export_Internal_Arg (Internal);
10958
10959             Def_Id := Entity (Internal);
10960
10961             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
10962                Error_Pragma_Arg
10963                  ("pragma% must designate an object", Internal);
10964             end if;
10965
10966             Check_Too_Long (Internal);
10967
10968             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10969                Error_Pragma_Arg
10970                  ("cannot use pragma% for imported/exported object",
10971                   Internal);
10972             end if;
10973
10974             if Is_Concurrent_Type (Etype (Internal)) then
10975                Error_Pragma_Arg
10976                  ("cannot specify pragma % for task/protected object",
10977                   Internal);
10978             end if;
10979
10980             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10981                  or else
10982                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10983             then
10984                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10985             end if;
10986
10987             if Ekind (Def_Id) = E_Constant then
10988                Error_Pragma_Arg
10989                  ("cannot specify pragma % for a constant", Internal);
10990             end if;
10991
10992             if Is_Record_Type (Etype (Internal)) then
10993                declare
10994                   Ent  : Entity_Id;
10995                   Decl : Entity_Id;
10996
10997                begin
10998                   Ent := First_Entity (Etype (Internal));
10999                   while Present (Ent) loop
11000                      Decl := Declaration_Node (Ent);
11001
11002                      if Ekind (Ent) = E_Component
11003                        and then Nkind (Decl) = N_Component_Declaration
11004                        and then Present (Expression (Decl))
11005                        and then Warn_On_Export_Import
11006                      then
11007                         Error_Msg_N
11008                           ("?object for pragma % has defaults", Internal);
11009                         exit;
11010
11011                      else
11012                         Next_Entity (Ent);
11013                      end if;
11014                   end loop;
11015                end;
11016             end if;
11017
11018             if Present (Size) then
11019                Check_Too_Long (Size);
11020             end if;
11021
11022             if Present (External) then
11023                Check_Arg_Is_External_Name (External);
11024                Check_Too_Long (External);
11025             end if;
11026
11027             --  If all error tests pass, link pragma on to the rep item chain
11028
11029             Record_Rep_Item (Def_Id, N);
11030          end Psect_Object;
11031
11032          ----------
11033          -- Pure --
11034          ----------
11035
11036          --  pragma Pure [(library_unit_NAME)];
11037
11038          when Pragma_Pure => Pure : declare
11039             Ent : Entity_Id;
11040
11041          begin
11042             Check_Ada_83_Warning;
11043             Check_Valid_Library_Unit_Pragma;
11044
11045             if Nkind (N) = N_Null_Statement then
11046                return;
11047             end if;
11048
11049             Ent := Find_Lib_Unit_Name;
11050             Set_Is_Pure (Ent);
11051             Set_Has_Pragma_Pure (Ent);
11052             Set_Suppress_Elaboration_Warnings (Ent);
11053          end Pure;
11054
11055          -------------
11056          -- Pure_05 --
11057          -------------
11058
11059          --  pragma Pure_05 [(library_unit_NAME)];
11060
11061          --  This pragma is useable only in GNAT_Mode, where it is used like
11062          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
11063          --  it is ignored). It may be used after a pragma Preelaborate, in
11064          --  which case it overrides the effect of the pragma Preelaborate.
11065          --  This is used to implement AI-362 which recategorizes some run-time
11066          --  packages in Ada 2005 mode.
11067
11068          when Pragma_Pure_05 => Pure_05 : declare
11069             Ent : Entity_Id;
11070
11071          begin
11072             GNAT_Pragma;
11073             Check_Valid_Library_Unit_Pragma;
11074
11075             if not GNAT_Mode then
11076                Error_Pragma ("pragma% only available in GNAT mode");
11077             end if;
11078
11079             if Nkind (N) = N_Null_Statement then
11080                return;
11081             end if;
11082
11083             --  This is one of the few cases where we need to test the value of
11084             --  Ada_Version_Explicit rather than Ada_Version (which is always
11085             --  set to Ada_12 in a predefined unit), we need to know the
11086             --  explicit version set to know if this pragma is active.
11087
11088             if Ada_Version_Explicit >= Ada_05 then
11089                Ent := Find_Lib_Unit_Name;
11090                Set_Is_Preelaborated (Ent, False);
11091                Set_Is_Pure (Ent);
11092                Set_Suppress_Elaboration_Warnings (Ent);
11093             end if;
11094          end Pure_05;
11095
11096          -------------------
11097          -- Pure_Function --
11098          -------------------
11099
11100          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11101
11102          when Pragma_Pure_Function => Pure_Function : declare
11103             E_Id      : Node_Id;
11104             E         : Entity_Id;
11105             Def_Id    : Entity_Id;
11106             Effective : Boolean := False;
11107
11108          begin
11109             GNAT_Pragma;
11110             Check_Arg_Count (1);
11111             Check_Optional_Identifier (Arg1, Name_Entity);
11112             Check_Arg_Is_Local_Name (Arg1);
11113             E_Id := Expression (Arg1);
11114
11115             if Error_Posted (E_Id) then
11116                return;
11117             end if;
11118
11119             --  Loop through homonyms (overloadings) of referenced entity
11120
11121             E := Entity (E_Id);
11122
11123             if Present (E) then
11124                loop
11125                   Def_Id := Get_Base_Subprogram (E);
11126
11127                   if not Ekind_In (Def_Id, E_Function,
11128                                            E_Generic_Function,
11129                                            E_Operator)
11130                   then
11131                      Error_Pragma_Arg
11132                        ("pragma% requires a function name", Arg1);
11133                   end if;
11134
11135                   Set_Is_Pure (Def_Id);
11136
11137                   if not Has_Pragma_Pure_Function (Def_Id) then
11138                      Set_Has_Pragma_Pure_Function (Def_Id);
11139                      Effective := True;
11140                   end if;
11141
11142                   E := Homonym (E);
11143                   exit when No (E) or else Scope (E) /= Current_Scope;
11144                end loop;
11145
11146                if not Effective
11147                  and then Warn_On_Redundant_Constructs
11148                then
11149                   Error_Msg_NE
11150                     ("pragma Pure_Function on& is redundant?",
11151                      N, Entity (E_Id));
11152                end if;
11153             end if;
11154          end Pure_Function;
11155
11156          --------------------
11157          -- Queuing_Policy --
11158          --------------------
11159
11160          --  pragma Queuing_Policy (policy_IDENTIFIER);
11161
11162          when Pragma_Queuing_Policy => declare
11163             QP : Character;
11164
11165          begin
11166             Check_Ada_83_Warning;
11167             Check_Arg_Count (1);
11168             Check_No_Identifiers;
11169             Check_Arg_Is_Queuing_Policy (Arg1);
11170             Check_Valid_Configuration_Pragma;
11171             Get_Name_String (Chars (Expression (Arg1)));
11172             QP := Fold_Upper (Name_Buffer (1));
11173
11174             if Queuing_Policy /= ' '
11175               and then Queuing_Policy /= QP
11176             then
11177                Error_Msg_Sloc := Queuing_Policy_Sloc;
11178                Error_Pragma ("queuing policy incompatible with policy#");
11179
11180             --  Set new policy, but always preserve System_Location since we
11181             --  like the error message with the run time name.
11182
11183             else
11184                Queuing_Policy := QP;
11185
11186                if Queuing_Policy_Sloc /= System_Location then
11187                   Queuing_Policy_Sloc := Loc;
11188                end if;
11189             end if;
11190          end;
11191
11192          -----------------------
11193          -- Relative_Deadline --
11194          -----------------------
11195
11196          --  pragma Relative_Deadline (time_span_EXPRESSION);
11197
11198          when Pragma_Relative_Deadline => Relative_Deadline : declare
11199             P   : constant Node_Id := Parent (N);
11200             Arg : Node_Id;
11201
11202          begin
11203             Ada_2005_Pragma;
11204             Check_No_Identifiers;
11205             Check_Arg_Count (1);
11206
11207             Arg := Expression (Arg1);
11208
11209             --  The expression must be analyzed in the special manner described
11210             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
11211
11212             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
11213
11214             --  Subprogram case
11215
11216             if Nkind (P) = N_Subprogram_Body then
11217                Check_In_Main_Program;
11218
11219             --  Tasks
11220
11221             elsif Nkind (P) = N_Task_Definition then
11222                null;
11223
11224             --  Anything else is incorrect
11225
11226             else
11227                Pragma_Misplaced;
11228             end if;
11229
11230             if Has_Relative_Deadline_Pragma (P) then
11231                Error_Pragma ("duplicate pragma% not allowed");
11232             else
11233                Set_Has_Relative_Deadline_Pragma (P, True);
11234
11235                if Nkind (P) = N_Task_Definition then
11236                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11237                end if;
11238             end if;
11239          end Relative_Deadline;
11240
11241          ---------------------------
11242          -- Remote_Call_Interface --
11243          ---------------------------
11244
11245          --  pragma Remote_Call_Interface [(library_unit_NAME)];
11246
11247          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
11248             Cunit_Node : Node_Id;
11249             Cunit_Ent  : Entity_Id;
11250             K          : Node_Kind;
11251
11252          begin
11253             Check_Ada_83_Warning;
11254             Check_Valid_Library_Unit_Pragma;
11255
11256             if Nkind (N) = N_Null_Statement then
11257                return;
11258             end if;
11259
11260             Cunit_Node := Cunit (Current_Sem_Unit);
11261             K          := Nkind (Unit (Cunit_Node));
11262             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
11263
11264             if K = N_Package_Declaration
11265               or else K = N_Generic_Package_Declaration
11266               or else K = N_Subprogram_Declaration
11267               or else K = N_Generic_Subprogram_Declaration
11268               or else (K = N_Subprogram_Body
11269                          and then Acts_As_Spec (Unit (Cunit_Node)))
11270             then
11271                null;
11272             else
11273                Error_Pragma (
11274                  "pragma% must apply to package or subprogram declaration");
11275             end if;
11276
11277             Set_Is_Remote_Call_Interface (Cunit_Ent);
11278          end Remote_Call_Interface;
11279
11280          ------------------
11281          -- Remote_Types --
11282          ------------------
11283
11284          --  pragma Remote_Types [(library_unit_NAME)];
11285
11286          when Pragma_Remote_Types => Remote_Types : declare
11287             Cunit_Node : Node_Id;
11288             Cunit_Ent  : Entity_Id;
11289
11290          begin
11291             Check_Ada_83_Warning;
11292             Check_Valid_Library_Unit_Pragma;
11293
11294             if Nkind (N) = N_Null_Statement then
11295                return;
11296             end if;
11297
11298             Cunit_Node := Cunit (Current_Sem_Unit);
11299             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
11300
11301             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11302                                                 N_Generic_Package_Declaration)
11303             then
11304                Error_Pragma
11305                  ("pragma% can only apply to a package declaration");
11306             end if;
11307
11308             Set_Is_Remote_Types (Cunit_Ent);
11309          end Remote_Types;
11310
11311          ---------------
11312          -- Ravenscar --
11313          ---------------
11314
11315          --  pragma Ravenscar;
11316
11317          when Pragma_Ravenscar =>
11318             GNAT_Pragma;
11319             Check_Arg_Count (0);
11320             Check_Valid_Configuration_Pragma;
11321             Set_Ravenscar_Profile (N);
11322
11323             if Warn_On_Obsolescent_Feature then
11324                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
11325                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
11326             end if;
11327
11328          -------------------------
11329          -- Restricted_Run_Time --
11330          -------------------------
11331
11332          --  pragma Restricted_Run_Time;
11333
11334          when Pragma_Restricted_Run_Time =>
11335             GNAT_Pragma;
11336             Check_Arg_Count (0);
11337             Check_Valid_Configuration_Pragma;
11338             Set_Profile_Restrictions
11339               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11340
11341             if Warn_On_Obsolescent_Feature then
11342                Error_Msg_N
11343                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
11344                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
11345             end if;
11346
11347          ------------------
11348          -- Restrictions --
11349          ------------------
11350
11351          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
11352
11353          --  RESTRICTION ::=
11354          --    restriction_IDENTIFIER
11355          --  | restriction_parameter_IDENTIFIER => EXPRESSION
11356
11357          when Pragma_Restrictions =>
11358             Process_Restrictions_Or_Restriction_Warnings
11359               (Warn => Treat_Restrictions_As_Warnings);
11360
11361          --------------------------
11362          -- Restriction_Warnings --
11363          --------------------------
11364
11365          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
11366
11367          --  RESTRICTION ::=
11368          --    restriction_IDENTIFIER
11369          --  | restriction_parameter_IDENTIFIER => EXPRESSION
11370
11371          when Pragma_Restriction_Warnings =>
11372             GNAT_Pragma;
11373             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
11374
11375          ----------------
11376          -- Reviewable --
11377          ----------------
11378
11379          --  pragma Reviewable;
11380
11381          when Pragma_Reviewable =>
11382             Check_Ada_83_Warning;
11383             Check_Arg_Count (0);
11384
11385             --  Call dummy debugging function rv. This is done to assist front
11386             --  end debugging. By placing a Reviewable pragma in the source
11387             --  program, a breakpoint on rv catches this place in the source,
11388             --  allowing convenient stepping to the point of interest.
11389
11390             rv;
11391
11392          --------------------------
11393          -- Short_Circuit_And_Or --
11394          --------------------------
11395
11396          when Pragma_Short_Circuit_And_Or =>
11397             GNAT_Pragma;
11398             Check_Arg_Count (0);
11399             Check_Valid_Configuration_Pragma;
11400             Short_Circuit_And_Or := True;
11401
11402          -------------------
11403          -- Share_Generic --
11404          -------------------
11405
11406          --  pragma Share_Generic (NAME {, NAME});
11407
11408          when Pragma_Share_Generic =>
11409             GNAT_Pragma;
11410             Process_Generic_List;
11411
11412          ------------
11413          -- Shared --
11414          ------------
11415
11416          --  pragma Shared (LOCAL_NAME);
11417
11418          when Pragma_Shared =>
11419             GNAT_Pragma;
11420             Process_Atomic_Shared_Volatile;
11421
11422          --------------------
11423          -- Shared_Passive --
11424          --------------------
11425
11426          --  pragma Shared_Passive [(library_unit_NAME)];
11427
11428          --  Set the flag Is_Shared_Passive of program unit name entity
11429
11430          when Pragma_Shared_Passive => Shared_Passive : declare
11431             Cunit_Node : Node_Id;
11432             Cunit_Ent  : Entity_Id;
11433
11434          begin
11435             Check_Ada_83_Warning;
11436             Check_Valid_Library_Unit_Pragma;
11437
11438             if Nkind (N) = N_Null_Statement then
11439                return;
11440             end if;
11441
11442             Cunit_Node := Cunit (Current_Sem_Unit);
11443             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
11444
11445             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11446                                                 N_Generic_Package_Declaration)
11447             then
11448                Error_Pragma
11449                  ("pragma% can only apply to a package declaration");
11450             end if;
11451
11452             Set_Is_Shared_Passive (Cunit_Ent);
11453          end Shared_Passive;
11454
11455          -----------------------
11456          -- Short_Descriptors --
11457          -----------------------
11458
11459          --  pragma Short_Descriptors;
11460
11461          when Pragma_Short_Descriptors =>
11462             GNAT_Pragma;
11463             Check_Arg_Count (0);
11464             Check_Valid_Configuration_Pragma;
11465             Short_Descriptors := True;
11466
11467          ----------------------
11468          -- Source_File_Name --
11469          ----------------------
11470
11471          --  There are five forms for this pragma:
11472
11473          --  pragma Source_File_Name (
11474          --    [UNIT_NAME      =>] unit_NAME,
11475          --     BODY_FILE_NAME =>  STRING_LITERAL
11476          --    [, [INDEX =>] INTEGER_LITERAL]);
11477
11478          --  pragma Source_File_Name (
11479          --    [UNIT_NAME      =>] unit_NAME,
11480          --     SPEC_FILE_NAME =>  STRING_LITERAL
11481          --    [, [INDEX =>] INTEGER_LITERAL]);
11482
11483          --  pragma Source_File_Name (
11484          --     BODY_FILE_NAME  => STRING_LITERAL
11485          --  [, DOT_REPLACEMENT => STRING_LITERAL]
11486          --  [, CASING          => CASING_SPEC]);
11487
11488          --  pragma Source_File_Name (
11489          --     SPEC_FILE_NAME  => STRING_LITERAL
11490          --  [, DOT_REPLACEMENT => STRING_LITERAL]
11491          --  [, CASING          => CASING_SPEC]);
11492
11493          --  pragma Source_File_Name (
11494          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
11495          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
11496          --  [, CASING             => CASING_SPEC]);
11497
11498          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
11499
11500          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
11501          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
11502          --  only be used when no project file is used, while SFNP can only be
11503          --  used when a project file is used.
11504
11505          --  No processing here. Processing was completed during parsing, since
11506          --  we need to have file names set as early as possible. Units are
11507          --  loaded well before semantic processing starts.
11508
11509          --  The only processing we defer to this point is the check for
11510          --  correct placement.
11511
11512          when Pragma_Source_File_Name =>
11513             GNAT_Pragma;
11514             Check_Valid_Configuration_Pragma;
11515
11516          ------------------------------
11517          -- Source_File_Name_Project --
11518          ------------------------------
11519
11520          --  See Source_File_Name for syntax
11521
11522          --  No processing here. Processing was completed during parsing, since
11523          --  we need to have file names set as early as possible. Units are
11524          --  loaded well before semantic processing starts.
11525
11526          --  The only processing we defer to this point is the check for
11527          --  correct placement.
11528
11529          when Pragma_Source_File_Name_Project =>
11530             GNAT_Pragma;
11531             Check_Valid_Configuration_Pragma;
11532
11533             --  Check that a pragma Source_File_Name_Project is used only in a
11534             --  configuration pragmas file.
11535
11536             --  Pragmas Source_File_Name_Project should only be generated by
11537             --  the Project Manager in configuration pragmas files.
11538
11539             --  This is really an ugly test. It seems to depend on some
11540             --  accidental and undocumented property. At the very least it
11541             --  needs to be documented, but it would be better to have a
11542             --  clean way of testing if we are in a configuration file???
11543
11544             if Present (Parent (N)) then
11545                Error_Pragma
11546                  ("pragma% can only appear in a configuration pragmas file");
11547             end if;
11548
11549          ----------------------
11550          -- Source_Reference --
11551          ----------------------
11552
11553          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
11554
11555          --  Nothing to do, all processing completed in Par.Prag, since we need
11556          --  the information for possible parser messages that are output.
11557
11558          when Pragma_Source_Reference =>
11559             GNAT_Pragma;
11560
11561          --------------------------------
11562          -- Static_Elaboration_Desired --
11563          --------------------------------
11564
11565          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
11566
11567          when Pragma_Static_Elaboration_Desired =>
11568             GNAT_Pragma;
11569             Check_At_Most_N_Arguments (1);
11570
11571             if Is_Compilation_Unit (Current_Scope)
11572               and then Ekind (Current_Scope) = E_Package
11573             then
11574                Set_Static_Elaboration_Desired (Current_Scope, True);
11575             else
11576                Error_Pragma ("pragma% must apply to a library-level package");
11577             end if;
11578
11579          ------------------
11580          -- Storage_Size --
11581          ------------------
11582
11583          --  pragma Storage_Size (EXPRESSION);
11584
11585          when Pragma_Storage_Size => Storage_Size : declare
11586             P   : constant Node_Id := Parent (N);
11587             Arg : Node_Id;
11588
11589          begin
11590             Check_No_Identifiers;
11591             Check_Arg_Count (1);
11592
11593             --  The expression must be analyzed in the special manner described
11594             --  in "Handling of Default Expressions" in sem.ads.
11595
11596             Arg := Expression (Arg1);
11597             Preanalyze_Spec_Expression (Arg, Any_Integer);
11598
11599             if not Is_Static_Expression (Arg) then
11600                Check_Restriction (Static_Storage_Size, Arg);
11601             end if;
11602
11603             if Nkind (P) /= N_Task_Definition then
11604                Pragma_Misplaced;
11605                return;
11606
11607             else
11608                if Has_Storage_Size_Pragma (P) then
11609                   Error_Pragma ("duplicate pragma% not allowed");
11610                else
11611                   Set_Has_Storage_Size_Pragma (P, True);
11612                end if;
11613
11614                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11615                --  ???  exp_ch9 should use this!
11616             end if;
11617          end Storage_Size;
11618
11619          ------------------
11620          -- Storage_Unit --
11621          ------------------
11622
11623          --  pragma Storage_Unit (NUMERIC_LITERAL);
11624
11625          --  Only permitted argument is System'Storage_Unit value
11626
11627          when Pragma_Storage_Unit =>
11628             Check_No_Identifiers;
11629             Check_Arg_Count (1);
11630             Check_Arg_Is_Integer_Literal (Arg1);
11631
11632             if Intval (Expression (Arg1)) /=
11633               UI_From_Int (Ttypes.System_Storage_Unit)
11634             then
11635                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
11636                Error_Pragma_Arg
11637                  ("the only allowed argument for pragma% is ^", Arg1);
11638             end if;
11639
11640          --------------------
11641          -- Stream_Convert --
11642          --------------------
11643
11644          --  pragma Stream_Convert (
11645          --    [Entity =>] type_LOCAL_NAME,
11646          --    [Read   =>] function_NAME,
11647          --    [Write  =>] function NAME);
11648
11649          when Pragma_Stream_Convert => Stream_Convert : declare
11650
11651             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
11652             --  Check that the given argument is the name of a local function
11653             --  of one argument that is not overloaded earlier in the current
11654             --  local scope. A check is also made that the argument is a
11655             --  function with one parameter.
11656
11657             --------------------------------------
11658             -- Check_OK_Stream_Convert_Function --
11659             --------------------------------------
11660
11661             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
11662                Ent : Entity_Id;
11663
11664             begin
11665                Check_Arg_Is_Local_Name (Arg);
11666                Ent := Entity (Expression (Arg));
11667
11668                if Has_Homonym (Ent) then
11669                   Error_Pragma_Arg
11670                     ("argument for pragma% may not be overloaded", Arg);
11671                end if;
11672
11673                if Ekind (Ent) /= E_Function
11674                  or else No (First_Formal (Ent))
11675                  or else Present (Next_Formal (First_Formal (Ent)))
11676                then
11677                   Error_Pragma_Arg
11678                     ("argument for pragma% must be" &
11679                      " function of one argument", Arg);
11680                end if;
11681             end Check_OK_Stream_Convert_Function;
11682
11683          --  Start of processing for Stream_Convert
11684
11685          begin
11686             GNAT_Pragma;
11687             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
11688             Check_Arg_Count (3);
11689             Check_Optional_Identifier (Arg1, Name_Entity);
11690             Check_Optional_Identifier (Arg2, Name_Read);
11691             Check_Optional_Identifier (Arg3, Name_Write);
11692             Check_Arg_Is_Local_Name (Arg1);
11693             Check_OK_Stream_Convert_Function (Arg2);
11694             Check_OK_Stream_Convert_Function (Arg3);
11695
11696             declare
11697                Typ   : constant Entity_Id :=
11698                          Underlying_Type (Entity (Expression (Arg1)));
11699                Read  : constant Entity_Id := Entity (Expression (Arg2));
11700                Write : constant Entity_Id := Entity (Expression (Arg3));
11701
11702             begin
11703                Check_First_Subtype (Arg1);
11704
11705                --  Check for too early or too late. Note that we don't enforce
11706                --  the rule about primitive operations in this case, since, as
11707                --  is the case for explicit stream attributes themselves, these
11708                --  restrictions are not appropriate. Note that the chaining of
11709                --  the pragma by Rep_Item_Too_Late is actually the critical
11710                --  processing done for this pragma.
11711
11712                if Rep_Item_Too_Early (Typ, N)
11713                     or else
11714                   Rep_Item_Too_Late (Typ, N, FOnly => True)
11715                then
11716                   return;
11717                end if;
11718
11719                --  Return if previous error
11720
11721                if Etype (Typ) = Any_Type
11722                     or else
11723                   Etype (Read) = Any_Type
11724                     or else
11725                   Etype (Write) = Any_Type
11726                then
11727                   return;
11728                end if;
11729
11730                --  Error checks
11731
11732                if Underlying_Type (Etype (Read)) /= Typ then
11733                   Error_Pragma_Arg
11734                     ("incorrect return type for function&", Arg2);
11735                end if;
11736
11737                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
11738                   Error_Pragma_Arg
11739                     ("incorrect parameter type for function&", Arg3);
11740                end if;
11741
11742                if Underlying_Type (Etype (First_Formal (Read))) /=
11743                   Underlying_Type (Etype (Write))
11744                then
11745                   Error_Pragma_Arg
11746                     ("result type of & does not match Read parameter type",
11747                      Arg3);
11748                end if;
11749             end;
11750          end Stream_Convert;
11751
11752          -------------------------
11753          -- Style_Checks (GNAT) --
11754          -------------------------
11755
11756          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11757
11758          --  This is processed by the parser since some of the style checks
11759          --  take place during source scanning and parsing. This means that
11760          --  we don't need to issue error messages here.
11761
11762          when Pragma_Style_Checks => Style_Checks : declare
11763             A  : constant Node_Id   := Expression (Arg1);
11764             S  : String_Id;
11765             C  : Char_Code;
11766
11767          begin
11768             GNAT_Pragma;
11769             Check_No_Identifiers;
11770
11771             --  Two argument form
11772
11773             if Arg_Count = 2 then
11774                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11775
11776                declare
11777                   E_Id : Node_Id;
11778                   E    : Entity_Id;
11779
11780                begin
11781                   E_Id := Expression (Arg2);
11782                   Analyze (E_Id);
11783
11784                   if not Is_Entity_Name (E_Id) then
11785                      Error_Pragma_Arg
11786                        ("second argument of pragma% must be entity name",
11787                         Arg2);
11788                   end if;
11789
11790                   E := Entity (E_Id);
11791
11792                   if E = Any_Id then
11793                      return;
11794                   else
11795                      loop
11796                         Set_Suppress_Style_Checks (E,
11797                           (Chars (Expression (Arg1)) = Name_Off));
11798                         exit when No (Homonym (E));
11799                         E := Homonym (E);
11800                      end loop;
11801                   end if;
11802                end;
11803
11804             --  One argument form
11805
11806             else
11807                Check_Arg_Count (1);
11808
11809                if Nkind (A) = N_String_Literal then
11810                   S   := Strval (A);
11811
11812                   declare
11813                      Slen    : constant Natural := Natural (String_Length (S));
11814                      Options : String (1 .. Slen);
11815                      J       : Natural;
11816
11817                   begin
11818                      J := 1;
11819                      loop
11820                         C := Get_String_Char (S, Int (J));
11821                         exit when not In_Character_Range (C);
11822                         Options (J) := Get_Character (C);
11823
11824                         --  If at end of string, set options. As per discussion
11825                         --  above, no need to check for errors, since we issued
11826                         --  them in the parser.
11827
11828                         if J = Slen then
11829                            Set_Style_Check_Options (Options);
11830                            exit;
11831                         end if;
11832
11833                         J := J + 1;
11834                      end loop;
11835                   end;
11836
11837                elsif Nkind (A) = N_Identifier then
11838                   if Chars (A) = Name_All_Checks then
11839                      if GNAT_Mode then
11840                         Set_GNAT_Style_Check_Options;
11841                      else
11842                         Set_Default_Style_Check_Options;
11843                      end if;
11844
11845                   elsif Chars (A) = Name_On then
11846                      Style_Check := True;
11847
11848                   elsif Chars (A) = Name_Off then
11849                      Style_Check := False;
11850                   end if;
11851                end if;
11852             end if;
11853          end Style_Checks;
11854
11855          --------------
11856          -- Subtitle --
11857          --------------
11858
11859          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
11860
11861          when Pragma_Subtitle =>
11862             GNAT_Pragma;
11863             Check_Arg_Count (1);
11864             Check_Optional_Identifier (Arg1, Name_Subtitle);
11865             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11866             Store_Note (N);
11867
11868          --------------
11869          -- Suppress --
11870          --------------
11871
11872          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
11873
11874          when Pragma_Suppress =>
11875             Process_Suppress_Unsuppress (True);
11876
11877          ------------------
11878          -- Suppress_All --
11879          ------------------
11880
11881          --  pragma Suppress_All;
11882
11883          --  The only check made here is that the pragma appears in the proper
11884          --  place, i.e. following a compilation unit. If indeed it appears in
11885          --  this context, then the parser has already inserted an equivalent
11886          --  pragma Suppress (All_Checks) to get the required effect.
11887
11888          when Pragma_Suppress_All =>
11889             GNAT_Pragma;
11890             Check_Arg_Count (0);
11891
11892             if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
11893               or else not Is_List_Member (N)
11894               or else List_Containing (N) /= Pragmas_After (Parent (N))
11895             then
11896                Error_Pragma
11897                  ("misplaced pragma%, must follow compilation unit");
11898             end if;
11899
11900          -------------------------
11901          -- Suppress_Debug_Info --
11902          -------------------------
11903
11904          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
11905
11906          when Pragma_Suppress_Debug_Info =>
11907             GNAT_Pragma;
11908             Check_Arg_Count (1);
11909             Check_Optional_Identifier (Arg1, Name_Entity);
11910             Check_Arg_Is_Local_Name (Arg1);
11911             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
11912
11913          ----------------------------------
11914          -- Suppress_Exception_Locations --
11915          ----------------------------------
11916
11917          --  pragma Suppress_Exception_Locations;
11918
11919          when Pragma_Suppress_Exception_Locations =>
11920             GNAT_Pragma;
11921             Check_Arg_Count (0);
11922             Check_Valid_Configuration_Pragma;
11923             Exception_Locations_Suppressed := True;
11924
11925          -----------------------------
11926          -- Suppress_Initialization --
11927          -----------------------------
11928
11929          --  pragma Suppress_Initialization ([Entity =>] type_Name);
11930
11931          when Pragma_Suppress_Initialization => Suppress_Init : declare
11932             E_Id : Node_Id;
11933             E    : Entity_Id;
11934
11935          begin
11936             GNAT_Pragma;
11937             Check_Arg_Count (1);
11938             Check_Optional_Identifier (Arg1, Name_Entity);
11939             Check_Arg_Is_Local_Name (Arg1);
11940
11941             E_Id := Expression (Arg1);
11942
11943             if Etype (E_Id) = Any_Type then
11944                return;
11945             end if;
11946
11947             E := Entity (E_Id);
11948
11949             if Is_Type (E) then
11950                if Is_Incomplete_Or_Private_Type (E) then
11951                   if No (Full_View (Base_Type (E))) then
11952                      Error_Pragma_Arg
11953                        ("argument of pragma% cannot be an incomplete type",
11954                          Arg1);
11955                   else
11956                      Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11957                   end if;
11958                else
11959                   Set_Suppress_Init_Proc (Base_Type (E));
11960                end if;
11961
11962             else
11963                Error_Pragma_Arg
11964                  ("pragma% requires argument that is a type name", Arg1);
11965             end if;
11966          end Suppress_Init;
11967
11968          -----------------
11969          -- System_Name --
11970          -----------------
11971
11972          --  pragma System_Name (DIRECT_NAME);
11973
11974          --  Syntax check: one argument, which must be the identifier GNAT or
11975          --  the identifier GCC, no other identifiers are acceptable.
11976
11977          when Pragma_System_Name =>
11978             GNAT_Pragma;
11979             Check_No_Identifiers;
11980             Check_Arg_Count (1);
11981             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11982
11983          -----------------------------
11984          -- Task_Dispatching_Policy --
11985          -----------------------------
11986
11987          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11988
11989          when Pragma_Task_Dispatching_Policy => declare
11990             DP : Character;
11991
11992          begin
11993             Check_Ada_83_Warning;
11994             Check_Arg_Count (1);
11995             Check_No_Identifiers;
11996             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11997             Check_Valid_Configuration_Pragma;
11998             Get_Name_String (Chars (Expression (Arg1)));
11999             DP := Fold_Upper (Name_Buffer (1));
12000
12001             if Task_Dispatching_Policy /= ' '
12002               and then Task_Dispatching_Policy /= DP
12003             then
12004                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12005                Error_Pragma
12006                  ("task dispatching policy incompatible with policy#");
12007
12008             --  Set new policy, but always preserve System_Location since we
12009             --  like the error message with the run time name.
12010
12011             else
12012                Task_Dispatching_Policy := DP;
12013
12014                if Task_Dispatching_Policy_Sloc /= System_Location then
12015                   Task_Dispatching_Policy_Sloc := Loc;
12016                end if;
12017             end if;
12018          end;
12019
12020          --------------
12021          -- Task_Info --
12022          --------------
12023
12024          --  pragma Task_Info (EXPRESSION);
12025
12026          when Pragma_Task_Info => Task_Info : declare
12027             P : constant Node_Id := Parent (N);
12028
12029          begin
12030             GNAT_Pragma;
12031
12032             if Nkind (P) /= N_Task_Definition then
12033                Error_Pragma ("pragma% must appear in task definition");
12034             end if;
12035
12036             Check_No_Identifiers;
12037             Check_Arg_Count (1);
12038
12039             Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
12040
12041             if Etype (Expression (Arg1)) = Any_Type then
12042                return;
12043             end if;
12044
12045             if Has_Task_Info_Pragma (P) then
12046                Error_Pragma ("duplicate pragma% not allowed");
12047             else
12048                Set_Has_Task_Info_Pragma (P, True);
12049             end if;
12050          end Task_Info;
12051
12052          ---------------
12053          -- Task_Name --
12054          ---------------
12055
12056          --  pragma Task_Name (string_EXPRESSION);
12057
12058          when Pragma_Task_Name => Task_Name : declare
12059             P   : constant Node_Id := Parent (N);
12060             Arg : Node_Id;
12061
12062          begin
12063             Check_No_Identifiers;
12064             Check_Arg_Count (1);
12065
12066             Arg := Expression (Arg1);
12067
12068             --  The expression is used in the call to Create_Task, and must be
12069             --  expanded there, not in the context of the current spec. It must
12070             --  however be analyzed to capture global references, in case it
12071             --  appears in a generic context.
12072
12073             Preanalyze_And_Resolve (Arg, Standard_String);
12074
12075             if Nkind (P) /= N_Task_Definition then
12076                Pragma_Misplaced;
12077             end if;
12078
12079             if Has_Task_Name_Pragma (P) then
12080                Error_Pragma ("duplicate pragma% not allowed");
12081             else
12082                Set_Has_Task_Name_Pragma (P, True);
12083                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12084             end if;
12085          end Task_Name;
12086
12087          ------------------
12088          -- Task_Storage --
12089          ------------------
12090
12091          --  pragma Task_Storage (
12092          --     [Task_Type =>] LOCAL_NAME,
12093          --     [Top_Guard =>] static_integer_EXPRESSION);
12094
12095          when Pragma_Task_Storage => Task_Storage : declare
12096             Args  : Args_List (1 .. 2);
12097             Names : constant Name_List (1 .. 2) := (
12098                       Name_Task_Type,
12099                       Name_Top_Guard);
12100
12101             Task_Type : Node_Id renames Args (1);
12102             Top_Guard : Node_Id renames Args (2);
12103
12104             Ent : Entity_Id;
12105
12106          begin
12107             GNAT_Pragma;
12108             Gather_Associations (Names, Args);
12109
12110             if No (Task_Type) then
12111                Error_Pragma
12112                  ("missing task_type argument for pragma%");
12113             end if;
12114
12115             Check_Arg_Is_Local_Name (Task_Type);
12116
12117             Ent := Entity (Task_Type);
12118
12119             if not Is_Task_Type (Ent) then
12120                Error_Pragma_Arg
12121                  ("argument for pragma% must be task type", Task_Type);
12122             end if;
12123
12124             if No (Top_Guard) then
12125                Error_Pragma_Arg
12126                  ("pragma% takes two arguments", Task_Type);
12127             else
12128                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12129             end if;
12130
12131             Check_First_Subtype (Task_Type);
12132
12133             if Rep_Item_Too_Late (Ent, N) then
12134                raise Pragma_Exit;
12135             end if;
12136          end Task_Storage;
12137
12138          --------------------------
12139          -- Thread_Local_Storage --
12140          --------------------------
12141
12142          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12143
12144          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12145             Id : Node_Id;
12146             E  : Entity_Id;
12147
12148          begin
12149             GNAT_Pragma;
12150             Check_Arg_Count (1);
12151             Check_Optional_Identifier (Arg1, Name_Entity);
12152             Check_Arg_Is_Library_Level_Local_Name (Arg1);
12153
12154             Id := Expression (Arg1);
12155             Analyze (Id);
12156
12157             if not Is_Entity_Name (Id)
12158               or else Ekind (Entity (Id)) /= E_Variable
12159             then
12160                Error_Pragma_Arg ("local variable name required", Arg1);
12161             end if;
12162
12163             E := Entity (Id);
12164
12165             if Rep_Item_Too_Early (E, N)
12166               or else Rep_Item_Too_Late (E, N)
12167             then
12168                raise Pragma_Exit;
12169             end if;
12170
12171             Set_Has_Pragma_Thread_Local_Storage (E);
12172             Set_Has_Gigi_Rep_Item (E);
12173          end Thread_Local_Storage;
12174
12175          ----------------
12176          -- Time_Slice --
12177          ----------------
12178
12179          --  pragma Time_Slice (static_duration_EXPRESSION);
12180
12181          when Pragma_Time_Slice => Time_Slice : declare
12182             Val : Ureal;
12183             Nod : Node_Id;
12184
12185          begin
12186             GNAT_Pragma;
12187             Check_Arg_Count (1);
12188             Check_No_Identifiers;
12189             Check_In_Main_Program;
12190             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
12191
12192             if not Error_Posted (Arg1) then
12193                Nod := Next (N);
12194                while Present (Nod) loop
12195                   if Nkind (Nod) = N_Pragma
12196                     and then Pragma_Name (Nod) = Name_Time_Slice
12197                   then
12198                      Error_Msg_Name_1 := Pname;
12199                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
12200                   end if;
12201
12202                   Next (Nod);
12203                end loop;
12204             end if;
12205
12206             --  Process only if in main unit
12207
12208             if Get_Source_Unit (Loc) = Main_Unit then
12209                Opt.Time_Slice_Set := True;
12210                Val := Expr_Value_R (Expression (Arg1));
12211
12212                if Val <= Ureal_0 then
12213                   Opt.Time_Slice_Value := 0;
12214
12215                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
12216                   Opt.Time_Slice_Value := 1_000_000_000;
12217
12218                else
12219                   Opt.Time_Slice_Value :=
12220                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
12221                end if;
12222             end if;
12223          end Time_Slice;
12224
12225          -----------
12226          -- Title --
12227          -----------
12228
12229          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
12230
12231          --   TITLING_OPTION ::=
12232          --     [Title =>] STRING_LITERAL
12233          --   | [Subtitle =>] STRING_LITERAL
12234
12235          when Pragma_Title => Title : declare
12236             Args  : Args_List (1 .. 2);
12237             Names : constant Name_List (1 .. 2) := (
12238                       Name_Title,
12239                       Name_Subtitle);
12240
12241          begin
12242             GNAT_Pragma;
12243             Gather_Associations (Names, Args);
12244             Store_Note (N);
12245
12246             for J in 1 .. 2 loop
12247                if Present (Args (J)) then
12248                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
12249                end if;
12250             end loop;
12251          end Title;
12252
12253          ---------------------
12254          -- Unchecked_Union --
12255          ---------------------
12256
12257          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
12258
12259          when Pragma_Unchecked_Union => Unchecked_Union : declare
12260             Assoc   : constant Node_Id := Arg1;
12261             Type_Id : constant Node_Id := Expression (Assoc);
12262             Typ     : Entity_Id;
12263             Discr   : Entity_Id;
12264             Tdef    : Node_Id;
12265             Clist   : Node_Id;
12266             Vpart   : Node_Id;
12267             Comp    : Node_Id;
12268             Variant : Node_Id;
12269
12270          begin
12271             Ada_2005_Pragma;
12272             Check_No_Identifiers;
12273             Check_Arg_Count (1);
12274             Check_Arg_Is_Local_Name (Arg1);
12275
12276             Find_Type (Type_Id);
12277             Typ := Entity (Type_Id);
12278
12279             if Typ = Any_Type
12280               or else Rep_Item_Too_Early (Typ, N)
12281             then
12282                return;
12283             else
12284                Typ := Underlying_Type (Typ);
12285             end if;
12286
12287             if Rep_Item_Too_Late (Typ, N) then
12288                return;
12289             end if;
12290
12291             Check_First_Subtype (Arg1);
12292
12293             --  Note remaining cases are references to a type in the current
12294             --  declarative part. If we find an error, we post the error on
12295             --  the relevant type declaration at an appropriate point.
12296
12297             if not Is_Record_Type (Typ) then
12298                Error_Msg_N ("Unchecked_Union must be record type", Typ);
12299                return;
12300
12301             elsif Is_Tagged_Type (Typ) then
12302                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
12303                return;
12304
12305             elsif Is_Limited_Type (Typ) then
12306                Error_Msg_N
12307                  ("Unchecked_Union must not be limited record type", Typ);
12308                Explain_Limited_Type (Typ, Typ);
12309                return;
12310
12311             else
12312                if not Has_Discriminants (Typ) then
12313                   Error_Msg_N
12314                     ("Unchecked_Union must have one discriminant", Typ);
12315                   return;
12316                end if;
12317
12318                Discr := First_Discriminant (Typ);
12319                while Present (Discr) loop
12320                   if No (Discriminant_Default_Value (Discr)) then
12321                      Error_Msg_N
12322                        ("Unchecked_Union discriminant must have default value",
12323                         Discr);
12324                   end if;
12325                   Next_Discriminant (Discr);
12326                end loop;
12327
12328                Tdef  := Type_Definition (Declaration_Node (Typ));
12329                Clist := Component_List (Tdef);
12330
12331                Comp := First (Component_Items (Clist));
12332                while Present (Comp) loop
12333                   Check_Component (Comp, Typ);
12334                   Next (Comp);
12335                end loop;
12336
12337                if No (Clist) or else No (Variant_Part (Clist)) then
12338                   Error_Msg_N
12339                     ("Unchecked_Union must have variant part",
12340                      Tdef);
12341                   return;
12342                end if;
12343
12344                Vpart := Variant_Part (Clist);
12345
12346                Variant := First (Variants (Vpart));
12347                while Present (Variant) loop
12348                   Check_Variant (Variant, Typ);
12349                   Next (Variant);
12350                end loop;
12351             end if;
12352
12353             Set_Is_Unchecked_Union  (Typ, True);
12354             Set_Convention          (Typ, Convention_C);
12355
12356             Set_Has_Unchecked_Union (Base_Type (Typ), True);
12357             Set_Is_Unchecked_Union  (Base_Type (Typ), True);
12358          end Unchecked_Union;
12359
12360          ------------------------
12361          -- Unimplemented_Unit --
12362          ------------------------
12363
12364          --  pragma Unimplemented_Unit;
12365
12366          --  Note: this only gives an error if we are generating code, or if
12367          --  we are in a generic library unit (where the pragma appears in the
12368          --  body, not in the spec).
12369
12370          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
12371             Cunitent : constant Entity_Id :=
12372                          Cunit_Entity (Get_Source_Unit (Loc));
12373             Ent_Kind : constant Entity_Kind :=
12374                          Ekind (Cunitent);
12375
12376          begin
12377             GNAT_Pragma;
12378             Check_Arg_Count (0);
12379
12380             if Operating_Mode = Generate_Code
12381               or else Ent_Kind = E_Generic_Function
12382               or else Ent_Kind = E_Generic_Procedure
12383               or else Ent_Kind = E_Generic_Package
12384             then
12385                Get_Name_String (Chars (Cunitent));
12386                Set_Casing (Mixed_Case);
12387                Write_Str (Name_Buffer (1 .. Name_Len));
12388                Write_Str (" is not supported in this configuration");
12389                Write_Eol;
12390                raise Unrecoverable_Error;
12391             end if;
12392          end Unimplemented_Unit;
12393
12394          ------------------------
12395          -- Universal_Aliasing --
12396          ------------------------
12397
12398          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
12399
12400          when Pragma_Universal_Aliasing => Universal_Alias : declare
12401             E_Id : Entity_Id;
12402
12403          begin
12404             GNAT_Pragma;
12405             Check_Arg_Count (1);
12406             Check_Optional_Identifier (Arg2, Name_Entity);
12407             Check_Arg_Is_Local_Name (Arg1);
12408             E_Id := Entity (Expression (Arg1));
12409
12410             if E_Id = Any_Type then
12411                return;
12412             elsif No (E_Id) or else not Is_Type (E_Id) then
12413                Error_Pragma_Arg ("pragma% requires type", Arg1);
12414             end if;
12415
12416             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
12417          end Universal_Alias;
12418
12419          --------------------
12420          -- Universal_Data --
12421          --------------------
12422
12423          --  pragma Universal_Data [(library_unit_NAME)];
12424
12425          when Pragma_Universal_Data =>
12426             GNAT_Pragma;
12427
12428             --  If this is a configuration pragma, then set the universal
12429             --  addressing option, otherwise confirm that the pragma satisfies
12430             --  the requirements of library unit pragma placement and leave it
12431             --  to the GNAAMP back end to detect the pragma (avoids transitive
12432             --  setting of the option due to withed units).
12433
12434             if Is_Configuration_Pragma then
12435                Universal_Addressing_On_AAMP := True;
12436             else
12437                Check_Valid_Library_Unit_Pragma;
12438             end if;
12439
12440             if not AAMP_On_Target then
12441                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
12442             end if;
12443
12444          ----------------
12445          -- Unmodified --
12446          ----------------
12447
12448          --  pragma Unmodified (local_Name {, local_Name});
12449
12450          when Pragma_Unmodified => Unmodified : declare
12451             Arg_Node : Node_Id;
12452             Arg_Expr : Node_Id;
12453             Arg_Ent  : Entity_Id;
12454
12455          begin
12456             GNAT_Pragma;
12457             Check_At_Least_N_Arguments (1);
12458
12459             --  Loop through arguments
12460
12461             Arg_Node := Arg1;
12462             while Present (Arg_Node) loop
12463                Check_No_Identifier (Arg_Node);
12464
12465                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
12466                --  in fact generate reference, so that the entity will have a
12467                --  reference, which will inhibit any warnings about it not
12468                --  being referenced, and also properly show up in the ali file
12469                --  as a reference. But this reference is recorded before the
12470                --  Has_Pragma_Unreferenced flag is set, so that no warning is
12471                --  generated for this reference.
12472
12473                Check_Arg_Is_Local_Name (Arg_Node);
12474                Arg_Expr := Get_Pragma_Arg (Arg_Node);
12475
12476                if Is_Entity_Name (Arg_Expr) then
12477                   Arg_Ent := Entity (Arg_Expr);
12478
12479                   if not Is_Assignable (Arg_Ent) then
12480                      Error_Pragma_Arg
12481                        ("pragma% can only be applied to a variable",
12482                         Arg_Expr);
12483                   else
12484                      Set_Has_Pragma_Unmodified (Arg_Ent);
12485                   end if;
12486                end if;
12487
12488                Next (Arg_Node);
12489             end loop;
12490          end Unmodified;
12491
12492          ------------------
12493          -- Unreferenced --
12494          ------------------
12495
12496          --  pragma Unreferenced (local_Name {, local_Name});
12497
12498          --    or when used in a context clause:
12499
12500          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
12501
12502          when Pragma_Unreferenced => Unreferenced : declare
12503             Arg_Node : Node_Id;
12504             Arg_Expr : Node_Id;
12505             Arg_Ent  : Entity_Id;
12506             Citem    : Node_Id;
12507
12508          begin
12509             GNAT_Pragma;
12510             Check_At_Least_N_Arguments (1);
12511
12512             --  Check case of appearing within context clause
12513
12514             if Is_In_Context_Clause then
12515
12516                --  The arguments must all be units mentioned in a with clause
12517                --  in the same context clause. Note we already checked (in
12518                --  Par.Prag) that the arguments are either identifiers or
12519                --  selected components.
12520
12521                Arg_Node := Arg1;
12522                while Present (Arg_Node) loop
12523                   Citem := First (List_Containing (N));
12524                   while Citem /= N loop
12525                      if Nkind (Citem) = N_With_Clause
12526                        and then Same_Name (Name (Citem), Expression (Arg_Node))
12527                      then
12528                         Set_Has_Pragma_Unreferenced
12529                           (Cunit_Entity
12530                              (Get_Source_Unit
12531                                 (Library_Unit (Citem))));
12532                         Set_Unit_Name (Expression (Arg_Node), Name (Citem));
12533                         exit;
12534                      end if;
12535
12536                      Next (Citem);
12537                   end loop;
12538
12539                   if Citem = N then
12540                      Error_Pragma_Arg
12541                        ("argument of pragma% is not with'ed unit", Arg_Node);
12542                   end if;
12543
12544                   Next (Arg_Node);
12545                end loop;
12546
12547             --  Case of not in list of context items
12548
12549             else
12550                Arg_Node := Arg1;
12551                while Present (Arg_Node) loop
12552                   Check_No_Identifier (Arg_Node);
12553
12554                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
12555                   --  will in fact generate reference, so that the entity will
12556                   --  have a reference, which will inhibit any warnings about
12557                   --  it not being referenced, and also properly show up in the
12558                   --  ali file as a reference. But this reference is recorded
12559                   --  before the Has_Pragma_Unreferenced flag is set, so that
12560                   --  no warning is generated for this reference.
12561
12562                   Check_Arg_Is_Local_Name (Arg_Node);
12563                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
12564
12565                   if Is_Entity_Name (Arg_Expr) then
12566                      Arg_Ent := Entity (Arg_Expr);
12567
12568                      --  If the entity is overloaded, the pragma applies to the
12569                      --  most recent overloading, as documented. In this case,
12570                      --  name resolution does not generate a reference, so it
12571                      --  must be done here explicitly.
12572
12573                      if Is_Overloaded (Arg_Expr) then
12574                         Generate_Reference (Arg_Ent, N);
12575                      end if;
12576
12577                      Set_Has_Pragma_Unreferenced (Arg_Ent);
12578                   end if;
12579
12580                   Next (Arg_Node);
12581                end loop;
12582             end if;
12583          end Unreferenced;
12584
12585          --------------------------
12586          -- Unreferenced_Objects --
12587          --------------------------
12588
12589          --  pragma Unreferenced_Objects (local_Name {, local_Name});
12590
12591          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
12592             Arg_Node : Node_Id;
12593             Arg_Expr : Node_Id;
12594
12595          begin
12596             GNAT_Pragma;
12597             Check_At_Least_N_Arguments (1);
12598
12599             Arg_Node := Arg1;
12600             while Present (Arg_Node) loop
12601                Check_No_Identifier (Arg_Node);
12602                Check_Arg_Is_Local_Name (Arg_Node);
12603                Arg_Expr := Get_Pragma_Arg (Arg_Node);
12604
12605                if not Is_Entity_Name (Arg_Expr)
12606                  or else not Is_Type (Entity (Arg_Expr))
12607                then
12608                   Error_Pragma_Arg
12609                     ("argument for pragma% must be type or subtype", Arg_Node);
12610                end if;
12611
12612                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
12613                Next (Arg_Node);
12614             end loop;
12615          end Unreferenced_Objects;
12616
12617          ------------------------------
12618          -- Unreserve_All_Interrupts --
12619          ------------------------------
12620
12621          --  pragma Unreserve_All_Interrupts;
12622
12623          when Pragma_Unreserve_All_Interrupts =>
12624             GNAT_Pragma;
12625             Check_Arg_Count (0);
12626
12627             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
12628                Unreserve_All_Interrupts := True;
12629             end if;
12630
12631          ----------------
12632          -- Unsuppress --
12633          ----------------
12634
12635          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
12636
12637          when Pragma_Unsuppress =>
12638             Ada_2005_Pragma;
12639             Process_Suppress_Unsuppress (False);
12640
12641          -------------------
12642          -- Use_VADS_Size --
12643          -------------------
12644
12645          --  pragma Use_VADS_Size;
12646
12647          when Pragma_Use_VADS_Size =>
12648             GNAT_Pragma;
12649             Check_Arg_Count (0);
12650             Check_Valid_Configuration_Pragma;
12651             Use_VADS_Size := True;
12652
12653          ---------------------
12654          -- Validity_Checks --
12655          ---------------------
12656
12657          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12658
12659          when Pragma_Validity_Checks => Validity_Checks : declare
12660             A  : constant Node_Id   := Expression (Arg1);
12661             S  : String_Id;
12662             C  : Char_Code;
12663
12664          begin
12665             GNAT_Pragma;
12666             Check_Arg_Count (1);
12667             Check_No_Identifiers;
12668
12669             if Nkind (A) = N_String_Literal then
12670                S   := Strval (A);
12671
12672                declare
12673                   Slen    : constant Natural := Natural (String_Length (S));
12674                   Options : String (1 .. Slen);
12675                   J       : Natural;
12676
12677                begin
12678                   J := 1;
12679                   loop
12680                      C := Get_String_Char (S, Int (J));
12681                      exit when not In_Character_Range (C);
12682                      Options (J) := Get_Character (C);
12683
12684                      if J = Slen then
12685                         Set_Validity_Check_Options (Options);
12686                         exit;
12687                      else
12688                         J := J + 1;
12689                      end if;
12690                   end loop;
12691                end;
12692
12693             elsif Nkind (A) = N_Identifier then
12694
12695                if Chars (A) = Name_All_Checks then
12696                   Set_Validity_Check_Options ("a");
12697
12698                elsif Chars (A) = Name_On then
12699                   Validity_Checks_On := True;
12700
12701                elsif Chars (A) = Name_Off then
12702                   Validity_Checks_On := False;
12703
12704                end if;
12705             end if;
12706          end Validity_Checks;
12707
12708          --------------
12709          -- Volatile --
12710          --------------
12711
12712          --  pragma Volatile (LOCAL_NAME);
12713
12714          when Pragma_Volatile =>
12715             Process_Atomic_Shared_Volatile;
12716
12717          -------------------------
12718          -- Volatile_Components --
12719          -------------------------
12720
12721          --  pragma Volatile_Components (array_LOCAL_NAME);
12722
12723          --  Volatile is handled by the same circuit as Atomic_Components
12724
12725          --------------
12726          -- Warnings --
12727          --------------
12728
12729          --  pragma Warnings (On | Off);
12730          --  pragma Warnings (On | Off, LOCAL_NAME);
12731          --  pragma Warnings (static_string_EXPRESSION);
12732          --  pragma Warnings (On | Off, STRING_LITERAL);
12733
12734          when Pragma_Warnings => Warnings : begin
12735             GNAT_Pragma;
12736             Check_At_Least_N_Arguments (1);
12737             Check_No_Identifiers;
12738
12739             --  If debug flag -gnatd.i is set, pragma is ignored
12740
12741             if Debug_Flag_Dot_I then
12742                return;
12743             end if;
12744
12745             --  Process various forms of the pragma
12746
12747             declare
12748                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12749
12750             begin
12751                --  One argument case
12752
12753                if Arg_Count = 1 then
12754
12755                   --  On/Off one argument case was processed by parser
12756
12757                   if Nkind (Argx) = N_Identifier
12758                     and then
12759                       (Chars (Argx) = Name_On
12760                          or else
12761                        Chars (Argx) = Name_Off)
12762                   then
12763                      null;
12764
12765                   --  One argument case must be ON/OFF or static string expr
12766
12767                   elsif not Is_Static_String_Expression (Arg1) then
12768                      Error_Pragma_Arg
12769                        ("argument of pragma% must be On/Off or " &
12770                         "static string expression", Arg1);
12771
12772                   --  One argument string expression case
12773
12774                   else
12775                      declare
12776                         Lit : constant Node_Id   := Expr_Value_S (Argx);
12777                         Str : constant String_Id := Strval (Lit);
12778                         Len : constant Nat       := String_Length (Str);
12779                         C   : Char_Code;
12780                         J   : Nat;
12781                         OK  : Boolean;
12782                         Chr : Character;
12783
12784                      begin
12785                         J := 1;
12786                         while J <= Len loop
12787                            C := Get_String_Char (Str, J);
12788                            OK := In_Character_Range (C);
12789
12790                            if OK then
12791                               Chr := Get_Character (C);
12792
12793                               --  Dot case
12794
12795                               if J < Len and then Chr = '.' then
12796                                  J := J + 1;
12797                                  C := Get_String_Char (Str, J);
12798                                  Chr := Get_Character (C);
12799
12800                                  if not Set_Dot_Warning_Switch (Chr) then
12801                                     Error_Pragma_Arg
12802                                       ("invalid warning switch character " &
12803                                        '.' & Chr, Arg1);
12804                                  end if;
12805
12806                               --  Non-Dot case
12807
12808                               else
12809                                  OK := Set_Warning_Switch (Chr);
12810                               end if;
12811                            end if;
12812
12813                            if not OK then
12814                               Error_Pragma_Arg
12815                                 ("invalid warning switch character " & Chr,
12816                                  Arg1);
12817                            end if;
12818
12819                            J := J + 1;
12820                         end loop;
12821                      end;
12822                   end if;
12823
12824                   --  Two or more arguments (must be two)
12825
12826                else
12827                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12828                   Check_At_Most_N_Arguments (2);
12829
12830                   declare
12831                      E_Id : Node_Id;
12832                      E    : Entity_Id;
12833                      Err  : Boolean;
12834
12835                   begin
12836                      E_Id := Expression (Arg2);
12837                      Analyze (E_Id);
12838
12839                      --  In the expansion of an inlined body, a reference to
12840                      --  the formal may be wrapped in a conversion if the
12841                      --  actual is a conversion. Retrieve the real entity name.
12842
12843                      if (In_Instance_Body
12844                          or else In_Inlined_Body)
12845                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
12846                      then
12847                         E_Id := Expression (E_Id);
12848                      end if;
12849
12850                      --  Entity name case
12851
12852                      if Is_Entity_Name (E_Id) then
12853                         E := Entity (E_Id);
12854
12855                         if E = Any_Id then
12856                            return;
12857                         else
12858                            loop
12859                               Set_Warnings_Off
12860                                 (E, (Chars (Expression (Arg1)) = Name_Off));
12861
12862                               if Chars (Expression (Arg1)) = Name_Off
12863                                 and then Warn_On_Warnings_Off
12864                               then
12865                                  Warnings_Off_Pragmas.Append ((N, E));
12866                               end if;
12867
12868                               if Is_Enumeration_Type (E) then
12869                                  declare
12870                                     Lit : Entity_Id;
12871                                  begin
12872                                     Lit := First_Literal (E);
12873                                     while Present (Lit) loop
12874                                        Set_Warnings_Off (Lit);
12875                                        Next_Literal (Lit);
12876                                     end loop;
12877                                  end;
12878                               end if;
12879
12880                               exit when No (Homonym (E));
12881                               E := Homonym (E);
12882                            end loop;
12883                         end if;
12884
12885                      --  Error if not entity or static string literal case
12886
12887                      elsif not Is_Static_String_Expression (Arg2) then
12888                         Error_Pragma_Arg
12889                           ("second argument of pragma% must be entity " &
12890                            "name or static string expression", Arg2);
12891
12892                      --  String literal case
12893
12894                      else
12895                         String_To_Name_Buffer
12896                           (Strval (Expr_Value_S (Expression (Arg2))));
12897
12898                         --  Note on configuration pragma case: If this is a
12899                         --  configuration pragma, then for an OFF pragma, we
12900                         --  just set Config True in the call, which is all
12901                         --  that needs to be done. For the case of ON, this
12902                         --  is normally an error, unless it is canceling the
12903                         --  effect of a previous OFF pragma in the same file.
12904                         --  In any other case, an error will be signalled (ON
12905                         --  with no matching OFF).
12906
12907                         if Chars (Argx) = Name_Off then
12908                            Set_Specific_Warning_Off
12909                              (Loc, Name_Buffer (1 .. Name_Len),
12910                               Config => Is_Configuration_Pragma);
12911
12912                         elsif Chars (Argx) = Name_On then
12913                            Set_Specific_Warning_On
12914                              (Loc, Name_Buffer (1 .. Name_Len), Err);
12915
12916                            if Err then
12917                               Error_Msg
12918                                 ("?pragma Warnings On with no " &
12919                                  "matching Warnings Off",
12920                                  Loc);
12921                            end if;
12922                         end if;
12923                      end if;
12924                   end;
12925                end if;
12926             end;
12927          end Warnings;
12928
12929          -------------------
12930          -- Weak_External --
12931          -------------------
12932
12933          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
12934
12935          when Pragma_Weak_External => Weak_External : declare
12936             Ent : Entity_Id;
12937
12938          begin
12939             GNAT_Pragma;
12940             Check_Arg_Count (1);
12941             Check_Optional_Identifier (Arg1, Name_Entity);
12942             Check_Arg_Is_Library_Level_Local_Name (Arg1);
12943             Ent := Entity (Expression (Arg1));
12944
12945             if Rep_Item_Too_Early (Ent, N) then
12946                return;
12947             else
12948                Ent := Underlying_Type (Ent);
12949             end if;
12950
12951             --  The only processing required is to link this item on to the
12952             --  list of rep items for the given entity. This is accomplished
12953             --  by the call to Rep_Item_Too_Late (when no error is detected
12954             --  and False is returned).
12955
12956             if Rep_Item_Too_Late (Ent, N) then
12957                return;
12958             else
12959                Set_Has_Gigi_Rep_Item (Ent);
12960             end if;
12961          end Weak_External;
12962
12963          -----------------------------
12964          -- Wide_Character_Encoding --
12965          -----------------------------
12966
12967          --  pragma Wide_Character_Encoding (IDENTIFIER);
12968
12969          when Pragma_Wide_Character_Encoding =>
12970             GNAT_Pragma;
12971
12972             --  Nothing to do, handled in parser. Note that we do not enforce
12973             --  configuration pragma placement, this pragma can appear at any
12974             --  place in the source, allowing mixed encodings within a single
12975             --  source program.
12976
12977             null;
12978
12979          --------------------
12980          -- Unknown_Pragma --
12981          --------------------
12982
12983          --  Should be impossible, since the case of an unknown pragma is
12984          --  separately processed before the case statement is entered.
12985
12986          when Unknown_Pragma =>
12987             raise Program_Error;
12988       end case;
12989
12990       --  AI05-0144: detect dangerous order dependence. Disabled for now,
12991       --  until AI is formally approved.
12992
12993       --  Check_Order_Dependence;
12994
12995    exception
12996       when Pragma_Exit => null;
12997    end Analyze_Pragma;
12998
12999    -------------------
13000    -- Check_Enabled --
13001    -------------------
13002
13003    function Check_Enabled (Nam : Name_Id) return Boolean is
13004       PP : Node_Id;
13005
13006    begin
13007       PP := Opt.Check_Policy_List;
13008       loop
13009          if No (PP) then
13010             return Assertions_Enabled;
13011
13012          elsif
13013            Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
13014          then
13015             case
13016               Chars (Expression (Last (Pragma_Argument_Associations (PP))))
13017             is
13018             when Name_On | Name_Check =>
13019                return True;
13020             when Name_Off | Name_Ignore =>
13021                return False;
13022             when others =>
13023                raise Program_Error;
13024             end case;
13025
13026          else
13027             PP := Next_Pragma (PP);
13028          end if;
13029       end loop;
13030    end Check_Enabled;
13031
13032    ---------------------------------
13033    -- Delay_Config_Pragma_Analyze --
13034    ---------------------------------
13035
13036    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13037    begin
13038       return Pragma_Name (N) = Name_Interrupt_State
13039                or else
13040              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13041    end Delay_Config_Pragma_Analyze;
13042
13043    -------------------------
13044    -- Get_Base_Subprogram --
13045    -------------------------
13046
13047    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13048       Result : Entity_Id;
13049
13050    begin
13051       --  Follow subprogram renaming chain
13052
13053       Result := Def_Id;
13054       while Is_Subprogram (Result)
13055         and then
13056           (Is_Generic_Instance (Result)
13057             or else Nkind (Parent (Declaration_Node (Result))) =
13058                                          N_Subprogram_Renaming_Declaration)
13059         and then Present (Alias (Result))
13060       loop
13061          Result := Alias (Result);
13062       end loop;
13063
13064       return Result;
13065    end Get_Base_Subprogram;
13066
13067    --------------------
13068    -- Get_Pragma_Arg --
13069    --------------------
13070
13071    function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
13072    begin
13073       if Nkind (Arg) = N_Pragma_Argument_Association then
13074          return Expression (Arg);
13075       else
13076          return Arg;
13077       end if;
13078    end Get_Pragma_Arg;
13079
13080    ----------------
13081    -- Initialize --
13082    ----------------
13083
13084    procedure Initialize is
13085    begin
13086       Externals.Init;
13087    end Initialize;
13088
13089    -----------------------------
13090    -- Is_Config_Static_String --
13091    -----------------------------
13092
13093    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13094
13095       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13096       --  This is an internal recursive function that is just like the outer
13097       --  function except that it adds the string to the name buffer rather
13098       --  than placing the string in the name buffer.
13099
13100       ------------------------------
13101       -- Add_Config_Static_String --
13102       ------------------------------
13103
13104       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13105          N : Node_Id;
13106          C : Char_Code;
13107
13108       begin
13109          N := Arg;
13110
13111          if Nkind (N) = N_Op_Concat then
13112             if Add_Config_Static_String (Left_Opnd (N)) then
13113                N := Right_Opnd (N);
13114             else
13115                return False;
13116             end if;
13117          end if;
13118
13119          if Nkind (N) /= N_String_Literal then
13120             Error_Msg_N ("string literal expected for pragma argument", N);
13121             return False;
13122
13123          else
13124             for J in 1 .. String_Length (Strval (N)) loop
13125                C := Get_String_Char (Strval (N), J);
13126
13127                if not In_Character_Range (C) then
13128                   Error_Msg
13129                     ("string literal contains invalid wide character",
13130                      Sloc (N) + 1 + Source_Ptr (J));
13131                   return False;
13132                end if;
13133
13134                Add_Char_To_Name_Buffer (Get_Character (C));
13135             end loop;
13136          end if;
13137
13138          return True;
13139       end Add_Config_Static_String;
13140
13141    --  Start of processing for Is_Config_Static_String
13142
13143    begin
13144
13145       Name_Len := 0;
13146       return Add_Config_Static_String (Arg);
13147    end Is_Config_Static_String;
13148
13149    -----------------------------------------
13150    -- Is_Non_Significant_Pragma_Reference --
13151    -----------------------------------------
13152
13153    --  This function makes use of the following static table which indicates
13154    --  whether a given pragma is significant.
13155
13156    --  -1  indicates that references in any argument position are significant
13157    --  0   indicates that appearence in any argument is not significant
13158    --  +n  indicates that appearence as argument n is significant, but all
13159    --      other arguments are not significant
13160    --  99  special processing required (e.g. for pragma Check)
13161
13162    Sig_Flags : constant array (Pragma_Id) of Int :=
13163      (Pragma_AST_Entry                     => -1,
13164       Pragma_Abort_Defer                   => -1,
13165       Pragma_Ada_83                        => -1,
13166       Pragma_Ada_95                        => -1,
13167       Pragma_Ada_05                        => -1,
13168       Pragma_Ada_2005                      => -1,
13169       Pragma_Ada_12                        => -1,
13170       Pragma_Ada_2012                      => -1,
13171       Pragma_All_Calls_Remote              => -1,
13172       Pragma_Annotate                      => -1,
13173       Pragma_Assert                        => -1,
13174       Pragma_Assertion_Policy              =>  0,
13175       Pragma_Assume_No_Invalid_Values      =>  0,
13176       Pragma_Asynchronous                  => -1,
13177       Pragma_Atomic                        =>  0,
13178       Pragma_Atomic_Components             =>  0,
13179       Pragma_Attach_Handler                => -1,
13180       Pragma_Check                         => 99,
13181       Pragma_Check_Name                    =>  0,
13182       Pragma_Check_Policy                  =>  0,
13183       Pragma_CIL_Constructor               => -1,
13184       Pragma_CPP_Class                     =>  0,
13185       Pragma_CPP_Constructor               =>  0,
13186       Pragma_CPP_Virtual                   =>  0,
13187       Pragma_CPP_Vtable                    =>  0,
13188       Pragma_C_Pass_By_Copy                =>  0,
13189       Pragma_Comment                       =>  0,
13190       Pragma_Common_Object                 => -1,
13191       Pragma_Compile_Time_Error            => -1,
13192       Pragma_Compile_Time_Warning          => -1,
13193       Pragma_Compiler_Unit                 =>  0,
13194       Pragma_Complete_Representation       =>  0,
13195       Pragma_Complex_Representation        =>  0,
13196       Pragma_Component_Alignment           => -1,
13197       Pragma_Controlled                    =>  0,
13198       Pragma_Convention                    =>  0,
13199       Pragma_Convention_Identifier         =>  0,
13200       Pragma_Debug                         => -1,
13201       Pragma_Debug_Policy                  =>  0,
13202       Pragma_Detect_Blocking               => -1,
13203       Pragma_Dimension                     => -1,
13204       Pragma_Discard_Names                 =>  0,
13205       Pragma_Elaborate                     => -1,
13206       Pragma_Elaborate_All                 => -1,
13207       Pragma_Elaborate_Body                => -1,
13208       Pragma_Elaboration_Checks            => -1,
13209       Pragma_Eliminate                     => -1,
13210       Pragma_Export                        => -1,
13211       Pragma_Export_Exception              => -1,
13212       Pragma_Export_Function               => -1,
13213       Pragma_Export_Object                 => -1,
13214       Pragma_Export_Procedure              => -1,
13215       Pragma_Export_Value                  => -1,
13216       Pragma_Export_Valued_Procedure       => -1,
13217       Pragma_Extend_System                 => -1,
13218       Pragma_Extensions_Allowed            => -1,
13219       Pragma_External                      => -1,
13220       Pragma_Favor_Top_Level               => -1,
13221       Pragma_External_Name_Casing          => -1,
13222       Pragma_Fast_Math                     => -1,
13223       Pragma_Finalize_Storage_Only         =>  0,
13224       Pragma_Float_Representation          =>  0,
13225       Pragma_Ident                         => -1,
13226       Pragma_Implemented                   => -1,
13227       Pragma_Implicit_Packing              =>  0,
13228       Pragma_Import                        => +2,
13229       Pragma_Import_Exception              =>  0,
13230       Pragma_Import_Function               =>  0,
13231       Pragma_Import_Object                 =>  0,
13232       Pragma_Import_Procedure              =>  0,
13233       Pragma_Import_Valued_Procedure       =>  0,
13234       Pragma_Independent                   =>  0,
13235       Pragma_Independent_Components        =>  0,
13236       Pragma_Initialize_Scalars            => -1,
13237       Pragma_Inline                        =>  0,
13238       Pragma_Inline_Always                 =>  0,
13239       Pragma_Inline_Generic                =>  0,
13240       Pragma_Inspection_Point              => -1,
13241       Pragma_Interface                     => +2,
13242       Pragma_Interface_Name                => +2,
13243       Pragma_Interrupt_Handler             => -1,
13244       Pragma_Interrupt_Priority            => -1,
13245       Pragma_Interrupt_State               => -1,
13246       Pragma_Java_Constructor              => -1,
13247       Pragma_Java_Interface                => -1,
13248       Pragma_Keep_Names                    =>  0,
13249       Pragma_License                       => -1,
13250       Pragma_Link_With                     => -1,
13251       Pragma_Linker_Alias                  => -1,
13252       Pragma_Linker_Constructor            => -1,
13253       Pragma_Linker_Destructor             => -1,
13254       Pragma_Linker_Options                => -1,
13255       Pragma_Linker_Section                => -1,
13256       Pragma_List                          => -1,
13257       Pragma_Locking_Policy                => -1,
13258       Pragma_Long_Float                    => -1,
13259       Pragma_Machine_Attribute             => -1,
13260       Pragma_Main                          => -1,
13261       Pragma_Main_Storage                  => -1,
13262       Pragma_Memory_Size                   => -1,
13263       Pragma_No_Return                     =>  0,
13264       Pragma_No_Body                       =>  0,
13265       Pragma_No_Run_Time                   => -1,
13266       Pragma_No_Strict_Aliasing            => -1,
13267       Pragma_Normalize_Scalars             => -1,
13268       Pragma_Obsolescent                   =>  0,
13269       Pragma_Optimize                      => -1,
13270       Pragma_Optimize_Alignment            => -1,
13271       Pragma_Ordered                       =>  0,
13272       Pragma_Pack                          =>  0,
13273       Pragma_Page                          => -1,
13274       Pragma_Passive                       => -1,
13275       Pragma_Preelaborable_Initialization  => -1,
13276       Pragma_Polling                       => -1,
13277       Pragma_Persistent_BSS                =>  0,
13278       Pragma_Postcondition                 => -1,
13279       Pragma_Precondition                  => -1,
13280       Pragma_Preelaborate                  => -1,
13281       Pragma_Preelaborate_05               => -1,
13282       Pragma_Priority                      => -1,
13283       Pragma_Priority_Specific_Dispatching => -1,
13284       Pragma_Profile                       =>  0,
13285       Pragma_Profile_Warnings              =>  0,
13286       Pragma_Propagate_Exceptions          => -1,
13287       Pragma_Psect_Object                  => -1,
13288       Pragma_Pure                          => -1,
13289       Pragma_Pure_05                       => -1,
13290       Pragma_Pure_Function                 => -1,
13291       Pragma_Queuing_Policy                => -1,
13292       Pragma_Ravenscar                     => -1,
13293       Pragma_Relative_Deadline             => -1,
13294       Pragma_Remote_Call_Interface         => -1,
13295       Pragma_Remote_Types                  => -1,
13296       Pragma_Restricted_Run_Time           => -1,
13297       Pragma_Restriction_Warnings          => -1,
13298       Pragma_Restrictions                  => -1,
13299       Pragma_Reviewable                    => -1,
13300       Pragma_Short_Circuit_And_Or          => -1,
13301       Pragma_Share_Generic                 => -1,
13302       Pragma_Shared                        => -1,
13303       Pragma_Shared_Passive                => -1,
13304       Pragma_Short_Descriptors             =>  0,
13305       Pragma_Source_File_Name              => -1,
13306       Pragma_Source_File_Name_Project      => -1,
13307       Pragma_Source_Reference              => -1,
13308       Pragma_Storage_Size                  => -1,
13309       Pragma_Storage_Unit                  => -1,
13310       Pragma_Static_Elaboration_Desired    => -1,
13311       Pragma_Stream_Convert                => -1,
13312       Pragma_Style_Checks                  => -1,
13313       Pragma_Subtitle                      => -1,
13314       Pragma_Suppress                      =>  0,
13315       Pragma_Suppress_Exception_Locations  =>  0,
13316       Pragma_Suppress_All                  => -1,
13317       Pragma_Suppress_Debug_Info           =>  0,
13318       Pragma_Suppress_Initialization       =>  0,
13319       Pragma_System_Name                   => -1,
13320       Pragma_Task_Dispatching_Policy       => -1,
13321       Pragma_Task_Info                     => -1,
13322       Pragma_Task_Name                     => -1,
13323       Pragma_Task_Storage                  =>  0,
13324       Pragma_Thread_Local_Storage          =>  0,
13325       Pragma_Time_Slice                    => -1,
13326       Pragma_Title                         => -1,
13327       Pragma_Unchecked_Union               =>  0,
13328       Pragma_Unimplemented_Unit            => -1,
13329       Pragma_Universal_Aliasing            => -1,
13330       Pragma_Universal_Data                => -1,
13331       Pragma_Unmodified                    => -1,
13332       Pragma_Unreferenced                  => -1,
13333       Pragma_Unreferenced_Objects          => -1,
13334       Pragma_Unreserve_All_Interrupts      => -1,
13335       Pragma_Unsuppress                    =>  0,
13336       Pragma_Use_VADS_Size                 => -1,
13337       Pragma_Validity_Checks               => -1,
13338       Pragma_Volatile                      =>  0,
13339       Pragma_Volatile_Components           =>  0,
13340       Pragma_Warnings                      => -1,
13341       Pragma_Weak_External                 => -1,
13342       Pragma_Wide_Character_Encoding       =>  0,
13343       Unknown_Pragma                       =>  0);
13344
13345    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
13346       Id : Pragma_Id;
13347       P  : Node_Id;
13348       C  : Int;
13349       A  : Node_Id;
13350
13351    begin
13352       P := Parent (N);
13353
13354       if Nkind (P) /= N_Pragma_Argument_Association then
13355          return False;
13356
13357       else
13358          Id := Get_Pragma_Id (Parent (P));
13359          C := Sig_Flags (Id);
13360
13361          case C is
13362             when -1 =>
13363                return False;
13364
13365             when 0 =>
13366                return True;
13367
13368             when 99 =>
13369                case Id is
13370
13371                   --  For pragma Check, the first argument is not significant,
13372                   --  the second and the third (if present) arguments are
13373                   --  significant.
13374
13375                   when Pragma_Check =>
13376                      return
13377                        P = First (Pragma_Argument_Associations (Parent (P)));
13378
13379                   when others =>
13380                      raise Program_Error;
13381                end case;
13382
13383             when others =>
13384                A := First (Pragma_Argument_Associations (Parent (P)));
13385                for J in 1 .. C - 1 loop
13386                   if No (A) then
13387                      return False;
13388                   end if;
13389
13390                   Next (A);
13391                end loop;
13392
13393                return A = P; -- is this wrong way round ???
13394          end case;
13395       end if;
13396    end Is_Non_Significant_Pragma_Reference;
13397
13398    ------------------------------
13399    -- Is_Pragma_String_Literal --
13400    ------------------------------
13401
13402    --  This function returns true if the corresponding pragma argument is a
13403    --  static string expression. These are the only cases in which string
13404    --  literals can appear as pragma arguments. We also allow a string literal
13405    --  as the first argument to pragma Assert (although it will of course
13406    --  always generate a type error).
13407
13408    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
13409       Pragn : constant Node_Id := Parent (Par);
13410       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
13411       Pname : constant Name_Id := Pragma_Name (Pragn);
13412       Argn  : Natural;
13413       N     : Node_Id;
13414
13415    begin
13416       Argn := 1;
13417       N := First (Assoc);
13418       loop
13419          exit when N = Par;
13420          Argn := Argn + 1;
13421          Next (N);
13422       end loop;
13423
13424       if Pname = Name_Assert then
13425          return True;
13426
13427       elsif Pname = Name_Export then
13428          return Argn > 2;
13429
13430       elsif Pname = Name_Ident then
13431          return Argn = 1;
13432
13433       elsif Pname = Name_Import then
13434          return Argn > 2;
13435
13436       elsif Pname = Name_Interface_Name then
13437          return Argn > 1;
13438
13439       elsif Pname = Name_Linker_Alias then
13440          return Argn = 2;
13441
13442       elsif Pname = Name_Linker_Section then
13443          return Argn = 2;
13444
13445       elsif Pname = Name_Machine_Attribute then
13446          return Argn = 2;
13447
13448       elsif Pname = Name_Source_File_Name then
13449          return True;
13450
13451       elsif Pname = Name_Source_Reference then
13452          return Argn = 2;
13453
13454       elsif Pname = Name_Title then
13455          return True;
13456
13457       elsif Pname = Name_Subtitle then
13458          return True;
13459
13460       else
13461          return False;
13462       end if;
13463    end Is_Pragma_String_Literal;
13464
13465    --------------------------------------
13466    -- Process_Compilation_Unit_Pragmas --
13467    --------------------------------------
13468
13469    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
13470    begin
13471       --  A special check for pragma Suppress_All, a very strange DEC pragma,
13472       --  strange because it comes at the end of the unit. If we have a pragma
13473       --  Suppress_All in the Pragmas_After of the current unit, then we insert
13474       --  a pragma Suppress (All_Checks) at the start of the context clause to
13475       --  ensure the correct processing.
13476
13477       declare
13478          PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
13479          P  : Node_Id;
13480
13481       begin
13482          if Present (PA) then
13483             P := First (PA);
13484             while Present (P) loop
13485                if Pragma_Name (P) = Name_Suppress_All then
13486                   Prepend_To (Context_Items (N),
13487                     Make_Pragma (Sloc (P),
13488                       Chars => Name_Suppress,
13489                       Pragma_Argument_Associations => New_List (
13490                         Make_Pragma_Argument_Association (Sloc (P),
13491                           Expression =>
13492                             Make_Identifier (Sloc (P),
13493                               Chars => Name_All_Checks)))));
13494                   exit;
13495                end if;
13496
13497                Next (P);
13498             end loop;
13499          end if;
13500       end;
13501    end Process_Compilation_Unit_Pragmas;
13502
13503    --------
13504    -- rv --
13505    --------
13506
13507    procedure rv is
13508    begin
13509       null;
13510    end rv;
13511
13512    --------------------------------
13513    -- Set_Encoded_Interface_Name --
13514    --------------------------------
13515
13516    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
13517       Str : constant String_Id := Strval (S);
13518       Len : constant Int       := String_Length (Str);
13519       CC  : Char_Code;
13520       C   : Character;
13521       J   : Int;
13522
13523       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
13524
13525       procedure Encode;
13526       --  Stores encoded value of character code CC. The encoding we use an
13527       --  underscore followed by four lower case hex digits.
13528
13529       ------------
13530       -- Encode --
13531       ------------
13532
13533       procedure Encode is
13534       begin
13535          Store_String_Char (Get_Char_Code ('_'));
13536          Store_String_Char
13537            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
13538          Store_String_Char
13539            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
13540          Store_String_Char
13541            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
13542          Store_String_Char
13543            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
13544       end Encode;
13545
13546    --  Start of processing for Set_Encoded_Interface_Name
13547
13548    begin
13549       --  If first character is asterisk, this is a link name, and we leave it
13550       --  completely unmodified. We also ignore null strings (the latter case
13551       --  happens only in error cases) and no encoding should occur for Java or
13552       --  AAMP interface names.
13553
13554       if Len = 0
13555         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
13556         or else VM_Target /= No_VM
13557         or else AAMP_On_Target
13558       then
13559          Set_Interface_Name (E, S);
13560
13561       else
13562          J := 1;
13563          loop
13564             CC := Get_String_Char (Str, J);
13565
13566             exit when not In_Character_Range (CC);
13567
13568             C := Get_Character (CC);
13569
13570             exit when C /= '_' and then C /= '$'
13571               and then C not in '0' .. '9'
13572               and then C not in 'a' .. 'z'
13573               and then C not in 'A' .. 'Z';
13574
13575             if J = Len then
13576                Set_Interface_Name (E, S);
13577                return;
13578
13579             else
13580                J := J + 1;
13581             end if;
13582          end loop;
13583
13584          --  Here we need to encode. The encoding we use as follows:
13585          --     three underscores  + four hex digits (lower case)
13586
13587          Start_String;
13588
13589          for J in 1 .. String_Length (Str) loop
13590             CC := Get_String_Char (Str, J);
13591
13592             if not In_Character_Range (CC) then
13593                Encode;
13594             else
13595                C := Get_Character (CC);
13596
13597                if C = '_' or else C = '$'
13598                  or else C in '0' .. '9'
13599                  or else C in 'a' .. 'z'
13600                  or else C in 'A' .. 'Z'
13601                then
13602                   Store_String_Char (CC);
13603                else
13604                   Encode;
13605                end if;
13606             end if;
13607          end loop;
13608
13609          Set_Interface_Name (E,
13610            Make_String_Literal (Sloc (S),
13611              Strval => End_String));
13612       end if;
13613    end Set_Encoded_Interface_Name;
13614
13615    -------------------
13616    -- Set_Unit_Name --
13617    -------------------
13618
13619    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
13620       Pref : Node_Id;
13621       Scop : Entity_Id;
13622
13623    begin
13624       if Nkind (N) = N_Identifier
13625         and then Nkind (With_Item) = N_Identifier
13626       then
13627          Set_Entity (N, Entity (With_Item));
13628
13629       elsif Nkind (N) = N_Selected_Component then
13630          Change_Selected_Component_To_Expanded_Name (N);
13631          Set_Entity (N, Entity (With_Item));
13632          Set_Entity (Selector_Name (N), Entity (N));
13633
13634          Pref := Prefix (N);
13635          Scop := Scope (Entity (N));
13636          while Nkind (Pref) = N_Selected_Component loop
13637             Change_Selected_Component_To_Expanded_Name (Pref);
13638             Set_Entity (Selector_Name (Pref), Scop);
13639             Set_Entity (Pref, Scop);
13640             Pref := Prefix (Pref);
13641             Scop := Scope (Scop);
13642          end loop;
13643
13644          Set_Entity (Pref, Scop);
13645       end if;
13646    end Set_Unit_Name;
13647
13648 end Sem_Prag;