OSDN Git Service

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