OSDN Git Service

2011-08-02 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ P R A G                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 --  This unit contains the semantic processing for all pragmas, both language
27 --  and implementation defined. For most pragmas, the parser only does the
28 --  most basic job of checking the syntax, so Sem_Prag also contains the code
29 --  to complete the syntax checks. Certain pragmas are handled partially or
30 --  completely by the parser (see Par.Prag for further details).
31
32 with Atree;    use Atree;
33 with Casing;   use Casing;
34 with Checks;   use Checks;
35 with Csets;    use Csets;
36 with Debug;    use Debug;
37 with Einfo;    use Einfo;
38 with Elists;   use Elists;
39 with Errout;   use Errout;
40 with Exp_Ch7;  use Exp_Ch7;
41 with Exp_Dist; use Exp_Dist;
42 with Lib;      use Lib;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists;   use Nlists;
47 with Nmake;    use Nmake;
48 with Opt;      use Opt;
49 with Output;   use Output;
50 with Par_SCO;  use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident;   use Rident;
53 with Rtsfind;  use Rtsfind;
54 with Sem;      use Sem;
55 with Sem_Aux;  use Sem_Aux;
56 with Sem_Ch3;  use Sem_Ch3;
57 with Sem_Ch6;  use Sem_Ch6;
58 with Sem_Ch8;  use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_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                   --  For the pragma case, climb homonym chain. This is
4410                   --  what implements allowing the pragma in the renaming
4411                   --  case, with the result applying to the ancestors.
4412
4413                   if not From_Aspect_Specification (N) then
4414                      while Present (Homonym (Subp))
4415                        and then Scope (Homonym (Subp)) = Current_Scope
4416                      loop
4417                         Make_Inline (Homonym (Subp));
4418                         Subp := Homonym (Subp);
4419                      end loop;
4420                   end if;
4421                end if;
4422             end if;
4423
4424             if not Applies then
4425                Error_Pragma_Arg
4426                  ("inappropriate argument for pragma%", Assoc);
4427
4428             elsif not Effective
4429               and then Warn_On_Redundant_Constructs
4430               and then not Suppress_All_Inlining
4431             then
4432                if Inlining_Not_Possible (Subp) then
4433                   Error_Msg_NE
4434                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4435                else
4436                   Error_Msg_NE
4437                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4438                end if;
4439             end if;
4440
4441             Next (Assoc);
4442          end loop;
4443       end Process_Inline;
4444
4445       ----------------------------
4446       -- Process_Interface_Name --
4447       ----------------------------
4448
4449       procedure Process_Interface_Name
4450         (Subprogram_Def : Entity_Id;
4451          Ext_Arg        : Node_Id;
4452          Link_Arg       : Node_Id)
4453       is
4454          Ext_Nam    : Node_Id;
4455          Link_Nam   : Node_Id;
4456          String_Val : String_Id;
4457
4458          procedure Check_Form_Of_Interface_Name
4459            (SN            : Node_Id;
4460             Ext_Name_Case : Boolean);
4461          --  SN is a string literal node for an interface name. This routine
4462          --  performs some minimal checks that the name is reasonable. In
4463          --  particular that no spaces or other obviously incorrect characters
4464          --  appear. This is only a warning, since any characters are allowed.
4465          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
4466
4467          ----------------------------------
4468          -- Check_Form_Of_Interface_Name --
4469          ----------------------------------
4470
4471          procedure Check_Form_Of_Interface_Name
4472            (SN            : Node_Id;
4473             Ext_Name_Case : Boolean)
4474          is
4475             S  : constant String_Id := Strval (Expr_Value_S (SN));
4476             SL : constant Nat       := String_Length (S);
4477             C  : Char_Code;
4478
4479          begin
4480             if SL = 0 then
4481                Error_Msg_N ("interface name cannot be null string", SN);
4482             end if;
4483
4484             for J in 1 .. SL loop
4485                C := Get_String_Char (S, J);
4486
4487                --  Look for dubious character and issue unconditional warning.
4488                --  Definitely dubious if not in character range.
4489
4490                if not In_Character_Range (C)
4491
4492                   --  For all cases except CLI target,
4493                   --  commas, spaces and slashes are dubious (in CLI, we use
4494                   --  commas and backslashes in external names to specify
4495                   --  assembly version and public key, while slashes and spaces
4496                   --  can be used in names to mark nested classes and
4497                   --  valuetypes).
4498
4499                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4500                              and then (Get_Character (C) = ','
4501                                          or else
4502                                        Get_Character (C) = '\'))
4503                  or else (VM_Target /= CLI_Target
4504                             and then (Get_Character (C) = ' '
4505                                         or else
4506                                       Get_Character (C) = '/'))
4507                then
4508                   Error_Msg
4509                     ("?interface name contains illegal character",
4510                      Sloc (SN) + Source_Ptr (J));
4511                end if;
4512             end loop;
4513          end Check_Form_Of_Interface_Name;
4514
4515       --  Start of processing for Process_Interface_Name
4516
4517       begin
4518          if No (Link_Arg) then
4519             if No (Ext_Arg) then
4520                if VM_Target = CLI_Target
4521                  and then Ekind (Subprogram_Def) = E_Package
4522                  and then Nkind (Parent (Subprogram_Def)) =
4523                                                  N_Package_Specification
4524                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
4525                then
4526                   Set_Interface_Name
4527                      (Subprogram_Def,
4528                       Interface_Name
4529                         (Generic_Parent (Parent (Subprogram_Def))));
4530                end if;
4531
4532                return;
4533
4534             elsif Chars (Ext_Arg) = Name_Link_Name then
4535                Ext_Nam  := Empty;
4536                Link_Nam := Expression (Ext_Arg);
4537
4538             else
4539                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4540                Ext_Nam  := Expression (Ext_Arg);
4541                Link_Nam := Empty;
4542             end if;
4543
4544          else
4545             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
4546             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4547             Ext_Nam  := Expression (Ext_Arg);
4548             Link_Nam := Expression (Link_Arg);
4549          end if;
4550
4551          --  Check expressions for external name and link name are static
4552
4553          if Present (Ext_Nam) then
4554             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4555             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4556
4557             --  Verify that external name is not the name of a local entity,
4558             --  which would hide the imported one and could lead to run-time
4559             --  surprises. The problem can only arise for entities declared in
4560             --  a package body (otherwise the external name is fully qualified
4561             --  and will not conflict).
4562
4563             declare
4564                Nam : Name_Id;
4565                E   : Entity_Id;
4566                Par : Node_Id;
4567
4568             begin
4569                if Prag_Id = Pragma_Import then
4570                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4571                   Nam := Name_Find;
4572                   E   := Entity_Id (Get_Name_Table_Info (Nam));
4573
4574                   if Nam /= Chars (Subprogram_Def)
4575                     and then Present (E)
4576                     and then not Is_Overloadable (E)
4577                     and then Is_Immediately_Visible (E)
4578                     and then not Is_Imported (E)
4579                     and then Ekind (Scope (E)) = E_Package
4580                   then
4581                      Par := Parent (E);
4582                      while Present (Par) loop
4583                         if Nkind (Par) = N_Package_Body then
4584                            Error_Msg_Sloc := Sloc (E);
4585                            Error_Msg_NE
4586                              ("imported entity is hidden by & declared#",
4587                               Ext_Arg, E);
4588                            exit;
4589                         end if;
4590
4591                         Par := Parent (Par);
4592                      end loop;
4593                   end if;
4594                end if;
4595             end;
4596          end if;
4597
4598          if Present (Link_Nam) then
4599             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4600             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4601          end if;
4602
4603          --  If there is no link name, just set the external name
4604
4605          if No (Link_Nam) then
4606             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4607
4608          --  For the Link_Name case, the given literal is preceded by an
4609          --  asterisk, which indicates to GCC that the given name should be
4610          --  taken literally, and in particular that no prepending of
4611          --  underlines should occur, even in systems where this is the
4612          --  normal default.
4613
4614          else
4615             Start_String;
4616
4617             if VM_Target = No_VM then
4618                Store_String_Char (Get_Char_Code ('*'));
4619             end if;
4620
4621             String_Val := Strval (Expr_Value_S (Link_Nam));
4622             Store_String_Chars (String_Val);
4623             Link_Nam :=
4624               Make_String_Literal (Sloc (Link_Nam),
4625                 Strval => End_String);
4626          end if;
4627
4628          Set_Encoded_Interface_Name
4629            (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4630
4631          --  We allow duplicated export names in CIL, as they are always
4632          --  enclosed in a namespace that differentiates them, and overloaded
4633          --  entities are supported by the VM.
4634
4635          if Convention (Subprogram_Def) /= Convention_CIL then
4636             Check_Duplicated_Export_Name (Link_Nam);
4637          end if;
4638       end Process_Interface_Name;
4639
4640       -----------------------------------------
4641       -- Process_Interrupt_Or_Attach_Handler --
4642       -----------------------------------------
4643
4644       procedure Process_Interrupt_Or_Attach_Handler is
4645          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
4646          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4647          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
4648
4649       begin
4650          Set_Is_Interrupt_Handler (Handler_Proc);
4651
4652          --  If the pragma is not associated with a handler procedure within a
4653          --  protected type, then it must be for a nonprotected procedure for
4654          --  the AAMP target, in which case we don't associate a representation
4655          --  item with the procedure's scope.
4656
4657          if Ekind (Proc_Scope) = E_Protected_Type then
4658             if Prag_Id = Pragma_Interrupt_Handler
4659                  or else
4660                Prag_Id = Pragma_Attach_Handler
4661             then
4662                Record_Rep_Item (Proc_Scope, N);
4663             end if;
4664          end if;
4665       end Process_Interrupt_Or_Attach_Handler;
4666
4667       --------------------------------------------------
4668       -- Process_Restrictions_Or_Restriction_Warnings --
4669       --------------------------------------------------
4670
4671       --  Note: some of the simple identifier cases were handled in par-prag,
4672       --  but it is harmless (and more straightforward) to simply handle all
4673       --  cases here, even if it means we repeat a bit of work in some cases.
4674
4675       procedure Process_Restrictions_Or_Restriction_Warnings
4676         (Warn : Boolean)
4677       is
4678          Arg   : Node_Id;
4679          R_Id  : Restriction_Id;
4680          Id    : Name_Id;
4681          Expr  : Node_Id;
4682          Val   : Uint;
4683
4684          procedure Check_Unit_Name (N : Node_Id);
4685          --  Checks unit name parameter for No_Dependence. Returns if it has
4686          --  an appropriate form, otherwise raises pragma argument error.
4687
4688          ---------------------
4689          -- Check_Unit_Name --
4690          ---------------------
4691
4692          procedure Check_Unit_Name (N : Node_Id) is
4693          begin
4694             if Nkind (N) = N_Selected_Component then
4695                Check_Unit_Name (Prefix (N));
4696                Check_Unit_Name (Selector_Name (N));
4697
4698             elsif Nkind (N) = N_Identifier then
4699                return;
4700
4701             else
4702                Error_Pragma_Arg
4703                  ("wrong form for unit name for No_Dependence", N);
4704             end if;
4705          end Check_Unit_Name;
4706
4707       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
4708
4709       begin
4710          --  Ignore all Restrictions pragma in CodePeer mode
4711
4712          if CodePeer_Mode then
4713             return;
4714          end if;
4715
4716          Check_Ada_83_Warning;
4717          Check_At_Least_N_Arguments (1);
4718          Check_Valid_Configuration_Pragma;
4719
4720          Arg := Arg1;
4721          while Present (Arg) loop
4722             Id := Chars (Arg);
4723             Expr := Get_Pragma_Arg (Arg);
4724
4725             --  Case of no restriction identifier present
4726
4727             if Id = No_Name then
4728                if Nkind (Expr) /= N_Identifier then
4729                   Error_Pragma_Arg
4730                     ("invalid form for restriction", Arg);
4731                end if;
4732
4733                R_Id :=
4734                  Get_Restriction_Id
4735                    (Process_Restriction_Synonyms (Expr));
4736
4737                if R_Id not in All_Boolean_Restrictions then
4738                   Error_Msg_Name_1 := Pname;
4739                   Error_Msg_N
4740                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4741
4742                   --  Check for possible misspelling
4743
4744                   for J in Restriction_Id loop
4745                      declare
4746                         Rnm : constant String := Restriction_Id'Image (J);
4747
4748                      begin
4749                         Name_Buffer (1 .. Rnm'Length) := Rnm;
4750                         Name_Len := Rnm'Length;
4751                         Set_Casing (All_Lower_Case);
4752
4753                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4754                            Set_Casing
4755                              (Identifier_Casing (Current_Source_File));
4756                            Error_Msg_String (1 .. Rnm'Length) :=
4757                              Name_Buffer (1 .. Name_Len);
4758                            Error_Msg_Strlen := Rnm'Length;
4759                            Error_Msg_N -- CODEFIX
4760                              ("\possible misspelling of ""~""",
4761                               Get_Pragma_Arg (Arg));
4762                            exit;
4763                         end if;
4764                      end;
4765                   end loop;
4766
4767                   raise Pragma_Exit;
4768                end if;
4769
4770                if Implementation_Restriction (R_Id) then
4771                   Check_Restriction (No_Implementation_Restrictions, Arg);
4772                end if;
4773
4774                --  If this is a warning, then set the warning unless we already
4775                --  have a real restriction active (we never want a warning to
4776                --  override a real restriction).
4777
4778                if Warn then
4779                   if not Restriction_Active (R_Id) then
4780                      Set_Restriction (R_Id, N);
4781                      Restriction_Warnings (R_Id) := True;
4782                   end if;
4783
4784                --  If real restriction case, then set it and make sure that the
4785                --  restriction warning flag is off, since a real restriction
4786                --  always overrides a warning.
4787
4788                else
4789                   Set_Restriction (R_Id, N);
4790                   Restriction_Warnings (R_Id) := False;
4791                end if;
4792
4793                --  Check for obsolescent restrictions in Ada 2005 mode
4794
4795                if not Warn
4796                  and then Ada_Version >= Ada_2005
4797                  and then (R_Id = No_Asynchronous_Control
4798                             or else
4799                            R_Id = No_Unchecked_Deallocation
4800                             or else
4801                            R_Id = No_Unchecked_Conversion)
4802                then
4803                   Check_Restriction (No_Obsolescent_Features, N);
4804                end if;
4805
4806                --  A very special case that must be processed here: pragma
4807                --  Restrictions (No_Exceptions) turns off all run-time
4808                --  checking. This is a bit dubious in terms of the formal
4809                --  language definition, but it is what is intended by RM
4810                --  H.4(12). Restriction_Warnings never affects generated code
4811                --  so this is done only in the real restriction case.
4812
4813                if R_Id = No_Exceptions and then not Warn then
4814                   Scope_Suppress := (others => True);
4815                end if;
4816
4817             --  Case of No_Dependence => unit-name. Note that the parser
4818             --  already made the necessary entry in the No_Dependence table.
4819
4820             elsif Id = Name_No_Dependence then
4821                Check_Unit_Name (Expr);
4822
4823             --  All other cases of restriction identifier present
4824
4825             else
4826                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4827                Analyze_And_Resolve (Expr, Any_Integer);
4828
4829                if R_Id not in All_Parameter_Restrictions then
4830                   Error_Pragma_Arg
4831                     ("invalid restriction parameter identifier", Arg);
4832
4833                elsif not Is_OK_Static_Expression (Expr) then
4834                   Flag_Non_Static_Expr
4835                     ("value must be static expression!", Expr);
4836                   raise Pragma_Exit;
4837
4838                elsif not Is_Integer_Type (Etype (Expr))
4839                  or else Expr_Value (Expr) < 0
4840                then
4841                   Error_Pragma_Arg
4842                     ("value must be non-negative integer", Arg);
4843                end if;
4844
4845                --  Restriction pragma is active
4846
4847                Val := Expr_Value (Expr);
4848
4849                if not UI_Is_In_Int_Range (Val) then
4850                   Error_Pragma_Arg
4851                     ("pragma ignored, value too large?", Arg);
4852                end if;
4853
4854                --  Warning case. If the real restriction is active, then we
4855                --  ignore the request, since warning never overrides a real
4856                --  restriction. Otherwise we set the proper warning. Note that
4857                --  this circuit sets the warning again if it is already set,
4858                --  which is what we want, since the constant may have changed.
4859
4860                if Warn then
4861                   if not Restriction_Active (R_Id) then
4862                      Set_Restriction
4863                        (R_Id, N, Integer (UI_To_Int (Val)));
4864                      Restriction_Warnings (R_Id) := True;
4865                   end if;
4866
4867                --  Real restriction case, set restriction and make sure warning
4868                --  flag is off since real restriction always overrides warning.
4869
4870                else
4871                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4872                   Restriction_Warnings (R_Id) := False;
4873                end if;
4874             end if;
4875
4876             Next (Arg);
4877          end loop;
4878       end Process_Restrictions_Or_Restriction_Warnings;
4879
4880       ---------------------------------
4881       -- Process_Suppress_Unsuppress --
4882       ---------------------------------
4883
4884       --  Note: this procedure makes entries in the check suppress data
4885       --  structures managed by Sem. See spec of package Sem for full
4886       --  details on how we handle recording of check suppression.
4887
4888       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4889          C    : Check_Id;
4890          E_Id : Node_Id;
4891          E    : Entity_Id;
4892
4893          In_Package_Spec : constant Boolean :=
4894                              Is_Package_Or_Generic_Package (Current_Scope)
4895                                and then not In_Package_Body (Current_Scope);
4896
4897          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4898          --  Used to suppress a single check on the given entity
4899
4900          --------------------------------
4901          -- Suppress_Unsuppress_Echeck --
4902          --------------------------------
4903
4904          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4905          begin
4906             Set_Checks_May_Be_Suppressed (E);
4907
4908             if In_Package_Spec then
4909                Push_Global_Suppress_Stack_Entry
4910                  (Entity   => E,
4911                   Check    => C,
4912                   Suppress => Suppress_Case);
4913
4914             else
4915                Push_Local_Suppress_Stack_Entry
4916                  (Entity   => E,
4917                   Check    => C,
4918                   Suppress => Suppress_Case);
4919             end if;
4920
4921             --  If this is a first subtype, and the base type is distinct,
4922             --  then also set the suppress flags on the base type.
4923
4924             if Is_First_Subtype (E)
4925               and then Etype (E) /= E
4926             then
4927                Suppress_Unsuppress_Echeck (Etype (E), C);
4928             end if;
4929          end Suppress_Unsuppress_Echeck;
4930
4931       --  Start of processing for Process_Suppress_Unsuppress
4932
4933       begin
4934          --  Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
4935          --  we want to generate checks for analysis purposes, as set by -gnatC
4936
4937          if CodePeer_Mode and then Comes_From_Source (N) then
4938             return;
4939          end if;
4940
4941          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
4942          --  declarative part or a package spec (RM 11.5(5)).
4943
4944          if not Is_Configuration_Pragma then
4945             Check_Is_In_Decl_Part_Or_Package_Spec;
4946          end if;
4947
4948          Check_At_Least_N_Arguments (1);
4949          Check_At_Most_N_Arguments (2);
4950          Check_No_Identifier (Arg1);
4951          Check_Arg_Is_Identifier (Arg1);
4952
4953          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
4954
4955          if C = No_Check_Id then
4956             Error_Pragma_Arg
4957               ("argument of pragma% is not valid check name", Arg1);
4958          end if;
4959
4960          if not Suppress_Case
4961            and then (C = All_Checks or else C = Overflow_Check)
4962          then
4963             Opt.Overflow_Checks_Unsuppressed := True;
4964          end if;
4965
4966          if Arg_Count = 1 then
4967
4968             --  Make an entry in the local scope suppress table. This is the
4969             --  table that directly shows the current value of the scope
4970             --  suppress check for any check id value.
4971
4972             if C = All_Checks then
4973
4974                --  For All_Checks, we set all specific predefined checks with
4975                --  the exception of Elaboration_Check, which is handled
4976                --  specially because of not wanting All_Checks to have the
4977                --  effect of deactivating static elaboration order processing.
4978
4979                for J in Scope_Suppress'Range loop
4980                   if J /= Elaboration_Check then
4981                      Scope_Suppress (J) := Suppress_Case;
4982                   end if;
4983                end loop;
4984
4985             --  If not All_Checks, and predefined check, then set appropriate
4986             --  scope entry. Note that we will set Elaboration_Check if this
4987             --  is explicitly specified.
4988
4989             elsif C in Predefined_Check_Id then
4990                Scope_Suppress (C) := Suppress_Case;
4991             end if;
4992
4993             --  Also make an entry in the Local_Entity_Suppress table
4994
4995             Push_Local_Suppress_Stack_Entry
4996               (Entity   => Empty,
4997                Check    => C,
4998                Suppress => Suppress_Case);
4999
5000          --  Case of two arguments present, where the check is suppressed for
5001          --  a specified entity (given as the second argument of the pragma)
5002
5003          else
5004             --  This is obsolescent in Ada 2005 mode
5005
5006             if Ada_Version >= Ada_2005 then
5007                Check_Restriction (No_Obsolescent_Features, Arg2);
5008             end if;
5009
5010             Check_Optional_Identifier (Arg2, Name_On);
5011             E_Id := Get_Pragma_Arg (Arg2);
5012             Analyze (E_Id);
5013
5014             if not Is_Entity_Name (E_Id) then
5015                Error_Pragma_Arg
5016                  ("second argument of pragma% must be entity name", Arg2);
5017             end if;
5018
5019             E := Entity (E_Id);
5020
5021             if E = Any_Id then
5022                return;
5023             end if;
5024
5025             --  Enforce RM 11.5(7) which requires that for a pragma that
5026             --  appears within a package spec, the named entity must be
5027             --  within the package spec. We allow the package name itself
5028             --  to be mentioned since that makes sense, although it is not
5029             --  strictly allowed by 11.5(7).
5030
5031             if In_Package_Spec
5032               and then E /= Current_Scope
5033               and then Scope (E) /= Current_Scope
5034             then
5035                Error_Pragma_Arg
5036                  ("entity in pragma% is not in package spec (RM 11.5(7))",
5037                   Arg2);
5038             end if;
5039
5040             --  Loop through homonyms. As noted below, in the case of a package
5041             --  spec, only homonyms within the package spec are considered.
5042
5043             loop
5044                Suppress_Unsuppress_Echeck (E, C);
5045
5046                if Is_Generic_Instance (E)
5047                  and then Is_Subprogram (E)
5048                  and then Present (Alias (E))
5049                then
5050                   Suppress_Unsuppress_Echeck (Alias (E), C);
5051                end if;
5052
5053                --  Move to next homonym if not aspect spec case
5054
5055                exit when From_Aspect_Specification (N);
5056                E := Homonym (E);
5057                exit when No (E);
5058
5059                --  If we are within a package specification, the pragma only
5060                --  applies to homonyms in the same scope.
5061
5062                exit when In_Package_Spec
5063                  and then Scope (E) /= Current_Scope;
5064             end loop;
5065          end if;
5066       end Process_Suppress_Unsuppress;
5067
5068       ------------------
5069       -- Set_Exported --
5070       ------------------
5071
5072       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5073       begin
5074          if Is_Imported (E) then
5075             Error_Pragma_Arg
5076               ("cannot export entity& that was previously imported", Arg);
5077
5078          elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5079             Error_Pragma_Arg
5080               ("cannot export entity& that has an address clause", Arg);
5081          end if;
5082
5083          Set_Is_Exported (E);
5084
5085          --  Generate a reference for entity explicitly, because the
5086          --  identifier may be overloaded and name resolution will not
5087          --  generate one.
5088
5089          Generate_Reference (E, Arg);
5090
5091          --  Deal with exporting non-library level entity
5092
5093          if not Is_Library_Level_Entity (E) then
5094
5095             --  Not allowed at all for subprograms
5096
5097             if Is_Subprogram (E) then
5098                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5099
5100             --  Otherwise set public and statically allocated
5101
5102             else
5103                Set_Is_Public (E);
5104                Set_Is_Statically_Allocated (E);
5105
5106                --  Warn if the corresponding W flag is set and the pragma comes
5107                --  from source. The latter may not be true e.g. on VMS where we
5108                --  expand export pragmas for exception codes associated with
5109                --  imported or exported exceptions. We do not want to generate
5110                --  a warning for something that the user did not write.
5111
5112                if Warn_On_Export_Import
5113                  and then Comes_From_Source (Arg)
5114                then
5115                   Error_Msg_NE
5116                     ("?& has been made static as a result of Export", Arg, E);
5117                   Error_Msg_N
5118                     ("\this usage is non-standard and non-portable", Arg);
5119                end if;
5120             end if;
5121          end if;
5122
5123          if Warn_On_Export_Import and then Is_Type (E) then
5124             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5125          end if;
5126
5127          if Warn_On_Export_Import and Inside_A_Generic then
5128             Error_Msg_NE
5129               ("all instances of& will have the same external name?", Arg, E);
5130          end if;
5131       end Set_Exported;
5132
5133       ----------------------------------------------
5134       -- Set_Extended_Import_Export_External_Name --
5135       ----------------------------------------------
5136
5137       procedure Set_Extended_Import_Export_External_Name
5138         (Internal_Ent : Entity_Id;
5139          Arg_External : Node_Id)
5140       is
5141          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5142          New_Name : Node_Id;
5143
5144       begin
5145          if No (Arg_External) then
5146             return;
5147          end if;
5148
5149          Check_Arg_Is_External_Name (Arg_External);
5150
5151          if Nkind (Arg_External) = N_String_Literal then
5152             if String_Length (Strval (Arg_External)) = 0 then
5153                return;
5154             else
5155                New_Name := Adjust_External_Name_Case (Arg_External);
5156             end if;
5157
5158          elsif Nkind (Arg_External) = N_Identifier then
5159             New_Name := Get_Default_External_Name (Arg_External);
5160
5161          --  Check_Arg_Is_External_Name should let through only identifiers and
5162          --  string literals or static string expressions (which are folded to
5163          --  string literals).
5164
5165          else
5166             raise Program_Error;
5167          end if;
5168
5169          --  If we already have an external name set (by a prior normal Import
5170          --  or Export pragma), then the external names must match
5171
5172          if Present (Interface_Name (Internal_Ent)) then
5173             Check_Matching_Internal_Names : declare
5174                S1 : constant String_Id := Strval (Old_Name);
5175                S2 : constant String_Id := Strval (New_Name);
5176
5177                procedure Mismatch;
5178                --  Called if names do not match
5179
5180                --------------
5181                -- Mismatch --
5182                --------------
5183
5184                procedure Mismatch is
5185                begin
5186                   Error_Msg_Sloc := Sloc (Old_Name);
5187                   Error_Pragma_Arg
5188                     ("external name does not match that given #",
5189                      Arg_External);
5190                end Mismatch;
5191
5192             --  Start of processing for Check_Matching_Internal_Names
5193
5194             begin
5195                if String_Length (S1) /= String_Length (S2) then
5196                   Mismatch;
5197
5198                else
5199                   for J in 1 .. String_Length (S1) loop
5200                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5201                         Mismatch;
5202                      end if;
5203                   end loop;
5204                end if;
5205             end Check_Matching_Internal_Names;
5206
5207          --  Otherwise set the given name
5208
5209          else
5210             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5211             Check_Duplicated_Export_Name (New_Name);
5212          end if;
5213       end Set_Extended_Import_Export_External_Name;
5214
5215       ------------------
5216       -- Set_Imported --
5217       ------------------
5218
5219       procedure Set_Imported (E : Entity_Id) is
5220       begin
5221          --  Error message if already imported or exported
5222
5223          if Is_Exported (E) or else Is_Imported (E) then
5224
5225             --  Error if being set Exported twice
5226
5227             if Is_Exported (E) then
5228                Error_Msg_NE ("entity& was previously exported", N, E);
5229
5230             --  OK if Import/Interface case
5231
5232             elsif Import_Interface_Present (N) then
5233                goto OK;
5234
5235             --  Error if being set Imported twice
5236
5237             else
5238                Error_Msg_NE ("entity& was previously imported", N, E);
5239             end if;
5240
5241             Error_Msg_Name_1 := Pname;
5242             Error_Msg_N
5243               ("\(pragma% applies to all previous entities)", N);
5244
5245             Error_Msg_Sloc  := Sloc (E);
5246             Error_Msg_NE ("\import not allowed for& declared#", N, E);
5247
5248          --  Here if not previously imported or exported, OK to import
5249
5250          else
5251             Set_Is_Imported (E);
5252
5253             --  If the entity is an object that is not at the library level,
5254             --  then it is statically allocated. We do not worry about objects
5255             --  with address clauses in this context since they are not really
5256             --  imported in the linker sense.
5257
5258             if Is_Object (E)
5259               and then not Is_Library_Level_Entity (E)
5260               and then No (Address_Clause (E))
5261             then
5262                Set_Is_Statically_Allocated (E);
5263             end if;
5264          end if;
5265
5266          <<OK>> null;
5267       end Set_Imported;
5268
5269       -------------------------
5270       -- Set_Mechanism_Value --
5271       -------------------------
5272
5273       --  Note: the mechanism name has not been analyzed (and cannot indeed be
5274       --  analyzed, since it is semantic nonsense), so we get it in the exact
5275       --  form created by the parser.
5276
5277       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5278          Class        : Node_Id;
5279          Param        : Node_Id;
5280          Mech_Name_Id : Name_Id;
5281
5282          procedure Bad_Class;
5283          --  Signal bad descriptor class name
5284
5285          procedure Bad_Mechanism;
5286          --  Signal bad mechanism name
5287
5288          ---------------
5289          -- Bad_Class --
5290          ---------------
5291
5292          procedure Bad_Class is
5293          begin
5294             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5295          end Bad_Class;
5296
5297          -------------------------
5298          -- Bad_Mechanism_Value --
5299          -------------------------
5300
5301          procedure Bad_Mechanism is
5302          begin
5303             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5304          end Bad_Mechanism;
5305
5306       --  Start of processing for Set_Mechanism_Value
5307
5308       begin
5309          if Mechanism (Ent) /= Default_Mechanism then
5310             Error_Msg_NE
5311               ("mechanism for & has already been set", Mech_Name, Ent);
5312          end if;
5313
5314          --  MECHANISM_NAME ::= value | reference | descriptor |
5315          --                     short_descriptor
5316
5317          if Nkind (Mech_Name) = N_Identifier then
5318             if Chars (Mech_Name) = Name_Value then
5319                Set_Mechanism (Ent, By_Copy);
5320                return;
5321
5322             elsif Chars (Mech_Name) = Name_Reference then
5323                Set_Mechanism (Ent, By_Reference);
5324                return;
5325
5326             elsif Chars (Mech_Name) = Name_Descriptor then
5327                Check_VMS (Mech_Name);
5328
5329                --  Descriptor => Short_Descriptor if pragma was given
5330
5331                if Short_Descriptors then
5332                   Set_Mechanism (Ent, By_Short_Descriptor);
5333                else
5334                   Set_Mechanism (Ent, By_Descriptor);
5335                end if;
5336
5337                return;
5338
5339             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5340                Check_VMS (Mech_Name);
5341                Set_Mechanism (Ent, By_Short_Descriptor);
5342                return;
5343
5344             elsif Chars (Mech_Name) = Name_Copy then
5345                Error_Pragma_Arg
5346                  ("bad mechanism name, Value assumed", Mech_Name);
5347
5348             else
5349                Bad_Mechanism;
5350             end if;
5351
5352          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5353          --                     short_descriptor (CLASS_NAME)
5354          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5355
5356          --  Note: this form is parsed as an indexed component
5357
5358          elsif Nkind (Mech_Name) = N_Indexed_Component then
5359             Class := First (Expressions (Mech_Name));
5360
5361             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5362              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5363                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5364              or else Present (Next (Class))
5365             then
5366                Bad_Mechanism;
5367             else
5368                Mech_Name_Id := Chars (Prefix (Mech_Name));
5369
5370                --  Change Descriptor => Short_Descriptor if pragma was given
5371
5372                if Mech_Name_Id = Name_Descriptor
5373                  and then Short_Descriptors
5374                then
5375                   Mech_Name_Id := Name_Short_Descriptor;
5376                end if;
5377             end if;
5378
5379          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5380          --                     short_descriptor (Class => CLASS_NAME)
5381          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5382
5383          --  Note: this form is parsed as a function call
5384
5385          elsif Nkind (Mech_Name) = N_Function_Call then
5386             Param := First (Parameter_Associations (Mech_Name));
5387
5388             if Nkind (Name (Mech_Name)) /= N_Identifier
5389               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5390                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5391               or else Present (Next (Param))
5392               or else No (Selector_Name (Param))
5393               or else Chars (Selector_Name (Param)) /= Name_Class
5394             then
5395                Bad_Mechanism;
5396             else
5397                Class := Explicit_Actual_Parameter (Param);
5398                Mech_Name_Id := Chars (Name (Mech_Name));
5399             end if;
5400
5401          else
5402             Bad_Mechanism;
5403          end if;
5404
5405          --  Fall through here with Class set to descriptor class name
5406
5407          Check_VMS (Mech_Name);
5408
5409          if Nkind (Class) /= N_Identifier then
5410             Bad_Class;
5411
5412          elsif Mech_Name_Id = Name_Descriptor
5413            and then Chars (Class) = Name_UBS
5414          then
5415             Set_Mechanism (Ent, By_Descriptor_UBS);
5416
5417          elsif Mech_Name_Id = Name_Descriptor
5418            and then Chars (Class) = Name_UBSB
5419          then
5420             Set_Mechanism (Ent, By_Descriptor_UBSB);
5421
5422          elsif Mech_Name_Id = Name_Descriptor
5423            and then Chars (Class) = Name_UBA
5424          then
5425             Set_Mechanism (Ent, By_Descriptor_UBA);
5426
5427          elsif Mech_Name_Id = Name_Descriptor
5428            and then Chars (Class) = Name_S
5429          then
5430             Set_Mechanism (Ent, By_Descriptor_S);
5431
5432          elsif Mech_Name_Id = Name_Descriptor
5433            and then Chars (Class) = Name_SB
5434          then
5435             Set_Mechanism (Ent, By_Descriptor_SB);
5436
5437          elsif Mech_Name_Id = Name_Descriptor
5438            and then Chars (Class) = Name_A
5439          then
5440             Set_Mechanism (Ent, By_Descriptor_A);
5441
5442          elsif Mech_Name_Id = Name_Descriptor
5443            and then Chars (Class) = Name_NCA
5444          then
5445             Set_Mechanism (Ent, By_Descriptor_NCA);
5446
5447          elsif Mech_Name_Id = Name_Short_Descriptor
5448            and then Chars (Class) = Name_UBS
5449          then
5450             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5451
5452          elsif Mech_Name_Id = Name_Short_Descriptor
5453            and then Chars (Class) = Name_UBSB
5454          then
5455             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5456
5457          elsif Mech_Name_Id = Name_Short_Descriptor
5458            and then Chars (Class) = Name_UBA
5459          then
5460             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5461
5462          elsif Mech_Name_Id = Name_Short_Descriptor
5463            and then Chars (Class) = Name_S
5464          then
5465             Set_Mechanism (Ent, By_Short_Descriptor_S);
5466
5467          elsif Mech_Name_Id = Name_Short_Descriptor
5468            and then Chars (Class) = Name_SB
5469          then
5470             Set_Mechanism (Ent, By_Short_Descriptor_SB);
5471
5472          elsif Mech_Name_Id = Name_Short_Descriptor
5473            and then Chars (Class) = Name_A
5474          then
5475             Set_Mechanism (Ent, By_Short_Descriptor_A);
5476
5477          elsif Mech_Name_Id = Name_Short_Descriptor
5478            and then Chars (Class) = Name_NCA
5479          then
5480             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5481
5482          else
5483             Bad_Class;
5484          end if;
5485       end Set_Mechanism_Value;
5486
5487       ---------------------------
5488       -- Set_Ravenscar_Profile --
5489       ---------------------------
5490
5491       --  The tasks to be done here are
5492
5493       --    Set required policies
5494
5495       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5496       --      pragma Locking_Policy (Ceiling_Locking)
5497
5498       --    Set Detect_Blocking mode
5499
5500       --    Set required restrictions (see System.Rident for detailed list)
5501
5502       --    Set the No_Dependence rules
5503       --      No_Dependence => Ada.Asynchronous_Task_Control
5504       --      No_Dependence => Ada.Calendar
5505       --      No_Dependence => Ada.Execution_Time.Group_Budget
5506       --      No_Dependence => Ada.Execution_Time.Timers
5507       --      No_Dependence => Ada.Task_Attributes
5508       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
5509
5510       procedure Set_Ravenscar_Profile (N : Node_Id) is
5511          Prefix_Entity   : Entity_Id;
5512          Selector_Entity : Entity_Id;
5513          Prefix_Node     : Node_Id;
5514          Node            : Node_Id;
5515
5516       begin
5517          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5518
5519          if Task_Dispatching_Policy /= ' '
5520            and then Task_Dispatching_Policy /= 'F'
5521          then
5522             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5523             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5524
5525          --  Set the FIFO_Within_Priorities policy, but always preserve
5526          --  System_Location since we like the error message with the run time
5527          --  name.
5528
5529          else
5530             Task_Dispatching_Policy := 'F';
5531
5532             if Task_Dispatching_Policy_Sloc /= System_Location then
5533                Task_Dispatching_Policy_Sloc := Loc;
5534             end if;
5535          end if;
5536
5537          --  pragma Locking_Policy (Ceiling_Locking)
5538
5539          if Locking_Policy /= ' '
5540            and then Locking_Policy /= 'C'
5541          then
5542             Error_Msg_Sloc := Locking_Policy_Sloc;
5543             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5544
5545          --  Set the Ceiling_Locking policy, but preserve System_Location since
5546          --  we like the error message with the run time name.
5547
5548          else
5549             Locking_Policy := 'C';
5550
5551             if Locking_Policy_Sloc /= System_Location then
5552                Locking_Policy_Sloc := Loc;
5553             end if;
5554          end if;
5555
5556          --  pragma Detect_Blocking
5557
5558          Detect_Blocking := True;
5559
5560          --  Set the corresponding restrictions
5561
5562          Set_Profile_Restrictions
5563            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5564
5565          --  Set the No_Dependence restrictions
5566
5567          --  The following No_Dependence restrictions:
5568          --    No_Dependence => Ada.Asynchronous_Task_Control
5569          --    No_Dependence => Ada.Calendar
5570          --    No_Dependence => Ada.Task_Attributes
5571          --  are already set by previous call to Set_Profile_Restrictions.
5572
5573          --  Set the following restrictions which were added to Ada 2005:
5574          --    No_Dependence => Ada.Execution_Time.Group_Budget
5575          --    No_Dependence => Ada.Execution_Time.Timers
5576
5577          if Ada_Version >= Ada_2005 then
5578             Name_Buffer (1 .. 3) := "ada";
5579             Name_Len := 3;
5580
5581             Prefix_Entity := Make_Identifier (Loc, Name_Find);
5582
5583             Name_Buffer (1 .. 14) := "execution_time";
5584             Name_Len := 14;
5585
5586             Selector_Entity := Make_Identifier (Loc, Name_Find);
5587
5588             Prefix_Node :=
5589               Make_Selected_Component
5590                 (Sloc          => Loc,
5591                  Prefix        => Prefix_Entity,
5592                  Selector_Name => Selector_Entity);
5593
5594             Name_Buffer (1 .. 13) := "group_budgets";
5595             Name_Len := 13;
5596
5597             Selector_Entity := Make_Identifier (Loc, Name_Find);
5598
5599             Node :=
5600               Make_Selected_Component
5601                 (Sloc          => Loc,
5602                  Prefix        => Prefix_Node,
5603                  Selector_Name => Selector_Entity);
5604
5605             Set_Restriction_No_Dependence
5606               (Unit    => Node,
5607                Warn    => Treat_Restrictions_As_Warnings,
5608                Profile => Ravenscar);
5609
5610             Name_Buffer (1 .. 6) := "timers";
5611             Name_Len := 6;
5612
5613             Selector_Entity := Make_Identifier (Loc, Name_Find);
5614
5615             Node :=
5616               Make_Selected_Component
5617                 (Sloc          => Loc,
5618                  Prefix        => Prefix_Node,
5619                  Selector_Name => Selector_Entity);
5620
5621             Set_Restriction_No_Dependence
5622               (Unit    => Node,
5623                Warn    => Treat_Restrictions_As_Warnings,
5624                Profile => Ravenscar);
5625          end if;
5626
5627          --  Set the following restrictions which was added to Ada 2012 (see
5628          --  AI-0171):
5629          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
5630
5631          if Ada_Version >= Ada_2012 then
5632             Name_Buffer (1 .. 6) := "system";
5633             Name_Len := 6;
5634
5635             Prefix_Entity := Make_Identifier (Loc, Name_Find);
5636
5637             Name_Buffer (1 .. 15) := "multiprocessors";
5638             Name_Len := 15;
5639
5640             Selector_Entity := Make_Identifier (Loc, Name_Find);
5641
5642             Prefix_Node :=
5643               Make_Selected_Component
5644                 (Sloc          => Loc,
5645                  Prefix        => Prefix_Entity,
5646                  Selector_Name => Selector_Entity);
5647
5648             Name_Buffer (1 .. 19) := "dispatching_domains";
5649             Name_Len := 19;
5650
5651             Selector_Entity := Make_Identifier (Loc, Name_Find);
5652
5653             Node :=
5654               Make_Selected_Component
5655                 (Sloc          => Loc,
5656                  Prefix        => Prefix_Node,
5657                  Selector_Name => Selector_Entity);
5658
5659             Set_Restriction_No_Dependence
5660               (Unit    => Node,
5661                Warn    => Treat_Restrictions_As_Warnings,
5662                Profile => Ravenscar);
5663          end if;
5664       end Set_Ravenscar_Profile;
5665
5666    --  Start of processing for Analyze_Pragma
5667
5668    begin
5669       --  Deal with unrecognized pragma
5670
5671       if not Is_Pragma_Name (Pname) then
5672          if Warn_On_Unrecognized_Pragma then
5673             Error_Msg_Name_1 := Pname;
5674             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5675
5676             for PN in First_Pragma_Name .. Last_Pragma_Name loop
5677                if Is_Bad_Spelling_Of (Pname, PN) then
5678                   Error_Msg_Name_1 := PN;
5679                   Error_Msg_N -- CODEFIX
5680                     ("\?possible misspelling of %!", Pragma_Identifier (N));
5681                   exit;
5682                end if;
5683             end loop;
5684          end if;
5685
5686          return;
5687       end if;
5688
5689       --  Here to start processing for recognized pragma
5690
5691       Prag_Id := Get_Pragma_Id (Pname);
5692
5693       --  Preset arguments
5694
5695       Arg_Count := 0;
5696       Arg1      := Empty;
5697       Arg2      := Empty;
5698       Arg3      := Empty;
5699       Arg4      := Empty;
5700
5701       if Present (Pragma_Argument_Associations (N)) then
5702          Arg_Count := List_Length (Pragma_Argument_Associations (N));
5703          Arg1 := First (Pragma_Argument_Associations (N));
5704
5705          if Present (Arg1) then
5706             Arg2 := Next (Arg1);
5707
5708             if Present (Arg2) then
5709                Arg3 := Next (Arg2);
5710
5711                if Present (Arg3) then
5712                   Arg4 := Next (Arg3);
5713                end if;
5714             end if;
5715          end if;
5716       end if;
5717
5718       --  An enumeration type defines the pragmas that are supported by the
5719       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
5720       --  into the corresponding enumeration value for the following case.
5721
5722       case Prag_Id is
5723
5724          -----------------
5725          -- Abort_Defer --
5726          -----------------
5727
5728          --  pragma Abort_Defer;
5729
5730          when Pragma_Abort_Defer =>
5731             GNAT_Pragma;
5732             Check_Arg_Count (0);
5733
5734             --  The only required semantic processing is to check the
5735             --  placement. This pragma must appear at the start of the
5736             --  statement sequence of a handled sequence of statements.
5737
5738             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5739               or else N /= First (Statements (Parent (N)))
5740             then
5741                Pragma_Misplaced;
5742             end if;
5743
5744          ------------
5745          -- Ada_83 --
5746          ------------
5747
5748          --  pragma Ada_83;
5749
5750          --  Note: this pragma also has some specific processing in Par.Prag
5751          --  because we want to set the Ada version mode during parsing.
5752
5753          when Pragma_Ada_83 =>
5754             GNAT_Pragma;
5755             Check_Arg_Count (0);
5756
5757             --  We really should check unconditionally for proper configuration
5758             --  pragma placement, since we really don't want mixed Ada modes
5759             --  within a single unit, and the GNAT reference manual has always
5760             --  said this was a configuration pragma, but we did not check and
5761             --  are hesitant to add the check now.
5762
5763             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5764             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5765             --  or Ada 2012 mode.
5766
5767             if Ada_Version >= Ada_2005 then
5768                Check_Valid_Configuration_Pragma;
5769             end if;
5770
5771             --  Now set Ada 83 mode
5772
5773             Ada_Version := Ada_83;
5774             Ada_Version_Explicit := Ada_Version;
5775
5776          ------------
5777          -- Ada_95 --
5778          ------------
5779
5780          --  pragma Ada_95;
5781
5782          --  Note: this pragma also has some specific processing in Par.Prag
5783          --  because we want to set the Ada 83 version mode during parsing.
5784
5785          when Pragma_Ada_95 =>
5786             GNAT_Pragma;
5787             Check_Arg_Count (0);
5788
5789             --  We really should check unconditionally for proper configuration
5790             --  pragma placement, since we really don't want mixed Ada modes
5791             --  within a single unit, and the GNAT reference manual has always
5792             --  said this was a configuration pragma, but we did not check and
5793             --  are hesitant to add the check now.
5794
5795             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
5796             --  or Ada 95, so we must check if we are in Ada 2005 mode.
5797
5798             if Ada_Version >= Ada_2005 then
5799                Check_Valid_Configuration_Pragma;
5800             end if;
5801
5802             --  Now set Ada 95 mode
5803
5804             Ada_Version := Ada_95;
5805             Ada_Version_Explicit := Ada_Version;
5806
5807          ---------------------
5808          -- Ada_05/Ada_2005 --
5809          ---------------------
5810
5811          --  pragma Ada_05;
5812          --  pragma Ada_05 (LOCAL_NAME);
5813
5814          --  pragma Ada_2005;
5815          --  pragma Ada_2005 (LOCAL_NAME):
5816
5817          --  Note: these pragmas also have some specific processing in Par.Prag
5818          --  because we want to set the Ada 2005 version mode during parsing.
5819
5820          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5821             E_Id : Node_Id;
5822
5823          begin
5824             GNAT_Pragma;
5825
5826             if Arg_Count = 1 then
5827                Check_Arg_Is_Local_Name (Arg1);
5828                E_Id := Get_Pragma_Arg (Arg1);
5829
5830                if Etype (E_Id) = Any_Type then
5831                   return;
5832                end if;
5833
5834                Set_Is_Ada_2005_Only (Entity (E_Id));
5835
5836             else
5837                Check_Arg_Count (0);
5838
5839                --  For Ada_2005 we unconditionally enforce the documented
5840                --  configuration pragma placement, since we do not want to
5841                --  tolerate mixed modes in a unit involving Ada 2005. That
5842                --  would cause real difficulties for those cases where there
5843                --  are incompatibilities between Ada 95 and Ada 2005.
5844
5845                Check_Valid_Configuration_Pragma;
5846
5847                --  Now set appropriate Ada mode
5848
5849                if Sense then
5850                   Ada_Version := Ada_2005;
5851                else
5852                   Ada_Version := Ada_Version_Default;
5853                end if;
5854
5855                Ada_Version_Explicit := Ada_2005;
5856             end if;
5857          end;
5858
5859          ---------------------
5860          -- Ada_12/Ada_2012 --
5861          ---------------------
5862
5863          --  pragma Ada_12;
5864          --  pragma Ada_12 (LOCAL_NAME);
5865
5866          --  pragma Ada_2012;
5867          --  pragma Ada_2012 (LOCAL_NAME):
5868
5869          --  Note: these pragmas also have some specific processing in Par.Prag
5870          --  because we want to set the Ada 2012 version mode during parsing.
5871
5872          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5873             E_Id : Node_Id;
5874
5875          begin
5876             GNAT_Pragma;
5877
5878             if Arg_Count = 1 then
5879                Check_Arg_Is_Local_Name (Arg1);
5880                E_Id := Get_Pragma_Arg (Arg1);
5881
5882                if Etype (E_Id) = Any_Type then
5883                   return;
5884                end if;
5885
5886                Set_Is_Ada_2012_Only (Entity (E_Id));
5887
5888             else
5889                Check_Arg_Count (0);
5890
5891                --  For Ada_2012 we unconditionally enforce the documented
5892                --  configuration pragma placement, since we do not want to
5893                --  tolerate mixed modes in a unit involving Ada 2012. That
5894                --  would cause real difficulties for those cases where there
5895                --  are incompatibilities between Ada 95 and Ada 2012. We could
5896                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5897
5898                Check_Valid_Configuration_Pragma;
5899
5900                --  Now set appropriate Ada mode
5901
5902                if Sense then
5903                   Ada_Version := Ada_2012;
5904                else
5905                   Ada_Version := Ada_Version_Default;
5906                end if;
5907
5908                Ada_Version_Explicit := Ada_2012;
5909             end if;
5910          end;
5911
5912          ----------------------
5913          -- All_Calls_Remote --
5914          ----------------------
5915
5916          --  pragma All_Calls_Remote [(library_package_NAME)];
5917
5918          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5919             Lib_Entity : Entity_Id;
5920
5921          begin
5922             Check_Ada_83_Warning;
5923             Check_Valid_Library_Unit_Pragma;
5924
5925             if Nkind (N) = N_Null_Statement then
5926                return;
5927             end if;
5928
5929             Lib_Entity := Find_Lib_Unit_Name;
5930
5931             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
5932
5933             if Present (Lib_Entity)
5934               and then not Debug_Flag_U
5935             then
5936                if not Is_Remote_Call_Interface (Lib_Entity) then
5937                   Error_Pragma ("pragma% only apply to rci unit");
5938
5939                --  Set flag for entity of the library unit
5940
5941                else
5942                   Set_Has_All_Calls_Remote (Lib_Entity);
5943                end if;
5944
5945             end if;
5946          end All_Calls_Remote;
5947
5948          --------------
5949          -- Annotate --
5950          --------------
5951
5952          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5953          --  ARG ::= NAME | EXPRESSION
5954
5955          --  The first two arguments are by convention intended to refer to an
5956          --  external tool and a tool-specific function. These arguments are
5957          --  not analyzed.
5958
5959          when Pragma_Annotate => Annotate : begin
5960             GNAT_Pragma;
5961             Check_At_Least_N_Arguments (1);
5962             Check_Arg_Is_Identifier (Arg1);
5963             Check_No_Identifiers;
5964             Store_Note (N);
5965
5966             declare
5967                Arg : Node_Id;
5968                Exp : Node_Id;
5969
5970             begin
5971                --  Second unanalyzed parameter is optional
5972
5973                if No (Arg2) then
5974                   null;
5975                else
5976                   Arg := Next (Arg2);
5977                   while Present (Arg) loop
5978                      Exp := Get_Pragma_Arg (Arg);
5979                      Analyze (Exp);
5980
5981                      if Is_Entity_Name (Exp) then
5982                         null;
5983
5984                      --  For string literals, we assume Standard_String as the
5985                      --  type, unless the string contains wide or wide_wide
5986                      --  characters.
5987
5988                      elsif Nkind (Exp) = N_String_Literal then
5989                         if Has_Wide_Wide_Character (Exp) then
5990                            Resolve (Exp, Standard_Wide_Wide_String);
5991                         elsif Has_Wide_Character (Exp) then
5992                            Resolve (Exp, Standard_Wide_String);
5993                         else
5994                            Resolve (Exp, Standard_String);
5995                         end if;
5996
5997                      elsif Is_Overloaded (Exp) then
5998                            Error_Pragma_Arg
5999                              ("ambiguous argument for pragma%", Exp);
6000
6001                      else
6002                         Resolve (Exp);
6003                      end if;
6004
6005                      Next (Arg);
6006                   end loop;
6007                end if;
6008             end;
6009          end Annotate;
6010
6011          ------------
6012          -- Assert --
6013          ------------
6014
6015          --  pragma Assert ([Check =>] Boolean_EXPRESSION
6016          --                 [, [Message =>] Static_String_EXPRESSION]);
6017
6018          when Pragma_Assert => Assert : declare
6019             Expr : Node_Id;
6020             Newa : List_Id;
6021
6022          begin
6023             Ada_2005_Pragma;
6024             Check_At_Least_N_Arguments (1);
6025             Check_At_Most_N_Arguments (2);
6026             Check_Arg_Order ((Name_Check, Name_Message));
6027             Check_Optional_Identifier (Arg1, Name_Check);
6028
6029             --  We treat pragma Assert as equivalent to:
6030
6031             --    pragma Check (Assertion, condition [, msg]);
6032
6033             --  So rewrite pragma in this manner, and analyze the result
6034
6035             Expr := Get_Pragma_Arg (Arg1);
6036             Newa := New_List (
6037               Make_Pragma_Argument_Association (Loc,
6038                 Expression => Make_Identifier (Loc, Name_Assertion)),
6039
6040               Make_Pragma_Argument_Association (Sloc (Expr),
6041                 Expression => Expr));
6042
6043             if Arg_Count > 1 then
6044                Check_Optional_Identifier (Arg2, Name_Message);
6045                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6046                Append_To (Newa, Relocate_Node (Arg2));
6047             end if;
6048
6049             Rewrite (N,
6050               Make_Pragma (Loc,
6051                 Chars => Name_Check,
6052                 Pragma_Argument_Associations => Newa));
6053             Analyze (N);
6054          end Assert;
6055
6056          ----------------------
6057          -- Assertion_Policy --
6058          ----------------------
6059
6060          --  pragma Assertion_Policy (Check | Ignore)
6061
6062          when Pragma_Assertion_Policy => Assertion_Policy : declare
6063             Policy : Node_Id;
6064
6065          begin
6066             Ada_2005_Pragma;
6067             Check_Valid_Configuration_Pragma;
6068             Check_Arg_Count (1);
6069             Check_No_Identifiers;
6070             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6071
6072             --  We treat pragma Assertion_Policy as equivalent to:
6073
6074             --    pragma Check_Policy (Assertion, policy)
6075
6076             --  So rewrite the pragma in that manner and link on to the chain
6077             --  of Check_Policy pragmas, marking the pragma as analyzed.
6078
6079             Policy := Get_Pragma_Arg (Arg1);
6080
6081             Rewrite (N,
6082               Make_Pragma (Loc,
6083                 Chars => Name_Check_Policy,
6084
6085                 Pragma_Argument_Associations => New_List (
6086                   Make_Pragma_Argument_Association (Loc,
6087                     Expression => Make_Identifier (Loc, Name_Assertion)),
6088
6089                   Make_Pragma_Argument_Association (Loc,
6090                     Expression =>
6091                       Make_Identifier (Sloc (Policy), Chars (Policy))))));
6092
6093             Set_Analyzed (N);
6094             Set_Next_Pragma (N, Opt.Check_Policy_List);
6095             Opt.Check_Policy_List := N;
6096          end Assertion_Policy;
6097
6098          ------------------------------
6099          -- Assume_No_Invalid_Values --
6100          ------------------------------
6101
6102          --  pragma Assume_No_Invalid_Values (On | Off);
6103
6104          when Pragma_Assume_No_Invalid_Values =>
6105             GNAT_Pragma;
6106             Check_Valid_Configuration_Pragma;
6107             Check_Arg_Count (1);
6108             Check_No_Identifiers;
6109             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6110
6111             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6112                Assume_No_Invalid_Values := True;
6113             else
6114                Assume_No_Invalid_Values := False;
6115             end if;
6116
6117          ---------------
6118          -- AST_Entry --
6119          ---------------
6120
6121          --  pragma AST_Entry (entry_IDENTIFIER);
6122
6123          when Pragma_AST_Entry => AST_Entry : declare
6124             Ent : Node_Id;
6125
6126          begin
6127             GNAT_Pragma;
6128             Check_VMS (N);
6129             Check_Arg_Count (1);
6130             Check_No_Identifiers;
6131             Check_Arg_Is_Local_Name (Arg1);
6132             Ent := Entity (Get_Pragma_Arg (Arg1));
6133
6134             --  Note: the implementation of the AST_Entry pragma could handle
6135             --  the entry family case fine, but for now we are consistent with
6136             --  the DEC rules, and do not allow the pragma, which of course
6137             --  has the effect of also forbidding the attribute.
6138
6139             if Ekind (Ent) /= E_Entry then
6140                Error_Pragma_Arg
6141                  ("pragma% argument must be simple entry name", Arg1);
6142
6143             elsif Is_AST_Entry (Ent) then
6144                Error_Pragma_Arg
6145                  ("duplicate % pragma for entry", Arg1);
6146
6147             elsif Has_Homonym (Ent) then
6148                Error_Pragma_Arg
6149                  ("pragma% argument cannot specify overloaded entry", Arg1);
6150
6151             else
6152                declare
6153                   FF : constant Entity_Id := First_Formal (Ent);
6154
6155                begin
6156                   if Present (FF) then
6157                      if Present (Next_Formal (FF)) then
6158                         Error_Pragma_Arg
6159                           ("entry for pragma% can have only one argument",
6160                            Arg1);
6161
6162                      elsif Parameter_Mode (FF) /= E_In_Parameter then
6163                         Error_Pragma_Arg
6164                           ("entry parameter for pragma% must have mode IN",
6165                            Arg1);
6166                      end if;
6167                   end if;
6168                end;
6169
6170                Set_Is_AST_Entry (Ent);
6171             end if;
6172          end AST_Entry;
6173
6174          ------------------
6175          -- Asynchronous --
6176          ------------------
6177
6178          --  pragma Asynchronous (LOCAL_NAME);
6179
6180          when Pragma_Asynchronous => Asynchronous : declare
6181             Nm     : Entity_Id;
6182             C_Ent  : Entity_Id;
6183             L      : List_Id;
6184             S      : Node_Id;
6185             N      : Node_Id;
6186             Formal : Entity_Id;
6187
6188             procedure Process_Async_Pragma;
6189             --  Common processing for procedure and access-to-procedure case
6190
6191             --------------------------
6192             -- Process_Async_Pragma --
6193             --------------------------
6194
6195             procedure Process_Async_Pragma is
6196             begin
6197                if No (L) then
6198                   Set_Is_Asynchronous (Nm);
6199                   return;
6200                end if;
6201
6202                --  The formals should be of mode IN (RM E.4.1(6))
6203
6204                S := First (L);
6205                while Present (S) loop
6206                   Formal := Defining_Identifier (S);
6207
6208                   if Nkind (Formal) = N_Defining_Identifier
6209                     and then Ekind (Formal) /= E_In_Parameter
6210                   then
6211                      Error_Pragma_Arg
6212                        ("pragma% procedure can only have IN parameter",
6213                         Arg1);
6214                   end if;
6215
6216                   Next (S);
6217                end loop;
6218
6219                Set_Is_Asynchronous (Nm);
6220             end Process_Async_Pragma;
6221
6222          --  Start of processing for pragma Asynchronous
6223
6224          begin
6225             Check_Ada_83_Warning;
6226             Check_No_Identifiers;
6227             Check_Arg_Count (1);
6228             Check_Arg_Is_Local_Name (Arg1);
6229
6230             if Debug_Flag_U then
6231                return;
6232             end if;
6233
6234             C_Ent := Cunit_Entity (Current_Sem_Unit);
6235             Analyze (Get_Pragma_Arg (Arg1));
6236             Nm := Entity (Get_Pragma_Arg (Arg1));
6237
6238             if not Is_Remote_Call_Interface (C_Ent)
6239               and then not Is_Remote_Types (C_Ent)
6240             then
6241                --  This pragma should only appear in an RCI or Remote Types
6242                --  unit (RM E.4.1(4)).
6243
6244                Error_Pragma
6245                  ("pragma% not in Remote_Call_Interface or " &
6246                   "Remote_Types unit");
6247             end if;
6248
6249             if Ekind (Nm) = E_Procedure
6250               and then Nkind (Parent (Nm)) = N_Procedure_Specification
6251             then
6252                if not Is_Remote_Call_Interface (Nm) then
6253                   Error_Pragma_Arg
6254                     ("pragma% cannot be applied on non-remote procedure",
6255                      Arg1);
6256                end if;
6257
6258                L := Parameter_Specifications (Parent (Nm));
6259                Process_Async_Pragma;
6260                return;
6261
6262             elsif Ekind (Nm) = E_Function then
6263                Error_Pragma_Arg
6264                  ("pragma% cannot be applied to function", Arg1);
6265
6266             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6267
6268                   if Is_Record_Type (Nm) then
6269
6270                   --  A record type that is the Equivalent_Type for a remote
6271                   --  access-to-subprogram type.
6272
6273                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
6274
6275                   else
6276                      --  A non-expanded RAS type (distribution is not enabled)
6277
6278                      N := Declaration_Node (Nm);
6279                   end if;
6280
6281                if Nkind (N) = N_Full_Type_Declaration
6282                  and then Nkind (Type_Definition (N)) =
6283                                      N_Access_Procedure_Definition
6284                then
6285                   L := Parameter_Specifications (Type_Definition (N));
6286                   Process_Async_Pragma;
6287
6288                   if Is_Asynchronous (Nm)
6289                     and then Expander_Active
6290                     and then Get_PCS_Name /= Name_No_DSA
6291                   then
6292                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6293                   end if;
6294
6295                else
6296                   Error_Pragma_Arg
6297                     ("pragma% cannot reference access-to-function type",
6298                     Arg1);
6299                end if;
6300
6301             --  Only other possibility is Access-to-class-wide type
6302
6303             elsif Is_Access_Type (Nm)
6304               and then Is_Class_Wide_Type (Designated_Type (Nm))
6305             then
6306                Check_First_Subtype (Arg1);
6307                Set_Is_Asynchronous (Nm);
6308                if Expander_Active then
6309                   RACW_Type_Is_Asynchronous (Nm);
6310                end if;
6311
6312             else
6313                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6314             end if;
6315          end Asynchronous;
6316
6317          ------------
6318          -- Atomic --
6319          ------------
6320
6321          --  pragma Atomic (LOCAL_NAME);
6322
6323          when Pragma_Atomic =>
6324             Process_Atomic_Shared_Volatile;
6325
6326          -----------------------
6327          -- Atomic_Components --
6328          -----------------------
6329
6330          --  pragma Atomic_Components (array_LOCAL_NAME);
6331
6332          --  This processing is shared by Volatile_Components
6333
6334          when Pragma_Atomic_Components   |
6335               Pragma_Volatile_Components =>
6336
6337          Atomic_Components : declare
6338             E_Id : Node_Id;
6339             E    : Entity_Id;
6340             D    : Node_Id;
6341             K    : Node_Kind;
6342
6343          begin
6344             Check_Ada_83_Warning;
6345             Check_No_Identifiers;
6346             Check_Arg_Count (1);
6347             Check_Arg_Is_Local_Name (Arg1);
6348             E_Id := Get_Pragma_Arg (Arg1);
6349
6350             if Etype (E_Id) = Any_Type then
6351                return;
6352             end if;
6353
6354             E := Entity (E_Id);
6355
6356             Check_Duplicate_Pragma (E);
6357
6358             if Rep_Item_Too_Early (E, N)
6359                  or else
6360                Rep_Item_Too_Late (E, N)
6361             then
6362                return;
6363             end if;
6364
6365             D := Declaration_Node (E);
6366             K := Nkind (D);
6367
6368             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6369               or else
6370                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6371                    and then Nkind (D) = N_Object_Declaration
6372                    and then Nkind (Object_Definition (D)) =
6373                                        N_Constrained_Array_Definition)
6374             then
6375                --  The flag is set on the object, or on the base type
6376
6377                if Nkind (D) /= N_Object_Declaration then
6378                   E := Base_Type (E);
6379                end if;
6380
6381                Set_Has_Volatile_Components (E, Sense);
6382
6383                if Prag_Id = Pragma_Atomic_Components then
6384                   Set_Has_Atomic_Components (E, Sense);
6385                end if;
6386
6387             else
6388                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6389             end if;
6390          end Atomic_Components;
6391
6392          --------------------
6393          -- Attach_Handler --
6394          --------------------
6395
6396          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
6397
6398          when Pragma_Attach_Handler =>
6399             Check_Ada_83_Warning;
6400             Check_No_Identifiers;
6401             Check_Arg_Count (2);
6402
6403             if No_Run_Time_Mode then
6404                Error_Msg_CRT ("Attach_Handler pragma", N);
6405             else
6406                Check_Interrupt_Or_Attach_Handler;
6407
6408                --  The expression that designates the attribute may depend on a
6409                --  discriminant, and is therefore a per- object expression, to
6410                --  be expanded in the init proc. If expansion is enabled, then
6411                --  perform semantic checks on a copy only.
6412
6413                if Expander_Active then
6414                   declare
6415                      Temp : constant Node_Id :=
6416                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
6417                   begin
6418                      Set_Parent (Temp, N);
6419                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6420                   end;
6421
6422                else
6423                   Analyze (Get_Pragma_Arg (Arg2));
6424                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6425                end if;
6426
6427                Process_Interrupt_Or_Attach_Handler;
6428             end if;
6429
6430          --------------------
6431          -- C_Pass_By_Copy --
6432          --------------------
6433
6434          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6435
6436          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6437             Arg : Node_Id;
6438             Val : Uint;
6439
6440          begin
6441             GNAT_Pragma;
6442             Check_Valid_Configuration_Pragma;
6443             Check_Arg_Count (1);
6444             Check_Optional_Identifier (Arg1, "max_size");
6445
6446             Arg := Get_Pragma_Arg (Arg1);
6447             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6448
6449             Val := Expr_Value (Arg);
6450
6451             if Val <= 0 then
6452                Error_Pragma_Arg
6453                  ("maximum size for pragma% must be positive", Arg1);
6454
6455             elsif UI_Is_In_Int_Range (Val) then
6456                Default_C_Record_Mechanism := UI_To_Int (Val);
6457
6458             --  If a giant value is given, Int'Last will do well enough.
6459             --  If sometime someone complains that a record larger than
6460             --  two gigabytes is not copied, we will worry about it then!
6461
6462             else
6463                Default_C_Record_Mechanism := Mechanism_Type'Last;
6464             end if;
6465          end C_Pass_By_Copy;
6466
6467          -----------
6468          -- Check --
6469          -----------
6470
6471          --  pragma Check ([Name    =>] Identifier,
6472          --                [Check   =>] Boolean_Expression
6473          --              [,[Message =>] String_Expression]);
6474
6475          when Pragma_Check => Check : declare
6476             Expr : Node_Id;
6477             Eloc : Source_Ptr;
6478
6479             Check_On : Boolean;
6480             --  Set True if category of assertions referenced by Name enabled
6481
6482          begin
6483             GNAT_Pragma;
6484             Check_At_Least_N_Arguments (2);
6485             Check_At_Most_N_Arguments (3);
6486             Check_Optional_Identifier (Arg1, Name_Name);
6487             Check_Optional_Identifier (Arg2, Name_Check);
6488
6489             if Arg_Count = 3 then
6490                Check_Optional_Identifier (Arg3, Name_Message);
6491                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6492             end if;
6493
6494             Check_Arg_Is_Identifier (Arg1);
6495
6496             --  Indicate if pragma is enabled. The Original_Node reference here
6497             --  is to deal with pragma Assert rewritten as a Check pragma.
6498
6499             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6500
6501             if Check_On then
6502                Set_Pragma_Enabled (N);
6503                Set_Pragma_Enabled (Original_Node (N));
6504                Set_SCO_Pragma_Enabled (Loc);
6505             end if;
6506
6507             --  If expansion is active and the check is not enabled then we
6508             --  rewrite the Check as:
6509
6510             --    if False and then condition then
6511             --       null;
6512             --    end if;
6513
6514             --  The reason we do this rewriting during semantic analysis rather
6515             --  than as part of normal expansion is that we cannot analyze and
6516             --  expand the code for the boolean expression directly, or it may
6517             --  cause insertion of actions that would escape the attempt to
6518             --  suppress the check code.
6519
6520             --  Note that the Sloc for the if statement corresponds to the
6521             --  argument condition, not the pragma itself. The reason for this
6522             --  is that we may generate a warning if the condition is False at
6523             --  compile time, and we do not want to delete this warning when we
6524             --  delete the if statement.
6525
6526             Expr := Get_Pragma_Arg (Arg2);
6527
6528             if Expander_Active and then not Check_On then
6529                Eloc := Sloc (Expr);
6530
6531                Rewrite (N,
6532                  Make_If_Statement (Eloc,
6533                    Condition =>
6534                      Make_And_Then (Eloc,
6535                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
6536                        Right_Opnd => Expr),
6537                    Then_Statements => New_List (
6538                      Make_Null_Statement (Eloc))));
6539
6540                Analyze (N);
6541
6542             --  Check is active
6543
6544             else
6545                Analyze_And_Resolve (Expr, Any_Boolean);
6546             end if;
6547          end Check;
6548
6549          ----------------
6550          -- Check_Name --
6551          ----------------
6552
6553          --  pragma Check_Name (check_IDENTIFIER);
6554
6555          when Pragma_Check_Name =>
6556             Check_No_Identifiers;
6557             GNAT_Pragma;
6558             Check_Valid_Configuration_Pragma;
6559             Check_Arg_Count (1);
6560             Check_Arg_Is_Identifier (Arg1);
6561
6562             declare
6563                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6564
6565             begin
6566                for J in Check_Names.First .. Check_Names.Last loop
6567                   if Check_Names.Table (J) = Nam then
6568                      return;
6569                   end if;
6570                end loop;
6571
6572                Check_Names.Append (Nam);
6573             end;
6574
6575          ------------------
6576          -- Check_Policy --
6577          ------------------
6578
6579          --  pragma Check_Policy (
6580          --    [Name   =>] IDENTIFIER,
6581          --    [Policy =>] POLICY_IDENTIFIER);
6582
6583          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6584
6585          --  Note: this is a configuration pragma, but it is allowed to appear
6586          --  anywhere else.
6587
6588          when Pragma_Check_Policy =>
6589             GNAT_Pragma;
6590             Check_Arg_Count (2);
6591             Check_Optional_Identifier (Arg1, Name_Name);
6592             Check_Optional_Identifier (Arg2, Name_Policy);
6593             Check_Arg_Is_One_Of
6594               (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6595
6596             --  A Check_Policy pragma can appear either as a configuration
6597             --  pragma, or in a declarative part or a package spec (see RM
6598             --  11.5(5) for rules for Suppress/Unsuppress which are also
6599             --  followed for Check_Policy).
6600
6601             if not Is_Configuration_Pragma then
6602                Check_Is_In_Decl_Part_Or_Package_Spec;
6603             end if;
6604
6605             Set_Next_Pragma (N, Opt.Check_Policy_List);
6606             Opt.Check_Policy_List := N;
6607
6608          ---------------------
6609          -- CIL_Constructor --
6610          ---------------------
6611
6612          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6613
6614          --  Processing for this pragma is shared with Java_Constructor
6615
6616          -------------
6617          -- Comment --
6618          -------------
6619
6620          --  pragma Comment (static_string_EXPRESSION)
6621
6622          --  Processing for pragma Comment shares the circuitry for pragma
6623          --  Ident. The only differences are that Ident enforces a limit of 31
6624          --  characters on its argument, and also enforces limitations on
6625          --  placement for DEC compatibility. Pragma Comment shares neither of
6626          --  these restrictions.
6627
6628          -------------------
6629          -- Common_Object --
6630          -------------------
6631
6632          --  pragma Common_Object (
6633          --        [Internal =>] LOCAL_NAME
6634          --     [, [External =>] EXTERNAL_SYMBOL]
6635          --     [, [Size     =>] EXTERNAL_SYMBOL]);
6636
6637          --  Processing for this pragma is shared with Psect_Object
6638
6639          ------------------------
6640          -- Compile_Time_Error --
6641          ------------------------
6642
6643          --  pragma Compile_Time_Error
6644          --    (boolean_EXPRESSION, static_string_EXPRESSION);
6645
6646          when Pragma_Compile_Time_Error =>
6647             GNAT_Pragma;
6648             Process_Compile_Time_Warning_Or_Error;
6649
6650          --------------------------
6651          -- Compile_Time_Warning --
6652          --------------------------
6653
6654          --  pragma Compile_Time_Warning
6655          --    (boolean_EXPRESSION, static_string_EXPRESSION);
6656
6657          when Pragma_Compile_Time_Warning =>
6658             GNAT_Pragma;
6659             Process_Compile_Time_Warning_Or_Error;
6660
6661          -------------------
6662          -- Compiler_Unit --
6663          -------------------
6664
6665          when Pragma_Compiler_Unit =>
6666             GNAT_Pragma;
6667             Check_Arg_Count (0);
6668             Set_Is_Compiler_Unit (Get_Source_Unit (N));
6669
6670          -----------------------------
6671          -- Complete_Representation --
6672          -----------------------------
6673
6674          --  pragma Complete_Representation;
6675
6676          when Pragma_Complete_Representation =>
6677             GNAT_Pragma;
6678             Check_Arg_Count (0);
6679
6680             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6681                Error_Pragma
6682                  ("pragma & must appear within record representation clause");
6683             end if;
6684
6685          ----------------------------
6686          -- Complex_Representation --
6687          ----------------------------
6688
6689          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6690
6691          when Pragma_Complex_Representation => Complex_Representation : declare
6692             E_Id : Entity_Id;
6693             E    : Entity_Id;
6694             Ent  : Entity_Id;
6695
6696          begin
6697             GNAT_Pragma;
6698             Check_Arg_Count (1);
6699             Check_Optional_Identifier (Arg1, Name_Entity);
6700             Check_Arg_Is_Local_Name (Arg1);
6701             E_Id := Get_Pragma_Arg (Arg1);
6702
6703             if Etype (E_Id) = Any_Type then
6704                return;
6705             end if;
6706
6707             E := Entity (E_Id);
6708
6709             if not Is_Record_Type (E) then
6710                Error_Pragma_Arg
6711                  ("argument for pragma% must be record type", Arg1);
6712             end if;
6713
6714             Ent := First_Entity (E);
6715
6716             if No (Ent)
6717               or else No (Next_Entity (Ent))
6718               or else Present (Next_Entity (Next_Entity (Ent)))
6719               or else not Is_Floating_Point_Type (Etype (Ent))
6720               or else Etype (Ent) /= Etype (Next_Entity (Ent))
6721             then
6722                Error_Pragma_Arg
6723                  ("record for pragma% must have two fields of the same "
6724                   & "floating-point type", Arg1);
6725
6726             else
6727                Set_Has_Complex_Representation (Base_Type (E));
6728
6729                --  We need to treat the type has having a non-standard
6730                --  representation, for back-end purposes, even though in
6731                --  general a complex will have the default representation
6732                --  of a record with two real components.
6733
6734                Set_Has_Non_Standard_Rep (Base_Type (E));
6735             end if;
6736          end Complex_Representation;
6737
6738          -------------------------
6739          -- Component_Alignment --
6740          -------------------------
6741
6742          --  pragma Component_Alignment (
6743          --        [Form =>] ALIGNMENT_CHOICE
6744          --     [, [Name =>] type_LOCAL_NAME]);
6745          --
6746          --   ALIGNMENT_CHOICE ::=
6747          --     Component_Size
6748          --   | Component_Size_4
6749          --   | Storage_Unit
6750          --   | Default
6751
6752          when Pragma_Component_Alignment => Component_AlignmentP : declare
6753             Args  : Args_List (1 .. 2);
6754             Names : constant Name_List (1 .. 2) := (
6755                       Name_Form,
6756                       Name_Name);
6757
6758             Form  : Node_Id renames Args (1);
6759             Name  : Node_Id renames Args (2);
6760
6761             Atype : Component_Alignment_Kind;
6762             Typ   : Entity_Id;
6763
6764          begin
6765             GNAT_Pragma;
6766             Gather_Associations (Names, Args);
6767
6768             if No (Form) then
6769                Error_Pragma ("missing Form argument for pragma%");
6770             end if;
6771
6772             Check_Arg_Is_Identifier (Form);
6773
6774             --  Get proper alignment, note that Default = Component_Size on all
6775             --  machines we have so far, and we want to set this value rather
6776             --  than the default value to indicate that it has been explicitly
6777             --  set (and thus will not get overridden by the default component
6778             --  alignment for the current scope)
6779
6780             if Chars (Form) = Name_Component_Size then
6781                Atype := Calign_Component_Size;
6782
6783             elsif Chars (Form) = Name_Component_Size_4 then
6784                Atype := Calign_Component_Size_4;
6785
6786             elsif Chars (Form) = Name_Default then
6787                Atype := Calign_Component_Size;
6788
6789             elsif Chars (Form) = Name_Storage_Unit then
6790                Atype := Calign_Storage_Unit;
6791
6792             else
6793                Error_Pragma_Arg
6794                  ("invalid Form parameter for pragma%", Form);
6795             end if;
6796
6797             --  Case with no name, supplied, affects scope table entry
6798
6799             if No (Name) then
6800                Scope_Stack.Table
6801                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
6802
6803             --  Case of name supplied
6804
6805             else
6806                Check_Arg_Is_Local_Name (Name);
6807                Find_Type (Name);
6808                Typ := Entity (Name);
6809
6810                if Typ = Any_Type
6811                  or else Rep_Item_Too_Early (Typ, N)
6812                then
6813                   return;
6814                else
6815                   Typ := Underlying_Type (Typ);
6816                end if;
6817
6818                if not Is_Record_Type (Typ)
6819                  and then not Is_Array_Type (Typ)
6820                then
6821                   Error_Pragma_Arg
6822                     ("Name parameter of pragma% must identify record or " &
6823                      "array type", Name);
6824                end if;
6825
6826                --  An explicit Component_Alignment pragma overrides an
6827                --  implicit pragma Pack, but not an explicit one.
6828
6829                if not Has_Pragma_Pack (Base_Type (Typ)) then
6830                   Set_Is_Packed (Base_Type (Typ), False);
6831                   Set_Component_Alignment (Base_Type (Typ), Atype);
6832                end if;
6833             end if;
6834          end Component_AlignmentP;
6835
6836          ----------------
6837          -- Controlled --
6838          ----------------
6839
6840          --  pragma Controlled (first_subtype_LOCAL_NAME);
6841
6842          when Pragma_Controlled => Controlled : declare
6843             Arg : Node_Id;
6844
6845          begin
6846             Check_No_Identifiers;
6847             Check_Arg_Count (1);
6848             Check_Arg_Is_Local_Name (Arg1);
6849             Arg := Get_Pragma_Arg (Arg1);
6850
6851             if not Is_Entity_Name (Arg)
6852               or else not Is_Access_Type (Entity (Arg))
6853             then
6854                Error_Pragma_Arg ("pragma% requires access type", Arg1);
6855             else
6856                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6857             end if;
6858          end Controlled;
6859
6860          ----------------
6861          -- Convention --
6862          ----------------
6863
6864          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
6865          --    [Entity =>] LOCAL_NAME);
6866
6867          when Pragma_Convention => Convention : declare
6868             C : Convention_Id;
6869             E : Entity_Id;
6870             pragma Warnings (Off, C);
6871             pragma Warnings (Off, E);
6872          begin
6873             Check_Arg_Order ((Name_Convention, Name_Entity));
6874             Check_Ada_83_Warning;
6875             Check_Arg_Count (2);
6876             Process_Convention (C, E);
6877          end Convention;
6878
6879          ---------------------------
6880          -- Convention_Identifier --
6881          ---------------------------
6882
6883          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
6884          --    [Convention =>] convention_IDENTIFIER);
6885
6886          when Pragma_Convention_Identifier => Convention_Identifier : declare
6887             Idnam : Name_Id;
6888             Cname : Name_Id;
6889
6890          begin
6891             GNAT_Pragma;
6892             Check_Arg_Order ((Name_Name, Name_Convention));
6893             Check_Arg_Count (2);
6894             Check_Optional_Identifier (Arg1, Name_Name);
6895             Check_Optional_Identifier (Arg2, Name_Convention);
6896             Check_Arg_Is_Identifier (Arg1);
6897             Check_Arg_Is_Identifier (Arg2);
6898             Idnam := Chars (Get_Pragma_Arg (Arg1));
6899             Cname := Chars (Get_Pragma_Arg (Arg2));
6900
6901             if Is_Convention_Name (Cname) then
6902                Record_Convention_Identifier
6903                  (Idnam, Get_Convention_Id (Cname));
6904             else
6905                Error_Pragma_Arg
6906                  ("second arg for % pragma must be convention", Arg2);
6907             end if;
6908          end Convention_Identifier;
6909
6910          ---------------
6911          -- CPP_Class --
6912          ---------------
6913
6914          --  pragma CPP_Class ([Entity =>] local_NAME)
6915
6916          when Pragma_CPP_Class => CPP_Class : declare
6917             Arg : Node_Id;
6918             Typ : Entity_Id;
6919
6920          begin
6921             if Warn_On_Obsolescent_Feature then
6922                Error_Msg_N
6923                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6924                   " by pragma import?", N);
6925             end if;
6926
6927             GNAT_Pragma;
6928             Check_Arg_Count (1);
6929             Check_Optional_Identifier (Arg1, Name_Entity);
6930             Check_Arg_Is_Local_Name (Arg1);
6931
6932             Arg := Get_Pragma_Arg (Arg1);
6933             Analyze (Arg);
6934
6935             if Etype (Arg) = Any_Type then
6936                return;
6937             end if;
6938
6939             if not Is_Entity_Name (Arg)
6940               or else not Is_Type (Entity (Arg))
6941             then
6942                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6943             end if;
6944
6945             Typ := Entity (Arg);
6946
6947             if not Is_Tagged_Type (Typ) then
6948                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6949             end if;
6950
6951             --  Types treated as CPP classes are treated as limited, but we
6952             --  don't require them to be declared this way. A warning is issued
6953             --  to encourage the user to declare them as limited. This is not
6954             --  an error, for compatibility reasons, because these types have
6955             --  been supported this way for some time.
6956
6957             if not Is_Limited_Type (Typ) then
6958                Error_Msg_N
6959                  ("imported 'C'P'P type should be " &
6960                     "explicitly declared limited?",
6961                   Get_Pragma_Arg (Arg1));
6962                Error_Msg_N
6963                  ("\type will be considered limited",
6964                   Get_Pragma_Arg (Arg1));
6965             end if;
6966
6967             Set_Is_CPP_Class      (Typ);
6968             Set_Is_Limited_Record (Typ);
6969             Set_Convention        (Typ, Convention_CPP);
6970
6971             --  Imported CPP types must not have discriminants (because C++
6972             --  classes do not have discriminants).
6973
6974             if Has_Discriminants (Typ) then
6975                Error_Msg_N
6976                  ("imported 'C'P'P type cannot have discriminants",
6977                   First (Discriminant_Specifications
6978                           (Declaration_Node (Typ))));
6979             end if;
6980
6981             --  Components of imported CPP types must not have default
6982             --  expressions because the constructor (if any) is in the
6983             --  C++ side.
6984
6985             if Is_Incomplete_Or_Private_Type (Typ)
6986               and then No (Underlying_Type (Typ))
6987             then
6988                --  It should be an error to apply pragma CPP to a private
6989                --  type if the underlying type is not visible (as it is
6990                --  for any representation item). For now, for backward
6991                --  compatibility we do nothing but we cannot check components
6992                --  because they are not available at this stage. All this code
6993                --  will be removed when we cleanup this obsolete GNAT pragma???
6994
6995                null;
6996
6997             else
6998                declare
6999                   Tdef  : constant Node_Id :=
7000                             Type_Definition (Declaration_Node (Typ));
7001                   Clist : Node_Id;
7002                   Comp  : Node_Id;
7003
7004                begin
7005                   if Nkind (Tdef) = N_Record_Definition then
7006                      Clist := Component_List (Tdef);
7007                   else
7008                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7009                      Clist := Component_List (Record_Extension_Part (Tdef));
7010                   end if;
7011
7012                   if Present (Clist) then
7013                      Comp := First (Component_Items (Clist));
7014                      while Present (Comp) loop
7015                         if Present (Expression (Comp)) then
7016                            Error_Msg_N
7017                              ("component of imported 'C'P'P type cannot have" &
7018                               " default expression", Expression (Comp));
7019                         end if;
7020
7021                         Next (Comp);
7022                      end loop;
7023                   end if;
7024                end;
7025             end if;
7026          end CPP_Class;
7027
7028          ---------------------
7029          -- CPP_Constructor --
7030          ---------------------
7031
7032          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7033          --    [, [External_Name =>] static_string_EXPRESSION ]
7034          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7035
7036          when Pragma_CPP_Constructor => CPP_Constructor : declare
7037             Elmt    : Elmt_Id;
7038             Id      : Entity_Id;
7039             Def_Id  : Entity_Id;
7040             Tag_Typ : Entity_Id;
7041
7042          begin
7043             GNAT_Pragma;
7044             Check_At_Least_N_Arguments (1);
7045             Check_At_Most_N_Arguments (3);
7046             Check_Optional_Identifier (Arg1, Name_Entity);
7047             Check_Arg_Is_Local_Name (Arg1);
7048
7049             Id := Get_Pragma_Arg (Arg1);
7050             Find_Program_Unit_Name (Id);
7051
7052             --  If we did not find the name, we are done
7053
7054             if Etype (Id) = Any_Type then
7055                return;
7056             end if;
7057
7058             Def_Id := Entity (Id);
7059
7060             --  Check if already defined as constructor
7061
7062             if Is_Constructor (Def_Id) then
7063                Error_Msg_N
7064                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7065                return;
7066             end if;
7067
7068             if Ekind (Def_Id) = E_Function
7069               and then (Is_CPP_Class (Etype (Def_Id))
7070                          or else (Is_Class_Wide_Type (Etype (Def_Id))
7071                                    and then
7072                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7073             then
7074                if Arg_Count >= 2 then
7075                   Set_Imported (Def_Id);
7076                   Set_Is_Public (Def_Id);
7077                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7078                end if;
7079
7080                Set_Has_Completion (Def_Id);
7081                Set_Is_Constructor (Def_Id);
7082
7083                --  Imported C++ constructors are not dispatching primitives
7084                --  because in C++ they don't have a dispatch table slot.
7085                --  However, in Ada the constructor has the profile of a
7086                --  function that returns a tagged type and therefore it has
7087                --  been treated as a primitive operation during semantic
7088                --  analysis. We now remove it from the list of primitive
7089                --  operations of the type.
7090
7091                if Is_Tagged_Type (Etype (Def_Id))
7092                  and then not Is_Class_Wide_Type (Etype (Def_Id))
7093                then
7094                   pragma Assert (Is_Dispatching_Operation (Def_Id));
7095                   Tag_Typ := Etype (Def_Id);
7096
7097                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7098                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7099                      Next_Elmt (Elmt);
7100                   end loop;
7101
7102                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7103                   Set_Is_Dispatching_Operation (Def_Id, False);
7104                end if;
7105
7106                --  For backward compatibility, if the constructor returns a
7107                --  class wide type, and we internally change the return type to
7108                --  the corresponding root type.
7109
7110                if Is_Class_Wide_Type (Etype (Def_Id)) then
7111                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7112                end if;
7113             else
7114                Error_Pragma_Arg
7115                  ("pragma% requires function returning a 'C'P'P_Class type",
7116                    Arg1);
7117             end if;
7118          end CPP_Constructor;
7119
7120          -----------------
7121          -- CPP_Virtual --
7122          -----------------
7123
7124          when Pragma_CPP_Virtual => CPP_Virtual : declare
7125          begin
7126             GNAT_Pragma;
7127
7128             if Warn_On_Obsolescent_Feature then
7129                Error_Msg_N
7130                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7131                   "no effect?", N);
7132             end if;
7133          end CPP_Virtual;
7134
7135          ----------------
7136          -- CPP_Vtable --
7137          ----------------
7138
7139          when Pragma_CPP_Vtable => CPP_Vtable : declare
7140          begin
7141             GNAT_Pragma;
7142
7143             if Warn_On_Obsolescent_Feature then
7144                Error_Msg_N
7145                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7146                   "no effect?", N);
7147             end if;
7148          end CPP_Vtable;
7149
7150          ---------
7151          -- CPU --
7152          ---------
7153
7154          --  pragma CPU (EXPRESSION);
7155
7156          when Pragma_CPU => CPU : declare
7157             P   : constant Node_Id := Parent (N);
7158             Arg : Node_Id;
7159
7160          begin
7161             Ada_2012_Pragma;
7162             Check_No_Identifiers;
7163             Check_Arg_Count (1);
7164
7165             --  Subprogram case
7166
7167             if Nkind (P) = N_Subprogram_Body then
7168                Check_In_Main_Program;
7169
7170                Arg := Get_Pragma_Arg (Arg1);
7171                Analyze_And_Resolve (Arg, Any_Integer);
7172
7173                --  Must be static
7174
7175                if not Is_Static_Expression (Arg) then
7176                   Flag_Non_Static_Expr
7177                     ("main subprogram affinity is not static!", Arg);
7178                   raise Pragma_Exit;
7179
7180                --  If constraint error, then we already signalled an error
7181
7182                elsif Raises_Constraint_Error (Arg) then
7183                   null;
7184
7185                --  Otherwise check in range
7186
7187                else
7188                   declare
7189                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7190                      --  This is the entity System.Multiprocessors.CPU_Range;
7191
7192                      Val : constant Uint := Expr_Value (Arg);
7193
7194                   begin
7195                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7196                           or else
7197                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7198                      then
7199                         Error_Pragma_Arg
7200                           ("main subprogram CPU is out of range", Arg1);
7201                      end if;
7202                   end;
7203                end if;
7204
7205                Set_Main_CPU
7206                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7207
7208             --  Task case
7209
7210             elsif Nkind (P) = N_Task_Definition then
7211                Arg := Get_Pragma_Arg (Arg1);
7212
7213                --  The expression must be analyzed in the special manner
7214                --  described in "Handling of Default and Per-Object
7215                --  Expressions" in sem.ads.
7216
7217                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7218
7219             --  Anything else is incorrect
7220
7221             else
7222                Pragma_Misplaced;
7223             end if;
7224
7225             if Has_Pragma_CPU (P) then
7226                Error_Pragma ("duplicate pragma% not allowed");
7227             else
7228                Set_Has_Pragma_CPU (P, True);
7229
7230                if Nkind (P) = N_Task_Definition then
7231                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7232                end if;
7233             end if;
7234          end CPU;
7235
7236          -----------
7237          -- Debug --
7238          -----------
7239
7240          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7241
7242          when Pragma_Debug => Debug : declare
7243                Cond : Node_Id;
7244
7245          begin
7246             GNAT_Pragma;
7247
7248             Cond :=
7249               New_Occurrence_Of
7250                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7251                  Loc);
7252
7253             if Arg_Count = 2 then
7254                Cond :=
7255                  Make_And_Then (Loc,
7256                    Left_Opnd   => Relocate_Node (Cond),
7257                    Right_Opnd  => Get_Pragma_Arg (Arg1));
7258             end if;
7259
7260             --  Rewrite into a conditional with an appropriate condition. We
7261             --  wrap the procedure call in a block so that overhead from e.g.
7262             --  use of the secondary stack does not generate execution overhead
7263             --  for suppressed conditions.
7264
7265             Rewrite (N, Make_Implicit_If_Statement (N,
7266               Condition => Cond,
7267                  Then_Statements => New_List (
7268                    Make_Block_Statement (Loc,
7269                      Handled_Statement_Sequence =>
7270                        Make_Handled_Sequence_Of_Statements (Loc,
7271                          Statements => New_List (
7272                            Relocate_Node (Debug_Statement (N))))))));
7273             Analyze (N);
7274          end Debug;
7275
7276          ------------------
7277          -- Debug_Policy --
7278          ------------------
7279
7280          --  pragma Debug_Policy (Check | Ignore)
7281
7282          when Pragma_Debug_Policy =>
7283             GNAT_Pragma;
7284             Check_Arg_Count (1);
7285             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7286             Debug_Pragmas_Enabled :=
7287               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7288
7289          ---------------------
7290          -- Detect_Blocking --
7291          ---------------------
7292
7293          --  pragma Detect_Blocking;
7294
7295          when Pragma_Detect_Blocking =>
7296             Ada_2005_Pragma;
7297             Check_Arg_Count (0);
7298             Check_Valid_Configuration_Pragma;
7299             Detect_Blocking := True;
7300
7301          --------------------------
7302          -- Default_Storage_Pool --
7303          --------------------------
7304
7305          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
7306
7307          when Pragma_Default_Storage_Pool =>
7308             Ada_2012_Pragma;
7309             Check_Arg_Count (1);
7310
7311             --  Default_Storage_Pool can appear as a configuration pragma, or
7312             --  in a declarative part or a package spec.
7313
7314             if not Is_Configuration_Pragma then
7315                Check_Is_In_Decl_Part_Or_Package_Spec;
7316             end if;
7317
7318             --  Case of Default_Storage_Pool (null);
7319
7320             if Nkind (Expression (Arg1)) = N_Null then
7321                Analyze (Expression (Arg1));
7322
7323                --  This is an odd case, this is not really an expression, so
7324                --  we don't have a type for it. So just set the type to Empty.
7325
7326                Set_Etype (Expression (Arg1), Empty);
7327
7328             --  Case of Default_Storage_Pool (storage_pool_NAME);
7329
7330             else
7331                --  If it's a configuration pragma, then the only allowed
7332                --  argument is "null".
7333
7334                if Is_Configuration_Pragma then
7335                   Error_Pragma_Arg ("NULL expected", Arg1);
7336                end if;
7337
7338                --  The expected type for a non-"null" argument is
7339                --  Root_Storage_Pool'Class.
7340
7341                Analyze_And_Resolve
7342                  (Get_Pragma_Arg (Arg1),
7343                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7344             end if;
7345
7346             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
7347             --  for an access type will use this information to set the
7348             --  appropriate attributes of the access type.
7349
7350             Default_Pool := Expression (Arg1);
7351
7352          ---------------
7353          -- Dimension --
7354          ---------------
7355
7356          when Pragma_Dimension =>
7357             GNAT_Pragma;
7358             Check_Arg_Count (4);
7359             Check_No_Identifiers;
7360             Check_Arg_Is_Local_Name (Arg1);
7361
7362             if not Is_Type (Arg1) then
7363                Error_Pragma ("first argument for pragma% must be subtype");
7364             end if;
7365
7366             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7367             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7368             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7369
7370          -------------------
7371          -- Discard_Names --
7372          -------------------
7373
7374          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
7375
7376          when Pragma_Discard_Names => Discard_Names : declare
7377             E    : Entity_Id;
7378             E_Id : Entity_Id;
7379
7380          begin
7381             Check_Ada_83_Warning;
7382
7383             --  Deal with configuration pragma case
7384
7385             if Arg_Count = 0 and then Is_Configuration_Pragma then
7386                Global_Discard_Names := True;
7387                return;
7388
7389             --  Otherwise, check correct appropriate context
7390
7391             else
7392                Check_Is_In_Decl_Part_Or_Package_Spec;
7393
7394                if Arg_Count = 0 then
7395
7396                   --  If there is no parameter, then from now on this pragma
7397                   --  applies to any enumeration, exception or tagged type
7398                   --  defined in the current declarative part, and recursively
7399                   --  to any nested scope.
7400
7401                   Set_Discard_Names (Current_Scope, Sense);
7402                   return;
7403
7404                else
7405                   Check_Arg_Count (1);
7406                   Check_Optional_Identifier (Arg1, Name_On);
7407                   Check_Arg_Is_Local_Name (Arg1);
7408
7409                   E_Id := Get_Pragma_Arg (Arg1);
7410
7411                   if Etype (E_Id) = Any_Type then
7412                      return;
7413                   else
7414                      E := Entity (E_Id);
7415                   end if;
7416
7417                   if (Is_First_Subtype (E)
7418                       and then
7419                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7420                     or else Ekind (E) = E_Exception
7421                   then
7422                      Set_Discard_Names (E, Sense);
7423                   else
7424                      Error_Pragma_Arg
7425                        ("inappropriate entity for pragma%", Arg1);
7426                   end if;
7427
7428                end if;
7429             end if;
7430          end Discard_Names;
7431
7432          ---------------
7433          -- Elaborate --
7434          ---------------
7435
7436          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7437
7438          when Pragma_Elaborate => Elaborate : declare
7439             Arg   : Node_Id;
7440             Citem : Node_Id;
7441
7442          begin
7443             --  Pragma must be in context items list of a compilation unit
7444
7445             if not Is_In_Context_Clause then
7446                Pragma_Misplaced;
7447             end if;
7448
7449             --  Must be at least one argument
7450
7451             if Arg_Count = 0 then
7452                Error_Pragma ("pragma% requires at least one argument");
7453             end if;
7454
7455             --  In Ada 83 mode, there can be no items following it in the
7456             --  context list except other pragmas and implicit with clauses
7457             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7458             --  placement rule does not apply.
7459
7460             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7461                Citem := Next (N);
7462                while Present (Citem) loop
7463                   if Nkind (Citem) = N_Pragma
7464                     or else (Nkind (Citem) = N_With_Clause
7465                               and then Implicit_With (Citem))
7466                   then
7467                      null;
7468                   else
7469                      Error_Pragma
7470                        ("(Ada 83) pragma% must be at end of context clause");
7471                   end if;
7472
7473                   Next (Citem);
7474                end loop;
7475             end if;
7476
7477             --  Finally, the arguments must all be units mentioned in a with
7478             --  clause in the same context clause. Note we already checked (in
7479             --  Par.Prag) that the arguments are all identifiers or selected
7480             --  components.
7481
7482             Arg := Arg1;
7483             Outer : while Present (Arg) loop
7484                Citem := First (List_Containing (N));
7485                Inner : while Citem /= N loop
7486                   if Nkind (Citem) = N_With_Clause
7487                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7488                   then
7489                      Set_Elaborate_Present (Citem, True);
7490                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7491
7492                      --  With the pragma present, elaboration calls on
7493                      --  subprograms from the named unit need no further
7494                      --  checks, as long as the pragma appears in the current
7495                      --  compilation unit. If the pragma appears in some unit
7496                      --  in the context, there might still be a need for an
7497                      --  Elaborate_All_Desirable from the current compilation
7498                      --  to the named unit, so we keep the check enabled.
7499
7500                      if In_Extended_Main_Source_Unit (N) then
7501                         Set_Suppress_Elaboration_Warnings
7502                           (Entity (Name (Citem)));
7503                      end if;
7504
7505                      exit Inner;
7506                   end if;
7507
7508                   Next (Citem);
7509                end loop Inner;
7510
7511                if Citem = N then
7512                   Error_Pragma_Arg
7513                     ("argument of pragma% is not with'ed unit", Arg);
7514                end if;
7515
7516                Next (Arg);
7517             end loop Outer;
7518
7519             --  Give a warning if operating in static mode with -gnatwl
7520             --  (elaboration warnings enabled) switch set.
7521
7522             if Elab_Warnings and not Dynamic_Elaboration_Checks then
7523                Error_Msg_N
7524                  ("?use of pragma Elaborate may not be safe", N);
7525                Error_Msg_N
7526                  ("?use pragma Elaborate_All instead if possible", N);
7527             end if;
7528          end Elaborate;
7529
7530          -------------------
7531          -- Elaborate_All --
7532          -------------------
7533
7534          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7535
7536          when Pragma_Elaborate_All => Elaborate_All : declare
7537             Arg   : Node_Id;
7538             Citem : Node_Id;
7539
7540          begin
7541             Check_Ada_83_Warning;
7542
7543             --  Pragma must be in context items list of a compilation unit
7544
7545             if not Is_In_Context_Clause then
7546                Pragma_Misplaced;
7547             end if;
7548
7549             --  Must be at least one argument
7550
7551             if Arg_Count = 0 then
7552                Error_Pragma ("pragma% requires at least one argument");
7553             end if;
7554
7555             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
7556             --  have to appear at the end of the context clause, but may
7557             --  appear mixed in with other items, even in Ada 83 mode.
7558
7559             --  Final check: the arguments must all be units mentioned in
7560             --  a with clause in the same context clause. Note that we
7561             --  already checked (in Par.Prag) that all the arguments are
7562             --  either identifiers or selected components.
7563
7564             Arg := Arg1;
7565             Outr : while Present (Arg) loop
7566                Citem := First (List_Containing (N));
7567                Innr : while Citem /= N loop
7568                   if Nkind (Citem) = N_With_Clause
7569                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7570                   then
7571                      Set_Elaborate_All_Present (Citem, True);
7572                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7573
7574                      --  Suppress warnings and elaboration checks on the named
7575                      --  unit if the pragma is in the current compilation, as
7576                      --  for pragma Elaborate.
7577
7578                      if In_Extended_Main_Source_Unit (N) then
7579                         Set_Suppress_Elaboration_Warnings
7580                           (Entity (Name (Citem)));
7581                      end if;
7582                      exit Innr;
7583                   end if;
7584
7585                   Next (Citem);
7586                end loop Innr;
7587
7588                if Citem = N then
7589                   Set_Error_Posted (N);
7590                   Error_Pragma_Arg
7591                     ("argument of pragma% is not with'ed unit", Arg);
7592                end if;
7593
7594                Next (Arg);
7595             end loop Outr;
7596          end Elaborate_All;
7597
7598          --------------------
7599          -- Elaborate_Body --
7600          --------------------
7601
7602          --  pragma Elaborate_Body [( library_unit_NAME )];
7603
7604          when Pragma_Elaborate_Body => Elaborate_Body : declare
7605             Cunit_Node : Node_Id;
7606             Cunit_Ent  : Entity_Id;
7607
7608          begin
7609             Check_Ada_83_Warning;
7610             Check_Valid_Library_Unit_Pragma;
7611
7612             if Nkind (N) = N_Null_Statement then
7613                return;
7614             end if;
7615
7616             Cunit_Node := Cunit (Current_Sem_Unit);
7617             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
7618
7619             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7620                                             N_Subprogram_Body)
7621             then
7622                Error_Pragma ("pragma% must refer to a spec, not a body");
7623             else
7624                Set_Body_Required (Cunit_Node, True);
7625                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7626
7627                --  If we are in dynamic elaboration mode, then we suppress
7628                --  elaboration warnings for the unit, since it is definitely
7629                --  fine NOT to do dynamic checks at the first level (and such
7630                --  checks will be suppressed because no elaboration boolean
7631                --  is created for Elaborate_Body packages).
7632
7633                --  But in the static model of elaboration, Elaborate_Body is
7634                --  definitely NOT good enough to ensure elaboration safety on
7635                --  its own, since the body may WITH other units that are not
7636                --  safe from an elaboration point of view, so a client must
7637                --  still do an Elaborate_All on such units.
7638
7639                --  Debug flag -gnatdD restores the old behavior of 3.13, where
7640                --  Elaborate_Body always suppressed elab warnings.
7641
7642                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7643                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7644                end if;
7645             end if;
7646          end Elaborate_Body;
7647
7648          ------------------------
7649          -- Elaboration_Checks --
7650          ------------------------
7651
7652          --  pragma Elaboration_Checks (Static | Dynamic);
7653
7654          when Pragma_Elaboration_Checks =>
7655             GNAT_Pragma;
7656             Check_Arg_Count (1);
7657             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7658             Dynamic_Elaboration_Checks :=
7659               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7660
7661          ---------------
7662          -- Eliminate --
7663          ---------------
7664
7665          --  pragma Eliminate (
7666          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
7667          --    [,[Entity     =>] IDENTIFIER |
7668          --                      SELECTED_COMPONENT |
7669          --                      STRING_LITERAL]
7670          --    [,                OVERLOADING_RESOLUTION]);
7671
7672          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7673          --                             SOURCE_LOCATION
7674
7675          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7676          --                                        FUNCTION_PROFILE
7677
7678          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7679
7680          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7681          --                       Result_Type => result_SUBTYPE_NAME]
7682
7683          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7684          --  SUBTYPE_NAME    ::= STRING_LITERAL
7685
7686          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7687          --  SOURCE_TRACE    ::= STRING_LITERAL
7688
7689          when Pragma_Eliminate => Eliminate : declare
7690             Args  : Args_List (1 .. 5);
7691             Names : constant Name_List (1 .. 5) := (
7692                       Name_Unit_Name,
7693                       Name_Entity,
7694                       Name_Parameter_Types,
7695                       Name_Result_Type,
7696                       Name_Source_Location);
7697
7698             Unit_Name       : Node_Id renames Args (1);
7699             Entity          : Node_Id renames Args (2);
7700             Parameter_Types : Node_Id renames Args (3);
7701             Result_Type     : Node_Id renames Args (4);
7702             Source_Location : Node_Id renames Args (5);
7703
7704          begin
7705             GNAT_Pragma;
7706             Check_Valid_Configuration_Pragma;
7707             Gather_Associations (Names, Args);
7708
7709             if No (Unit_Name) then
7710                Error_Pragma ("missing Unit_Name argument for pragma%");
7711             end if;
7712
7713             if No (Entity)
7714               and then (Present (Parameter_Types)
7715                           or else
7716                         Present (Result_Type)
7717                           or else
7718                         Present (Source_Location))
7719             then
7720                Error_Pragma ("missing Entity argument for pragma%");
7721             end if;
7722
7723             if (Present (Parameter_Types)
7724                        or else
7725                 Present (Result_Type))
7726               and then
7727                 Present (Source_Location)
7728             then
7729                Error_Pragma
7730                  ("parameter profile and source location cannot " &
7731                   "be used together in pragma%");
7732             end if;
7733
7734             Process_Eliminate_Pragma
7735               (N,
7736                Unit_Name,
7737                Entity,
7738                Parameter_Types,
7739                Result_Type,
7740                Source_Location);
7741          end Eliminate;
7742
7743          ------------
7744          -- Export --
7745          ------------
7746
7747          --  pragma Export (
7748          --    [   Convention    =>] convention_IDENTIFIER,
7749          --    [   Entity        =>] local_NAME
7750          --    [, [External_Name =>] static_string_EXPRESSION ]
7751          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7752
7753          when Pragma_Export => Export : declare
7754             C      : Convention_Id;
7755             Def_Id : Entity_Id;
7756
7757             pragma Warnings (Off, C);
7758
7759          begin
7760             Check_Ada_83_Warning;
7761             Check_Arg_Order
7762               ((Name_Convention,
7763                 Name_Entity,
7764                 Name_External_Name,
7765                 Name_Link_Name));
7766             Check_At_Least_N_Arguments (2);
7767             Check_At_Most_N_Arguments  (4);
7768             Process_Convention (C, Def_Id);
7769
7770             if Ekind (Def_Id) /= E_Constant then
7771                Note_Possible_Modification
7772                  (Get_Pragma_Arg (Arg2), Sure => False);
7773             end if;
7774
7775             Process_Interface_Name (Def_Id, Arg3, Arg4);
7776             Set_Exported (Def_Id, Arg2);
7777
7778             --  If the entity is a deferred constant, propagate the information
7779             --  to the full view, because gigi elaborates the full view only.
7780
7781             if Ekind (Def_Id) = E_Constant
7782               and then Present (Full_View (Def_Id))
7783             then
7784                declare
7785                   Id2 : constant Entity_Id := Full_View (Def_Id);
7786                begin
7787                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
7788                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
7789                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7790                end;
7791             end if;
7792          end Export;
7793
7794          ----------------------
7795          -- Export_Exception --
7796          ----------------------
7797
7798          --  pragma Export_Exception (
7799          --        [Internal         =>] LOCAL_NAME
7800          --     [, [External         =>] EXTERNAL_SYMBOL]
7801          --     [, [Form     =>] Ada | VMS]
7802          --     [, [Code     =>] static_integer_EXPRESSION]);
7803
7804          when Pragma_Export_Exception => Export_Exception : declare
7805             Args  : Args_List (1 .. 4);
7806             Names : constant Name_List (1 .. 4) := (
7807                       Name_Internal,
7808                       Name_External,
7809                       Name_Form,
7810                       Name_Code);
7811
7812             Internal : Node_Id renames Args (1);
7813             External : Node_Id renames Args (2);
7814             Form     : Node_Id renames Args (3);
7815             Code     : Node_Id renames Args (4);
7816
7817          begin
7818             GNAT_Pragma;
7819
7820             if Inside_A_Generic then
7821                Error_Pragma ("pragma% cannot be used for generic entities");
7822             end if;
7823
7824             Gather_Associations (Names, Args);
7825             Process_Extended_Import_Export_Exception_Pragma (
7826               Arg_Internal => Internal,
7827               Arg_External => External,
7828               Arg_Form     => Form,
7829               Arg_Code     => Code);
7830
7831             if not Is_VMS_Exception (Entity (Internal)) then
7832                Set_Exported (Entity (Internal), Internal);
7833             end if;
7834          end Export_Exception;
7835
7836          ---------------------
7837          -- Export_Function --
7838          ---------------------
7839
7840          --  pragma Export_Function (
7841          --        [Internal         =>] LOCAL_NAME
7842          --     [, [External         =>] EXTERNAL_SYMBOL]
7843          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
7844          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
7845          --     [, [Mechanism        =>] MECHANISM]
7846          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
7847
7848          --  EXTERNAL_SYMBOL ::=
7849          --    IDENTIFIER
7850          --  | static_string_EXPRESSION
7851
7852          --  PARAMETER_TYPES ::=
7853          --    null
7854          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7855
7856          --  TYPE_DESIGNATOR ::=
7857          --    subtype_NAME
7858          --  | subtype_Name ' Access
7859
7860          --  MECHANISM ::=
7861          --    MECHANISM_NAME
7862          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7863
7864          --  MECHANISM_ASSOCIATION ::=
7865          --    [formal_parameter_NAME =>] MECHANISM_NAME
7866
7867          --  MECHANISM_NAME ::=
7868          --    Value
7869          --  | Reference
7870          --  | Descriptor [([Class =>] CLASS_NAME)]
7871
7872          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7873
7874          when Pragma_Export_Function => Export_Function : declare
7875             Args  : Args_List (1 .. 6);
7876             Names : constant Name_List (1 .. 6) := (
7877                       Name_Internal,
7878                       Name_External,
7879                       Name_Parameter_Types,
7880                       Name_Result_Type,
7881                       Name_Mechanism,
7882                       Name_Result_Mechanism);
7883
7884             Internal         : Node_Id renames Args (1);
7885             External         : Node_Id renames Args (2);
7886             Parameter_Types  : Node_Id renames Args (3);
7887             Result_Type      : Node_Id renames Args (4);
7888             Mechanism        : Node_Id renames Args (5);
7889             Result_Mechanism : Node_Id renames Args (6);
7890
7891          begin
7892             GNAT_Pragma;
7893             Gather_Associations (Names, Args);
7894             Process_Extended_Import_Export_Subprogram_Pragma (
7895               Arg_Internal         => Internal,
7896               Arg_External         => External,
7897               Arg_Parameter_Types  => Parameter_Types,
7898               Arg_Result_Type      => Result_Type,
7899               Arg_Mechanism        => Mechanism,
7900               Arg_Result_Mechanism => Result_Mechanism);
7901          end Export_Function;
7902
7903          -------------------
7904          -- Export_Object --
7905          -------------------
7906
7907          --  pragma Export_Object (
7908          --        [Internal =>] LOCAL_NAME
7909          --     [, [External =>] EXTERNAL_SYMBOL]
7910          --     [, [Size     =>] EXTERNAL_SYMBOL]);
7911
7912          --  EXTERNAL_SYMBOL ::=
7913          --    IDENTIFIER
7914          --  | static_string_EXPRESSION
7915
7916          --  PARAMETER_TYPES ::=
7917          --    null
7918          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7919
7920          --  TYPE_DESIGNATOR ::=
7921          --    subtype_NAME
7922          --  | subtype_Name ' Access
7923
7924          --  MECHANISM ::=
7925          --    MECHANISM_NAME
7926          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7927
7928          --  MECHANISM_ASSOCIATION ::=
7929          --    [formal_parameter_NAME =>] MECHANISM_NAME
7930
7931          --  MECHANISM_NAME ::=
7932          --    Value
7933          --  | Reference
7934          --  | Descriptor [([Class =>] CLASS_NAME)]
7935
7936          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7937
7938          when Pragma_Export_Object => Export_Object : declare
7939             Args  : Args_List (1 .. 3);
7940             Names : constant Name_List (1 .. 3) := (
7941                       Name_Internal,
7942                       Name_External,
7943                       Name_Size);
7944
7945             Internal : Node_Id renames Args (1);
7946             External : Node_Id renames Args (2);
7947             Size     : Node_Id renames Args (3);
7948
7949          begin
7950             GNAT_Pragma;
7951             Gather_Associations (Names, Args);
7952             Process_Extended_Import_Export_Object_Pragma (
7953               Arg_Internal => Internal,
7954               Arg_External => External,
7955               Arg_Size     => Size);
7956          end Export_Object;
7957
7958          ----------------------
7959          -- Export_Procedure --
7960          ----------------------
7961
7962          --  pragma Export_Procedure (
7963          --        [Internal         =>] LOCAL_NAME
7964          --     [, [External         =>] EXTERNAL_SYMBOL]
7965          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
7966          --     [, [Mechanism        =>] MECHANISM]);
7967
7968          --  EXTERNAL_SYMBOL ::=
7969          --    IDENTIFIER
7970          --  | static_string_EXPRESSION
7971
7972          --  PARAMETER_TYPES ::=
7973          --    null
7974          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7975
7976          --  TYPE_DESIGNATOR ::=
7977          --    subtype_NAME
7978          --  | subtype_Name ' Access
7979
7980          --  MECHANISM ::=
7981          --    MECHANISM_NAME
7982          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7983
7984          --  MECHANISM_ASSOCIATION ::=
7985          --    [formal_parameter_NAME =>] MECHANISM_NAME
7986
7987          --  MECHANISM_NAME ::=
7988          --    Value
7989          --  | Reference
7990          --  | Descriptor [([Class =>] CLASS_NAME)]
7991
7992          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7993
7994          when Pragma_Export_Procedure => Export_Procedure : declare
7995             Args  : Args_List (1 .. 4);
7996             Names : constant Name_List (1 .. 4) := (
7997                       Name_Internal,
7998                       Name_External,
7999                       Name_Parameter_Types,
8000                       Name_Mechanism);
8001
8002             Internal        : Node_Id renames Args (1);
8003             External        : Node_Id renames Args (2);
8004             Parameter_Types : Node_Id renames Args (3);
8005             Mechanism       : Node_Id renames Args (4);
8006
8007          begin
8008             GNAT_Pragma;
8009             Gather_Associations (Names, Args);
8010             Process_Extended_Import_Export_Subprogram_Pragma (
8011               Arg_Internal        => Internal,
8012               Arg_External        => External,
8013               Arg_Parameter_Types => Parameter_Types,
8014               Arg_Mechanism       => Mechanism);
8015          end Export_Procedure;
8016
8017          ------------------
8018          -- Export_Value --
8019          ------------------
8020
8021          --  pragma Export_Value (
8022          --     [Value     =>] static_integer_EXPRESSION,
8023          --     [Link_Name =>] static_string_EXPRESSION);
8024
8025          when Pragma_Export_Value =>
8026             GNAT_Pragma;
8027             Check_Arg_Order ((Name_Value, Name_Link_Name));
8028             Check_Arg_Count (2);
8029
8030             Check_Optional_Identifier (Arg1, Name_Value);
8031             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8032
8033             Check_Optional_Identifier (Arg2, Name_Link_Name);
8034             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8035
8036          -----------------------------
8037          -- Export_Valued_Procedure --
8038          -----------------------------
8039
8040          --  pragma Export_Valued_Procedure (
8041          --        [Internal         =>] LOCAL_NAME
8042          --     [, [External         =>] EXTERNAL_SYMBOL,]
8043          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8044          --     [, [Mechanism        =>] MECHANISM]);
8045
8046          --  EXTERNAL_SYMBOL ::=
8047          --    IDENTIFIER
8048          --  | static_string_EXPRESSION
8049
8050          --  PARAMETER_TYPES ::=
8051          --    null
8052          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8053
8054          --  TYPE_DESIGNATOR ::=
8055          --    subtype_NAME
8056          --  | subtype_Name ' Access
8057
8058          --  MECHANISM ::=
8059          --    MECHANISM_NAME
8060          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8061
8062          --  MECHANISM_ASSOCIATION ::=
8063          --    [formal_parameter_NAME =>] MECHANISM_NAME
8064
8065          --  MECHANISM_NAME ::=
8066          --    Value
8067          --  | Reference
8068          --  | Descriptor [([Class =>] CLASS_NAME)]
8069
8070          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8071
8072          when Pragma_Export_Valued_Procedure =>
8073          Export_Valued_Procedure : declare
8074             Args  : Args_List (1 .. 4);
8075             Names : constant Name_List (1 .. 4) := (
8076                       Name_Internal,
8077                       Name_External,
8078                       Name_Parameter_Types,
8079                       Name_Mechanism);
8080
8081             Internal        : Node_Id renames Args (1);
8082             External        : Node_Id renames Args (2);
8083             Parameter_Types : Node_Id renames Args (3);
8084             Mechanism       : Node_Id renames Args (4);
8085
8086          begin
8087             GNAT_Pragma;
8088             Gather_Associations (Names, Args);
8089             Process_Extended_Import_Export_Subprogram_Pragma (
8090               Arg_Internal        => Internal,
8091               Arg_External        => External,
8092               Arg_Parameter_Types => Parameter_Types,
8093               Arg_Mechanism       => Mechanism);
8094          end Export_Valued_Procedure;
8095
8096          -------------------
8097          -- Extend_System --
8098          -------------------
8099
8100          --  pragma Extend_System ([Name =>] Identifier);
8101
8102          when Pragma_Extend_System => Extend_System : declare
8103          begin
8104             GNAT_Pragma;
8105             Check_Valid_Configuration_Pragma;
8106             Check_Arg_Count (1);
8107             Check_Optional_Identifier (Arg1, Name_Name);
8108             Check_Arg_Is_Identifier (Arg1);
8109
8110             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8111
8112             if Name_Len > 4
8113               and then Name_Buffer (1 .. 4) = "aux_"
8114             then
8115                if Present (System_Extend_Pragma_Arg) then
8116                   if Chars (Get_Pragma_Arg (Arg1)) =
8117                      Chars (Expression (System_Extend_Pragma_Arg))
8118                   then
8119                      null;
8120                   else
8121                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8122                      Error_Pragma ("pragma% conflicts with that #");
8123                   end if;
8124
8125                else
8126                   System_Extend_Pragma_Arg := Arg1;
8127
8128                   if not GNAT_Mode then
8129                      System_Extend_Unit := Arg1;
8130                   end if;
8131                end if;
8132             else
8133                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8134             end if;
8135          end Extend_System;
8136
8137          ------------------------
8138          -- Extensions_Allowed --
8139          ------------------------
8140
8141          --  pragma Extensions_Allowed (ON | OFF);
8142
8143          when Pragma_Extensions_Allowed =>
8144             GNAT_Pragma;
8145             Check_Arg_Count (1);
8146             Check_No_Identifiers;
8147             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8148
8149             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8150                Extensions_Allowed := True;
8151                Ada_Version := Ada_Version_Type'Last;
8152
8153             else
8154                Extensions_Allowed := False;
8155                Ada_Version := Ada_Version_Explicit;
8156             end if;
8157
8158          --------------
8159          -- External --
8160          --------------
8161
8162          --  pragma External (
8163          --    [   Convention    =>] convention_IDENTIFIER,
8164          --    [   Entity        =>] local_NAME
8165          --    [, [External_Name =>] static_string_EXPRESSION ]
8166          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8167
8168          when Pragma_External => External : declare
8169                Def_Id : Entity_Id;
8170
8171                C : Convention_Id;
8172                pragma Warnings (Off, C);
8173
8174          begin
8175             GNAT_Pragma;
8176             Check_Arg_Order
8177               ((Name_Convention,
8178                 Name_Entity,
8179                 Name_External_Name,
8180                 Name_Link_Name));
8181             Check_At_Least_N_Arguments (2);
8182             Check_At_Most_N_Arguments  (4);
8183             Process_Convention (C, Def_Id);
8184             Note_Possible_Modification
8185               (Get_Pragma_Arg (Arg2), Sure => False);
8186             Process_Interface_Name (Def_Id, Arg3, Arg4);
8187             Set_Exported (Def_Id, Arg2);
8188          end External;
8189
8190          --------------------------
8191          -- External_Name_Casing --
8192          --------------------------
8193
8194          --  pragma External_Name_Casing (
8195          --    UPPERCASE | LOWERCASE
8196          --    [, AS_IS | UPPERCASE | LOWERCASE]);
8197
8198          when Pragma_External_Name_Casing => External_Name_Casing : declare
8199          begin
8200             GNAT_Pragma;
8201             Check_No_Identifiers;
8202
8203             if Arg_Count = 2 then
8204                Check_Arg_Is_One_Of
8205                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8206
8207                case Chars (Get_Pragma_Arg (Arg2)) is
8208                   when Name_As_Is     =>
8209                      Opt.External_Name_Exp_Casing := As_Is;
8210
8211                   when Name_Uppercase =>
8212                      Opt.External_Name_Exp_Casing := Uppercase;
8213
8214                   when Name_Lowercase =>
8215                      Opt.External_Name_Exp_Casing := Lowercase;
8216
8217                   when others =>
8218                      null;
8219                end case;
8220
8221             else
8222                Check_Arg_Count (1);
8223             end if;
8224
8225             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8226
8227             case Chars (Get_Pragma_Arg (Arg1)) is
8228                when Name_Uppercase =>
8229                   Opt.External_Name_Imp_Casing := Uppercase;
8230
8231                when Name_Lowercase =>
8232                   Opt.External_Name_Imp_Casing := Lowercase;
8233
8234                when others =>
8235                   null;
8236             end case;
8237          end External_Name_Casing;
8238
8239          --------------------------
8240          -- Favor_Top_Level --
8241          --------------------------
8242
8243          --  pragma Favor_Top_Level (type_NAME);
8244
8245          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8246                Named_Entity : Entity_Id;
8247
8248          begin
8249             GNAT_Pragma;
8250             Check_No_Identifiers;
8251             Check_Arg_Count (1);
8252             Check_Arg_Is_Local_Name (Arg1);
8253             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8254
8255             --  If it's an access-to-subprogram type (in particular, not a
8256             --  subtype), set the flag on that type.
8257
8258             if Is_Access_Subprogram_Type (Named_Entity) then
8259                if Sense then
8260                   Set_Can_Use_Internal_Rep (Named_Entity, False);
8261                end if;
8262
8263             --  Otherwise it's an error (name denotes the wrong sort of entity)
8264
8265             else
8266                Error_Pragma_Arg
8267                  ("access-to-subprogram type expected",
8268                   Get_Pragma_Arg (Arg1));
8269             end if;
8270          end Favor_Top_Level;
8271
8272          ---------------
8273          -- Fast_Math --
8274          ---------------
8275
8276          --  pragma Fast_Math;
8277
8278          when Pragma_Fast_Math =>
8279             GNAT_Pragma;
8280             Check_No_Identifiers;
8281             Check_Valid_Configuration_Pragma;
8282             Fast_Math := True;
8283
8284          ---------------------------
8285          -- Finalize_Storage_Only --
8286          ---------------------------
8287
8288          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8289
8290          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8291             Assoc   : constant Node_Id := Arg1;
8292             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8293             Typ     : Entity_Id;
8294
8295          begin
8296             GNAT_Pragma;
8297             Check_No_Identifiers;
8298             Check_Arg_Count (1);
8299             Check_Arg_Is_Local_Name (Arg1);
8300
8301             Find_Type (Type_Id);
8302             Typ := Entity (Type_Id);
8303
8304             if Typ = Any_Type
8305               or else Rep_Item_Too_Early (Typ, N)
8306             then
8307                return;
8308             else
8309                Typ := Underlying_Type (Typ);
8310             end if;
8311
8312             if not Is_Controlled (Typ) then
8313                Error_Pragma ("pragma% must specify controlled type");
8314             end if;
8315
8316             Check_First_Subtype (Arg1);
8317
8318             if Finalize_Storage_Only (Typ) then
8319                Error_Pragma ("duplicate pragma%, only one allowed");
8320
8321             elsif not Rep_Item_Too_Late (Typ, N) then
8322                Set_Finalize_Storage_Only (Base_Type (Typ), True);
8323             end if;
8324          end Finalize_Storage;
8325
8326          --------------------------
8327          -- Float_Representation --
8328          --------------------------
8329
8330          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8331
8332          --  FLOAT_REP ::= VAX_Float | IEEE_Float
8333
8334          when Pragma_Float_Representation => Float_Representation : declare
8335             Argx : Node_Id;
8336             Digs : Nat;
8337             Ent  : Entity_Id;
8338
8339          begin
8340             GNAT_Pragma;
8341
8342             if Arg_Count = 1 then
8343                Check_Valid_Configuration_Pragma;
8344             else
8345                Check_Arg_Count (2);
8346                Check_Optional_Identifier (Arg2, Name_Entity);
8347                Check_Arg_Is_Local_Name (Arg2);
8348             end if;
8349
8350             Check_No_Identifier (Arg1);
8351             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8352
8353             if not OpenVMS_On_Target then
8354                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8355                   Error_Pragma
8356                     ("?pragma% ignored (applies only to Open'V'M'S)");
8357                end if;
8358
8359                return;
8360             end if;
8361
8362             --  One argument case
8363
8364             if Arg_Count = 1 then
8365                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8366                   if Opt.Float_Format = 'I' then
8367                      Error_Pragma ("'I'E'E'E format previously specified");
8368                   end if;
8369
8370                   Opt.Float_Format := 'V';
8371
8372                else
8373                   if Opt.Float_Format = 'V' then
8374                      Error_Pragma ("'V'A'X format previously specified");
8375                   end if;
8376
8377                   Opt.Float_Format := 'I';
8378                end if;
8379
8380                Set_Standard_Fpt_Formats;
8381
8382             --  Two argument case
8383
8384             else
8385                Argx := Get_Pragma_Arg (Arg2);
8386
8387                if not Is_Entity_Name (Argx)
8388                  or else not Is_Floating_Point_Type (Entity (Argx))
8389                then
8390                   Error_Pragma_Arg
8391                     ("second argument of% pragma must be floating-point type",
8392                      Arg2);
8393                end if;
8394
8395                Ent  := Entity (Argx);
8396                Digs := UI_To_Int (Digits_Value (Ent));
8397
8398                --  Two arguments, VAX_Float case
8399
8400                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8401                   case Digs is
8402                      when  6 => Set_F_Float (Ent);
8403                      when  9 => Set_D_Float (Ent);
8404                      when 15 => Set_G_Float (Ent);
8405
8406                      when others =>
8407                         Error_Pragma_Arg
8408                           ("wrong digits value, must be 6,9 or 15", Arg2);
8409                   end case;
8410
8411                --  Two arguments, IEEE_Float case
8412
8413                else
8414                   case Digs is
8415                      when  6 => Set_IEEE_Short (Ent);
8416                      when 15 => Set_IEEE_Long  (Ent);
8417
8418                      when others =>
8419                         Error_Pragma_Arg
8420                           ("wrong digits value, must be 6 or 15", Arg2);
8421                   end case;
8422                end if;
8423             end if;
8424          end Float_Representation;
8425
8426          -----------
8427          -- Ident --
8428          -----------
8429
8430          --  pragma Ident (static_string_EXPRESSION)
8431
8432          --  Note: pragma Comment shares this processing. Pragma Comment is
8433          --  identical to Ident, except that the restriction of the argument to
8434          --  31 characters and the placement restrictions are not enforced for
8435          --  pragma Comment.
8436
8437          when Pragma_Ident | Pragma_Comment => Ident : declare
8438             Str : Node_Id;
8439
8440          begin
8441             GNAT_Pragma;
8442             Check_Arg_Count (1);
8443             Check_No_Identifiers;
8444             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8445             Store_Note (N);
8446
8447             --  For pragma Ident, preserve DEC compatibility by requiring the
8448             --  pragma to appear in a declarative part or package spec.
8449
8450             if Prag_Id = Pragma_Ident then
8451                Check_Is_In_Decl_Part_Or_Package_Spec;
8452             end if;
8453
8454             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8455
8456             declare
8457                CS : Node_Id;
8458                GP : Node_Id;
8459
8460             begin
8461                GP := Parent (Parent (N));
8462
8463                if Nkind_In (GP, N_Package_Declaration,
8464                                 N_Generic_Package_Declaration)
8465                then
8466                   GP := Parent (GP);
8467                end if;
8468
8469                --  If we have a compilation unit, then record the ident value,
8470                --  checking for improper duplication.
8471
8472                if Nkind (GP) = N_Compilation_Unit then
8473                   CS := Ident_String (Current_Sem_Unit);
8474
8475                   if Present (CS) then
8476
8477                      --  For Ident, we do not permit multiple instances
8478
8479                      if Prag_Id = Pragma_Ident then
8480                         Error_Pragma ("duplicate% pragma not permitted");
8481
8482                      --  For Comment, we concatenate the string, unless we want
8483                      --  to preserve the tree structure for ASIS.
8484
8485                      elsif not ASIS_Mode then
8486                         Start_String (Strval (CS));
8487                         Store_String_Char (' ');
8488                         Store_String_Chars (Strval (Str));
8489                         Set_Strval (CS, End_String);
8490                      end if;
8491
8492                   else
8493                      --  In VMS, the effect of IDENT is achieved by passing
8494                      --  --identification=name as a --for-linker switch.
8495
8496                      if OpenVMS_On_Target then
8497                         Start_String;
8498                         Store_String_Chars
8499                           ("--for-linker=--identification=");
8500                         String_To_Name_Buffer (Strval (Str));
8501                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
8502
8503                         --  Only the last processed IDENT is saved. The main
8504                         --  purpose is so an IDENT associated with a main
8505                         --  procedure will be used in preference to an IDENT
8506                         --  associated with a with'd package.
8507
8508                         Replace_Linker_Option_String
8509                           (End_String, "--for-linker=--identification=");
8510                      end if;
8511
8512                      Set_Ident_String (Current_Sem_Unit, Str);
8513                   end if;
8514
8515                --  For subunits, we just ignore the Ident, since in GNAT these
8516                --  are not separate object files, and hence not separate units
8517                --  in the unit table.
8518
8519                elsif Nkind (GP) = N_Subunit then
8520                   null;
8521
8522                --  Otherwise we have a misplaced pragma Ident, but we ignore
8523                --  this if we are in an instantiation, since it comes from
8524                --  a generic, and has no relevance to the instantiation.
8525
8526                elsif Prag_Id = Pragma_Ident then
8527                   if Instantiation_Location (Loc) = No_Location then
8528                      Error_Pragma ("pragma% only allowed at outer level");
8529                   end if;
8530                end if;
8531             end;
8532          end Ident;
8533
8534          -----------------
8535          -- Implemented --
8536          -----------------
8537
8538          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8539          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8540
8541          when Pragma_Implemented => Implemented : declare
8542             Proc_Id : Entity_Id;
8543             Typ     : Entity_Id;
8544
8545          begin
8546             Ada_2012_Pragma;
8547             Check_Arg_Count (2);
8548             Check_No_Identifiers;
8549             Check_Arg_Is_Identifier (Arg1);
8550             Check_Arg_Is_Local_Name (Arg1);
8551             Check_Arg_Is_One_Of
8552               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8553
8554             --  Extract the name of the local procedure
8555
8556             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8557
8558             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8559             --  primitive procedure of a synchronized tagged type.
8560
8561             if Ekind (Proc_Id) = E_Procedure
8562               and then Is_Primitive (Proc_Id)
8563               and then Present (First_Formal (Proc_Id))
8564             then
8565                Typ := Etype (First_Formal (Proc_Id));
8566
8567                if Is_Tagged_Type (Typ)
8568                  and then
8569
8570                   --  Check for a protected, a synchronized or a task interface
8571
8572                    ((Is_Interface (Typ)
8573                        and then Is_Synchronized_Interface (Typ))
8574
8575                   --  Check for a protected type or a task type that implements
8576                   --  an interface.
8577
8578                    or else
8579                     (Is_Concurrent_Record_Type (Typ)
8580                        and then Present (Interfaces (Typ)))
8581
8582                   --  Check for a private record extension with keyword
8583                   --  "synchronized".
8584
8585                    or else
8586                     (Ekind_In (Typ, E_Record_Type_With_Private,
8587                                     E_Record_Subtype_With_Private)
8588                        and then Synchronized_Present (Parent (Typ))))
8589                then
8590                   null;
8591                else
8592                   Error_Pragma_Arg
8593                     ("controlling formal must be of synchronized " &
8594                      "tagged type", Arg1);
8595                   return;
8596                end if;
8597
8598             --  Procedures declared inside a protected type must be accepted
8599
8600             elsif Ekind (Proc_Id) = E_Procedure
8601               and then Is_Protected_Type (Scope (Proc_Id))
8602             then
8603                null;
8604
8605             --  The first argument is not a primitive procedure
8606
8607             else
8608                Error_Pragma_Arg
8609                  ("pragma % must be applied to a primitive procedure", Arg1);
8610                return;
8611             end if;
8612
8613             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8614             --  By_Protected_Procedure to the primitive procedure of a task
8615             --  interface.
8616
8617             if Chars (Arg2) = Name_By_Protected_Procedure
8618               and then Is_Interface (Typ)
8619               and then Is_Task_Interface (Typ)
8620             then
8621                Error_Pragma_Arg
8622                  ("implementation kind By_Protected_Procedure cannot be " &
8623                   "applied to a task interface primitive", Arg2);
8624                return;
8625             end if;
8626
8627             Record_Rep_Item (Proc_Id, N);
8628          end Implemented;
8629
8630          ----------------------
8631          -- Implicit_Packing --
8632          ----------------------
8633
8634          --  pragma Implicit_Packing;
8635
8636          when Pragma_Implicit_Packing =>
8637             GNAT_Pragma;
8638             Check_Arg_Count (0);
8639             Implicit_Packing := True;
8640
8641          ------------
8642          -- Import --
8643          ------------
8644
8645          --  pragma Import (
8646          --       [Convention    =>] convention_IDENTIFIER,
8647          --       [Entity        =>] local_NAME
8648          --    [, [External_Name =>] static_string_EXPRESSION ]
8649          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8650
8651          when Pragma_Import =>
8652             Check_Ada_83_Warning;
8653             Check_Arg_Order
8654               ((Name_Convention,
8655                 Name_Entity,
8656                 Name_External_Name,
8657                 Name_Link_Name));
8658             Check_At_Least_N_Arguments (2);
8659             Check_At_Most_N_Arguments  (4);
8660             Process_Import_Or_Interface;
8661
8662          ----------------------
8663          -- Import_Exception --
8664          ----------------------
8665
8666          --  pragma Import_Exception (
8667          --        [Internal         =>] LOCAL_NAME
8668          --     [, [External         =>] EXTERNAL_SYMBOL]
8669          --     [, [Form     =>] Ada | VMS]
8670          --     [, [Code     =>] static_integer_EXPRESSION]);
8671
8672          when Pragma_Import_Exception => Import_Exception : declare
8673             Args  : Args_List (1 .. 4);
8674             Names : constant Name_List (1 .. 4) := (
8675                       Name_Internal,
8676                       Name_External,
8677                       Name_Form,
8678                       Name_Code);
8679
8680             Internal : Node_Id renames Args (1);
8681             External : Node_Id renames Args (2);
8682             Form     : Node_Id renames Args (3);
8683             Code     : Node_Id renames Args (4);
8684
8685          begin
8686             GNAT_Pragma;
8687             Gather_Associations (Names, Args);
8688
8689             if Present (External) and then Present (Code) then
8690                Error_Pragma
8691                  ("cannot give both External and Code options for pragma%");
8692             end if;
8693
8694             Process_Extended_Import_Export_Exception_Pragma (
8695               Arg_Internal => Internal,
8696               Arg_External => External,
8697               Arg_Form     => Form,
8698               Arg_Code     => Code);
8699
8700             if not Is_VMS_Exception (Entity (Internal)) then
8701                Set_Imported (Entity (Internal));
8702             end if;
8703          end Import_Exception;
8704
8705          ---------------------
8706          -- Import_Function --
8707          ---------------------
8708
8709          --  pragma Import_Function (
8710          --        [Internal                 =>] LOCAL_NAME,
8711          --     [, [External                 =>] EXTERNAL_SYMBOL]
8712          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
8713          --     [, [Result_Type              =>] SUBTYPE_MARK]
8714          --     [, [Mechanism                =>] MECHANISM]
8715          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
8716          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
8717
8718          --  EXTERNAL_SYMBOL ::=
8719          --    IDENTIFIER
8720          --  | static_string_EXPRESSION
8721
8722          --  PARAMETER_TYPES ::=
8723          --    null
8724          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8725
8726          --  TYPE_DESIGNATOR ::=
8727          --    subtype_NAME
8728          --  | subtype_Name ' Access
8729
8730          --  MECHANISM ::=
8731          --    MECHANISM_NAME
8732          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8733
8734          --  MECHANISM_ASSOCIATION ::=
8735          --    [formal_parameter_NAME =>] MECHANISM_NAME
8736
8737          --  MECHANISM_NAME ::=
8738          --    Value
8739          --  | Reference
8740          --  | Descriptor [([Class =>] CLASS_NAME)]
8741
8742          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8743
8744          when Pragma_Import_Function => Import_Function : declare
8745             Args  : Args_List (1 .. 7);
8746             Names : constant Name_List (1 .. 7) := (
8747                       Name_Internal,
8748                       Name_External,
8749                       Name_Parameter_Types,
8750                       Name_Result_Type,
8751                       Name_Mechanism,
8752                       Name_Result_Mechanism,
8753                       Name_First_Optional_Parameter);
8754
8755             Internal                 : Node_Id renames Args (1);
8756             External                 : Node_Id renames Args (2);
8757             Parameter_Types          : Node_Id renames Args (3);
8758             Result_Type              : Node_Id renames Args (4);
8759             Mechanism                : Node_Id renames Args (5);
8760             Result_Mechanism         : Node_Id renames Args (6);
8761             First_Optional_Parameter : Node_Id renames Args (7);
8762
8763          begin
8764             GNAT_Pragma;
8765             Gather_Associations (Names, Args);
8766             Process_Extended_Import_Export_Subprogram_Pragma (
8767               Arg_Internal                 => Internal,
8768               Arg_External                 => External,
8769               Arg_Parameter_Types          => Parameter_Types,
8770               Arg_Result_Type              => Result_Type,
8771               Arg_Mechanism                => Mechanism,
8772               Arg_Result_Mechanism         => Result_Mechanism,
8773               Arg_First_Optional_Parameter => First_Optional_Parameter);
8774          end Import_Function;
8775
8776          -------------------
8777          -- Import_Object --
8778          -------------------
8779
8780          --  pragma Import_Object (
8781          --        [Internal =>] LOCAL_NAME
8782          --     [, [External =>] EXTERNAL_SYMBOL]
8783          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8784
8785          --  EXTERNAL_SYMBOL ::=
8786          --    IDENTIFIER
8787          --  | static_string_EXPRESSION
8788
8789          when Pragma_Import_Object => Import_Object : declare
8790             Args  : Args_List (1 .. 3);
8791             Names : constant Name_List (1 .. 3) := (
8792                       Name_Internal,
8793                       Name_External,
8794                       Name_Size);
8795
8796             Internal : Node_Id renames Args (1);
8797             External : Node_Id renames Args (2);
8798             Size     : Node_Id renames Args (3);
8799
8800          begin
8801             GNAT_Pragma;
8802             Gather_Associations (Names, Args);
8803             Process_Extended_Import_Export_Object_Pragma (
8804               Arg_Internal => Internal,
8805               Arg_External => External,
8806               Arg_Size     => Size);
8807          end Import_Object;
8808
8809          ----------------------
8810          -- Import_Procedure --
8811          ----------------------
8812
8813          --  pragma Import_Procedure (
8814          --        [Internal                 =>] LOCAL_NAME
8815          --     [, [External                 =>] EXTERNAL_SYMBOL]
8816          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
8817          --     [, [Mechanism                =>] MECHANISM]
8818          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
8819
8820          --  EXTERNAL_SYMBOL ::=
8821          --    IDENTIFIER
8822          --  | static_string_EXPRESSION
8823
8824          --  PARAMETER_TYPES ::=
8825          --    null
8826          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8827
8828          --  TYPE_DESIGNATOR ::=
8829          --    subtype_NAME
8830          --  | subtype_Name ' Access
8831
8832          --  MECHANISM ::=
8833          --    MECHANISM_NAME
8834          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8835
8836          --  MECHANISM_ASSOCIATION ::=
8837          --    [formal_parameter_NAME =>] MECHANISM_NAME
8838
8839          --  MECHANISM_NAME ::=
8840          --    Value
8841          --  | Reference
8842          --  | Descriptor [([Class =>] CLASS_NAME)]
8843
8844          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8845
8846          when Pragma_Import_Procedure => Import_Procedure : declare
8847             Args  : Args_List (1 .. 5);
8848             Names : constant Name_List (1 .. 5) := (
8849                       Name_Internal,
8850                       Name_External,
8851                       Name_Parameter_Types,
8852                       Name_Mechanism,
8853                       Name_First_Optional_Parameter);
8854
8855             Internal                 : Node_Id renames Args (1);
8856             External                 : Node_Id renames Args (2);
8857             Parameter_Types          : Node_Id renames Args (3);
8858             Mechanism                : Node_Id renames Args (4);
8859             First_Optional_Parameter : Node_Id renames Args (5);
8860
8861          begin
8862             GNAT_Pragma;
8863             Gather_Associations (Names, Args);
8864             Process_Extended_Import_Export_Subprogram_Pragma (
8865               Arg_Internal                 => Internal,
8866               Arg_External                 => External,
8867               Arg_Parameter_Types          => Parameter_Types,
8868               Arg_Mechanism                => Mechanism,
8869               Arg_First_Optional_Parameter => First_Optional_Parameter);
8870          end Import_Procedure;
8871
8872          -----------------------------
8873          -- Import_Valued_Procedure --
8874          -----------------------------
8875
8876          --  pragma Import_Valued_Procedure (
8877          --        [Internal                 =>] LOCAL_NAME
8878          --     [, [External                 =>] EXTERNAL_SYMBOL]
8879          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
8880          --     [, [Mechanism                =>] MECHANISM]
8881          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
8882
8883          --  EXTERNAL_SYMBOL ::=
8884          --    IDENTIFIER
8885          --  | static_string_EXPRESSION
8886
8887          --  PARAMETER_TYPES ::=
8888          --    null
8889          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8890
8891          --  TYPE_DESIGNATOR ::=
8892          --    subtype_NAME
8893          --  | subtype_Name ' Access
8894
8895          --  MECHANISM ::=
8896          --    MECHANISM_NAME
8897          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8898
8899          --  MECHANISM_ASSOCIATION ::=
8900          --    [formal_parameter_NAME =>] MECHANISM_NAME
8901
8902          --  MECHANISM_NAME ::=
8903          --    Value
8904          --  | Reference
8905          --  | Descriptor [([Class =>] CLASS_NAME)]
8906
8907          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8908
8909          when Pragma_Import_Valued_Procedure =>
8910          Import_Valued_Procedure : declare
8911             Args  : Args_List (1 .. 5);
8912             Names : constant Name_List (1 .. 5) := (
8913                       Name_Internal,
8914                       Name_External,
8915                       Name_Parameter_Types,
8916                       Name_Mechanism,
8917                       Name_First_Optional_Parameter);
8918
8919             Internal                 : Node_Id renames Args (1);
8920             External                 : Node_Id renames Args (2);
8921             Parameter_Types          : Node_Id renames Args (3);
8922             Mechanism                : Node_Id renames Args (4);
8923             First_Optional_Parameter : Node_Id renames Args (5);
8924
8925          begin
8926             GNAT_Pragma;
8927             Gather_Associations (Names, Args);
8928             Process_Extended_Import_Export_Subprogram_Pragma (
8929               Arg_Internal                 => Internal,
8930               Arg_External                 => External,
8931               Arg_Parameter_Types          => Parameter_Types,
8932               Arg_Mechanism                => Mechanism,
8933               Arg_First_Optional_Parameter => First_Optional_Parameter);
8934          end Import_Valued_Procedure;
8935
8936          -----------------
8937          -- Independent --
8938          -----------------
8939
8940          --  pragma Independent (LOCAL_NAME);
8941
8942          when Pragma_Independent => Independent : declare
8943             E_Id : Node_Id;
8944             E    : Entity_Id;
8945             D    : Node_Id;
8946             K    : Node_Kind;
8947
8948          begin
8949             Check_Ada_83_Warning;
8950             Ada_2012_Pragma;
8951             Check_No_Identifiers;
8952             Check_Arg_Count (1);
8953             Check_Arg_Is_Local_Name (Arg1);
8954             E_Id := Get_Pragma_Arg (Arg1);
8955
8956             if Etype (E_Id) = Any_Type then
8957                return;
8958             end if;
8959
8960             E := Entity (E_Id);
8961             D := Declaration_Node (E);
8962             K := Nkind (D);
8963
8964             --  Check duplicate before we chain ourselves!
8965
8966             Check_Duplicate_Pragma (E);
8967
8968             --  Check appropriate entity
8969
8970             if Is_Type (E) then
8971                if Rep_Item_Too_Early (E, N)
8972                     or else
8973                   Rep_Item_Too_Late (E, N)
8974                then
8975                   return;
8976                else
8977                   Check_First_Subtype (Arg1);
8978                end if;
8979
8980             elsif K = N_Object_Declaration
8981               or else (K = N_Component_Declaration
8982                        and then Original_Record_Component (E) = E)
8983             then
8984                if Rep_Item_Too_Late (E, N) then
8985                   return;
8986                end if;
8987
8988             else
8989                Error_Pragma_Arg
8990                  ("inappropriate entity for pragma%", Arg1);
8991             end if;
8992
8993             Independence_Checks.Append ((N, E));
8994          end Independent;
8995
8996          ----------------------------
8997          -- Independent_Components --
8998          ----------------------------
8999
9000          --  pragma Atomic_Components (array_LOCAL_NAME);
9001
9002          --  This processing is shared by Volatile_Components
9003
9004          when Pragma_Independent_Components => Independent_Components : declare
9005             E_Id : Node_Id;
9006             E    : Entity_Id;
9007             D    : Node_Id;
9008             K    : Node_Kind;
9009
9010          begin
9011             Check_Ada_83_Warning;
9012             Ada_2012_Pragma;
9013             Check_No_Identifiers;
9014             Check_Arg_Count (1);
9015             Check_Arg_Is_Local_Name (Arg1);
9016             E_Id := Get_Pragma_Arg (Arg1);
9017
9018             if Etype (E_Id) = Any_Type then
9019                return;
9020             end if;
9021
9022             E := Entity (E_Id);
9023
9024             --  Check duplicate before we chain ourselves!
9025
9026             Check_Duplicate_Pragma (E);
9027
9028             --  Check appropriate entity
9029
9030             if Rep_Item_Too_Early (E, N)
9031                  or else
9032                Rep_Item_Too_Late (E, N)
9033             then
9034                return;
9035             end if;
9036
9037             D := Declaration_Node (E);
9038             K := Nkind (D);
9039
9040             if (K = N_Full_Type_Declaration
9041                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9042               or else
9043                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9044                    and then Nkind (D) = N_Object_Declaration
9045                    and then Nkind (Object_Definition (D)) =
9046                                        N_Constrained_Array_Definition)
9047             then
9048                Independence_Checks.Append ((N, E));
9049
9050             else
9051                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9052             end if;
9053          end Independent_Components;
9054
9055          ------------------------
9056          -- Initialize_Scalars --
9057          ------------------------
9058
9059          --  pragma Initialize_Scalars;
9060
9061          when Pragma_Initialize_Scalars =>
9062             GNAT_Pragma;
9063             Check_Arg_Count (0);
9064             Check_Valid_Configuration_Pragma;
9065             Check_Restriction (No_Initialize_Scalars, N);
9066
9067             --  Initialize_Scalars creates false positives in CodePeer,
9068             --  so ignore this pragma in this mode.
9069
9070             if not Restriction_Active (No_Initialize_Scalars)
9071               and then not CodePeer_Mode
9072             then
9073                Init_Or_Norm_Scalars := True;
9074                Initialize_Scalars := True;
9075             end if;
9076
9077          ------------
9078          -- Inline --
9079          ------------
9080
9081          --  pragma Inline ( NAME {, NAME} );
9082
9083          when Pragma_Inline =>
9084
9085             --  Pragma is active if inlining option is active
9086
9087             Process_Inline (Inline_Active);
9088
9089          -------------------
9090          -- Inline_Always --
9091          -------------------
9092
9093          --  pragma Inline_Always ( NAME {, NAME} );
9094
9095          when Pragma_Inline_Always =>
9096             GNAT_Pragma;
9097
9098             --  Pragma always active unless in CodePeer mode, since this causes
9099             --  walk order issues.
9100
9101             if not CodePeer_Mode then
9102                Process_Inline (True);
9103             end if;
9104
9105          --------------------
9106          -- Inline_Generic --
9107          --------------------
9108
9109          --  pragma Inline_Generic (NAME {, NAME});
9110
9111          when Pragma_Inline_Generic =>
9112             GNAT_Pragma;
9113             Process_Generic_List;
9114
9115          ----------------------
9116          -- Inspection_Point --
9117          ----------------------
9118
9119          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
9120
9121          when Pragma_Inspection_Point => Inspection_Point : declare
9122             Arg : Node_Id;
9123             Exp : Node_Id;
9124
9125          begin
9126             if Arg_Count > 0 then
9127                Arg := Arg1;
9128                loop
9129                   Exp := Get_Pragma_Arg (Arg);
9130                   Analyze (Exp);
9131
9132                   if not Is_Entity_Name (Exp)
9133                     or else not Is_Object (Entity (Exp))
9134                   then
9135                      Error_Pragma_Arg ("object name required", Arg);
9136                   end if;
9137
9138                   Next (Arg);
9139                   exit when No (Arg);
9140                end loop;
9141             end if;
9142          end Inspection_Point;
9143
9144          ---------------
9145          -- Interface --
9146          ---------------
9147
9148          --  pragma Interface (
9149          --    [   Convention    =>] convention_IDENTIFIER,
9150          --    [   Entity        =>] local_NAME
9151          --    [, [External_Name =>] static_string_EXPRESSION ]
9152          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9153
9154          when Pragma_Interface =>
9155             GNAT_Pragma;
9156             Check_Arg_Order
9157               ((Name_Convention,
9158                 Name_Entity,
9159                 Name_External_Name,
9160                 Name_Link_Name));
9161             Check_At_Least_N_Arguments (2);
9162             Check_At_Most_N_Arguments  (4);
9163             Process_Import_Or_Interface;
9164
9165             --  In Ada 2005, the permission to use Interface (a reserved word)
9166             --  as a pragma name is considered an obsolescent feature.
9167
9168             if Ada_Version >= Ada_2005 then
9169                Check_Restriction
9170                  (No_Obsolescent_Features, Pragma_Identifier (N));
9171             end if;
9172
9173          --------------------
9174          -- Interface_Name --
9175          --------------------
9176
9177          --  pragma Interface_Name (
9178          --    [  Entity        =>] local_NAME
9179          --    [,[External_Name =>] static_string_EXPRESSION ]
9180          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
9181
9182          when Pragma_Interface_Name => Interface_Name : declare
9183             Id     : Node_Id;
9184             Def_Id : Entity_Id;
9185             Hom_Id : Entity_Id;
9186             Found  : Boolean;
9187
9188          begin
9189             GNAT_Pragma;
9190             Check_Arg_Order
9191               ((Name_Entity, Name_External_Name, Name_Link_Name));
9192             Check_At_Least_N_Arguments (2);
9193             Check_At_Most_N_Arguments  (3);
9194             Id := Get_Pragma_Arg (Arg1);
9195             Analyze (Id);
9196
9197             if not Is_Entity_Name (Id) then
9198                Error_Pragma_Arg
9199                  ("first argument for pragma% must be entity name", Arg1);
9200             elsif Etype (Id) = Any_Type then
9201                return;
9202             else
9203                Def_Id := Entity (Id);
9204             end if;
9205
9206             --  Special DEC-compatible processing for the object case, forces
9207             --  object to be imported.
9208
9209             if Ekind (Def_Id) = E_Variable then
9210                Kill_Size_Check_Code (Def_Id);
9211                Note_Possible_Modification (Id, Sure => False);
9212
9213                --  Initialization is not allowed for imported variable
9214
9215                if Present (Expression (Parent (Def_Id)))
9216                  and then Comes_From_Source (Expression (Parent (Def_Id)))
9217                then
9218                   Error_Msg_Sloc := Sloc (Def_Id);
9219                   Error_Pragma_Arg
9220                     ("no initialization allowed for declaration of& #",
9221                      Arg2);
9222
9223                else
9224                   --  For compatibility, support VADS usage of providing both
9225                   --  pragmas Interface and Interface_Name to obtain the effect
9226                   --  of a single Import pragma.
9227
9228                   if Is_Imported (Def_Id)
9229                     and then Present (First_Rep_Item (Def_Id))
9230                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9231                     and then
9232                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9233                   then
9234                      null;
9235                   else
9236                      Set_Imported (Def_Id);
9237                   end if;
9238
9239                   Set_Is_Public (Def_Id);
9240                   Process_Interface_Name (Def_Id, Arg2, Arg3);
9241                end if;
9242
9243             --  Otherwise must be subprogram
9244
9245             elsif not Is_Subprogram (Def_Id) then
9246                Error_Pragma_Arg
9247                  ("argument of pragma% is not subprogram", Arg1);
9248
9249             else
9250                Check_At_Most_N_Arguments (3);
9251                Hom_Id := Def_Id;
9252                Found := False;
9253
9254                --  Loop through homonyms
9255
9256                loop
9257                   Def_Id := Get_Base_Subprogram (Hom_Id);
9258
9259                   if Is_Imported (Def_Id) then
9260                      Process_Interface_Name (Def_Id, Arg2, Arg3);
9261                      Found := True;
9262                   end if;
9263
9264                   exit when From_Aspect_Specification (N);
9265                   Hom_Id := Homonym (Hom_Id);
9266
9267                   exit when No (Hom_Id)
9268                     or else Scope (Hom_Id) /= Current_Scope;
9269                end loop;
9270
9271                if not Found then
9272                   Error_Pragma_Arg
9273                     ("argument of pragma% is not imported subprogram",
9274                      Arg1);
9275                end if;
9276             end if;
9277          end Interface_Name;
9278
9279          -----------------------
9280          -- Interrupt_Handler --
9281          -----------------------
9282
9283          --  pragma Interrupt_Handler (handler_NAME);
9284
9285          when Pragma_Interrupt_Handler =>
9286             Check_Ada_83_Warning;
9287             Check_Arg_Count (1);
9288             Check_No_Identifiers;
9289
9290             if No_Run_Time_Mode then
9291                Error_Msg_CRT ("Interrupt_Handler pragma", N);
9292             else
9293                Check_Interrupt_Or_Attach_Handler;
9294                Process_Interrupt_Or_Attach_Handler;
9295             end if;
9296
9297          ------------------------
9298          -- Interrupt_Priority --
9299          ------------------------
9300
9301          --  pragma Interrupt_Priority [(EXPRESSION)];
9302
9303          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9304             P   : constant Node_Id := Parent (N);
9305             Arg : Node_Id;
9306
9307          begin
9308             Check_Ada_83_Warning;
9309
9310             if Arg_Count /= 0 then
9311                Arg := Get_Pragma_Arg (Arg1);
9312                Check_Arg_Count (1);
9313                Check_No_Identifiers;
9314
9315                --  The expression must be analyzed in the special manner
9316                --  described in "Handling of Default and Per-Object
9317                --  Expressions" in sem.ads.
9318
9319                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9320             end if;
9321
9322             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9323                Pragma_Misplaced;
9324                return;
9325
9326             elsif Has_Pragma_Priority (P) then
9327                Error_Pragma ("duplicate pragma% not allowed");
9328
9329             else
9330                Set_Has_Pragma_Priority (P, True);
9331                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9332             end if;
9333          end Interrupt_Priority;
9334
9335          ---------------------
9336          -- Interrupt_State --
9337          ---------------------
9338
9339          --  pragma Interrupt_State (
9340          --    [Name  =>] INTERRUPT_ID,
9341          --    [State =>] INTERRUPT_STATE);
9342
9343          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9344          --  INTERRUPT_STATE => System | Runtime | User
9345
9346          --  Note: if the interrupt id is given as an identifier, then it must
9347          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9348          --  given as a static integer expression which must be in the range of
9349          --  Ada.Interrupts.Interrupt_ID.
9350
9351          when Pragma_Interrupt_State => Interrupt_State : declare
9352
9353             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9354             --  This is the entity Ada.Interrupts.Interrupt_ID;
9355
9356             State_Type : Character;
9357             --  Set to 's'/'r'/'u' for System/Runtime/User
9358
9359             IST_Num : Pos;
9360             --  Index to entry in Interrupt_States table
9361
9362             Int_Val : Uint;
9363             --  Value of interrupt
9364
9365             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9366             --  The first argument to the pragma
9367
9368             Int_Ent : Entity_Id;
9369             --  Interrupt entity in Ada.Interrupts.Names
9370
9371          begin
9372             GNAT_Pragma;
9373             Check_Arg_Order ((Name_Name, Name_State));
9374             Check_Arg_Count (2);
9375
9376             Check_Optional_Identifier (Arg1, Name_Name);
9377             Check_Optional_Identifier (Arg2, Name_State);
9378             Check_Arg_Is_Identifier (Arg2);
9379
9380             --  First argument is identifier
9381
9382             if Nkind (Arg1X) = N_Identifier then
9383
9384                --  Search list of names in Ada.Interrupts.Names
9385
9386                Int_Ent := First_Entity (RTE (RE_Names));
9387                loop
9388                   if No (Int_Ent) then
9389                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
9390
9391                   elsif Chars (Int_Ent) = Chars (Arg1X) then
9392                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
9393                      exit;
9394                   end if;
9395
9396                   Next_Entity (Int_Ent);
9397                end loop;
9398
9399             --  First argument is not an identifier, so it must be a static
9400             --  expression of type Ada.Interrupts.Interrupt_ID.
9401
9402             else
9403                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9404                Int_Val := Expr_Value (Arg1X);
9405
9406                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9407                     or else
9408                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9409                then
9410                   Error_Pragma_Arg
9411                     ("value not in range of type " &
9412                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9413                end if;
9414             end if;
9415
9416             --  Check OK state
9417
9418             case Chars (Get_Pragma_Arg (Arg2)) is
9419                when Name_Runtime => State_Type := 'r';
9420                when Name_System  => State_Type := 's';
9421                when Name_User    => State_Type := 'u';
9422
9423                when others =>
9424                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
9425             end case;
9426
9427             --  Check if entry is already stored
9428
9429             IST_Num := Interrupt_States.First;
9430             loop
9431                --  If entry not found, add it
9432
9433                if IST_Num > Interrupt_States.Last then
9434                   Interrupt_States.Append
9435                     ((Interrupt_Number => UI_To_Int (Int_Val),
9436                       Interrupt_State  => State_Type,
9437                       Pragma_Loc       => Loc));
9438                   exit;
9439
9440                --  Case of entry for the same entry
9441
9442                elsif Int_Val = Interrupt_States.Table (IST_Num).
9443                                                            Interrupt_Number
9444                then
9445                   --  If state matches, done, no need to make redundant entry
9446
9447                   exit when
9448                     State_Type = Interrupt_States.Table (IST_Num).
9449                                                            Interrupt_State;
9450
9451                   --  Otherwise if state does not match, error
9452
9453                   Error_Msg_Sloc :=
9454                     Interrupt_States.Table (IST_Num).Pragma_Loc;
9455                   Error_Pragma_Arg
9456                     ("state conflicts with that given #", Arg2);
9457                   exit;
9458                end if;
9459
9460                IST_Num := IST_Num + 1;
9461             end loop;
9462          end Interrupt_State;
9463
9464          ---------------
9465          -- Invariant --
9466          ---------------
9467
9468          --  pragma Invariant
9469          --    ([Entity =>]    type_LOCAL_NAME,
9470          --     [Check  =>]    EXPRESSION
9471          --     [,[Message =>] String_Expression]);
9472
9473          when Pragma_Invariant => Invariant : declare
9474             Type_Id : Node_Id;
9475             Typ     : Entity_Id;
9476
9477             Discard : Boolean;
9478             pragma Unreferenced (Discard);
9479
9480          begin
9481             GNAT_Pragma;
9482             Check_At_Least_N_Arguments (2);
9483             Check_At_Most_N_Arguments (3);
9484             Check_Optional_Identifier (Arg1, Name_Entity);
9485             Check_Optional_Identifier (Arg2, Name_Check);
9486
9487             if Arg_Count = 3 then
9488                Check_Optional_Identifier (Arg3, Name_Message);
9489                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9490             end if;
9491
9492             Check_Arg_Is_Local_Name (Arg1);
9493
9494             Type_Id := Get_Pragma_Arg (Arg1);
9495             Find_Type (Type_Id);
9496             Typ := Entity (Type_Id);
9497
9498             if Typ = Any_Type then
9499                return;
9500
9501             elsif not Ekind_In (Typ, E_Private_Type,
9502                                      E_Record_Type_With_Private,
9503                                      E_Limited_Private_Type)
9504             then
9505                Error_Pragma_Arg
9506                  ("pragma% only allowed for private type", Arg1);
9507             end if;
9508
9509             --  Note that the type has at least one invariant, and also that
9510             --  it has inheritable invariants if we have Invariant'Class.
9511
9512             Set_Has_Invariants (Typ);
9513
9514             if Class_Present (N) then
9515                Set_Has_Inheritable_Invariants (Typ);
9516             end if;
9517
9518             --  The remaining processing is simply to link the pragma on to
9519             --  the rep item chain, for processing when the type is frozen.
9520             --  This is accomplished by a call to Rep_Item_Too_Late.
9521
9522             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9523          end Invariant;
9524
9525          ----------------------
9526          -- Java_Constructor --
9527          ----------------------
9528
9529          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9530
9531          --  Also handles pragma CIL_Constructor
9532
9533          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9534          Java_Constructor : declare
9535             Convention  : Convention_Id;
9536             Def_Id      : Entity_Id;
9537             Hom_Id      : Entity_Id;
9538             Id          : Entity_Id;
9539             This_Formal : Entity_Id;
9540
9541          begin
9542             GNAT_Pragma;
9543             Check_Arg_Count (1);
9544             Check_Optional_Identifier (Arg1, Name_Entity);
9545             Check_Arg_Is_Local_Name (Arg1);
9546
9547             Id := Get_Pragma_Arg (Arg1);
9548             Find_Program_Unit_Name (Id);
9549
9550             --  If we did not find the name, we are done
9551
9552             if Etype (Id) = Any_Type then
9553                return;
9554             end if;
9555
9556             --  Check wrong use of pragma in wrong VM target
9557
9558             if VM_Target = No_VM then
9559                return;
9560
9561             elsif VM_Target = CLI_Target
9562               and then Prag_Id = Pragma_Java_Constructor
9563             then
9564                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9565
9566             elsif VM_Target = JVM_Target
9567               and then Prag_Id = Pragma_CIL_Constructor
9568             then
9569                Error_Pragma ("must use pragma 'Java_'Constructor");
9570             end if;
9571
9572             case Prag_Id is
9573                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
9574                when Pragma_Java_Constructor => Convention := Convention_Java;
9575                when others                  => null;
9576             end case;
9577
9578             Hom_Id := Entity (Id);
9579
9580             --  Loop through homonyms
9581
9582             loop
9583                Def_Id := Get_Base_Subprogram (Hom_Id);
9584
9585                --  The constructor is required to be a function
9586
9587                if Ekind (Def_Id) /= E_Function then
9588                   if VM_Target = JVM_Target then
9589                      Error_Pragma_Arg
9590                        ("pragma% requires function returning a " &
9591                         "'Java access type", Def_Id);
9592                   else
9593                      Error_Pragma_Arg
9594                        ("pragma% requires function returning a " &
9595                         "'C'I'L access type", Def_Id);
9596                   end if;
9597                end if;
9598
9599                --  Check arguments: For tagged type the first formal must be
9600                --  named "this" and its type must be a named access type
9601                --  designating a class-wide tagged type that has convention
9602                --  CIL/Java. The first formal must also have a null default
9603                --  value. For example:
9604
9605                --      type Typ is tagged ...
9606                --      type Ref is access all Typ;
9607                --      pragma Convention (CIL, Typ);
9608
9609                --      function New_Typ (This : Ref) return Ref;
9610                --      function New_Typ (This : Ref; I : Integer) return Ref;
9611                --      pragma Cil_Constructor (New_Typ);
9612
9613                --  Reason: The first formal must NOT be a primitive of the
9614                --  tagged type.
9615
9616                --  This rule also applies to constructors of delegates used
9617                --  to interface with standard target libraries. For example:
9618
9619                --      type Delegate is access procedure ...
9620                --      pragma Import (CIL, Delegate, ...);
9621
9622                --      function new_Delegate
9623                --        (This : Delegate := null; ... ) return Delegate;
9624
9625                --  For value-types this rule does not apply.
9626
9627                if not Is_Value_Type (Etype (Def_Id)) then
9628                   if No (First_Formal (Def_Id)) then
9629                      Error_Msg_Name_1 := Pname;
9630                      Error_Msg_N ("% function must have parameters", Def_Id);
9631                      return;
9632                   end if;
9633
9634                   --  In the JRE library we have several occurrences in which
9635                   --  the "this" parameter is not the first formal.
9636
9637                   This_Formal := First_Formal (Def_Id);
9638
9639                   --  In the JRE library we have several occurrences in which
9640                   --  the "this" parameter is not the first formal. Search for
9641                   --  it.
9642
9643                   if VM_Target = JVM_Target then
9644                      while Present (This_Formal)
9645                        and then Get_Name_String (Chars (This_Formal)) /= "this"
9646                      loop
9647                         Next_Formal (This_Formal);
9648                      end loop;
9649
9650                      if No (This_Formal) then
9651                         This_Formal := First_Formal (Def_Id);
9652                      end if;
9653                   end if;
9654
9655                   --  Warning: The first parameter should be named "this".
9656                   --  We temporarily allow it because we have the following
9657                   --  case in the Java runtime (file s-osinte.ads) ???
9658
9659                   --    function new_Thread
9660                   --      (Self_Id : System.Address) return Thread_Id;
9661                   --    pragma Java_Constructor (new_Thread);
9662
9663                   if VM_Target = JVM_Target
9664                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
9665                                = "self_id"
9666                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9667                   then
9668                      null;
9669
9670                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9671                      Error_Msg_Name_1 := Pname;
9672                      Error_Msg_N
9673                        ("first formal of % function must be named `this`",
9674                         Parent (This_Formal));
9675
9676                   elsif not Is_Access_Type (Etype (This_Formal)) then
9677                      Error_Msg_Name_1 := Pname;
9678                      Error_Msg_N
9679                        ("first formal of % function must be an access type",
9680                         Parameter_Type (Parent (This_Formal)));
9681
9682                   --  For delegates the type of the first formal must be a
9683                   --  named access-to-subprogram type (see previous example)
9684
9685                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9686                     and then Ekind (Etype (This_Formal))
9687                                /= E_Access_Subprogram_Type
9688                   then
9689                      Error_Msg_Name_1 := Pname;
9690                      Error_Msg_N
9691                        ("first formal of % function must be a named access" &
9692                         " to subprogram type",
9693                         Parameter_Type (Parent (This_Formal)));
9694
9695                   --  Warning: We should reject anonymous access types because
9696                   --  the constructor must not be handled as a primitive of the
9697                   --  tagged type. We temporarily allow it because this profile
9698                   --  is currently generated by cil2ada???
9699
9700                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9701                     and then not Ekind_In (Etype (This_Formal),
9702                                              E_Access_Type,
9703                                              E_General_Access_Type,
9704                                              E_Anonymous_Access_Type)
9705                   then
9706                      Error_Msg_Name_1 := Pname;
9707                      Error_Msg_N
9708                        ("first formal of % function must be a named access" &
9709                         " type",
9710                         Parameter_Type (Parent (This_Formal)));
9711
9712                   elsif Atree.Convention
9713                          (Designated_Type (Etype (This_Formal))) /= Convention
9714                   then
9715                      Error_Msg_Name_1 := Pname;
9716
9717                      if Convention = Convention_Java then
9718                         Error_Msg_N
9719                           ("pragma% requires convention 'Cil in designated" &
9720                            " type",
9721                            Parameter_Type (Parent (This_Formal)));
9722                      else
9723                         Error_Msg_N
9724                           ("pragma% requires convention 'Java in designated" &
9725                            " type",
9726                            Parameter_Type (Parent (This_Formal)));
9727                      end if;
9728
9729                   elsif No (Expression (Parent (This_Formal)))
9730                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9731                   then
9732                      Error_Msg_Name_1 := Pname;
9733                      Error_Msg_N
9734                        ("pragma% requires first formal with default `null`",
9735                         Parameter_Type (Parent (This_Formal)));
9736                   end if;
9737                end if;
9738
9739                --  Check result type: the constructor must be a function
9740                --  returning:
9741                --   * a value type (only allowed in the CIL compiler)
9742                --   * an access-to-subprogram type with convention Java/CIL
9743                --   * an access-type designating a type that has convention
9744                --     Java/CIL.
9745
9746                if Is_Value_Type (Etype (Def_Id)) then
9747                   null;
9748
9749                --  Access-to-subprogram type with convention Java/CIL
9750
9751                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9752                   if Atree.Convention (Etype (Def_Id)) /= Convention then
9753                      if Convention = Convention_Java then
9754                         Error_Pragma_Arg
9755                           ("pragma% requires function returning a " &
9756                            "'Java access type", Arg1);
9757                      else
9758                         pragma Assert (Convention = Convention_CIL);
9759                         Error_Pragma_Arg
9760                           ("pragma% requires function returning a " &
9761                            "'C'I'L access type", Arg1);
9762                      end if;
9763                   end if;
9764
9765                elsif Ekind (Etype (Def_Id)) in Access_Kind then
9766                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
9767                                                    E_General_Access_Type)
9768                     or else
9769                       Atree.Convention
9770                         (Designated_Type (Etype (Def_Id))) /= Convention
9771                   then
9772                      Error_Msg_Name_1 := Pname;
9773
9774                      if Convention = Convention_Java then
9775                         Error_Pragma_Arg
9776                           ("pragma% requires function returning a named" &
9777                            "'Java access type", Arg1);
9778                      else
9779                         Error_Pragma_Arg
9780                           ("pragma% requires function returning a named" &
9781                            "'C'I'L access type", Arg1);
9782                      end if;
9783                   end if;
9784                end if;
9785
9786                Set_Is_Constructor (Def_Id);
9787                Set_Convention     (Def_Id, Convention);
9788                Set_Is_Imported    (Def_Id);
9789
9790                exit when From_Aspect_Specification (N);
9791                Hom_Id := Homonym (Hom_Id);
9792
9793                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9794             end loop;
9795          end Java_Constructor;
9796
9797          ----------------------
9798          -- Java_Interface --
9799          ----------------------
9800
9801          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
9802
9803          when Pragma_Java_Interface => Java_Interface : declare
9804             Arg : Node_Id;
9805             Typ : Entity_Id;
9806
9807          begin
9808             GNAT_Pragma;
9809             Check_Arg_Count (1);
9810             Check_Optional_Identifier (Arg1, Name_Entity);
9811             Check_Arg_Is_Local_Name (Arg1);
9812
9813             Arg := Get_Pragma_Arg (Arg1);
9814             Analyze (Arg);
9815
9816             if Etype (Arg) = Any_Type then
9817                return;
9818             end if;
9819
9820             if not Is_Entity_Name (Arg)
9821               or else not Is_Type (Entity (Arg))
9822             then
9823                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9824             end if;
9825
9826             Typ := Underlying_Type (Entity (Arg));
9827
9828             --  For now simply check some of the semantic constraints on the
9829             --  type. This currently leaves out some restrictions on interface
9830             --  types, namely that the parent type must be java.lang.Object.Typ
9831             --  and that all primitives of the type should be declared
9832             --  abstract. ???
9833
9834             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9835                Error_Pragma_Arg ("pragma% requires an abstract "
9836                  & "tagged type", Arg1);
9837
9838             elsif not Has_Discriminants (Typ)
9839               or else Ekind (Etype (First_Discriminant (Typ)))
9840                         /= E_Anonymous_Access_Type
9841               or else
9842                 not Is_Class_Wide_Type
9843                       (Designated_Type (Etype (First_Discriminant (Typ))))
9844             then
9845                Error_Pragma_Arg
9846                  ("type must have a class-wide access discriminant", Arg1);
9847             end if;
9848          end Java_Interface;
9849
9850          ----------------
9851          -- Keep_Names --
9852          ----------------
9853
9854          --  pragma Keep_Names ([On => ] local_NAME);
9855
9856          when Pragma_Keep_Names => Keep_Names : declare
9857             Arg : Node_Id;
9858
9859          begin
9860             GNAT_Pragma;
9861             Check_Arg_Count (1);
9862             Check_Optional_Identifier (Arg1, Name_On);
9863             Check_Arg_Is_Local_Name (Arg1);
9864
9865             Arg := Get_Pragma_Arg (Arg1);
9866             Analyze (Arg);
9867
9868             if Etype (Arg) = Any_Type then
9869                return;
9870             end if;
9871
9872             if not Is_Entity_Name (Arg)
9873               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9874             then
9875                Error_Pragma_Arg
9876                  ("pragma% requires a local enumeration type", Arg1);
9877             end if;
9878
9879             Set_Discard_Names (Entity (Arg), False);
9880          end Keep_Names;
9881
9882          -------------
9883          -- License --
9884          -------------
9885
9886          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9887
9888          when Pragma_License =>
9889             GNAT_Pragma;
9890             Check_Arg_Count (1);
9891             Check_No_Identifiers;
9892             Check_Valid_Configuration_Pragma;
9893             Check_Arg_Is_Identifier (Arg1);
9894
9895             declare
9896                Sind : constant Source_File_Index :=
9897                         Source_Index (Current_Sem_Unit);
9898
9899             begin
9900                case Chars (Get_Pragma_Arg (Arg1)) is
9901                   when Name_GPL =>
9902                      Set_License (Sind, GPL);
9903
9904                   when Name_Modified_GPL =>
9905                      Set_License (Sind, Modified_GPL);
9906
9907                   when Name_Restricted =>
9908                      Set_License (Sind, Restricted);
9909
9910                   when Name_Unrestricted =>
9911                      Set_License (Sind, Unrestricted);
9912
9913                   when others =>
9914                      Error_Pragma_Arg ("invalid license name", Arg1);
9915                end case;
9916             end;
9917
9918          ---------------
9919          -- Link_With --
9920          ---------------
9921
9922          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9923
9924          when Pragma_Link_With => Link_With : declare
9925             Arg : Node_Id;
9926
9927          begin
9928             GNAT_Pragma;
9929
9930             if Operating_Mode = Generate_Code
9931               and then In_Extended_Main_Source_Unit (N)
9932             then
9933                Check_At_Least_N_Arguments (1);
9934                Check_No_Identifiers;
9935                Check_Is_In_Decl_Part_Or_Package_Spec;
9936                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9937                Start_String;
9938
9939                Arg := Arg1;
9940                while Present (Arg) loop
9941                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
9942
9943                   --  Store argument, converting sequences of spaces to a
9944                   --  single null character (this is one of the differences
9945                   --  in processing between Link_With and Linker_Options).
9946
9947                   Arg_Store : declare
9948                      C : constant Char_Code := Get_Char_Code (' ');
9949                      S : constant String_Id :=
9950                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
9951                      L : constant Nat := String_Length (S);
9952                      F : Nat := 1;
9953
9954                      procedure Skip_Spaces;
9955                      --  Advance F past any spaces
9956
9957                      -----------------
9958                      -- Skip_Spaces --
9959                      -----------------
9960
9961                      procedure Skip_Spaces is
9962                      begin
9963                         while F <= L and then Get_String_Char (S, F) = C loop
9964                            F := F + 1;
9965                         end loop;
9966                      end Skip_Spaces;
9967
9968                   --  Start of processing for Arg_Store
9969
9970                   begin
9971                      Skip_Spaces; -- skip leading spaces
9972
9973                      --  Loop through characters, changing any embedded
9974                      --  sequence of spaces to a single null character (this
9975                      --  is how Link_With/Linker_Options differ)
9976
9977                      while F <= L loop
9978                         if Get_String_Char (S, F) = C then
9979                            Skip_Spaces;
9980                            exit when F > L;
9981                            Store_String_Char (ASCII.NUL);
9982
9983                         else
9984                            Store_String_Char (Get_String_Char (S, F));
9985                            F := F + 1;
9986                         end if;
9987                      end loop;
9988                   end Arg_Store;
9989
9990                   Arg := Next (Arg);
9991
9992                   if Present (Arg) then
9993                      Store_String_Char (ASCII.NUL);
9994                   end if;
9995                end loop;
9996
9997                Store_Linker_Option_String (End_String);
9998             end if;
9999          end Link_With;
10000
10001          ------------------
10002          -- Linker_Alias --
10003          ------------------
10004
10005          --  pragma Linker_Alias (
10006          --      [Entity =>]  LOCAL_NAME
10007          --      [Target =>]  static_string_EXPRESSION);
10008
10009          when Pragma_Linker_Alias =>
10010             GNAT_Pragma;
10011             Check_Arg_Order ((Name_Entity, Name_Target));
10012             Check_Arg_Count (2);
10013             Check_Optional_Identifier (Arg1, Name_Entity);
10014             Check_Optional_Identifier (Arg2, Name_Target);
10015             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10016             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10017
10018             --  The only processing required is to link this item on to the
10019             --  list of rep items for the given entity. This is accomplished
10020             --  by the call to Rep_Item_Too_Late (when no error is detected
10021             --  and False is returned).
10022
10023             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10024                return;
10025             else
10026                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10027             end if;
10028
10029          ------------------------
10030          -- Linker_Constructor --
10031          ------------------------
10032
10033          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
10034
10035          --  Code is shared with Linker_Destructor
10036
10037          -----------------------
10038          -- Linker_Destructor --
10039          -----------------------
10040
10041          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
10042
10043          when Pragma_Linker_Constructor |
10044               Pragma_Linker_Destructor =>
10045          Linker_Constructor : declare
10046             Arg1_X : Node_Id;
10047             Proc   : Entity_Id;
10048
10049          begin
10050             GNAT_Pragma;
10051             Check_Arg_Count (1);
10052             Check_No_Identifiers;
10053             Check_Arg_Is_Local_Name (Arg1);
10054             Arg1_X := Get_Pragma_Arg (Arg1);
10055             Analyze (Arg1_X);
10056             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10057
10058             if not Is_Library_Level_Entity (Proc) then
10059                Error_Pragma_Arg
10060                 ("argument for pragma% must be library level entity", Arg1);
10061             end if;
10062
10063             --  The only processing required is to link this item on to the
10064             --  list of rep items for the given entity. This is accomplished
10065             --  by the call to Rep_Item_Too_Late (when no error is detected
10066             --  and False is returned).
10067
10068             if Rep_Item_Too_Late (Proc, N) then
10069                return;
10070             else
10071                Set_Has_Gigi_Rep_Item (Proc);
10072             end if;
10073          end Linker_Constructor;
10074
10075          --------------------
10076          -- Linker_Options --
10077          --------------------
10078
10079          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10080
10081          when Pragma_Linker_Options => Linker_Options : declare
10082             Arg : Node_Id;
10083
10084          begin
10085             Check_Ada_83_Warning;
10086             Check_No_Identifiers;
10087             Check_Arg_Count (1);
10088             Check_Is_In_Decl_Part_Or_Package_Spec;
10089             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10090             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10091
10092             Arg := Arg2;
10093             while Present (Arg) loop
10094                Check_Arg_Is_Static_Expression (Arg, Standard_String);
10095                Store_String_Char (ASCII.NUL);
10096                Store_String_Chars
10097                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10098                Arg := Next (Arg);
10099             end loop;
10100
10101             if Operating_Mode = Generate_Code
10102               and then In_Extended_Main_Source_Unit (N)
10103             then
10104                Store_Linker_Option_String (End_String);
10105             end if;
10106          end Linker_Options;
10107
10108          --------------------
10109          -- Linker_Section --
10110          --------------------
10111
10112          --  pragma Linker_Section (
10113          --      [Entity  =>]  LOCAL_NAME
10114          --      [Section =>]  static_string_EXPRESSION);
10115
10116          when Pragma_Linker_Section =>
10117             GNAT_Pragma;
10118             Check_Arg_Order ((Name_Entity, Name_Section));
10119             Check_Arg_Count (2);
10120             Check_Optional_Identifier (Arg1, Name_Entity);
10121             Check_Optional_Identifier (Arg2, Name_Section);
10122             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10123             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10124
10125             --  This pragma applies only to objects
10126
10127             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10128                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10129             end if;
10130
10131             --  The only processing required is to link this item on to the
10132             --  list of rep items for the given entity. This is accomplished
10133             --  by the call to Rep_Item_Too_Late (when no error is detected
10134             --  and False is returned).
10135
10136             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10137                return;
10138             else
10139                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10140             end if;
10141
10142          ----------
10143          -- List --
10144          ----------
10145
10146          --  pragma List (On | Off)
10147
10148          --  There is nothing to do here, since we did all the processing for
10149          --  this pragma in Par.Prag (so that it works properly even in syntax
10150          --  only mode).
10151
10152          when Pragma_List =>
10153             null;
10154
10155          --------------------
10156          -- Locking_Policy --
10157          --------------------
10158
10159          --  pragma Locking_Policy (policy_IDENTIFIER);
10160
10161          when Pragma_Locking_Policy => declare
10162             LP : Character;
10163
10164          begin
10165             Check_Ada_83_Warning;
10166             Check_Arg_Count (1);
10167             Check_No_Identifiers;
10168             Check_Arg_Is_Locking_Policy (Arg1);
10169             Check_Valid_Configuration_Pragma;
10170             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10171             LP := Fold_Upper (Name_Buffer (1));
10172
10173             if Locking_Policy /= ' '
10174               and then Locking_Policy /= LP
10175             then
10176                Error_Msg_Sloc := Locking_Policy_Sloc;
10177                Error_Pragma ("locking policy incompatible with policy#");
10178
10179             --  Set new policy, but always preserve System_Location since we
10180             --  like the error message with the run time name.
10181
10182             else
10183                Locking_Policy := LP;
10184
10185                if Locking_Policy_Sloc /= System_Location then
10186                   Locking_Policy_Sloc := Loc;
10187                end if;
10188             end if;
10189          end;
10190
10191          ----------------
10192          -- Long_Float --
10193          ----------------
10194
10195          --  pragma Long_Float (D_Float | G_Float);
10196
10197          when Pragma_Long_Float =>
10198             GNAT_Pragma;
10199             Check_Valid_Configuration_Pragma;
10200             Check_Arg_Count (1);
10201             Check_No_Identifier (Arg1);
10202             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10203
10204             if not OpenVMS_On_Target then
10205                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10206             end if;
10207
10208             --  D_Float case
10209
10210             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10211                if Opt.Float_Format_Long = 'G' then
10212                   Error_Pragma ("G_Float previously specified");
10213                end if;
10214
10215                Opt.Float_Format_Long := 'D';
10216
10217             --  G_Float case (this is the default, does not need overriding)
10218
10219             else
10220                if Opt.Float_Format_Long = 'D' then
10221                   Error_Pragma ("D_Float previously specified");
10222                end if;
10223
10224                Opt.Float_Format_Long := 'G';
10225             end if;
10226
10227             Set_Standard_Fpt_Formats;
10228
10229          -----------------------
10230          -- Machine_Attribute --
10231          -----------------------
10232
10233          --  pragma Machine_Attribute (
10234          --       [Entity         =>] LOCAL_NAME,
10235          --       [Attribute_Name =>] static_string_EXPRESSION
10236          --    [, [Info           =>] static_EXPRESSION] );
10237
10238          when Pragma_Machine_Attribute => Machine_Attribute : declare
10239             Def_Id : Entity_Id;
10240
10241          begin
10242             GNAT_Pragma;
10243             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10244
10245             if Arg_Count = 3 then
10246                Check_Optional_Identifier (Arg3, Name_Info);
10247                Check_Arg_Is_Static_Expression (Arg3);
10248             else
10249                Check_Arg_Count (2);
10250             end if;
10251
10252             Check_Optional_Identifier (Arg1, Name_Entity);
10253             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10254             Check_Arg_Is_Local_Name (Arg1);
10255             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10256             Def_Id := Entity (Get_Pragma_Arg (Arg1));
10257
10258             if Is_Access_Type (Def_Id) then
10259                Def_Id := Designated_Type (Def_Id);
10260             end if;
10261
10262             if Rep_Item_Too_Early (Def_Id, N) then
10263                return;
10264             end if;
10265
10266             Def_Id := Underlying_Type (Def_Id);
10267
10268             --  The only processing required is to link this item on to the
10269             --  list of rep items for the given entity. This is accomplished
10270             --  by the call to Rep_Item_Too_Late (when no error is detected
10271             --  and False is returned).
10272
10273             if Rep_Item_Too_Late (Def_Id, N) then
10274                return;
10275             else
10276                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10277             end if;
10278          end Machine_Attribute;
10279
10280          ----------
10281          -- Main --
10282          ----------
10283
10284          --  pragma Main
10285          --   (MAIN_OPTION [, MAIN_OPTION]);
10286
10287          --  MAIN_OPTION ::=
10288          --    [STACK_SIZE              =>] static_integer_EXPRESSION
10289          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10290          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
10291
10292          when Pragma_Main => Main : declare
10293             Args  : Args_List (1 .. 3);
10294             Names : constant Name_List (1 .. 3) := (
10295                       Name_Stack_Size,
10296                       Name_Task_Stack_Size_Default,
10297                       Name_Time_Slicing_Enabled);
10298
10299             Nod : Node_Id;
10300
10301          begin
10302             GNAT_Pragma;
10303             Gather_Associations (Names, Args);
10304
10305             for J in 1 .. 2 loop
10306                if Present (Args (J)) then
10307                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10308                end if;
10309             end loop;
10310
10311             if Present (Args (3)) then
10312                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10313             end if;
10314
10315             Nod := Next (N);
10316             while Present (Nod) loop
10317                if Nkind (Nod) = N_Pragma
10318                  and then Pragma_Name (Nod) = Name_Main
10319                then
10320                   Error_Msg_Name_1 := Pname;
10321                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10322                end if;
10323
10324                Next (Nod);
10325             end loop;
10326          end Main;
10327
10328          ------------------
10329          -- Main_Storage --
10330          ------------------
10331
10332          --  pragma Main_Storage
10333          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10334
10335          --  MAIN_STORAGE_OPTION ::=
10336          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10337          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10338
10339          when Pragma_Main_Storage => Main_Storage : declare
10340             Args  : Args_List (1 .. 2);
10341             Names : constant Name_List (1 .. 2) := (
10342                       Name_Working_Storage,
10343                       Name_Top_Guard);
10344
10345             Nod : Node_Id;
10346
10347          begin
10348             GNAT_Pragma;
10349             Gather_Associations (Names, Args);
10350
10351             for J in 1 .. 2 loop
10352                if Present (Args (J)) then
10353                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10354                end if;
10355             end loop;
10356
10357             Check_In_Main_Program;
10358
10359             Nod := Next (N);
10360             while Present (Nod) loop
10361                if Nkind (Nod) = N_Pragma
10362                  and then Pragma_Name (Nod) = Name_Main_Storage
10363                then
10364                   Error_Msg_Name_1 := Pname;
10365                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10366                end if;
10367
10368                Next (Nod);
10369             end loop;
10370          end Main_Storage;
10371
10372          -----------------
10373          -- Memory_Size --
10374          -----------------
10375
10376          --  pragma Memory_Size (NUMERIC_LITERAL)
10377
10378          when Pragma_Memory_Size =>
10379             GNAT_Pragma;
10380
10381             --  Memory size is simply ignored
10382
10383             Check_No_Identifiers;
10384             Check_Arg_Count (1);
10385             Check_Arg_Is_Integer_Literal (Arg1);
10386
10387          -------------
10388          -- No_Body --
10389          -------------
10390
10391          --  pragma No_Body;
10392
10393          --  The only correct use of this pragma is on its own in a file, in
10394          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
10395          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10396          --  check for a file containing nothing but a No_Body pragma). If we
10397          --  attempt to process it during normal semantics processing, it means
10398          --  it was misplaced.
10399
10400          when Pragma_No_Body =>
10401             GNAT_Pragma;
10402             Pragma_Misplaced;
10403
10404          ---------------
10405          -- No_Return --
10406          ---------------
10407
10408          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10409
10410          when Pragma_No_Return => No_Return : declare
10411             Id    : Node_Id;
10412             E     : Entity_Id;
10413             Found : Boolean;
10414             Arg   : Node_Id;
10415
10416          begin
10417             Ada_2005_Pragma;
10418             Check_At_Least_N_Arguments (1);
10419
10420             --  Loop through arguments of pragma
10421
10422             Arg := Arg1;
10423             while Present (Arg) loop
10424                Check_Arg_Is_Local_Name (Arg);
10425                Id := Get_Pragma_Arg (Arg);
10426                Analyze (Id);
10427
10428                if not Is_Entity_Name (Id) then
10429                   Error_Pragma_Arg ("entity name required", Arg);
10430                end if;
10431
10432                if Etype (Id) = Any_Type then
10433                   raise Pragma_Exit;
10434                end if;
10435
10436                --  Loop to find matching procedures
10437
10438                E := Entity (Id);
10439                Found := False;
10440                while Present (E)
10441                  and then Scope (E) = Current_Scope
10442                loop
10443                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10444                      Set_No_Return (E);
10445
10446                      --  Set flag on any alias as well
10447
10448                      if Is_Overloadable (E) and then Present (Alias (E)) then
10449                         Set_No_Return (Alias (E));
10450                      end if;
10451
10452                      Found := True;
10453                   end if;
10454
10455                   exit when From_Aspect_Specification (N);
10456                   E := Homonym (E);
10457                end loop;
10458
10459                if not Found then
10460                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10461                end if;
10462
10463                Next (Arg);
10464             end loop;
10465          end No_Return;
10466
10467          -----------------
10468          -- No_Run_Time --
10469          -----------------
10470
10471          --  pragma No_Run_Time;
10472
10473          --  Note: this pragma is retained for backwards compatibility. See
10474          --  body of Rtsfind for full details on its handling.
10475
10476          when Pragma_No_Run_Time =>
10477             GNAT_Pragma;
10478             Check_Valid_Configuration_Pragma;
10479             Check_Arg_Count (0);
10480
10481             No_Run_Time_Mode           := True;
10482             Configurable_Run_Time_Mode := True;
10483
10484             --  Set Duration to 32 bits if word size is 32
10485
10486             if Ttypes.System_Word_Size = 32 then
10487                Duration_32_Bits_On_Target := True;
10488             end if;
10489
10490             --  Set appropriate restrictions
10491
10492             Set_Restriction (No_Finalization, N);
10493             Set_Restriction (No_Exception_Handlers, N);
10494             Set_Restriction (Max_Tasks, N, 0);
10495             Set_Restriction (No_Tasking, N);
10496
10497          ------------------------
10498          -- No_Strict_Aliasing --
10499          ------------------------
10500
10501          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10502
10503          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10504             E_Id : Entity_Id;
10505
10506          begin
10507             GNAT_Pragma;
10508             Check_At_Most_N_Arguments (1);
10509
10510             if Arg_Count = 0 then
10511                Check_Valid_Configuration_Pragma;
10512                Opt.No_Strict_Aliasing := True;
10513
10514             else
10515                Check_Optional_Identifier (Arg2, Name_Entity);
10516                Check_Arg_Is_Local_Name (Arg1);
10517                E_Id := Entity (Get_Pragma_Arg (Arg1));
10518
10519                if E_Id = Any_Type then
10520                   return;
10521                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10522                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
10523                end if;
10524
10525                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10526             end if;
10527          end No_Strict_Aliasing;
10528
10529          -----------------------
10530          -- Normalize_Scalars --
10531          -----------------------
10532
10533          --  pragma Normalize_Scalars;
10534
10535          when Pragma_Normalize_Scalars =>
10536             Check_Ada_83_Warning;
10537             Check_Arg_Count (0);
10538             Check_Valid_Configuration_Pragma;
10539
10540             --  Normalize_Scalars creates false positives in CodePeer, so
10541             --  ignore this pragma in this mode.
10542
10543             if not CodePeer_Mode then
10544                Normalize_Scalars := True;
10545                Init_Or_Norm_Scalars := True;
10546             end if;
10547
10548          -----------------
10549          -- Obsolescent --
10550          -----------------
10551
10552          --  pragma Obsolescent;
10553
10554          --  pragma Obsolescent (
10555          --    [Message =>] static_string_EXPRESSION
10556          --  [,[Version =>] Ada_05]]);
10557
10558          --  pragma Obsolescent (
10559          --    [Entity  =>] NAME
10560          --  [,[Message =>] static_string_EXPRESSION
10561          --  [,[Version =>] Ada_05]] );
10562
10563          when Pragma_Obsolescent => Obsolescent : declare
10564             Ename : Node_Id;
10565             Decl  : Node_Id;
10566
10567             procedure Set_Obsolescent (E : Entity_Id);
10568             --  Given an entity Ent, mark it as obsolescent if appropriate
10569
10570             ---------------------
10571             -- Set_Obsolescent --
10572             ---------------------
10573
10574             procedure Set_Obsolescent (E : Entity_Id) is
10575                Active : Boolean;
10576                Ent    : Entity_Id;
10577                S      : String_Id;
10578
10579             begin
10580                Active := True;
10581                Ent    := E;
10582
10583                --  Entity name was given
10584
10585                if Present (Ename) then
10586
10587                   --  If entity name matches, we are fine. Save entity in
10588                   --  pragma argument, for ASIS use.
10589
10590                   if Chars (Ename) = Chars (Ent) then
10591                      Set_Entity (Ename, Ent);
10592                      Generate_Reference (Ent, Ename);
10593
10594                   --  If entity name does not match, only possibility is an
10595                   --  enumeration literal from an enumeration type declaration.
10596
10597                   elsif Ekind (Ent) /= E_Enumeration_Type then
10598                      Error_Pragma
10599                        ("pragma % entity name does not match declaration");
10600
10601                   else
10602                      Ent := First_Literal (E);
10603                      loop
10604                         if No (Ent) then
10605                            Error_Pragma
10606                              ("pragma % entity name does not match any " &
10607                               "enumeration literal");
10608
10609                         elsif Chars (Ent) = Chars (Ename) then
10610                            Set_Entity (Ename, Ent);
10611                            Generate_Reference (Ent, Ename);
10612                            exit;
10613
10614                         else
10615                            Ent := Next_Literal (Ent);
10616                         end if;
10617                      end loop;
10618                   end if;
10619                end if;
10620
10621                --  Ent points to entity to be marked
10622
10623                if Arg_Count >= 1 then
10624
10625                   --  Deal with static string argument
10626
10627                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10628                   S := Strval (Get_Pragma_Arg (Arg1));
10629
10630                   for J in 1 .. String_Length (S) loop
10631                      if not In_Character_Range (Get_String_Char (S, J)) then
10632                         Error_Pragma_Arg
10633                           ("pragma% argument does not allow wide characters",
10634                            Arg1);
10635                      end if;
10636                   end loop;
10637
10638                   Obsolescent_Warnings.Append
10639                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10640
10641                   --  Check for Ada_05 parameter
10642
10643                   if Arg_Count /= 1 then
10644                      Check_Arg_Count (2);
10645
10646                      declare
10647                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10648
10649                      begin
10650                         Check_Arg_Is_Identifier (Argx);
10651
10652                         if Chars (Argx) /= Name_Ada_05 then
10653                            Error_Msg_Name_2 := Name_Ada_05;
10654                            Error_Pragma_Arg
10655                              ("only allowed argument for pragma% is %", Argx);
10656                         end if;
10657
10658                         if Ada_Version_Explicit < Ada_2005
10659                           or else not Warn_On_Ada_2005_Compatibility
10660                         then
10661                            Active := False;
10662                         end if;
10663                      end;
10664                   end if;
10665                end if;
10666
10667                --  Set flag if pragma active
10668
10669                if Active then
10670                   Set_Is_Obsolescent (Ent);
10671                end if;
10672
10673                return;
10674             end Set_Obsolescent;
10675
10676          --  Start of processing for pragma Obsolescent
10677
10678          begin
10679             GNAT_Pragma;
10680
10681             Check_At_Most_N_Arguments (3);
10682
10683             --  See if first argument specifies an entity name
10684
10685             if Arg_Count >= 1
10686               and then
10687                 (Chars (Arg1) = Name_Entity
10688                    or else
10689                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10690                                                       N_Identifier,
10691                                                       N_Operator_Symbol))
10692             then
10693                Ename := Get_Pragma_Arg (Arg1);
10694
10695                --  Eliminate first argument, so we can share processing
10696
10697                Arg1 := Arg2;
10698                Arg2 := Arg3;
10699                Arg_Count := Arg_Count - 1;
10700
10701             --  No Entity name argument given
10702
10703             else
10704                Ename := Empty;
10705             end if;
10706
10707             if Arg_Count >= 1 then
10708                Check_Optional_Identifier (Arg1, Name_Message);
10709
10710                if Arg_Count = 2 then
10711                   Check_Optional_Identifier (Arg2, Name_Version);
10712                end if;
10713             end if;
10714
10715             --  Get immediately preceding declaration
10716
10717             Decl := Prev (N);
10718             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10719                Prev (Decl);
10720             end loop;
10721
10722             --  Cases where we do not follow anything other than another pragma
10723
10724             if No (Decl) then
10725
10726                --  First case: library level compilation unit declaration with
10727                --  the pragma immediately following the declaration.
10728
10729                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10730                   Set_Obsolescent
10731                     (Defining_Entity (Unit (Parent (Parent (N)))));
10732                   return;
10733
10734                --  Case 2: library unit placement for package
10735
10736                else
10737                   declare
10738                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
10739                   begin
10740                      if Is_Package_Or_Generic_Package (Ent) then
10741                         Set_Obsolescent (Ent);
10742                         return;
10743                      end if;
10744                   end;
10745                end if;
10746
10747             --  Cases where we must follow a declaration
10748
10749             else
10750                if         Nkind (Decl) not in N_Declaration
10751                  and then Nkind (Decl) not in N_Later_Decl_Item
10752                  and then Nkind (Decl) not in N_Generic_Declaration
10753                  and then Nkind (Decl) not in N_Renaming_Declaration
10754                then
10755                   Error_Pragma
10756                     ("pragma% misplaced, "
10757                      & "must immediately follow a declaration");
10758
10759                else
10760                   Set_Obsolescent (Defining_Entity (Decl));
10761                   return;
10762                end if;
10763             end if;
10764          end Obsolescent;
10765
10766          --------------
10767          -- Optimize --
10768          --------------
10769
10770          --  pragma Optimize (Time | Space | Off);
10771
10772          --  The actual check for optimize is done in Gigi. Note that this
10773          --  pragma does not actually change the optimization setting, it
10774          --  simply checks that it is consistent with the pragma.
10775
10776          when Pragma_Optimize =>
10777             Check_No_Identifiers;
10778             Check_Arg_Count (1);
10779             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10780
10781          ------------------------
10782          -- Optimize_Alignment --
10783          ------------------------
10784
10785          --  pragma Optimize_Alignment (Time | Space | Off);
10786
10787          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10788             GNAT_Pragma;
10789             Check_No_Identifiers;
10790             Check_Arg_Count (1);
10791             Check_Valid_Configuration_Pragma;
10792
10793             declare
10794                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10795             begin
10796                case Nam is
10797                   when Name_Time =>
10798                      Opt.Optimize_Alignment := 'T';
10799                   when Name_Space =>
10800                      Opt.Optimize_Alignment := 'S';
10801                   when Name_Off =>
10802                      Opt.Optimize_Alignment := 'O';
10803                   when others =>
10804                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10805                end case;
10806             end;
10807
10808             --  Set indication that mode is set locally. If we are in fact in a
10809             --  configuration pragma file, this setting is harmless since the
10810             --  switch will get reset anyway at the start of each unit.
10811
10812             Optimize_Alignment_Local := True;
10813          end Optimize_Alignment;
10814
10815          -------------
10816          -- Ordered --
10817          -------------
10818
10819          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10820
10821          when Pragma_Ordered => Ordered : declare
10822             Assoc   : constant Node_Id := Arg1;
10823             Type_Id : Node_Id;
10824             Typ     : Entity_Id;
10825
10826          begin
10827             GNAT_Pragma;
10828             Check_No_Identifiers;
10829             Check_Arg_Count (1);
10830             Check_Arg_Is_Local_Name (Arg1);
10831
10832             Type_Id := Get_Pragma_Arg (Assoc);
10833             Find_Type (Type_Id);
10834             Typ := Entity (Type_Id);
10835
10836             if Typ = Any_Type then
10837                return;
10838             else
10839                Typ := Underlying_Type (Typ);
10840             end if;
10841
10842             if not Is_Enumeration_Type (Typ) then
10843                Error_Pragma ("pragma% must specify enumeration type");
10844             end if;
10845
10846             Check_First_Subtype (Arg1);
10847             Set_Has_Pragma_Ordered (Base_Type (Typ));
10848          end Ordered;
10849
10850          ----------
10851          -- Pack --
10852          ----------
10853
10854          --  pragma Pack (first_subtype_LOCAL_NAME);
10855
10856          when Pragma_Pack => Pack : declare
10857             Assoc   : constant Node_Id := Arg1;
10858             Type_Id : Node_Id;
10859             Typ     : Entity_Id;
10860             Ctyp    : Entity_Id;
10861             Ignore  : Boolean := False;
10862
10863          begin
10864             Check_No_Identifiers;
10865             Check_Arg_Count (1);
10866             Check_Arg_Is_Local_Name (Arg1);
10867
10868             Type_Id := Get_Pragma_Arg (Assoc);
10869             Find_Type (Type_Id);
10870             Typ := Entity (Type_Id);
10871
10872             if Typ = Any_Type
10873               or else Rep_Item_Too_Early (Typ, N)
10874             then
10875                return;
10876             else
10877                Typ := Underlying_Type (Typ);
10878             end if;
10879
10880             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10881                Error_Pragma ("pragma% must specify array or record type");
10882             end if;
10883
10884             Check_First_Subtype (Arg1);
10885             Check_Duplicate_Pragma (Typ);
10886
10887             --  Array type
10888
10889             if Is_Array_Type (Typ) then
10890                Ctyp := Component_Type (Typ);
10891
10892                --  Ignore pack that does nothing
10893
10894                if Known_Static_Esize (Ctyp)
10895                  and then Known_Static_RM_Size (Ctyp)
10896                  and then Esize (Ctyp) = RM_Size (Ctyp)
10897                  and then Addressable (Esize (Ctyp))
10898                then
10899                   Ignore := True;
10900                end if;
10901
10902                --  Process OK pragma Pack. Note that if there is a separate
10903                --  component clause present, the Pack will be cancelled. This
10904                --  processing is in Freeze.
10905
10906                if not Rep_Item_Too_Late (Typ, N) then
10907
10908                   --  In the context of static code analysis, we do not need
10909                   --  complex front-end expansions related to pragma Pack,
10910                   --  so disable handling of pragma Pack in this case.
10911
10912                   if CodePeer_Mode then
10913                      null;
10914
10915                   --  Don't attempt any packing for VM targets. We possibly
10916                   --  could deal with some cases of array bit-packing, but we
10917                   --  don't bother, since this is not a typical kind of
10918                   --  representation in the VM context anyway (and would not
10919                   --  for example work nicely with the debugger).
10920
10921                   elsif VM_Target /= No_VM then
10922                      if not GNAT_Mode then
10923                         Error_Pragma
10924                           ("?pragma% ignored in this configuration");
10925                      end if;
10926
10927                   --  Normal case where we do the pack action
10928
10929                   else
10930                      if not Ignore then
10931                         Set_Is_Packed            (Base_Type (Typ), Sense);
10932                         Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10933                      end if;
10934
10935                      Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10936
10937                      --  Complete reset action for Aspect_Cancel case
10938
10939                      if Sense = False then
10940
10941                         --  Cancel size unless explicitly set
10942
10943                         if not Has_Size_Clause (Typ)
10944                            and then not Has_Object_Size_Clause (Typ)
10945                         then
10946                            Set_Esize     (Typ, Uint_0);
10947                            Set_RM_Size   (Typ, Uint_0);
10948                            Set_Alignment (Typ, Uint_0);
10949                            Set_Packed_Array_Type (Typ, Empty);
10950                         end if;
10951
10952                         --  Reset component size unless explicitly set
10953
10954                         if not Has_Component_Size_Clause (Typ) then
10955                            if Known_Static_Esize (Ctyp)
10956                              and then Known_Static_RM_Size (Ctyp)
10957                              and then Esize (Ctyp) = RM_Size (Ctyp)
10958                              and then Addressable (Esize (Ctyp))
10959                            then
10960                               Set_Component_Size
10961                                 (Base_Type (Typ), Esize (Ctyp));
10962                            else
10963                               Set_Component_Size
10964                                 (Base_Type (Typ), Uint_0);
10965                            end if;
10966                         end if;
10967                      end if;
10968                   end if;
10969                end if;
10970
10971             --  For record types, the pack is always effective
10972
10973             else pragma Assert (Is_Record_Type (Typ));
10974                if not Rep_Item_Too_Late (Typ, N) then
10975
10976                   --  Ignore pack request with warning in VM mode (skip warning
10977                   --  if we are compiling GNAT run time library).
10978
10979                   if VM_Target /= No_VM then
10980                      if not GNAT_Mode then
10981                         Error_Pragma
10982                           ("?pragma% ignored in this configuration");
10983                      end if;
10984
10985                   --  Normal case of pack request active
10986
10987                   else
10988                      Set_Is_Packed            (Base_Type (Typ), Sense);
10989                      Set_Has_Pragma_Pack      (Base_Type (Typ), Sense);
10990                      Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10991
10992                      --  Complete reset action for Aspect_Cancel case
10993
10994                      if Sense = False then
10995
10996                         --  Cancel size if not explicitly given
10997
10998                         if not Has_Size_Clause (Typ)
10999                           and then not Has_Object_Size_Clause (Typ)
11000                         then
11001                            Set_Esize     (Typ, Uint_0);
11002                            Set_Alignment (Typ, Uint_0);
11003                         end if;
11004                      end if;
11005                   end if;
11006                end if;
11007             end if;
11008          end Pack;
11009
11010          ----------
11011          -- Page --
11012          ----------
11013
11014          --  pragma Page;
11015
11016          --  There is nothing to do here, since we did all the processing for
11017          --  this pragma in Par.Prag (so that it works properly even in syntax
11018          --  only mode).
11019
11020          when Pragma_Page =>
11021             null;
11022
11023          -------------
11024          -- Passive --
11025          -------------
11026
11027          --  pragma Passive [(PASSIVE_FORM)];
11028
11029          --  PASSIVE_FORM ::= Semaphore | No
11030
11031          when Pragma_Passive =>
11032             GNAT_Pragma;
11033
11034             if Nkind (Parent (N)) /= N_Task_Definition then
11035                Error_Pragma ("pragma% must be within task definition");
11036             end if;
11037
11038             if Arg_Count /= 0 then
11039                Check_Arg_Count (1);
11040                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11041             end if;
11042
11043          ----------------------------------
11044          -- Preelaborable_Initialization --
11045          ----------------------------------
11046
11047          --  pragma Preelaborable_Initialization (DIRECT_NAME);
11048
11049          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11050             Ent : Entity_Id;
11051
11052          begin
11053             Ada_2005_Pragma;
11054             Check_Arg_Count (1);
11055             Check_No_Identifiers;
11056             Check_Arg_Is_Identifier (Arg1);
11057             Check_Arg_Is_Local_Name (Arg1);
11058             Check_First_Subtype (Arg1);
11059             Ent := Entity (Get_Pragma_Arg (Arg1));
11060
11061             if not (Is_Private_Type (Ent)
11062                       or else
11063                     Is_Protected_Type (Ent)
11064                       or else
11065                     (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11066             then
11067                Error_Pragma_Arg
11068                  ("pragma % can only be applied to private, formal derived or "
11069                   & "protected type",
11070                   Arg1);
11071             end if;
11072
11073             --  Give an error if the pragma is applied to a protected type that
11074             --  does not qualify (due to having entries, or due to components
11075             --  that do not qualify).
11076
11077             if Is_Protected_Type (Ent)
11078               and then not Has_Preelaborable_Initialization (Ent)
11079             then
11080                Error_Msg_N
11081                  ("protected type & does not have preelaborable " &
11082                   "initialization", Ent);
11083
11084             --  Otherwise mark the type as definitely having preelaborable
11085             --  initialization.
11086
11087             else
11088                Set_Known_To_Have_Preelab_Init (Ent);
11089             end if;
11090
11091             if Has_Pragma_Preelab_Init (Ent)
11092               and then Warn_On_Redundant_Constructs
11093             then
11094                Error_Pragma ("?duplicate pragma%!");
11095             else
11096                Set_Has_Pragma_Preelab_Init (Ent);
11097             end if;
11098          end Preelab_Init;
11099
11100          --------------------
11101          -- Persistent_BSS --
11102          --------------------
11103
11104          --  pragma Persistent_BSS [(object_NAME)];
11105
11106          when Pragma_Persistent_BSS => Persistent_BSS :  declare
11107             Decl : Node_Id;
11108             Ent  : Entity_Id;
11109             Prag : Node_Id;
11110
11111          begin
11112             GNAT_Pragma;
11113             Check_At_Most_N_Arguments (1);
11114
11115             --  Case of application to specific object (one argument)
11116
11117             if Arg_Count = 1 then
11118                Check_Arg_Is_Library_Level_Local_Name (Arg1);
11119
11120                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11121                  or else not
11122                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11123                                                             E_Constant)
11124                then
11125                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11126                end if;
11127
11128                Ent := Entity (Get_Pragma_Arg (Arg1));
11129                Decl := Parent (Ent);
11130
11131                if Rep_Item_Too_Late (Ent, N) then
11132                   return;
11133                end if;
11134
11135                if Present (Expression (Decl)) then
11136                   Error_Pragma_Arg
11137                     ("object for pragma% cannot have initialization", Arg1);
11138                end if;
11139
11140                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11141                   Error_Pragma_Arg
11142                     ("object type for pragma% is not potentially persistent",
11143                      Arg1);
11144                end if;
11145
11146                Check_Duplicate_Pragma (Ent);
11147
11148                if Sense then
11149                   Prag :=
11150                     Make_Linker_Section_Pragma
11151                       (Ent, Sloc (N), ".persistent.bss");
11152                   Insert_After (N, Prag);
11153                   Analyze (Prag);
11154                end if;
11155
11156             --  Case of use as configuration pragma with no arguments
11157
11158             else
11159                Check_Valid_Configuration_Pragma;
11160                Persistent_BSS_Mode := True;
11161             end if;
11162          end Persistent_BSS;
11163
11164          -------------
11165          -- Polling --
11166          -------------
11167
11168          --  pragma Polling (ON | OFF);
11169
11170          when Pragma_Polling =>
11171             GNAT_Pragma;
11172             Check_Arg_Count (1);
11173             Check_No_Identifiers;
11174             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11175             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11176
11177          -------------------
11178          -- Postcondition --
11179          -------------------
11180
11181          --  pragma Postcondition ([Check   =>] Boolean_Expression
11182          --                      [,[Message =>] String_Expression]);
11183
11184          when Pragma_Postcondition => Postcondition : declare
11185             In_Body : Boolean;
11186             pragma Warnings (Off, In_Body);
11187
11188          begin
11189             GNAT_Pragma;
11190             Check_At_Least_N_Arguments (1);
11191             Check_At_Most_N_Arguments (2);
11192             Check_Optional_Identifier (Arg1, Name_Check);
11193
11194             --  All we need to do here is call the common check procedure,
11195             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11196
11197             Check_Precondition_Postcondition (In_Body);
11198          end Postcondition;
11199
11200          ------------------
11201          -- Precondition --
11202          ------------------
11203
11204          --  pragma Precondition ([Check   =>] Boolean_Expression
11205          --                     [,[Message =>] String_Expression]);
11206
11207          when Pragma_Precondition => Precondition : declare
11208             In_Body : Boolean;
11209
11210          begin
11211             GNAT_Pragma;
11212             Check_At_Least_N_Arguments (1);
11213             Check_At_Most_N_Arguments (2);
11214             Check_Optional_Identifier (Arg1, Name_Check);
11215             Check_Precondition_Postcondition (In_Body);
11216
11217             --  If in spec, nothing more to do. If in body, then we convert the
11218             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
11219             --  this whether or not precondition checks are enabled. That works
11220             --  fine since pragma Check will do this check, and will also
11221             --  analyze the condition itself in the proper context.
11222
11223             if In_Body then
11224                Rewrite (N,
11225                  Make_Pragma (Loc,
11226                    Chars => Name_Check,
11227                    Pragma_Argument_Associations => New_List (
11228                      Make_Pragma_Argument_Association (Loc,
11229                        Expression => Make_Identifier (Loc, Name_Precondition)),
11230
11231                      Make_Pragma_Argument_Association (Sloc (Arg1),
11232                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11233
11234                if Arg_Count = 2 then
11235                   Append_To (Pragma_Argument_Associations (N),
11236                     Make_Pragma_Argument_Association (Sloc (Arg2),
11237                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11238                end if;
11239
11240                Analyze (N);
11241             end if;
11242          end Precondition;
11243
11244          ---------------
11245          -- Predicate --
11246          ---------------
11247
11248          --  pragma Predicate
11249          --    ([Entity =>] type_LOCAL_NAME,
11250          --     [Check  =>] EXPRESSION);
11251
11252          when Pragma_Predicate => Predicate : declare
11253             Type_Id : Node_Id;
11254             Typ     : Entity_Id;
11255
11256             Discard : Boolean;
11257             pragma Unreferenced (Discard);
11258
11259          begin
11260             GNAT_Pragma;
11261             Check_Arg_Count (2);
11262             Check_Optional_Identifier (Arg1, Name_Entity);
11263             Check_Optional_Identifier (Arg2, Name_Check);
11264
11265             Check_Arg_Is_Local_Name (Arg1);
11266
11267             Type_Id := Get_Pragma_Arg (Arg1);
11268             Find_Type (Type_Id);
11269             Typ := Entity (Type_Id);
11270
11271             if Typ = Any_Type then
11272                return;
11273             end if;
11274
11275             --  The remaining processing is simply to link the pragma on to
11276             --  the rep item chain, for processing when the type is frozen.
11277             --  This is accomplished by a call to Rep_Item_Too_Late. We also
11278             --  mark the type as having predicates.
11279
11280             Set_Has_Predicates (Typ);
11281             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11282          end Predicate;
11283
11284          ------------------
11285          -- Preelaborate --
11286          ------------------
11287
11288          --  pragma Preelaborate [(library_unit_NAME)];
11289
11290          --  Set the flag Is_Preelaborated of program unit name entity
11291
11292          when Pragma_Preelaborate => Preelaborate : declare
11293             Pa  : constant Node_Id   := Parent (N);
11294             Pk  : constant Node_Kind := Nkind (Pa);
11295             Ent : Entity_Id;
11296
11297          begin
11298             Check_Ada_83_Warning;
11299             Check_Valid_Library_Unit_Pragma;
11300
11301             if Nkind (N) = N_Null_Statement then
11302                return;
11303             end if;
11304
11305             Ent := Find_Lib_Unit_Name;
11306             Check_Duplicate_Pragma (Ent);
11307
11308             --  This filters out pragmas inside generic parent then
11309             --  show up inside instantiation
11310
11311             if Present (Ent)
11312               and then not (Pk = N_Package_Specification
11313                               and then Present (Generic_Parent (Pa)))
11314             then
11315                if not Debug_Flag_U then
11316                   Set_Is_Preelaborated (Ent, Sense);
11317                   Set_Suppress_Elaboration_Warnings (Ent, Sense);
11318                end if;
11319             end if;
11320          end Preelaborate;
11321
11322          ---------------------
11323          -- Preelaborate_05 --
11324          ---------------------
11325
11326          --  pragma Preelaborate_05 [(library_unit_NAME)];
11327
11328          --  This pragma is useable only in GNAT_Mode, where it is used like
11329          --  pragma Preelaborate but it is only effective in Ada 2005 mode
11330          --  (otherwise it is ignored). This is used to implement AI-362 which
11331          --  recategorizes some run-time packages in Ada 2005 mode.
11332
11333          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11334             Ent : Entity_Id;
11335
11336          begin
11337             GNAT_Pragma;
11338             Check_Valid_Library_Unit_Pragma;
11339
11340             if not GNAT_Mode then
11341                Error_Pragma ("pragma% only available in GNAT mode");
11342             end if;
11343
11344             if Nkind (N) = N_Null_Statement then
11345                return;
11346             end if;
11347
11348             --  This is one of the few cases where we need to test the value of
11349             --  Ada_Version_Explicit rather than Ada_Version (which is always
11350             --  set to Ada_2012 in a predefined unit), we need to know the
11351             --  explicit version set to know if this pragma is active.
11352
11353             if Ada_Version_Explicit >= Ada_2005 then
11354                Ent := Find_Lib_Unit_Name;
11355                Set_Is_Preelaborated (Ent);
11356                Set_Suppress_Elaboration_Warnings (Ent);
11357             end if;
11358          end Preelaborate_05;
11359
11360          --------------
11361          -- Priority --
11362          --------------
11363
11364          --  pragma Priority (EXPRESSION);
11365
11366          when Pragma_Priority => Priority : declare
11367             P   : constant Node_Id := Parent (N);
11368             Arg : Node_Id;
11369
11370          begin
11371             Check_No_Identifiers;
11372             Check_Arg_Count (1);
11373
11374             --  Subprogram case
11375
11376             if Nkind (P) = N_Subprogram_Body then
11377                Check_In_Main_Program;
11378
11379                Arg := Get_Pragma_Arg (Arg1);
11380                Analyze_And_Resolve (Arg, Standard_Integer);
11381
11382                --  Must be static
11383
11384                if not Is_Static_Expression (Arg) then
11385                   Flag_Non_Static_Expr
11386                     ("main subprogram priority is not static!", Arg);
11387                   raise Pragma_Exit;
11388
11389                --  If constraint error, then we already signalled an error
11390
11391                elsif Raises_Constraint_Error (Arg) then
11392                   null;
11393
11394                --  Otherwise check in range
11395
11396                else
11397                   declare
11398                      Val : constant Uint := Expr_Value (Arg);
11399
11400                   begin
11401                      if Val < 0
11402                        or else Val > Expr_Value (Expression
11403                                        (Parent (RTE (RE_Max_Priority))))
11404                      then
11405                         Error_Pragma_Arg
11406                           ("main subprogram priority is out of range", Arg1);
11407                      end if;
11408                   end;
11409                end if;
11410
11411                Set_Main_Priority
11412                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11413
11414                --  Load an arbitrary entity from System.Tasking to make sure
11415                --  this package is implicitly with'ed, since we need to have
11416                --  the tasking run-time active for the pragma Priority to have
11417                --  any effect.
11418
11419                declare
11420                   Discard : Entity_Id;
11421                   pragma Warnings (Off, Discard);
11422                begin
11423                   Discard := RTE (RE_Task_List);
11424                end;
11425
11426             --  Task or Protected, must be of type Integer
11427
11428             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11429                Arg := Get_Pragma_Arg (Arg1);
11430
11431                --  The expression must be analyzed in the special manner
11432                --  described in "Handling of Default and Per-Object
11433                --  Expressions" in sem.ads.
11434
11435                Preanalyze_Spec_Expression (Arg, Standard_Integer);
11436
11437                if not Is_Static_Expression (Arg) then
11438                   Check_Restriction (Static_Priorities, Arg);
11439                end if;
11440
11441             --  Anything else is incorrect
11442
11443             else
11444                Pragma_Misplaced;
11445             end if;
11446
11447             if Has_Pragma_Priority (P) then
11448                Error_Pragma ("duplicate pragma% not allowed");
11449             else
11450                Set_Has_Pragma_Priority (P, True);
11451
11452                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11453                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11454                   --  exp_ch9 should use this ???
11455                end if;
11456             end if;
11457          end Priority;
11458
11459          -----------------------------------
11460          -- Priority_Specific_Dispatching --
11461          -----------------------------------
11462
11463          --  pragma Priority_Specific_Dispatching (
11464          --    policy_IDENTIFIER,
11465          --    first_priority_EXPRESSION,
11466          --    last_priority_EXPRESSION);
11467
11468          when Pragma_Priority_Specific_Dispatching =>
11469          Priority_Specific_Dispatching : declare
11470             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11471             --  This is the entity System.Any_Priority;
11472
11473             DP          : Character;
11474             Lower_Bound : Node_Id;
11475             Upper_Bound : Node_Id;
11476             Lower_Val   : Uint;
11477             Upper_Val   : Uint;
11478
11479          begin
11480             Ada_2005_Pragma;
11481             Check_Arg_Count (3);
11482             Check_No_Identifiers;
11483             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11484             Check_Valid_Configuration_Pragma;
11485             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11486             DP := Fold_Upper (Name_Buffer (1));
11487
11488             Lower_Bound := Get_Pragma_Arg (Arg2);
11489             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11490             Lower_Val := Expr_Value (Lower_Bound);
11491
11492             Upper_Bound := Get_Pragma_Arg (Arg3);
11493             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11494             Upper_Val := Expr_Value (Upper_Bound);
11495
11496             --  It is not allowed to use Task_Dispatching_Policy and
11497             --  Priority_Specific_Dispatching in the same partition.
11498
11499             if Task_Dispatching_Policy /= ' ' then
11500                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11501                Error_Pragma
11502                  ("pragma% incompatible with Task_Dispatching_Policy#");
11503
11504             --  Check lower bound in range
11505
11506             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11507                     or else
11508                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11509             then
11510                Error_Pragma_Arg
11511                  ("first_priority is out of range", Arg2);
11512
11513             --  Check upper bound in range
11514
11515             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11516                     or else
11517                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11518             then
11519                Error_Pragma_Arg
11520                  ("last_priority is out of range", Arg3);
11521
11522             --  Check that the priority range is valid
11523
11524             elsif Lower_Val > Upper_Val then
11525                Error_Pragma
11526                  ("last_priority_expression must be greater than" &
11527                   " or equal to first_priority_expression");
11528
11529             --  Store the new policy, but always preserve System_Location since
11530             --  we like the error message with the run-time name.
11531
11532             else
11533                --  Check overlapping in the priority ranges specified in other
11534                --  Priority_Specific_Dispatching pragmas within the same
11535                --  partition. We can only check those we know about!
11536
11537                for J in
11538                   Specific_Dispatching.First .. Specific_Dispatching.Last
11539                loop
11540                   if Specific_Dispatching.Table (J).First_Priority in
11541                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11542                   or else Specific_Dispatching.Table (J).Last_Priority in
11543                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11544                   then
11545                      Error_Msg_Sloc :=
11546                        Specific_Dispatching.Table (J).Pragma_Loc;
11547                         Error_Pragma
11548                           ("priority range overlaps with "
11549                            & "Priority_Specific_Dispatching#");
11550                   end if;
11551                end loop;
11552
11553                --  The use of Priority_Specific_Dispatching is incompatible
11554                --  with Task_Dispatching_Policy.
11555
11556                if Task_Dispatching_Policy /= ' ' then
11557                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11558                      Error_Pragma
11559                        ("Priority_Specific_Dispatching incompatible "
11560                         & "with Task_Dispatching_Policy#");
11561                end if;
11562
11563                --  The use of Priority_Specific_Dispatching forces ceiling
11564                --  locking policy.
11565
11566                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11567                   Error_Msg_Sloc := Locking_Policy_Sloc;
11568                      Error_Pragma
11569                        ("Priority_Specific_Dispatching incompatible "
11570                         & "with Locking_Policy#");
11571
11572                --  Set the Ceiling_Locking policy, but preserve System_Location
11573                --  since we like the error message with the run time name.
11574
11575                else
11576                   Locking_Policy := 'C';
11577
11578                   if Locking_Policy_Sloc /= System_Location then
11579                      Locking_Policy_Sloc := Loc;
11580                   end if;
11581                end if;
11582
11583                --  Add entry in the table
11584
11585                Specific_Dispatching.Append
11586                     ((Dispatching_Policy => DP,
11587                       First_Priority     => UI_To_Int (Lower_Val),
11588                       Last_Priority      => UI_To_Int (Upper_Val),
11589                       Pragma_Loc         => Loc));
11590             end if;
11591          end Priority_Specific_Dispatching;
11592
11593          -------------
11594          -- Profile --
11595          -------------
11596
11597          --  pragma Profile (profile_IDENTIFIER);
11598
11599          --  profile_IDENTIFIER => Restricted | Ravenscar
11600
11601          when Pragma_Profile =>
11602             Ada_2005_Pragma;
11603             Check_Arg_Count (1);
11604             Check_Valid_Configuration_Pragma;
11605             Check_No_Identifiers;
11606
11607             declare
11608                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11609             begin
11610                if Chars (Argx) = Name_Ravenscar then
11611                   Set_Ravenscar_Profile (N);
11612                elsif Chars (Argx) = Name_Restricted then
11613                   Set_Profile_Restrictions
11614                     (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11615                else
11616                   Error_Pragma_Arg ("& is not a valid profile", Argx);
11617                end if;
11618             end;
11619
11620          ----------------------
11621          -- Profile_Warnings --
11622          ----------------------
11623
11624          --  pragma Profile_Warnings (profile_IDENTIFIER);
11625
11626          --  profile_IDENTIFIER => Restricted | Ravenscar
11627
11628          when Pragma_Profile_Warnings =>
11629             GNAT_Pragma;
11630             Check_Arg_Count (1);
11631             Check_Valid_Configuration_Pragma;
11632             Check_No_Identifiers;
11633
11634             declare
11635                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11636             begin
11637                if Chars (Argx) = Name_Ravenscar then
11638                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11639                elsif Chars (Argx) = Name_Restricted then
11640                   Set_Profile_Restrictions (Restricted, N, Warn => True);
11641                else
11642                   Error_Pragma_Arg ("& is not a valid profile", Argx);
11643                end if;
11644             end;
11645
11646          --------------------------
11647          -- Propagate_Exceptions --
11648          --------------------------
11649
11650          --  pragma Propagate_Exceptions;
11651
11652          --  Note: this pragma is obsolete and has no effect
11653
11654          when Pragma_Propagate_Exceptions =>
11655             GNAT_Pragma;
11656             Check_Arg_Count (0);
11657
11658             if In_Extended_Main_Source_Unit (N) then
11659                Propagate_Exceptions := True;
11660             end if;
11661
11662          ------------------
11663          -- Psect_Object --
11664          ------------------
11665
11666          --  pragma Psect_Object (
11667          --        [Internal =>] LOCAL_NAME,
11668          --     [, [External =>] EXTERNAL_SYMBOL]
11669          --     [, [Size     =>] EXTERNAL_SYMBOL]);
11670
11671          when Pragma_Psect_Object | Pragma_Common_Object =>
11672          Psect_Object : declare
11673             Args  : Args_List (1 .. 3);
11674             Names : constant Name_List (1 .. 3) := (
11675                       Name_Internal,
11676                       Name_External,
11677                       Name_Size);
11678
11679             Internal : Node_Id renames Args (1);
11680             External : Node_Id renames Args (2);
11681             Size     : Node_Id renames Args (3);
11682
11683             Def_Id : Entity_Id;
11684
11685             procedure Check_Too_Long (Arg : Node_Id);
11686             --  Posts message if the argument is an identifier with more
11687             --  than 31 characters, or a string literal with more than
11688             --  31 characters, and we are operating under VMS
11689
11690             --------------------
11691             -- Check_Too_Long --
11692             --------------------
11693
11694             procedure Check_Too_Long (Arg : Node_Id) is
11695                X : constant Node_Id := Original_Node (Arg);
11696
11697             begin
11698                if not Nkind_In (X, N_String_Literal, N_Identifier) then
11699                   Error_Pragma_Arg
11700                     ("inappropriate argument for pragma %", Arg);
11701                end if;
11702
11703                if OpenVMS_On_Target then
11704                   if (Nkind (X) = N_String_Literal
11705                        and then String_Length (Strval (X)) > 31)
11706                     or else
11707                      (Nkind (X) = N_Identifier
11708                        and then Length_Of_Name (Chars (X)) > 31)
11709                   then
11710                      Error_Pragma_Arg
11711                        ("argument for pragma % is longer than 31 characters",
11712                         Arg);
11713                   end if;
11714                end if;
11715             end Check_Too_Long;
11716
11717          --  Start of processing for Common_Object/Psect_Object
11718
11719          begin
11720             GNAT_Pragma;
11721             Gather_Associations (Names, Args);
11722             Process_Extended_Import_Export_Internal_Arg (Internal);
11723
11724             Def_Id := Entity (Internal);
11725
11726             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11727                Error_Pragma_Arg
11728                  ("pragma% must designate an object", Internal);
11729             end if;
11730
11731             Check_Too_Long (Internal);
11732
11733             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11734                Error_Pragma_Arg
11735                  ("cannot use pragma% for imported/exported object",
11736                   Internal);
11737             end if;
11738
11739             if Is_Concurrent_Type (Etype (Internal)) then
11740                Error_Pragma_Arg
11741                  ("cannot specify pragma % for task/protected object",
11742                   Internal);
11743             end if;
11744
11745             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11746                  or else
11747                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11748             then
11749                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11750             end if;
11751
11752             if Ekind (Def_Id) = E_Constant then
11753                Error_Pragma_Arg
11754                  ("cannot specify pragma % for a constant", Internal);
11755             end if;
11756
11757             if Is_Record_Type (Etype (Internal)) then
11758                declare
11759                   Ent  : Entity_Id;
11760                   Decl : Entity_Id;
11761
11762                begin
11763                   Ent := First_Entity (Etype (Internal));
11764                   while Present (Ent) loop
11765                      Decl := Declaration_Node (Ent);
11766
11767                      if Ekind (Ent) = E_Component
11768                        and then Nkind (Decl) = N_Component_Declaration
11769                        and then Present (Expression (Decl))
11770                        and then Warn_On_Export_Import
11771                      then
11772                         Error_Msg_N
11773                           ("?object for pragma % has defaults", Internal);
11774                         exit;
11775
11776                      else
11777                         Next_Entity (Ent);
11778                      end if;
11779                   end loop;
11780                end;
11781             end if;
11782
11783             if Present (Size) then
11784                Check_Too_Long (Size);
11785             end if;
11786
11787             if Present (External) then
11788                Check_Arg_Is_External_Name (External);
11789                Check_Too_Long (External);
11790             end if;
11791
11792             --  If all error tests pass, link pragma on to the rep item chain
11793
11794             Record_Rep_Item (Def_Id, N);
11795          end Psect_Object;
11796
11797          ----------
11798          -- Pure --
11799          ----------
11800
11801          --  pragma Pure [(library_unit_NAME)];
11802
11803          when Pragma_Pure => Pure : declare
11804             Ent : Entity_Id;
11805
11806          begin
11807             Check_Ada_83_Warning;
11808             Check_Valid_Library_Unit_Pragma;
11809
11810             if Nkind (N) = N_Null_Statement then
11811                return;
11812             end if;
11813
11814             Ent := Find_Lib_Unit_Name;
11815             Set_Is_Pure (Ent);
11816             Set_Has_Pragma_Pure (Ent);
11817             Set_Suppress_Elaboration_Warnings (Ent);
11818          end Pure;
11819
11820          -------------
11821          -- Pure_05 --
11822          -------------
11823
11824          --  pragma Pure_05 [(library_unit_NAME)];
11825
11826          --  This pragma is useable only in GNAT_Mode, where it is used like
11827          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
11828          --  it is ignored). It may be used after a pragma Preelaborate, in
11829          --  which case it overrides the effect of the pragma Preelaborate.
11830          --  This is used to implement AI-362 which recategorizes some run-time
11831          --  packages in Ada 2005 mode.
11832
11833          when Pragma_Pure_05 => Pure_05 : declare
11834             Ent : Entity_Id;
11835
11836          begin
11837             GNAT_Pragma;
11838             Check_Valid_Library_Unit_Pragma;
11839
11840             if not GNAT_Mode then
11841                Error_Pragma ("pragma% only available in GNAT mode");
11842             end if;
11843
11844             if Nkind (N) = N_Null_Statement then
11845                return;
11846             end if;
11847
11848             --  This is one of the few cases where we need to test the value of
11849             --  Ada_Version_Explicit rather than Ada_Version (which is always
11850             --  set to Ada_2012 in a predefined unit), we need to know the
11851             --  explicit version set to know if this pragma is active.
11852
11853             if Ada_Version_Explicit >= Ada_2005 then
11854                Ent := Find_Lib_Unit_Name;
11855                Set_Is_Preelaborated (Ent, False);
11856                Set_Is_Pure (Ent);
11857                Set_Suppress_Elaboration_Warnings (Ent);
11858             end if;
11859          end Pure_05;
11860
11861          -------------------
11862          -- Pure_Function --
11863          -------------------
11864
11865          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11866
11867          when Pragma_Pure_Function => Pure_Function : declare
11868             E_Id      : Node_Id;
11869             E         : Entity_Id;
11870             Def_Id    : Entity_Id;
11871             Effective : Boolean := False;
11872
11873          begin
11874             GNAT_Pragma;
11875             Check_Arg_Count (1);
11876             Check_Optional_Identifier (Arg1, Name_Entity);
11877             Check_Arg_Is_Local_Name (Arg1);
11878             E_Id := Get_Pragma_Arg (Arg1);
11879
11880             if Error_Posted (E_Id) then
11881                return;
11882             end if;
11883
11884             --  Loop through homonyms (overloadings) of referenced entity
11885
11886             E := Entity (E_Id);
11887
11888             if Present (E) then
11889                loop
11890                   Def_Id := Get_Base_Subprogram (E);
11891
11892                   if not Ekind_In (Def_Id, E_Function,
11893                                            E_Generic_Function,
11894                                            E_Operator)
11895                   then
11896                      Error_Pragma_Arg
11897                        ("pragma% requires a function name", Arg1);
11898                   end if;
11899
11900                   Set_Is_Pure (Def_Id, Sense);
11901
11902                   if not Has_Pragma_Pure_Function (Def_Id) then
11903                      Set_Has_Pragma_Pure_Function (Def_Id, Sense);
11904                      Effective := Sense;
11905                   end if;
11906
11907                   exit when From_Aspect_Specification (N);
11908                   E := Homonym (E);
11909                   exit when No (E) or else Scope (E) /= Current_Scope;
11910                end loop;
11911
11912                if Sense and then not Effective
11913                  and then Warn_On_Redundant_Constructs
11914                then
11915                   Error_Msg_NE
11916                     ("pragma Pure_Function on& is redundant?",
11917                      N, Entity (E_Id));
11918                end if;
11919             end if;
11920          end Pure_Function;
11921
11922          --------------------
11923          -- Queuing_Policy --
11924          --------------------
11925
11926          --  pragma Queuing_Policy (policy_IDENTIFIER);
11927
11928          when Pragma_Queuing_Policy => declare
11929             QP : Character;
11930
11931          begin
11932             Check_Ada_83_Warning;
11933             Check_Arg_Count (1);
11934             Check_No_Identifiers;
11935             Check_Arg_Is_Queuing_Policy (Arg1);
11936             Check_Valid_Configuration_Pragma;
11937             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11938             QP := Fold_Upper (Name_Buffer (1));
11939
11940             if Queuing_Policy /= ' '
11941               and then Queuing_Policy /= QP
11942             then
11943                Error_Msg_Sloc := Queuing_Policy_Sloc;
11944                Error_Pragma ("queuing policy incompatible with policy#");
11945
11946             --  Set new policy, but always preserve System_Location since we
11947             --  like the error message with the run time name.
11948
11949             else
11950                Queuing_Policy := QP;
11951
11952                if Queuing_Policy_Sloc /= System_Location then
11953                   Queuing_Policy_Sloc := Loc;
11954                end if;
11955             end if;
11956          end;
11957
11958          -----------------------
11959          -- Relative_Deadline --
11960          -----------------------
11961
11962          --  pragma Relative_Deadline (time_span_EXPRESSION);
11963
11964          when Pragma_Relative_Deadline => Relative_Deadline : declare
11965             P   : constant Node_Id := Parent (N);
11966             Arg : Node_Id;
11967
11968          begin
11969             Ada_2005_Pragma;
11970             Check_No_Identifiers;
11971             Check_Arg_Count (1);
11972
11973             Arg := Get_Pragma_Arg (Arg1);
11974
11975             --  The expression must be analyzed in the special manner described
11976             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
11977
11978             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
11979
11980             --  Subprogram case
11981
11982             if Nkind (P) = N_Subprogram_Body then
11983                Check_In_Main_Program;
11984
11985             --  Tasks
11986
11987             elsif Nkind (P) = N_Task_Definition then
11988                null;
11989
11990             --  Anything else is incorrect
11991
11992             else
11993                Pragma_Misplaced;
11994             end if;
11995
11996             if Has_Relative_Deadline_Pragma (P) then
11997                Error_Pragma ("duplicate pragma% not allowed");
11998             else
11999                Set_Has_Relative_Deadline_Pragma (P, True);
12000
12001                if Nkind (P) = N_Task_Definition then
12002                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12003                end if;
12004             end if;
12005          end Relative_Deadline;
12006
12007          ---------------------------
12008          -- Remote_Call_Interface --
12009          ---------------------------
12010
12011          --  pragma Remote_Call_Interface [(library_unit_NAME)];
12012
12013          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12014             Cunit_Node : Node_Id;
12015             Cunit_Ent  : Entity_Id;
12016             K          : Node_Kind;
12017
12018          begin
12019             Check_Ada_83_Warning;
12020             Check_Valid_Library_Unit_Pragma;
12021
12022             if Nkind (N) = N_Null_Statement then
12023                return;
12024             end if;
12025
12026             Cunit_Node := Cunit (Current_Sem_Unit);
12027             K          := Nkind (Unit (Cunit_Node));
12028             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12029
12030             if K = N_Package_Declaration
12031               or else K = N_Generic_Package_Declaration
12032               or else K = N_Subprogram_Declaration
12033               or else K = N_Generic_Subprogram_Declaration
12034               or else (K = N_Subprogram_Body
12035                          and then Acts_As_Spec (Unit (Cunit_Node)))
12036             then
12037                null;
12038             else
12039                Error_Pragma (
12040                  "pragma% must apply to package or subprogram declaration");
12041             end if;
12042
12043             Set_Is_Remote_Call_Interface (Cunit_Ent);
12044          end Remote_Call_Interface;
12045
12046          ------------------
12047          -- Remote_Types --
12048          ------------------
12049
12050          --  pragma Remote_Types [(library_unit_NAME)];
12051
12052          when Pragma_Remote_Types => Remote_Types : declare
12053             Cunit_Node : Node_Id;
12054             Cunit_Ent  : Entity_Id;
12055
12056          begin
12057             Check_Ada_83_Warning;
12058             Check_Valid_Library_Unit_Pragma;
12059
12060             if Nkind (N) = N_Null_Statement then
12061                return;
12062             end if;
12063
12064             Cunit_Node := Cunit (Current_Sem_Unit);
12065             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12066
12067             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12068                                                 N_Generic_Package_Declaration)
12069             then
12070                Error_Pragma
12071                  ("pragma% can only apply to a package declaration");
12072             end if;
12073
12074             Set_Is_Remote_Types (Cunit_Ent);
12075          end Remote_Types;
12076
12077          ---------------
12078          -- Ravenscar --
12079          ---------------
12080
12081          --  pragma Ravenscar;
12082
12083          when Pragma_Ravenscar =>
12084             GNAT_Pragma;
12085             Check_Arg_Count (0);
12086             Check_Valid_Configuration_Pragma;
12087             Set_Ravenscar_Profile (N);
12088
12089             if Warn_On_Obsolescent_Feature then
12090                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12091                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12092             end if;
12093
12094          -------------------------
12095          -- Restricted_Run_Time --
12096          -------------------------
12097
12098          --  pragma Restricted_Run_Time;
12099
12100          when Pragma_Restricted_Run_Time =>
12101             GNAT_Pragma;
12102             Check_Arg_Count (0);
12103             Check_Valid_Configuration_Pragma;
12104             Set_Profile_Restrictions
12105               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12106
12107             if Warn_On_Obsolescent_Feature then
12108                Error_Msg_N
12109                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12110                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12111             end if;
12112
12113          ------------------
12114          -- Restrictions --
12115          ------------------
12116
12117          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
12118
12119          --  RESTRICTION ::=
12120          --    restriction_IDENTIFIER
12121          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12122
12123          when Pragma_Restrictions =>
12124             Process_Restrictions_Or_Restriction_Warnings
12125               (Warn => Treat_Restrictions_As_Warnings);
12126
12127          --------------------------
12128          -- Restriction_Warnings --
12129          --------------------------
12130
12131          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12132
12133          --  RESTRICTION ::=
12134          --    restriction_IDENTIFIER
12135          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12136
12137          when Pragma_Restriction_Warnings =>
12138             GNAT_Pragma;
12139             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12140
12141          ----------------
12142          -- Reviewable --
12143          ----------------
12144
12145          --  pragma Reviewable;
12146
12147          when Pragma_Reviewable =>
12148             Check_Ada_83_Warning;
12149             Check_Arg_Count (0);
12150
12151             --  Call dummy debugging function rv. This is done to assist front
12152             --  end debugging. By placing a Reviewable pragma in the source
12153             --  program, a breakpoint on rv catches this place in the source,
12154             --  allowing convenient stepping to the point of interest.
12155
12156             rv;
12157
12158          --------------------------
12159          -- Short_Circuit_And_Or --
12160          --------------------------
12161
12162          when Pragma_Short_Circuit_And_Or =>
12163             GNAT_Pragma;
12164             Check_Arg_Count (0);
12165             Check_Valid_Configuration_Pragma;
12166             Short_Circuit_And_Or := True;
12167
12168          -------------------
12169          -- Share_Generic --
12170          -------------------
12171
12172          --  pragma Share_Generic (NAME {, NAME});
12173
12174          when Pragma_Share_Generic =>
12175             GNAT_Pragma;
12176             Process_Generic_List;
12177
12178          ------------
12179          -- Shared --
12180          ------------
12181
12182          --  pragma Shared (LOCAL_NAME);
12183
12184          when Pragma_Shared =>
12185             GNAT_Pragma;
12186             Process_Atomic_Shared_Volatile;
12187
12188          --------------------
12189          -- Shared_Passive --
12190          --------------------
12191
12192          --  pragma Shared_Passive [(library_unit_NAME)];
12193
12194          --  Set the flag Is_Shared_Passive of program unit name entity
12195
12196          when Pragma_Shared_Passive => Shared_Passive : declare
12197             Cunit_Node : Node_Id;
12198             Cunit_Ent  : Entity_Id;
12199
12200          begin
12201             Check_Ada_83_Warning;
12202             Check_Valid_Library_Unit_Pragma;
12203
12204             if Nkind (N) = N_Null_Statement then
12205                return;
12206             end if;
12207
12208             Cunit_Node := Cunit (Current_Sem_Unit);
12209             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12210
12211             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12212                                                 N_Generic_Package_Declaration)
12213             then
12214                Error_Pragma
12215                  ("pragma% can only apply to a package declaration");
12216             end if;
12217
12218             Set_Is_Shared_Passive (Cunit_Ent);
12219          end Shared_Passive;
12220
12221          -----------------------
12222          -- Short_Descriptors --
12223          -----------------------
12224
12225          --  pragma Short_Descriptors;
12226
12227          when Pragma_Short_Descriptors =>
12228             GNAT_Pragma;
12229             Check_Arg_Count (0);
12230             Check_Valid_Configuration_Pragma;
12231             Short_Descriptors := True;
12232
12233          ----------------------
12234          -- Source_File_Name --
12235          ----------------------
12236
12237          --  There are five forms for this pragma:
12238
12239          --  pragma Source_File_Name (
12240          --    [UNIT_NAME      =>] unit_NAME,
12241          --     BODY_FILE_NAME =>  STRING_LITERAL
12242          --    [, [INDEX =>] INTEGER_LITERAL]);
12243
12244          --  pragma Source_File_Name (
12245          --    [UNIT_NAME      =>] unit_NAME,
12246          --     SPEC_FILE_NAME =>  STRING_LITERAL
12247          --    [, [INDEX =>] INTEGER_LITERAL]);
12248
12249          --  pragma Source_File_Name (
12250          --     BODY_FILE_NAME  => STRING_LITERAL
12251          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12252          --  [, CASING          => CASING_SPEC]);
12253
12254          --  pragma Source_File_Name (
12255          --     SPEC_FILE_NAME  => STRING_LITERAL
12256          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12257          --  [, CASING          => CASING_SPEC]);
12258
12259          --  pragma Source_File_Name (
12260          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
12261          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
12262          --  [, CASING             => CASING_SPEC]);
12263
12264          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12265
12266          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12267          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
12268          --  only be used when no project file is used, while SFNP can only be
12269          --  used when a project file is used.
12270
12271          --  No processing here. Processing was completed during parsing, since
12272          --  we need to have file names set as early as possible. Units are
12273          --  loaded well before semantic processing starts.
12274
12275          --  The only processing we defer to this point is the check for
12276          --  correct placement.
12277
12278          when Pragma_Source_File_Name =>
12279             GNAT_Pragma;
12280             Check_Valid_Configuration_Pragma;
12281
12282          ------------------------------
12283          -- Source_File_Name_Project --
12284          ------------------------------
12285
12286          --  See Source_File_Name for syntax
12287
12288          --  No processing here. Processing was completed during parsing, since
12289          --  we need to have file names set as early as possible. Units are
12290          --  loaded well before semantic processing starts.
12291
12292          --  The only processing we defer to this point is the check for
12293          --  correct placement.
12294
12295          when Pragma_Source_File_Name_Project =>
12296             GNAT_Pragma;
12297             Check_Valid_Configuration_Pragma;
12298
12299             --  Check that a pragma Source_File_Name_Project is used only in a
12300             --  configuration pragmas file.
12301
12302             --  Pragmas Source_File_Name_Project should only be generated by
12303             --  the Project Manager in configuration pragmas files.
12304
12305             --  This is really an ugly test. It seems to depend on some
12306             --  accidental and undocumented property. At the very least it
12307             --  needs to be documented, but it would be better to have a
12308             --  clean way of testing if we are in a configuration file???
12309
12310             if Present (Parent (N)) then
12311                Error_Pragma
12312                  ("pragma% can only appear in a configuration pragmas file");
12313             end if;
12314
12315          ----------------------
12316          -- Source_Reference --
12317          ----------------------
12318
12319          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12320
12321          --  Nothing to do, all processing completed in Par.Prag, since we need
12322          --  the information for possible parser messages that are output.
12323
12324          when Pragma_Source_Reference =>
12325             GNAT_Pragma;
12326
12327          --------------
12328          -- SPARK_95 --
12329          --------------
12330
12331          --  pragma SPARK_95;
12332
12333          --  Note: this pragma also has some specific processing in Par.Prag
12334          --  because we want to set the SPARK 95 version mode during parsing.
12335
12336          when Pragma_SPARK_95 =>
12337             GNAT_Pragma;
12338             Check_Arg_Count (0);
12339             Check_Valid_Configuration_Pragma;
12340             SPARK_Version := SPARK_95;
12341             SPARK_Mode := True;
12342             Formal_Verification_Mode := True;
12343             Set_Error_Msg_Lang ("spark");
12344
12345          --------------------------------
12346          -- Static_Elaboration_Desired --
12347          --------------------------------
12348
12349          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
12350
12351          when Pragma_Static_Elaboration_Desired =>
12352             GNAT_Pragma;
12353             Check_At_Most_N_Arguments (1);
12354
12355             if Is_Compilation_Unit (Current_Scope)
12356               and then Ekind (Current_Scope) = E_Package
12357             then
12358                Set_Static_Elaboration_Desired (Current_Scope, True);
12359             else
12360                Error_Pragma ("pragma% must apply to a library-level package");
12361             end if;
12362
12363          ------------------
12364          -- Storage_Size --
12365          ------------------
12366
12367          --  pragma Storage_Size (EXPRESSION);
12368
12369          when Pragma_Storage_Size => Storage_Size : declare
12370             P   : constant Node_Id := Parent (N);
12371             Arg : Node_Id;
12372
12373          begin
12374             Check_No_Identifiers;
12375             Check_Arg_Count (1);
12376
12377             --  The expression must be analyzed in the special manner described
12378             --  in "Handling of Default Expressions" in sem.ads.
12379
12380             Arg := Get_Pragma_Arg (Arg1);
12381             Preanalyze_Spec_Expression (Arg, Any_Integer);
12382
12383             if not Is_Static_Expression (Arg) then
12384                Check_Restriction (Static_Storage_Size, Arg);
12385             end if;
12386
12387             if Nkind (P) /= N_Task_Definition then
12388                Pragma_Misplaced;
12389                return;
12390
12391             else
12392                if Has_Storage_Size_Pragma (P) then
12393                   Error_Pragma ("duplicate pragma% not allowed");
12394                else
12395                   Set_Has_Storage_Size_Pragma (P, True);
12396                end if;
12397
12398                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12399                --  ???  exp_ch9 should use this!
12400             end if;
12401          end Storage_Size;
12402
12403          ------------------
12404          -- Storage_Unit --
12405          ------------------
12406
12407          --  pragma Storage_Unit (NUMERIC_LITERAL);
12408
12409          --  Only permitted argument is System'Storage_Unit value
12410
12411          when Pragma_Storage_Unit =>
12412             Check_No_Identifiers;
12413             Check_Arg_Count (1);
12414             Check_Arg_Is_Integer_Literal (Arg1);
12415
12416             if Intval (Get_Pragma_Arg (Arg1)) /=
12417               UI_From_Int (Ttypes.System_Storage_Unit)
12418             then
12419                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12420                Error_Pragma_Arg
12421                  ("the only allowed argument for pragma% is ^", Arg1);
12422             end if;
12423
12424          --------------------
12425          -- Stream_Convert --
12426          --------------------
12427
12428          --  pragma Stream_Convert (
12429          --    [Entity =>] type_LOCAL_NAME,
12430          --    [Read   =>] function_NAME,
12431          --    [Write  =>] function NAME);
12432
12433          when Pragma_Stream_Convert => Stream_Convert : declare
12434
12435             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12436             --  Check that the given argument is the name of a local function
12437             --  of one argument that is not overloaded earlier in the current
12438             --  local scope. A check is also made that the argument is a
12439             --  function with one parameter.
12440
12441             --------------------------------------
12442             -- Check_OK_Stream_Convert_Function --
12443             --------------------------------------
12444
12445             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12446                Ent : Entity_Id;
12447
12448             begin
12449                Check_Arg_Is_Local_Name (Arg);
12450                Ent := Entity (Get_Pragma_Arg (Arg));
12451
12452                if Has_Homonym (Ent) then
12453                   Error_Pragma_Arg
12454                     ("argument for pragma% may not be overloaded", Arg);
12455                end if;
12456
12457                if Ekind (Ent) /= E_Function
12458                  or else No (First_Formal (Ent))
12459                  or else Present (Next_Formal (First_Formal (Ent)))
12460                then
12461                   Error_Pragma_Arg
12462                     ("argument for pragma% must be" &
12463                      " function of one argument", Arg);
12464                end if;
12465             end Check_OK_Stream_Convert_Function;
12466
12467          --  Start of processing for Stream_Convert
12468
12469          begin
12470             GNAT_Pragma;
12471             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12472             Check_Arg_Count (3);
12473             Check_Optional_Identifier (Arg1, Name_Entity);
12474             Check_Optional_Identifier (Arg2, Name_Read);
12475             Check_Optional_Identifier (Arg3, Name_Write);
12476             Check_Arg_Is_Local_Name (Arg1);
12477             Check_OK_Stream_Convert_Function (Arg2);
12478             Check_OK_Stream_Convert_Function (Arg3);
12479
12480             declare
12481                Typ   : constant Entity_Id :=
12482                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12483                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12484                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12485
12486             begin
12487                Check_First_Subtype (Arg1);
12488
12489                --  Check for too early or too late. Note that we don't enforce
12490                --  the rule about primitive operations in this case, since, as
12491                --  is the case for explicit stream attributes themselves, these
12492                --  restrictions are not appropriate. Note that the chaining of
12493                --  the pragma by Rep_Item_Too_Late is actually the critical
12494                --  processing done for this pragma.
12495
12496                if Rep_Item_Too_Early (Typ, N)
12497                     or else
12498                   Rep_Item_Too_Late (Typ, N, FOnly => True)
12499                then
12500                   return;
12501                end if;
12502
12503                --  Return if previous error
12504
12505                if Etype (Typ) = Any_Type
12506                     or else
12507                   Etype (Read) = Any_Type
12508                     or else
12509                   Etype (Write) = Any_Type
12510                then
12511                   return;
12512                end if;
12513
12514                --  Error checks
12515
12516                if Underlying_Type (Etype (Read)) /= Typ then
12517                   Error_Pragma_Arg
12518                     ("incorrect return type for function&", Arg2);
12519                end if;
12520
12521                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12522                   Error_Pragma_Arg
12523                     ("incorrect parameter type for function&", Arg3);
12524                end if;
12525
12526                if Underlying_Type (Etype (First_Formal (Read))) /=
12527                   Underlying_Type (Etype (Write))
12528                then
12529                   Error_Pragma_Arg
12530                     ("result type of & does not match Read parameter type",
12531                      Arg3);
12532                end if;
12533             end;
12534          end Stream_Convert;
12535
12536          -------------------------
12537          -- Style_Checks (GNAT) --
12538          -------------------------
12539
12540          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12541
12542          --  This is processed by the parser since some of the style checks
12543          --  take place during source scanning and parsing. This means that
12544          --  we don't need to issue error messages here.
12545
12546          when Pragma_Style_Checks => Style_Checks : declare
12547             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
12548             S  : String_Id;
12549             C  : Char_Code;
12550
12551          begin
12552             GNAT_Pragma;
12553             Check_No_Identifiers;
12554
12555             --  Two argument form
12556
12557             if Arg_Count = 2 then
12558                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12559
12560                declare
12561                   E_Id : Node_Id;
12562                   E    : Entity_Id;
12563
12564                begin
12565                   E_Id := Get_Pragma_Arg (Arg2);
12566                   Analyze (E_Id);
12567
12568                   if not Is_Entity_Name (E_Id) then
12569                      Error_Pragma_Arg
12570                        ("second argument of pragma% must be entity name",
12571                         Arg2);
12572                   end if;
12573
12574                   E := Entity (E_Id);
12575
12576                   if E = Any_Id then
12577                      return;
12578                   else
12579                      loop
12580                         Set_Suppress_Style_Checks (E,
12581                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12582                         exit when No (Homonym (E));
12583                         E := Homonym (E);
12584                      end loop;
12585                   end if;
12586                end;
12587
12588             --  One argument form
12589
12590             else
12591                Check_Arg_Count (1);
12592
12593                if Nkind (A) = N_String_Literal then
12594                   S   := Strval (A);
12595
12596                   declare
12597                      Slen    : constant Natural := Natural (String_Length (S));
12598                      Options : String (1 .. Slen);
12599                      J       : Natural;
12600
12601                   begin
12602                      J := 1;
12603                      loop
12604                         C := Get_String_Char (S, Int (J));
12605                         exit when not In_Character_Range (C);
12606                         Options (J) := Get_Character (C);
12607
12608                         --  If at end of string, set options. As per discussion
12609                         --  above, no need to check for errors, since we issued
12610                         --  them in the parser.
12611
12612                         if J = Slen then
12613                            Set_Style_Check_Options (Options);
12614                            exit;
12615                         end if;
12616
12617                         J := J + 1;
12618                      end loop;
12619                   end;
12620
12621                elsif Nkind (A) = N_Identifier then
12622                   if Chars (A) = Name_All_Checks then
12623                      if GNAT_Mode then
12624                         Set_GNAT_Style_Check_Options;
12625                      else
12626                         Set_Default_Style_Check_Options;
12627                      end if;
12628
12629                   elsif Chars (A) = Name_On then
12630                      Style_Check := True;
12631
12632                   elsif Chars (A) = Name_Off then
12633                      Style_Check := False;
12634                   end if;
12635                end if;
12636             end if;
12637          end Style_Checks;
12638
12639          --------------
12640          -- Subtitle --
12641          --------------
12642
12643          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12644
12645          when Pragma_Subtitle =>
12646             GNAT_Pragma;
12647             Check_Arg_Count (1);
12648             Check_Optional_Identifier (Arg1, Name_Subtitle);
12649             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12650             Store_Note (N);
12651
12652          --------------
12653          -- Suppress --
12654          --------------
12655
12656          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12657
12658          when Pragma_Suppress =>
12659             Process_Suppress_Unsuppress (True);
12660
12661          ------------------
12662          -- Suppress_All --
12663          ------------------
12664
12665          --  pragma Suppress_All;
12666
12667          --  The only check made here is that the pragma has no arguments.
12668          --  There are no placement rules, and the processing required (setting
12669          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
12670          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
12671          --  then creates and inserts a pragma Suppress (All_Checks).
12672
12673          when Pragma_Suppress_All =>
12674             GNAT_Pragma;
12675             Check_Arg_Count (0);
12676
12677          -------------------------
12678          -- Suppress_Debug_Info --
12679          -------------------------
12680
12681          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12682
12683          when Pragma_Suppress_Debug_Info =>
12684             GNAT_Pragma;
12685             Check_Arg_Count (1);
12686             Check_Optional_Identifier (Arg1, Name_Entity);
12687             Check_Arg_Is_Local_Name (Arg1);
12688             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)), Sense);
12689
12690          ----------------------------------
12691          -- Suppress_Exception_Locations --
12692          ----------------------------------
12693
12694          --  pragma Suppress_Exception_Locations;
12695
12696          when Pragma_Suppress_Exception_Locations =>
12697             GNAT_Pragma;
12698             Check_Arg_Count (0);
12699             Check_Valid_Configuration_Pragma;
12700             Exception_Locations_Suppressed := True;
12701
12702          -----------------------------
12703          -- Suppress_Initialization --
12704          -----------------------------
12705
12706          --  pragma Suppress_Initialization ([Entity =>] type_Name);
12707
12708          when Pragma_Suppress_Initialization => Suppress_Init : declare
12709             E_Id : Node_Id;
12710             E    : Entity_Id;
12711
12712          begin
12713             GNAT_Pragma;
12714             Check_Arg_Count (1);
12715             Check_Optional_Identifier (Arg1, Name_Entity);
12716             Check_Arg_Is_Local_Name (Arg1);
12717
12718             E_Id := Get_Pragma_Arg (Arg1);
12719
12720             if Etype (E_Id) = Any_Type then
12721                return;
12722             end if;
12723
12724             E := Entity (E_Id);
12725
12726             if Is_Type (E) then
12727                if Is_Incomplete_Or_Private_Type (E) then
12728                   if No (Full_View (Base_Type (E))) then
12729                      Error_Pragma_Arg
12730                        ("argument of pragma% cannot be an incomplete type",
12731                          Arg1);
12732                   else
12733                      Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12734                   end if;
12735                else
12736                   Set_Suppress_Init_Proc (Base_Type (E));
12737                end if;
12738
12739             else
12740                Error_Pragma_Arg
12741                  ("pragma% requires argument that is a type name", Arg1);
12742             end if;
12743          end Suppress_Init;
12744
12745          -----------------
12746          -- System_Name --
12747          -----------------
12748
12749          --  pragma System_Name (DIRECT_NAME);
12750
12751          --  Syntax check: one argument, which must be the identifier GNAT or
12752          --  the identifier GCC, no other identifiers are acceptable.
12753
12754          when Pragma_System_Name =>
12755             GNAT_Pragma;
12756             Check_No_Identifiers;
12757             Check_Arg_Count (1);
12758             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12759
12760          -----------------------------
12761          -- Task_Dispatching_Policy --
12762          -----------------------------
12763
12764          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12765
12766          when Pragma_Task_Dispatching_Policy => declare
12767             DP : Character;
12768
12769          begin
12770             Check_Ada_83_Warning;
12771             Check_Arg_Count (1);
12772             Check_No_Identifiers;
12773             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12774             Check_Valid_Configuration_Pragma;
12775             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12776             DP := Fold_Upper (Name_Buffer (1));
12777
12778             if Task_Dispatching_Policy /= ' '
12779               and then Task_Dispatching_Policy /= DP
12780             then
12781                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12782                Error_Pragma
12783                  ("task dispatching policy incompatible with policy#");
12784
12785             --  Set new policy, but always preserve System_Location since we
12786             --  like the error message with the run time name.
12787
12788             else
12789                Task_Dispatching_Policy := DP;
12790
12791                if Task_Dispatching_Policy_Sloc /= System_Location then
12792                   Task_Dispatching_Policy_Sloc := Loc;
12793                end if;
12794             end if;
12795          end;
12796
12797          --------------
12798          -- Task_Info --
12799          --------------
12800
12801          --  pragma Task_Info (EXPRESSION);
12802
12803          when Pragma_Task_Info => Task_Info : declare
12804             P : constant Node_Id := Parent (N);
12805
12806          begin
12807             GNAT_Pragma;
12808
12809             if Nkind (P) /= N_Task_Definition then
12810                Error_Pragma ("pragma% must appear in task definition");
12811             end if;
12812
12813             Check_No_Identifiers;
12814             Check_Arg_Count (1);
12815
12816             Analyze_And_Resolve
12817               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12818
12819             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12820                return;
12821             end if;
12822
12823             if Has_Task_Info_Pragma (P) then
12824                Error_Pragma ("duplicate pragma% not allowed");
12825             else
12826                Set_Has_Task_Info_Pragma (P, True);
12827             end if;
12828          end Task_Info;
12829
12830          ---------------
12831          -- Task_Name --
12832          ---------------
12833
12834          --  pragma Task_Name (string_EXPRESSION);
12835
12836          when Pragma_Task_Name => Task_Name : declare
12837             P   : constant Node_Id := Parent (N);
12838             Arg : Node_Id;
12839
12840          begin
12841             Check_No_Identifiers;
12842             Check_Arg_Count (1);
12843
12844             Arg := Get_Pragma_Arg (Arg1);
12845
12846             --  The expression is used in the call to Create_Task, and must be
12847             --  expanded there, not in the context of the current spec. It must
12848             --  however be analyzed to capture global references, in case it
12849             --  appears in a generic context.
12850
12851             Preanalyze_And_Resolve (Arg, Standard_String);
12852
12853             if Nkind (P) /= N_Task_Definition then
12854                Pragma_Misplaced;
12855             end if;
12856
12857             if Has_Task_Name_Pragma (P) then
12858                Error_Pragma ("duplicate pragma% not allowed");
12859             else
12860                Set_Has_Task_Name_Pragma (P, True);
12861                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12862             end if;
12863          end Task_Name;
12864
12865          ------------------
12866          -- Task_Storage --
12867          ------------------
12868
12869          --  pragma Task_Storage (
12870          --     [Task_Type =>] LOCAL_NAME,
12871          --     [Top_Guard =>] static_integer_EXPRESSION);
12872
12873          when Pragma_Task_Storage => Task_Storage : declare
12874             Args  : Args_List (1 .. 2);
12875             Names : constant Name_List (1 .. 2) := (
12876                       Name_Task_Type,
12877                       Name_Top_Guard);
12878
12879             Task_Type : Node_Id renames Args (1);
12880             Top_Guard : Node_Id renames Args (2);
12881
12882             Ent : Entity_Id;
12883
12884          begin
12885             GNAT_Pragma;
12886             Gather_Associations (Names, Args);
12887
12888             if No (Task_Type) then
12889                Error_Pragma
12890                  ("missing task_type argument for pragma%");
12891             end if;
12892
12893             Check_Arg_Is_Local_Name (Task_Type);
12894
12895             Ent := Entity (Task_Type);
12896
12897             if not Is_Task_Type (Ent) then
12898                Error_Pragma_Arg
12899                  ("argument for pragma% must be task type", Task_Type);
12900             end if;
12901
12902             if No (Top_Guard) then
12903                Error_Pragma_Arg
12904                  ("pragma% takes two arguments", Task_Type);
12905             else
12906                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12907             end if;
12908
12909             Check_First_Subtype (Task_Type);
12910
12911             if Rep_Item_Too_Late (Ent, N) then
12912                raise Pragma_Exit;
12913             end if;
12914          end Task_Storage;
12915
12916          --------------------------
12917          -- Thread_Local_Storage --
12918          --------------------------
12919
12920          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12921
12922          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12923             Id : Node_Id;
12924             E  : Entity_Id;
12925
12926          begin
12927             GNAT_Pragma;
12928             Check_Arg_Count (1);
12929             Check_Optional_Identifier (Arg1, Name_Entity);
12930             Check_Arg_Is_Library_Level_Local_Name (Arg1);
12931
12932             Id := Get_Pragma_Arg (Arg1);
12933             Analyze (Id);
12934
12935             if not Is_Entity_Name (Id)
12936               or else Ekind (Entity (Id)) /= E_Variable
12937             then
12938                Error_Pragma_Arg ("local variable name required", Arg1);
12939             end if;
12940
12941             E := Entity (Id);
12942
12943             if Rep_Item_Too_Early (E, N)
12944               or else Rep_Item_Too_Late (E, N)
12945             then
12946                raise Pragma_Exit;
12947             end if;
12948
12949             Set_Has_Pragma_Thread_Local_Storage (E);
12950             Set_Has_Gigi_Rep_Item (E);
12951          end Thread_Local_Storage;
12952
12953          ----------------
12954          -- Time_Slice --
12955          ----------------
12956
12957          --  pragma Time_Slice (static_duration_EXPRESSION);
12958
12959          when Pragma_Time_Slice => Time_Slice : declare
12960             Val : Ureal;
12961             Nod : Node_Id;
12962
12963          begin
12964             GNAT_Pragma;
12965             Check_Arg_Count (1);
12966             Check_No_Identifiers;
12967             Check_In_Main_Program;
12968             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
12969
12970             if not Error_Posted (Arg1) then
12971                Nod := Next (N);
12972                while Present (Nod) loop
12973                   if Nkind (Nod) = N_Pragma
12974                     and then Pragma_Name (Nod) = Name_Time_Slice
12975                   then
12976                      Error_Msg_Name_1 := Pname;
12977                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
12978                   end if;
12979
12980                   Next (Nod);
12981                end loop;
12982             end if;
12983
12984             --  Process only if in main unit
12985
12986             if Get_Source_Unit (Loc) = Main_Unit then
12987                Opt.Time_Slice_Set := True;
12988                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
12989
12990                if Val <= Ureal_0 then
12991                   Opt.Time_Slice_Value := 0;
12992
12993                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
12994                   Opt.Time_Slice_Value := 1_000_000_000;
12995
12996                else
12997                   Opt.Time_Slice_Value :=
12998                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
12999                end if;
13000             end if;
13001          end Time_Slice;
13002
13003          -----------
13004          -- Title --
13005          -----------
13006
13007          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
13008
13009          --   TITLING_OPTION ::=
13010          --     [Title =>] STRING_LITERAL
13011          --   | [Subtitle =>] STRING_LITERAL
13012
13013          when Pragma_Title => Title : declare
13014             Args  : Args_List (1 .. 2);
13015             Names : constant Name_List (1 .. 2) := (
13016                       Name_Title,
13017                       Name_Subtitle);
13018
13019          begin
13020             GNAT_Pragma;
13021             Gather_Associations (Names, Args);
13022             Store_Note (N);
13023
13024             for J in 1 .. 2 loop
13025                if Present (Args (J)) then
13026                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13027                end if;
13028             end loop;
13029          end Title;
13030
13031          ---------------------
13032          -- Unchecked_Union --
13033          ---------------------
13034
13035          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13036
13037          when Pragma_Unchecked_Union => Unchecked_Union : declare
13038             Assoc   : constant Node_Id := Arg1;
13039             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13040             Typ     : Entity_Id;
13041             Discr   : Entity_Id;
13042             Tdef    : Node_Id;
13043             Clist   : Node_Id;
13044             Vpart   : Node_Id;
13045             Comp    : Node_Id;
13046             Variant : Node_Id;
13047
13048          begin
13049             Ada_2005_Pragma;
13050             Check_No_Identifiers;
13051             Check_Arg_Count (1);
13052             Check_Arg_Is_Local_Name (Arg1);
13053
13054             Find_Type (Type_Id);
13055             Typ := Entity (Type_Id);
13056
13057             if Typ = Any_Type
13058               or else Rep_Item_Too_Early (Typ, N)
13059             then
13060                return;
13061             else
13062                Typ := Underlying_Type (Typ);
13063             end if;
13064
13065             if Rep_Item_Too_Late (Typ, N) then
13066                return;
13067             end if;
13068
13069             Check_First_Subtype (Arg1);
13070
13071             --  Note remaining cases are references to a type in the current
13072             --  declarative part. If we find an error, we post the error on
13073             --  the relevant type declaration at an appropriate point.
13074
13075             if not Is_Record_Type (Typ) then
13076                Error_Msg_N ("Unchecked_Union must be record type", Typ);
13077                return;
13078
13079             elsif Is_Tagged_Type (Typ) then
13080                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13081                return;
13082
13083             elsif Is_Limited_Type (Typ) then
13084                Error_Msg_N
13085                  ("Unchecked_Union must not be limited record type", Typ);
13086                Explain_Limited_Type (Typ, Typ);
13087                return;
13088
13089             else
13090                if not Has_Discriminants (Typ) then
13091                   Error_Msg_N
13092                     ("Unchecked_Union must have one discriminant", Typ);
13093                   return;
13094                end if;
13095
13096                Discr := First_Discriminant (Typ);
13097                while Present (Discr) loop
13098                   if No (Discriminant_Default_Value (Discr)) then
13099                      Error_Msg_N
13100                        ("Unchecked_Union discriminant must have default value",
13101                         Discr);
13102                   end if;
13103
13104                   Next_Discriminant (Discr);
13105                end loop;
13106
13107                Tdef  := Type_Definition (Declaration_Node (Typ));
13108                Clist := Component_List (Tdef);
13109
13110                Comp := First (Component_Items (Clist));
13111                while Present (Comp) loop
13112                   Check_Component (Comp, Typ);
13113                   Next (Comp);
13114                end loop;
13115
13116                if No (Clist) or else No (Variant_Part (Clist)) then
13117                   Error_Msg_N
13118                     ("Unchecked_Union must have variant part",
13119                      Tdef);
13120                   return;
13121                end if;
13122
13123                Vpart := Variant_Part (Clist);
13124
13125                Variant := First (Variants (Vpart));
13126                while Present (Variant) loop
13127                   Check_Variant (Variant, Typ);
13128                   Next (Variant);
13129                end loop;
13130             end if;
13131
13132             Set_Is_Unchecked_Union  (Typ, Sense);
13133
13134             if Sense then
13135                Set_Convention (Typ, Convention_C);
13136             end if;
13137
13138             Set_Has_Unchecked_Union (Base_Type (Typ), Sense);
13139             Set_Is_Unchecked_Union  (Base_Type (Typ), Sense);
13140          end Unchecked_Union;
13141
13142          ------------------------
13143          -- Unimplemented_Unit --
13144          ------------------------
13145
13146          --  pragma Unimplemented_Unit;
13147
13148          --  Note: this only gives an error if we are generating code, or if
13149          --  we are in a generic library unit (where the pragma appears in the
13150          --  body, not in the spec).
13151
13152          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13153             Cunitent : constant Entity_Id :=
13154                          Cunit_Entity (Get_Source_Unit (Loc));
13155             Ent_Kind : constant Entity_Kind :=
13156                          Ekind (Cunitent);
13157
13158          begin
13159             GNAT_Pragma;
13160             Check_Arg_Count (0);
13161
13162             if Operating_Mode = Generate_Code
13163               or else Ent_Kind = E_Generic_Function
13164               or else Ent_Kind = E_Generic_Procedure
13165               or else Ent_Kind = E_Generic_Package
13166             then
13167                Get_Name_String (Chars (Cunitent));
13168                Set_Casing (Mixed_Case);
13169                Write_Str (Name_Buffer (1 .. Name_Len));
13170                Write_Str (" is not supported in this configuration");
13171                Write_Eol;
13172                raise Unrecoverable_Error;
13173             end if;
13174          end Unimplemented_Unit;
13175
13176          ------------------------
13177          -- Universal_Aliasing --
13178          ------------------------
13179
13180          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13181
13182          when Pragma_Universal_Aliasing => Universal_Alias : declare
13183             E_Id : Entity_Id;
13184
13185          begin
13186             GNAT_Pragma;
13187             Check_Arg_Count (1);
13188             Check_Optional_Identifier (Arg2, Name_Entity);
13189             Check_Arg_Is_Local_Name (Arg1);
13190             E_Id := Entity (Get_Pragma_Arg (Arg1));
13191
13192             if E_Id = Any_Type then
13193                return;
13194             elsif No (E_Id) or else not Is_Type (E_Id) then
13195                Error_Pragma_Arg ("pragma% requires type", Arg1);
13196             end if;
13197
13198             Set_Universal_Aliasing (Implementation_Base_Type (E_Id), Sense);
13199          end Universal_Alias;
13200
13201          --------------------
13202          -- Universal_Data --
13203          --------------------
13204
13205          --  pragma Universal_Data [(library_unit_NAME)];
13206
13207          when Pragma_Universal_Data =>
13208             GNAT_Pragma;
13209
13210             --  If this is a configuration pragma, then set the universal
13211             --  addressing option, otherwise confirm that the pragma satisfies
13212             --  the requirements of library unit pragma placement and leave it
13213             --  to the GNAAMP back end to detect the pragma (avoids transitive
13214             --  setting of the option due to withed units).
13215
13216             if Is_Configuration_Pragma then
13217                Universal_Addressing_On_AAMP := True;
13218             else
13219                Check_Valid_Library_Unit_Pragma;
13220             end if;
13221
13222             if not AAMP_On_Target then
13223                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13224             end if;
13225
13226          ----------------
13227          -- Unmodified --
13228          ----------------
13229
13230          --  pragma Unmodified (local_Name {, local_Name});
13231
13232          when Pragma_Unmodified => Unmodified : declare
13233             Arg_Node : Node_Id;
13234             Arg_Expr : Node_Id;
13235             Arg_Ent  : Entity_Id;
13236
13237          begin
13238             GNAT_Pragma;
13239             Check_At_Least_N_Arguments (1);
13240
13241             --  Loop through arguments
13242
13243             Arg_Node := Arg1;
13244             while Present (Arg_Node) loop
13245                Check_No_Identifier (Arg_Node);
13246
13247                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
13248                --  in fact generate reference, so that the entity will have a
13249                --  reference, which will inhibit any warnings about it not
13250                --  being referenced, and also properly show up in the ali file
13251                --  as a reference. But this reference is recorded before the
13252                --  Has_Pragma_Unreferenced flag is set, so that no warning is
13253                --  generated for this reference.
13254
13255                Check_Arg_Is_Local_Name (Arg_Node);
13256                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13257
13258                if Is_Entity_Name (Arg_Expr) then
13259                   Arg_Ent := Entity (Arg_Expr);
13260
13261                   if not Is_Assignable (Arg_Ent) then
13262                      Error_Pragma_Arg
13263                        ("pragma% can only be applied to a variable",
13264                         Arg_Expr);
13265                   else
13266                      Set_Has_Pragma_Unmodified (Arg_Ent, Sense);
13267                   end if;
13268                end if;
13269
13270                Next (Arg_Node);
13271             end loop;
13272          end Unmodified;
13273
13274          ------------------
13275          -- Unreferenced --
13276          ------------------
13277
13278          --  pragma Unreferenced (local_Name {, local_Name});
13279
13280          --    or when used in a context clause:
13281
13282          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13283
13284          when Pragma_Unreferenced => Unreferenced : declare
13285             Arg_Node : Node_Id;
13286             Arg_Expr : Node_Id;
13287             Arg_Ent  : Entity_Id;
13288             Citem    : Node_Id;
13289
13290          begin
13291             GNAT_Pragma;
13292             Check_At_Least_N_Arguments (1);
13293
13294             --  Check case of appearing within context clause
13295
13296             if Is_In_Context_Clause then
13297
13298                --  The arguments must all be units mentioned in a with clause
13299                --  in the same context clause. Note we already checked (in
13300                --  Par.Prag) that the arguments are either identifiers or
13301                --  selected components.
13302
13303                Arg_Node := Arg1;
13304                while Present (Arg_Node) loop
13305                   Citem := First (List_Containing (N));
13306                   while Citem /= N loop
13307                      if Nkind (Citem) = N_With_Clause
13308                        and then
13309                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13310                      then
13311                         Set_Has_Pragma_Unreferenced
13312                           (Cunit_Entity
13313                              (Get_Source_Unit
13314                                 (Library_Unit (Citem))));
13315                         Set_Unit_Name
13316                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
13317                         exit;
13318                      end if;
13319
13320                      Next (Citem);
13321                   end loop;
13322
13323                   if Citem = N then
13324                      Error_Pragma_Arg
13325                        ("argument of pragma% is not with'ed unit", Arg_Node);
13326                   end if;
13327
13328                   Next (Arg_Node);
13329                end loop;
13330
13331             --  Case of not in list of context items
13332
13333             else
13334                Arg_Node := Arg1;
13335                while Present (Arg_Node) loop
13336                   Check_No_Identifier (Arg_Node);
13337
13338                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
13339                   --  will in fact generate reference, so that the entity will
13340                   --  have a reference, which will inhibit any warnings about
13341                   --  it not being referenced, and also properly show up in the
13342                   --  ali file as a reference. But this reference is recorded
13343                   --  before the Has_Pragma_Unreferenced flag is set, so that
13344                   --  no warning is generated for this reference.
13345
13346                   Check_Arg_Is_Local_Name (Arg_Node);
13347                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
13348
13349                   if Is_Entity_Name (Arg_Expr) then
13350                      Arg_Ent := Entity (Arg_Expr);
13351
13352                      --  If the entity is overloaded, the pragma applies to the
13353                      --  most recent overloading, as documented. In this case,
13354                      --  name resolution does not generate a reference, so it
13355                      --  must be done here explicitly.
13356
13357                      if Is_Overloaded (Arg_Expr) then
13358                         Generate_Reference (Arg_Ent, N);
13359                      end if;
13360
13361                      Set_Has_Pragma_Unreferenced (Arg_Ent, Sense);
13362                   end if;
13363
13364                   Next (Arg_Node);
13365                end loop;
13366             end if;
13367          end Unreferenced;
13368
13369          --------------------------
13370          -- Unreferenced_Objects --
13371          --------------------------
13372
13373          --  pragma Unreferenced_Objects (local_Name {, local_Name});
13374
13375          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13376             Arg_Node : Node_Id;
13377             Arg_Expr : Node_Id;
13378
13379          begin
13380             GNAT_Pragma;
13381             Check_At_Least_N_Arguments (1);
13382
13383             Arg_Node := Arg1;
13384             while Present (Arg_Node) loop
13385                Check_No_Identifier (Arg_Node);
13386                Check_Arg_Is_Local_Name (Arg_Node);
13387                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13388
13389                if not Is_Entity_Name (Arg_Expr)
13390                  or else not Is_Type (Entity (Arg_Expr))
13391                then
13392                   Error_Pragma_Arg
13393                     ("argument for pragma% must be type or subtype", Arg_Node);
13394                end if;
13395
13396                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr), Sense);
13397                Next (Arg_Node);
13398             end loop;
13399          end Unreferenced_Objects;
13400
13401          ------------------------------
13402          -- Unreserve_All_Interrupts --
13403          ------------------------------
13404
13405          --  pragma Unreserve_All_Interrupts;
13406
13407          when Pragma_Unreserve_All_Interrupts =>
13408             GNAT_Pragma;
13409             Check_Arg_Count (0);
13410
13411             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13412                Unreserve_All_Interrupts := True;
13413             end if;
13414
13415          ----------------
13416          -- Unsuppress --
13417          ----------------
13418
13419          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13420
13421          when Pragma_Unsuppress =>
13422             Ada_2005_Pragma;
13423             Process_Suppress_Unsuppress (False);
13424
13425          -------------------
13426          -- Use_VADS_Size --
13427          -------------------
13428
13429          --  pragma Use_VADS_Size;
13430
13431          when Pragma_Use_VADS_Size =>
13432             GNAT_Pragma;
13433             Check_Arg_Count (0);
13434             Check_Valid_Configuration_Pragma;
13435             Use_VADS_Size := True;
13436
13437          ---------------------
13438          -- Validity_Checks --
13439          ---------------------
13440
13441          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13442
13443          when Pragma_Validity_Checks => Validity_Checks : declare
13444             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13445             S  : String_Id;
13446             C  : Char_Code;
13447
13448          begin
13449             GNAT_Pragma;
13450             Check_Arg_Count (1);
13451             Check_No_Identifiers;
13452
13453             if Nkind (A) = N_String_Literal then
13454                S   := Strval (A);
13455
13456                declare
13457                   Slen    : constant Natural := Natural (String_Length (S));
13458                   Options : String (1 .. Slen);
13459                   J       : Natural;
13460
13461                begin
13462                   J := 1;
13463                   loop
13464                      C := Get_String_Char (S, Int (J));
13465                      exit when not In_Character_Range (C);
13466                      Options (J) := Get_Character (C);
13467
13468                      if J = Slen then
13469                         Set_Validity_Check_Options (Options);
13470                         exit;
13471                      else
13472                         J := J + 1;
13473                      end if;
13474                   end loop;
13475                end;
13476
13477             elsif Nkind (A) = N_Identifier then
13478
13479                if Chars (A) = Name_All_Checks then
13480                   Set_Validity_Check_Options ("a");
13481
13482                elsif Chars (A) = Name_On then
13483                   Validity_Checks_On := True;
13484
13485                elsif Chars (A) = Name_Off then
13486                   Validity_Checks_On := False;
13487
13488                end if;
13489             end if;
13490          end Validity_Checks;
13491
13492          --------------
13493          -- Volatile --
13494          --------------
13495
13496          --  pragma Volatile (LOCAL_NAME);
13497
13498          when Pragma_Volatile =>
13499             Process_Atomic_Shared_Volatile;
13500
13501          -------------------------
13502          -- Volatile_Components --
13503          -------------------------
13504
13505          --  pragma Volatile_Components (array_LOCAL_NAME);
13506
13507          --  Volatile is handled by the same circuit as Atomic_Components
13508
13509          --------------
13510          -- Warnings --
13511          --------------
13512
13513          --  pragma Warnings (On | Off);
13514          --  pragma Warnings (On | Off, LOCAL_NAME);
13515          --  pragma Warnings (static_string_EXPRESSION);
13516          --  pragma Warnings (On | Off, STRING_LITERAL);
13517
13518          when Pragma_Warnings => Warnings : begin
13519             GNAT_Pragma;
13520             Check_At_Least_N_Arguments (1);
13521             Check_No_Identifiers;
13522
13523             --  If debug flag -gnatd.i is set, pragma is ignored
13524
13525             if Debug_Flag_Dot_I then
13526                return;
13527             end if;
13528
13529             --  Process various forms of the pragma
13530
13531             declare
13532                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13533
13534             begin
13535                --  One argument case
13536
13537                if Arg_Count = 1 then
13538
13539                   --  On/Off one argument case was processed by parser
13540
13541                   if Nkind (Argx) = N_Identifier
13542                     and then
13543                       (Chars (Argx) = Name_On
13544                          or else
13545                        Chars (Argx) = Name_Off)
13546                   then
13547                      null;
13548
13549                   --  One argument case must be ON/OFF or static string expr
13550
13551                   elsif not Is_Static_String_Expression (Arg1) then
13552                      Error_Pragma_Arg
13553                        ("argument of pragma% must be On/Off or " &
13554                         "static string expression", Arg1);
13555
13556                   --  One argument string expression case
13557
13558                   else
13559                      declare
13560                         Lit : constant Node_Id   := Expr_Value_S (Argx);
13561                         Str : constant String_Id := Strval (Lit);
13562                         Len : constant Nat       := String_Length (Str);
13563                         C   : Char_Code;
13564                         J   : Nat;
13565                         OK  : Boolean;
13566                         Chr : Character;
13567
13568                      begin
13569                         J := 1;
13570                         while J <= Len loop
13571                            C := Get_String_Char (Str, J);
13572                            OK := In_Character_Range (C);
13573
13574                            if OK then
13575                               Chr := Get_Character (C);
13576
13577                               --  Dot case
13578
13579                               if J < Len and then Chr = '.' then
13580                                  J := J + 1;
13581                                  C := Get_String_Char (Str, J);
13582                                  Chr := Get_Character (C);
13583
13584                                  if not Set_Dot_Warning_Switch (Chr) then
13585                                     Error_Pragma_Arg
13586                                       ("invalid warning switch character " &
13587                                        '.' & Chr, Arg1);
13588                                  end if;
13589
13590                               --  Non-Dot case
13591
13592                               else
13593                                  OK := Set_Warning_Switch (Chr);
13594                               end if;
13595                            end if;
13596
13597                            if not OK then
13598                               Error_Pragma_Arg
13599                                 ("invalid warning switch character " & Chr,
13600                                  Arg1);
13601                            end if;
13602
13603                            J := J + 1;
13604                         end loop;
13605                      end;
13606                   end if;
13607
13608                   --  Two or more arguments (must be two)
13609
13610                else
13611                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13612                   Check_At_Most_N_Arguments (2);
13613
13614                   declare
13615                      E_Id : Node_Id;
13616                      E    : Entity_Id;
13617                      Err  : Boolean;
13618
13619                   begin
13620                      E_Id := Get_Pragma_Arg (Arg2);
13621                      Analyze (E_Id);
13622
13623                      --  In the expansion of an inlined body, a reference to
13624                      --  the formal may be wrapped in a conversion if the
13625                      --  actual is a conversion. Retrieve the real entity name.
13626
13627                      if (In_Instance_Body
13628                          or else In_Inlined_Body)
13629                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13630                      then
13631                         E_Id := Expression (E_Id);
13632                      end if;
13633
13634                      --  Entity name case
13635
13636                      if Is_Entity_Name (E_Id) then
13637                         E := Entity (E_Id);
13638
13639                         if E = Any_Id then
13640                            return;
13641                         else
13642                            loop
13643                               Set_Warnings_Off
13644                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13645                                                               Name_Off));
13646
13647                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13648                                 and then Warn_On_Warnings_Off
13649                               then
13650                                  Warnings_Off_Pragmas.Append ((N, E));
13651                               end if;
13652
13653                               if Is_Enumeration_Type (E) then
13654                                  declare
13655                                     Lit : Entity_Id;
13656                                  begin
13657                                     Lit := First_Literal (E);
13658                                     while Present (Lit) loop
13659                                        Set_Warnings_Off (Lit);
13660                                        Next_Literal (Lit);
13661                                     end loop;
13662                                  end;
13663                               end if;
13664
13665                               exit when No (Homonym (E));
13666                               E := Homonym (E);
13667                            end loop;
13668                         end if;
13669
13670                      --  Error if not entity or static string literal case
13671
13672                      elsif not Is_Static_String_Expression (Arg2) then
13673                         Error_Pragma_Arg
13674                           ("second argument of pragma% must be entity " &
13675                            "name or static string expression", Arg2);
13676
13677                      --  String literal case
13678
13679                      else
13680                         String_To_Name_Buffer
13681                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13682
13683                         --  Note on configuration pragma case: If this is a
13684                         --  configuration pragma, then for an OFF pragma, we
13685                         --  just set Config True in the call, which is all
13686                         --  that needs to be done. For the case of ON, this
13687                         --  is normally an error, unless it is canceling the
13688                         --  effect of a previous OFF pragma in the same file.
13689                         --  In any other case, an error will be signalled (ON
13690                         --  with no matching OFF).
13691
13692                         if Chars (Argx) = Name_Off then
13693                            Set_Specific_Warning_Off
13694                              (Loc, Name_Buffer (1 .. Name_Len),
13695                               Config => Is_Configuration_Pragma);
13696
13697                         elsif Chars (Argx) = Name_On then
13698                            Set_Specific_Warning_On
13699                              (Loc, Name_Buffer (1 .. Name_Len), Err);
13700
13701                            if Err then
13702                               Error_Msg
13703                                 ("?pragma Warnings On with no " &
13704                                  "matching Warnings Off",
13705                                  Loc);
13706                            end if;
13707                         end if;
13708                      end if;
13709                   end;
13710                end if;
13711             end;
13712          end Warnings;
13713
13714          -------------------
13715          -- Weak_External --
13716          -------------------
13717
13718          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
13719
13720          when Pragma_Weak_External => Weak_External : declare
13721             Ent : Entity_Id;
13722
13723          begin
13724             GNAT_Pragma;
13725             Check_Arg_Count (1);
13726             Check_Optional_Identifier (Arg1, Name_Entity);
13727             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13728             Ent := Entity (Get_Pragma_Arg (Arg1));
13729
13730             if Rep_Item_Too_Early (Ent, N) then
13731                return;
13732             else
13733                Ent := Underlying_Type (Ent);
13734             end if;
13735
13736             --  The only processing required is to link this item on to the
13737             --  list of rep items for the given entity. This is accomplished
13738             --  by the call to Rep_Item_Too_Late (when no error is detected
13739             --  and False is returned).
13740
13741             if Rep_Item_Too_Late (Ent, N) then
13742                return;
13743             else
13744                Set_Has_Gigi_Rep_Item (Ent);
13745             end if;
13746          end Weak_External;
13747
13748          -----------------------------
13749          -- Wide_Character_Encoding --
13750          -----------------------------
13751
13752          --  pragma Wide_Character_Encoding (IDENTIFIER);
13753
13754          when Pragma_Wide_Character_Encoding =>
13755             GNAT_Pragma;
13756
13757             --  Nothing to do, handled in parser. Note that we do not enforce
13758             --  configuration pragma placement, this pragma can appear at any
13759             --  place in the source, allowing mixed encodings within a single
13760             --  source program.
13761
13762             null;
13763
13764          --------------------
13765          -- Unknown_Pragma --
13766          --------------------
13767
13768          --  Should be impossible, since the case of an unknown pragma is
13769          --  separately processed before the case statement is entered.
13770
13771          when Unknown_Pragma =>
13772             raise Program_Error;
13773       end case;
13774
13775       --  AI05-0144: detect dangerous order dependence. Disabled for now,
13776       --  until AI is formally approved.
13777
13778       --  Check_Order_Dependence;
13779
13780    exception
13781       when Pragma_Exit => null;
13782    end Analyze_Pragma;
13783
13784    -------------------
13785    -- Check_Enabled --
13786    -------------------
13787
13788    function Check_Enabled (Nam : Name_Id) return Boolean is
13789       PP : Node_Id;
13790
13791    begin
13792       --  Loop through entries in check policy list
13793
13794       PP := Opt.Check_Policy_List;
13795       loop
13796          --  If there are no specific entries that matched, then we let the
13797          --  setting of assertions govern. Note that this provides the needed
13798          --  compatibility with the RM for the cases of assertion, invariant,
13799          --  precondition, predicate, and postcondition.
13800
13801          if No (PP) then
13802             return Assertions_Enabled;
13803
13804          --  Here we have an entry see if it matches
13805
13806          else
13807             declare
13808                PPA : constant List_Id := Pragma_Argument_Associations (PP);
13809
13810             begin
13811                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13812                   case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13813                      when Name_On | Name_Check =>
13814                         return True;
13815                      when Name_Off | Name_Ignore =>
13816                         return False;
13817                      when others =>
13818                         raise Program_Error;
13819                   end case;
13820
13821                else
13822                   PP := Next_Pragma (PP);
13823                end if;
13824             end;
13825          end if;
13826       end loop;
13827    end Check_Enabled;
13828
13829    ---------------------------------
13830    -- Delay_Config_Pragma_Analyze --
13831    ---------------------------------
13832
13833    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13834    begin
13835       return Pragma_Name (N) = Name_Interrupt_State
13836                or else
13837              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13838    end Delay_Config_Pragma_Analyze;
13839
13840    -------------------------
13841    -- Get_Base_Subprogram --
13842    -------------------------
13843
13844    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13845       Result : Entity_Id;
13846
13847    begin
13848       --  Follow subprogram renaming chain
13849
13850       Result := Def_Id;
13851       while Is_Subprogram (Result)
13852         and then
13853           (Is_Generic_Instance (Result)
13854             or else Nkind (Parent (Declaration_Node (Result))) =
13855                                          N_Subprogram_Renaming_Declaration)
13856         and then Present (Alias (Result))
13857       loop
13858          Result := Alias (Result);
13859       end loop;
13860
13861       return Result;
13862    end Get_Base_Subprogram;
13863
13864    ----------------
13865    -- Initialize --
13866    ----------------
13867
13868    procedure Initialize is
13869    begin
13870       Externals.Init;
13871    end Initialize;
13872
13873    -----------------------------
13874    -- Is_Config_Static_String --
13875    -----------------------------
13876
13877    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13878
13879       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13880       --  This is an internal recursive function that is just like the outer
13881       --  function except that it adds the string to the name buffer rather
13882       --  than placing the string in the name buffer.
13883
13884       ------------------------------
13885       -- Add_Config_Static_String --
13886       ------------------------------
13887
13888       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13889          N : Node_Id;
13890          C : Char_Code;
13891
13892       begin
13893          N := Arg;
13894
13895          if Nkind (N) = N_Op_Concat then
13896             if Add_Config_Static_String (Left_Opnd (N)) then
13897                N := Right_Opnd (N);
13898             else
13899                return False;
13900             end if;
13901          end if;
13902
13903          if Nkind (N) /= N_String_Literal then
13904             Error_Msg_N ("string literal expected for pragma argument", N);
13905             return False;
13906
13907          else
13908             for J in 1 .. String_Length (Strval (N)) loop
13909                C := Get_String_Char (Strval (N), J);
13910
13911                if not In_Character_Range (C) then
13912                   Error_Msg
13913                     ("string literal contains invalid wide character",
13914                      Sloc (N) + 1 + Source_Ptr (J));
13915                   return False;
13916                end if;
13917
13918                Add_Char_To_Name_Buffer (Get_Character (C));
13919             end loop;
13920          end if;
13921
13922          return True;
13923       end Add_Config_Static_String;
13924
13925    --  Start of processing for Is_Config_Static_String
13926
13927    begin
13928
13929       Name_Len := 0;
13930       return Add_Config_Static_String (Arg);
13931    end Is_Config_Static_String;
13932
13933    -----------------------------------------
13934    -- Is_Non_Significant_Pragma_Reference --
13935    -----------------------------------------
13936
13937    --  This function makes use of the following static table which indicates
13938    --  whether a given pragma is significant.
13939
13940    --  -1  indicates that references in any argument position are significant
13941    --  0   indicates that appearance in any argument is not significant
13942    --  +n  indicates that appearance as argument n is significant, but all
13943    --      other arguments are not significant
13944    --  99  special processing required (e.g. for pragma Check)
13945
13946    Sig_Flags : constant array (Pragma_Id) of Int :=
13947      (Pragma_AST_Entry                     => -1,
13948       Pragma_Abort_Defer                   => -1,
13949       Pragma_Ada_83                        => -1,
13950       Pragma_Ada_95                        => -1,
13951       Pragma_Ada_05                        => -1,
13952       Pragma_Ada_2005                      => -1,
13953       Pragma_Ada_12                        => -1,
13954       Pragma_Ada_2012                      => -1,
13955       Pragma_All_Calls_Remote              => -1,
13956       Pragma_Annotate                      => -1,
13957       Pragma_Assert                        => -1,
13958       Pragma_Assertion_Policy              =>  0,
13959       Pragma_Assume_No_Invalid_Values      =>  0,
13960       Pragma_Asynchronous                  => -1,
13961       Pragma_Atomic                        =>  0,
13962       Pragma_Atomic_Components             =>  0,
13963       Pragma_Attach_Handler                => -1,
13964       Pragma_Check                         => 99,
13965       Pragma_Check_Name                    =>  0,
13966       Pragma_Check_Policy                  =>  0,
13967       Pragma_CIL_Constructor               => -1,
13968       Pragma_CPP_Class                     =>  0,
13969       Pragma_CPP_Constructor               =>  0,
13970       Pragma_CPP_Virtual                   =>  0,
13971       Pragma_CPP_Vtable                    =>  0,
13972       Pragma_CPU                           => -1,
13973       Pragma_C_Pass_By_Copy                =>  0,
13974       Pragma_Comment                       =>  0,
13975       Pragma_Common_Object                 => -1,
13976       Pragma_Compile_Time_Error            => -1,
13977       Pragma_Compile_Time_Warning          => -1,
13978       Pragma_Compiler_Unit                 =>  0,
13979       Pragma_Complete_Representation       =>  0,
13980       Pragma_Complex_Representation        =>  0,
13981       Pragma_Component_Alignment           => -1,
13982       Pragma_Controlled                    =>  0,
13983       Pragma_Convention                    =>  0,
13984       Pragma_Convention_Identifier         =>  0,
13985       Pragma_Debug                         => -1,
13986       Pragma_Debug_Policy                  =>  0,
13987       Pragma_Detect_Blocking               => -1,
13988       Pragma_Default_Storage_Pool          => -1,
13989       Pragma_Dimension                     => -1,
13990       Pragma_Discard_Names                 =>  0,
13991       Pragma_Elaborate                     => -1,
13992       Pragma_Elaborate_All                 => -1,
13993       Pragma_Elaborate_Body                => -1,
13994       Pragma_Elaboration_Checks            => -1,
13995       Pragma_Eliminate                     => -1,
13996       Pragma_Export                        => -1,
13997       Pragma_Export_Exception              => -1,
13998       Pragma_Export_Function               => -1,
13999       Pragma_Export_Object                 => -1,
14000       Pragma_Export_Procedure              => -1,
14001       Pragma_Export_Value                  => -1,
14002       Pragma_Export_Valued_Procedure       => -1,
14003       Pragma_Extend_System                 => -1,
14004       Pragma_Extensions_Allowed            => -1,
14005       Pragma_External                      => -1,
14006       Pragma_Favor_Top_Level               => -1,
14007       Pragma_External_Name_Casing          => -1,
14008       Pragma_Fast_Math                     => -1,
14009       Pragma_Finalize_Storage_Only         =>  0,
14010       Pragma_Float_Representation          =>  0,
14011       Pragma_Ident                         => -1,
14012       Pragma_Implemented                   => -1,
14013       Pragma_Implicit_Packing              =>  0,
14014       Pragma_Import                        => +2,
14015       Pragma_Import_Exception              =>  0,
14016       Pragma_Import_Function               =>  0,
14017       Pragma_Import_Object                 =>  0,
14018       Pragma_Import_Procedure              =>  0,
14019       Pragma_Import_Valued_Procedure       =>  0,
14020       Pragma_Independent                   =>  0,
14021       Pragma_Independent_Components        =>  0,
14022       Pragma_Initialize_Scalars            => -1,
14023       Pragma_Inline                        =>  0,
14024       Pragma_Inline_Always                 =>  0,
14025       Pragma_Inline_Generic                =>  0,
14026       Pragma_Inspection_Point              => -1,
14027       Pragma_Interface                     => +2,
14028       Pragma_Interface_Name                => +2,
14029       Pragma_Interrupt_Handler             => -1,
14030       Pragma_Interrupt_Priority            => -1,
14031       Pragma_Interrupt_State               => -1,
14032       Pragma_Invariant                     => -1,
14033       Pragma_Java_Constructor              => -1,
14034       Pragma_Java_Interface                => -1,
14035       Pragma_Keep_Names                    =>  0,
14036       Pragma_License                       => -1,
14037       Pragma_Link_With                     => -1,
14038       Pragma_Linker_Alias                  => -1,
14039       Pragma_Linker_Constructor            => -1,
14040       Pragma_Linker_Destructor             => -1,
14041       Pragma_Linker_Options                => -1,
14042       Pragma_Linker_Section                => -1,
14043       Pragma_List                          => -1,
14044       Pragma_Locking_Policy                => -1,
14045       Pragma_Long_Float                    => -1,
14046       Pragma_Machine_Attribute             => -1,
14047       Pragma_Main                          => -1,
14048       Pragma_Main_Storage                  => -1,
14049       Pragma_Memory_Size                   => -1,
14050       Pragma_No_Return                     =>  0,
14051       Pragma_No_Body                       =>  0,
14052       Pragma_No_Run_Time                   => -1,
14053       Pragma_No_Strict_Aliasing            => -1,
14054       Pragma_Normalize_Scalars             => -1,
14055       Pragma_Obsolescent                   =>  0,
14056       Pragma_Optimize                      => -1,
14057       Pragma_Optimize_Alignment            => -1,
14058       Pragma_Ordered                       =>  0,
14059       Pragma_Pack                          =>  0,
14060       Pragma_Page                          => -1,
14061       Pragma_Passive                       => -1,
14062       Pragma_Preelaborable_Initialization  => -1,
14063       Pragma_Polling                       => -1,
14064       Pragma_Persistent_BSS                =>  0,
14065       Pragma_Postcondition                 => -1,
14066       Pragma_Precondition                  => -1,
14067       Pragma_Predicate                     => -1,
14068       Pragma_Preelaborate                  => -1,
14069       Pragma_Preelaborate_05               => -1,
14070       Pragma_Priority                      => -1,
14071       Pragma_Priority_Specific_Dispatching => -1,
14072       Pragma_Profile                       =>  0,
14073       Pragma_Profile_Warnings              =>  0,
14074       Pragma_Propagate_Exceptions          => -1,
14075       Pragma_Psect_Object                  => -1,
14076       Pragma_Pure                          => -1,
14077       Pragma_Pure_05                       => -1,
14078       Pragma_Pure_Function                 => -1,
14079       Pragma_Queuing_Policy                => -1,
14080       Pragma_Ravenscar                     => -1,
14081       Pragma_Relative_Deadline             => -1,
14082       Pragma_Remote_Call_Interface         => -1,
14083       Pragma_Remote_Types                  => -1,
14084       Pragma_Restricted_Run_Time           => -1,
14085       Pragma_Restriction_Warnings          => -1,
14086       Pragma_Restrictions                  => -1,
14087       Pragma_Reviewable                    => -1,
14088       Pragma_Short_Circuit_And_Or          => -1,
14089       Pragma_Share_Generic                 => -1,
14090       Pragma_Shared                        => -1,
14091       Pragma_Shared_Passive                => -1,
14092       Pragma_Short_Descriptors             =>  0,
14093       Pragma_Source_File_Name              => -1,
14094       Pragma_Source_File_Name_Project      => -1,
14095       Pragma_Source_Reference              => -1,
14096       Pragma_SPARK_95                      => -1,
14097       Pragma_Storage_Size                  => -1,
14098       Pragma_Storage_Unit                  => -1,
14099       Pragma_Static_Elaboration_Desired    => -1,
14100       Pragma_Stream_Convert                => -1,
14101       Pragma_Style_Checks                  => -1,
14102       Pragma_Subtitle                      => -1,
14103       Pragma_Suppress                      =>  0,
14104       Pragma_Suppress_Exception_Locations  =>  0,
14105       Pragma_Suppress_All                  => -1,
14106       Pragma_Suppress_Debug_Info           =>  0,
14107       Pragma_Suppress_Initialization       =>  0,
14108       Pragma_System_Name                   => -1,
14109       Pragma_Task_Dispatching_Policy       => -1,
14110       Pragma_Task_Info                     => -1,
14111       Pragma_Task_Name                     => -1,
14112       Pragma_Task_Storage                  =>  0,
14113       Pragma_Thread_Local_Storage          =>  0,
14114       Pragma_Time_Slice                    => -1,
14115       Pragma_Title                         => -1,
14116       Pragma_Unchecked_Union               =>  0,
14117       Pragma_Unimplemented_Unit            => -1,
14118       Pragma_Universal_Aliasing            => -1,
14119       Pragma_Universal_Data                => -1,
14120       Pragma_Unmodified                    => -1,
14121       Pragma_Unreferenced                  => -1,
14122       Pragma_Unreferenced_Objects          => -1,
14123       Pragma_Unreserve_All_Interrupts      => -1,
14124       Pragma_Unsuppress                    =>  0,
14125       Pragma_Use_VADS_Size                 => -1,
14126       Pragma_Validity_Checks               => -1,
14127       Pragma_Volatile                      =>  0,
14128       Pragma_Volatile_Components           =>  0,
14129       Pragma_Warnings                      => -1,
14130       Pragma_Weak_External                 => -1,
14131       Pragma_Wide_Character_Encoding       =>  0,
14132       Unknown_Pragma                       =>  0);
14133
14134    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14135       Id : Pragma_Id;
14136       P  : Node_Id;
14137       C  : Int;
14138       A  : Node_Id;
14139
14140    begin
14141       P := Parent (N);
14142
14143       if Nkind (P) /= N_Pragma_Argument_Association then
14144          return False;
14145
14146       else
14147          Id := Get_Pragma_Id (Parent (P));
14148          C := Sig_Flags (Id);
14149
14150          case C is
14151             when -1 =>
14152                return False;
14153
14154             when 0 =>
14155                return True;
14156
14157             when 99 =>
14158                case Id is
14159
14160                   --  For pragma Check, the first argument is not significant,
14161                   --  the second and the third (if present) arguments are
14162                   --  significant.
14163
14164                   when Pragma_Check =>
14165                      return
14166                        P = First (Pragma_Argument_Associations (Parent (P)));
14167
14168                   when others =>
14169                      raise Program_Error;
14170                end case;
14171
14172             when others =>
14173                A := First (Pragma_Argument_Associations (Parent (P)));
14174                for J in 1 .. C - 1 loop
14175                   if No (A) then
14176                      return False;
14177                   end if;
14178
14179                   Next (A);
14180                end loop;
14181
14182                return A = P; -- is this wrong way round ???
14183          end case;
14184       end if;
14185    end Is_Non_Significant_Pragma_Reference;
14186
14187    ------------------------------
14188    -- Is_Pragma_String_Literal --
14189    ------------------------------
14190
14191    --  This function returns true if the corresponding pragma argument is a
14192    --  static string expression. These are the only cases in which string
14193    --  literals can appear as pragma arguments. We also allow a string literal
14194    --  as the first argument to pragma Assert (although it will of course
14195    --  always generate a type error).
14196
14197    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14198       Pragn : constant Node_Id := Parent (Par);
14199       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14200       Pname : constant Name_Id := Pragma_Name (Pragn);
14201       Argn  : Natural;
14202       N     : Node_Id;
14203
14204    begin
14205       Argn := 1;
14206       N := First (Assoc);
14207       loop
14208          exit when N = Par;
14209          Argn := Argn + 1;
14210          Next (N);
14211       end loop;
14212
14213       if Pname = Name_Assert then
14214          return True;
14215
14216       elsif Pname = Name_Export then
14217          return Argn > 2;
14218
14219       elsif Pname = Name_Ident then
14220          return Argn = 1;
14221
14222       elsif Pname = Name_Import then
14223          return Argn > 2;
14224
14225       elsif Pname = Name_Interface_Name then
14226          return Argn > 1;
14227
14228       elsif Pname = Name_Linker_Alias then
14229          return Argn = 2;
14230
14231       elsif Pname = Name_Linker_Section then
14232          return Argn = 2;
14233
14234       elsif Pname = Name_Machine_Attribute then
14235          return Argn = 2;
14236
14237       elsif Pname = Name_Source_File_Name then
14238          return True;
14239
14240       elsif Pname = Name_Source_Reference then
14241          return Argn = 2;
14242
14243       elsif Pname = Name_Title then
14244          return True;
14245
14246       elsif Pname = Name_Subtitle then
14247          return True;
14248
14249       else
14250          return False;
14251       end if;
14252    end Is_Pragma_String_Literal;
14253
14254    --------------------------------------
14255    -- Process_Compilation_Unit_Pragmas --
14256    --------------------------------------
14257
14258    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14259    begin
14260       --  A special check for pragma Suppress_All, a very strange DEC pragma,
14261       --  strange because it comes at the end of the unit. Rational has the
14262       --  same name for a pragma, but treats it as a program unit pragma, In
14263       --  GNAT we just decide to allow it anywhere at all. If it appeared then
14264       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
14265       --  node, and we insert a pragma Suppress (All_Checks) at the start of
14266       --  the context clause to ensure the correct processing.
14267
14268       if Has_Pragma_Suppress_All (N) then
14269          Prepend_To (Context_Items (N),
14270            Make_Pragma (Sloc (N),
14271              Chars                        => Name_Suppress,
14272              Pragma_Argument_Associations => New_List (
14273                Make_Pragma_Argument_Association (Sloc (N),
14274                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14275       end if;
14276
14277       --  Nothing else to do at the current time!
14278
14279    end Process_Compilation_Unit_Pragmas;
14280
14281    --------
14282    -- rv --
14283    --------
14284
14285    procedure rv is
14286    begin
14287       null;
14288    end rv;
14289
14290    --------------------------------
14291    -- Set_Encoded_Interface_Name --
14292    --------------------------------
14293
14294    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14295       Str : constant String_Id := Strval (S);
14296       Len : constant Int       := String_Length (Str);
14297       CC  : Char_Code;
14298       C   : Character;
14299       J   : Int;
14300
14301       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14302
14303       procedure Encode;
14304       --  Stores encoded value of character code CC. The encoding we use an
14305       --  underscore followed by four lower case hex digits.
14306
14307       ------------
14308       -- Encode --
14309       ------------
14310
14311       procedure Encode is
14312       begin
14313          Store_String_Char (Get_Char_Code ('_'));
14314          Store_String_Char
14315            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14316          Store_String_Char
14317            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14318          Store_String_Char
14319            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14320          Store_String_Char
14321            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14322       end Encode;
14323
14324    --  Start of processing for Set_Encoded_Interface_Name
14325
14326    begin
14327       --  If first character is asterisk, this is a link name, and we leave it
14328       --  completely unmodified. We also ignore null strings (the latter case
14329       --  happens only in error cases) and no encoding should occur for Java or
14330       --  AAMP interface names.
14331
14332       if Len = 0
14333         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14334         or else VM_Target /= No_VM
14335         or else AAMP_On_Target
14336       then
14337          Set_Interface_Name (E, S);
14338
14339       else
14340          J := 1;
14341          loop
14342             CC := Get_String_Char (Str, J);
14343
14344             exit when not In_Character_Range (CC);
14345
14346             C := Get_Character (CC);
14347
14348             exit when C /= '_' and then C /= '$'
14349               and then C not in '0' .. '9'
14350               and then C not in 'a' .. 'z'
14351               and then C not in 'A' .. 'Z';
14352
14353             if J = Len then
14354                Set_Interface_Name (E, S);
14355                return;
14356
14357             else
14358                J := J + 1;
14359             end if;
14360          end loop;
14361
14362          --  Here we need to encode. The encoding we use as follows:
14363          --     three underscores  + four hex digits (lower case)
14364
14365          Start_String;
14366
14367          for J in 1 .. String_Length (Str) loop
14368             CC := Get_String_Char (Str, J);
14369
14370             if not In_Character_Range (CC) then
14371                Encode;
14372             else
14373                C := Get_Character (CC);
14374
14375                if C = '_' or else C = '$'
14376                  or else C in '0' .. '9'
14377                  or else C in 'a' .. 'z'
14378                  or else C in 'A' .. 'Z'
14379                then
14380                   Store_String_Char (CC);
14381                else
14382                   Encode;
14383                end if;
14384             end if;
14385          end loop;
14386
14387          Set_Interface_Name (E,
14388            Make_String_Literal (Sloc (S),
14389              Strval => End_String));
14390       end if;
14391    end Set_Encoded_Interface_Name;
14392
14393    -------------------
14394    -- Set_Unit_Name --
14395    -------------------
14396
14397    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14398       Pref : Node_Id;
14399       Scop : Entity_Id;
14400
14401    begin
14402       if Nkind (N) = N_Identifier
14403         and then Nkind (With_Item) = N_Identifier
14404       then
14405          Set_Entity (N, Entity (With_Item));
14406
14407       elsif Nkind (N) = N_Selected_Component then
14408          Change_Selected_Component_To_Expanded_Name (N);
14409          Set_Entity (N, Entity (With_Item));
14410          Set_Entity (Selector_Name (N), Entity (N));
14411
14412          Pref := Prefix (N);
14413          Scop := Scope (Entity (N));
14414          while Nkind (Pref) = N_Selected_Component loop
14415             Change_Selected_Component_To_Expanded_Name (Pref);
14416             Set_Entity (Selector_Name (Pref), Scop);
14417             Set_Entity (Pref, Scop);
14418             Pref := Prefix (Pref);
14419             Scop := Scope (Scop);
14420          end loop;
14421
14422          Set_Entity (Pref, Scop);
14423       end if;
14424    end Set_Unit_Name;
14425
14426 end Sem_Prag;