OSDN Git Service

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