OSDN Git Service

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