OSDN Git Service

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