OSDN Git Service

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