OSDN Git Service

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