OSDN Git Service

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