OSDN Git Service

2010-10-18 Jose Ruiz <ruiz@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, CPU).
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          -- CPU --
6966          ---------
6967
6968          --  pragma CPU (EXPRESSION);
6969
6970          when Pragma_CPU => CPU : declare
6971             P   : constant Node_Id := Parent (N);
6972             Arg : Node_Id;
6973
6974          begin
6975             Ada_2012_Pragma;
6976             Check_No_Identifiers;
6977             Check_Arg_Count (1);
6978
6979             --  Subprogram case
6980
6981             if Nkind (P) = N_Subprogram_Body then
6982                Check_In_Main_Program;
6983
6984                Arg := Get_Pragma_Arg (Arg1);
6985                Analyze_And_Resolve (Arg, Any_Integer);
6986
6987                --  Must be static
6988
6989                if not Is_Static_Expression (Arg) then
6990                   Flag_Non_Static_Expr
6991                     ("main subprogram affinity is not static!", Arg);
6992                   raise Pragma_Exit;
6993
6994                --  If constraint error, then we already signalled an error
6995
6996                elsif Raises_Constraint_Error (Arg) then
6997                   null;
6998
6999                --  Otherwise check in range
7000
7001                else
7002                   declare
7003                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7004                      --  This is the entity System.Multiprocessors.CPU_Range;
7005
7006                      Val : constant Uint := Expr_Value (Arg);
7007
7008                   begin
7009                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7010                           or else
7011                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7012                      then
7013                         Error_Pragma_Arg
7014                           ("main subprogram CPU is out of range", Arg1);
7015                      end if;
7016                   end;
7017                end if;
7018
7019                Set_Main_CPU
7020                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7021
7022             --  Task case
7023
7024             elsif Nkind (P) = N_Task_Definition then
7025                Arg := Get_Pragma_Arg (Arg1);
7026
7027                --  The expression must be analyzed in the special manner
7028                --  described in "Handling of Default and Per-Object
7029                --  Expressions" in sem.ads.
7030
7031                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7032
7033             --  Anything else is incorrect
7034
7035             else
7036                Pragma_Misplaced;
7037             end if;
7038
7039             if Has_Pragma_CPU (P) then
7040                Error_Pragma ("duplicate pragma% not allowed");
7041             else
7042                Set_Has_Pragma_CPU (P, True);
7043
7044                if Nkind (P) = N_Task_Definition then
7045                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7046                end if;
7047             end if;
7048          end CPU;
7049
7050          -----------
7051          -- Debug --
7052          -----------
7053
7054          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7055
7056          when Pragma_Debug => Debug : declare
7057                Cond : Node_Id;
7058
7059          begin
7060             GNAT_Pragma;
7061
7062             Cond :=
7063               New_Occurrence_Of
7064                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7065                  Loc);
7066
7067             if Arg_Count = 2 then
7068                Cond :=
7069                  Make_And_Then (Loc,
7070                    Left_Opnd   => Relocate_Node (Cond),
7071                    Right_Opnd  => Get_Pragma_Arg (Arg1));
7072             end if;
7073
7074             --  Rewrite into a conditional with an appropriate condition. We
7075             --  wrap the procedure call in a block so that overhead from e.g.
7076             --  use of the secondary stack does not generate execution overhead
7077             --  for suppressed conditions.
7078
7079             Rewrite (N, Make_Implicit_If_Statement (N,
7080               Condition => Cond,
7081                  Then_Statements => New_List (
7082                    Make_Block_Statement (Loc,
7083                      Handled_Statement_Sequence =>
7084                        Make_Handled_Sequence_Of_Statements (Loc,
7085                          Statements => New_List (
7086                            Relocate_Node (Debug_Statement (N))))))));
7087             Analyze (N);
7088          end Debug;
7089
7090          ------------------
7091          -- Debug_Policy --
7092          ------------------
7093
7094          --  pragma Debug_Policy (Check | Ignore)
7095
7096          when Pragma_Debug_Policy =>
7097             GNAT_Pragma;
7098             Check_Arg_Count (1);
7099             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7100             Debug_Pragmas_Enabled :=
7101               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7102
7103          ---------------------
7104          -- Detect_Blocking --
7105          ---------------------
7106
7107          --  pragma Detect_Blocking;
7108
7109          when Pragma_Detect_Blocking =>
7110             Ada_2005_Pragma;
7111             Check_Arg_Count (0);
7112             Check_Valid_Configuration_Pragma;
7113             Detect_Blocking := True;
7114
7115          ---------------
7116          -- Dimension --
7117          ---------------
7118
7119          when Pragma_Dimension =>
7120             GNAT_Pragma;
7121             Check_Arg_Count (4);
7122             Check_No_Identifiers;
7123             Check_Arg_Is_Local_Name (Arg1);
7124
7125             if not Is_Type (Arg1) then
7126                Error_Pragma ("first argument for pragma% must be subtype");
7127             end if;
7128
7129             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7130             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7131             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7132
7133          -------------------
7134          -- Discard_Names --
7135          -------------------
7136
7137          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
7138
7139          when Pragma_Discard_Names => Discard_Names : declare
7140             E    : Entity_Id;
7141             E_Id : Entity_Id;
7142
7143          begin
7144             Check_Ada_83_Warning;
7145
7146             --  Deal with configuration pragma case
7147
7148             if Arg_Count = 0 and then Is_Configuration_Pragma then
7149                Global_Discard_Names := True;
7150                return;
7151
7152             --  Otherwise, check correct appropriate context
7153
7154             else
7155                Check_Is_In_Decl_Part_Or_Package_Spec;
7156
7157                if Arg_Count = 0 then
7158
7159                   --  If there is no parameter, then from now on this pragma
7160                   --  applies to any enumeration, exception or tagged type
7161                   --  defined in the current declarative part, and recursively
7162                   --  to any nested scope.
7163
7164                   Set_Discard_Names (Current_Scope, Sense);
7165                   return;
7166
7167                else
7168                   Check_Arg_Count (1);
7169                   Check_Optional_Identifier (Arg1, Name_On);
7170                   Check_Arg_Is_Local_Name (Arg1);
7171
7172                   E_Id := Get_Pragma_Arg (Arg1);
7173
7174                   if Etype (E_Id) = Any_Type then
7175                      return;
7176                   else
7177                      E := Entity (E_Id);
7178                   end if;
7179
7180                   if (Is_First_Subtype (E)
7181                       and then
7182                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7183                     or else Ekind (E) = E_Exception
7184                   then
7185                      Set_Discard_Names (E, Sense);
7186                   else
7187                      Error_Pragma_Arg
7188                        ("inappropriate entity for pragma%", Arg1);
7189                   end if;
7190
7191                end if;
7192             end if;
7193          end Discard_Names;
7194
7195          ---------------
7196          -- Elaborate --
7197          ---------------
7198
7199          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7200
7201          when Pragma_Elaborate => Elaborate : declare
7202             Arg   : Node_Id;
7203             Citem : Node_Id;
7204
7205          begin
7206             --  Pragma must be in context items list of a compilation unit
7207
7208             if not Is_In_Context_Clause then
7209                Pragma_Misplaced;
7210             end if;
7211
7212             --  Must be at least one argument
7213
7214             if Arg_Count = 0 then
7215                Error_Pragma ("pragma% requires at least one argument");
7216             end if;
7217
7218             --  In Ada 83 mode, there can be no items following it in the
7219             --  context list except other pragmas and implicit with clauses
7220             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7221             --  placement rule does not apply.
7222
7223             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7224                Citem := Next (N);
7225                while Present (Citem) loop
7226                   if Nkind (Citem) = N_Pragma
7227                     or else (Nkind (Citem) = N_With_Clause
7228                               and then Implicit_With (Citem))
7229                   then
7230                      null;
7231                   else
7232                      Error_Pragma
7233                        ("(Ada 83) pragma% must be at end of context clause");
7234                   end if;
7235
7236                   Next (Citem);
7237                end loop;
7238             end if;
7239
7240             --  Finally, the arguments must all be units mentioned in a with
7241             --  clause in the same context clause. Note we already checked (in
7242             --  Par.Prag) that the arguments are all identifiers or selected
7243             --  components.
7244
7245             Arg := Arg1;
7246             Outer : while Present (Arg) loop
7247                Citem := First (List_Containing (N));
7248                Inner : while Citem /= N loop
7249                   if Nkind (Citem) = N_With_Clause
7250                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7251                   then
7252                      Set_Elaborate_Present (Citem, True);
7253                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7254
7255                      --  With the pragma present, elaboration calls on
7256                      --  subprograms from the named unit need no further
7257                      --  checks, as long as the pragma appears in the current
7258                      --  compilation unit. If the pragma appears in some unit
7259                      --  in the context, there might still be a need for an
7260                      --  Elaborate_All_Desirable from the current compilation
7261                      --  to the named unit, so we keep the check enabled.
7262
7263                      if In_Extended_Main_Source_Unit (N) then
7264                         Set_Suppress_Elaboration_Warnings
7265                           (Entity (Name (Citem)));
7266                      end if;
7267
7268                      exit Inner;
7269                   end if;
7270
7271                   Next (Citem);
7272                end loop Inner;
7273
7274                if Citem = N then
7275                   Error_Pragma_Arg
7276                     ("argument of pragma% is not with'ed unit", Arg);
7277                end if;
7278
7279                Next (Arg);
7280             end loop Outer;
7281
7282             --  Give a warning if operating in static mode with -gnatwl
7283             --  (elaboration warnings enabled) switch set.
7284
7285             if Elab_Warnings and not Dynamic_Elaboration_Checks then
7286                Error_Msg_N
7287                  ("?use of pragma Elaborate may not be safe", N);
7288                Error_Msg_N
7289                  ("?use pragma Elaborate_All instead if possible", N);
7290             end if;
7291          end Elaborate;
7292
7293          -------------------
7294          -- Elaborate_All --
7295          -------------------
7296
7297          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7298
7299          when Pragma_Elaborate_All => Elaborate_All : declare
7300             Arg   : Node_Id;
7301             Citem : Node_Id;
7302
7303          begin
7304             Check_Ada_83_Warning;
7305
7306             --  Pragma must be in context items list of a compilation unit
7307
7308             if not Is_In_Context_Clause then
7309                Pragma_Misplaced;
7310             end if;
7311
7312             --  Must be at least one argument
7313
7314             if Arg_Count = 0 then
7315                Error_Pragma ("pragma% requires at least one argument");
7316             end if;
7317
7318             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
7319             --  have to appear at the end of the context clause, but may
7320             --  appear mixed in with other items, even in Ada 83 mode.
7321
7322             --  Final check: the arguments must all be units mentioned in
7323             --  a with clause in the same context clause. Note that we
7324             --  already checked (in Par.Prag) that all the arguments are
7325             --  either identifiers or selected components.
7326
7327             Arg := Arg1;
7328             Outr : while Present (Arg) loop
7329                Citem := First (List_Containing (N));
7330                Innr : while Citem /= N loop
7331                   if Nkind (Citem) = N_With_Clause
7332                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7333                   then
7334                      Set_Elaborate_All_Present (Citem, True);
7335                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7336
7337                      --  Suppress warnings and elaboration checks on the named
7338                      --  unit if the pragma is in the current compilation, as
7339                      --  for pragma Elaborate.
7340
7341                      if In_Extended_Main_Source_Unit (N) then
7342                         Set_Suppress_Elaboration_Warnings
7343                           (Entity (Name (Citem)));
7344                      end if;
7345                      exit Innr;
7346                   end if;
7347
7348                   Next (Citem);
7349                end loop Innr;
7350
7351                if Citem = N then
7352                   Set_Error_Posted (N);
7353                   Error_Pragma_Arg
7354                     ("argument of pragma% is not with'ed unit", Arg);
7355                end if;
7356
7357                Next (Arg);
7358             end loop Outr;
7359          end Elaborate_All;
7360
7361          --------------------
7362          -- Elaborate_Body --
7363          --------------------
7364
7365          --  pragma Elaborate_Body [( library_unit_NAME )];
7366
7367          when Pragma_Elaborate_Body => Elaborate_Body : declare
7368             Cunit_Node : Node_Id;
7369             Cunit_Ent  : Entity_Id;
7370
7371          begin
7372             Check_Ada_83_Warning;
7373             Check_Valid_Library_Unit_Pragma;
7374
7375             if Nkind (N) = N_Null_Statement then
7376                return;
7377             end if;
7378
7379             Cunit_Node := Cunit (Current_Sem_Unit);
7380             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
7381
7382             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7383                                             N_Subprogram_Body)
7384             then
7385                Error_Pragma ("pragma% must refer to a spec, not a body");
7386             else
7387                Set_Body_Required (Cunit_Node, True);
7388                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7389
7390                --  If we are in dynamic elaboration mode, then we suppress
7391                --  elaboration warnings for the unit, since it is definitely
7392                --  fine NOT to do dynamic checks at the first level (and such
7393                --  checks will be suppressed because no elaboration boolean
7394                --  is created for Elaborate_Body packages).
7395
7396                --  But in the static model of elaboration, Elaborate_Body is
7397                --  definitely NOT good enough to ensure elaboration safety on
7398                --  its own, since the body may WITH other units that are not
7399                --  safe from an elaboration point of view, so a client must
7400                --  still do an Elaborate_All on such units.
7401
7402                --  Debug flag -gnatdD restores the old behavior of 3.13, where
7403                --  Elaborate_Body always suppressed elab warnings.
7404
7405                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7406                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7407                end if;
7408             end if;
7409          end Elaborate_Body;
7410
7411          ------------------------
7412          -- Elaboration_Checks --
7413          ------------------------
7414
7415          --  pragma Elaboration_Checks (Static | Dynamic);
7416
7417          when Pragma_Elaboration_Checks =>
7418             GNAT_Pragma;
7419             Check_Arg_Count (1);
7420             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7421             Dynamic_Elaboration_Checks :=
7422               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7423
7424          ---------------
7425          -- Eliminate --
7426          ---------------
7427
7428          --  pragma Eliminate (
7429          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
7430          --    [,[Entity     =>] IDENTIFIER |
7431          --                      SELECTED_COMPONENT |
7432          --                      STRING_LITERAL]
7433          --    [,                OVERLOADING_RESOLUTION]);
7434
7435          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7436          --                             SOURCE_LOCATION
7437
7438          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7439          --                                        FUNCTION_PROFILE
7440
7441          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7442
7443          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7444          --                       Result_Type => result_SUBTYPE_NAME]
7445
7446          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7447          --  SUBTYPE_NAME    ::= STRING_LITERAL
7448
7449          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7450          --  SOURCE_TRACE    ::= STRING_LITERAL
7451
7452          when Pragma_Eliminate => Eliminate : declare
7453             Args  : Args_List (1 .. 5);
7454             Names : constant Name_List (1 .. 5) := (
7455                       Name_Unit_Name,
7456                       Name_Entity,
7457                       Name_Parameter_Types,
7458                       Name_Result_Type,
7459                       Name_Source_Location);
7460
7461             Unit_Name       : Node_Id renames Args (1);
7462             Entity          : Node_Id renames Args (2);
7463             Parameter_Types : Node_Id renames Args (3);
7464             Result_Type     : Node_Id renames Args (4);
7465             Source_Location : Node_Id renames Args (5);
7466
7467          begin
7468             GNAT_Pragma;
7469             Check_Valid_Configuration_Pragma;
7470             Gather_Associations (Names, Args);
7471
7472             if No (Unit_Name) then
7473                Error_Pragma ("missing Unit_Name argument for pragma%");
7474             end if;
7475
7476             if No (Entity)
7477               and then (Present (Parameter_Types)
7478                           or else
7479                         Present (Result_Type)
7480                           or else
7481                         Present (Source_Location))
7482             then
7483                Error_Pragma ("missing Entity argument for pragma%");
7484             end if;
7485
7486             if (Present (Parameter_Types)
7487                        or else
7488                 Present (Result_Type))
7489               and then
7490                 Present (Source_Location)
7491             then
7492                Error_Pragma
7493                  ("parameter profile and source location cannot " &
7494                   "be used together in pragma%");
7495             end if;
7496
7497             Process_Eliminate_Pragma
7498               (N,
7499                Unit_Name,
7500                Entity,
7501                Parameter_Types,
7502                Result_Type,
7503                Source_Location);
7504          end Eliminate;
7505
7506          ------------
7507          -- Export --
7508          ------------
7509
7510          --  pragma Export (
7511          --    [   Convention    =>] convention_IDENTIFIER,
7512          --    [   Entity        =>] local_NAME
7513          --    [, [External_Name =>] static_string_EXPRESSION ]
7514          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7515
7516          when Pragma_Export => Export : declare
7517             C      : Convention_Id;
7518             Def_Id : Entity_Id;
7519
7520             pragma Warnings (Off, C);
7521
7522          begin
7523             Check_Ada_83_Warning;
7524             Check_Arg_Order
7525               ((Name_Convention,
7526                 Name_Entity,
7527                 Name_External_Name,
7528                 Name_Link_Name));
7529             Check_At_Least_N_Arguments (2);
7530             Check_At_Most_N_Arguments  (4);
7531             Process_Convention (C, Def_Id);
7532
7533             if Ekind (Def_Id) /= E_Constant then
7534                Note_Possible_Modification
7535                  (Get_Pragma_Arg (Arg2), Sure => False);
7536             end if;
7537
7538             Process_Interface_Name (Def_Id, Arg3, Arg4);
7539             Set_Exported (Def_Id, Arg2);
7540
7541             --  If the entity is a deferred constant, propagate the information
7542             --  to the full view, because gigi elaborates the full view only.
7543
7544             if Ekind (Def_Id) = E_Constant
7545               and then Present (Full_View (Def_Id))
7546             then
7547                declare
7548                   Id2 : constant Entity_Id := Full_View (Def_Id);
7549                begin
7550                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
7551                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
7552                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7553                end;
7554             end if;
7555          end Export;
7556
7557          ----------------------
7558          -- Export_Exception --
7559          ----------------------
7560
7561          --  pragma Export_Exception (
7562          --        [Internal         =>] LOCAL_NAME
7563          --     [, [External         =>] EXTERNAL_SYMBOL]
7564          --     [, [Form     =>] Ada | VMS]
7565          --     [, [Code     =>] static_integer_EXPRESSION]);
7566
7567          when Pragma_Export_Exception => Export_Exception : declare
7568             Args  : Args_List (1 .. 4);
7569             Names : constant Name_List (1 .. 4) := (
7570                       Name_Internal,
7571                       Name_External,
7572                       Name_Form,
7573                       Name_Code);
7574
7575             Internal : Node_Id renames Args (1);
7576             External : Node_Id renames Args (2);
7577             Form     : Node_Id renames Args (3);
7578             Code     : Node_Id renames Args (4);
7579
7580          begin
7581             GNAT_Pragma;
7582
7583             if Inside_A_Generic then
7584                Error_Pragma ("pragma% cannot be used for generic entities");
7585             end if;
7586
7587             Gather_Associations (Names, Args);
7588             Process_Extended_Import_Export_Exception_Pragma (
7589               Arg_Internal => Internal,
7590               Arg_External => External,
7591               Arg_Form     => Form,
7592               Arg_Code     => Code);
7593
7594             if not Is_VMS_Exception (Entity (Internal)) then
7595                Set_Exported (Entity (Internal), Internal);
7596             end if;
7597          end Export_Exception;
7598
7599          ---------------------
7600          -- Export_Function --
7601          ---------------------
7602
7603          --  pragma Export_Function (
7604          --        [Internal         =>] LOCAL_NAME
7605          --     [, [External         =>] EXTERNAL_SYMBOL]
7606          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
7607          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
7608          --     [, [Mechanism        =>] MECHANISM]
7609          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
7610
7611          --  EXTERNAL_SYMBOL ::=
7612          --    IDENTIFIER
7613          --  | static_string_EXPRESSION
7614
7615          --  PARAMETER_TYPES ::=
7616          --    null
7617          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7618
7619          --  TYPE_DESIGNATOR ::=
7620          --    subtype_NAME
7621          --  | subtype_Name ' Access
7622
7623          --  MECHANISM ::=
7624          --    MECHANISM_NAME
7625          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7626
7627          --  MECHANISM_ASSOCIATION ::=
7628          --    [formal_parameter_NAME =>] MECHANISM_NAME
7629
7630          --  MECHANISM_NAME ::=
7631          --    Value
7632          --  | Reference
7633          --  | Descriptor [([Class =>] CLASS_NAME)]
7634
7635          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7636
7637          when Pragma_Export_Function => Export_Function : declare
7638             Args  : Args_List (1 .. 6);
7639             Names : constant Name_List (1 .. 6) := (
7640                       Name_Internal,
7641                       Name_External,
7642                       Name_Parameter_Types,
7643                       Name_Result_Type,
7644                       Name_Mechanism,
7645                       Name_Result_Mechanism);
7646
7647             Internal         : Node_Id renames Args (1);
7648             External         : Node_Id renames Args (2);
7649             Parameter_Types  : Node_Id renames Args (3);
7650             Result_Type      : Node_Id renames Args (4);
7651             Mechanism        : Node_Id renames Args (5);
7652             Result_Mechanism : Node_Id renames Args (6);
7653
7654          begin
7655             GNAT_Pragma;
7656             Gather_Associations (Names, Args);
7657             Process_Extended_Import_Export_Subprogram_Pragma (
7658               Arg_Internal         => Internal,
7659               Arg_External         => External,
7660               Arg_Parameter_Types  => Parameter_Types,
7661               Arg_Result_Type      => Result_Type,
7662               Arg_Mechanism        => Mechanism,
7663               Arg_Result_Mechanism => Result_Mechanism);
7664          end Export_Function;
7665
7666          -------------------
7667          -- Export_Object --
7668          -------------------
7669
7670          --  pragma Export_Object (
7671          --        [Internal =>] LOCAL_NAME
7672          --     [, [External =>] EXTERNAL_SYMBOL]
7673          --     [, [Size     =>] EXTERNAL_SYMBOL]);
7674
7675          --  EXTERNAL_SYMBOL ::=
7676          --    IDENTIFIER
7677          --  | static_string_EXPRESSION
7678
7679          --  PARAMETER_TYPES ::=
7680          --    null
7681          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7682
7683          --  TYPE_DESIGNATOR ::=
7684          --    subtype_NAME
7685          --  | subtype_Name ' Access
7686
7687          --  MECHANISM ::=
7688          --    MECHANISM_NAME
7689          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7690
7691          --  MECHANISM_ASSOCIATION ::=
7692          --    [formal_parameter_NAME =>] MECHANISM_NAME
7693
7694          --  MECHANISM_NAME ::=
7695          --    Value
7696          --  | Reference
7697          --  | Descriptor [([Class =>] CLASS_NAME)]
7698
7699          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7700
7701          when Pragma_Export_Object => Export_Object : declare
7702             Args  : Args_List (1 .. 3);
7703             Names : constant Name_List (1 .. 3) := (
7704                       Name_Internal,
7705                       Name_External,
7706                       Name_Size);
7707
7708             Internal : Node_Id renames Args (1);
7709             External : Node_Id renames Args (2);
7710             Size     : Node_Id renames Args (3);
7711
7712          begin
7713             GNAT_Pragma;
7714             Gather_Associations (Names, Args);
7715             Process_Extended_Import_Export_Object_Pragma (
7716               Arg_Internal => Internal,
7717               Arg_External => External,
7718               Arg_Size     => Size);
7719          end Export_Object;
7720
7721          ----------------------
7722          -- Export_Procedure --
7723          ----------------------
7724
7725          --  pragma Export_Procedure (
7726          --        [Internal         =>] LOCAL_NAME
7727          --     [, [External         =>] EXTERNAL_SYMBOL]
7728          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
7729          --     [, [Mechanism        =>] MECHANISM]);
7730
7731          --  EXTERNAL_SYMBOL ::=
7732          --    IDENTIFIER
7733          --  | static_string_EXPRESSION
7734
7735          --  PARAMETER_TYPES ::=
7736          --    null
7737          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7738
7739          --  TYPE_DESIGNATOR ::=
7740          --    subtype_NAME
7741          --  | subtype_Name ' Access
7742
7743          --  MECHANISM ::=
7744          --    MECHANISM_NAME
7745          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7746
7747          --  MECHANISM_ASSOCIATION ::=
7748          --    [formal_parameter_NAME =>] MECHANISM_NAME
7749
7750          --  MECHANISM_NAME ::=
7751          --    Value
7752          --  | Reference
7753          --  | Descriptor [([Class =>] CLASS_NAME)]
7754
7755          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7756
7757          when Pragma_Export_Procedure => Export_Procedure : declare
7758             Args  : Args_List (1 .. 4);
7759             Names : constant Name_List (1 .. 4) := (
7760                       Name_Internal,
7761                       Name_External,
7762                       Name_Parameter_Types,
7763                       Name_Mechanism);
7764
7765             Internal        : Node_Id renames Args (1);
7766             External        : Node_Id renames Args (2);
7767             Parameter_Types : Node_Id renames Args (3);
7768             Mechanism       : Node_Id renames Args (4);
7769
7770          begin
7771             GNAT_Pragma;
7772             Gather_Associations (Names, Args);
7773             Process_Extended_Import_Export_Subprogram_Pragma (
7774               Arg_Internal        => Internal,
7775               Arg_External        => External,
7776               Arg_Parameter_Types => Parameter_Types,
7777               Arg_Mechanism       => Mechanism);
7778          end Export_Procedure;
7779
7780          ------------------
7781          -- Export_Value --
7782          ------------------
7783
7784          --  pragma Export_Value (
7785          --     [Value     =>] static_integer_EXPRESSION,
7786          --     [Link_Name =>] static_string_EXPRESSION);
7787
7788          when Pragma_Export_Value =>
7789             GNAT_Pragma;
7790             Check_Arg_Order ((Name_Value, Name_Link_Name));
7791             Check_Arg_Count (2);
7792
7793             Check_Optional_Identifier (Arg1, Name_Value);
7794             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7795
7796             Check_Optional_Identifier (Arg2, Name_Link_Name);
7797             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7798
7799          -----------------------------
7800          -- Export_Valued_Procedure --
7801          -----------------------------
7802
7803          --  pragma Export_Valued_Procedure (
7804          --        [Internal         =>] LOCAL_NAME
7805          --     [, [External         =>] EXTERNAL_SYMBOL,]
7806          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
7807          --     [, [Mechanism        =>] MECHANISM]);
7808
7809          --  EXTERNAL_SYMBOL ::=
7810          --    IDENTIFIER
7811          --  | static_string_EXPRESSION
7812
7813          --  PARAMETER_TYPES ::=
7814          --    null
7815          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7816
7817          --  TYPE_DESIGNATOR ::=
7818          --    subtype_NAME
7819          --  | subtype_Name ' Access
7820
7821          --  MECHANISM ::=
7822          --    MECHANISM_NAME
7823          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7824
7825          --  MECHANISM_ASSOCIATION ::=
7826          --    [formal_parameter_NAME =>] MECHANISM_NAME
7827
7828          --  MECHANISM_NAME ::=
7829          --    Value
7830          --  | Reference
7831          --  | Descriptor [([Class =>] CLASS_NAME)]
7832
7833          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7834
7835          when Pragma_Export_Valued_Procedure =>
7836          Export_Valued_Procedure : declare
7837             Args  : Args_List (1 .. 4);
7838             Names : constant Name_List (1 .. 4) := (
7839                       Name_Internal,
7840                       Name_External,
7841                       Name_Parameter_Types,
7842                       Name_Mechanism);
7843
7844             Internal        : Node_Id renames Args (1);
7845             External        : Node_Id renames Args (2);
7846             Parameter_Types : Node_Id renames Args (3);
7847             Mechanism       : Node_Id renames Args (4);
7848
7849          begin
7850             GNAT_Pragma;
7851             Gather_Associations (Names, Args);
7852             Process_Extended_Import_Export_Subprogram_Pragma (
7853               Arg_Internal        => Internal,
7854               Arg_External        => External,
7855               Arg_Parameter_Types => Parameter_Types,
7856               Arg_Mechanism       => Mechanism);
7857          end Export_Valued_Procedure;
7858
7859          -------------------
7860          -- Extend_System --
7861          -------------------
7862
7863          --  pragma Extend_System ([Name =>] Identifier);
7864
7865          when Pragma_Extend_System => Extend_System : declare
7866          begin
7867             GNAT_Pragma;
7868             Check_Valid_Configuration_Pragma;
7869             Check_Arg_Count (1);
7870             Check_Optional_Identifier (Arg1, Name_Name);
7871             Check_Arg_Is_Identifier (Arg1);
7872
7873             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
7874
7875             if Name_Len > 4
7876               and then Name_Buffer (1 .. 4) = "aux_"
7877             then
7878                if Present (System_Extend_Pragma_Arg) then
7879                   if Chars (Get_Pragma_Arg (Arg1)) =
7880                      Chars (Expression (System_Extend_Pragma_Arg))
7881                   then
7882                      null;
7883                   else
7884                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7885                      Error_Pragma ("pragma% conflicts with that #");
7886                   end if;
7887
7888                else
7889                   System_Extend_Pragma_Arg := Arg1;
7890
7891                   if not GNAT_Mode then
7892                      System_Extend_Unit := Arg1;
7893                   end if;
7894                end if;
7895             else
7896                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7897             end if;
7898          end Extend_System;
7899
7900          ------------------------
7901          -- Extensions_Allowed --
7902          ------------------------
7903
7904          --  pragma Extensions_Allowed (ON | OFF);
7905
7906          when Pragma_Extensions_Allowed =>
7907             GNAT_Pragma;
7908             Check_Arg_Count (1);
7909             Check_No_Identifiers;
7910             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7911
7912             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
7913                Extensions_Allowed := True;
7914                Ada_Version := Ada_Version_Type'Last;
7915
7916             else
7917                Extensions_Allowed := False;
7918                Ada_Version := Ada_Version_Explicit;
7919             end if;
7920
7921          --------------
7922          -- External --
7923          --------------
7924
7925          --  pragma External (
7926          --    [   Convention    =>] convention_IDENTIFIER,
7927          --    [   Entity        =>] local_NAME
7928          --    [, [External_Name =>] static_string_EXPRESSION ]
7929          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7930
7931          when Pragma_External => External : declare
7932                Def_Id : Entity_Id;
7933
7934                C : Convention_Id;
7935                pragma Warnings (Off, C);
7936
7937          begin
7938             GNAT_Pragma;
7939             Check_Arg_Order
7940               ((Name_Convention,
7941                 Name_Entity,
7942                 Name_External_Name,
7943                 Name_Link_Name));
7944             Check_At_Least_N_Arguments (2);
7945             Check_At_Most_N_Arguments  (4);
7946             Process_Convention (C, Def_Id);
7947             Note_Possible_Modification
7948               (Get_Pragma_Arg (Arg2), Sure => False);
7949             Process_Interface_Name (Def_Id, Arg3, Arg4);
7950             Set_Exported (Def_Id, Arg2);
7951          end External;
7952
7953          --------------------------
7954          -- External_Name_Casing --
7955          --------------------------
7956
7957          --  pragma External_Name_Casing (
7958          --    UPPERCASE | LOWERCASE
7959          --    [, AS_IS | UPPERCASE | LOWERCASE]);
7960
7961          when Pragma_External_Name_Casing => External_Name_Casing : declare
7962          begin
7963             GNAT_Pragma;
7964             Check_No_Identifiers;
7965
7966             if Arg_Count = 2 then
7967                Check_Arg_Is_One_Of
7968                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7969
7970                case Chars (Get_Pragma_Arg (Arg2)) is
7971                   when Name_As_Is     =>
7972                      Opt.External_Name_Exp_Casing := As_Is;
7973
7974                   when Name_Uppercase =>
7975                      Opt.External_Name_Exp_Casing := Uppercase;
7976
7977                   when Name_Lowercase =>
7978                      Opt.External_Name_Exp_Casing := Lowercase;
7979
7980                   when others =>
7981                      null;
7982                end case;
7983
7984             else
7985                Check_Arg_Count (1);
7986             end if;
7987
7988             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7989
7990             case Chars (Get_Pragma_Arg (Arg1)) is
7991                when Name_Uppercase =>
7992                   Opt.External_Name_Imp_Casing := Uppercase;
7993
7994                when Name_Lowercase =>
7995                   Opt.External_Name_Imp_Casing := Lowercase;
7996
7997                when others =>
7998                   null;
7999             end case;
8000          end External_Name_Casing;
8001
8002          --------------------------
8003          -- Favor_Top_Level --
8004          --------------------------
8005
8006          --  pragma Favor_Top_Level (type_NAME);
8007
8008          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8009                Named_Entity : Entity_Id;
8010
8011          begin
8012             GNAT_Pragma;
8013             Check_No_Identifiers;
8014             Check_Arg_Count (1);
8015             Check_Arg_Is_Local_Name (Arg1);
8016             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8017
8018             --  If it's an access-to-subprogram type (in particular, not a
8019             --  subtype), set the flag on that type.
8020
8021             if Is_Access_Subprogram_Type (Named_Entity) then
8022                if Sense then
8023                   Set_Can_Use_Internal_Rep (Named_Entity, False);
8024                end if;
8025
8026             --  Otherwise it's an error (name denotes the wrong sort of entity)
8027
8028             else
8029                Error_Pragma_Arg
8030                  ("access-to-subprogram type expected",
8031                   Get_Pragma_Arg (Arg1));
8032             end if;
8033          end Favor_Top_Level;
8034
8035          ---------------
8036          -- Fast_Math --
8037          ---------------
8038
8039          --  pragma Fast_Math;
8040
8041          when Pragma_Fast_Math =>
8042             GNAT_Pragma;
8043             Check_No_Identifiers;
8044             Check_Valid_Configuration_Pragma;
8045             Fast_Math := True;
8046
8047          ---------------------------
8048          -- Finalize_Storage_Only --
8049          ---------------------------
8050
8051          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8052
8053          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8054             Assoc   : constant Node_Id := Arg1;
8055             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8056             Typ     : Entity_Id;
8057
8058          begin
8059             GNAT_Pragma;
8060             Check_No_Identifiers;
8061             Check_Arg_Count (1);
8062             Check_Arg_Is_Local_Name (Arg1);
8063
8064             Find_Type (Type_Id);
8065             Typ := Entity (Type_Id);
8066
8067             if Typ = Any_Type
8068               or else Rep_Item_Too_Early (Typ, N)
8069             then
8070                return;
8071             else
8072                Typ := Underlying_Type (Typ);
8073             end if;
8074
8075             if not Is_Controlled (Typ) then
8076                Error_Pragma ("pragma% must specify controlled type");
8077             end if;
8078
8079             Check_First_Subtype (Arg1);
8080
8081             if Finalize_Storage_Only (Typ) then
8082                Error_Pragma ("duplicate pragma%, only one allowed");
8083
8084             elsif not Rep_Item_Too_Late (Typ, N) then
8085                Set_Finalize_Storage_Only (Base_Type (Typ), True);
8086             end if;
8087          end Finalize_Storage;
8088
8089          --------------------------
8090          -- Float_Representation --
8091          --------------------------
8092
8093          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8094
8095          --  FLOAT_REP ::= VAX_Float | IEEE_Float
8096
8097          when Pragma_Float_Representation => Float_Representation : declare
8098             Argx : Node_Id;
8099             Digs : Nat;
8100             Ent  : Entity_Id;
8101
8102          begin
8103             GNAT_Pragma;
8104
8105             if Arg_Count = 1 then
8106                Check_Valid_Configuration_Pragma;
8107             else
8108                Check_Arg_Count (2);
8109                Check_Optional_Identifier (Arg2, Name_Entity);
8110                Check_Arg_Is_Local_Name (Arg2);
8111             end if;
8112
8113             Check_No_Identifier (Arg1);
8114             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8115
8116             if not OpenVMS_On_Target then
8117                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8118                   Error_Pragma
8119                     ("?pragma% ignored (applies only to Open'V'M'S)");
8120                end if;
8121
8122                return;
8123             end if;
8124
8125             --  One argument case
8126
8127             if Arg_Count = 1 then
8128                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8129                   if Opt.Float_Format = 'I' then
8130                      Error_Pragma ("'I'E'E'E format previously specified");
8131                   end if;
8132
8133                   Opt.Float_Format := 'V';
8134
8135                else
8136                   if Opt.Float_Format = 'V' then
8137                      Error_Pragma ("'V'A'X format previously specified");
8138                   end if;
8139
8140                   Opt.Float_Format := 'I';
8141                end if;
8142
8143                Set_Standard_Fpt_Formats;
8144
8145             --  Two argument case
8146
8147             else
8148                Argx := Get_Pragma_Arg (Arg2);
8149
8150                if not Is_Entity_Name (Argx)
8151                  or else not Is_Floating_Point_Type (Entity (Argx))
8152                then
8153                   Error_Pragma_Arg
8154                     ("second argument of% pragma must be floating-point type",
8155                      Arg2);
8156                end if;
8157
8158                Ent  := Entity (Argx);
8159                Digs := UI_To_Int (Digits_Value (Ent));
8160
8161                --  Two arguments, VAX_Float case
8162
8163                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8164                   case Digs is
8165                      when  6 => Set_F_Float (Ent);
8166                      when  9 => Set_D_Float (Ent);
8167                      when 15 => Set_G_Float (Ent);
8168
8169                      when others =>
8170                         Error_Pragma_Arg
8171                           ("wrong digits value, must be 6,9 or 15", Arg2);
8172                   end case;
8173
8174                --  Two arguments, IEEE_Float case
8175
8176                else
8177                   case Digs is
8178                      when  6 => Set_IEEE_Short (Ent);
8179                      when 15 => Set_IEEE_Long  (Ent);
8180
8181                      when others =>
8182                         Error_Pragma_Arg
8183                           ("wrong digits value, must be 6 or 15", Arg2);
8184                   end case;
8185                end if;
8186             end if;
8187          end Float_Representation;
8188
8189          -----------
8190          -- Ident --
8191          -----------
8192
8193          --  pragma Ident (static_string_EXPRESSION)
8194
8195          --  Note: pragma Comment shares this processing. Pragma Comment is
8196          --  identical to Ident, except that the restriction of the argument to
8197          --  31 characters and the placement restrictions are not enforced for
8198          --  pragma Comment.
8199
8200          when Pragma_Ident | Pragma_Comment => Ident : declare
8201             Str : Node_Id;
8202
8203          begin
8204             GNAT_Pragma;
8205             Check_Arg_Count (1);
8206             Check_No_Identifiers;
8207             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8208             Store_Note (N);
8209
8210             --  For pragma Ident, preserve DEC compatibility by requiring the
8211             --  pragma to appear in a declarative part or package spec.
8212
8213             if Prag_Id = Pragma_Ident then
8214                Check_Is_In_Decl_Part_Or_Package_Spec;
8215             end if;
8216
8217             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8218
8219             declare
8220                CS : Node_Id;
8221                GP : Node_Id;
8222
8223             begin
8224                GP := Parent (Parent (N));
8225
8226                if Nkind_In (GP, N_Package_Declaration,
8227                                 N_Generic_Package_Declaration)
8228                then
8229                   GP := Parent (GP);
8230                end if;
8231
8232                --  If we have a compilation unit, then record the ident value,
8233                --  checking for improper duplication.
8234
8235                if Nkind (GP) = N_Compilation_Unit then
8236                   CS := Ident_String (Current_Sem_Unit);
8237
8238                   if Present (CS) then
8239
8240                      --  For Ident, we do not permit multiple instances
8241
8242                      if Prag_Id = Pragma_Ident then
8243                         Error_Pragma ("duplicate% pragma not permitted");
8244
8245                      --  For Comment, we concatenate the string, unless we want
8246                      --  to preserve the tree structure for ASIS.
8247
8248                      elsif not ASIS_Mode then
8249                         Start_String (Strval (CS));
8250                         Store_String_Char (' ');
8251                         Store_String_Chars (Strval (Str));
8252                         Set_Strval (CS, End_String);
8253                      end if;
8254
8255                   else
8256                      --  In VMS, the effect of IDENT is achieved by passing
8257                      --  --identification=name as a --for-linker switch.
8258
8259                      if OpenVMS_On_Target then
8260                         Start_String;
8261                         Store_String_Chars
8262                           ("--for-linker=--identification=");
8263                         String_To_Name_Buffer (Strval (Str));
8264                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
8265
8266                         --  Only the last processed IDENT is saved. The main
8267                         --  purpose is so an IDENT associated with a main
8268                         --  procedure will be used in preference to an IDENT
8269                         --  associated with a with'd package.
8270
8271                         Replace_Linker_Option_String
8272                           (End_String, "--for-linker=--identification=");
8273                      end if;
8274
8275                      Set_Ident_String (Current_Sem_Unit, Str);
8276                   end if;
8277
8278                --  For subunits, we just ignore the Ident, since in GNAT these
8279                --  are not separate object files, and hence not separate units
8280                --  in the unit table.
8281
8282                elsif Nkind (GP) = N_Subunit then
8283                   null;
8284
8285                --  Otherwise we have a misplaced pragma Ident, but we ignore
8286                --  this if we are in an instantiation, since it comes from
8287                --  a generic, and has no relevance to the instantiation.
8288
8289                elsif Prag_Id = Pragma_Ident then
8290                   if Instantiation_Location (Loc) = No_Location then
8291                      Error_Pragma ("pragma% only allowed at outer level");
8292                   end if;
8293                end if;
8294             end;
8295          end Ident;
8296
8297          -----------------
8298          -- Implemented --
8299          -----------------
8300
8301          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8302          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8303
8304          when Pragma_Implemented => Implemented : declare
8305             Proc_Id : Entity_Id;
8306             Typ     : Entity_Id;
8307
8308          begin
8309             Ada_2012_Pragma;
8310             Check_Arg_Count (2);
8311             Check_No_Identifiers;
8312             Check_Arg_Is_Identifier (Arg1);
8313             Check_Arg_Is_Local_Name (Arg1);
8314             Check_Arg_Is_One_Of
8315               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8316
8317             --  Extract the name of the local procedure
8318
8319             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8320
8321             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8322             --  primitive procedure of a synchronized tagged type.
8323
8324             if Ekind (Proc_Id) = E_Procedure
8325               and then Is_Primitive (Proc_Id)
8326               and then Present (First_Formal (Proc_Id))
8327             then
8328                Typ := Etype (First_Formal (Proc_Id));
8329
8330                if Is_Tagged_Type (Typ)
8331                  and then
8332
8333                   --  Check for a protected, a synchronized or a task interface
8334
8335                    ((Is_Interface (Typ)
8336                        and then Is_Synchronized_Interface (Typ))
8337
8338                   --  Check for a protected type or a task type that implements
8339                   --  an interface.
8340
8341                    or else
8342                     (Is_Concurrent_Record_Type (Typ)
8343                        and then Present (Interfaces (Typ)))
8344
8345                   --  Check for a private record extension with keyword
8346                   --  "synchronized".
8347
8348                    or else
8349                     (Ekind_In (Typ, E_Record_Type_With_Private,
8350                                     E_Record_Subtype_With_Private)
8351                        and then Synchronized_Present (Parent (Typ))))
8352                then
8353                   null;
8354                else
8355                   Error_Pragma_Arg
8356                     ("controlling formal must be of synchronized " &
8357                      "tagged type", Arg1);
8358                   return;
8359                end if;
8360
8361             --  Procedures declared inside a protected type must be accepted
8362
8363             elsif Ekind (Proc_Id) = E_Procedure
8364               and then Is_Protected_Type (Scope (Proc_Id))
8365             then
8366                null;
8367
8368             --  The first argument is not a primitive procedure
8369
8370             else
8371                Error_Pragma_Arg
8372                  ("pragma % must be applied to a primitive procedure", Arg1);
8373                return;
8374             end if;
8375
8376             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8377             --  By_Protected_Procedure to the primitive procedure of a task
8378             --  interface.
8379
8380             if Chars (Arg2) = Name_By_Protected_Procedure
8381               and then Is_Interface (Typ)
8382               and then Is_Task_Interface (Typ)
8383             then
8384                Error_Pragma_Arg
8385                  ("implementation kind By_Protected_Procedure cannot be " &
8386                   "applied to a task interface primitive", Arg2);
8387                return;
8388             end if;
8389
8390             Record_Rep_Item (Proc_Id, N);
8391          end Implemented;
8392
8393          ----------------------
8394          -- Implicit_Packing --
8395          ----------------------
8396
8397          --  pragma Implicit_Packing;
8398
8399          when Pragma_Implicit_Packing =>
8400             GNAT_Pragma;
8401             Check_Arg_Count (0);
8402             Implicit_Packing := True;
8403
8404          ------------
8405          -- Import --
8406          ------------
8407
8408          --  pragma Import (
8409          --       [Convention    =>] convention_IDENTIFIER,
8410          --       [Entity        =>] local_NAME
8411          --    [, [External_Name =>] static_string_EXPRESSION ]
8412          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8413
8414          when Pragma_Import =>
8415             Check_Ada_83_Warning;
8416             Check_Arg_Order
8417               ((Name_Convention,
8418                 Name_Entity,
8419                 Name_External_Name,
8420                 Name_Link_Name));
8421             Check_At_Least_N_Arguments (2);
8422             Check_At_Most_N_Arguments  (4);
8423             Process_Import_Or_Interface;
8424
8425          ----------------------
8426          -- Import_Exception --
8427          ----------------------
8428
8429          --  pragma Import_Exception (
8430          --        [Internal         =>] LOCAL_NAME
8431          --     [, [External         =>] EXTERNAL_SYMBOL]
8432          --     [, [Form     =>] Ada | VMS]
8433          --     [, [Code     =>] static_integer_EXPRESSION]);
8434
8435          when Pragma_Import_Exception => Import_Exception : declare
8436             Args  : Args_List (1 .. 4);
8437             Names : constant Name_List (1 .. 4) := (
8438                       Name_Internal,
8439                       Name_External,
8440                       Name_Form,
8441                       Name_Code);
8442
8443             Internal : Node_Id renames Args (1);
8444             External : Node_Id renames Args (2);
8445             Form     : Node_Id renames Args (3);
8446             Code     : Node_Id renames Args (4);
8447
8448          begin
8449             GNAT_Pragma;
8450             Gather_Associations (Names, Args);
8451
8452             if Present (External) and then Present (Code) then
8453                Error_Pragma
8454                  ("cannot give both External and Code options for pragma%");
8455             end if;
8456
8457             Process_Extended_Import_Export_Exception_Pragma (
8458               Arg_Internal => Internal,
8459               Arg_External => External,
8460               Arg_Form     => Form,
8461               Arg_Code     => Code);
8462
8463             if not Is_VMS_Exception (Entity (Internal)) then
8464                Set_Imported (Entity (Internal));
8465             end if;
8466          end Import_Exception;
8467
8468          ---------------------
8469          -- Import_Function --
8470          ---------------------
8471
8472          --  pragma Import_Function (
8473          --        [Internal                 =>] LOCAL_NAME,
8474          --     [, [External                 =>] EXTERNAL_SYMBOL]
8475          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
8476          --     [, [Result_Type              =>] SUBTYPE_MARK]
8477          --     [, [Mechanism                =>] MECHANISM]
8478          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
8479          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
8480
8481          --  EXTERNAL_SYMBOL ::=
8482          --    IDENTIFIER
8483          --  | static_string_EXPRESSION
8484
8485          --  PARAMETER_TYPES ::=
8486          --    null
8487          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8488
8489          --  TYPE_DESIGNATOR ::=
8490          --    subtype_NAME
8491          --  | subtype_Name ' Access
8492
8493          --  MECHANISM ::=
8494          --    MECHANISM_NAME
8495          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8496
8497          --  MECHANISM_ASSOCIATION ::=
8498          --    [formal_parameter_NAME =>] MECHANISM_NAME
8499
8500          --  MECHANISM_NAME ::=
8501          --    Value
8502          --  | Reference
8503          --  | Descriptor [([Class =>] CLASS_NAME)]
8504
8505          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8506
8507          when Pragma_Import_Function => Import_Function : declare
8508             Args  : Args_List (1 .. 7);
8509             Names : constant Name_List (1 .. 7) := (
8510                       Name_Internal,
8511                       Name_External,
8512                       Name_Parameter_Types,
8513                       Name_Result_Type,
8514                       Name_Mechanism,
8515                       Name_Result_Mechanism,
8516                       Name_First_Optional_Parameter);
8517
8518             Internal                 : Node_Id renames Args (1);
8519             External                 : Node_Id renames Args (2);
8520             Parameter_Types          : Node_Id renames Args (3);
8521             Result_Type              : Node_Id renames Args (4);
8522             Mechanism                : Node_Id renames Args (5);
8523             Result_Mechanism         : Node_Id renames Args (6);
8524             First_Optional_Parameter : Node_Id renames Args (7);
8525
8526          begin
8527             GNAT_Pragma;
8528             Gather_Associations (Names, Args);
8529             Process_Extended_Import_Export_Subprogram_Pragma (
8530               Arg_Internal                 => Internal,
8531               Arg_External                 => External,
8532               Arg_Parameter_Types          => Parameter_Types,
8533               Arg_Result_Type              => Result_Type,
8534               Arg_Mechanism                => Mechanism,
8535               Arg_Result_Mechanism         => Result_Mechanism,
8536               Arg_First_Optional_Parameter => First_Optional_Parameter);
8537          end Import_Function;
8538
8539          -------------------
8540          -- Import_Object --
8541          -------------------
8542
8543          --  pragma Import_Object (
8544          --        [Internal =>] LOCAL_NAME
8545          --     [, [External =>] EXTERNAL_SYMBOL]
8546          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8547
8548          --  EXTERNAL_SYMBOL ::=
8549          --    IDENTIFIER
8550          --  | static_string_EXPRESSION
8551
8552          when Pragma_Import_Object => Import_Object : declare
8553             Args  : Args_List (1 .. 3);
8554             Names : constant Name_List (1 .. 3) := (
8555                       Name_Internal,
8556                       Name_External,
8557                       Name_Size);
8558
8559             Internal : Node_Id renames Args (1);
8560             External : Node_Id renames Args (2);
8561             Size     : Node_Id renames Args (3);
8562
8563          begin
8564             GNAT_Pragma;
8565             Gather_Associations (Names, Args);
8566             Process_Extended_Import_Export_Object_Pragma (
8567               Arg_Internal => Internal,
8568               Arg_External => External,
8569               Arg_Size     => Size);
8570          end Import_Object;
8571
8572          ----------------------
8573          -- Import_Procedure --
8574          ----------------------
8575
8576          --  pragma Import_Procedure (
8577          --        [Internal                 =>] LOCAL_NAME
8578          --     [, [External                 =>] EXTERNAL_SYMBOL]
8579          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
8580          --     [, [Mechanism                =>] MECHANISM]
8581          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
8582
8583          --  EXTERNAL_SYMBOL ::=
8584          --    IDENTIFIER
8585          --  | static_string_EXPRESSION
8586
8587          --  PARAMETER_TYPES ::=
8588          --    null
8589          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8590
8591          --  TYPE_DESIGNATOR ::=
8592          --    subtype_NAME
8593          --  | subtype_Name ' Access
8594
8595          --  MECHANISM ::=
8596          --    MECHANISM_NAME
8597          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8598
8599          --  MECHANISM_ASSOCIATION ::=
8600          --    [formal_parameter_NAME =>] MECHANISM_NAME
8601
8602          --  MECHANISM_NAME ::=
8603          --    Value
8604          --  | Reference
8605          --  | Descriptor [([Class =>] CLASS_NAME)]
8606
8607          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8608
8609          when Pragma_Import_Procedure => Import_Procedure : declare
8610             Args  : Args_List (1 .. 5);
8611             Names : constant Name_List (1 .. 5) := (
8612                       Name_Internal,
8613                       Name_External,
8614                       Name_Parameter_Types,
8615                       Name_Mechanism,
8616                       Name_First_Optional_Parameter);
8617
8618             Internal                 : Node_Id renames Args (1);
8619             External                 : Node_Id renames Args (2);
8620             Parameter_Types          : Node_Id renames Args (3);
8621             Mechanism                : Node_Id renames Args (4);
8622             First_Optional_Parameter : Node_Id renames Args (5);
8623
8624          begin
8625             GNAT_Pragma;
8626             Gather_Associations (Names, Args);
8627             Process_Extended_Import_Export_Subprogram_Pragma (
8628               Arg_Internal                 => Internal,
8629               Arg_External                 => External,
8630               Arg_Parameter_Types          => Parameter_Types,
8631               Arg_Mechanism                => Mechanism,
8632               Arg_First_Optional_Parameter => First_Optional_Parameter);
8633          end Import_Procedure;
8634
8635          -----------------------------
8636          -- Import_Valued_Procedure --
8637          -----------------------------
8638
8639          --  pragma Import_Valued_Procedure (
8640          --        [Internal                 =>] LOCAL_NAME
8641          --     [, [External                 =>] EXTERNAL_SYMBOL]
8642          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
8643          --     [, [Mechanism                =>] MECHANISM]
8644          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
8645
8646          --  EXTERNAL_SYMBOL ::=
8647          --    IDENTIFIER
8648          --  | static_string_EXPRESSION
8649
8650          --  PARAMETER_TYPES ::=
8651          --    null
8652          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8653
8654          --  TYPE_DESIGNATOR ::=
8655          --    subtype_NAME
8656          --  | subtype_Name ' Access
8657
8658          --  MECHANISM ::=
8659          --    MECHANISM_NAME
8660          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8661
8662          --  MECHANISM_ASSOCIATION ::=
8663          --    [formal_parameter_NAME =>] MECHANISM_NAME
8664
8665          --  MECHANISM_NAME ::=
8666          --    Value
8667          --  | Reference
8668          --  | Descriptor [([Class =>] CLASS_NAME)]
8669
8670          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8671
8672          when Pragma_Import_Valued_Procedure =>
8673          Import_Valued_Procedure : declare
8674             Args  : Args_List (1 .. 5);
8675             Names : constant Name_List (1 .. 5) := (
8676                       Name_Internal,
8677                       Name_External,
8678                       Name_Parameter_Types,
8679                       Name_Mechanism,
8680                       Name_First_Optional_Parameter);
8681
8682             Internal                 : Node_Id renames Args (1);
8683             External                 : Node_Id renames Args (2);
8684             Parameter_Types          : Node_Id renames Args (3);
8685             Mechanism                : Node_Id renames Args (4);
8686             First_Optional_Parameter : Node_Id renames Args (5);
8687
8688          begin
8689             GNAT_Pragma;
8690             Gather_Associations (Names, Args);
8691             Process_Extended_Import_Export_Subprogram_Pragma (
8692               Arg_Internal                 => Internal,
8693               Arg_External                 => External,
8694               Arg_Parameter_Types          => Parameter_Types,
8695               Arg_Mechanism                => Mechanism,
8696               Arg_First_Optional_Parameter => First_Optional_Parameter);
8697          end Import_Valued_Procedure;
8698
8699          -----------------
8700          -- Independent --
8701          -----------------
8702
8703          --  pragma Independent (LOCAL_NAME);
8704
8705          when Pragma_Independent => Independent : declare
8706             E_Id : Node_Id;
8707             E    : Entity_Id;
8708             D    : Node_Id;
8709             K    : Node_Kind;
8710
8711          begin
8712             Check_Ada_83_Warning;
8713             Ada_2012_Pragma;
8714             Check_No_Identifiers;
8715             Check_Arg_Count (1);
8716             Check_Arg_Is_Local_Name (Arg1);
8717             E_Id := Get_Pragma_Arg (Arg1);
8718
8719             if Etype (E_Id) = Any_Type then
8720                return;
8721             end if;
8722
8723             E := Entity (E_Id);
8724             D := Declaration_Node (E);
8725             K := Nkind (D);
8726
8727             --  Check duplicate before we chain ourselves!
8728
8729             Check_Duplicate_Pragma (E);
8730
8731             --  Check appropriate entity
8732
8733             if Is_Type (E) then
8734                if Rep_Item_Too_Early (E, N)
8735                     or else
8736                   Rep_Item_Too_Late (E, N)
8737                then
8738                   return;
8739                else
8740                   Check_First_Subtype (Arg1);
8741                end if;
8742
8743             elsif K = N_Object_Declaration
8744               or else (K = N_Component_Declaration
8745                        and then Original_Record_Component (E) = E)
8746             then
8747                if Rep_Item_Too_Late (E, N) then
8748                   return;
8749                end if;
8750
8751             else
8752                Error_Pragma_Arg
8753                  ("inappropriate entity for pragma%", Arg1);
8754             end if;
8755
8756             Independence_Checks.Append ((N, E));
8757          end Independent;
8758
8759          ----------------------------
8760          -- Independent_Components --
8761          ----------------------------
8762
8763          --  pragma Atomic_Components (array_LOCAL_NAME);
8764
8765          --  This processing is shared by Volatile_Components
8766
8767          when Pragma_Independent_Components => Independent_Components : declare
8768             E_Id : Node_Id;
8769             E    : Entity_Id;
8770             D    : Node_Id;
8771             K    : Node_Kind;
8772
8773          begin
8774             Check_Ada_83_Warning;
8775             Ada_2012_Pragma;
8776             Check_No_Identifiers;
8777             Check_Arg_Count (1);
8778             Check_Arg_Is_Local_Name (Arg1);
8779             E_Id := Get_Pragma_Arg (Arg1);
8780
8781             if Etype (E_Id) = Any_Type then
8782                return;
8783             end if;
8784
8785             E := Entity (E_Id);
8786
8787             --  Check duplicate before we chain ourselves!
8788
8789             Check_Duplicate_Pragma (E);
8790
8791             --  Check appropriate entity
8792
8793             if Rep_Item_Too_Early (E, N)
8794                  or else
8795                Rep_Item_Too_Late (E, N)
8796             then
8797                return;
8798             end if;
8799
8800             D := Declaration_Node (E);
8801             K := Nkind (D);
8802
8803             if (K = N_Full_Type_Declaration
8804                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
8805               or else
8806                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8807                    and then Nkind (D) = N_Object_Declaration
8808                    and then Nkind (Object_Definition (D)) =
8809                                        N_Constrained_Array_Definition)
8810             then
8811                Independence_Checks.Append ((N, E));
8812
8813             else
8814                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
8815             end if;
8816          end Independent_Components;
8817
8818          ------------------------
8819          -- Initialize_Scalars --
8820          ------------------------
8821
8822          --  pragma Initialize_Scalars;
8823
8824          when Pragma_Initialize_Scalars =>
8825             GNAT_Pragma;
8826             Check_Arg_Count (0);
8827             Check_Valid_Configuration_Pragma;
8828             Check_Restriction (No_Initialize_Scalars, N);
8829
8830             --  Initialize_Scalars creates false positives in CodePeer,
8831             --  so ignore this pragma in this mode.
8832
8833             if not Restriction_Active (No_Initialize_Scalars)
8834               and then not CodePeer_Mode
8835             then
8836                Init_Or_Norm_Scalars := True;
8837                Initialize_Scalars := True;
8838             end if;
8839
8840          ------------
8841          -- Inline --
8842          ------------
8843
8844          --  pragma Inline ( NAME {, NAME} );
8845
8846          when Pragma_Inline =>
8847
8848             --  Pragma is active if inlining option is active
8849
8850             Process_Inline (Inline_Active);
8851
8852          -------------------
8853          -- Inline_Always --
8854          -------------------
8855
8856          --  pragma Inline_Always ( NAME {, NAME} );
8857
8858          when Pragma_Inline_Always =>
8859             GNAT_Pragma;
8860
8861             --  Pragma always active unless in CodePeer mode, since this causes
8862             --  walk order issues.
8863
8864             if not CodePeer_Mode then
8865                Process_Inline (True);
8866             end if;
8867
8868          --------------------
8869          -- Inline_Generic --
8870          --------------------
8871
8872          --  pragma Inline_Generic (NAME {, NAME});
8873
8874          when Pragma_Inline_Generic =>
8875             GNAT_Pragma;
8876             Process_Generic_List;
8877
8878          ----------------------
8879          -- Inspection_Point --
8880          ----------------------
8881
8882          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
8883
8884          when Pragma_Inspection_Point => Inspection_Point : declare
8885             Arg : Node_Id;
8886             Exp : Node_Id;
8887
8888          begin
8889             if Arg_Count > 0 then
8890                Arg := Arg1;
8891                loop
8892                   Exp := Get_Pragma_Arg (Arg);
8893                   Analyze (Exp);
8894
8895                   if not Is_Entity_Name (Exp)
8896                     or else not Is_Object (Entity (Exp))
8897                   then
8898                      Error_Pragma_Arg ("object name required", Arg);
8899                   end if;
8900
8901                   Next (Arg);
8902                   exit when No (Arg);
8903                end loop;
8904             end if;
8905          end Inspection_Point;
8906
8907          ---------------
8908          -- Interface --
8909          ---------------
8910
8911          --  pragma Interface (
8912          --    [   Convention    =>] convention_IDENTIFIER,
8913          --    [   Entity        =>] local_NAME
8914          --    [, [External_Name =>] static_string_EXPRESSION ]
8915          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8916
8917          when Pragma_Interface =>
8918             GNAT_Pragma;
8919             Check_Arg_Order
8920               ((Name_Convention,
8921                 Name_Entity,
8922                 Name_External_Name,
8923                 Name_Link_Name));
8924             Check_At_Least_N_Arguments (2);
8925             Check_At_Most_N_Arguments  (4);
8926             Process_Import_Or_Interface;
8927
8928             --  In Ada 2005, the permission to use Interface (a reserved word)
8929             --  as a pragma name is considered an obsolescent feature.
8930
8931             if Ada_Version >= Ada_2005 then
8932                Check_Restriction
8933                  (No_Obsolescent_Features, Pragma_Identifier (N));
8934             end if;
8935
8936          --------------------
8937          -- Interface_Name --
8938          --------------------
8939
8940          --  pragma Interface_Name (
8941          --    [  Entity        =>] local_NAME
8942          --    [,[External_Name =>] static_string_EXPRESSION ]
8943          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
8944
8945          when Pragma_Interface_Name => Interface_Name : declare
8946             Id     : Node_Id;
8947             Def_Id : Entity_Id;
8948             Hom_Id : Entity_Id;
8949             Found  : Boolean;
8950
8951          begin
8952             GNAT_Pragma;
8953             Check_Arg_Order
8954               ((Name_Entity, Name_External_Name, Name_Link_Name));
8955             Check_At_Least_N_Arguments (2);
8956             Check_At_Most_N_Arguments  (3);
8957             Id := Get_Pragma_Arg (Arg1);
8958             Analyze (Id);
8959
8960             if not Is_Entity_Name (Id) then
8961                Error_Pragma_Arg
8962                  ("first argument for pragma% must be entity name", Arg1);
8963             elsif Etype (Id) = Any_Type then
8964                return;
8965             else
8966                Def_Id := Entity (Id);
8967             end if;
8968
8969             --  Special DEC-compatible processing for the object case, forces
8970             --  object to be imported.
8971
8972             if Ekind (Def_Id) = E_Variable then
8973                Kill_Size_Check_Code (Def_Id);
8974                Note_Possible_Modification (Id, Sure => False);
8975
8976                --  Initialization is not allowed for imported variable
8977
8978                if Present (Expression (Parent (Def_Id)))
8979                  and then Comes_From_Source (Expression (Parent (Def_Id)))
8980                then
8981                   Error_Msg_Sloc := Sloc (Def_Id);
8982                   Error_Pragma_Arg
8983                     ("no initialization allowed for declaration of& #",
8984                      Arg2);
8985
8986                else
8987                   --  For compatibility, support VADS usage of providing both
8988                   --  pragmas Interface and Interface_Name to obtain the effect
8989                   --  of a single Import pragma.
8990
8991                   if Is_Imported (Def_Id)
8992                     and then Present (First_Rep_Item (Def_Id))
8993                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8994                     and then
8995                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8996                   then
8997                      null;
8998                   else
8999                      Set_Imported (Def_Id);
9000                   end if;
9001
9002                   Set_Is_Public (Def_Id);
9003                   Process_Interface_Name (Def_Id, Arg2, Arg3);
9004                end if;
9005
9006             --  Otherwise must be subprogram
9007
9008             elsif not Is_Subprogram (Def_Id) then
9009                Error_Pragma_Arg
9010                  ("argument of pragma% is not subprogram", Arg1);
9011
9012             else
9013                Check_At_Most_N_Arguments (3);
9014                Hom_Id := Def_Id;
9015                Found := False;
9016
9017                --  Loop through homonyms
9018
9019                loop
9020                   Def_Id := Get_Base_Subprogram (Hom_Id);
9021
9022                   if Is_Imported (Def_Id) then
9023                      Process_Interface_Name (Def_Id, Arg2, Arg3);
9024                      Found := True;
9025                   end if;
9026
9027                   exit when From_Aspect_Specification (N);
9028                   Hom_Id := Homonym (Hom_Id);
9029
9030                   exit when No (Hom_Id)
9031                     or else Scope (Hom_Id) /= Current_Scope;
9032                end loop;
9033
9034                if not Found then
9035                   Error_Pragma_Arg
9036                     ("argument of pragma% is not imported subprogram",
9037                      Arg1);
9038                end if;
9039             end if;
9040          end Interface_Name;
9041
9042          -----------------------
9043          -- Interrupt_Handler --
9044          -----------------------
9045
9046          --  pragma Interrupt_Handler (handler_NAME);
9047
9048          when Pragma_Interrupt_Handler =>
9049             Check_Ada_83_Warning;
9050             Check_Arg_Count (1);
9051             Check_No_Identifiers;
9052
9053             if No_Run_Time_Mode then
9054                Error_Msg_CRT ("Interrupt_Handler pragma", N);
9055             else
9056                Check_Interrupt_Or_Attach_Handler;
9057                Process_Interrupt_Or_Attach_Handler;
9058             end if;
9059
9060          ------------------------
9061          -- Interrupt_Priority --
9062          ------------------------
9063
9064          --  pragma Interrupt_Priority [(EXPRESSION)];
9065
9066          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9067             P   : constant Node_Id := Parent (N);
9068             Arg : Node_Id;
9069
9070          begin
9071             Check_Ada_83_Warning;
9072
9073             if Arg_Count /= 0 then
9074                Arg := Get_Pragma_Arg (Arg1);
9075                Check_Arg_Count (1);
9076                Check_No_Identifiers;
9077
9078                --  The expression must be analyzed in the special manner
9079                --  described in "Handling of Default and Per-Object
9080                --  Expressions" in sem.ads.
9081
9082                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9083             end if;
9084
9085             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9086                Pragma_Misplaced;
9087                return;
9088
9089             elsif Has_Pragma_Priority (P) then
9090                Error_Pragma ("duplicate pragma% not allowed");
9091
9092             else
9093                Set_Has_Pragma_Priority (P, True);
9094                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9095             end if;
9096          end Interrupt_Priority;
9097
9098          ---------------------
9099          -- Interrupt_State --
9100          ---------------------
9101
9102          --  pragma Interrupt_State (
9103          --    [Name  =>] INTERRUPT_ID,
9104          --    [State =>] INTERRUPT_STATE);
9105
9106          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9107          --  INTERRUPT_STATE => System | Runtime | User
9108
9109          --  Note: if the interrupt id is given as an identifier, then it must
9110          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9111          --  given as a static integer expression which must be in the range of
9112          --  Ada.Interrupts.Interrupt_ID.
9113
9114          when Pragma_Interrupt_State => Interrupt_State : declare
9115
9116             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9117             --  This is the entity Ada.Interrupts.Interrupt_ID;
9118
9119             State_Type : Character;
9120             --  Set to 's'/'r'/'u' for System/Runtime/User
9121
9122             IST_Num : Pos;
9123             --  Index to entry in Interrupt_States table
9124
9125             Int_Val : Uint;
9126             --  Value of interrupt
9127
9128             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9129             --  The first argument to the pragma
9130
9131             Int_Ent : Entity_Id;
9132             --  Interrupt entity in Ada.Interrupts.Names
9133
9134          begin
9135             GNAT_Pragma;
9136             Check_Arg_Order ((Name_Name, Name_State));
9137             Check_Arg_Count (2);
9138
9139             Check_Optional_Identifier (Arg1, Name_Name);
9140             Check_Optional_Identifier (Arg2, Name_State);
9141             Check_Arg_Is_Identifier (Arg2);
9142
9143             --  First argument is identifier
9144
9145             if Nkind (Arg1X) = N_Identifier then
9146
9147                --  Search list of names in Ada.Interrupts.Names
9148
9149                Int_Ent := First_Entity (RTE (RE_Names));
9150                loop
9151                   if No (Int_Ent) then
9152                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
9153
9154                   elsif Chars (Int_Ent) = Chars (Arg1X) then
9155                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
9156                      exit;
9157                   end if;
9158
9159                   Next_Entity (Int_Ent);
9160                end loop;
9161
9162             --  First argument is not an identifier, so it must be a static
9163             --  expression of type Ada.Interrupts.Interrupt_ID.
9164
9165             else
9166                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9167                Int_Val := Expr_Value (Arg1X);
9168
9169                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9170                     or else
9171                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9172                then
9173                   Error_Pragma_Arg
9174                     ("value not in range of type " &
9175                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9176                end if;
9177             end if;
9178
9179             --  Check OK state
9180
9181             case Chars (Get_Pragma_Arg (Arg2)) is
9182                when Name_Runtime => State_Type := 'r';
9183                when Name_System  => State_Type := 's';
9184                when Name_User    => State_Type := 'u';
9185
9186                when others =>
9187                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
9188             end case;
9189
9190             --  Check if entry is already stored
9191
9192             IST_Num := Interrupt_States.First;
9193             loop
9194                --  If entry not found, add it
9195
9196                if IST_Num > Interrupt_States.Last then
9197                   Interrupt_States.Append
9198                     ((Interrupt_Number => UI_To_Int (Int_Val),
9199                       Interrupt_State  => State_Type,
9200                       Pragma_Loc       => Loc));
9201                   exit;
9202
9203                --  Case of entry for the same entry
9204
9205                elsif Int_Val = Interrupt_States.Table (IST_Num).
9206                                                            Interrupt_Number
9207                then
9208                   --  If state matches, done, no need to make redundant entry
9209
9210                   exit when
9211                     State_Type = Interrupt_States.Table (IST_Num).
9212                                                            Interrupt_State;
9213
9214                   --  Otherwise if state does not match, error
9215
9216                   Error_Msg_Sloc :=
9217                     Interrupt_States.Table (IST_Num).Pragma_Loc;
9218                   Error_Pragma_Arg
9219                     ("state conflicts with that given #", Arg2);
9220                   exit;
9221                end if;
9222
9223                IST_Num := IST_Num + 1;
9224             end loop;
9225          end Interrupt_State;
9226
9227          ----------------------
9228          -- Java_Constructor --
9229          ----------------------
9230
9231          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9232
9233          --  Also handles pragma CIL_Constructor
9234
9235          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9236          Java_Constructor : declare
9237             Convention  : Convention_Id;
9238             Def_Id      : Entity_Id;
9239             Hom_Id      : Entity_Id;
9240             Id          : Entity_Id;
9241             This_Formal : Entity_Id;
9242
9243          begin
9244             GNAT_Pragma;
9245             Check_Arg_Count (1);
9246             Check_Optional_Identifier (Arg1, Name_Entity);
9247             Check_Arg_Is_Local_Name (Arg1);
9248
9249             Id := Get_Pragma_Arg (Arg1);
9250             Find_Program_Unit_Name (Id);
9251
9252             --  If we did not find the name, we are done
9253
9254             if Etype (Id) = Any_Type then
9255                return;
9256             end if;
9257
9258             --  Check wrong use of pragma in wrong VM target
9259
9260             if VM_Target = No_VM then
9261                return;
9262
9263             elsif VM_Target = CLI_Target
9264               and then Prag_Id = Pragma_Java_Constructor
9265             then
9266                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9267
9268             elsif VM_Target = JVM_Target
9269               and then Prag_Id = Pragma_CIL_Constructor
9270             then
9271                Error_Pragma ("must use pragma 'Java_'Constructor");
9272             end if;
9273
9274             case Prag_Id is
9275                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
9276                when Pragma_Java_Constructor => Convention := Convention_Java;
9277                when others                  => null;
9278             end case;
9279
9280             Hom_Id := Entity (Id);
9281
9282             --  Loop through homonyms
9283
9284             loop
9285                Def_Id := Get_Base_Subprogram (Hom_Id);
9286
9287                --  The constructor is required to be a function
9288
9289                if Ekind (Def_Id) /= E_Function then
9290                   if VM_Target = JVM_Target then
9291                      Error_Pragma_Arg
9292                        ("pragma% requires function returning a " &
9293                         "'Java access type", Def_Id);
9294                   else
9295                      Error_Pragma_Arg
9296                        ("pragma% requires function returning a " &
9297                         "'C'I'L access type", Def_Id);
9298                   end if;
9299                end if;
9300
9301                --  Check arguments: For tagged type the first formal must be
9302                --  named "this" and its type must be a named access type
9303                --  designating a class-wide tagged type that has convention
9304                --  CIL/Java. The first formal must also have a null default
9305                --  value. For example:
9306
9307                --      type Typ is tagged ...
9308                --      type Ref is access all Typ;
9309                --      pragma Convention (CIL, Typ);
9310
9311                --      function New_Typ (This : Ref) return Ref;
9312                --      function New_Typ (This : Ref; I : Integer) return Ref;
9313                --      pragma Cil_Constructor (New_Typ);
9314
9315                --  Reason: The first formal must NOT be a primitive of the
9316                --  tagged type.
9317
9318                --  This rule also applies to constructors of delegates used
9319                --  to interface with standard target libraries. For example:
9320
9321                --      type Delegate is access procedure ...
9322                --      pragma Import (CIL, Delegate, ...);
9323
9324                --      function new_Delegate
9325                --        (This : Delegate := null; ... ) return Delegate;
9326
9327                --  For value-types this rule does not apply.
9328
9329                if not Is_Value_Type (Etype (Def_Id)) then
9330                   if No (First_Formal (Def_Id)) then
9331                      Error_Msg_Name_1 := Pname;
9332                      Error_Msg_N ("% function must have parameters", Def_Id);
9333                      return;
9334                   end if;
9335
9336                   --  In the JRE library we have several occurrences in which
9337                   --  the "this" parameter is not the first formal.
9338
9339                   This_Formal := First_Formal (Def_Id);
9340
9341                   --  In the JRE library we have several occurrences in which
9342                   --  the "this" parameter is not the first formal. Search for
9343                   --  it.
9344
9345                   if VM_Target = JVM_Target then
9346                      while Present (This_Formal)
9347                        and then Get_Name_String (Chars (This_Formal)) /= "this"
9348                      loop
9349                         Next_Formal (This_Formal);
9350                      end loop;
9351
9352                      if No (This_Formal) then
9353                         This_Formal := First_Formal (Def_Id);
9354                      end if;
9355                   end if;
9356
9357                   --  Warning: The first parameter should be named "this".
9358                   --  We temporarily allow it because we have the following
9359                   --  case in the Java runtime (file s-osinte.ads) ???
9360
9361                   --    function new_Thread
9362                   --      (Self_Id : System.Address) return Thread_Id;
9363                   --    pragma Java_Constructor (new_Thread);
9364
9365                   if VM_Target = JVM_Target
9366                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
9367                                = "self_id"
9368                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9369                   then
9370                      null;
9371
9372                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9373                      Error_Msg_Name_1 := Pname;
9374                      Error_Msg_N
9375                        ("first formal of % function must be named `this`",
9376                         Parent (This_Formal));
9377
9378                   elsif not Is_Access_Type (Etype (This_Formal)) then
9379                      Error_Msg_Name_1 := Pname;
9380                      Error_Msg_N
9381                        ("first formal of % function must be an access type",
9382                         Parameter_Type (Parent (This_Formal)));
9383
9384                   --  For delegates the type of the first formal must be a
9385                   --  named access-to-subprogram type (see previous example)
9386
9387                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9388                     and then Ekind (Etype (This_Formal))
9389                                /= E_Access_Subprogram_Type
9390                   then
9391                      Error_Msg_Name_1 := Pname;
9392                      Error_Msg_N
9393                        ("first formal of % function must be a named access" &
9394                         " to subprogram type",
9395                         Parameter_Type (Parent (This_Formal)));
9396
9397                   --  Warning: We should reject anonymous access types because
9398                   --  the constructor must not be handled as a primitive of the
9399                   --  tagged type. We temporarily allow it because this profile
9400                   --  is currently generated by cil2ada???
9401
9402                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9403                     and then not Ekind_In (Etype (This_Formal),
9404                                              E_Access_Type,
9405                                              E_General_Access_Type,
9406                                              E_Anonymous_Access_Type)
9407                   then
9408                      Error_Msg_Name_1 := Pname;
9409                      Error_Msg_N
9410                        ("first formal of % function must be a named access" &
9411                         " type",
9412                         Parameter_Type (Parent (This_Formal)));
9413
9414                   elsif Atree.Convention
9415                          (Designated_Type (Etype (This_Formal))) /= Convention
9416                   then
9417                      Error_Msg_Name_1 := Pname;
9418
9419                      if Convention = Convention_Java then
9420                         Error_Msg_N
9421                           ("pragma% requires convention 'Cil in designated" &
9422                            " type",
9423                            Parameter_Type (Parent (This_Formal)));
9424                      else
9425                         Error_Msg_N
9426                           ("pragma% requires convention 'Java in designated" &
9427                            " type",
9428                            Parameter_Type (Parent (This_Formal)));
9429                      end if;
9430
9431                   elsif No (Expression (Parent (This_Formal)))
9432                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9433                   then
9434                      Error_Msg_Name_1 := Pname;
9435                      Error_Msg_N
9436                        ("pragma% requires first formal with default `null`",
9437                         Parameter_Type (Parent (This_Formal)));
9438                   end if;
9439                end if;
9440
9441                --  Check result type: the constructor must be a function
9442                --  returning:
9443                --   * a value type (only allowed in the CIL compiler)
9444                --   * an access-to-subprogram type with convention Java/CIL
9445                --   * an access-type designating a type that has convention
9446                --     Java/CIL.
9447
9448                if Is_Value_Type (Etype (Def_Id)) then
9449                   null;
9450
9451                --  Access-to-subprogram type with convention Java/CIL
9452
9453                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9454                   if Atree.Convention (Etype (Def_Id)) /= Convention then
9455                      if Convention = Convention_Java then
9456                         Error_Pragma_Arg
9457                           ("pragma% requires function returning a " &
9458                            "'Java access type", Arg1);
9459                      else
9460                         pragma Assert (Convention = Convention_CIL);
9461                         Error_Pragma_Arg
9462                           ("pragma% requires function returning a " &
9463                            "'C'I'L access type", Arg1);
9464                      end if;
9465                   end if;
9466
9467                elsif Ekind (Etype (Def_Id)) in Access_Kind then
9468                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
9469                                                    E_General_Access_Type)
9470                     or else
9471                       Atree.Convention
9472                         (Designated_Type (Etype (Def_Id))) /= Convention
9473                   then
9474                      Error_Msg_Name_1 := Pname;
9475
9476                      if Convention = Convention_Java then
9477                         Error_Pragma_Arg
9478                           ("pragma% requires function returning a named" &
9479                            "'Java access type", Arg1);
9480                      else
9481                         Error_Pragma_Arg
9482                           ("pragma% requires function returning a named" &
9483                            "'C'I'L access type", Arg1);
9484                      end if;
9485                   end if;
9486                end if;
9487
9488                Set_Is_Constructor (Def_Id);
9489                Set_Convention     (Def_Id, Convention);
9490                Set_Is_Imported    (Def_Id);
9491
9492                exit when From_Aspect_Specification (N);
9493                Hom_Id := Homonym (Hom_Id);
9494
9495                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9496             end loop;
9497          end Java_Constructor;
9498
9499          ----------------------
9500          -- Java_Interface --
9501          ----------------------
9502
9503          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
9504
9505          when Pragma_Java_Interface => Java_Interface : declare
9506             Arg : Node_Id;
9507             Typ : Entity_Id;
9508
9509          begin
9510             GNAT_Pragma;
9511             Check_Arg_Count (1);
9512             Check_Optional_Identifier (Arg1, Name_Entity);
9513             Check_Arg_Is_Local_Name (Arg1);
9514
9515             Arg := Get_Pragma_Arg (Arg1);
9516             Analyze (Arg);
9517
9518             if Etype (Arg) = Any_Type then
9519                return;
9520             end if;
9521
9522             if not Is_Entity_Name (Arg)
9523               or else not Is_Type (Entity (Arg))
9524             then
9525                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9526             end if;
9527
9528             Typ := Underlying_Type (Entity (Arg));
9529
9530             --  For now simply check some of the semantic constraints on the
9531             --  type. This currently leaves out some restrictions on interface
9532             --  types, namely that the parent type must be java.lang.Object.Typ
9533             --  and that all primitives of the type should be declared
9534             --  abstract. ???
9535
9536             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9537                Error_Pragma_Arg ("pragma% requires an abstract "
9538                  & "tagged type", Arg1);
9539
9540             elsif not Has_Discriminants (Typ)
9541               or else Ekind (Etype (First_Discriminant (Typ)))
9542                         /= E_Anonymous_Access_Type
9543               or else
9544                 not Is_Class_Wide_Type
9545                       (Designated_Type (Etype (First_Discriminant (Typ))))
9546             then
9547                Error_Pragma_Arg
9548                  ("type must have a class-wide access discriminant", Arg1);
9549             end if;
9550          end Java_Interface;
9551
9552          ----------------
9553          -- Keep_Names --
9554          ----------------
9555
9556          --  pragma Keep_Names ([On => ] local_NAME);
9557
9558          when Pragma_Keep_Names => Keep_Names : declare
9559             Arg : Node_Id;
9560
9561          begin
9562             GNAT_Pragma;
9563             Check_Arg_Count (1);
9564             Check_Optional_Identifier (Arg1, Name_On);
9565             Check_Arg_Is_Local_Name (Arg1);
9566
9567             Arg := Get_Pragma_Arg (Arg1);
9568             Analyze (Arg);
9569
9570             if Etype (Arg) = Any_Type then
9571                return;
9572             end if;
9573
9574             if not Is_Entity_Name (Arg)
9575               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9576             then
9577                Error_Pragma_Arg
9578                  ("pragma% requires a local enumeration type", Arg1);
9579             end if;
9580
9581             Set_Discard_Names (Entity (Arg), False);
9582          end Keep_Names;
9583
9584          -------------
9585          -- License --
9586          -------------
9587
9588          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9589
9590          when Pragma_License =>
9591             GNAT_Pragma;
9592             Check_Arg_Count (1);
9593             Check_No_Identifiers;
9594             Check_Valid_Configuration_Pragma;
9595             Check_Arg_Is_Identifier (Arg1);
9596
9597             declare
9598                Sind : constant Source_File_Index :=
9599                         Source_Index (Current_Sem_Unit);
9600
9601             begin
9602                case Chars (Get_Pragma_Arg (Arg1)) is
9603                   when Name_GPL =>
9604                      Set_License (Sind, GPL);
9605
9606                   when Name_Modified_GPL =>
9607                      Set_License (Sind, Modified_GPL);
9608
9609                   when Name_Restricted =>
9610                      Set_License (Sind, Restricted);
9611
9612                   when Name_Unrestricted =>
9613                      Set_License (Sind, Unrestricted);
9614
9615                   when others =>
9616                      Error_Pragma_Arg ("invalid license name", Arg1);
9617                end case;
9618             end;
9619
9620          ---------------
9621          -- Link_With --
9622          ---------------
9623
9624          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9625
9626          when Pragma_Link_With => Link_With : declare
9627             Arg : Node_Id;
9628
9629          begin
9630             GNAT_Pragma;
9631
9632             if Operating_Mode = Generate_Code
9633               and then In_Extended_Main_Source_Unit (N)
9634             then
9635                Check_At_Least_N_Arguments (1);
9636                Check_No_Identifiers;
9637                Check_Is_In_Decl_Part_Or_Package_Spec;
9638                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9639                Start_String;
9640
9641                Arg := Arg1;
9642                while Present (Arg) loop
9643                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
9644
9645                   --  Store argument, converting sequences of spaces to a
9646                   --  single null character (this is one of the differences
9647                   --  in processing between Link_With and Linker_Options).
9648
9649                   Arg_Store : declare
9650                      C : constant Char_Code := Get_Char_Code (' ');
9651                      S : constant String_Id :=
9652                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
9653                      L : constant Nat := String_Length (S);
9654                      F : Nat := 1;
9655
9656                      procedure Skip_Spaces;
9657                      --  Advance F past any spaces
9658
9659                      -----------------
9660                      -- Skip_Spaces --
9661                      -----------------
9662
9663                      procedure Skip_Spaces is
9664                      begin
9665                         while F <= L and then Get_String_Char (S, F) = C loop
9666                            F := F + 1;
9667                         end loop;
9668                      end Skip_Spaces;
9669
9670                   --  Start of processing for Arg_Store
9671
9672                   begin
9673                      Skip_Spaces; -- skip leading spaces
9674
9675                      --  Loop through characters, changing any embedded
9676                      --  sequence of spaces to a single null character (this
9677                      --  is how Link_With/Linker_Options differ)
9678
9679                      while F <= L loop
9680                         if Get_String_Char (S, F) = C then
9681                            Skip_Spaces;
9682                            exit when F > L;
9683                            Store_String_Char (ASCII.NUL);
9684
9685                         else
9686                            Store_String_Char (Get_String_Char (S, F));
9687                            F := F + 1;
9688                         end if;
9689                      end loop;
9690                   end Arg_Store;
9691
9692                   Arg := Next (Arg);
9693
9694                   if Present (Arg) then
9695                      Store_String_Char (ASCII.NUL);
9696                   end if;
9697                end loop;
9698
9699                Store_Linker_Option_String (End_String);
9700             end if;
9701          end Link_With;
9702
9703          ------------------
9704          -- Linker_Alias --
9705          ------------------
9706
9707          --  pragma Linker_Alias (
9708          --      [Entity =>]  LOCAL_NAME
9709          --      [Target =>]  static_string_EXPRESSION);
9710
9711          when Pragma_Linker_Alias =>
9712             GNAT_Pragma;
9713             Check_Arg_Order ((Name_Entity, Name_Target));
9714             Check_Arg_Count (2);
9715             Check_Optional_Identifier (Arg1, Name_Entity);
9716             Check_Optional_Identifier (Arg2, Name_Target);
9717             Check_Arg_Is_Library_Level_Local_Name (Arg1);
9718             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9719
9720             --  The only processing required is to link this item on to the
9721             --  list of rep items for the given entity. This is accomplished
9722             --  by the call to Rep_Item_Too_Late (when no error is detected
9723             --  and False is returned).
9724
9725             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
9726                return;
9727             else
9728                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
9729             end if;
9730
9731          ------------------------
9732          -- Linker_Constructor --
9733          ------------------------
9734
9735          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
9736
9737          --  Code is shared with Linker_Destructor
9738
9739          -----------------------
9740          -- Linker_Destructor --
9741          -----------------------
9742
9743          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
9744
9745          when Pragma_Linker_Constructor |
9746               Pragma_Linker_Destructor =>
9747          Linker_Constructor : declare
9748             Arg1_X : Node_Id;
9749             Proc   : Entity_Id;
9750
9751          begin
9752             GNAT_Pragma;
9753             Check_Arg_Count (1);
9754             Check_No_Identifiers;
9755             Check_Arg_Is_Local_Name (Arg1);
9756             Arg1_X := Get_Pragma_Arg (Arg1);
9757             Analyze (Arg1_X);
9758             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
9759
9760             if not Is_Library_Level_Entity (Proc) then
9761                Error_Pragma_Arg
9762                 ("argument for pragma% must be library level entity", Arg1);
9763             end if;
9764
9765             --  The only processing required is to link this item on to the
9766             --  list of rep items for the given entity. This is accomplished
9767             --  by the call to Rep_Item_Too_Late (when no error is detected
9768             --  and False is returned).
9769
9770             if Rep_Item_Too_Late (Proc, N) then
9771                return;
9772             else
9773                Set_Has_Gigi_Rep_Item (Proc);
9774             end if;
9775          end Linker_Constructor;
9776
9777          --------------------
9778          -- Linker_Options --
9779          --------------------
9780
9781          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
9782
9783          when Pragma_Linker_Options => Linker_Options : declare
9784             Arg : Node_Id;
9785
9786          begin
9787             Check_Ada_83_Warning;
9788             Check_No_Identifiers;
9789             Check_Arg_Count (1);
9790             Check_Is_In_Decl_Part_Or_Package_Spec;
9791             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9792             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
9793
9794             Arg := Arg2;
9795             while Present (Arg) loop
9796                Check_Arg_Is_Static_Expression (Arg, Standard_String);
9797                Store_String_Char (ASCII.NUL);
9798                Store_String_Chars
9799                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
9800                Arg := Next (Arg);
9801             end loop;
9802
9803             if Operating_Mode = Generate_Code
9804               and then In_Extended_Main_Source_Unit (N)
9805             then
9806                Store_Linker_Option_String (End_String);
9807             end if;
9808          end Linker_Options;
9809
9810          --------------------
9811          -- Linker_Section --
9812          --------------------
9813
9814          --  pragma Linker_Section (
9815          --      [Entity  =>]  LOCAL_NAME
9816          --      [Section =>]  static_string_EXPRESSION);
9817
9818          when Pragma_Linker_Section =>
9819             GNAT_Pragma;
9820             Check_Arg_Order ((Name_Entity, Name_Section));
9821             Check_Arg_Count (2);
9822             Check_Optional_Identifier (Arg1, Name_Entity);
9823             Check_Optional_Identifier (Arg2, Name_Section);
9824             Check_Arg_Is_Library_Level_Local_Name (Arg1);
9825             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9826
9827             --  This pragma applies only to objects
9828
9829             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
9830                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
9831             end if;
9832
9833             --  The only processing required is to link this item on to the
9834             --  list of rep items for the given entity. This is accomplished
9835             --  by the call to Rep_Item_Too_Late (when no error is detected
9836             --  and False is returned).
9837
9838             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
9839                return;
9840             else
9841                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
9842             end if;
9843
9844          ----------
9845          -- List --
9846          ----------
9847
9848          --  pragma List (On | Off)
9849
9850          --  There is nothing to do here, since we did all the processing for
9851          --  this pragma in Par.Prag (so that it works properly even in syntax
9852          --  only mode).
9853
9854          when Pragma_List =>
9855             null;
9856
9857          --------------------
9858          -- Locking_Policy --
9859          --------------------
9860
9861          --  pragma Locking_Policy (policy_IDENTIFIER);
9862
9863          when Pragma_Locking_Policy => declare
9864             LP : Character;
9865
9866          begin
9867             Check_Ada_83_Warning;
9868             Check_Arg_Count (1);
9869             Check_No_Identifiers;
9870             Check_Arg_Is_Locking_Policy (Arg1);
9871             Check_Valid_Configuration_Pragma;
9872             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
9873             LP := Fold_Upper (Name_Buffer (1));
9874
9875             if Locking_Policy /= ' '
9876               and then Locking_Policy /= LP
9877             then
9878                Error_Msg_Sloc := Locking_Policy_Sloc;
9879                Error_Pragma ("locking policy incompatible with policy#");
9880
9881             --  Set new policy, but always preserve System_Location since we
9882             --  like the error message with the run time name.
9883
9884             else
9885                Locking_Policy := LP;
9886
9887                if Locking_Policy_Sloc /= System_Location then
9888                   Locking_Policy_Sloc := Loc;
9889                end if;
9890             end if;
9891          end;
9892
9893          ----------------
9894          -- Long_Float --
9895          ----------------
9896
9897          --  pragma Long_Float (D_Float | G_Float);
9898
9899          when Pragma_Long_Float =>
9900             GNAT_Pragma;
9901             Check_Valid_Configuration_Pragma;
9902             Check_Arg_Count (1);
9903             Check_No_Identifier (Arg1);
9904             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
9905
9906             if not OpenVMS_On_Target then
9907                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
9908             end if;
9909
9910             --  D_Float case
9911
9912             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
9913                if Opt.Float_Format_Long = 'G' then
9914                   Error_Pragma ("G_Float previously specified");
9915                end if;
9916
9917                Opt.Float_Format_Long := 'D';
9918
9919             --  G_Float case (this is the default, does not need overriding)
9920
9921             else
9922                if Opt.Float_Format_Long = 'D' then
9923                   Error_Pragma ("D_Float previously specified");
9924                end if;
9925
9926                Opt.Float_Format_Long := 'G';
9927             end if;
9928
9929             Set_Standard_Fpt_Formats;
9930
9931          -----------------------
9932          -- Machine_Attribute --
9933          -----------------------
9934
9935          --  pragma Machine_Attribute (
9936          --       [Entity         =>] LOCAL_NAME,
9937          --       [Attribute_Name =>] static_string_EXPRESSION
9938          --    [, [Info           =>] static_EXPRESSION] );
9939
9940          when Pragma_Machine_Attribute => Machine_Attribute : declare
9941             Def_Id : Entity_Id;
9942
9943          begin
9944             GNAT_Pragma;
9945             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
9946
9947             if Arg_Count = 3 then
9948                Check_Optional_Identifier (Arg3, Name_Info);
9949                Check_Arg_Is_Static_Expression (Arg3);
9950             else
9951                Check_Arg_Count (2);
9952             end if;
9953
9954             Check_Optional_Identifier (Arg1, Name_Entity);
9955             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
9956             Check_Arg_Is_Local_Name (Arg1);
9957             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9958             Def_Id := Entity (Get_Pragma_Arg (Arg1));
9959
9960             if Is_Access_Type (Def_Id) then
9961                Def_Id := Designated_Type (Def_Id);
9962             end if;
9963
9964             if Rep_Item_Too_Early (Def_Id, N) then
9965                return;
9966             end if;
9967
9968             Def_Id := Underlying_Type (Def_Id);
9969
9970             --  The only processing required is to link this item on to the
9971             --  list of rep items for the given entity. This is accomplished
9972             --  by the call to Rep_Item_Too_Late (when no error is detected
9973             --  and False is returned).
9974
9975             if Rep_Item_Too_Late (Def_Id, N) then
9976                return;
9977             else
9978                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
9979             end if;
9980          end Machine_Attribute;
9981
9982          ----------
9983          -- Main --
9984          ----------
9985
9986          --  pragma Main
9987          --   (MAIN_OPTION [, MAIN_OPTION]);
9988
9989          --  MAIN_OPTION ::=
9990          --    [STACK_SIZE              =>] static_integer_EXPRESSION
9991          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
9992          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
9993
9994          when Pragma_Main => Main : declare
9995             Args  : Args_List (1 .. 3);
9996             Names : constant Name_List (1 .. 3) := (
9997                       Name_Stack_Size,
9998                       Name_Task_Stack_Size_Default,
9999                       Name_Time_Slicing_Enabled);
10000
10001             Nod : Node_Id;
10002
10003          begin
10004             GNAT_Pragma;
10005             Gather_Associations (Names, Args);
10006
10007             for J in 1 .. 2 loop
10008                if Present (Args (J)) then
10009                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10010                end if;
10011             end loop;
10012
10013             if Present (Args (3)) then
10014                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10015             end if;
10016
10017             Nod := Next (N);
10018             while Present (Nod) loop
10019                if Nkind (Nod) = N_Pragma
10020                  and then Pragma_Name (Nod) = Name_Main
10021                then
10022                   Error_Msg_Name_1 := Pname;
10023                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10024                end if;
10025
10026                Next (Nod);
10027             end loop;
10028          end Main;
10029
10030          ------------------
10031          -- Main_Storage --
10032          ------------------
10033
10034          --  pragma Main_Storage
10035          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10036
10037          --  MAIN_STORAGE_OPTION ::=
10038          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10039          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10040
10041          when Pragma_Main_Storage => Main_Storage : declare
10042             Args  : Args_List (1 .. 2);
10043             Names : constant Name_List (1 .. 2) := (
10044                       Name_Working_Storage,
10045                       Name_Top_Guard);
10046
10047             Nod : Node_Id;
10048
10049          begin
10050             GNAT_Pragma;
10051             Gather_Associations (Names, Args);
10052
10053             for J in 1 .. 2 loop
10054                if Present (Args (J)) then
10055                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10056                end if;
10057             end loop;
10058
10059             Check_In_Main_Program;
10060
10061             Nod := Next (N);
10062             while Present (Nod) loop
10063                if Nkind (Nod) = N_Pragma
10064                  and then Pragma_Name (Nod) = Name_Main_Storage
10065                then
10066                   Error_Msg_Name_1 := Pname;
10067                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10068                end if;
10069
10070                Next (Nod);
10071             end loop;
10072          end Main_Storage;
10073
10074          -----------------
10075          -- Memory_Size --
10076          -----------------
10077
10078          --  pragma Memory_Size (NUMERIC_LITERAL)
10079
10080          when Pragma_Memory_Size =>
10081             GNAT_Pragma;
10082
10083             --  Memory size is simply ignored
10084
10085             Check_No_Identifiers;
10086             Check_Arg_Count (1);
10087             Check_Arg_Is_Integer_Literal (Arg1);
10088
10089          -------------
10090          -- No_Body --
10091          -------------
10092
10093          --  pragma No_Body;
10094
10095          --  The only correct use of this pragma is on its own in a file, in
10096          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
10097          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10098          --  check for a file containing nothing but a No_Body pragma). If we
10099          --  attempt to process it during normal semantics processing, it means
10100          --  it was misplaced.
10101
10102          when Pragma_No_Body =>
10103             GNAT_Pragma;
10104             Pragma_Misplaced;
10105
10106          ---------------
10107          -- No_Return --
10108          ---------------
10109
10110          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10111
10112          when Pragma_No_Return => No_Return : declare
10113             Id    : Node_Id;
10114             E     : Entity_Id;
10115             Found : Boolean;
10116             Arg   : Node_Id;
10117
10118          begin
10119             Ada_2005_Pragma;
10120             Check_At_Least_N_Arguments (1);
10121
10122             --  Loop through arguments of pragma
10123
10124             Arg := Arg1;
10125             while Present (Arg) loop
10126                Check_Arg_Is_Local_Name (Arg);
10127                Id := Get_Pragma_Arg (Arg);
10128                Analyze (Id);
10129
10130                if not Is_Entity_Name (Id) then
10131                   Error_Pragma_Arg ("entity name required", Arg);
10132                end if;
10133
10134                if Etype (Id) = Any_Type then
10135                   raise Pragma_Exit;
10136                end if;
10137
10138                --  Loop to find matching procedures
10139
10140                E := Entity (Id);
10141                Found := False;
10142                while Present (E)
10143                  and then Scope (E) = Current_Scope
10144                loop
10145                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10146                      Set_No_Return (E);
10147
10148                      --  Set flag on any alias as well
10149
10150                      if Is_Overloadable (E) and then Present (Alias (E)) then
10151                         Set_No_Return (Alias (E));
10152                      end if;
10153
10154                      Found := True;
10155                   end if;
10156
10157                   exit when From_Aspect_Specification (N);
10158                   E := Homonym (E);
10159                end loop;
10160
10161                if not Found then
10162                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10163                end if;
10164
10165                Next (Arg);
10166             end loop;
10167          end No_Return;
10168
10169          -----------------
10170          -- No_Run_Time --
10171          -----------------
10172
10173          --  pragma No_Run_Time;
10174
10175          --  Note: this pragma is retained for backwards compatibility. See
10176          --  body of Rtsfind for full details on its handling.
10177
10178          when Pragma_No_Run_Time =>
10179             GNAT_Pragma;
10180             Check_Valid_Configuration_Pragma;
10181             Check_Arg_Count (0);
10182
10183             No_Run_Time_Mode           := True;
10184             Configurable_Run_Time_Mode := True;
10185
10186             --  Set Duration to 32 bits if word size is 32
10187
10188             if Ttypes.System_Word_Size = 32 then
10189                Duration_32_Bits_On_Target := True;
10190             end if;
10191
10192             --  Set appropriate restrictions
10193
10194             Set_Restriction (No_Finalization, N);
10195             Set_Restriction (No_Exception_Handlers, N);
10196             Set_Restriction (Max_Tasks, N, 0);
10197             Set_Restriction (No_Tasking, N);
10198
10199          ------------------------
10200          -- No_Strict_Aliasing --
10201          ------------------------
10202
10203          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10204
10205          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10206             E_Id : Entity_Id;
10207
10208          begin
10209             GNAT_Pragma;
10210             Check_At_Most_N_Arguments (1);
10211
10212             if Arg_Count = 0 then
10213                Check_Valid_Configuration_Pragma;
10214                Opt.No_Strict_Aliasing := True;
10215
10216             else
10217                Check_Optional_Identifier (Arg2, Name_Entity);
10218                Check_Arg_Is_Local_Name (Arg1);
10219                E_Id := Entity (Get_Pragma_Arg (Arg1));
10220
10221                if E_Id = Any_Type then
10222                   return;
10223                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10224                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
10225                end if;
10226
10227                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10228             end if;
10229          end No_Strict_Aliasing;
10230
10231          -----------------------
10232          -- Normalize_Scalars --
10233          -----------------------
10234
10235          --  pragma Normalize_Scalars;
10236
10237          when Pragma_Normalize_Scalars =>
10238             Check_Ada_83_Warning;
10239             Check_Arg_Count (0);
10240             Check_Valid_Configuration_Pragma;
10241
10242             --  Normalize_Scalars creates false positives in CodePeer, so
10243             --  ignore this pragma in this mode.
10244
10245             if not CodePeer_Mode then
10246                Normalize_Scalars := True;
10247                Init_Or_Norm_Scalars := True;
10248             end if;
10249
10250          -----------------
10251          -- Obsolescent --
10252          -----------------
10253
10254          --  pragma Obsolescent;
10255
10256          --  pragma Obsolescent (
10257          --    [Message =>] static_string_EXPRESSION
10258          --  [,[Version =>] Ada_05]]);
10259
10260          --  pragma Obsolescent (
10261          --    [Entity  =>] NAME
10262          --  [,[Message =>] static_string_EXPRESSION
10263          --  [,[Version =>] Ada_05]] );
10264
10265          when Pragma_Obsolescent => Obsolescent : declare
10266             Ename : Node_Id;
10267             Decl  : Node_Id;
10268
10269             procedure Set_Obsolescent (E : Entity_Id);
10270             --  Given an entity Ent, mark it as obsolescent if appropriate
10271
10272             ---------------------
10273             -- Set_Obsolescent --
10274             ---------------------
10275
10276             procedure Set_Obsolescent (E : Entity_Id) is
10277                Active : Boolean;
10278                Ent    : Entity_Id;
10279                S      : String_Id;
10280
10281             begin
10282                Active := True;
10283                Ent    := E;
10284
10285                --  Entity name was given
10286
10287                if Present (Ename) then
10288
10289                   --  If entity name matches, we are fine. Save entity in
10290                   --  pragma argument, for ASIS use.
10291
10292                   if Chars (Ename) = Chars (Ent) then
10293                      Set_Entity (Ename, Ent);
10294                      Generate_Reference (Ent, Ename);
10295
10296                   --  If entity name does not match, only possibility is an
10297                   --  enumeration literal from an enumeration type declaration.
10298
10299                   elsif Ekind (Ent) /= E_Enumeration_Type then
10300                      Error_Pragma
10301                        ("pragma % entity name does not match declaration");
10302
10303                   else
10304                      Ent := First_Literal (E);
10305                      loop
10306                         if No (Ent) then
10307                            Error_Pragma
10308                              ("pragma % entity name does not match any " &
10309                               "enumeration literal");
10310
10311                         elsif Chars (Ent) = Chars (Ename) then
10312                            Set_Entity (Ename, Ent);
10313                            Generate_Reference (Ent, Ename);
10314                            exit;
10315
10316                         else
10317                            Ent := Next_Literal (Ent);
10318                         end if;
10319                      end loop;
10320                   end if;
10321                end if;
10322
10323                --  Ent points to entity to be marked
10324
10325                if Arg_Count >= 1 then
10326
10327                   --  Deal with static string argument
10328
10329                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10330                   S := Strval (Get_Pragma_Arg (Arg1));
10331
10332                   for J in 1 .. String_Length (S) loop
10333                      if not In_Character_Range (Get_String_Char (S, J)) then
10334                         Error_Pragma_Arg
10335                           ("pragma% argument does not allow wide characters",
10336                            Arg1);
10337                      end if;
10338                   end loop;
10339
10340                   Obsolescent_Warnings.Append
10341                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10342
10343                   --  Check for Ada_05 parameter
10344
10345                   if Arg_Count /= 1 then
10346                      Check_Arg_Count (2);
10347
10348                      declare
10349                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10350
10351                      begin
10352                         Check_Arg_Is_Identifier (Argx);
10353
10354                         if Chars (Argx) /= Name_Ada_05 then
10355                            Error_Msg_Name_2 := Name_Ada_05;
10356                            Error_Pragma_Arg
10357                              ("only allowed argument for pragma% is %", Argx);
10358                         end if;
10359
10360                         if Ada_Version_Explicit < Ada_2005
10361                           or else not Warn_On_Ada_2005_Compatibility
10362                         then
10363                            Active := False;
10364                         end if;
10365                      end;
10366                   end if;
10367                end if;
10368
10369                --  Set flag if pragma active
10370
10371                if Active then
10372                   Set_Is_Obsolescent (Ent);
10373                end if;
10374
10375                return;
10376             end Set_Obsolescent;
10377
10378          --  Start of processing for pragma Obsolescent
10379
10380          begin
10381             GNAT_Pragma;
10382
10383             Check_At_Most_N_Arguments (3);
10384
10385             --  See if first argument specifies an entity name
10386
10387             if Arg_Count >= 1
10388               and then
10389                 (Chars (Arg1) = Name_Entity
10390                    or else
10391                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10392                                                       N_Identifier,
10393                                                       N_Operator_Symbol))
10394             then
10395                Ename := Get_Pragma_Arg (Arg1);
10396
10397                --  Eliminate first argument, so we can share processing
10398
10399                Arg1 := Arg2;
10400                Arg2 := Arg3;
10401                Arg_Count := Arg_Count - 1;
10402
10403             --  No Entity name argument given
10404
10405             else
10406                Ename := Empty;
10407             end if;
10408
10409             if Arg_Count >= 1 then
10410                Check_Optional_Identifier (Arg1, Name_Message);
10411
10412                if Arg_Count = 2 then
10413                   Check_Optional_Identifier (Arg2, Name_Version);
10414                end if;
10415             end if;
10416
10417             --  Get immediately preceding declaration
10418
10419             Decl := Prev (N);
10420             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10421                Prev (Decl);
10422             end loop;
10423
10424             --  Cases where we do not follow anything other than another pragma
10425
10426             if No (Decl) then
10427
10428                --  First case: library level compilation unit declaration with
10429                --  the pragma immediately following the declaration.
10430
10431                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10432                   Set_Obsolescent
10433                     (Defining_Entity (Unit (Parent (Parent (N)))));
10434                   return;
10435
10436                --  Case 2: library unit placement for package
10437
10438                else
10439                   declare
10440                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
10441                   begin
10442                      if Is_Package_Or_Generic_Package (Ent) then
10443                         Set_Obsolescent (Ent);
10444                         return;
10445                      end if;
10446                   end;
10447                end if;
10448
10449             --  Cases where we must follow a declaration
10450
10451             else
10452                if         Nkind (Decl) not in N_Declaration
10453                  and then Nkind (Decl) not in N_Later_Decl_Item
10454                  and then Nkind (Decl) not in N_Generic_Declaration
10455                  and then Nkind (Decl) not in N_Renaming_Declaration
10456                then
10457                   Error_Pragma
10458                     ("pragma% misplaced, "
10459                      & "must immediately follow a declaration");
10460
10461                else
10462                   Set_Obsolescent (Defining_Entity (Decl));
10463                   return;
10464                end if;
10465             end if;
10466          end Obsolescent;
10467
10468          --------------
10469          -- Optimize --
10470          --------------
10471
10472          --  pragma Optimize (Time | Space | Off);
10473
10474          --  The actual check for optimize is done in Gigi. Note that this
10475          --  pragma does not actually change the optimization setting, it
10476          --  simply checks that it is consistent with the pragma.
10477
10478          when Pragma_Optimize =>
10479             Check_No_Identifiers;
10480             Check_Arg_Count (1);
10481             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10482
10483          ------------------------
10484          -- Optimize_Alignment --
10485          ------------------------
10486
10487          --  pragma Optimize_Alignment (Time | Space | Off);
10488
10489          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10490             GNAT_Pragma;
10491             Check_No_Identifiers;
10492             Check_Arg_Count (1);
10493             Check_Valid_Configuration_Pragma;
10494
10495             declare
10496                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10497             begin
10498                case Nam is
10499                   when Name_Time =>
10500                      Opt.Optimize_Alignment := 'T';
10501                   when Name_Space =>
10502                      Opt.Optimize_Alignment := 'S';
10503                   when Name_Off =>
10504                      Opt.Optimize_Alignment := 'O';
10505                   when others =>
10506                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10507                end case;
10508             end;
10509
10510             --  Set indication that mode is set locally. If we are in fact in a
10511             --  configuration pragma file, this setting is harmless since the
10512             --  switch will get reset anyway at the start of each unit.
10513
10514             Optimize_Alignment_Local := True;
10515          end Optimize_Alignment;
10516
10517          -------------
10518          -- Ordered --
10519          -------------
10520
10521          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10522
10523          when Pragma_Ordered => Ordered : declare
10524             Assoc   : constant Node_Id := Arg1;
10525             Type_Id : Node_Id;
10526             Typ     : Entity_Id;
10527
10528          begin
10529             GNAT_Pragma;
10530             Check_No_Identifiers;
10531             Check_Arg_Count (1);
10532             Check_Arg_Is_Local_Name (Arg1);
10533
10534             Type_Id := Get_Pragma_Arg (Assoc);
10535             Find_Type (Type_Id);
10536             Typ := Entity (Type_Id);
10537
10538             if Typ = Any_Type then
10539                return;
10540             else
10541                Typ := Underlying_Type (Typ);
10542             end if;
10543
10544             if not Is_Enumeration_Type (Typ) then
10545                Error_Pragma ("pragma% must specify enumeration type");
10546             end if;
10547
10548             Check_First_Subtype (Arg1);
10549             Set_Has_Pragma_Ordered (Base_Type (Typ));
10550          end Ordered;
10551
10552          ----------
10553          -- Pack --
10554          ----------
10555
10556          --  pragma Pack (first_subtype_LOCAL_NAME);
10557
10558          when Pragma_Pack => Pack : declare
10559             Assoc   : constant Node_Id := Arg1;
10560             Type_Id : Node_Id;
10561             Typ     : Entity_Id;
10562             Ctyp    : Entity_Id;
10563             Ignore  : Boolean := False;
10564
10565          begin
10566             Check_No_Identifiers;
10567             Check_Arg_Count (1);
10568             Check_Arg_Is_Local_Name (Arg1);
10569
10570             Type_Id := Get_Pragma_Arg (Assoc);
10571             Find_Type (Type_Id);
10572             Typ := Entity (Type_Id);
10573
10574             if Typ = Any_Type
10575               or else Rep_Item_Too_Early (Typ, N)
10576             then
10577                return;
10578             else
10579                Typ := Underlying_Type (Typ);
10580             end if;
10581
10582             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10583                Error_Pragma ("pragma% must specify array or record type");
10584             end if;
10585
10586             Check_First_Subtype (Arg1);
10587             Check_Duplicate_Pragma (Typ);
10588
10589             --  Array type
10590
10591             if Is_Array_Type (Typ) then
10592                Ctyp := Component_Type (Typ);
10593
10594                --  Ignore pack that does nothing
10595
10596                if Known_Static_Esize (Ctyp)
10597                  and then Known_Static_RM_Size (Ctyp)
10598                  and then Esize (Ctyp) = RM_Size (Ctyp)
10599                  and then Addressable (Esize (Ctyp))
10600                then
10601                   Ignore := True;
10602                end if;
10603
10604                --  Process OK pragma Pack. Note that if there is a separate
10605                --  component clause present, the Pack will be cancelled. This
10606                --  processing is in Freeze.
10607
10608                if not Rep_Item_Too_Late (Typ, N) then
10609
10610                   --  In the context of static code analysis, we do not need
10611                   --  complex front-end expansions related to pragma Pack,
10612                   --  so disable handling of pragma Pack in this case.
10613
10614                   if CodePeer_Mode then
10615                      null;
10616
10617                   --  Don't attempt any packing for VM targets. We possibly
10618                   --  could deal with some cases of array bit-packing, but we
10619                   --  don't bother, since this is not a typical kind of
10620                   --  representation in the VM context anyway (and would not
10621                   --  for example work nicely with the debugger).
10622
10623                   elsif VM_Target /= No_VM then
10624                      if not GNAT_Mode then
10625                         Error_Pragma
10626                           ("?pragma% ignored in this configuration");
10627                      end if;
10628
10629                   --  Normal case where we do the pack action
10630
10631                   else
10632                      if not Ignore then
10633                         Set_Is_Packed            (Base_Type (Typ), Sense);
10634                         Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10635                      end if;
10636
10637                      Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10638
10639                      --  Complete reset action for Aspect_Cancel case
10640
10641                      if Sense = False then
10642
10643                         --  Cancel size unless explicitly set
10644
10645                         if not Has_Size_Clause (Typ)
10646                            and then not Has_Object_Size_Clause (Typ)
10647                         then
10648                            Set_Esize     (Typ, Uint_0);
10649                            Set_RM_Size   (Typ, Uint_0);
10650                            Set_Alignment (Typ, Uint_0);
10651                            Set_Packed_Array_Type (Typ, Empty);
10652                         end if;
10653
10654                         --  Reset component size unless explicitly set
10655
10656                         if not Has_Component_Size_Clause (Typ) then
10657                            if Known_Static_Esize (Ctyp)
10658                              and then Known_Static_RM_Size (Ctyp)
10659                              and then Esize (Ctyp) = RM_Size (Ctyp)
10660                              and then Addressable (Esize (Ctyp))
10661                            then
10662                               Set_Component_Size
10663                                 (Base_Type (Typ), Esize (Ctyp));
10664                            else
10665                               Set_Component_Size
10666                                 (Base_Type (Typ), Uint_0);
10667                            end if;
10668                         end if;
10669                      end if;
10670                   end if;
10671                end if;
10672
10673             --  For record types, the pack is always effective
10674
10675             else pragma Assert (Is_Record_Type (Typ));
10676                if not Rep_Item_Too_Late (Typ, N) then
10677
10678                   --  Ignore pack request with warning in VM mode (skip warning
10679                   --  if we are compiling GNAT run time library).
10680
10681                   if VM_Target /= No_VM then
10682                      if not GNAT_Mode then
10683                         Error_Pragma
10684                           ("?pragma% ignored in this configuration");
10685                      end if;
10686
10687                   --  Normal case of pack request active
10688
10689                   else
10690                      Set_Is_Packed            (Base_Type (Typ), Sense);
10691                      Set_Has_Pragma_Pack      (Base_Type (Typ), Sense);
10692                      Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10693
10694                      --  Complete reset action for Aspect_Cancel case
10695
10696                      if Sense = False then
10697
10698                         --  Cancel size if not explicitly given
10699
10700                         if not Has_Size_Clause (Typ)
10701                           and then not Has_Object_Size_Clause (Typ)
10702                         then
10703                            Set_Esize     (Typ, Uint_0);
10704                            Set_Alignment (Typ, Uint_0);
10705                         end if;
10706                      end if;
10707                   end if;
10708                end if;
10709             end if;
10710          end Pack;
10711
10712          ----------
10713          -- Page --
10714          ----------
10715
10716          --  pragma Page;
10717
10718          --  There is nothing to do here, since we did all the processing for
10719          --  this pragma in Par.Prag (so that it works properly even in syntax
10720          --  only mode).
10721
10722          when Pragma_Page =>
10723             null;
10724
10725          -------------
10726          -- Passive --
10727          -------------
10728
10729          --  pragma Passive [(PASSIVE_FORM)];
10730
10731          --  PASSIVE_FORM ::= Semaphore | No
10732
10733          when Pragma_Passive =>
10734             GNAT_Pragma;
10735
10736             if Nkind (Parent (N)) /= N_Task_Definition then
10737                Error_Pragma ("pragma% must be within task definition");
10738             end if;
10739
10740             if Arg_Count /= 0 then
10741                Check_Arg_Count (1);
10742                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
10743             end if;
10744
10745          ----------------------------------
10746          -- Preelaborable_Initialization --
10747          ----------------------------------
10748
10749          --  pragma Preelaborable_Initialization (DIRECT_NAME);
10750
10751          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
10752             Ent : Entity_Id;
10753
10754          begin
10755             Ada_2005_Pragma;
10756             Check_Arg_Count (1);
10757             Check_No_Identifiers;
10758             Check_Arg_Is_Identifier (Arg1);
10759             Check_Arg_Is_Local_Name (Arg1);
10760             Check_First_Subtype (Arg1);
10761             Ent := Entity (Get_Pragma_Arg (Arg1));
10762
10763             if not Is_Private_Type (Ent)
10764               and then not Is_Protected_Type (Ent)
10765             then
10766                Error_Pragma_Arg
10767                  ("pragma % can only be applied to private or protected type",
10768                   Arg1);
10769             end if;
10770
10771             --  Give an error if the pragma is applied to a protected type that
10772             --  does not qualify (due to having entries, or due to components
10773             --  that do not qualify).
10774
10775             if Is_Protected_Type (Ent)
10776               and then not Has_Preelaborable_Initialization (Ent)
10777             then
10778                Error_Msg_N
10779                  ("protected type & does not have preelaborable " &
10780                   "initialization", Ent);
10781
10782             --  Otherwise mark the type as definitely having preelaborable
10783             --  initialization.
10784
10785             else
10786                Set_Known_To_Have_Preelab_Init (Ent);
10787             end if;
10788
10789             if Has_Pragma_Preelab_Init (Ent)
10790               and then Warn_On_Redundant_Constructs
10791             then
10792                Error_Pragma ("?duplicate pragma%!");
10793             else
10794                Set_Has_Pragma_Preelab_Init (Ent);
10795             end if;
10796          end Preelab_Init;
10797
10798          --------------------
10799          -- Persistent_BSS --
10800          --------------------
10801
10802          --  pragma Persistent_BSS [(object_NAME)];
10803
10804          when Pragma_Persistent_BSS => Persistent_BSS :  declare
10805             Decl : Node_Id;
10806             Ent  : Entity_Id;
10807             Prag : Node_Id;
10808
10809          begin
10810             GNAT_Pragma;
10811             Check_At_Most_N_Arguments (1);
10812
10813             --  Case of application to specific object (one argument)
10814
10815             if Arg_Count = 1 then
10816                Check_Arg_Is_Library_Level_Local_Name (Arg1);
10817
10818                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
10819                  or else not
10820                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
10821                                                             E_Constant)
10822                then
10823                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
10824                end if;
10825
10826                Ent := Entity (Get_Pragma_Arg (Arg1));
10827                Decl := Parent (Ent);
10828
10829                if Rep_Item_Too_Late (Ent, N) then
10830                   return;
10831                end if;
10832
10833                if Present (Expression (Decl)) then
10834                   Error_Pragma_Arg
10835                     ("object for pragma% cannot have initialization", Arg1);
10836                end if;
10837
10838                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
10839                   Error_Pragma_Arg
10840                     ("object type for pragma% is not potentially persistent",
10841                      Arg1);
10842                end if;
10843
10844                Check_Duplicate_Pragma (Ent);
10845
10846                if Sense then
10847                   Prag :=
10848                     Make_Linker_Section_Pragma
10849                       (Ent, Sloc (N), ".persistent.bss");
10850                   Insert_After (N, Prag);
10851                   Analyze (Prag);
10852                end if;
10853
10854             --  Case of use as configuration pragma with no arguments
10855
10856             else
10857                Check_Valid_Configuration_Pragma;
10858                Persistent_BSS_Mode := True;
10859             end if;
10860          end Persistent_BSS;
10861
10862          -------------
10863          -- Polling --
10864          -------------
10865
10866          --  pragma Polling (ON | OFF);
10867
10868          when Pragma_Polling =>
10869             GNAT_Pragma;
10870             Check_Arg_Count (1);
10871             Check_No_Identifiers;
10872             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10873             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
10874
10875          -------------------
10876          -- Postcondition --
10877          -------------------
10878
10879          --  pragma Postcondition ([Check   =>] Boolean_Expression
10880          --                      [,[Message =>] String_Expression]);
10881
10882          when Pragma_Postcondition => Postcondition : declare
10883             In_Body : Boolean;
10884             pragma Warnings (Off, In_Body);
10885
10886          begin
10887             GNAT_Pragma;
10888             Check_At_Least_N_Arguments (1);
10889             Check_At_Most_N_Arguments (2);
10890             Check_Optional_Identifier (Arg1, Name_Check);
10891
10892             --  All we need to do here is call the common check procedure,
10893             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
10894
10895             Check_Precondition_Postcondition (In_Body);
10896          end Postcondition;
10897
10898          ------------------
10899          -- Precondition --
10900          ------------------
10901
10902          --  pragma Precondition ([Check   =>] Boolean_Expression
10903          --                     [,[Message =>] String_Expression]);
10904
10905          when Pragma_Precondition => Precondition : declare
10906             In_Body : Boolean;
10907
10908          begin
10909             GNAT_Pragma;
10910             Check_At_Least_N_Arguments (1);
10911             Check_At_Most_N_Arguments (2);
10912             Check_Optional_Identifier (Arg1, Name_Check);
10913             Check_Precondition_Postcondition (In_Body);
10914
10915             --  If in spec, nothing more to do. If in body, then we convert the
10916             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
10917             --  this whether or not precondition checks are enabled. That works
10918             --  fine since pragma Check will do this check, and will also
10919             --  analyze the condition itself in the proper context.
10920
10921             if In_Body then
10922                Rewrite (N,
10923                  Make_Pragma (Loc,
10924                    Chars => Name_Check,
10925                    Pragma_Argument_Associations => New_List (
10926                      Make_Pragma_Argument_Association (Loc,
10927                        Expression =>
10928                          Make_Identifier (Loc,
10929                            Chars => Name_Precondition)),
10930
10931                      Make_Pragma_Argument_Association (Sloc (Arg1),
10932                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
10933
10934                if Arg_Count = 2 then
10935                   Append_To (Pragma_Argument_Associations (N),
10936                     Make_Pragma_Argument_Association (Sloc (Arg2),
10937                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
10938                end if;
10939
10940                Analyze (N);
10941             end if;
10942          end Precondition;
10943
10944          ------------------
10945          -- Preelaborate --
10946          ------------------
10947
10948          --  pragma Preelaborate [(library_unit_NAME)];
10949
10950          --  Set the flag Is_Preelaborated of program unit name entity
10951
10952          when Pragma_Preelaborate => Preelaborate : declare
10953             Pa  : constant Node_Id   := Parent (N);
10954             Pk  : constant Node_Kind := Nkind (Pa);
10955             Ent : Entity_Id;
10956
10957          begin
10958             Check_Ada_83_Warning;
10959             Check_Valid_Library_Unit_Pragma;
10960
10961             if Nkind (N) = N_Null_Statement then
10962                return;
10963             end if;
10964
10965             Ent := Find_Lib_Unit_Name;
10966             Check_Duplicate_Pragma (Ent);
10967
10968             --  This filters out pragmas inside generic parent then
10969             --  show up inside instantiation
10970
10971             if Present (Ent)
10972               and then not (Pk = N_Package_Specification
10973                               and then Present (Generic_Parent (Pa)))
10974             then
10975                if not Debug_Flag_U then
10976                   Set_Is_Preelaborated (Ent, Sense);
10977                   Set_Suppress_Elaboration_Warnings (Ent, Sense);
10978                end if;
10979             end if;
10980          end Preelaborate;
10981
10982          ---------------------
10983          -- Preelaborate_05 --
10984          ---------------------
10985
10986          --  pragma Preelaborate_05 [(library_unit_NAME)];
10987
10988          --  This pragma is useable only in GNAT_Mode, where it is used like
10989          --  pragma Preelaborate but it is only effective in Ada 2005 mode
10990          --  (otherwise it is ignored). This is used to implement AI-362 which
10991          --  recategorizes some run-time packages in Ada 2005 mode.
10992
10993          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
10994             Ent : Entity_Id;
10995
10996          begin
10997             GNAT_Pragma;
10998             Check_Valid_Library_Unit_Pragma;
10999
11000             if not GNAT_Mode then
11001                Error_Pragma ("pragma% only available in GNAT mode");
11002             end if;
11003
11004             if Nkind (N) = N_Null_Statement then
11005                return;
11006             end if;
11007
11008             --  This is one of the few cases where we need to test the value of
11009             --  Ada_Version_Explicit rather than Ada_Version (which is always
11010             --  set to Ada_2012 in a predefined unit), we need to know the
11011             --  explicit version set to know if this pragma is active.
11012
11013             if Ada_Version_Explicit >= Ada_2005 then
11014                Ent := Find_Lib_Unit_Name;
11015                Set_Is_Preelaborated (Ent);
11016                Set_Suppress_Elaboration_Warnings (Ent);
11017             end if;
11018          end Preelaborate_05;
11019
11020          --------------
11021          -- Priority --
11022          --------------
11023
11024          --  pragma Priority (EXPRESSION);
11025
11026          when Pragma_Priority => Priority : declare
11027             P   : constant Node_Id := Parent (N);
11028             Arg : Node_Id;
11029
11030          begin
11031             Check_No_Identifiers;
11032             Check_Arg_Count (1);
11033
11034             --  Subprogram case
11035
11036             if Nkind (P) = N_Subprogram_Body then
11037                Check_In_Main_Program;
11038
11039                Arg := Get_Pragma_Arg (Arg1);
11040                Analyze_And_Resolve (Arg, Standard_Integer);
11041
11042                --  Must be static
11043
11044                if not Is_Static_Expression (Arg) then
11045                   Flag_Non_Static_Expr
11046                     ("main subprogram priority is not static!", Arg);
11047                   raise Pragma_Exit;
11048
11049                --  If constraint error, then we already signalled an error
11050
11051                elsif Raises_Constraint_Error (Arg) then
11052                   null;
11053
11054                --  Otherwise check in range
11055
11056                else
11057                   declare
11058                      Val : constant Uint := Expr_Value (Arg);
11059
11060                   begin
11061                      if Val < 0
11062                        or else Val > Expr_Value (Expression
11063                                        (Parent (RTE (RE_Max_Priority))))
11064                      then
11065                         Error_Pragma_Arg
11066                           ("main subprogram priority is out of range", Arg1);
11067                      end if;
11068                   end;
11069                end if;
11070
11071                Set_Main_Priority
11072                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11073
11074                --  Load an arbitrary entity from System.Tasking to make sure
11075                --  this package is implicitly with'ed, since we need to have
11076                --  the tasking run-time active for the pragma Priority to have
11077                --  any effect.
11078
11079                declare
11080                   Discard : Entity_Id;
11081                   pragma Warnings (Off, Discard);
11082                begin
11083                   Discard := RTE (RE_Task_List);
11084                end;
11085
11086             --  Task or Protected, must be of type Integer
11087
11088             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11089                Arg := Get_Pragma_Arg (Arg1);
11090
11091                --  The expression must be analyzed in the special manner
11092                --  described in "Handling of Default and Per-Object
11093                --  Expressions" in sem.ads.
11094
11095                Preanalyze_Spec_Expression (Arg, Standard_Integer);
11096
11097                if not Is_Static_Expression (Arg) then
11098                   Check_Restriction (Static_Priorities, Arg);
11099                end if;
11100
11101             --  Anything else is incorrect
11102
11103             else
11104                Pragma_Misplaced;
11105             end if;
11106
11107             if Has_Pragma_Priority (P) then
11108                Error_Pragma ("duplicate pragma% not allowed");
11109             else
11110                Set_Has_Pragma_Priority (P, True);
11111
11112                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11113                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11114                   --  exp_ch9 should use this ???
11115                end if;
11116             end if;
11117          end Priority;
11118
11119          -----------------------------------
11120          -- Priority_Specific_Dispatching --
11121          -----------------------------------
11122
11123          --  pragma Priority_Specific_Dispatching (
11124          --    policy_IDENTIFIER,
11125          --    first_priority_EXPRESSION,
11126          --    last_priority_EXPRESSION);
11127
11128          when Pragma_Priority_Specific_Dispatching =>
11129          Priority_Specific_Dispatching : declare
11130             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11131             --  This is the entity System.Any_Priority;
11132
11133             DP          : Character;
11134             Lower_Bound : Node_Id;
11135             Upper_Bound : Node_Id;
11136             Lower_Val   : Uint;
11137             Upper_Val   : Uint;
11138
11139          begin
11140             Ada_2005_Pragma;
11141             Check_Arg_Count (3);
11142             Check_No_Identifiers;
11143             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11144             Check_Valid_Configuration_Pragma;
11145             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11146             DP := Fold_Upper (Name_Buffer (1));
11147
11148             Lower_Bound := Get_Pragma_Arg (Arg2);
11149             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11150             Lower_Val := Expr_Value (Lower_Bound);
11151
11152             Upper_Bound := Get_Pragma_Arg (Arg3);
11153             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11154             Upper_Val := Expr_Value (Upper_Bound);
11155
11156             --  It is not allowed to use Task_Dispatching_Policy and
11157             --  Priority_Specific_Dispatching in the same partition.
11158
11159             if Task_Dispatching_Policy /= ' ' then
11160                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11161                Error_Pragma
11162                  ("pragma% incompatible with Task_Dispatching_Policy#");
11163
11164             --  Check lower bound in range
11165
11166             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11167                     or else
11168                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11169             then
11170                Error_Pragma_Arg
11171                  ("first_priority is out of range", Arg2);
11172
11173             --  Check upper bound in range
11174
11175             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11176                     or else
11177                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11178             then
11179                Error_Pragma_Arg
11180                  ("last_priority is out of range", Arg3);
11181
11182             --  Check that the priority range is valid
11183
11184             elsif Lower_Val > Upper_Val then
11185                Error_Pragma
11186                  ("last_priority_expression must be greater than" &
11187                   " or equal to first_priority_expression");
11188
11189             --  Store the new policy, but always preserve System_Location since
11190             --  we like the error message with the run-time name.
11191
11192             else
11193                --  Check overlapping in the priority ranges specified in other
11194                --  Priority_Specific_Dispatching pragmas within the same
11195                --  partition. We can only check those we know about!
11196
11197                for J in
11198                   Specific_Dispatching.First .. Specific_Dispatching.Last
11199                loop
11200                   if Specific_Dispatching.Table (J).First_Priority in
11201                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11202                   or else Specific_Dispatching.Table (J).Last_Priority in
11203                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11204                   then
11205                      Error_Msg_Sloc :=
11206                        Specific_Dispatching.Table (J).Pragma_Loc;
11207                         Error_Pragma
11208                           ("priority range overlaps with "
11209                            & "Priority_Specific_Dispatching#");
11210                   end if;
11211                end loop;
11212
11213                --  The use of Priority_Specific_Dispatching is incompatible
11214                --  with Task_Dispatching_Policy.
11215
11216                if Task_Dispatching_Policy /= ' ' then
11217                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11218                      Error_Pragma
11219                        ("Priority_Specific_Dispatching incompatible "
11220                         & "with Task_Dispatching_Policy#");
11221                end if;
11222
11223                --  The use of Priority_Specific_Dispatching forces ceiling
11224                --  locking policy.
11225
11226                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11227                   Error_Msg_Sloc := Locking_Policy_Sloc;
11228                      Error_Pragma
11229                        ("Priority_Specific_Dispatching incompatible "
11230                         & "with Locking_Policy#");
11231
11232                --  Set the Ceiling_Locking policy, but preserve System_Location
11233                --  since we like the error message with the run time name.
11234
11235                else
11236                   Locking_Policy := 'C';
11237
11238                   if Locking_Policy_Sloc /= System_Location then
11239                      Locking_Policy_Sloc := Loc;
11240                   end if;
11241                end if;
11242
11243                --  Add entry in the table
11244
11245                Specific_Dispatching.Append
11246                     ((Dispatching_Policy => DP,
11247                       First_Priority     => UI_To_Int (Lower_Val),
11248                       Last_Priority      => UI_To_Int (Upper_Val),
11249                       Pragma_Loc         => Loc));
11250             end if;
11251          end Priority_Specific_Dispatching;
11252
11253          -------------
11254          -- Profile --
11255          -------------
11256
11257          --  pragma Profile (profile_IDENTIFIER);
11258
11259          --  profile_IDENTIFIER => Restricted | Ravenscar
11260
11261          when Pragma_Profile =>
11262             Ada_2005_Pragma;
11263             Check_Arg_Count (1);
11264             Check_Valid_Configuration_Pragma;
11265             Check_No_Identifiers;
11266
11267             declare
11268                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11269             begin
11270                if Chars (Argx) = Name_Ravenscar then
11271                   Set_Ravenscar_Profile (N);
11272                elsif Chars (Argx) = Name_Restricted then
11273                   Set_Profile_Restrictions
11274                     (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11275                else
11276                   Error_Pragma_Arg ("& is not a valid profile", Argx);
11277                end if;
11278             end;
11279
11280          ----------------------
11281          -- Profile_Warnings --
11282          ----------------------
11283
11284          --  pragma Profile_Warnings (profile_IDENTIFIER);
11285
11286          --  profile_IDENTIFIER => Restricted | Ravenscar
11287
11288          when Pragma_Profile_Warnings =>
11289             GNAT_Pragma;
11290             Check_Arg_Count (1);
11291             Check_Valid_Configuration_Pragma;
11292             Check_No_Identifiers;
11293
11294             declare
11295                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11296             begin
11297                if Chars (Argx) = Name_Ravenscar then
11298                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11299                elsif Chars (Argx) = Name_Restricted then
11300                   Set_Profile_Restrictions (Restricted, N, Warn => True);
11301                else
11302                   Error_Pragma_Arg ("& is not a valid profile", Argx);
11303                end if;
11304             end;
11305
11306          --------------------------
11307          -- Propagate_Exceptions --
11308          --------------------------
11309
11310          --  pragma Propagate_Exceptions;
11311
11312          --  Note: this pragma is obsolete and has no effect
11313
11314          when Pragma_Propagate_Exceptions =>
11315             GNAT_Pragma;
11316             Check_Arg_Count (0);
11317
11318             if In_Extended_Main_Source_Unit (N) then
11319                Propagate_Exceptions := True;
11320             end if;
11321
11322          ------------------
11323          -- Psect_Object --
11324          ------------------
11325
11326          --  pragma Psect_Object (
11327          --        [Internal =>] LOCAL_NAME,
11328          --     [, [External =>] EXTERNAL_SYMBOL]
11329          --     [, [Size     =>] EXTERNAL_SYMBOL]);
11330
11331          when Pragma_Psect_Object | Pragma_Common_Object =>
11332          Psect_Object : declare
11333             Args  : Args_List (1 .. 3);
11334             Names : constant Name_List (1 .. 3) := (
11335                       Name_Internal,
11336                       Name_External,
11337                       Name_Size);
11338
11339             Internal : Node_Id renames Args (1);
11340             External : Node_Id renames Args (2);
11341             Size     : Node_Id renames Args (3);
11342
11343             Def_Id : Entity_Id;
11344
11345             procedure Check_Too_Long (Arg : Node_Id);
11346             --  Posts message if the argument is an identifier with more
11347             --  than 31 characters, or a string literal with more than
11348             --  31 characters, and we are operating under VMS
11349
11350             --------------------
11351             -- Check_Too_Long --
11352             --------------------
11353
11354             procedure Check_Too_Long (Arg : Node_Id) is
11355                X : constant Node_Id := Original_Node (Arg);
11356
11357             begin
11358                if not Nkind_In (X, N_String_Literal, N_Identifier) then
11359                   Error_Pragma_Arg
11360                     ("inappropriate argument for pragma %", Arg);
11361                end if;
11362
11363                if OpenVMS_On_Target then
11364                   if (Nkind (X) = N_String_Literal
11365                        and then String_Length (Strval (X)) > 31)
11366                     or else
11367                      (Nkind (X) = N_Identifier
11368                        and then Length_Of_Name (Chars (X)) > 31)
11369                   then
11370                      Error_Pragma_Arg
11371                        ("argument for pragma % is longer than 31 characters",
11372                         Arg);
11373                   end if;
11374                end if;
11375             end Check_Too_Long;
11376
11377          --  Start of processing for Common_Object/Psect_Object
11378
11379          begin
11380             GNAT_Pragma;
11381             Gather_Associations (Names, Args);
11382             Process_Extended_Import_Export_Internal_Arg (Internal);
11383
11384             Def_Id := Entity (Internal);
11385
11386             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11387                Error_Pragma_Arg
11388                  ("pragma% must designate an object", Internal);
11389             end if;
11390
11391             Check_Too_Long (Internal);
11392
11393             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11394                Error_Pragma_Arg
11395                  ("cannot use pragma% for imported/exported object",
11396                   Internal);
11397             end if;
11398
11399             if Is_Concurrent_Type (Etype (Internal)) then
11400                Error_Pragma_Arg
11401                  ("cannot specify pragma % for task/protected object",
11402                   Internal);
11403             end if;
11404
11405             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11406                  or else
11407                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11408             then
11409                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11410             end if;
11411
11412             if Ekind (Def_Id) = E_Constant then
11413                Error_Pragma_Arg
11414                  ("cannot specify pragma % for a constant", Internal);
11415             end if;
11416
11417             if Is_Record_Type (Etype (Internal)) then
11418                declare
11419                   Ent  : Entity_Id;
11420                   Decl : Entity_Id;
11421
11422                begin
11423                   Ent := First_Entity (Etype (Internal));
11424                   while Present (Ent) loop
11425                      Decl := Declaration_Node (Ent);
11426
11427                      if Ekind (Ent) = E_Component
11428                        and then Nkind (Decl) = N_Component_Declaration
11429                        and then Present (Expression (Decl))
11430                        and then Warn_On_Export_Import
11431                      then
11432                         Error_Msg_N
11433                           ("?object for pragma % has defaults", Internal);
11434                         exit;
11435
11436                      else
11437                         Next_Entity (Ent);
11438                      end if;
11439                   end loop;
11440                end;
11441             end if;
11442
11443             if Present (Size) then
11444                Check_Too_Long (Size);
11445             end if;
11446
11447             if Present (External) then
11448                Check_Arg_Is_External_Name (External);
11449                Check_Too_Long (External);
11450             end if;
11451
11452             --  If all error tests pass, link pragma on to the rep item chain
11453
11454             Record_Rep_Item (Def_Id, N);
11455          end Psect_Object;
11456
11457          ----------
11458          -- Pure --
11459          ----------
11460
11461          --  pragma Pure [(library_unit_NAME)];
11462
11463          when Pragma_Pure => Pure : declare
11464             Ent : Entity_Id;
11465
11466          begin
11467             Check_Ada_83_Warning;
11468             Check_Valid_Library_Unit_Pragma;
11469
11470             if Nkind (N) = N_Null_Statement then
11471                return;
11472             end if;
11473
11474             Ent := Find_Lib_Unit_Name;
11475             Set_Is_Pure (Ent);
11476             Set_Has_Pragma_Pure (Ent);
11477             Set_Suppress_Elaboration_Warnings (Ent);
11478          end Pure;
11479
11480          -------------
11481          -- Pure_05 --
11482          -------------
11483
11484          --  pragma Pure_05 [(library_unit_NAME)];
11485
11486          --  This pragma is useable only in GNAT_Mode, where it is used like
11487          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
11488          --  it is ignored). It may be used after a pragma Preelaborate, in
11489          --  which case it overrides the effect of the pragma Preelaborate.
11490          --  This is used to implement AI-362 which recategorizes some run-time
11491          --  packages in Ada 2005 mode.
11492
11493          when Pragma_Pure_05 => Pure_05 : declare
11494             Ent : Entity_Id;
11495
11496          begin
11497             GNAT_Pragma;
11498             Check_Valid_Library_Unit_Pragma;
11499
11500             if not GNAT_Mode then
11501                Error_Pragma ("pragma% only available in GNAT mode");
11502             end if;
11503
11504             if Nkind (N) = N_Null_Statement then
11505                return;
11506             end if;
11507
11508             --  This is one of the few cases where we need to test the value of
11509             --  Ada_Version_Explicit rather than Ada_Version (which is always
11510             --  set to Ada_2012 in a predefined unit), we need to know the
11511             --  explicit version set to know if this pragma is active.
11512
11513             if Ada_Version_Explicit >= Ada_2005 then
11514                Ent := Find_Lib_Unit_Name;
11515                Set_Is_Preelaborated (Ent, False);
11516                Set_Is_Pure (Ent);
11517                Set_Suppress_Elaboration_Warnings (Ent);
11518             end if;
11519          end Pure_05;
11520
11521          -------------------
11522          -- Pure_Function --
11523          -------------------
11524
11525          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11526
11527          when Pragma_Pure_Function => Pure_Function : declare
11528             E_Id      : Node_Id;
11529             E         : Entity_Id;
11530             Def_Id    : Entity_Id;
11531             Effective : Boolean := False;
11532
11533          begin
11534             GNAT_Pragma;
11535             Check_Arg_Count (1);
11536             Check_Optional_Identifier (Arg1, Name_Entity);
11537             Check_Arg_Is_Local_Name (Arg1);
11538             E_Id := Get_Pragma_Arg (Arg1);
11539
11540             if Error_Posted (E_Id) then
11541                return;
11542             end if;
11543
11544             --  Loop through homonyms (overloadings) of referenced entity
11545
11546             E := Entity (E_Id);
11547
11548             if Present (E) then
11549                loop
11550                   Def_Id := Get_Base_Subprogram (E);
11551
11552                   if not Ekind_In (Def_Id, E_Function,
11553                                            E_Generic_Function,
11554                                            E_Operator)
11555                   then
11556                      Error_Pragma_Arg
11557                        ("pragma% requires a function name", Arg1);
11558                   end if;
11559
11560                   Set_Is_Pure (Def_Id, Sense);
11561
11562                   if not Has_Pragma_Pure_Function (Def_Id) then
11563                      Set_Has_Pragma_Pure_Function (Def_Id, Sense);
11564                      Effective := Sense;
11565                   end if;
11566
11567                   exit when From_Aspect_Specification (N);
11568                   E := Homonym (E);
11569                   exit when No (E) or else Scope (E) /= Current_Scope;
11570                end loop;
11571
11572                if Sense and then not Effective
11573                  and then Warn_On_Redundant_Constructs
11574                then
11575                   Error_Msg_NE
11576                     ("pragma Pure_Function on& is redundant?",
11577                      N, Entity (E_Id));
11578                end if;
11579             end if;
11580          end Pure_Function;
11581
11582          --------------------
11583          -- Queuing_Policy --
11584          --------------------
11585
11586          --  pragma Queuing_Policy (policy_IDENTIFIER);
11587
11588          when Pragma_Queuing_Policy => declare
11589             QP : Character;
11590
11591          begin
11592             Check_Ada_83_Warning;
11593             Check_Arg_Count (1);
11594             Check_No_Identifiers;
11595             Check_Arg_Is_Queuing_Policy (Arg1);
11596             Check_Valid_Configuration_Pragma;
11597             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11598             QP := Fold_Upper (Name_Buffer (1));
11599
11600             if Queuing_Policy /= ' '
11601               and then Queuing_Policy /= QP
11602             then
11603                Error_Msg_Sloc := Queuing_Policy_Sloc;
11604                Error_Pragma ("queuing policy incompatible with policy#");
11605
11606             --  Set new policy, but always preserve System_Location since we
11607             --  like the error message with the run time name.
11608
11609             else
11610                Queuing_Policy := QP;
11611
11612                if Queuing_Policy_Sloc /= System_Location then
11613                   Queuing_Policy_Sloc := Loc;
11614                end if;
11615             end if;
11616          end;
11617
11618          -----------------------
11619          -- Relative_Deadline --
11620          -----------------------
11621
11622          --  pragma Relative_Deadline (time_span_EXPRESSION);
11623
11624          when Pragma_Relative_Deadline => Relative_Deadline : declare
11625             P   : constant Node_Id := Parent (N);
11626             Arg : Node_Id;
11627
11628          begin
11629             Ada_2005_Pragma;
11630             Check_No_Identifiers;
11631             Check_Arg_Count (1);
11632
11633             Arg := Get_Pragma_Arg (Arg1);
11634
11635             --  The expression must be analyzed in the special manner described
11636             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
11637
11638             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
11639
11640             --  Subprogram case
11641
11642             if Nkind (P) = N_Subprogram_Body then
11643                Check_In_Main_Program;
11644
11645             --  Tasks
11646
11647             elsif Nkind (P) = N_Task_Definition then
11648                null;
11649
11650             --  Anything else is incorrect
11651
11652             else
11653                Pragma_Misplaced;
11654             end if;
11655
11656             if Has_Relative_Deadline_Pragma (P) then
11657                Error_Pragma ("duplicate pragma% not allowed");
11658             else
11659                Set_Has_Relative_Deadline_Pragma (P, True);
11660
11661                if Nkind (P) = N_Task_Definition then
11662                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11663                end if;
11664             end if;
11665          end Relative_Deadline;
11666
11667          ---------------------------
11668          -- Remote_Call_Interface --
11669          ---------------------------
11670
11671          --  pragma Remote_Call_Interface [(library_unit_NAME)];
11672
11673          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
11674             Cunit_Node : Node_Id;
11675             Cunit_Ent  : Entity_Id;
11676             K          : Node_Kind;
11677
11678          begin
11679             Check_Ada_83_Warning;
11680             Check_Valid_Library_Unit_Pragma;
11681
11682             if Nkind (N) = N_Null_Statement then
11683                return;
11684             end if;
11685
11686             Cunit_Node := Cunit (Current_Sem_Unit);
11687             K          := Nkind (Unit (Cunit_Node));
11688             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
11689
11690             if K = N_Package_Declaration
11691               or else K = N_Generic_Package_Declaration
11692               or else K = N_Subprogram_Declaration
11693               or else K = N_Generic_Subprogram_Declaration
11694               or else (K = N_Subprogram_Body
11695                          and then Acts_As_Spec (Unit (Cunit_Node)))
11696             then
11697                null;
11698             else
11699                Error_Pragma (
11700                  "pragma% must apply to package or subprogram declaration");
11701             end if;
11702
11703             Set_Is_Remote_Call_Interface (Cunit_Ent);
11704          end Remote_Call_Interface;
11705
11706          ------------------
11707          -- Remote_Types --
11708          ------------------
11709
11710          --  pragma Remote_Types [(library_unit_NAME)];
11711
11712          when Pragma_Remote_Types => Remote_Types : declare
11713             Cunit_Node : Node_Id;
11714             Cunit_Ent  : Entity_Id;
11715
11716          begin
11717             Check_Ada_83_Warning;
11718             Check_Valid_Library_Unit_Pragma;
11719
11720             if Nkind (N) = N_Null_Statement then
11721                return;
11722             end if;
11723
11724             Cunit_Node := Cunit (Current_Sem_Unit);
11725             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
11726
11727             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11728                                                 N_Generic_Package_Declaration)
11729             then
11730                Error_Pragma
11731                  ("pragma% can only apply to a package declaration");
11732             end if;
11733
11734             Set_Is_Remote_Types (Cunit_Ent);
11735          end Remote_Types;
11736
11737          ---------------
11738          -- Ravenscar --
11739          ---------------
11740
11741          --  pragma Ravenscar;
11742
11743          when Pragma_Ravenscar =>
11744             GNAT_Pragma;
11745             Check_Arg_Count (0);
11746             Check_Valid_Configuration_Pragma;
11747             Set_Ravenscar_Profile (N);
11748
11749             if Warn_On_Obsolescent_Feature then
11750                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
11751                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
11752             end if;
11753
11754          -------------------------
11755          -- Restricted_Run_Time --
11756          -------------------------
11757
11758          --  pragma Restricted_Run_Time;
11759
11760          when Pragma_Restricted_Run_Time =>
11761             GNAT_Pragma;
11762             Check_Arg_Count (0);
11763             Check_Valid_Configuration_Pragma;
11764             Set_Profile_Restrictions
11765               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11766
11767             if Warn_On_Obsolescent_Feature then
11768                Error_Msg_N
11769                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
11770                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
11771             end if;
11772
11773          ------------------
11774          -- Restrictions --
11775          ------------------
11776
11777          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
11778
11779          --  RESTRICTION ::=
11780          --    restriction_IDENTIFIER
11781          --  | restriction_parameter_IDENTIFIER => EXPRESSION
11782
11783          when Pragma_Restrictions =>
11784             Process_Restrictions_Or_Restriction_Warnings
11785               (Warn => Treat_Restrictions_As_Warnings);
11786
11787          --------------------------
11788          -- Restriction_Warnings --
11789          --------------------------
11790
11791          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
11792
11793          --  RESTRICTION ::=
11794          --    restriction_IDENTIFIER
11795          --  | restriction_parameter_IDENTIFIER => EXPRESSION
11796
11797          when Pragma_Restriction_Warnings =>
11798             GNAT_Pragma;
11799             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
11800
11801          ----------------
11802          -- Reviewable --
11803          ----------------
11804
11805          --  pragma Reviewable;
11806
11807          when Pragma_Reviewable =>
11808             Check_Ada_83_Warning;
11809             Check_Arg_Count (0);
11810
11811             --  Call dummy debugging function rv. This is done to assist front
11812             --  end debugging. By placing a Reviewable pragma in the source
11813             --  program, a breakpoint on rv catches this place in the source,
11814             --  allowing convenient stepping to the point of interest.
11815
11816             rv;
11817
11818          --------------------------
11819          -- Short_Circuit_And_Or --
11820          --------------------------
11821
11822          when Pragma_Short_Circuit_And_Or =>
11823             GNAT_Pragma;
11824             Check_Arg_Count (0);
11825             Check_Valid_Configuration_Pragma;
11826             Short_Circuit_And_Or := True;
11827
11828          -------------------
11829          -- Share_Generic --
11830          -------------------
11831
11832          --  pragma Share_Generic (NAME {, NAME});
11833
11834          when Pragma_Share_Generic =>
11835             GNAT_Pragma;
11836             Process_Generic_List;
11837
11838          ------------
11839          -- Shared --
11840          ------------
11841
11842          --  pragma Shared (LOCAL_NAME);
11843
11844          when Pragma_Shared =>
11845             GNAT_Pragma;
11846             Process_Atomic_Shared_Volatile;
11847
11848          --------------------
11849          -- Shared_Passive --
11850          --------------------
11851
11852          --  pragma Shared_Passive [(library_unit_NAME)];
11853
11854          --  Set the flag Is_Shared_Passive of program unit name entity
11855
11856          when Pragma_Shared_Passive => Shared_Passive : declare
11857             Cunit_Node : Node_Id;
11858             Cunit_Ent  : Entity_Id;
11859
11860          begin
11861             Check_Ada_83_Warning;
11862             Check_Valid_Library_Unit_Pragma;
11863
11864             if Nkind (N) = N_Null_Statement then
11865                return;
11866             end if;
11867
11868             Cunit_Node := Cunit (Current_Sem_Unit);
11869             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
11870
11871             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11872                                                 N_Generic_Package_Declaration)
11873             then
11874                Error_Pragma
11875                  ("pragma% can only apply to a package declaration");
11876             end if;
11877
11878             Set_Is_Shared_Passive (Cunit_Ent);
11879          end Shared_Passive;
11880
11881          -----------------------
11882          -- Short_Descriptors --
11883          -----------------------
11884
11885          --  pragma Short_Descriptors;
11886
11887          when Pragma_Short_Descriptors =>
11888             GNAT_Pragma;
11889             Check_Arg_Count (0);
11890             Check_Valid_Configuration_Pragma;
11891             Short_Descriptors := True;
11892
11893          ----------------------
11894          -- Source_File_Name --
11895          ----------------------
11896
11897          --  There are five forms for this pragma:
11898
11899          --  pragma Source_File_Name (
11900          --    [UNIT_NAME      =>] unit_NAME,
11901          --     BODY_FILE_NAME =>  STRING_LITERAL
11902          --    [, [INDEX =>] INTEGER_LITERAL]);
11903
11904          --  pragma Source_File_Name (
11905          --    [UNIT_NAME      =>] unit_NAME,
11906          --     SPEC_FILE_NAME =>  STRING_LITERAL
11907          --    [, [INDEX =>] INTEGER_LITERAL]);
11908
11909          --  pragma Source_File_Name (
11910          --     BODY_FILE_NAME  => STRING_LITERAL
11911          --  [, DOT_REPLACEMENT => STRING_LITERAL]
11912          --  [, CASING          => CASING_SPEC]);
11913
11914          --  pragma Source_File_Name (
11915          --     SPEC_FILE_NAME  => STRING_LITERAL
11916          --  [, DOT_REPLACEMENT => STRING_LITERAL]
11917          --  [, CASING          => CASING_SPEC]);
11918
11919          --  pragma Source_File_Name (
11920          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
11921          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
11922          --  [, CASING             => CASING_SPEC]);
11923
11924          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
11925
11926          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
11927          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
11928          --  only be used when no project file is used, while SFNP can only be
11929          --  used when a project file is used.
11930
11931          --  No processing here. Processing was completed during parsing, since
11932          --  we need to have file names set as early as possible. Units are
11933          --  loaded well before semantic processing starts.
11934
11935          --  The only processing we defer to this point is the check for
11936          --  correct placement.
11937
11938          when Pragma_Source_File_Name =>
11939             GNAT_Pragma;
11940             Check_Valid_Configuration_Pragma;
11941
11942          ------------------------------
11943          -- Source_File_Name_Project --
11944          ------------------------------
11945
11946          --  See Source_File_Name for syntax
11947
11948          --  No processing here. Processing was completed during parsing, since
11949          --  we need to have file names set as early as possible. Units are
11950          --  loaded well before semantic processing starts.
11951
11952          --  The only processing we defer to this point is the check for
11953          --  correct placement.
11954
11955          when Pragma_Source_File_Name_Project =>
11956             GNAT_Pragma;
11957             Check_Valid_Configuration_Pragma;
11958
11959             --  Check that a pragma Source_File_Name_Project is used only in a
11960             --  configuration pragmas file.
11961
11962             --  Pragmas Source_File_Name_Project should only be generated by
11963             --  the Project Manager in configuration pragmas files.
11964
11965             --  This is really an ugly test. It seems to depend on some
11966             --  accidental and undocumented property. At the very least it
11967             --  needs to be documented, but it would be better to have a
11968             --  clean way of testing if we are in a configuration file???
11969
11970             if Present (Parent (N)) then
11971                Error_Pragma
11972                  ("pragma% can only appear in a configuration pragmas file");
11973             end if;
11974
11975          ----------------------
11976          -- Source_Reference --
11977          ----------------------
11978
11979          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
11980
11981          --  Nothing to do, all processing completed in Par.Prag, since we need
11982          --  the information for possible parser messages that are output.
11983
11984          when Pragma_Source_Reference =>
11985             GNAT_Pragma;
11986
11987          --------------------------------
11988          -- Static_Elaboration_Desired --
11989          --------------------------------
11990
11991          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
11992
11993          when Pragma_Static_Elaboration_Desired =>
11994             GNAT_Pragma;
11995             Check_At_Most_N_Arguments (1);
11996
11997             if Is_Compilation_Unit (Current_Scope)
11998               and then Ekind (Current_Scope) = E_Package
11999             then
12000                Set_Static_Elaboration_Desired (Current_Scope, True);
12001             else
12002                Error_Pragma ("pragma% must apply to a library-level package");
12003             end if;
12004
12005          ------------------
12006          -- Storage_Size --
12007          ------------------
12008
12009          --  pragma Storage_Size (EXPRESSION);
12010
12011          when Pragma_Storage_Size => Storage_Size : declare
12012             P   : constant Node_Id := Parent (N);
12013             Arg : Node_Id;
12014
12015          begin
12016             Check_No_Identifiers;
12017             Check_Arg_Count (1);
12018
12019             --  The expression must be analyzed in the special manner described
12020             --  in "Handling of Default Expressions" in sem.ads.
12021
12022             Arg := Get_Pragma_Arg (Arg1);
12023             Preanalyze_Spec_Expression (Arg, Any_Integer);
12024
12025             if not Is_Static_Expression (Arg) then
12026                Check_Restriction (Static_Storage_Size, Arg);
12027             end if;
12028
12029             if Nkind (P) /= N_Task_Definition then
12030                Pragma_Misplaced;
12031                return;
12032
12033             else
12034                if Has_Storage_Size_Pragma (P) then
12035                   Error_Pragma ("duplicate pragma% not allowed");
12036                else
12037                   Set_Has_Storage_Size_Pragma (P, True);
12038                end if;
12039
12040                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12041                --  ???  exp_ch9 should use this!
12042             end if;
12043          end Storage_Size;
12044
12045          ------------------
12046          -- Storage_Unit --
12047          ------------------
12048
12049          --  pragma Storage_Unit (NUMERIC_LITERAL);
12050
12051          --  Only permitted argument is System'Storage_Unit value
12052
12053          when Pragma_Storage_Unit =>
12054             Check_No_Identifiers;
12055             Check_Arg_Count (1);
12056             Check_Arg_Is_Integer_Literal (Arg1);
12057
12058             if Intval (Get_Pragma_Arg (Arg1)) /=
12059               UI_From_Int (Ttypes.System_Storage_Unit)
12060             then
12061                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12062                Error_Pragma_Arg
12063                  ("the only allowed argument for pragma% is ^", Arg1);
12064             end if;
12065
12066          --------------------
12067          -- Stream_Convert --
12068          --------------------
12069
12070          --  pragma Stream_Convert (
12071          --    [Entity =>] type_LOCAL_NAME,
12072          --    [Read   =>] function_NAME,
12073          --    [Write  =>] function NAME);
12074
12075          when Pragma_Stream_Convert => Stream_Convert : declare
12076
12077             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12078             --  Check that the given argument is the name of a local function
12079             --  of one argument that is not overloaded earlier in the current
12080             --  local scope. A check is also made that the argument is a
12081             --  function with one parameter.
12082
12083             --------------------------------------
12084             -- Check_OK_Stream_Convert_Function --
12085             --------------------------------------
12086
12087             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12088                Ent : Entity_Id;
12089
12090             begin
12091                Check_Arg_Is_Local_Name (Arg);
12092                Ent := Entity (Get_Pragma_Arg (Arg));
12093
12094                if Has_Homonym (Ent) then
12095                   Error_Pragma_Arg
12096                     ("argument for pragma% may not be overloaded", Arg);
12097                end if;
12098
12099                if Ekind (Ent) /= E_Function
12100                  or else No (First_Formal (Ent))
12101                  or else Present (Next_Formal (First_Formal (Ent)))
12102                then
12103                   Error_Pragma_Arg
12104                     ("argument for pragma% must be" &
12105                      " function of one argument", Arg);
12106                end if;
12107             end Check_OK_Stream_Convert_Function;
12108
12109          --  Start of processing for Stream_Convert
12110
12111          begin
12112             GNAT_Pragma;
12113             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12114             Check_Arg_Count (3);
12115             Check_Optional_Identifier (Arg1, Name_Entity);
12116             Check_Optional_Identifier (Arg2, Name_Read);
12117             Check_Optional_Identifier (Arg3, Name_Write);
12118             Check_Arg_Is_Local_Name (Arg1);
12119             Check_OK_Stream_Convert_Function (Arg2);
12120             Check_OK_Stream_Convert_Function (Arg3);
12121
12122             declare
12123                Typ   : constant Entity_Id :=
12124                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12125                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12126                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12127
12128             begin
12129                Check_First_Subtype (Arg1);
12130
12131                --  Check for too early or too late. Note that we don't enforce
12132                --  the rule about primitive operations in this case, since, as
12133                --  is the case for explicit stream attributes themselves, these
12134                --  restrictions are not appropriate. Note that the chaining of
12135                --  the pragma by Rep_Item_Too_Late is actually the critical
12136                --  processing done for this pragma.
12137
12138                if Rep_Item_Too_Early (Typ, N)
12139                     or else
12140                   Rep_Item_Too_Late (Typ, N, FOnly => True)
12141                then
12142                   return;
12143                end if;
12144
12145                --  Return if previous error
12146
12147                if Etype (Typ) = Any_Type
12148                     or else
12149                   Etype (Read) = Any_Type
12150                     or else
12151                   Etype (Write) = Any_Type
12152                then
12153                   return;
12154                end if;
12155
12156                --  Error checks
12157
12158                if Underlying_Type (Etype (Read)) /= Typ then
12159                   Error_Pragma_Arg
12160                     ("incorrect return type for function&", Arg2);
12161                end if;
12162
12163                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12164                   Error_Pragma_Arg
12165                     ("incorrect parameter type for function&", Arg3);
12166                end if;
12167
12168                if Underlying_Type (Etype (First_Formal (Read))) /=
12169                   Underlying_Type (Etype (Write))
12170                then
12171                   Error_Pragma_Arg
12172                     ("result type of & does not match Read parameter type",
12173                      Arg3);
12174                end if;
12175             end;
12176          end Stream_Convert;
12177
12178          -------------------------
12179          -- Style_Checks (GNAT) --
12180          -------------------------
12181
12182          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12183
12184          --  This is processed by the parser since some of the style checks
12185          --  take place during source scanning and parsing. This means that
12186          --  we don't need to issue error messages here.
12187
12188          when Pragma_Style_Checks => Style_Checks : declare
12189             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
12190             S  : String_Id;
12191             C  : Char_Code;
12192
12193          begin
12194             GNAT_Pragma;
12195             Check_No_Identifiers;
12196
12197             --  Two argument form
12198
12199             if Arg_Count = 2 then
12200                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12201
12202                declare
12203                   E_Id : Node_Id;
12204                   E    : Entity_Id;
12205
12206                begin
12207                   E_Id := Get_Pragma_Arg (Arg2);
12208                   Analyze (E_Id);
12209
12210                   if not Is_Entity_Name (E_Id) then
12211                      Error_Pragma_Arg
12212                        ("second argument of pragma% must be entity name",
12213                         Arg2);
12214                   end if;
12215
12216                   E := Entity (E_Id);
12217
12218                   if E = Any_Id then
12219                      return;
12220                   else
12221                      loop
12222                         Set_Suppress_Style_Checks (E,
12223                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12224                         exit when No (Homonym (E));
12225                         E := Homonym (E);
12226                      end loop;
12227                   end if;
12228                end;
12229
12230             --  One argument form
12231
12232             else
12233                Check_Arg_Count (1);
12234
12235                if Nkind (A) = N_String_Literal then
12236                   S   := Strval (A);
12237
12238                   declare
12239                      Slen    : constant Natural := Natural (String_Length (S));
12240                      Options : String (1 .. Slen);
12241                      J       : Natural;
12242
12243                   begin
12244                      J := 1;
12245                      loop
12246                         C := Get_String_Char (S, Int (J));
12247                         exit when not In_Character_Range (C);
12248                         Options (J) := Get_Character (C);
12249
12250                         --  If at end of string, set options. As per discussion
12251                         --  above, no need to check for errors, since we issued
12252                         --  them in the parser.
12253
12254                         if J = Slen then
12255                            Set_Style_Check_Options (Options);
12256                            exit;
12257                         end if;
12258
12259                         J := J + 1;
12260                      end loop;
12261                   end;
12262
12263                elsif Nkind (A) = N_Identifier then
12264                   if Chars (A) = Name_All_Checks then
12265                      if GNAT_Mode then
12266                         Set_GNAT_Style_Check_Options;
12267                      else
12268                         Set_Default_Style_Check_Options;
12269                      end if;
12270
12271                   elsif Chars (A) = Name_On then
12272                      Style_Check := True;
12273
12274                   elsif Chars (A) = Name_Off then
12275                      Style_Check := False;
12276                   end if;
12277                end if;
12278             end if;
12279          end Style_Checks;
12280
12281          --------------
12282          -- Subtitle --
12283          --------------
12284
12285          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12286
12287          when Pragma_Subtitle =>
12288             GNAT_Pragma;
12289             Check_Arg_Count (1);
12290             Check_Optional_Identifier (Arg1, Name_Subtitle);
12291             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12292             Store_Note (N);
12293
12294          --------------
12295          -- Suppress --
12296          --------------
12297
12298          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12299
12300          when Pragma_Suppress =>
12301             Process_Suppress_Unsuppress (True);
12302
12303          ------------------
12304          -- Suppress_All --
12305          ------------------
12306
12307          --  pragma Suppress_All;
12308
12309          --  The only check made here is that the pragma has no arguments.
12310          --  There are no placement rules, and the processing required (setting
12311          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
12312          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
12313          --  then creates and inserts a pragma Suppress (All_Checks).
12314
12315          when Pragma_Suppress_All =>
12316             GNAT_Pragma;
12317             Check_Arg_Count (0);
12318
12319          -------------------------
12320          -- Suppress_Debug_Info --
12321          -------------------------
12322
12323          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12324
12325          when Pragma_Suppress_Debug_Info =>
12326             GNAT_Pragma;
12327             Check_Arg_Count (1);
12328             Check_Optional_Identifier (Arg1, Name_Entity);
12329             Check_Arg_Is_Local_Name (Arg1);
12330             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)), Sense);
12331
12332          ----------------------------------
12333          -- Suppress_Exception_Locations --
12334          ----------------------------------
12335
12336          --  pragma Suppress_Exception_Locations;
12337
12338          when Pragma_Suppress_Exception_Locations =>
12339             GNAT_Pragma;
12340             Check_Arg_Count (0);
12341             Check_Valid_Configuration_Pragma;
12342             Exception_Locations_Suppressed := True;
12343
12344          -----------------------------
12345          -- Suppress_Initialization --
12346          -----------------------------
12347
12348          --  pragma Suppress_Initialization ([Entity =>] type_Name);
12349
12350          when Pragma_Suppress_Initialization => Suppress_Init : declare
12351             E_Id : Node_Id;
12352             E    : Entity_Id;
12353
12354          begin
12355             GNAT_Pragma;
12356             Check_Arg_Count (1);
12357             Check_Optional_Identifier (Arg1, Name_Entity);
12358             Check_Arg_Is_Local_Name (Arg1);
12359
12360             E_Id := Get_Pragma_Arg (Arg1);
12361
12362             if Etype (E_Id) = Any_Type then
12363                return;
12364             end if;
12365
12366             E := Entity (E_Id);
12367
12368             if Is_Type (E) then
12369                if Is_Incomplete_Or_Private_Type (E) then
12370                   if No (Full_View (Base_Type (E))) then
12371                      Error_Pragma_Arg
12372                        ("argument of pragma% cannot be an incomplete type",
12373                          Arg1);
12374                   else
12375                      Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12376                   end if;
12377                else
12378                   Set_Suppress_Init_Proc (Base_Type (E));
12379                end if;
12380
12381             else
12382                Error_Pragma_Arg
12383                  ("pragma% requires argument that is a type name", Arg1);
12384             end if;
12385          end Suppress_Init;
12386
12387          -----------------
12388          -- System_Name --
12389          -----------------
12390
12391          --  pragma System_Name (DIRECT_NAME);
12392
12393          --  Syntax check: one argument, which must be the identifier GNAT or
12394          --  the identifier GCC, no other identifiers are acceptable.
12395
12396          when Pragma_System_Name =>
12397             GNAT_Pragma;
12398             Check_No_Identifiers;
12399             Check_Arg_Count (1);
12400             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12401
12402          -----------------------------
12403          -- Task_Dispatching_Policy --
12404          -----------------------------
12405
12406          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12407
12408          when Pragma_Task_Dispatching_Policy => declare
12409             DP : Character;
12410
12411          begin
12412             Check_Ada_83_Warning;
12413             Check_Arg_Count (1);
12414             Check_No_Identifiers;
12415             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12416             Check_Valid_Configuration_Pragma;
12417             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12418             DP := Fold_Upper (Name_Buffer (1));
12419
12420             if Task_Dispatching_Policy /= ' '
12421               and then Task_Dispatching_Policy /= DP
12422             then
12423                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12424                Error_Pragma
12425                  ("task dispatching policy incompatible with policy#");
12426
12427             --  Set new policy, but always preserve System_Location since we
12428             --  like the error message with the run time name.
12429
12430             else
12431                Task_Dispatching_Policy := DP;
12432
12433                if Task_Dispatching_Policy_Sloc /= System_Location then
12434                   Task_Dispatching_Policy_Sloc := Loc;
12435                end if;
12436             end if;
12437          end;
12438
12439          --------------
12440          -- Task_Info --
12441          --------------
12442
12443          --  pragma Task_Info (EXPRESSION);
12444
12445          when Pragma_Task_Info => Task_Info : declare
12446             P : constant Node_Id := Parent (N);
12447
12448          begin
12449             GNAT_Pragma;
12450
12451             if Nkind (P) /= N_Task_Definition then
12452                Error_Pragma ("pragma% must appear in task definition");
12453             end if;
12454
12455             Check_No_Identifiers;
12456             Check_Arg_Count (1);
12457
12458             Analyze_And_Resolve
12459               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12460
12461             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12462                return;
12463             end if;
12464
12465             if Has_Task_Info_Pragma (P) then
12466                Error_Pragma ("duplicate pragma% not allowed");
12467             else
12468                Set_Has_Task_Info_Pragma (P, True);
12469             end if;
12470          end Task_Info;
12471
12472          ---------------
12473          -- Task_Name --
12474          ---------------
12475
12476          --  pragma Task_Name (string_EXPRESSION);
12477
12478          when Pragma_Task_Name => Task_Name : declare
12479             P   : constant Node_Id := Parent (N);
12480             Arg : Node_Id;
12481
12482          begin
12483             Check_No_Identifiers;
12484             Check_Arg_Count (1);
12485
12486             Arg := Get_Pragma_Arg (Arg1);
12487
12488             --  The expression is used in the call to Create_Task, and must be
12489             --  expanded there, not in the context of the current spec. It must
12490             --  however be analyzed to capture global references, in case it
12491             --  appears in a generic context.
12492
12493             Preanalyze_And_Resolve (Arg, Standard_String);
12494
12495             if Nkind (P) /= N_Task_Definition then
12496                Pragma_Misplaced;
12497             end if;
12498
12499             if Has_Task_Name_Pragma (P) then
12500                Error_Pragma ("duplicate pragma% not allowed");
12501             else
12502                Set_Has_Task_Name_Pragma (P, True);
12503                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12504             end if;
12505          end Task_Name;
12506
12507          ------------------
12508          -- Task_Storage --
12509          ------------------
12510
12511          --  pragma Task_Storage (
12512          --     [Task_Type =>] LOCAL_NAME,
12513          --     [Top_Guard =>] static_integer_EXPRESSION);
12514
12515          when Pragma_Task_Storage => Task_Storage : declare
12516             Args  : Args_List (1 .. 2);
12517             Names : constant Name_List (1 .. 2) := (
12518                       Name_Task_Type,
12519                       Name_Top_Guard);
12520
12521             Task_Type : Node_Id renames Args (1);
12522             Top_Guard : Node_Id renames Args (2);
12523
12524             Ent : Entity_Id;
12525
12526          begin
12527             GNAT_Pragma;
12528             Gather_Associations (Names, Args);
12529
12530             if No (Task_Type) then
12531                Error_Pragma
12532                  ("missing task_type argument for pragma%");
12533             end if;
12534
12535             Check_Arg_Is_Local_Name (Task_Type);
12536
12537             Ent := Entity (Task_Type);
12538
12539             if not Is_Task_Type (Ent) then
12540                Error_Pragma_Arg
12541                  ("argument for pragma% must be task type", Task_Type);
12542             end if;
12543
12544             if No (Top_Guard) then
12545                Error_Pragma_Arg
12546                  ("pragma% takes two arguments", Task_Type);
12547             else
12548                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12549             end if;
12550
12551             Check_First_Subtype (Task_Type);
12552
12553             if Rep_Item_Too_Late (Ent, N) then
12554                raise Pragma_Exit;
12555             end if;
12556          end Task_Storage;
12557
12558          --------------------------
12559          -- Thread_Local_Storage --
12560          --------------------------
12561
12562          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12563
12564          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12565             Id : Node_Id;
12566             E  : Entity_Id;
12567
12568          begin
12569             GNAT_Pragma;
12570             Check_Arg_Count (1);
12571             Check_Optional_Identifier (Arg1, Name_Entity);
12572             Check_Arg_Is_Library_Level_Local_Name (Arg1);
12573
12574             Id := Get_Pragma_Arg (Arg1);
12575             Analyze (Id);
12576
12577             if not Is_Entity_Name (Id)
12578               or else Ekind (Entity (Id)) /= E_Variable
12579             then
12580                Error_Pragma_Arg ("local variable name required", Arg1);
12581             end if;
12582
12583             E := Entity (Id);
12584
12585             if Rep_Item_Too_Early (E, N)
12586               or else Rep_Item_Too_Late (E, N)
12587             then
12588                raise Pragma_Exit;
12589             end if;
12590
12591             Set_Has_Pragma_Thread_Local_Storage (E);
12592             Set_Has_Gigi_Rep_Item (E);
12593          end Thread_Local_Storage;
12594
12595          ----------------
12596          -- Time_Slice --
12597          ----------------
12598
12599          --  pragma Time_Slice (static_duration_EXPRESSION);
12600
12601          when Pragma_Time_Slice => Time_Slice : declare
12602             Val : Ureal;
12603             Nod : Node_Id;
12604
12605          begin
12606             GNAT_Pragma;
12607             Check_Arg_Count (1);
12608             Check_No_Identifiers;
12609             Check_In_Main_Program;
12610             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
12611
12612             if not Error_Posted (Arg1) then
12613                Nod := Next (N);
12614                while Present (Nod) loop
12615                   if Nkind (Nod) = N_Pragma
12616                     and then Pragma_Name (Nod) = Name_Time_Slice
12617                   then
12618                      Error_Msg_Name_1 := Pname;
12619                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
12620                   end if;
12621
12622                   Next (Nod);
12623                end loop;
12624             end if;
12625
12626             --  Process only if in main unit
12627
12628             if Get_Source_Unit (Loc) = Main_Unit then
12629                Opt.Time_Slice_Set := True;
12630                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
12631
12632                if Val <= Ureal_0 then
12633                   Opt.Time_Slice_Value := 0;
12634
12635                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
12636                   Opt.Time_Slice_Value := 1_000_000_000;
12637
12638                else
12639                   Opt.Time_Slice_Value :=
12640                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
12641                end if;
12642             end if;
12643          end Time_Slice;
12644
12645          -----------
12646          -- Title --
12647          -----------
12648
12649          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
12650
12651          --   TITLING_OPTION ::=
12652          --     [Title =>] STRING_LITERAL
12653          --   | [Subtitle =>] STRING_LITERAL
12654
12655          when Pragma_Title => Title : declare
12656             Args  : Args_List (1 .. 2);
12657             Names : constant Name_List (1 .. 2) := (
12658                       Name_Title,
12659                       Name_Subtitle);
12660
12661          begin
12662             GNAT_Pragma;
12663             Gather_Associations (Names, Args);
12664             Store_Note (N);
12665
12666             for J in 1 .. 2 loop
12667                if Present (Args (J)) then
12668                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
12669                end if;
12670             end loop;
12671          end Title;
12672
12673          ---------------------
12674          -- Unchecked_Union --
12675          ---------------------
12676
12677          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
12678
12679          when Pragma_Unchecked_Union => Unchecked_Union : declare
12680             Assoc   : constant Node_Id := Arg1;
12681             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
12682             Typ     : Entity_Id;
12683             Discr   : Entity_Id;
12684             Tdef    : Node_Id;
12685             Clist   : Node_Id;
12686             Vpart   : Node_Id;
12687             Comp    : Node_Id;
12688             Variant : Node_Id;
12689
12690          begin
12691             Ada_2005_Pragma;
12692             Check_No_Identifiers;
12693             Check_Arg_Count (1);
12694             Check_Arg_Is_Local_Name (Arg1);
12695
12696             Find_Type (Type_Id);
12697             Typ := Entity (Type_Id);
12698
12699             if Typ = Any_Type
12700               or else Rep_Item_Too_Early (Typ, N)
12701             then
12702                return;
12703             else
12704                Typ := Underlying_Type (Typ);
12705             end if;
12706
12707             if Rep_Item_Too_Late (Typ, N) then
12708                return;
12709             end if;
12710
12711             Check_First_Subtype (Arg1);
12712
12713             --  Note remaining cases are references to a type in the current
12714             --  declarative part. If we find an error, we post the error on
12715             --  the relevant type declaration at an appropriate point.
12716
12717             if not Is_Record_Type (Typ) then
12718                Error_Msg_N ("Unchecked_Union must be record type", Typ);
12719                return;
12720
12721             elsif Is_Tagged_Type (Typ) then
12722                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
12723                return;
12724
12725             elsif Is_Limited_Type (Typ) then
12726                Error_Msg_N
12727                  ("Unchecked_Union must not be limited record type", Typ);
12728                Explain_Limited_Type (Typ, Typ);
12729                return;
12730
12731             else
12732                if not Has_Discriminants (Typ) then
12733                   Error_Msg_N
12734                     ("Unchecked_Union must have one discriminant", Typ);
12735                   return;
12736                end if;
12737
12738                Discr := First_Discriminant (Typ);
12739                while Present (Discr) loop
12740                   if No (Discriminant_Default_Value (Discr)) then
12741                      Error_Msg_N
12742                        ("Unchecked_Union discriminant must have default value",
12743                         Discr);
12744                   end if;
12745
12746                   Next_Discriminant (Discr);
12747                end loop;
12748
12749                Tdef  := Type_Definition (Declaration_Node (Typ));
12750                Clist := Component_List (Tdef);
12751
12752                Comp := First (Component_Items (Clist));
12753                while Present (Comp) loop
12754                   Check_Component (Comp, Typ);
12755                   Next (Comp);
12756                end loop;
12757
12758                if No (Clist) or else No (Variant_Part (Clist)) then
12759                   Error_Msg_N
12760                     ("Unchecked_Union must have variant part",
12761                      Tdef);
12762                   return;
12763                end if;
12764
12765                Vpart := Variant_Part (Clist);
12766
12767                Variant := First (Variants (Vpart));
12768                while Present (Variant) loop
12769                   Check_Variant (Variant, Typ);
12770                   Next (Variant);
12771                end loop;
12772             end if;
12773
12774             Set_Is_Unchecked_Union  (Typ, Sense);
12775
12776             if Sense then
12777                Set_Convention (Typ, Convention_C);
12778             end if;
12779
12780             Set_Has_Unchecked_Union (Base_Type (Typ), Sense);
12781             Set_Is_Unchecked_Union  (Base_Type (Typ), Sense);
12782          end Unchecked_Union;
12783
12784          ------------------------
12785          -- Unimplemented_Unit --
12786          ------------------------
12787
12788          --  pragma Unimplemented_Unit;
12789
12790          --  Note: this only gives an error if we are generating code, or if
12791          --  we are in a generic library unit (where the pragma appears in the
12792          --  body, not in the spec).
12793
12794          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
12795             Cunitent : constant Entity_Id :=
12796                          Cunit_Entity (Get_Source_Unit (Loc));
12797             Ent_Kind : constant Entity_Kind :=
12798                          Ekind (Cunitent);
12799
12800          begin
12801             GNAT_Pragma;
12802             Check_Arg_Count (0);
12803
12804             if Operating_Mode = Generate_Code
12805               or else Ent_Kind = E_Generic_Function
12806               or else Ent_Kind = E_Generic_Procedure
12807               or else Ent_Kind = E_Generic_Package
12808             then
12809                Get_Name_String (Chars (Cunitent));
12810                Set_Casing (Mixed_Case);
12811                Write_Str (Name_Buffer (1 .. Name_Len));
12812                Write_Str (" is not supported in this configuration");
12813                Write_Eol;
12814                raise Unrecoverable_Error;
12815             end if;
12816          end Unimplemented_Unit;
12817
12818          ------------------------
12819          -- Universal_Aliasing --
12820          ------------------------
12821
12822          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
12823
12824          when Pragma_Universal_Aliasing => Universal_Alias : declare
12825             E_Id : Entity_Id;
12826
12827          begin
12828             GNAT_Pragma;
12829             Check_Arg_Count (1);
12830             Check_Optional_Identifier (Arg2, Name_Entity);
12831             Check_Arg_Is_Local_Name (Arg1);
12832             E_Id := Entity (Get_Pragma_Arg (Arg1));
12833
12834             if E_Id = Any_Type then
12835                return;
12836             elsif No (E_Id) or else not Is_Type (E_Id) then
12837                Error_Pragma_Arg ("pragma% requires type", Arg1);
12838             end if;
12839
12840             Set_Universal_Aliasing (Implementation_Base_Type (E_Id), Sense);
12841          end Universal_Alias;
12842
12843          --------------------
12844          -- Universal_Data --
12845          --------------------
12846
12847          --  pragma Universal_Data [(library_unit_NAME)];
12848
12849          when Pragma_Universal_Data =>
12850             GNAT_Pragma;
12851
12852             --  If this is a configuration pragma, then set the universal
12853             --  addressing option, otherwise confirm that the pragma satisfies
12854             --  the requirements of library unit pragma placement and leave it
12855             --  to the GNAAMP back end to detect the pragma (avoids transitive
12856             --  setting of the option due to withed units).
12857
12858             if Is_Configuration_Pragma then
12859                Universal_Addressing_On_AAMP := True;
12860             else
12861                Check_Valid_Library_Unit_Pragma;
12862             end if;
12863
12864             if not AAMP_On_Target then
12865                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
12866             end if;
12867
12868          ----------------
12869          -- Unmodified --
12870          ----------------
12871
12872          --  pragma Unmodified (local_Name {, local_Name});
12873
12874          when Pragma_Unmodified => Unmodified : declare
12875             Arg_Node : Node_Id;
12876             Arg_Expr : Node_Id;
12877             Arg_Ent  : Entity_Id;
12878
12879          begin
12880             GNAT_Pragma;
12881             Check_At_Least_N_Arguments (1);
12882
12883             --  Loop through arguments
12884
12885             Arg_Node := Arg1;
12886             while Present (Arg_Node) loop
12887                Check_No_Identifier (Arg_Node);
12888
12889                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
12890                --  in fact generate reference, so that the entity will have a
12891                --  reference, which will inhibit any warnings about it not
12892                --  being referenced, and also properly show up in the ali file
12893                --  as a reference. But this reference is recorded before the
12894                --  Has_Pragma_Unreferenced flag is set, so that no warning is
12895                --  generated for this reference.
12896
12897                Check_Arg_Is_Local_Name (Arg_Node);
12898                Arg_Expr := Get_Pragma_Arg (Arg_Node);
12899
12900                if Is_Entity_Name (Arg_Expr) then
12901                   Arg_Ent := Entity (Arg_Expr);
12902
12903                   if not Is_Assignable (Arg_Ent) then
12904                      Error_Pragma_Arg
12905                        ("pragma% can only be applied to a variable",
12906                         Arg_Expr);
12907                   else
12908                      Set_Has_Pragma_Unmodified (Arg_Ent, Sense);
12909                   end if;
12910                end if;
12911
12912                Next (Arg_Node);
12913             end loop;
12914          end Unmodified;
12915
12916          ------------------
12917          -- Unreferenced --
12918          ------------------
12919
12920          --  pragma Unreferenced (local_Name {, local_Name});
12921
12922          --    or when used in a context clause:
12923
12924          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
12925
12926          when Pragma_Unreferenced => Unreferenced : declare
12927             Arg_Node : Node_Id;
12928             Arg_Expr : Node_Id;
12929             Arg_Ent  : Entity_Id;
12930             Citem    : Node_Id;
12931
12932          begin
12933             GNAT_Pragma;
12934             Check_At_Least_N_Arguments (1);
12935
12936             --  Check case of appearing within context clause
12937
12938             if Is_In_Context_Clause then
12939
12940                --  The arguments must all be units mentioned in a with clause
12941                --  in the same context clause. Note we already checked (in
12942                --  Par.Prag) that the arguments are either identifiers or
12943                --  selected components.
12944
12945                Arg_Node := Arg1;
12946                while Present (Arg_Node) loop
12947                   Citem := First (List_Containing (N));
12948                   while Citem /= N loop
12949                      if Nkind (Citem) = N_With_Clause
12950                        and then
12951                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
12952                      then
12953                         Set_Has_Pragma_Unreferenced
12954                           (Cunit_Entity
12955                              (Get_Source_Unit
12956                                 (Library_Unit (Citem))));
12957                         Set_Unit_Name
12958                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
12959                         exit;
12960                      end if;
12961
12962                      Next (Citem);
12963                   end loop;
12964
12965                   if Citem = N then
12966                      Error_Pragma_Arg
12967                        ("argument of pragma% is not with'ed unit", Arg_Node);
12968                   end if;
12969
12970                   Next (Arg_Node);
12971                end loop;
12972
12973             --  Case of not in list of context items
12974
12975             else
12976                Arg_Node := Arg1;
12977                while Present (Arg_Node) loop
12978                   Check_No_Identifier (Arg_Node);
12979
12980                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
12981                   --  will in fact generate reference, so that the entity will
12982                   --  have a reference, which will inhibit any warnings about
12983                   --  it not being referenced, and also properly show up in the
12984                   --  ali file as a reference. But this reference is recorded
12985                   --  before the Has_Pragma_Unreferenced flag is set, so that
12986                   --  no warning is generated for this reference.
12987
12988                   Check_Arg_Is_Local_Name (Arg_Node);
12989                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
12990
12991                   if Is_Entity_Name (Arg_Expr) then
12992                      Arg_Ent := Entity (Arg_Expr);
12993
12994                      --  If the entity is overloaded, the pragma applies to the
12995                      --  most recent overloading, as documented. In this case,
12996                      --  name resolution does not generate a reference, so it
12997                      --  must be done here explicitly.
12998
12999                      if Is_Overloaded (Arg_Expr) then
13000                         Generate_Reference (Arg_Ent, N);
13001                      end if;
13002
13003                      Set_Has_Pragma_Unreferenced (Arg_Ent, Sense);
13004                   end if;
13005
13006                   Next (Arg_Node);
13007                end loop;
13008             end if;
13009          end Unreferenced;
13010
13011          --------------------------
13012          -- Unreferenced_Objects --
13013          --------------------------
13014
13015          --  pragma Unreferenced_Objects (local_Name {, local_Name});
13016
13017          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13018             Arg_Node : Node_Id;
13019             Arg_Expr : Node_Id;
13020
13021          begin
13022             GNAT_Pragma;
13023             Check_At_Least_N_Arguments (1);
13024
13025             Arg_Node := Arg1;
13026             while Present (Arg_Node) loop
13027                Check_No_Identifier (Arg_Node);
13028                Check_Arg_Is_Local_Name (Arg_Node);
13029                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13030
13031                if not Is_Entity_Name (Arg_Expr)
13032                  or else not Is_Type (Entity (Arg_Expr))
13033                then
13034                   Error_Pragma_Arg
13035                     ("argument for pragma% must be type or subtype", Arg_Node);
13036                end if;
13037
13038                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr), Sense);
13039                Next (Arg_Node);
13040             end loop;
13041          end Unreferenced_Objects;
13042
13043          ------------------------------
13044          -- Unreserve_All_Interrupts --
13045          ------------------------------
13046
13047          --  pragma Unreserve_All_Interrupts;
13048
13049          when Pragma_Unreserve_All_Interrupts =>
13050             GNAT_Pragma;
13051             Check_Arg_Count (0);
13052
13053             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13054                Unreserve_All_Interrupts := True;
13055             end if;
13056
13057          ----------------
13058          -- Unsuppress --
13059          ----------------
13060
13061          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13062
13063          when Pragma_Unsuppress =>
13064             Ada_2005_Pragma;
13065             Process_Suppress_Unsuppress (False);
13066
13067          -------------------
13068          -- Use_VADS_Size --
13069          -------------------
13070
13071          --  pragma Use_VADS_Size;
13072
13073          when Pragma_Use_VADS_Size =>
13074             GNAT_Pragma;
13075             Check_Arg_Count (0);
13076             Check_Valid_Configuration_Pragma;
13077             Use_VADS_Size := True;
13078
13079          ---------------------
13080          -- Validity_Checks --
13081          ---------------------
13082
13083          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13084
13085          when Pragma_Validity_Checks => Validity_Checks : declare
13086             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13087             S  : String_Id;
13088             C  : Char_Code;
13089
13090          begin
13091             GNAT_Pragma;
13092             Check_Arg_Count (1);
13093             Check_No_Identifiers;
13094
13095             if Nkind (A) = N_String_Literal then
13096                S   := Strval (A);
13097
13098                declare
13099                   Slen    : constant Natural := Natural (String_Length (S));
13100                   Options : String (1 .. Slen);
13101                   J       : Natural;
13102
13103                begin
13104                   J := 1;
13105                   loop
13106                      C := Get_String_Char (S, Int (J));
13107                      exit when not In_Character_Range (C);
13108                      Options (J) := Get_Character (C);
13109
13110                      if J = Slen then
13111                         Set_Validity_Check_Options (Options);
13112                         exit;
13113                      else
13114                         J := J + 1;
13115                      end if;
13116                   end loop;
13117                end;
13118
13119             elsif Nkind (A) = N_Identifier then
13120
13121                if Chars (A) = Name_All_Checks then
13122                   Set_Validity_Check_Options ("a");
13123
13124                elsif Chars (A) = Name_On then
13125                   Validity_Checks_On := True;
13126
13127                elsif Chars (A) = Name_Off then
13128                   Validity_Checks_On := False;
13129
13130                end if;
13131             end if;
13132          end Validity_Checks;
13133
13134          --------------
13135          -- Volatile --
13136          --------------
13137
13138          --  pragma Volatile (LOCAL_NAME);
13139
13140          when Pragma_Volatile =>
13141             Process_Atomic_Shared_Volatile;
13142
13143          -------------------------
13144          -- Volatile_Components --
13145          -------------------------
13146
13147          --  pragma Volatile_Components (array_LOCAL_NAME);
13148
13149          --  Volatile is handled by the same circuit as Atomic_Components
13150
13151          --------------
13152          -- Warnings --
13153          --------------
13154
13155          --  pragma Warnings (On | Off);
13156          --  pragma Warnings (On | Off, LOCAL_NAME);
13157          --  pragma Warnings (static_string_EXPRESSION);
13158          --  pragma Warnings (On | Off, STRING_LITERAL);
13159
13160          when Pragma_Warnings => Warnings : begin
13161             GNAT_Pragma;
13162             Check_At_Least_N_Arguments (1);
13163             Check_No_Identifiers;
13164
13165             --  If debug flag -gnatd.i is set, pragma is ignored
13166
13167             if Debug_Flag_Dot_I then
13168                return;
13169             end if;
13170
13171             --  Process various forms of the pragma
13172
13173             declare
13174                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13175
13176             begin
13177                --  One argument case
13178
13179                if Arg_Count = 1 then
13180
13181                   --  On/Off one argument case was processed by parser
13182
13183                   if Nkind (Argx) = N_Identifier
13184                     and then
13185                       (Chars (Argx) = Name_On
13186                          or else
13187                        Chars (Argx) = Name_Off)
13188                   then
13189                      null;
13190
13191                   --  One argument case must be ON/OFF or static string expr
13192
13193                   elsif not Is_Static_String_Expression (Arg1) then
13194                      Error_Pragma_Arg
13195                        ("argument of pragma% must be On/Off or " &
13196                         "static string expression", Arg1);
13197
13198                   --  One argument string expression case
13199
13200                   else
13201                      declare
13202                         Lit : constant Node_Id   := Expr_Value_S (Argx);
13203                         Str : constant String_Id := Strval (Lit);
13204                         Len : constant Nat       := String_Length (Str);
13205                         C   : Char_Code;
13206                         J   : Nat;
13207                         OK  : Boolean;
13208                         Chr : Character;
13209
13210                      begin
13211                         J := 1;
13212                         while J <= Len loop
13213                            C := Get_String_Char (Str, J);
13214                            OK := In_Character_Range (C);
13215
13216                            if OK then
13217                               Chr := Get_Character (C);
13218
13219                               --  Dot case
13220
13221                               if J < Len and then Chr = '.' then
13222                                  J := J + 1;
13223                                  C := Get_String_Char (Str, J);
13224                                  Chr := Get_Character (C);
13225
13226                                  if not Set_Dot_Warning_Switch (Chr) then
13227                                     Error_Pragma_Arg
13228                                       ("invalid warning switch character " &
13229                                        '.' & Chr, Arg1);
13230                                  end if;
13231
13232                               --  Non-Dot case
13233
13234                               else
13235                                  OK := Set_Warning_Switch (Chr);
13236                               end if;
13237                            end if;
13238
13239                            if not OK then
13240                               Error_Pragma_Arg
13241                                 ("invalid warning switch character " & Chr,
13242                                  Arg1);
13243                            end if;
13244
13245                            J := J + 1;
13246                         end loop;
13247                      end;
13248                   end if;
13249
13250                   --  Two or more arguments (must be two)
13251
13252                else
13253                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13254                   Check_At_Most_N_Arguments (2);
13255
13256                   declare
13257                      E_Id : Node_Id;
13258                      E    : Entity_Id;
13259                      Err  : Boolean;
13260
13261                   begin
13262                      E_Id := Get_Pragma_Arg (Arg2);
13263                      Analyze (E_Id);
13264
13265                      --  In the expansion of an inlined body, a reference to
13266                      --  the formal may be wrapped in a conversion if the
13267                      --  actual is a conversion. Retrieve the real entity name.
13268
13269                      if (In_Instance_Body
13270                          or else In_Inlined_Body)
13271                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13272                      then
13273                         E_Id := Expression (E_Id);
13274                      end if;
13275
13276                      --  Entity name case
13277
13278                      if Is_Entity_Name (E_Id) then
13279                         E := Entity (E_Id);
13280
13281                         if E = Any_Id then
13282                            return;
13283                         else
13284                            loop
13285                               Set_Warnings_Off
13286                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13287                                                               Name_Off));
13288
13289                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13290                                 and then Warn_On_Warnings_Off
13291                               then
13292                                  Warnings_Off_Pragmas.Append ((N, E));
13293                               end if;
13294
13295                               if Is_Enumeration_Type (E) then
13296                                  declare
13297                                     Lit : Entity_Id;
13298                                  begin
13299                                     Lit := First_Literal (E);
13300                                     while Present (Lit) loop
13301                                        Set_Warnings_Off (Lit);
13302                                        Next_Literal (Lit);
13303                                     end loop;
13304                                  end;
13305                               end if;
13306
13307                               exit when No (Homonym (E));
13308                               E := Homonym (E);
13309                            end loop;
13310                         end if;
13311
13312                      --  Error if not entity or static string literal case
13313
13314                      elsif not Is_Static_String_Expression (Arg2) then
13315                         Error_Pragma_Arg
13316                           ("second argument of pragma% must be entity " &
13317                            "name or static string expression", Arg2);
13318
13319                      --  String literal case
13320
13321                      else
13322                         String_To_Name_Buffer
13323                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13324
13325                         --  Note on configuration pragma case: If this is a
13326                         --  configuration pragma, then for an OFF pragma, we
13327                         --  just set Config True in the call, which is all
13328                         --  that needs to be done. For the case of ON, this
13329                         --  is normally an error, unless it is canceling the
13330                         --  effect of a previous OFF pragma in the same file.
13331                         --  In any other case, an error will be signalled (ON
13332                         --  with no matching OFF).
13333
13334                         if Chars (Argx) = Name_Off then
13335                            Set_Specific_Warning_Off
13336                              (Loc, Name_Buffer (1 .. Name_Len),
13337                               Config => Is_Configuration_Pragma);
13338
13339                         elsif Chars (Argx) = Name_On then
13340                            Set_Specific_Warning_On
13341                              (Loc, Name_Buffer (1 .. Name_Len), Err);
13342
13343                            if Err then
13344                               Error_Msg
13345                                 ("?pragma Warnings On with no " &
13346                                  "matching Warnings Off",
13347                                  Loc);
13348                            end if;
13349                         end if;
13350                      end if;
13351                   end;
13352                end if;
13353             end;
13354          end Warnings;
13355
13356          -------------------
13357          -- Weak_External --
13358          -------------------
13359
13360          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
13361
13362          when Pragma_Weak_External => Weak_External : declare
13363             Ent : Entity_Id;
13364
13365          begin
13366             GNAT_Pragma;
13367             Check_Arg_Count (1);
13368             Check_Optional_Identifier (Arg1, Name_Entity);
13369             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13370             Ent := Entity (Get_Pragma_Arg (Arg1));
13371
13372             if Rep_Item_Too_Early (Ent, N) then
13373                return;
13374             else
13375                Ent := Underlying_Type (Ent);
13376             end if;
13377
13378             --  The only processing required is to link this item on to the
13379             --  list of rep items for the given entity. This is accomplished
13380             --  by the call to Rep_Item_Too_Late (when no error is detected
13381             --  and False is returned).
13382
13383             if Rep_Item_Too_Late (Ent, N) then
13384                return;
13385             else
13386                Set_Has_Gigi_Rep_Item (Ent);
13387             end if;
13388          end Weak_External;
13389
13390          -----------------------------
13391          -- Wide_Character_Encoding --
13392          -----------------------------
13393
13394          --  pragma Wide_Character_Encoding (IDENTIFIER);
13395
13396          when Pragma_Wide_Character_Encoding =>
13397             GNAT_Pragma;
13398
13399             --  Nothing to do, handled in parser. Note that we do not enforce
13400             --  configuration pragma placement, this pragma can appear at any
13401             --  place in the source, allowing mixed encodings within a single
13402             --  source program.
13403
13404             null;
13405
13406          --------------------
13407          -- Unknown_Pragma --
13408          --------------------
13409
13410          --  Should be impossible, since the case of an unknown pragma is
13411          --  separately processed before the case statement is entered.
13412
13413          when Unknown_Pragma =>
13414             raise Program_Error;
13415       end case;
13416
13417       --  AI05-0144: detect dangerous order dependence. Disabled for now,
13418       --  until AI is formally approved.
13419
13420       --  Check_Order_Dependence;
13421
13422    exception
13423       when Pragma_Exit => null;
13424    end Analyze_Pragma;
13425
13426    -------------------
13427    -- Check_Enabled --
13428    -------------------
13429
13430    function Check_Enabled (Nam : Name_Id) return Boolean is
13431       PP : Node_Id;
13432
13433    begin
13434       PP := Opt.Check_Policy_List;
13435       loop
13436          if No (PP) then
13437             return Assertions_Enabled;
13438
13439          elsif
13440            Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
13441          then
13442             case
13443               Chars (Expression (Last (Pragma_Argument_Associations (PP))))
13444             is
13445             when Name_On | Name_Check =>
13446                return True;
13447             when Name_Off | Name_Ignore =>
13448                return False;
13449             when others =>
13450                raise Program_Error;
13451             end case;
13452
13453          else
13454             PP := Next_Pragma (PP);
13455          end if;
13456       end loop;
13457    end Check_Enabled;
13458
13459    ---------------------------------
13460    -- Delay_Config_Pragma_Analyze --
13461    ---------------------------------
13462
13463    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13464    begin
13465       return Pragma_Name (N) = Name_Interrupt_State
13466                or else
13467              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13468    end Delay_Config_Pragma_Analyze;
13469
13470    -------------------------
13471    -- Get_Base_Subprogram --
13472    -------------------------
13473
13474    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13475       Result : Entity_Id;
13476
13477    begin
13478       --  Follow subprogram renaming chain
13479
13480       Result := Def_Id;
13481       while Is_Subprogram (Result)
13482         and then
13483           (Is_Generic_Instance (Result)
13484             or else Nkind (Parent (Declaration_Node (Result))) =
13485                                          N_Subprogram_Renaming_Declaration)
13486         and then Present (Alias (Result))
13487       loop
13488          Result := Alias (Result);
13489       end loop;
13490
13491       return Result;
13492    end Get_Base_Subprogram;
13493
13494    ----------------
13495    -- Initialize --
13496    ----------------
13497
13498    procedure Initialize is
13499    begin
13500       Externals.Init;
13501    end Initialize;
13502
13503    -----------------------------
13504    -- Is_Config_Static_String --
13505    -----------------------------
13506
13507    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13508
13509       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13510       --  This is an internal recursive function that is just like the outer
13511       --  function except that it adds the string to the name buffer rather
13512       --  than placing the string in the name buffer.
13513
13514       ------------------------------
13515       -- Add_Config_Static_String --
13516       ------------------------------
13517
13518       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13519          N : Node_Id;
13520          C : Char_Code;
13521
13522       begin
13523          N := Arg;
13524
13525          if Nkind (N) = N_Op_Concat then
13526             if Add_Config_Static_String (Left_Opnd (N)) then
13527                N := Right_Opnd (N);
13528             else
13529                return False;
13530             end if;
13531          end if;
13532
13533          if Nkind (N) /= N_String_Literal then
13534             Error_Msg_N ("string literal expected for pragma argument", N);
13535             return False;
13536
13537          else
13538             for J in 1 .. String_Length (Strval (N)) loop
13539                C := Get_String_Char (Strval (N), J);
13540
13541                if not In_Character_Range (C) then
13542                   Error_Msg
13543                     ("string literal contains invalid wide character",
13544                      Sloc (N) + 1 + Source_Ptr (J));
13545                   return False;
13546                end if;
13547
13548                Add_Char_To_Name_Buffer (Get_Character (C));
13549             end loop;
13550          end if;
13551
13552          return True;
13553       end Add_Config_Static_String;
13554
13555    --  Start of processing for Is_Config_Static_String
13556
13557    begin
13558
13559       Name_Len := 0;
13560       return Add_Config_Static_String (Arg);
13561    end Is_Config_Static_String;
13562
13563    -----------------------------------------
13564    -- Is_Non_Significant_Pragma_Reference --
13565    -----------------------------------------
13566
13567    --  This function makes use of the following static table which indicates
13568    --  whether a given pragma is significant.
13569
13570    --  -1  indicates that references in any argument position are significant
13571    --  0   indicates that appearence in any argument is not significant
13572    --  +n  indicates that appearence as argument n is significant, but all
13573    --      other arguments are not significant
13574    --  99  special processing required (e.g. for pragma Check)
13575
13576    Sig_Flags : constant array (Pragma_Id) of Int :=
13577      (Pragma_AST_Entry                     => -1,
13578       Pragma_Abort_Defer                   => -1,
13579       Pragma_Ada_83                        => -1,
13580       Pragma_Ada_95                        => -1,
13581       Pragma_Ada_05                        => -1,
13582       Pragma_Ada_2005                      => -1,
13583       Pragma_Ada_12                        => -1,
13584       Pragma_Ada_2012                      => -1,
13585       Pragma_All_Calls_Remote              => -1,
13586       Pragma_Annotate                      => -1,
13587       Pragma_Assert                        => -1,
13588       Pragma_Assertion_Policy              =>  0,
13589       Pragma_Assume_No_Invalid_Values      =>  0,
13590       Pragma_Asynchronous                  => -1,
13591       Pragma_Atomic                        =>  0,
13592       Pragma_Atomic_Components             =>  0,
13593       Pragma_Attach_Handler                => -1,
13594       Pragma_Check                         => 99,
13595       Pragma_Check_Name                    =>  0,
13596       Pragma_Check_Policy                  =>  0,
13597       Pragma_CIL_Constructor               => -1,
13598       Pragma_CPP_Class                     =>  0,
13599       Pragma_CPP_Constructor               =>  0,
13600       Pragma_CPP_Virtual                   =>  0,
13601       Pragma_CPP_Vtable                    =>  0,
13602       Pragma_CPU                           => -1,
13603       Pragma_C_Pass_By_Copy                =>  0,
13604       Pragma_Comment                       =>  0,
13605       Pragma_Common_Object                 => -1,
13606       Pragma_Compile_Time_Error            => -1,
13607       Pragma_Compile_Time_Warning          => -1,
13608       Pragma_Compiler_Unit                 =>  0,
13609       Pragma_Complete_Representation       =>  0,
13610       Pragma_Complex_Representation        =>  0,
13611       Pragma_Component_Alignment           => -1,
13612       Pragma_Controlled                    =>  0,
13613       Pragma_Convention                    =>  0,
13614       Pragma_Convention_Identifier         =>  0,
13615       Pragma_Debug                         => -1,
13616       Pragma_Debug_Policy                  =>  0,
13617       Pragma_Detect_Blocking               => -1,
13618       Pragma_Dimension                     => -1,
13619       Pragma_Discard_Names                 =>  0,
13620       Pragma_Elaborate                     => -1,
13621       Pragma_Elaborate_All                 => -1,
13622       Pragma_Elaborate_Body                => -1,
13623       Pragma_Elaboration_Checks            => -1,
13624       Pragma_Eliminate                     => -1,
13625       Pragma_Export                        => -1,
13626       Pragma_Export_Exception              => -1,
13627       Pragma_Export_Function               => -1,
13628       Pragma_Export_Object                 => -1,
13629       Pragma_Export_Procedure              => -1,
13630       Pragma_Export_Value                  => -1,
13631       Pragma_Export_Valued_Procedure       => -1,
13632       Pragma_Extend_System                 => -1,
13633       Pragma_Extensions_Allowed            => -1,
13634       Pragma_External                      => -1,
13635       Pragma_Favor_Top_Level               => -1,
13636       Pragma_External_Name_Casing          => -1,
13637       Pragma_Fast_Math                     => -1,
13638       Pragma_Finalize_Storage_Only         =>  0,
13639       Pragma_Float_Representation          =>  0,
13640       Pragma_Ident                         => -1,
13641       Pragma_Implemented                   => -1,
13642       Pragma_Implicit_Packing              =>  0,
13643       Pragma_Import                        => +2,
13644       Pragma_Import_Exception              =>  0,
13645       Pragma_Import_Function               =>  0,
13646       Pragma_Import_Object                 =>  0,
13647       Pragma_Import_Procedure              =>  0,
13648       Pragma_Import_Valued_Procedure       =>  0,
13649       Pragma_Independent                   =>  0,
13650       Pragma_Independent_Components        =>  0,
13651       Pragma_Initialize_Scalars            => -1,
13652       Pragma_Inline                        =>  0,
13653       Pragma_Inline_Always                 =>  0,
13654       Pragma_Inline_Generic                =>  0,
13655       Pragma_Inspection_Point              => -1,
13656       Pragma_Interface                     => +2,
13657       Pragma_Interface_Name                => +2,
13658       Pragma_Interrupt_Handler             => -1,
13659       Pragma_Interrupt_Priority            => -1,
13660       Pragma_Interrupt_State               => -1,
13661       Pragma_Java_Constructor              => -1,
13662       Pragma_Java_Interface                => -1,
13663       Pragma_Keep_Names                    =>  0,
13664       Pragma_License                       => -1,
13665       Pragma_Link_With                     => -1,
13666       Pragma_Linker_Alias                  => -1,
13667       Pragma_Linker_Constructor            => -1,
13668       Pragma_Linker_Destructor             => -1,
13669       Pragma_Linker_Options                => -1,
13670       Pragma_Linker_Section                => -1,
13671       Pragma_List                          => -1,
13672       Pragma_Locking_Policy                => -1,
13673       Pragma_Long_Float                    => -1,
13674       Pragma_Machine_Attribute             => -1,
13675       Pragma_Main                          => -1,
13676       Pragma_Main_Storage                  => -1,
13677       Pragma_Memory_Size                   => -1,
13678       Pragma_No_Return                     =>  0,
13679       Pragma_No_Body                       =>  0,
13680       Pragma_No_Run_Time                   => -1,
13681       Pragma_No_Strict_Aliasing            => -1,
13682       Pragma_Normalize_Scalars             => -1,
13683       Pragma_Obsolescent                   =>  0,
13684       Pragma_Optimize                      => -1,
13685       Pragma_Optimize_Alignment            => -1,
13686       Pragma_Ordered                       =>  0,
13687       Pragma_Pack                          =>  0,
13688       Pragma_Page                          => -1,
13689       Pragma_Passive                       => -1,
13690       Pragma_Preelaborable_Initialization  => -1,
13691       Pragma_Polling                       => -1,
13692       Pragma_Persistent_BSS                =>  0,
13693       Pragma_Postcondition                 => -1,
13694       Pragma_Precondition                  => -1,
13695       Pragma_Preelaborate                  => -1,
13696       Pragma_Preelaborate_05               => -1,
13697       Pragma_Priority                      => -1,
13698       Pragma_Priority_Specific_Dispatching => -1,
13699       Pragma_Profile                       =>  0,
13700       Pragma_Profile_Warnings              =>  0,
13701       Pragma_Propagate_Exceptions          => -1,
13702       Pragma_Psect_Object                  => -1,
13703       Pragma_Pure                          => -1,
13704       Pragma_Pure_05                       => -1,
13705       Pragma_Pure_Function                 => -1,
13706       Pragma_Queuing_Policy                => -1,
13707       Pragma_Ravenscar                     => -1,
13708       Pragma_Relative_Deadline             => -1,
13709       Pragma_Remote_Call_Interface         => -1,
13710       Pragma_Remote_Types                  => -1,
13711       Pragma_Restricted_Run_Time           => -1,
13712       Pragma_Restriction_Warnings          => -1,
13713       Pragma_Restrictions                  => -1,
13714       Pragma_Reviewable                    => -1,
13715       Pragma_Short_Circuit_And_Or          => -1,
13716       Pragma_Share_Generic                 => -1,
13717       Pragma_Shared                        => -1,
13718       Pragma_Shared_Passive                => -1,
13719       Pragma_Short_Descriptors             =>  0,
13720       Pragma_Source_File_Name              => -1,
13721       Pragma_Source_File_Name_Project      => -1,
13722       Pragma_Source_Reference              => -1,
13723       Pragma_Storage_Size                  => -1,
13724       Pragma_Storage_Unit                  => -1,
13725       Pragma_Static_Elaboration_Desired    => -1,
13726       Pragma_Stream_Convert                => -1,
13727       Pragma_Style_Checks                  => -1,
13728       Pragma_Subtitle                      => -1,
13729       Pragma_Suppress                      =>  0,
13730       Pragma_Suppress_Exception_Locations  =>  0,
13731       Pragma_Suppress_All                  => -1,
13732       Pragma_Suppress_Debug_Info           =>  0,
13733       Pragma_Suppress_Initialization       =>  0,
13734       Pragma_System_Name                   => -1,
13735       Pragma_Task_Dispatching_Policy       => -1,
13736       Pragma_Task_Info                     => -1,
13737       Pragma_Task_Name                     => -1,
13738       Pragma_Task_Storage                  =>  0,
13739       Pragma_Thread_Local_Storage          =>  0,
13740       Pragma_Time_Slice                    => -1,
13741       Pragma_Title                         => -1,
13742       Pragma_Unchecked_Union               =>  0,
13743       Pragma_Unimplemented_Unit            => -1,
13744       Pragma_Universal_Aliasing            => -1,
13745       Pragma_Universal_Data                => -1,
13746       Pragma_Unmodified                    => -1,
13747       Pragma_Unreferenced                  => -1,
13748       Pragma_Unreferenced_Objects          => -1,
13749       Pragma_Unreserve_All_Interrupts      => -1,
13750       Pragma_Unsuppress                    =>  0,
13751       Pragma_Use_VADS_Size                 => -1,
13752       Pragma_Validity_Checks               => -1,
13753       Pragma_Volatile                      =>  0,
13754       Pragma_Volatile_Components           =>  0,
13755       Pragma_Warnings                      => -1,
13756       Pragma_Weak_External                 => -1,
13757       Pragma_Wide_Character_Encoding       =>  0,
13758       Unknown_Pragma                       =>  0);
13759
13760    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
13761       Id : Pragma_Id;
13762       P  : Node_Id;
13763       C  : Int;
13764       A  : Node_Id;
13765
13766    begin
13767       P := Parent (N);
13768
13769       if Nkind (P) /= N_Pragma_Argument_Association then
13770          return False;
13771
13772       else
13773          Id := Get_Pragma_Id (Parent (P));
13774          C := Sig_Flags (Id);
13775
13776          case C is
13777             when -1 =>
13778                return False;
13779
13780             when 0 =>
13781                return True;
13782
13783             when 99 =>
13784                case Id is
13785
13786                   --  For pragma Check, the first argument is not significant,
13787                   --  the second and the third (if present) arguments are
13788                   --  significant.
13789
13790                   when Pragma_Check =>
13791                      return
13792                        P = First (Pragma_Argument_Associations (Parent (P)));
13793
13794                   when others =>
13795                      raise Program_Error;
13796                end case;
13797
13798             when others =>
13799                A := First (Pragma_Argument_Associations (Parent (P)));
13800                for J in 1 .. C - 1 loop
13801                   if No (A) then
13802                      return False;
13803                   end if;
13804
13805                   Next (A);
13806                end loop;
13807
13808                return A = P; -- is this wrong way round ???
13809          end case;
13810       end if;
13811    end Is_Non_Significant_Pragma_Reference;
13812
13813    ------------------------------
13814    -- Is_Pragma_String_Literal --
13815    ------------------------------
13816
13817    --  This function returns true if the corresponding pragma argument is a
13818    --  static string expression. These are the only cases in which string
13819    --  literals can appear as pragma arguments. We also allow a string literal
13820    --  as the first argument to pragma Assert (although it will of course
13821    --  always generate a type error).
13822
13823    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
13824       Pragn : constant Node_Id := Parent (Par);
13825       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
13826       Pname : constant Name_Id := Pragma_Name (Pragn);
13827       Argn  : Natural;
13828       N     : Node_Id;
13829
13830    begin
13831       Argn := 1;
13832       N := First (Assoc);
13833       loop
13834          exit when N = Par;
13835          Argn := Argn + 1;
13836          Next (N);
13837       end loop;
13838
13839       if Pname = Name_Assert then
13840          return True;
13841
13842       elsif Pname = Name_Export then
13843          return Argn > 2;
13844
13845       elsif Pname = Name_Ident then
13846          return Argn = 1;
13847
13848       elsif Pname = Name_Import then
13849          return Argn > 2;
13850
13851       elsif Pname = Name_Interface_Name then
13852          return Argn > 1;
13853
13854       elsif Pname = Name_Linker_Alias then
13855          return Argn = 2;
13856
13857       elsif Pname = Name_Linker_Section then
13858          return Argn = 2;
13859
13860       elsif Pname = Name_Machine_Attribute then
13861          return Argn = 2;
13862
13863       elsif Pname = Name_Source_File_Name then
13864          return True;
13865
13866       elsif Pname = Name_Source_Reference then
13867          return Argn = 2;
13868
13869       elsif Pname = Name_Title then
13870          return True;
13871
13872       elsif Pname = Name_Subtitle then
13873          return True;
13874
13875       else
13876          return False;
13877       end if;
13878    end Is_Pragma_String_Literal;
13879
13880    --------------------------------------
13881    -- Process_Compilation_Unit_Pragmas --
13882    --------------------------------------
13883
13884    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
13885    begin
13886       --  A special check for pragma Suppress_All, a very strange DEC pragma,
13887       --  strange because it comes at the end of the unit. Rational has the
13888       --  same name for a pragma, but treats it as a program unit pragma, In
13889       --  GNAT we just decide to allow it anywhere at all. If it appeared then
13890       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
13891       --  node, and we insert a pragma Suppress (All_Checks) at the start of
13892       --  the context clause to ensure the correct processing.
13893
13894       if Has_Pragma_Suppress_All (N) then
13895          Prepend_To (Context_Items (N),
13896            Make_Pragma (Sloc (N),
13897              Chars                        => Name_Suppress,
13898              Pragma_Argument_Associations => New_List (
13899                Make_Pragma_Argument_Association (Sloc (N),
13900                  Expression =>
13901                    Make_Identifier (Sloc (N),
13902                      Chars => Name_All_Checks)))));
13903       end if;
13904
13905       --  Nothing else to do at the current time!
13906
13907    end Process_Compilation_Unit_Pragmas;
13908
13909    --------
13910    -- rv --
13911    --------
13912
13913    procedure rv is
13914    begin
13915       null;
13916    end rv;
13917
13918    --------------------------------
13919    -- Set_Encoded_Interface_Name --
13920    --------------------------------
13921
13922    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
13923       Str : constant String_Id := Strval (S);
13924       Len : constant Int       := String_Length (Str);
13925       CC  : Char_Code;
13926       C   : Character;
13927       J   : Int;
13928
13929       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
13930
13931       procedure Encode;
13932       --  Stores encoded value of character code CC. The encoding we use an
13933       --  underscore followed by four lower case hex digits.
13934
13935       ------------
13936       -- Encode --
13937       ------------
13938
13939       procedure Encode is
13940       begin
13941          Store_String_Char (Get_Char_Code ('_'));
13942          Store_String_Char
13943            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
13944          Store_String_Char
13945            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
13946          Store_String_Char
13947            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
13948          Store_String_Char
13949            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
13950       end Encode;
13951
13952    --  Start of processing for Set_Encoded_Interface_Name
13953
13954    begin
13955       --  If first character is asterisk, this is a link name, and we leave it
13956       --  completely unmodified. We also ignore null strings (the latter case
13957       --  happens only in error cases) and no encoding should occur for Java or
13958       --  AAMP interface names.
13959
13960       if Len = 0
13961         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
13962         or else VM_Target /= No_VM
13963         or else AAMP_On_Target
13964       then
13965          Set_Interface_Name (E, S);
13966
13967       else
13968          J := 1;
13969          loop
13970             CC := Get_String_Char (Str, J);
13971
13972             exit when not In_Character_Range (CC);
13973
13974             C := Get_Character (CC);
13975
13976             exit when C /= '_' and then C /= '$'
13977               and then C not in '0' .. '9'
13978               and then C not in 'a' .. 'z'
13979               and then C not in 'A' .. 'Z';
13980
13981             if J = Len then
13982                Set_Interface_Name (E, S);
13983                return;
13984
13985             else
13986                J := J + 1;
13987             end if;
13988          end loop;
13989
13990          --  Here we need to encode. The encoding we use as follows:
13991          --     three underscores  + four hex digits (lower case)
13992
13993          Start_String;
13994
13995          for J in 1 .. String_Length (Str) loop
13996             CC := Get_String_Char (Str, J);
13997
13998             if not In_Character_Range (CC) then
13999                Encode;
14000             else
14001                C := Get_Character (CC);
14002
14003                if C = '_' or else C = '$'
14004                  or else C in '0' .. '9'
14005                  or else C in 'a' .. 'z'
14006                  or else C in 'A' .. 'Z'
14007                then
14008                   Store_String_Char (CC);
14009                else
14010                   Encode;
14011                end if;
14012             end if;
14013          end loop;
14014
14015          Set_Interface_Name (E,
14016            Make_String_Literal (Sloc (S),
14017              Strval => End_String));
14018       end if;
14019    end Set_Encoded_Interface_Name;
14020
14021    -------------------
14022    -- Set_Unit_Name --
14023    -------------------
14024
14025    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14026       Pref : Node_Id;
14027       Scop : Entity_Id;
14028
14029    begin
14030       if Nkind (N) = N_Identifier
14031         and then Nkind (With_Item) = N_Identifier
14032       then
14033          Set_Entity (N, Entity (With_Item));
14034
14035       elsif Nkind (N) = N_Selected_Component then
14036          Change_Selected_Component_To_Expanded_Name (N);
14037          Set_Entity (N, Entity (With_Item));
14038          Set_Entity (Selector_Name (N), Entity (N));
14039
14040          Pref := Prefix (N);
14041          Scop := Scope (Entity (N));
14042          while Nkind (Pref) = N_Selected_Component loop
14043             Change_Selected_Component_To_Expanded_Name (Pref);
14044             Set_Entity (Selector_Name (Pref), Scop);
14045             Set_Entity (Pref, Scop);
14046             Pref := Prefix (Pref);
14047             Scop := Scope (Scop);
14048          end loop;
14049
14050          Set_Entity (Pref, Scop);
14051       end if;
14052    end Set_Unit_Name;
14053
14054 end Sem_Prag;